Typescript Documentation
1. Introduction
Section titled “1. Introduction”The Sec-Gemini SDK provides a streamlined way to interact with Sec-Gemini v1, a new experimental AI model focused on advancing cybersecurity AI frontiers. This Typescript SDK enables developers to access certain methods including:
- Create a session
- Resume an existing session
- Send and Recieve prompts/responses via webhooks
The SDK handles all communication with the Sec-Gemini backend service, allowing you to focus on your application’s core functionality while maintaining robust security.
Core Concepts
Section titled “Core Concepts”- Initialization: The SDK is initialized using the
SecGemini.create()
method, which requires an API key and optionally a base URL and websockets URL. - Sessions: The SDK uses the concept of “sessions” (
InteractiveSession
) to manage user interactions. You can create new sessions or resume existing ones. - Messages: Communication within a session is structured using
Message
objects, which include information like the message type, role, and content. - Streaming: The SDK supports bidirectional streaming of messages through the
Streamer
class, enabling real-time communication with the user. - HTTP Client: The
HttpClient
class handles communication with the backend API.
2. Installation
Section titled “2. Installation”Using npm/yarn
Section titled “Using npm/yarn”npm install sec-gemini# oryarn add sec-gemini
Importing into your project
Section titled “Importing into your project”// ES Modulesimport SecGemini from "sec-gemini";import { MessageTypeEnum, Message } from "sec-gemini";
3. Set Up
Section titled “3. Set Up”Initialization
Section titled “Initialization”The SDK is initialized with your API key and optional configuration:
const apiKey = "your_api_key_here";const sdk = await SecGemini.create(apiKey: string);
4. Sessions
Section titled “4. Sessions”Create a new session
Section titled “Create a new session”-
Purpose: Creates a new interactive session.
-
Parameters:
options
(object): Configuration options for the new sessionttl
(number, optional): Time to live for the session in seconds (default: 86400).name
(string, optional): Human-readable name for the session.description
(string, optional): Description of the session.logSession
(boolean, optional): Whether the session can be logged (default: true).model
(string|ModelInfoInput, optional): Model to use (‘stable’, ‘experimental’, or specific ModelInfoInput).language
(string, optional): ISO language code (default: ‘en’).
-
Return Value:
Promise<InteractiveSession>
- A promise that resolves to a newInteractiveSession
object.
const session = await sdk.createSession({ ttl: 3600, name: "My Session", description: "Testing Sec-Gemini SDK", model: "stable", language: "en",});
Resume a session
Section titled “Resume a session”-
Purpose: Creates a new interactive session.
-
Parameters:
session_id
(string): The id of the session you would like to resume.
-
Return Value:
Promise<InteractiveSession>
- A promise that resolves to a newInteractiveSession
object.
const session = await SecGemini.resumeSession("1473-3434-3434-3433");
5. Communication with the backend
Section titled “5. Communication with the backend”Create a streamer
Section titled “Create a streamer”-
Purpose: Initializes a streamer for bidirectional communication.
-
Parameters:
-
onmessage
(function): Callback function to handle individual messages (Message
) from the stream. -
onresult
(function): Callback function to handle the final result (Message
) from the stream. -
Return Value:
Promise<Streamer>
- A promise that resolves to aStreamer
object.const streamer = await session.streamer((message) => { console.log('Message:', message.content); },(result) => { console.log('Result:', result.content); });```
-
Sending a message
Section titled “Sending a message”-
Purpose: Sends data to the stream.
-
Parameters:
data
(string): The data to send (e.g., a prompt or request).
-
Return Value:
Promise<void>
-
Example:
await streamer.send("Tell me about csrf");
Attaching a file
Section titled “Attaching a file”-
Purpose: Attaches a file to the current session. This allows for uploading files to be used within the session’s context.
-
Parameters:
fileName
(string): The name of the file to be attached.fileContent
(string | ArrayBuffer | Uint8Array): The content of the file, potentially base64 encoded.mimeTypeHint
(MimeType, optional): The MIME type of the file, to hint.
-
Return Value:
Promise<void>
- A promise that resolves when the file is successfully attached to the session.await session.attachFile("myFile.txt", base64fileContent);
Accessing User Information
Section titled “Accessing User Information”const userInfo = sdk.getUserInfo();const user = sdk.getUser();console.log(`Logged in as: ${user?.email}`);
Configuration Defaults
Section titled “Configuration Defaults”const DEFAULT_BASE_URL = "https://api.secgemini.google";const DEFAULT_WS_URL = "wss://api.secgemini.google";const DEFAULT_TTL = 86400; // 24 hours in seconds
Note:
- The
fileContent
is expected to be a string, and it might need to be base64 encoded depending on the file type.