@factory/droid-sdk 0.7.0 → 0.9.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/dist/{chunk-C3KHERVH.js → chunk-FJP5OKS5.js} +6250 -4329
- package/dist/chunk-FJP5OKS5.js.map +1 -0
- package/dist/{chunk-5UXINOXG.mjs → chunk-KXDG5ZWS.mjs} +8897 -6976
- package/dist/chunk-KXDG5ZWS.mjs.map +1 -0
- package/dist/{index-D_SzTnFR.d.mts → index-BowvC0_E.d.mts} +43128 -10981
- package/dist/{index-D_SzTnFR.d.ts → index-BowvC0_E.d.ts} +43128 -10981
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -1
- package/dist/node.d.mts +25 -3
- package/dist/node.d.ts +25 -3
- package/dist/node.js +565 -423
- package/dist/node.js.map +1 -1
- package/dist/node.mjs +186 -44
- package/dist/node.mjs.map +1 -1
- package/docs/typescript-sdk-reference.md +903 -726
- package/examples/browser/daemon-model-discovery.ts +47 -0
- package/examples/browser/index.html +2 -1
- package/examples/browser/list-sessions.ts +1 -3
- package/examples/node/abort-session-stream.ts +2 -0
- package/examples/node/ask-user-elicitation.ts +11 -7
- package/examples/node/compact-session.ts +33 -18
- package/examples/node/custom-system-prompt.ts +35 -0
- package/examples/node/document-input.ts +58 -0
- package/examples/node/enter-spec-mode.ts +50 -29
- package/examples/node/external-mcp.ts +45 -0
- package/examples/node/fork-session.ts +21 -10
- package/examples/node/hook-execution.ts +37 -37
- package/examples/node/image-attachment.ts +8 -2
- package/examples/node/interrupt-session.ts +27 -8
- package/examples/node/model-discovery.ts +28 -0
- package/examples/node/model-selection.ts +35 -0
- package/examples/node/multi-turn-session.ts +4 -0
- package/examples/node/observability.ts +4 -17
- package/examples/node/partial-stream.ts +56 -0
- package/examples/node/permission-handler.ts +9 -4
- package/examples/node/rename-session.ts +7 -3
- package/examples/node/result-metadata.ts +10 -1
- package/examples/node/resume-session.ts +41 -0
- package/examples/node/rewind-session.ts +19 -9
- package/examples/node/run.ts +14 -7
- package/examples/node/sdk-mcp-tool.ts +10 -8
- package/examples/node/session-settings.ts +9 -9
- package/examples/node/session-stream.ts +17 -2
- package/examples/node/skills.ts +24 -0
- package/examples/node/spec-mode-new-session.ts +38 -10
- package/examples/node/spec-mode-same-session.ts +37 -3
- package/examples/node/structured-output.ts +30 -7
- package/package.json +1 -1
- package/dist/chunk-5UXINOXG.mjs.map +0 -1
- package/dist/chunk-C3KHERVH.js.map +0 -1
package/dist/node.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
AddUserMessageRequestSchema,
|
|
9
9
|
AddUserMessageResponseSchema,
|
|
10
10
|
AddUserMessageResultSchema,
|
|
11
|
+
AppendMessagesResponseSchema,
|
|
11
12
|
ApplyPatchToolConfirmationDetailsSchema,
|
|
12
13
|
AskUserCollectedAnswerSchema,
|
|
13
14
|
AskUserConfirmationDetailsSchema,
|
|
@@ -194,6 +195,9 @@ import {
|
|
|
194
195
|
ListMcpToolsRequestSchema,
|
|
195
196
|
ListMcpToolsResponseSchema,
|
|
196
197
|
ListMcpToolsResultSchema,
|
|
198
|
+
ListModelsOptionsSchema,
|
|
199
|
+
ListModelsResponseSchema,
|
|
200
|
+
ListModelsResultSchema,
|
|
197
201
|
ListSkillsRequestParamsSchema,
|
|
198
202
|
ListSkillsRequestSchema,
|
|
199
203
|
ListSkillsResponseSchema,
|
|
@@ -247,6 +251,8 @@ import {
|
|
|
247
251
|
MissionStateSchema,
|
|
248
252
|
MissionWorkerCompletedNotificationSchema,
|
|
249
253
|
MissionWorkerStartedNotificationSchema,
|
|
254
|
+
ModelInfoSchema,
|
|
255
|
+
ModelMetadataSchema,
|
|
250
256
|
ModelProvider,
|
|
251
257
|
MultiMissionStateManager,
|
|
252
258
|
MultiSessionStateManager,
|
|
@@ -284,6 +290,8 @@ import {
|
|
|
284
290
|
RewindEvictedFileSchema,
|
|
285
291
|
RewindFileCreationSchema,
|
|
286
292
|
RewindFileSnapshotSchema,
|
|
293
|
+
SDK_CLIENT_METADATA,
|
|
294
|
+
SDK_REQUEST_ATTRIBUTION,
|
|
287
295
|
SDK_TAG,
|
|
288
296
|
SDK_VERSION,
|
|
289
297
|
SESSION_INIT_TIMEOUT,
|
|
@@ -399,6 +407,7 @@ import {
|
|
|
399
407
|
deleteComputer,
|
|
400
408
|
extractInnerNotification,
|
|
401
409
|
filterMessagesForUI,
|
|
410
|
+
formatSdkClientMetadata,
|
|
402
411
|
getComputer,
|
|
403
412
|
getComputerByName,
|
|
404
413
|
getComputerMetrics,
|
|
@@ -434,8 +443,9 @@ import {
|
|
|
434
443
|
toError,
|
|
435
444
|
unwrapResponseResult,
|
|
436
445
|
updateComputer,
|
|
437
|
-
wireAbortSignal
|
|
438
|
-
|
|
446
|
+
wireAbortSignal,
|
|
447
|
+
withSdkTag
|
|
448
|
+
} from "./chunk-KXDG5ZWS.mjs";
|
|
439
449
|
|
|
440
450
|
// src/exec-core/client.ts
|
|
441
451
|
import EventEmitter from "events";
|
|
@@ -797,6 +807,7 @@ function inspectJsonRpcEnvelope2(message) {
|
|
|
797
807
|
var DroidClient = class _DroidClient extends EventEmitter {
|
|
798
808
|
transport;
|
|
799
809
|
requestTimeout;
|
|
810
|
+
sessionInitTimeout;
|
|
800
811
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
801
812
|
permissionHandlers = /* @__PURE__ */ new Map();
|
|
802
813
|
askUserHandlers = /* @__PURE__ */ new Map();
|
|
@@ -810,9 +821,11 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
810
821
|
* requests from hanging on a dead transport.
|
|
811
822
|
*/
|
|
812
823
|
transportError = null;
|
|
824
|
+
completedTurnObserved = false;
|
|
813
825
|
logger;
|
|
814
826
|
tracing;
|
|
815
827
|
onRequestSettled;
|
|
828
|
+
getRequestAttribution;
|
|
816
829
|
constructor(options, deps = defaultExecCoreDeps) {
|
|
817
830
|
super();
|
|
818
831
|
this.transport = options.transport;
|
|
@@ -820,7 +833,9 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
820
833
|
this.logger = resolved.logger;
|
|
821
834
|
this.tracing = resolved.tracing;
|
|
822
835
|
this.requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT2;
|
|
836
|
+
this.sessionInitTimeout = options.sessionInitTimeout ?? SESSION_INIT_TIMEOUT2;
|
|
823
837
|
this.onRequestSettled = options.onRequestSettled;
|
|
838
|
+
this.getRequestAttribution = options.getRequestAttribution;
|
|
824
839
|
this.transport.onMessage((message) => {
|
|
825
840
|
void this.handleMessage(message).catch((error) => {
|
|
826
841
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
@@ -834,7 +849,14 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
834
849
|
});
|
|
835
850
|
this.transport.onError((error) => {
|
|
836
851
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
837
|
-
|
|
852
|
+
const expectedCleanExit = err instanceof ProcessExitError && err.exitCode === 0 && this.completedTurnObserved;
|
|
853
|
+
if (expectedCleanExit) {
|
|
854
|
+
this.logger.info("[DroidClient] Process exited after completed turn", {
|
|
855
|
+
exitCode: err.exitCode
|
|
856
|
+
});
|
|
857
|
+
} else {
|
|
858
|
+
this.logger.exception(err, "Transport error");
|
|
859
|
+
}
|
|
838
860
|
this.transportError = err;
|
|
839
861
|
this.rejectAllPending(err);
|
|
840
862
|
if (this.listenerCount("error" /* ERROR */) > 0) {
|
|
@@ -883,7 +905,10 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
883
905
|
method: "droid.initialize_session" /* INITIALIZE_SESSION */,
|
|
884
906
|
params
|
|
885
907
|
};
|
|
886
|
-
const rawResponse = await this.sendRequest(
|
|
908
|
+
const rawResponse = await this.sendRequest(
|
|
909
|
+
request,
|
|
910
|
+
this.sessionInitTimeout
|
|
911
|
+
);
|
|
887
912
|
const response = InitializeSessionResponseSchema.parse(rawResponse);
|
|
888
913
|
this.peerProtocolVersion = response.factoryProtocolVersion;
|
|
889
914
|
if (response.error) {
|
|
@@ -909,7 +934,10 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
909
934
|
method: "droid.load_session" /* LOAD_SESSION */,
|
|
910
935
|
params
|
|
911
936
|
};
|
|
912
|
-
const rawResponse = await this.sendRequest(
|
|
937
|
+
const rawResponse = await this.sendRequest(
|
|
938
|
+
request,
|
|
939
|
+
this.sessionInitTimeout
|
|
940
|
+
);
|
|
913
941
|
const response = LoadSessionResponseSchema.parse(rawResponse);
|
|
914
942
|
this.peerProtocolVersion = response.factoryProtocolVersion;
|
|
915
943
|
if (response.error) {
|
|
@@ -939,6 +967,7 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
939
967
|
"No active session. Call initializeSession or loadSession first."
|
|
940
968
|
);
|
|
941
969
|
}
|
|
970
|
+
this.completedTurnObserved = false;
|
|
942
971
|
const request = {
|
|
943
972
|
factoryApiVersion: LEGACY_FACTORY_API_VERSION,
|
|
944
973
|
factoryProtocolVersion: FACTORY_PROTOCOL_VERSION,
|
|
@@ -947,16 +976,8 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
947
976
|
id: requestId ?? uuidv4(),
|
|
948
977
|
method: "droid.add_user_message" /* ADD_USER_MESSAGE */,
|
|
949
978
|
params: {
|
|
950
|
-
...params
|
|
951
|
-
|
|
952
|
-
images: params.images,
|
|
953
|
-
imagePaths: params.imagePaths,
|
|
954
|
-
files: params.files,
|
|
955
|
-
outputFormat: params.outputFormat,
|
|
956
|
-
...params.skipAgentLoop && { skipAgentLoop: params.skipAgentLoop },
|
|
957
|
-
queuePlacement: params.queuePlacement ?? "end_of_turn" /* EndOfTurn */,
|
|
958
|
-
...params.role && { role: params.role },
|
|
959
|
-
...params.visibility && { visibility: params.visibility }
|
|
979
|
+
...params,
|
|
980
|
+
queuePlacement: params.queuePlacement ?? "end_of_turn" /* EndOfTurn */
|
|
960
981
|
}
|
|
961
982
|
};
|
|
962
983
|
const rawResponse = await this.sendRequest(request);
|
|
@@ -971,6 +992,39 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
971
992
|
}
|
|
972
993
|
return response;
|
|
973
994
|
}
|
|
995
|
+
/**
|
|
996
|
+
* Persists user-only messages without starting an agent turn.
|
|
997
|
+
*
|
|
998
|
+
* Use for daemon-owned activity that belongs in session history but was not
|
|
999
|
+
* produced by the agent, such as commands run while a session starts.
|
|
1000
|
+
*/
|
|
1001
|
+
async appendMessages(params, requestId) {
|
|
1002
|
+
if (!this.currentSessionId) {
|
|
1003
|
+
throw new SessionError(
|
|
1004
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
const request = {
|
|
1008
|
+
factoryApiVersion: LEGACY_FACTORY_API_VERSION,
|
|
1009
|
+
factoryProtocolVersion: FACTORY_PROTOCOL_VERSION,
|
|
1010
|
+
type: "request",
|
|
1011
|
+
jsonrpc: JSONRPC_VERSION2,
|
|
1012
|
+
id: requestId ?? uuidv4(),
|
|
1013
|
+
method: "droid.append_messages" /* APPEND_MESSAGES */,
|
|
1014
|
+
params
|
|
1015
|
+
};
|
|
1016
|
+
const rawResponse = await this.sendRequest(request);
|
|
1017
|
+
const response = AppendMessagesResponseSchema.parse(rawResponse);
|
|
1018
|
+
if (response.error) {
|
|
1019
|
+
throw new ProtocolError("Append messages request failed", {
|
|
1020
|
+
requestId: request.id,
|
|
1021
|
+
code: response.error.code,
|
|
1022
|
+
message: response.error.message,
|
|
1023
|
+
data: response.error.data
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
return response;
|
|
1027
|
+
}
|
|
974
1028
|
async resolveQueuedUserMessage(params) {
|
|
975
1029
|
if (!this.currentSessionId) {
|
|
976
1030
|
throw new SessionError(
|
|
@@ -1092,19 +1146,7 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
1092
1146
|
jsonrpc: JSONRPC_VERSION2,
|
|
1093
1147
|
id: requestId ?? uuidv4(),
|
|
1094
1148
|
method: "droid.update_session_settings" /* UPDATE_SESSION_SETTINGS */,
|
|
1095
|
-
params
|
|
1096
|
-
modelId: params.modelId,
|
|
1097
|
-
reasoningEffort: params.reasoningEffort,
|
|
1098
|
-
interactionMode: params.interactionMode,
|
|
1099
|
-
autonomyLevel: params.autonomyLevel,
|
|
1100
|
-
specModeModelId: params.specModeModelId,
|
|
1101
|
-
specModeReasoningEffort: params.specModeReasoningEffort,
|
|
1102
|
-
missionSettings: params.missionSettings,
|
|
1103
|
-
tags: params.tags,
|
|
1104
|
-
compactionTokenLimit: params.compactionTokenLimit,
|
|
1105
|
-
compactionThresholdCheckEnabled: params.compactionThresholdCheckEnabled,
|
|
1106
|
-
disabledToolIds: params.disabledToolIds
|
|
1107
|
-
}
|
|
1149
|
+
params
|
|
1108
1150
|
};
|
|
1109
1151
|
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1110
1152
|
const responseParsed = UpdateSessionSettingsResponseSchema.safeParse(rawResponse);
|
|
@@ -1284,6 +1326,19 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
1284
1326
|
const response = RemoveMcpServerResponseSchema.parse(rawResponse);
|
|
1285
1327
|
return response;
|
|
1286
1328
|
}
|
|
1329
|
+
async listModels(params = {}) {
|
|
1330
|
+
const request = {
|
|
1331
|
+
factoryApiVersion: LEGACY_FACTORY_API_VERSION,
|
|
1332
|
+
factoryProtocolVersion: FACTORY_PROTOCOL_VERSION,
|
|
1333
|
+
type: "request",
|
|
1334
|
+
jsonrpc: JSONRPC_VERSION2,
|
|
1335
|
+
id: uuidv4(),
|
|
1336
|
+
method: "droid.list_models" /* LIST_MODELS */,
|
|
1337
|
+
params
|
|
1338
|
+
};
|
|
1339
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1340
|
+
return ListModelsResponseSchema.parse(rawResponse);
|
|
1341
|
+
}
|
|
1287
1342
|
async listMcpRegistry() {
|
|
1288
1343
|
if (!this.currentSessionId) {
|
|
1289
1344
|
throw new SessionError(
|
|
@@ -1745,9 +1800,12 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
1745
1800
|
});
|
|
1746
1801
|
}
|
|
1747
1802
|
);
|
|
1748
|
-
const
|
|
1803
|
+
const requestAttribution = this.getRequestAttribution?.();
|
|
1804
|
+
const _meta = {
|
|
1805
|
+
...requestAttribution && { requestAttribution }
|
|
1806
|
+
};
|
|
1749
1807
|
this.tracing.injectContext(_meta, this.tracing.getCurrentContext());
|
|
1750
|
-
const requestWithMeta = _meta.traceparent ? { ...request, _meta } : request;
|
|
1808
|
+
const requestWithMeta = _meta.traceparent || _meta.requestAttribution ? { ...request, _meta } : request;
|
|
1751
1809
|
try {
|
|
1752
1810
|
this.logger.info("[DroidClient] [daemon -> droid] sending request", {
|
|
1753
1811
|
requestId: request.id,
|
|
@@ -1806,6 +1864,9 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
1806
1864
|
case "droid.add_user_message" /* ADD_USER_MESSAGE */:
|
|
1807
1865
|
validatedResponse = AddUserMessageResponseSchema.parse(response);
|
|
1808
1866
|
break;
|
|
1867
|
+
case "droid.append_messages" /* APPEND_MESSAGES */:
|
|
1868
|
+
validatedResponse = AppendMessagesResponseSchema.parse(response);
|
|
1869
|
+
break;
|
|
1809
1870
|
case "droid.resolve_queued_user_message" /* RESOLVE_QUEUED_USER_MESSAGE */:
|
|
1810
1871
|
validatedResponse = ResolveQueuedUserMessageResponseSchema.parse(response);
|
|
1811
1872
|
break;
|
|
@@ -1839,6 +1900,9 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
1839
1900
|
case "droid.remove_mcp_server" /* REMOVE_MCP_SERVER */:
|
|
1840
1901
|
validatedResponse = RemoveMcpServerResponseSchema.parse(response);
|
|
1841
1902
|
break;
|
|
1903
|
+
case "droid.list_models" /* LIST_MODELS */:
|
|
1904
|
+
validatedResponse = ListModelsResponseSchema.parse(response);
|
|
1905
|
+
break;
|
|
1842
1906
|
case "droid.list_mcp_registry" /* LIST_MCP_REGISTRY */:
|
|
1843
1907
|
validatedResponse = ListMcpRegistryResponseSchema.parse(response);
|
|
1844
1908
|
break;
|
|
@@ -1977,6 +2041,12 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
1977
2041
|
try {
|
|
1978
2042
|
const validatedEvent = CliRequestOrNotificationSchema.parse(event);
|
|
1979
2043
|
if (validatedEvent.method === "droid.session_notification" /* SESSION_NOTIFICATION */) {
|
|
2044
|
+
const notification = validatedEvent.params.notification;
|
|
2045
|
+
if (notification.type === "agent_turn_completed" /* AGENT_TURN_COMPLETED */) {
|
|
2046
|
+
this.completedTurnObserved = true;
|
|
2047
|
+
} else if (notification.type === "droid_working_state_changed" /* DROID_WORKING_STATE_CHANGED */ && notification.newState !== "idle" /* Idle */) {
|
|
2048
|
+
this.completedTurnObserved = false;
|
|
2049
|
+
}
|
|
1980
2050
|
this.emit("session_notification" /* SESSION_NOTIFICATION */, validatedEvent);
|
|
1981
2051
|
} else if (validatedEvent.method === "droid.request_permission" /* REQUEST_PERMISSION */) {
|
|
1982
2052
|
await this.handlePermissionRequest(validatedEvent);
|
|
@@ -2073,7 +2143,7 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
2073
2143
|
}
|
|
2074
2144
|
this.logger.info("[DroidClient] Handling permission request", {
|
|
2075
2145
|
requestId: event.id,
|
|
2076
|
-
|
|
2146
|
+
count: event.params.toolUses.length
|
|
2077
2147
|
});
|
|
2078
2148
|
this.emit("request_permission" /* REQUEST_PERMISSION */, event);
|
|
2079
2149
|
let selectedOption = "cancel" /* Cancel */;
|
|
@@ -2191,7 +2261,7 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
2191
2261
|
this.logger.info("[DroidClient] Handling ask-user request", {
|
|
2192
2262
|
requestId: event.id,
|
|
2193
2263
|
toolCallId: event.params.toolCallId,
|
|
2194
|
-
|
|
2264
|
+
count: event.params.questions.length
|
|
2195
2265
|
});
|
|
2196
2266
|
this.emit("ask_user" /* ASK_USER */, event);
|
|
2197
2267
|
let result = { cancelled: true, answers: [] };
|
|
@@ -2225,7 +2295,7 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
2225
2295
|
this.logger.info("[DroidClient] Ask-user handler resolved", {
|
|
2226
2296
|
requestId: event.id,
|
|
2227
2297
|
cancelled: result.cancelled ?? false,
|
|
2228
|
-
|
|
2298
|
+
count: result.answers.length
|
|
2229
2299
|
});
|
|
2230
2300
|
} catch (error) {
|
|
2231
2301
|
this.logger.exception(error, "Failed to handle ask-user request");
|
|
@@ -2297,6 +2367,7 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
2297
2367
|
message: error.message,
|
|
2298
2368
|
errorType: _DroidClient.getErrorType(error),
|
|
2299
2369
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2370
|
+
...error instanceof ProcessExitError && error.exitCode !== void 0 ? { exitCode: error.exitCode } : {},
|
|
2300
2371
|
error: {
|
|
2301
2372
|
name: error.name,
|
|
2302
2373
|
message: error.message
|
|
@@ -2333,6 +2404,7 @@ var DroidClient = class _DroidClient extends EventEmitter {
|
|
|
2333
2404
|
};
|
|
2334
2405
|
|
|
2335
2406
|
// src/exec-core/managed-process.ts
|
|
2407
|
+
import { spawnSync } from "child_process";
|
|
2336
2408
|
import fs2 from "fs";
|
|
2337
2409
|
import * as readline from "readline";
|
|
2338
2410
|
|
|
@@ -2764,12 +2836,16 @@ var ManagedProcessImpl = class {
|
|
|
2764
2836
|
let forcedExitTimeout;
|
|
2765
2837
|
const gracefulExitTimeout = setTimeout(() => {
|
|
2766
2838
|
if (processToClose.exitCode === null) {
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2839
|
+
if (process.platform === "win32") {
|
|
2840
|
+
this.killProcessTree(processToClose, "SIGKILL");
|
|
2841
|
+
} else {
|
|
2842
|
+
this.killProcessTree(processToClose, "SIGTERM");
|
|
2843
|
+
forcedExitTimeout = setTimeout(() => {
|
|
2844
|
+
if (processToClose.exitCode === null) {
|
|
2845
|
+
this.killProcessTree(processToClose, "SIGKILL");
|
|
2846
|
+
}
|
|
2847
|
+
}, FORCED_EXIT_TIMEOUT_MS);
|
|
2848
|
+
}
|
|
2773
2849
|
}
|
|
2774
2850
|
}, GRACEFUL_EXIT_TIMEOUT_MS);
|
|
2775
2851
|
processToClose.once("exit", () => {
|
|
@@ -2795,6 +2871,34 @@ var ManagedProcessImpl = class {
|
|
|
2795
2871
|
this._childProcess = null;
|
|
2796
2872
|
this.isClosing = false;
|
|
2797
2873
|
}
|
|
2874
|
+
killProcessTree(childProcess, signal) {
|
|
2875
|
+
if (process.platform !== "win32" || childProcess.pid === void 0) {
|
|
2876
|
+
childProcess.kill(signal);
|
|
2877
|
+
return;
|
|
2878
|
+
}
|
|
2879
|
+
const result = spawnSync(
|
|
2880
|
+
"taskkill",
|
|
2881
|
+
["/PID", String(childProcess.pid), "/T", "/F"],
|
|
2882
|
+
{
|
|
2883
|
+
stdio: "ignore",
|
|
2884
|
+
windowsHide: true
|
|
2885
|
+
}
|
|
2886
|
+
);
|
|
2887
|
+
if (!result.error && result.status === 0) {
|
|
2888
|
+
return;
|
|
2889
|
+
}
|
|
2890
|
+
logWarn(
|
|
2891
|
+
this.logger,
|
|
2892
|
+
"[ManagedProcess] Failed to kill Windows process tree",
|
|
2893
|
+
{
|
|
2894
|
+
pid: childProcess.pid,
|
|
2895
|
+
signal,
|
|
2896
|
+
status: result.status,
|
|
2897
|
+
cause: result.error
|
|
2898
|
+
}
|
|
2899
|
+
);
|
|
2900
|
+
childProcess.kill(signal);
|
|
2901
|
+
}
|
|
2798
2902
|
get isConnected() {
|
|
2799
2903
|
return this._childProcess !== null && !this._childProcess.killed && this._childProcess.stdin !== null && !this._childProcess.stdin.destroyed && ("writable" in this._childProcess.stdin ? this._childProcess.stdin.writable : true);
|
|
2800
2904
|
}
|
|
@@ -3178,7 +3282,12 @@ async function createTransport(options) {
|
|
|
3178
3282
|
droidExecPath: options.execPath,
|
|
3179
3283
|
droidExecExtraArgs: options.execArgs,
|
|
3180
3284
|
cwd: options.cwd,
|
|
3181
|
-
env: {
|
|
3285
|
+
env: {
|
|
3286
|
+
...options.env,
|
|
3287
|
+
FACTORY_API_KEY: resolveApiKey(options.apiKey),
|
|
3288
|
+
FACTORY_UPSTREAM_CLIENT_TYPE: "sdk" /* SDK */,
|
|
3289
|
+
FACTORY_UPSTREAM_SDK: formatSdkClientMetadata(SDK_CLIENT_METADATA)
|
|
3290
|
+
},
|
|
3182
3291
|
observability: options.observability
|
|
3183
3292
|
});
|
|
3184
3293
|
await processTransport.connect();
|
|
@@ -3198,7 +3307,8 @@ async function createConfiguredClient(options) {
|
|
|
3198
3307
|
const transport = await createTransport(options);
|
|
3199
3308
|
const client = new DroidClient({
|
|
3200
3309
|
transport,
|
|
3201
|
-
observability: options.observability
|
|
3310
|
+
observability: options.observability,
|
|
3311
|
+
getRequestAttribution: () => SDK_REQUEST_ATTRIBUTION
|
|
3202
3312
|
});
|
|
3203
3313
|
setupClientHandlers(client, options);
|
|
3204
3314
|
return { transport, client };
|
|
@@ -3226,6 +3336,9 @@ function buildInitParams(options) {
|
|
|
3226
3336
|
...options.reasoningEffort !== void 0 && {
|
|
3227
3337
|
reasoningEffort: options.reasoningEffort
|
|
3228
3338
|
},
|
|
3339
|
+
...options.systemPrompt !== void 0 && {
|
|
3340
|
+
systemPrompt: options.systemPrompt
|
|
3341
|
+
},
|
|
3229
3342
|
...options.specModeModelId !== void 0 && {
|
|
3230
3343
|
specModeModelId: options.specModeModelId
|
|
3231
3344
|
},
|
|
@@ -3241,13 +3354,14 @@ function buildInitParams(options) {
|
|
|
3241
3354
|
...options.sessionSource !== void 0 && {
|
|
3242
3355
|
sessionSource: options.sessionSource
|
|
3243
3356
|
},
|
|
3357
|
+
sessionOriginHint: "sdk" /* Sdk */,
|
|
3244
3358
|
...options.autoRejectPermissionRequests !== void 0 && {
|
|
3245
3359
|
autoRejectPermissionRequests: options.autoRejectPermissionRequests
|
|
3246
3360
|
},
|
|
3247
3361
|
...options.disableBuiltinSkills !== void 0 && {
|
|
3248
3362
|
disableBuiltinSkills: options.disableBuiltinSkills
|
|
3249
3363
|
},
|
|
3250
|
-
tags:
|
|
3364
|
+
tags: withSdkTag(options.tags)
|
|
3251
3365
|
};
|
|
3252
3366
|
}
|
|
3253
3367
|
|
|
@@ -3521,7 +3635,10 @@ var DroidSession = class _DroidSession {
|
|
|
3521
3635
|
if (inner) handler(inner);
|
|
3522
3636
|
}),
|
|
3523
3637
|
onError: (handler) => this._client.onError(handler),
|
|
3524
|
-
addUserMessage: (params) => this._client.addUserMessage(
|
|
3638
|
+
addUserMessage: (params) => this._client.addUserMessage({
|
|
3639
|
+
...params,
|
|
3640
|
+
userMessageSource: "sdk" /* Sdk */
|
|
3641
|
+
}),
|
|
3525
3642
|
interruptSession: () => this._client.interruptSession()
|
|
3526
3643
|
},
|
|
3527
3644
|
this._sessionId,
|
|
@@ -3575,6 +3692,11 @@ var DroidSession = class _DroidSession {
|
|
|
3575
3692
|
...params
|
|
3576
3693
|
});
|
|
3577
3694
|
}
|
|
3695
|
+
async exitSpecMode() {
|
|
3696
|
+
return this.updateSettings({
|
|
3697
|
+
interactionMode: "auto" /* Auto */
|
|
3698
|
+
});
|
|
3699
|
+
}
|
|
3578
3700
|
async addMcpServer(params) {
|
|
3579
3701
|
this._ensureNotClosed();
|
|
3580
3702
|
return unwrapResponseResult(await this._client.addMcpServer(params));
|
|
@@ -3831,7 +3953,8 @@ function createReplacementLoadParams(options, mcpServers) {
|
|
|
3831
3953
|
disabledToolIds: options.disabledToolIds,
|
|
3832
3954
|
autoRejectPermissionRequests: options.autoRejectPermissionRequests,
|
|
3833
3955
|
disableBuiltinSkills: options.disableBuiltinSkills,
|
|
3834
|
-
sessionSource: options.sessionSource
|
|
3956
|
+
sessionSource: options.sessionSource,
|
|
3957
|
+
sessionOriginHint: "sdk" /* Sdk */
|
|
3835
3958
|
};
|
|
3836
3959
|
}
|
|
3837
3960
|
async function createSession(options = {}) {
|
|
@@ -4153,6 +4276,20 @@ async function listSessions(options = {}) {
|
|
|
4153
4276
|
}
|
|
4154
4277
|
return sorted;
|
|
4155
4278
|
}
|
|
4279
|
+
|
|
4280
|
+
// src/model-discovery.ts
|
|
4281
|
+
async function listModels(options = {}) {
|
|
4282
|
+
const { includeDisabled, ...transportOptions } = options;
|
|
4283
|
+
const { client } = await createConfiguredClient(transportOptions);
|
|
4284
|
+
try {
|
|
4285
|
+
const response = await client.listModels({
|
|
4286
|
+
...includeDisabled !== void 0 && { includeDisabled }
|
|
4287
|
+
});
|
|
4288
|
+
return unwrapResponseResult(response).models;
|
|
4289
|
+
} finally {
|
|
4290
|
+
await closeQuietly(client);
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4156
4293
|
export {
|
|
4157
4294
|
AbortError,
|
|
4158
4295
|
AddMcpServerRequestParamsSchema,
|
|
@@ -4349,6 +4486,8 @@ export {
|
|
|
4349
4486
|
ListMcpToolsRequestSchema,
|
|
4350
4487
|
ListMcpToolsResponseSchema,
|
|
4351
4488
|
ListMcpToolsResultSchema,
|
|
4489
|
+
ListModelsOptionsSchema,
|
|
4490
|
+
ListModelsResultSchema,
|
|
4352
4491
|
ListSkillsRequestParamsSchema,
|
|
4353
4492
|
ListSkillsRequestSchema,
|
|
4354
4493
|
ListSkillsResponseSchema,
|
|
@@ -4402,6 +4541,8 @@ export {
|
|
|
4402
4541
|
MissionStateChangedNotificationSchema,
|
|
4403
4542
|
MissionWorkerCompletedNotificationSchema,
|
|
4404
4543
|
MissionWorkerStartedNotificationSchema,
|
|
4544
|
+
ModelInfoSchema,
|
|
4545
|
+
ModelMetadataSchema,
|
|
4405
4546
|
ModelProvider,
|
|
4406
4547
|
MultiMissionStateManager,
|
|
4407
4548
|
MultiSessionStateManager,
|
|
@@ -4576,6 +4717,7 @@ export {
|
|
|
4576
4717
|
isTransportLoggingEnabled,
|
|
4577
4718
|
listComputers,
|
|
4578
4719
|
listMachineTemplates,
|
|
4720
|
+
listModels,
|
|
4579
4721
|
listRemoteSessions,
|
|
4580
4722
|
listSessions,
|
|
4581
4723
|
logTransportMessage,
|