@realtimex/sdk 1.3.4 → 1.3.5-rc.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/README.md +61 -0
- package/dist/index.d.mts +646 -7
- package/dist/index.d.ts +646 -7
- package/dist/index.js +1899 -31
- package/dist/index.mjs +1859 -30
- package/package.json +2 -1
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()
|
|
384
|
+
*/
|
|
385
|
+
claimed(taskUuid: string, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
386
|
+
/**
|
|
387
|
+
* Mark task as processing.
|
|
388
|
+
* Backward compatible signature: start(taskUuid, machineId?)
|
|
389
|
+
*/
|
|
390
|
+
start(taskUuid: string, machineIdOrOptions?: string | TaskEventOptions): Promise<TaskStatusResponse>;
|
|
391
|
+
/**
|
|
392
|
+
* Report incremental task progress.
|
|
393
|
+
*/
|
|
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?)
|
|
317
398
|
*/
|
|
318
|
-
|
|
399
|
+
complete(taskUuid: string, result?: Record<string, unknown>, machineIdOrOptions?: string | TaskEventOptions): Promise<TaskStatusResponse>;
|
|
319
400
|
/**
|
|
320
|
-
* Mark task as
|
|
401
|
+
* Mark task as failed with error.
|
|
402
|
+
* Backward compatible signature: fail(taskUuid, error, machineId?)
|
|
321
403
|
*/
|
|
322
|
-
|
|
404
|
+
fail(taskUuid: string, error: string, machineIdOrOptions?: string | TaskEventOptions): Promise<TaskStatusResponse>;
|
|
323
405
|
/**
|
|
324
|
-
* Mark task as
|
|
406
|
+
* Mark task as canceled.
|
|
325
407
|
*/
|
|
326
|
-
|
|
408
|
+
cancel(taskUuid: string, reason?: string, options?: TaskEventOptions): Promise<TaskStatusResponse>;
|
|
409
|
+
private _normalizeOptions;
|
|
327
410
|
private _sendEvent;
|
|
328
411
|
}
|
|
329
412
|
|
|
@@ -1050,6 +1133,560 @@ declare class MCPModule extends ApiModule {
|
|
|
1050
1133
|
executeTool(serverName: string, toolName: string, args?: Record<string, any>, provider?: 'local' | 'remote'): Promise<any>;
|
|
1051
1134
|
}
|
|
1052
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
|
+
|
|
1180
|
+
type ProviderKind = 'gemini' | 'claude' | 'codex';
|
|
1181
|
+
type ContractStrictness = 'compatible' | 'strict';
|
|
1182
|
+
interface ContractCallbackRules {
|
|
1183
|
+
event_id_header?: string;
|
|
1184
|
+
signature_header?: string;
|
|
1185
|
+
signature_algorithm?: string;
|
|
1186
|
+
signature_message?: string;
|
|
1187
|
+
attempt_id_format?: string;
|
|
1188
|
+
idempotency?: string;
|
|
1189
|
+
}
|
|
1190
|
+
interface ContractCapabilityTrigger {
|
|
1191
|
+
event: 'task.trigger';
|
|
1192
|
+
route?: string;
|
|
1193
|
+
payload_template?: Record<string, unknown>;
|
|
1194
|
+
}
|
|
1195
|
+
interface ContractCapability {
|
|
1196
|
+
capability_id: string;
|
|
1197
|
+
name: string;
|
|
1198
|
+
description: string;
|
|
1199
|
+
input_schema: Record<string, unknown>;
|
|
1200
|
+
output_schema?: Record<string, unknown>;
|
|
1201
|
+
permission: string;
|
|
1202
|
+
trigger: ContractCapabilityTrigger;
|
|
1203
|
+
}
|
|
1204
|
+
interface LocalAppContractV1 {
|
|
1205
|
+
contract_version: 'local-app-contract/v1';
|
|
1206
|
+
strictness: ContractStrictness;
|
|
1207
|
+
supported_contract_events: string[];
|
|
1208
|
+
supported_legacy_events?: string[];
|
|
1209
|
+
aliases?: Record<string, string>;
|
|
1210
|
+
status_map?: Record<string, string>;
|
|
1211
|
+
legacy_action_map?: Record<string, string>;
|
|
1212
|
+
callback?: ContractCallbackRules;
|
|
1213
|
+
capabilities?: ContractCapability[];
|
|
1214
|
+
}
|
|
1215
|
+
interface LegacyLocalAppContractShape {
|
|
1216
|
+
id?: string;
|
|
1217
|
+
version?: string;
|
|
1218
|
+
strictness?: ContractStrictness;
|
|
1219
|
+
supported_events?: string[];
|
|
1220
|
+
supported_contract_events?: string[];
|
|
1221
|
+
supported_legacy_events?: string[];
|
|
1222
|
+
aliases?: Record<string, string>;
|
|
1223
|
+
status_map?: Record<string, string>;
|
|
1224
|
+
legacy_action_map?: Record<string, string>;
|
|
1225
|
+
callback?: ContractCallbackRules;
|
|
1226
|
+
capabilities?: ContractCapability[];
|
|
1227
|
+
}
|
|
1228
|
+
interface ContractDiscoveryResponse {
|
|
1229
|
+
success: boolean;
|
|
1230
|
+
contract: LocalAppContractV1 | LegacyLocalAppContractShape;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
interface ProjectToolsInput {
|
|
1234
|
+
contract: LocalAppContractV1;
|
|
1235
|
+
provider: ProviderKind;
|
|
1236
|
+
appId: string;
|
|
1237
|
+
namespace?: string;
|
|
1238
|
+
}
|
|
1239
|
+
interface CanonicalToolDefinition {
|
|
1240
|
+
tool_name: string;
|
|
1241
|
+
title: string;
|
|
1242
|
+
description: string;
|
|
1243
|
+
input_schema: Record<string, unknown>;
|
|
1244
|
+
output_schema?: Record<string, unknown>;
|
|
1245
|
+
permission: string;
|
|
1246
|
+
capability_id: string;
|
|
1247
|
+
trigger: ContractCapability['trigger'];
|
|
1248
|
+
}
|
|
1249
|
+
interface HostToolAdapter<TProviderTool, TProviderToolCall, TProviderResult> {
|
|
1250
|
+
toProviderTools(tools: CanonicalToolDefinition[]): TProviderTool[];
|
|
1251
|
+
fromProviderToolCall(call: TProviderToolCall): {
|
|
1252
|
+
tool_call_id: string;
|
|
1253
|
+
tool_name: string;
|
|
1254
|
+
args: Record<string, unknown>;
|
|
1255
|
+
};
|
|
1256
|
+
toProviderResult(result: {
|
|
1257
|
+
status: 'completed' | 'failed' | 'queued';
|
|
1258
|
+
tool_call_id?: string;
|
|
1259
|
+
task_id?: string;
|
|
1260
|
+
attempt_id?: string;
|
|
1261
|
+
output?: Record<string, unknown>;
|
|
1262
|
+
error?: {
|
|
1263
|
+
code: string;
|
|
1264
|
+
message: string;
|
|
1265
|
+
retryable: boolean;
|
|
1266
|
+
};
|
|
1267
|
+
}): TProviderResult;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
interface ToolCall {
|
|
1271
|
+
tool_call_id: string;
|
|
1272
|
+
tool_name: string;
|
|
1273
|
+
args: Record<string, unknown>;
|
|
1274
|
+
}
|
|
1275
|
+
interface ExecutionContext {
|
|
1276
|
+
appId: string;
|
|
1277
|
+
userId: string;
|
|
1278
|
+
workspaceId?: string;
|
|
1279
|
+
requestId?: string;
|
|
1280
|
+
idempotencyKey?: string;
|
|
1281
|
+
provider?: ProviderKind;
|
|
1282
|
+
namespace?: string;
|
|
1283
|
+
metadata?: Record<string, unknown>;
|
|
1284
|
+
}
|
|
1285
|
+
interface ExecutionResult {
|
|
1286
|
+
status: 'completed' | 'failed' | 'queued';
|
|
1287
|
+
tool_call_id?: string;
|
|
1288
|
+
task_id?: string;
|
|
1289
|
+
attempt_id?: string;
|
|
1290
|
+
output?: Record<string, unknown>;
|
|
1291
|
+
error?: {
|
|
1292
|
+
code: string;
|
|
1293
|
+
message: string;
|
|
1294
|
+
retryable: boolean;
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
type LifecycleEventType = 'task.claimed' | 'task.started' | 'task.progress' | 'task.completed' | 'task.failed' | 'task.canceled';
|
|
1298
|
+
interface RuntimeExecutionEvent {
|
|
1299
|
+
tool_call_id: string;
|
|
1300
|
+
task_id: string;
|
|
1301
|
+
attempt_id?: string;
|
|
1302
|
+
event_type: LifecycleEventType;
|
|
1303
|
+
event_id: string;
|
|
1304
|
+
timestamp: string;
|
|
1305
|
+
payload?: Record<string, unknown>;
|
|
1306
|
+
}
|
|
1307
|
+
interface GetToolsInput {
|
|
1308
|
+
appId: string;
|
|
1309
|
+
provider: ProviderKind;
|
|
1310
|
+
namespace?: string;
|
|
1311
|
+
}
|
|
1312
|
+
interface IngestExecutionEventInput {
|
|
1313
|
+
event?: string;
|
|
1314
|
+
event_type?: string;
|
|
1315
|
+
event_id?: string;
|
|
1316
|
+
task_id?: string;
|
|
1317
|
+
task_uuid?: string;
|
|
1318
|
+
attempt_id?: string | number | null;
|
|
1319
|
+
tool_call_id?: string;
|
|
1320
|
+
timestamp?: string;
|
|
1321
|
+
payload?: Record<string, unknown>;
|
|
1322
|
+
data?: Record<string, unknown>;
|
|
1323
|
+
[key: string]: unknown;
|
|
1324
|
+
}
|
|
1325
|
+
interface ContractRuntimeInterface {
|
|
1326
|
+
getContract(appId: string): Promise<LocalAppContractV1>;
|
|
1327
|
+
getTools(input: GetToolsInput): Promise<CanonicalToolDefinition[]>;
|
|
1328
|
+
executeToolCall(call: ToolCall, context: ExecutionContext): Promise<ExecutionResult>;
|
|
1329
|
+
onExecutionEvent(handler: (event: RuntimeExecutionEvent) => void): () => void;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
interface RetryPolicyOptions {
|
|
1333
|
+
maxAttempts?: number;
|
|
1334
|
+
baseDelayMs?: number;
|
|
1335
|
+
maxDelayMs?: number;
|
|
1336
|
+
shouldRetry?: (error: unknown, attempt: number) => boolean;
|
|
1337
|
+
}
|
|
1338
|
+
declare class RetryPolicy {
|
|
1339
|
+
private readonly maxAttempts;
|
|
1340
|
+
private readonly baseDelayMs;
|
|
1341
|
+
private readonly maxDelayMs;
|
|
1342
|
+
private readonly shouldRetry;
|
|
1343
|
+
constructor(options?: RetryPolicyOptions);
|
|
1344
|
+
execute<T>(operation: (attempt: number) => Promise<T>): Promise<T>;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
interface ContractRuntimeOptions {
|
|
1348
|
+
baseUrl: string;
|
|
1349
|
+
appId?: string;
|
|
1350
|
+
appName?: string;
|
|
1351
|
+
apiKey?: string;
|
|
1352
|
+
permissions?: string[];
|
|
1353
|
+
namespace?: string;
|
|
1354
|
+
fetchImpl?: typeof fetch;
|
|
1355
|
+
cacheTtlMs?: number;
|
|
1356
|
+
retry?: RetryPolicyOptions;
|
|
1357
|
+
}
|
|
1358
|
+
declare class ContractRuntime implements ContractRuntimeInterface {
|
|
1359
|
+
private readonly appId?;
|
|
1360
|
+
private readonly appName?;
|
|
1361
|
+
private readonly defaultNamespace?;
|
|
1362
|
+
private readonly contractClient;
|
|
1363
|
+
private readonly toolProjector;
|
|
1364
|
+
private readonly executionStore;
|
|
1365
|
+
private readonly lifecycleReporter;
|
|
1366
|
+
private readonly scopeGuard;
|
|
1367
|
+
private readonly retryPolicy;
|
|
1368
|
+
private readonly httpClient;
|
|
1369
|
+
constructor(options: ContractRuntimeOptions);
|
|
1370
|
+
getContract(appId: string): Promise<LocalAppContractV1>;
|
|
1371
|
+
getTools(input: GetToolsInput): Promise<CanonicalToolDefinition[]>;
|
|
1372
|
+
executeToolCall(call: ToolCall, context: ExecutionContext): Promise<ExecutionResult>;
|
|
1373
|
+
onExecutionEvent(handler: (event: RuntimeExecutionEvent) => void): () => void;
|
|
1374
|
+
ingestExecutionEvent(input: IngestExecutionEventInput): RuntimeExecutionEvent | null;
|
|
1375
|
+
clearCache(): void;
|
|
1376
|
+
private assertAppContext;
|
|
1377
|
+
private buildRegistryKey;
|
|
1378
|
+
private resolveTaskId;
|
|
1379
|
+
private buildTriggerRequestBody;
|
|
1380
|
+
private validateToolArgs;
|
|
1381
|
+
private matchesType;
|
|
1382
|
+
private tryEmitLifecycleEvent;
|
|
1383
|
+
private toFailedResult;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
interface ContractHttpClientConfig {
|
|
1387
|
+
baseUrl: string;
|
|
1388
|
+
appId?: string;
|
|
1389
|
+
appName?: string;
|
|
1390
|
+
apiKey?: string;
|
|
1391
|
+
fetchImpl?: typeof fetch;
|
|
1392
|
+
}
|
|
1393
|
+
declare class ContractHttpClient {
|
|
1394
|
+
private readonly baseUrl;
|
|
1395
|
+
private readonly appId?;
|
|
1396
|
+
private readonly appName?;
|
|
1397
|
+
private readonly apiKey?;
|
|
1398
|
+
private readonly fetchImpl;
|
|
1399
|
+
constructor(config: ContractHttpClientConfig);
|
|
1400
|
+
get<T>(path: string, headers?: HeadersInit): Promise<T>;
|
|
1401
|
+
post<T>(path: string, body: unknown, headers?: HeadersInit): Promise<T>;
|
|
1402
|
+
request<T>(path: string, options?: RequestInit): Promise<T>;
|
|
1403
|
+
private buildHeaders;
|
|
1404
|
+
private parseResponse;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
declare class ContractCache {
|
|
1408
|
+
private readonly ttlMs;
|
|
1409
|
+
private readonly entries;
|
|
1410
|
+
constructor(ttlMs?: number);
|
|
1411
|
+
get(key: string): LocalAppContractV1 | null;
|
|
1412
|
+
set(key: string, value: LocalAppContractV1): void;
|
|
1413
|
+
clear(key?: string): void;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
interface ContractClientOptions {
|
|
1417
|
+
cache?: ContractCache;
|
|
1418
|
+
cacheKey?: string;
|
|
1419
|
+
}
|
|
1420
|
+
declare class ContractClient {
|
|
1421
|
+
private readonly httpClient;
|
|
1422
|
+
private readonly cache;
|
|
1423
|
+
private readonly cacheKey;
|
|
1424
|
+
constructor(httpClient: ContractHttpClient, options?: ContractClientOptions);
|
|
1425
|
+
getLocalAppV1(forceRefresh?: boolean): Promise<LocalAppContractV1>;
|
|
1426
|
+
clearCache(): void;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
declare function normalizeLocalAppContractV1(payload: unknown): LocalAppContractV1;
|
|
1430
|
+
|
|
1431
|
+
declare class ToolProjector {
|
|
1432
|
+
project(input: ProjectToolsInput): CanonicalToolDefinition[];
|
|
1433
|
+
private ensureUniqueToolName;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
declare function normalizeSchema(schema?: Record<string, unknown>): Record<string, unknown>;
|
|
1437
|
+
|
|
1438
|
+
declare function toStableToolName(capabilityId: string, namespace?: string): string;
|
|
1439
|
+
|
|
1440
|
+
declare class ScopeGuard {
|
|
1441
|
+
private readonly scopes;
|
|
1442
|
+
constructor(scopes?: string[]);
|
|
1443
|
+
can(permission?: string): boolean;
|
|
1444
|
+
assert(permission?: string): void;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
interface AuthProvider {
|
|
1448
|
+
buildHeaders(baseHeaders?: Record<string, string>): Record<string, string>;
|
|
1449
|
+
}
|
|
1450
|
+
interface StaticAuthProviderOptions {
|
|
1451
|
+
appId?: string;
|
|
1452
|
+
appName?: string;
|
|
1453
|
+
apiKey?: string;
|
|
1454
|
+
}
|
|
1455
|
+
declare class StaticAuthProvider implements AuthProvider {
|
|
1456
|
+
private readonly appId?;
|
|
1457
|
+
private readonly appName?;
|
|
1458
|
+
private readonly apiKey?;
|
|
1459
|
+
constructor(options?: StaticAuthProviderOptions);
|
|
1460
|
+
buildHeaders(baseHeaders?: Record<string, string>): Record<string, string>;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
declare class ContractError extends Error {
|
|
1464
|
+
readonly code: string;
|
|
1465
|
+
readonly details?: unknown;
|
|
1466
|
+
constructor(code: string, message: string, details?: unknown);
|
|
1467
|
+
}
|
|
1468
|
+
declare class ContractValidationError extends ContractError {
|
|
1469
|
+
constructor(message: string, details?: unknown);
|
|
1470
|
+
}
|
|
1471
|
+
declare class ToolValidationError extends ContractError {
|
|
1472
|
+
constructor(message: string, details?: unknown);
|
|
1473
|
+
}
|
|
1474
|
+
declare class ToolNotFoundError extends ContractError {
|
|
1475
|
+
constructor(toolName: string, details?: unknown);
|
|
1476
|
+
}
|
|
1477
|
+
declare class ScopeDeniedError extends ContractError {
|
|
1478
|
+
constructor(permission: string, details?: unknown);
|
|
1479
|
+
}
|
|
1480
|
+
declare class RuntimeTransportError extends ContractError {
|
|
1481
|
+
readonly statusCode?: number;
|
|
1482
|
+
constructor(message: string, statusCode?: number, details?: unknown);
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
interface GeminiFunctionDeclaration {
|
|
1486
|
+
name: string;
|
|
1487
|
+
description?: string;
|
|
1488
|
+
parameters?: Record<string, unknown>;
|
|
1489
|
+
}
|
|
1490
|
+
interface GeminiToolCall {
|
|
1491
|
+
id: string;
|
|
1492
|
+
name: string;
|
|
1493
|
+
args?: Record<string, unknown> | string;
|
|
1494
|
+
}
|
|
1495
|
+
interface GeminiToolResult {
|
|
1496
|
+
tool_call_id: string;
|
|
1497
|
+
status: ExecutionResult['status'];
|
|
1498
|
+
payload: Record<string, unknown>;
|
|
1499
|
+
}
|
|
1500
|
+
declare class GeminiToolAdapter implements HostToolAdapter<GeminiFunctionDeclaration, GeminiToolCall, GeminiToolResult> {
|
|
1501
|
+
toProviderTools(tools: CanonicalToolDefinition[]): GeminiFunctionDeclaration[];
|
|
1502
|
+
fromProviderToolCall(call: GeminiToolCall): ToolCall;
|
|
1503
|
+
toProviderResult(result: ExecutionResult): GeminiToolResult;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
interface ClaudeToolDefinition {
|
|
1507
|
+
name: string;
|
|
1508
|
+
description: string;
|
|
1509
|
+
input_schema: Record<string, unknown>;
|
|
1510
|
+
}
|
|
1511
|
+
interface ClaudeToolCall {
|
|
1512
|
+
id: string;
|
|
1513
|
+
name: string;
|
|
1514
|
+
input?: Record<string, unknown>;
|
|
1515
|
+
}
|
|
1516
|
+
interface ClaudeToolResult {
|
|
1517
|
+
type: 'tool_result';
|
|
1518
|
+
tool_use_id: string;
|
|
1519
|
+
content: string;
|
|
1520
|
+
is_error?: boolean;
|
|
1521
|
+
}
|
|
1522
|
+
declare class ClaudeToolAdapter implements HostToolAdapter<ClaudeToolDefinition, ClaudeToolCall, ClaudeToolResult> {
|
|
1523
|
+
toProviderTools(tools: CanonicalToolDefinition[]): ClaudeToolDefinition[];
|
|
1524
|
+
fromProviderToolCall(call: ClaudeToolCall): ToolCall;
|
|
1525
|
+
toProviderResult(result: ExecutionResult): ClaudeToolResult;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
interface CodexToolDefinition {
|
|
1529
|
+
type: 'function';
|
|
1530
|
+
function: {
|
|
1531
|
+
name: string;
|
|
1532
|
+
description: string;
|
|
1533
|
+
parameters: Record<string, unknown>;
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
interface CodexToolCall {
|
|
1537
|
+
id: string;
|
|
1538
|
+
function: {
|
|
1539
|
+
name: string;
|
|
1540
|
+
arguments?: string | Record<string, unknown>;
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
interface CodexToolResult {
|
|
1544
|
+
tool_call_id: string;
|
|
1545
|
+
output: string;
|
|
1546
|
+
is_error?: boolean;
|
|
1547
|
+
}
|
|
1548
|
+
declare class CodexToolAdapter implements HostToolAdapter<CodexToolDefinition, CodexToolCall, CodexToolResult> {
|
|
1549
|
+
toProviderTools(tools: CanonicalToolDefinition[]): CodexToolDefinition[];
|
|
1550
|
+
fromProviderToolCall(call: CodexToolCall): ToolCall;
|
|
1551
|
+
toProviderResult(result: ExecutionResult): CodexToolResult;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
type ACPToolKind = 'read' | 'edit' | 'delete' | 'move' | 'search' | 'execute' | 'think' | 'fetch' | 'other';
|
|
1555
|
+
type ACPToolStatus = 'pending' | 'in_progress' | 'completed' | 'failed';
|
|
1556
|
+
interface ACPTextContent {
|
|
1557
|
+
type: 'text';
|
|
1558
|
+
text: string;
|
|
1559
|
+
}
|
|
1560
|
+
interface ACPSessionToolUpdate {
|
|
1561
|
+
type: 'tool_call' | 'tool_call_update';
|
|
1562
|
+
toolCallId: string;
|
|
1563
|
+
title?: string;
|
|
1564
|
+
kind?: ACPToolKind;
|
|
1565
|
+
status: ACPToolStatus;
|
|
1566
|
+
content?: ACPTextContent[];
|
|
1567
|
+
rawInput?: Record<string, unknown>;
|
|
1568
|
+
rawOutput?: Record<string, unknown>;
|
|
1569
|
+
_meta?: Record<string, unknown>;
|
|
1570
|
+
}
|
|
1571
|
+
interface ACPSessionUpdateParams {
|
|
1572
|
+
sessionId: string;
|
|
1573
|
+
update: ACPSessionToolUpdate;
|
|
1574
|
+
}
|
|
1575
|
+
interface ACPNotifier {
|
|
1576
|
+
notify(method: 'session/update', params: ACPSessionUpdateParams): Promise<void>;
|
|
1577
|
+
request?<T = unknown>(method: string, params: Record<string, unknown>): Promise<T>;
|
|
1578
|
+
}
|
|
1579
|
+
interface ACPAdapterContext {
|
|
1580
|
+
sessionId: string;
|
|
1581
|
+
appId: string;
|
|
1582
|
+
userId: string;
|
|
1583
|
+
workspaceId?: string;
|
|
1584
|
+
provider?: 'gemini' | 'claude' | 'codex';
|
|
1585
|
+
namespace?: string;
|
|
1586
|
+
}
|
|
1587
|
+
interface ACPToolInvocation {
|
|
1588
|
+
toolCallId: string;
|
|
1589
|
+
toolName: string;
|
|
1590
|
+
args: Record<string, unknown>;
|
|
1591
|
+
title?: string;
|
|
1592
|
+
kind?: ACPToolKind;
|
|
1593
|
+
}
|
|
1594
|
+
interface ACPExecutionReference {
|
|
1595
|
+
sessionId: string;
|
|
1596
|
+
toolCallId: string;
|
|
1597
|
+
appId: string;
|
|
1598
|
+
userId: string;
|
|
1599
|
+
workspaceId?: string;
|
|
1600
|
+
provider?: 'gemini' | 'claude' | 'codex';
|
|
1601
|
+
namespace?: string;
|
|
1602
|
+
title?: string;
|
|
1603
|
+
kind?: ACPToolKind;
|
|
1604
|
+
}
|
|
1605
|
+
interface PermissionOption {
|
|
1606
|
+
id: string;
|
|
1607
|
+
label: string;
|
|
1608
|
+
kind?: 'allow_once' | 'allow_always' | 'deny_once' | 'deny_always';
|
|
1609
|
+
}
|
|
1610
|
+
interface ACPContractRuntime {
|
|
1611
|
+
executeToolCall(call: ToolCall, context: ExecutionContext): Promise<ExecutionResult>;
|
|
1612
|
+
onExecutionEvent(handler: (event: RuntimeExecutionEvent) => void): () => void;
|
|
1613
|
+
ingestExecutionEvent(input: IngestExecutionEventInput): RuntimeExecutionEvent | null;
|
|
1614
|
+
}
|
|
1615
|
+
interface ACPContractAdapterOptions {
|
|
1616
|
+
runtime: ACPContractRuntime;
|
|
1617
|
+
notifier: ACPNotifier;
|
|
1618
|
+
requestPermission?: boolean;
|
|
1619
|
+
buildPermissionOptions?: (input: ACPToolInvocation) => PermissionOption[];
|
|
1620
|
+
telemetry?: ACPAdapterTelemetrySink;
|
|
1621
|
+
}
|
|
1622
|
+
interface ACPAdapterTelemetryEvent {
|
|
1623
|
+
phase: 'execute' | 'notify' | 'permission' | 'runtime_event' | 'ingest';
|
|
1624
|
+
result: 'ok' | 'failed' | 'skipped';
|
|
1625
|
+
sessionId?: string;
|
|
1626
|
+
toolCallId?: string;
|
|
1627
|
+
toolName?: string;
|
|
1628
|
+
taskId?: string;
|
|
1629
|
+
attemptId?: string;
|
|
1630
|
+
eventId?: string;
|
|
1631
|
+
eventType?: string;
|
|
1632
|
+
status?: ACPToolStatus;
|
|
1633
|
+
error?: string;
|
|
1634
|
+
metadata?: Record<string, unknown>;
|
|
1635
|
+
}
|
|
1636
|
+
interface ACPAdapterTelemetrySink {
|
|
1637
|
+
emit(event: ACPAdapterTelemetryEvent): void | Promise<void>;
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
declare class ACPContractAdapter {
|
|
1641
|
+
private readonly runtime;
|
|
1642
|
+
private readonly notifier;
|
|
1643
|
+
private readonly mapper;
|
|
1644
|
+
private readonly permissionBridge;
|
|
1645
|
+
private readonly telemetry;
|
|
1646
|
+
private readonly taskReferences;
|
|
1647
|
+
private readonly toolCallReferences;
|
|
1648
|
+
private readonly runtimeUnsubscribe;
|
|
1649
|
+
constructor(options: ACPContractAdapterOptions);
|
|
1650
|
+
dispose(): void;
|
|
1651
|
+
executeTool(invocation: ACPToolInvocation, context: ACPAdapterContext): Promise<ExecutionResult>;
|
|
1652
|
+
ingestContractCallback(payload: Record<string, unknown>, context: Pick<ACPAdapterContext, 'sessionId'>): RuntimeExecutionEvent | null;
|
|
1653
|
+
private handleRuntimeEvent;
|
|
1654
|
+
private resolveReferenceForEvent;
|
|
1655
|
+
private rememberReference;
|
|
1656
|
+
private cleanupReference;
|
|
1657
|
+
private notify;
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
declare class ACPEventMapper {
|
|
1661
|
+
createReference(invocation: ACPToolInvocation, context: ACPAdapterContext): ACPExecutionReference;
|
|
1662
|
+
buildPendingUpdate(invocation: ACPToolInvocation, reference: ACPExecutionReference): ACPSessionUpdateParams;
|
|
1663
|
+
buildResultUpdate(result: ExecutionResult, reference: ACPExecutionReference): ACPSessionUpdateParams;
|
|
1664
|
+
buildLifecycleUpdate(event: RuntimeExecutionEvent, reference: ACPExecutionReference): ACPSessionUpdateParams | null;
|
|
1665
|
+
buildNotifyFailureUpdate(reference: ACPExecutionReference, error: unknown): ACPSessionUpdateParams;
|
|
1666
|
+
mapContractEventStatus(eventType: string): ACPToolStatus | null;
|
|
1667
|
+
private mapExecutionResultStatus;
|
|
1668
|
+
private resolveEventText;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
interface ACPPermissionBridgeOptions {
|
|
1672
|
+
notifier: ACPNotifier;
|
|
1673
|
+
enabled: boolean;
|
|
1674
|
+
buildPermissionOptions?: (input: ACPToolInvocation) => PermissionOption[];
|
|
1675
|
+
}
|
|
1676
|
+
declare class ACPPermissionBridge {
|
|
1677
|
+
private readonly notifier;
|
|
1678
|
+
private readonly enabled;
|
|
1679
|
+
private readonly buildPermissionOptions?;
|
|
1680
|
+
constructor(options: ACPPermissionBridgeOptions);
|
|
1681
|
+
requestToolPermission(invocation: ACPToolInvocation, context: ACPAdapterContext): Promise<boolean>;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
declare class ACPTelemetry {
|
|
1685
|
+
private readonly sink?;
|
|
1686
|
+
constructor(sink?: ACPAdapterTelemetrySink);
|
|
1687
|
+
emit(event: ACPAdapterTelemetryEvent): void;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1053
1690
|
/**
|
|
1054
1691
|
* RealtimeX Local App SDK
|
|
1055
1692
|
*
|
|
@@ -1068,6 +1705,8 @@ declare class RealtimeXSDK {
|
|
|
1068
1705
|
stt: STTModule;
|
|
1069
1706
|
agent: AgentModule;
|
|
1070
1707
|
mcp: MCPModule;
|
|
1708
|
+
contract: ContractModule;
|
|
1709
|
+
contractRuntime: ContractRuntime;
|
|
1071
1710
|
readonly appId: string;
|
|
1072
1711
|
readonly appName: string | undefined;
|
|
1073
1712
|
readonly apiKey: string | undefined;
|
|
@@ -1102,4 +1741,4 @@ declare class RealtimeXSDK {
|
|
|
1102
1741
|
getAppDataDir(): Promise<string>;
|
|
1103
1742
|
}
|
|
1104
1743
|
|
|
1105
|
-
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, 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 };
|
|
1744
|
+
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, type AuthProvider, 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, ContractModule, ContractRuntime, type ContractRuntimeInterface, type ContractRuntimeOptions, type ContractSignInput, type ContractStrictness, ContractValidationError, 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 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 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 };
|