@factory/droid-sdk 0.1.4 → 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 +400 -76
- package/dist/index.cjs +2154 -1458
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8065 -4332
- package/dist/index.d.ts +8065 -4332
- package/dist/index.js +2078 -1456
- package/dist/index.js.map +1 -1
- package/docs/sdk-usage-guide.md +678 -0
- package/examples/.gitkeep +1 -0
- package/examples/abort-session-stream.ts +31 -0
- package/examples/droid-dev-structured-output.ts +43 -0
- package/examples/fork-session.ts +61 -0
- package/examples/hook-execution.ts +62 -0
- package/examples/init-metadata.ts +19 -0
- package/examples/interrupt-session.ts +32 -0
- package/examples/list-sessions.ts +19 -0
- package/examples/multi-turn-session.ts +35 -0
- package/examples/permission-handler.ts +40 -0
- package/examples/readme-structured-output.ts +25 -0
- package/examples/result-metadata.ts +62 -0
- package/examples/run.ts +38 -0
- package/examples/sdk-mcp-tool.ts +42 -0
- package/examples/session-stream.ts +54 -0
- package/examples/spec-mode-new-session.ts +60 -0
- package/examples/spec-mode-same-session.ts +71 -0
- package/examples/structured-output.ts +59 -0
- package/examples/test-compact.ts +62 -0
- package/examples/test-rewind.ts +87 -0
- package/examples/tool-controls.ts +36 -0
- package/package.json +26 -4
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,
|
|
@@ -59,6 +60,7 @@ __export(index_exports, {
|
|
|
59
60
|
BaseRequestSchema: () => BaseRequestSchema,
|
|
60
61
|
BaseResponseFailureSchema: () => BaseResponseFailureSchema,
|
|
61
62
|
BaseResponseSuccessSchema: () => BaseResponseSuccessSchema,
|
|
63
|
+
COMPACTION_TIMEOUT: () => COMPACTION_TIMEOUT,
|
|
62
64
|
CancelMcpAuthRequestParamsSchema: () => CancelMcpAuthRequestParamsSchema,
|
|
63
65
|
CancelMcpAuthRequestSchema: () => CancelMcpAuthRequestSchema,
|
|
64
66
|
CancelMcpAuthResponseSchema: () => CancelMcpAuthResponseSchema,
|
|
@@ -69,8 +71,18 @@ __export(index_exports, {
|
|
|
69
71
|
ClearMcpAuthResultSchema: () => ClearMcpAuthResultSchema,
|
|
70
72
|
CliRequestOrNotificationSchema: () => CliRequestOrNotificationSchema,
|
|
71
73
|
ClientRequestSchema: () => ClientRequestSchema,
|
|
74
|
+
CloseSessionRequestParamsSchema: () => CloseSessionRequestParamsSchema,
|
|
75
|
+
CloseSessionRequestSchema: () => CloseSessionRequestSchema,
|
|
76
|
+
CloseSessionResponseSchema: () => CloseSessionResponseSchema,
|
|
77
|
+
CloseSessionResultSchema: () => CloseSessionResultSchema,
|
|
78
|
+
CompactSessionRequestParamsSchema: () => CompactSessionRequestParamsSchema,
|
|
79
|
+
CompactSessionRequestSchema: () => CompactSessionRequestSchema,
|
|
80
|
+
CompactSessionResponseSchema: () => CompactSessionResponseSchema,
|
|
81
|
+
CompactSessionResultSchema: () => CompactSessionResultSchema,
|
|
72
82
|
ConnectionError: () => ConnectionError,
|
|
73
83
|
ContentBlockSchema: () => ContentBlockSchema,
|
|
84
|
+
ContextStatsAccuracy: () => ContextStatsAccuracy,
|
|
85
|
+
ContextStatsSchema: () => ContextStatsSchema,
|
|
74
86
|
CreateMessageNotificationSchema: () => CreateMessageNotificationSchema,
|
|
75
87
|
CreateToolConfirmationDetailsSchema: () => CreateToolConfirmationDetailsSchema,
|
|
76
88
|
DEFAULT_REQUEST_TIMEOUT: () => DEFAULT_REQUEST_TIMEOUT,
|
|
@@ -83,26 +95,54 @@ __export(index_exports, {
|
|
|
83
95
|
DroidClient: () => DroidClient,
|
|
84
96
|
DroidClientMethod: () => DroidClientMethod,
|
|
85
97
|
DroidErrorType: () => DroidErrorType,
|
|
98
|
+
DroidHookEventSchema: () => DroidHookEventSchema,
|
|
99
|
+
DroidHookExecutionResultSchema: () => DroidHookExecutionResultSchema,
|
|
100
|
+
DroidHookOutputSchema: () => DroidHookOutputSchema,
|
|
101
|
+
DroidHookSpecificOutputSchema: () => DroidHookSpecificOutputSchema,
|
|
86
102
|
DroidInteractionMode: () => DroidInteractionMode,
|
|
103
|
+
DroidMessageType: () => DroidMessageType,
|
|
87
104
|
DroidServerMethod: () => DroidServerMethod,
|
|
88
105
|
DroidSession: () => DroidSession,
|
|
89
106
|
DroidWorkingState: () => DroidWorkingState,
|
|
90
107
|
DroidWorkingStateChangedNotificationSchema: () => DroidWorkingStateChangedNotificationSchema,
|
|
91
108
|
EditToolConfirmationDetailsSchema: () => EditToolConfirmationDetailsSchema,
|
|
109
|
+
EmptyResultSchema: () => EmptyResultSchema,
|
|
92
110
|
ErrorDetailSchema: () => ErrorDetailSchema,
|
|
93
111
|
ErrorNotificationSchema: () => ErrorNotificationSchema,
|
|
112
|
+
ExecToolInfoSchema: () => ExecToolInfoSchema,
|
|
113
|
+
ExecuteRewindRequestParamsSchema: () => ExecuteRewindRequestParamsSchema,
|
|
114
|
+
ExecuteRewindRequestSchema: () => ExecuteRewindRequestSchema,
|
|
115
|
+
ExecuteRewindResponseSchema: () => ExecuteRewindResponseSchema,
|
|
116
|
+
ExecuteRewindResultSchema: () => ExecuteRewindResultSchema,
|
|
94
117
|
ExecuteToolConfirmationDetailsSchema: () => ExecuteToolConfirmationDetailsSchema,
|
|
95
118
|
ExitSpecModeConfirmationDetailsSchema: () => ExitSpecModeConfirmationDetailsSchema,
|
|
96
119
|
FACTORY_CLIENT_HEADER: () => FACTORY_CLIENT_HEADER,
|
|
97
120
|
FACTORY_CLIENT_VERSION: () => FACTORY_CLIENT_VERSION,
|
|
98
121
|
FACTORY_PROTOCOL_VERSION: () => FACTORY_PROTOCOL_VERSION,
|
|
122
|
+
FactoryDroidMessageRole: () => FactoryDroidMessageRole,
|
|
99
123
|
FactoryDroidMessageSchema: () => FactoryDroidMessageSchema,
|
|
100
124
|
FeatureStatus: () => FeatureStatus,
|
|
101
125
|
FeatureSuccessState: () => FeatureSuccessState,
|
|
102
126
|
FeatureSuccessStateSchema: () => FeatureSuccessStateSchema,
|
|
127
|
+
ForkSessionRequestParamsSchema: () => ForkSessionRequestParamsSchema,
|
|
128
|
+
ForkSessionRequestSchema: () => ForkSessionRequestSchema,
|
|
129
|
+
ForkSessionResponseSchema: () => ForkSessionResponseSchema,
|
|
130
|
+
ForkSessionResultSchema: () => ForkSessionResultSchema,
|
|
131
|
+
GetContextStatsRequestParamsSchema: () => GetContextStatsRequestParamsSchema,
|
|
132
|
+
GetContextStatsRequestSchema: () => GetContextStatsRequestSchema,
|
|
133
|
+
GetContextStatsResponseSchema: () => GetContextStatsResponseSchema,
|
|
134
|
+
GetContextStatsResultSchema: () => GetContextStatsResultSchema,
|
|
135
|
+
GetRewindInfoRequestParamsSchema: () => GetRewindInfoRequestParamsSchema,
|
|
136
|
+
GetRewindInfoRequestSchema: () => GetRewindInfoRequestSchema,
|
|
137
|
+
GetRewindInfoResponseSchema: () => GetRewindInfoResponseSchema,
|
|
138
|
+
GetRewindInfoResultSchema: () => GetRewindInfoResultSchema,
|
|
103
139
|
GitRepoInfoSchema: () => GitRepoInfoSchema,
|
|
104
140
|
HandoffItemsDismissedEntrySchema: () => HandoffItemsDismissedEntrySchema,
|
|
105
141
|
HandoffSchema: () => HandoffSchema,
|
|
142
|
+
HookCommandSchema: () => HookCommandSchema,
|
|
143
|
+
HookExecutionCompletedNotificationSchema: () => HookExecutionCompletedNotificationSchema,
|
|
144
|
+
HookExecutionStartedNotificationSchema: () => HookExecutionStartedNotificationSchema,
|
|
145
|
+
HookResultSchema: () => HookResultSchema,
|
|
106
146
|
HttpHeaderSchema: () => HttpHeaderSchema,
|
|
107
147
|
HttpMcpConfigSchema: () => HttpMcpConfigSchema,
|
|
108
148
|
ImageBlockSchema: () => ImageBlockSchema,
|
|
@@ -117,6 +157,8 @@ __export(index_exports, {
|
|
|
117
157
|
InterruptSessionResultSchema: () => InterruptSessionResultSchema,
|
|
118
158
|
IssueSeverity: () => IssueSeverity,
|
|
119
159
|
JSONRPC_VERSION: () => JSONRPC_VERSION,
|
|
160
|
+
JsonArraySchema: () => JsonArraySchema,
|
|
161
|
+
JsonObjectSchema: () => JsonObjectSchema,
|
|
120
162
|
JsonRpcEnvelopeSchema: () => JsonRpcEnvelopeSchema,
|
|
121
163
|
JsonRpcErrorCode: () => JsonRpcErrorCode,
|
|
122
164
|
JsonRpcErrorSchema: () => JsonRpcErrorSchema,
|
|
@@ -127,6 +169,7 @@ __export(index_exports, {
|
|
|
127
169
|
JsonRpcResponseFailureSchema: () => JsonRpcResponseFailureSchema,
|
|
128
170
|
JsonRpcResponseSchema: () => JsonRpcResponseSchema,
|
|
129
171
|
JsonRpcResponseSuccessSchema: () => JsonRpcResponseSuccessSchema,
|
|
172
|
+
JsonValueSchema: () => JsonValueSchema,
|
|
130
173
|
KillWorkerSessionRequestParamsSchema: () => KillWorkerSessionRequestParamsSchema,
|
|
131
174
|
KillWorkerSessionRequestSchema: () => KillWorkerSessionRequestSchema,
|
|
132
175
|
KillWorkerSessionResponseSchema: () => KillWorkerSessionResponseSchema,
|
|
@@ -148,6 +191,10 @@ __export(index_exports, {
|
|
|
148
191
|
ListSkillsRequestSchema: () => ListSkillsRequestSchema,
|
|
149
192
|
ListSkillsResponseSchema: () => ListSkillsResponseSchema,
|
|
150
193
|
ListSkillsResultSchema: () => ListSkillsResultSchema,
|
|
194
|
+
ListToolsRequestParamsSchema: () => ListToolsRequestParamsSchema,
|
|
195
|
+
ListToolsRequestSchema: () => ListToolsRequestSchema,
|
|
196
|
+
ListToolsResponseSchema: () => ListToolsResponseSchema,
|
|
197
|
+
ListToolsResultSchema: () => ListToolsResultSchema,
|
|
151
198
|
LoadSessionRequestParamsSchema: () => LoadSessionRequestParamsSchema,
|
|
152
199
|
LoadSessionRequestSchema: () => LoadSessionRequestSchema,
|
|
153
200
|
LoadSessionResponseSchema: () => LoadSessionResponseSchema,
|
|
@@ -185,6 +232,8 @@ __export(index_exports, {
|
|
|
185
232
|
MissionWorkerCompletedNotificationSchema: () => MissionWorkerCompletedNotificationSchema,
|
|
186
233
|
MissionWorkerStartedNotificationSchema: () => MissionWorkerStartedNotificationSchema,
|
|
187
234
|
ModelProvider: () => ModelProvider,
|
|
235
|
+
OutputFormatSchema: () => OutputFormatSchema,
|
|
236
|
+
OutputFormatType: () => OutputFormatType,
|
|
188
237
|
PermissionResolvedNotificationSchema: () => PermissionResolvedNotificationSchema,
|
|
189
238
|
ProcessExitError: () => ProcessExitError,
|
|
190
239
|
ProcessTransport: () => ProcessTransport,
|
|
@@ -193,26 +242,40 @@ __export(index_exports, {
|
|
|
193
242
|
ProposeMissionConfirmationDetailsSchema: () => ProposeMissionConfirmationDetailsSchema,
|
|
194
243
|
ProtocolEngine: () => ProtocolEngine,
|
|
195
244
|
ProtocolError: () => ProtocolError,
|
|
245
|
+
REWIND_TIMEOUT: () => REWIND_TIMEOUT,
|
|
196
246
|
ReasoningEffort: () => ReasoningEffort,
|
|
197
247
|
RedactedThinkingBlockSchema: () => RedactedThinkingBlockSchema,
|
|
198
248
|
RemoveMcpServerRequestParamsSchema: () => RemoveMcpServerRequestParamsSchema,
|
|
199
249
|
RemoveMcpServerRequestSchema: () => RemoveMcpServerRequestSchema,
|
|
200
250
|
RemoveMcpServerResponseSchema: () => RemoveMcpServerResponseSchema,
|
|
201
251
|
RemoveMcpServerResultSchema: () => RemoveMcpServerResultSchema,
|
|
252
|
+
RenameSessionRequestParamsSchema: () => RenameSessionRequestParamsSchema,
|
|
253
|
+
RenameSessionRequestSchema: () => RenameSessionRequestSchema,
|
|
254
|
+
RenameSessionResponseSchema: () => RenameSessionResponseSchema,
|
|
255
|
+
RenameSessionResultSchema: () => RenameSessionResultSchema,
|
|
202
256
|
RequestPermissionRequestParamsSchema: () => RequestPermissionRequestParamsSchema,
|
|
203
257
|
RequestPermissionRequestSchema: () => RequestPermissionRequestSchema,
|
|
204
258
|
RequestPermissionResponseSchema: () => RequestPermissionResponseSchema,
|
|
205
259
|
RequestPermissionResultSchema: () => RequestPermissionResultSchema,
|
|
260
|
+
RewindEvictedFileSchema: () => RewindEvictedFileSchema,
|
|
261
|
+
RewindFileCreationSchema: () => RewindFileCreationSchema,
|
|
262
|
+
RewindFileSnapshotSchema: () => RewindFileSnapshotSchema,
|
|
263
|
+
SDK_TAG: () => SDK_TAG,
|
|
264
|
+
SDK_VERSION: () => SDK_VERSION,
|
|
206
265
|
SESSION_INIT_TIMEOUT: () => SESSION_INIT_TIMEOUT,
|
|
266
|
+
SdkMcpServer: () => SdkMcpServer,
|
|
207
267
|
SessionError: () => SessionError,
|
|
268
|
+
SessionMetadataSchema: () => SessionMetadataSchema,
|
|
208
269
|
SessionNotFoundError: () => SessionNotFoundError,
|
|
209
270
|
SessionNotificationParamsSchema: () => SessionNotificationParamsSchema,
|
|
210
271
|
SessionNotificationPayloadSchema: () => SessionNotificationPayloadSchema,
|
|
211
272
|
SessionNotificationSchema: () => SessionNotificationSchema,
|
|
212
273
|
SessionNotificationSchemaList: () => SessionNotificationSchemaList,
|
|
213
274
|
SessionNotificationType: () => SessionNotificationType,
|
|
275
|
+
SessionSettingsFileSchema: () => SessionSettingsFileSchema,
|
|
214
276
|
SessionSettingsSchema: () => SessionSettingsSchema,
|
|
215
277
|
SessionSourceSchema: () => SessionSourceSchema,
|
|
278
|
+
SessionStartEventSchema: () => SessionStartEventSchema,
|
|
216
279
|
SessionTagSchema: () => SessionTagSchema,
|
|
217
280
|
SessionTitleUpdatedNotificationSchema: () => SessionTitleUpdatedNotificationSchema,
|
|
218
281
|
SessionTokenUsageChangedNotificationSchema: () => SessionTokenUsageChangedNotificationSchema,
|
|
@@ -228,6 +291,8 @@ __export(index_exports, {
|
|
|
228
291
|
StartMissionRunConfirmationDetailsSchema: () => StartMissionRunConfirmationDetailsSchema,
|
|
229
292
|
StdioMcpConfigSchema: () => StdioMcpConfigSchema,
|
|
230
293
|
StreamStateTracker: () => StreamStateTracker,
|
|
294
|
+
StructuredOutputErrorSchema: () => StructuredOutputErrorSchema,
|
|
295
|
+
StructuredOutputNotificationSchema: () => StructuredOutputNotificationSchema,
|
|
231
296
|
SubmitBugReportRequestParamsSchema: () => SubmitBugReportRequestParamsSchema,
|
|
232
297
|
SubmitBugReportRequestSchema: () => SubmitBugReportRequestSchema,
|
|
233
298
|
SubmitBugReportResponseSchema: () => SubmitBugReportResponseSchema,
|
|
@@ -236,11 +301,13 @@ __export(index_exports, {
|
|
|
236
301
|
SubmitMcpAuthCodeRequestSchema: () => SubmitMcpAuthCodeRequestSchema,
|
|
237
302
|
SubmitMcpAuthCodeResponseSchema: () => SubmitMcpAuthCodeResponseSchema,
|
|
238
303
|
SubmitMcpAuthCodeResultSchema: () => SubmitMcpAuthCodeResultSchema,
|
|
304
|
+
SuccessResultSchema: () => SuccessResultSchema,
|
|
239
305
|
TestCaseSchema: () => TestCaseSchema,
|
|
240
306
|
TestFileSchema: () => TestFileSchema,
|
|
241
307
|
TestsSchema: () => TestsSchema,
|
|
242
308
|
TextBlockSchema: () => TextBlockSchema,
|
|
243
309
|
ThinkingBlockSchema: () => ThinkingBlockSchema,
|
|
310
|
+
ThinkingTextCompleteNotificationSchema: () => ThinkingTextCompleteNotificationSchema,
|
|
244
311
|
ThinkingTextDeltaNotificationSchema: () => ThinkingTextDeltaNotificationSchema,
|
|
245
312
|
TimeoutError: () => TimeoutError,
|
|
246
313
|
ToggleMcpServerRequestParamsSchema: () => ToggleMcpServerRequestParamsSchema,
|
|
@@ -252,6 +319,7 @@ __export(index_exports, {
|
|
|
252
319
|
ToggleMcpToolResponseSchema: () => ToggleMcpToolResponseSchema,
|
|
253
320
|
ToggleMcpToolResultSchema: () => ToggleMcpToolResultSchema,
|
|
254
321
|
TokenUsageSchema: () => TokenUsageSchema,
|
|
322
|
+
ToolCallNotificationSchema: () => ToolCallNotificationSchema,
|
|
255
323
|
ToolConfirmationDetailsSchema: () => ToolConfirmationDetailsSchema,
|
|
256
324
|
ToolConfirmationInfoSchema: () => ToolConfirmationInfoSchema,
|
|
257
325
|
ToolConfirmationListItemSchema: () => ToolConfirmationListItemSchema,
|
|
@@ -261,6 +329,7 @@ __export(index_exports, {
|
|
|
261
329
|
ToolProgressUpdateSchema: () => ToolProgressUpdateSchema,
|
|
262
330
|
ToolResultBlockSchema: () => ToolResultBlockSchema,
|
|
263
331
|
ToolResultNotificationSchema: () => ToolResultNotificationSchema,
|
|
332
|
+
ToolSelectionOverridesSchema: () => ToolSelectionOverridesSchema,
|
|
264
333
|
ToolUseBlockSchema: () => ToolUseBlockSchema,
|
|
265
334
|
ToolUseSchema: () => ToolUseSchema,
|
|
266
335
|
TraceContextMetaSchema: () => TraceContextMetaSchema,
|
|
@@ -277,9 +346,14 @@ __export(index_exports, {
|
|
|
277
346
|
WorkerStartedEntrySchema: () => WorkerStartedEntrySchema,
|
|
278
347
|
WorkerStateInfoSchema: () => WorkerStateInfoSchema,
|
|
279
348
|
convertNotificationToStreamMessage: () => convertNotificationToStreamMessage,
|
|
349
|
+
createResponseSchema: () => createResponseSchema,
|
|
350
|
+
createSdkMcpServer: () => createSdkMcpServer,
|
|
280
351
|
createSession: () => createSession,
|
|
281
|
-
|
|
282
|
-
|
|
352
|
+
dispatchNotification: () => dispatchNotification,
|
|
353
|
+
listSessions: () => listSessions,
|
|
354
|
+
resumeSession: () => resumeSession,
|
|
355
|
+
run: () => run,
|
|
356
|
+
tool: () => tool
|
|
283
357
|
});
|
|
284
358
|
module.exports = __toCommonJS(index_exports);
|
|
285
359
|
|
|
@@ -288,6 +362,7 @@ var DroidServerMethod = /* @__PURE__ */ ((DroidServerMethod2) => {
|
|
|
288
362
|
DroidServerMethod2["INITIALIZE_SESSION"] = "droid.initialize_session";
|
|
289
363
|
DroidServerMethod2["LOAD_SESSION"] = "droid.load_session";
|
|
290
364
|
DroidServerMethod2["ADD_USER_MESSAGE"] = "droid.add_user_message";
|
|
365
|
+
DroidServerMethod2["CLOSE_SESSION"] = "droid.close_session";
|
|
291
366
|
DroidServerMethod2["INTERRUPT_SESSION"] = "droid.interrupt_session";
|
|
292
367
|
DroidServerMethod2["KILL_WORKER_SESSION"] = "droid.kill_worker_session";
|
|
293
368
|
DroidServerMethod2["UPDATE_SESSION_SETTINGS"] = "droid.update_session_settings";
|
|
@@ -299,11 +374,18 @@ var DroidServerMethod = /* @__PURE__ */ ((DroidServerMethod2) => {
|
|
|
299
374
|
DroidServerMethod2["REMOVE_MCP_SERVER"] = "droid.remove_mcp_server";
|
|
300
375
|
DroidServerMethod2["LIST_MCP_REGISTRY"] = "droid.list_mcp_registry";
|
|
301
376
|
DroidServerMethod2["LIST_MCP_TOOLS"] = "droid.list_mcp_tools";
|
|
377
|
+
DroidServerMethod2["LIST_TOOLS"] = "droid.list_tools";
|
|
302
378
|
DroidServerMethod2["LIST_MCP_SERVERS"] = "droid.list_mcp_servers";
|
|
303
379
|
DroidServerMethod2["TOGGLE_MCP_TOOL"] = "droid.toggle_mcp_tool";
|
|
304
380
|
DroidServerMethod2["SUBMIT_MCP_AUTH_CODE"] = "droid.submit_mcp_auth_code";
|
|
305
381
|
DroidServerMethod2["LIST_SKILLS"] = "droid.list_skills";
|
|
306
382
|
DroidServerMethod2["SUBMIT_BUG_REPORT"] = "droid.submit_bug_report";
|
|
383
|
+
DroidServerMethod2["GET_REWIND_INFO"] = "droid.get_rewind_info";
|
|
384
|
+
DroidServerMethod2["EXECUTE_REWIND"] = "droid.execute_rewind";
|
|
385
|
+
DroidServerMethod2["COMPACT_SESSION"] = "droid.compact_session";
|
|
386
|
+
DroidServerMethod2["FORK_SESSION"] = "droid.fork_session";
|
|
387
|
+
DroidServerMethod2["RENAME_SESSION"] = "droid.rename_session";
|
|
388
|
+
DroidServerMethod2["GET_CONTEXT_STATS"] = "droid.get_context_stats";
|
|
307
389
|
return DroidServerMethod2;
|
|
308
390
|
})(DroidServerMethod || {});
|
|
309
391
|
var DroidClientMethod = /* @__PURE__ */ ((DroidClientMethod2) => {
|
|
@@ -323,7 +405,10 @@ var SessionNotificationType = /* @__PURE__ */ ((SessionNotificationType2) => {
|
|
|
323
405
|
SessionNotificationType2["SESSION_TITLE_UPDATED"] = "session_title_updated";
|
|
324
406
|
SessionNotificationType2["MCP_STATUS_CHANGED"] = "mcp_status_changed";
|
|
325
407
|
SessionNotificationType2["ASSISTANT_TEXT_DELTA"] = "assistant_text_delta";
|
|
408
|
+
SessionNotificationType2["ASSISTANT_TEXT_COMPLETE"] = "assistant_text_complete";
|
|
326
409
|
SessionNotificationType2["THINKING_TEXT_DELTA"] = "thinking_text_delta";
|
|
410
|
+
SessionNotificationType2["THINKING_TEXT_COMPLETE"] = "thinking_text_complete";
|
|
411
|
+
SessionNotificationType2["TOOL_CALL"] = "tool_call";
|
|
327
412
|
SessionNotificationType2["SESSION_TOKEN_USAGE_CHANGED"] = "session_token_usage_changed";
|
|
328
413
|
SessionNotificationType2["MISSION_STATE_CHANGED"] = "mission_state_changed";
|
|
329
414
|
SessionNotificationType2["MISSION_FEATURES_CHANGED"] = "mission_features_changed";
|
|
@@ -333,6 +418,9 @@ var SessionNotificationType = /* @__PURE__ */ ((SessionNotificationType2) => {
|
|
|
333
418
|
SessionNotificationType2["MISSION_WORKER_COMPLETED"] = "mission_worker_completed";
|
|
334
419
|
SessionNotificationType2["MCP_AUTH_REQUIRED"] = "mcp_auth_required";
|
|
335
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";
|
|
336
424
|
return SessionNotificationType2;
|
|
337
425
|
})(SessionNotificationType || {});
|
|
338
426
|
var ToolConfirmationOutcome = /* @__PURE__ */ ((ToolConfirmationOutcome3) => {
|
|
@@ -342,6 +430,10 @@ var ToolConfirmationOutcome = /* @__PURE__ */ ((ToolConfirmationOutcome3) => {
|
|
|
342
430
|
ToolConfirmationOutcome3["ProceedAutoRunLow"] = "proceed_auto_run_low";
|
|
343
431
|
ToolConfirmationOutcome3["ProceedAutoRunMedium"] = "proceed_auto_run_medium";
|
|
344
432
|
ToolConfirmationOutcome3["ProceedAutoRunHigh"] = "proceed_auto_run_high";
|
|
433
|
+
ToolConfirmationOutcome3["ProceedNewSession"] = "proceed_new_session";
|
|
434
|
+
ToolConfirmationOutcome3["ProceedNewSessionLow"] = "proceed_new_session_low";
|
|
435
|
+
ToolConfirmationOutcome3["ProceedNewSessionMedium"] = "proceed_new_session_medium";
|
|
436
|
+
ToolConfirmationOutcome3["ProceedNewSessionHigh"] = "proceed_new_session_high";
|
|
345
437
|
ToolConfirmationOutcome3["ProceedEdit"] = "proceed_edit";
|
|
346
438
|
ToolConfirmationOutcome3["Cancel"] = "cancel";
|
|
347
439
|
return ToolConfirmationOutcome3;
|
|
@@ -366,6 +458,11 @@ var DroidWorkingState = /* @__PURE__ */ ((DroidWorkingState2) => {
|
|
|
366
458
|
DroidWorkingState2["CompactingConversation"] = "compacting_conversation";
|
|
367
459
|
return DroidWorkingState2;
|
|
368
460
|
})(DroidWorkingState || {});
|
|
461
|
+
var ContextStatsAccuracy = /* @__PURE__ */ ((ContextStatsAccuracy2) => {
|
|
462
|
+
ContextStatsAccuracy2["Exact"] = "exact";
|
|
463
|
+
ContextStatsAccuracy2["Estimated"] = "estimated";
|
|
464
|
+
return ContextStatsAccuracy2;
|
|
465
|
+
})(ContextStatsAccuracy || {});
|
|
369
466
|
var DroidErrorType = /* @__PURE__ */ ((DroidErrorType2) => {
|
|
370
467
|
DroidErrorType2["CONNECTION_ERROR"] = "ConnectionError";
|
|
371
468
|
DroidErrorType2["PROTOCOL_ERROR"] = "ProtocolError";
|
|
@@ -537,19 +634,39 @@ var SkillLocation = /* @__PURE__ */ ((SkillLocation2) => {
|
|
|
537
634
|
// src/schemas/constants.ts
|
|
538
635
|
var JSONRPC_VERSION = "2.0";
|
|
539
636
|
var LEGACY_FACTORY_API_VERSION = "1.0.0";
|
|
540
|
-
var FACTORY_PROTOCOL_VERSION = "1.
|
|
637
|
+
var FACTORY_PROTOCOL_VERSION = "1.3.0";
|
|
541
638
|
var FACTORY_CLIENT_HEADER = "X-Factory-Client";
|
|
542
639
|
var FACTORY_CLIENT_VERSION = "X-Client-Version";
|
|
543
640
|
var DEFAULT_REQUEST_TIMEOUT = 3e4;
|
|
544
641
|
var SESSION_INIT_TIMEOUT = 6e4;
|
|
545
642
|
var MCP_AUTH_TIMEOUT = 3e5;
|
|
643
|
+
var COMPACTION_TIMEOUT = 24e4;
|
|
644
|
+
var REWIND_TIMEOUT = 6e4;
|
|
546
645
|
|
|
547
646
|
// src/schemas/shared.ts
|
|
548
647
|
var import_zod = require("zod");
|
|
648
|
+
var JsonValueSchema = import_zod.z.lazy(
|
|
649
|
+
() => import_zod.z.union([
|
|
650
|
+
import_zod.z.string(),
|
|
651
|
+
import_zod.z.number(),
|
|
652
|
+
import_zod.z.boolean(),
|
|
653
|
+
import_zod.z.null(),
|
|
654
|
+
import_zod.z.array(JsonValueSchema),
|
|
655
|
+
import_zod.z.record(JsonValueSchema)
|
|
656
|
+
])
|
|
657
|
+
);
|
|
658
|
+
var JsonObjectSchema = import_zod.z.record(JsonValueSchema);
|
|
659
|
+
var JsonArraySchema = import_zod.z.array(JsonValueSchema);
|
|
549
660
|
var TraceContextMetaSchema = import_zod.z.object({
|
|
550
661
|
traceparent: import_zod.z.string().optional(),
|
|
551
662
|
tracestate: import_zod.z.string().optional()
|
|
552
663
|
});
|
|
664
|
+
var ToolSelectionOverridesSchema = import_zod.z.object({
|
|
665
|
+
enabledToolIds: import_zod.z.array(import_zod.z.string()).optional(),
|
|
666
|
+
disabledToolIds: import_zod.z.array(import_zod.z.string()).optional()
|
|
667
|
+
});
|
|
668
|
+
var EmptyResultSchema = import_zod.z.object({}).passthrough();
|
|
669
|
+
var SuccessResultSchema = import_zod.z.object({ success: import_zod.z.boolean() }).passthrough();
|
|
553
670
|
var JsonRpcEnvelopeSchema = import_zod.z.object({
|
|
554
671
|
jsonrpc: import_zod.z.literal(JSONRPC_VERSION),
|
|
555
672
|
factoryApiVersion: import_zod.z.literal(LEGACY_FACTORY_API_VERSION),
|
|
@@ -559,18 +676,18 @@ var JsonRpcEnvelopeSchema = import_zod.z.object({
|
|
|
559
676
|
var JsonRpcErrorSchema = import_zod.z.object({
|
|
560
677
|
code: import_zod.z.nativeEnum(JsonRpcErrorCode),
|
|
561
678
|
message: import_zod.z.string(),
|
|
562
|
-
data:
|
|
679
|
+
data: JsonValueSchema.optional()
|
|
563
680
|
});
|
|
564
681
|
var BaseRequestSchema = import_zod.z.object({
|
|
565
682
|
type: import_zod.z.literal("request"),
|
|
566
683
|
id: import_zod.z.string(),
|
|
567
684
|
method: import_zod.z.string(),
|
|
568
|
-
params:
|
|
685
|
+
params: JsonValueSchema.optional()
|
|
569
686
|
});
|
|
570
687
|
var BaseResponseSuccessSchema = import_zod.z.object({
|
|
571
688
|
type: import_zod.z.literal("response"),
|
|
572
689
|
id: import_zod.z.string(),
|
|
573
|
-
result:
|
|
690
|
+
result: JsonValueSchema
|
|
574
691
|
});
|
|
575
692
|
var BaseResponseFailureSchema = import_zod.z.object({
|
|
576
693
|
type: import_zod.z.literal("response"),
|
|
@@ -580,7 +697,7 @@ var BaseResponseFailureSchema = import_zod.z.object({
|
|
|
580
697
|
var BaseNotificationSchema = import_zod.z.object({
|
|
581
698
|
type: import_zod.z.literal("notification"),
|
|
582
699
|
method: import_zod.z.string(),
|
|
583
|
-
params:
|
|
700
|
+
params: JsonValueSchema.optional()
|
|
584
701
|
});
|
|
585
702
|
var JsonRpcRequestSchema = JsonRpcEnvelopeSchema.extend(
|
|
586
703
|
BaseRequestSchema.shape
|
|
@@ -603,61 +720,134 @@ var JsonRpcMessageSchema = import_zod.z.discriminatedUnion("type", [
|
|
|
603
720
|
JsonRpcEnvelopeSchema.extend({
|
|
604
721
|
type: import_zod.z.literal("response"),
|
|
605
722
|
id: import_zod.z.string().nullable(),
|
|
606
|
-
result:
|
|
723
|
+
result: JsonValueSchema.optional(),
|
|
607
724
|
error: JsonRpcErrorSchema.optional()
|
|
608
725
|
}),
|
|
609
726
|
JsonRpcNotificationSchema
|
|
610
727
|
]);
|
|
728
|
+
function createResponseSchema(resultSchema) {
|
|
729
|
+
return import_zod.z.union([
|
|
730
|
+
JsonRpcResponseSuccessSchema.extend({ result: resultSchema }),
|
|
731
|
+
JsonRpcResponseFailureSchema
|
|
732
|
+
]);
|
|
733
|
+
}
|
|
611
734
|
|
|
612
|
-
// src/schemas/
|
|
735
|
+
// src/schemas/session-metadata.ts
|
|
736
|
+
var import_zod6 = require("zod");
|
|
737
|
+
|
|
738
|
+
// src/schemas/client.ts
|
|
739
|
+
var import_zod5 = require("zod");
|
|
740
|
+
|
|
741
|
+
// src/schemas/mcp.ts
|
|
613
742
|
var import_zod2 = require("zod");
|
|
614
|
-
var
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
743
|
+
var McpStdioServerConfigFieldsSchema = import_zod2.z.object({
|
|
744
|
+
command: import_zod2.z.string().optional(),
|
|
745
|
+
args: import_zod2.z.array(import_zod2.z.string()).optional()
|
|
746
|
+
});
|
|
747
|
+
var McpHttpServerConfigFieldsSchema = import_zod2.z.object({
|
|
748
|
+
url: import_zod2.z.string().optional()
|
|
749
|
+
});
|
|
750
|
+
var McpSseServerConfigFieldsSchema = import_zod2.z.object({
|
|
751
|
+
url: import_zod2.z.string(),
|
|
752
|
+
headers: import_zod2.z.record(import_zod2.z.string()).optional()
|
|
753
|
+
});
|
|
754
|
+
var McpServerStatusInfoSchema = import_zod2.z.object({
|
|
755
|
+
name: import_zod2.z.string(),
|
|
756
|
+
status: import_zod2.z.nativeEnum(McpServerStatus),
|
|
757
|
+
source: import_zod2.z.nativeEnum(SettingsLevel),
|
|
758
|
+
isManaged: import_zod2.z.boolean(),
|
|
759
|
+
error: import_zod2.z.string().optional(),
|
|
760
|
+
toolCount: import_zod2.z.number().optional(),
|
|
761
|
+
serverType: import_zod2.z.nativeEnum(McpServerType).optional(),
|
|
762
|
+
hasAuthTokens: import_zod2.z.boolean().optional()
|
|
763
|
+
}).passthrough();
|
|
764
|
+
var McpStatusSummarySchema = import_zod2.z.object({
|
|
765
|
+
total: import_zod2.z.number(),
|
|
766
|
+
connected: import_zod2.z.number(),
|
|
767
|
+
connecting: import_zod2.z.number(),
|
|
768
|
+
failed: import_zod2.z.number(),
|
|
769
|
+
disabled: import_zod2.z.number().optional()
|
|
770
|
+
}).passthrough();
|
|
771
|
+
var McpRegistryServerSchema = import_zod2.z.object({
|
|
772
|
+
name: import_zod2.z.string(),
|
|
773
|
+
description: import_zod2.z.string(),
|
|
774
|
+
type: import_zod2.z.nativeEnum(McpServerType),
|
|
775
|
+
// Stdio config fields
|
|
776
|
+
command: import_zod2.z.string().optional(),
|
|
777
|
+
args: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
778
|
+
// HTTP config fields
|
|
779
|
+
url: import_zod2.z.string().optional(),
|
|
780
|
+
// Additional metadata
|
|
781
|
+
note: import_zod2.z.string().optional(),
|
|
782
|
+
logoUrl: import_zod2.z.string().optional()
|
|
783
|
+
}).passthrough();
|
|
784
|
+
var McpToolInputSchemaSchema = import_zod2.z.object({
|
|
785
|
+
type: import_zod2.z.string().optional(),
|
|
786
|
+
properties: JsonObjectSchema.optional(),
|
|
787
|
+
required: import_zod2.z.array(import_zod2.z.string()).optional()
|
|
788
|
+
}).passthrough();
|
|
789
|
+
var McpToolInfoSchema = import_zod2.z.object({
|
|
790
|
+
serverName: import_zod2.z.string(),
|
|
645
791
|
name: import_zod2.z.string(),
|
|
646
|
-
|
|
792
|
+
description: import_zod2.z.string().optional(),
|
|
793
|
+
isEnabled: import_zod2.z.boolean(),
|
|
794
|
+
isReadOnly: import_zod2.z.boolean().optional(),
|
|
795
|
+
inputSchema: McpToolInputSchemaSchema.optional()
|
|
796
|
+
}).passthrough();
|
|
797
|
+
var ToolConfirmationListItemSchema = import_zod2.z.object({
|
|
798
|
+
label: import_zod2.z.string(),
|
|
799
|
+
value: import_zod2.z.nativeEnum(ToolConfirmationOutcome)
|
|
800
|
+
}).passthrough();
|
|
801
|
+
|
|
802
|
+
// src/schemas/messages.ts
|
|
803
|
+
var import_zod3 = require("zod");
|
|
804
|
+
var TextBlockSchema = import_zod3.z.object({
|
|
805
|
+
type: import_zod3.z.literal("text"),
|
|
806
|
+
text: import_zod3.z.string(),
|
|
807
|
+
id: import_zod3.z.string().optional()
|
|
808
|
+
}).passthrough();
|
|
809
|
+
var Base64ImageSourceSchema = import_zod3.z.object({
|
|
810
|
+
type: import_zod3.z.literal("base64"),
|
|
811
|
+
data: import_zod3.z.string(),
|
|
812
|
+
mediaType: import_zod3.z.enum(["image/jpeg", "image/png", "image/gif", "image/webp"])
|
|
813
|
+
}).passthrough();
|
|
814
|
+
var ImageBlockSchema = import_zod3.z.object({
|
|
815
|
+
type: import_zod3.z.literal("image"),
|
|
816
|
+
source: Base64ImageSourceSchema,
|
|
817
|
+
id: import_zod3.z.string().optional()
|
|
647
818
|
}).passthrough();
|
|
648
|
-
var
|
|
649
|
-
type:
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
819
|
+
var ThinkingBlockSchema = import_zod3.z.object({
|
|
820
|
+
type: import_zod3.z.literal("thinking"),
|
|
821
|
+
signature: import_zod3.z.string(),
|
|
822
|
+
thinking: import_zod3.z.string(),
|
|
823
|
+
id: import_zod3.z.string().optional(),
|
|
824
|
+
signatureProvider: import_zod3.z.string().optional()
|
|
654
825
|
}).passthrough();
|
|
655
|
-
var
|
|
656
|
-
type:
|
|
657
|
-
|
|
658
|
-
id:
|
|
826
|
+
var RedactedThinkingBlockSchema = import_zod3.z.object({
|
|
827
|
+
type: import_zod3.z.literal("redacted_thinking"),
|
|
828
|
+
data: import_zod3.z.string(),
|
|
829
|
+
id: import_zod3.z.string().optional()
|
|
659
830
|
}).passthrough();
|
|
660
|
-
var
|
|
831
|
+
var ToolUseBlockSchema = import_zod3.z.object({
|
|
832
|
+
type: import_zod3.z.literal("tool_use"),
|
|
833
|
+
id: import_zod3.z.string(),
|
|
834
|
+
input: JsonObjectSchema,
|
|
835
|
+
name: import_zod3.z.string(),
|
|
836
|
+
thoughtSignature: import_zod3.z.string().optional()
|
|
837
|
+
}).passthrough();
|
|
838
|
+
var ToolResultBlockSchema = import_zod3.z.object({
|
|
839
|
+
type: import_zod3.z.literal("tool_result"),
|
|
840
|
+
toolUseId: import_zod3.z.string(),
|
|
841
|
+
content: import_zod3.z.union([import_zod3.z.string(), import_zod3.z.array(JsonValueSchema)]).optional(),
|
|
842
|
+
isError: import_zod3.z.boolean().optional(),
|
|
843
|
+
id: import_zod3.z.string().optional()
|
|
844
|
+
}).passthrough();
|
|
845
|
+
var DocumentBlockSchema = import_zod3.z.object({
|
|
846
|
+
type: import_zod3.z.literal("document"),
|
|
847
|
+
source: JsonObjectSchema,
|
|
848
|
+
id: import_zod3.z.string().optional()
|
|
849
|
+
}).passthrough();
|
|
850
|
+
var ContentBlockSchema = import_zod3.z.discriminatedUnion("type", [
|
|
661
851
|
TextBlockSchema,
|
|
662
852
|
ImageBlockSchema,
|
|
663
853
|
ThinkingBlockSchema,
|
|
@@ -666,83 +856,33 @@ var ContentBlockSchema = import_zod2.z.discriminatedUnion("type", [
|
|
|
666
856
|
ToolResultBlockSchema,
|
|
667
857
|
DocumentBlockSchema
|
|
668
858
|
]);
|
|
669
|
-
var
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
var McpStdioServerConfigFieldsSchema = import_zod3.z.object({
|
|
690
|
-
command: import_zod3.z.string().optional(),
|
|
691
|
-
args: import_zod3.z.array(import_zod3.z.string()).optional()
|
|
692
|
-
});
|
|
693
|
-
var McpHttpServerConfigFieldsSchema = import_zod3.z.object({
|
|
694
|
-
url: import_zod3.z.string().optional()
|
|
695
|
-
});
|
|
696
|
-
var McpSseServerConfigFieldsSchema = import_zod3.z.object({
|
|
697
|
-
url: import_zod3.z.string(),
|
|
698
|
-
headers: import_zod3.z.record(import_zod3.z.string()).optional()
|
|
699
|
-
});
|
|
700
|
-
var McpServerStatusInfoSchema = import_zod3.z.object({
|
|
701
|
-
name: import_zod3.z.string(),
|
|
702
|
-
status: import_zod3.z.nativeEnum(McpServerStatus),
|
|
703
|
-
source: import_zod3.z.nativeEnum(SettingsLevel),
|
|
704
|
-
isManaged: import_zod3.z.boolean(),
|
|
705
|
-
error: import_zod3.z.string().optional(),
|
|
706
|
-
toolCount: import_zod3.z.number().optional(),
|
|
707
|
-
serverType: import_zod3.z.nativeEnum(McpServerType).optional(),
|
|
708
|
-
hasAuthTokens: import_zod3.z.boolean().optional()
|
|
709
|
-
}).passthrough();
|
|
710
|
-
var McpStatusSummarySchema = import_zod3.z.object({
|
|
711
|
-
total: import_zod3.z.number(),
|
|
712
|
-
connected: import_zod3.z.number(),
|
|
713
|
-
connecting: import_zod3.z.number(),
|
|
714
|
-
failed: import_zod3.z.number(),
|
|
715
|
-
disabled: import_zod3.z.number().optional()
|
|
716
|
-
}).passthrough();
|
|
717
|
-
var McpRegistryServerSchema = import_zod3.z.object({
|
|
718
|
-
name: import_zod3.z.string(),
|
|
719
|
-
description: import_zod3.z.string(),
|
|
720
|
-
type: import_zod3.z.nativeEnum(McpServerType),
|
|
721
|
-
// Stdio config fields
|
|
722
|
-
command: import_zod3.z.string().optional(),
|
|
723
|
-
args: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
724
|
-
// HTTP config fields
|
|
725
|
-
url: import_zod3.z.string().optional(),
|
|
726
|
-
// Additional metadata
|
|
727
|
-
note: import_zod3.z.string().optional(),
|
|
728
|
-
logoUrl: import_zod3.z.string().optional()
|
|
729
|
-
}).passthrough();
|
|
730
|
-
var McpToolInputSchemaSchema = import_zod3.z.object({
|
|
731
|
-
type: import_zod3.z.string().optional(),
|
|
732
|
-
properties: import_zod3.z.record(import_zod3.z.unknown()).optional(),
|
|
733
|
-
required: import_zod3.z.array(import_zod3.z.string()).optional()
|
|
734
|
-
}).passthrough();
|
|
735
|
-
var McpToolInfoSchema = import_zod3.z.object({
|
|
736
|
-
serverName: import_zod3.z.string(),
|
|
737
|
-
name: import_zod3.z.string(),
|
|
738
|
-
description: import_zod3.z.string().optional(),
|
|
739
|
-
isEnabled: import_zod3.z.boolean(),
|
|
740
|
-
isReadOnly: import_zod3.z.boolean().optional(),
|
|
741
|
-
inputSchema: McpToolInputSchemaSchema.optional()
|
|
859
|
+
var FactoryDroidMessageRole = {
|
|
860
|
+
User: "user",
|
|
861
|
+
Assistant: "assistant",
|
|
862
|
+
Tool: "tool",
|
|
863
|
+
System: "system"
|
|
864
|
+
};
|
|
865
|
+
var FactoryDroidMessageSchema = import_zod3.z.object({
|
|
866
|
+
id: import_zod3.z.string(),
|
|
867
|
+
role: import_zod3.z.enum([
|
|
868
|
+
FactoryDroidMessageRole.User,
|
|
869
|
+
FactoryDroidMessageRole.Assistant,
|
|
870
|
+
FactoryDroidMessageRole.Tool,
|
|
871
|
+
FactoryDroidMessageRole.System
|
|
872
|
+
]),
|
|
873
|
+
content: import_zod3.z.array(ContentBlockSchema),
|
|
874
|
+
createdAt: import_zod3.z.number(),
|
|
875
|
+
updatedAt: import_zod3.z.number(),
|
|
876
|
+
parentId: import_zod3.z.string().optional(),
|
|
877
|
+
visibility: import_zod3.z.enum(["both", "llm_only", "user_only"]).optional(),
|
|
878
|
+
isError: import_zod3.z.boolean().optional()
|
|
742
879
|
}).passthrough();
|
|
743
|
-
var
|
|
744
|
-
|
|
745
|
-
|
|
880
|
+
var DocumentSourceSchema = import_zod3.z.object({
|
|
881
|
+
type: import_zod3.z.string(),
|
|
882
|
+
mediaType: import_zod3.z.string(),
|
|
883
|
+
data: import_zod3.z.string(),
|
|
884
|
+
name: import_zod3.z.string().optional(),
|
|
885
|
+
mime: import_zod3.z.string().optional()
|
|
746
886
|
}).passthrough();
|
|
747
887
|
|
|
748
888
|
// src/schemas/mission.ts
|
|
@@ -893,7 +1033,12 @@ var ProgressLogEntrySchema = import_zod4.z.discriminatedUnion("type", [
|
|
|
893
1033
|
]);
|
|
894
1034
|
|
|
895
1035
|
// src/schemas/client.ts
|
|
896
|
-
var
|
|
1036
|
+
var SessionModeRequestFieldsShape = {
|
|
1037
|
+
modelId: import_zod5.z.string().optional(),
|
|
1038
|
+
autonomyMode: import_zod5.z.nativeEnum(AutonomyMode).optional(),
|
|
1039
|
+
interactionMode: import_zod5.z.nativeEnum(DroidInteractionMode).optional(),
|
|
1040
|
+
autonomyLevel: import_zod5.z.nativeEnum(AutonomyLevel).optional()
|
|
1041
|
+
};
|
|
897
1042
|
var SessionTagSchema = import_zod5.z.object({
|
|
898
1043
|
name: import_zod5.z.string(),
|
|
899
1044
|
metadata: import_zod5.z.record(import_zod5.z.string()).optional()
|
|
@@ -935,7 +1080,8 @@ var SessionSettingsSchema = import_zod5.z.object({
|
|
|
935
1080
|
interactionMode: import_zod5.z.nativeEnum(DroidInteractionMode).optional().catch(void 0),
|
|
936
1081
|
autonomyLevel: import_zod5.z.nativeEnum(AutonomyLevel).optional().catch(void 0),
|
|
937
1082
|
specModeModelId: import_zod5.z.string().optional(),
|
|
938
|
-
specModeReasoningEffort: import_zod5.z.nativeEnum(ReasoningEffort).optional()
|
|
1083
|
+
specModeReasoningEffort: import_zod5.z.nativeEnum(ReasoningEffort).optional(),
|
|
1084
|
+
...ToolSelectionOverridesSchema.shape
|
|
939
1085
|
}).passthrough();
|
|
940
1086
|
var GitRepoInfoSchema = import_zod5.z.object({
|
|
941
1087
|
owner: import_zod5.z.string().optional(),
|
|
@@ -955,7 +1101,7 @@ var AvailableModelConfigSchema = import_zod5.z.object({
|
|
|
955
1101
|
tier: import_zod5.z.string().optional(),
|
|
956
1102
|
tokenMultiplier: import_zod5.z.number().optional(),
|
|
957
1103
|
promoLabel: import_zod5.z.string().optional(),
|
|
958
|
-
featureFlag:
|
|
1104
|
+
featureFlag: JsonObjectSchema.optional(),
|
|
959
1105
|
usesUSBasedInference: import_zod5.z.boolean().optional()
|
|
960
1106
|
}).passthrough();
|
|
961
1107
|
var TokenUsageSchema = import_zod5.z.object({
|
|
@@ -965,6 +1111,13 @@ var TokenUsageSchema = import_zod5.z.object({
|
|
|
965
1111
|
cacheReadTokens: import_zod5.z.number(),
|
|
966
1112
|
thinkingTokens: import_zod5.z.number()
|
|
967
1113
|
}).passthrough();
|
|
1114
|
+
var ContextStatsSchema = import_zod5.z.object({
|
|
1115
|
+
used: import_zod5.z.number(),
|
|
1116
|
+
remaining: import_zod5.z.number(),
|
|
1117
|
+
limit: import_zod5.z.number(),
|
|
1118
|
+
accuracy: import_zod5.z.nativeEnum(ContextStatsAccuracy),
|
|
1119
|
+
updatedAt: import_zod5.z.string()
|
|
1120
|
+
}).passthrough();
|
|
968
1121
|
var WorkerStateInfoSchema = import_zod5.z.object({
|
|
969
1122
|
startedAt: import_zod5.z.string(),
|
|
970
1123
|
completedAt: import_zod5.z.string().optional(),
|
|
@@ -992,17 +1145,14 @@ var InitializeSessionRequestParamsSchema = import_zod5.z.object({
|
|
|
992
1145
|
workspaceId: import_zod5.z.string().optional(),
|
|
993
1146
|
sessionId: import_zod5.z.string().optional(),
|
|
994
1147
|
mcpServers: import_zod5.z.array(McpServerConfigSchema).optional(),
|
|
995
|
-
|
|
996
|
-
interactionMode: import_zod5.z.nativeEnum(DroidInteractionMode).optional().catch(void 0),
|
|
997
|
-
autonomyLevel: import_zod5.z.nativeEnum(AutonomyLevel).optional().catch(void 0),
|
|
998
|
-
modelId: import_zod5.z.string().optional(),
|
|
1148
|
+
...SessionModeRequestFieldsShape,
|
|
999
1149
|
reasoningEffort: import_zod5.z.nativeEnum(ReasoningEffort).optional(),
|
|
1000
1150
|
specModeModelId: import_zod5.z.string().optional(),
|
|
1001
1151
|
specModeReasoningEffort: import_zod5.z.nativeEnum(ReasoningEffort).optional(),
|
|
1002
1152
|
decompSessionType: import_zod5.z.nativeEnum(DecompSessionType).optional(),
|
|
1003
1153
|
decompMissionId: import_zod5.z.string().optional(),
|
|
1004
1154
|
skipPermissionsUnsafe: import_zod5.z.boolean().optional(),
|
|
1005
|
-
|
|
1155
|
+
...ToolSelectionOverridesSchema.shape,
|
|
1006
1156
|
sessionLocation: import_zod5.z.string().optional(),
|
|
1007
1157
|
sessionSource: SessionSourceSchema.optional(),
|
|
1008
1158
|
tags: import_zod5.z.array(SessionTagSchema).optional(),
|
|
@@ -1013,24 +1163,33 @@ var LoadSessionRequestParamsSchema = import_zod5.z.object({
|
|
|
1013
1163
|
mcpServers: import_zod5.z.array(McpServerConfigSchema).optional(),
|
|
1014
1164
|
mcpOAuthCallbackUri: import_zod5.z.string().optional()
|
|
1015
1165
|
}).strict();
|
|
1166
|
+
var OutputFormatType = {
|
|
1167
|
+
JsonSchema: "json_schema"
|
|
1168
|
+
};
|
|
1169
|
+
var OutputFormatSchema = import_zod5.z.object({
|
|
1170
|
+
type: import_zod5.z.literal(OutputFormatType.JsonSchema),
|
|
1171
|
+
schema: JsonObjectSchema
|
|
1172
|
+
}).strict();
|
|
1016
1173
|
var AddUserMessageRequestParamsSchema = import_zod5.z.object({
|
|
1017
1174
|
messageId: import_zod5.z.string().optional(),
|
|
1018
1175
|
text: import_zod5.z.string(),
|
|
1019
1176
|
images: import_zod5.z.array(Base64ImageSourceSchema).optional(),
|
|
1020
|
-
files: import_zod5.z.array(DocumentSourceSchema).optional()
|
|
1177
|
+
files: import_zod5.z.array(DocumentSourceSchema).optional(),
|
|
1178
|
+
outputFormat: OutputFormatSchema.optional()
|
|
1021
1179
|
}).strict();
|
|
1022
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();
|
|
1023
1184
|
var KillWorkerSessionRequestParamsSchema = import_zod5.z.object({
|
|
1024
1185
|
workerSessionId: import_zod5.z.string()
|
|
1025
1186
|
}).strict();
|
|
1026
1187
|
var UpdateSessionSettingsRequestParamsSchema = import_zod5.z.object({
|
|
1027
|
-
|
|
1188
|
+
...SessionModeRequestFieldsShape,
|
|
1028
1189
|
reasoningEffort: import_zod5.z.nativeEnum(ReasoningEffort).optional(),
|
|
1029
|
-
autonomyMode: import_zod5.z.nativeEnum(AutonomyMode).optional(),
|
|
1030
|
-
interactionMode: import_zod5.z.nativeEnum(DroidInteractionMode).optional().catch(void 0),
|
|
1031
|
-
autonomyLevel: import_zod5.z.nativeEnum(AutonomyLevel).optional().catch(void 0),
|
|
1032
1190
|
specModeModelId: import_zod5.z.string().nullable().optional(),
|
|
1033
|
-
specModeReasoningEffort: import_zod5.z.nativeEnum(ReasoningEffort).nullable().optional()
|
|
1191
|
+
specModeReasoningEffort: import_zod5.z.nativeEnum(ReasoningEffort).nullable().optional(),
|
|
1192
|
+
...ToolSelectionOverridesSchema.shape
|
|
1034
1193
|
}).strict();
|
|
1035
1194
|
var ToggleMcpServerRequestParamsSchema = import_zod5.z.object({
|
|
1036
1195
|
serverName: import_zod5.z.string(),
|
|
@@ -1066,6 +1225,22 @@ var RemoveMcpServerRequestParamsSchema = import_zod5.z.object({
|
|
|
1066
1225
|
}).strict();
|
|
1067
1226
|
var ListMcpRegistryRequestParamsSchema = import_zod5.z.object({}).strict();
|
|
1068
1227
|
var ListMcpToolsRequestParamsSchema = import_zod5.z.object({}).strict();
|
|
1228
|
+
var ExecToolInfoSchema = import_zod5.z.object({
|
|
1229
|
+
id: import_zod5.z.string(),
|
|
1230
|
+
llmId: import_zod5.z.string(),
|
|
1231
|
+
displayName: import_zod5.z.string(),
|
|
1232
|
+
description: import_zod5.z.string(),
|
|
1233
|
+
category: import_zod5.z.enum(["read", "edit", "execute", "other"]),
|
|
1234
|
+
defaultAllowed: import_zod5.z.boolean(),
|
|
1235
|
+
currentlyAllowed: import_zod5.z.boolean()
|
|
1236
|
+
}).passthrough();
|
|
1237
|
+
var ListToolsRequestParamsSchema = import_zod5.z.object({
|
|
1238
|
+
...SessionModeRequestFieldsShape,
|
|
1239
|
+
specModeModelId: import_zod5.z.string().nullable().optional(),
|
|
1240
|
+
skipPermissionsUnsafe: import_zod5.z.boolean().optional(),
|
|
1241
|
+
...ToolSelectionOverridesSchema.shape,
|
|
1242
|
+
depth: import_zod5.z.number().int().min(0).optional()
|
|
1243
|
+
}).strict();
|
|
1069
1244
|
var ListMcpServersRequestParamsSchema = import_zod5.z.object({}).strict();
|
|
1070
1245
|
var ToggleMcpToolRequestParamsSchema = import_zod5.z.object({
|
|
1071
1246
|
serverName: import_zod5.z.string(),
|
|
@@ -1077,6 +1252,35 @@ var SubmitBugReportRequestParamsSchema = import_zod5.z.object({
|
|
|
1077
1252
|
userComment: import_zod5.z.string(),
|
|
1078
1253
|
clientLogs: import_zod5.z.string().optional()
|
|
1079
1254
|
}).strict();
|
|
1255
|
+
var RewindFileSnapshotSchema = import_zod5.z.object({
|
|
1256
|
+
filePath: import_zod5.z.string(),
|
|
1257
|
+
contentHash: import_zod5.z.string(),
|
|
1258
|
+
size: import_zod5.z.number()
|
|
1259
|
+
}).passthrough();
|
|
1260
|
+
var RewindFileCreationSchema = import_zod5.z.object({
|
|
1261
|
+
filePath: import_zod5.z.string()
|
|
1262
|
+
}).passthrough();
|
|
1263
|
+
var RewindEvictedFileSchema = import_zod5.z.object({
|
|
1264
|
+
filePath: import_zod5.z.string(),
|
|
1265
|
+
reason: import_zod5.z.string()
|
|
1266
|
+
}).passthrough();
|
|
1267
|
+
var GetRewindInfoRequestParamsSchema = import_zod5.z.object({
|
|
1268
|
+
messageId: import_zod5.z.string()
|
|
1269
|
+
}).passthrough();
|
|
1270
|
+
var ExecuteRewindRequestParamsSchema = import_zod5.z.object({
|
|
1271
|
+
messageId: import_zod5.z.string(),
|
|
1272
|
+
filesToRestore: import_zod5.z.array(RewindFileSnapshotSchema),
|
|
1273
|
+
filesToDelete: import_zod5.z.array(RewindFileCreationSchema),
|
|
1274
|
+
forkTitle: import_zod5.z.string()
|
|
1275
|
+
}).passthrough();
|
|
1276
|
+
var CompactSessionRequestParamsSchema = import_zod5.z.object({
|
|
1277
|
+
customInstructions: import_zod5.z.string().optional()
|
|
1278
|
+
}).passthrough();
|
|
1279
|
+
var RenameSessionRequestParamsSchema = import_zod5.z.object({
|
|
1280
|
+
title: import_zod5.z.string()
|
|
1281
|
+
}).passthrough();
|
|
1282
|
+
var ForkSessionRequestParamsSchema = import_zod5.z.object({}).passthrough();
|
|
1283
|
+
var GetContextStatsRequestParamsSchema = import_zod5.z.object({}).passthrough();
|
|
1080
1284
|
var InitializeSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1081
1285
|
method: import_zod5.z.literal("droid.initialize_session" /* INITIALIZE_SESSION */),
|
|
1082
1286
|
params: InitializeSessionRequestParamsSchema
|
|
@@ -1093,6 +1297,10 @@ var InterruptSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
|
1093
1297
|
method: import_zod5.z.literal("droid.interrupt_session" /* INTERRUPT_SESSION */),
|
|
1094
1298
|
params: InterruptSessionRequestParamsSchema
|
|
1095
1299
|
});
|
|
1300
|
+
var CloseSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1301
|
+
method: import_zod5.z.literal("droid.close_session" /* CLOSE_SESSION */),
|
|
1302
|
+
params: CloseSessionRequestParamsSchema
|
|
1303
|
+
});
|
|
1096
1304
|
var KillWorkerSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1097
1305
|
method: import_zod5.z.literal("droid.kill_worker_session" /* KILL_WORKER_SESSION */),
|
|
1098
1306
|
params: KillWorkerSessionRequestParamsSchema
|
|
@@ -1137,6 +1345,10 @@ var ListMcpToolsRequestSchema = JsonRpcRequestSchema.extend({
|
|
|
1137
1345
|
method: import_zod5.z.literal("droid.list_mcp_tools" /* LIST_MCP_TOOLS */),
|
|
1138
1346
|
params: ListMcpToolsRequestParamsSchema
|
|
1139
1347
|
});
|
|
1348
|
+
var ListToolsRequestSchema = JsonRpcRequestSchema.extend({
|
|
1349
|
+
method: import_zod5.z.literal("droid.list_tools" /* LIST_TOOLS */),
|
|
1350
|
+
params: ListToolsRequestParamsSchema
|
|
1351
|
+
});
|
|
1140
1352
|
var ListMcpServersRequestSchema = JsonRpcRequestSchema.extend({
|
|
1141
1353
|
method: import_zod5.z.literal("droid.list_mcp_servers" /* LIST_MCP_SERVERS */),
|
|
1142
1354
|
params: ListMcpServersRequestParamsSchema
|
|
@@ -1153,10 +1365,35 @@ var SubmitBugReportRequestSchema = JsonRpcRequestSchema.extend({
|
|
|
1153
1365
|
method: import_zod5.z.literal("droid.submit_bug_report" /* SUBMIT_BUG_REPORT */),
|
|
1154
1366
|
params: SubmitBugReportRequestParamsSchema
|
|
1155
1367
|
});
|
|
1368
|
+
var GetRewindInfoRequestSchema = JsonRpcRequestSchema.extend({
|
|
1369
|
+
method: import_zod5.z.literal("droid.get_rewind_info" /* GET_REWIND_INFO */),
|
|
1370
|
+
params: GetRewindInfoRequestParamsSchema
|
|
1371
|
+
});
|
|
1372
|
+
var ExecuteRewindRequestSchema = JsonRpcRequestSchema.extend({
|
|
1373
|
+
method: import_zod5.z.literal("droid.execute_rewind" /* EXECUTE_REWIND */),
|
|
1374
|
+
params: ExecuteRewindRequestParamsSchema
|
|
1375
|
+
});
|
|
1376
|
+
var CompactSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1377
|
+
method: import_zod5.z.literal("droid.compact_session" /* COMPACT_SESSION */),
|
|
1378
|
+
params: CompactSessionRequestParamsSchema
|
|
1379
|
+
});
|
|
1380
|
+
var ForkSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1381
|
+
method: import_zod5.z.literal("droid.fork_session" /* FORK_SESSION */),
|
|
1382
|
+
params: ForkSessionRequestParamsSchema
|
|
1383
|
+
});
|
|
1384
|
+
var GetContextStatsRequestSchema = JsonRpcRequestSchema.extend({
|
|
1385
|
+
method: import_zod5.z.literal("droid.get_context_stats" /* GET_CONTEXT_STATS */),
|
|
1386
|
+
params: GetContextStatsRequestParamsSchema
|
|
1387
|
+
});
|
|
1388
|
+
var RenameSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1389
|
+
method: import_zod5.z.literal("droid.rename_session" /* RENAME_SESSION */),
|
|
1390
|
+
params: RenameSessionRequestParamsSchema
|
|
1391
|
+
});
|
|
1156
1392
|
var ClientRequestSchema = import_zod5.z.discriminatedUnion("method", [
|
|
1157
1393
|
InitializeSessionRequestSchema,
|
|
1158
1394
|
LoadSessionRequestSchema,
|
|
1159
1395
|
AddUserMessageRequestSchema,
|
|
1396
|
+
CloseSessionRequestSchema,
|
|
1160
1397
|
InterruptSessionRequestSchema,
|
|
1161
1398
|
KillWorkerSessionRequestSchema,
|
|
1162
1399
|
UpdateSessionSettingsRequestSchema,
|
|
@@ -1169,10 +1406,17 @@ var ClientRequestSchema = import_zod5.z.discriminatedUnion("method", [
|
|
|
1169
1406
|
RemoveMcpServerRequestSchema,
|
|
1170
1407
|
ListMcpRegistryRequestSchema,
|
|
1171
1408
|
ListMcpToolsRequestSchema,
|
|
1409
|
+
ListToolsRequestSchema,
|
|
1172
1410
|
ListMcpServersRequestSchema,
|
|
1173
1411
|
ToggleMcpToolRequestSchema,
|
|
1174
1412
|
ListSkillsRequestSchema,
|
|
1175
|
-
SubmitBugReportRequestSchema
|
|
1413
|
+
SubmitBugReportRequestSchema,
|
|
1414
|
+
GetRewindInfoRequestSchema,
|
|
1415
|
+
ExecuteRewindRequestSchema,
|
|
1416
|
+
CompactSessionRequestSchema,
|
|
1417
|
+
ForkSessionRequestSchema,
|
|
1418
|
+
GetContextStatsRequestSchema,
|
|
1419
|
+
RenameSessionRequestSchema
|
|
1176
1420
|
]);
|
|
1177
1421
|
var MissionSnapshotSchema = import_zod5.z.object({
|
|
1178
1422
|
state: import_zod5.z.nativeEnum(MissionState),
|
|
@@ -1185,20 +1429,20 @@ var MissionSnapshotSchema = import_zod5.z.object({
|
|
|
1185
1429
|
}).passthrough();
|
|
1186
1430
|
var InitializeSessionResultSchema = import_zod5.z.object({
|
|
1187
1431
|
sessionId: import_zod5.z.string(),
|
|
1188
|
-
session:
|
|
1432
|
+
session: JsonObjectSchema,
|
|
1189
1433
|
mcpServers: import_zod5.z.array(McpServerConfigSchema).optional(),
|
|
1190
1434
|
settings: SessionSettingsSchema,
|
|
1191
1435
|
gitRepo: GitRepoInfoSchema.optional(),
|
|
1192
1436
|
availableModels: import_zod5.z.array(AvailableModelConfigSchema).optional()
|
|
1193
1437
|
}).passthrough();
|
|
1194
1438
|
var LoadSessionResultSchema = import_zod5.z.object({
|
|
1195
|
-
session:
|
|
1439
|
+
session: JsonObjectSchema,
|
|
1196
1440
|
mcpServers: import_zod5.z.array(McpServerConfigSchema).optional(),
|
|
1197
|
-
pendingPermissions: import_zod5.z.array(
|
|
1198
|
-
pendingAskUserRequests: import_zod5.z.array(
|
|
1441
|
+
pendingPermissions: import_zod5.z.array(JsonObjectSchema).optional(),
|
|
1442
|
+
pendingAskUserRequests: import_zod5.z.array(JsonObjectSchema).optional(),
|
|
1199
1443
|
settings: SessionSettingsSchema,
|
|
1200
1444
|
isAgentLoopInProgress: import_zod5.z.boolean().optional(),
|
|
1201
|
-
queuedMessages: import_zod5.z.array(
|
|
1445
|
+
queuedMessages: import_zod5.z.array(JsonObjectSchema).optional(),
|
|
1202
1446
|
gitRepo: GitRepoInfoSchema.optional(),
|
|
1203
1447
|
cwd: import_zod5.z.string().optional(),
|
|
1204
1448
|
callingSessionId: import_zod5.z.string().optional(),
|
|
@@ -1208,258 +1452,386 @@ var LoadSessionResultSchema = import_zod5.z.object({
|
|
|
1208
1452
|
mission: MissionSnapshotSchema.optional(),
|
|
1209
1453
|
decompSessionType: import_zod5.z.nativeEnum(DecompSessionType).optional()
|
|
1210
1454
|
}).passthrough();
|
|
1211
|
-
var AddUserMessageResultSchema =
|
|
1212
|
-
var InterruptSessionResultSchema =
|
|
1213
|
-
var
|
|
1214
|
-
var
|
|
1215
|
-
var
|
|
1216
|
-
var
|
|
1217
|
-
var
|
|
1218
|
-
var
|
|
1219
|
-
var
|
|
1220
|
-
var
|
|
1221
|
-
var
|
|
1455
|
+
var AddUserMessageResultSchema = EmptyResultSchema;
|
|
1456
|
+
var InterruptSessionResultSchema = EmptyResultSchema;
|
|
1457
|
+
var CloseSessionResultSchema = EmptyResultSchema;
|
|
1458
|
+
var KillWorkerSessionResultSchema = EmptyResultSchema;
|
|
1459
|
+
var UpdateSessionSettingsResultSchema = EmptyResultSchema;
|
|
1460
|
+
var ToggleMcpServerResultSchema = SuccessResultSchema;
|
|
1461
|
+
var AuthenticateMcpServerResultSchema = SuccessResultSchema;
|
|
1462
|
+
var CancelMcpAuthResultSchema = SuccessResultSchema;
|
|
1463
|
+
var ClearMcpAuthResultSchema = SuccessResultSchema;
|
|
1464
|
+
var SubmitMcpAuthCodeResultSchema = SuccessResultSchema;
|
|
1465
|
+
var AddMcpServerResultSchema = SuccessResultSchema;
|
|
1466
|
+
var RemoveMcpServerResultSchema = SuccessResultSchema;
|
|
1222
1467
|
var ListMcpRegistryResultSchema = import_zod5.z.object({ servers: import_zod5.z.array(McpRegistryServerSchema) }).passthrough();
|
|
1223
1468
|
var ListMcpToolsResultSchema = import_zod5.z.object({ tools: import_zod5.z.array(McpToolInfoSchema) }).passthrough();
|
|
1469
|
+
var ListToolsResultSchema = import_zod5.z.object({ tools: import_zod5.z.array(ExecToolInfoSchema) }).passthrough();
|
|
1224
1470
|
var ListMcpServersResultSchema = import_zod5.z.object({
|
|
1225
1471
|
servers: import_zod5.z.array(McpServerStatusInfoSchema),
|
|
1226
1472
|
summary: McpStatusSummarySchema
|
|
1227
1473
|
}).passthrough();
|
|
1228
|
-
var ToggleMcpToolResultSchema =
|
|
1474
|
+
var ToggleMcpToolResultSchema = SuccessResultSchema;
|
|
1229
1475
|
var ListSkillsResultSchema = import_zod5.z.object({ skills: import_zod5.z.array(SkillInfoSchema) }).passthrough();
|
|
1230
1476
|
var SubmitBugReportResultSchema = import_zod5.z.object({ bugReportId: import_zod5.z.string() }).passthrough();
|
|
1231
|
-
var
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1477
|
+
var GetRewindInfoResultSchema = import_zod5.z.object({
|
|
1478
|
+
availableFiles: import_zod5.z.array(RewindFileSnapshotSchema),
|
|
1479
|
+
createdFiles: import_zod5.z.array(RewindFileCreationSchema),
|
|
1480
|
+
evictedFiles: import_zod5.z.array(RewindEvictedFileSchema)
|
|
1481
|
+
}).passthrough();
|
|
1482
|
+
var ExecuteRewindResultSchema = import_zod5.z.object({
|
|
1483
|
+
newSessionId: import_zod5.z.string(),
|
|
1484
|
+
restoredCount: import_zod5.z.number(),
|
|
1485
|
+
deletedCount: import_zod5.z.number(),
|
|
1486
|
+
failedRestoreCount: import_zod5.z.number(),
|
|
1487
|
+
failedDeleteCount: import_zod5.z.number()
|
|
1488
|
+
}).passthrough();
|
|
1489
|
+
var CompactSessionResultSchema = import_zod5.z.object({
|
|
1490
|
+
newSessionId: import_zod5.z.string(),
|
|
1491
|
+
removedCount: import_zod5.z.number()
|
|
1492
|
+
}).passthrough();
|
|
1493
|
+
var ForkSessionResultSchema = import_zod5.z.object({
|
|
1494
|
+
newSessionId: import_zod5.z.string()
|
|
1495
|
+
}).passthrough();
|
|
1496
|
+
var GetContextStatsResultSchema = ContextStatsSchema;
|
|
1497
|
+
var RenameSessionResultSchema = SuccessResultSchema;
|
|
1498
|
+
var InitializeSessionResponseSchema = createResponseSchema(
|
|
1499
|
+
InitializeSessionResultSchema
|
|
1500
|
+
);
|
|
1501
|
+
var _LoadSessionResponseSchema = createResponseSchema(
|
|
1502
|
+
LoadSessionResultSchema
|
|
1503
|
+
);
|
|
1241
1504
|
var LoadSessionResponseSchema = _LoadSessionResponseSchema;
|
|
1242
|
-
var AddUserMessageResponseSchema =
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
var
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
var
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
var
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
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
|
+
);
|
|
1580
|
+
|
|
1581
|
+
// src/schemas/session-metadata.ts
|
|
1582
|
+
var SessionMetadataSchema = import_zod6.z.object({
|
|
1583
|
+
id: import_zod6.z.string(),
|
|
1584
|
+
title: import_zod6.z.string(),
|
|
1585
|
+
sessionTitle: import_zod6.z.string().optional(),
|
|
1586
|
+
owner: import_zod6.z.string(),
|
|
1587
|
+
messageCount: import_zod6.z.number(),
|
|
1588
|
+
modifiedTime: import_zod6.z.date(),
|
|
1589
|
+
createdTime: import_zod6.z.date(),
|
|
1590
|
+
isFavorite: import_zod6.z.boolean().optional(),
|
|
1591
|
+
cwd: import_zod6.z.string().optional(),
|
|
1592
|
+
decompSessionType: import_zod6.z.nativeEnum(DecompSessionType).optional(),
|
|
1593
|
+
decompMissionId: import_zod6.z.string().optional()
|
|
1594
|
+
}).passthrough();
|
|
1595
|
+
var SessionStartEventSchema = import_zod6.z.object({
|
|
1596
|
+
type: import_zod6.z.literal("session_start"),
|
|
1597
|
+
sessionId: import_zod6.z.string().optional(),
|
|
1598
|
+
title: import_zod6.z.string().optional(),
|
|
1599
|
+
sessionTitle: import_zod6.z.string().optional(),
|
|
1600
|
+
owner: import_zod6.z.string().optional(),
|
|
1601
|
+
cwd: import_zod6.z.string().optional(),
|
|
1602
|
+
decompSessionType: import_zod6.z.nativeEnum(DecompSessionType).optional().catch(void 0),
|
|
1603
|
+
decompMissionId: import_zod6.z.string().optional()
|
|
1604
|
+
}).passthrough();
|
|
1605
|
+
var SessionSettingsFileSchema = import_zod6.z.object({
|
|
1606
|
+
archivedAt: import_zod6.z.string().optional(),
|
|
1607
|
+
tags: import_zod6.z.array(SessionTagSchema).optional()
|
|
1608
|
+
}).passthrough();
|
|
1609
|
+
|
|
1610
|
+
// src/schemas/hooks.ts
|
|
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"
|
|
1323
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
|
+
});
|
|
1324
1644
|
|
|
1325
1645
|
// src/schemas/server.ts
|
|
1326
|
-
var
|
|
1327
|
-
var
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
var ToolProgressUpdateNotificationSchema = import_zod6.z.object({
|
|
1368
|
-
type: import_zod6.z.literal("tool_progress_update" /* TOOL_PROGRESS_UPDATE */),
|
|
1369
|
-
toolUseId: import_zod6.z.string(),
|
|
1370
|
-
toolName: import_zod6.z.string(),
|
|
1646
|
+
var import_zod8 = require("zod");
|
|
1647
|
+
var ToolUseBlockSchema2 = ToolUseBlockSchema;
|
|
1648
|
+
var ToolUseSchema = ToolUseBlockSchema2;
|
|
1649
|
+
var ErrorDetailSchema = import_zod8.z.object({
|
|
1650
|
+
name: import_zod8.z.string(),
|
|
1651
|
+
message: import_zod8.z.string()
|
|
1652
|
+
}).passthrough();
|
|
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(),
|
|
1661
|
+
parameters: JsonObjectSchema.optional(),
|
|
1662
|
+
valueSnippet: import_zod8.z.string().optional(),
|
|
1663
|
+
subagentSessionId: import_zod8.z.string().optional()
|
|
1664
|
+
}).passthrough();
|
|
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(),
|
|
1673
|
+
...ToolSelectionOverridesSchema.shape
|
|
1674
|
+
}).passthrough();
|
|
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(),
|
|
1679
|
+
content: JsonValueSchema.optional(),
|
|
1680
|
+
isError: import_zod8.z.boolean().optional(),
|
|
1681
|
+
id: import_zod8.z.string().optional()
|
|
1682
|
+
}).passthrough();
|
|
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(),
|
|
1371
1687
|
update: ToolProgressUpdateSchema
|
|
1372
1688
|
}).passthrough();
|
|
1373
|
-
var CreateMessageNotificationSchema =
|
|
1374
|
-
type:
|
|
1689
|
+
var CreateMessageNotificationSchema = import_zod8.z.object({
|
|
1690
|
+
type: import_zod8.z.literal("create_message" /* CREATE_MESSAGE */),
|
|
1375
1691
|
message: FactoryDroidMessageSchema,
|
|
1376
|
-
parentId:
|
|
1377
|
-
requestId:
|
|
1378
|
-
}).passthrough();
|
|
1379
|
-
var ErrorNotificationSchema =
|
|
1380
|
-
type:
|
|
1381
|
-
message:
|
|
1382
|
-
errorType:
|
|
1383
|
-
timestamp:
|
|
1692
|
+
parentId: import_zod8.z.string().optional(),
|
|
1693
|
+
requestId: import_zod8.z.string().optional()
|
|
1694
|
+
}).passthrough();
|
|
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(),
|
|
1384
1700
|
error: ErrorDetailSchema.optional()
|
|
1385
1701
|
}).passthrough();
|
|
1386
|
-
var DroidWorkingStateChangedNotificationSchema =
|
|
1387
|
-
type:
|
|
1388
|
-
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)
|
|
1389
1705
|
}).passthrough();
|
|
1390
|
-
var PermissionResolvedNotificationSchema =
|
|
1391
|
-
type:
|
|
1392
|
-
requestId:
|
|
1393
|
-
toolUseIds:
|
|
1394
|
-
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)
|
|
1395
1711
|
}).passthrough();
|
|
1396
|
-
var SettingsUpdatedNotificationSchema =
|
|
1397
|
-
type:
|
|
1712
|
+
var SettingsUpdatedNotificationSchema = import_zod8.z.object({
|
|
1713
|
+
type: import_zod8.z.literal("settings_updated" /* SETTINGS_UPDATED */),
|
|
1398
1714
|
settings: SettingsUpdatedPayloadSchema
|
|
1399
1715
|
}).passthrough();
|
|
1400
|
-
var SessionTitleUpdatedNotificationSchema =
|
|
1401
|
-
type:
|
|
1402
|
-
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()
|
|
1403
1719
|
}).passthrough();
|
|
1404
|
-
var McpStatusChangedNotificationSchema =
|
|
1405
|
-
type:
|
|
1406
|
-
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),
|
|
1407
1723
|
summary: McpStatusSummarySchema
|
|
1408
1724
|
}).passthrough();
|
|
1409
|
-
var AssistantTextDeltaNotificationSchema =
|
|
1410
|
-
type:
|
|
1411
|
-
messageId:
|
|
1412
|
-
blockIndex:
|
|
1413
|
-
textDelta:
|
|
1414
|
-
}).passthrough();
|
|
1415
|
-
var
|
|
1416
|
-
type:
|
|
1417
|
-
messageId:
|
|
1418
|
-
blockIndex:
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
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()
|
|
1735
|
+
}).passthrough();
|
|
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()
|
|
1741
|
+
}).passthrough();
|
|
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(),
|
|
1424
1755
|
tokenUsage: TokenUsageSchema
|
|
1425
1756
|
}).passthrough();
|
|
1426
|
-
var MissionStateChangedNotificationSchema =
|
|
1427
|
-
type:
|
|
1428
|
-
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)
|
|
1768
|
+
}).passthrough();
|
|
1769
|
+
var MissionHeartbeatNotificationSchema = import_zod8.z.object({
|
|
1770
|
+
type: import_zod8.z.literal("mission_heartbeat" /* MISSION_HEARTBEAT */),
|
|
1771
|
+
timestamp: import_zod8.z.string()
|
|
1429
1772
|
}).passthrough();
|
|
1430
|
-
var
|
|
1431
|
-
type:
|
|
1432
|
-
|
|
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()
|
|
1433
1776
|
}).passthrough();
|
|
1434
|
-
var
|
|
1435
|
-
type:
|
|
1436
|
-
|
|
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()
|
|
1437
1781
|
}).passthrough();
|
|
1438
|
-
var
|
|
1439
|
-
type:
|
|
1440
|
-
|
|
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()
|
|
1441
1788
|
}).passthrough();
|
|
1442
|
-
var
|
|
1443
|
-
type:
|
|
1444
|
-
|
|
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()
|
|
1445
1794
|
}).passthrough();
|
|
1446
|
-
var
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
exitCode: import_zod6.z.number()
|
|
1795
|
+
var HookCommandSchema = import_zod8.z.object({
|
|
1796
|
+
command: import_zod8.z.string(),
|
|
1797
|
+
timeout: import_zod8.z.number().optional()
|
|
1450
1798
|
}).passthrough();
|
|
1451
|
-
var
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
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()
|
|
1457
1805
|
}).passthrough();
|
|
1458
|
-
var
|
|
1459
|
-
type:
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
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()
|
|
1463
1835
|
}).passthrough();
|
|
1464
1836
|
var SessionNotificationSchemaList = [
|
|
1465
1837
|
ToolResultNotificationSchema,
|
|
@@ -1472,7 +1844,10 @@ var SessionNotificationSchemaList = [
|
|
|
1472
1844
|
SessionTitleUpdatedNotificationSchema,
|
|
1473
1845
|
McpStatusChangedNotificationSchema,
|
|
1474
1846
|
AssistantTextDeltaNotificationSchema,
|
|
1847
|
+
AssistantTextCompleteNotificationSchema,
|
|
1475
1848
|
ThinkingTextDeltaNotificationSchema,
|
|
1849
|
+
ThinkingTextCompleteNotificationSchema,
|
|
1850
|
+
ToolCallNotificationSchema,
|
|
1476
1851
|
SessionTokenUsageChangedNotificationSchema,
|
|
1477
1852
|
MissionStateChangedNotificationSchema,
|
|
1478
1853
|
MissionFeaturesChangedNotificationSchema,
|
|
@@ -1481,86 +1856,91 @@ var SessionNotificationSchemaList = [
|
|
|
1481
1856
|
MissionWorkerStartedNotificationSchema,
|
|
1482
1857
|
MissionWorkerCompletedNotificationSchema,
|
|
1483
1858
|
McpAuthRequiredNotificationSchema,
|
|
1484
|
-
McpAuthCompletedNotificationSchema
|
|
1859
|
+
McpAuthCompletedNotificationSchema,
|
|
1860
|
+
HookExecutionStartedNotificationSchema,
|
|
1861
|
+
HookExecutionCompletedNotificationSchema,
|
|
1862
|
+
StructuredOutputNotificationSchema
|
|
1485
1863
|
];
|
|
1486
|
-
var SessionNotificationPayloadSchema =
|
|
1864
|
+
var SessionNotificationPayloadSchema = import_zod8.z.discriminatedUnion(
|
|
1487
1865
|
"type",
|
|
1488
1866
|
SessionNotificationSchemaList
|
|
1489
1867
|
);
|
|
1490
|
-
var
|
|
1868
|
+
var _SessionNotificationParamsSchema = import_zod8.z.object({
|
|
1491
1869
|
notification: SessionNotificationPayloadSchema
|
|
1492
1870
|
}).passthrough();
|
|
1493
|
-
var
|
|
1494
|
-
|
|
1871
|
+
var SessionNotificationParamsSchema = _SessionNotificationParamsSchema;
|
|
1872
|
+
var _SessionNotificationSchema = JsonRpcNotificationSchema.extend({
|
|
1873
|
+
method: import_zod8.z.literal("droid.session_notification" /* SESSION_NOTIFICATION */),
|
|
1495
1874
|
params: SessionNotificationParamsSchema
|
|
1496
1875
|
});
|
|
1497
|
-
var
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1876
|
+
var SessionNotificationSchema = _SessionNotificationSchema;
|
|
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()
|
|
1883
|
+
}).passthrough();
|
|
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()
|
|
1890
|
+
}).passthrough();
|
|
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()
|
|
1896
|
+
}).passthrough();
|
|
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())
|
|
1902
|
+
}).passthrough();
|
|
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)
|
|
1528
1908
|
}).optional(),
|
|
1529
|
-
parseError:
|
|
1530
|
-
message:
|
|
1531
|
-
line:
|
|
1909
|
+
parseError: import_zod8.z.object({
|
|
1910
|
+
message: import_zod8.z.string(),
|
|
1911
|
+
line: import_zod8.z.number().optional()
|
|
1532
1912
|
}).optional()
|
|
1533
1913
|
}).passthrough();
|
|
1534
|
-
var ExitSpecModeConfirmationDetailsSchema =
|
|
1535
|
-
type:
|
|
1536
|
-
plan:
|
|
1537
|
-
title:
|
|
1538
|
-
optionNames:
|
|
1539
|
-
}).passthrough();
|
|
1540
|
-
var ProposeMissionConfirmationDetailsSchema =
|
|
1541
|
-
type:
|
|
1542
|
-
proposal:
|
|
1543
|
-
title:
|
|
1544
|
-
}).passthrough();
|
|
1545
|
-
var StartMissionRunConfirmationDetailsSchema =
|
|
1546
|
-
type:
|
|
1547
|
-
runningMissionCount:
|
|
1548
|
-
runningMissionSessionIds:
|
|
1549
|
-
}).passthrough();
|
|
1550
|
-
var ApplyPatchToolConfirmationDetailsSchema =
|
|
1551
|
-
type:
|
|
1552
|
-
filePath:
|
|
1553
|
-
fileName:
|
|
1554
|
-
patchContent:
|
|
1555
|
-
oldContent:
|
|
1556
|
-
newContent:
|
|
1557
|
-
}).passthrough();
|
|
1558
|
-
var McpToolConfirmationDetailsSchema =
|
|
1559
|
-
type:
|
|
1560
|
-
toolName:
|
|
1561
|
-
impactLevel:
|
|
1562
|
-
}).passthrough();
|
|
1563
|
-
var ToolConfirmationDetailsSchema =
|
|
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()
|
|
1919
|
+
}).passthrough();
|
|
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()
|
|
1924
|
+
}).passthrough();
|
|
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())
|
|
1929
|
+
}).passthrough();
|
|
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()
|
|
1937
|
+
}).passthrough();
|
|
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()
|
|
1942
|
+
}).passthrough();
|
|
1943
|
+
var ToolConfirmationDetailsSchema = import_zod8.z.discriminatedUnion("type", [
|
|
1564
1944
|
EditToolConfirmationDetailsSchema,
|
|
1565
1945
|
ExecuteToolConfirmationDetailsSchema,
|
|
1566
1946
|
CreateToolConfirmationDetailsSchema,
|
|
@@ -1571,60 +1951,61 @@ var ToolConfirmationDetailsSchema = import_zod6.z.discriminatedUnion("type", [
|
|
|
1571
1951
|
ApplyPatchToolConfirmationDetailsSchema,
|
|
1572
1952
|
McpToolConfirmationDetailsSchema
|
|
1573
1953
|
]);
|
|
1574
|
-
var ToolConfirmationInfoSchema =
|
|
1954
|
+
var ToolConfirmationInfoSchema = import_zod8.z.object({
|
|
1575
1955
|
toolUse: ToolUseSchema,
|
|
1576
|
-
confirmationType:
|
|
1956
|
+
confirmationType: import_zod8.z.nativeEnum(ToolConfirmationType),
|
|
1577
1957
|
details: ToolConfirmationDetailsSchema
|
|
1578
1958
|
}).passthrough();
|
|
1579
|
-
var RequestPermissionRequestParamsSchema =
|
|
1580
|
-
toolUses:
|
|
1581
|
-
options:
|
|
1959
|
+
var RequestPermissionRequestParamsSchema = import_zod8.z.object({
|
|
1960
|
+
toolUses: import_zod8.z.array(ToolConfirmationInfoSchema),
|
|
1961
|
+
options: import_zod8.z.array(ToolConfirmationListItemSchema)
|
|
1582
1962
|
}).passthrough();
|
|
1583
1963
|
var RequestPermissionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1584
|
-
method:
|
|
1964
|
+
method: import_zod8.z.literal("droid.request_permission" /* REQUEST_PERMISSION */),
|
|
1585
1965
|
params: RequestPermissionRequestParamsSchema
|
|
1586
1966
|
});
|
|
1587
|
-
var RequestPermissionResultSchema =
|
|
1588
|
-
selectedOption:
|
|
1967
|
+
var RequestPermissionResultSchema = import_zod8.z.object({
|
|
1968
|
+
selectedOption: import_zod8.z.nativeEnum(ToolConfirmationOutcome),
|
|
1969
|
+
comment: import_zod8.z.string().optional()
|
|
1589
1970
|
}).strict();
|
|
1590
|
-
var RequestPermissionResponseSchema =
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
var AskUserRequestParamsSchema = import_zod6.z.object({
|
|
1597
|
-
toolCallId: import_zod6.z.string(),
|
|
1598
|
-
questions: import_zod6.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)
|
|
1599
1977
|
}).passthrough();
|
|
1600
1978
|
var AskUserRequestSchema = JsonRpcRequestSchema.extend({
|
|
1601
|
-
method:
|
|
1979
|
+
method: import_zod8.z.literal("droid.ask_user" /* ASK_USER */),
|
|
1602
1980
|
params: AskUserRequestParamsSchema
|
|
1603
1981
|
});
|
|
1604
|
-
var AskUserCollectedAnswerSchema =
|
|
1605
|
-
index:
|
|
1606
|
-
question:
|
|
1607
|
-
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()
|
|
1608
1986
|
}).strict();
|
|
1609
|
-
var AskUserResultSchema =
|
|
1610
|
-
cancelled:
|
|
1611
|
-
answers:
|
|
1987
|
+
var AskUserResultSchema = import_zod8.z.object({
|
|
1988
|
+
cancelled: import_zod8.z.boolean().optional(),
|
|
1989
|
+
answers: import_zod8.z.array(AskUserCollectedAnswerSchema)
|
|
1612
1990
|
}).strict();
|
|
1613
|
-
var AskUserResponseSchema =
|
|
1614
|
-
|
|
1615
|
-
JsonRpcResponseFailureSchema
|
|
1616
|
-
]);
|
|
1617
|
-
var CliRequestOrNotificationSchema = import_zod6.z.union([
|
|
1991
|
+
var AskUserResponseSchema = createResponseSchema(AskUserResultSchema);
|
|
1992
|
+
var _CliRequestOrNotificationSchema = import_zod8.z.union([
|
|
1618
1993
|
SessionNotificationSchema,
|
|
1619
1994
|
RequestPermissionRequestSchema,
|
|
1620
1995
|
AskUserRequestSchema
|
|
1621
1996
|
]);
|
|
1997
|
+
var CliRequestOrNotificationSchema = _CliRequestOrNotificationSchema;
|
|
1998
|
+
|
|
1999
|
+
// src/constants.ts
|
|
2000
|
+
var SDK_VERSION = "0.3.0";
|
|
2001
|
+
var SDK_TAG = {
|
|
2002
|
+
name: "sdk",
|
|
2003
|
+
metadata: { language: "typescript", version: SDK_VERSION }
|
|
2004
|
+
};
|
|
1622
2005
|
|
|
1623
2006
|
// src/errors.ts
|
|
1624
2007
|
var ConnectionError = class _ConnectionError extends Error {
|
|
1625
|
-
/** The working directory used when spawning the process. */
|
|
1626
2008
|
cwd;
|
|
1627
|
-
/** The executable path used when spawning the process. */
|
|
1628
2009
|
execPath;
|
|
1629
2010
|
constructor(message, options) {
|
|
1630
2011
|
super(message);
|
|
@@ -1635,9 +2016,7 @@ var ConnectionError = class _ConnectionError extends Error {
|
|
|
1635
2016
|
}
|
|
1636
2017
|
};
|
|
1637
2018
|
var ProtocolError = class _ProtocolError extends Error {
|
|
1638
|
-
/** The JSON-RPC error code, if available. */
|
|
1639
2019
|
code;
|
|
1640
|
-
/** Additional error data from the JSON-RPC response. */
|
|
1641
2020
|
data;
|
|
1642
2021
|
constructor(message, options) {
|
|
1643
2022
|
super(message);
|
|
@@ -1655,7 +2034,6 @@ var SessionError = class _SessionError extends Error {
|
|
|
1655
2034
|
}
|
|
1656
2035
|
};
|
|
1657
2036
|
var SessionNotFoundError = class _SessionNotFoundError extends SessionError {
|
|
1658
|
-
/** The ID of the session that was not found. */
|
|
1659
2037
|
sessionId;
|
|
1660
2038
|
constructor(sessionId) {
|
|
1661
2039
|
super(`Session not found: ${sessionId}`);
|
|
@@ -1672,9 +2050,7 @@ var TimeoutError = class _TimeoutError extends Error {
|
|
|
1672
2050
|
}
|
|
1673
2051
|
};
|
|
1674
2052
|
var ProcessExitError = class _ProcessExitError extends Error {
|
|
1675
|
-
/** The exit code of the process, or null if terminated by signal. */
|
|
1676
2053
|
exitCode;
|
|
1677
|
-
/** The signal that terminated the process, or null if exited normally. */
|
|
1678
2054
|
signal;
|
|
1679
2055
|
constructor(message, options) {
|
|
1680
2056
|
super(message);
|
|
@@ -1688,6 +2064,13 @@ var ProcessExitError = class _ProcessExitError extends Error {
|
|
|
1688
2064
|
// src/transport.ts
|
|
1689
2065
|
var import_node_child_process = require("child_process");
|
|
1690
2066
|
var readline = __toESM(require("readline"), 1);
|
|
2067
|
+
|
|
2068
|
+
// src/utils.ts
|
|
2069
|
+
function isRecord(value) {
|
|
2070
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
// src/transport.ts
|
|
1691
2074
|
var DEFAULT_EXEC_ARGS = [
|
|
1692
2075
|
"exec",
|
|
1693
2076
|
"--input-format",
|
|
@@ -1706,12 +2089,9 @@ var ProcessTransport = class {
|
|
|
1706
2089
|
readlineInterface = null;
|
|
1707
2090
|
messageHandler = null;
|
|
1708
2091
|
errorHandler = null;
|
|
1709
|
-
/**
|
|
1710
|
-
* Sticky error from a process error or unexpected exit. Once set,
|
|
1711
|
-
* all subsequent `send()` calls throw immediately.
|
|
1712
|
-
*/
|
|
2092
|
+
/** Once set, all subsequent `send()` calls throw immediately. */
|
|
1713
2093
|
processError = null;
|
|
1714
|
-
/**
|
|
2094
|
+
/** Serializes stdin writes to prevent interleaving. */
|
|
1715
2095
|
writeChain = Promise.resolve();
|
|
1716
2096
|
_isConnected = false;
|
|
1717
2097
|
isClosing = false;
|
|
@@ -1722,9 +2102,6 @@ var ProcessTransport = class {
|
|
|
1722
2102
|
this.env = options.env;
|
|
1723
2103
|
this.gracePeriodMs = (options.gracePeriod ?? DEFAULT_GRACE_PERIOD_MS / 1e3) * 1e3;
|
|
1724
2104
|
}
|
|
1725
|
-
// -----------------------------------------------------------------------
|
|
1726
|
-
// DroidClientTransport interface
|
|
1727
|
-
// -----------------------------------------------------------------------
|
|
1728
2105
|
get isConnected() {
|
|
1729
2106
|
return this._isConnected;
|
|
1730
2107
|
}
|
|
@@ -1776,7 +2153,7 @@ var ProcessTransport = class {
|
|
|
1776
2153
|
if (this.processError) {
|
|
1777
2154
|
throw this.processError;
|
|
1778
2155
|
}
|
|
1779
|
-
await new Promise((
|
|
2156
|
+
await new Promise((resolve2, reject) => {
|
|
1780
2157
|
if (!this.childProcess || !this.childProcess.stdin) {
|
|
1781
2158
|
reject(
|
|
1782
2159
|
new ConnectionError("Process stdin unavailable", {
|
|
@@ -1812,7 +2189,7 @@ var ProcessTransport = class {
|
|
|
1812
2189
|
);
|
|
1813
2190
|
}
|
|
1814
2191
|
} else {
|
|
1815
|
-
|
|
2192
|
+
resolve2();
|
|
1816
2193
|
}
|
|
1817
2194
|
});
|
|
1818
2195
|
});
|
|
@@ -1837,7 +2214,7 @@ var ProcessTransport = class {
|
|
|
1837
2214
|
this.readlineInterface = null;
|
|
1838
2215
|
}
|
|
1839
2216
|
if (proc && proc.exitCode === null && !proc.killed) {
|
|
1840
|
-
await new Promise((
|
|
2217
|
+
await new Promise((resolve2) => {
|
|
1841
2218
|
const timeout = setTimeout(() => {
|
|
1842
2219
|
if (proc.exitCode === null && !proc.killed) {
|
|
1843
2220
|
try {
|
|
@@ -1848,7 +2225,7 @@ var ProcessTransport = class {
|
|
|
1848
2225
|
}, this.gracePeriodMs);
|
|
1849
2226
|
proc.once("exit", () => {
|
|
1850
2227
|
clearTimeout(timeout);
|
|
1851
|
-
|
|
2228
|
+
resolve2();
|
|
1852
2229
|
});
|
|
1853
2230
|
if (proc.stdin) {
|
|
1854
2231
|
try {
|
|
@@ -1860,15 +2237,12 @@ var ProcessTransport = class {
|
|
|
1860
2237
|
proc.kill("SIGTERM");
|
|
1861
2238
|
} catch {
|
|
1862
2239
|
clearTimeout(timeout);
|
|
1863
|
-
|
|
2240
|
+
resolve2();
|
|
1864
2241
|
}
|
|
1865
2242
|
});
|
|
1866
2243
|
}
|
|
1867
2244
|
this.isClosing = false;
|
|
1868
2245
|
}
|
|
1869
|
-
// -----------------------------------------------------------------------
|
|
1870
|
-
// Private helpers
|
|
1871
|
-
// -----------------------------------------------------------------------
|
|
1872
2246
|
setupHandlers() {
|
|
1873
2247
|
const proc = this.childProcess;
|
|
1874
2248
|
if (!proc || !proc.stdout) {
|
|
@@ -1883,10 +2257,10 @@ var ProcessTransport = class {
|
|
|
1883
2257
|
if (!trimmed) {
|
|
1884
2258
|
return;
|
|
1885
2259
|
}
|
|
1886
|
-
if (trimmed.startsWith("{")
|
|
2260
|
+
if (trimmed.startsWith("{")) {
|
|
1887
2261
|
try {
|
|
1888
2262
|
const parsed = JSON.parse(trimmed);
|
|
1889
|
-
if (this.messageHandler &&
|
|
2263
|
+
if (this.messageHandler && isRecord(parsed)) {
|
|
1890
2264
|
this.messageHandler(parsed);
|
|
1891
2265
|
}
|
|
1892
2266
|
} catch {
|
|
@@ -1939,26 +2313,33 @@ var ProcessTransport = class {
|
|
|
1939
2313
|
|
|
1940
2314
|
// src/protocol.ts
|
|
1941
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
|
+
}
|
|
1942
2334
|
var ProtocolEngine = class {
|
|
1943
2335
|
_transport;
|
|
1944
2336
|
_defaultTimeout;
|
|
1945
|
-
/** Pending requests keyed by UUID string. */
|
|
1946
2337
|
_pendingRequests = /* @__PURE__ */ new Map();
|
|
1947
|
-
/** Notification listener registry. */
|
|
1948
2338
|
_notificationListeners = /* @__PURE__ */ new Set();
|
|
1949
|
-
/** Server→client request handlers. */
|
|
1950
2339
|
_permissionHandler = null;
|
|
1951
2340
|
_askUserHandler = null;
|
|
1952
|
-
/** Sticky transport error — once set, all requests fail immediately. */
|
|
1953
2341
|
_transportError = null;
|
|
1954
|
-
/** Closed flag — once true, new requests are rejected. */
|
|
1955
2342
|
_closed = false;
|
|
1956
|
-
/**
|
|
1957
|
-
* Create a new ProtocolEngine.
|
|
1958
|
-
*
|
|
1959
|
-
* @param options.transport - A connected DroidClientTransport implementation.
|
|
1960
|
-
* @param options.defaultTimeout - Default timeout in ms for sendRequest (default 30 000).
|
|
1961
|
-
*/
|
|
1962
2343
|
constructor(options) {
|
|
1963
2344
|
this._transport = options.transport;
|
|
1964
2345
|
this._defaultTimeout = options.defaultTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
@@ -1969,25 +2350,6 @@ var ProtocolEngine = class {
|
|
|
1969
2350
|
this._handleTransportError(error);
|
|
1970
2351
|
});
|
|
1971
2352
|
}
|
|
1972
|
-
// ------------------------------------------------------------------
|
|
1973
|
-
// Public API: Sending requests
|
|
1974
|
-
// ------------------------------------------------------------------
|
|
1975
|
-
/**
|
|
1976
|
-
* Send a JSON-RPC request and wait for the response.
|
|
1977
|
-
*
|
|
1978
|
-
* Constructs the full envelope, registers a pending promise, sends
|
|
1979
|
-
* via transport, and returns the parsed response `result` field.
|
|
1980
|
-
*
|
|
1981
|
-
* @param method - The RPC method name (e.g. `"droid.list_skills"`).
|
|
1982
|
-
* @param params - Method parameters object.
|
|
1983
|
-
* @param timeout - Timeout in ms. Defaults to `defaultTimeout`.
|
|
1984
|
-
* @returns The `result` field from the JSON-RPC success response.
|
|
1985
|
-
* @throws {ConnectionError} If the engine is closed.
|
|
1986
|
-
* @throws {ConnectionError} If the transport has a sticky error.
|
|
1987
|
-
* @throws {TimeoutError} If no response arrives within the timeout.
|
|
1988
|
-
* @throws {ProtocolError} If the response contains a protocol error.
|
|
1989
|
-
* @throws {SessionNotFoundError} If error code is ENTITY_NOT_FOUND.
|
|
1990
|
-
*/
|
|
1991
2353
|
async sendRequest(method, params, timeout) {
|
|
1992
2354
|
if (this._closed) {
|
|
1993
2355
|
throw new ConnectionError("Protocol engine is closed");
|
|
@@ -2003,12 +2365,12 @@ var ProtocolEngine = class {
|
|
|
2003
2365
|
jsonrpc: JSONRPC_VERSION,
|
|
2004
2366
|
factoryApiVersion: LEGACY_FACTORY_API_VERSION,
|
|
2005
2367
|
factoryProtocolVersion: FACTORY_PROTOCOL_VERSION,
|
|
2006
|
-
type: "request"
|
|
2368
|
+
type: "request" /* Request */,
|
|
2007
2369
|
id: requestId,
|
|
2008
2370
|
method,
|
|
2009
2371
|
params
|
|
2010
2372
|
};
|
|
2011
|
-
return new Promise((
|
|
2373
|
+
return new Promise((resolve2, reject) => {
|
|
2012
2374
|
const timer = setTimeout(() => {
|
|
2013
2375
|
this._pendingRequests.delete(requestId);
|
|
2014
2376
|
reject(
|
|
@@ -2021,7 +2383,7 @@ var ProtocolEngine = class {
|
|
|
2021
2383
|
method,
|
|
2022
2384
|
requestId,
|
|
2023
2385
|
params,
|
|
2024
|
-
resolve,
|
|
2386
|
+
resolve: resolve2,
|
|
2025
2387
|
reject,
|
|
2026
2388
|
timer
|
|
2027
2389
|
};
|
|
@@ -2041,19 +2403,6 @@ var ProtocolEngine = class {
|
|
|
2041
2403
|
}
|
|
2042
2404
|
});
|
|
2043
2405
|
}
|
|
2044
|
-
// ------------------------------------------------------------------
|
|
2045
|
-
// Public API: Notification listeners
|
|
2046
|
-
// ------------------------------------------------------------------
|
|
2047
|
-
/**
|
|
2048
|
-
* Register a callback for incoming notification messages.
|
|
2049
|
-
*
|
|
2050
|
-
* Multiple listeners can be registered. Each receives the full
|
|
2051
|
-
* parsed notification object.
|
|
2052
|
-
*
|
|
2053
|
-
* @param callback - Invoked with the notification object.
|
|
2054
|
-
* @param filter - Optional filter to only receive specific notification types.
|
|
2055
|
-
* @returns An unsubscribe function. Calling it again is safe (no-op).
|
|
2056
|
-
*/
|
|
2057
2406
|
onNotification(callback, filter) {
|
|
2058
2407
|
const listener = { callback, filter };
|
|
2059
2408
|
this._notificationListeners.add(listener);
|
|
@@ -2065,23 +2414,9 @@ var ProtocolEngine = class {
|
|
|
2065
2414
|
}
|
|
2066
2415
|
};
|
|
2067
2416
|
}
|
|
2068
|
-
// ------------------------------------------------------------------
|
|
2069
|
-
// Public API: Server→client request handlers
|
|
2070
|
-
// ------------------------------------------------------------------
|
|
2071
|
-
/**
|
|
2072
|
-
* Register a handler for server→client permission requests.
|
|
2073
|
-
*
|
|
2074
|
-
* The handler receives the request params and should return a
|
|
2075
|
-
* ToolConfirmationOutcome string value.
|
|
2076
|
-
*
|
|
2077
|
-
* Replaces any previously registered handler.
|
|
2078
|
-
*/
|
|
2079
2417
|
setPermissionHandler(handler) {
|
|
2080
2418
|
this._permissionHandler = handler;
|
|
2081
2419
|
}
|
|
2082
|
-
/**
|
|
2083
|
-
* Remove the permission request handler (restores default Cancel).
|
|
2084
|
-
*/
|
|
2085
2420
|
clearPermissionHandler() {
|
|
2086
2421
|
this._permissionHandler = null;
|
|
2087
2422
|
}
|
|
@@ -2096,31 +2431,12 @@ var ProtocolEngine = class {
|
|
|
2096
2431
|
setAskUserHandler(handler) {
|
|
2097
2432
|
this._askUserHandler = handler;
|
|
2098
2433
|
}
|
|
2099
|
-
/**
|
|
2100
|
-
* Remove the ask-user request handler (restores default cancelled=true).
|
|
2101
|
-
*/
|
|
2102
2434
|
clearAskUserHandler() {
|
|
2103
2435
|
this._askUserHandler = null;
|
|
2104
2436
|
}
|
|
2105
|
-
// ------------------------------------------------------------------
|
|
2106
|
-
// Public API: Health check
|
|
2107
|
-
// ------------------------------------------------------------------
|
|
2108
|
-
/**
|
|
2109
|
-
* Whether the engine is in a healthy state — not closed and no
|
|
2110
|
-
* sticky transport error.
|
|
2111
|
-
*/
|
|
2112
2437
|
get isHealthy() {
|
|
2113
2438
|
return !this._closed && this._transportError === null;
|
|
2114
2439
|
}
|
|
2115
|
-
// ------------------------------------------------------------------
|
|
2116
|
-
// Public API: Close
|
|
2117
|
-
// ------------------------------------------------------------------
|
|
2118
|
-
/**
|
|
2119
|
-
* Close the protocol engine.
|
|
2120
|
-
*
|
|
2121
|
-
* Rejects all pending requests, closes the transport, and prevents
|
|
2122
|
-
* new requests. Idempotent — safe to call multiple times.
|
|
2123
|
-
*/
|
|
2124
2440
|
async close() {
|
|
2125
2441
|
if (this._closed) {
|
|
2126
2442
|
return;
|
|
@@ -2135,38 +2451,25 @@ var ProtocolEngine = class {
|
|
|
2135
2451
|
this._notificationListeners.clear();
|
|
2136
2452
|
await this._transport.close();
|
|
2137
2453
|
}
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
} else {
|
|
2155
|
-
if ("result" in parsed || "error" in parsed) {
|
|
2156
|
-
this._handleResponse(parsed);
|
|
2157
|
-
} else if ("method" in parsed && !("id" in parsed)) {
|
|
2158
|
-
this._handleNotification(parsed);
|
|
2159
|
-
} else if ("method" in parsed && "id" in parsed) {
|
|
2160
|
-
void this._handleServerRequest(parsed);
|
|
2161
|
-
}
|
|
2454
|
+
_handleMessage(raw) {
|
|
2455
|
+
const parsed = JsonRpcMessageSchema.safeParse(raw);
|
|
2456
|
+
if (!parsed.success) {
|
|
2457
|
+
return;
|
|
2458
|
+
}
|
|
2459
|
+
const msg = parsed.data;
|
|
2460
|
+
switch (msg.type) {
|
|
2461
|
+
case "response" /* Response */:
|
|
2462
|
+
this._handleResponse(msg.id, msg.result, msg.error);
|
|
2463
|
+
break;
|
|
2464
|
+
case "notification" /* Notification */:
|
|
2465
|
+
this._handleNotification(msg);
|
|
2466
|
+
break;
|
|
2467
|
+
case "request" /* Request */:
|
|
2468
|
+
void this._handleServerRequest(msg.method, msg.id, msg.params);
|
|
2469
|
+
break;
|
|
2162
2470
|
}
|
|
2163
2471
|
}
|
|
2164
|
-
|
|
2165
|
-
* Handle an incoming response message.
|
|
2166
|
-
* Matches by ID to resolve the correct pending Promise.
|
|
2167
|
-
*/
|
|
2168
|
-
_handleResponse(response) {
|
|
2169
|
-
const responseId = response["id"];
|
|
2472
|
+
_handleResponse(responseId, result, error) {
|
|
2170
2473
|
if (responseId == null) {
|
|
2171
2474
|
return;
|
|
2172
2475
|
}
|
|
@@ -2176,68 +2479,50 @@ var ProtocolEngine = class {
|
|
|
2176
2479
|
}
|
|
2177
2480
|
this._pendingRequests.delete(responseId);
|
|
2178
2481
|
clearTimeout(pending.timer);
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
const error = errorObj;
|
|
2182
|
-
const code = error["code"];
|
|
2183
|
-
const message = error["message"] ?? "Unknown error";
|
|
2184
|
-
const data = error["data"];
|
|
2185
|
-
if (code === -32004 /* ENTITY_NOT_FOUND */) {
|
|
2482
|
+
if (error != null) {
|
|
2483
|
+
if (error.code === -32004 /* ENTITY_NOT_FOUND */) {
|
|
2186
2484
|
const sessionId = String(
|
|
2187
2485
|
pending.params["sessionId"] ?? pending.requestId
|
|
2188
2486
|
);
|
|
2189
2487
|
pending.reject(new SessionNotFoundError(sessionId));
|
|
2190
2488
|
return;
|
|
2191
2489
|
}
|
|
2192
|
-
pending.reject(
|
|
2490
|
+
pending.reject(
|
|
2491
|
+
new ProtocolError(error.message, { code: error.code, data: error.data })
|
|
2492
|
+
);
|
|
2193
2493
|
return;
|
|
2194
2494
|
}
|
|
2195
|
-
pending.resolve(
|
|
2495
|
+
pending.resolve(result);
|
|
2196
2496
|
}
|
|
2197
|
-
/**
|
|
2198
|
-
* Handle an incoming notification message.
|
|
2199
|
-
* Dispatches to all registered notification listeners that match.
|
|
2200
|
-
*/
|
|
2201
2497
|
_handleNotification(notification) {
|
|
2202
|
-
|
|
2203
|
-
const innerNotification = params?.["notification"];
|
|
2204
|
-
const notificationType = innerNotification?.["type"];
|
|
2205
|
-
for (const listener of this._notificationListeners) {
|
|
2206
|
-
if (listener.filter?.type != null && listener.filter.type !== notificationType) {
|
|
2207
|
-
continue;
|
|
2208
|
-
}
|
|
2209
|
-
try {
|
|
2210
|
-
listener.callback(notification);
|
|
2211
|
-
} catch {
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2498
|
+
dispatchNotification(notification, this._notificationListeners);
|
|
2214
2499
|
}
|
|
2215
|
-
|
|
2216
|
-
* Handle an incoming server→client request.
|
|
2217
|
-
* Dispatches to the appropriate handler based on the method field.
|
|
2218
|
-
*/
|
|
2219
|
-
async _handleServerRequest(request) {
|
|
2220
|
-
const method = request["method"];
|
|
2221
|
-
const requestId = request["id"];
|
|
2222
|
-
const params = request["params"] ?? {};
|
|
2500
|
+
async _handleServerRequest(method, requestId, params) {
|
|
2223
2501
|
if (method === "droid.request_permission" /* REQUEST_PERMISSION */) {
|
|
2224
2502
|
await this._handlePermissionRequest(requestId, params);
|
|
2225
2503
|
} else if (method === "droid.ask_user" /* ASK_USER */) {
|
|
2226
2504
|
await this._handleAskUserRequest(requestId, params);
|
|
2227
2505
|
}
|
|
2228
2506
|
}
|
|
2229
|
-
/**
|
|
2230
|
-
* Handle droid.request_permission server→client request.
|
|
2231
|
-
*/
|
|
2232
2507
|
async _handlePermissionRequest(requestId, params) {
|
|
2233
2508
|
const handler = this._permissionHandler;
|
|
2234
2509
|
if (handler == null) {
|
|
2235
|
-
this._sendResponse(
|
|
2510
|
+
this._sendResponse(
|
|
2511
|
+
requestId,
|
|
2512
|
+
RequestPermissionResultSchema.parse({
|
|
2513
|
+
selectedOption: "cancel" /* Cancel */
|
|
2514
|
+
})
|
|
2515
|
+
);
|
|
2236
2516
|
return;
|
|
2237
2517
|
}
|
|
2238
2518
|
try {
|
|
2239
|
-
const
|
|
2240
|
-
|
|
2519
|
+
const parsedParams = RequestPermissionRequestParamsSchema.parse(params);
|
|
2520
|
+
const selection = await Promise.resolve(handler(parsedParams));
|
|
2521
|
+
const result = typeof selection === "string" ? { selectedOption: selection } : selection;
|
|
2522
|
+
this._sendResponse(
|
|
2523
|
+
requestId,
|
|
2524
|
+
RequestPermissionResultSchema.parse(result)
|
|
2525
|
+
);
|
|
2241
2526
|
} catch (exc) {
|
|
2242
2527
|
const errorMessage = exc instanceof Error ? exc.message : String(exc);
|
|
2243
2528
|
this._sendErrorResponse(
|
|
@@ -2248,18 +2533,19 @@ var ProtocolEngine = class {
|
|
|
2248
2533
|
);
|
|
2249
2534
|
}
|
|
2250
2535
|
}
|
|
2251
|
-
/**
|
|
2252
|
-
* Handle droid.ask_user server→client request.
|
|
2253
|
-
*/
|
|
2254
2536
|
async _handleAskUserRequest(requestId, params) {
|
|
2255
2537
|
const handler = this._askUserHandler;
|
|
2256
2538
|
if (handler == null) {
|
|
2257
|
-
this._sendResponse(
|
|
2539
|
+
this._sendResponse(
|
|
2540
|
+
requestId,
|
|
2541
|
+
AskUserResultSchema.parse({ cancelled: true, answers: [] })
|
|
2542
|
+
);
|
|
2258
2543
|
return;
|
|
2259
2544
|
}
|
|
2260
2545
|
try {
|
|
2261
|
-
const
|
|
2262
|
-
|
|
2546
|
+
const parsedParams = AskUserRequestParamsSchema.parse(params);
|
|
2547
|
+
const result = await Promise.resolve(handler(parsedParams));
|
|
2548
|
+
this._sendResponse(requestId, AskUserResultSchema.parse(result));
|
|
2263
2549
|
} catch (exc) {
|
|
2264
2550
|
const errorMessage = exc instanceof Error ? exc.message : String(exc);
|
|
2265
2551
|
this._sendErrorResponse(
|
|
@@ -2270,9 +2556,6 @@ var ProtocolEngine = class {
|
|
|
2270
2556
|
);
|
|
2271
2557
|
}
|
|
2272
2558
|
}
|
|
2273
|
-
// ------------------------------------------------------------------
|
|
2274
|
-
// Internal: Transport error handling
|
|
2275
|
-
// ------------------------------------------------------------------
|
|
2276
2559
|
/**
|
|
2277
2560
|
* Handle a transport error.
|
|
2278
2561
|
* Sets the sticky transport error and rejects all pending requests.
|
|
@@ -2286,29 +2569,17 @@ var ProtocolEngine = class {
|
|
|
2286
2569
|
connectionError.cause = error;
|
|
2287
2570
|
this._rejectAllPending(connectionError);
|
|
2288
2571
|
}
|
|
2289
|
-
// ------------------------------------------------------------------
|
|
2290
|
-
// Internal: Response helpers
|
|
2291
|
-
// ------------------------------------------------------------------
|
|
2292
|
-
/**
|
|
2293
|
-
* Send a JSON-RPC success response back to the server.
|
|
2294
|
-
*/
|
|
2295
2572
|
_sendResponse(requestId, result) {
|
|
2296
2573
|
const response = {
|
|
2297
2574
|
jsonrpc: JSONRPC_VERSION,
|
|
2298
2575
|
factoryApiVersion: LEGACY_FACTORY_API_VERSION,
|
|
2299
2576
|
factoryProtocolVersion: FACTORY_PROTOCOL_VERSION,
|
|
2300
|
-
type: "response"
|
|
2577
|
+
type: "response" /* Response */,
|
|
2301
2578
|
id: requestId,
|
|
2302
2579
|
result
|
|
2303
2580
|
};
|
|
2304
|
-
|
|
2305
|
-
this._transport.send(response);
|
|
2306
|
-
} catch {
|
|
2307
|
-
}
|
|
2581
|
+
this._sendBestEffort(response);
|
|
2308
2582
|
}
|
|
2309
|
-
/**
|
|
2310
|
-
* Send a JSON-RPC error response back to the server.
|
|
2311
|
-
*/
|
|
2312
2583
|
_sendErrorResponse(requestId, code, message, data) {
|
|
2313
2584
|
const errorObj = { code, message };
|
|
2314
2585
|
if (data !== void 0) {
|
|
@@ -2318,18 +2589,18 @@ var ProtocolEngine = class {
|
|
|
2318
2589
|
jsonrpc: JSONRPC_VERSION,
|
|
2319
2590
|
factoryApiVersion: LEGACY_FACTORY_API_VERSION,
|
|
2320
2591
|
factoryProtocolVersion: FACTORY_PROTOCOL_VERSION,
|
|
2321
|
-
type: "response"
|
|
2592
|
+
type: "response" /* Response */,
|
|
2322
2593
|
id: requestId,
|
|
2323
2594
|
error: errorObj
|
|
2324
2595
|
};
|
|
2596
|
+
this._sendBestEffort(response);
|
|
2597
|
+
}
|
|
2598
|
+
_sendBestEffort(message) {
|
|
2325
2599
|
try {
|
|
2326
|
-
this._transport.send(
|
|
2600
|
+
this._transport.send(message);
|
|
2327
2601
|
} catch {
|
|
2328
2602
|
}
|
|
2329
2603
|
}
|
|
2330
|
-
/**
|
|
2331
|
-
* Reject all pending requests with the given error.
|
|
2332
|
-
*/
|
|
2333
2604
|
_rejectAllPending(error) {
|
|
2334
2605
|
const pending = new Map(this._pendingRequests);
|
|
2335
2606
|
this._pendingRequests.clear();
|
|
@@ -2345,10 +2616,6 @@ var DroidClient = class {
|
|
|
2345
2616
|
_engine;
|
|
2346
2617
|
_sessionId = null;
|
|
2347
2618
|
_closed = false;
|
|
2348
|
-
/**
|
|
2349
|
-
* Client-level notification listeners.
|
|
2350
|
-
* Each entry is [callback, optional type filter string].
|
|
2351
|
-
*/
|
|
2352
2619
|
_notificationListeners = [];
|
|
2353
2620
|
/** Client-level permission handler. */
|
|
2354
2621
|
_permissionHandler = null;
|
|
@@ -2369,329 +2636,219 @@ var DroidClient = class {
|
|
|
2369
2636
|
(params) => this._dispatchAskUserRequest(params)
|
|
2370
2637
|
);
|
|
2371
2638
|
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2639
|
+
async _rpc(method, params, schema, timeout) {
|
|
2640
|
+
const raw = await this._engine.sendRequest(method, params, timeout);
|
|
2641
|
+
return schema.parse(raw);
|
|
2642
|
+
}
|
|
2643
|
+
async _sessionRpc(method, params, schema, timeout) {
|
|
2644
|
+
this._ensureNotClosed();
|
|
2645
|
+
this._ensureSession();
|
|
2646
|
+
return this._rpc(method, params, schema, timeout);
|
|
2647
|
+
}
|
|
2648
|
+
async _sessionRpcWithoutParams(method, schema, timeout) {
|
|
2649
|
+
return this._sessionRpc(method, {}, schema, timeout);
|
|
2650
|
+
}
|
|
2378
2651
|
get sessionId() {
|
|
2379
2652
|
return this._sessionId;
|
|
2380
2653
|
}
|
|
2381
|
-
/**
|
|
2382
|
-
* Whether the client is in a healthy state — not closed and no
|
|
2383
|
-
* transport errors have occurred. Returns false after transport
|
|
2384
|
-
* disconnect/error.
|
|
2385
|
-
*/
|
|
2386
2654
|
get isConnected() {
|
|
2387
2655
|
return !this._closed && this._engine.isHealthy;
|
|
2388
2656
|
}
|
|
2389
|
-
// ------------------------------------------------------------------
|
|
2390
|
-
// Session lifecycle methods
|
|
2391
|
-
// ------------------------------------------------------------------
|
|
2392
|
-
/**
|
|
2393
|
-
* Initialize a new session.
|
|
2394
|
-
*
|
|
2395
|
-
* Sends `droid.initialize_session` with extended timeout. On success,
|
|
2396
|
-
* stores the session ID internally and returns the typed result.
|
|
2397
|
-
*/
|
|
2398
2657
|
async initializeSession(params) {
|
|
2399
2658
|
this._ensureNotClosed();
|
|
2400
|
-
const
|
|
2659
|
+
const result = await this._rpc(
|
|
2401
2660
|
"droid.initialize_session" /* INITIALIZE_SESSION */,
|
|
2402
2661
|
params,
|
|
2662
|
+
InitializeSessionResultSchema,
|
|
2403
2663
|
SESSION_INIT_TIMEOUT
|
|
2404
2664
|
);
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
this._sessionId = result.sessionId;
|
|
2408
|
-
return result;
|
|
2409
|
-
}
|
|
2410
|
-
if ("sessionId" in response) {
|
|
2411
|
-
this._sessionId = response["sessionId"];
|
|
2412
|
-
return response;
|
|
2413
|
-
}
|
|
2414
|
-
return response;
|
|
2665
|
+
this._sessionId = result.sessionId;
|
|
2666
|
+
return result;
|
|
2415
2667
|
}
|
|
2416
|
-
/**
|
|
2417
|
-
* Load an existing session.
|
|
2418
|
-
*
|
|
2419
|
-
* Sends `droid.load_session`. SessionNotFoundError is thrown for
|
|
2420
|
-
* non-existent sessions (mapped from ENTITY_NOT_FOUND by the protocol engine).
|
|
2421
|
-
*/
|
|
2422
2668
|
async loadSession(params) {
|
|
2423
2669
|
this._ensureNotClosed();
|
|
2424
|
-
const
|
|
2670
|
+
const result = await this._rpc(
|
|
2425
2671
|
"droid.load_session" /* LOAD_SESSION */,
|
|
2426
2672
|
params,
|
|
2673
|
+
LoadSessionResultSchema,
|
|
2427
2674
|
SESSION_INIT_TIMEOUT
|
|
2428
2675
|
);
|
|
2429
|
-
const result = response["result"];
|
|
2430
|
-
if (result) {
|
|
2431
|
-
this._sessionId = params.sessionId;
|
|
2432
|
-
return result;
|
|
2433
|
-
}
|
|
2434
2676
|
this._sessionId = params.sessionId;
|
|
2435
|
-
return
|
|
2677
|
+
return result;
|
|
2436
2678
|
}
|
|
2437
|
-
/**
|
|
2438
|
-
* Add a user message to the active session.
|
|
2439
|
-
*
|
|
2440
|
-
* Sends `droid.add_user_message` with text and optional images/files.
|
|
2441
|
-
*/
|
|
2442
2679
|
async addUserMessage(params) {
|
|
2443
|
-
this.
|
|
2444
|
-
this._ensureSession();
|
|
2445
|
-
const response = await this._engine.sendRequest(
|
|
2680
|
+
return this._sessionRpc(
|
|
2446
2681
|
"droid.add_user_message" /* ADD_USER_MESSAGE */,
|
|
2447
|
-
params
|
|
2682
|
+
params,
|
|
2683
|
+
AddUserMessageResultSchema
|
|
2448
2684
|
);
|
|
2449
|
-
const result = response["result"];
|
|
2450
|
-
return result ?? response;
|
|
2451
2685
|
}
|
|
2452
|
-
/**
|
|
2453
|
-
* Interrupt the current session.
|
|
2454
|
-
*
|
|
2455
|
-
* Sends `droid.interrupt_session` with empty params.
|
|
2456
|
-
*/
|
|
2457
2686
|
async interruptSession() {
|
|
2458
|
-
this.
|
|
2459
|
-
this._ensureSession();
|
|
2460
|
-
const response = await this._engine.sendRequest(
|
|
2687
|
+
return this._sessionRpcWithoutParams(
|
|
2461
2688
|
"droid.interrupt_session" /* INTERRUPT_SESSION */,
|
|
2462
|
-
|
|
2689
|
+
InterruptSessionResultSchema
|
|
2690
|
+
);
|
|
2691
|
+
}
|
|
2692
|
+
async closeSession(params = {}) {
|
|
2693
|
+
return this._sessionRpc(
|
|
2694
|
+
"droid.close_session" /* CLOSE_SESSION */,
|
|
2695
|
+
params,
|
|
2696
|
+
CloseSessionResultSchema
|
|
2463
2697
|
);
|
|
2464
|
-
const result = response["result"];
|
|
2465
|
-
return result ?? response;
|
|
2466
2698
|
}
|
|
2467
|
-
/**
|
|
2468
|
-
* Kill a worker session.
|
|
2469
|
-
*
|
|
2470
|
-
* Sends `droid.kill_worker_session`.
|
|
2471
|
-
*/
|
|
2472
2699
|
async killWorkerSession(params) {
|
|
2473
|
-
this.
|
|
2474
|
-
this._ensureSession();
|
|
2475
|
-
const response = await this._engine.sendRequest(
|
|
2700
|
+
return this._sessionRpc(
|
|
2476
2701
|
"droid.kill_worker_session" /* KILL_WORKER_SESSION */,
|
|
2477
|
-
params
|
|
2702
|
+
params,
|
|
2703
|
+
KillWorkerSessionResultSchema
|
|
2478
2704
|
);
|
|
2479
|
-
const result = response["result"];
|
|
2480
|
-
return result ?? response;
|
|
2481
2705
|
}
|
|
2482
|
-
/**
|
|
2483
|
-
* Update session settings.
|
|
2484
|
-
*
|
|
2485
|
-
* Sends `droid.update_session_settings` with the provided partial settings.
|
|
2486
|
-
*/
|
|
2487
2706
|
async updateSessionSettings(params) {
|
|
2488
|
-
this.
|
|
2489
|
-
this._ensureSession();
|
|
2490
|
-
const response = await this._engine.sendRequest(
|
|
2707
|
+
return this._sessionRpc(
|
|
2491
2708
|
"droid.update_session_settings" /* UPDATE_SESSION_SETTINGS */,
|
|
2492
|
-
params
|
|
2709
|
+
params,
|
|
2710
|
+
UpdateSessionSettingsResultSchema
|
|
2493
2711
|
);
|
|
2494
|
-
const result = response["result"];
|
|
2495
|
-
return result ?? response;
|
|
2496
2712
|
}
|
|
2497
|
-
// ------------------------------------------------------------------
|
|
2498
|
-
// MCP methods
|
|
2499
|
-
// ------------------------------------------------------------------
|
|
2500
|
-
/**
|
|
2501
|
-
* Toggle an MCP server on or off.
|
|
2502
|
-
*/
|
|
2503
2713
|
async toggleMcpServer(params) {
|
|
2504
|
-
this.
|
|
2505
|
-
this._ensureSession();
|
|
2506
|
-
const response = await this._engine.sendRequest(
|
|
2714
|
+
return this._sessionRpc(
|
|
2507
2715
|
"droid.toggle_mcp_server" /* TOGGLE_MCP_SERVER */,
|
|
2508
|
-
params
|
|
2716
|
+
params,
|
|
2717
|
+
ToggleMcpServerResultSchema
|
|
2509
2718
|
);
|
|
2510
|
-
const result = response["result"];
|
|
2511
|
-
return result ?? response;
|
|
2512
2719
|
}
|
|
2513
|
-
/**
|
|
2514
|
-
* Authenticate an MCP server (OAuth flow).
|
|
2515
|
-
* Uses extended timeout (300s) since OAuth requires user interaction.
|
|
2516
|
-
*/
|
|
2517
2720
|
async authenticateMcpServer(params) {
|
|
2518
|
-
this.
|
|
2519
|
-
this._ensureSession();
|
|
2520
|
-
const response = await this._engine.sendRequest(
|
|
2721
|
+
return this._sessionRpc(
|
|
2521
2722
|
"droid.authenticate_mcp_server" /* AUTHENTICATE_MCP_SERVER */,
|
|
2522
2723
|
params,
|
|
2724
|
+
AuthenticateMcpServerResultSchema,
|
|
2523
2725
|
MCP_AUTH_TIMEOUT
|
|
2524
2726
|
);
|
|
2525
|
-
const result = response["result"];
|
|
2526
|
-
return result ?? response;
|
|
2527
2727
|
}
|
|
2528
|
-
/**
|
|
2529
|
-
* Cancel an in-progress MCP authentication.
|
|
2530
|
-
*/
|
|
2531
2728
|
async cancelMcpAuth(params) {
|
|
2532
|
-
this.
|
|
2533
|
-
this._ensureSession();
|
|
2534
|
-
const response = await this._engine.sendRequest(
|
|
2729
|
+
return this._sessionRpc(
|
|
2535
2730
|
"droid.cancel_mcp_auth" /* CANCEL_MCP_AUTH */,
|
|
2536
|
-
params
|
|
2731
|
+
params,
|
|
2732
|
+
CancelMcpAuthResultSchema
|
|
2537
2733
|
);
|
|
2538
|
-
const result = response["result"];
|
|
2539
|
-
return result ?? response;
|
|
2540
2734
|
}
|
|
2541
|
-
/**
|
|
2542
|
-
* Clear stored MCP authentication tokens.
|
|
2543
|
-
*/
|
|
2544
2735
|
async clearMcpAuth(params) {
|
|
2545
|
-
this.
|
|
2546
|
-
this._ensureSession();
|
|
2547
|
-
const response = await this._engine.sendRequest(
|
|
2736
|
+
return this._sessionRpc(
|
|
2548
2737
|
"droid.clear_mcp_auth" /* CLEAR_MCP_AUTH */,
|
|
2549
|
-
params
|
|
2738
|
+
params,
|
|
2739
|
+
ClearMcpAuthResultSchema
|
|
2550
2740
|
);
|
|
2551
|
-
const result = response["result"];
|
|
2552
|
-
return result ?? response;
|
|
2553
2741
|
}
|
|
2554
|
-
/**
|
|
2555
|
-
* Submit an MCP authentication code (OAuth callback).
|
|
2556
|
-
*/
|
|
2557
2742
|
async submitMcpAuthCode(params) {
|
|
2558
|
-
this.
|
|
2559
|
-
this._ensureSession();
|
|
2560
|
-
const response = await this._engine.sendRequest(
|
|
2743
|
+
return this._sessionRpc(
|
|
2561
2744
|
"droid.submit_mcp_auth_code" /* SUBMIT_MCP_AUTH_CODE */,
|
|
2562
|
-
params
|
|
2745
|
+
params,
|
|
2746
|
+
SubmitMcpAuthCodeResultSchema
|
|
2563
2747
|
);
|
|
2564
|
-
const result = response["result"];
|
|
2565
|
-
return result ?? response;
|
|
2566
2748
|
}
|
|
2567
|
-
/**
|
|
2568
|
-
* Add an MCP server.
|
|
2569
|
-
*/
|
|
2570
2749
|
async addMcpServer(params) {
|
|
2571
|
-
this.
|
|
2572
|
-
this._ensureSession();
|
|
2573
|
-
const response = await this._engine.sendRequest(
|
|
2750
|
+
return this._sessionRpc(
|
|
2574
2751
|
"droid.add_mcp_server" /* ADD_MCP_SERVER */,
|
|
2575
|
-
params
|
|
2752
|
+
params,
|
|
2753
|
+
AddMcpServerResultSchema
|
|
2576
2754
|
);
|
|
2577
|
-
const result = response["result"];
|
|
2578
|
-
return result ?? response;
|
|
2579
2755
|
}
|
|
2580
|
-
/**
|
|
2581
|
-
* Remove an MCP server.
|
|
2582
|
-
*/
|
|
2583
2756
|
async removeMcpServer(params) {
|
|
2584
|
-
this.
|
|
2585
|
-
this._ensureSession();
|
|
2586
|
-
const response = await this._engine.sendRequest(
|
|
2757
|
+
return this._sessionRpc(
|
|
2587
2758
|
"droid.remove_mcp_server" /* REMOVE_MCP_SERVER */,
|
|
2588
|
-
params
|
|
2759
|
+
params,
|
|
2760
|
+
RemoveMcpServerResultSchema
|
|
2589
2761
|
);
|
|
2590
|
-
const result = response["result"];
|
|
2591
|
-
return result ?? response;
|
|
2592
2762
|
}
|
|
2593
|
-
/**
|
|
2594
|
-
* List available MCP registry servers.
|
|
2595
|
-
*/
|
|
2596
2763
|
async listMcpRegistry() {
|
|
2597
|
-
this.
|
|
2598
|
-
this._ensureSession();
|
|
2599
|
-
const response = await this._engine.sendRequest(
|
|
2764
|
+
return this._sessionRpcWithoutParams(
|
|
2600
2765
|
"droid.list_mcp_registry" /* LIST_MCP_REGISTRY */,
|
|
2601
|
-
|
|
2766
|
+
ListMcpRegistryResultSchema
|
|
2602
2767
|
);
|
|
2603
|
-
const result = response["result"];
|
|
2604
|
-
return result ?? response;
|
|
2605
2768
|
}
|
|
2606
|
-
/**
|
|
2607
|
-
* List available MCP tools.
|
|
2608
|
-
*/
|
|
2609
2769
|
async listMcpTools() {
|
|
2610
|
-
this.
|
|
2611
|
-
this._ensureSession();
|
|
2612
|
-
const response = await this._engine.sendRequest(
|
|
2770
|
+
return this._sessionRpcWithoutParams(
|
|
2613
2771
|
"droid.list_mcp_tools" /* LIST_MCP_TOOLS */,
|
|
2614
|
-
|
|
2772
|
+
ListMcpToolsResultSchema
|
|
2773
|
+
);
|
|
2774
|
+
}
|
|
2775
|
+
async listTools(params = {}) {
|
|
2776
|
+
return this._sessionRpc(
|
|
2777
|
+
"droid.list_tools" /* LIST_TOOLS */,
|
|
2778
|
+
params,
|
|
2779
|
+
ListToolsResultSchema
|
|
2615
2780
|
);
|
|
2616
|
-
const result = response["result"];
|
|
2617
|
-
return result ?? response;
|
|
2618
2781
|
}
|
|
2619
|
-
/**
|
|
2620
|
-
* List MCP servers with status and summary.
|
|
2621
|
-
*/
|
|
2622
2782
|
async listMcpServers() {
|
|
2623
|
-
this.
|
|
2624
|
-
this._ensureSession();
|
|
2625
|
-
const response = await this._engine.sendRequest(
|
|
2783
|
+
return this._sessionRpcWithoutParams(
|
|
2626
2784
|
"droid.list_mcp_servers" /* LIST_MCP_SERVERS */,
|
|
2627
|
-
|
|
2785
|
+
ListMcpServersResultSchema
|
|
2628
2786
|
);
|
|
2629
|
-
const result = response["result"];
|
|
2630
|
-
return result ?? response;
|
|
2631
2787
|
}
|
|
2632
|
-
/**
|
|
2633
|
-
* Toggle an MCP tool on or off.
|
|
2634
|
-
*/
|
|
2635
2788
|
async toggleMcpTool(params) {
|
|
2636
|
-
this.
|
|
2637
|
-
this._ensureSession();
|
|
2638
|
-
const response = await this._engine.sendRequest(
|
|
2789
|
+
return this._sessionRpc(
|
|
2639
2790
|
"droid.toggle_mcp_tool" /* TOGGLE_MCP_TOOL */,
|
|
2640
|
-
params
|
|
2791
|
+
params,
|
|
2792
|
+
ToggleMcpToolResultSchema
|
|
2641
2793
|
);
|
|
2642
|
-
const result = response["result"];
|
|
2643
|
-
return result ?? response;
|
|
2644
2794
|
}
|
|
2645
|
-
// ------------------------------------------------------------------
|
|
2646
|
-
// Skills and bug report methods
|
|
2647
|
-
// ------------------------------------------------------------------
|
|
2648
|
-
/**
|
|
2649
|
-
* List available skills.
|
|
2650
|
-
*/
|
|
2651
2795
|
async listSkills() {
|
|
2652
|
-
this.
|
|
2653
|
-
this._ensureSession();
|
|
2654
|
-
const response = await this._engine.sendRequest(
|
|
2796
|
+
return this._sessionRpcWithoutParams(
|
|
2655
2797
|
"droid.list_skills" /* LIST_SKILLS */,
|
|
2656
|
-
|
|
2798
|
+
ListSkillsResultSchema
|
|
2657
2799
|
);
|
|
2658
|
-
const result = response["result"];
|
|
2659
|
-
return result ?? response;
|
|
2660
2800
|
}
|
|
2661
|
-
/**
|
|
2662
|
-
* Submit a bug report.
|
|
2663
|
-
*/
|
|
2664
2801
|
async submitBugReport(params) {
|
|
2665
|
-
this.
|
|
2666
|
-
this._ensureSession();
|
|
2667
|
-
const response = await this._engine.sendRequest(
|
|
2802
|
+
return this._sessionRpc(
|
|
2668
2803
|
"droid.submit_bug_report" /* SUBMIT_BUG_REPORT */,
|
|
2669
|
-
params
|
|
2804
|
+
params,
|
|
2805
|
+
SubmitBugReportResultSchema
|
|
2806
|
+
);
|
|
2807
|
+
}
|
|
2808
|
+
async getRewindInfo(params) {
|
|
2809
|
+
return this._sessionRpc(
|
|
2810
|
+
"droid.get_rewind_info" /* GET_REWIND_INFO */,
|
|
2811
|
+
params,
|
|
2812
|
+
GetRewindInfoResultSchema
|
|
2813
|
+
);
|
|
2814
|
+
}
|
|
2815
|
+
async executeRewind(params) {
|
|
2816
|
+
return this._sessionRpc(
|
|
2817
|
+
"droid.execute_rewind" /* EXECUTE_REWIND */,
|
|
2818
|
+
params,
|
|
2819
|
+
ExecuteRewindResultSchema,
|
|
2820
|
+
REWIND_TIMEOUT
|
|
2821
|
+
);
|
|
2822
|
+
}
|
|
2823
|
+
async compactSession(params) {
|
|
2824
|
+
return this._sessionRpc(
|
|
2825
|
+
"droid.compact_session" /* COMPACT_SESSION */,
|
|
2826
|
+
params,
|
|
2827
|
+
CompactSessionResultSchema,
|
|
2828
|
+
COMPACTION_TIMEOUT
|
|
2829
|
+
);
|
|
2830
|
+
}
|
|
2831
|
+
async forkSession() {
|
|
2832
|
+
return this._sessionRpcWithoutParams(
|
|
2833
|
+
"droid.fork_session" /* FORK_SESSION */,
|
|
2834
|
+
ForkSessionResultSchema
|
|
2835
|
+
);
|
|
2836
|
+
}
|
|
2837
|
+
async getContextStats() {
|
|
2838
|
+
return this._sessionRpcWithoutParams(
|
|
2839
|
+
"droid.get_context_stats" /* GET_CONTEXT_STATS */,
|
|
2840
|
+
GetContextStatsResultSchema
|
|
2841
|
+
);
|
|
2842
|
+
}
|
|
2843
|
+
async renameSession(params) {
|
|
2844
|
+
return this._sessionRpc(
|
|
2845
|
+
"droid.rename_session" /* RENAME_SESSION */,
|
|
2846
|
+
params,
|
|
2847
|
+
RenameSessionResultSchema
|
|
2670
2848
|
);
|
|
2671
|
-
const result = response["result"];
|
|
2672
|
-
return result ?? response;
|
|
2673
2849
|
}
|
|
2674
|
-
// ------------------------------------------------------------------
|
|
2675
|
-
// Notification subscription
|
|
2676
|
-
// ------------------------------------------------------------------
|
|
2677
|
-
/**
|
|
2678
|
-
* Register a callback for incoming notification messages.
|
|
2679
|
-
*
|
|
2680
|
-
* Multiple listeners can be registered. Each receives the full parsed
|
|
2681
|
-
* notification object. Optionally filter by notification type.
|
|
2682
|
-
*
|
|
2683
|
-
* Listener exceptions are isolated — if one raises, others still receive
|
|
2684
|
-
* the event and the engine continues.
|
|
2685
|
-
*
|
|
2686
|
-
* @param callback - Invoked with the notification object.
|
|
2687
|
-
* @param filter - Optional filter to only receive specific notification types.
|
|
2688
|
-
* @returns An unsubscribe function. Calling it again is safe (no-op).
|
|
2689
|
-
*/
|
|
2690
2850
|
onNotification(callback, filter) {
|
|
2691
|
-
const entry = {
|
|
2692
|
-
callback,
|
|
2693
|
-
typeFilter: filter?.type
|
|
2694
|
-
};
|
|
2851
|
+
const entry = { callback, filter };
|
|
2695
2852
|
this._notificationListeners.push(entry);
|
|
2696
2853
|
let unsubscribed = false;
|
|
2697
2854
|
return () => {
|
|
@@ -2704,54 +2861,18 @@ var DroidClient = class {
|
|
|
2704
2861
|
}
|
|
2705
2862
|
};
|
|
2706
2863
|
}
|
|
2707
|
-
// ------------------------------------------------------------------
|
|
2708
|
-
// Permission/ask-user handler registration
|
|
2709
|
-
// ------------------------------------------------------------------
|
|
2710
|
-
/**
|
|
2711
|
-
* Register a handler for server→client permission requests.
|
|
2712
|
-
*
|
|
2713
|
-
* The handler receives the request params and should return a
|
|
2714
|
-
* ToolConfirmationOutcome string value. Async handlers are awaited.
|
|
2715
|
-
* Replaces any previously registered handler.
|
|
2716
|
-
*/
|
|
2717
2864
|
setPermissionHandler(handler) {
|
|
2718
2865
|
this._permissionHandler = handler;
|
|
2719
2866
|
}
|
|
2720
|
-
/**
|
|
2721
|
-
* Remove the permission request handler.
|
|
2722
|
-
* Restores default behavior: return "cancel".
|
|
2723
|
-
*/
|
|
2724
2867
|
clearPermissionHandler() {
|
|
2725
2868
|
this._permissionHandler = null;
|
|
2726
2869
|
}
|
|
2727
|
-
/**
|
|
2728
|
-
* Register a handler for server→client ask-user requests.
|
|
2729
|
-
*
|
|
2730
|
-
* The handler receives the request params and should return a result
|
|
2731
|
-
* object with `cancelled` and `answers` keys. Async handlers are awaited.
|
|
2732
|
-
* Replaces any previously registered handler.
|
|
2733
|
-
*/
|
|
2734
2870
|
setAskUserHandler(handler) {
|
|
2735
2871
|
this._askUserHandler = handler;
|
|
2736
2872
|
}
|
|
2737
|
-
/**
|
|
2738
|
-
* Remove the ask-user request handler.
|
|
2739
|
-
* Restores default behavior: return `{ cancelled: true, answers: [] }`.
|
|
2740
|
-
*/
|
|
2741
2873
|
clearAskUserHandler() {
|
|
2742
2874
|
this._askUserHandler = null;
|
|
2743
2875
|
}
|
|
2744
|
-
// ------------------------------------------------------------------
|
|
2745
|
-
// Lifecycle
|
|
2746
|
-
// ------------------------------------------------------------------
|
|
2747
|
-
/**
|
|
2748
|
-
* Close the client and release all resources.
|
|
2749
|
-
*
|
|
2750
|
-
* Rejects pending requests, clears handlers and listeners, and closes
|
|
2751
|
-
* the protocol engine. Idempotent — safe to call multiple times.
|
|
2752
|
-
*
|
|
2753
|
-
* After close, all method calls throw ConnectionError immediately.
|
|
2754
|
-
*/
|
|
2755
2876
|
async close() {
|
|
2756
2877
|
if (this._closed) {
|
|
2757
2878
|
return;
|
|
@@ -2762,48 +2883,16 @@ var DroidClient = class {
|
|
|
2762
2883
|
this._askUserHandler = null;
|
|
2763
2884
|
await this._engine.close();
|
|
2764
2885
|
}
|
|
2765
|
-
// ------------------------------------------------------------------
|
|
2766
|
-
// Internal: dispatch methods
|
|
2767
|
-
// ------------------------------------------------------------------
|
|
2768
|
-
/**
|
|
2769
|
-
* Dispatch a notification to all registered client-level listeners.
|
|
2770
|
-
* Filters by notification type if a type filter is set.
|
|
2771
|
-
* Exception in one listener does not affect others.
|
|
2772
|
-
*/
|
|
2773
2886
|
_dispatchNotification(notification) {
|
|
2774
|
-
|
|
2775
|
-
const innerNotification = params?.["notification"];
|
|
2776
|
-
const notificationType = innerNotification?.["type"];
|
|
2777
|
-
const listeners = [...this._notificationListeners];
|
|
2778
|
-
for (const listener of listeners) {
|
|
2779
|
-
if (listener.typeFilter != null && listener.typeFilter !== notificationType) {
|
|
2780
|
-
continue;
|
|
2781
|
-
}
|
|
2782
|
-
try {
|
|
2783
|
-
listener.callback(notification);
|
|
2784
|
-
} catch {
|
|
2785
|
-
}
|
|
2786
|
-
}
|
|
2887
|
+
dispatchNotification(notification, [...this._notificationListeners]);
|
|
2787
2888
|
}
|
|
2788
|
-
/**
|
|
2789
|
-
* Dispatch to the client-level permission handler.
|
|
2790
|
-
* If no handler is set, returns the default "cancel" outcome.
|
|
2791
|
-
* If handler throws, the error propagates to the protocol engine
|
|
2792
|
-
* which sends an error response.
|
|
2793
|
-
*/
|
|
2794
2889
|
_dispatchPermissionRequest(params) {
|
|
2795
2890
|
const handler = this._permissionHandler;
|
|
2796
2891
|
if (handler == null) {
|
|
2797
|
-
return "cancel"
|
|
2892
|
+
return "cancel" /* Cancel */;
|
|
2798
2893
|
}
|
|
2799
2894
|
return handler(params);
|
|
2800
2895
|
}
|
|
2801
|
-
/**
|
|
2802
|
-
* Dispatch to the client-level ask-user handler.
|
|
2803
|
-
* If no handler is set, returns the default cancelled response.
|
|
2804
|
-
* If handler throws, the error propagates to the protocol engine
|
|
2805
|
-
* which sends an error response.
|
|
2806
|
-
*/
|
|
2807
2896
|
_dispatchAskUserRequest(params) {
|
|
2808
2897
|
const handler = this._askUserHandler;
|
|
2809
2898
|
if (handler == null) {
|
|
@@ -2811,12 +2900,6 @@ var DroidClient = class {
|
|
|
2811
2900
|
}
|
|
2812
2901
|
return handler(params);
|
|
2813
2902
|
}
|
|
2814
|
-
// ------------------------------------------------------------------
|
|
2815
|
-
// Internal: guards
|
|
2816
|
-
// ------------------------------------------------------------------
|
|
2817
|
-
/**
|
|
2818
|
-
* Throw ConnectionError if the client has been closed.
|
|
2819
|
-
*/
|
|
2820
2903
|
_ensureNotClosed() {
|
|
2821
2904
|
if (this._closed) {
|
|
2822
2905
|
throw new ConnectionError(
|
|
@@ -2824,9 +2907,6 @@ var DroidClient = class {
|
|
|
2824
2907
|
);
|
|
2825
2908
|
}
|
|
2826
2909
|
}
|
|
2827
|
-
/**
|
|
2828
|
-
* Throw SessionError if no active session.
|
|
2829
|
-
*/
|
|
2830
2910
|
_ensureSession() {
|
|
2831
2911
|
if (this._sessionId == null) {
|
|
2832
2912
|
throw new SessionError(
|
|
@@ -2837,26 +2917,79 @@ var DroidClient = class {
|
|
|
2837
2917
|
};
|
|
2838
2918
|
|
|
2839
2919
|
// src/stream.ts
|
|
2840
|
-
|
|
2920
|
+
var DroidMessageType = {
|
|
2921
|
+
Assistant: "assistant",
|
|
2922
|
+
User: "user",
|
|
2923
|
+
ToolCall: "tool_call",
|
|
2924
|
+
AssistantTextDelta: "assistant_text_delta",
|
|
2925
|
+
AssistantTextComplete: "assistant_text_complete",
|
|
2926
|
+
ThinkingTextDelta: "thinking_text_delta",
|
|
2927
|
+
ThinkingTextComplete: "thinking_text_complete",
|
|
2928
|
+
ToolCallDelta: "tool_call_delta",
|
|
2929
|
+
ToolResult: "tool_result",
|
|
2930
|
+
ToolProgress: "tool_progress",
|
|
2931
|
+
WorkingStateChanged: "working_state_changed",
|
|
2932
|
+
TokenUsageUpdate: "token_usage_update",
|
|
2933
|
+
PermissionResolved: "permission_resolved",
|
|
2934
|
+
SettingsUpdated: "settings_updated",
|
|
2935
|
+
SessionTitleUpdated: "session_title_updated",
|
|
2936
|
+
McpStatusChanged: "mcp_status_changed",
|
|
2937
|
+
MissionStateChanged: "mission_state_changed",
|
|
2938
|
+
MissionFeaturesChanged: "mission_features_changed",
|
|
2939
|
+
MissionProgressEntry: "mission_progress_entry",
|
|
2940
|
+
MissionHeartbeat: "mission_heartbeat",
|
|
2941
|
+
MissionWorkerStarted: "mission_worker_started",
|
|
2942
|
+
MissionWorkerCompleted: "mission_worker_completed",
|
|
2943
|
+
McpAuthRequired: "mcp_auth_required",
|
|
2944
|
+
McpAuthCompleted: "mcp_auth_completed",
|
|
2945
|
+
Hook: "hook",
|
|
2946
|
+
Error: "error",
|
|
2947
|
+
Result: "result"
|
|
2948
|
+
};
|
|
2949
|
+
function convertNotificationToStreamMessage(raw) {
|
|
2950
|
+
const parsed = SessionNotificationPayloadSchema.safeParse(raw);
|
|
2951
|
+
if (!parsed.success) {
|
|
2952
|
+
return null;
|
|
2953
|
+
}
|
|
2954
|
+
const notification = parsed.data;
|
|
2841
2955
|
switch (notification.type) {
|
|
2842
2956
|
case "assistant_text_delta" /* ASSISTANT_TEXT_DELTA */:
|
|
2843
2957
|
return {
|
|
2844
|
-
type:
|
|
2958
|
+
type: DroidMessageType.AssistantTextDelta,
|
|
2845
2959
|
messageId: notification.messageId,
|
|
2846
2960
|
blockIndex: notification.blockIndex,
|
|
2847
2961
|
text: notification.textDelta
|
|
2848
2962
|
};
|
|
2963
|
+
case "assistant_text_complete" /* ASSISTANT_TEXT_COMPLETE */:
|
|
2964
|
+
return {
|
|
2965
|
+
type: DroidMessageType.AssistantTextComplete,
|
|
2966
|
+
messageId: notification.messageId,
|
|
2967
|
+
blockIndex: notification.blockIndex
|
|
2968
|
+
};
|
|
2849
2969
|
case "thinking_text_delta" /* THINKING_TEXT_DELTA */:
|
|
2850
2970
|
return {
|
|
2851
|
-
type:
|
|
2971
|
+
type: DroidMessageType.ThinkingTextDelta,
|
|
2852
2972
|
messageId: notification.messageId,
|
|
2853
2973
|
blockIndex: notification.blockIndex,
|
|
2854
2974
|
text: notification.textDelta
|
|
2855
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
|
+
};
|
|
2856
2988
|
case "tool_result" /* TOOL_RESULT */:
|
|
2857
2989
|
return {
|
|
2858
|
-
type:
|
|
2990
|
+
type: DroidMessageType.ToolResult,
|
|
2859
2991
|
toolUseId: notification.toolUseId,
|
|
2992
|
+
toolName: "",
|
|
2860
2993
|
content: normalizeToolResultContent(notification.content),
|
|
2861
2994
|
isError: Boolean(notification.isError)
|
|
2862
2995
|
};
|
|
@@ -2864,7 +2997,7 @@ function convertNotificationToStreamMessage(notification) {
|
|
|
2864
2997
|
const update = notification.update;
|
|
2865
2998
|
const text = update?.text ?? update?.status ?? update?.details ?? "";
|
|
2866
2999
|
return {
|
|
2867
|
-
type:
|
|
3000
|
+
type: DroidMessageType.ToolProgress,
|
|
2868
3001
|
toolUseId: notification.toolUseId,
|
|
2869
3002
|
toolName: notification.toolName,
|
|
2870
3003
|
content: text,
|
|
@@ -2873,108 +3006,117 @@ function convertNotificationToStreamMessage(notification) {
|
|
|
2873
3006
|
}
|
|
2874
3007
|
case "droid_working_state_changed" /* DROID_WORKING_STATE_CHANGED */:
|
|
2875
3008
|
return {
|
|
2876
|
-
type:
|
|
3009
|
+
type: DroidMessageType.WorkingStateChanged,
|
|
2877
3010
|
state: notification.newState
|
|
2878
3011
|
};
|
|
2879
3012
|
case "session_token_usage_changed" /* SESSION_TOKEN_USAGE_CHANGED */: {
|
|
2880
3013
|
const tu = notification.tokenUsage;
|
|
2881
3014
|
return {
|
|
2882
|
-
type:
|
|
3015
|
+
type: DroidMessageType.TokenUsageUpdate,
|
|
2883
3016
|
inputTokens: tu.inputTokens,
|
|
2884
3017
|
outputTokens: tu.outputTokens,
|
|
2885
3018
|
cacheReadTokens: tu.cacheReadTokens,
|
|
2886
|
-
|
|
3019
|
+
cacheCreationTokens: tu.cacheCreationTokens,
|
|
2887
3020
|
thinkingTokens: tu.thinkingTokens
|
|
2888
3021
|
};
|
|
2889
3022
|
}
|
|
2890
3023
|
case "create_message" /* CREATE_MESSAGE */: {
|
|
2891
3024
|
const msg = notification.message;
|
|
2892
3025
|
const messages = [];
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
toolInput: block.input ?? {},
|
|
2900
|
-
toolUseId: block.id
|
|
2901
|
-
});
|
|
2902
|
-
}
|
|
3026
|
+
for (const block of msg.content) {
|
|
3027
|
+
if (block.type === "tool_use") {
|
|
3028
|
+
messages.push({
|
|
3029
|
+
type: DroidMessageType.ToolCall,
|
|
3030
|
+
toolUse: block
|
|
3031
|
+
});
|
|
2903
3032
|
}
|
|
2904
3033
|
}
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
})
|
|
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
|
+
}
|
|
2912
3054
|
return messages;
|
|
2913
3055
|
}
|
|
2914
3056
|
case "error" /* ERROR */:
|
|
2915
3057
|
return {
|
|
2916
|
-
type:
|
|
3058
|
+
type: DroidMessageType.Error,
|
|
2917
3059
|
message: notification.message,
|
|
2918
3060
|
errorType: notification.errorType,
|
|
2919
3061
|
timestamp: notification.timestamp
|
|
2920
3062
|
};
|
|
2921
3063
|
case "permission_resolved" /* PERMISSION_RESOLVED */:
|
|
2922
3064
|
return {
|
|
2923
|
-
type:
|
|
3065
|
+
type: DroidMessageType.PermissionResolved,
|
|
2924
3066
|
requestId: notification.requestId,
|
|
2925
3067
|
toolUseIds: notification.toolUseIds,
|
|
2926
3068
|
selectedOption: notification.selectedOption
|
|
2927
3069
|
};
|
|
2928
3070
|
case "settings_updated" /* SETTINGS_UPDATED */:
|
|
2929
3071
|
return {
|
|
2930
|
-
type:
|
|
3072
|
+
type: DroidMessageType.SettingsUpdated,
|
|
2931
3073
|
settings: notification.settings
|
|
2932
3074
|
};
|
|
2933
3075
|
case "session_title_updated" /* SESSION_TITLE_UPDATED */:
|
|
2934
3076
|
return {
|
|
2935
|
-
type:
|
|
3077
|
+
type: DroidMessageType.SessionTitleUpdated,
|
|
2936
3078
|
title: notification.title
|
|
2937
3079
|
};
|
|
2938
3080
|
case "mcp_status_changed" /* MCP_STATUS_CHANGED */:
|
|
2939
3081
|
return {
|
|
2940
|
-
type:
|
|
3082
|
+
type: DroidMessageType.McpStatusChanged,
|
|
2941
3083
|
servers: notification.servers,
|
|
2942
3084
|
summary: notification.summary
|
|
2943
3085
|
};
|
|
2944
3086
|
case "mission_state_changed" /* MISSION_STATE_CHANGED */:
|
|
2945
3087
|
return {
|
|
2946
|
-
type:
|
|
3088
|
+
type: DroidMessageType.MissionStateChanged,
|
|
2947
3089
|
state: notification.state
|
|
2948
3090
|
};
|
|
2949
3091
|
case "mission_features_changed" /* MISSION_FEATURES_CHANGED */:
|
|
2950
3092
|
return {
|
|
2951
|
-
type:
|
|
3093
|
+
type: DroidMessageType.MissionFeaturesChanged,
|
|
2952
3094
|
features: notification.features
|
|
2953
3095
|
};
|
|
2954
3096
|
case "mission_progress_entry" /* MISSION_PROGRESS_ENTRY */:
|
|
2955
3097
|
return {
|
|
2956
|
-
type:
|
|
3098
|
+
type: DroidMessageType.MissionProgressEntry,
|
|
2957
3099
|
progressLog: notification.progressLog
|
|
2958
3100
|
};
|
|
2959
3101
|
case "mission_heartbeat" /* MISSION_HEARTBEAT */:
|
|
2960
3102
|
return {
|
|
2961
|
-
type:
|
|
3103
|
+
type: DroidMessageType.MissionHeartbeat,
|
|
2962
3104
|
timestamp: notification.timestamp
|
|
2963
3105
|
};
|
|
2964
3106
|
case "mission_worker_started" /* MISSION_WORKER_STARTED */:
|
|
2965
3107
|
return {
|
|
2966
|
-
type:
|
|
3108
|
+
type: DroidMessageType.MissionWorkerStarted,
|
|
2967
3109
|
workerSessionId: notification.workerSessionId
|
|
2968
3110
|
};
|
|
2969
3111
|
case "mission_worker_completed" /* MISSION_WORKER_COMPLETED */:
|
|
2970
3112
|
return {
|
|
2971
|
-
type:
|
|
3113
|
+
type: DroidMessageType.MissionWorkerCompleted,
|
|
2972
3114
|
workerSessionId: notification.workerSessionId,
|
|
2973
3115
|
exitCode: notification.exitCode
|
|
2974
3116
|
};
|
|
2975
3117
|
case "mcp_auth_required" /* MCP_AUTH_REQUIRED */:
|
|
2976
3118
|
return {
|
|
2977
|
-
type:
|
|
3119
|
+
type: DroidMessageType.McpAuthRequired,
|
|
2978
3120
|
serverName: notification.serverName,
|
|
2979
3121
|
authUrl: notification.authUrl,
|
|
2980
3122
|
message: notification.message,
|
|
@@ -2982,56 +3124,210 @@ function convertNotificationToStreamMessage(notification) {
|
|
|
2982
3124
|
};
|
|
2983
3125
|
case "mcp_auth_completed" /* MCP_AUTH_COMPLETED */:
|
|
2984
3126
|
return {
|
|
2985
|
-
type:
|
|
3127
|
+
type: DroidMessageType.McpAuthCompleted,
|
|
2986
3128
|
serverName: notification.serverName,
|
|
2987
3129
|
outcome: notification.outcome,
|
|
2988
3130
|
message: notification.message
|
|
2989
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
|
+
};
|
|
2990
3164
|
default:
|
|
2991
|
-
console.warn(
|
|
2992
|
-
`[droid-sdk] Unknown notification type: ${String(notification.type)}`
|
|
2993
|
-
);
|
|
2994
3165
|
return null;
|
|
2995
3166
|
}
|
|
2996
3167
|
}
|
|
2997
3168
|
var StreamStateTracker = class {
|
|
2998
|
-
|
|
3169
|
+
constructor(options = {}) {
|
|
3170
|
+
this.options = options;
|
|
3171
|
+
}
|
|
2999
3172
|
hasBeenNonIdle = false;
|
|
3000
|
-
/** Last-seen token usage update (to attach to TurnComplete). */
|
|
3001
3173
|
lastTokenUsage = null;
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3174
|
+
fullText = "";
|
|
3175
|
+
finalAssistantText = "";
|
|
3176
|
+
structuredOutput = null;
|
|
3177
|
+
structuredOutputError = null;
|
|
3178
|
+
errors = [];
|
|
3179
|
+
numTurns = 0;
|
|
3180
|
+
emittedMessages = [];
|
|
3181
|
+
toolNameMap = /* @__PURE__ */ new Map();
|
|
3182
|
+
getToolName(toolUseId) {
|
|
3183
|
+
return this.toolNameMap.get(toolUseId) ?? "";
|
|
3184
|
+
}
|
|
3009
3185
|
processMessage(message) {
|
|
3010
3186
|
const additional = [];
|
|
3011
|
-
if (message.type === "
|
|
3187
|
+
if (message.type === "tool_use") {
|
|
3188
|
+
this.toolNameMap.set(message.toolUseId, message.toolName);
|
|
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
|
+
}
|
|
3196
|
+
if (message.type === DroidMessageType.ToolResult) {
|
|
3197
|
+
message = { ...message, toolName: this.getToolName(message.toolUseId) };
|
|
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
|
+
}
|
|
3208
|
+
if (message.type === DroidMessageType.TokenUsageUpdate) {
|
|
3012
3209
|
this.lastTokenUsage = message;
|
|
3013
3210
|
}
|
|
3014
|
-
if (message.type ===
|
|
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
|
+
}
|
|
3219
|
+
if (message.type === DroidMessageType.WorkingStateChanged) {
|
|
3015
3220
|
if (message.state !== "idle" /* Idle */) {
|
|
3016
3221
|
this.hasBeenNonIdle = true;
|
|
3017
3222
|
} else if (this.hasBeenNonIdle) {
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
tokenUsage: this.lastTokenUsage
|
|
3021
|
-
});
|
|
3223
|
+
this.numTurns++;
|
|
3224
|
+
additional.push(this.createResultMessage());
|
|
3022
3225
|
this.hasBeenNonIdle = false;
|
|
3226
|
+
this.resetTurnState();
|
|
3023
3227
|
}
|
|
3024
3228
|
}
|
|
3025
|
-
|
|
3229
|
+
if (message.type !== DroidMessageType.WorkingStateChanged) {
|
|
3230
|
+
this.trackEmittedMessage(message);
|
|
3231
|
+
}
|
|
3232
|
+
return { message, additional };
|
|
3026
3233
|
}
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
this.
|
|
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() {
|
|
3032
3291
|
this.lastTokenUsage = null;
|
|
3292
|
+
this.fullText = "";
|
|
3293
|
+
this.finalAssistantText = "";
|
|
3294
|
+
this.structuredOutput = null;
|
|
3295
|
+
this.structuredOutputError = null;
|
|
3296
|
+
this.errors = [];
|
|
3297
|
+
this.emittedMessages = [];
|
|
3033
3298
|
}
|
|
3034
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
|
+
}
|
|
3035
3331
|
function normalizeToolResultContent(content) {
|
|
3036
3332
|
if (content == null) {
|
|
3037
3333
|
return "";
|
|
@@ -3044,436 +3340,562 @@ function normalizeToolResultContent(content) {
|
|
|
3044
3340
|
}
|
|
3045
3341
|
return String(content);
|
|
3046
3342
|
}
|
|
3343
|
+
function extractTextFromMessage(message) {
|
|
3344
|
+
return message.content.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
3345
|
+
}
|
|
3047
3346
|
|
|
3048
|
-
// src/
|
|
3049
|
-
function
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
if (!innerNotification) {
|
|
3099
|
-
return;
|
|
3100
|
-
}
|
|
3101
|
-
const converted = convertNotificationToStreamMessage(
|
|
3102
|
-
innerNotification
|
|
3103
|
-
);
|
|
3104
|
-
if (converted === null) {
|
|
3105
|
-
return;
|
|
3106
|
-
}
|
|
3107
|
-
const messages = Array.isArray(converted) ? converted : [converted];
|
|
3108
|
-
for (const msg of messages) {
|
|
3109
|
-
enqueueMessage(msg);
|
|
3110
|
-
const additional = stateTracker.processMessage(msg);
|
|
3111
|
-
for (const extra of additional) {
|
|
3112
|
-
enqueueMessage(extra);
|
|
3113
|
-
if (extra.type === "turn_complete") {
|
|
3114
|
-
signalDone();
|
|
3115
|
-
}
|
|
3347
|
+
// src/helpers.ts
|
|
3348
|
+
function wireAbortSignal(signal, onAbort) {
|
|
3349
|
+
if (!signal) return () => {
|
|
3350
|
+
};
|
|
3351
|
+
if (signal.aborted) {
|
|
3352
|
+
onAbort();
|
|
3353
|
+
return () => {
|
|
3354
|
+
};
|
|
3355
|
+
} else {
|
|
3356
|
+
const listener = () => onAbort();
|
|
3357
|
+
signal.addEventListener("abort", listener, { once: true });
|
|
3358
|
+
return () => signal.removeEventListener("abort", listener);
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
function extractInnerNotification(notification) {
|
|
3362
|
+
const parsed = SessionNotificationSchema.safeParse(notification);
|
|
3363
|
+
return parsed.success ? parsed.data.params.notification : null;
|
|
3364
|
+
}
|
|
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
|
+
}
|
|
3375
|
+
_queue = [];
|
|
3376
|
+
_onDone;
|
|
3377
|
+
_resolveWaiting = null;
|
|
3378
|
+
_done = false;
|
|
3379
|
+
_stateTracker;
|
|
3380
|
+
notificationHandler = (notification) => {
|
|
3381
|
+
const inner = extractInnerNotification(notification);
|
|
3382
|
+
if (!inner) return;
|
|
3383
|
+
const converted = convertNotificationToStreamMessage(inner);
|
|
3384
|
+
if (converted === null) return;
|
|
3385
|
+
const messages = Array.isArray(converted) ? converted : [converted];
|
|
3386
|
+
for (const msg of messages) {
|
|
3387
|
+
const { message, additional } = this._stateTracker.processMessage(msg);
|
|
3388
|
+
if (message && this._shouldYield(message)) {
|
|
3389
|
+
this._enqueue(message);
|
|
3390
|
+
}
|
|
3391
|
+
for (const extra of additional) {
|
|
3392
|
+
if (this._shouldYield(extra)) {
|
|
3393
|
+
this._enqueue(extra);
|
|
3394
|
+
}
|
|
3395
|
+
if (extra.type === DroidMessageType.Result) {
|
|
3396
|
+
this._signalDone();
|
|
3116
3397
|
}
|
|
3117
3398
|
}
|
|
3118
|
-
});
|
|
3119
|
-
const initParams = {
|
|
3120
|
-
machineId: options.machineId ?? "default",
|
|
3121
|
-
cwd: options.cwd ?? "."
|
|
3122
|
-
};
|
|
3123
|
-
if (options.modelId !== void 0) {
|
|
3124
|
-
initParams.modelId = options.modelId;
|
|
3125
3399
|
}
|
|
3126
|
-
|
|
3127
|
-
|
|
3400
|
+
};
|
|
3401
|
+
signalDone() {
|
|
3402
|
+
this._signalDone();
|
|
3403
|
+
}
|
|
3404
|
+
async *messages() {
|
|
3405
|
+
while (true) {
|
|
3406
|
+
while (this._queue.length > 0) {
|
|
3407
|
+
const msg = this._queue.shift();
|
|
3408
|
+
yield msg;
|
|
3409
|
+
if (msg.type === DroidMessageType.Result) {
|
|
3410
|
+
return;
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
if (this._done && this._queue.length === 0) {
|
|
3414
|
+
return;
|
|
3415
|
+
}
|
|
3416
|
+
await new Promise((resolve2) => {
|
|
3417
|
+
this._resolveWaiting = resolve2;
|
|
3418
|
+
});
|
|
3128
3419
|
}
|
|
3129
|
-
|
|
3130
|
-
|
|
3420
|
+
}
|
|
3421
|
+
_shouldYield(message) {
|
|
3422
|
+
if (isInternalMessage(message)) {
|
|
3423
|
+
return false;
|
|
3131
3424
|
}
|
|
3132
|
-
|
|
3133
|
-
|
|
3425
|
+
return this._options.includePartialMessages ? true : isDefaultStreamMessage(message);
|
|
3426
|
+
}
|
|
3427
|
+
_enqueue(msg) {
|
|
3428
|
+
this._queue.push(msg);
|
|
3429
|
+
if (this._resolveWaiting) {
|
|
3430
|
+
const resolve2 = this._resolveWaiting;
|
|
3431
|
+
this._resolveWaiting = null;
|
|
3432
|
+
resolve2();
|
|
3134
3433
|
}
|
|
3135
|
-
|
|
3136
|
-
|
|
3434
|
+
}
|
|
3435
|
+
_signalDone() {
|
|
3436
|
+
const wasDone = this._done;
|
|
3437
|
+
this._done = true;
|
|
3438
|
+
if (!wasDone) {
|
|
3439
|
+
this._onDone?.();
|
|
3137
3440
|
}
|
|
3138
|
-
if (
|
|
3139
|
-
|
|
3441
|
+
if (this._resolveWaiting) {
|
|
3442
|
+
const resolve2 = this._resolveWaiting;
|
|
3443
|
+
this._resolveWaiting = null;
|
|
3444
|
+
resolve2();
|
|
3140
3445
|
}
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3446
|
+
}
|
|
3447
|
+
};
|
|
3448
|
+
async function createTransport(options) {
|
|
3449
|
+
if (options.transport) {
|
|
3450
|
+
return options.transport;
|
|
3451
|
+
}
|
|
3452
|
+
const transportOptions = {
|
|
3453
|
+
execPath: options.execPath,
|
|
3454
|
+
execArgs: options.execArgs,
|
|
3455
|
+
cwd: options.cwd,
|
|
3456
|
+
env: options.env
|
|
3457
|
+
};
|
|
3458
|
+
const processTransport = new ProcessTransport(transportOptions);
|
|
3459
|
+
await processTransport.connect();
|
|
3460
|
+
return processTransport;
|
|
3461
|
+
}
|
|
3462
|
+
function setupClientHandlers(client, options) {
|
|
3463
|
+
if (options.permissionHandler) {
|
|
3464
|
+
client.setPermissionHandler(options.permissionHandler);
|
|
3465
|
+
}
|
|
3466
|
+
if (options.askUserHandler) {
|
|
3467
|
+
client.setAskUserHandler(options.askUserHandler);
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
async function createConfiguredClient(options) {
|
|
3471
|
+
const transport = await createTransport(options);
|
|
3472
|
+
const client = new DroidClient({ transport });
|
|
3473
|
+
setupClientHandlers(client, options);
|
|
3474
|
+
return { transport, client };
|
|
3475
|
+
}
|
|
3476
|
+
async function closeQuietly(resource) {
|
|
3477
|
+
if (!resource) {
|
|
3478
|
+
return;
|
|
3479
|
+
}
|
|
3480
|
+
try {
|
|
3481
|
+
await resource.close();
|
|
3482
|
+
} catch {
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
function buildInitParams(options) {
|
|
3486
|
+
return {
|
|
3487
|
+
machineId: options.machineId ?? "default",
|
|
3488
|
+
cwd: options.cwd ?? ".",
|
|
3489
|
+
...options.modelId !== void 0 && { modelId: options.modelId },
|
|
3490
|
+
...options.autonomyLevel !== void 0 && {
|
|
3491
|
+
autonomyLevel: options.autonomyLevel
|
|
3492
|
+
},
|
|
3493
|
+
...options.interactionMode !== void 0 && {
|
|
3494
|
+
interactionMode: options.interactionMode
|
|
3495
|
+
},
|
|
3496
|
+
...options.reasoningEffort !== void 0 && {
|
|
3497
|
+
reasoningEffort: options.reasoningEffort
|
|
3498
|
+
},
|
|
3499
|
+
...options.specModeModelId !== void 0 && {
|
|
3500
|
+
specModeModelId: options.specModeModelId
|
|
3501
|
+
},
|
|
3502
|
+
...options.specModeReasoningEffort !== void 0 && {
|
|
3503
|
+
specModeReasoningEffort: options.specModeReasoningEffort
|
|
3504
|
+
},
|
|
3505
|
+
...options.mcpServers !== void 0 && {
|
|
3506
|
+
mcpServers: options.mcpServers
|
|
3507
|
+
},
|
|
3508
|
+
...options.enabledToolIds !== void 0 && {
|
|
3509
|
+
enabledToolIds: options.enabledToolIds
|
|
3510
|
+
},
|
|
3511
|
+
...options.disabledToolIds !== void 0 && {
|
|
3512
|
+
disabledToolIds: options.disabledToolIds
|
|
3513
|
+
},
|
|
3514
|
+
tags: [...options.tags ?? [], SDK_TAG]
|
|
3515
|
+
};
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3518
|
+
// src/mcp.ts
|
|
3519
|
+
var import_node_events = require("events");
|
|
3520
|
+
var import_node_http = __toESM(require("http"), 1);
|
|
3521
|
+
var import_mcp4 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
3522
|
+
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
3523
|
+
var import_zod9 = require("zod");
|
|
3524
|
+
function tool(name, description, inputSchemaOrHandler, handler) {
|
|
3525
|
+
if (typeof inputSchemaOrHandler === "function") {
|
|
3526
|
+
const actualHandler = inputSchemaOrHandler;
|
|
3527
|
+
return {
|
|
3528
|
+
name,
|
|
3529
|
+
description,
|
|
3530
|
+
handler: (input) => actualHandler(input)
|
|
3531
|
+
};
|
|
3532
|
+
}
|
|
3533
|
+
if (!handler) {
|
|
3534
|
+
throw new Error(`Missing handler for SDK MCP tool "${name}"`);
|
|
3535
|
+
}
|
|
3536
|
+
const inputObjectSchema = import_zod9.z.object(inputSchemaOrHandler);
|
|
3537
|
+
return {
|
|
3538
|
+
name,
|
|
3539
|
+
description,
|
|
3540
|
+
inputSchema: inputSchemaOrHandler,
|
|
3541
|
+
handler: (input) => handler(inputObjectSchema.parse(input))
|
|
3542
|
+
};
|
|
3543
|
+
}
|
|
3544
|
+
function isSdkMcpServer(server) {
|
|
3545
|
+
return server instanceof SdkMcpServer;
|
|
3546
|
+
}
|
|
3547
|
+
function toCallToolResult(result) {
|
|
3548
|
+
if (typeof result === "string") {
|
|
3549
|
+
return {
|
|
3550
|
+
content: [{ type: "text", text: result }]
|
|
3551
|
+
};
|
|
3552
|
+
}
|
|
3553
|
+
return result;
|
|
3554
|
+
}
|
|
3555
|
+
async function readJsonBody(req) {
|
|
3556
|
+
const chunks = [];
|
|
3557
|
+
for await (const chunk of req) {
|
|
3558
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
3559
|
+
}
|
|
3560
|
+
if (chunks.length === 0) {
|
|
3561
|
+
return void 0;
|
|
3562
|
+
}
|
|
3563
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
3564
|
+
}
|
|
3565
|
+
function writeJsonError(res, statusCode, message) {
|
|
3566
|
+
if (res.headersSent) {
|
|
3567
|
+
return;
|
|
3568
|
+
}
|
|
3569
|
+
res.writeHead(statusCode, { "content-type": "application/json" });
|
|
3570
|
+
res.end(
|
|
3571
|
+
JSON.stringify({
|
|
3572
|
+
jsonrpc: JSONRPC_VERSION,
|
|
3573
|
+
error: { code: -32603 /* INTERNAL_ERROR */, message },
|
|
3574
|
+
id: null
|
|
3575
|
+
})
|
|
3576
|
+
);
|
|
3577
|
+
}
|
|
3578
|
+
var SdkMcpServer = class {
|
|
3579
|
+
name;
|
|
3580
|
+
version;
|
|
3581
|
+
tools;
|
|
3582
|
+
_httpServer = null;
|
|
3583
|
+
_url = null;
|
|
3584
|
+
constructor(options) {
|
|
3585
|
+
this.name = options.name;
|
|
3586
|
+
this.version = options.version ?? "1.0.0";
|
|
3587
|
+
this.tools = options.tools;
|
|
3588
|
+
}
|
|
3589
|
+
get config() {
|
|
3590
|
+
if (!this._url) {
|
|
3591
|
+
return null;
|
|
3592
|
+
}
|
|
3593
|
+
return {
|
|
3594
|
+
type: "http" /* Http */,
|
|
3595
|
+
name: this.name,
|
|
3596
|
+
url: this._url,
|
|
3597
|
+
headers: []
|
|
3598
|
+
};
|
|
3599
|
+
}
|
|
3600
|
+
async start() {
|
|
3601
|
+
if (this.config) {
|
|
3602
|
+
return this.config;
|
|
3603
|
+
}
|
|
3604
|
+
this._httpServer = import_node_http.default.createServer((req, res) => {
|
|
3605
|
+
void this.handleRequest(req, res);
|
|
3606
|
+
});
|
|
3607
|
+
this._httpServer.listen(0, "127.0.0.1");
|
|
3608
|
+
await (0, import_node_events.once)(this._httpServer, "listening");
|
|
3609
|
+
const address = this._httpServer.address();
|
|
3610
|
+
if (!address || typeof address === "string") {
|
|
3611
|
+
throw new Error("Unable to determine SDK MCP server address");
|
|
3612
|
+
}
|
|
3613
|
+
this._url = `http://127.0.0.1:${address.port}/mcp`;
|
|
3614
|
+
const config = this.config;
|
|
3615
|
+
if (!config) {
|
|
3616
|
+
throw new Error("Unable to start SDK MCP server");
|
|
3617
|
+
}
|
|
3618
|
+
return config;
|
|
3619
|
+
}
|
|
3620
|
+
async close() {
|
|
3621
|
+
const server = this._httpServer;
|
|
3622
|
+
this._httpServer = null;
|
|
3623
|
+
this._url = null;
|
|
3624
|
+
if (!server) {
|
|
3625
|
+
return;
|
|
3626
|
+
}
|
|
3627
|
+
server.closeAllConnections?.();
|
|
3628
|
+
server.close();
|
|
3629
|
+
await (0, import_node_events.once)(server, "close");
|
|
3630
|
+
}
|
|
3631
|
+
createMcpServer() {
|
|
3632
|
+
const server = new import_mcp4.McpServer({
|
|
3633
|
+
name: this.name,
|
|
3634
|
+
version: this.version
|
|
3635
|
+
});
|
|
3636
|
+
for (const sdkTool of this.tools) {
|
|
3637
|
+
server.registerTool(
|
|
3638
|
+
sdkTool.name,
|
|
3639
|
+
{
|
|
3640
|
+
description: sdkTool.description,
|
|
3641
|
+
...sdkTool.inputSchema && {
|
|
3642
|
+
inputSchema: sdkTool.inputSchema
|
|
3156
3643
|
}
|
|
3157
|
-
}
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
}
|
|
3161
|
-
await new Promise((resolve) => {
|
|
3162
|
-
resolveWaiting = resolve;
|
|
3163
|
-
});
|
|
3164
|
-
}
|
|
3165
|
-
} finally {
|
|
3644
|
+
},
|
|
3645
|
+
async (input) => toCallToolResult(await sdkTool.handler(input))
|
|
3646
|
+
);
|
|
3166
3647
|
}
|
|
3648
|
+
return server;
|
|
3167
3649
|
}
|
|
3168
|
-
|
|
3169
|
-
|
|
3650
|
+
async handleRequest(req, res) {
|
|
3651
|
+
if (req.url !== "/mcp") {
|
|
3652
|
+
res.writeHead(404).end();
|
|
3653
|
+
return;
|
|
3654
|
+
}
|
|
3655
|
+
if (req.method !== "POST") {
|
|
3656
|
+
res.writeHead(405).end();
|
|
3657
|
+
return;
|
|
3658
|
+
}
|
|
3659
|
+
const server = this.createMcpServer();
|
|
3660
|
+
const transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
3661
|
+
sessionIdGenerator: void 0
|
|
3662
|
+
});
|
|
3663
|
+
res.on("close", () => {
|
|
3664
|
+
void transport.close();
|
|
3665
|
+
void server.close();
|
|
3666
|
+
});
|
|
3170
3667
|
try {
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3668
|
+
const body = await readJsonBody(req);
|
|
3669
|
+
await server.connect(transport);
|
|
3670
|
+
await transport.handleRequest(req, res, body);
|
|
3671
|
+
} catch (error) {
|
|
3672
|
+
writeJsonError(
|
|
3673
|
+
res,
|
|
3674
|
+
500,
|
|
3675
|
+
error instanceof Error ? error.message : "Internal server error"
|
|
3676
|
+
);
|
|
3677
|
+
await transport.close();
|
|
3678
|
+
await server.close();
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
};
|
|
3682
|
+
function createSdkMcpServer(options) {
|
|
3683
|
+
return new SdkMcpServer(options);
|
|
3684
|
+
}
|
|
3685
|
+
async function startSdkMcpServers(servers) {
|
|
3686
|
+
if (!servers) {
|
|
3687
|
+
return { cleanup: async () => {
|
|
3688
|
+
} };
|
|
3689
|
+
}
|
|
3690
|
+
const startedServers = [];
|
|
3691
|
+
const mcpServers = [];
|
|
3692
|
+
try {
|
|
3693
|
+
for (const server of servers) {
|
|
3694
|
+
if (isSdkMcpServer(server)) {
|
|
3695
|
+
mcpServers.push(await server.start());
|
|
3696
|
+
startedServers.push(server);
|
|
3697
|
+
} else {
|
|
3698
|
+
mcpServers.push(server);
|
|
3184
3699
|
}
|
|
3185
|
-
transport = null;
|
|
3186
3700
|
}
|
|
3701
|
+
} catch (error) {
|
|
3702
|
+
await Promise.all(startedServers.map((server) => server.close()));
|
|
3703
|
+
throw error;
|
|
3187
3704
|
}
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
value: async function interrupt() {
|
|
3193
|
-
if (client && !aborted) {
|
|
3194
|
-
await client.interruptSession();
|
|
3195
|
-
}
|
|
3196
|
-
},
|
|
3197
|
-
writable: false,
|
|
3198
|
-
enumerable: true
|
|
3199
|
-
},
|
|
3200
|
-
abort: {
|
|
3201
|
-
value: function abort() {
|
|
3202
|
-
aborted = true;
|
|
3203
|
-
signalDone();
|
|
3204
|
-
if (client) {
|
|
3205
|
-
void client.close().catch(() => {
|
|
3206
|
-
});
|
|
3207
|
-
client = null;
|
|
3208
|
-
} else if (transport) {
|
|
3209
|
-
void transport.close().catch(() => {
|
|
3210
|
-
});
|
|
3211
|
-
}
|
|
3212
|
-
transport = null;
|
|
3213
|
-
},
|
|
3214
|
-
writable: false,
|
|
3215
|
-
enumerable: true
|
|
3216
|
-
},
|
|
3217
|
-
sessionId: {
|
|
3218
|
-
get() {
|
|
3219
|
-
return sessionId;
|
|
3220
|
-
},
|
|
3221
|
-
enumerable: true
|
|
3705
|
+
return {
|
|
3706
|
+
mcpServers,
|
|
3707
|
+
cleanup: async () => {
|
|
3708
|
+
await Promise.all(startedServers.map((server) => server.close()));
|
|
3222
3709
|
}
|
|
3223
|
-
}
|
|
3224
|
-
return droidQuery;
|
|
3710
|
+
};
|
|
3225
3711
|
}
|
|
3226
3712
|
|
|
3227
3713
|
// src/session.ts
|
|
3714
|
+
function getAbortError(signal) {
|
|
3715
|
+
if (signal.reason instanceof Error) {
|
|
3716
|
+
return signal.reason;
|
|
3717
|
+
}
|
|
3718
|
+
return new Error(
|
|
3719
|
+
typeof signal.reason === "string" ? signal.reason : "Operation aborted"
|
|
3720
|
+
);
|
|
3721
|
+
}
|
|
3722
|
+
function throwIfAborted(signal) {
|
|
3723
|
+
if (signal?.aborted) {
|
|
3724
|
+
throw getAbortError(signal);
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3228
3727
|
var DroidSession = class {
|
|
3229
3728
|
_client;
|
|
3230
3729
|
_sessionId;
|
|
3231
3730
|
_initResult;
|
|
3232
3731
|
_closed = false;
|
|
3732
|
+
_cleanupAbortSignal = null;
|
|
3733
|
+
_cleanupCallbacks = [];
|
|
3734
|
+
_activeBridges = /* @__PURE__ */ new Set();
|
|
3233
3735
|
/** @internal */
|
|
3234
3736
|
constructor(client, sessionId, initResult) {
|
|
3235
3737
|
this._client = client;
|
|
3236
3738
|
this._sessionId = sessionId;
|
|
3237
3739
|
this._initResult = initResult;
|
|
3238
3740
|
}
|
|
3239
|
-
// ------------------------------------------------------------------
|
|
3240
|
-
// Properties
|
|
3241
|
-
// ------------------------------------------------------------------
|
|
3242
|
-
/** The session ID. */
|
|
3243
3741
|
get sessionId() {
|
|
3244
3742
|
return this._sessionId;
|
|
3245
3743
|
}
|
|
3246
|
-
/** The result from session initialization or loading. */
|
|
3247
3744
|
get initResult() {
|
|
3248
3745
|
return this._initResult;
|
|
3249
3746
|
}
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
* @param text - The user message text.
|
|
3260
|
-
* @param options - Optional images/files to include.
|
|
3261
|
-
* @returns An async generator yielding DroidMessage events.
|
|
3262
|
-
*/
|
|
3263
|
-
async *stream(text, options) {
|
|
3747
|
+
/** @internal */
|
|
3748
|
+
setAbortSignalCleanup(cleanup) {
|
|
3749
|
+
this._cleanupAbortSignal = cleanup;
|
|
3750
|
+
}
|
|
3751
|
+
/** @internal */
|
|
3752
|
+
addCleanup(cleanup) {
|
|
3753
|
+
this._cleanupCallbacks.push(cleanup);
|
|
3754
|
+
}
|
|
3755
|
+
async *stream(prompt, options) {
|
|
3264
3756
|
this._ensureNotClosed();
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
let
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
const resolve = resolveWaiting;
|
|
3272
|
-
resolveWaiting = null;
|
|
3273
|
-
resolve();
|
|
3274
|
-
}
|
|
3275
|
-
}
|
|
3276
|
-
function signalDone() {
|
|
3277
|
-
streamDone = true;
|
|
3278
|
-
if (resolveWaiting) {
|
|
3279
|
-
const resolve = resolveWaiting;
|
|
3280
|
-
resolveWaiting = null;
|
|
3281
|
-
resolve();
|
|
3282
|
-
}
|
|
3283
|
-
}
|
|
3284
|
-
const stateTracker = new StreamStateTracker();
|
|
3285
|
-
const unsubscribe = this._client.onNotification((notification) => {
|
|
3286
|
-
const params = notification["params"];
|
|
3287
|
-
const innerNotification = params?.["notification"];
|
|
3288
|
-
if (!innerNotification) {
|
|
3289
|
-
return;
|
|
3290
|
-
}
|
|
3291
|
-
const converted = convertNotificationToStreamMessage(
|
|
3292
|
-
innerNotification
|
|
3293
|
-
);
|
|
3294
|
-
if (converted === null) {
|
|
3295
|
-
return;
|
|
3296
|
-
}
|
|
3297
|
-
const messages = Array.isArray(converted) ? converted : [converted];
|
|
3298
|
-
for (const msg of messages) {
|
|
3299
|
-
enqueueMessage(msg);
|
|
3300
|
-
const additional = stateTracker.processMessage(msg);
|
|
3301
|
-
for (const extra of additional) {
|
|
3302
|
-
enqueueMessage(extra);
|
|
3303
|
-
if (extra.type === "turn_complete") {
|
|
3304
|
-
signalDone();
|
|
3305
|
-
}
|
|
3306
|
-
}
|
|
3307
|
-
}
|
|
3757
|
+
throwIfAborted(options?.abortSignal);
|
|
3758
|
+
const startedAt = Date.now();
|
|
3759
|
+
let resolveDone = () => {
|
|
3760
|
+
};
|
|
3761
|
+
const donePromise = new Promise((resolve2) => {
|
|
3762
|
+
resolveDone = resolve2;
|
|
3308
3763
|
});
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
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);
|
|
3771
|
+
const unsubscribe = this._client.onNotification(bridge.notificationHandler);
|
|
3772
|
+
let resolveAbort = () => {
|
|
3773
|
+
};
|
|
3774
|
+
const abortPromise = new Promise((resolve2) => {
|
|
3775
|
+
resolveAbort = resolve2;
|
|
3776
|
+
});
|
|
3777
|
+
const cleanupAbortSignal = wireAbortSignal(options?.abortSignal, () => {
|
|
3778
|
+
bridge.signalDone();
|
|
3779
|
+
resolveAbort();
|
|
3780
|
+
void this._client.interruptSession().catch(() => {
|
|
3314
3781
|
});
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3782
|
+
});
|
|
3783
|
+
try {
|
|
3784
|
+
await Promise.race([
|
|
3785
|
+
this._client.addUserMessage({
|
|
3786
|
+
text: prompt,
|
|
3787
|
+
images: options?.images,
|
|
3788
|
+
files: options?.files,
|
|
3789
|
+
outputFormat: options?.outputFormat
|
|
3790
|
+
}),
|
|
3791
|
+
donePromise,
|
|
3792
|
+
abortPromise
|
|
3793
|
+
]);
|
|
3794
|
+
throwIfAborted(options?.abortSignal);
|
|
3795
|
+
for await (const msg of bridge.messages()) {
|
|
3796
|
+
throwIfAborted(options?.abortSignal);
|
|
3797
|
+
yield msg;
|
|
3329
3798
|
}
|
|
3799
|
+
throwIfAborted(options?.abortSignal);
|
|
3330
3800
|
} finally {
|
|
3801
|
+
cleanupAbortSignal();
|
|
3331
3802
|
unsubscribe();
|
|
3803
|
+
this._activeBridges.delete(bridge);
|
|
3332
3804
|
}
|
|
3333
3805
|
}
|
|
3334
|
-
/**
|
|
3335
|
-
* Send a message and collect the complete response (non-streaming).
|
|
3336
|
-
*
|
|
3337
|
-
* Internally consumes all stream messages and returns an aggregated
|
|
3338
|
-
* {@link DroidResult} with the concatenated text, all messages, and
|
|
3339
|
-
* final token usage.
|
|
3340
|
-
*
|
|
3341
|
-
* @param text - The user message text.
|
|
3342
|
-
* @param options - Optional images/files to include.
|
|
3343
|
-
* @returns Aggregated result with text, messages, and token usage.
|
|
3344
|
-
*/
|
|
3345
|
-
async send(text, options) {
|
|
3346
|
-
this._ensureNotClosed();
|
|
3347
|
-
const messages = [];
|
|
3348
|
-
let fullText = "";
|
|
3349
|
-
let lastTokenUsage = null;
|
|
3350
|
-
for await (const msg of this.stream(text, options)) {
|
|
3351
|
-
messages.push(msg);
|
|
3352
|
-
if (msg.type === "assistant_text_delta") {
|
|
3353
|
-
fullText += msg.text;
|
|
3354
|
-
}
|
|
3355
|
-
if (msg.type === "token_usage_update") {
|
|
3356
|
-
lastTokenUsage = msg;
|
|
3357
|
-
}
|
|
3358
|
-
if (msg.type === "turn_complete" && msg.tokenUsage) {
|
|
3359
|
-
lastTokenUsage = msg.tokenUsage;
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
return {
|
|
3363
|
-
text: fullText,
|
|
3364
|
-
messages,
|
|
3365
|
-
tokenUsage: lastTokenUsage
|
|
3366
|
-
};
|
|
3367
|
-
}
|
|
3368
|
-
// ------------------------------------------------------------------
|
|
3369
|
-
// Session control
|
|
3370
|
-
// ------------------------------------------------------------------
|
|
3371
|
-
/**
|
|
3372
|
-
* Interrupt the current agent turn.
|
|
3373
|
-
*
|
|
3374
|
-
* Sends an interrupt request. The agent will stop after completing
|
|
3375
|
-
* its current operation.
|
|
3376
|
-
*/
|
|
3377
3806
|
async interrupt() {
|
|
3378
3807
|
this._ensureNotClosed();
|
|
3379
3808
|
await this._client.interruptSession();
|
|
3380
3809
|
}
|
|
3381
|
-
/**
|
|
3382
|
-
* Close the session and release all resources.
|
|
3383
|
-
*
|
|
3384
|
-
* Closes the underlying transport and rejects any pending requests.
|
|
3385
|
-
* After close, the session cannot be used.
|
|
3386
|
-
*/
|
|
3387
3810
|
async close() {
|
|
3388
3811
|
if (this._closed) {
|
|
3389
3812
|
return;
|
|
3390
3813
|
}
|
|
3391
3814
|
this._closed = true;
|
|
3392
|
-
|
|
3815
|
+
this._cleanupAbortSignal?.();
|
|
3816
|
+
this._cleanupAbortSignal = null;
|
|
3817
|
+
for (const bridge of this._activeBridges) {
|
|
3818
|
+
bridge.signalDone();
|
|
3819
|
+
}
|
|
3820
|
+
try {
|
|
3821
|
+
await this._client.closeSession({ reason: "other" }).catch(() => {
|
|
3822
|
+
});
|
|
3823
|
+
await this._client.close();
|
|
3824
|
+
} finally {
|
|
3825
|
+
const cleanups = this._cleanupCallbacks.splice(0);
|
|
3826
|
+
await Promise.all(cleanups.map((cleanup) => cleanup()));
|
|
3827
|
+
}
|
|
3393
3828
|
}
|
|
3394
|
-
// ------------------------------------------------------------------
|
|
3395
|
-
// Settings
|
|
3396
|
-
// ------------------------------------------------------------------
|
|
3397
|
-
/**
|
|
3398
|
-
* Update session settings (model, reasoning effort, autonomy, etc.).
|
|
3399
|
-
*
|
|
3400
|
-
* @param params - Partial settings to update.
|
|
3401
|
-
*/
|
|
3402
3829
|
async updateSettings(params) {
|
|
3403
3830
|
this._ensureNotClosed();
|
|
3404
3831
|
return this._client.updateSessionSettings(params);
|
|
3405
3832
|
}
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3833
|
+
async enterSpecMode(params = {}) {
|
|
3834
|
+
this._ensureNotClosed();
|
|
3835
|
+
return this._client.updateSessionSettings({
|
|
3836
|
+
interactionMode: "spec" /* Spec */,
|
|
3837
|
+
...params
|
|
3838
|
+
});
|
|
3839
|
+
}
|
|
3412
3840
|
async addMcpServer(params) {
|
|
3413
3841
|
this._ensureNotClosed();
|
|
3414
3842
|
return this._client.addMcpServer(params);
|
|
3415
3843
|
}
|
|
3416
|
-
/**
|
|
3417
|
-
* Remove an MCP server from the session.
|
|
3418
|
-
*/
|
|
3419
3844
|
async removeMcpServer(params) {
|
|
3420
3845
|
this._ensureNotClosed();
|
|
3421
3846
|
return this._client.removeMcpServer(params);
|
|
3422
3847
|
}
|
|
3423
|
-
/**
|
|
3424
|
-
* Toggle an MCP server on or off.
|
|
3425
|
-
*/
|
|
3426
3848
|
async toggleMcpServer(params) {
|
|
3427
3849
|
this._ensureNotClosed();
|
|
3428
3850
|
return this._client.toggleMcpServer(params);
|
|
3429
3851
|
}
|
|
3430
|
-
/**
|
|
3431
|
-
* List MCP servers and their status.
|
|
3432
|
-
*/
|
|
3433
3852
|
async listMcpServers() {
|
|
3434
3853
|
this._ensureNotClosed();
|
|
3435
3854
|
return this._client.listMcpServers();
|
|
3436
3855
|
}
|
|
3437
|
-
/**
|
|
3438
|
-
* List available MCP tools.
|
|
3439
|
-
*/
|
|
3440
3856
|
async listMcpTools() {
|
|
3441
3857
|
this._ensureNotClosed();
|
|
3442
3858
|
return this._client.listMcpTools();
|
|
3443
3859
|
}
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3860
|
+
async listTools(params = {}) {
|
|
3861
|
+
this._ensureNotClosed();
|
|
3862
|
+
return this._client.listTools(params);
|
|
3863
|
+
}
|
|
3447
3864
|
async authenticateMcpServer(params) {
|
|
3448
3865
|
this._ensureNotClosed();
|
|
3449
3866
|
return this._client.authenticateMcpServer(params);
|
|
3450
3867
|
}
|
|
3451
|
-
// ------------------------------------------------------------------
|
|
3452
|
-
// Skills
|
|
3453
|
-
// ------------------------------------------------------------------
|
|
3454
|
-
/**
|
|
3455
|
-
* List available skills.
|
|
3456
|
-
*/
|
|
3457
3868
|
async listSkills() {
|
|
3458
3869
|
this._ensureNotClosed();
|
|
3459
3870
|
return this._client.listSkills();
|
|
3460
3871
|
}
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3872
|
+
async getRewindInfo(params) {
|
|
3873
|
+
this._ensureNotClosed();
|
|
3874
|
+
return this._client.getRewindInfo(params);
|
|
3875
|
+
}
|
|
3876
|
+
async executeRewind(params) {
|
|
3877
|
+
this._ensureNotClosed();
|
|
3878
|
+
return this._client.executeRewind(params);
|
|
3879
|
+
}
|
|
3880
|
+
async compactSession(params) {
|
|
3881
|
+
this._ensureNotClosed();
|
|
3882
|
+
return this._client.compactSession(params ?? {});
|
|
3883
|
+
}
|
|
3884
|
+
async forkSession() {
|
|
3885
|
+
this._ensureNotClosed();
|
|
3886
|
+
return this._client.forkSession();
|
|
3887
|
+
}
|
|
3888
|
+
async getContextStats() {
|
|
3889
|
+
this._ensureNotClosed();
|
|
3890
|
+
return this._client.getContextStats();
|
|
3891
|
+
}
|
|
3892
|
+
async renameSession(params) {
|
|
3893
|
+
this._ensureNotClosed();
|
|
3894
|
+
return this._client.renameSession(params);
|
|
3895
|
+
}
|
|
3471
3896
|
onNotification(callback, filter) {
|
|
3472
3897
|
return this._client.onNotification(callback, filter);
|
|
3473
3898
|
}
|
|
3474
|
-
// ------------------------------------------------------------------
|
|
3475
|
-
// Internal
|
|
3476
|
-
// ------------------------------------------------------------------
|
|
3477
3899
|
_ensureNotClosed() {
|
|
3478
3900
|
if (this._closed) {
|
|
3479
3901
|
throw new ConnectionError(
|
|
@@ -3483,98 +3905,298 @@ var DroidSession = class {
|
|
|
3483
3905
|
}
|
|
3484
3906
|
};
|
|
3485
3907
|
async function createSession(options = {}) {
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3908
|
+
const { client } = await createConfiguredClient(options);
|
|
3909
|
+
let cleanupInitAbortSignal = options.abortSignal?.aborted ? () => {
|
|
3910
|
+
} : wireAbortSignal(options.abortSignal, () => {
|
|
3911
|
+
void closeQuietly(client);
|
|
3912
|
+
});
|
|
3913
|
+
let sdkMcpServers;
|
|
3914
|
+
try {
|
|
3915
|
+
sdkMcpServers = await startSdkMcpServers(options.mcpServers);
|
|
3916
|
+
const initParams = buildInitParams({
|
|
3917
|
+
...options,
|
|
3918
|
+
mcpServers: sdkMcpServers.mcpServers
|
|
3919
|
+
});
|
|
3920
|
+
const initResult = await client.initializeSession(initParams);
|
|
3921
|
+
const session = new DroidSession(client, initResult.sessionId, initResult);
|
|
3922
|
+
session.addCleanup(sdkMcpServers.cleanup);
|
|
3923
|
+
cleanupInitAbortSignal();
|
|
3924
|
+
cleanupInitAbortSignal = () => {
|
|
3495
3925
|
};
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
client.setAskUserHandler(options.askUserHandler);
|
|
3926
|
+
session.setAbortSignalCleanup(
|
|
3927
|
+
wireAbortSignal(options.abortSignal, () => void session.close())
|
|
3928
|
+
);
|
|
3929
|
+
return session;
|
|
3930
|
+
} catch (error) {
|
|
3931
|
+
cleanupInitAbortSignal();
|
|
3932
|
+
await sdkMcpServers?.cleanup();
|
|
3933
|
+
await closeQuietly(client);
|
|
3934
|
+
throw error;
|
|
3506
3935
|
}
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3936
|
+
}
|
|
3937
|
+
async function resumeSession(sessionId, options = {}) {
|
|
3938
|
+
const { client } = await createConfiguredClient(options);
|
|
3939
|
+
let sdkMcpServers;
|
|
3940
|
+
try {
|
|
3941
|
+
sdkMcpServers = await startSdkMcpServers(options.mcpServers);
|
|
3942
|
+
const loadParams = {
|
|
3943
|
+
sessionId,
|
|
3944
|
+
mcpServers: sdkMcpServers.mcpServers
|
|
3945
|
+
};
|
|
3946
|
+
const loadResult = await client.loadSession(loadParams);
|
|
3947
|
+
const session = new DroidSession(client, sessionId, loadResult);
|
|
3948
|
+
session.addCleanup(sdkMcpServers.cleanup);
|
|
3949
|
+
session.setAbortSignalCleanup(
|
|
3950
|
+
wireAbortSignal(options.abortSignal, () => void session.close())
|
|
3951
|
+
);
|
|
3952
|
+
return session;
|
|
3953
|
+
} catch (error) {
|
|
3954
|
+
await sdkMcpServers?.cleanup();
|
|
3955
|
+
await closeQuietly(client);
|
|
3956
|
+
throw error;
|
|
3513
3957
|
}
|
|
3514
|
-
|
|
3515
|
-
|
|
3958
|
+
}
|
|
3959
|
+
|
|
3960
|
+
// src/run.ts
|
|
3961
|
+
async function run(prompt, options = {}) {
|
|
3962
|
+
const session = await createSession(options);
|
|
3963
|
+
try {
|
|
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");
|
|
3973
|
+
} finally {
|
|
3974
|
+
await session.close();
|
|
3516
3975
|
}
|
|
3517
|
-
|
|
3518
|
-
|
|
3976
|
+
}
|
|
3977
|
+
|
|
3978
|
+
// src/session-discovery.ts
|
|
3979
|
+
var fs = __toESM(require("fs"), 1);
|
|
3980
|
+
var os = __toESM(require("os"), 1);
|
|
3981
|
+
var path = __toESM(require("path"), 1);
|
|
3982
|
+
var FAVORITES_FILE = ".favorites";
|
|
3983
|
+
var SESSION_EXTENSION = ".jsonl";
|
|
3984
|
+
var SETTINGS_SUFFIX = ".settings.json";
|
|
3985
|
+
var MISSION_TAG_PREFIX = "mission:";
|
|
3986
|
+
var MISSION_ID_METADATA_KEY = "missionId";
|
|
3987
|
+
var DECOMP_SESSION_TYPE_TAG = "decompSessionType";
|
|
3988
|
+
var DECOMP_SESSION_TYPE_METADATA_KEY = "value";
|
|
3989
|
+
var LF = 10;
|
|
3990
|
+
var CR = 13;
|
|
3991
|
+
var SPACE = 32;
|
|
3992
|
+
var TAB = 9;
|
|
3993
|
+
var PARSE_OVERSAMPLE = 20;
|
|
3994
|
+
function readFileBuffer(filePath) {
|
|
3995
|
+
try {
|
|
3996
|
+
return fs.readFileSync(filePath);
|
|
3997
|
+
} catch {
|
|
3998
|
+
return null;
|
|
3519
3999
|
}
|
|
3520
|
-
|
|
3521
|
-
|
|
4000
|
+
}
|
|
4001
|
+
function parseJsonBuffer(buf) {
|
|
4002
|
+
try {
|
|
4003
|
+
return JSON.parse(buf.toString("utf-8"));
|
|
4004
|
+
} catch {
|
|
4005
|
+
return null;
|
|
3522
4006
|
}
|
|
3523
|
-
|
|
3524
|
-
|
|
4007
|
+
}
|
|
4008
|
+
function scanBufferForLines(buf) {
|
|
4009
|
+
let nonEmptyLineCount = 0;
|
|
4010
|
+
let firstLineEnd = -1;
|
|
4011
|
+
let currentLineHasContent = false;
|
|
4012
|
+
for (let i = 0; i < buf.length; i++) {
|
|
4013
|
+
const ch = buf[i];
|
|
4014
|
+
if (ch === LF) {
|
|
4015
|
+
if (currentLineHasContent) nonEmptyLineCount++;
|
|
4016
|
+
if (firstLineEnd === -1) firstLineEnd = i;
|
|
4017
|
+
currentLineHasContent = false;
|
|
4018
|
+
} else if (ch !== CR && ch !== SPACE && ch !== TAB) {
|
|
4019
|
+
currentLineHasContent = true;
|
|
4020
|
+
}
|
|
3525
4021
|
}
|
|
3526
|
-
if (
|
|
3527
|
-
|
|
4022
|
+
if (currentLineHasContent) nonEmptyLineCount++;
|
|
4023
|
+
const end = firstLineEnd === -1 ? buf.length : firstLineEnd > 0 && buf[firstLineEnd - 1] === CR ? firstLineEnd - 1 : firstLineEnd;
|
|
4024
|
+
return {
|
|
4025
|
+
firstLine: buf.subarray(0, end),
|
|
4026
|
+
nonEmptyLineCount
|
|
4027
|
+
};
|
|
4028
|
+
}
|
|
4029
|
+
function loadFavorites(sessionsDir) {
|
|
4030
|
+
const buf = readFileBuffer(path.join(sessionsDir, FAVORITES_FILE));
|
|
4031
|
+
if (!buf) return /* @__PURE__ */ new Set();
|
|
4032
|
+
const parsed = parseJsonBuffer(buf);
|
|
4033
|
+
if (!Array.isArray(parsed)) return /* @__PURE__ */ new Set();
|
|
4034
|
+
return new Set(parsed.filter((id) => typeof id === "string"));
|
|
4035
|
+
}
|
|
4036
|
+
function loadSettingsFile(directory, sessionId) {
|
|
4037
|
+
const buf = readFileBuffer(
|
|
4038
|
+
path.join(directory, `${sessionId}${SETTINGS_SUFFIX}`)
|
|
4039
|
+
);
|
|
4040
|
+
if (!buf) return null;
|
|
4041
|
+
const parsed = parseJsonBuffer(buf);
|
|
4042
|
+
if (parsed === null) return null;
|
|
4043
|
+
const result = SessionSettingsFileSchema.safeParse(parsed);
|
|
4044
|
+
return result.success ? result.data : null;
|
|
4045
|
+
}
|
|
4046
|
+
function getMissionMetadataFromTags(settings) {
|
|
4047
|
+
if (!settings?.tags) return {};
|
|
4048
|
+
const missionTag = settings.tags.find(
|
|
4049
|
+
(tag) => tag.name.startsWith(MISSION_TAG_PREFIX)
|
|
4050
|
+
);
|
|
4051
|
+
const roleTag = settings.tags.find(
|
|
4052
|
+
(tag) => tag.name === DECOMP_SESSION_TYPE_TAG
|
|
4053
|
+
);
|
|
4054
|
+
return {
|
|
4055
|
+
decompMissionId: missionTag?.metadata?.[MISSION_ID_METADATA_KEY],
|
|
4056
|
+
decompSessionType: roleTag?.metadata?.[DECOMP_SESSION_TYPE_METADATA_KEY]
|
|
4057
|
+
};
|
|
4058
|
+
}
|
|
4059
|
+
function parseSessionFile(candidate, ctx) {
|
|
4060
|
+
const buf = readFileBuffer(candidate.sessionPath);
|
|
4061
|
+
if (!buf) return null;
|
|
4062
|
+
const scanned = scanBufferForLines(buf);
|
|
4063
|
+
const firstParsed = parseJsonBuffer(scanned.firstLine);
|
|
4064
|
+
if (firstParsed === null) return null;
|
|
4065
|
+
const firstResult = SessionStartEventSchema.safeParse(firstParsed);
|
|
4066
|
+
if (!firstResult.success) return null;
|
|
4067
|
+
const summary = firstResult.data;
|
|
4068
|
+
if (ctx.requiredCwd !== void 0 && (summary.cwd === void 0 || path.resolve(summary.cwd) !== ctx.requiredCwd)) {
|
|
4069
|
+
return null;
|
|
3528
4070
|
}
|
|
4071
|
+
const settingsName = `${candidate.sessionId}${SETTINGS_SUFFIX}`;
|
|
4072
|
+
const settings = candidate.siblingNames.has(settingsName) ? loadSettingsFile(candidate.directory, candidate.sessionId) : null;
|
|
4073
|
+
if (settings?.archivedAt) return null;
|
|
4074
|
+
const tagMeta = getMissionMetadataFromTags(settings);
|
|
4075
|
+
const decompSessionType = summary.decompSessionType ?? SessionStartEventSchema.shape.decompSessionType.safeParse(
|
|
4076
|
+
tagMeta.decompSessionType
|
|
4077
|
+
).data;
|
|
4078
|
+
const messageCount = Math.max(0, scanned.nonEmptyLineCount - 1);
|
|
4079
|
+
return {
|
|
4080
|
+
id: candidate.sessionId,
|
|
4081
|
+
title: summary.title ?? "",
|
|
4082
|
+
sessionTitle: summary.sessionTitle,
|
|
4083
|
+
owner: summary.owner ?? "",
|
|
4084
|
+
messageCount,
|
|
4085
|
+
modifiedTime: candidate.stats.mtime,
|
|
4086
|
+
createdTime: candidate.stats.birthtime || candidate.stats.ctime,
|
|
4087
|
+
isFavorite: ctx.favorites.has(candidate.sessionId),
|
|
4088
|
+
cwd: summary.cwd,
|
|
4089
|
+
decompSessionType,
|
|
4090
|
+
decompMissionId: tagMeta.decompMissionId ?? summary.decompMissionId
|
|
4091
|
+
};
|
|
4092
|
+
}
|
|
4093
|
+
function readDirEntries(directory) {
|
|
3529
4094
|
try {
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
4095
|
+
return fs.readdirSync(directory, { withFileTypes: true });
|
|
4096
|
+
} catch {
|
|
4097
|
+
return [];
|
|
4098
|
+
}
|
|
4099
|
+
}
|
|
4100
|
+
function collectCandidates(directory, entries) {
|
|
4101
|
+
const siblingNames = new Set(entries.map((e) => e.name));
|
|
4102
|
+
const candidates = [];
|
|
4103
|
+
for (const entry of entries) {
|
|
4104
|
+
if (entry.isDirectory()) continue;
|
|
4105
|
+
if (!entry.name.endsWith(SESSION_EXTENSION)) continue;
|
|
4106
|
+
const sessionPath = path.join(directory, entry.name);
|
|
4107
|
+
let stats;
|
|
3535
4108
|
try {
|
|
3536
|
-
|
|
4109
|
+
stats = fs.statSync(sessionPath);
|
|
3537
4110
|
} catch {
|
|
4111
|
+
continue;
|
|
3538
4112
|
}
|
|
3539
|
-
|
|
4113
|
+
candidates.push({
|
|
4114
|
+
sessionId: entry.name.slice(0, -SESSION_EXTENSION.length),
|
|
4115
|
+
sessionPath,
|
|
4116
|
+
directory,
|
|
4117
|
+
siblingNames,
|
|
4118
|
+
stats
|
|
4119
|
+
});
|
|
3540
4120
|
}
|
|
4121
|
+
return candidates;
|
|
3541
4122
|
}
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
execPath: options.execPath,
|
|
3549
|
-
execArgs: options.execArgs,
|
|
3550
|
-
cwd: options.cwd,
|
|
3551
|
-
env: options.env
|
|
3552
|
-
};
|
|
3553
|
-
const processTransport = new ProcessTransport(transportOptions);
|
|
3554
|
-
await processTransport.connect();
|
|
3555
|
-
transport = processTransport;
|
|
3556
|
-
}
|
|
3557
|
-
const client = new DroidClient({ transport });
|
|
3558
|
-
if (options.permissionHandler) {
|
|
3559
|
-
client.setPermissionHandler(options.permissionHandler);
|
|
4123
|
+
function parseUpTo(candidates, ctx, limit) {
|
|
4124
|
+
const out = [];
|
|
4125
|
+
for (const candidate of candidates) {
|
|
4126
|
+
if (limit !== void 0 && out.length >= limit) break;
|
|
4127
|
+
const metadata = parseSessionFile(candidate, ctx);
|
|
4128
|
+
if (metadata) out.push(metadata);
|
|
3560
4129
|
}
|
|
3561
|
-
|
|
3562
|
-
|
|
4130
|
+
return out;
|
|
4131
|
+
}
|
|
4132
|
+
function sanitizePathToDirectoryName(cwd) {
|
|
4133
|
+
let expandedPath = cwd;
|
|
4134
|
+
if (cwd.startsWith("~/") || cwd === "~") {
|
|
4135
|
+
expandedPath = path.join(os.homedir(), cwd.slice(1));
|
|
3563
4136
|
}
|
|
3564
|
-
const
|
|
3565
|
-
|
|
3566
|
-
mcpServers: options.mcpServers
|
|
3567
|
-
};
|
|
4137
|
+
const absolutePath = path.resolve(expandedPath);
|
|
4138
|
+
let canonicalPath = absolutePath;
|
|
3568
4139
|
try {
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
4140
|
+
canonicalPath = fs.realpathSync(absolutePath);
|
|
4141
|
+
} catch {
|
|
4142
|
+
canonicalPath = absolutePath;
|
|
4143
|
+
}
|
|
4144
|
+
const normalized = canonicalPath.replace(/[\\/]+$/, "");
|
|
4145
|
+
if (process.platform === "win32") {
|
|
4146
|
+
return `-${normalized.replace(/^([A-Z]):/i, "$1").replace(/[\\/]+/g, "-")}`;
|
|
4147
|
+
}
|
|
4148
|
+
return `-${normalized.replace(/^\/+/, "").replace(/\/+/g, "-")}`;
|
|
4149
|
+
}
|
|
4150
|
+
function getDefaultSessionsDir() {
|
|
4151
|
+
return path.join(os.homedir(), ".factory", "sessions");
|
|
4152
|
+
}
|
|
4153
|
+
async function listSessions(options = {}) {
|
|
4154
|
+
const sessionsDir = options.sessionsDir ?? getDefaultSessionsDir();
|
|
4155
|
+
const favorites = loadFavorites(sessionsDir);
|
|
4156
|
+
const rootEntries = readDirEntries(sessionsDir);
|
|
4157
|
+
const legacyCandidates = collectCandidates(sessionsDir, rootEntries);
|
|
4158
|
+
const projectCandidates = [];
|
|
4159
|
+
let requiredCwd;
|
|
4160
|
+
if (options.fetchOutsideCWD) {
|
|
4161
|
+
for (const entry of rootEntries) {
|
|
4162
|
+
if (!entry.isDirectory()) continue;
|
|
4163
|
+
if (!entry.name.startsWith("-")) continue;
|
|
4164
|
+
const dir = path.join(sessionsDir, entry.name);
|
|
4165
|
+
projectCandidates.push(...collectCandidates(dir, readDirEntries(dir)));
|
|
3575
4166
|
}
|
|
3576
|
-
|
|
4167
|
+
} else {
|
|
4168
|
+
const normalizedCwd = path.resolve(options.cwd ?? process.cwd());
|
|
4169
|
+
requiredCwd = normalizedCwd;
|
|
4170
|
+
const projectDir = path.join(
|
|
4171
|
+
sessionsDir,
|
|
4172
|
+
sanitizePathToDirectoryName(normalizedCwd)
|
|
4173
|
+
);
|
|
4174
|
+
projectCandidates.push(
|
|
4175
|
+
...collectCandidates(projectDir, readDirEntries(projectDir))
|
|
4176
|
+
);
|
|
4177
|
+
}
|
|
4178
|
+
const byMtimeDesc = (a, b) => b.stats.mtime.getTime() - a.stats.mtime.getTime();
|
|
4179
|
+
projectCandidates.sort(byMtimeDesc);
|
|
4180
|
+
legacyCandidates.sort(byMtimeDesc);
|
|
4181
|
+
const parseLimit = options.numSessions !== void 0 && options.numSessions >= 0 ? options.numSessions + PARSE_OVERSAMPLE : void 0;
|
|
4182
|
+
const ctx = { favorites };
|
|
4183
|
+
const legacyCtx = requiredCwd !== void 0 ? { favorites, requiredCwd } : ctx;
|
|
4184
|
+
const projectSessions = parseUpTo(projectCandidates, ctx, parseLimit);
|
|
4185
|
+
const legacySessions = parseUpTo(legacyCandidates, legacyCtx, parseLimit);
|
|
4186
|
+
const byId = /* @__PURE__ */ new Map();
|
|
4187
|
+
for (const session of [...projectSessions, ...legacySessions]) {
|
|
4188
|
+
const existing = byId.get(session.id);
|
|
4189
|
+
if (!existing || session.modifiedTime.getTime() > existing.modifiedTime.getTime()) {
|
|
4190
|
+
byId.set(session.id, session);
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
const sorted = Array.from(byId.values()).sort(
|
|
4194
|
+
(a, b) => b.modifiedTime.getTime() - a.modifiedTime.getTime()
|
|
4195
|
+
);
|
|
4196
|
+
if (options.numSessions !== void 0 && options.numSessions >= 0) {
|
|
4197
|
+
return sorted.slice(0, options.numSessions);
|
|
3577
4198
|
}
|
|
4199
|
+
return sorted;
|
|
3578
4200
|
}
|
|
3579
4201
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3580
4202
|
0 && (module.exports = {
|
|
@@ -3594,6 +4216,7 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3594
4216
|
AskUserRequestSchema,
|
|
3595
4217
|
AskUserResponseSchema,
|
|
3596
4218
|
AskUserResultSchema,
|
|
4219
|
+
AssistantTextCompleteNotificationSchema,
|
|
3597
4220
|
AssistantTextDeltaNotificationSchema,
|
|
3598
4221
|
AuthenticateMcpServerRequestParamsSchema,
|
|
3599
4222
|
AuthenticateMcpServerRequestSchema,
|
|
@@ -3607,6 +4230,7 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3607
4230
|
BaseRequestSchema,
|
|
3608
4231
|
BaseResponseFailureSchema,
|
|
3609
4232
|
BaseResponseSuccessSchema,
|
|
4233
|
+
COMPACTION_TIMEOUT,
|
|
3610
4234
|
CancelMcpAuthRequestParamsSchema,
|
|
3611
4235
|
CancelMcpAuthRequestSchema,
|
|
3612
4236
|
CancelMcpAuthResponseSchema,
|
|
@@ -3617,8 +4241,18 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3617
4241
|
ClearMcpAuthResultSchema,
|
|
3618
4242
|
CliRequestOrNotificationSchema,
|
|
3619
4243
|
ClientRequestSchema,
|
|
4244
|
+
CloseSessionRequestParamsSchema,
|
|
4245
|
+
CloseSessionRequestSchema,
|
|
4246
|
+
CloseSessionResponseSchema,
|
|
4247
|
+
CloseSessionResultSchema,
|
|
4248
|
+
CompactSessionRequestParamsSchema,
|
|
4249
|
+
CompactSessionRequestSchema,
|
|
4250
|
+
CompactSessionResponseSchema,
|
|
4251
|
+
CompactSessionResultSchema,
|
|
3620
4252
|
ConnectionError,
|
|
3621
4253
|
ContentBlockSchema,
|
|
4254
|
+
ContextStatsAccuracy,
|
|
4255
|
+
ContextStatsSchema,
|
|
3622
4256
|
CreateMessageNotificationSchema,
|
|
3623
4257
|
CreateToolConfirmationDetailsSchema,
|
|
3624
4258
|
DEFAULT_REQUEST_TIMEOUT,
|
|
@@ -3631,26 +4265,54 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3631
4265
|
DroidClient,
|
|
3632
4266
|
DroidClientMethod,
|
|
3633
4267
|
DroidErrorType,
|
|
4268
|
+
DroidHookEventSchema,
|
|
4269
|
+
DroidHookExecutionResultSchema,
|
|
4270
|
+
DroidHookOutputSchema,
|
|
4271
|
+
DroidHookSpecificOutputSchema,
|
|
3634
4272
|
DroidInteractionMode,
|
|
4273
|
+
DroidMessageType,
|
|
3635
4274
|
DroidServerMethod,
|
|
3636
4275
|
DroidSession,
|
|
3637
4276
|
DroidWorkingState,
|
|
3638
4277
|
DroidWorkingStateChangedNotificationSchema,
|
|
3639
4278
|
EditToolConfirmationDetailsSchema,
|
|
4279
|
+
EmptyResultSchema,
|
|
3640
4280
|
ErrorDetailSchema,
|
|
3641
4281
|
ErrorNotificationSchema,
|
|
4282
|
+
ExecToolInfoSchema,
|
|
4283
|
+
ExecuteRewindRequestParamsSchema,
|
|
4284
|
+
ExecuteRewindRequestSchema,
|
|
4285
|
+
ExecuteRewindResponseSchema,
|
|
4286
|
+
ExecuteRewindResultSchema,
|
|
3642
4287
|
ExecuteToolConfirmationDetailsSchema,
|
|
3643
4288
|
ExitSpecModeConfirmationDetailsSchema,
|
|
3644
4289
|
FACTORY_CLIENT_HEADER,
|
|
3645
4290
|
FACTORY_CLIENT_VERSION,
|
|
3646
4291
|
FACTORY_PROTOCOL_VERSION,
|
|
4292
|
+
FactoryDroidMessageRole,
|
|
3647
4293
|
FactoryDroidMessageSchema,
|
|
3648
4294
|
FeatureStatus,
|
|
3649
4295
|
FeatureSuccessState,
|
|
3650
4296
|
FeatureSuccessStateSchema,
|
|
4297
|
+
ForkSessionRequestParamsSchema,
|
|
4298
|
+
ForkSessionRequestSchema,
|
|
4299
|
+
ForkSessionResponseSchema,
|
|
4300
|
+
ForkSessionResultSchema,
|
|
4301
|
+
GetContextStatsRequestParamsSchema,
|
|
4302
|
+
GetContextStatsRequestSchema,
|
|
4303
|
+
GetContextStatsResponseSchema,
|
|
4304
|
+
GetContextStatsResultSchema,
|
|
4305
|
+
GetRewindInfoRequestParamsSchema,
|
|
4306
|
+
GetRewindInfoRequestSchema,
|
|
4307
|
+
GetRewindInfoResponseSchema,
|
|
4308
|
+
GetRewindInfoResultSchema,
|
|
3651
4309
|
GitRepoInfoSchema,
|
|
3652
4310
|
HandoffItemsDismissedEntrySchema,
|
|
3653
4311
|
HandoffSchema,
|
|
4312
|
+
HookCommandSchema,
|
|
4313
|
+
HookExecutionCompletedNotificationSchema,
|
|
4314
|
+
HookExecutionStartedNotificationSchema,
|
|
4315
|
+
HookResultSchema,
|
|
3654
4316
|
HttpHeaderSchema,
|
|
3655
4317
|
HttpMcpConfigSchema,
|
|
3656
4318
|
ImageBlockSchema,
|
|
@@ -3665,6 +4327,8 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3665
4327
|
InterruptSessionResultSchema,
|
|
3666
4328
|
IssueSeverity,
|
|
3667
4329
|
JSONRPC_VERSION,
|
|
4330
|
+
JsonArraySchema,
|
|
4331
|
+
JsonObjectSchema,
|
|
3668
4332
|
JsonRpcEnvelopeSchema,
|
|
3669
4333
|
JsonRpcErrorCode,
|
|
3670
4334
|
JsonRpcErrorSchema,
|
|
@@ -3675,6 +4339,7 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3675
4339
|
JsonRpcResponseFailureSchema,
|
|
3676
4340
|
JsonRpcResponseSchema,
|
|
3677
4341
|
JsonRpcResponseSuccessSchema,
|
|
4342
|
+
JsonValueSchema,
|
|
3678
4343
|
KillWorkerSessionRequestParamsSchema,
|
|
3679
4344
|
KillWorkerSessionRequestSchema,
|
|
3680
4345
|
KillWorkerSessionResponseSchema,
|
|
@@ -3696,6 +4361,10 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3696
4361
|
ListSkillsRequestSchema,
|
|
3697
4362
|
ListSkillsResponseSchema,
|
|
3698
4363
|
ListSkillsResultSchema,
|
|
4364
|
+
ListToolsRequestParamsSchema,
|
|
4365
|
+
ListToolsRequestSchema,
|
|
4366
|
+
ListToolsResponseSchema,
|
|
4367
|
+
ListToolsResultSchema,
|
|
3699
4368
|
LoadSessionRequestParamsSchema,
|
|
3700
4369
|
LoadSessionRequestSchema,
|
|
3701
4370
|
LoadSessionResponseSchema,
|
|
@@ -3733,6 +4402,8 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3733
4402
|
MissionWorkerCompletedNotificationSchema,
|
|
3734
4403
|
MissionWorkerStartedNotificationSchema,
|
|
3735
4404
|
ModelProvider,
|
|
4405
|
+
OutputFormatSchema,
|
|
4406
|
+
OutputFormatType,
|
|
3736
4407
|
PermissionResolvedNotificationSchema,
|
|
3737
4408
|
ProcessExitError,
|
|
3738
4409
|
ProcessTransport,
|
|
@@ -3741,26 +4412,40 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3741
4412
|
ProposeMissionConfirmationDetailsSchema,
|
|
3742
4413
|
ProtocolEngine,
|
|
3743
4414
|
ProtocolError,
|
|
4415
|
+
REWIND_TIMEOUT,
|
|
3744
4416
|
ReasoningEffort,
|
|
3745
4417
|
RedactedThinkingBlockSchema,
|
|
3746
4418
|
RemoveMcpServerRequestParamsSchema,
|
|
3747
4419
|
RemoveMcpServerRequestSchema,
|
|
3748
4420
|
RemoveMcpServerResponseSchema,
|
|
3749
4421
|
RemoveMcpServerResultSchema,
|
|
4422
|
+
RenameSessionRequestParamsSchema,
|
|
4423
|
+
RenameSessionRequestSchema,
|
|
4424
|
+
RenameSessionResponseSchema,
|
|
4425
|
+
RenameSessionResultSchema,
|
|
3750
4426
|
RequestPermissionRequestParamsSchema,
|
|
3751
4427
|
RequestPermissionRequestSchema,
|
|
3752
4428
|
RequestPermissionResponseSchema,
|
|
3753
4429
|
RequestPermissionResultSchema,
|
|
4430
|
+
RewindEvictedFileSchema,
|
|
4431
|
+
RewindFileCreationSchema,
|
|
4432
|
+
RewindFileSnapshotSchema,
|
|
4433
|
+
SDK_TAG,
|
|
4434
|
+
SDK_VERSION,
|
|
3754
4435
|
SESSION_INIT_TIMEOUT,
|
|
4436
|
+
SdkMcpServer,
|
|
3755
4437
|
SessionError,
|
|
4438
|
+
SessionMetadataSchema,
|
|
3756
4439
|
SessionNotFoundError,
|
|
3757
4440
|
SessionNotificationParamsSchema,
|
|
3758
4441
|
SessionNotificationPayloadSchema,
|
|
3759
4442
|
SessionNotificationSchema,
|
|
3760
4443
|
SessionNotificationSchemaList,
|
|
3761
4444
|
SessionNotificationType,
|
|
4445
|
+
SessionSettingsFileSchema,
|
|
3762
4446
|
SessionSettingsSchema,
|
|
3763
4447
|
SessionSourceSchema,
|
|
4448
|
+
SessionStartEventSchema,
|
|
3764
4449
|
SessionTagSchema,
|
|
3765
4450
|
SessionTitleUpdatedNotificationSchema,
|
|
3766
4451
|
SessionTokenUsageChangedNotificationSchema,
|
|
@@ -3776,6 +4461,8 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3776
4461
|
StartMissionRunConfirmationDetailsSchema,
|
|
3777
4462
|
StdioMcpConfigSchema,
|
|
3778
4463
|
StreamStateTracker,
|
|
4464
|
+
StructuredOutputErrorSchema,
|
|
4465
|
+
StructuredOutputNotificationSchema,
|
|
3779
4466
|
SubmitBugReportRequestParamsSchema,
|
|
3780
4467
|
SubmitBugReportRequestSchema,
|
|
3781
4468
|
SubmitBugReportResponseSchema,
|
|
@@ -3784,11 +4471,13 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3784
4471
|
SubmitMcpAuthCodeRequestSchema,
|
|
3785
4472
|
SubmitMcpAuthCodeResponseSchema,
|
|
3786
4473
|
SubmitMcpAuthCodeResultSchema,
|
|
4474
|
+
SuccessResultSchema,
|
|
3787
4475
|
TestCaseSchema,
|
|
3788
4476
|
TestFileSchema,
|
|
3789
4477
|
TestsSchema,
|
|
3790
4478
|
TextBlockSchema,
|
|
3791
4479
|
ThinkingBlockSchema,
|
|
4480
|
+
ThinkingTextCompleteNotificationSchema,
|
|
3792
4481
|
ThinkingTextDeltaNotificationSchema,
|
|
3793
4482
|
TimeoutError,
|
|
3794
4483
|
ToggleMcpServerRequestParamsSchema,
|
|
@@ -3800,6 +4489,7 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3800
4489
|
ToggleMcpToolResponseSchema,
|
|
3801
4490
|
ToggleMcpToolResultSchema,
|
|
3802
4491
|
TokenUsageSchema,
|
|
4492
|
+
ToolCallNotificationSchema,
|
|
3803
4493
|
ToolConfirmationDetailsSchema,
|
|
3804
4494
|
ToolConfirmationInfoSchema,
|
|
3805
4495
|
ToolConfirmationListItemSchema,
|
|
@@ -3809,6 +4499,7 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3809
4499
|
ToolProgressUpdateSchema,
|
|
3810
4500
|
ToolResultBlockSchema,
|
|
3811
4501
|
ToolResultNotificationSchema,
|
|
4502
|
+
ToolSelectionOverridesSchema,
|
|
3812
4503
|
ToolUseBlockSchema,
|
|
3813
4504
|
ToolUseSchema,
|
|
3814
4505
|
TraceContextMetaSchema,
|
|
@@ -3825,8 +4516,13 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3825
4516
|
WorkerStartedEntrySchema,
|
|
3826
4517
|
WorkerStateInfoSchema,
|
|
3827
4518
|
convertNotificationToStreamMessage,
|
|
4519
|
+
createResponseSchema,
|
|
4520
|
+
createSdkMcpServer,
|
|
3828
4521
|
createSession,
|
|
3829
|
-
|
|
3830
|
-
|
|
4522
|
+
dispatchNotification,
|
|
4523
|
+
listSessions,
|
|
4524
|
+
resumeSession,
|
|
4525
|
+
run,
|
|
4526
|
+
tool
|
|
3831
4527
|
});
|
|
3832
4528
|
//# sourceMappingURL=index.cjs.map
|