@realtimex/sdk 1.3.3 → 1.3.5-rc.1
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/README.md +61 -0
- package/dist/index.d.mts +204 -7
- package/dist/index.d.ts +204 -7
- package/dist/index.js +416 -31
- package/dist/index.mjs +399 -30
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -108,6 +108,67 @@ await sdk.webhook.triggerAgent({
|
|
|
108
108
|
});
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
+
### Contract Discovery
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// Read canonical contract metadata published by Main App
|
|
115
|
+
const contract = await sdk.contract.getLocalAppV1();
|
|
116
|
+
|
|
117
|
+
console.log(contract.version); // local-app-contract/v1
|
|
118
|
+
console.log(contract.supported_events); // task.trigger, task.claimed, ...
|
|
119
|
+
console.log(contract.callback?.signature_header); // x-rtx-contract-signature
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Worker Callback Lifecycle
|
|
123
|
+
|
|
124
|
+
Use this when your worker receives `task_uuid`, `attempt_id`, and callback metadata from RealtimeX task context.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
sdk.task.configureContract({
|
|
128
|
+
callbackSecret: process.env.RTX_CONTRACT_CALLBACK_SECRET,
|
|
129
|
+
signCallbacksByDefault: true,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await sdk.task.claim(taskUuid, {
|
|
133
|
+
callbackUrl,
|
|
134
|
+
machineId,
|
|
135
|
+
attemptId,
|
|
136
|
+
userEmail,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await sdk.task.start(taskUuid, {
|
|
140
|
+
callbackUrl,
|
|
141
|
+
machineId,
|
|
142
|
+
attemptId,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await sdk.task.progress(taskUuid, { percent: 50, message: 'Halfway done' }, {
|
|
146
|
+
callbackUrl,
|
|
147
|
+
machineId,
|
|
148
|
+
attemptId,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
await sdk.task.complete(taskUuid, { summary: 'Done' }, {
|
|
152
|
+
callbackUrl,
|
|
153
|
+
machineId,
|
|
154
|
+
attemptId,
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`TaskModule` auto-populates:
|
|
159
|
+
- `event_id` for idempotency
|
|
160
|
+
- canonical `event` names
|
|
161
|
+
- optional HMAC signature header (`x-rtx-contract-signature`) when signing is enabled
|
|
162
|
+
- legacy `action` alongside canonical `event` for compatibility when posting to callback URLs
|
|
163
|
+
|
|
164
|
+
### Contract Compatibility Check
|
|
165
|
+
|
|
166
|
+
Run the cross-language harness (Main App endpoint + TypeScript SDK + Python SDK):
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
RTX_API_KEY=sk-... RTX_CONTRACT_VERIFY_BASE_URL=http://127.0.0.1:3001 npm run contract:verify
|
|
170
|
+
```
|
|
171
|
+
|
|
111
172
|
### Public APIs
|
|
112
173
|
|
|
113
174
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,10 @@ interface SDKConfig {
|
|
|
10
10
|
};
|
|
11
11
|
defaultPort?: number;
|
|
12
12
|
permissions?: string[];
|
|
13
|
+
contract?: {
|
|
14
|
+
callbackSecret?: string;
|
|
15
|
+
signCallbacksByDefault?: boolean;
|
|
16
|
+
};
|
|
13
17
|
}
|
|
14
18
|
interface Activity {
|
|
15
19
|
id: string;
|
|
@@ -30,15 +34,46 @@ interface TriggerAgentPayload {
|
|
|
30
34
|
workspace_slug?: string;
|
|
31
35
|
thread_slug?: string;
|
|
32
36
|
prompt?: string;
|
|
37
|
+
event_id?: string;
|
|
38
|
+
attempt_id?: string | number;
|
|
33
39
|
}
|
|
34
40
|
interface TriggerAgentResponse {
|
|
35
41
|
success: boolean;
|
|
36
42
|
task_uuid?: string;
|
|
43
|
+
task_id?: string;
|
|
44
|
+
event_id?: string;
|
|
45
|
+
attempt_id?: string;
|
|
46
|
+
event_type?: ContractEventType | string;
|
|
47
|
+
contract_version?: string;
|
|
37
48
|
calendar_event_uuid?: string;
|
|
38
49
|
auto_run?: boolean;
|
|
39
50
|
message?: string;
|
|
40
51
|
error?: string;
|
|
41
52
|
}
|
|
53
|
+
type ContractEventType = 'task.trigger' | 'system.ping' | 'task.claimed' | 'task.started' | 'task.progress' | 'task.completed' | 'task.failed' | 'task.canceled';
|
|
54
|
+
interface ContractCallbackMetadata {
|
|
55
|
+
event_id_header?: string;
|
|
56
|
+
signature_header?: string;
|
|
57
|
+
signature_algorithm?: string;
|
|
58
|
+
signature_message?: string;
|
|
59
|
+
attempt_id_format?: string;
|
|
60
|
+
idempotency?: string;
|
|
61
|
+
}
|
|
62
|
+
interface LocalAppContractDefinition {
|
|
63
|
+
id: string;
|
|
64
|
+
version: string;
|
|
65
|
+
events: Record<string, ContractEventType>;
|
|
66
|
+
supported_events: ContractEventType[];
|
|
67
|
+
supported_legacy_events: string[];
|
|
68
|
+
aliases: Record<string, ContractEventType>;
|
|
69
|
+
status_map: Record<string, string>;
|
|
70
|
+
legacy_action_map: Record<ContractEventType, string>;
|
|
71
|
+
callback?: ContractCallbackMetadata;
|
|
72
|
+
}
|
|
73
|
+
interface LocalAppContractResponse {
|
|
74
|
+
success: boolean;
|
|
75
|
+
contract: LocalAppContractDefinition;
|
|
76
|
+
}
|
|
42
77
|
interface Agent {
|
|
43
78
|
slug: string;
|
|
44
79
|
name: string;
|
|
@@ -60,6 +95,7 @@ interface Thread {
|
|
|
60
95
|
}
|
|
61
96
|
interface TaskRun {
|
|
62
97
|
id: number;
|
|
98
|
+
attempt_id?: string;
|
|
63
99
|
agent_name: string;
|
|
64
100
|
workspace_slug: string;
|
|
65
101
|
thread_slug?: string;
|
|
@@ -300,30 +336,77 @@ declare class ApiModule {
|
|
|
300
336
|
* Task Module - Report task status to RealtimeX
|
|
301
337
|
* Used by external agents/processors to update task status
|
|
302
338
|
*/
|
|
339
|
+
|
|
303
340
|
interface TaskStatusResponse {
|
|
304
341
|
success: boolean;
|
|
305
342
|
task_uuid: string;
|
|
306
343
|
status: string;
|
|
344
|
+
event_id?: string;
|
|
345
|
+
attempt_id?: string;
|
|
346
|
+
event_type?: ContractEventType | string;
|
|
347
|
+
deduplicated?: boolean;
|
|
348
|
+
duplicate?: boolean;
|
|
307
349
|
message?: string;
|
|
308
350
|
}
|
|
351
|
+
interface TaskEventOptions {
|
|
352
|
+
machineId?: string;
|
|
353
|
+
attemptId?: string | number;
|
|
354
|
+
eventId?: string;
|
|
355
|
+
timestamp?: string;
|
|
356
|
+
callbackUrl?: string;
|
|
357
|
+
callbackSecret?: string;
|
|
358
|
+
sign?: boolean;
|
|
359
|
+
userEmail?: string;
|
|
360
|
+
activityId?: string;
|
|
361
|
+
tableName?: string;
|
|
362
|
+
}
|
|
309
363
|
declare class TaskModule {
|
|
310
364
|
private realtimexUrl;
|
|
311
365
|
private appName?;
|
|
312
366
|
private appId?;
|
|
313
367
|
private apiKey?;
|
|
368
|
+
private callbackSecret?;
|
|
369
|
+
private signCallbacksByDefault;
|
|
314
370
|
constructor(realtimexUrl: string, appName?: string, appId?: string, apiKey?: string);
|
|
315
371
|
/**
|
|
316
|
-
*
|
|
372
|
+
* Configure callback signing behavior.
|
|
373
|
+
*/
|
|
374
|
+
configureContract(config: {
|
|
375
|
+
callbackSecret?: string;
|
|
376
|
+
signCallbacksByDefault?: boolean;
|
|
377
|
+
}): void;
|
|
378
|
+
/**
|
|
379
|
+
* Claim a task before processing.
|
|
380
|
+
*/
|
|
381
|
+
claim(taskUuid: string, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
382
|
+
/**
|
|
383
|
+
* Alias for claim()
|
|
317
384
|
*/
|
|
318
|
-
|
|
385
|
+
claimed(taskUuid: string, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
319
386
|
/**
|
|
320
|
-
* Mark task as
|
|
387
|
+
* Mark task as processing.
|
|
388
|
+
* Backward compatible signature: start(taskUuid, machineId?)
|
|
321
389
|
*/
|
|
322
|
-
|
|
390
|
+
start(taskUuid: string, machineIdOrOptions?: string | TaskEventOptions): Promise<TaskStatusResponse>;
|
|
323
391
|
/**
|
|
324
|
-
*
|
|
392
|
+
* Report incremental task progress.
|
|
325
393
|
*/
|
|
326
|
-
|
|
394
|
+
progress(taskUuid: string, progressData?: Record<string, unknown>, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
395
|
+
/**
|
|
396
|
+
* Mark task as completed with result.
|
|
397
|
+
* Backward compatible signature: complete(taskUuid, result?, machineId?)
|
|
398
|
+
*/
|
|
399
|
+
complete(taskUuid: string, result?: Record<string, unknown>, machineIdOrOptions?: string | TaskEventOptions): Promise<TaskStatusResponse>;
|
|
400
|
+
/**
|
|
401
|
+
* Mark task as failed with error.
|
|
402
|
+
* Backward compatible signature: fail(taskUuid, error, machineId?)
|
|
403
|
+
*/
|
|
404
|
+
fail(taskUuid: string, error: string, machineIdOrOptions?: string | TaskEventOptions): Promise<TaskStatusResponse>;
|
|
405
|
+
/**
|
|
406
|
+
* Mark task as canceled.
|
|
407
|
+
*/
|
|
408
|
+
cancel(taskUuid: string, reason?: string, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
409
|
+
private _normalizeOptions;
|
|
327
410
|
private _sendEvent;
|
|
328
411
|
}
|
|
329
412
|
|
|
@@ -982,6 +1065,118 @@ declare class AgentModule {
|
|
|
982
1065
|
}>;
|
|
983
1066
|
}
|
|
984
1067
|
|
|
1068
|
+
/**
|
|
1069
|
+
* MCP Module - Interact with MCP servers via RealtimeX SDK
|
|
1070
|
+
*/
|
|
1071
|
+
|
|
1072
|
+
interface MCPServer {
|
|
1073
|
+
/** Unique server name (slug) */
|
|
1074
|
+
name: string;
|
|
1075
|
+
/** User-friendly display name */
|
|
1076
|
+
display_name: string;
|
|
1077
|
+
/** Server description */
|
|
1078
|
+
description: string | null;
|
|
1079
|
+
/** Server type: 'stdio', 'http', 'sse', or 'remote' */
|
|
1080
|
+
server_type: string;
|
|
1081
|
+
/** Whether the server is enabled */
|
|
1082
|
+
enabled: boolean;
|
|
1083
|
+
/** Provider: 'local' or 'remote' */
|
|
1084
|
+
provider: 'local' | 'remote';
|
|
1085
|
+
/** Tags / categories */
|
|
1086
|
+
tags: string[];
|
|
1087
|
+
}
|
|
1088
|
+
interface MCPTool {
|
|
1089
|
+
/** Tool name */
|
|
1090
|
+
name: string;
|
|
1091
|
+
/** Tool description */
|
|
1092
|
+
description: string | null;
|
|
1093
|
+
/** JSON Schema describing the tool's input parameters */
|
|
1094
|
+
input_schema: Record<string, any>;
|
|
1095
|
+
}
|
|
1096
|
+
interface MCPToolResult {
|
|
1097
|
+
/** Whether the execution was successful */
|
|
1098
|
+
success: boolean;
|
|
1099
|
+
/** Server that executed the tool */
|
|
1100
|
+
server: string;
|
|
1101
|
+
/** Tool that was executed */
|
|
1102
|
+
tool: string;
|
|
1103
|
+
/** Provider used */
|
|
1104
|
+
provider: string;
|
|
1105
|
+
/** Execution result data */
|
|
1106
|
+
result: any;
|
|
1107
|
+
/** Error message if failed */
|
|
1108
|
+
error?: string;
|
|
1109
|
+
}
|
|
1110
|
+
declare class MCPModule extends ApiModule {
|
|
1111
|
+
constructor(realtimexUrl: string, appId: string, appName?: string, apiKey?: string);
|
|
1112
|
+
/**
|
|
1113
|
+
* List configured MCP servers.
|
|
1114
|
+
* @param provider - Filter by provider: 'local', 'remote', or 'all' (default: 'all')
|
|
1115
|
+
* @returns Array of MCP server objects
|
|
1116
|
+
*/
|
|
1117
|
+
getServers(provider?: 'local' | 'remote' | 'all'): Promise<MCPServer[]>;
|
|
1118
|
+
/**
|
|
1119
|
+
* List available tools for a specific MCP server.
|
|
1120
|
+
* @param serverName - The server name (slug)
|
|
1121
|
+
* @param provider - Provider: 'local' or 'remote' (default: 'local')
|
|
1122
|
+
* @returns Array of tool objects with name, description, and input schema
|
|
1123
|
+
*/
|
|
1124
|
+
getTools(serverName: string, provider?: 'local' | 'remote'): Promise<MCPTool[]>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Execute a tool on an MCP server.
|
|
1127
|
+
* @param serverName - The server name (slug)
|
|
1128
|
+
* @param toolName - The tool name to execute
|
|
1129
|
+
* @param args - Arguments to pass to the tool (matches tool's input_schema)
|
|
1130
|
+
* @param provider - Provider: 'local' or 'remote' (default: 'local')
|
|
1131
|
+
* @returns Tool execution result
|
|
1132
|
+
*/
|
|
1133
|
+
executeTool(serverName: string, toolName: string, args?: Record<string, any>, provider?: 'local' | 'remote'): Promise<any>;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
declare const LOCAL_APP_CONTRACT_VERSION = "local-app-contract/v1";
|
|
1137
|
+
declare const CONTRACT_SIGNATURE_HEADER = "x-rtx-contract-signature";
|
|
1138
|
+
declare const CONTRACT_EVENT_ID_HEADER = "x-rtx-event-id";
|
|
1139
|
+
declare const CONTRACT_SIGNATURE_ALGORITHM = "sha256";
|
|
1140
|
+
declare const CONTRACT_ATTEMPT_PREFIX = "run-";
|
|
1141
|
+
interface ContractSignInput {
|
|
1142
|
+
secret: string;
|
|
1143
|
+
eventId?: string;
|
|
1144
|
+
eventType: ContractEventType | string;
|
|
1145
|
+
taskId: string;
|
|
1146
|
+
attemptId?: string | number | null;
|
|
1147
|
+
timestamp?: string | null;
|
|
1148
|
+
payload?: unknown;
|
|
1149
|
+
}
|
|
1150
|
+
declare function normalizeContractEvent(eventLike?: string | null): ContractEventType | null;
|
|
1151
|
+
declare function normalizeAttemptId(attemptLike?: string | number | null): string | undefined;
|
|
1152
|
+
declare function parseAttemptRunId(attemptLike?: string | number | null): number | null;
|
|
1153
|
+
declare function hashContractPayload(payload: unknown): string;
|
|
1154
|
+
declare function createContractEventId(): string;
|
|
1155
|
+
declare function buildContractSignatureMessage({ eventId, eventType, taskId, attemptId, timestamp, payload, }: Omit<ContractSignInput, 'secret'>): string;
|
|
1156
|
+
declare function signContractEvent(input: ContractSignInput): string;
|
|
1157
|
+
declare function canonicalEventToLegacyAction(eventLike: string): string | null;
|
|
1158
|
+
declare function buildContractIdempotencyKey({ taskId, eventType, eventId, attemptId, machineId, timestamp, payload, }: {
|
|
1159
|
+
taskId: string;
|
|
1160
|
+
eventType: string;
|
|
1161
|
+
eventId?: string | null;
|
|
1162
|
+
attemptId?: string | number | null;
|
|
1163
|
+
machineId?: string | null;
|
|
1164
|
+
timestamp?: string | null;
|
|
1165
|
+
payload?: unknown;
|
|
1166
|
+
}): string;
|
|
1167
|
+
declare class ContractModule {
|
|
1168
|
+
private readonly realtimexUrl;
|
|
1169
|
+
private readonly appName?;
|
|
1170
|
+
private readonly appId?;
|
|
1171
|
+
private readonly apiKey?;
|
|
1172
|
+
private cachedContract;
|
|
1173
|
+
constructor(realtimexUrl: string, appName?: string, appId?: string, apiKey?: string);
|
|
1174
|
+
private requestPermission;
|
|
1175
|
+
private request;
|
|
1176
|
+
getLocalAppV1(forceRefresh?: boolean): Promise<LocalAppContractDefinition>;
|
|
1177
|
+
clearCache(): void;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
985
1180
|
/**
|
|
986
1181
|
* RealtimeX Local App SDK
|
|
987
1182
|
*
|
|
@@ -999,6 +1194,8 @@ declare class RealtimeXSDK {
|
|
|
999
1194
|
tts: TTSModule;
|
|
1000
1195
|
stt: STTModule;
|
|
1001
1196
|
agent: AgentModule;
|
|
1197
|
+
mcp: MCPModule;
|
|
1198
|
+
contract: ContractModule;
|
|
1002
1199
|
readonly appId: string;
|
|
1003
1200
|
readonly appName: string | undefined;
|
|
1004
1201
|
readonly apiKey: string | undefined;
|
|
@@ -1033,4 +1230,4 @@ declare class RealtimeXSDK {
|
|
|
1033
1230
|
getAppDataDir(): Promise<string>;
|
|
1034
1231
|
}
|
|
1035
1232
|
|
|
1036
|
-
export { ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, type EmbedOptions, type EmbedResponse, LLMModule, LLMPermissionError, LLMProviderError, PermissionDeniedError, PermissionRequiredError, PortModule, type Provider, type ProvidersResponse, RealtimeXSDK, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, type StreamChunk, type StreamChunkEvent, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace };
|
|
1233
|
+
export { ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, type ContractCallbackMetadata, type ContractEventType, ContractModule, type ContractSignInput, type EmbedOptions, type EmbedResponse, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LocalAppContractDefinition, type LocalAppContractResponse, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, PermissionRequiredError, PortModule, type Provider, type ProvidersResponse, RealtimeXSDK, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, type StreamChunk, type StreamChunkEvent, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, 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, parseAttemptRunId, signContractEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ interface SDKConfig {
|
|
|
10
10
|
};
|
|
11
11
|
defaultPort?: number;
|
|
12
12
|
permissions?: string[];
|
|
13
|
+
contract?: {
|
|
14
|
+
callbackSecret?: string;
|
|
15
|
+
signCallbacksByDefault?: boolean;
|
|
16
|
+
};
|
|
13
17
|
}
|
|
14
18
|
interface Activity {
|
|
15
19
|
id: string;
|
|
@@ -30,15 +34,46 @@ interface TriggerAgentPayload {
|
|
|
30
34
|
workspace_slug?: string;
|
|
31
35
|
thread_slug?: string;
|
|
32
36
|
prompt?: string;
|
|
37
|
+
event_id?: string;
|
|
38
|
+
attempt_id?: string | number;
|
|
33
39
|
}
|
|
34
40
|
interface TriggerAgentResponse {
|
|
35
41
|
success: boolean;
|
|
36
42
|
task_uuid?: string;
|
|
43
|
+
task_id?: string;
|
|
44
|
+
event_id?: string;
|
|
45
|
+
attempt_id?: string;
|
|
46
|
+
event_type?: ContractEventType | string;
|
|
47
|
+
contract_version?: string;
|
|
37
48
|
calendar_event_uuid?: string;
|
|
38
49
|
auto_run?: boolean;
|
|
39
50
|
message?: string;
|
|
40
51
|
error?: string;
|
|
41
52
|
}
|
|
53
|
+
type ContractEventType = 'task.trigger' | 'system.ping' | 'task.claimed' | 'task.started' | 'task.progress' | 'task.completed' | 'task.failed' | 'task.canceled';
|
|
54
|
+
interface ContractCallbackMetadata {
|
|
55
|
+
event_id_header?: string;
|
|
56
|
+
signature_header?: string;
|
|
57
|
+
signature_algorithm?: string;
|
|
58
|
+
signature_message?: string;
|
|
59
|
+
attempt_id_format?: string;
|
|
60
|
+
idempotency?: string;
|
|
61
|
+
}
|
|
62
|
+
interface LocalAppContractDefinition {
|
|
63
|
+
id: string;
|
|
64
|
+
version: string;
|
|
65
|
+
events: Record<string, ContractEventType>;
|
|
66
|
+
supported_events: ContractEventType[];
|
|
67
|
+
supported_legacy_events: string[];
|
|
68
|
+
aliases: Record<string, ContractEventType>;
|
|
69
|
+
status_map: Record<string, string>;
|
|
70
|
+
legacy_action_map: Record<ContractEventType, string>;
|
|
71
|
+
callback?: ContractCallbackMetadata;
|
|
72
|
+
}
|
|
73
|
+
interface LocalAppContractResponse {
|
|
74
|
+
success: boolean;
|
|
75
|
+
contract: LocalAppContractDefinition;
|
|
76
|
+
}
|
|
42
77
|
interface Agent {
|
|
43
78
|
slug: string;
|
|
44
79
|
name: string;
|
|
@@ -60,6 +95,7 @@ interface Thread {
|
|
|
60
95
|
}
|
|
61
96
|
interface TaskRun {
|
|
62
97
|
id: number;
|
|
98
|
+
attempt_id?: string;
|
|
63
99
|
agent_name: string;
|
|
64
100
|
workspace_slug: string;
|
|
65
101
|
thread_slug?: string;
|
|
@@ -300,30 +336,77 @@ declare class ApiModule {
|
|
|
300
336
|
* Task Module - Report task status to RealtimeX
|
|
301
337
|
* Used by external agents/processors to update task status
|
|
302
338
|
*/
|
|
339
|
+
|
|
303
340
|
interface TaskStatusResponse {
|
|
304
341
|
success: boolean;
|
|
305
342
|
task_uuid: string;
|
|
306
343
|
status: string;
|
|
344
|
+
event_id?: string;
|
|
345
|
+
attempt_id?: string;
|
|
346
|
+
event_type?: ContractEventType | string;
|
|
347
|
+
deduplicated?: boolean;
|
|
348
|
+
duplicate?: boolean;
|
|
307
349
|
message?: string;
|
|
308
350
|
}
|
|
351
|
+
interface TaskEventOptions {
|
|
352
|
+
machineId?: string;
|
|
353
|
+
attemptId?: string | number;
|
|
354
|
+
eventId?: string;
|
|
355
|
+
timestamp?: string;
|
|
356
|
+
callbackUrl?: string;
|
|
357
|
+
callbackSecret?: string;
|
|
358
|
+
sign?: boolean;
|
|
359
|
+
userEmail?: string;
|
|
360
|
+
activityId?: string;
|
|
361
|
+
tableName?: string;
|
|
362
|
+
}
|
|
309
363
|
declare class TaskModule {
|
|
310
364
|
private realtimexUrl;
|
|
311
365
|
private appName?;
|
|
312
366
|
private appId?;
|
|
313
367
|
private apiKey?;
|
|
368
|
+
private callbackSecret?;
|
|
369
|
+
private signCallbacksByDefault;
|
|
314
370
|
constructor(realtimexUrl: string, appName?: string, appId?: string, apiKey?: string);
|
|
315
371
|
/**
|
|
316
|
-
*
|
|
372
|
+
* Configure callback signing behavior.
|
|
373
|
+
*/
|
|
374
|
+
configureContract(config: {
|
|
375
|
+
callbackSecret?: string;
|
|
376
|
+
signCallbacksByDefault?: boolean;
|
|
377
|
+
}): void;
|
|
378
|
+
/**
|
|
379
|
+
* Claim a task before processing.
|
|
380
|
+
*/
|
|
381
|
+
claim(taskUuid: string, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
382
|
+
/**
|
|
383
|
+
* Alias for claim()
|
|
317
384
|
*/
|
|
318
|
-
|
|
385
|
+
claimed(taskUuid: string, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
319
386
|
/**
|
|
320
|
-
* Mark task as
|
|
387
|
+
* Mark task as processing.
|
|
388
|
+
* Backward compatible signature: start(taskUuid, machineId?)
|
|
321
389
|
*/
|
|
322
|
-
|
|
390
|
+
start(taskUuid: string, machineIdOrOptions?: string | TaskEventOptions): Promise<TaskStatusResponse>;
|
|
323
391
|
/**
|
|
324
|
-
*
|
|
392
|
+
* Report incremental task progress.
|
|
325
393
|
*/
|
|
326
|
-
|
|
394
|
+
progress(taskUuid: string, progressData?: Record<string, unknown>, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
395
|
+
/**
|
|
396
|
+
* Mark task as completed with result.
|
|
397
|
+
* Backward compatible signature: complete(taskUuid, result?, machineId?)
|
|
398
|
+
*/
|
|
399
|
+
complete(taskUuid: string, result?: Record<string, unknown>, machineIdOrOptions?: string | TaskEventOptions): Promise<TaskStatusResponse>;
|
|
400
|
+
/**
|
|
401
|
+
* Mark task as failed with error.
|
|
402
|
+
* Backward compatible signature: fail(taskUuid, error, machineId?)
|
|
403
|
+
*/
|
|
404
|
+
fail(taskUuid: string, error: string, machineIdOrOptions?: string | TaskEventOptions): Promise<TaskStatusResponse>;
|
|
405
|
+
/**
|
|
406
|
+
* Mark task as canceled.
|
|
407
|
+
*/
|
|
408
|
+
cancel(taskUuid: string, reason?: string, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
409
|
+
private _normalizeOptions;
|
|
327
410
|
private _sendEvent;
|
|
328
411
|
}
|
|
329
412
|
|
|
@@ -982,6 +1065,118 @@ declare class AgentModule {
|
|
|
982
1065
|
}>;
|
|
983
1066
|
}
|
|
984
1067
|
|
|
1068
|
+
/**
|
|
1069
|
+
* MCP Module - Interact with MCP servers via RealtimeX SDK
|
|
1070
|
+
*/
|
|
1071
|
+
|
|
1072
|
+
interface MCPServer {
|
|
1073
|
+
/** Unique server name (slug) */
|
|
1074
|
+
name: string;
|
|
1075
|
+
/** User-friendly display name */
|
|
1076
|
+
display_name: string;
|
|
1077
|
+
/** Server description */
|
|
1078
|
+
description: string | null;
|
|
1079
|
+
/** Server type: 'stdio', 'http', 'sse', or 'remote' */
|
|
1080
|
+
server_type: string;
|
|
1081
|
+
/** Whether the server is enabled */
|
|
1082
|
+
enabled: boolean;
|
|
1083
|
+
/** Provider: 'local' or 'remote' */
|
|
1084
|
+
provider: 'local' | 'remote';
|
|
1085
|
+
/** Tags / categories */
|
|
1086
|
+
tags: string[];
|
|
1087
|
+
}
|
|
1088
|
+
interface MCPTool {
|
|
1089
|
+
/** Tool name */
|
|
1090
|
+
name: string;
|
|
1091
|
+
/** Tool description */
|
|
1092
|
+
description: string | null;
|
|
1093
|
+
/** JSON Schema describing the tool's input parameters */
|
|
1094
|
+
input_schema: Record<string, any>;
|
|
1095
|
+
}
|
|
1096
|
+
interface MCPToolResult {
|
|
1097
|
+
/** Whether the execution was successful */
|
|
1098
|
+
success: boolean;
|
|
1099
|
+
/** Server that executed the tool */
|
|
1100
|
+
server: string;
|
|
1101
|
+
/** Tool that was executed */
|
|
1102
|
+
tool: string;
|
|
1103
|
+
/** Provider used */
|
|
1104
|
+
provider: string;
|
|
1105
|
+
/** Execution result data */
|
|
1106
|
+
result: any;
|
|
1107
|
+
/** Error message if failed */
|
|
1108
|
+
error?: string;
|
|
1109
|
+
}
|
|
1110
|
+
declare class MCPModule extends ApiModule {
|
|
1111
|
+
constructor(realtimexUrl: string, appId: string, appName?: string, apiKey?: string);
|
|
1112
|
+
/**
|
|
1113
|
+
* List configured MCP servers.
|
|
1114
|
+
* @param provider - Filter by provider: 'local', 'remote', or 'all' (default: 'all')
|
|
1115
|
+
* @returns Array of MCP server objects
|
|
1116
|
+
*/
|
|
1117
|
+
getServers(provider?: 'local' | 'remote' | 'all'): Promise<MCPServer[]>;
|
|
1118
|
+
/**
|
|
1119
|
+
* List available tools for a specific MCP server.
|
|
1120
|
+
* @param serverName - The server name (slug)
|
|
1121
|
+
* @param provider - Provider: 'local' or 'remote' (default: 'local')
|
|
1122
|
+
* @returns Array of tool objects with name, description, and input schema
|
|
1123
|
+
*/
|
|
1124
|
+
getTools(serverName: string, provider?: 'local' | 'remote'): Promise<MCPTool[]>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Execute a tool on an MCP server.
|
|
1127
|
+
* @param serverName - The server name (slug)
|
|
1128
|
+
* @param toolName - The tool name to execute
|
|
1129
|
+
* @param args - Arguments to pass to the tool (matches tool's input_schema)
|
|
1130
|
+
* @param provider - Provider: 'local' or 'remote' (default: 'local')
|
|
1131
|
+
* @returns Tool execution result
|
|
1132
|
+
*/
|
|
1133
|
+
executeTool(serverName: string, toolName: string, args?: Record<string, any>, provider?: 'local' | 'remote'): Promise<any>;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
declare const LOCAL_APP_CONTRACT_VERSION = "local-app-contract/v1";
|
|
1137
|
+
declare const CONTRACT_SIGNATURE_HEADER = "x-rtx-contract-signature";
|
|
1138
|
+
declare const CONTRACT_EVENT_ID_HEADER = "x-rtx-event-id";
|
|
1139
|
+
declare const CONTRACT_SIGNATURE_ALGORITHM = "sha256";
|
|
1140
|
+
declare const CONTRACT_ATTEMPT_PREFIX = "run-";
|
|
1141
|
+
interface ContractSignInput {
|
|
1142
|
+
secret: string;
|
|
1143
|
+
eventId?: string;
|
|
1144
|
+
eventType: ContractEventType | string;
|
|
1145
|
+
taskId: string;
|
|
1146
|
+
attemptId?: string | number | null;
|
|
1147
|
+
timestamp?: string | null;
|
|
1148
|
+
payload?: unknown;
|
|
1149
|
+
}
|
|
1150
|
+
declare function normalizeContractEvent(eventLike?: string | null): ContractEventType | null;
|
|
1151
|
+
declare function normalizeAttemptId(attemptLike?: string | number | null): string | undefined;
|
|
1152
|
+
declare function parseAttemptRunId(attemptLike?: string | number | null): number | null;
|
|
1153
|
+
declare function hashContractPayload(payload: unknown): string;
|
|
1154
|
+
declare function createContractEventId(): string;
|
|
1155
|
+
declare function buildContractSignatureMessage({ eventId, eventType, taskId, attemptId, timestamp, payload, }: Omit<ContractSignInput, 'secret'>): string;
|
|
1156
|
+
declare function signContractEvent(input: ContractSignInput): string;
|
|
1157
|
+
declare function canonicalEventToLegacyAction(eventLike: string): string | null;
|
|
1158
|
+
declare function buildContractIdempotencyKey({ taskId, eventType, eventId, attemptId, machineId, timestamp, payload, }: {
|
|
1159
|
+
taskId: string;
|
|
1160
|
+
eventType: string;
|
|
1161
|
+
eventId?: string | null;
|
|
1162
|
+
attemptId?: string | number | null;
|
|
1163
|
+
machineId?: string | null;
|
|
1164
|
+
timestamp?: string | null;
|
|
1165
|
+
payload?: unknown;
|
|
1166
|
+
}): string;
|
|
1167
|
+
declare class ContractModule {
|
|
1168
|
+
private readonly realtimexUrl;
|
|
1169
|
+
private readonly appName?;
|
|
1170
|
+
private readonly appId?;
|
|
1171
|
+
private readonly apiKey?;
|
|
1172
|
+
private cachedContract;
|
|
1173
|
+
constructor(realtimexUrl: string, appName?: string, appId?: string, apiKey?: string);
|
|
1174
|
+
private requestPermission;
|
|
1175
|
+
private request;
|
|
1176
|
+
getLocalAppV1(forceRefresh?: boolean): Promise<LocalAppContractDefinition>;
|
|
1177
|
+
clearCache(): void;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
985
1180
|
/**
|
|
986
1181
|
* RealtimeX Local App SDK
|
|
987
1182
|
*
|
|
@@ -999,6 +1194,8 @@ declare class RealtimeXSDK {
|
|
|
999
1194
|
tts: TTSModule;
|
|
1000
1195
|
stt: STTModule;
|
|
1001
1196
|
agent: AgentModule;
|
|
1197
|
+
mcp: MCPModule;
|
|
1198
|
+
contract: ContractModule;
|
|
1002
1199
|
readonly appId: string;
|
|
1003
1200
|
readonly appName: string | undefined;
|
|
1004
1201
|
readonly apiKey: string | undefined;
|
|
@@ -1033,4 +1230,4 @@ declare class RealtimeXSDK {
|
|
|
1033
1230
|
getAppDataDir(): Promise<string>;
|
|
1034
1231
|
}
|
|
1035
1232
|
|
|
1036
|
-
export { ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, type EmbedOptions, type EmbedResponse, LLMModule, LLMPermissionError, LLMProviderError, PermissionDeniedError, PermissionRequiredError, PortModule, type Provider, type ProvidersResponse, RealtimeXSDK, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, type StreamChunk, type StreamChunkEvent, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace };
|
|
1233
|
+
export { ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, type ContractCallbackMetadata, type ContractEventType, ContractModule, type ContractSignInput, type EmbedOptions, type EmbedResponse, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LocalAppContractDefinition, type LocalAppContractResponse, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, PermissionRequiredError, PortModule, type Provider, type ProvidersResponse, RealtimeXSDK, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, type StreamChunk, type StreamChunkEvent, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, 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, parseAttemptRunId, signContractEvent };
|