@factory/droid-sdk 0.2.0 → 0.3.0
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 +214 -82
- package/dist/index.cjs +734 -611
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1649 -206
- package/dist/index.d.ts +1649 -206
- package/dist/index.js +729 -624
- package/dist/index.js.map +1 -1
- package/docs/sdk-usage-guide.md +678 -0
- package/examples/abort-session-stream.ts +19 -55
- package/examples/droid-dev-structured-output.ts +4 -5
- package/examples/fork-session.ts +25 -6
- package/examples/hook-execution.ts +62 -0
- package/examples/init-metadata.ts +9 -66
- package/examples/interrupt-session.ts +19 -54
- package/examples/list-sessions.ts +9 -55
- package/examples/multi-turn-session.ts +21 -53
- package/examples/permission-handler.ts +26 -84
- package/examples/readme-structured-output.ts +25 -0
- package/examples/result-metadata.ts +1 -1
- package/examples/run.ts +1 -1
- package/examples/sdk-mcp-tool.ts +11 -7
- package/examples/session-stream.ts +54 -0
- package/examples/spec-mode-new-session.ts +38 -99
- package/examples/spec-mode-same-session.ts +49 -111
- package/examples/structured-output.ts +16 -10
- package/examples/test-compact.ts +5 -3
- package/examples/test-rewind.ts +49 -117
- package/examples/tool-controls.ts +22 -55
- package/package.json +1 -1
- package/docs/examples/init-metadata.md +0 -79
- package/docs/examples/list-sessions.md +0 -64
- package/docs/examples/multi-turn-session.md +0 -77
- package/docs/examples/one-shot-query.md +0 -73
- package/docs/examples/permission-handler.md +0 -102
- package/docs/examples/run.md +0 -52
- package/docs/examples/spec-mode.md +0 -101
- package/docs/examples/tool-controls.md +0 -90
- package/docs/typescript-sdk-reference.md +0 -372
- package/examples/simple-query.ts +0 -53
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,7 @@ __export(index_exports, {
|
|
|
46
46
|
AskUserRequestSchema: () => AskUserRequestSchema,
|
|
47
47
|
AskUserResponseSchema: () => AskUserResponseSchema,
|
|
48
48
|
AskUserResultSchema: () => AskUserResultSchema,
|
|
49
|
+
AssistantTextCompleteNotificationSchema: () => AssistantTextCompleteNotificationSchema,
|
|
49
50
|
AssistantTextDeltaNotificationSchema: () => AssistantTextDeltaNotificationSchema,
|
|
50
51
|
AuthenticateMcpServerRequestParamsSchema: () => AuthenticateMcpServerRequestParamsSchema,
|
|
51
52
|
AuthenticateMcpServerRequestSchema: () => AuthenticateMcpServerRequestSchema,
|
|
@@ -70,6 +71,10 @@ __export(index_exports, {
|
|
|
70
71
|
ClearMcpAuthResultSchema: () => ClearMcpAuthResultSchema,
|
|
71
72
|
CliRequestOrNotificationSchema: () => CliRequestOrNotificationSchema,
|
|
72
73
|
ClientRequestSchema: () => ClientRequestSchema,
|
|
74
|
+
CloseSessionRequestParamsSchema: () => CloseSessionRequestParamsSchema,
|
|
75
|
+
CloseSessionRequestSchema: () => CloseSessionRequestSchema,
|
|
76
|
+
CloseSessionResponseSchema: () => CloseSessionResponseSchema,
|
|
77
|
+
CloseSessionResultSchema: () => CloseSessionResultSchema,
|
|
73
78
|
CompactSessionRequestParamsSchema: () => CompactSessionRequestParamsSchema,
|
|
74
79
|
CompactSessionRequestSchema: () => CompactSessionRequestSchema,
|
|
75
80
|
CompactSessionResponseSchema: () => CompactSessionResponseSchema,
|
|
@@ -90,6 +95,10 @@ __export(index_exports, {
|
|
|
90
95
|
DroidClient: () => DroidClient,
|
|
91
96
|
DroidClientMethod: () => DroidClientMethod,
|
|
92
97
|
DroidErrorType: () => DroidErrorType,
|
|
98
|
+
DroidHookEventSchema: () => DroidHookEventSchema,
|
|
99
|
+
DroidHookExecutionResultSchema: () => DroidHookExecutionResultSchema,
|
|
100
|
+
DroidHookOutputSchema: () => DroidHookOutputSchema,
|
|
101
|
+
DroidHookSpecificOutputSchema: () => DroidHookSpecificOutputSchema,
|
|
93
102
|
DroidInteractionMode: () => DroidInteractionMode,
|
|
94
103
|
DroidMessageType: () => DroidMessageType,
|
|
95
104
|
DroidServerMethod: () => DroidServerMethod,
|
|
@@ -130,6 +139,10 @@ __export(index_exports, {
|
|
|
130
139
|
GitRepoInfoSchema: () => GitRepoInfoSchema,
|
|
131
140
|
HandoffItemsDismissedEntrySchema: () => HandoffItemsDismissedEntrySchema,
|
|
132
141
|
HandoffSchema: () => HandoffSchema,
|
|
142
|
+
HookCommandSchema: () => HookCommandSchema,
|
|
143
|
+
HookExecutionCompletedNotificationSchema: () => HookExecutionCompletedNotificationSchema,
|
|
144
|
+
HookExecutionStartedNotificationSchema: () => HookExecutionStartedNotificationSchema,
|
|
145
|
+
HookResultSchema: () => HookResultSchema,
|
|
133
146
|
HttpHeaderSchema: () => HttpHeaderSchema,
|
|
134
147
|
HttpMcpConfigSchema: () => HttpMcpConfigSchema,
|
|
135
148
|
ImageBlockSchema: () => ImageBlockSchema,
|
|
@@ -278,6 +291,8 @@ __export(index_exports, {
|
|
|
278
291
|
StartMissionRunConfirmationDetailsSchema: () => StartMissionRunConfirmationDetailsSchema,
|
|
279
292
|
StdioMcpConfigSchema: () => StdioMcpConfigSchema,
|
|
280
293
|
StreamStateTracker: () => StreamStateTracker,
|
|
294
|
+
StructuredOutputErrorSchema: () => StructuredOutputErrorSchema,
|
|
295
|
+
StructuredOutputNotificationSchema: () => StructuredOutputNotificationSchema,
|
|
281
296
|
SubmitBugReportRequestParamsSchema: () => SubmitBugReportRequestParamsSchema,
|
|
282
297
|
SubmitBugReportRequestSchema: () => SubmitBugReportRequestSchema,
|
|
283
298
|
SubmitBugReportResponseSchema: () => SubmitBugReportResponseSchema,
|
|
@@ -292,6 +307,7 @@ __export(index_exports, {
|
|
|
292
307
|
TestsSchema: () => TestsSchema,
|
|
293
308
|
TextBlockSchema: () => TextBlockSchema,
|
|
294
309
|
ThinkingBlockSchema: () => ThinkingBlockSchema,
|
|
310
|
+
ThinkingTextCompleteNotificationSchema: () => ThinkingTextCompleteNotificationSchema,
|
|
295
311
|
ThinkingTextDeltaNotificationSchema: () => ThinkingTextDeltaNotificationSchema,
|
|
296
312
|
TimeoutError: () => TimeoutError,
|
|
297
313
|
ToggleMcpServerRequestParamsSchema: () => ToggleMcpServerRequestParamsSchema,
|
|
@@ -303,6 +319,7 @@ __export(index_exports, {
|
|
|
303
319
|
ToggleMcpToolResponseSchema: () => ToggleMcpToolResponseSchema,
|
|
304
320
|
ToggleMcpToolResultSchema: () => ToggleMcpToolResultSchema,
|
|
305
321
|
TokenUsageSchema: () => TokenUsageSchema,
|
|
322
|
+
ToolCallNotificationSchema: () => ToolCallNotificationSchema,
|
|
306
323
|
ToolConfirmationDetailsSchema: () => ToolConfirmationDetailsSchema,
|
|
307
324
|
ToolConfirmationInfoSchema: () => ToolConfirmationInfoSchema,
|
|
308
325
|
ToolConfirmationListItemSchema: () => ToolConfirmationListItemSchema,
|
|
@@ -329,10 +346,11 @@ __export(index_exports, {
|
|
|
329
346
|
WorkerStartedEntrySchema: () => WorkerStartedEntrySchema,
|
|
330
347
|
WorkerStateInfoSchema: () => WorkerStateInfoSchema,
|
|
331
348
|
convertNotificationToStreamMessage: () => convertNotificationToStreamMessage,
|
|
349
|
+
createResponseSchema: () => createResponseSchema,
|
|
332
350
|
createSdkMcpServer: () => createSdkMcpServer,
|
|
333
351
|
createSession: () => createSession,
|
|
352
|
+
dispatchNotification: () => dispatchNotification,
|
|
334
353
|
listSessions: () => listSessions,
|
|
335
|
-
query: () => query,
|
|
336
354
|
resumeSession: () => resumeSession,
|
|
337
355
|
run: () => run,
|
|
338
356
|
tool: () => tool
|
|
@@ -344,6 +362,7 @@ var DroidServerMethod = /* @__PURE__ */ ((DroidServerMethod2) => {
|
|
|
344
362
|
DroidServerMethod2["INITIALIZE_SESSION"] = "droid.initialize_session";
|
|
345
363
|
DroidServerMethod2["LOAD_SESSION"] = "droid.load_session";
|
|
346
364
|
DroidServerMethod2["ADD_USER_MESSAGE"] = "droid.add_user_message";
|
|
365
|
+
DroidServerMethod2["CLOSE_SESSION"] = "droid.close_session";
|
|
347
366
|
DroidServerMethod2["INTERRUPT_SESSION"] = "droid.interrupt_session";
|
|
348
367
|
DroidServerMethod2["KILL_WORKER_SESSION"] = "droid.kill_worker_session";
|
|
349
368
|
DroidServerMethod2["UPDATE_SESSION_SETTINGS"] = "droid.update_session_settings";
|
|
@@ -386,7 +405,10 @@ var SessionNotificationType = /* @__PURE__ */ ((SessionNotificationType2) => {
|
|
|
386
405
|
SessionNotificationType2["SESSION_TITLE_UPDATED"] = "session_title_updated";
|
|
387
406
|
SessionNotificationType2["MCP_STATUS_CHANGED"] = "mcp_status_changed";
|
|
388
407
|
SessionNotificationType2["ASSISTANT_TEXT_DELTA"] = "assistant_text_delta";
|
|
408
|
+
SessionNotificationType2["ASSISTANT_TEXT_COMPLETE"] = "assistant_text_complete";
|
|
389
409
|
SessionNotificationType2["THINKING_TEXT_DELTA"] = "thinking_text_delta";
|
|
410
|
+
SessionNotificationType2["THINKING_TEXT_COMPLETE"] = "thinking_text_complete";
|
|
411
|
+
SessionNotificationType2["TOOL_CALL"] = "tool_call";
|
|
390
412
|
SessionNotificationType2["SESSION_TOKEN_USAGE_CHANGED"] = "session_token_usage_changed";
|
|
391
413
|
SessionNotificationType2["MISSION_STATE_CHANGED"] = "mission_state_changed";
|
|
392
414
|
SessionNotificationType2["MISSION_FEATURES_CHANGED"] = "mission_features_changed";
|
|
@@ -396,6 +418,9 @@ var SessionNotificationType = /* @__PURE__ */ ((SessionNotificationType2) => {
|
|
|
396
418
|
SessionNotificationType2["MISSION_WORKER_COMPLETED"] = "mission_worker_completed";
|
|
397
419
|
SessionNotificationType2["MCP_AUTH_REQUIRED"] = "mcp_auth_required";
|
|
398
420
|
SessionNotificationType2["MCP_AUTH_COMPLETED"] = "mcp_auth_completed";
|
|
421
|
+
SessionNotificationType2["HOOK_EXECUTION_STARTED"] = "hook_execution_started";
|
|
422
|
+
SessionNotificationType2["HOOK_EXECUTION_COMPLETED"] = "hook_execution_completed";
|
|
423
|
+
SessionNotificationType2["STRUCTURED_OUTPUT"] = "structured_output";
|
|
399
424
|
return SessionNotificationType2;
|
|
400
425
|
})(SessionNotificationType || {});
|
|
401
426
|
var ToolConfirmationOutcome = /* @__PURE__ */ ((ToolConfirmationOutcome3) => {
|
|
@@ -700,6 +725,12 @@ var JsonRpcMessageSchema = import_zod.z.discriminatedUnion("type", [
|
|
|
700
725
|
}),
|
|
701
726
|
JsonRpcNotificationSchema
|
|
702
727
|
]);
|
|
728
|
+
function createResponseSchema(resultSchema) {
|
|
729
|
+
return import_zod.z.union([
|
|
730
|
+
JsonRpcResponseSuccessSchema.extend({ result: resultSchema }),
|
|
731
|
+
JsonRpcResponseFailureSchema
|
|
732
|
+
]);
|
|
733
|
+
}
|
|
703
734
|
|
|
704
735
|
// src/schemas/session-metadata.ts
|
|
705
736
|
var import_zod6 = require("zod");
|
|
@@ -1147,6 +1178,9 @@ var AddUserMessageRequestParamsSchema = import_zod5.z.object({
|
|
|
1147
1178
|
outputFormat: OutputFormatSchema.optional()
|
|
1148
1179
|
}).strict();
|
|
1149
1180
|
var InterruptSessionRequestParamsSchema = import_zod5.z.object({}).strict();
|
|
1181
|
+
var CloseSessionRequestParamsSchema = import_zod5.z.object({
|
|
1182
|
+
reason: import_zod5.z.enum(["clear", "logout", "prompt_input_exit", "other"]).optional()
|
|
1183
|
+
}).strict();
|
|
1150
1184
|
var KillWorkerSessionRequestParamsSchema = import_zod5.z.object({
|
|
1151
1185
|
workerSessionId: import_zod5.z.string()
|
|
1152
1186
|
}).strict();
|
|
@@ -1263,6 +1297,10 @@ var InterruptSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
|
1263
1297
|
method: import_zod5.z.literal("droid.interrupt_session" /* INTERRUPT_SESSION */),
|
|
1264
1298
|
params: InterruptSessionRequestParamsSchema
|
|
1265
1299
|
});
|
|
1300
|
+
var CloseSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1301
|
+
method: import_zod5.z.literal("droid.close_session" /* CLOSE_SESSION */),
|
|
1302
|
+
params: CloseSessionRequestParamsSchema
|
|
1303
|
+
});
|
|
1266
1304
|
var KillWorkerSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1267
1305
|
method: import_zod5.z.literal("droid.kill_worker_session" /* KILL_WORKER_SESSION */),
|
|
1268
1306
|
params: KillWorkerSessionRequestParamsSchema
|
|
@@ -1355,6 +1393,7 @@ var ClientRequestSchema = import_zod5.z.discriminatedUnion("method", [
|
|
|
1355
1393
|
InitializeSessionRequestSchema,
|
|
1356
1394
|
LoadSessionRequestSchema,
|
|
1357
1395
|
AddUserMessageRequestSchema,
|
|
1396
|
+
CloseSessionRequestSchema,
|
|
1358
1397
|
InterruptSessionRequestSchema,
|
|
1359
1398
|
KillWorkerSessionRequestSchema,
|
|
1360
1399
|
UpdateSessionSettingsRequestSchema,
|
|
@@ -1415,6 +1454,7 @@ var LoadSessionResultSchema = import_zod5.z.object({
|
|
|
1415
1454
|
}).passthrough();
|
|
1416
1455
|
var AddUserMessageResultSchema = EmptyResultSchema;
|
|
1417
1456
|
var InterruptSessionResultSchema = EmptyResultSchema;
|
|
1457
|
+
var CloseSessionResultSchema = EmptyResultSchema;
|
|
1418
1458
|
var KillWorkerSessionResultSchema = EmptyResultSchema;
|
|
1419
1459
|
var UpdateSessionSettingsResultSchema = EmptyResultSchema;
|
|
1420
1460
|
var ToggleMcpServerResultSchema = SuccessResultSchema;
|
|
@@ -1455,127 +1495,88 @@ var ForkSessionResultSchema = import_zod5.z.object({
|
|
|
1455
1495
|
}).passthrough();
|
|
1456
1496
|
var GetContextStatsResultSchema = ContextStatsSchema;
|
|
1457
1497
|
var RenameSessionResultSchema = SuccessResultSchema;
|
|
1458
|
-
var InitializeSessionResponseSchema =
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
var _LoadSessionResponseSchema = import_zod5.z.union([
|
|
1465
|
-
JsonRpcResponseSuccessSchema.extend({ result: LoadSessionResultSchema }),
|
|
1466
|
-
JsonRpcResponseFailureSchema
|
|
1467
|
-
]);
|
|
1498
|
+
var InitializeSessionResponseSchema = createResponseSchema(
|
|
1499
|
+
InitializeSessionResultSchema
|
|
1500
|
+
);
|
|
1501
|
+
var _LoadSessionResponseSchema = createResponseSchema(
|
|
1502
|
+
LoadSessionResultSchema
|
|
1503
|
+
);
|
|
1468
1504
|
var LoadSessionResponseSchema = _LoadSessionResponseSchema;
|
|
1469
|
-
var AddUserMessageResponseSchema =
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
var
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
var
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
var
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
JsonRpcResponseSuccessSchema.extend({ result: ToggleMcpToolResultSchema }),
|
|
1545
|
-
JsonRpcResponseFailureSchema
|
|
1546
|
-
]);
|
|
1547
|
-
var ListSkillsResponseSchema = import_zod5.z.union([
|
|
1548
|
-
JsonRpcResponseSuccessSchema.extend({ result: ListSkillsResultSchema }),
|
|
1549
|
-
JsonRpcResponseFailureSchema
|
|
1550
|
-
]);
|
|
1551
|
-
var SubmitBugReportResponseSchema = import_zod5.z.union([
|
|
1552
|
-
JsonRpcResponseSuccessSchema.extend({ result: SubmitBugReportResultSchema }),
|
|
1553
|
-
JsonRpcResponseFailureSchema
|
|
1554
|
-
]);
|
|
1555
|
-
var GetRewindInfoResponseSchema = import_zod5.z.union([
|
|
1556
|
-
JsonRpcResponseSuccessSchema.extend({ result: GetRewindInfoResultSchema }),
|
|
1557
|
-
JsonRpcResponseFailureSchema
|
|
1558
|
-
]);
|
|
1559
|
-
var ExecuteRewindResponseSchema = import_zod5.z.union([
|
|
1560
|
-
JsonRpcResponseSuccessSchema.extend({ result: ExecuteRewindResultSchema }),
|
|
1561
|
-
JsonRpcResponseFailureSchema
|
|
1562
|
-
]);
|
|
1563
|
-
var CompactSessionResponseSchema = import_zod5.z.union([
|
|
1564
|
-
JsonRpcResponseSuccessSchema.extend({ result: CompactSessionResultSchema }),
|
|
1565
|
-
JsonRpcResponseFailureSchema
|
|
1566
|
-
]);
|
|
1567
|
-
var ForkSessionResponseSchema = import_zod5.z.union([
|
|
1568
|
-
JsonRpcResponseSuccessSchema.extend({ result: ForkSessionResultSchema }),
|
|
1569
|
-
JsonRpcResponseFailureSchema
|
|
1570
|
-
]);
|
|
1571
|
-
var GetContextStatsResponseSchema = import_zod5.z.union([
|
|
1572
|
-
JsonRpcResponseSuccessSchema.extend({ result: GetContextStatsResultSchema }),
|
|
1573
|
-
JsonRpcResponseFailureSchema
|
|
1574
|
-
]);
|
|
1575
|
-
var RenameSessionResponseSchema = import_zod5.z.union([
|
|
1576
|
-
JsonRpcResponseSuccessSchema.extend({ result: RenameSessionResultSchema }),
|
|
1577
|
-
JsonRpcResponseFailureSchema
|
|
1578
|
-
]);
|
|
1505
|
+
var AddUserMessageResponseSchema = createResponseSchema(
|
|
1506
|
+
AddUserMessageResultSchema
|
|
1507
|
+
);
|
|
1508
|
+
var InterruptSessionResponseSchema = createResponseSchema(
|
|
1509
|
+
InterruptSessionResultSchema
|
|
1510
|
+
);
|
|
1511
|
+
var CloseSessionResponseSchema = createResponseSchema(
|
|
1512
|
+
CloseSessionResultSchema
|
|
1513
|
+
);
|
|
1514
|
+
var KillWorkerSessionResponseSchema = createResponseSchema(
|
|
1515
|
+
KillWorkerSessionResultSchema
|
|
1516
|
+
);
|
|
1517
|
+
var UpdateSessionSettingsResponseSchema = createResponseSchema(
|
|
1518
|
+
UpdateSessionSettingsResultSchema
|
|
1519
|
+
);
|
|
1520
|
+
var ToggleMcpServerResponseSchema = createResponseSchema(
|
|
1521
|
+
ToggleMcpServerResultSchema
|
|
1522
|
+
);
|
|
1523
|
+
var AuthenticateMcpServerResponseSchema = createResponseSchema(
|
|
1524
|
+
AuthenticateMcpServerResultSchema
|
|
1525
|
+
);
|
|
1526
|
+
var CancelMcpAuthResponseSchema = createResponseSchema(
|
|
1527
|
+
CancelMcpAuthResultSchema
|
|
1528
|
+
);
|
|
1529
|
+
var ClearMcpAuthResponseSchema = createResponseSchema(
|
|
1530
|
+
ClearMcpAuthResultSchema
|
|
1531
|
+
);
|
|
1532
|
+
var SubmitMcpAuthCodeResponseSchema = createResponseSchema(
|
|
1533
|
+
SubmitMcpAuthCodeResultSchema
|
|
1534
|
+
);
|
|
1535
|
+
var AddMcpServerResponseSchema = createResponseSchema(
|
|
1536
|
+
AddMcpServerResultSchema
|
|
1537
|
+
);
|
|
1538
|
+
var RemoveMcpServerResponseSchema = createResponseSchema(
|
|
1539
|
+
RemoveMcpServerResultSchema
|
|
1540
|
+
);
|
|
1541
|
+
var ListMcpRegistryResponseSchema = createResponseSchema(
|
|
1542
|
+
ListMcpRegistryResultSchema
|
|
1543
|
+
);
|
|
1544
|
+
var ListMcpToolsResponseSchema = createResponseSchema(
|
|
1545
|
+
ListMcpToolsResultSchema
|
|
1546
|
+
);
|
|
1547
|
+
var ListToolsResponseSchema = createResponseSchema(
|
|
1548
|
+
ListToolsResultSchema
|
|
1549
|
+
);
|
|
1550
|
+
var ListMcpServersResponseSchema = createResponseSchema(
|
|
1551
|
+
ListMcpServersResultSchema
|
|
1552
|
+
);
|
|
1553
|
+
var ToggleMcpToolResponseSchema = createResponseSchema(
|
|
1554
|
+
ToggleMcpToolResultSchema
|
|
1555
|
+
);
|
|
1556
|
+
var ListSkillsResponseSchema = createResponseSchema(
|
|
1557
|
+
ListSkillsResultSchema
|
|
1558
|
+
);
|
|
1559
|
+
var SubmitBugReportResponseSchema = createResponseSchema(
|
|
1560
|
+
SubmitBugReportResultSchema
|
|
1561
|
+
);
|
|
1562
|
+
var GetRewindInfoResponseSchema = createResponseSchema(
|
|
1563
|
+
GetRewindInfoResultSchema
|
|
1564
|
+
);
|
|
1565
|
+
var ExecuteRewindResponseSchema = createResponseSchema(
|
|
1566
|
+
ExecuteRewindResultSchema
|
|
1567
|
+
);
|
|
1568
|
+
var CompactSessionResponseSchema = createResponseSchema(
|
|
1569
|
+
CompactSessionResultSchema
|
|
1570
|
+
);
|
|
1571
|
+
var ForkSessionResponseSchema = createResponseSchema(
|
|
1572
|
+
ForkSessionResultSchema
|
|
1573
|
+
);
|
|
1574
|
+
var GetContextStatsResponseSchema = createResponseSchema(
|
|
1575
|
+
GetContextStatsResultSchema
|
|
1576
|
+
);
|
|
1577
|
+
var RenameSessionResponseSchema = createResponseSchema(
|
|
1578
|
+
RenameSessionResultSchema
|
|
1579
|
+
);
|
|
1579
1580
|
|
|
1580
1581
|
// src/schemas/session-metadata.ts
|
|
1581
1582
|
var SessionMetadataSchema = import_zod6.z.object({
|
|
@@ -1606,140 +1607,231 @@ var SessionSettingsFileSchema = import_zod6.z.object({
|
|
|
1606
1607
|
tags: import_zod6.z.array(SessionTagSchema).optional()
|
|
1607
1608
|
}).passthrough();
|
|
1608
1609
|
|
|
1609
|
-
// src/schemas/
|
|
1610
|
+
// src/schemas/hooks.ts
|
|
1610
1611
|
var import_zod7 = require("zod");
|
|
1612
|
+
var DroidHookEventSchema = import_zod7.z.enum([
|
|
1613
|
+
"PreToolUse",
|
|
1614
|
+
"PostToolUse",
|
|
1615
|
+
"Notification",
|
|
1616
|
+
"UserPromptSubmit",
|
|
1617
|
+
"Stop",
|
|
1618
|
+
"SubagentStop",
|
|
1619
|
+
"PreCompact",
|
|
1620
|
+
"SessionStart",
|
|
1621
|
+
"SessionEnd"
|
|
1622
|
+
]);
|
|
1623
|
+
var DroidHookSpecificOutputSchema = import_zod7.z.object({
|
|
1624
|
+
hookEventName: DroidHookEventSchema.optional(),
|
|
1625
|
+
permissionDecision: import_zod7.z.enum(["allow", "deny", "ask"]).optional(),
|
|
1626
|
+
permissionDecisionReason: import_zod7.z.string().optional(),
|
|
1627
|
+
additionalContext: import_zod7.z.string().optional(),
|
|
1628
|
+
updatedInput: import_zod7.z.record(import_zod7.z.unknown()).optional()
|
|
1629
|
+
}).passthrough();
|
|
1630
|
+
var DroidHookOutputSchema = import_zod7.z.object({
|
|
1631
|
+
continue: import_zod7.z.boolean().optional(),
|
|
1632
|
+
stopReason: import_zod7.z.string().optional(),
|
|
1633
|
+
suppressOutput: import_zod7.z.boolean().optional(),
|
|
1634
|
+
systemMessage: import_zod7.z.string().optional(),
|
|
1635
|
+
decision: import_zod7.z.enum(["block", "approve"]).optional(),
|
|
1636
|
+
reason: import_zod7.z.string().optional(),
|
|
1637
|
+
hookSpecificOutput: DroidHookSpecificOutputSchema.optional()
|
|
1638
|
+
}).passthrough();
|
|
1639
|
+
var DroidHookExecutionResultSchema = DroidHookOutputSchema.extend({
|
|
1640
|
+
exitCode: import_zod7.z.number(),
|
|
1641
|
+
stdout: import_zod7.z.string(),
|
|
1642
|
+
stderr: import_zod7.z.string()
|
|
1643
|
+
});
|
|
1644
|
+
|
|
1645
|
+
// src/schemas/server.ts
|
|
1646
|
+
var import_zod8 = require("zod");
|
|
1611
1647
|
var ToolUseBlockSchema2 = ToolUseBlockSchema;
|
|
1612
1648
|
var ToolUseSchema = ToolUseBlockSchema2;
|
|
1613
|
-
var ErrorDetailSchema =
|
|
1614
|
-
name:
|
|
1615
|
-
message:
|
|
1649
|
+
var ErrorDetailSchema = import_zod8.z.object({
|
|
1650
|
+
name: import_zod8.z.string(),
|
|
1651
|
+
message: import_zod8.z.string()
|
|
1616
1652
|
}).passthrough();
|
|
1617
|
-
var ToolProgressUpdateSchema =
|
|
1618
|
-
type:
|
|
1619
|
-
toolName:
|
|
1620
|
-
status:
|
|
1621
|
-
details:
|
|
1622
|
-
text:
|
|
1623
|
-
error:
|
|
1624
|
-
timestamp:
|
|
1653
|
+
var ToolProgressUpdateSchema = import_zod8.z.object({
|
|
1654
|
+
type: import_zod8.z.enum(["tool_call", "tool_result", "error", "status", "message"]),
|
|
1655
|
+
toolName: import_zod8.z.string().optional(),
|
|
1656
|
+
status: import_zod8.z.string().optional(),
|
|
1657
|
+
details: import_zod8.z.string().optional(),
|
|
1658
|
+
text: import_zod8.z.string().optional(),
|
|
1659
|
+
error: import_zod8.z.string().optional(),
|
|
1660
|
+
timestamp: import_zod8.z.number().optional(),
|
|
1625
1661
|
parameters: JsonObjectSchema.optional(),
|
|
1626
|
-
valueSnippet:
|
|
1627
|
-
subagentSessionId:
|
|
1662
|
+
valueSnippet: import_zod8.z.string().optional(),
|
|
1663
|
+
subagentSessionId: import_zod8.z.string().optional()
|
|
1628
1664
|
}).passthrough();
|
|
1629
|
-
var SettingsUpdatedPayloadSchema =
|
|
1630
|
-
autonomyMode:
|
|
1631
|
-
interactionMode:
|
|
1632
|
-
autonomyLevel:
|
|
1633
|
-
modelId:
|
|
1634
|
-
reasoningEffort:
|
|
1635
|
-
specModeModelId:
|
|
1636
|
-
specModeReasoningEffort:
|
|
1665
|
+
var SettingsUpdatedPayloadSchema = import_zod8.z.object({
|
|
1666
|
+
autonomyMode: import_zod8.z.nativeEnum(AutonomyMode).optional(),
|
|
1667
|
+
interactionMode: import_zod8.z.nativeEnum(DroidInteractionMode).optional().catch(void 0),
|
|
1668
|
+
autonomyLevel: import_zod8.z.nativeEnum(AutonomyLevel).optional().catch(void 0),
|
|
1669
|
+
modelId: import_zod8.z.string().optional(),
|
|
1670
|
+
reasoningEffort: import_zod8.z.nativeEnum(ReasoningEffort).optional(),
|
|
1671
|
+
specModeModelId: import_zod8.z.string().optional(),
|
|
1672
|
+
specModeReasoningEffort: import_zod8.z.nativeEnum(ReasoningEffort).optional(),
|
|
1637
1673
|
...ToolSelectionOverridesSchema.shape
|
|
1638
1674
|
}).passthrough();
|
|
1639
|
-
var ToolResultNotificationSchema =
|
|
1640
|
-
type:
|
|
1641
|
-
messageId:
|
|
1642
|
-
toolUseId:
|
|
1675
|
+
var ToolResultNotificationSchema = import_zod8.z.object({
|
|
1676
|
+
type: import_zod8.z.literal("tool_result" /* TOOL_RESULT */),
|
|
1677
|
+
messageId: import_zod8.z.string(),
|
|
1678
|
+
toolUseId: import_zod8.z.string(),
|
|
1643
1679
|
content: JsonValueSchema.optional(),
|
|
1644
|
-
isError:
|
|
1645
|
-
id:
|
|
1680
|
+
isError: import_zod8.z.boolean().optional(),
|
|
1681
|
+
id: import_zod8.z.string().optional()
|
|
1646
1682
|
}).passthrough();
|
|
1647
|
-
var ToolProgressUpdateNotificationSchema =
|
|
1648
|
-
type:
|
|
1649
|
-
toolUseId:
|
|
1650
|
-
toolName:
|
|
1683
|
+
var ToolProgressUpdateNotificationSchema = import_zod8.z.object({
|
|
1684
|
+
type: import_zod8.z.literal("tool_progress_update" /* TOOL_PROGRESS_UPDATE */),
|
|
1685
|
+
toolUseId: import_zod8.z.string(),
|
|
1686
|
+
toolName: import_zod8.z.string(),
|
|
1651
1687
|
update: ToolProgressUpdateSchema
|
|
1652
1688
|
}).passthrough();
|
|
1653
|
-
var CreateMessageNotificationSchema =
|
|
1654
|
-
type:
|
|
1689
|
+
var CreateMessageNotificationSchema = import_zod8.z.object({
|
|
1690
|
+
type: import_zod8.z.literal("create_message" /* CREATE_MESSAGE */),
|
|
1655
1691
|
message: FactoryDroidMessageSchema,
|
|
1656
|
-
parentId:
|
|
1657
|
-
requestId:
|
|
1692
|
+
parentId: import_zod8.z.string().optional(),
|
|
1693
|
+
requestId: import_zod8.z.string().optional()
|
|
1658
1694
|
}).passthrough();
|
|
1659
|
-
var ErrorNotificationSchema =
|
|
1660
|
-
type:
|
|
1661
|
-
message:
|
|
1662
|
-
errorType:
|
|
1663
|
-
timestamp:
|
|
1695
|
+
var ErrorNotificationSchema = import_zod8.z.object({
|
|
1696
|
+
type: import_zod8.z.literal("error" /* ERROR */),
|
|
1697
|
+
message: import_zod8.z.string(),
|
|
1698
|
+
errorType: import_zod8.z.nativeEnum(DroidErrorType),
|
|
1699
|
+
timestamp: import_zod8.z.string(),
|
|
1664
1700
|
error: ErrorDetailSchema.optional()
|
|
1665
1701
|
}).passthrough();
|
|
1666
|
-
var DroidWorkingStateChangedNotificationSchema =
|
|
1667
|
-
type:
|
|
1668
|
-
newState:
|
|
1702
|
+
var DroidWorkingStateChangedNotificationSchema = import_zod8.z.object({
|
|
1703
|
+
type: import_zod8.z.literal("droid_working_state_changed" /* DROID_WORKING_STATE_CHANGED */),
|
|
1704
|
+
newState: import_zod8.z.nativeEnum(DroidWorkingState)
|
|
1669
1705
|
}).passthrough();
|
|
1670
|
-
var PermissionResolvedNotificationSchema =
|
|
1671
|
-
type:
|
|
1672
|
-
requestId:
|
|
1673
|
-
toolUseIds:
|
|
1674
|
-
selectedOption:
|
|
1706
|
+
var PermissionResolvedNotificationSchema = import_zod8.z.object({
|
|
1707
|
+
type: import_zod8.z.literal("permission_resolved" /* PERMISSION_RESOLVED */),
|
|
1708
|
+
requestId: import_zod8.z.string(),
|
|
1709
|
+
toolUseIds: import_zod8.z.array(import_zod8.z.string()),
|
|
1710
|
+
selectedOption: import_zod8.z.nativeEnum(ToolConfirmationOutcome)
|
|
1675
1711
|
}).passthrough();
|
|
1676
|
-
var SettingsUpdatedNotificationSchema =
|
|
1677
|
-
type:
|
|
1712
|
+
var SettingsUpdatedNotificationSchema = import_zod8.z.object({
|
|
1713
|
+
type: import_zod8.z.literal("settings_updated" /* SETTINGS_UPDATED */),
|
|
1678
1714
|
settings: SettingsUpdatedPayloadSchema
|
|
1679
1715
|
}).passthrough();
|
|
1680
|
-
var SessionTitleUpdatedNotificationSchema =
|
|
1681
|
-
type:
|
|
1682
|
-
title:
|
|
1716
|
+
var SessionTitleUpdatedNotificationSchema = import_zod8.z.object({
|
|
1717
|
+
type: import_zod8.z.literal("session_title_updated" /* SESSION_TITLE_UPDATED */),
|
|
1718
|
+
title: import_zod8.z.string()
|
|
1683
1719
|
}).passthrough();
|
|
1684
|
-
var McpStatusChangedNotificationSchema =
|
|
1685
|
-
type:
|
|
1686
|
-
servers:
|
|
1720
|
+
var McpStatusChangedNotificationSchema = import_zod8.z.object({
|
|
1721
|
+
type: import_zod8.z.literal("mcp_status_changed" /* MCP_STATUS_CHANGED */),
|
|
1722
|
+
servers: import_zod8.z.array(McpServerStatusInfoSchema),
|
|
1687
1723
|
summary: McpStatusSummarySchema
|
|
1688
1724
|
}).passthrough();
|
|
1689
|
-
var AssistantTextDeltaNotificationSchema =
|
|
1690
|
-
type:
|
|
1691
|
-
messageId:
|
|
1692
|
-
blockIndex:
|
|
1693
|
-
textDelta:
|
|
1725
|
+
var AssistantTextDeltaNotificationSchema = import_zod8.z.object({
|
|
1726
|
+
type: import_zod8.z.literal("assistant_text_delta" /* ASSISTANT_TEXT_DELTA */),
|
|
1727
|
+
messageId: import_zod8.z.string(),
|
|
1728
|
+
blockIndex: import_zod8.z.number(),
|
|
1729
|
+
textDelta: import_zod8.z.string()
|
|
1730
|
+
}).passthrough();
|
|
1731
|
+
var AssistantTextCompleteNotificationSchema = import_zod8.z.object({
|
|
1732
|
+
type: import_zod8.z.literal("assistant_text_complete" /* ASSISTANT_TEXT_COMPLETE */),
|
|
1733
|
+
messageId: import_zod8.z.string(),
|
|
1734
|
+
blockIndex: import_zod8.z.number()
|
|
1694
1735
|
}).passthrough();
|
|
1695
|
-
var ThinkingTextDeltaNotificationSchema =
|
|
1696
|
-
type:
|
|
1697
|
-
messageId:
|
|
1698
|
-
blockIndex:
|
|
1699
|
-
textDelta:
|
|
1736
|
+
var ThinkingTextDeltaNotificationSchema = import_zod8.z.object({
|
|
1737
|
+
type: import_zod8.z.literal("thinking_text_delta" /* THINKING_TEXT_DELTA */),
|
|
1738
|
+
messageId: import_zod8.z.string(),
|
|
1739
|
+
blockIndex: import_zod8.z.number(),
|
|
1740
|
+
textDelta: import_zod8.z.string()
|
|
1700
1741
|
}).passthrough();
|
|
1701
|
-
var
|
|
1702
|
-
type:
|
|
1703
|
-
|
|
1742
|
+
var ThinkingTextCompleteNotificationSchema = import_zod8.z.object({
|
|
1743
|
+
type: import_zod8.z.literal("thinking_text_complete" /* THINKING_TEXT_COMPLETE */),
|
|
1744
|
+
messageId: import_zod8.z.string(),
|
|
1745
|
+
blockIndex: import_zod8.z.number(),
|
|
1746
|
+
durationMs: import_zod8.z.number().optional()
|
|
1747
|
+
}).passthrough();
|
|
1748
|
+
var ToolCallNotificationSchema = import_zod8.z.object({
|
|
1749
|
+
type: import_zod8.z.literal("tool_call" /* TOOL_CALL */),
|
|
1750
|
+
toolUse: ToolUseBlockSchema2
|
|
1751
|
+
}).passthrough();
|
|
1752
|
+
var SessionTokenUsageChangedNotificationSchema = import_zod8.z.object({
|
|
1753
|
+
type: import_zod8.z.literal("session_token_usage_changed" /* SESSION_TOKEN_USAGE_CHANGED */),
|
|
1754
|
+
sessionId: import_zod8.z.string(),
|
|
1704
1755
|
tokenUsage: TokenUsageSchema
|
|
1705
1756
|
}).passthrough();
|
|
1706
|
-
var MissionStateChangedNotificationSchema =
|
|
1707
|
-
type:
|
|
1708
|
-
state:
|
|
1757
|
+
var MissionStateChangedNotificationSchema = import_zod8.z.object({
|
|
1758
|
+
type: import_zod8.z.literal("mission_state_changed" /* MISSION_STATE_CHANGED */),
|
|
1759
|
+
state: import_zod8.z.nativeEnum(MissionState)
|
|
1760
|
+
}).passthrough();
|
|
1761
|
+
var MissionFeaturesChangedNotificationSchema = import_zod8.z.object({
|
|
1762
|
+
type: import_zod8.z.literal("mission_features_changed" /* MISSION_FEATURES_CHANGED */),
|
|
1763
|
+
features: import_zod8.z.array(MissionFeatureSchema)
|
|
1764
|
+
}).passthrough();
|
|
1765
|
+
var MissionProgressEntryNotificationSchema = import_zod8.z.object({
|
|
1766
|
+
type: import_zod8.z.literal("mission_progress_entry" /* MISSION_PROGRESS_ENTRY */),
|
|
1767
|
+
progressLog: import_zod8.z.array(ProgressLogEntrySchema)
|
|
1709
1768
|
}).passthrough();
|
|
1710
|
-
var
|
|
1711
|
-
type:
|
|
1712
|
-
|
|
1769
|
+
var MissionHeartbeatNotificationSchema = import_zod8.z.object({
|
|
1770
|
+
type: import_zod8.z.literal("mission_heartbeat" /* MISSION_HEARTBEAT */),
|
|
1771
|
+
timestamp: import_zod8.z.string()
|
|
1713
1772
|
}).passthrough();
|
|
1714
|
-
var
|
|
1715
|
-
type:
|
|
1716
|
-
|
|
1773
|
+
var MissionWorkerStartedNotificationSchema = import_zod8.z.object({
|
|
1774
|
+
type: import_zod8.z.literal("mission_worker_started" /* MISSION_WORKER_STARTED */),
|
|
1775
|
+
workerSessionId: import_zod8.z.string()
|
|
1717
1776
|
}).passthrough();
|
|
1718
|
-
var
|
|
1719
|
-
type:
|
|
1720
|
-
|
|
1777
|
+
var MissionWorkerCompletedNotificationSchema = import_zod8.z.object({
|
|
1778
|
+
type: import_zod8.z.literal("mission_worker_completed" /* MISSION_WORKER_COMPLETED */),
|
|
1779
|
+
workerSessionId: import_zod8.z.string(),
|
|
1780
|
+
exitCode: import_zod8.z.number()
|
|
1721
1781
|
}).passthrough();
|
|
1722
|
-
var
|
|
1723
|
-
type:
|
|
1724
|
-
|
|
1782
|
+
var McpAuthRequiredNotificationSchema = import_zod8.z.object({
|
|
1783
|
+
type: import_zod8.z.literal("mcp_auth_required" /* MCP_AUTH_REQUIRED */),
|
|
1784
|
+
serverName: import_zod8.z.string(),
|
|
1785
|
+
authUrl: import_zod8.z.string(),
|
|
1786
|
+
message: import_zod8.z.string(),
|
|
1787
|
+
state: import_zod8.z.string()
|
|
1725
1788
|
}).passthrough();
|
|
1726
|
-
var
|
|
1727
|
-
type:
|
|
1728
|
-
|
|
1729
|
-
|
|
1789
|
+
var McpAuthCompletedNotificationSchema = import_zod8.z.object({
|
|
1790
|
+
type: import_zod8.z.literal("mcp_auth_completed" /* MCP_AUTH_COMPLETED */),
|
|
1791
|
+
serverName: import_zod8.z.string(),
|
|
1792
|
+
outcome: import_zod8.z.nativeEnum(McpAuthOutcome),
|
|
1793
|
+
message: import_zod8.z.string()
|
|
1730
1794
|
}).passthrough();
|
|
1731
|
-
var
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
authUrl: import_zod7.z.string(),
|
|
1735
|
-
message: import_zod7.z.string(),
|
|
1736
|
-
state: import_zod7.z.string()
|
|
1795
|
+
var HookCommandSchema = import_zod8.z.object({
|
|
1796
|
+
command: import_zod8.z.string(),
|
|
1797
|
+
timeout: import_zod8.z.number().optional()
|
|
1737
1798
|
}).passthrough();
|
|
1738
|
-
var
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1799
|
+
var HookResultSchema = import_zod8.z.object({
|
|
1800
|
+
exitCode: import_zod8.z.number(),
|
|
1801
|
+
stdout: import_zod8.z.string(),
|
|
1802
|
+
stderr: import_zod8.z.string(),
|
|
1803
|
+
command: import_zod8.z.string().optional(),
|
|
1804
|
+
timeout: import_zod8.z.number().optional()
|
|
1805
|
+
}).passthrough();
|
|
1806
|
+
var HookExecutionStartedNotificationSchema = import_zod8.z.object({
|
|
1807
|
+
type: import_zod8.z.literal("hook_execution_started" /* HOOK_EXECUTION_STARTED */),
|
|
1808
|
+
hookId: import_zod8.z.string(),
|
|
1809
|
+
hookEventName: DroidHookEventSchema,
|
|
1810
|
+
hookMatcher: import_zod8.z.string().optional(),
|
|
1811
|
+
hookCommands: import_zod8.z.array(HookCommandSchema),
|
|
1812
|
+
hookToolCallId: import_zod8.z.string().optional(),
|
|
1813
|
+
isParallelExecution: import_zod8.z.boolean().optional(),
|
|
1814
|
+
parallelGroupId: import_zod8.z.string().optional()
|
|
1815
|
+
}).passthrough();
|
|
1816
|
+
var HookExecutionCompletedNotificationSchema = import_zod8.z.object({
|
|
1817
|
+
type: import_zod8.z.literal("hook_execution_completed" /* HOOK_EXECUTION_COMPLETED */),
|
|
1818
|
+
hookId: import_zod8.z.string(),
|
|
1819
|
+
hookEventName: DroidHookEventSchema.optional(),
|
|
1820
|
+
hookMatcher: import_zod8.z.string().optional(),
|
|
1821
|
+
hookToolCallId: import_zod8.z.string().optional(),
|
|
1822
|
+
hookStatus: import_zod8.z.enum(["completed", "error"]),
|
|
1823
|
+
hookResults: import_zod8.z.array(HookResultSchema).optional()
|
|
1824
|
+
}).passthrough();
|
|
1825
|
+
var StructuredOutputErrorSchema = import_zod8.z.object({
|
|
1826
|
+
code: import_zod8.z.string(),
|
|
1827
|
+
message: import_zod8.z.string(),
|
|
1828
|
+
details: import_zod8.z.unknown().optional()
|
|
1829
|
+
}).passthrough();
|
|
1830
|
+
var StructuredOutputNotificationSchema = import_zod8.z.object({
|
|
1831
|
+
type: import_zod8.z.literal("structured_output" /* STRUCTURED_OUTPUT */),
|
|
1832
|
+
messageId: import_zod8.z.string(),
|
|
1833
|
+
structuredOutput: JsonObjectSchema.nullable(),
|
|
1834
|
+
structuredOutputError: StructuredOutputErrorSchema.nullable()
|
|
1743
1835
|
}).passthrough();
|
|
1744
1836
|
var SessionNotificationSchemaList = [
|
|
1745
1837
|
ToolResultNotificationSchema,
|
|
@@ -1752,7 +1844,10 @@ var SessionNotificationSchemaList = [
|
|
|
1752
1844
|
SessionTitleUpdatedNotificationSchema,
|
|
1753
1845
|
McpStatusChangedNotificationSchema,
|
|
1754
1846
|
AssistantTextDeltaNotificationSchema,
|
|
1847
|
+
AssistantTextCompleteNotificationSchema,
|
|
1755
1848
|
ThinkingTextDeltaNotificationSchema,
|
|
1849
|
+
ThinkingTextCompleteNotificationSchema,
|
|
1850
|
+
ToolCallNotificationSchema,
|
|
1756
1851
|
SessionTokenUsageChangedNotificationSchema,
|
|
1757
1852
|
MissionStateChangedNotificationSchema,
|
|
1758
1853
|
MissionFeaturesChangedNotificationSchema,
|
|
@@ -1761,88 +1856,91 @@ var SessionNotificationSchemaList = [
|
|
|
1761
1856
|
MissionWorkerStartedNotificationSchema,
|
|
1762
1857
|
MissionWorkerCompletedNotificationSchema,
|
|
1763
1858
|
McpAuthRequiredNotificationSchema,
|
|
1764
|
-
McpAuthCompletedNotificationSchema
|
|
1859
|
+
McpAuthCompletedNotificationSchema,
|
|
1860
|
+
HookExecutionStartedNotificationSchema,
|
|
1861
|
+
HookExecutionCompletedNotificationSchema,
|
|
1862
|
+
StructuredOutputNotificationSchema
|
|
1765
1863
|
];
|
|
1766
|
-
var SessionNotificationPayloadSchema =
|
|
1864
|
+
var SessionNotificationPayloadSchema = import_zod8.z.discriminatedUnion(
|
|
1767
1865
|
"type",
|
|
1768
1866
|
SessionNotificationSchemaList
|
|
1769
1867
|
);
|
|
1770
|
-
var _SessionNotificationParamsSchema =
|
|
1868
|
+
var _SessionNotificationParamsSchema = import_zod8.z.object({
|
|
1771
1869
|
notification: SessionNotificationPayloadSchema
|
|
1772
1870
|
}).passthrough();
|
|
1773
1871
|
var SessionNotificationParamsSchema = _SessionNotificationParamsSchema;
|
|
1774
1872
|
var _SessionNotificationSchema = JsonRpcNotificationSchema.extend({
|
|
1775
|
-
method:
|
|
1873
|
+
method: import_zod8.z.literal("droid.session_notification" /* SESSION_NOTIFICATION */),
|
|
1776
1874
|
params: SessionNotificationParamsSchema
|
|
1777
1875
|
});
|
|
1778
1876
|
var SessionNotificationSchema = _SessionNotificationSchema;
|
|
1779
|
-
var EditToolConfirmationDetailsSchema =
|
|
1780
|
-
type:
|
|
1781
|
-
filePath:
|
|
1782
|
-
fileName:
|
|
1783
|
-
oldContent:
|
|
1784
|
-
newContent:
|
|
1877
|
+
var EditToolConfirmationDetailsSchema = import_zod8.z.object({
|
|
1878
|
+
type: import_zod8.z.literal("edit" /* Edit */),
|
|
1879
|
+
filePath: import_zod8.z.string(),
|
|
1880
|
+
fileName: import_zod8.z.string(),
|
|
1881
|
+
oldContent: import_zod8.z.string().optional(),
|
|
1882
|
+
newContent: import_zod8.z.string().optional()
|
|
1785
1883
|
}).passthrough();
|
|
1786
|
-
var ExecuteToolConfirmationDetailsSchema =
|
|
1787
|
-
type:
|
|
1788
|
-
fullCommand:
|
|
1789
|
-
command:
|
|
1790
|
-
extractedCommands:
|
|
1791
|
-
impactLevel:
|
|
1884
|
+
var ExecuteToolConfirmationDetailsSchema = import_zod8.z.object({
|
|
1885
|
+
type: import_zod8.z.literal("exec" /* Execute */),
|
|
1886
|
+
fullCommand: import_zod8.z.string(),
|
|
1887
|
+
command: import_zod8.z.string(),
|
|
1888
|
+
extractedCommands: import_zod8.z.array(import_zod8.z.string()).optional(),
|
|
1889
|
+
impactLevel: import_zod8.z.string().optional()
|
|
1792
1890
|
}).passthrough();
|
|
1793
|
-
var CreateToolConfirmationDetailsSchema =
|
|
1794
|
-
type:
|
|
1795
|
-
filePath:
|
|
1796
|
-
fileName:
|
|
1797
|
-
content:
|
|
1891
|
+
var CreateToolConfirmationDetailsSchema = import_zod8.z.object({
|
|
1892
|
+
type: import_zod8.z.literal("create" /* Create */),
|
|
1893
|
+
filePath: import_zod8.z.string(),
|
|
1894
|
+
fileName: import_zod8.z.string(),
|
|
1895
|
+
content: import_zod8.z.string()
|
|
1798
1896
|
}).passthrough();
|
|
1799
|
-
var AskUserQuestionSchema =
|
|
1800
|
-
index:
|
|
1801
|
-
topic:
|
|
1802
|
-
question:
|
|
1803
|
-
options:
|
|
1897
|
+
var AskUserQuestionSchema = import_zod8.z.object({
|
|
1898
|
+
index: import_zod8.z.number(),
|
|
1899
|
+
topic: import_zod8.z.string(),
|
|
1900
|
+
question: import_zod8.z.string(),
|
|
1901
|
+
options: import_zod8.z.array(import_zod8.z.string())
|
|
1804
1902
|
}).passthrough();
|
|
1805
|
-
var AskUserConfirmationDetailsSchema =
|
|
1806
|
-
type:
|
|
1807
|
-
questionnaire:
|
|
1808
|
-
parsed:
|
|
1809
|
-
questions:
|
|
1903
|
+
var AskUserConfirmationDetailsSchema = import_zod8.z.object({
|
|
1904
|
+
type: import_zod8.z.literal("ask_user" /* AskUser */),
|
|
1905
|
+
questionnaire: import_zod8.z.string(),
|
|
1906
|
+
parsed: import_zod8.z.object({
|
|
1907
|
+
questions: import_zod8.z.array(AskUserQuestionSchema)
|
|
1810
1908
|
}).optional(),
|
|
1811
|
-
parseError:
|
|
1812
|
-
message:
|
|
1813
|
-
line:
|
|
1909
|
+
parseError: import_zod8.z.object({
|
|
1910
|
+
message: import_zod8.z.string(),
|
|
1911
|
+
line: import_zod8.z.number().optional()
|
|
1814
1912
|
}).optional()
|
|
1815
1913
|
}).passthrough();
|
|
1816
|
-
var ExitSpecModeConfirmationDetailsSchema =
|
|
1817
|
-
type:
|
|
1818
|
-
plan:
|
|
1819
|
-
title:
|
|
1820
|
-
optionNames:
|
|
1914
|
+
var ExitSpecModeConfirmationDetailsSchema = import_zod8.z.object({
|
|
1915
|
+
type: import_zod8.z.literal("exit_spec_mode" /* ExitSpecMode */),
|
|
1916
|
+
plan: import_zod8.z.string(),
|
|
1917
|
+
title: import_zod8.z.string().optional(),
|
|
1918
|
+
optionNames: import_zod8.z.array(import_zod8.z.string()).optional()
|
|
1821
1919
|
}).passthrough();
|
|
1822
|
-
var ProposeMissionConfirmationDetailsSchema =
|
|
1823
|
-
type:
|
|
1824
|
-
proposal:
|
|
1825
|
-
title:
|
|
1920
|
+
var ProposeMissionConfirmationDetailsSchema = import_zod8.z.object({
|
|
1921
|
+
type: import_zod8.z.literal("propose_mission" /* ProposeMission */),
|
|
1922
|
+
proposal: import_zod8.z.string(),
|
|
1923
|
+
title: import_zod8.z.string().optional()
|
|
1826
1924
|
}).passthrough();
|
|
1827
|
-
var StartMissionRunConfirmationDetailsSchema =
|
|
1828
|
-
type:
|
|
1829
|
-
runningMissionCount:
|
|
1830
|
-
runningMissionSessionIds:
|
|
1925
|
+
var StartMissionRunConfirmationDetailsSchema = import_zod8.z.object({
|
|
1926
|
+
type: import_zod8.z.literal("start_mission_run" /* StartMissionRun */),
|
|
1927
|
+
runningMissionCount: import_zod8.z.number(),
|
|
1928
|
+
runningMissionSessionIds: import_zod8.z.array(import_zod8.z.string())
|
|
1831
1929
|
}).passthrough();
|
|
1832
|
-
var ApplyPatchToolConfirmationDetailsSchema =
|
|
1833
|
-
type:
|
|
1834
|
-
filePath:
|
|
1835
|
-
fileName:
|
|
1836
|
-
patchContent:
|
|
1837
|
-
oldContent:
|
|
1838
|
-
newContent:
|
|
1930
|
+
var ApplyPatchToolConfirmationDetailsSchema = import_zod8.z.object({
|
|
1931
|
+
type: import_zod8.z.literal("apply_patch" /* ApplyPatch */),
|
|
1932
|
+
filePath: import_zod8.z.string(),
|
|
1933
|
+
fileName: import_zod8.z.string(),
|
|
1934
|
+
patchContent: import_zod8.z.string(),
|
|
1935
|
+
oldContent: import_zod8.z.string().optional(),
|
|
1936
|
+
newContent: import_zod8.z.string().optional()
|
|
1839
1937
|
}).passthrough();
|
|
1840
|
-
var McpToolConfirmationDetailsSchema =
|
|
1841
|
-
type:
|
|
1842
|
-
toolName:
|
|
1843
|
-
impactLevel:
|
|
1938
|
+
var McpToolConfirmationDetailsSchema = import_zod8.z.object({
|
|
1939
|
+
type: import_zod8.z.literal("mcp_tool" /* McpTool */),
|
|
1940
|
+
toolName: import_zod8.z.string(),
|
|
1941
|
+
impactLevel: import_zod8.z.string()
|
|
1844
1942
|
}).passthrough();
|
|
1845
|
-
var ToolConfirmationDetailsSchema =
|
|
1943
|
+
var ToolConfirmationDetailsSchema = import_zod8.z.discriminatedUnion("type", [
|
|
1846
1944
|
EditToolConfirmationDetailsSchema,
|
|
1847
1945
|
ExecuteToolConfirmationDetailsSchema,
|
|
1848
1946
|
CreateToolConfirmationDetailsSchema,
|
|
@@ -1853,51 +1951,45 @@ var ToolConfirmationDetailsSchema = import_zod7.z.discriminatedUnion("type", [
|
|
|
1853
1951
|
ApplyPatchToolConfirmationDetailsSchema,
|
|
1854
1952
|
McpToolConfirmationDetailsSchema
|
|
1855
1953
|
]);
|
|
1856
|
-
var ToolConfirmationInfoSchema =
|
|
1954
|
+
var ToolConfirmationInfoSchema = import_zod8.z.object({
|
|
1857
1955
|
toolUse: ToolUseSchema,
|
|
1858
|
-
confirmationType:
|
|
1956
|
+
confirmationType: import_zod8.z.nativeEnum(ToolConfirmationType),
|
|
1859
1957
|
details: ToolConfirmationDetailsSchema
|
|
1860
1958
|
}).passthrough();
|
|
1861
|
-
var RequestPermissionRequestParamsSchema =
|
|
1862
|
-
toolUses:
|
|
1863
|
-
options:
|
|
1959
|
+
var RequestPermissionRequestParamsSchema = import_zod8.z.object({
|
|
1960
|
+
toolUses: import_zod8.z.array(ToolConfirmationInfoSchema),
|
|
1961
|
+
options: import_zod8.z.array(ToolConfirmationListItemSchema)
|
|
1864
1962
|
}).passthrough();
|
|
1865
1963
|
var RequestPermissionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1866
|
-
method:
|
|
1964
|
+
method: import_zod8.z.literal("droid.request_permission" /* REQUEST_PERMISSION */),
|
|
1867
1965
|
params: RequestPermissionRequestParamsSchema
|
|
1868
1966
|
});
|
|
1869
|
-
var RequestPermissionResultSchema =
|
|
1870
|
-
selectedOption:
|
|
1871
|
-
comment:
|
|
1967
|
+
var RequestPermissionResultSchema = import_zod8.z.object({
|
|
1968
|
+
selectedOption: import_zod8.z.nativeEnum(ToolConfirmationOutcome),
|
|
1969
|
+
comment: import_zod8.z.string().optional()
|
|
1872
1970
|
}).strict();
|
|
1873
|
-
var RequestPermissionResponseSchema =
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
var AskUserRequestParamsSchema = import_zod7.z.object({
|
|
1880
|
-
toolCallId: import_zod7.z.string(),
|
|
1881
|
-
questions: import_zod7.z.array(AskUserQuestionSchema)
|
|
1971
|
+
var RequestPermissionResponseSchema = createResponseSchema(
|
|
1972
|
+
RequestPermissionResultSchema
|
|
1973
|
+
);
|
|
1974
|
+
var AskUserRequestParamsSchema = import_zod8.z.object({
|
|
1975
|
+
toolCallId: import_zod8.z.string(),
|
|
1976
|
+
questions: import_zod8.z.array(AskUserQuestionSchema)
|
|
1882
1977
|
}).passthrough();
|
|
1883
1978
|
var AskUserRequestSchema = JsonRpcRequestSchema.extend({
|
|
1884
|
-
method:
|
|
1979
|
+
method: import_zod8.z.literal("droid.ask_user" /* ASK_USER */),
|
|
1885
1980
|
params: AskUserRequestParamsSchema
|
|
1886
1981
|
});
|
|
1887
|
-
var AskUserCollectedAnswerSchema =
|
|
1888
|
-
index:
|
|
1889
|
-
question:
|
|
1890
|
-
answer:
|
|
1982
|
+
var AskUserCollectedAnswerSchema = import_zod8.z.object({
|
|
1983
|
+
index: import_zod8.z.number(),
|
|
1984
|
+
question: import_zod8.z.string(),
|
|
1985
|
+
answer: import_zod8.z.string()
|
|
1891
1986
|
}).strict();
|
|
1892
|
-
var AskUserResultSchema =
|
|
1893
|
-
cancelled:
|
|
1894
|
-
answers:
|
|
1987
|
+
var AskUserResultSchema = import_zod8.z.object({
|
|
1988
|
+
cancelled: import_zod8.z.boolean().optional(),
|
|
1989
|
+
answers: import_zod8.z.array(AskUserCollectedAnswerSchema)
|
|
1895
1990
|
}).strict();
|
|
1896
|
-
var AskUserResponseSchema =
|
|
1897
|
-
|
|
1898
|
-
JsonRpcResponseFailureSchema
|
|
1899
|
-
]);
|
|
1900
|
-
var _CliRequestOrNotificationSchema = import_zod7.z.union([
|
|
1991
|
+
var AskUserResponseSchema = createResponseSchema(AskUserResultSchema);
|
|
1992
|
+
var _CliRequestOrNotificationSchema = import_zod8.z.union([
|
|
1901
1993
|
SessionNotificationSchema,
|
|
1902
1994
|
RequestPermissionRequestSchema,
|
|
1903
1995
|
AskUserRequestSchema
|
|
@@ -1905,7 +1997,7 @@ var _CliRequestOrNotificationSchema = import_zod7.z.union([
|
|
|
1905
1997
|
var CliRequestOrNotificationSchema = _CliRequestOrNotificationSchema;
|
|
1906
1998
|
|
|
1907
1999
|
// src/constants.ts
|
|
1908
|
-
var SDK_VERSION = "0.
|
|
2000
|
+
var SDK_VERSION = "0.3.0";
|
|
1909
2001
|
var SDK_TAG = {
|
|
1910
2002
|
name: "sdk",
|
|
1911
2003
|
metadata: { language: "typescript", version: SDK_VERSION }
|
|
@@ -2221,6 +2313,24 @@ var ProcessTransport = class {
|
|
|
2221
2313
|
|
|
2222
2314
|
// src/protocol.ts
|
|
2223
2315
|
var import_uuid = require("uuid");
|
|
2316
|
+
function dispatchNotification(notification, listeners) {
|
|
2317
|
+
let notificationType;
|
|
2318
|
+
const parsed = SessionNotificationParamsSchema.safeParse(
|
|
2319
|
+
notification["params"]
|
|
2320
|
+
);
|
|
2321
|
+
if (parsed.success) {
|
|
2322
|
+
notificationType = parsed.data.notification.type;
|
|
2323
|
+
}
|
|
2324
|
+
for (const listener of listeners) {
|
|
2325
|
+
if (listener.filter?.type != null && listener.filter.type !== notificationType) {
|
|
2326
|
+
continue;
|
|
2327
|
+
}
|
|
2328
|
+
try {
|
|
2329
|
+
listener.callback(notification);
|
|
2330
|
+
} catch {
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2224
2334
|
var ProtocolEngine = class {
|
|
2225
2335
|
_transport;
|
|
2226
2336
|
_defaultTimeout;
|
|
@@ -2385,22 +2495,7 @@ var ProtocolEngine = class {
|
|
|
2385
2495
|
pending.resolve(result);
|
|
2386
2496
|
}
|
|
2387
2497
|
_handleNotification(notification) {
|
|
2388
|
-
|
|
2389
|
-
const parsed = SessionNotificationParamsSchema.safeParse(
|
|
2390
|
-
notification["params"]
|
|
2391
|
-
);
|
|
2392
|
-
if (parsed.success) {
|
|
2393
|
-
notificationType = parsed.data.notification.type;
|
|
2394
|
-
}
|
|
2395
|
-
for (const listener of this._notificationListeners) {
|
|
2396
|
-
if (listener.filter?.type != null && listener.filter.type !== notificationType) {
|
|
2397
|
-
continue;
|
|
2398
|
-
}
|
|
2399
|
-
try {
|
|
2400
|
-
listener.callback(notification);
|
|
2401
|
-
} catch {
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2498
|
+
dispatchNotification(notification, this._notificationListeners);
|
|
2404
2499
|
}
|
|
2405
2500
|
async _handleServerRequest(method, requestId, params) {
|
|
2406
2501
|
if (method === "droid.request_permission" /* REQUEST_PERMISSION */) {
|
|
@@ -2521,10 +2616,6 @@ var DroidClient = class {
|
|
|
2521
2616
|
_engine;
|
|
2522
2617
|
_sessionId = null;
|
|
2523
2618
|
_closed = false;
|
|
2524
|
-
/**
|
|
2525
|
-
* Client-level notification listeners.
|
|
2526
|
-
* Each entry is [callback, optional notification filter].
|
|
2527
|
-
*/
|
|
2528
2619
|
_notificationListeners = [];
|
|
2529
2620
|
/** Client-level permission handler. */
|
|
2530
2621
|
_permissionHandler = null;
|
|
@@ -2598,6 +2689,13 @@ var DroidClient = class {
|
|
|
2598
2689
|
InterruptSessionResultSchema
|
|
2599
2690
|
);
|
|
2600
2691
|
}
|
|
2692
|
+
async closeSession(params = {}) {
|
|
2693
|
+
return this._sessionRpc(
|
|
2694
|
+
"droid.close_session" /* CLOSE_SESSION */,
|
|
2695
|
+
params,
|
|
2696
|
+
CloseSessionResultSchema
|
|
2697
|
+
);
|
|
2698
|
+
}
|
|
2601
2699
|
async killWorkerSession(params) {
|
|
2602
2700
|
return this._sessionRpc(
|
|
2603
2701
|
"droid.kill_worker_session" /* KILL_WORKER_SESSION */,
|
|
@@ -2786,23 +2884,7 @@ var DroidClient = class {
|
|
|
2786
2884
|
await this._engine.close();
|
|
2787
2885
|
}
|
|
2788
2886
|
_dispatchNotification(notification) {
|
|
2789
|
-
|
|
2790
|
-
const parsed = SessionNotificationParamsSchema.safeParse(
|
|
2791
|
-
notification["params"]
|
|
2792
|
-
);
|
|
2793
|
-
if (parsed.success) {
|
|
2794
|
-
notificationType = parsed.data.notification.type;
|
|
2795
|
-
}
|
|
2796
|
-
const listeners = [...this._notificationListeners];
|
|
2797
|
-
for (const listener of listeners) {
|
|
2798
|
-
if (listener.filter?.type != null && listener.filter.type !== notificationType) {
|
|
2799
|
-
continue;
|
|
2800
|
-
}
|
|
2801
|
-
try {
|
|
2802
|
-
listener.callback(notification);
|
|
2803
|
-
} catch {
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2887
|
+
dispatchNotification(notification, [...this._notificationListeners]);
|
|
2806
2888
|
}
|
|
2807
2889
|
_dispatchPermissionRequest(params) {
|
|
2808
2890
|
const handler = this._permissionHandler;
|
|
@@ -2836,14 +2918,18 @@ var DroidClient = class {
|
|
|
2836
2918
|
|
|
2837
2919
|
// src/stream.ts
|
|
2838
2920
|
var DroidMessageType = {
|
|
2921
|
+
Assistant: "assistant",
|
|
2922
|
+
User: "user",
|
|
2923
|
+
ToolCall: "tool_call",
|
|
2839
2924
|
AssistantTextDelta: "assistant_text_delta",
|
|
2925
|
+
AssistantTextComplete: "assistant_text_complete",
|
|
2840
2926
|
ThinkingTextDelta: "thinking_text_delta",
|
|
2841
|
-
|
|
2927
|
+
ThinkingTextComplete: "thinking_text_complete",
|
|
2928
|
+
ToolCallDelta: "tool_call_delta",
|
|
2842
2929
|
ToolResult: "tool_result",
|
|
2843
2930
|
ToolProgress: "tool_progress",
|
|
2844
2931
|
WorkingStateChanged: "working_state_changed",
|
|
2845
2932
|
TokenUsageUpdate: "token_usage_update",
|
|
2846
|
-
CreateMessage: "create_message",
|
|
2847
2933
|
PermissionResolved: "permission_resolved",
|
|
2848
2934
|
SettingsUpdated: "settings_updated",
|
|
2849
2935
|
SessionTitleUpdated: "session_title_updated",
|
|
@@ -2856,8 +2942,9 @@ var DroidMessageType = {
|
|
|
2856
2942
|
MissionWorkerCompleted: "mission_worker_completed",
|
|
2857
2943
|
McpAuthRequired: "mcp_auth_required",
|
|
2858
2944
|
McpAuthCompleted: "mcp_auth_completed",
|
|
2945
|
+
Hook: "hook",
|
|
2859
2946
|
Error: "error",
|
|
2860
|
-
|
|
2947
|
+
Result: "result"
|
|
2861
2948
|
};
|
|
2862
2949
|
function convertNotificationToStreamMessage(raw) {
|
|
2863
2950
|
const parsed = SessionNotificationPayloadSchema.safeParse(raw);
|
|
@@ -2873,6 +2960,12 @@ function convertNotificationToStreamMessage(raw) {
|
|
|
2873
2960
|
blockIndex: notification.blockIndex,
|
|
2874
2961
|
text: notification.textDelta
|
|
2875
2962
|
};
|
|
2963
|
+
case "assistant_text_complete" /* ASSISTANT_TEXT_COMPLETE */:
|
|
2964
|
+
return {
|
|
2965
|
+
type: DroidMessageType.AssistantTextComplete,
|
|
2966
|
+
messageId: notification.messageId,
|
|
2967
|
+
blockIndex: notification.blockIndex
|
|
2968
|
+
};
|
|
2876
2969
|
case "thinking_text_delta" /* THINKING_TEXT_DELTA */:
|
|
2877
2970
|
return {
|
|
2878
2971
|
type: DroidMessageType.ThinkingTextDelta,
|
|
@@ -2880,6 +2973,18 @@ function convertNotificationToStreamMessage(raw) {
|
|
|
2880
2973
|
blockIndex: notification.blockIndex,
|
|
2881
2974
|
text: notification.textDelta
|
|
2882
2975
|
};
|
|
2976
|
+
case "thinking_text_complete" /* THINKING_TEXT_COMPLETE */:
|
|
2977
|
+
return {
|
|
2978
|
+
type: DroidMessageType.ThinkingTextComplete,
|
|
2979
|
+
messageId: notification.messageId,
|
|
2980
|
+
blockIndex: notification.blockIndex,
|
|
2981
|
+
durationMs: notification.durationMs
|
|
2982
|
+
};
|
|
2983
|
+
case "tool_call" /* TOOL_CALL */:
|
|
2984
|
+
return {
|
|
2985
|
+
type: DroidMessageType.ToolCallDelta,
|
|
2986
|
+
toolUse: notification.toolUse
|
|
2987
|
+
};
|
|
2883
2988
|
case "tool_result" /* TOOL_RESULT */:
|
|
2884
2989
|
return {
|
|
2885
2990
|
type: DroidMessageType.ToolResult,
|
|
@@ -2919,22 +3024,33 @@ function convertNotificationToStreamMessage(raw) {
|
|
|
2919
3024
|
const msg = notification.message;
|
|
2920
3025
|
const messages = [];
|
|
2921
3026
|
for (const block of msg.content) {
|
|
2922
|
-
if (block.type ===
|
|
3027
|
+
if (block.type === "tool_use") {
|
|
2923
3028
|
messages.push({
|
|
2924
|
-
type: DroidMessageType.
|
|
2925
|
-
|
|
2926
|
-
toolInput: block.input,
|
|
2927
|
-
toolUseId: block.id
|
|
3029
|
+
type: DroidMessageType.ToolCall,
|
|
3030
|
+
toolUse: block
|
|
2928
3031
|
});
|
|
2929
3032
|
}
|
|
2930
3033
|
}
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
})
|
|
3034
|
+
if (msg.role === FactoryDroidMessageRole.Assistant) {
|
|
3035
|
+
messages.push({
|
|
3036
|
+
type: DroidMessageType.Assistant,
|
|
3037
|
+
message: msg,
|
|
3038
|
+
text: extractTextFromMessage(msg)
|
|
3039
|
+
});
|
|
3040
|
+
} else if (msg.role === FactoryDroidMessageRole.User) {
|
|
3041
|
+
messages.push({
|
|
3042
|
+
type: DroidMessageType.User,
|
|
3043
|
+
message: msg
|
|
3044
|
+
});
|
|
3045
|
+
} else {
|
|
3046
|
+
messages.push({
|
|
3047
|
+
type: "create_message",
|
|
3048
|
+
messageId: msg.id,
|
|
3049
|
+
role: msg.role,
|
|
3050
|
+
content: msg.content,
|
|
3051
|
+
parentId: notification.parentId
|
|
3052
|
+
});
|
|
3053
|
+
}
|
|
2938
3054
|
return messages;
|
|
2939
3055
|
}
|
|
2940
3056
|
case "error" /* ERROR */:
|
|
@@ -3013,42 +3129,205 @@ function convertNotificationToStreamMessage(raw) {
|
|
|
3013
3129
|
outcome: notification.outcome,
|
|
3014
3130
|
message: notification.message
|
|
3015
3131
|
};
|
|
3132
|
+
case "hook_execution_started" /* HOOK_EXECUTION_STARTED */:
|
|
3133
|
+
return notification.hookCommands.map((hookCommand) => ({
|
|
3134
|
+
type: DroidMessageType.Hook,
|
|
3135
|
+
hookId: notification.hookId,
|
|
3136
|
+
eventName: notification.hookEventName,
|
|
3137
|
+
matcher: notification.hookMatcher,
|
|
3138
|
+
toolCallId: notification.hookToolCallId,
|
|
3139
|
+
command: hookCommand.command,
|
|
3140
|
+
timeout: hookCommand.timeout,
|
|
3141
|
+
status: "started"
|
|
3142
|
+
}));
|
|
3143
|
+
case "hook_execution_completed" /* HOOK_EXECUTION_COMPLETED */:
|
|
3144
|
+
return (notification.hookResults ?? []).map((hookResult) => ({
|
|
3145
|
+
type: DroidMessageType.Hook,
|
|
3146
|
+
hookId: notification.hookId,
|
|
3147
|
+
eventName: notification.hookEventName,
|
|
3148
|
+
matcher: notification.hookMatcher,
|
|
3149
|
+
toolCallId: notification.hookToolCallId,
|
|
3150
|
+
command: hookResult.command,
|
|
3151
|
+
timeout: hookResult.timeout,
|
|
3152
|
+
status: notification.hookStatus,
|
|
3153
|
+
exitCode: hookResult.exitCode,
|
|
3154
|
+
stdout: hookResult.stdout,
|
|
3155
|
+
stderr: hookResult.stderr
|
|
3156
|
+
}));
|
|
3157
|
+
case "structured_output" /* STRUCTURED_OUTPUT */:
|
|
3158
|
+
return {
|
|
3159
|
+
type: "structured_output",
|
|
3160
|
+
messageId: notification.messageId,
|
|
3161
|
+
structuredOutput: notification.structuredOutput,
|
|
3162
|
+
structuredOutputError: notification.structuredOutputError
|
|
3163
|
+
};
|
|
3016
3164
|
default:
|
|
3017
3165
|
return null;
|
|
3018
3166
|
}
|
|
3019
3167
|
}
|
|
3020
3168
|
var StreamStateTracker = class {
|
|
3169
|
+
constructor(options = {}) {
|
|
3170
|
+
this.options = options;
|
|
3171
|
+
}
|
|
3021
3172
|
hasBeenNonIdle = false;
|
|
3022
3173
|
lastTokenUsage = null;
|
|
3174
|
+
fullText = "";
|
|
3175
|
+
finalAssistantText = "";
|
|
3176
|
+
structuredOutput = null;
|
|
3177
|
+
structuredOutputError = null;
|
|
3178
|
+
errors = [];
|
|
3179
|
+
numTurns = 0;
|
|
3180
|
+
emittedMessages = [];
|
|
3023
3181
|
toolNameMap = /* @__PURE__ */ new Map();
|
|
3024
3182
|
getToolName(toolUseId) {
|
|
3025
3183
|
return this.toolNameMap.get(toolUseId) ?? "";
|
|
3026
3184
|
}
|
|
3027
3185
|
processMessage(message) {
|
|
3028
3186
|
const additional = [];
|
|
3029
|
-
if (message.type ===
|
|
3187
|
+
if (message.type === "tool_use") {
|
|
3030
3188
|
this.toolNameMap.set(message.toolUseId, message.toolName);
|
|
3031
3189
|
}
|
|
3190
|
+
if (message.type === DroidMessageType.ToolCall) {
|
|
3191
|
+
this.toolNameMap.set(message.toolUse.id, message.toolUse.name);
|
|
3192
|
+
}
|
|
3193
|
+
if (message.type === DroidMessageType.ToolCallDelta) {
|
|
3194
|
+
this.toolNameMap.set(message.toolUse.id, message.toolUse.name);
|
|
3195
|
+
}
|
|
3032
3196
|
if (message.type === DroidMessageType.ToolResult) {
|
|
3033
3197
|
message = { ...message, toolName: this.getToolName(message.toolUseId) };
|
|
3034
3198
|
}
|
|
3199
|
+
if (message.type === DroidMessageType.AssistantTextDelta) {
|
|
3200
|
+
this.fullText += message.text;
|
|
3201
|
+
}
|
|
3202
|
+
if (message.type === DroidMessageType.Assistant) {
|
|
3203
|
+
this.finalAssistantText = message.text;
|
|
3204
|
+
if (this.fullText.length === 0) {
|
|
3205
|
+
this.fullText = message.text;
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3035
3208
|
if (message.type === DroidMessageType.TokenUsageUpdate) {
|
|
3036
3209
|
this.lastTokenUsage = message;
|
|
3037
3210
|
}
|
|
3211
|
+
if (message.type === DroidMessageType.Error) {
|
|
3212
|
+
this.errors.push(message);
|
|
3213
|
+
}
|
|
3214
|
+
if (message.type === "structured_output") {
|
|
3215
|
+
this.structuredOutput = message.structuredOutput;
|
|
3216
|
+
this.structuredOutputError = message.structuredOutputError;
|
|
3217
|
+
return { message: null, additional };
|
|
3218
|
+
}
|
|
3038
3219
|
if (message.type === DroidMessageType.WorkingStateChanged) {
|
|
3039
3220
|
if (message.state !== "idle" /* Idle */) {
|
|
3040
3221
|
this.hasBeenNonIdle = true;
|
|
3041
3222
|
} else if (this.hasBeenNonIdle) {
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
tokenUsage: this.lastTokenUsage
|
|
3045
|
-
});
|
|
3223
|
+
this.numTurns++;
|
|
3224
|
+
additional.push(this.createResultMessage());
|
|
3046
3225
|
this.hasBeenNonIdle = false;
|
|
3226
|
+
this.resetTurnState();
|
|
3047
3227
|
}
|
|
3048
3228
|
}
|
|
3229
|
+
if (message.type !== DroidMessageType.WorkingStateChanged) {
|
|
3230
|
+
this.trackEmittedMessage(message);
|
|
3231
|
+
}
|
|
3049
3232
|
return { message, additional };
|
|
3050
3233
|
}
|
|
3234
|
+
createResultMessage() {
|
|
3235
|
+
if (this.options.hasOutputFormat && this.structuredOutput === null && this.structuredOutputError === null) {
|
|
3236
|
+
this.structuredOutput = parseJsonObject(this.finalAssistantText || this.fullText) ?? null;
|
|
3237
|
+
}
|
|
3238
|
+
const tokenUsage = this.lastTokenUsage ? stripTokenUsageType(this.lastTokenUsage) : null;
|
|
3239
|
+
const result = this.finalAssistantText || this.fullText;
|
|
3240
|
+
const base = {
|
|
3241
|
+
type: DroidMessageType.Result,
|
|
3242
|
+
sessionId: this.options.sessionId ?? "",
|
|
3243
|
+
durationMs: Date.now() - (this.options.startedAt ?? Date.now()),
|
|
3244
|
+
numTurns: this.numTurns,
|
|
3245
|
+
result,
|
|
3246
|
+
tokenUsage,
|
|
3247
|
+
messages: [...this.emittedMessages],
|
|
3248
|
+
text: result,
|
|
3249
|
+
turnCount: this.numTurns
|
|
3250
|
+
};
|
|
3251
|
+
if (this.structuredOutputError) {
|
|
3252
|
+
return {
|
|
3253
|
+
...base,
|
|
3254
|
+
subtype: "error_structured_output",
|
|
3255
|
+
isError: true,
|
|
3256
|
+
success: false,
|
|
3257
|
+
errors: [this.structuredOutputError.message],
|
|
3258
|
+
structuredOutput: this.structuredOutput,
|
|
3259
|
+
structuredOutputError: this.structuredOutputError,
|
|
3260
|
+
error: null
|
|
3261
|
+
};
|
|
3262
|
+
}
|
|
3263
|
+
if (this.errors.length > 0) {
|
|
3264
|
+
return {
|
|
3265
|
+
...base,
|
|
3266
|
+
subtype: "error_during_execution",
|
|
3267
|
+
isError: true,
|
|
3268
|
+
success: false,
|
|
3269
|
+
errors: this.errors.map((error) => error.message),
|
|
3270
|
+
structuredOutput: this.structuredOutput,
|
|
3271
|
+
structuredOutputError: null,
|
|
3272
|
+
error: this.errors[0] ?? null
|
|
3273
|
+
};
|
|
3274
|
+
}
|
|
3275
|
+
return {
|
|
3276
|
+
...base,
|
|
3277
|
+
subtype: "success",
|
|
3278
|
+
isError: false,
|
|
3279
|
+
success: true,
|
|
3280
|
+
structuredOutput: this.structuredOutput,
|
|
3281
|
+
structuredOutputError: null,
|
|
3282
|
+
error: null
|
|
3283
|
+
};
|
|
3284
|
+
}
|
|
3285
|
+
trackEmittedMessage(message) {
|
|
3286
|
+
if (isDefaultStreamMessage(message)) {
|
|
3287
|
+
this.emittedMessages.push(message);
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
resetTurnState() {
|
|
3291
|
+
this.lastTokenUsage = null;
|
|
3292
|
+
this.fullText = "";
|
|
3293
|
+
this.finalAssistantText = "";
|
|
3294
|
+
this.structuredOutput = null;
|
|
3295
|
+
this.structuredOutputError = null;
|
|
3296
|
+
this.errors = [];
|
|
3297
|
+
this.emittedMessages = [];
|
|
3298
|
+
}
|
|
3051
3299
|
};
|
|
3300
|
+
function isInternalMessage(message) {
|
|
3301
|
+
return message.type === "structured_output" || message.type === "tool_use" || message.type === "create_message";
|
|
3302
|
+
}
|
|
3303
|
+
function isDefaultStreamMessage(message) {
|
|
3304
|
+
return message.type === DroidMessageType.Assistant || message.type === DroidMessageType.User || message.type === DroidMessageType.ToolCall || message.type === DroidMessageType.ToolResult || message.type === DroidMessageType.Hook || message.type === DroidMessageType.Error || message.type === DroidMessageType.Result;
|
|
3305
|
+
}
|
|
3306
|
+
function stripTokenUsageType(message) {
|
|
3307
|
+
const {
|
|
3308
|
+
inputTokens,
|
|
3309
|
+
outputTokens,
|
|
3310
|
+
cacheCreationTokens,
|
|
3311
|
+
cacheReadTokens,
|
|
3312
|
+
thinkingTokens
|
|
3313
|
+
} = message;
|
|
3314
|
+
return {
|
|
3315
|
+
inputTokens,
|
|
3316
|
+
outputTokens,
|
|
3317
|
+
cacheCreationTokens,
|
|
3318
|
+
cacheReadTokens,
|
|
3319
|
+
thinkingTokens
|
|
3320
|
+
};
|
|
3321
|
+
}
|
|
3322
|
+
function parseJsonObject(text) {
|
|
3323
|
+
try {
|
|
3324
|
+
const parsed = JSON.parse(text);
|
|
3325
|
+
const result = JsonObjectSchema.safeParse(parsed);
|
|
3326
|
+
return result.success ? result.data : null;
|
|
3327
|
+
} catch {
|
|
3328
|
+
return null;
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3052
3331
|
function normalizeToolResultContent(content) {
|
|
3053
3332
|
if (content == null) {
|
|
3054
3333
|
return "";
|
|
@@ -3061,6 +3340,9 @@ function normalizeToolResultContent(content) {
|
|
|
3061
3340
|
}
|
|
3062
3341
|
return String(content);
|
|
3063
3342
|
}
|
|
3343
|
+
function extractTextFromMessage(message) {
|
|
3344
|
+
return message.content.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
3345
|
+
}
|
|
3064
3346
|
|
|
3065
3347
|
// src/helpers.ts
|
|
3066
3348
|
function wireAbortSignal(signal, onAbort) {
|
|
@@ -3081,10 +3363,20 @@ function extractInnerNotification(notification) {
|
|
|
3081
3363
|
return parsed.success ? parsed.data.params.notification : null;
|
|
3082
3364
|
}
|
|
3083
3365
|
var MessageBridge = class {
|
|
3366
|
+
constructor(onDone, _options = {}) {
|
|
3367
|
+
this._options = _options;
|
|
3368
|
+
this._onDone = onDone;
|
|
3369
|
+
this._stateTracker = new StreamStateTracker({
|
|
3370
|
+
sessionId: _options.sessionId,
|
|
3371
|
+
startedAt: _options.startedAt,
|
|
3372
|
+
hasOutputFormat: _options.outputFormat !== void 0
|
|
3373
|
+
});
|
|
3374
|
+
}
|
|
3084
3375
|
_queue = [];
|
|
3376
|
+
_onDone;
|
|
3085
3377
|
_resolveWaiting = null;
|
|
3086
3378
|
_done = false;
|
|
3087
|
-
_stateTracker
|
|
3379
|
+
_stateTracker;
|
|
3088
3380
|
notificationHandler = (notification) => {
|
|
3089
3381
|
const inner = extractInnerNotification(notification);
|
|
3090
3382
|
if (!inner) return;
|
|
@@ -3093,10 +3385,14 @@ var MessageBridge = class {
|
|
|
3093
3385
|
const messages = Array.isArray(converted) ? converted : [converted];
|
|
3094
3386
|
for (const msg of messages) {
|
|
3095
3387
|
const { message, additional } = this._stateTracker.processMessage(msg);
|
|
3096
|
-
this.
|
|
3388
|
+
if (message && this._shouldYield(message)) {
|
|
3389
|
+
this._enqueue(message);
|
|
3390
|
+
}
|
|
3097
3391
|
for (const extra of additional) {
|
|
3098
|
-
this.
|
|
3099
|
-
|
|
3392
|
+
if (this._shouldYield(extra)) {
|
|
3393
|
+
this._enqueue(extra);
|
|
3394
|
+
}
|
|
3395
|
+
if (extra.type === DroidMessageType.Result) {
|
|
3100
3396
|
this._signalDone();
|
|
3101
3397
|
}
|
|
3102
3398
|
}
|
|
@@ -3110,7 +3406,7 @@ var MessageBridge = class {
|
|
|
3110
3406
|
while (this._queue.length > 0) {
|
|
3111
3407
|
const msg = this._queue.shift();
|
|
3112
3408
|
yield msg;
|
|
3113
|
-
if (msg.type === DroidMessageType.
|
|
3409
|
+
if (msg.type === DroidMessageType.Result) {
|
|
3114
3410
|
return;
|
|
3115
3411
|
}
|
|
3116
3412
|
}
|
|
@@ -3122,6 +3418,12 @@ var MessageBridge = class {
|
|
|
3122
3418
|
});
|
|
3123
3419
|
}
|
|
3124
3420
|
}
|
|
3421
|
+
_shouldYield(message) {
|
|
3422
|
+
if (isInternalMessage(message)) {
|
|
3423
|
+
return false;
|
|
3424
|
+
}
|
|
3425
|
+
return this._options.includePartialMessages ? true : isDefaultStreamMessage(message);
|
|
3426
|
+
}
|
|
3125
3427
|
_enqueue(msg) {
|
|
3126
3428
|
this._queue.push(msg);
|
|
3127
3429
|
if (this._resolveWaiting) {
|
|
@@ -3131,7 +3433,11 @@ var MessageBridge = class {
|
|
|
3131
3433
|
}
|
|
3132
3434
|
}
|
|
3133
3435
|
_signalDone() {
|
|
3436
|
+
const wasDone = this._done;
|
|
3134
3437
|
this._done = true;
|
|
3438
|
+
if (!wasDone) {
|
|
3439
|
+
this._onDone?.();
|
|
3440
|
+
}
|
|
3135
3441
|
if (this._resolveWaiting) {
|
|
3136
3442
|
const resolve2 = this._resolveWaiting;
|
|
3137
3443
|
this._resolveWaiting = null;
|
|
@@ -3214,7 +3520,7 @@ var import_node_events = require("events");
|
|
|
3214
3520
|
var import_node_http = __toESM(require("http"), 1);
|
|
3215
3521
|
var import_mcp4 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
3216
3522
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
3217
|
-
var
|
|
3523
|
+
var import_zod9 = require("zod");
|
|
3218
3524
|
function tool(name, description, inputSchemaOrHandler, handler) {
|
|
3219
3525
|
if (typeof inputSchemaOrHandler === "function") {
|
|
3220
3526
|
const actualHandler = inputSchemaOrHandler;
|
|
@@ -3227,7 +3533,7 @@ function tool(name, description, inputSchemaOrHandler, handler) {
|
|
|
3227
3533
|
if (!handler) {
|
|
3228
3534
|
throw new Error(`Missing handler for SDK MCP tool "${name}"`);
|
|
3229
3535
|
}
|
|
3230
|
-
const inputObjectSchema =
|
|
3536
|
+
const inputObjectSchema = import_zod9.z.object(inputSchemaOrHandler);
|
|
3231
3537
|
return {
|
|
3232
3538
|
name,
|
|
3233
3539
|
description,
|
|
@@ -3404,162 +3710,6 @@ async function startSdkMcpServers(servers) {
|
|
|
3404
3710
|
};
|
|
3405
3711
|
}
|
|
3406
3712
|
|
|
3407
|
-
// src/query.ts
|
|
3408
|
-
var DroidQueryImpl = class {
|
|
3409
|
-
_generator;
|
|
3410
|
-
_getSessionId;
|
|
3411
|
-
_getInitResult;
|
|
3412
|
-
_getInitialized;
|
|
3413
|
-
_interruptFn;
|
|
3414
|
-
_abortFn;
|
|
3415
|
-
constructor(generator, getSessionId, getInitResult, getInitialized, interruptFn, abortFn) {
|
|
3416
|
-
this._generator = generator;
|
|
3417
|
-
this._getSessionId = getSessionId;
|
|
3418
|
-
this._getInitResult = getInitResult;
|
|
3419
|
-
this._getInitialized = getInitialized;
|
|
3420
|
-
this._interruptFn = interruptFn;
|
|
3421
|
-
this._abortFn = abortFn;
|
|
3422
|
-
}
|
|
3423
|
-
get sessionId() {
|
|
3424
|
-
return this._getSessionId();
|
|
3425
|
-
}
|
|
3426
|
-
get initResult() {
|
|
3427
|
-
return this._getInitResult();
|
|
3428
|
-
}
|
|
3429
|
-
get initialized() {
|
|
3430
|
-
return this._getInitialized();
|
|
3431
|
-
}
|
|
3432
|
-
async interrupt() {
|
|
3433
|
-
return this._interruptFn();
|
|
3434
|
-
}
|
|
3435
|
-
abort() {
|
|
3436
|
-
this._abortFn();
|
|
3437
|
-
}
|
|
3438
|
-
next(...args) {
|
|
3439
|
-
return this._generator.next(...args);
|
|
3440
|
-
}
|
|
3441
|
-
return(value) {
|
|
3442
|
-
return this._generator.return(value);
|
|
3443
|
-
}
|
|
3444
|
-
throw(e) {
|
|
3445
|
-
return this._generator.throw(e);
|
|
3446
|
-
}
|
|
3447
|
-
[Symbol.asyncIterator]() {
|
|
3448
|
-
return this;
|
|
3449
|
-
}
|
|
3450
|
-
};
|
|
3451
|
-
function query(options) {
|
|
3452
|
-
let transport = null;
|
|
3453
|
-
let client = null;
|
|
3454
|
-
let sessionId = null;
|
|
3455
|
-
let initResult = null;
|
|
3456
|
-
let aborted = false;
|
|
3457
|
-
let initializationPromise = null;
|
|
3458
|
-
let promptPromise = null;
|
|
3459
|
-
let cleanupAbortSignal = () => {
|
|
3460
|
-
};
|
|
3461
|
-
let cleanupSdkMcpServers = null;
|
|
3462
|
-
const bridge = new MessageBridge();
|
|
3463
|
-
const closeActiveResources = async () => {
|
|
3464
|
-
const closer = client ?? transport;
|
|
3465
|
-
const cleanupMcp = cleanupSdkMcpServers;
|
|
3466
|
-
client = null;
|
|
3467
|
-
transport = null;
|
|
3468
|
-
cleanupSdkMcpServers = null;
|
|
3469
|
-
await Promise.all([closeQuietly(closer), cleanupMcp?.()]);
|
|
3470
|
-
};
|
|
3471
|
-
const ensureInitialized = () => {
|
|
3472
|
-
if (initResult) {
|
|
3473
|
-
return Promise.resolve(initResult);
|
|
3474
|
-
}
|
|
3475
|
-
if (initializationPromise) {
|
|
3476
|
-
return initializationPromise;
|
|
3477
|
-
}
|
|
3478
|
-
initializationPromise = (async () => {
|
|
3479
|
-
try {
|
|
3480
|
-
if (aborted) {
|
|
3481
|
-
throw new Error("Query aborted before initialization");
|
|
3482
|
-
}
|
|
3483
|
-
const configuredClient = await createConfiguredClient(options);
|
|
3484
|
-
transport = configuredClient.transport;
|
|
3485
|
-
client = configuredClient.client;
|
|
3486
|
-
client.onNotification(bridge.notificationHandler);
|
|
3487
|
-
if (aborted) {
|
|
3488
|
-
throw new Error("Query aborted before initialization");
|
|
3489
|
-
}
|
|
3490
|
-
const sdkMcpServers = await startSdkMcpServers(options.mcpServers);
|
|
3491
|
-
cleanupSdkMcpServers = sdkMcpServers.cleanup;
|
|
3492
|
-
const result = await client.initializeSession(
|
|
3493
|
-
buildInitParams({
|
|
3494
|
-
...options,
|
|
3495
|
-
mcpServers: sdkMcpServers.mcpServers
|
|
3496
|
-
})
|
|
3497
|
-
);
|
|
3498
|
-
sessionId = result.sessionId;
|
|
3499
|
-
initResult = result;
|
|
3500
|
-
return result;
|
|
3501
|
-
} catch (error) {
|
|
3502
|
-
await closeActiveResources();
|
|
3503
|
-
throw error;
|
|
3504
|
-
}
|
|
3505
|
-
})();
|
|
3506
|
-
return initializationPromise;
|
|
3507
|
-
};
|
|
3508
|
-
const ensurePromptSent = () => {
|
|
3509
|
-
if (promptPromise) {
|
|
3510
|
-
return promptPromise;
|
|
3511
|
-
}
|
|
3512
|
-
promptPromise = (async () => {
|
|
3513
|
-
await ensureInitialized();
|
|
3514
|
-
if (aborted || client === null) {
|
|
3515
|
-
return;
|
|
3516
|
-
}
|
|
3517
|
-
await client.addUserMessage({ text: options.prompt });
|
|
3518
|
-
})();
|
|
3519
|
-
return promptPromise;
|
|
3520
|
-
};
|
|
3521
|
-
async function* generateMessages() {
|
|
3522
|
-
if (aborted) return;
|
|
3523
|
-
await ensurePromptSent();
|
|
3524
|
-
if (aborted) return;
|
|
3525
|
-
for await (const msg of bridge.messages()) {
|
|
3526
|
-
if (aborted) return;
|
|
3527
|
-
yield msg;
|
|
3528
|
-
}
|
|
3529
|
-
}
|
|
3530
|
-
const generator = generateMessages();
|
|
3531
|
-
async function* wrappedGenerator() {
|
|
3532
|
-
try {
|
|
3533
|
-
yield* generator;
|
|
3534
|
-
} finally {
|
|
3535
|
-
cleanupAbortSignal();
|
|
3536
|
-
await closeActiveResources();
|
|
3537
|
-
}
|
|
3538
|
-
}
|
|
3539
|
-
const droidQuery = new DroidQueryImpl(
|
|
3540
|
-
wrappedGenerator(),
|
|
3541
|
-
() => sessionId,
|
|
3542
|
-
() => initResult,
|
|
3543
|
-
() => ensureInitialized(),
|
|
3544
|
-
async () => {
|
|
3545
|
-
if (client && !aborted) {
|
|
3546
|
-
await client.interruptSession();
|
|
3547
|
-
}
|
|
3548
|
-
},
|
|
3549
|
-
() => {
|
|
3550
|
-
aborted = true;
|
|
3551
|
-
bridge.signalDone();
|
|
3552
|
-
cleanupAbortSignal();
|
|
3553
|
-
void closeActiveResources();
|
|
3554
|
-
}
|
|
3555
|
-
);
|
|
3556
|
-
cleanupAbortSignal = wireAbortSignal(
|
|
3557
|
-
options.abortSignal,
|
|
3558
|
-
() => droidQuery.abort()
|
|
3559
|
-
);
|
|
3560
|
-
return droidQuery;
|
|
3561
|
-
}
|
|
3562
|
-
|
|
3563
3713
|
// src/session.ts
|
|
3564
3714
|
function getAbortError(signal) {
|
|
3565
3715
|
if (signal.reason instanceof Error) {
|
|
@@ -3574,24 +3724,6 @@ function throwIfAborted(signal) {
|
|
|
3574
3724
|
throw getAbortError(signal);
|
|
3575
3725
|
}
|
|
3576
3726
|
}
|
|
3577
|
-
function parseJsonObject(text) {
|
|
3578
|
-
try {
|
|
3579
|
-
const parsed = JSON.parse(text);
|
|
3580
|
-
const result = JsonObjectSchema.safeParse(parsed);
|
|
3581
|
-
return result.success ? result.data : null;
|
|
3582
|
-
} catch {
|
|
3583
|
-
return null;
|
|
3584
|
-
}
|
|
3585
|
-
}
|
|
3586
|
-
function extractAssistantText(message) {
|
|
3587
|
-
if (message.type !== DroidMessageType.CreateMessage) {
|
|
3588
|
-
return "";
|
|
3589
|
-
}
|
|
3590
|
-
if (message.role !== FactoryDroidMessageRole.Assistant) {
|
|
3591
|
-
return "";
|
|
3592
|
-
}
|
|
3593
|
-
return message.content.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
3594
|
-
}
|
|
3595
3727
|
var DroidSession = class {
|
|
3596
3728
|
_client;
|
|
3597
3729
|
_sessionId;
|
|
@@ -3599,6 +3731,7 @@ var DroidSession = class {
|
|
|
3599
3731
|
_closed = false;
|
|
3600
3732
|
_cleanupAbortSignal = null;
|
|
3601
3733
|
_cleanupCallbacks = [];
|
|
3734
|
+
_activeBridges = /* @__PURE__ */ new Set();
|
|
3602
3735
|
/** @internal */
|
|
3603
3736
|
constructor(client, sessionId, initResult) {
|
|
3604
3737
|
this._client = client;
|
|
@@ -3619,11 +3752,22 @@ var DroidSession = class {
|
|
|
3619
3752
|
addCleanup(cleanup) {
|
|
3620
3753
|
this._cleanupCallbacks.push(cleanup);
|
|
3621
3754
|
}
|
|
3622
|
-
|
|
3623
|
-
async *stream(text, options) {
|
|
3755
|
+
async *stream(prompt, options) {
|
|
3624
3756
|
this._ensureNotClosed();
|
|
3625
3757
|
throwIfAborted(options?.abortSignal);
|
|
3626
|
-
const
|
|
3758
|
+
const startedAt = Date.now();
|
|
3759
|
+
let resolveDone = () => {
|
|
3760
|
+
};
|
|
3761
|
+
const donePromise = new Promise((resolve2) => {
|
|
3762
|
+
resolveDone = resolve2;
|
|
3763
|
+
});
|
|
3764
|
+
const bridge = new MessageBridge(resolveDone, {
|
|
3765
|
+
includePartialMessages: options?.includePartialMessages,
|
|
3766
|
+
sessionId: this._sessionId,
|
|
3767
|
+
startedAt,
|
|
3768
|
+
outputFormat: options?.outputFormat
|
|
3769
|
+
});
|
|
3770
|
+
this._activeBridges.add(bridge);
|
|
3627
3771
|
const unsubscribe = this._client.onNotification(bridge.notificationHandler);
|
|
3628
3772
|
let resolveAbort = () => {
|
|
3629
3773
|
};
|
|
@@ -3639,11 +3783,12 @@ var DroidSession = class {
|
|
|
3639
3783
|
try {
|
|
3640
3784
|
await Promise.race([
|
|
3641
3785
|
this._client.addUserMessage({
|
|
3642
|
-
text,
|
|
3786
|
+
text: prompt,
|
|
3643
3787
|
images: options?.images,
|
|
3644
3788
|
files: options?.files,
|
|
3645
3789
|
outputFormat: options?.outputFormat
|
|
3646
3790
|
}),
|
|
3791
|
+
donePromise,
|
|
3647
3792
|
abortPromise
|
|
3648
3793
|
]);
|
|
3649
3794
|
throwIfAborted(options?.abortSignal);
|
|
@@ -3655,62 +3800,9 @@ var DroidSession = class {
|
|
|
3655
3800
|
} finally {
|
|
3656
3801
|
cleanupAbortSignal();
|
|
3657
3802
|
unsubscribe();
|
|
3803
|
+
this._activeBridges.delete(bridge);
|
|
3658
3804
|
}
|
|
3659
3805
|
}
|
|
3660
|
-
/** Consumes the stream and returns an aggregated {@link DroidResult}. */
|
|
3661
|
-
async send(text, options) {
|
|
3662
|
-
this._ensureNotClosed();
|
|
3663
|
-
const messages = [];
|
|
3664
|
-
let fullText = "";
|
|
3665
|
-
let lastTokenUsage = null;
|
|
3666
|
-
let firstError = null;
|
|
3667
|
-
let structuredOutput = null;
|
|
3668
|
-
let finalAssistantText = "";
|
|
3669
|
-
let turnCount = 0;
|
|
3670
|
-
const startedAt = Date.now();
|
|
3671
|
-
for await (const msg of this.stream(text, options)) {
|
|
3672
|
-
messages.push(msg);
|
|
3673
|
-
if (msg.type === DroidMessageType.AssistantTextDelta) {
|
|
3674
|
-
fullText += msg.text;
|
|
3675
|
-
}
|
|
3676
|
-
const assistantText = extractAssistantText(msg);
|
|
3677
|
-
if (assistantText) {
|
|
3678
|
-
finalAssistantText = assistantText;
|
|
3679
|
-
if (options?.outputFormat && fullText.length === 0) {
|
|
3680
|
-
fullText = assistantText;
|
|
3681
|
-
}
|
|
3682
|
-
}
|
|
3683
|
-
if (msg.type === DroidMessageType.TokenUsageUpdate) {
|
|
3684
|
-
lastTokenUsage = msg;
|
|
3685
|
-
}
|
|
3686
|
-
if (msg.type === DroidMessageType.Error && firstError === null) {
|
|
3687
|
-
firstError = msg;
|
|
3688
|
-
}
|
|
3689
|
-
if (options?.outputFormat && structuredOutput === null) {
|
|
3690
|
-
const textToParse = finalAssistantText || fullText;
|
|
3691
|
-
if (textToParse) {
|
|
3692
|
-
structuredOutput = parseJsonObject(textToParse);
|
|
3693
|
-
}
|
|
3694
|
-
}
|
|
3695
|
-
if (msg.type === DroidMessageType.TurnComplete) {
|
|
3696
|
-
turnCount++;
|
|
3697
|
-
if (msg.tokenUsage) {
|
|
3698
|
-
lastTokenUsage = msg.tokenUsage;
|
|
3699
|
-
}
|
|
3700
|
-
}
|
|
3701
|
-
}
|
|
3702
|
-
return {
|
|
3703
|
-
sessionId: this._sessionId,
|
|
3704
|
-
text: fullText,
|
|
3705
|
-
messages,
|
|
3706
|
-
tokenUsage: lastTokenUsage,
|
|
3707
|
-
durationMs: Date.now() - startedAt,
|
|
3708
|
-
turnCount,
|
|
3709
|
-
error: firstError,
|
|
3710
|
-
structuredOutput,
|
|
3711
|
-
success: firstError === null
|
|
3712
|
-
};
|
|
3713
|
-
}
|
|
3714
3806
|
async interrupt() {
|
|
3715
3807
|
this._ensureNotClosed();
|
|
3716
3808
|
await this._client.interruptSession();
|
|
@@ -3722,7 +3814,12 @@ var DroidSession = class {
|
|
|
3722
3814
|
this._closed = true;
|
|
3723
3815
|
this._cleanupAbortSignal?.();
|
|
3724
3816
|
this._cleanupAbortSignal = null;
|
|
3817
|
+
for (const bridge of this._activeBridges) {
|
|
3818
|
+
bridge.signalDone();
|
|
3819
|
+
}
|
|
3725
3820
|
try {
|
|
3821
|
+
await this._client.closeSession({ reason: "other" }).catch(() => {
|
|
3822
|
+
});
|
|
3726
3823
|
await this._client.close();
|
|
3727
3824
|
} finally {
|
|
3728
3825
|
const cleanups = this._cleanupCallbacks.splice(0);
|
|
@@ -3861,10 +3958,18 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3861
3958
|
}
|
|
3862
3959
|
|
|
3863
3960
|
// src/run.ts
|
|
3864
|
-
async function run(
|
|
3961
|
+
async function run(prompt, options = {}) {
|
|
3865
3962
|
const session = await createSession(options);
|
|
3866
3963
|
try {
|
|
3867
|
-
|
|
3964
|
+
for await (const msg of session.stream(prompt, {
|
|
3965
|
+
...options,
|
|
3966
|
+
includePartialMessages: false
|
|
3967
|
+
})) {
|
|
3968
|
+
if (msg.type === DroidMessageType.Result) {
|
|
3969
|
+
return msg;
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
throw new Error("Stream completed without a result message");
|
|
3868
3973
|
} finally {
|
|
3869
3974
|
await session.close();
|
|
3870
3975
|
}
|
|
@@ -4111,6 +4216,7 @@ async function listSessions(options = {}) {
|
|
|
4111
4216
|
AskUserRequestSchema,
|
|
4112
4217
|
AskUserResponseSchema,
|
|
4113
4218
|
AskUserResultSchema,
|
|
4219
|
+
AssistantTextCompleteNotificationSchema,
|
|
4114
4220
|
AssistantTextDeltaNotificationSchema,
|
|
4115
4221
|
AuthenticateMcpServerRequestParamsSchema,
|
|
4116
4222
|
AuthenticateMcpServerRequestSchema,
|
|
@@ -4135,6 +4241,10 @@ async function listSessions(options = {}) {
|
|
|
4135
4241
|
ClearMcpAuthResultSchema,
|
|
4136
4242
|
CliRequestOrNotificationSchema,
|
|
4137
4243
|
ClientRequestSchema,
|
|
4244
|
+
CloseSessionRequestParamsSchema,
|
|
4245
|
+
CloseSessionRequestSchema,
|
|
4246
|
+
CloseSessionResponseSchema,
|
|
4247
|
+
CloseSessionResultSchema,
|
|
4138
4248
|
CompactSessionRequestParamsSchema,
|
|
4139
4249
|
CompactSessionRequestSchema,
|
|
4140
4250
|
CompactSessionResponseSchema,
|
|
@@ -4155,6 +4265,10 @@ async function listSessions(options = {}) {
|
|
|
4155
4265
|
DroidClient,
|
|
4156
4266
|
DroidClientMethod,
|
|
4157
4267
|
DroidErrorType,
|
|
4268
|
+
DroidHookEventSchema,
|
|
4269
|
+
DroidHookExecutionResultSchema,
|
|
4270
|
+
DroidHookOutputSchema,
|
|
4271
|
+
DroidHookSpecificOutputSchema,
|
|
4158
4272
|
DroidInteractionMode,
|
|
4159
4273
|
DroidMessageType,
|
|
4160
4274
|
DroidServerMethod,
|
|
@@ -4195,6 +4309,10 @@ async function listSessions(options = {}) {
|
|
|
4195
4309
|
GitRepoInfoSchema,
|
|
4196
4310
|
HandoffItemsDismissedEntrySchema,
|
|
4197
4311
|
HandoffSchema,
|
|
4312
|
+
HookCommandSchema,
|
|
4313
|
+
HookExecutionCompletedNotificationSchema,
|
|
4314
|
+
HookExecutionStartedNotificationSchema,
|
|
4315
|
+
HookResultSchema,
|
|
4198
4316
|
HttpHeaderSchema,
|
|
4199
4317
|
HttpMcpConfigSchema,
|
|
4200
4318
|
ImageBlockSchema,
|
|
@@ -4343,6 +4461,8 @@ async function listSessions(options = {}) {
|
|
|
4343
4461
|
StartMissionRunConfirmationDetailsSchema,
|
|
4344
4462
|
StdioMcpConfigSchema,
|
|
4345
4463
|
StreamStateTracker,
|
|
4464
|
+
StructuredOutputErrorSchema,
|
|
4465
|
+
StructuredOutputNotificationSchema,
|
|
4346
4466
|
SubmitBugReportRequestParamsSchema,
|
|
4347
4467
|
SubmitBugReportRequestSchema,
|
|
4348
4468
|
SubmitBugReportResponseSchema,
|
|
@@ -4357,6 +4477,7 @@ async function listSessions(options = {}) {
|
|
|
4357
4477
|
TestsSchema,
|
|
4358
4478
|
TextBlockSchema,
|
|
4359
4479
|
ThinkingBlockSchema,
|
|
4480
|
+
ThinkingTextCompleteNotificationSchema,
|
|
4360
4481
|
ThinkingTextDeltaNotificationSchema,
|
|
4361
4482
|
TimeoutError,
|
|
4362
4483
|
ToggleMcpServerRequestParamsSchema,
|
|
@@ -4368,6 +4489,7 @@ async function listSessions(options = {}) {
|
|
|
4368
4489
|
ToggleMcpToolResponseSchema,
|
|
4369
4490
|
ToggleMcpToolResultSchema,
|
|
4370
4491
|
TokenUsageSchema,
|
|
4492
|
+
ToolCallNotificationSchema,
|
|
4371
4493
|
ToolConfirmationDetailsSchema,
|
|
4372
4494
|
ToolConfirmationInfoSchema,
|
|
4373
4495
|
ToolConfirmationListItemSchema,
|
|
@@ -4394,10 +4516,11 @@ async function listSessions(options = {}) {
|
|
|
4394
4516
|
WorkerStartedEntrySchema,
|
|
4395
4517
|
WorkerStateInfoSchema,
|
|
4396
4518
|
convertNotificationToStreamMessage,
|
|
4519
|
+
createResponseSchema,
|
|
4397
4520
|
createSdkMcpServer,
|
|
4398
4521
|
createSession,
|
|
4522
|
+
dispatchNotification,
|
|
4399
4523
|
listSessions,
|
|
4400
|
-
query,
|
|
4401
4524
|
resumeSession,
|
|
4402
4525
|
run,
|
|
4403
4526
|
tool
|