@factory/droid-sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +214 -82
- package/dist/index.cjs +734 -611
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1649 -206
- package/dist/index.d.ts +1649 -206
- package/dist/index.js +729 -624
- package/dist/index.js.map +1 -1
- package/docs/sdk-usage-guide.md +678 -0
- package/examples/abort-session-stream.ts +19 -55
- package/examples/droid-dev-structured-output.ts +4 -5
- package/examples/fork-session.ts +25 -6
- package/examples/hook-execution.ts +62 -0
- package/examples/init-metadata.ts +9 -66
- package/examples/interrupt-session.ts +19 -54
- package/examples/list-sessions.ts +9 -55
- package/examples/multi-turn-session.ts +21 -53
- package/examples/permission-handler.ts +26 -84
- package/examples/readme-structured-output.ts +25 -0
- package/examples/result-metadata.ts +1 -1
- package/examples/run.ts +1 -1
- package/examples/sdk-mcp-tool.ts +11 -7
- package/examples/session-stream.ts +54 -0
- package/examples/spec-mode-new-session.ts +38 -99
- package/examples/spec-mode-same-session.ts +49 -111
- package/examples/structured-output.ts +16 -10
- package/examples/test-compact.ts +5 -3
- package/examples/test-rewind.ts +49 -117
- package/examples/tool-controls.ts +22 -55
- package/package.json +1 -1
- package/docs/examples/init-metadata.md +0 -79
- package/docs/examples/list-sessions.md +0 -64
- package/docs/examples/multi-turn-session.md +0 -77
- package/docs/examples/one-shot-query.md +0 -73
- package/docs/examples/permission-handler.md +0 -102
- package/docs/examples/run.md +0 -52
- package/docs/examples/spec-mode.md +0 -101
- package/docs/examples/tool-controls.md +0 -90
- package/docs/typescript-sdk-reference.md +0 -372
- package/examples/simple-query.ts +0 -53
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ var DroidServerMethod = /* @__PURE__ */ ((DroidServerMethod2) => {
|
|
|
3
3
|
DroidServerMethod2["INITIALIZE_SESSION"] = "droid.initialize_session";
|
|
4
4
|
DroidServerMethod2["LOAD_SESSION"] = "droid.load_session";
|
|
5
5
|
DroidServerMethod2["ADD_USER_MESSAGE"] = "droid.add_user_message";
|
|
6
|
+
DroidServerMethod2["CLOSE_SESSION"] = "droid.close_session";
|
|
6
7
|
DroidServerMethod2["INTERRUPT_SESSION"] = "droid.interrupt_session";
|
|
7
8
|
DroidServerMethod2["KILL_WORKER_SESSION"] = "droid.kill_worker_session";
|
|
8
9
|
DroidServerMethod2["UPDATE_SESSION_SETTINGS"] = "droid.update_session_settings";
|
|
@@ -45,7 +46,10 @@ var SessionNotificationType = /* @__PURE__ */ ((SessionNotificationType2) => {
|
|
|
45
46
|
SessionNotificationType2["SESSION_TITLE_UPDATED"] = "session_title_updated";
|
|
46
47
|
SessionNotificationType2["MCP_STATUS_CHANGED"] = "mcp_status_changed";
|
|
47
48
|
SessionNotificationType2["ASSISTANT_TEXT_DELTA"] = "assistant_text_delta";
|
|
49
|
+
SessionNotificationType2["ASSISTANT_TEXT_COMPLETE"] = "assistant_text_complete";
|
|
48
50
|
SessionNotificationType2["THINKING_TEXT_DELTA"] = "thinking_text_delta";
|
|
51
|
+
SessionNotificationType2["THINKING_TEXT_COMPLETE"] = "thinking_text_complete";
|
|
52
|
+
SessionNotificationType2["TOOL_CALL"] = "tool_call";
|
|
49
53
|
SessionNotificationType2["SESSION_TOKEN_USAGE_CHANGED"] = "session_token_usage_changed";
|
|
50
54
|
SessionNotificationType2["MISSION_STATE_CHANGED"] = "mission_state_changed";
|
|
51
55
|
SessionNotificationType2["MISSION_FEATURES_CHANGED"] = "mission_features_changed";
|
|
@@ -55,6 +59,9 @@ var SessionNotificationType = /* @__PURE__ */ ((SessionNotificationType2) => {
|
|
|
55
59
|
SessionNotificationType2["MISSION_WORKER_COMPLETED"] = "mission_worker_completed";
|
|
56
60
|
SessionNotificationType2["MCP_AUTH_REQUIRED"] = "mcp_auth_required";
|
|
57
61
|
SessionNotificationType2["MCP_AUTH_COMPLETED"] = "mcp_auth_completed";
|
|
62
|
+
SessionNotificationType2["HOOK_EXECUTION_STARTED"] = "hook_execution_started";
|
|
63
|
+
SessionNotificationType2["HOOK_EXECUTION_COMPLETED"] = "hook_execution_completed";
|
|
64
|
+
SessionNotificationType2["STRUCTURED_OUTPUT"] = "structured_output";
|
|
58
65
|
return SessionNotificationType2;
|
|
59
66
|
})(SessionNotificationType || {});
|
|
60
67
|
var ToolConfirmationOutcome = /* @__PURE__ */ ((ToolConfirmationOutcome3) => {
|
|
@@ -359,6 +366,12 @@ var JsonRpcMessageSchema = z.discriminatedUnion("type", [
|
|
|
359
366
|
}),
|
|
360
367
|
JsonRpcNotificationSchema
|
|
361
368
|
]);
|
|
369
|
+
function createResponseSchema(resultSchema) {
|
|
370
|
+
return z.union([
|
|
371
|
+
JsonRpcResponseSuccessSchema.extend({ result: resultSchema }),
|
|
372
|
+
JsonRpcResponseFailureSchema
|
|
373
|
+
]);
|
|
374
|
+
}
|
|
362
375
|
|
|
363
376
|
// src/schemas/session-metadata.ts
|
|
364
377
|
import { z as z6 } from "zod";
|
|
@@ -806,6 +819,9 @@ var AddUserMessageRequestParamsSchema = z5.object({
|
|
|
806
819
|
outputFormat: OutputFormatSchema.optional()
|
|
807
820
|
}).strict();
|
|
808
821
|
var InterruptSessionRequestParamsSchema = z5.object({}).strict();
|
|
822
|
+
var CloseSessionRequestParamsSchema = z5.object({
|
|
823
|
+
reason: z5.enum(["clear", "logout", "prompt_input_exit", "other"]).optional()
|
|
824
|
+
}).strict();
|
|
809
825
|
var KillWorkerSessionRequestParamsSchema = z5.object({
|
|
810
826
|
workerSessionId: z5.string()
|
|
811
827
|
}).strict();
|
|
@@ -922,6 +938,10 @@ var InterruptSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
|
922
938
|
method: z5.literal("droid.interrupt_session" /* INTERRUPT_SESSION */),
|
|
923
939
|
params: InterruptSessionRequestParamsSchema
|
|
924
940
|
});
|
|
941
|
+
var CloseSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
942
|
+
method: z5.literal("droid.close_session" /* CLOSE_SESSION */),
|
|
943
|
+
params: CloseSessionRequestParamsSchema
|
|
944
|
+
});
|
|
925
945
|
var KillWorkerSessionRequestSchema = JsonRpcRequestSchema.extend({
|
|
926
946
|
method: z5.literal("droid.kill_worker_session" /* KILL_WORKER_SESSION */),
|
|
927
947
|
params: KillWorkerSessionRequestParamsSchema
|
|
@@ -1014,6 +1034,7 @@ var ClientRequestSchema = z5.discriminatedUnion("method", [
|
|
|
1014
1034
|
InitializeSessionRequestSchema,
|
|
1015
1035
|
LoadSessionRequestSchema,
|
|
1016
1036
|
AddUserMessageRequestSchema,
|
|
1037
|
+
CloseSessionRequestSchema,
|
|
1017
1038
|
InterruptSessionRequestSchema,
|
|
1018
1039
|
KillWorkerSessionRequestSchema,
|
|
1019
1040
|
UpdateSessionSettingsRequestSchema,
|
|
@@ -1074,6 +1095,7 @@ var LoadSessionResultSchema = z5.object({
|
|
|
1074
1095
|
}).passthrough();
|
|
1075
1096
|
var AddUserMessageResultSchema = EmptyResultSchema;
|
|
1076
1097
|
var InterruptSessionResultSchema = EmptyResultSchema;
|
|
1098
|
+
var CloseSessionResultSchema = EmptyResultSchema;
|
|
1077
1099
|
var KillWorkerSessionResultSchema = EmptyResultSchema;
|
|
1078
1100
|
var UpdateSessionSettingsResultSchema = EmptyResultSchema;
|
|
1079
1101
|
var ToggleMcpServerResultSchema = SuccessResultSchema;
|
|
@@ -1114,127 +1136,88 @@ var ForkSessionResultSchema = z5.object({
|
|
|
1114
1136
|
}).passthrough();
|
|
1115
1137
|
var GetContextStatsResultSchema = ContextStatsSchema;
|
|
1116
1138
|
var RenameSessionResultSchema = SuccessResultSchema;
|
|
1117
|
-
var InitializeSessionResponseSchema =
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
var _LoadSessionResponseSchema = z5.union([
|
|
1124
|
-
JsonRpcResponseSuccessSchema.extend({ result: LoadSessionResultSchema }),
|
|
1125
|
-
JsonRpcResponseFailureSchema
|
|
1126
|
-
]);
|
|
1139
|
+
var InitializeSessionResponseSchema = createResponseSchema(
|
|
1140
|
+
InitializeSessionResultSchema
|
|
1141
|
+
);
|
|
1142
|
+
var _LoadSessionResponseSchema = createResponseSchema(
|
|
1143
|
+
LoadSessionResultSchema
|
|
1144
|
+
);
|
|
1127
1145
|
var LoadSessionResponseSchema = _LoadSessionResponseSchema;
|
|
1128
|
-
var AddUserMessageResponseSchema =
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
var
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
var
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
var
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
JsonRpcResponseSuccessSchema.extend({ result: ToggleMcpToolResultSchema }),
|
|
1204
|
-
JsonRpcResponseFailureSchema
|
|
1205
|
-
]);
|
|
1206
|
-
var ListSkillsResponseSchema = z5.union([
|
|
1207
|
-
JsonRpcResponseSuccessSchema.extend({ result: ListSkillsResultSchema }),
|
|
1208
|
-
JsonRpcResponseFailureSchema
|
|
1209
|
-
]);
|
|
1210
|
-
var SubmitBugReportResponseSchema = z5.union([
|
|
1211
|
-
JsonRpcResponseSuccessSchema.extend({ result: SubmitBugReportResultSchema }),
|
|
1212
|
-
JsonRpcResponseFailureSchema
|
|
1213
|
-
]);
|
|
1214
|
-
var GetRewindInfoResponseSchema = z5.union([
|
|
1215
|
-
JsonRpcResponseSuccessSchema.extend({ result: GetRewindInfoResultSchema }),
|
|
1216
|
-
JsonRpcResponseFailureSchema
|
|
1217
|
-
]);
|
|
1218
|
-
var ExecuteRewindResponseSchema = z5.union([
|
|
1219
|
-
JsonRpcResponseSuccessSchema.extend({ result: ExecuteRewindResultSchema }),
|
|
1220
|
-
JsonRpcResponseFailureSchema
|
|
1221
|
-
]);
|
|
1222
|
-
var CompactSessionResponseSchema = z5.union([
|
|
1223
|
-
JsonRpcResponseSuccessSchema.extend({ result: CompactSessionResultSchema }),
|
|
1224
|
-
JsonRpcResponseFailureSchema
|
|
1225
|
-
]);
|
|
1226
|
-
var ForkSessionResponseSchema = z5.union([
|
|
1227
|
-
JsonRpcResponseSuccessSchema.extend({ result: ForkSessionResultSchema }),
|
|
1228
|
-
JsonRpcResponseFailureSchema
|
|
1229
|
-
]);
|
|
1230
|
-
var GetContextStatsResponseSchema = z5.union([
|
|
1231
|
-
JsonRpcResponseSuccessSchema.extend({ result: GetContextStatsResultSchema }),
|
|
1232
|
-
JsonRpcResponseFailureSchema
|
|
1233
|
-
]);
|
|
1234
|
-
var RenameSessionResponseSchema = z5.union([
|
|
1235
|
-
JsonRpcResponseSuccessSchema.extend({ result: RenameSessionResultSchema }),
|
|
1236
|
-
JsonRpcResponseFailureSchema
|
|
1237
|
-
]);
|
|
1146
|
+
var AddUserMessageResponseSchema = createResponseSchema(
|
|
1147
|
+
AddUserMessageResultSchema
|
|
1148
|
+
);
|
|
1149
|
+
var InterruptSessionResponseSchema = createResponseSchema(
|
|
1150
|
+
InterruptSessionResultSchema
|
|
1151
|
+
);
|
|
1152
|
+
var CloseSessionResponseSchema = createResponseSchema(
|
|
1153
|
+
CloseSessionResultSchema
|
|
1154
|
+
);
|
|
1155
|
+
var KillWorkerSessionResponseSchema = createResponseSchema(
|
|
1156
|
+
KillWorkerSessionResultSchema
|
|
1157
|
+
);
|
|
1158
|
+
var UpdateSessionSettingsResponseSchema = createResponseSchema(
|
|
1159
|
+
UpdateSessionSettingsResultSchema
|
|
1160
|
+
);
|
|
1161
|
+
var ToggleMcpServerResponseSchema = createResponseSchema(
|
|
1162
|
+
ToggleMcpServerResultSchema
|
|
1163
|
+
);
|
|
1164
|
+
var AuthenticateMcpServerResponseSchema = createResponseSchema(
|
|
1165
|
+
AuthenticateMcpServerResultSchema
|
|
1166
|
+
);
|
|
1167
|
+
var CancelMcpAuthResponseSchema = createResponseSchema(
|
|
1168
|
+
CancelMcpAuthResultSchema
|
|
1169
|
+
);
|
|
1170
|
+
var ClearMcpAuthResponseSchema = createResponseSchema(
|
|
1171
|
+
ClearMcpAuthResultSchema
|
|
1172
|
+
);
|
|
1173
|
+
var SubmitMcpAuthCodeResponseSchema = createResponseSchema(
|
|
1174
|
+
SubmitMcpAuthCodeResultSchema
|
|
1175
|
+
);
|
|
1176
|
+
var AddMcpServerResponseSchema = createResponseSchema(
|
|
1177
|
+
AddMcpServerResultSchema
|
|
1178
|
+
);
|
|
1179
|
+
var RemoveMcpServerResponseSchema = createResponseSchema(
|
|
1180
|
+
RemoveMcpServerResultSchema
|
|
1181
|
+
);
|
|
1182
|
+
var ListMcpRegistryResponseSchema = createResponseSchema(
|
|
1183
|
+
ListMcpRegistryResultSchema
|
|
1184
|
+
);
|
|
1185
|
+
var ListMcpToolsResponseSchema = createResponseSchema(
|
|
1186
|
+
ListMcpToolsResultSchema
|
|
1187
|
+
);
|
|
1188
|
+
var ListToolsResponseSchema = createResponseSchema(
|
|
1189
|
+
ListToolsResultSchema
|
|
1190
|
+
);
|
|
1191
|
+
var ListMcpServersResponseSchema = createResponseSchema(
|
|
1192
|
+
ListMcpServersResultSchema
|
|
1193
|
+
);
|
|
1194
|
+
var ToggleMcpToolResponseSchema = createResponseSchema(
|
|
1195
|
+
ToggleMcpToolResultSchema
|
|
1196
|
+
);
|
|
1197
|
+
var ListSkillsResponseSchema = createResponseSchema(
|
|
1198
|
+
ListSkillsResultSchema
|
|
1199
|
+
);
|
|
1200
|
+
var SubmitBugReportResponseSchema = createResponseSchema(
|
|
1201
|
+
SubmitBugReportResultSchema
|
|
1202
|
+
);
|
|
1203
|
+
var GetRewindInfoResponseSchema = createResponseSchema(
|
|
1204
|
+
GetRewindInfoResultSchema
|
|
1205
|
+
);
|
|
1206
|
+
var ExecuteRewindResponseSchema = createResponseSchema(
|
|
1207
|
+
ExecuteRewindResultSchema
|
|
1208
|
+
);
|
|
1209
|
+
var CompactSessionResponseSchema = createResponseSchema(
|
|
1210
|
+
CompactSessionResultSchema
|
|
1211
|
+
);
|
|
1212
|
+
var ForkSessionResponseSchema = createResponseSchema(
|
|
1213
|
+
ForkSessionResultSchema
|
|
1214
|
+
);
|
|
1215
|
+
var GetContextStatsResponseSchema = createResponseSchema(
|
|
1216
|
+
GetContextStatsResultSchema
|
|
1217
|
+
);
|
|
1218
|
+
var RenameSessionResponseSchema = createResponseSchema(
|
|
1219
|
+
RenameSessionResultSchema
|
|
1220
|
+
);
|
|
1238
1221
|
|
|
1239
1222
|
// src/schemas/session-metadata.ts
|
|
1240
1223
|
var SessionMetadataSchema = z6.object({
|
|
@@ -1265,140 +1248,231 @@ var SessionSettingsFileSchema = z6.object({
|
|
|
1265
1248
|
tags: z6.array(SessionTagSchema).optional()
|
|
1266
1249
|
}).passthrough();
|
|
1267
1250
|
|
|
1268
|
-
// src/schemas/
|
|
1251
|
+
// src/schemas/hooks.ts
|
|
1269
1252
|
import { z as z7 } from "zod";
|
|
1253
|
+
var DroidHookEventSchema = z7.enum([
|
|
1254
|
+
"PreToolUse",
|
|
1255
|
+
"PostToolUse",
|
|
1256
|
+
"Notification",
|
|
1257
|
+
"UserPromptSubmit",
|
|
1258
|
+
"Stop",
|
|
1259
|
+
"SubagentStop",
|
|
1260
|
+
"PreCompact",
|
|
1261
|
+
"SessionStart",
|
|
1262
|
+
"SessionEnd"
|
|
1263
|
+
]);
|
|
1264
|
+
var DroidHookSpecificOutputSchema = z7.object({
|
|
1265
|
+
hookEventName: DroidHookEventSchema.optional(),
|
|
1266
|
+
permissionDecision: z7.enum(["allow", "deny", "ask"]).optional(),
|
|
1267
|
+
permissionDecisionReason: z7.string().optional(),
|
|
1268
|
+
additionalContext: z7.string().optional(),
|
|
1269
|
+
updatedInput: z7.record(z7.unknown()).optional()
|
|
1270
|
+
}).passthrough();
|
|
1271
|
+
var DroidHookOutputSchema = z7.object({
|
|
1272
|
+
continue: z7.boolean().optional(),
|
|
1273
|
+
stopReason: z7.string().optional(),
|
|
1274
|
+
suppressOutput: z7.boolean().optional(),
|
|
1275
|
+
systemMessage: z7.string().optional(),
|
|
1276
|
+
decision: z7.enum(["block", "approve"]).optional(),
|
|
1277
|
+
reason: z7.string().optional(),
|
|
1278
|
+
hookSpecificOutput: DroidHookSpecificOutputSchema.optional()
|
|
1279
|
+
}).passthrough();
|
|
1280
|
+
var DroidHookExecutionResultSchema = DroidHookOutputSchema.extend({
|
|
1281
|
+
exitCode: z7.number(),
|
|
1282
|
+
stdout: z7.string(),
|
|
1283
|
+
stderr: z7.string()
|
|
1284
|
+
});
|
|
1285
|
+
|
|
1286
|
+
// src/schemas/server.ts
|
|
1287
|
+
import { z as z8 } from "zod";
|
|
1270
1288
|
var ToolUseBlockSchema2 = ToolUseBlockSchema;
|
|
1271
1289
|
var ToolUseSchema = ToolUseBlockSchema2;
|
|
1272
|
-
var ErrorDetailSchema =
|
|
1273
|
-
name:
|
|
1274
|
-
message:
|
|
1275
|
-
}).passthrough();
|
|
1276
|
-
var ToolProgressUpdateSchema =
|
|
1277
|
-
type:
|
|
1278
|
-
toolName:
|
|
1279
|
-
status:
|
|
1280
|
-
details:
|
|
1281
|
-
text:
|
|
1282
|
-
error:
|
|
1283
|
-
timestamp:
|
|
1290
|
+
var ErrorDetailSchema = z8.object({
|
|
1291
|
+
name: z8.string(),
|
|
1292
|
+
message: z8.string()
|
|
1293
|
+
}).passthrough();
|
|
1294
|
+
var ToolProgressUpdateSchema = z8.object({
|
|
1295
|
+
type: z8.enum(["tool_call", "tool_result", "error", "status", "message"]),
|
|
1296
|
+
toolName: z8.string().optional(),
|
|
1297
|
+
status: z8.string().optional(),
|
|
1298
|
+
details: z8.string().optional(),
|
|
1299
|
+
text: z8.string().optional(),
|
|
1300
|
+
error: z8.string().optional(),
|
|
1301
|
+
timestamp: z8.number().optional(),
|
|
1284
1302
|
parameters: JsonObjectSchema.optional(),
|
|
1285
|
-
valueSnippet:
|
|
1286
|
-
subagentSessionId:
|
|
1287
|
-
}).passthrough();
|
|
1288
|
-
var SettingsUpdatedPayloadSchema =
|
|
1289
|
-
autonomyMode:
|
|
1290
|
-
interactionMode:
|
|
1291
|
-
autonomyLevel:
|
|
1292
|
-
modelId:
|
|
1293
|
-
reasoningEffort:
|
|
1294
|
-
specModeModelId:
|
|
1295
|
-
specModeReasoningEffort:
|
|
1303
|
+
valueSnippet: z8.string().optional(),
|
|
1304
|
+
subagentSessionId: z8.string().optional()
|
|
1305
|
+
}).passthrough();
|
|
1306
|
+
var SettingsUpdatedPayloadSchema = z8.object({
|
|
1307
|
+
autonomyMode: z8.nativeEnum(AutonomyMode).optional(),
|
|
1308
|
+
interactionMode: z8.nativeEnum(DroidInteractionMode).optional().catch(void 0),
|
|
1309
|
+
autonomyLevel: z8.nativeEnum(AutonomyLevel).optional().catch(void 0),
|
|
1310
|
+
modelId: z8.string().optional(),
|
|
1311
|
+
reasoningEffort: z8.nativeEnum(ReasoningEffort).optional(),
|
|
1312
|
+
specModeModelId: z8.string().optional(),
|
|
1313
|
+
specModeReasoningEffort: z8.nativeEnum(ReasoningEffort).optional(),
|
|
1296
1314
|
...ToolSelectionOverridesSchema.shape
|
|
1297
1315
|
}).passthrough();
|
|
1298
|
-
var ToolResultNotificationSchema =
|
|
1299
|
-
type:
|
|
1300
|
-
messageId:
|
|
1301
|
-
toolUseId:
|
|
1316
|
+
var ToolResultNotificationSchema = z8.object({
|
|
1317
|
+
type: z8.literal("tool_result" /* TOOL_RESULT */),
|
|
1318
|
+
messageId: z8.string(),
|
|
1319
|
+
toolUseId: z8.string(),
|
|
1302
1320
|
content: JsonValueSchema.optional(),
|
|
1303
|
-
isError:
|
|
1304
|
-
id:
|
|
1321
|
+
isError: z8.boolean().optional(),
|
|
1322
|
+
id: z8.string().optional()
|
|
1305
1323
|
}).passthrough();
|
|
1306
|
-
var ToolProgressUpdateNotificationSchema =
|
|
1307
|
-
type:
|
|
1308
|
-
toolUseId:
|
|
1309
|
-
toolName:
|
|
1324
|
+
var ToolProgressUpdateNotificationSchema = z8.object({
|
|
1325
|
+
type: z8.literal("tool_progress_update" /* TOOL_PROGRESS_UPDATE */),
|
|
1326
|
+
toolUseId: z8.string(),
|
|
1327
|
+
toolName: z8.string(),
|
|
1310
1328
|
update: ToolProgressUpdateSchema
|
|
1311
1329
|
}).passthrough();
|
|
1312
|
-
var CreateMessageNotificationSchema =
|
|
1313
|
-
type:
|
|
1330
|
+
var CreateMessageNotificationSchema = z8.object({
|
|
1331
|
+
type: z8.literal("create_message" /* CREATE_MESSAGE */),
|
|
1314
1332
|
message: FactoryDroidMessageSchema,
|
|
1315
|
-
parentId:
|
|
1316
|
-
requestId:
|
|
1317
|
-
}).passthrough();
|
|
1318
|
-
var ErrorNotificationSchema =
|
|
1319
|
-
type:
|
|
1320
|
-
message:
|
|
1321
|
-
errorType:
|
|
1322
|
-
timestamp:
|
|
1333
|
+
parentId: z8.string().optional(),
|
|
1334
|
+
requestId: z8.string().optional()
|
|
1335
|
+
}).passthrough();
|
|
1336
|
+
var ErrorNotificationSchema = z8.object({
|
|
1337
|
+
type: z8.literal("error" /* ERROR */),
|
|
1338
|
+
message: z8.string(),
|
|
1339
|
+
errorType: z8.nativeEnum(DroidErrorType),
|
|
1340
|
+
timestamp: z8.string(),
|
|
1323
1341
|
error: ErrorDetailSchema.optional()
|
|
1324
1342
|
}).passthrough();
|
|
1325
|
-
var DroidWorkingStateChangedNotificationSchema =
|
|
1326
|
-
type:
|
|
1327
|
-
newState:
|
|
1343
|
+
var DroidWorkingStateChangedNotificationSchema = z8.object({
|
|
1344
|
+
type: z8.literal("droid_working_state_changed" /* DROID_WORKING_STATE_CHANGED */),
|
|
1345
|
+
newState: z8.nativeEnum(DroidWorkingState)
|
|
1328
1346
|
}).passthrough();
|
|
1329
|
-
var PermissionResolvedNotificationSchema =
|
|
1330
|
-
type:
|
|
1331
|
-
requestId:
|
|
1332
|
-
toolUseIds:
|
|
1333
|
-
selectedOption:
|
|
1347
|
+
var PermissionResolvedNotificationSchema = z8.object({
|
|
1348
|
+
type: z8.literal("permission_resolved" /* PERMISSION_RESOLVED */),
|
|
1349
|
+
requestId: z8.string(),
|
|
1350
|
+
toolUseIds: z8.array(z8.string()),
|
|
1351
|
+
selectedOption: z8.nativeEnum(ToolConfirmationOutcome)
|
|
1334
1352
|
}).passthrough();
|
|
1335
|
-
var SettingsUpdatedNotificationSchema =
|
|
1336
|
-
type:
|
|
1353
|
+
var SettingsUpdatedNotificationSchema = z8.object({
|
|
1354
|
+
type: z8.literal("settings_updated" /* SETTINGS_UPDATED */),
|
|
1337
1355
|
settings: SettingsUpdatedPayloadSchema
|
|
1338
1356
|
}).passthrough();
|
|
1339
|
-
var SessionTitleUpdatedNotificationSchema =
|
|
1340
|
-
type:
|
|
1341
|
-
title:
|
|
1357
|
+
var SessionTitleUpdatedNotificationSchema = z8.object({
|
|
1358
|
+
type: z8.literal("session_title_updated" /* SESSION_TITLE_UPDATED */),
|
|
1359
|
+
title: z8.string()
|
|
1342
1360
|
}).passthrough();
|
|
1343
|
-
var McpStatusChangedNotificationSchema =
|
|
1344
|
-
type:
|
|
1345
|
-
servers:
|
|
1361
|
+
var McpStatusChangedNotificationSchema = z8.object({
|
|
1362
|
+
type: z8.literal("mcp_status_changed" /* MCP_STATUS_CHANGED */),
|
|
1363
|
+
servers: z8.array(McpServerStatusInfoSchema),
|
|
1346
1364
|
summary: McpStatusSummarySchema
|
|
1347
1365
|
}).passthrough();
|
|
1348
|
-
var AssistantTextDeltaNotificationSchema =
|
|
1349
|
-
type:
|
|
1350
|
-
messageId:
|
|
1351
|
-
blockIndex:
|
|
1352
|
-
textDelta:
|
|
1353
|
-
}).passthrough();
|
|
1354
|
-
var
|
|
1355
|
-
type:
|
|
1356
|
-
messageId:
|
|
1357
|
-
blockIndex:
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1366
|
+
var AssistantTextDeltaNotificationSchema = z8.object({
|
|
1367
|
+
type: z8.literal("assistant_text_delta" /* ASSISTANT_TEXT_DELTA */),
|
|
1368
|
+
messageId: z8.string(),
|
|
1369
|
+
blockIndex: z8.number(),
|
|
1370
|
+
textDelta: z8.string()
|
|
1371
|
+
}).passthrough();
|
|
1372
|
+
var AssistantTextCompleteNotificationSchema = z8.object({
|
|
1373
|
+
type: z8.literal("assistant_text_complete" /* ASSISTANT_TEXT_COMPLETE */),
|
|
1374
|
+
messageId: z8.string(),
|
|
1375
|
+
blockIndex: z8.number()
|
|
1376
|
+
}).passthrough();
|
|
1377
|
+
var ThinkingTextDeltaNotificationSchema = z8.object({
|
|
1378
|
+
type: z8.literal("thinking_text_delta" /* THINKING_TEXT_DELTA */),
|
|
1379
|
+
messageId: z8.string(),
|
|
1380
|
+
blockIndex: z8.number(),
|
|
1381
|
+
textDelta: z8.string()
|
|
1382
|
+
}).passthrough();
|
|
1383
|
+
var ThinkingTextCompleteNotificationSchema = z8.object({
|
|
1384
|
+
type: z8.literal("thinking_text_complete" /* THINKING_TEXT_COMPLETE */),
|
|
1385
|
+
messageId: z8.string(),
|
|
1386
|
+
blockIndex: z8.number(),
|
|
1387
|
+
durationMs: z8.number().optional()
|
|
1388
|
+
}).passthrough();
|
|
1389
|
+
var ToolCallNotificationSchema = z8.object({
|
|
1390
|
+
type: z8.literal("tool_call" /* TOOL_CALL */),
|
|
1391
|
+
toolUse: ToolUseBlockSchema2
|
|
1392
|
+
}).passthrough();
|
|
1393
|
+
var SessionTokenUsageChangedNotificationSchema = z8.object({
|
|
1394
|
+
type: z8.literal("session_token_usage_changed" /* SESSION_TOKEN_USAGE_CHANGED */),
|
|
1395
|
+
sessionId: z8.string(),
|
|
1363
1396
|
tokenUsage: TokenUsageSchema
|
|
1364
1397
|
}).passthrough();
|
|
1365
|
-
var MissionStateChangedNotificationSchema =
|
|
1366
|
-
type:
|
|
1367
|
-
state:
|
|
1398
|
+
var MissionStateChangedNotificationSchema = z8.object({
|
|
1399
|
+
type: z8.literal("mission_state_changed" /* MISSION_STATE_CHANGED */),
|
|
1400
|
+
state: z8.nativeEnum(MissionState)
|
|
1368
1401
|
}).passthrough();
|
|
1369
|
-
var MissionFeaturesChangedNotificationSchema =
|
|
1370
|
-
type:
|
|
1371
|
-
features:
|
|
1402
|
+
var MissionFeaturesChangedNotificationSchema = z8.object({
|
|
1403
|
+
type: z8.literal("mission_features_changed" /* MISSION_FEATURES_CHANGED */),
|
|
1404
|
+
features: z8.array(MissionFeatureSchema)
|
|
1372
1405
|
}).passthrough();
|
|
1373
|
-
var MissionProgressEntryNotificationSchema =
|
|
1374
|
-
type:
|
|
1375
|
-
progressLog:
|
|
1406
|
+
var MissionProgressEntryNotificationSchema = z8.object({
|
|
1407
|
+
type: z8.literal("mission_progress_entry" /* MISSION_PROGRESS_ENTRY */),
|
|
1408
|
+
progressLog: z8.array(ProgressLogEntrySchema)
|
|
1376
1409
|
}).passthrough();
|
|
1377
|
-
var MissionHeartbeatNotificationSchema =
|
|
1378
|
-
type:
|
|
1379
|
-
timestamp:
|
|
1410
|
+
var MissionHeartbeatNotificationSchema = z8.object({
|
|
1411
|
+
type: z8.literal("mission_heartbeat" /* MISSION_HEARTBEAT */),
|
|
1412
|
+
timestamp: z8.string()
|
|
1380
1413
|
}).passthrough();
|
|
1381
|
-
var MissionWorkerStartedNotificationSchema =
|
|
1382
|
-
type:
|
|
1383
|
-
workerSessionId:
|
|
1414
|
+
var MissionWorkerStartedNotificationSchema = z8.object({
|
|
1415
|
+
type: z8.literal("mission_worker_started" /* MISSION_WORKER_STARTED */),
|
|
1416
|
+
workerSessionId: z8.string()
|
|
1384
1417
|
}).passthrough();
|
|
1385
|
-
var MissionWorkerCompletedNotificationSchema =
|
|
1386
|
-
type:
|
|
1387
|
-
workerSessionId:
|
|
1388
|
-
exitCode:
|
|
1418
|
+
var MissionWorkerCompletedNotificationSchema = z8.object({
|
|
1419
|
+
type: z8.literal("mission_worker_completed" /* MISSION_WORKER_COMPLETED */),
|
|
1420
|
+
workerSessionId: z8.string(),
|
|
1421
|
+
exitCode: z8.number()
|
|
1389
1422
|
}).passthrough();
|
|
1390
|
-
var McpAuthRequiredNotificationSchema =
|
|
1391
|
-
type:
|
|
1392
|
-
serverName:
|
|
1393
|
-
authUrl:
|
|
1394
|
-
message:
|
|
1395
|
-
state:
|
|
1423
|
+
var McpAuthRequiredNotificationSchema = z8.object({
|
|
1424
|
+
type: z8.literal("mcp_auth_required" /* MCP_AUTH_REQUIRED */),
|
|
1425
|
+
serverName: z8.string(),
|
|
1426
|
+
authUrl: z8.string(),
|
|
1427
|
+
message: z8.string(),
|
|
1428
|
+
state: z8.string()
|
|
1396
1429
|
}).passthrough();
|
|
1397
|
-
var McpAuthCompletedNotificationSchema =
|
|
1398
|
-
type:
|
|
1399
|
-
serverName:
|
|
1400
|
-
outcome:
|
|
1401
|
-
message:
|
|
1430
|
+
var McpAuthCompletedNotificationSchema = z8.object({
|
|
1431
|
+
type: z8.literal("mcp_auth_completed" /* MCP_AUTH_COMPLETED */),
|
|
1432
|
+
serverName: z8.string(),
|
|
1433
|
+
outcome: z8.nativeEnum(McpAuthOutcome),
|
|
1434
|
+
message: z8.string()
|
|
1435
|
+
}).passthrough();
|
|
1436
|
+
var HookCommandSchema = z8.object({
|
|
1437
|
+
command: z8.string(),
|
|
1438
|
+
timeout: z8.number().optional()
|
|
1439
|
+
}).passthrough();
|
|
1440
|
+
var HookResultSchema = z8.object({
|
|
1441
|
+
exitCode: z8.number(),
|
|
1442
|
+
stdout: z8.string(),
|
|
1443
|
+
stderr: z8.string(),
|
|
1444
|
+
command: z8.string().optional(),
|
|
1445
|
+
timeout: z8.number().optional()
|
|
1446
|
+
}).passthrough();
|
|
1447
|
+
var HookExecutionStartedNotificationSchema = z8.object({
|
|
1448
|
+
type: z8.literal("hook_execution_started" /* HOOK_EXECUTION_STARTED */),
|
|
1449
|
+
hookId: z8.string(),
|
|
1450
|
+
hookEventName: DroidHookEventSchema,
|
|
1451
|
+
hookMatcher: z8.string().optional(),
|
|
1452
|
+
hookCommands: z8.array(HookCommandSchema),
|
|
1453
|
+
hookToolCallId: z8.string().optional(),
|
|
1454
|
+
isParallelExecution: z8.boolean().optional(),
|
|
1455
|
+
parallelGroupId: z8.string().optional()
|
|
1456
|
+
}).passthrough();
|
|
1457
|
+
var HookExecutionCompletedNotificationSchema = z8.object({
|
|
1458
|
+
type: z8.literal("hook_execution_completed" /* HOOK_EXECUTION_COMPLETED */),
|
|
1459
|
+
hookId: z8.string(),
|
|
1460
|
+
hookEventName: DroidHookEventSchema.optional(),
|
|
1461
|
+
hookMatcher: z8.string().optional(),
|
|
1462
|
+
hookToolCallId: z8.string().optional(),
|
|
1463
|
+
hookStatus: z8.enum(["completed", "error"]),
|
|
1464
|
+
hookResults: z8.array(HookResultSchema).optional()
|
|
1465
|
+
}).passthrough();
|
|
1466
|
+
var StructuredOutputErrorSchema = z8.object({
|
|
1467
|
+
code: z8.string(),
|
|
1468
|
+
message: z8.string(),
|
|
1469
|
+
details: z8.unknown().optional()
|
|
1470
|
+
}).passthrough();
|
|
1471
|
+
var StructuredOutputNotificationSchema = z8.object({
|
|
1472
|
+
type: z8.literal("structured_output" /* STRUCTURED_OUTPUT */),
|
|
1473
|
+
messageId: z8.string(),
|
|
1474
|
+
structuredOutput: JsonObjectSchema.nullable(),
|
|
1475
|
+
structuredOutputError: StructuredOutputErrorSchema.nullable()
|
|
1402
1476
|
}).passthrough();
|
|
1403
1477
|
var SessionNotificationSchemaList = [
|
|
1404
1478
|
ToolResultNotificationSchema,
|
|
@@ -1411,7 +1485,10 @@ var SessionNotificationSchemaList = [
|
|
|
1411
1485
|
SessionTitleUpdatedNotificationSchema,
|
|
1412
1486
|
McpStatusChangedNotificationSchema,
|
|
1413
1487
|
AssistantTextDeltaNotificationSchema,
|
|
1488
|
+
AssistantTextCompleteNotificationSchema,
|
|
1414
1489
|
ThinkingTextDeltaNotificationSchema,
|
|
1490
|
+
ThinkingTextCompleteNotificationSchema,
|
|
1491
|
+
ToolCallNotificationSchema,
|
|
1415
1492
|
SessionTokenUsageChangedNotificationSchema,
|
|
1416
1493
|
MissionStateChangedNotificationSchema,
|
|
1417
1494
|
MissionFeaturesChangedNotificationSchema,
|
|
@@ -1420,88 +1497,91 @@ var SessionNotificationSchemaList = [
|
|
|
1420
1497
|
MissionWorkerStartedNotificationSchema,
|
|
1421
1498
|
MissionWorkerCompletedNotificationSchema,
|
|
1422
1499
|
McpAuthRequiredNotificationSchema,
|
|
1423
|
-
McpAuthCompletedNotificationSchema
|
|
1500
|
+
McpAuthCompletedNotificationSchema,
|
|
1501
|
+
HookExecutionStartedNotificationSchema,
|
|
1502
|
+
HookExecutionCompletedNotificationSchema,
|
|
1503
|
+
StructuredOutputNotificationSchema
|
|
1424
1504
|
];
|
|
1425
|
-
var SessionNotificationPayloadSchema =
|
|
1505
|
+
var SessionNotificationPayloadSchema = z8.discriminatedUnion(
|
|
1426
1506
|
"type",
|
|
1427
1507
|
SessionNotificationSchemaList
|
|
1428
1508
|
);
|
|
1429
|
-
var _SessionNotificationParamsSchema =
|
|
1509
|
+
var _SessionNotificationParamsSchema = z8.object({
|
|
1430
1510
|
notification: SessionNotificationPayloadSchema
|
|
1431
1511
|
}).passthrough();
|
|
1432
1512
|
var SessionNotificationParamsSchema = _SessionNotificationParamsSchema;
|
|
1433
1513
|
var _SessionNotificationSchema = JsonRpcNotificationSchema.extend({
|
|
1434
|
-
method:
|
|
1514
|
+
method: z8.literal("droid.session_notification" /* SESSION_NOTIFICATION */),
|
|
1435
1515
|
params: SessionNotificationParamsSchema
|
|
1436
1516
|
});
|
|
1437
1517
|
var SessionNotificationSchema = _SessionNotificationSchema;
|
|
1438
|
-
var EditToolConfirmationDetailsSchema =
|
|
1439
|
-
type:
|
|
1440
|
-
filePath:
|
|
1441
|
-
fileName:
|
|
1442
|
-
oldContent:
|
|
1443
|
-
newContent:
|
|
1444
|
-
}).passthrough();
|
|
1445
|
-
var ExecuteToolConfirmationDetailsSchema =
|
|
1446
|
-
type:
|
|
1447
|
-
fullCommand:
|
|
1448
|
-
command:
|
|
1449
|
-
extractedCommands:
|
|
1450
|
-
impactLevel:
|
|
1451
|
-
}).passthrough();
|
|
1452
|
-
var CreateToolConfirmationDetailsSchema =
|
|
1453
|
-
type:
|
|
1454
|
-
filePath:
|
|
1455
|
-
fileName:
|
|
1456
|
-
content:
|
|
1457
|
-
}).passthrough();
|
|
1458
|
-
var AskUserQuestionSchema =
|
|
1459
|
-
index:
|
|
1460
|
-
topic:
|
|
1461
|
-
question:
|
|
1462
|
-
options:
|
|
1463
|
-
}).passthrough();
|
|
1464
|
-
var AskUserConfirmationDetailsSchema =
|
|
1465
|
-
type:
|
|
1466
|
-
questionnaire:
|
|
1467
|
-
parsed:
|
|
1468
|
-
questions:
|
|
1518
|
+
var EditToolConfirmationDetailsSchema = z8.object({
|
|
1519
|
+
type: z8.literal("edit" /* Edit */),
|
|
1520
|
+
filePath: z8.string(),
|
|
1521
|
+
fileName: z8.string(),
|
|
1522
|
+
oldContent: z8.string().optional(),
|
|
1523
|
+
newContent: z8.string().optional()
|
|
1524
|
+
}).passthrough();
|
|
1525
|
+
var ExecuteToolConfirmationDetailsSchema = z8.object({
|
|
1526
|
+
type: z8.literal("exec" /* Execute */),
|
|
1527
|
+
fullCommand: z8.string(),
|
|
1528
|
+
command: z8.string(),
|
|
1529
|
+
extractedCommands: z8.array(z8.string()).optional(),
|
|
1530
|
+
impactLevel: z8.string().optional()
|
|
1531
|
+
}).passthrough();
|
|
1532
|
+
var CreateToolConfirmationDetailsSchema = z8.object({
|
|
1533
|
+
type: z8.literal("create" /* Create */),
|
|
1534
|
+
filePath: z8.string(),
|
|
1535
|
+
fileName: z8.string(),
|
|
1536
|
+
content: z8.string()
|
|
1537
|
+
}).passthrough();
|
|
1538
|
+
var AskUserQuestionSchema = z8.object({
|
|
1539
|
+
index: z8.number(),
|
|
1540
|
+
topic: z8.string(),
|
|
1541
|
+
question: z8.string(),
|
|
1542
|
+
options: z8.array(z8.string())
|
|
1543
|
+
}).passthrough();
|
|
1544
|
+
var AskUserConfirmationDetailsSchema = z8.object({
|
|
1545
|
+
type: z8.literal("ask_user" /* AskUser */),
|
|
1546
|
+
questionnaire: z8.string(),
|
|
1547
|
+
parsed: z8.object({
|
|
1548
|
+
questions: z8.array(AskUserQuestionSchema)
|
|
1469
1549
|
}).optional(),
|
|
1470
|
-
parseError:
|
|
1471
|
-
message:
|
|
1472
|
-
line:
|
|
1550
|
+
parseError: z8.object({
|
|
1551
|
+
message: z8.string(),
|
|
1552
|
+
line: z8.number().optional()
|
|
1473
1553
|
}).optional()
|
|
1474
1554
|
}).passthrough();
|
|
1475
|
-
var ExitSpecModeConfirmationDetailsSchema =
|
|
1476
|
-
type:
|
|
1477
|
-
plan:
|
|
1478
|
-
title:
|
|
1479
|
-
optionNames:
|
|
1480
|
-
}).passthrough();
|
|
1481
|
-
var ProposeMissionConfirmationDetailsSchema =
|
|
1482
|
-
type:
|
|
1483
|
-
proposal:
|
|
1484
|
-
title:
|
|
1485
|
-
}).passthrough();
|
|
1486
|
-
var StartMissionRunConfirmationDetailsSchema =
|
|
1487
|
-
type:
|
|
1488
|
-
runningMissionCount:
|
|
1489
|
-
runningMissionSessionIds:
|
|
1490
|
-
}).passthrough();
|
|
1491
|
-
var ApplyPatchToolConfirmationDetailsSchema =
|
|
1492
|
-
type:
|
|
1493
|
-
filePath:
|
|
1494
|
-
fileName:
|
|
1495
|
-
patchContent:
|
|
1496
|
-
oldContent:
|
|
1497
|
-
newContent:
|
|
1498
|
-
}).passthrough();
|
|
1499
|
-
var McpToolConfirmationDetailsSchema =
|
|
1500
|
-
type:
|
|
1501
|
-
toolName:
|
|
1502
|
-
impactLevel:
|
|
1503
|
-
}).passthrough();
|
|
1504
|
-
var ToolConfirmationDetailsSchema =
|
|
1555
|
+
var ExitSpecModeConfirmationDetailsSchema = z8.object({
|
|
1556
|
+
type: z8.literal("exit_spec_mode" /* ExitSpecMode */),
|
|
1557
|
+
plan: z8.string(),
|
|
1558
|
+
title: z8.string().optional(),
|
|
1559
|
+
optionNames: z8.array(z8.string()).optional()
|
|
1560
|
+
}).passthrough();
|
|
1561
|
+
var ProposeMissionConfirmationDetailsSchema = z8.object({
|
|
1562
|
+
type: z8.literal("propose_mission" /* ProposeMission */),
|
|
1563
|
+
proposal: z8.string(),
|
|
1564
|
+
title: z8.string().optional()
|
|
1565
|
+
}).passthrough();
|
|
1566
|
+
var StartMissionRunConfirmationDetailsSchema = z8.object({
|
|
1567
|
+
type: z8.literal("start_mission_run" /* StartMissionRun */),
|
|
1568
|
+
runningMissionCount: z8.number(),
|
|
1569
|
+
runningMissionSessionIds: z8.array(z8.string())
|
|
1570
|
+
}).passthrough();
|
|
1571
|
+
var ApplyPatchToolConfirmationDetailsSchema = z8.object({
|
|
1572
|
+
type: z8.literal("apply_patch" /* ApplyPatch */),
|
|
1573
|
+
filePath: z8.string(),
|
|
1574
|
+
fileName: z8.string(),
|
|
1575
|
+
patchContent: z8.string(),
|
|
1576
|
+
oldContent: z8.string().optional(),
|
|
1577
|
+
newContent: z8.string().optional()
|
|
1578
|
+
}).passthrough();
|
|
1579
|
+
var McpToolConfirmationDetailsSchema = z8.object({
|
|
1580
|
+
type: z8.literal("mcp_tool" /* McpTool */),
|
|
1581
|
+
toolName: z8.string(),
|
|
1582
|
+
impactLevel: z8.string()
|
|
1583
|
+
}).passthrough();
|
|
1584
|
+
var ToolConfirmationDetailsSchema = z8.discriminatedUnion("type", [
|
|
1505
1585
|
EditToolConfirmationDetailsSchema,
|
|
1506
1586
|
ExecuteToolConfirmationDetailsSchema,
|
|
1507
1587
|
CreateToolConfirmationDetailsSchema,
|
|
@@ -1512,51 +1592,45 @@ var ToolConfirmationDetailsSchema = z7.discriminatedUnion("type", [
|
|
|
1512
1592
|
ApplyPatchToolConfirmationDetailsSchema,
|
|
1513
1593
|
McpToolConfirmationDetailsSchema
|
|
1514
1594
|
]);
|
|
1515
|
-
var ToolConfirmationInfoSchema =
|
|
1595
|
+
var ToolConfirmationInfoSchema = z8.object({
|
|
1516
1596
|
toolUse: ToolUseSchema,
|
|
1517
|
-
confirmationType:
|
|
1597
|
+
confirmationType: z8.nativeEnum(ToolConfirmationType),
|
|
1518
1598
|
details: ToolConfirmationDetailsSchema
|
|
1519
1599
|
}).passthrough();
|
|
1520
|
-
var RequestPermissionRequestParamsSchema =
|
|
1521
|
-
toolUses:
|
|
1522
|
-
options:
|
|
1600
|
+
var RequestPermissionRequestParamsSchema = z8.object({
|
|
1601
|
+
toolUses: z8.array(ToolConfirmationInfoSchema),
|
|
1602
|
+
options: z8.array(ToolConfirmationListItemSchema)
|
|
1523
1603
|
}).passthrough();
|
|
1524
1604
|
var RequestPermissionRequestSchema = JsonRpcRequestSchema.extend({
|
|
1525
|
-
method:
|
|
1605
|
+
method: z8.literal("droid.request_permission" /* REQUEST_PERMISSION */),
|
|
1526
1606
|
params: RequestPermissionRequestParamsSchema
|
|
1527
1607
|
});
|
|
1528
|
-
var RequestPermissionResultSchema =
|
|
1529
|
-
selectedOption:
|
|
1530
|
-
comment:
|
|
1608
|
+
var RequestPermissionResultSchema = z8.object({
|
|
1609
|
+
selectedOption: z8.nativeEnum(ToolConfirmationOutcome),
|
|
1610
|
+
comment: z8.string().optional()
|
|
1531
1611
|
}).strict();
|
|
1532
|
-
var RequestPermissionResponseSchema =
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
var AskUserRequestParamsSchema = z7.object({
|
|
1539
|
-
toolCallId: z7.string(),
|
|
1540
|
-
questions: z7.array(AskUserQuestionSchema)
|
|
1612
|
+
var RequestPermissionResponseSchema = createResponseSchema(
|
|
1613
|
+
RequestPermissionResultSchema
|
|
1614
|
+
);
|
|
1615
|
+
var AskUserRequestParamsSchema = z8.object({
|
|
1616
|
+
toolCallId: z8.string(),
|
|
1617
|
+
questions: z8.array(AskUserQuestionSchema)
|
|
1541
1618
|
}).passthrough();
|
|
1542
1619
|
var AskUserRequestSchema = JsonRpcRequestSchema.extend({
|
|
1543
|
-
method:
|
|
1620
|
+
method: z8.literal("droid.ask_user" /* ASK_USER */),
|
|
1544
1621
|
params: AskUserRequestParamsSchema
|
|
1545
1622
|
});
|
|
1546
|
-
var AskUserCollectedAnswerSchema =
|
|
1547
|
-
index:
|
|
1548
|
-
question:
|
|
1549
|
-
answer:
|
|
1623
|
+
var AskUserCollectedAnswerSchema = z8.object({
|
|
1624
|
+
index: z8.number(),
|
|
1625
|
+
question: z8.string(),
|
|
1626
|
+
answer: z8.string()
|
|
1550
1627
|
}).strict();
|
|
1551
|
-
var AskUserResultSchema =
|
|
1552
|
-
cancelled:
|
|
1553
|
-
answers:
|
|
1628
|
+
var AskUserResultSchema = z8.object({
|
|
1629
|
+
cancelled: z8.boolean().optional(),
|
|
1630
|
+
answers: z8.array(AskUserCollectedAnswerSchema)
|
|
1554
1631
|
}).strict();
|
|
1555
|
-
var AskUserResponseSchema =
|
|
1556
|
-
|
|
1557
|
-
JsonRpcResponseFailureSchema
|
|
1558
|
-
]);
|
|
1559
|
-
var _CliRequestOrNotificationSchema = z7.union([
|
|
1632
|
+
var AskUserResponseSchema = createResponseSchema(AskUserResultSchema);
|
|
1633
|
+
var _CliRequestOrNotificationSchema = z8.union([
|
|
1560
1634
|
SessionNotificationSchema,
|
|
1561
1635
|
RequestPermissionRequestSchema,
|
|
1562
1636
|
AskUserRequestSchema
|
|
@@ -1564,7 +1638,7 @@ var _CliRequestOrNotificationSchema = z7.union([
|
|
|
1564
1638
|
var CliRequestOrNotificationSchema = _CliRequestOrNotificationSchema;
|
|
1565
1639
|
|
|
1566
1640
|
// src/constants.ts
|
|
1567
|
-
var SDK_VERSION = "0.
|
|
1641
|
+
var SDK_VERSION = "0.3.0";
|
|
1568
1642
|
var SDK_TAG = {
|
|
1569
1643
|
name: "sdk",
|
|
1570
1644
|
metadata: { language: "typescript", version: SDK_VERSION }
|
|
@@ -1880,6 +1954,24 @@ var ProcessTransport = class {
|
|
|
1880
1954
|
|
|
1881
1955
|
// src/protocol.ts
|
|
1882
1956
|
import { v4 as uuidv4 } from "uuid";
|
|
1957
|
+
function dispatchNotification(notification, listeners) {
|
|
1958
|
+
let notificationType;
|
|
1959
|
+
const parsed = SessionNotificationParamsSchema.safeParse(
|
|
1960
|
+
notification["params"]
|
|
1961
|
+
);
|
|
1962
|
+
if (parsed.success) {
|
|
1963
|
+
notificationType = parsed.data.notification.type;
|
|
1964
|
+
}
|
|
1965
|
+
for (const listener of listeners) {
|
|
1966
|
+
if (listener.filter?.type != null && listener.filter.type !== notificationType) {
|
|
1967
|
+
continue;
|
|
1968
|
+
}
|
|
1969
|
+
try {
|
|
1970
|
+
listener.callback(notification);
|
|
1971
|
+
} catch {
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1883
1975
|
var ProtocolEngine = class {
|
|
1884
1976
|
_transport;
|
|
1885
1977
|
_defaultTimeout;
|
|
@@ -2044,22 +2136,7 @@ var ProtocolEngine = class {
|
|
|
2044
2136
|
pending.resolve(result);
|
|
2045
2137
|
}
|
|
2046
2138
|
_handleNotification(notification) {
|
|
2047
|
-
|
|
2048
|
-
const parsed = SessionNotificationParamsSchema.safeParse(
|
|
2049
|
-
notification["params"]
|
|
2050
|
-
);
|
|
2051
|
-
if (parsed.success) {
|
|
2052
|
-
notificationType = parsed.data.notification.type;
|
|
2053
|
-
}
|
|
2054
|
-
for (const listener of this._notificationListeners) {
|
|
2055
|
-
if (listener.filter?.type != null && listener.filter.type !== notificationType) {
|
|
2056
|
-
continue;
|
|
2057
|
-
}
|
|
2058
|
-
try {
|
|
2059
|
-
listener.callback(notification);
|
|
2060
|
-
} catch {
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2139
|
+
dispatchNotification(notification, this._notificationListeners);
|
|
2063
2140
|
}
|
|
2064
2141
|
async _handleServerRequest(method, requestId, params) {
|
|
2065
2142
|
if (method === "droid.request_permission" /* REQUEST_PERMISSION */) {
|
|
@@ -2180,10 +2257,6 @@ var DroidClient = class {
|
|
|
2180
2257
|
_engine;
|
|
2181
2258
|
_sessionId = null;
|
|
2182
2259
|
_closed = false;
|
|
2183
|
-
/**
|
|
2184
|
-
* Client-level notification listeners.
|
|
2185
|
-
* Each entry is [callback, optional notification filter].
|
|
2186
|
-
*/
|
|
2187
2260
|
_notificationListeners = [];
|
|
2188
2261
|
/** Client-level permission handler. */
|
|
2189
2262
|
_permissionHandler = null;
|
|
@@ -2257,6 +2330,13 @@ var DroidClient = class {
|
|
|
2257
2330
|
InterruptSessionResultSchema
|
|
2258
2331
|
);
|
|
2259
2332
|
}
|
|
2333
|
+
async closeSession(params = {}) {
|
|
2334
|
+
return this._sessionRpc(
|
|
2335
|
+
"droid.close_session" /* CLOSE_SESSION */,
|
|
2336
|
+
params,
|
|
2337
|
+
CloseSessionResultSchema
|
|
2338
|
+
);
|
|
2339
|
+
}
|
|
2260
2340
|
async killWorkerSession(params) {
|
|
2261
2341
|
return this._sessionRpc(
|
|
2262
2342
|
"droid.kill_worker_session" /* KILL_WORKER_SESSION */,
|
|
@@ -2445,23 +2525,7 @@ var DroidClient = class {
|
|
|
2445
2525
|
await this._engine.close();
|
|
2446
2526
|
}
|
|
2447
2527
|
_dispatchNotification(notification) {
|
|
2448
|
-
|
|
2449
|
-
const parsed = SessionNotificationParamsSchema.safeParse(
|
|
2450
|
-
notification["params"]
|
|
2451
|
-
);
|
|
2452
|
-
if (parsed.success) {
|
|
2453
|
-
notificationType = parsed.data.notification.type;
|
|
2454
|
-
}
|
|
2455
|
-
const listeners = [...this._notificationListeners];
|
|
2456
|
-
for (const listener of listeners) {
|
|
2457
|
-
if (listener.filter?.type != null && listener.filter.type !== notificationType) {
|
|
2458
|
-
continue;
|
|
2459
|
-
}
|
|
2460
|
-
try {
|
|
2461
|
-
listener.callback(notification);
|
|
2462
|
-
} catch {
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2528
|
+
dispatchNotification(notification, [...this._notificationListeners]);
|
|
2465
2529
|
}
|
|
2466
2530
|
_dispatchPermissionRequest(params) {
|
|
2467
2531
|
const handler = this._permissionHandler;
|
|
@@ -2495,14 +2559,18 @@ var DroidClient = class {
|
|
|
2495
2559
|
|
|
2496
2560
|
// src/stream.ts
|
|
2497
2561
|
var DroidMessageType = {
|
|
2562
|
+
Assistant: "assistant",
|
|
2563
|
+
User: "user",
|
|
2564
|
+
ToolCall: "tool_call",
|
|
2498
2565
|
AssistantTextDelta: "assistant_text_delta",
|
|
2566
|
+
AssistantTextComplete: "assistant_text_complete",
|
|
2499
2567
|
ThinkingTextDelta: "thinking_text_delta",
|
|
2500
|
-
|
|
2568
|
+
ThinkingTextComplete: "thinking_text_complete",
|
|
2569
|
+
ToolCallDelta: "tool_call_delta",
|
|
2501
2570
|
ToolResult: "tool_result",
|
|
2502
2571
|
ToolProgress: "tool_progress",
|
|
2503
2572
|
WorkingStateChanged: "working_state_changed",
|
|
2504
2573
|
TokenUsageUpdate: "token_usage_update",
|
|
2505
|
-
CreateMessage: "create_message",
|
|
2506
2574
|
PermissionResolved: "permission_resolved",
|
|
2507
2575
|
SettingsUpdated: "settings_updated",
|
|
2508
2576
|
SessionTitleUpdated: "session_title_updated",
|
|
@@ -2515,8 +2583,9 @@ var DroidMessageType = {
|
|
|
2515
2583
|
MissionWorkerCompleted: "mission_worker_completed",
|
|
2516
2584
|
McpAuthRequired: "mcp_auth_required",
|
|
2517
2585
|
McpAuthCompleted: "mcp_auth_completed",
|
|
2586
|
+
Hook: "hook",
|
|
2518
2587
|
Error: "error",
|
|
2519
|
-
|
|
2588
|
+
Result: "result"
|
|
2520
2589
|
};
|
|
2521
2590
|
function convertNotificationToStreamMessage(raw) {
|
|
2522
2591
|
const parsed = SessionNotificationPayloadSchema.safeParse(raw);
|
|
@@ -2532,6 +2601,12 @@ function convertNotificationToStreamMessage(raw) {
|
|
|
2532
2601
|
blockIndex: notification.blockIndex,
|
|
2533
2602
|
text: notification.textDelta
|
|
2534
2603
|
};
|
|
2604
|
+
case "assistant_text_complete" /* ASSISTANT_TEXT_COMPLETE */:
|
|
2605
|
+
return {
|
|
2606
|
+
type: DroidMessageType.AssistantTextComplete,
|
|
2607
|
+
messageId: notification.messageId,
|
|
2608
|
+
blockIndex: notification.blockIndex
|
|
2609
|
+
};
|
|
2535
2610
|
case "thinking_text_delta" /* THINKING_TEXT_DELTA */:
|
|
2536
2611
|
return {
|
|
2537
2612
|
type: DroidMessageType.ThinkingTextDelta,
|
|
@@ -2539,6 +2614,18 @@ function convertNotificationToStreamMessage(raw) {
|
|
|
2539
2614
|
blockIndex: notification.blockIndex,
|
|
2540
2615
|
text: notification.textDelta
|
|
2541
2616
|
};
|
|
2617
|
+
case "thinking_text_complete" /* THINKING_TEXT_COMPLETE */:
|
|
2618
|
+
return {
|
|
2619
|
+
type: DroidMessageType.ThinkingTextComplete,
|
|
2620
|
+
messageId: notification.messageId,
|
|
2621
|
+
blockIndex: notification.blockIndex,
|
|
2622
|
+
durationMs: notification.durationMs
|
|
2623
|
+
};
|
|
2624
|
+
case "tool_call" /* TOOL_CALL */:
|
|
2625
|
+
return {
|
|
2626
|
+
type: DroidMessageType.ToolCallDelta,
|
|
2627
|
+
toolUse: notification.toolUse
|
|
2628
|
+
};
|
|
2542
2629
|
case "tool_result" /* TOOL_RESULT */:
|
|
2543
2630
|
return {
|
|
2544
2631
|
type: DroidMessageType.ToolResult,
|
|
@@ -2578,22 +2665,33 @@ function convertNotificationToStreamMessage(raw) {
|
|
|
2578
2665
|
const msg = notification.message;
|
|
2579
2666
|
const messages = [];
|
|
2580
2667
|
for (const block of msg.content) {
|
|
2581
|
-
if (block.type ===
|
|
2668
|
+
if (block.type === "tool_use") {
|
|
2582
2669
|
messages.push({
|
|
2583
|
-
type: DroidMessageType.
|
|
2584
|
-
|
|
2585
|
-
toolInput: block.input,
|
|
2586
|
-
toolUseId: block.id
|
|
2670
|
+
type: DroidMessageType.ToolCall,
|
|
2671
|
+
toolUse: block
|
|
2587
2672
|
});
|
|
2588
2673
|
}
|
|
2589
2674
|
}
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
})
|
|
2675
|
+
if (msg.role === FactoryDroidMessageRole.Assistant) {
|
|
2676
|
+
messages.push({
|
|
2677
|
+
type: DroidMessageType.Assistant,
|
|
2678
|
+
message: msg,
|
|
2679
|
+
text: extractTextFromMessage(msg)
|
|
2680
|
+
});
|
|
2681
|
+
} else if (msg.role === FactoryDroidMessageRole.User) {
|
|
2682
|
+
messages.push({
|
|
2683
|
+
type: DroidMessageType.User,
|
|
2684
|
+
message: msg
|
|
2685
|
+
});
|
|
2686
|
+
} else {
|
|
2687
|
+
messages.push({
|
|
2688
|
+
type: "create_message",
|
|
2689
|
+
messageId: msg.id,
|
|
2690
|
+
role: msg.role,
|
|
2691
|
+
content: msg.content,
|
|
2692
|
+
parentId: notification.parentId
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2597
2695
|
return messages;
|
|
2598
2696
|
}
|
|
2599
2697
|
case "error" /* ERROR */:
|
|
@@ -2672,42 +2770,205 @@ function convertNotificationToStreamMessage(raw) {
|
|
|
2672
2770
|
outcome: notification.outcome,
|
|
2673
2771
|
message: notification.message
|
|
2674
2772
|
};
|
|
2773
|
+
case "hook_execution_started" /* HOOK_EXECUTION_STARTED */:
|
|
2774
|
+
return notification.hookCommands.map((hookCommand) => ({
|
|
2775
|
+
type: DroidMessageType.Hook,
|
|
2776
|
+
hookId: notification.hookId,
|
|
2777
|
+
eventName: notification.hookEventName,
|
|
2778
|
+
matcher: notification.hookMatcher,
|
|
2779
|
+
toolCallId: notification.hookToolCallId,
|
|
2780
|
+
command: hookCommand.command,
|
|
2781
|
+
timeout: hookCommand.timeout,
|
|
2782
|
+
status: "started"
|
|
2783
|
+
}));
|
|
2784
|
+
case "hook_execution_completed" /* HOOK_EXECUTION_COMPLETED */:
|
|
2785
|
+
return (notification.hookResults ?? []).map((hookResult) => ({
|
|
2786
|
+
type: DroidMessageType.Hook,
|
|
2787
|
+
hookId: notification.hookId,
|
|
2788
|
+
eventName: notification.hookEventName,
|
|
2789
|
+
matcher: notification.hookMatcher,
|
|
2790
|
+
toolCallId: notification.hookToolCallId,
|
|
2791
|
+
command: hookResult.command,
|
|
2792
|
+
timeout: hookResult.timeout,
|
|
2793
|
+
status: notification.hookStatus,
|
|
2794
|
+
exitCode: hookResult.exitCode,
|
|
2795
|
+
stdout: hookResult.stdout,
|
|
2796
|
+
stderr: hookResult.stderr
|
|
2797
|
+
}));
|
|
2798
|
+
case "structured_output" /* STRUCTURED_OUTPUT */:
|
|
2799
|
+
return {
|
|
2800
|
+
type: "structured_output",
|
|
2801
|
+
messageId: notification.messageId,
|
|
2802
|
+
structuredOutput: notification.structuredOutput,
|
|
2803
|
+
structuredOutputError: notification.structuredOutputError
|
|
2804
|
+
};
|
|
2675
2805
|
default:
|
|
2676
2806
|
return null;
|
|
2677
2807
|
}
|
|
2678
2808
|
}
|
|
2679
2809
|
var StreamStateTracker = class {
|
|
2810
|
+
constructor(options = {}) {
|
|
2811
|
+
this.options = options;
|
|
2812
|
+
}
|
|
2680
2813
|
hasBeenNonIdle = false;
|
|
2681
2814
|
lastTokenUsage = null;
|
|
2815
|
+
fullText = "";
|
|
2816
|
+
finalAssistantText = "";
|
|
2817
|
+
structuredOutput = null;
|
|
2818
|
+
structuredOutputError = null;
|
|
2819
|
+
errors = [];
|
|
2820
|
+
numTurns = 0;
|
|
2821
|
+
emittedMessages = [];
|
|
2682
2822
|
toolNameMap = /* @__PURE__ */ new Map();
|
|
2683
2823
|
getToolName(toolUseId) {
|
|
2684
2824
|
return this.toolNameMap.get(toolUseId) ?? "";
|
|
2685
2825
|
}
|
|
2686
2826
|
processMessage(message) {
|
|
2687
2827
|
const additional = [];
|
|
2688
|
-
if (message.type ===
|
|
2828
|
+
if (message.type === "tool_use") {
|
|
2689
2829
|
this.toolNameMap.set(message.toolUseId, message.toolName);
|
|
2690
2830
|
}
|
|
2831
|
+
if (message.type === DroidMessageType.ToolCall) {
|
|
2832
|
+
this.toolNameMap.set(message.toolUse.id, message.toolUse.name);
|
|
2833
|
+
}
|
|
2834
|
+
if (message.type === DroidMessageType.ToolCallDelta) {
|
|
2835
|
+
this.toolNameMap.set(message.toolUse.id, message.toolUse.name);
|
|
2836
|
+
}
|
|
2691
2837
|
if (message.type === DroidMessageType.ToolResult) {
|
|
2692
2838
|
message = { ...message, toolName: this.getToolName(message.toolUseId) };
|
|
2693
2839
|
}
|
|
2840
|
+
if (message.type === DroidMessageType.AssistantTextDelta) {
|
|
2841
|
+
this.fullText += message.text;
|
|
2842
|
+
}
|
|
2843
|
+
if (message.type === DroidMessageType.Assistant) {
|
|
2844
|
+
this.finalAssistantText = message.text;
|
|
2845
|
+
if (this.fullText.length === 0) {
|
|
2846
|
+
this.fullText = message.text;
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2694
2849
|
if (message.type === DroidMessageType.TokenUsageUpdate) {
|
|
2695
2850
|
this.lastTokenUsage = message;
|
|
2696
2851
|
}
|
|
2852
|
+
if (message.type === DroidMessageType.Error) {
|
|
2853
|
+
this.errors.push(message);
|
|
2854
|
+
}
|
|
2855
|
+
if (message.type === "structured_output") {
|
|
2856
|
+
this.structuredOutput = message.structuredOutput;
|
|
2857
|
+
this.structuredOutputError = message.structuredOutputError;
|
|
2858
|
+
return { message: null, additional };
|
|
2859
|
+
}
|
|
2697
2860
|
if (message.type === DroidMessageType.WorkingStateChanged) {
|
|
2698
2861
|
if (message.state !== "idle" /* Idle */) {
|
|
2699
2862
|
this.hasBeenNonIdle = true;
|
|
2700
2863
|
} else if (this.hasBeenNonIdle) {
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
tokenUsage: this.lastTokenUsage
|
|
2704
|
-
});
|
|
2864
|
+
this.numTurns++;
|
|
2865
|
+
additional.push(this.createResultMessage());
|
|
2705
2866
|
this.hasBeenNonIdle = false;
|
|
2867
|
+
this.resetTurnState();
|
|
2706
2868
|
}
|
|
2707
2869
|
}
|
|
2870
|
+
if (message.type !== DroidMessageType.WorkingStateChanged) {
|
|
2871
|
+
this.trackEmittedMessage(message);
|
|
2872
|
+
}
|
|
2708
2873
|
return { message, additional };
|
|
2709
2874
|
}
|
|
2875
|
+
createResultMessage() {
|
|
2876
|
+
if (this.options.hasOutputFormat && this.structuredOutput === null && this.structuredOutputError === null) {
|
|
2877
|
+
this.structuredOutput = parseJsonObject(this.finalAssistantText || this.fullText) ?? null;
|
|
2878
|
+
}
|
|
2879
|
+
const tokenUsage = this.lastTokenUsage ? stripTokenUsageType(this.lastTokenUsage) : null;
|
|
2880
|
+
const result = this.finalAssistantText || this.fullText;
|
|
2881
|
+
const base = {
|
|
2882
|
+
type: DroidMessageType.Result,
|
|
2883
|
+
sessionId: this.options.sessionId ?? "",
|
|
2884
|
+
durationMs: Date.now() - (this.options.startedAt ?? Date.now()),
|
|
2885
|
+
numTurns: this.numTurns,
|
|
2886
|
+
result,
|
|
2887
|
+
tokenUsage,
|
|
2888
|
+
messages: [...this.emittedMessages],
|
|
2889
|
+
text: result,
|
|
2890
|
+
turnCount: this.numTurns
|
|
2891
|
+
};
|
|
2892
|
+
if (this.structuredOutputError) {
|
|
2893
|
+
return {
|
|
2894
|
+
...base,
|
|
2895
|
+
subtype: "error_structured_output",
|
|
2896
|
+
isError: true,
|
|
2897
|
+
success: false,
|
|
2898
|
+
errors: [this.structuredOutputError.message],
|
|
2899
|
+
structuredOutput: this.structuredOutput,
|
|
2900
|
+
structuredOutputError: this.structuredOutputError,
|
|
2901
|
+
error: null
|
|
2902
|
+
};
|
|
2903
|
+
}
|
|
2904
|
+
if (this.errors.length > 0) {
|
|
2905
|
+
return {
|
|
2906
|
+
...base,
|
|
2907
|
+
subtype: "error_during_execution",
|
|
2908
|
+
isError: true,
|
|
2909
|
+
success: false,
|
|
2910
|
+
errors: this.errors.map((error) => error.message),
|
|
2911
|
+
structuredOutput: this.structuredOutput,
|
|
2912
|
+
structuredOutputError: null,
|
|
2913
|
+
error: this.errors[0] ?? null
|
|
2914
|
+
};
|
|
2915
|
+
}
|
|
2916
|
+
return {
|
|
2917
|
+
...base,
|
|
2918
|
+
subtype: "success",
|
|
2919
|
+
isError: false,
|
|
2920
|
+
success: true,
|
|
2921
|
+
structuredOutput: this.structuredOutput,
|
|
2922
|
+
structuredOutputError: null,
|
|
2923
|
+
error: null
|
|
2924
|
+
};
|
|
2925
|
+
}
|
|
2926
|
+
trackEmittedMessage(message) {
|
|
2927
|
+
if (isDefaultStreamMessage(message)) {
|
|
2928
|
+
this.emittedMessages.push(message);
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
resetTurnState() {
|
|
2932
|
+
this.lastTokenUsage = null;
|
|
2933
|
+
this.fullText = "";
|
|
2934
|
+
this.finalAssistantText = "";
|
|
2935
|
+
this.structuredOutput = null;
|
|
2936
|
+
this.structuredOutputError = null;
|
|
2937
|
+
this.errors = [];
|
|
2938
|
+
this.emittedMessages = [];
|
|
2939
|
+
}
|
|
2710
2940
|
};
|
|
2941
|
+
function isInternalMessage(message) {
|
|
2942
|
+
return message.type === "structured_output" || message.type === "tool_use" || message.type === "create_message";
|
|
2943
|
+
}
|
|
2944
|
+
function isDefaultStreamMessage(message) {
|
|
2945
|
+
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;
|
|
2946
|
+
}
|
|
2947
|
+
function stripTokenUsageType(message) {
|
|
2948
|
+
const {
|
|
2949
|
+
inputTokens,
|
|
2950
|
+
outputTokens,
|
|
2951
|
+
cacheCreationTokens,
|
|
2952
|
+
cacheReadTokens,
|
|
2953
|
+
thinkingTokens
|
|
2954
|
+
} = message;
|
|
2955
|
+
return {
|
|
2956
|
+
inputTokens,
|
|
2957
|
+
outputTokens,
|
|
2958
|
+
cacheCreationTokens,
|
|
2959
|
+
cacheReadTokens,
|
|
2960
|
+
thinkingTokens
|
|
2961
|
+
};
|
|
2962
|
+
}
|
|
2963
|
+
function parseJsonObject(text) {
|
|
2964
|
+
try {
|
|
2965
|
+
const parsed = JSON.parse(text);
|
|
2966
|
+
const result = JsonObjectSchema.safeParse(parsed);
|
|
2967
|
+
return result.success ? result.data : null;
|
|
2968
|
+
} catch {
|
|
2969
|
+
return null;
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2711
2972
|
function normalizeToolResultContent(content) {
|
|
2712
2973
|
if (content == null) {
|
|
2713
2974
|
return "";
|
|
@@ -2720,6 +2981,9 @@ function normalizeToolResultContent(content) {
|
|
|
2720
2981
|
}
|
|
2721
2982
|
return String(content);
|
|
2722
2983
|
}
|
|
2984
|
+
function extractTextFromMessage(message) {
|
|
2985
|
+
return message.content.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
2986
|
+
}
|
|
2723
2987
|
|
|
2724
2988
|
// src/helpers.ts
|
|
2725
2989
|
function wireAbortSignal(signal, onAbort) {
|
|
@@ -2740,10 +3004,20 @@ function extractInnerNotification(notification) {
|
|
|
2740
3004
|
return parsed.success ? parsed.data.params.notification : null;
|
|
2741
3005
|
}
|
|
2742
3006
|
var MessageBridge = class {
|
|
3007
|
+
constructor(onDone, _options = {}) {
|
|
3008
|
+
this._options = _options;
|
|
3009
|
+
this._onDone = onDone;
|
|
3010
|
+
this._stateTracker = new StreamStateTracker({
|
|
3011
|
+
sessionId: _options.sessionId,
|
|
3012
|
+
startedAt: _options.startedAt,
|
|
3013
|
+
hasOutputFormat: _options.outputFormat !== void 0
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
2743
3016
|
_queue = [];
|
|
3017
|
+
_onDone;
|
|
2744
3018
|
_resolveWaiting = null;
|
|
2745
3019
|
_done = false;
|
|
2746
|
-
_stateTracker
|
|
3020
|
+
_stateTracker;
|
|
2747
3021
|
notificationHandler = (notification) => {
|
|
2748
3022
|
const inner = extractInnerNotification(notification);
|
|
2749
3023
|
if (!inner) return;
|
|
@@ -2752,10 +3026,14 @@ var MessageBridge = class {
|
|
|
2752
3026
|
const messages = Array.isArray(converted) ? converted : [converted];
|
|
2753
3027
|
for (const msg of messages) {
|
|
2754
3028
|
const { message, additional } = this._stateTracker.processMessage(msg);
|
|
2755
|
-
this.
|
|
3029
|
+
if (message && this._shouldYield(message)) {
|
|
3030
|
+
this._enqueue(message);
|
|
3031
|
+
}
|
|
2756
3032
|
for (const extra of additional) {
|
|
2757
|
-
this.
|
|
2758
|
-
|
|
3033
|
+
if (this._shouldYield(extra)) {
|
|
3034
|
+
this._enqueue(extra);
|
|
3035
|
+
}
|
|
3036
|
+
if (extra.type === DroidMessageType.Result) {
|
|
2759
3037
|
this._signalDone();
|
|
2760
3038
|
}
|
|
2761
3039
|
}
|
|
@@ -2769,7 +3047,7 @@ var MessageBridge = class {
|
|
|
2769
3047
|
while (this._queue.length > 0) {
|
|
2770
3048
|
const msg = this._queue.shift();
|
|
2771
3049
|
yield msg;
|
|
2772
|
-
if (msg.type === DroidMessageType.
|
|
3050
|
+
if (msg.type === DroidMessageType.Result) {
|
|
2773
3051
|
return;
|
|
2774
3052
|
}
|
|
2775
3053
|
}
|
|
@@ -2781,6 +3059,12 @@ var MessageBridge = class {
|
|
|
2781
3059
|
});
|
|
2782
3060
|
}
|
|
2783
3061
|
}
|
|
3062
|
+
_shouldYield(message) {
|
|
3063
|
+
if (isInternalMessage(message)) {
|
|
3064
|
+
return false;
|
|
3065
|
+
}
|
|
3066
|
+
return this._options.includePartialMessages ? true : isDefaultStreamMessage(message);
|
|
3067
|
+
}
|
|
2784
3068
|
_enqueue(msg) {
|
|
2785
3069
|
this._queue.push(msg);
|
|
2786
3070
|
if (this._resolveWaiting) {
|
|
@@ -2790,7 +3074,11 @@ var MessageBridge = class {
|
|
|
2790
3074
|
}
|
|
2791
3075
|
}
|
|
2792
3076
|
_signalDone() {
|
|
3077
|
+
const wasDone = this._done;
|
|
2793
3078
|
this._done = true;
|
|
3079
|
+
if (!wasDone) {
|
|
3080
|
+
this._onDone?.();
|
|
3081
|
+
}
|
|
2794
3082
|
if (this._resolveWaiting) {
|
|
2795
3083
|
const resolve2 = this._resolveWaiting;
|
|
2796
3084
|
this._resolveWaiting = null;
|
|
@@ -2873,7 +3161,7 @@ import { once } from "events";
|
|
|
2873
3161
|
import http from "http";
|
|
2874
3162
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2875
3163
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
2876
|
-
import { z as
|
|
3164
|
+
import { z as z9 } from "zod";
|
|
2877
3165
|
function tool(name, description, inputSchemaOrHandler, handler) {
|
|
2878
3166
|
if (typeof inputSchemaOrHandler === "function") {
|
|
2879
3167
|
const actualHandler = inputSchemaOrHandler;
|
|
@@ -2886,7 +3174,7 @@ function tool(name, description, inputSchemaOrHandler, handler) {
|
|
|
2886
3174
|
if (!handler) {
|
|
2887
3175
|
throw new Error(`Missing handler for SDK MCP tool "${name}"`);
|
|
2888
3176
|
}
|
|
2889
|
-
const inputObjectSchema =
|
|
3177
|
+
const inputObjectSchema = z9.object(inputSchemaOrHandler);
|
|
2890
3178
|
return {
|
|
2891
3179
|
name,
|
|
2892
3180
|
description,
|
|
@@ -3063,162 +3351,6 @@ async function startSdkMcpServers(servers) {
|
|
|
3063
3351
|
};
|
|
3064
3352
|
}
|
|
3065
3353
|
|
|
3066
|
-
// src/query.ts
|
|
3067
|
-
var DroidQueryImpl = class {
|
|
3068
|
-
_generator;
|
|
3069
|
-
_getSessionId;
|
|
3070
|
-
_getInitResult;
|
|
3071
|
-
_getInitialized;
|
|
3072
|
-
_interruptFn;
|
|
3073
|
-
_abortFn;
|
|
3074
|
-
constructor(generator, getSessionId, getInitResult, getInitialized, interruptFn, abortFn) {
|
|
3075
|
-
this._generator = generator;
|
|
3076
|
-
this._getSessionId = getSessionId;
|
|
3077
|
-
this._getInitResult = getInitResult;
|
|
3078
|
-
this._getInitialized = getInitialized;
|
|
3079
|
-
this._interruptFn = interruptFn;
|
|
3080
|
-
this._abortFn = abortFn;
|
|
3081
|
-
}
|
|
3082
|
-
get sessionId() {
|
|
3083
|
-
return this._getSessionId();
|
|
3084
|
-
}
|
|
3085
|
-
get initResult() {
|
|
3086
|
-
return this._getInitResult();
|
|
3087
|
-
}
|
|
3088
|
-
get initialized() {
|
|
3089
|
-
return this._getInitialized();
|
|
3090
|
-
}
|
|
3091
|
-
async interrupt() {
|
|
3092
|
-
return this._interruptFn();
|
|
3093
|
-
}
|
|
3094
|
-
abort() {
|
|
3095
|
-
this._abortFn();
|
|
3096
|
-
}
|
|
3097
|
-
next(...args) {
|
|
3098
|
-
return this._generator.next(...args);
|
|
3099
|
-
}
|
|
3100
|
-
return(value) {
|
|
3101
|
-
return this._generator.return(value);
|
|
3102
|
-
}
|
|
3103
|
-
throw(e) {
|
|
3104
|
-
return this._generator.throw(e);
|
|
3105
|
-
}
|
|
3106
|
-
[Symbol.asyncIterator]() {
|
|
3107
|
-
return this;
|
|
3108
|
-
}
|
|
3109
|
-
};
|
|
3110
|
-
function query(options) {
|
|
3111
|
-
let transport = null;
|
|
3112
|
-
let client = null;
|
|
3113
|
-
let sessionId = null;
|
|
3114
|
-
let initResult = null;
|
|
3115
|
-
let aborted = false;
|
|
3116
|
-
let initializationPromise = null;
|
|
3117
|
-
let promptPromise = null;
|
|
3118
|
-
let cleanupAbortSignal = () => {
|
|
3119
|
-
};
|
|
3120
|
-
let cleanupSdkMcpServers = null;
|
|
3121
|
-
const bridge = new MessageBridge();
|
|
3122
|
-
const closeActiveResources = async () => {
|
|
3123
|
-
const closer = client ?? transport;
|
|
3124
|
-
const cleanupMcp = cleanupSdkMcpServers;
|
|
3125
|
-
client = null;
|
|
3126
|
-
transport = null;
|
|
3127
|
-
cleanupSdkMcpServers = null;
|
|
3128
|
-
await Promise.all([closeQuietly(closer), cleanupMcp?.()]);
|
|
3129
|
-
};
|
|
3130
|
-
const ensureInitialized = () => {
|
|
3131
|
-
if (initResult) {
|
|
3132
|
-
return Promise.resolve(initResult);
|
|
3133
|
-
}
|
|
3134
|
-
if (initializationPromise) {
|
|
3135
|
-
return initializationPromise;
|
|
3136
|
-
}
|
|
3137
|
-
initializationPromise = (async () => {
|
|
3138
|
-
try {
|
|
3139
|
-
if (aborted) {
|
|
3140
|
-
throw new Error("Query aborted before initialization");
|
|
3141
|
-
}
|
|
3142
|
-
const configuredClient = await createConfiguredClient(options);
|
|
3143
|
-
transport = configuredClient.transport;
|
|
3144
|
-
client = configuredClient.client;
|
|
3145
|
-
client.onNotification(bridge.notificationHandler);
|
|
3146
|
-
if (aborted) {
|
|
3147
|
-
throw new Error("Query aborted before initialization");
|
|
3148
|
-
}
|
|
3149
|
-
const sdkMcpServers = await startSdkMcpServers(options.mcpServers);
|
|
3150
|
-
cleanupSdkMcpServers = sdkMcpServers.cleanup;
|
|
3151
|
-
const result = await client.initializeSession(
|
|
3152
|
-
buildInitParams({
|
|
3153
|
-
...options,
|
|
3154
|
-
mcpServers: sdkMcpServers.mcpServers
|
|
3155
|
-
})
|
|
3156
|
-
);
|
|
3157
|
-
sessionId = result.sessionId;
|
|
3158
|
-
initResult = result;
|
|
3159
|
-
return result;
|
|
3160
|
-
} catch (error) {
|
|
3161
|
-
await closeActiveResources();
|
|
3162
|
-
throw error;
|
|
3163
|
-
}
|
|
3164
|
-
})();
|
|
3165
|
-
return initializationPromise;
|
|
3166
|
-
};
|
|
3167
|
-
const ensurePromptSent = () => {
|
|
3168
|
-
if (promptPromise) {
|
|
3169
|
-
return promptPromise;
|
|
3170
|
-
}
|
|
3171
|
-
promptPromise = (async () => {
|
|
3172
|
-
await ensureInitialized();
|
|
3173
|
-
if (aborted || client === null) {
|
|
3174
|
-
return;
|
|
3175
|
-
}
|
|
3176
|
-
await client.addUserMessage({ text: options.prompt });
|
|
3177
|
-
})();
|
|
3178
|
-
return promptPromise;
|
|
3179
|
-
};
|
|
3180
|
-
async function* generateMessages() {
|
|
3181
|
-
if (aborted) return;
|
|
3182
|
-
await ensurePromptSent();
|
|
3183
|
-
if (aborted) return;
|
|
3184
|
-
for await (const msg of bridge.messages()) {
|
|
3185
|
-
if (aborted) return;
|
|
3186
|
-
yield msg;
|
|
3187
|
-
}
|
|
3188
|
-
}
|
|
3189
|
-
const generator = generateMessages();
|
|
3190
|
-
async function* wrappedGenerator() {
|
|
3191
|
-
try {
|
|
3192
|
-
yield* generator;
|
|
3193
|
-
} finally {
|
|
3194
|
-
cleanupAbortSignal();
|
|
3195
|
-
await closeActiveResources();
|
|
3196
|
-
}
|
|
3197
|
-
}
|
|
3198
|
-
const droidQuery = new DroidQueryImpl(
|
|
3199
|
-
wrappedGenerator(),
|
|
3200
|
-
() => sessionId,
|
|
3201
|
-
() => initResult,
|
|
3202
|
-
() => ensureInitialized(),
|
|
3203
|
-
async () => {
|
|
3204
|
-
if (client && !aborted) {
|
|
3205
|
-
await client.interruptSession();
|
|
3206
|
-
}
|
|
3207
|
-
},
|
|
3208
|
-
() => {
|
|
3209
|
-
aborted = true;
|
|
3210
|
-
bridge.signalDone();
|
|
3211
|
-
cleanupAbortSignal();
|
|
3212
|
-
void closeActiveResources();
|
|
3213
|
-
}
|
|
3214
|
-
);
|
|
3215
|
-
cleanupAbortSignal = wireAbortSignal(
|
|
3216
|
-
options.abortSignal,
|
|
3217
|
-
() => droidQuery.abort()
|
|
3218
|
-
);
|
|
3219
|
-
return droidQuery;
|
|
3220
|
-
}
|
|
3221
|
-
|
|
3222
3354
|
// src/session.ts
|
|
3223
3355
|
function getAbortError(signal) {
|
|
3224
3356
|
if (signal.reason instanceof Error) {
|
|
@@ -3233,24 +3365,6 @@ function throwIfAborted(signal) {
|
|
|
3233
3365
|
throw getAbortError(signal);
|
|
3234
3366
|
}
|
|
3235
3367
|
}
|
|
3236
|
-
function parseJsonObject(text) {
|
|
3237
|
-
try {
|
|
3238
|
-
const parsed = JSON.parse(text);
|
|
3239
|
-
const result = JsonObjectSchema.safeParse(parsed);
|
|
3240
|
-
return result.success ? result.data : null;
|
|
3241
|
-
} catch {
|
|
3242
|
-
return null;
|
|
3243
|
-
}
|
|
3244
|
-
}
|
|
3245
|
-
function extractAssistantText(message) {
|
|
3246
|
-
if (message.type !== DroidMessageType.CreateMessage) {
|
|
3247
|
-
return "";
|
|
3248
|
-
}
|
|
3249
|
-
if (message.role !== FactoryDroidMessageRole.Assistant) {
|
|
3250
|
-
return "";
|
|
3251
|
-
}
|
|
3252
|
-
return message.content.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
3253
|
-
}
|
|
3254
3368
|
var DroidSession = class {
|
|
3255
3369
|
_client;
|
|
3256
3370
|
_sessionId;
|
|
@@ -3258,6 +3372,7 @@ var DroidSession = class {
|
|
|
3258
3372
|
_closed = false;
|
|
3259
3373
|
_cleanupAbortSignal = null;
|
|
3260
3374
|
_cleanupCallbacks = [];
|
|
3375
|
+
_activeBridges = /* @__PURE__ */ new Set();
|
|
3261
3376
|
/** @internal */
|
|
3262
3377
|
constructor(client, sessionId, initResult) {
|
|
3263
3378
|
this._client = client;
|
|
@@ -3278,11 +3393,22 @@ var DroidSession = class {
|
|
|
3278
3393
|
addCleanup(cleanup) {
|
|
3279
3394
|
this._cleanupCallbacks.push(cleanup);
|
|
3280
3395
|
}
|
|
3281
|
-
|
|
3282
|
-
async *stream(text, options) {
|
|
3396
|
+
async *stream(prompt, options) {
|
|
3283
3397
|
this._ensureNotClosed();
|
|
3284
3398
|
throwIfAborted(options?.abortSignal);
|
|
3285
|
-
const
|
|
3399
|
+
const startedAt = Date.now();
|
|
3400
|
+
let resolveDone = () => {
|
|
3401
|
+
};
|
|
3402
|
+
const donePromise = new Promise((resolve2) => {
|
|
3403
|
+
resolveDone = resolve2;
|
|
3404
|
+
});
|
|
3405
|
+
const bridge = new MessageBridge(resolveDone, {
|
|
3406
|
+
includePartialMessages: options?.includePartialMessages,
|
|
3407
|
+
sessionId: this._sessionId,
|
|
3408
|
+
startedAt,
|
|
3409
|
+
outputFormat: options?.outputFormat
|
|
3410
|
+
});
|
|
3411
|
+
this._activeBridges.add(bridge);
|
|
3286
3412
|
const unsubscribe = this._client.onNotification(bridge.notificationHandler);
|
|
3287
3413
|
let resolveAbort = () => {
|
|
3288
3414
|
};
|
|
@@ -3298,11 +3424,12 @@ var DroidSession = class {
|
|
|
3298
3424
|
try {
|
|
3299
3425
|
await Promise.race([
|
|
3300
3426
|
this._client.addUserMessage({
|
|
3301
|
-
text,
|
|
3427
|
+
text: prompt,
|
|
3302
3428
|
images: options?.images,
|
|
3303
3429
|
files: options?.files,
|
|
3304
3430
|
outputFormat: options?.outputFormat
|
|
3305
3431
|
}),
|
|
3432
|
+
donePromise,
|
|
3306
3433
|
abortPromise
|
|
3307
3434
|
]);
|
|
3308
3435
|
throwIfAborted(options?.abortSignal);
|
|
@@ -3314,62 +3441,9 @@ var DroidSession = class {
|
|
|
3314
3441
|
} finally {
|
|
3315
3442
|
cleanupAbortSignal();
|
|
3316
3443
|
unsubscribe();
|
|
3444
|
+
this._activeBridges.delete(bridge);
|
|
3317
3445
|
}
|
|
3318
3446
|
}
|
|
3319
|
-
/** Consumes the stream and returns an aggregated {@link DroidResult}. */
|
|
3320
|
-
async send(text, options) {
|
|
3321
|
-
this._ensureNotClosed();
|
|
3322
|
-
const messages = [];
|
|
3323
|
-
let fullText = "";
|
|
3324
|
-
let lastTokenUsage = null;
|
|
3325
|
-
let firstError = null;
|
|
3326
|
-
let structuredOutput = null;
|
|
3327
|
-
let finalAssistantText = "";
|
|
3328
|
-
let turnCount = 0;
|
|
3329
|
-
const startedAt = Date.now();
|
|
3330
|
-
for await (const msg of this.stream(text, options)) {
|
|
3331
|
-
messages.push(msg);
|
|
3332
|
-
if (msg.type === DroidMessageType.AssistantTextDelta) {
|
|
3333
|
-
fullText += msg.text;
|
|
3334
|
-
}
|
|
3335
|
-
const assistantText = extractAssistantText(msg);
|
|
3336
|
-
if (assistantText) {
|
|
3337
|
-
finalAssistantText = assistantText;
|
|
3338
|
-
if (options?.outputFormat && fullText.length === 0) {
|
|
3339
|
-
fullText = assistantText;
|
|
3340
|
-
}
|
|
3341
|
-
}
|
|
3342
|
-
if (msg.type === DroidMessageType.TokenUsageUpdate) {
|
|
3343
|
-
lastTokenUsage = msg;
|
|
3344
|
-
}
|
|
3345
|
-
if (msg.type === DroidMessageType.Error && firstError === null) {
|
|
3346
|
-
firstError = msg;
|
|
3347
|
-
}
|
|
3348
|
-
if (options?.outputFormat && structuredOutput === null) {
|
|
3349
|
-
const textToParse = finalAssistantText || fullText;
|
|
3350
|
-
if (textToParse) {
|
|
3351
|
-
structuredOutput = parseJsonObject(textToParse);
|
|
3352
|
-
}
|
|
3353
|
-
}
|
|
3354
|
-
if (msg.type === DroidMessageType.TurnComplete) {
|
|
3355
|
-
turnCount++;
|
|
3356
|
-
if (msg.tokenUsage) {
|
|
3357
|
-
lastTokenUsage = msg.tokenUsage;
|
|
3358
|
-
}
|
|
3359
|
-
}
|
|
3360
|
-
}
|
|
3361
|
-
return {
|
|
3362
|
-
sessionId: this._sessionId,
|
|
3363
|
-
text: fullText,
|
|
3364
|
-
messages,
|
|
3365
|
-
tokenUsage: lastTokenUsage,
|
|
3366
|
-
durationMs: Date.now() - startedAt,
|
|
3367
|
-
turnCount,
|
|
3368
|
-
error: firstError,
|
|
3369
|
-
structuredOutput,
|
|
3370
|
-
success: firstError === null
|
|
3371
|
-
};
|
|
3372
|
-
}
|
|
3373
3447
|
async interrupt() {
|
|
3374
3448
|
this._ensureNotClosed();
|
|
3375
3449
|
await this._client.interruptSession();
|
|
@@ -3381,7 +3455,12 @@ var DroidSession = class {
|
|
|
3381
3455
|
this._closed = true;
|
|
3382
3456
|
this._cleanupAbortSignal?.();
|
|
3383
3457
|
this._cleanupAbortSignal = null;
|
|
3458
|
+
for (const bridge of this._activeBridges) {
|
|
3459
|
+
bridge.signalDone();
|
|
3460
|
+
}
|
|
3384
3461
|
try {
|
|
3462
|
+
await this._client.closeSession({ reason: "other" }).catch(() => {
|
|
3463
|
+
});
|
|
3385
3464
|
await this._client.close();
|
|
3386
3465
|
} finally {
|
|
3387
3466
|
const cleanups = this._cleanupCallbacks.splice(0);
|
|
@@ -3520,10 +3599,18 @@ async function resumeSession(sessionId, options = {}) {
|
|
|
3520
3599
|
}
|
|
3521
3600
|
|
|
3522
3601
|
// src/run.ts
|
|
3523
|
-
async function run(
|
|
3602
|
+
async function run(prompt, options = {}) {
|
|
3524
3603
|
const session = await createSession(options);
|
|
3525
3604
|
try {
|
|
3526
|
-
|
|
3605
|
+
for await (const msg of session.stream(prompt, {
|
|
3606
|
+
...options,
|
|
3607
|
+
includePartialMessages: false
|
|
3608
|
+
})) {
|
|
3609
|
+
if (msg.type === DroidMessageType.Result) {
|
|
3610
|
+
return msg;
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
throw new Error("Stream completed without a result message");
|
|
3527
3614
|
} finally {
|
|
3528
3615
|
await session.close();
|
|
3529
3616
|
}
|
|
@@ -3769,6 +3856,7 @@ export {
|
|
|
3769
3856
|
AskUserRequestSchema,
|
|
3770
3857
|
AskUserResponseSchema,
|
|
3771
3858
|
AskUserResultSchema,
|
|
3859
|
+
AssistantTextCompleteNotificationSchema,
|
|
3772
3860
|
AssistantTextDeltaNotificationSchema,
|
|
3773
3861
|
AuthenticateMcpServerRequestParamsSchema,
|
|
3774
3862
|
AuthenticateMcpServerRequestSchema,
|
|
@@ -3793,6 +3881,10 @@ export {
|
|
|
3793
3881
|
ClearMcpAuthResultSchema,
|
|
3794
3882
|
CliRequestOrNotificationSchema,
|
|
3795
3883
|
ClientRequestSchema,
|
|
3884
|
+
CloseSessionRequestParamsSchema,
|
|
3885
|
+
CloseSessionRequestSchema,
|
|
3886
|
+
CloseSessionResponseSchema,
|
|
3887
|
+
CloseSessionResultSchema,
|
|
3796
3888
|
CompactSessionRequestParamsSchema,
|
|
3797
3889
|
CompactSessionRequestSchema,
|
|
3798
3890
|
CompactSessionResponseSchema,
|
|
@@ -3813,6 +3905,10 @@ export {
|
|
|
3813
3905
|
DroidClient,
|
|
3814
3906
|
DroidClientMethod,
|
|
3815
3907
|
DroidErrorType,
|
|
3908
|
+
DroidHookEventSchema,
|
|
3909
|
+
DroidHookExecutionResultSchema,
|
|
3910
|
+
DroidHookOutputSchema,
|
|
3911
|
+
DroidHookSpecificOutputSchema,
|
|
3816
3912
|
DroidInteractionMode,
|
|
3817
3913
|
DroidMessageType,
|
|
3818
3914
|
DroidServerMethod,
|
|
@@ -3853,6 +3949,10 @@ export {
|
|
|
3853
3949
|
GitRepoInfoSchema,
|
|
3854
3950
|
HandoffItemsDismissedEntrySchema,
|
|
3855
3951
|
HandoffSchema,
|
|
3952
|
+
HookCommandSchema,
|
|
3953
|
+
HookExecutionCompletedNotificationSchema,
|
|
3954
|
+
HookExecutionStartedNotificationSchema,
|
|
3955
|
+
HookResultSchema,
|
|
3856
3956
|
HttpHeaderSchema,
|
|
3857
3957
|
HttpMcpConfigSchema,
|
|
3858
3958
|
ImageBlockSchema,
|
|
@@ -4001,6 +4101,8 @@ export {
|
|
|
4001
4101
|
StartMissionRunConfirmationDetailsSchema,
|
|
4002
4102
|
StdioMcpConfigSchema,
|
|
4003
4103
|
StreamStateTracker,
|
|
4104
|
+
StructuredOutputErrorSchema,
|
|
4105
|
+
StructuredOutputNotificationSchema,
|
|
4004
4106
|
SubmitBugReportRequestParamsSchema,
|
|
4005
4107
|
SubmitBugReportRequestSchema,
|
|
4006
4108
|
SubmitBugReportResponseSchema,
|
|
@@ -4015,6 +4117,7 @@ export {
|
|
|
4015
4117
|
TestsSchema,
|
|
4016
4118
|
TextBlockSchema,
|
|
4017
4119
|
ThinkingBlockSchema,
|
|
4120
|
+
ThinkingTextCompleteNotificationSchema,
|
|
4018
4121
|
ThinkingTextDeltaNotificationSchema,
|
|
4019
4122
|
TimeoutError,
|
|
4020
4123
|
ToggleMcpServerRequestParamsSchema,
|
|
@@ -4026,6 +4129,7 @@ export {
|
|
|
4026
4129
|
ToggleMcpToolResponseSchema,
|
|
4027
4130
|
ToggleMcpToolResultSchema,
|
|
4028
4131
|
TokenUsageSchema,
|
|
4132
|
+
ToolCallNotificationSchema,
|
|
4029
4133
|
ToolConfirmationDetailsSchema,
|
|
4030
4134
|
ToolConfirmationInfoSchema,
|
|
4031
4135
|
ToolConfirmationListItemSchema,
|
|
@@ -4052,10 +4156,11 @@ export {
|
|
|
4052
4156
|
WorkerStartedEntrySchema,
|
|
4053
4157
|
WorkerStateInfoSchema,
|
|
4054
4158
|
convertNotificationToStreamMessage,
|
|
4159
|
+
createResponseSchema,
|
|
4055
4160
|
createSdkMcpServer,
|
|
4056
4161
|
createSession,
|
|
4162
|
+
dispatchNotification,
|
|
4057
4163
|
listSessions,
|
|
4058
|
-
query,
|
|
4059
4164
|
resumeSession,
|
|
4060
4165
|
run,
|
|
4061
4166
|
tool
|