@realtimex/sdk 1.3.7-rc.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +130 -1
- package/dist/index.d.ts +130 -1
- package/dist/index.js +190 -0
- package/dist/index.mjs +189 -0
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
|
@@ -1117,6 +1117,134 @@ declare class AgentModule {
|
|
|
1117
1117
|
}>;
|
|
1118
1118
|
}
|
|
1119
1119
|
|
|
1120
|
+
/**
|
|
1121
|
+
* ACP Agent Module — CLI-based agent sessions via ACP bridge
|
|
1122
|
+
*
|
|
1123
|
+
* Provides session lifecycle, sync/streaming chat, permission resolution,
|
|
1124
|
+
* and turn control for CLI agents (Claude, Gemini, Codex, etc.).
|
|
1125
|
+
*
|
|
1126
|
+
* Unlike AgentModule (LLM API-based), ACP agents spawn CLI processes
|
|
1127
|
+
* and can execute commands, read/write files, and interact with tools.
|
|
1128
|
+
*/
|
|
1129
|
+
|
|
1130
|
+
interface AcpAgentInfo {
|
|
1131
|
+
id: string;
|
|
1132
|
+
label: string;
|
|
1133
|
+
handles: string[];
|
|
1134
|
+
installed: boolean;
|
|
1135
|
+
authReady: boolean;
|
|
1136
|
+
version?: string | null;
|
|
1137
|
+
status: "installed" | "not_installed";
|
|
1138
|
+
/** Present when listAgents({ includeModels: true }). */
|
|
1139
|
+
models?: Array<{
|
|
1140
|
+
id: string;
|
|
1141
|
+
name?: string;
|
|
1142
|
+
}>;
|
|
1143
|
+
/** "provider_api" | "fallback" — how models were resolved. */
|
|
1144
|
+
source?: string | null;
|
|
1145
|
+
/** Non-null if model fetch failed and fell back. */
|
|
1146
|
+
error?: string | null;
|
|
1147
|
+
}
|
|
1148
|
+
interface AcpSessionOptions {
|
|
1149
|
+
agent_id: string;
|
|
1150
|
+
cwd?: string;
|
|
1151
|
+
label?: string;
|
|
1152
|
+
model?: string;
|
|
1153
|
+
approvalPolicy?: "approve-all" | "approve-reads" | "deny-all";
|
|
1154
|
+
}
|
|
1155
|
+
interface AcpSession {
|
|
1156
|
+
session_key: string;
|
|
1157
|
+
agent_id: string;
|
|
1158
|
+
state: "initializing" | "ready" | "stale" | "closed";
|
|
1159
|
+
backend_id: string;
|
|
1160
|
+
created_at: string;
|
|
1161
|
+
}
|
|
1162
|
+
interface AcpSessionStatus extends AcpSession {
|
|
1163
|
+
runtime_options: AcpRuntimeOptionPatch;
|
|
1164
|
+
last_activity_at: string | null;
|
|
1165
|
+
last_error?: string;
|
|
1166
|
+
}
|
|
1167
|
+
interface AcpRuntimeOptionPatch {
|
|
1168
|
+
model?: string;
|
|
1169
|
+
cwd?: string;
|
|
1170
|
+
timeoutSeconds?: number;
|
|
1171
|
+
runtimeMode?: string;
|
|
1172
|
+
approvalPolicy?: "approve-all" | "approve-reads" | "deny-all";
|
|
1173
|
+
extras?: Record<string, string>;
|
|
1174
|
+
}
|
|
1175
|
+
interface AcpAttachment {
|
|
1176
|
+
contentString: string;
|
|
1177
|
+
mime: string;
|
|
1178
|
+
}
|
|
1179
|
+
interface AcpChatResponse {
|
|
1180
|
+
text: string;
|
|
1181
|
+
stop_reason?: string;
|
|
1182
|
+
}
|
|
1183
|
+
interface AcpStreamEvent {
|
|
1184
|
+
type: "text_delta" | "status" | "tool_call" | "permission_request" | "done" | "error" | "close";
|
|
1185
|
+
data: Record<string, unknown>;
|
|
1186
|
+
}
|
|
1187
|
+
interface AcpPermissionDecision {
|
|
1188
|
+
requestId: string;
|
|
1189
|
+
optionId: string;
|
|
1190
|
+
outcome?: string;
|
|
1191
|
+
}
|
|
1192
|
+
declare class AcpAgentModule {
|
|
1193
|
+
private httpClient;
|
|
1194
|
+
constructor(httpClient: HttpClient);
|
|
1195
|
+
/** List available CLI agents. Pass includeModels to get model lists per agent. */
|
|
1196
|
+
listAgents(opts?: {
|
|
1197
|
+
includeModels?: boolean;
|
|
1198
|
+
}): Promise<AcpAgentInfo[]>;
|
|
1199
|
+
/** Create and initialize a new ACP session. Spawns the CLI agent process. */
|
|
1200
|
+
createSession(options: AcpSessionOptions): Promise<AcpSession>;
|
|
1201
|
+
/** Get session status and runtime options. */
|
|
1202
|
+
getSession(sessionKey: string): Promise<AcpSessionStatus>;
|
|
1203
|
+
/** List active ACP sessions owned by this app. */
|
|
1204
|
+
listSessions(): Promise<AcpSessionStatus[]>;
|
|
1205
|
+
/** Update runtime options (applied on next turn). */
|
|
1206
|
+
patchSession(sessionKey: string, patch: AcpRuntimeOptionPatch): Promise<void>;
|
|
1207
|
+
/** Close session and stop the agent process. */
|
|
1208
|
+
closeSession(sessionKey: string, reason?: string): Promise<void>;
|
|
1209
|
+
/**
|
|
1210
|
+
* Synchronous turn — waits for completion, returns full response.
|
|
1211
|
+
* Requires approvalPolicy set on the session (via create or patchSession).
|
|
1212
|
+
*/
|
|
1213
|
+
chat(sessionKey: string, message: string, attachments?: AcpAttachment[]): Promise<AcpChatResponse>;
|
|
1214
|
+
/**
|
|
1215
|
+
* Streaming turn via SSE. Yields events as they arrive.
|
|
1216
|
+
*
|
|
1217
|
+
* Uses named SSE events (event: + data: lines). The event type comes
|
|
1218
|
+
* from the `event:` line, not from inside the JSON payload.
|
|
1219
|
+
*
|
|
1220
|
+
* @example
|
|
1221
|
+
* ```typescript
|
|
1222
|
+
* for await (const event of sdk.acpAgent.streamChat(key, 'Explain this')) {
|
|
1223
|
+
* if (event.type === 'text_delta') console.log(event.data.text);
|
|
1224
|
+
* if (event.type === 'permission_request') {
|
|
1225
|
+
* await sdk.acpAgent.resolvePermission(key, {
|
|
1226
|
+
* requestId: event.data.requestId as string,
|
|
1227
|
+
* optionId: 'allow_once',
|
|
1228
|
+
* });
|
|
1229
|
+
* }
|
|
1230
|
+
* }
|
|
1231
|
+
* ```
|
|
1232
|
+
*/
|
|
1233
|
+
streamChat(sessionKey: string, message: string, attachments?: AcpAttachment[]): AsyncIterableIterator<AcpStreamEvent>;
|
|
1234
|
+
/** Cancel the active turn on a session. */
|
|
1235
|
+
cancelTurn(sessionKey: string, reason?: string): Promise<void>;
|
|
1236
|
+
/** Resolve a pending permission request (call while SSE stream is active). */
|
|
1237
|
+
resolvePermission(sessionKey: string, decision: AcpPermissionDecision): Promise<{
|
|
1238
|
+
resolved: boolean;
|
|
1239
|
+
reason?: string;
|
|
1240
|
+
}>;
|
|
1241
|
+
/** Convenience: create session + first sync chat in one call. */
|
|
1242
|
+
startChat(message: string, options: AcpSessionOptions): Promise<{
|
|
1243
|
+
session: AcpSession;
|
|
1244
|
+
response: AcpChatResponse;
|
|
1245
|
+
}>;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1120
1248
|
/**
|
|
1121
1249
|
* MCP Module - Interact with MCP servers via RealtimeX SDK
|
|
1122
1250
|
*/
|
|
@@ -1847,6 +1975,7 @@ declare class RealtimeXSDK {
|
|
|
1847
1975
|
tts: TTSModule;
|
|
1848
1976
|
stt: STTModule;
|
|
1849
1977
|
agent: AgentModule;
|
|
1978
|
+
acpAgent: AcpAgentModule;
|
|
1850
1979
|
mcp: MCPModule;
|
|
1851
1980
|
contract: ContractModule;
|
|
1852
1981
|
contractRuntime: ContractRuntime;
|
|
@@ -1886,4 +2015,4 @@ declare class RealtimeXSDK {
|
|
|
1886
2015
|
getAppDataDir(): Promise<string>;
|
|
1887
2016
|
}
|
|
1888
2017
|
|
|
1889
|
-
export { type ACPAdapterContext, type ACPAdapterTelemetryEvent, type ACPAdapterTelemetrySink, ACPContractAdapter, type ACPContractAdapterOptions, type ACPContractRuntime, ACPEventMapper, type ACPExecutionReference, type ACPNotifier, ACPPermissionBridge, type ACPSessionToolUpdate, type ACPSessionUpdateParams, ACPTelemetry, type ACPTextContent, type ACPToolInvocation, type ACPToolKind, type ACPToolStatus, ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, AuthModule, type AuthProvider, type AuthTokenResponse, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type CanonicalToolDefinition, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, ClaudeToolAdapter, type ClaudeToolCall, type ClaudeToolDefinition, type ClaudeToolResult, CodexToolAdapter, type CodexToolCall, type CodexToolDefinition, type CodexToolResult, ContractCache, type ContractCallbackMetadata, type ContractCallbackRules, type ContractCapability, type ContractCapabilityTrigger, ContractClient, type ContractClientOptions, type ContractDiscoveryResponse, ContractError, type ContractEventType, ContractHttpClient, type ContractHttpClientConfig, type ContractInvokePayload, ContractModule, ContractRuntime, type ContractRuntimeInterface, type ContractRuntimeOptions, type ContractSignInput, type ContractStrictness, ContractValidationError, type DatabaseConfig, DatabaseModule, type EmbedOptions, type EmbedResponse, type ExecutionContext, type ExecutionResult, type GeminiFunctionDeclaration, GeminiToolAdapter, type GeminiToolCall, type GeminiToolResult, type GetToolsInput, type HostToolAdapter, type IngestExecutionEventInput, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LegacyLocalAppContractShape, type LifecycleEventType, type LocalAppCapabilitiesResponse, type LocalAppCapabilityDetailResponse, type LocalAppCapabilitySearchResponse, type LocalAppContractDefinition, type LocalAppContractResponse, type LocalAppContractV1, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, type PermissionOption, PermissionRequiredError, PortModule, type ProjectToolsInput, type Provider, type ProviderKind, type ProvidersResponse, RealtimeXSDK, RetryPolicy, type RetryPolicyOptions, type RuntimeExecutionEvent, RuntimeTransportError, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, ScopeDeniedError, ScopeGuard, StaticAuthProvider, type StaticAuthProviderOptions, type StreamChunk, type StreamChunkEvent, type SyncTokenResponse, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type ToolCall, ToolNotFoundError, ToolProjector, ToolValidationError, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace, buildContractIdempotencyKey, buildContractSignatureMessage, canonicalEventToLegacyAction, createContractEventId, hashContractPayload, normalizeAttemptId, normalizeContractEvent, normalizeLocalAppContractV1, normalizeSchema, parseAttemptRunId, signContractEvent, toStableToolName };
|
|
2018
|
+
export { type ACPAdapterContext, type ACPAdapterTelemetryEvent, type ACPAdapterTelemetrySink, ACPContractAdapter, type ACPContractAdapterOptions, type ACPContractRuntime, ACPEventMapper, type ACPExecutionReference, type ACPNotifier, ACPPermissionBridge, type ACPSessionToolUpdate, type ACPSessionUpdateParams, ACPTelemetry, type ACPTextContent, type ACPToolInvocation, type ACPToolKind, type ACPToolStatus, type AcpAgentInfo, AcpAgentModule, type AcpAttachment, type AcpChatResponse, type AcpPermissionDecision, type AcpRuntimeOptionPatch, type AcpSession, type AcpSessionOptions, type AcpSessionStatus, type AcpStreamEvent, ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, AuthModule, type AuthProvider, type AuthTokenResponse, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type CanonicalToolDefinition, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, ClaudeToolAdapter, type ClaudeToolCall, type ClaudeToolDefinition, type ClaudeToolResult, CodexToolAdapter, type CodexToolCall, type CodexToolDefinition, type CodexToolResult, ContractCache, type ContractCallbackMetadata, type ContractCallbackRules, type ContractCapability, type ContractCapabilityTrigger, ContractClient, type ContractClientOptions, type ContractDiscoveryResponse, ContractError, type ContractEventType, ContractHttpClient, type ContractHttpClientConfig, type ContractInvokePayload, ContractModule, ContractRuntime, type ContractRuntimeInterface, type ContractRuntimeOptions, type ContractSignInput, type ContractStrictness, ContractValidationError, type DatabaseConfig, DatabaseModule, type EmbedOptions, type EmbedResponse, type ExecutionContext, type ExecutionResult, type GeminiFunctionDeclaration, GeminiToolAdapter, type GeminiToolCall, type GeminiToolResult, type GetToolsInput, type HostToolAdapter, type IngestExecutionEventInput, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LegacyLocalAppContractShape, type LifecycleEventType, type LocalAppCapabilitiesResponse, type LocalAppCapabilityDetailResponse, type LocalAppCapabilitySearchResponse, type LocalAppContractDefinition, type LocalAppContractResponse, type LocalAppContractV1, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, type PermissionOption, PermissionRequiredError, PortModule, type ProjectToolsInput, type Provider, type ProviderKind, type ProvidersResponse, RealtimeXSDK, RetryPolicy, type RetryPolicyOptions, type RuntimeExecutionEvent, RuntimeTransportError, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, ScopeDeniedError, ScopeGuard, StaticAuthProvider, type StaticAuthProviderOptions, type StreamChunk, type StreamChunkEvent, type SyncTokenResponse, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type ToolCall, ToolNotFoundError, ToolProjector, ToolValidationError, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace, buildContractIdempotencyKey, buildContractSignatureMessage, canonicalEventToLegacyAction, createContractEventId, hashContractPayload, normalizeAttemptId, normalizeContractEvent, normalizeLocalAppContractV1, normalizeSchema, parseAttemptRunId, signContractEvent, toStableToolName };
|
package/dist/index.d.ts
CHANGED
|
@@ -1117,6 +1117,134 @@ declare class AgentModule {
|
|
|
1117
1117
|
}>;
|
|
1118
1118
|
}
|
|
1119
1119
|
|
|
1120
|
+
/**
|
|
1121
|
+
* ACP Agent Module — CLI-based agent sessions via ACP bridge
|
|
1122
|
+
*
|
|
1123
|
+
* Provides session lifecycle, sync/streaming chat, permission resolution,
|
|
1124
|
+
* and turn control for CLI agents (Claude, Gemini, Codex, etc.).
|
|
1125
|
+
*
|
|
1126
|
+
* Unlike AgentModule (LLM API-based), ACP agents spawn CLI processes
|
|
1127
|
+
* and can execute commands, read/write files, and interact with tools.
|
|
1128
|
+
*/
|
|
1129
|
+
|
|
1130
|
+
interface AcpAgentInfo {
|
|
1131
|
+
id: string;
|
|
1132
|
+
label: string;
|
|
1133
|
+
handles: string[];
|
|
1134
|
+
installed: boolean;
|
|
1135
|
+
authReady: boolean;
|
|
1136
|
+
version?: string | null;
|
|
1137
|
+
status: "installed" | "not_installed";
|
|
1138
|
+
/** Present when listAgents({ includeModels: true }). */
|
|
1139
|
+
models?: Array<{
|
|
1140
|
+
id: string;
|
|
1141
|
+
name?: string;
|
|
1142
|
+
}>;
|
|
1143
|
+
/** "provider_api" | "fallback" — how models were resolved. */
|
|
1144
|
+
source?: string | null;
|
|
1145
|
+
/** Non-null if model fetch failed and fell back. */
|
|
1146
|
+
error?: string | null;
|
|
1147
|
+
}
|
|
1148
|
+
interface AcpSessionOptions {
|
|
1149
|
+
agent_id: string;
|
|
1150
|
+
cwd?: string;
|
|
1151
|
+
label?: string;
|
|
1152
|
+
model?: string;
|
|
1153
|
+
approvalPolicy?: "approve-all" | "approve-reads" | "deny-all";
|
|
1154
|
+
}
|
|
1155
|
+
interface AcpSession {
|
|
1156
|
+
session_key: string;
|
|
1157
|
+
agent_id: string;
|
|
1158
|
+
state: "initializing" | "ready" | "stale" | "closed";
|
|
1159
|
+
backend_id: string;
|
|
1160
|
+
created_at: string;
|
|
1161
|
+
}
|
|
1162
|
+
interface AcpSessionStatus extends AcpSession {
|
|
1163
|
+
runtime_options: AcpRuntimeOptionPatch;
|
|
1164
|
+
last_activity_at: string | null;
|
|
1165
|
+
last_error?: string;
|
|
1166
|
+
}
|
|
1167
|
+
interface AcpRuntimeOptionPatch {
|
|
1168
|
+
model?: string;
|
|
1169
|
+
cwd?: string;
|
|
1170
|
+
timeoutSeconds?: number;
|
|
1171
|
+
runtimeMode?: string;
|
|
1172
|
+
approvalPolicy?: "approve-all" | "approve-reads" | "deny-all";
|
|
1173
|
+
extras?: Record<string, string>;
|
|
1174
|
+
}
|
|
1175
|
+
interface AcpAttachment {
|
|
1176
|
+
contentString: string;
|
|
1177
|
+
mime: string;
|
|
1178
|
+
}
|
|
1179
|
+
interface AcpChatResponse {
|
|
1180
|
+
text: string;
|
|
1181
|
+
stop_reason?: string;
|
|
1182
|
+
}
|
|
1183
|
+
interface AcpStreamEvent {
|
|
1184
|
+
type: "text_delta" | "status" | "tool_call" | "permission_request" | "done" | "error" | "close";
|
|
1185
|
+
data: Record<string, unknown>;
|
|
1186
|
+
}
|
|
1187
|
+
interface AcpPermissionDecision {
|
|
1188
|
+
requestId: string;
|
|
1189
|
+
optionId: string;
|
|
1190
|
+
outcome?: string;
|
|
1191
|
+
}
|
|
1192
|
+
declare class AcpAgentModule {
|
|
1193
|
+
private httpClient;
|
|
1194
|
+
constructor(httpClient: HttpClient);
|
|
1195
|
+
/** List available CLI agents. Pass includeModels to get model lists per agent. */
|
|
1196
|
+
listAgents(opts?: {
|
|
1197
|
+
includeModels?: boolean;
|
|
1198
|
+
}): Promise<AcpAgentInfo[]>;
|
|
1199
|
+
/** Create and initialize a new ACP session. Spawns the CLI agent process. */
|
|
1200
|
+
createSession(options: AcpSessionOptions): Promise<AcpSession>;
|
|
1201
|
+
/** Get session status and runtime options. */
|
|
1202
|
+
getSession(sessionKey: string): Promise<AcpSessionStatus>;
|
|
1203
|
+
/** List active ACP sessions owned by this app. */
|
|
1204
|
+
listSessions(): Promise<AcpSessionStatus[]>;
|
|
1205
|
+
/** Update runtime options (applied on next turn). */
|
|
1206
|
+
patchSession(sessionKey: string, patch: AcpRuntimeOptionPatch): Promise<void>;
|
|
1207
|
+
/** Close session and stop the agent process. */
|
|
1208
|
+
closeSession(sessionKey: string, reason?: string): Promise<void>;
|
|
1209
|
+
/**
|
|
1210
|
+
* Synchronous turn — waits for completion, returns full response.
|
|
1211
|
+
* Requires approvalPolicy set on the session (via create or patchSession).
|
|
1212
|
+
*/
|
|
1213
|
+
chat(sessionKey: string, message: string, attachments?: AcpAttachment[]): Promise<AcpChatResponse>;
|
|
1214
|
+
/**
|
|
1215
|
+
* Streaming turn via SSE. Yields events as they arrive.
|
|
1216
|
+
*
|
|
1217
|
+
* Uses named SSE events (event: + data: lines). The event type comes
|
|
1218
|
+
* from the `event:` line, not from inside the JSON payload.
|
|
1219
|
+
*
|
|
1220
|
+
* @example
|
|
1221
|
+
* ```typescript
|
|
1222
|
+
* for await (const event of sdk.acpAgent.streamChat(key, 'Explain this')) {
|
|
1223
|
+
* if (event.type === 'text_delta') console.log(event.data.text);
|
|
1224
|
+
* if (event.type === 'permission_request') {
|
|
1225
|
+
* await sdk.acpAgent.resolvePermission(key, {
|
|
1226
|
+
* requestId: event.data.requestId as string,
|
|
1227
|
+
* optionId: 'allow_once',
|
|
1228
|
+
* });
|
|
1229
|
+
* }
|
|
1230
|
+
* }
|
|
1231
|
+
* ```
|
|
1232
|
+
*/
|
|
1233
|
+
streamChat(sessionKey: string, message: string, attachments?: AcpAttachment[]): AsyncIterableIterator<AcpStreamEvent>;
|
|
1234
|
+
/** Cancel the active turn on a session. */
|
|
1235
|
+
cancelTurn(sessionKey: string, reason?: string): Promise<void>;
|
|
1236
|
+
/** Resolve a pending permission request (call while SSE stream is active). */
|
|
1237
|
+
resolvePermission(sessionKey: string, decision: AcpPermissionDecision): Promise<{
|
|
1238
|
+
resolved: boolean;
|
|
1239
|
+
reason?: string;
|
|
1240
|
+
}>;
|
|
1241
|
+
/** Convenience: create session + first sync chat in one call. */
|
|
1242
|
+
startChat(message: string, options: AcpSessionOptions): Promise<{
|
|
1243
|
+
session: AcpSession;
|
|
1244
|
+
response: AcpChatResponse;
|
|
1245
|
+
}>;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1120
1248
|
/**
|
|
1121
1249
|
* MCP Module - Interact with MCP servers via RealtimeX SDK
|
|
1122
1250
|
*/
|
|
@@ -1847,6 +1975,7 @@ declare class RealtimeXSDK {
|
|
|
1847
1975
|
tts: TTSModule;
|
|
1848
1976
|
stt: STTModule;
|
|
1849
1977
|
agent: AgentModule;
|
|
1978
|
+
acpAgent: AcpAgentModule;
|
|
1850
1979
|
mcp: MCPModule;
|
|
1851
1980
|
contract: ContractModule;
|
|
1852
1981
|
contractRuntime: ContractRuntime;
|
|
@@ -1886,4 +2015,4 @@ declare class RealtimeXSDK {
|
|
|
1886
2015
|
getAppDataDir(): Promise<string>;
|
|
1887
2016
|
}
|
|
1888
2017
|
|
|
1889
|
-
export { type ACPAdapterContext, type ACPAdapterTelemetryEvent, type ACPAdapterTelemetrySink, ACPContractAdapter, type ACPContractAdapterOptions, type ACPContractRuntime, ACPEventMapper, type ACPExecutionReference, type ACPNotifier, ACPPermissionBridge, type ACPSessionToolUpdate, type ACPSessionUpdateParams, ACPTelemetry, type ACPTextContent, type ACPToolInvocation, type ACPToolKind, type ACPToolStatus, ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, AuthModule, type AuthProvider, type AuthTokenResponse, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type CanonicalToolDefinition, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, ClaudeToolAdapter, type ClaudeToolCall, type ClaudeToolDefinition, type ClaudeToolResult, CodexToolAdapter, type CodexToolCall, type CodexToolDefinition, type CodexToolResult, ContractCache, type ContractCallbackMetadata, type ContractCallbackRules, type ContractCapability, type ContractCapabilityTrigger, ContractClient, type ContractClientOptions, type ContractDiscoveryResponse, ContractError, type ContractEventType, ContractHttpClient, type ContractHttpClientConfig, type ContractInvokePayload, ContractModule, ContractRuntime, type ContractRuntimeInterface, type ContractRuntimeOptions, type ContractSignInput, type ContractStrictness, ContractValidationError, type DatabaseConfig, DatabaseModule, type EmbedOptions, type EmbedResponse, type ExecutionContext, type ExecutionResult, type GeminiFunctionDeclaration, GeminiToolAdapter, type GeminiToolCall, type GeminiToolResult, type GetToolsInput, type HostToolAdapter, type IngestExecutionEventInput, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LegacyLocalAppContractShape, type LifecycleEventType, type LocalAppCapabilitiesResponse, type LocalAppCapabilityDetailResponse, type LocalAppCapabilitySearchResponse, type LocalAppContractDefinition, type LocalAppContractResponse, type LocalAppContractV1, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, type PermissionOption, PermissionRequiredError, PortModule, type ProjectToolsInput, type Provider, type ProviderKind, type ProvidersResponse, RealtimeXSDK, RetryPolicy, type RetryPolicyOptions, type RuntimeExecutionEvent, RuntimeTransportError, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, ScopeDeniedError, ScopeGuard, StaticAuthProvider, type StaticAuthProviderOptions, type StreamChunk, type StreamChunkEvent, type SyncTokenResponse, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type ToolCall, ToolNotFoundError, ToolProjector, ToolValidationError, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace, buildContractIdempotencyKey, buildContractSignatureMessage, canonicalEventToLegacyAction, createContractEventId, hashContractPayload, normalizeAttemptId, normalizeContractEvent, normalizeLocalAppContractV1, normalizeSchema, parseAttemptRunId, signContractEvent, toStableToolName };
|
|
2018
|
+
export { type ACPAdapterContext, type ACPAdapterTelemetryEvent, type ACPAdapterTelemetrySink, ACPContractAdapter, type ACPContractAdapterOptions, type ACPContractRuntime, ACPEventMapper, type ACPExecutionReference, type ACPNotifier, ACPPermissionBridge, type ACPSessionToolUpdate, type ACPSessionUpdateParams, ACPTelemetry, type ACPTextContent, type ACPToolInvocation, type ACPToolKind, type ACPToolStatus, type AcpAgentInfo, AcpAgentModule, type AcpAttachment, type AcpChatResponse, type AcpPermissionDecision, type AcpRuntimeOptionPatch, type AcpSession, type AcpSessionOptions, type AcpSessionStatus, type AcpStreamEvent, ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, AuthModule, type AuthProvider, type AuthTokenResponse, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type CanonicalToolDefinition, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, ClaudeToolAdapter, type ClaudeToolCall, type ClaudeToolDefinition, type ClaudeToolResult, CodexToolAdapter, type CodexToolCall, type CodexToolDefinition, type CodexToolResult, ContractCache, type ContractCallbackMetadata, type ContractCallbackRules, type ContractCapability, type ContractCapabilityTrigger, ContractClient, type ContractClientOptions, type ContractDiscoveryResponse, ContractError, type ContractEventType, ContractHttpClient, type ContractHttpClientConfig, type ContractInvokePayload, ContractModule, ContractRuntime, type ContractRuntimeInterface, type ContractRuntimeOptions, type ContractSignInput, type ContractStrictness, ContractValidationError, type DatabaseConfig, DatabaseModule, type EmbedOptions, type EmbedResponse, type ExecutionContext, type ExecutionResult, type GeminiFunctionDeclaration, GeminiToolAdapter, type GeminiToolCall, type GeminiToolResult, type GetToolsInput, type HostToolAdapter, type IngestExecutionEventInput, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LegacyLocalAppContractShape, type LifecycleEventType, type LocalAppCapabilitiesResponse, type LocalAppCapabilityDetailResponse, type LocalAppCapabilitySearchResponse, type LocalAppContractDefinition, type LocalAppContractResponse, type LocalAppContractV1, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, type PermissionOption, PermissionRequiredError, PortModule, type ProjectToolsInput, type Provider, type ProviderKind, type ProvidersResponse, RealtimeXSDK, RetryPolicy, type RetryPolicyOptions, type RuntimeExecutionEvent, RuntimeTransportError, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, ScopeDeniedError, ScopeGuard, StaticAuthProvider, type StaticAuthProviderOptions, type StreamChunk, type StreamChunkEvent, type SyncTokenResponse, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type ToolCall, ToolNotFoundError, ToolProjector, ToolValidationError, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace, buildContractIdempotencyKey, buildContractSignatureMessage, canonicalEventToLegacyAction, createContractEventId, hashContractPayload, normalizeAttemptId, normalizeContractEvent, normalizeLocalAppContractV1, normalizeSchema, parseAttemptRunId, signContractEvent, toStableToolName };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
ACPEventMapper: () => ACPEventMapper,
|
|
35
35
|
ACPPermissionBridge: () => ACPPermissionBridge,
|
|
36
36
|
ACPTelemetry: () => ACPTelemetry,
|
|
37
|
+
AcpAgentModule: () => AcpAgentModule,
|
|
37
38
|
ActivitiesModule: () => ActivitiesModule,
|
|
38
39
|
AgentModule: () => AgentModule,
|
|
39
40
|
ApiModule: () => ApiModule,
|
|
@@ -1783,6 +1784,193 @@ var AgentModule = class {
|
|
|
1783
1784
|
}
|
|
1784
1785
|
};
|
|
1785
1786
|
|
|
1787
|
+
// src/modules/acpAgent.ts
|
|
1788
|
+
function encodeSessionKey(sessionKey) {
|
|
1789
|
+
return encodeURIComponent(sessionKey);
|
|
1790
|
+
}
|
|
1791
|
+
async function parseJsonResponse(response, fallbackError) {
|
|
1792
|
+
const data = await response.json();
|
|
1793
|
+
if (!response.ok) throw new Error(data.error || fallbackError);
|
|
1794
|
+
return data;
|
|
1795
|
+
}
|
|
1796
|
+
var AcpAgentModule = class {
|
|
1797
|
+
constructor(httpClient) {
|
|
1798
|
+
this.httpClient = httpClient;
|
|
1799
|
+
}
|
|
1800
|
+
/** List available CLI agents. Pass includeModels to get model lists per agent. */
|
|
1801
|
+
async listAgents(opts) {
|
|
1802
|
+
const qs = opts?.includeModels ? "?includeModels=true" : "";
|
|
1803
|
+
const response = await this.httpClient.fetch(`/sdk/acp/agents${qs}`);
|
|
1804
|
+
const data = await parseJsonResponse(
|
|
1805
|
+
response,
|
|
1806
|
+
"Failed to list agents"
|
|
1807
|
+
);
|
|
1808
|
+
return data.agents;
|
|
1809
|
+
}
|
|
1810
|
+
/** Create and initialize a new ACP session. Spawns the CLI agent process. */
|
|
1811
|
+
async createSession(options) {
|
|
1812
|
+
const response = await this.httpClient.fetch("/sdk/acp/session", {
|
|
1813
|
+
method: "POST",
|
|
1814
|
+
body: JSON.stringify(options)
|
|
1815
|
+
});
|
|
1816
|
+
const data = await parseJsonResponse(
|
|
1817
|
+
response,
|
|
1818
|
+
"Failed to create session"
|
|
1819
|
+
);
|
|
1820
|
+
return data.session;
|
|
1821
|
+
}
|
|
1822
|
+
/** Get session status and runtime options. */
|
|
1823
|
+
async getSession(sessionKey) {
|
|
1824
|
+
const response = await this.httpClient.fetch(
|
|
1825
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}`
|
|
1826
|
+
);
|
|
1827
|
+
const data = await parseJsonResponse(
|
|
1828
|
+
response,
|
|
1829
|
+
"Failed to get session"
|
|
1830
|
+
);
|
|
1831
|
+
return data.session;
|
|
1832
|
+
}
|
|
1833
|
+
/** List active ACP sessions owned by this app. */
|
|
1834
|
+
async listSessions() {
|
|
1835
|
+
const response = await this.httpClient.fetch("/sdk/acp/sessions");
|
|
1836
|
+
const data = await parseJsonResponse(
|
|
1837
|
+
response,
|
|
1838
|
+
"Failed to list sessions"
|
|
1839
|
+
);
|
|
1840
|
+
return data.sessions;
|
|
1841
|
+
}
|
|
1842
|
+
/** Update runtime options (applied on next turn). */
|
|
1843
|
+
async patchSession(sessionKey, patch) {
|
|
1844
|
+
const response = await this.httpClient.fetch(
|
|
1845
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}`,
|
|
1846
|
+
{ method: "PATCH", body: JSON.stringify(patch) }
|
|
1847
|
+
);
|
|
1848
|
+
await parseJsonResponse(response, "Failed to update session");
|
|
1849
|
+
}
|
|
1850
|
+
/** Close session and stop the agent process. */
|
|
1851
|
+
async closeSession(sessionKey, reason) {
|
|
1852
|
+
const response = await this.httpClient.fetch(
|
|
1853
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}`,
|
|
1854
|
+
{
|
|
1855
|
+
method: "DELETE",
|
|
1856
|
+
body: reason ? JSON.stringify({ reason }) : void 0
|
|
1857
|
+
}
|
|
1858
|
+
);
|
|
1859
|
+
await parseJsonResponse(response, "Failed to close session");
|
|
1860
|
+
}
|
|
1861
|
+
/**
|
|
1862
|
+
* Synchronous turn — waits for completion, returns full response.
|
|
1863
|
+
* Requires approvalPolicy set on the session (via create or patchSession).
|
|
1864
|
+
*/
|
|
1865
|
+
async chat(sessionKey, message, attachments) {
|
|
1866
|
+
const body = { message };
|
|
1867
|
+
if (attachments?.length) body.attachments = attachments;
|
|
1868
|
+
const response = await this.httpClient.fetch(
|
|
1869
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}/chat`,
|
|
1870
|
+
{ method: "POST", body: JSON.stringify(body) }
|
|
1871
|
+
);
|
|
1872
|
+
const data = await parseJsonResponse(
|
|
1873
|
+
response,
|
|
1874
|
+
"Chat request failed"
|
|
1875
|
+
);
|
|
1876
|
+
return data.response;
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Streaming turn via SSE. Yields events as they arrive.
|
|
1880
|
+
*
|
|
1881
|
+
* Uses named SSE events (event: + data: lines). The event type comes
|
|
1882
|
+
* from the `event:` line, not from inside the JSON payload.
|
|
1883
|
+
*
|
|
1884
|
+
* @example
|
|
1885
|
+
* ```typescript
|
|
1886
|
+
* for await (const event of sdk.acpAgent.streamChat(key, 'Explain this')) {
|
|
1887
|
+
* if (event.type === 'text_delta') console.log(event.data.text);
|
|
1888
|
+
* if (event.type === 'permission_request') {
|
|
1889
|
+
* await sdk.acpAgent.resolvePermission(key, {
|
|
1890
|
+
* requestId: event.data.requestId as string,
|
|
1891
|
+
* optionId: 'allow_once',
|
|
1892
|
+
* });
|
|
1893
|
+
* }
|
|
1894
|
+
* }
|
|
1895
|
+
* ```
|
|
1896
|
+
*/
|
|
1897
|
+
async *streamChat(sessionKey, message, attachments) {
|
|
1898
|
+
const body = { message };
|
|
1899
|
+
if (attachments?.length) body.attachments = attachments;
|
|
1900
|
+
const response = await this.httpClient.fetch(
|
|
1901
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}/chat/stream`,
|
|
1902
|
+
{ method: "POST", body: JSON.stringify(body) }
|
|
1903
|
+
);
|
|
1904
|
+
if (!response.ok) {
|
|
1905
|
+
const data = await response.json();
|
|
1906
|
+
throw new Error(data.error || "Stream request failed");
|
|
1907
|
+
}
|
|
1908
|
+
if (!response.body) {
|
|
1909
|
+
throw new Error("Response body is null");
|
|
1910
|
+
}
|
|
1911
|
+
yield* parseNamedSSEStream(response.body);
|
|
1912
|
+
}
|
|
1913
|
+
/** Cancel the active turn on a session. */
|
|
1914
|
+
async cancelTurn(sessionKey, reason) {
|
|
1915
|
+
const response = await this.httpClient.fetch(
|
|
1916
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}/cancel`,
|
|
1917
|
+
{
|
|
1918
|
+
method: "POST",
|
|
1919
|
+
body: reason ? JSON.stringify({ reason }) : void 0
|
|
1920
|
+
}
|
|
1921
|
+
);
|
|
1922
|
+
await parseJsonResponse(response, "Failed to cancel turn");
|
|
1923
|
+
}
|
|
1924
|
+
/** Resolve a pending permission request (call while SSE stream is active). */
|
|
1925
|
+
async resolvePermission(sessionKey, decision) {
|
|
1926
|
+
const response = await this.httpClient.fetch(
|
|
1927
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}/permission`,
|
|
1928
|
+
{ method: "POST", body: JSON.stringify(decision) }
|
|
1929
|
+
);
|
|
1930
|
+
return parseJsonResponse(response, "Failed to resolve permission");
|
|
1931
|
+
}
|
|
1932
|
+
/** Convenience: create session + first sync chat in one call. */
|
|
1933
|
+
async startChat(message, options) {
|
|
1934
|
+
const session = await this.createSession(options);
|
|
1935
|
+
const chatResponse = await this.chat(session.session_key, message);
|
|
1936
|
+
return { session, response: chatResponse };
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
async function* parseNamedSSEStream(body) {
|
|
1940
|
+
const reader = body.getReader();
|
|
1941
|
+
const decoder = new TextDecoder();
|
|
1942
|
+
let buffer = "";
|
|
1943
|
+
let currentEvent = "";
|
|
1944
|
+
try {
|
|
1945
|
+
while (true) {
|
|
1946
|
+
const { done, value } = await reader.read();
|
|
1947
|
+
if (done) break;
|
|
1948
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1949
|
+
const lines = buffer.split("\n");
|
|
1950
|
+
buffer = lines.pop() || "";
|
|
1951
|
+
for (const line of lines) {
|
|
1952
|
+
if (line.startsWith("event: ")) {
|
|
1953
|
+
currentEvent = line.slice(7).trim();
|
|
1954
|
+
} else if (line.startsWith("data: ")) {
|
|
1955
|
+
const jsonStr = line.slice(6);
|
|
1956
|
+
const eventType = currentEvent || void 0;
|
|
1957
|
+
currentEvent = "";
|
|
1958
|
+
if (!eventType) continue;
|
|
1959
|
+
try {
|
|
1960
|
+
const data = JSON.parse(jsonStr);
|
|
1961
|
+
yield { type: eventType, data };
|
|
1962
|
+
} catch {
|
|
1963
|
+
}
|
|
1964
|
+
} else if (line === "") {
|
|
1965
|
+
currentEvent = "";
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
} finally {
|
|
1970
|
+
reader.releaseLock();
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1786
1974
|
// src/modules/mcp.ts
|
|
1787
1975
|
var MCPModule = class extends ApiModule {
|
|
1788
1976
|
constructor(realtimexUrl, appId, appName, apiKey) {
|
|
@@ -3506,6 +3694,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
3506
3694
|
this.tts = new TTSModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
3507
3695
|
this.stt = new STTModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
3508
3696
|
this.agent = new AgentModule(this.httpClient);
|
|
3697
|
+
this.acpAgent = new AcpAgentModule(this.httpClient);
|
|
3509
3698
|
this.mcp = new MCPModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
3510
3699
|
this.contract = new ContractModule(this.realtimexUrl, this.appName, this.appId, this.apiKey);
|
|
3511
3700
|
this.contractRuntime = new ContractRuntime({
|
|
@@ -3622,6 +3811,7 @@ var RealtimeXSDK = _RealtimeXSDK;
|
|
|
3622
3811
|
ACPEventMapper,
|
|
3623
3812
|
ACPPermissionBridge,
|
|
3624
3813
|
ACPTelemetry,
|
|
3814
|
+
AcpAgentModule,
|
|
3625
3815
|
ActivitiesModule,
|
|
3626
3816
|
AgentModule,
|
|
3627
3817
|
ApiModule,
|
package/dist/index.mjs
CHANGED
|
@@ -1691,6 +1691,193 @@ var AgentModule = class {
|
|
|
1691
1691
|
}
|
|
1692
1692
|
};
|
|
1693
1693
|
|
|
1694
|
+
// src/modules/acpAgent.ts
|
|
1695
|
+
function encodeSessionKey(sessionKey) {
|
|
1696
|
+
return encodeURIComponent(sessionKey);
|
|
1697
|
+
}
|
|
1698
|
+
async function parseJsonResponse(response, fallbackError) {
|
|
1699
|
+
const data = await response.json();
|
|
1700
|
+
if (!response.ok) throw new Error(data.error || fallbackError);
|
|
1701
|
+
return data;
|
|
1702
|
+
}
|
|
1703
|
+
var AcpAgentModule = class {
|
|
1704
|
+
constructor(httpClient) {
|
|
1705
|
+
this.httpClient = httpClient;
|
|
1706
|
+
}
|
|
1707
|
+
/** List available CLI agents. Pass includeModels to get model lists per agent. */
|
|
1708
|
+
async listAgents(opts) {
|
|
1709
|
+
const qs = opts?.includeModels ? "?includeModels=true" : "";
|
|
1710
|
+
const response = await this.httpClient.fetch(`/sdk/acp/agents${qs}`);
|
|
1711
|
+
const data = await parseJsonResponse(
|
|
1712
|
+
response,
|
|
1713
|
+
"Failed to list agents"
|
|
1714
|
+
);
|
|
1715
|
+
return data.agents;
|
|
1716
|
+
}
|
|
1717
|
+
/** Create and initialize a new ACP session. Spawns the CLI agent process. */
|
|
1718
|
+
async createSession(options) {
|
|
1719
|
+
const response = await this.httpClient.fetch("/sdk/acp/session", {
|
|
1720
|
+
method: "POST",
|
|
1721
|
+
body: JSON.stringify(options)
|
|
1722
|
+
});
|
|
1723
|
+
const data = await parseJsonResponse(
|
|
1724
|
+
response,
|
|
1725
|
+
"Failed to create session"
|
|
1726
|
+
);
|
|
1727
|
+
return data.session;
|
|
1728
|
+
}
|
|
1729
|
+
/** Get session status and runtime options. */
|
|
1730
|
+
async getSession(sessionKey) {
|
|
1731
|
+
const response = await this.httpClient.fetch(
|
|
1732
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}`
|
|
1733
|
+
);
|
|
1734
|
+
const data = await parseJsonResponse(
|
|
1735
|
+
response,
|
|
1736
|
+
"Failed to get session"
|
|
1737
|
+
);
|
|
1738
|
+
return data.session;
|
|
1739
|
+
}
|
|
1740
|
+
/** List active ACP sessions owned by this app. */
|
|
1741
|
+
async listSessions() {
|
|
1742
|
+
const response = await this.httpClient.fetch("/sdk/acp/sessions");
|
|
1743
|
+
const data = await parseJsonResponse(
|
|
1744
|
+
response,
|
|
1745
|
+
"Failed to list sessions"
|
|
1746
|
+
);
|
|
1747
|
+
return data.sessions;
|
|
1748
|
+
}
|
|
1749
|
+
/** Update runtime options (applied on next turn). */
|
|
1750
|
+
async patchSession(sessionKey, patch) {
|
|
1751
|
+
const response = await this.httpClient.fetch(
|
|
1752
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}`,
|
|
1753
|
+
{ method: "PATCH", body: JSON.stringify(patch) }
|
|
1754
|
+
);
|
|
1755
|
+
await parseJsonResponse(response, "Failed to update session");
|
|
1756
|
+
}
|
|
1757
|
+
/** Close session and stop the agent process. */
|
|
1758
|
+
async closeSession(sessionKey, reason) {
|
|
1759
|
+
const response = await this.httpClient.fetch(
|
|
1760
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}`,
|
|
1761
|
+
{
|
|
1762
|
+
method: "DELETE",
|
|
1763
|
+
body: reason ? JSON.stringify({ reason }) : void 0
|
|
1764
|
+
}
|
|
1765
|
+
);
|
|
1766
|
+
await parseJsonResponse(response, "Failed to close session");
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Synchronous turn — waits for completion, returns full response.
|
|
1770
|
+
* Requires approvalPolicy set on the session (via create or patchSession).
|
|
1771
|
+
*/
|
|
1772
|
+
async chat(sessionKey, message, attachments) {
|
|
1773
|
+
const body = { message };
|
|
1774
|
+
if (attachments?.length) body.attachments = attachments;
|
|
1775
|
+
const response = await this.httpClient.fetch(
|
|
1776
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}/chat`,
|
|
1777
|
+
{ method: "POST", body: JSON.stringify(body) }
|
|
1778
|
+
);
|
|
1779
|
+
const data = await parseJsonResponse(
|
|
1780
|
+
response,
|
|
1781
|
+
"Chat request failed"
|
|
1782
|
+
);
|
|
1783
|
+
return data.response;
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Streaming turn via SSE. Yields events as they arrive.
|
|
1787
|
+
*
|
|
1788
|
+
* Uses named SSE events (event: + data: lines). The event type comes
|
|
1789
|
+
* from the `event:` line, not from inside the JSON payload.
|
|
1790
|
+
*
|
|
1791
|
+
* @example
|
|
1792
|
+
* ```typescript
|
|
1793
|
+
* for await (const event of sdk.acpAgent.streamChat(key, 'Explain this')) {
|
|
1794
|
+
* if (event.type === 'text_delta') console.log(event.data.text);
|
|
1795
|
+
* if (event.type === 'permission_request') {
|
|
1796
|
+
* await sdk.acpAgent.resolvePermission(key, {
|
|
1797
|
+
* requestId: event.data.requestId as string,
|
|
1798
|
+
* optionId: 'allow_once',
|
|
1799
|
+
* });
|
|
1800
|
+
* }
|
|
1801
|
+
* }
|
|
1802
|
+
* ```
|
|
1803
|
+
*/
|
|
1804
|
+
async *streamChat(sessionKey, message, attachments) {
|
|
1805
|
+
const body = { message };
|
|
1806
|
+
if (attachments?.length) body.attachments = attachments;
|
|
1807
|
+
const response = await this.httpClient.fetch(
|
|
1808
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}/chat/stream`,
|
|
1809
|
+
{ method: "POST", body: JSON.stringify(body) }
|
|
1810
|
+
);
|
|
1811
|
+
if (!response.ok) {
|
|
1812
|
+
const data = await response.json();
|
|
1813
|
+
throw new Error(data.error || "Stream request failed");
|
|
1814
|
+
}
|
|
1815
|
+
if (!response.body) {
|
|
1816
|
+
throw new Error("Response body is null");
|
|
1817
|
+
}
|
|
1818
|
+
yield* parseNamedSSEStream(response.body);
|
|
1819
|
+
}
|
|
1820
|
+
/** Cancel the active turn on a session. */
|
|
1821
|
+
async cancelTurn(sessionKey, reason) {
|
|
1822
|
+
const response = await this.httpClient.fetch(
|
|
1823
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}/cancel`,
|
|
1824
|
+
{
|
|
1825
|
+
method: "POST",
|
|
1826
|
+
body: reason ? JSON.stringify({ reason }) : void 0
|
|
1827
|
+
}
|
|
1828
|
+
);
|
|
1829
|
+
await parseJsonResponse(response, "Failed to cancel turn");
|
|
1830
|
+
}
|
|
1831
|
+
/** Resolve a pending permission request (call while SSE stream is active). */
|
|
1832
|
+
async resolvePermission(sessionKey, decision) {
|
|
1833
|
+
const response = await this.httpClient.fetch(
|
|
1834
|
+
`/sdk/acp/session/${encodeSessionKey(sessionKey)}/permission`,
|
|
1835
|
+
{ method: "POST", body: JSON.stringify(decision) }
|
|
1836
|
+
);
|
|
1837
|
+
return parseJsonResponse(response, "Failed to resolve permission");
|
|
1838
|
+
}
|
|
1839
|
+
/** Convenience: create session + first sync chat in one call. */
|
|
1840
|
+
async startChat(message, options) {
|
|
1841
|
+
const session = await this.createSession(options);
|
|
1842
|
+
const chatResponse = await this.chat(session.session_key, message);
|
|
1843
|
+
return { session, response: chatResponse };
|
|
1844
|
+
}
|
|
1845
|
+
};
|
|
1846
|
+
async function* parseNamedSSEStream(body) {
|
|
1847
|
+
const reader = body.getReader();
|
|
1848
|
+
const decoder = new TextDecoder();
|
|
1849
|
+
let buffer = "";
|
|
1850
|
+
let currentEvent = "";
|
|
1851
|
+
try {
|
|
1852
|
+
while (true) {
|
|
1853
|
+
const { done, value } = await reader.read();
|
|
1854
|
+
if (done) break;
|
|
1855
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1856
|
+
const lines = buffer.split("\n");
|
|
1857
|
+
buffer = lines.pop() || "";
|
|
1858
|
+
for (const line of lines) {
|
|
1859
|
+
if (line.startsWith("event: ")) {
|
|
1860
|
+
currentEvent = line.slice(7).trim();
|
|
1861
|
+
} else if (line.startsWith("data: ")) {
|
|
1862
|
+
const jsonStr = line.slice(6);
|
|
1863
|
+
const eventType = currentEvent || void 0;
|
|
1864
|
+
currentEvent = "";
|
|
1865
|
+
if (!eventType) continue;
|
|
1866
|
+
try {
|
|
1867
|
+
const data = JSON.parse(jsonStr);
|
|
1868
|
+
yield { type: eventType, data };
|
|
1869
|
+
} catch {
|
|
1870
|
+
}
|
|
1871
|
+
} else if (line === "") {
|
|
1872
|
+
currentEvent = "";
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
} finally {
|
|
1877
|
+
reader.releaseLock();
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1694
1881
|
// src/modules/mcp.ts
|
|
1695
1882
|
var MCPModule = class extends ApiModule {
|
|
1696
1883
|
constructor(realtimexUrl, appId, appName, apiKey) {
|
|
@@ -3414,6 +3601,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
3414
3601
|
this.tts = new TTSModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
3415
3602
|
this.stt = new STTModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
3416
3603
|
this.agent = new AgentModule(this.httpClient);
|
|
3604
|
+
this.acpAgent = new AcpAgentModule(this.httpClient);
|
|
3417
3605
|
this.mcp = new MCPModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
3418
3606
|
this.contract = new ContractModule(this.realtimexUrl, this.appName, this.appId, this.apiKey);
|
|
3419
3607
|
this.contractRuntime = new ContractRuntime({
|
|
@@ -3529,6 +3717,7 @@ export {
|
|
|
3529
3717
|
ACPEventMapper,
|
|
3530
3718
|
ACPPermissionBridge,
|
|
3531
3719
|
ACPTelemetry,
|
|
3720
|
+
AcpAgentModule,
|
|
3532
3721
|
ActivitiesModule,
|
|
3533
3722
|
AgentModule,
|
|
3534
3723
|
ApiModule,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realtimex/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "SDK for building Local Apps that integrate with RealtimeX",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
18
18
|
"test": "vitest run",
|
|
19
19
|
"contract:verify": "node ../scripts/verify-contract-compat.mjs",
|
|
20
|
+
"skill:generate": "node ../scripts/generate-skill.mjs",
|
|
21
|
+
"skill:update": "node ../scripts/generate-skill.mjs --force",
|
|
20
22
|
"prepublishOnly": "npm run build"
|
|
21
23
|
},
|
|
22
24
|
"keywords": [
|