@skilder-ai/runtime 0.8.3 → 0.8.4
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/index.js +87 -18
- package/dist/index.js.map +2 -2
- package/dist/script-sdk-bundle.cjs +3 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -87668,6 +87668,7 @@ var DEFAULT_OPTIMIZATION_INSIGHTS_LOOKBACK_SECONDS = 30 * 24 * 60 * 60;
|
|
|
87668
87668
|
// ../common/src/constants.node.ts
|
|
87669
87669
|
var MCP_CALL_TOOL_TIMEOUT = parseInt(process.env.MCP_CALL_TOOL_TIMEOUT ?? "10000", 10);
|
|
87670
87670
|
var DEFAULT_REQUEST_TIMEOUT = parseInt(process.env.DEFAULT_REQUEST_TIMEOUT ?? "10000", 10);
|
|
87671
|
+
var SCRIPT_ROUTE_TIMEOUT_MS = 31e4;
|
|
87671
87672
|
|
|
87672
87673
|
// ../../node_modules/.pnpm/bcryptjs@3.0.3/node_modules/bcryptjs/index.js
|
|
87673
87674
|
var nextTick = typeof setImmediate === "function" ? setImmediate : typeof scheduler === "object" && typeof scheduler.postTask === "function" ? scheduler.postTask.bind(scheduler) : setTimeout;
|
|
@@ -143989,7 +143990,6 @@ var ACTIVATION_COOLDOWN_MS = 6e4;
|
|
|
143989
143990
|
var DEFAULT_IDLE_TIMEOUT_MS = 3e5;
|
|
143990
143991
|
var DEFAULT_SCRIPT_TIMEOUT_MS = 3e4;
|
|
143991
143992
|
var MAX_INTERACTIVE_SCRIPT_TIMEOUT_MS = 3e5;
|
|
143992
|
-
var SCRIPT_ROUTE_TIMEOUT_MS = MAX_INTERACTIVE_SCRIPT_TIMEOUT_MS + 1e4;
|
|
143993
143993
|
var MAX_SCRIPT_OUTPUT_SIZE = 10485760;
|
|
143994
143994
|
var MAX_CONCURRENT_SCRIPTS = 16;
|
|
143995
143995
|
var MAX_DELEGATE_DEPTH = 3;
|
|
@@ -145959,7 +145959,8 @@ The path must point to a downloadable (binary) resource in a skill's related ite
|
|
|
145959
145959
|
if (toolConfig.__routing.type === "static") {
|
|
145960
145960
|
this.logger.debug(`Handling static tool ${toolConfig.__routing.toolName} for user ${this.identity.id}`);
|
|
145961
145961
|
const { response, skillIds } = await this.handleStaticTool(toolConfig.__routing.toolName, args);
|
|
145962
|
-
|
|
145962
|
+
const isWrapperTool = toolConfig.__routing.toolName === "call_tool";
|
|
145963
|
+
if (toolConfig.__routing.workspaceId && !isWrapperTool) {
|
|
145963
145964
|
try {
|
|
145964
145965
|
const message = SkillCallToolRequest.create({
|
|
145965
145966
|
type: "static",
|
|
@@ -149851,12 +149852,29 @@ var ScriptExecutorService = class ScriptExecutorService2 {
|
|
|
149851
149852
|
NODE_PATH: (0, import_path2.join)(tempDir, "node_modules")
|
|
149852
149853
|
}
|
|
149853
149854
|
});
|
|
149855
|
+
const pendingIds = /* @__PURE__ */ new Set();
|
|
149854
149856
|
let currentTimeout = timeout2;
|
|
149855
149857
|
let lastExtendingMethod;
|
|
149858
|
+
const killForTimeout = (reason) => {
|
|
149859
|
+
const ids = Array.from(pendingIds);
|
|
149860
|
+
pendingIds.clear();
|
|
149861
|
+
for (const id of ids) {
|
|
149862
|
+
writeFromKill(id, -32001, reason);
|
|
149863
|
+
}
|
|
149864
|
+
try {
|
|
149865
|
+
child.stdin?.end();
|
|
149866
|
+
} catch (err) {
|
|
149867
|
+
this.logger.debug({ error: err }, "child.stdin.end() during killForTimeout failed");
|
|
149868
|
+
}
|
|
149869
|
+
setTimeout(() => {
|
|
149870
|
+
if (!childExited)
|
|
149871
|
+
child.kill("SIGKILL");
|
|
149872
|
+
}, 250);
|
|
149873
|
+
};
|
|
149856
149874
|
let timeoutId = setTimeout(() => {
|
|
149857
149875
|
killed = true;
|
|
149858
|
-
child.kill("SIGKILL");
|
|
149859
149876
|
this.logger.warn({ timeout: currentTimeout, method: lastExtendingMethod }, "Interactive script timed out");
|
|
149877
|
+
killForTimeout(`Script timeout: runtime killed the script after ${currentTimeout}ms${lastExtendingMethod ? ` (last extending method: ${lastExtendingMethod})` : ""}.`);
|
|
149860
149878
|
}, currentTimeout);
|
|
149861
149879
|
const resetTimeout = (extraMs, method) => {
|
|
149862
149880
|
clearTimeout(timeoutId);
|
|
@@ -149864,25 +149882,27 @@ var ScriptExecutorService = class ScriptExecutorService2 {
|
|
|
149864
149882
|
const remaining = Math.min(extraMs, MAX_INTERACTIVE_SCRIPT_TIMEOUT_MS - elapsed);
|
|
149865
149883
|
if (remaining <= 0) {
|
|
149866
149884
|
killed = true;
|
|
149867
|
-
child.kill("SIGKILL");
|
|
149868
149885
|
this.logger.warn({ method }, "Interactive script exceeded max total timeout");
|
|
149886
|
+
killForTimeout(`Script timeout: exceeded max total interactive timeout (${MAX_INTERACTIVE_SCRIPT_TIMEOUT_MS}ms)${method ? ` while waiting on ${method}` : ""}.`);
|
|
149869
149887
|
return;
|
|
149870
149888
|
}
|
|
149871
149889
|
lastExtendingMethod = method;
|
|
149872
149890
|
currentTimeout = remaining;
|
|
149873
149891
|
timeoutId = setTimeout(() => {
|
|
149874
149892
|
killed = true;
|
|
149875
|
-
child.kill("SIGKILL");
|
|
149876
149893
|
this.logger.warn({ timeout: currentTimeout, method: lastExtendingMethod }, "Interactive script timed out");
|
|
149894
|
+
killForTimeout(`Script timeout: runtime killed the script after ${currentTimeout}ms${lastExtendingMethod ? ` (last extending method: ${lastExtendingMethod})` : ""}.`);
|
|
149877
149895
|
}, currentTimeout);
|
|
149878
149896
|
};
|
|
149879
149897
|
const safeWrite = (data) => {
|
|
149880
149898
|
if (childExited || !child.stdin?.writable)
|
|
149881
|
-
return;
|
|
149899
|
+
return false;
|
|
149882
149900
|
try {
|
|
149883
149901
|
child.stdin.write(data);
|
|
149902
|
+
return true;
|
|
149884
149903
|
} catch (err) {
|
|
149885
149904
|
this.logger.debug({ error: err }, "Failed to write to child stdin (process may have exited)");
|
|
149905
|
+
return false;
|
|
149886
149906
|
}
|
|
149887
149907
|
};
|
|
149888
149908
|
const writeResponse = (id, result) => {
|
|
@@ -149891,6 +149911,12 @@ var ScriptExecutorService = class ScriptExecutorService2 {
|
|
|
149891
149911
|
const writeError = (id, code, message) => {
|
|
149892
149912
|
safeWrite(JSON.stringify({ jsonrpc: "2.0", error: { code, message }, id }) + "\n");
|
|
149893
149913
|
};
|
|
149914
|
+
const writeFromKill = (id, code, message) => {
|
|
149915
|
+
const ok = safeWrite(JSON.stringify({ jsonrpc: "2.0", error: { code, message }, id }) + "\n");
|
|
149916
|
+
if (!ok) {
|
|
149917
|
+
this.logger.warn({ id, message, event: "script_timeout_error_frame_drop" }, "Failed to deliver timeout JSON-RPC error frame to script \u2014 SDK will fall back to generic IPC-closed message");
|
|
149918
|
+
}
|
|
149919
|
+
};
|
|
149894
149920
|
const rl = (0, import_readline.createInterface)({ input: child.stdout, crlfDelay: Infinity });
|
|
149895
149921
|
rl.on("line", (line) => {
|
|
149896
149922
|
if (outputTruncated)
|
|
@@ -149918,6 +149944,7 @@ var ScriptExecutorService = class ScriptExecutorService2 {
|
|
|
149918
149944
|
return;
|
|
149919
149945
|
}
|
|
149920
149946
|
inflightCount++;
|
|
149947
|
+
pendingIds.add(msg.id);
|
|
149921
149948
|
(async () => {
|
|
149922
149949
|
try {
|
|
149923
149950
|
if (msg.method === "delegate") {
|
|
@@ -149926,11 +149953,16 @@ var ScriptExecutorService = class ScriptExecutorService2 {
|
|
|
149926
149953
|
resetTimeout(toolCallTimeout + timeout2, msg.method);
|
|
149927
149954
|
}
|
|
149928
149955
|
const result = await onRequest(msg.method, msg.params);
|
|
149929
|
-
|
|
149956
|
+
if (pendingIds.delete(msg.id)) {
|
|
149957
|
+
writeResponse(msg.id, result);
|
|
149958
|
+
}
|
|
149930
149959
|
} catch (err) {
|
|
149931
|
-
|
|
149932
|
-
|
|
149960
|
+
if (pendingIds.delete(msg.id)) {
|
|
149961
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
149962
|
+
writeError(msg.id, -32e3, message);
|
|
149963
|
+
}
|
|
149933
149964
|
} finally {
|
|
149965
|
+
pendingIds.delete(msg.id);
|
|
149934
149966
|
inflightCount--;
|
|
149935
149967
|
if (inflightCount === 0 && inflightDone)
|
|
149936
149968
|
inflightDone();
|
|
@@ -154159,7 +154191,7 @@ ${cleanError}` : cleanError;
|
|
|
154159
154191
|
throw new Error("Invalid delegate params: expected { context: string, model?: string, temperature?: number }");
|
|
154160
154192
|
}
|
|
154161
154193
|
const { context: context2, model, temperature } = params;
|
|
154162
|
-
return this.handleScriptDelegate(context2, model, temperature, workspaceId, userKey, delegateDepth);
|
|
154194
|
+
return this.handleScriptDelegate(context2, model, temperature, workspaceId, userId, userKey, runtimeId, delegateDepth);
|
|
154163
154195
|
}
|
|
154164
154196
|
case "scripts/execute": {
|
|
154165
154197
|
if (!params || typeof params !== "object" || typeof params.path !== "string") {
|
|
@@ -154249,7 +154281,7 @@ ${cleanError}` : cleanError;
|
|
|
154249
154281
|
* Handle a delegate request from a TypeScript script via JSON-RPC IPC.
|
|
154250
154282
|
* Spawns a sub-agent using DelegateService and returns the result as a CallToolResult.
|
|
154251
154283
|
*/
|
|
154252
|
-
async handleScriptDelegate(context2, model, temperature, workspaceId, userKey, delegateDepth) {
|
|
154284
|
+
async handleScriptDelegate(context2, model, temperature, workspaceId, userId, userKey, runtimeId, delegateDepth) {
|
|
154253
154285
|
if (!this.delegateService) {
|
|
154254
154286
|
this.logger.warn({ event: "delegate_service_unavailable" }, "Delegate requested but DelegateService not injected");
|
|
154255
154287
|
return {
|
|
@@ -154262,14 +154294,51 @@ ${cleanError}` : cleanError;
|
|
|
154262
154294
|
isError: true
|
|
154263
154295
|
};
|
|
154264
154296
|
}
|
|
154265
|
-
|
|
154266
|
-
|
|
154267
|
-
|
|
154268
|
-
|
|
154269
|
-
|
|
154270
|
-
|
|
154271
|
-
|
|
154297
|
+
const publishMonitoring = (response) => {
|
|
154298
|
+
try {
|
|
154299
|
+
const message = new SkillCallToolRequest({
|
|
154300
|
+
type: "static",
|
|
154301
|
+
toolName: "delegate",
|
|
154302
|
+
workspaceId,
|
|
154303
|
+
from: runtimeId ?? "script",
|
|
154304
|
+
userId,
|
|
154305
|
+
userKey,
|
|
154306
|
+
arguments: {
|
|
154307
|
+
context: context2,
|
|
154308
|
+
...model !== void 0 && { model },
|
|
154309
|
+
...temperature !== void 0 && { temperature }
|
|
154310
|
+
},
|
|
154311
|
+
response,
|
|
154312
|
+
delegateDepth
|
|
154313
|
+
});
|
|
154314
|
+
this.natsService.publish(message);
|
|
154315
|
+
} catch (error48) {
|
|
154316
|
+
this.logger.error({ err: error48, event: "script_delegate_publish_failed" }, "Failed to publish script delegate monitoring event");
|
|
154317
|
+
}
|
|
154318
|
+
};
|
|
154319
|
+
let result;
|
|
154320
|
+
try {
|
|
154321
|
+
result = await this.delegateService.execute({
|
|
154322
|
+
context: context2,
|
|
154323
|
+
model,
|
|
154324
|
+
temperature,
|
|
154325
|
+
workspaceId,
|
|
154326
|
+
userKey,
|
|
154327
|
+
delegateDepth: delegateDepth ?? 0
|
|
154328
|
+
});
|
|
154329
|
+
} catch (error48) {
|
|
154330
|
+
const message = error48 instanceof Error ? error48.message : String(error48);
|
|
154331
|
+
publishMonitoring({
|
|
154332
|
+
content: [{ type: "text", text: `Error: Delegate failed unexpectedly: ${message}` }],
|
|
154333
|
+
isError: true
|
|
154334
|
+
});
|
|
154335
|
+
throw error48;
|
|
154336
|
+
}
|
|
154337
|
+
publishMonitoring({
|
|
154338
|
+
content: result.content,
|
|
154339
|
+
...result.isError && { isError: true }
|
|
154272
154340
|
});
|
|
154341
|
+
return result;
|
|
154273
154342
|
}
|
|
154274
154343
|
/**
|
|
154275
154344
|
* Route a tool call from a script to the appropriate MCP server via NATS.
|