@codelia/runtime 0.1.89 → 0.1.90
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-NPCH2IMV.js → chunk-DSYHEFZM.js} +120 -53
- package/dist/{chunk-LNUGYGST.js → chunk-QWJ4JW4T.js} +635 -575
- package/dist/index.cjs +953 -833
- package/dist/index.js +2 -2
- package/dist/sdk.cjs +953 -833
- package/dist/sdk.js +2 -2
- package/dist/subagents/child-entry.cjs +64 -17
- package/dist/subagents/child-entry.js +1 -1
- package/package.json +10 -10
package/dist/sdk.cjs
CHANGED
|
@@ -213,7 +213,10 @@ var import_node_path27 = __toESM(require("path"), 1);
|
|
|
213
213
|
var import_logger = require("@codelia/logger");
|
|
214
214
|
|
|
215
215
|
// src/rpc/ui-requests.ts
|
|
216
|
-
var
|
|
216
|
+
var import_protocol3 = require("@codelia/protocol");
|
|
217
|
+
|
|
218
|
+
// src/rpc/protocol.ts
|
|
219
|
+
var import_protocol2 = require("@codelia/protocol");
|
|
217
220
|
|
|
218
221
|
// src/rpc/transport.ts
|
|
219
222
|
var import_node_async_hooks = require("async_hooks");
|
|
@@ -317,65 +320,107 @@ var sendResponse = (response) => {
|
|
|
317
320
|
var sendAgentEvent = (state, runId, event) => {
|
|
318
321
|
if (state.shouldSuppressEvent(runId)) return null;
|
|
319
322
|
const seq = state.nextSequence(runId);
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
run_id: runId,
|
|
325
|
-
seq,
|
|
326
|
-
event
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
sendNotification(state, notify);
|
|
323
|
+
sendNotification(
|
|
324
|
+
state,
|
|
325
|
+
notificationMessage("agent.event", { run_id: runId, seq, event })
|
|
326
|
+
);
|
|
330
327
|
return seq;
|
|
331
328
|
};
|
|
332
329
|
var sendRunStatus = (state, runId, status2, message, error, extras) => {
|
|
333
|
-
const notify = {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
...extras?.unconsumed_steer_ids?.length ? { unconsumed_steer_ids: extras.unconsumed_steer_ids } : {}
|
|
342
|
-
}
|
|
343
|
-
};
|
|
330
|
+
const notify = notificationMessage("run.status", {
|
|
331
|
+
run_id: runId,
|
|
332
|
+
status: status2,
|
|
333
|
+
message,
|
|
334
|
+
...error ? { error } : {},
|
|
335
|
+
...extras?.unconsumed_steer_ids?.length ? { unconsumed_steer_ids: extras.unconsumed_steer_ids } : {},
|
|
336
|
+
...extras?.unconsumed_client_steer_ids?.length ? { unconsumed_client_steer_ids: extras.unconsumed_client_steer_ids } : {}
|
|
337
|
+
});
|
|
344
338
|
sendNotification(state, notify);
|
|
345
339
|
};
|
|
346
340
|
var sendRunContext = (state, runId, contextLeftPercent) => {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
params: {
|
|
341
|
+
sendNotification(
|
|
342
|
+
state,
|
|
343
|
+
notificationMessage("run.context", {
|
|
351
344
|
run_id: runId,
|
|
352
345
|
context_left_percent: contextLeftPercent
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
sendNotification(state, notify);
|
|
346
|
+
})
|
|
347
|
+
);
|
|
356
348
|
};
|
|
357
349
|
var sendRunDiagnostics = (state, params) => {
|
|
358
|
-
|
|
359
|
-
jsonrpc: "2.0",
|
|
360
|
-
method: "run.diagnostics",
|
|
361
|
-
params
|
|
362
|
-
};
|
|
363
|
-
sendNotification(state, notify);
|
|
350
|
+
sendNotification(state, notificationMessage("run.diagnostics", params));
|
|
364
351
|
};
|
|
365
352
|
var sendRunMetrics = (state, params) => {
|
|
366
|
-
sendNotification(state,
|
|
353
|
+
sendNotification(state, notificationMessage("run.metrics", params));
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
// src/rpc/protocol.ts
|
|
357
|
+
var MAX_ISSUES = 10;
|
|
358
|
+
var describeIssues = (error) => error.issues.slice(0, MAX_ISSUES).map((issue) => ({
|
|
359
|
+
path: issue.path.map(String).join("."),
|
|
360
|
+
code: issue.code,
|
|
361
|
+
message: issue.message
|
|
362
|
+
}));
|
|
363
|
+
var schemaFor = (method, slot) => {
|
|
364
|
+
const spec = import_protocol2.protocolMethods[method];
|
|
365
|
+
if (slot === "params") return spec.params;
|
|
366
|
+
if (!("result" in spec))
|
|
367
|
+
throw new Error(`${method} is a notification without a result`);
|
|
368
|
+
return spec.result;
|
|
369
|
+
};
|
|
370
|
+
var assertOutgoing = (method, slot, value) => {
|
|
371
|
+
if (process.env.CODELIA_PROTOCOL_ASSERT !== "1") return;
|
|
372
|
+
const result = schemaFor(method, slot).safeParse(value);
|
|
373
|
+
if (!result.success)
|
|
374
|
+
throw new Error(
|
|
375
|
+
`protocol assertion failed for ${method} ${slot}: ${JSON.stringify(describeIssues(result.error))}`
|
|
376
|
+
);
|
|
377
|
+
};
|
|
378
|
+
var parseRequestParams = (method, raw) => {
|
|
379
|
+
const result = schemaFor(method, "params").safeParse(
|
|
380
|
+
raw === void 0 ? {} : raw
|
|
381
|
+
);
|
|
382
|
+
if (result.success) return { ok: true, params: result.data };
|
|
383
|
+
const issues = describeIssues(result.error);
|
|
384
|
+
const first = issues[0];
|
|
385
|
+
return {
|
|
386
|
+
ok: false,
|
|
387
|
+
error: {
|
|
388
|
+
code: import_protocol2.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
389
|
+
// The first issue names the field; issue messages never echo values.
|
|
390
|
+
message: first ? `invalid ${method} params: ${first.path || "params"}: ${first.message}` : `invalid ${method} params`,
|
|
391
|
+
data: { issues }
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
var parseUiNotificationParams = (method, raw) => {
|
|
396
|
+
const result = schemaFor(method, "params").safeParse(
|
|
397
|
+
raw === void 0 ? {} : raw
|
|
398
|
+
);
|
|
399
|
+
return result.success ? result.data : null;
|
|
400
|
+
};
|
|
401
|
+
var sendRequestResult = (method, id2, result) => {
|
|
402
|
+
assertOutgoing(method, "result", result);
|
|
403
|
+
sendResult(id2, result);
|
|
404
|
+
};
|
|
405
|
+
var notificationMessage = (method, params) => {
|
|
406
|
+
assertOutgoing(method, "params", params);
|
|
407
|
+
return { jsonrpc: "2.0", method, params };
|
|
408
|
+
};
|
|
409
|
+
var requestMessage = (method, id2, params) => {
|
|
410
|
+
assertOutgoing(method, "params", params);
|
|
411
|
+
return { jsonrpc: "2.0", id: id2, method, params };
|
|
412
|
+
};
|
|
413
|
+
var parseUiResult = (method, raw) => {
|
|
414
|
+
const result = schemaFor(method, "result").safeParse(raw);
|
|
415
|
+
if (result.success) return { ok: true, result: result.data };
|
|
416
|
+
return { ok: false, issues: describeIssues(result.error) };
|
|
367
417
|
};
|
|
368
418
|
|
|
369
419
|
// src/rpc/ui-requests.ts
|
|
370
420
|
var requestUi = async (state, method, params, signal) => {
|
|
371
421
|
if (signal?.aborted) return null;
|
|
372
422
|
const id2 = state.nextUiRequestId();
|
|
373
|
-
const request =
|
|
374
|
-
jsonrpc: "2.0",
|
|
375
|
-
id: id2,
|
|
376
|
-
method,
|
|
377
|
-
params
|
|
378
|
-
};
|
|
423
|
+
const request = requestMessage(method, id2, params);
|
|
379
424
|
const response = state.waitForUiResponse(id2);
|
|
380
425
|
let sent = false;
|
|
381
426
|
const abort = () => {
|
|
@@ -383,13 +428,12 @@ var requestUi = async (state, method, params, signal) => {
|
|
|
383
428
|
jsonrpc: "2.0",
|
|
384
429
|
id: id2,
|
|
385
430
|
error: {
|
|
386
|
-
code:
|
|
431
|
+
code: import_protocol3.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
387
432
|
message: "UI request cancelled"
|
|
388
433
|
}
|
|
389
434
|
});
|
|
390
|
-
if (cancelled
|
|
391
|
-
|
|
392
|
-
}
|
|
435
|
+
if (!cancelled || !sent || method !== "ui.pick.request") return;
|
|
436
|
+
send(notificationMessage("ui.pick.cancelled", { id: id2 }));
|
|
393
437
|
};
|
|
394
438
|
signal?.addEventListener("abort", abort, { once: true });
|
|
395
439
|
try {
|
|
@@ -398,7 +442,12 @@ var requestUi = async (state, method, params, signal) => {
|
|
|
398
442
|
send(request);
|
|
399
443
|
sent = true;
|
|
400
444
|
}
|
|
401
|
-
|
|
445
|
+
const parsed = parseUiResult(method, await response);
|
|
446
|
+
if (parsed.ok) return parsed.result;
|
|
447
|
+
(0, import_logger.log)(
|
|
448
|
+
`protocol mismatch: ${method} result: ${JSON.stringify(parsed.issues)}`
|
|
449
|
+
);
|
|
450
|
+
return null;
|
|
402
451
|
} catch {
|
|
403
452
|
return null;
|
|
404
453
|
} finally {
|
|
@@ -895,6 +944,7 @@ var updateTuiTheme = async (workingDir, theme) => {
|
|
|
895
944
|
await (0, import_config_loader.updateTuiConfig)(target2.path, { theme });
|
|
896
945
|
return target2;
|
|
897
946
|
};
|
|
947
|
+
var normalizeModelLevel = (value) => value.trim().toLowerCase();
|
|
898
948
|
var resolveReasoningEffort = (value) => {
|
|
899
949
|
return resolveModelLevelOption(value, "model.reasoning", {
|
|
900
950
|
allowXhigh: true
|
|
@@ -907,7 +957,7 @@ var resolveTextVerbosity = (value) => {
|
|
|
907
957
|
};
|
|
908
958
|
function resolveModelLevelOption(value, fieldName, options) {
|
|
909
959
|
if (!value) return void 0;
|
|
910
|
-
const normalized = value
|
|
960
|
+
const normalized = normalizeModelLevel(value);
|
|
911
961
|
if (normalized === "low" || normalized === "medium" || normalized === "high") {
|
|
912
962
|
return normalized;
|
|
913
963
|
}
|
|
@@ -10806,6 +10856,7 @@ var RuntimeState = class {
|
|
|
10806
10856
|
authority
|
|
10807
10857
|
]);
|
|
10808
10858
|
}
|
|
10859
|
+
acceptedSteerIds = /* @__PURE__ */ new Map();
|
|
10809
10860
|
pendingSteersByRun = /* @__PURE__ */ new Map();
|
|
10810
10861
|
steerClosedRuns = /* @__PURE__ */ new Set();
|
|
10811
10862
|
uiRequestCounter = 0;
|
|
@@ -10940,6 +10991,7 @@ var RuntimeState = class {
|
|
|
10940
10991
|
this.lastContextLeftPercent = null;
|
|
10941
10992
|
this.runSeq.delete(runId);
|
|
10942
10993
|
this.pendingSteersByRun.delete(runId);
|
|
10994
|
+
this.acceptedSteerIds.delete(runId);
|
|
10943
10995
|
this.steerClosedRuns.delete(runId);
|
|
10944
10996
|
if (this.activeRunId === null) {
|
|
10945
10997
|
this.sessionAppend = null;
|
|
@@ -10952,10 +11004,18 @@ var RuntimeState = class {
|
|
|
10952
11004
|
canSteerRun(runId) {
|
|
10953
11005
|
return this.activeRunId === runId && !this.cancelRequested && !this.steerClosedRuns.has(runId);
|
|
10954
11006
|
}
|
|
11007
|
+
acceptedRunSteerId(runId, clientSteerId) {
|
|
11008
|
+
return this.acceptedSteerIds.get(runId)?.get(clientSteerId);
|
|
11009
|
+
}
|
|
10955
11010
|
enqueueRunSteer(runId, content, clientSteerId, approvalUserText) {
|
|
10956
11011
|
this.signalApprovalChange();
|
|
10957
11012
|
this.runSteerCounter += 1;
|
|
10958
11013
|
const steerId = `s${this.runSteerCounter}`;
|
|
11014
|
+
if (clientSteerId !== void 0) {
|
|
11015
|
+
const accepted = this.acceptedSteerIds.get(runId) ?? /* @__PURE__ */ new Map();
|
|
11016
|
+
accepted.set(clientSteerId, steerId);
|
|
11017
|
+
this.acceptedSteerIds.set(runId, accepted);
|
|
11018
|
+
}
|
|
10959
11019
|
if (this.approvalIntent?.runId === runId) {
|
|
10960
11020
|
this.approvalIntent.steers.push({
|
|
10961
11021
|
id: steerId,
|
|
@@ -10966,7 +11026,7 @@ var RuntimeState = class {
|
|
|
10966
11026
|
const queue = this.pendingSteersByRun.get(runId) ?? [];
|
|
10967
11027
|
queue.push({
|
|
10968
11028
|
steer_id: steerId,
|
|
10969
|
-
...clientSteerId ? { client_steer_id: clientSteerId } : {},
|
|
11029
|
+
...clientSteerId !== void 0 ? { client_steer_id: clientSteerId } : {},
|
|
10970
11030
|
content
|
|
10971
11031
|
});
|
|
10972
11032
|
this.pendingSteersByRun.set(runId, queue);
|
|
@@ -12631,7 +12691,7 @@ var formatExecutionEnvironmentContext = (options) => {
|
|
|
12631
12691
|
"<execution_environment>",
|
|
12632
12692
|
`os: ${options.hostInfo.osDescription}`,
|
|
12633
12693
|
`shell tool execution environment: ${options.hostInfo.shellExecution}`,
|
|
12634
|
-
`
|
|
12694
|
+
`shell uses Bash: ${options.hostInfo.bashSyntaxGuaranteed ? "yes" : "no"}`,
|
|
12635
12695
|
`sandbox root: ${options.sandboxRoot}`,
|
|
12636
12696
|
`working directory: ${options.workingDir}`
|
|
12637
12697
|
];
|
|
@@ -16101,30 +16161,26 @@ var createApplyPatchTool = (sandboxKey, outputCacheStore) => {
|
|
|
16101
16161
|
// src/rpc/client-tool-requests.ts
|
|
16102
16162
|
var requestClientToolCall = async (state, params, timeoutMs) => {
|
|
16103
16163
|
const id2 = state.nextUiRequestId();
|
|
16104
|
-
|
|
16105
|
-
|
|
16106
|
-
|
|
16107
|
-
|
|
16108
|
-
|
|
16109
|
-
|
|
16110
|
-
|
|
16111
|
-
|
|
16112
|
-
|
|
16113
|
-
|
|
16114
|
-
|
|
16115
|
-
|
|
16116
|
-
|
|
16117
|
-
|
|
16118
|
-
|
|
16119
|
-
request_id: id2,
|
|
16120
|
-
run_id: params.run_id,
|
|
16121
|
-
name: params.name,
|
|
16122
|
-
reason: "timeout"
|
|
16123
|
-
}
|
|
16124
|
-
};
|
|
16125
|
-
send(notification);
|
|
16126
|
-
}
|
|
16164
|
+
send(requestMessage("client.tool.call", id2, params));
|
|
16165
|
+
const raw = await state.waitForUiResponse(id2, timeoutMs, () => {
|
|
16166
|
+
send(
|
|
16167
|
+
notificationMessage("client.tool.cancel", {
|
|
16168
|
+
request_id: id2,
|
|
16169
|
+
run_id: params.run_id,
|
|
16170
|
+
name: params.name,
|
|
16171
|
+
reason: "timeout"
|
|
16172
|
+
})
|
|
16173
|
+
);
|
|
16174
|
+
});
|
|
16175
|
+
const parsed = parseUiResult("client.tool.call", raw);
|
|
16176
|
+
if (parsed.ok) return parsed.result;
|
|
16177
|
+
(0, import_logger.log)(
|
|
16178
|
+
`protocol mismatch: client.tool.call result for ${params.name}: ${JSON.stringify(parsed.issues)}`
|
|
16127
16179
|
);
|
|
16180
|
+
return {
|
|
16181
|
+
ok: false,
|
|
16182
|
+
error: "The client returned a result that does not match the protocol."
|
|
16183
|
+
};
|
|
16128
16184
|
};
|
|
16129
16185
|
|
|
16130
16186
|
// src/tools/attachment-read.ts
|
|
@@ -16765,7 +16821,7 @@ var createRuntimeToolApproval = ({
|
|
|
16765
16821
|
// src/rpc/tool.ts
|
|
16766
16822
|
var import_node_crypto14 = require("crypto");
|
|
16767
16823
|
var import_core15 = require("@codelia/core");
|
|
16768
|
-
var
|
|
16824
|
+
var import_protocol6 = require("@codelia/protocol");
|
|
16769
16825
|
var normalizeToolResult = (result) => {
|
|
16770
16826
|
switch (result.type) {
|
|
16771
16827
|
case "json":
|
|
@@ -16802,14 +16858,14 @@ var createToolHandlers = ({
|
|
|
16802
16858
|
const toolName = params?.name;
|
|
16803
16859
|
if (!toolName) {
|
|
16804
16860
|
sendError(id2, {
|
|
16805
|
-
code:
|
|
16861
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
16806
16862
|
message: "tool name is required"
|
|
16807
16863
|
});
|
|
16808
16864
|
return;
|
|
16809
16865
|
}
|
|
16810
16866
|
if (toolName === "attachment_read" && state.attachments) {
|
|
16811
16867
|
sendError(id2, {
|
|
16812
|
-
code:
|
|
16868
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
16813
16869
|
message: "attachment_read is only available during a model run"
|
|
16814
16870
|
});
|
|
16815
16871
|
return;
|
|
@@ -16826,7 +16882,7 @@ var createToolHandlers = ({
|
|
|
16826
16882
|
const tool = state.tools?.find((entry) => entry.name === toolName);
|
|
16827
16883
|
if (!tool) {
|
|
16828
16884
|
sendError(id2, {
|
|
16829
|
-
code:
|
|
16885
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
16830
16886
|
message: `unknown tool: ${toolName}`
|
|
16831
16887
|
});
|
|
16832
16888
|
return;
|
|
@@ -16852,11 +16908,11 @@ var createToolHandlers = ({
|
|
|
16852
16908
|
};
|
|
16853
16909
|
});
|
|
16854
16910
|
assertReceiptScopeCurrent(scope);
|
|
16855
|
-
|
|
16911
|
+
sendRequestResult("tool.call", id2, result);
|
|
16856
16912
|
} catch (error) {
|
|
16857
16913
|
if (scope.connectionSignal.aborted) return;
|
|
16858
16914
|
sendError(id2, {
|
|
16859
|
-
code:
|
|
16915
|
+
code: import_protocol6.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
16860
16916
|
message: scope.ownerSignal.aborted ? "approval_expired" : error instanceof import_core15.ToolPermissionDenied ? error.decision.reason ?? "permission_denied" : `tool call failed: ${String(error)}`
|
|
16861
16917
|
});
|
|
16862
16918
|
}
|
|
@@ -20980,13 +21036,13 @@ var shellStateSchema = import_zod34.z.enum([
|
|
|
20980
21036
|
]);
|
|
20981
21037
|
var shellRunSchema = import_zod34.z.object({
|
|
20982
21038
|
command: import_zod34.z.string().describe(
|
|
20983
|
-
"
|
|
21039
|
+
"Complete shell source for the active interpreter; multiline scripts are accepted. Pass the source directly, without adding an outer layer of shell quoting or a shell wrapper."
|
|
20984
21040
|
),
|
|
20985
21041
|
cwd: import_zod34.z.string().min(1).optional().describe(
|
|
20986
|
-
"Working directory for this launch. Relative paths resolve from the workspace; omit to use its root."
|
|
21042
|
+
"Working directory for this launch; set this instead of prefixing the command with cd. Relative paths resolve from the workspace; omit to use its root."
|
|
20987
21043
|
),
|
|
20988
21044
|
label: import_zod34.z.string().max(SHELL_LABEL_MAX_CHARS).optional().describe(
|
|
20989
|
-
`Short label used to build the
|
|
21045
|
+
`Short task label, also used to build the task key. Use this for a heading instead of printing one from the command. Max ${SHELL_LABEL_MAX_CHARS} chars.`
|
|
20990
21046
|
),
|
|
20991
21047
|
timeout: import_zod34.z.number().int().positive().optional().describe(
|
|
20992
21048
|
`Execution timeout in seconds. Foreground: default ${DEFAULT_TIMEOUT_SECONDS}, max ${MAX_TIMEOUT_SECONDS}. Detached: max ${MAX_EXECUTION_TIMEOUT_SECONDS}; omit for no execution timer.`
|
|
@@ -24001,7 +24057,7 @@ function createRuntimeAttachmentService(state) {
|
|
|
24001
24057
|
}
|
|
24002
24058
|
|
|
24003
24059
|
// src/mcp/manager.ts
|
|
24004
|
-
var
|
|
24060
|
+
var import_protocol8 = require("@codelia/protocol");
|
|
24005
24061
|
var import_storage26 = require("@codelia/storage");
|
|
24006
24062
|
|
|
24007
24063
|
// src/mcp/sse.ts
|
|
@@ -24607,7 +24663,7 @@ var McpManager = class {
|
|
|
24607
24663
|
}
|
|
24608
24664
|
this.clients.add(client);
|
|
24609
24665
|
runtime.client = client;
|
|
24610
|
-
const protocolVersion = (0,
|
|
24666
|
+
const protocolVersion = (0, import_protocol8.getMcpProtocolVersion)();
|
|
24611
24667
|
const initializeResult = await client.request(
|
|
24612
24668
|
"initialize",
|
|
24613
24669
|
{
|
|
@@ -24621,10 +24677,10 @@ var McpManager = class {
|
|
|
24621
24677
|
{ timeoutMs: runtime.config.request_timeout_ms }
|
|
24622
24678
|
);
|
|
24623
24679
|
if (this.closed) return;
|
|
24624
|
-
const negotiatedProtocol = (0,
|
|
24625
|
-
if (negotiatedProtocol && !(0,
|
|
24680
|
+
const negotiatedProtocol = (0, import_protocol8.getInitializeProtocolVersion)(initializeResult);
|
|
24681
|
+
if (negotiatedProtocol && !(0, import_protocol8.isSupportedMcpProtocolVersion)(negotiatedProtocol)) {
|
|
24626
24682
|
throw new Error(
|
|
24627
|
-
`unsupported protocol version: ${negotiatedProtocol} (supported: ${(0,
|
|
24683
|
+
`unsupported protocol version: ${negotiatedProtocol} (supported: ${(0, import_protocol8.getMcpCompatibleProtocolVersions)().join(", ")})`
|
|
24628
24684
|
);
|
|
24629
24685
|
}
|
|
24630
24686
|
if (negotiatedProtocol && negotiatedProtocol !== protocolVersion) {
|
|
@@ -24998,7 +25054,7 @@ var McpManager = class {
|
|
|
24998
25054
|
serverId: config.id,
|
|
24999
25055
|
url: config.url ?? "",
|
|
25000
25056
|
headers: config.headers,
|
|
25001
|
-
protocolVersion: (0,
|
|
25057
|
+
protocolVersion: (0, import_protocol8.getMcpProtocolVersion)(),
|
|
25002
25058
|
log: this.options.log,
|
|
25003
25059
|
getAccessToken: () => this.getServerAccessToken(config.id, config),
|
|
25004
25060
|
refreshAccessToken: (failedAccessToken) => this.refreshServerAccessToken(
|
|
@@ -25024,7 +25080,7 @@ var McpManager = class {
|
|
|
25024
25080
|
};
|
|
25025
25081
|
|
|
25026
25082
|
// src/rpc/handlers.ts
|
|
25027
|
-
var
|
|
25083
|
+
var import_protocol45 = require("@codelia/protocol");
|
|
25028
25084
|
var import_storage35 = require("@codelia/storage");
|
|
25029
25085
|
|
|
25030
25086
|
// src/constants.ts
|
|
@@ -25033,80 +25089,77 @@ var SERVER_VERSION = "0.1.0";
|
|
|
25033
25089
|
var PROTOCOL_VERSION = "0";
|
|
25034
25090
|
|
|
25035
25091
|
// src/rpc/attachment.ts
|
|
25036
|
-
var
|
|
25037
|
-
async function handleAttachmentUpload(state, id2, method,
|
|
25092
|
+
var import_protocol9 = require("@codelia/protocol");
|
|
25093
|
+
async function handleAttachmentUpload(state, id2, method, raw) {
|
|
25038
25094
|
const attachments = state.attachments;
|
|
25039
25095
|
try {
|
|
25040
25096
|
if (!attachments)
|
|
25041
25097
|
throw new AttachmentUploadError("Attachment uploads are disabled");
|
|
25042
|
-
if (!
|
|
25098
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
25043
25099
|
throw new AttachmentUploadError(
|
|
25044
25100
|
"Attachment upload parameters are required"
|
|
25045
25101
|
);
|
|
25046
25102
|
switch (method) {
|
|
25047
|
-
case "attachment.upload.begin":
|
|
25048
|
-
|
|
25103
|
+
case "attachment.upload.begin": {
|
|
25104
|
+
const parsed = parseRequestParams(method, raw);
|
|
25105
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25106
|
+
return sendRequestResult(
|
|
25107
|
+
method,
|
|
25049
25108
|
id2,
|
|
25050
|
-
await attachments.begin(
|
|
25051
|
-
params,
|
|
25052
|
-
state.sessionId
|
|
25053
|
-
)
|
|
25109
|
+
await attachments.begin(parsed.params, state.sessionId)
|
|
25054
25110
|
);
|
|
25055
|
-
|
|
25056
|
-
|
|
25111
|
+
}
|
|
25112
|
+
case "attachment.upload.chunk": {
|
|
25113
|
+
const parsed = parseRequestParams(method, raw);
|
|
25114
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25115
|
+
return sendRequestResult(
|
|
25116
|
+
method,
|
|
25057
25117
|
id2,
|
|
25058
|
-
await attachments.chunk(
|
|
25059
|
-
params,
|
|
25060
|
-
state.sessionId
|
|
25061
|
-
)
|
|
25118
|
+
await attachments.chunk(parsed.params, state.sessionId)
|
|
25062
25119
|
);
|
|
25063
|
-
|
|
25064
|
-
|
|
25120
|
+
}
|
|
25121
|
+
case "attachment.upload.finish": {
|
|
25122
|
+
const parsed = parseRequestParams(method, raw);
|
|
25123
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25124
|
+
return sendRequestResult(
|
|
25125
|
+
method,
|
|
25065
25126
|
id2,
|
|
25066
|
-
await attachments.finish(
|
|
25067
|
-
params.upload_id,
|
|
25068
|
-
state.sessionId
|
|
25069
|
-
)
|
|
25070
|
-
);
|
|
25071
|
-
case "attachment.upload.cancel":
|
|
25072
|
-
await attachments.cancel(
|
|
25073
|
-
params.upload_id,
|
|
25074
|
-
state.sessionId
|
|
25127
|
+
await attachments.finish(parsed.params.upload_id, state.sessionId)
|
|
25075
25128
|
);
|
|
25076
|
-
|
|
25077
|
-
|
|
25078
|
-
|
|
25129
|
+
}
|
|
25130
|
+
case "attachment.upload.cancel": {
|
|
25131
|
+
const parsed = parseRequestParams(method, raw);
|
|
25132
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25133
|
+
await attachments.cancel(parsed.params.upload_id, state.sessionId);
|
|
25134
|
+
return sendRequestResult(method, id2, { ok: true });
|
|
25135
|
+
}
|
|
25079
25136
|
}
|
|
25080
25137
|
} catch (error) {
|
|
25081
25138
|
if (!(error instanceof AttachmentUploadError)) throw error;
|
|
25082
25139
|
sendError(id2, {
|
|
25083
|
-
code:
|
|
25140
|
+
code: import_protocol9.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25084
25141
|
message: error.message
|
|
25085
25142
|
});
|
|
25086
25143
|
}
|
|
25087
25144
|
}
|
|
25088
25145
|
|
|
25089
25146
|
// src/rpc/auth.ts
|
|
25090
|
-
var
|
|
25091
|
-
var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2,
|
|
25147
|
+
var import_protocol11 = require("@codelia/protocol");
|
|
25148
|
+
var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, raw) => {
|
|
25092
25149
|
if (state.activeRunId) {
|
|
25093
25150
|
sendError(id2, {
|
|
25094
|
-
code:
|
|
25151
|
+
code: import_protocol11.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25095
25152
|
message: "runtime busy"
|
|
25096
25153
|
});
|
|
25097
25154
|
return;
|
|
25098
25155
|
}
|
|
25099
|
-
const
|
|
25100
|
-
if (
|
|
25156
|
+
const parsed = parseRequestParams("auth.logout", raw);
|
|
25157
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25158
|
+
const params = parsed.params;
|
|
25159
|
+
const provider = params.provider;
|
|
25160
|
+
if (provider !== void 0 && !/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(provider)) {
|
|
25101
25161
|
sendError(id2, {
|
|
25102
|
-
code:
|
|
25103
|
-
message: "confirmed must be a boolean"
|
|
25104
|
-
});
|
|
25105
|
-
return;
|
|
25106
|
-
}
|
|
25107
|
-
if (provider !== void 0 && (typeof provider !== "string" || !/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(provider))) {
|
|
25108
|
-
sendError(id2, {
|
|
25109
|
-
code: import_protocol5.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25162
|
+
code: import_protocol11.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25110
25163
|
message: "invalid logout provider name"
|
|
25111
25164
|
});
|
|
25112
25165
|
return;
|
|
@@ -25124,7 +25177,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25124
25177
|
const credentials = state.effectiveEnvironment.adapters.credentialProvider;
|
|
25125
25178
|
if (provider ? !credentials?.clearProviderAuth : !credentials?.clearAuth) {
|
|
25126
25179
|
sendError(id2, {
|
|
25127
|
-
code:
|
|
25180
|
+
code: import_protocol11.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25128
25181
|
message: provider ? "host auth provider does not support scoped logout" : "host auth provider does not support logout"
|
|
25129
25182
|
});
|
|
25130
25183
|
return;
|
|
@@ -25137,7 +25190,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25137
25190
|
const auth = await store.loadV2();
|
|
25138
25191
|
if (!Object.hasOwn(auth.providers, provider) && !configuredProviders(config?.providers).includes(provider)) {
|
|
25139
25192
|
sendError(id2, {
|
|
25140
|
-
code:
|
|
25193
|
+
code: import_protocol11.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25141
25194
|
message: `unknown logout provider: ${provider}`
|
|
25142
25195
|
});
|
|
25143
25196
|
return;
|
|
@@ -25146,7 +25199,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25146
25199
|
const preconfirmed = params?.confirmed === true;
|
|
25147
25200
|
if (!preconfirmed && !state.uiCapabilities?.supports_confirm) {
|
|
25148
25201
|
sendError(id2, {
|
|
25149
|
-
code:
|
|
25202
|
+
code: import_protocol11.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25150
25203
|
message: "UI confirmation is required for logout"
|
|
25151
25204
|
});
|
|
25152
25205
|
return;
|
|
@@ -25161,7 +25214,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25161
25214
|
allow_reason: false
|
|
25162
25215
|
});
|
|
25163
25216
|
if (!confirm?.ok) {
|
|
25164
|
-
|
|
25217
|
+
sendRequestResult("auth.logout", id2, {
|
|
25165
25218
|
ok: false,
|
|
25166
25219
|
auth_cleared: false,
|
|
25167
25220
|
session_cleared: false,
|
|
@@ -25187,7 +25240,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25187
25240
|
state.sessionAppend = null;
|
|
25188
25241
|
state.sessionModelOverride = null;
|
|
25189
25242
|
}
|
|
25190
|
-
|
|
25243
|
+
sendRequestResult("auth.logout", id2, {
|
|
25191
25244
|
ok: true,
|
|
25192
25245
|
auth_cleared: true,
|
|
25193
25246
|
session_cleared: clearSession,
|
|
@@ -25198,14 +25251,14 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25198
25251
|
);
|
|
25199
25252
|
} catch {
|
|
25200
25253
|
sendError(id2, {
|
|
25201
|
-
code:
|
|
25254
|
+
code: import_protocol11.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25202
25255
|
message: "auth logout failed"
|
|
25203
25256
|
});
|
|
25204
25257
|
}
|
|
25205
25258
|
};
|
|
25206
25259
|
|
|
25207
25260
|
// src/rpc/auth-management.ts
|
|
25208
|
-
var
|
|
25261
|
+
var import_protocol13 = require("@codelia/protocol");
|
|
25209
25262
|
var import_storage27 = require("@codelia/storage");
|
|
25210
25263
|
|
|
25211
25264
|
// src/mcp/config-secret-warnings.ts
|
|
@@ -25270,7 +25323,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25270
25323
|
const rejectUnsupported = (id2) => {
|
|
25271
25324
|
if (supportsAuthManagement(state)) return false;
|
|
25272
25325
|
sendError(id2, {
|
|
25273
|
-
code:
|
|
25326
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25274
25327
|
message: "auth is host-owned"
|
|
25275
25328
|
});
|
|
25276
25329
|
return true;
|
|
@@ -25283,11 +25336,10 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25283
25336
|
status: status2,
|
|
25284
25337
|
...message ? { message } : {}
|
|
25285
25338
|
};
|
|
25286
|
-
void sendNotificationAsync(
|
|
25287
|
-
|
|
25288
|
-
|
|
25289
|
-
|
|
25290
|
-
});
|
|
25339
|
+
void sendNotificationAsync(
|
|
25340
|
+
state,
|
|
25341
|
+
notificationMessage("auth.login.status", params)
|
|
25342
|
+
);
|
|
25291
25343
|
};
|
|
25292
25344
|
const settle = (login) => {
|
|
25293
25345
|
if (login.settled) return false;
|
|
@@ -25328,12 +25380,15 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25328
25380
|
);
|
|
25329
25381
|
return { config, providers: uniqueProviders(config.providers) };
|
|
25330
25382
|
};
|
|
25331
|
-
const handleStatus = async (id2,
|
|
25383
|
+
const handleStatus = async (id2, raw) => {
|
|
25332
25384
|
if (rejectUnsupported(id2)) return;
|
|
25385
|
+
const parsed = parseRequestParams("auth.status", raw);
|
|
25386
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25387
|
+
const params = parsed.params;
|
|
25333
25388
|
const requested = params?.provider;
|
|
25334
25389
|
if (requested !== void 0 && (typeof requested !== "string" || !PROVIDER_NAME_PATTERN.test(requested))) {
|
|
25335
25390
|
sendError(id2, {
|
|
25336
|
-
code:
|
|
25391
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25337
25392
|
message: "invalid provider name"
|
|
25338
25393
|
});
|
|
25339
25394
|
return;
|
|
@@ -25342,7 +25397,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25342
25397
|
const { config, providers } = await resolveProviders();
|
|
25343
25398
|
if (requested !== void 0 && !providers.includes(requested)) {
|
|
25344
25399
|
sendError(id2, {
|
|
25345
|
-
code:
|
|
25400
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25346
25401
|
message: `unknown provider: ${requested}`
|
|
25347
25402
|
});
|
|
25348
25403
|
return;
|
|
@@ -25445,28 +25500,31 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25445
25500
|
},
|
|
25446
25501
|
...warnings.length > 0 ? { warnings } : {}
|
|
25447
25502
|
};
|
|
25448
|
-
|
|
25503
|
+
sendRequestResult("auth.status", id2, result);
|
|
25449
25504
|
} catch {
|
|
25450
25505
|
sendError(id2, {
|
|
25451
|
-
code:
|
|
25506
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25452
25507
|
message: "auth status failed"
|
|
25453
25508
|
});
|
|
25454
25509
|
}
|
|
25455
25510
|
};
|
|
25456
|
-
const handleLogin = async (id2,
|
|
25511
|
+
const handleLogin = async (id2, raw) => {
|
|
25457
25512
|
if (rejectUnsupported(id2)) return;
|
|
25458
25513
|
if (state.activeRunId) {
|
|
25459
25514
|
sendError(id2, {
|
|
25460
|
-
code:
|
|
25515
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25461
25516
|
message: "runtime busy"
|
|
25462
25517
|
});
|
|
25463
25518
|
return;
|
|
25464
25519
|
}
|
|
25520
|
+
const parsed = parseRequestParams("auth.login", raw);
|
|
25521
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25522
|
+
const params = parsed.params;
|
|
25465
25523
|
const provider = params?.provider;
|
|
25466
25524
|
const method = params?.method;
|
|
25467
25525
|
if (typeof provider !== "string" || !PROVIDER_NAME_PATTERN.test(provider)) {
|
|
25468
25526
|
sendError(id2, {
|
|
25469
|
-
code:
|
|
25527
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25470
25528
|
message: "invalid provider name"
|
|
25471
25529
|
});
|
|
25472
25530
|
return;
|
|
@@ -25479,31 +25537,31 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25479
25537
|
providerConfigs = resolved.config.providers;
|
|
25480
25538
|
} catch {
|
|
25481
25539
|
sendError(id2, {
|
|
25482
|
-
code:
|
|
25540
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25483
25541
|
message: "auth login failed"
|
|
25484
25542
|
});
|
|
25485
25543
|
return;
|
|
25486
25544
|
}
|
|
25487
25545
|
if (!providers.includes(provider)) {
|
|
25488
25546
|
sendError(id2, {
|
|
25489
|
-
code:
|
|
25547
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25490
25548
|
message: `unknown provider: ${provider}`
|
|
25491
25549
|
});
|
|
25492
25550
|
return;
|
|
25493
25551
|
}
|
|
25494
25552
|
if (!method || !providerAuthMethods(provider, providerConfigs).includes(method)) {
|
|
25495
25553
|
sendError(id2, {
|
|
25496
|
-
code:
|
|
25554
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25497
25555
|
message: `unsupported auth method for ${provider}`
|
|
25498
25556
|
});
|
|
25499
25557
|
return;
|
|
25500
25558
|
}
|
|
25501
25559
|
if (method === "api_key") {
|
|
25502
|
-
const
|
|
25503
|
-
const apiKey = typeof
|
|
25560
|
+
const raw2 = params.api_key;
|
|
25561
|
+
const apiKey = typeof raw2 === "string" ? raw2.trim() : "";
|
|
25504
25562
|
if (!apiKey || apiKey.length > MAX_API_KEY_LENGTH || /\s/.test(apiKey)) {
|
|
25505
25563
|
sendError(id2, {
|
|
25506
|
-
code:
|
|
25564
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25507
25565
|
message: "api_key must be a non-empty single-line string"
|
|
25508
25566
|
});
|
|
25509
25567
|
return;
|
|
@@ -25521,19 +25579,19 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25521
25579
|
});
|
|
25522
25580
|
} catch {
|
|
25523
25581
|
sendError(id2, {
|
|
25524
|
-
code:
|
|
25582
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25525
25583
|
message: "saving credentials failed"
|
|
25526
25584
|
});
|
|
25527
25585
|
return;
|
|
25528
25586
|
}
|
|
25529
25587
|
if (saved === "busy") {
|
|
25530
25588
|
sendError(id2, {
|
|
25531
|
-
code:
|
|
25589
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25532
25590
|
message: "runtime busy"
|
|
25533
25591
|
});
|
|
25534
25592
|
return;
|
|
25535
25593
|
}
|
|
25536
|
-
|
|
25594
|
+
sendRequestResult("auth.login", id2, {
|
|
25537
25595
|
status: "completed",
|
|
25538
25596
|
provider,
|
|
25539
25597
|
method: "api_key"
|
|
@@ -25543,7 +25601,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25543
25601
|
}
|
|
25544
25602
|
if (pending) {
|
|
25545
25603
|
sendError(id2, {
|
|
25546
|
-
code:
|
|
25604
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25547
25605
|
message: "another login is pending"
|
|
25548
25606
|
});
|
|
25549
25607
|
return;
|
|
@@ -25551,7 +25609,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25551
25609
|
const typed = params;
|
|
25552
25610
|
if (typed.callback !== void 0 && typed.callback !== "loopback" && typed.callback !== "paste") {
|
|
25553
25611
|
sendError(id2, {
|
|
25554
|
-
code:
|
|
25612
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25555
25613
|
message: "callback must be loopback or paste"
|
|
25556
25614
|
});
|
|
25557
25615
|
return;
|
|
@@ -25574,7 +25632,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25574
25632
|
}
|
|
25575
25633
|
stop();
|
|
25576
25634
|
sendError(id2, {
|
|
25577
|
-
code:
|
|
25635
|
+
code: import_protocol13.RPC_ERROR_CODE.USER_CANCELLED,
|
|
25578
25636
|
message: "login cancelled"
|
|
25579
25637
|
});
|
|
25580
25638
|
return true;
|
|
@@ -25586,7 +25644,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25586
25644
|
});
|
|
25587
25645
|
if (cancelledDuringSetup(session.stop)) return;
|
|
25588
25646
|
login.completeFromInput = session.completeFromInput;
|
|
25589
|
-
|
|
25647
|
+
sendRequestResult("auth.login", id2, {
|
|
25590
25648
|
status: "pending",
|
|
25591
25649
|
login_id: login.id,
|
|
25592
25650
|
provider,
|
|
@@ -25604,7 +25662,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25604
25662
|
const session = await createOpenAiDeviceCodeSession();
|
|
25605
25663
|
const abort = new AbortController();
|
|
25606
25664
|
if (cancelledDuringSetup(() => abort.abort())) return;
|
|
25607
|
-
|
|
25665
|
+
sendRequestResult("auth.login", id2, {
|
|
25608
25666
|
status: "pending",
|
|
25609
25667
|
login_id: login.id,
|
|
25610
25668
|
provider,
|
|
@@ -25623,17 +25681,20 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25623
25681
|
login.settled = true;
|
|
25624
25682
|
if (pending === login) pending = null;
|
|
25625
25683
|
sendError(id2, {
|
|
25626
|
-
code:
|
|
25684
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25627
25685
|
message: `auth login failed: ${failureMessage(error)}`
|
|
25628
25686
|
});
|
|
25629
25687
|
}
|
|
25630
25688
|
};
|
|
25631
|
-
const handleLoginComplete = async (id2,
|
|
25689
|
+
const handleLoginComplete = async (id2, raw) => {
|
|
25632
25690
|
if (rejectUnsupported(id2)) return;
|
|
25691
|
+
const parsed = parseRequestParams("auth.login.complete", raw);
|
|
25692
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25693
|
+
const params = parsed.params;
|
|
25633
25694
|
const login = pending;
|
|
25634
25695
|
if (!login || login.id !== params?.login_id) {
|
|
25635
25696
|
sendError(id2, {
|
|
25636
|
-
code:
|
|
25697
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25637
25698
|
message: "no matching pending login"
|
|
25638
25699
|
});
|
|
25639
25700
|
return;
|
|
@@ -25641,7 +25702,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25641
25702
|
const input = params?.callback_input;
|
|
25642
25703
|
if (!login.completeFromInput || typeof input !== "string" || !input.trim() || input.length > MAX_CALLBACK_INPUT_LENGTH) {
|
|
25643
25704
|
sendError(id2, {
|
|
25644
|
-
code:
|
|
25705
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25645
25706
|
message: "callback_input is required for a pending OAuth login"
|
|
25646
25707
|
});
|
|
25647
25708
|
return;
|
|
@@ -25651,38 +25712,44 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25651
25712
|
completion = login.completeFromInput(input.trim());
|
|
25652
25713
|
} catch {
|
|
25653
25714
|
sendError(id2, {
|
|
25654
|
-
code:
|
|
25715
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25655
25716
|
message: "invalid OAuth callback input"
|
|
25656
25717
|
});
|
|
25657
25718
|
return;
|
|
25658
25719
|
}
|
|
25659
|
-
|
|
25720
|
+
sendRequestResult("auth.login.complete", id2, { ok: true });
|
|
25660
25721
|
completion.then(
|
|
25661
25722
|
(tokens) => finishLogin(login, tokens),
|
|
25662
25723
|
(error) => failLogin(login, error)
|
|
25663
25724
|
);
|
|
25664
25725
|
};
|
|
25665
|
-
const handleLoginCancel = async (id2,
|
|
25726
|
+
const handleLoginCancel = async (id2, raw) => {
|
|
25666
25727
|
if (rejectUnsupported(id2)) return;
|
|
25728
|
+
const parsed = parseRequestParams("auth.login.cancel", raw);
|
|
25729
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25730
|
+
const params = parsed.params;
|
|
25667
25731
|
const login = pending;
|
|
25668
25732
|
if (!login || login.id !== params?.login_id) {
|
|
25669
|
-
|
|
25733
|
+
sendRequestResult("auth.login.cancel", id2, { cancelled: false });
|
|
25670
25734
|
return;
|
|
25671
25735
|
}
|
|
25672
25736
|
settle(login);
|
|
25673
|
-
|
|
25737
|
+
sendRequestResult("auth.login.cancel", id2, { cancelled: true });
|
|
25674
25738
|
notifyLogin(login, "cancelled");
|
|
25675
25739
|
log2(`auth.login cancelled provider=${login.provider}`);
|
|
25676
25740
|
};
|
|
25677
|
-
const handleResolveConflict = async (id2,
|
|
25741
|
+
const handleResolveConflict = async (id2, raw) => {
|
|
25678
25742
|
if (rejectUnsupported(id2)) return;
|
|
25679
25743
|
if (state.activeRunId) {
|
|
25680
25744
|
sendError(id2, {
|
|
25681
|
-
code:
|
|
25745
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25682
25746
|
message: "runtime busy"
|
|
25683
25747
|
});
|
|
25684
25748
|
return;
|
|
25685
25749
|
}
|
|
25750
|
+
const parsed = parseRequestParams("auth.storage.resolve_conflict", raw);
|
|
25751
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25752
|
+
const params = parsed.params;
|
|
25686
25753
|
const strategy = params?.strategy;
|
|
25687
25754
|
const validStrategies = /* @__PURE__ */ new Set([
|
|
25688
25755
|
"keep_keyring",
|
|
@@ -25692,7 +25759,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25692
25759
|
]);
|
|
25693
25760
|
if (typeof strategy !== "string" || !validStrategies.has(strategy)) {
|
|
25694
25761
|
sendError(id2, {
|
|
25695
|
-
code:
|
|
25762
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25696
25763
|
message: "strategy must be one of keep_keyring, keep_file, keep_legacy, or clear_all"
|
|
25697
25764
|
});
|
|
25698
25765
|
return;
|
|
@@ -25701,7 +25768,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25701
25768
|
if (params?.stores !== void 0) {
|
|
25702
25769
|
if (!Array.isArray(params.stores) || params.stores.length === 0 || !params.stores.every((s) => s === "auth" || s === "mcp_auth")) {
|
|
25703
25770
|
sendError(id2, {
|
|
25704
|
-
code:
|
|
25771
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25705
25772
|
message: "stores must be a non-empty array of 'auth' or 'mcp_auth'"
|
|
25706
25773
|
});
|
|
25707
25774
|
return;
|
|
@@ -25710,7 +25777,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25710
25777
|
}
|
|
25711
25778
|
if (params?.confirmed !== void 0 && typeof params.confirmed !== "boolean") {
|
|
25712
25779
|
sendError(id2, {
|
|
25713
|
-
code:
|
|
25780
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25714
25781
|
message: "confirmed must be a boolean"
|
|
25715
25782
|
});
|
|
25716
25783
|
return;
|
|
@@ -25718,7 +25785,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25718
25785
|
const preconfirmed = params?.confirmed === true;
|
|
25719
25786
|
if (!preconfirmed && !state.uiCapabilities?.supports_confirm) {
|
|
25720
25787
|
sendError(id2, {
|
|
25721
|
-
code:
|
|
25788
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25722
25789
|
message: "UI confirmation is required to resolve credential conflicts"
|
|
25723
25790
|
});
|
|
25724
25791
|
return;
|
|
@@ -25734,7 +25801,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25734
25801
|
allow_reason: false
|
|
25735
25802
|
});
|
|
25736
25803
|
if (!confirm?.ok) {
|
|
25737
|
-
|
|
25804
|
+
sendRequestResult("auth.storage.resolve_conflict", id2, {
|
|
25738
25805
|
ok: false,
|
|
25739
25806
|
resolved_stores: [],
|
|
25740
25807
|
cancelled: true
|
|
@@ -25757,7 +25824,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25757
25824
|
});
|
|
25758
25825
|
runtimeLocalAutoReview(state).revokeAuth();
|
|
25759
25826
|
state.requestAgentInvalidation();
|
|
25760
|
-
|
|
25827
|
+
sendRequestResult("auth.storage.resolve_conflict", id2, {
|
|
25761
25828
|
ok: true,
|
|
25762
25829
|
active: resolved.active,
|
|
25763
25830
|
resolved_stores: resolved.resolvedStores
|
|
@@ -25768,13 +25835,13 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25768
25835
|
} catch (error) {
|
|
25769
25836
|
if (error instanceof Error && error.message === "runtime busy") {
|
|
25770
25837
|
sendError(id2, {
|
|
25771
|
-
code:
|
|
25838
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25772
25839
|
message: "runtime busy"
|
|
25773
25840
|
});
|
|
25774
25841
|
return;
|
|
25775
25842
|
}
|
|
25776
25843
|
sendError(id2, {
|
|
25777
|
-
code:
|
|
25844
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25778
25845
|
message: `failed to resolve credential conflict: ${failureMessage(error)}`
|
|
25779
25846
|
});
|
|
25780
25847
|
}
|
|
@@ -25789,29 +25856,25 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25789
25856
|
};
|
|
25790
25857
|
|
|
25791
25858
|
// src/rpc/auto-review.ts
|
|
25792
|
-
var
|
|
25859
|
+
var import_protocol15 = require("@codelia/protocol");
|
|
25793
25860
|
var import_storage28 = require("@codelia/storage");
|
|
25794
|
-
var import_zod46 = require("zod");
|
|
25795
|
-
var paramsSchema = import_zod46.z.strictObject({
|
|
25796
|
-
action: import_zod46.z.enum(["pick", "status", "off"]).default("pick")
|
|
25797
|
-
});
|
|
25798
25861
|
var reviewerId = (reviewer) => `${reviewer.provider}/${reviewer.model}`;
|
|
25799
25862
|
var oneChoice = (result) => Array.isArray(result.ids) && result.ids.length === 1 ? result.ids[0] : void 0;
|
|
25800
25863
|
var supportsLocalAutoReviewConfiguration = (state) => state.effectiveEnvironment.sourcePreset === "tui-local" && !state.effectiveEnvironment.adapters.approvalReviewer && process.geteuid !== void 0;
|
|
25801
25864
|
var handleAutoReview = async (state, id2, raw) => {
|
|
25802
|
-
const fail = (message, code =
|
|
25865
|
+
const fail = (message, code = import_protocol15.RPC_ERROR_CODE.INVALID_PARAMS) => sendError(id2, { code, message });
|
|
25803
25866
|
if (!supportsLocalAutoReviewConfiguration(state))
|
|
25804
25867
|
return fail(
|
|
25805
25868
|
"Local Auto approve settings are unavailable.",
|
|
25806
|
-
|
|
25869
|
+
import_protocol15.RPC_ERROR_CODE.METHOD_NOT_FOUND
|
|
25807
25870
|
);
|
|
25808
|
-
const
|
|
25809
|
-
if (!
|
|
25810
|
-
|
|
25811
|
-
const { action } = params.data;
|
|
25871
|
+
const parsed = parseRequestParams("auto_review.configure", raw);
|
|
25872
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25873
|
+
const { action = "pick" } = parsed.params;
|
|
25812
25874
|
const workspace = state.runtimeSandboxRoot ?? state.runtimeWorkingDir ?? process.cwd();
|
|
25813
25875
|
const local = runtimeLocalAutoReview(state);
|
|
25814
|
-
const status2 = async () =>
|
|
25876
|
+
const status2 = async () => sendRequestResult(
|
|
25877
|
+
"auto_review.configure",
|
|
25815
25878
|
id2,
|
|
25816
25879
|
local.status(workspace, await reviewChatRouteForStatus(state, workspace))
|
|
25817
25880
|
);
|
|
@@ -25826,7 +25889,7 @@ var handleAutoReview = async (state, id2, raw) => {
|
|
|
25826
25889
|
if (state.activeRunId)
|
|
25827
25890
|
return fail(
|
|
25828
25891
|
"Wait for the current run to finish before configuring Auto approve.",
|
|
25829
|
-
|
|
25892
|
+
import_protocol15.RPC_ERROR_CODE.RUNTIME_BUSY
|
|
25830
25893
|
);
|
|
25831
25894
|
if (!state.uiCapabilities?.supports_pick)
|
|
25832
25895
|
return fail("Auto approve setup requires a client with picker support.");
|
|
@@ -25921,7 +25984,7 @@ var handleAutoReview = async (state, id2, raw) => {
|
|
|
25921
25984
|
|
|
25922
25985
|
// src/rpc/config.ts
|
|
25923
25986
|
var import_config_loader2 = require("@codelia/config-loader");
|
|
25924
|
-
var
|
|
25987
|
+
var import_protocol17 = require("@codelia/protocol");
|
|
25925
25988
|
|
|
25926
25989
|
// src/config-keys.ts
|
|
25927
25990
|
var import_config18 = require("@codelia/config");
|
|
@@ -26084,17 +26147,20 @@ var createConfigHandlers = ({
|
|
|
26084
26147
|
const rejectUnsupported = (id2) => {
|
|
26085
26148
|
if (supportsConfigReadWrite(state)) return false;
|
|
26086
26149
|
sendError(id2, {
|
|
26087
|
-
code:
|
|
26150
|
+
code: import_protocol17.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
26088
26151
|
message: "config read/write is not available for this runtime"
|
|
26089
26152
|
});
|
|
26090
26153
|
return true;
|
|
26091
26154
|
};
|
|
26092
|
-
const handleConfigGet = async (id2,
|
|
26155
|
+
const handleConfigGet = async (id2, raw) => {
|
|
26093
26156
|
if (rejectUnsupported(id2)) return;
|
|
26157
|
+
const parsed = parseRequestParams("config.get", raw);
|
|
26158
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
26159
|
+
const params = parsed.params;
|
|
26094
26160
|
const keys = params?.keys;
|
|
26095
26161
|
if (keys !== void 0 && (!Array.isArray(keys) || keys.length > MAX_KEYS_PER_REQUEST || keys.some((key) => typeof key !== "string" || !findConfigKey(key)))) {
|
|
26096
26162
|
sendError(id2, {
|
|
26097
|
-
code:
|
|
26163
|
+
code: import_protocol17.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
26098
26164
|
message: "keys must list known config keys"
|
|
26099
26165
|
});
|
|
26100
26166
|
return;
|
|
@@ -26106,18 +26172,21 @@ var createConfigHandlers = ({
|
|
|
26106
26172
|
entries: specs.map((spec) => buildConfigEntry(spec, layers)),
|
|
26107
26173
|
...layers.errors.length ? { errors: layers.errors } : {}
|
|
26108
26174
|
};
|
|
26109
|
-
|
|
26175
|
+
sendRequestResult("config.get", id2, result);
|
|
26110
26176
|
};
|
|
26111
|
-
const handleConfigSet = async (id2,
|
|
26177
|
+
const handleConfigSet = async (id2, raw) => {
|
|
26112
26178
|
if (rejectUnsupported(id2)) return;
|
|
26113
26179
|
if (state.activeRunId) {
|
|
26114
26180
|
sendError(id2, {
|
|
26115
|
-
code:
|
|
26181
|
+
code: import_protocol17.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
26116
26182
|
message: "runtime busy"
|
|
26117
26183
|
});
|
|
26118
26184
|
return;
|
|
26119
26185
|
}
|
|
26120
|
-
const
|
|
26186
|
+
const parsed = parseRequestParams("config.set", raw);
|
|
26187
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
26188
|
+
const params = parsed.params;
|
|
26189
|
+
const invalid = (message) => sendError(id2, { code: import_protocol17.RPC_ERROR_CODE.INVALID_PARAMS, message });
|
|
26121
26190
|
const scope = params?.scope;
|
|
26122
26191
|
if (scope !== "global" && scope !== "project") {
|
|
26123
26192
|
invalid("scope must be global or project");
|
|
@@ -26172,14 +26241,14 @@ var createConfigHandlers = ({
|
|
|
26172
26241
|
});
|
|
26173
26242
|
} catch {
|
|
26174
26243
|
sendError(id2, {
|
|
26175
|
-
code:
|
|
26244
|
+
code: import_protocol17.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
26176
26245
|
message: `${scope} config write failed`
|
|
26177
26246
|
});
|
|
26178
26247
|
return;
|
|
26179
26248
|
}
|
|
26180
26249
|
if (changed === "busy") {
|
|
26181
26250
|
sendError(id2, {
|
|
26182
|
-
code:
|
|
26251
|
+
code: import_protocol17.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
26183
26252
|
message: "runtime busy"
|
|
26184
26253
|
});
|
|
26185
26254
|
return;
|
|
@@ -26192,7 +26261,7 @@ var createConfigHandlers = ({
|
|
|
26192
26261
|
entry: buildConfigEntry(spec, layers),
|
|
26193
26262
|
applies: "next_run"
|
|
26194
26263
|
};
|
|
26195
|
-
|
|
26264
|
+
sendRequestResult("config.set", id2, result);
|
|
26196
26265
|
log2(
|
|
26197
26266
|
`config.set ${spec.key} scope=${scope} ${unset ? "unset" : "set"} changed=${changed}`
|
|
26198
26267
|
);
|
|
@@ -26201,7 +26270,7 @@ var createConfigHandlers = ({
|
|
|
26201
26270
|
};
|
|
26202
26271
|
|
|
26203
26272
|
// src/rpc/context.ts
|
|
26204
|
-
var
|
|
26273
|
+
var import_protocol19 = require("@codelia/protocol");
|
|
26205
26274
|
var createContextHandlers = ({
|
|
26206
26275
|
state,
|
|
26207
26276
|
log: log2
|
|
@@ -26335,10 +26404,10 @@ var createContextHandlers = ({
|
|
|
26335
26404
|
result.skills = snapshot;
|
|
26336
26405
|
}
|
|
26337
26406
|
}
|
|
26338
|
-
|
|
26407
|
+
sendRequestResult("context.inspect", id2, result);
|
|
26339
26408
|
} catch (error) {
|
|
26340
26409
|
sendError(id2, {
|
|
26341
|
-
code:
|
|
26410
|
+
code: import_protocol19.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
26342
26411
|
message: `context.inspect failed: ${String(error)}`
|
|
26343
26412
|
});
|
|
26344
26413
|
}
|
|
@@ -26347,7 +26416,7 @@ var createContextHandlers = ({
|
|
|
26347
26416
|
};
|
|
26348
26417
|
|
|
26349
26418
|
// src/rpc/context-usage.ts
|
|
26350
|
-
var
|
|
26419
|
+
var import_protocol21 = require("@codelia/protocol");
|
|
26351
26420
|
var emptyUsage = (state) => ({
|
|
26352
26421
|
provider: state.currentModelProvider,
|
|
26353
26422
|
model: state.currentModelName,
|
|
@@ -26369,11 +26438,11 @@ var createContextUsageHandlers = ({
|
|
|
26369
26438
|
...usage,
|
|
26370
26439
|
...state.sessionId ? { session_id: state.sessionId } : {}
|
|
26371
26440
|
};
|
|
26372
|
-
|
|
26441
|
+
sendRequestResult("context.usage", id2, result);
|
|
26373
26442
|
} catch (error) {
|
|
26374
26443
|
log2(`context.usage failed: ${String(error)}`);
|
|
26375
26444
|
sendError(id2, {
|
|
26376
|
-
code:
|
|
26445
|
+
code: import_protocol21.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
26377
26446
|
message: "context usage unavailable"
|
|
26378
26447
|
});
|
|
26379
26448
|
}
|
|
@@ -26390,15 +26459,13 @@ var createRunContextUsageEmitter = (options) => {
|
|
|
26390
26459
|
if (usage === lastUsage && eventType !== "compaction_complete") return;
|
|
26391
26460
|
lastUsage = usage;
|
|
26392
26461
|
try {
|
|
26393
|
-
|
|
26394
|
-
|
|
26395
|
-
|
|
26396
|
-
params: {
|
|
26462
|
+
void sendNotificationAsync(
|
|
26463
|
+
state,
|
|
26464
|
+
notificationMessage("run.context.usage", {
|
|
26397
26465
|
run_id: runId,
|
|
26398
26466
|
...agent.getContextUsage()
|
|
26399
|
-
}
|
|
26400
|
-
|
|
26401
|
-
void sendNotificationAsync(state, notify);
|
|
26467
|
+
})
|
|
26468
|
+
);
|
|
26402
26469
|
} catch (error) {
|
|
26403
26470
|
log2(`run.context.usage emit failed: ${String(error)}`);
|
|
26404
26471
|
}
|
|
@@ -26408,10 +26475,17 @@ var createRunContextUsageEmitter = (options) => {
|
|
|
26408
26475
|
// src/rpc/history.ts
|
|
26409
26476
|
var import_node_fs42 = require("fs");
|
|
26410
26477
|
var import_node_path45 = __toESM(require("path"), 1);
|
|
26411
|
-
var
|
|
26478
|
+
var import_protocol23 = require("@codelia/protocol");
|
|
26412
26479
|
var import_storage29 = require("@codelia/storage");
|
|
26413
26480
|
var DEFAULT_HISTORY_RUNS = 20;
|
|
26414
26481
|
var DEFAULT_HISTORY_EVENTS = 1500;
|
|
26482
|
+
var projectHistoryEvent = (event) => {
|
|
26483
|
+
if (event.type !== "tool_call") return event;
|
|
26484
|
+
const args = event.args;
|
|
26485
|
+
if (args && typeof args === "object" && !Array.isArray(args)) return event;
|
|
26486
|
+
const raw = typeof event.raw_args === "string" ? event.raw_args : JSON.stringify(args) ?? "null";
|
|
26487
|
+
return { ...event, args: { _raw: raw } };
|
|
26488
|
+
};
|
|
26415
26489
|
var runStartInputToHiddenMessage = (input) => {
|
|
26416
26490
|
if (!input) {
|
|
26417
26491
|
return "";
|
|
@@ -26619,7 +26693,7 @@ var createHistoryHandlers = ({
|
|
|
26619
26693
|
sessions = await sessionStateStore.list();
|
|
26620
26694
|
} catch (error) {
|
|
26621
26695
|
sendError(id2, {
|
|
26622
|
-
code:
|
|
26696
|
+
code: import_protocol23.RPC_ERROR_CODE.SESSION_LIST_FAILED,
|
|
26623
26697
|
message: `session list failed: ${String(error)}`
|
|
26624
26698
|
});
|
|
26625
26699
|
return;
|
|
@@ -26636,7 +26710,7 @@ var createHistoryHandlers = ({
|
|
|
26636
26710
|
sessions: filtered,
|
|
26637
26711
|
current_workspace_root: requestedWorkspaceRoot
|
|
26638
26712
|
};
|
|
26639
|
-
|
|
26713
|
+
sendRequestResult("session.list", id2, result);
|
|
26640
26714
|
};
|
|
26641
26715
|
const collectRuns = async (sessionId, maxRuns) => {
|
|
26642
26716
|
if (runIndex) {
|
|
@@ -26652,7 +26726,7 @@ var createHistoryHandlers = ({
|
|
|
26652
26726
|
const sessionId = params?.session_id?.trim();
|
|
26653
26727
|
if (!sessionId) {
|
|
26654
26728
|
sendError(id2, {
|
|
26655
|
-
code:
|
|
26729
|
+
code: import_protocol23.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
26656
26730
|
message: "session_id is required"
|
|
26657
26731
|
});
|
|
26658
26732
|
return;
|
|
@@ -26664,7 +26738,7 @@ var createHistoryHandlers = ({
|
|
|
26664
26738
|
runs: 0,
|
|
26665
26739
|
events_sent: 0
|
|
26666
26740
|
};
|
|
26667
|
-
|
|
26741
|
+
sendRequestResult("session.history", id2, result2);
|
|
26668
26742
|
return;
|
|
26669
26743
|
}
|
|
26670
26744
|
const runs = readRunLogs ? await collectRuns(sessionId, maxRuns) : [];
|
|
@@ -26706,7 +26780,11 @@ var createHistoryHandlers = ({
|
|
|
26706
26780
|
const truncated = replayEvents.length > maxEvents;
|
|
26707
26781
|
const selectedEvents = truncated ? replayEvents.slice(replayEvents.length - maxEvents) : replayEvents;
|
|
26708
26782
|
for (const event of selectedEvents) {
|
|
26709
|
-
await emitHistoryEvent(
|
|
26783
|
+
await emitHistoryEvent(
|
|
26784
|
+
event.runId,
|
|
26785
|
+
event.seq,
|
|
26786
|
+
projectHistoryEvent(event.event)
|
|
26787
|
+
);
|
|
26710
26788
|
}
|
|
26711
26789
|
let resumeDiff;
|
|
26712
26790
|
if (buildResumeDiffSummary) {
|
|
@@ -26725,25 +26803,14 @@ var createHistoryHandlers = ({
|
|
|
26725
26803
|
...truncated ? { truncated: true } : {},
|
|
26726
26804
|
...resumeDiff ? { resume_diff: resumeDiff } : {}
|
|
26727
26805
|
};
|
|
26728
|
-
|
|
26806
|
+
sendRequestResult("session.history", id2, result);
|
|
26729
26807
|
};
|
|
26730
26808
|
return { handleSessionList, handleSessionHistory };
|
|
26731
26809
|
};
|
|
26732
26810
|
|
|
26733
26811
|
// src/rpc/image.ts
|
|
26734
26812
|
var import_config20 = require("@codelia/config");
|
|
26735
|
-
var
|
|
26736
|
-
var import_zod47 = require("zod");
|
|
26737
|
-
var paramsSchema2 = import_zod47.z.object({
|
|
26738
|
-
mode: import_zod47.z.enum(["off", "builtin", "custom"]).optional(),
|
|
26739
|
-
provider: import_zod47.z.enum(["openai", "openrouter", "google"]).optional(),
|
|
26740
|
-
model: import_zod47.z.string().max(160).optional(),
|
|
26741
|
-
endpoint: import_zod47.z.string().max(160).optional(),
|
|
26742
|
-
api_key_env: import_zod47.z.string().max(128).optional(),
|
|
26743
|
-
image_size: import_zod47.z.enum(["1K", "2K", "4K"]).optional(),
|
|
26744
|
-
aspect_ratio: import_zod47.z.string().max(8).optional(),
|
|
26745
|
-
output_format: import_zod47.z.enum(["jpeg"]).optional()
|
|
26746
|
-
}).strict();
|
|
26813
|
+
var import_protocol25 = require("@codelia/protocol");
|
|
26747
26814
|
function createImageHandlers(state) {
|
|
26748
26815
|
const catalog = new ImageCatalog();
|
|
26749
26816
|
let configuring = false;
|
|
@@ -26930,23 +26997,29 @@ function createImageHandlers(state) {
|
|
|
26930
26997
|
try {
|
|
26931
26998
|
const root = workspace();
|
|
26932
26999
|
if (operation === "artifact") {
|
|
26933
|
-
const
|
|
26934
|
-
|
|
26935
|
-
}
|
|
26936
|
-
if (
|
|
27000
|
+
const parsed = parseRequestParams("image.artifact.get", params);
|
|
27001
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
27002
|
+
const { artifact_id: artifactId } = parsed.params;
|
|
27003
|
+
if (!/^codelia-image-[0-9a-f-]{36}$/.test(artifactId))
|
|
26937
27004
|
throw new ImageGenerationError("Invalid image artifact request.");
|
|
26938
27005
|
const { metadata, bytes } = await createLocalImageStore(
|
|
26939
27006
|
root,
|
|
26940
27007
|
() => state.sessionId
|
|
26941
|
-
).read(
|
|
26942
|
-
|
|
27008
|
+
).read(artifactId);
|
|
27009
|
+
sendRequestResult("image.artifact.get", id2, {
|
|
26943
27010
|
metadata,
|
|
26944
27011
|
data_url: `data:${metadata.media_type};base64,${bytes.toString("base64")}`
|
|
26945
27012
|
});
|
|
26946
27013
|
return;
|
|
26947
27014
|
}
|
|
26948
27015
|
if (operation === "get") {
|
|
26949
|
-
|
|
27016
|
+
const parsed = parseRequestParams("image.model.get", params);
|
|
27017
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
27018
|
+
sendRequestResult(
|
|
27019
|
+
"image.model.get",
|
|
27020
|
+
id2,
|
|
27021
|
+
await status2(await resolveImageGenerationConfig(root))
|
|
27022
|
+
);
|
|
26950
27023
|
return;
|
|
26951
27024
|
}
|
|
26952
27025
|
if (state.activeRunId || configuring)
|
|
@@ -26955,10 +27028,14 @@ function createImageHandlers(state) {
|
|
|
26955
27028
|
);
|
|
26956
27029
|
configuring = true;
|
|
26957
27030
|
ownsConfiguration = true;
|
|
26958
|
-
const
|
|
26959
|
-
if (!
|
|
27031
|
+
const catalogParams = parseRequestParams("image.model.configure", params);
|
|
27032
|
+
if (!catalogParams.ok) {
|
|
27033
|
+
sendError(id2, catalogParams.error);
|
|
27034
|
+
return;
|
|
27035
|
+
}
|
|
27036
|
+
const p = catalogParams.params;
|
|
27037
|
+
if ((p.model?.length ?? 0) > 160 || (p.endpoint?.length ?? 0) > 160 || (p.api_key_env?.length ?? 0) > 128 || (p.aspect_ratio?.length ?? 0) > 8)
|
|
26960
27038
|
throw new ImageGenerationError("Invalid image model settings.");
|
|
26961
|
-
const p = parsed.data;
|
|
26962
27039
|
if (p.provider === "google" && p.endpoint || p.provider !== "google" && (p.image_size || p.aspect_ratio || p.output_format))
|
|
26963
27040
|
throw new ImageGenerationError(
|
|
26964
27041
|
"Image settings do not match the selected provider."
|
|
@@ -27001,7 +27078,9 @@ function createImageHandlers(state) {
|
|
|
27001
27078
|
config = await choose();
|
|
27002
27079
|
}
|
|
27003
27080
|
if (!config) {
|
|
27004
|
-
|
|
27081
|
+
sendRequestResult("image.model.configure", id2, {
|
|
27082
|
+
message: "Image settings unchanged."
|
|
27083
|
+
});
|
|
27005
27084
|
return;
|
|
27006
27085
|
}
|
|
27007
27086
|
const next = await status2(config);
|
|
@@ -27018,7 +27097,9 @@ This saves image settings only; generation requests use the tool permission poli
|
|
|
27018
27097
|
cancel_label: "Cancel"
|
|
27019
27098
|
});
|
|
27020
27099
|
if (!confirm?.ok) {
|
|
27021
|
-
|
|
27100
|
+
sendRequestResult("image.model.configure", id2, {
|
|
27101
|
+
message: "Image settings unchanged."
|
|
27102
|
+
});
|
|
27022
27103
|
return;
|
|
27023
27104
|
}
|
|
27024
27105
|
}
|
|
@@ -27031,14 +27112,14 @@ This saves image settings only; generation requests use the tool permission poli
|
|
|
27031
27112
|
state.tools = null;
|
|
27032
27113
|
state.toolDefinitions = null;
|
|
27033
27114
|
const scope = target2.scope === "project" ? "project" : "user";
|
|
27034
|
-
|
|
27115
|
+
sendRequestResult("image.model.configure", id2, {
|
|
27035
27116
|
...next,
|
|
27036
27117
|
message: `${next.message}
|
|
27037
27118
|
Saved to ${scope} settings.`
|
|
27038
27119
|
});
|
|
27039
27120
|
} catch (error) {
|
|
27040
27121
|
sendError(id2, {
|
|
27041
|
-
code:
|
|
27122
|
+
code: import_protocol25.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27042
27123
|
message: error instanceof ImageGenerationError ? error.message : "Image operation failed; check settings, artifact and runtime storage. No credentials were changed."
|
|
27043
27124
|
});
|
|
27044
27125
|
} finally {
|
|
@@ -27051,7 +27132,7 @@ Saved to ${scope} settings.`
|
|
|
27051
27132
|
// src/rpc/model.ts
|
|
27052
27133
|
var import_core38 = require("@codelia/core");
|
|
27053
27134
|
var import_model_metadata3 = require("@codelia/model-metadata");
|
|
27054
|
-
var
|
|
27135
|
+
var import_protocol27 = require("@codelia/protocol");
|
|
27055
27136
|
var import_shared_types9 = require("@codelia/shared-types");
|
|
27056
27137
|
var isSupportedProvider = (provider, providers) => SUPPORTED_PROVIDERS.includes(provider) || Boolean(providers && Object.hasOwn(providers, provider));
|
|
27057
27138
|
var resolveProviderModelEntry2 = (providerEntries, provider, model) => {
|
|
@@ -27413,7 +27494,10 @@ var createModelHandlers = ({
|
|
|
27413
27494
|
meta: nextMeta
|
|
27414
27495
|
});
|
|
27415
27496
|
};
|
|
27416
|
-
const handleModelList = async (id2,
|
|
27497
|
+
const handleModelList = async (id2, raw) => {
|
|
27498
|
+
const parsed = parseRequestParams("model.list", raw);
|
|
27499
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
27500
|
+
const params = parsed.params;
|
|
27417
27501
|
const requestedProvider = params?.provider;
|
|
27418
27502
|
const includeDetails = params?.include_details ?? false;
|
|
27419
27503
|
let providers;
|
|
@@ -27441,7 +27525,7 @@ var createModelHandlers = ({
|
|
|
27441
27525
|
}
|
|
27442
27526
|
} catch (error) {
|
|
27443
27527
|
sendError(id2, {
|
|
27444
|
-
code:
|
|
27528
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27445
27529
|
message: String(error)
|
|
27446
27530
|
});
|
|
27447
27531
|
return;
|
|
@@ -27449,7 +27533,7 @@ var createModelHandlers = ({
|
|
|
27449
27533
|
const provider = requestedProvider ?? configuredProvider ?? "openai";
|
|
27450
27534
|
if (!isSupportedProvider(provider, providers)) {
|
|
27451
27535
|
sendError(id2, {
|
|
27452
|
-
code:
|
|
27536
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27453
27537
|
message: `unsupported provider: ${provider}`
|
|
27454
27538
|
});
|
|
27455
27539
|
return;
|
|
@@ -27468,7 +27552,7 @@ var createModelHandlers = ({
|
|
|
27468
27552
|
details = result2.details;
|
|
27469
27553
|
} catch (error) {
|
|
27470
27554
|
sendError(id2, {
|
|
27471
|
-
code:
|
|
27555
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27472
27556
|
message: String(error)
|
|
27473
27557
|
});
|
|
27474
27558
|
return;
|
|
@@ -27494,20 +27578,29 @@ var createModelHandlers = ({
|
|
|
27494
27578
|
...configuredFast !== void 0 ? { fast: configuredFast } : {},
|
|
27495
27579
|
...details ? { details } : {}
|
|
27496
27580
|
};
|
|
27497
|
-
|
|
27581
|
+
sendRequestResult("model.list", id2, result);
|
|
27498
27582
|
};
|
|
27499
|
-
const handleModelSet = async (id2,
|
|
27583
|
+
const handleModelSet = async (id2, raw) => {
|
|
27500
27584
|
if (state.activeRunId) {
|
|
27501
27585
|
sendError(id2, {
|
|
27502
|
-
code:
|
|
27586
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27503
27587
|
message: "runtime busy"
|
|
27504
27588
|
});
|
|
27505
27589
|
return;
|
|
27506
27590
|
}
|
|
27591
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw) && "reasoning" in raw && typeof raw.reasoning === "string") {
|
|
27592
|
+
raw = {
|
|
27593
|
+
...raw,
|
|
27594
|
+
reasoning: raw.reasoning ? normalizeModelLevel(raw.reasoning) : void 0
|
|
27595
|
+
};
|
|
27596
|
+
}
|
|
27597
|
+
const parsed = parseRequestParams("model.set", raw);
|
|
27598
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
27599
|
+
const params = parsed.params;
|
|
27507
27600
|
const scope = params?.scope ?? "config";
|
|
27508
27601
|
if (scope !== "config" && scope !== "session") {
|
|
27509
27602
|
sendError(id2, {
|
|
27510
|
-
code:
|
|
27603
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27511
27604
|
message: `unsupported model scope: ${scope}`
|
|
27512
27605
|
});
|
|
27513
27606
|
return;
|
|
@@ -27516,7 +27609,7 @@ var createModelHandlers = ({
|
|
|
27516
27609
|
if (params?.reset) {
|
|
27517
27610
|
if (scope !== "session") {
|
|
27518
27611
|
sendError(id2, {
|
|
27519
|
-
code:
|
|
27612
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27520
27613
|
message: "model reset is only supported for session scope"
|
|
27521
27614
|
});
|
|
27522
27615
|
return;
|
|
@@ -27527,7 +27620,7 @@ var createModelHandlers = ({
|
|
|
27527
27620
|
const name3 = config.name;
|
|
27528
27621
|
if (!name3) {
|
|
27529
27622
|
sendError(id2, {
|
|
27530
|
-
code:
|
|
27623
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27531
27624
|
message: "configured model name is missing"
|
|
27532
27625
|
});
|
|
27533
27626
|
return;
|
|
@@ -27543,7 +27636,7 @@ var createModelHandlers = ({
|
|
|
27543
27636
|
);
|
|
27544
27637
|
} catch (error) {
|
|
27545
27638
|
sendError(id2, {
|
|
27546
|
-
code:
|
|
27639
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27547
27640
|
message: String(error)
|
|
27548
27641
|
});
|
|
27549
27642
|
return;
|
|
@@ -27561,11 +27654,11 @@ var createModelHandlers = ({
|
|
|
27561
27654
|
...effectiveReasoning ? { reasoning: effectiveReasoning } : {},
|
|
27562
27655
|
...config.fast !== void 0 ? { fast: effectiveFast } : {}
|
|
27563
27656
|
};
|
|
27564
|
-
|
|
27657
|
+
sendRequestResult("model.set", id2, result);
|
|
27565
27658
|
log2(`model.set reset session override -> ${provider2}/${name3}`);
|
|
27566
27659
|
} catch (error) {
|
|
27567
27660
|
sendError(id2, {
|
|
27568
|
-
code:
|
|
27661
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27569
27662
|
message: String(error)
|
|
27570
27663
|
});
|
|
27571
27664
|
}
|
|
@@ -27575,7 +27668,7 @@ var createModelHandlers = ({
|
|
|
27575
27668
|
let name2 = params?.name?.trim();
|
|
27576
27669
|
if (!name2) {
|
|
27577
27670
|
sendError(id2, {
|
|
27578
|
-
code:
|
|
27671
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27579
27672
|
message: "model name is required"
|
|
27580
27673
|
});
|
|
27581
27674
|
return;
|
|
@@ -27586,7 +27679,7 @@ var createModelHandlers = ({
|
|
|
27586
27679
|
reasoning = resolveReasoningEffort(params.reasoning);
|
|
27587
27680
|
} catch (error) {
|
|
27588
27681
|
sendError(id2, {
|
|
27589
|
-
code:
|
|
27682
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27590
27683
|
message: String(error)
|
|
27591
27684
|
});
|
|
27592
27685
|
return;
|
|
@@ -27596,7 +27689,7 @@ var createModelHandlers = ({
|
|
|
27596
27689
|
const endpoint = getResponsesProvider(configured, provider);
|
|
27597
27690
|
if (!isSupportedProvider(provider, configured.providers)) {
|
|
27598
27691
|
sendError(id2, {
|
|
27599
|
-
code:
|
|
27692
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27600
27693
|
message: `unsupported provider: ${provider}`
|
|
27601
27694
|
});
|
|
27602
27695
|
return;
|
|
@@ -27609,7 +27702,7 @@ var createModelHandlers = ({
|
|
|
27609
27702
|
);
|
|
27610
27703
|
if (!spec) {
|
|
27611
27704
|
sendError(id2, {
|
|
27612
|
-
code:
|
|
27705
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27613
27706
|
message: `unknown model: ${name2}`
|
|
27614
27707
|
});
|
|
27615
27708
|
return;
|
|
@@ -27642,7 +27735,7 @@ var createModelHandlers = ({
|
|
|
27642
27735
|
await validateFastSelection(provider, name2, candidate.fast);
|
|
27643
27736
|
} catch (error) {
|
|
27644
27737
|
sendError(id2, {
|
|
27645
|
-
code:
|
|
27738
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27646
27739
|
message: String(error)
|
|
27647
27740
|
});
|
|
27648
27741
|
return;
|
|
@@ -27690,14 +27783,14 @@ var createModelHandlers = ({
|
|
|
27690
27783
|
...effectiveReasoning ? { reasoning: effectiveReasoning } : {},
|
|
27691
27784
|
...updatedConfig.fast !== void 0 ? { fast: effectiveFast } : {}
|
|
27692
27785
|
};
|
|
27693
|
-
|
|
27786
|
+
sendRequestResult("model.set", id2, result);
|
|
27694
27787
|
const persistence = scope === "config" && target2 ? ` scope=${target2.scope} path=${target2.path}` : " scope=session";
|
|
27695
27788
|
log2(
|
|
27696
27789
|
`model.set ${provider}/${name2}${effectiveReasoning ? ` reasoning=${effectiveReasoning}` : ""}${persistence}`
|
|
27697
27790
|
);
|
|
27698
27791
|
} catch (error) {
|
|
27699
27792
|
sendError(id2, {
|
|
27700
|
-
code:
|
|
27793
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27701
27794
|
message: String(error)
|
|
27702
27795
|
});
|
|
27703
27796
|
}
|
|
@@ -27708,7 +27801,7 @@ var createModelHandlers = ({
|
|
|
27708
27801
|
// src/rpc/permissions.ts
|
|
27709
27802
|
var import_node_fs43 = require("fs");
|
|
27710
27803
|
var import_config_loader3 = require("@codelia/config-loader");
|
|
27711
|
-
var
|
|
27804
|
+
var import_protocol29 = require("@codelia/protocol");
|
|
27712
27805
|
var import_storage30 = require("@codelia/storage");
|
|
27713
27806
|
var MAX_RULE_FIELD_LENGTH = 4096;
|
|
27714
27807
|
var RULE_FIELDS = ["tool", "command", "command_glob", "skill_name"];
|
|
@@ -27718,23 +27811,10 @@ var toSpec = (rule) => ({
|
|
|
27718
27811
|
...rule.command_glob !== void 0 ? { command_glob: rule.command_glob } : {},
|
|
27719
27812
|
...rule.skill_name !== void 0 ? { skill_name: rule.skill_name } : {}
|
|
27720
27813
|
});
|
|
27721
|
-
var
|
|
27722
|
-
|
|
27723
|
-
|
|
27724
|
-
|
|
27725
|
-
const record = value;
|
|
27726
|
-
if (Object.keys(record).some((key) => !RULE_FIELDS.includes(key))) {
|
|
27727
|
-
return null;
|
|
27728
|
-
}
|
|
27729
|
-
for (const field of RULE_FIELDS) {
|
|
27730
|
-
const entry = record[field];
|
|
27731
|
-
if (entry === void 0 && field !== "tool") continue;
|
|
27732
|
-
if (typeof entry !== "string" || !entry.trim() || entry.length > MAX_RULE_FIELD_LENGTH) {
|
|
27733
|
-
return null;
|
|
27734
|
-
}
|
|
27735
|
-
}
|
|
27736
|
-
return toSpec(record);
|
|
27737
|
-
};
|
|
27814
|
+
var isValidRemovalRule = (rule) => RULE_FIELDS.every((field) => {
|
|
27815
|
+
const value = rule[field];
|
|
27816
|
+
return value === void 0 || value.trim().length > 0 && value.length <= MAX_RULE_FIELD_LENGTH;
|
|
27817
|
+
});
|
|
27738
27818
|
var fileRules = (config, scope) => [
|
|
27739
27819
|
...(config?.permissions?.allow ?? []).map((rule) => ({
|
|
27740
27820
|
kind: "allow",
|
|
@@ -27758,16 +27838,19 @@ var createPermissionsHandlers = ({
|
|
|
27758
27838
|
const rejectUnsupported = (id2) => {
|
|
27759
27839
|
if (supportsConfigReadWrite(state)) return false;
|
|
27760
27840
|
sendError(id2, {
|
|
27761
|
-
code:
|
|
27841
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27762
27842
|
message: "permission rules are not available for this runtime"
|
|
27763
27843
|
});
|
|
27764
27844
|
return true;
|
|
27765
27845
|
};
|
|
27766
|
-
const handlePermissionsList = async (id2,
|
|
27846
|
+
const handlePermissionsList = async (id2, raw) => {
|
|
27767
27847
|
if (rejectUnsupported(id2)) return;
|
|
27848
|
+
const parsed = parseRequestParams("permissions.list", raw);
|
|
27849
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
27850
|
+
const params = parsed.params;
|
|
27768
27851
|
if (params?.include_system !== void 0 && typeof params.include_system !== "boolean") {
|
|
27769
27852
|
sendError(id2, {
|
|
27770
|
-
code:
|
|
27853
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27771
27854
|
message: "include_system must be a boolean"
|
|
27772
27855
|
});
|
|
27773
27856
|
return;
|
|
@@ -27863,108 +27946,113 @@ var createPermissionsHandlers = ({
|
|
|
27863
27946
|
rules,
|
|
27864
27947
|
...errors.length ? { errors } : {}
|
|
27865
27948
|
};
|
|
27866
|
-
|
|
27949
|
+
sendRequestResult("permissions.list", id2, result);
|
|
27867
27950
|
};
|
|
27868
|
-
const
|
|
27869
|
-
|
|
27870
|
-
if (params
|
|
27871
|
-
|
|
27872
|
-
|
|
27873
|
-
|
|
27874
|
-
|
|
27875
|
-
message: "Invalid remembered tool"
|
|
27876
|
-
});
|
|
27877
|
-
return;
|
|
27878
|
-
}
|
|
27879
|
-
try {
|
|
27880
|
-
const workspace = (0, import_node_fs43.realpathSync)(root);
|
|
27881
|
-
const removed2 = await state.withAdmissionLock(async () => {
|
|
27882
|
-
if (state.activeRunId) return "busy";
|
|
27883
|
-
return new import_storage30.ProjectsPolicyStore().updateRememberedTool(
|
|
27884
|
-
workspace,
|
|
27885
|
-
params.remembered_tool,
|
|
27886
|
-
false,
|
|
27887
|
-
() => {
|
|
27888
|
-
if (resolveConfigWorkspaceDir(state) !== root || (0, import_node_fs43.realpathSync)(root) !== workspace)
|
|
27889
|
-
throw new Error("workspace_changed");
|
|
27890
|
-
}
|
|
27891
|
-
);
|
|
27892
|
-
});
|
|
27893
|
-
if (removed2 === "busy") {
|
|
27894
|
-
sendError(id2, {
|
|
27895
|
-
code: import_protocol14.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27896
|
-
message: "runtime busy"
|
|
27897
|
-
});
|
|
27898
|
-
return;
|
|
27899
|
-
}
|
|
27900
|
-
if (removed2) state.reviseApprovalAuthority();
|
|
27901
|
-
sendResult(id2, {
|
|
27902
|
-
...params,
|
|
27903
|
-
removed: Number(removed2)
|
|
27904
|
-
});
|
|
27905
|
-
} catch {
|
|
27906
|
-
sendError(id2, {
|
|
27907
|
-
code: import_protocol14.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27908
|
-
message: "Remembered tool removal failed"
|
|
27909
|
-
});
|
|
27910
|
-
}
|
|
27951
|
+
const removeRememberedTool = async (id2, params) => {
|
|
27952
|
+
const root = resolveConfigWorkspaceDir(state);
|
|
27953
|
+
if (!root || !localProjectAllows(state) || params.scope !== "project" || !configurableToolInvocations.has(params.remembered_tool)) {
|
|
27954
|
+
sendError(id2, {
|
|
27955
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27956
|
+
message: "Invalid remembered tool"
|
|
27957
|
+
});
|
|
27911
27958
|
return;
|
|
27912
27959
|
}
|
|
27913
|
-
|
|
27914
|
-
const
|
|
27915
|
-
|
|
27960
|
+
try {
|
|
27961
|
+
const workspace = (0, import_node_fs43.realpathSync)(root);
|
|
27962
|
+
const removed = await state.withAdmissionLock(async () => {
|
|
27963
|
+
if (state.activeRunId) return "busy";
|
|
27964
|
+
return new import_storage30.ProjectsPolicyStore().updateRememberedTool(
|
|
27965
|
+
workspace,
|
|
27966
|
+
params.remembered_tool,
|
|
27967
|
+
false,
|
|
27968
|
+
() => {
|
|
27969
|
+
if (resolveConfigWorkspaceDir(state) !== root || (0, import_node_fs43.realpathSync)(root) !== workspace)
|
|
27970
|
+
throw new Error("workspace_changed");
|
|
27971
|
+
}
|
|
27972
|
+
);
|
|
27973
|
+
});
|
|
27974
|
+
if (removed === "busy") {
|
|
27916
27975
|
sendError(id2, {
|
|
27917
|
-
code:
|
|
27918
|
-
message: "
|
|
27976
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27977
|
+
message: "runtime busy"
|
|
27919
27978
|
});
|
|
27920
27979
|
return;
|
|
27921
27980
|
}
|
|
27922
|
-
|
|
27923
|
-
|
|
27924
|
-
|
|
27925
|
-
|
|
27926
|
-
|
|
27981
|
+
if (removed) state.reviseApprovalAuthority();
|
|
27982
|
+
sendRequestResult("permissions.remove", id2, {
|
|
27983
|
+
...params,
|
|
27984
|
+
removed: Number(removed)
|
|
27985
|
+
});
|
|
27986
|
+
} catch {
|
|
27987
|
+
sendError(id2, {
|
|
27988
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27989
|
+
message: "Remembered tool removal failed"
|
|
27990
|
+
});
|
|
27991
|
+
}
|
|
27992
|
+
};
|
|
27993
|
+
const removeWorkspaceGrant = (id2, params) => {
|
|
27994
|
+
const workspaceDir = resolveConfigWorkspaceDir(state);
|
|
27995
|
+
if (!workspaceDir || params.resource !== "workspace_write" || params.scope !== "session") {
|
|
27996
|
+
sendError(id2, {
|
|
27997
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27998
|
+
message: "Invalid workspace grant reference"
|
|
27927
27999
|
});
|
|
27928
28000
|
return;
|
|
27929
28001
|
}
|
|
27930
|
-
|
|
27931
|
-
|
|
27932
|
-
|
|
27933
|
-
|
|
27934
|
-
|
|
27935
|
-
|
|
27936
|
-
|
|
27937
|
-
|
|
27938
|
-
|
|
27939
|
-
|
|
27940
|
-
|
|
27941
|
-
|
|
27942
|
-
|
|
27943
|
-
|
|
27944
|
-
params.scope
|
|
27945
|
-
);
|
|
27946
|
-
if (removed2) state.reviseApprovalAuthority();
|
|
27947
|
-
const result2 = {
|
|
27948
|
-
...params,
|
|
27949
|
-
removed: removed2 ? 1 : 0
|
|
27950
|
-
};
|
|
27951
|
-
sendResult(id2, result2);
|
|
27952
|
-
} catch {
|
|
27953
|
-
sendError(id2, {
|
|
27954
|
-
code: import_protocol14.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27955
|
-
message: "Launch rule removal failed"
|
|
27956
|
-
});
|
|
27957
|
-
}
|
|
28002
|
+
const removed = removeWorkspaceWriteGrant(state, workspaceDir);
|
|
28003
|
+
sendRequestResult("permissions.remove", id2, {
|
|
28004
|
+
resource: params.resource,
|
|
28005
|
+
scope: "session",
|
|
28006
|
+
removed: removed ? 1 : 0
|
|
28007
|
+
});
|
|
28008
|
+
};
|
|
28009
|
+
const removeLaunchRule = (id2, params) => {
|
|
28010
|
+
const workspaceDir = resolveConfigWorkspaceDir(state);
|
|
28011
|
+
if (!workspaceDir || !/^[a-f0-9]{64}$/u.test(params.launch_rule_id) || params.scope !== "session" && params.scope !== "project" || state.effectiveEnvironment.sourcePreset !== "tui-local") {
|
|
28012
|
+
sendError(id2, {
|
|
28013
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
28014
|
+
message: "Invalid launch rule reference"
|
|
28015
|
+
});
|
|
27958
28016
|
return;
|
|
27959
28017
|
}
|
|
28018
|
+
try {
|
|
28019
|
+
const removed = runtimeLaunchRules(state).remove(
|
|
28020
|
+
(0, import_node_fs43.realpathSync)(workspaceDir),
|
|
28021
|
+
state.sessionId ?? "operator",
|
|
28022
|
+
params.launch_rule_id,
|
|
28023
|
+
params.scope
|
|
28024
|
+
);
|
|
28025
|
+
if (removed) state.reviseApprovalAuthority();
|
|
28026
|
+
const result = {
|
|
28027
|
+
...params,
|
|
28028
|
+
removed: removed ? 1 : 0
|
|
28029
|
+
};
|
|
28030
|
+
sendRequestResult("permissions.remove", id2, result);
|
|
28031
|
+
} catch {
|
|
28032
|
+
sendError(id2, {
|
|
28033
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
28034
|
+
message: "Launch rule removal failed"
|
|
28035
|
+
});
|
|
28036
|
+
}
|
|
28037
|
+
};
|
|
28038
|
+
const handlePermissionsRemove = async (id2, raw) => {
|
|
28039
|
+
if (rejectUnsupported(id2)) return;
|
|
28040
|
+
const parsed = parseRequestParams("permissions.remove", raw);
|
|
28041
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
28042
|
+
const params = parsed.params;
|
|
28043
|
+
if (params && "remembered_tool" in params)
|
|
28044
|
+
return removeRememberedTool(id2, params);
|
|
28045
|
+
if (params && "resource" in params) return removeWorkspaceGrant(id2, params);
|
|
28046
|
+
if (params && "launch_rule_id" in params)
|
|
28047
|
+
return removeLaunchRule(id2, params);
|
|
27960
28048
|
if (state.activeRunId) {
|
|
27961
28049
|
sendError(id2, {
|
|
27962
|
-
code:
|
|
28050
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27963
28051
|
message: "runtime busy"
|
|
27964
28052
|
});
|
|
27965
28053
|
return;
|
|
27966
28054
|
}
|
|
27967
|
-
const invalid = (message) => sendError(id2, { code:
|
|
28055
|
+
const invalid = (message) => sendError(id2, { code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS, message });
|
|
27968
28056
|
const scope = params?.scope;
|
|
27969
28057
|
const kind = params?.kind;
|
|
27970
28058
|
if (scope !== "global" && scope !== "project") {
|
|
@@ -27975,8 +28063,8 @@ var createPermissionsHandlers = ({
|
|
|
27975
28063
|
invalid("kind must be allow or deny");
|
|
27976
28064
|
return;
|
|
27977
28065
|
}
|
|
27978
|
-
const rule =
|
|
27979
|
-
if (!rule) {
|
|
28066
|
+
const rule = params.rule;
|
|
28067
|
+
if (!isValidRemovalRule(rule)) {
|
|
27980
28068
|
invalid("rule must have a tool and only string rule fields");
|
|
27981
28069
|
return;
|
|
27982
28070
|
}
|
|
@@ -28000,33 +28088,36 @@ var createPermissionsHandlers = ({
|
|
|
28000
28088
|
});
|
|
28001
28089
|
} catch {
|
|
28002
28090
|
sendError(id2, {
|
|
28003
|
-
code:
|
|
28091
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
28004
28092
|
message: `${scope} config write failed`
|
|
28005
28093
|
});
|
|
28006
28094
|
return;
|
|
28007
28095
|
}
|
|
28008
28096
|
if (removed === "busy") {
|
|
28009
28097
|
sendError(id2, {
|
|
28010
|
-
code:
|
|
28098
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
28011
28099
|
message: "runtime busy"
|
|
28012
28100
|
});
|
|
28013
28101
|
return;
|
|
28014
28102
|
}
|
|
28015
28103
|
const result = { scope, kind, path: path51, removed };
|
|
28016
|
-
|
|
28104
|
+
sendRequestResult("permissions.remove", id2, result);
|
|
28017
28105
|
log2(`permissions.remove scope=${scope} kind=${kind} removed=${removed}`);
|
|
28018
28106
|
};
|
|
28019
|
-
const handleProjectAllowTrustSet = async (id2,
|
|
28107
|
+
const handleProjectAllowTrustSet = async (id2, raw) => {
|
|
28020
28108
|
if (!supportsProjectAllowTrust(state)) {
|
|
28021
28109
|
sendError(id2, {
|
|
28022
|
-
code:
|
|
28110
|
+
code: import_protocol29.RPC_ERROR_CODE.METHOD_NOT_FOUND,
|
|
28023
28111
|
message: "Project allow trust changes are unavailable for this runtime."
|
|
28024
28112
|
});
|
|
28025
28113
|
return;
|
|
28026
28114
|
}
|
|
28115
|
+
const parsed = parseRequestParams("permissions.projectTrust.set", raw);
|
|
28116
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
28117
|
+
const params = parsed.params;
|
|
28027
28118
|
if (typeof params?.workspace !== "string" || typeof params.trusted !== "boolean" || typeof params.expected_revision !== "string" || !params.expected_revision) {
|
|
28028
28119
|
sendError(id2, {
|
|
28029
|
-
code:
|
|
28120
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
28030
28121
|
message: "Expected a reviewed project allow list for this local workspace"
|
|
28031
28122
|
});
|
|
28032
28123
|
return;
|
|
@@ -28035,7 +28126,7 @@ var createPermissionsHandlers = ({
|
|
|
28035
28126
|
await state.withAdmissionLock(async () => {
|
|
28036
28127
|
if (state.activeRunId) {
|
|
28037
28128
|
sendError(id2, {
|
|
28038
|
-
code:
|
|
28129
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
28039
28130
|
message: "runtime busy"
|
|
28040
28131
|
});
|
|
28041
28132
|
return;
|
|
@@ -28043,7 +28134,7 @@ var createPermissionsHandlers = ({
|
|
|
28043
28134
|
const root = resolveConfigWorkspaceDir(state);
|
|
28044
28135
|
if (!root || (0, import_node_fs43.realpathSync)(root) !== params.workspace) {
|
|
28045
28136
|
sendError(id2, {
|
|
28046
|
-
code:
|
|
28137
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
28047
28138
|
message: "Workspace changed. Review the current project allow list again."
|
|
28048
28139
|
});
|
|
28049
28140
|
return;
|
|
@@ -28055,7 +28146,7 @@ var createPermissionsHandlers = ({
|
|
|
28055
28146
|
params.expected_revision
|
|
28056
28147
|
);
|
|
28057
28148
|
state.invalidateAgentCache();
|
|
28058
|
-
|
|
28149
|
+
sendRequestResult("permissions.projectTrust.set", id2, {
|
|
28059
28150
|
workspace: params.workspace,
|
|
28060
28151
|
trusted: params.trusted
|
|
28061
28152
|
});
|
|
@@ -28063,7 +28154,7 @@ var createPermissionsHandlers = ({
|
|
|
28063
28154
|
} catch (error) {
|
|
28064
28155
|
const changed = error instanceof Error && error.message === "project_allow_trust_changed";
|
|
28065
28156
|
sendError(id2, {
|
|
28066
|
-
code: changed ?
|
|
28157
|
+
code: changed ? import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
28067
28158
|
message: changed ? "The project allow list or its trust state changed. Review it again." : "Project allow trust is unavailable."
|
|
28068
28159
|
});
|
|
28069
28160
|
}
|
|
@@ -28448,7 +28539,7 @@ var buildResumeDiff = async (meta, state, options = {}) => {
|
|
|
28448
28539
|
};
|
|
28449
28540
|
|
|
28450
28541
|
// src/rpc/run.ts
|
|
28451
|
-
var
|
|
28542
|
+
var import_protocol33 = require("@codelia/protocol");
|
|
28452
28543
|
|
|
28453
28544
|
// src/provider-errors.ts
|
|
28454
28545
|
var import_core39 = require("@codelia/core");
|
|
@@ -28518,23 +28609,23 @@ var normalizeRunFailure = (error) => {
|
|
|
28518
28609
|
|
|
28519
28610
|
// src/rpc/goals.ts
|
|
28520
28611
|
var import_core40 = require("@codelia/core");
|
|
28521
|
-
var
|
|
28612
|
+
var import_protocol31 = require("@codelia/protocol");
|
|
28522
28613
|
var import_storage31 = require("@codelia/storage");
|
|
28523
|
-
var
|
|
28524
|
-
var id =
|
|
28525
|
-
var revision =
|
|
28526
|
-
var target =
|
|
28527
|
-
var budget =
|
|
28614
|
+
var import_zod46 = require("zod");
|
|
28615
|
+
var id = import_zod46.z.string().min(1).max(200);
|
|
28616
|
+
var revision = import_zod46.z.number().int().positive();
|
|
28617
|
+
var target = import_zod46.z.object({ session_id: id, goal_id: id, revision });
|
|
28618
|
+
var budget = import_zod46.z.number().int().positive().nullable();
|
|
28528
28619
|
var schemas = {
|
|
28529
|
-
"goal.get":
|
|
28620
|
+
"goal.get": import_zod46.z.object({
|
|
28530
28621
|
session_id: id.optional(),
|
|
28531
28622
|
continuation_id: id.optional()
|
|
28532
28623
|
}),
|
|
28533
28624
|
"goal.set": target.partial().extend({
|
|
28534
|
-
objective:
|
|
28625
|
+
objective: import_zod46.z.string().trim().min(1).max(8e3).optional(),
|
|
28535
28626
|
token_budget: budget.optional()
|
|
28536
28627
|
}),
|
|
28537
|
-
"goal.pause":
|
|
28628
|
+
"goal.pause": import_zod46.z.object({
|
|
28538
28629
|
session_id: id,
|
|
28539
28630
|
goal_id: id,
|
|
28540
28631
|
activation_id: id,
|
|
@@ -28627,11 +28718,12 @@ var GoalController = class {
|
|
|
28627
28718
|
}
|
|
28628
28719
|
publish(goal) {
|
|
28629
28720
|
if (this.enabled && this.state.sessionId === goal.session_id)
|
|
28630
|
-
send(
|
|
28631
|
-
|
|
28632
|
-
|
|
28633
|
-
|
|
28634
|
-
|
|
28721
|
+
send(
|
|
28722
|
+
notificationMessage(
|
|
28723
|
+
"goal.updated",
|
|
28724
|
+
this.snapshot(goal.session_id, goal)
|
|
28725
|
+
)
|
|
28726
|
+
);
|
|
28635
28727
|
}
|
|
28636
28728
|
ready(goal, afterRunId) {
|
|
28637
28729
|
if (!this.enabled || this.state.activeRunId || this.state.sessionId !== goal.session_id || goal.status !== "active" || !this.owns(goal) || this.offer)
|
|
@@ -28643,7 +28735,7 @@ var GoalController = class {
|
|
|
28643
28735
|
continuation_id: crypto.randomUUID(),
|
|
28644
28736
|
...afterRunId ? { after_run_id: afterRunId } : {}
|
|
28645
28737
|
};
|
|
28646
|
-
send(
|
|
28738
|
+
send(notificationMessage("goal.ready", this.offer));
|
|
28647
28739
|
}
|
|
28648
28740
|
bound(requested) {
|
|
28649
28741
|
if (requested !== void 0 && requested !== this.state.sessionId)
|
|
@@ -28670,7 +28762,7 @@ var GoalController = class {
|
|
|
28670
28762
|
handle(requestId, method, raw, serialize, interrupt, onError) {
|
|
28671
28763
|
if (!this.enabled) {
|
|
28672
28764
|
sendError(requestId, {
|
|
28673
|
-
code:
|
|
28765
|
+
code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
28674
28766
|
message: "Goals are unavailable on this connection."
|
|
28675
28767
|
});
|
|
28676
28768
|
return Promise.resolve();
|
|
@@ -28693,7 +28785,8 @@ var GoalController = class {
|
|
|
28693
28785
|
const params = schemas[method].parse(raw ?? {});
|
|
28694
28786
|
sessionId = this.bound(params.session_id);
|
|
28695
28787
|
const result = sessionId ? await this.store.read(sessionId, params.continuation_id) : null;
|
|
28696
|
-
|
|
28788
|
+
sendRequestResult(
|
|
28789
|
+
method,
|
|
28697
28790
|
requestId,
|
|
28698
28791
|
this.snapshot(
|
|
28699
28792
|
sessionId,
|
|
@@ -28845,15 +28938,14 @@ var GoalController = class {
|
|
|
28845
28938
|
}
|
|
28846
28939
|
}
|
|
28847
28940
|
const snapshot = this.snapshot(sessionId, goal);
|
|
28848
|
-
|
|
28849
|
-
if (cleared)
|
|
28850
|
-
send({ jsonrpc: "2.0", method: "goal.cleared", params: snapshot });
|
|
28941
|
+
sendRequestResult(method, requestId, snapshot);
|
|
28942
|
+
if (cleared) send(notificationMessage("goal.cleared", snapshot));
|
|
28851
28943
|
if (goal) {
|
|
28852
28944
|
this.publish(goal);
|
|
28853
28945
|
if (method === "goal.set" || method === "goal.resume") this.ready(goal);
|
|
28854
28946
|
}
|
|
28855
28947
|
}).catch((error) => {
|
|
28856
|
-
if (!(error instanceof GoalConflict) && !(error instanceof
|
|
28948
|
+
if (!(error instanceof GoalConflict) && !(error instanceof import_zod46.z.ZodError)) {
|
|
28857
28949
|
if (method !== "goal.get") this.disarm();
|
|
28858
28950
|
onError(error);
|
|
28859
28951
|
}
|
|
@@ -28863,8 +28955,8 @@ var GoalController = class {
|
|
|
28863
28955
|
reject(requestId, error) {
|
|
28864
28956
|
const conflict = error instanceof GoalConflict ? error : null;
|
|
28865
28957
|
sendError(requestId, {
|
|
28866
|
-
code: conflict?.reason === "busy" ?
|
|
28867
|
-
message: conflict?.message ?? (error instanceof
|
|
28958
|
+
code: conflict?.reason === "busy" ? import_protocol31.RPC_ERROR_CODE.RUNTIME_BUSY : conflict || error instanceof import_zod46.z.ZodError ? import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol31.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
28959
|
+
message: conflict?.message ?? (error instanceof import_zod46.z.ZodError ? "Invalid goal parameters." : "Goal operation failed.")
|
|
28868
28960
|
});
|
|
28869
28961
|
}
|
|
28870
28962
|
validateOffer(raw) {
|
|
@@ -28954,7 +29046,7 @@ var GoalController = class {
|
|
|
28954
29046
|
(0, import_core40.defineTool)({
|
|
28955
29047
|
name: "get_goal",
|
|
28956
29048
|
description: "Read this run's session goal, including its objective, status, recorded tokens, and budget, or get {goal: null} if the run no longer holds the goal reservation.",
|
|
28957
|
-
input:
|
|
29049
|
+
input: import_zod46.z.object({}),
|
|
28958
29050
|
execute: async () => {
|
|
28959
29051
|
const entry = (await this.store.read(run.goal.session_id)).entry;
|
|
28960
29052
|
const goal = entry?.claim?.run_id === run.runId ? entry.goal : null;
|
|
@@ -28969,14 +29061,14 @@ ${goal.objective}` : "This run no longer holds the goal reservation."
|
|
|
28969
29061
|
(0, import_core40.defineTool)({
|
|
28970
29062
|
name: "update_goal",
|
|
28971
29063
|
description: "Report verified goal completion or a blocker that prevents further work before giving your final answer.",
|
|
28972
|
-
input:
|
|
28973
|
-
status:
|
|
29064
|
+
input: import_zod46.z.object({
|
|
29065
|
+
status: import_zod46.z.enum(["complete", "blocked"]).describe(
|
|
28974
29066
|
"Use complete after verifying every goal requirement, or blocked when a concrete obstacle prevents further work. Omit the tool call for ordinary progress."
|
|
28975
29067
|
),
|
|
28976
|
-
evidence:
|
|
29068
|
+
evidence: import_zod46.z.string().trim().min(1).max(2e3).describe(
|
|
28977
29069
|
"For complete, state what you verified and the observed result. For blocked, state the obstacle and why it prevents further work."
|
|
28978
29070
|
),
|
|
28979
|
-
blocker_key:
|
|
29071
|
+
blocker_key: import_zod46.z.string().trim().min(1).max(200).optional().describe(
|
|
28980
29072
|
"Required for blocked. Reuse the same short key for the same obstacle across runs. Three consecutive goal runs reporting the same key stop the goal."
|
|
28981
29073
|
)
|
|
28982
29074
|
}),
|
|
@@ -29621,6 +29713,47 @@ var createTextDeltaCoalescer = (options) => {
|
|
|
29621
29713
|
var nowIso5 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
29622
29714
|
var SESSION_STATE_SAVE_DEBOUNCE_MS = 1500;
|
|
29623
29715
|
var SESSION_WORKSPACE_ROOT_META_KEY = "codelia_workspace_root";
|
|
29716
|
+
var collectUnconsumedSteers = (steers, releaseAttachments) => {
|
|
29717
|
+
const seenSteerIds = /* @__PURE__ */ new Set();
|
|
29718
|
+
const unconsumedSteerIds = [];
|
|
29719
|
+
const unconsumedClientSteerIds = [];
|
|
29720
|
+
for (const steer of steers) {
|
|
29721
|
+
if (seenSteerIds.has(steer.steer_id)) continue;
|
|
29722
|
+
seenSteerIds.add(steer.steer_id);
|
|
29723
|
+
unconsumedSteerIds.push(steer.steer_id);
|
|
29724
|
+
if (steer.client_steer_id !== void 0)
|
|
29725
|
+
unconsumedClientSteerIds.push(steer.client_steer_id);
|
|
29726
|
+
releaseAttachments(steer.steer_id);
|
|
29727
|
+
}
|
|
29728
|
+
if (unconsumedSteerIds.length === 0) {
|
|
29729
|
+
return void 0;
|
|
29730
|
+
}
|
|
29731
|
+
return {
|
|
29732
|
+
unconsumed_steer_ids: unconsumedSteerIds,
|
|
29733
|
+
...unconsumedClientSteerIds.length ? { unconsumed_client_steer_ids: unconsumedClientSteerIds } : {}
|
|
29734
|
+
};
|
|
29735
|
+
};
|
|
29736
|
+
var correlateAppliedSteer = (event, polledSteers) => {
|
|
29737
|
+
if (event.type !== "steer_applied")
|
|
29738
|
+
return { confirmedIndex: -1, forwardedEvent: event };
|
|
29739
|
+
const confirmedIndex = polledSteers.findIndex(
|
|
29740
|
+
(steer) => steer.steer_id === event.steer_id
|
|
29741
|
+
);
|
|
29742
|
+
const clientSteerId = polledSteers[confirmedIndex]?.client_steer_id;
|
|
29743
|
+
const forwardedEvent = clientSteerId === void 0 ? event : { ...event, client_steer_id: clientSteerId };
|
|
29744
|
+
return { confirmedIndex, forwardedEvent };
|
|
29745
|
+
};
|
|
29746
|
+
var parseSteerInput = (input) => {
|
|
29747
|
+
let value;
|
|
29748
|
+
try {
|
|
29749
|
+
value = normalizeRunInput(input, "run.steer");
|
|
29750
|
+
} catch (error) {
|
|
29751
|
+
return { error: String(error) };
|
|
29752
|
+
}
|
|
29753
|
+
if (isRunInputEmpty(value))
|
|
29754
|
+
return { error: "run.steer input must not be empty" };
|
|
29755
|
+
return { value };
|
|
29756
|
+
};
|
|
29624
29757
|
var registerRunTools = (tools, wrap) => tools.map((tool) => {
|
|
29625
29758
|
const registered = wrap?.(tool);
|
|
29626
29759
|
if (!registered || !isSecuredRuntimeTool(registered))
|
|
@@ -29784,7 +29917,7 @@ var createRunHandlers = ({
|
|
|
29784
29917
|
initialInput = normalizeRunInput(params.input);
|
|
29785
29918
|
} catch (error) {
|
|
29786
29919
|
sendError(id2, {
|
|
29787
|
-
code:
|
|
29920
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29788
29921
|
message: String(error)
|
|
29789
29922
|
});
|
|
29790
29923
|
return;
|
|
@@ -29792,7 +29925,7 @@ var createRunHandlers = ({
|
|
|
29792
29925
|
const attachmentIds = runAttachmentIds(initialInput);
|
|
29793
29926
|
if (params.force_compaction && attachmentIds.length > 0) {
|
|
29794
29927
|
sendError(id2, {
|
|
29795
|
-
code:
|
|
29928
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29796
29929
|
message: "A compaction run cannot admit new attachments"
|
|
29797
29930
|
});
|
|
29798
29931
|
return;
|
|
@@ -29802,7 +29935,7 @@ var createRunHandlers = ({
|
|
|
29802
29935
|
await beforeRunStart();
|
|
29803
29936
|
} catch (error) {
|
|
29804
29937
|
sendError(id2, {
|
|
29805
|
-
code:
|
|
29938
|
+
code: import_protocol33.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
29806
29939
|
message: `startup onboarding failed: ${String(error)}`
|
|
29807
29940
|
});
|
|
29808
29941
|
return;
|
|
@@ -29810,7 +29943,7 @@ var createRunHandlers = ({
|
|
|
29810
29943
|
}
|
|
29811
29944
|
if (state.activeRunId) {
|
|
29812
29945
|
sendError(id2, {
|
|
29813
|
-
code:
|
|
29946
|
+
code: import_protocol33.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
29814
29947
|
message: "runtime busy"
|
|
29815
29948
|
});
|
|
29816
29949
|
return;
|
|
@@ -29827,14 +29960,14 @@ var createRunHandlers = ({
|
|
|
29827
29960
|
resumeState = await sessionStateStore.load(requestedSessionId);
|
|
29828
29961
|
} catch (error) {
|
|
29829
29962
|
sendError(id2, {
|
|
29830
|
-
code:
|
|
29963
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_LOAD_FAILED,
|
|
29831
29964
|
message: `session load failed: ${String(error)}`
|
|
29832
29965
|
});
|
|
29833
29966
|
return;
|
|
29834
29967
|
}
|
|
29835
29968
|
if (!resumeState) {
|
|
29836
29969
|
sendError(id2, {
|
|
29837
|
-
code:
|
|
29970
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_NOT_FOUND,
|
|
29838
29971
|
message: "session not found"
|
|
29839
29972
|
});
|
|
29840
29973
|
return;
|
|
@@ -29845,7 +29978,7 @@ var createRunHandlers = ({
|
|
|
29845
29978
|
resumeState = await sessionStateStore.load(state.sessionId);
|
|
29846
29979
|
} catch (error) {
|
|
29847
29980
|
sendError(id2, {
|
|
29848
|
-
code:
|
|
29981
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_LOAD_FAILED,
|
|
29849
29982
|
message: `session reload failed: ${String(error)}`
|
|
29850
29983
|
});
|
|
29851
29984
|
return;
|
|
@@ -29862,7 +29995,7 @@ var createRunHandlers = ({
|
|
|
29862
29995
|
if (resumeState?.meta?.codelia_subagent) {
|
|
29863
29996
|
restorePreviousModel();
|
|
29864
29997
|
sendError(id2, {
|
|
29865
|
-
code:
|
|
29998
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29866
29999
|
message: "Delegated sessions cannot be resumed as a root run"
|
|
29867
30000
|
});
|
|
29868
30001
|
return;
|
|
@@ -29887,7 +30020,7 @@ var createRunHandlers = ({
|
|
|
29887
30020
|
} catch (error) {
|
|
29888
30021
|
restorePreviousModel();
|
|
29889
30022
|
sendError(id2, {
|
|
29890
|
-
code: error instanceof AttachmentAdmissionError ?
|
|
30023
|
+
code: error instanceof AttachmentAdmissionError ? import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol33.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
29891
30024
|
message: error instanceof Error ? error.message : String(error)
|
|
29892
30025
|
});
|
|
29893
30026
|
return;
|
|
@@ -29904,7 +30037,7 @@ var createRunHandlers = ({
|
|
|
29904
30037
|
} catch (error) {
|
|
29905
30038
|
restorePreviousModel();
|
|
29906
30039
|
sendError(id2, {
|
|
29907
|
-
code:
|
|
30040
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29908
30041
|
message: String(error)
|
|
29909
30042
|
});
|
|
29910
30043
|
return;
|
|
@@ -29923,7 +30056,7 @@ var createRunHandlers = ({
|
|
|
29923
30056
|
} catch {
|
|
29924
30057
|
restorePreviousModel();
|
|
29925
30058
|
sendError(id2, {
|
|
29926
|
-
code:
|
|
30059
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29927
30060
|
message: "Could not claim the attachments for this conversation. Upload them again."
|
|
29928
30061
|
});
|
|
29929
30062
|
return;
|
|
@@ -30250,7 +30383,7 @@ var createRunHandlers = ({
|
|
|
30250
30383
|
session_id: sessionId,
|
|
30251
30384
|
...sessionStore.filePath ? { session_log_path: sessionStore.filePath } : {}
|
|
30252
30385
|
};
|
|
30253
|
-
|
|
30386
|
+
sendRequestResult("run.start", id2, result);
|
|
30254
30387
|
responseSent = true;
|
|
30255
30388
|
log2(`run.start ${runId}`);
|
|
30256
30389
|
emitRunStatus(runId, "running");
|
|
@@ -30272,22 +30405,12 @@ var createRunHandlers = ({
|
|
|
30272
30405
|
const remainingSteers = state.drainRunSteers(runId);
|
|
30273
30406
|
if (goals && admittedGoal && polledUnconfirmedSteers.length)
|
|
30274
30407
|
goals.recordApprovalSteer(admittedGoal, void 0);
|
|
30275
|
-
const
|
|
30276
|
-
|
|
30277
|
-
|
|
30278
|
-
|
|
30279
|
-
...remainingSteers
|
|
30280
|
-
]) {
|
|
30281
|
-
if (seenSteerIds.has(steer.steer_id)) continue;
|
|
30282
|
-
seenSteerIds.add(steer.steer_id);
|
|
30283
|
-
unconsumedSteerIds.push(steer.steer_id);
|
|
30284
|
-
releaseSteerAttachments(steer.steer_id);
|
|
30285
|
-
}
|
|
30408
|
+
const extras = collectUnconsumedSteers(
|
|
30409
|
+
[...polledUnconfirmedSteers, ...remainingSteers],
|
|
30410
|
+
releaseSteerAttachments
|
|
30411
|
+
);
|
|
30286
30412
|
polledUnconfirmedSteers.length = 0;
|
|
30287
|
-
|
|
30288
|
-
return void 0;
|
|
30289
|
-
}
|
|
30290
|
-
return { unconsumed_steer_ids: unconsumedSteerIds };
|
|
30413
|
+
return extras;
|
|
30291
30414
|
};
|
|
30292
30415
|
const queueSessionSave = (reason) => {
|
|
30293
30416
|
sessionSaveChain = sessionSaveChain.then(async () => {
|
|
@@ -30441,32 +30564,31 @@ var createRunHandlers = ({
|
|
|
30441
30564
|
`event.received ${summarizeRunEvent(event)}`
|
|
30442
30565
|
);
|
|
30443
30566
|
}
|
|
30444
|
-
const
|
|
30445
|
-
|
|
30446
|
-
|
|
30447
|
-
|
|
30448
|
-
|
|
30449
|
-
|
|
30450
|
-
|
|
30451
|
-
|
|
30452
|
-
|
|
30453
|
-
|
|
30567
|
+
const { confirmedIndex, forwardedEvent } = correlateAppliedSteer(
|
|
30568
|
+
event,
|
|
30569
|
+
polledUnconfirmedSteers
|
|
30570
|
+
);
|
|
30571
|
+
const seq = sendAgentEvent(state, runId, forwardedEvent);
|
|
30572
|
+
if (seq !== null && event.type === "steer_applied" && confirmedIndex >= 0) {
|
|
30573
|
+
if (goals && admittedGoal)
|
|
30574
|
+
goals.recordApprovalSteer(
|
|
30575
|
+
admittedGoal,
|
|
30576
|
+
state.approvalSteerText(runId, event.steer_id)
|
|
30577
|
+
);
|
|
30578
|
+
state.confirmApprovalSteer(runId, event.steer_id);
|
|
30579
|
+
polledUnconfirmedSteers.splice(confirmedIndex, 1);
|
|
30580
|
+
releaseSteerAttachments(event.steer_id);
|
|
30581
|
+
if (approvalScope && sessionStateStore.confirmApprovalSteer) {
|
|
30582
|
+
try {
|
|
30583
|
+
await sessionStateStore.confirmApprovalSteer(
|
|
30584
|
+
sessionId,
|
|
30585
|
+
runId,
|
|
30586
|
+
event.steer_id
|
|
30587
|
+
);
|
|
30588
|
+
} catch (error) {
|
|
30589
|
+
log2(
|
|
30590
|
+
`Could not record applied Steer for historical approval: ${String(error)}`
|
|
30454
30591
|
);
|
|
30455
|
-
state.confirmApprovalSteer(runId, event.steer_id);
|
|
30456
|
-
polledUnconfirmedSteers.splice(confirmedIndex, 1);
|
|
30457
|
-
releaseSteerAttachments(event.steer_id);
|
|
30458
|
-
if (approvalScope && sessionStateStore.confirmApprovalSteer) {
|
|
30459
|
-
try {
|
|
30460
|
-
await sessionStateStore.confirmApprovalSteer(
|
|
30461
|
-
sessionId,
|
|
30462
|
-
runId,
|
|
30463
|
-
event.steer_id
|
|
30464
|
-
);
|
|
30465
|
-
} catch (error) {
|
|
30466
|
-
log2(
|
|
30467
|
-
`Could not record applied Steer for historical approval: ${String(error)}`
|
|
30468
|
-
);
|
|
30469
|
-
}
|
|
30470
30592
|
}
|
|
30471
30593
|
}
|
|
30472
30594
|
}
|
|
@@ -30483,7 +30605,7 @@ var createRunHandlers = ({
|
|
|
30483
30605
|
run_id: runId,
|
|
30484
30606
|
ts: nowIso5(),
|
|
30485
30607
|
seq,
|
|
30486
|
-
event
|
|
30608
|
+
event: forwardedEvent
|
|
30487
30609
|
});
|
|
30488
30610
|
}
|
|
30489
30611
|
emitContextUsage(event.type);
|
|
@@ -30607,33 +30729,35 @@ var createRunHandlers = ({
|
|
|
30607
30729
|
const runId = typeof params?.run_id === "string" ? params.run_id.trim() : "";
|
|
30608
30730
|
if (!runId) {
|
|
30609
30731
|
sendError(id2, {
|
|
30610
|
-
code:
|
|
30732
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30611
30733
|
message: "run_id is required"
|
|
30612
30734
|
});
|
|
30613
30735
|
return Promise.resolve();
|
|
30614
30736
|
}
|
|
30615
|
-
|
|
30616
|
-
|
|
30617
|
-
|
|
30618
|
-
|
|
30619
|
-
|
|
30620
|
-
|
|
30621
|
-
message: String(error)
|
|
30622
|
-
});
|
|
30623
|
-
return Promise.resolve();
|
|
30624
|
-
}
|
|
30625
|
-
if (isRunInputEmpty(initialInput)) {
|
|
30626
|
-
sendError(id2, {
|
|
30627
|
-
code: import_protocol16.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30628
|
-
message: "run.steer input must not be empty"
|
|
30629
|
-
});
|
|
30630
|
-
return Promise.resolve();
|
|
30631
|
-
}
|
|
30632
|
-
const clientSteerId = typeof params.client_steer_id === "string" && params.client_steer_id.trim() ? params.client_steer_id.trim() : void 0;
|
|
30737
|
+
const clientSteerId = params.client_steer_id;
|
|
30738
|
+
const acknowledge = (steerId) => sendRequestResult("run.steer", id2, {
|
|
30739
|
+
ok: true,
|
|
30740
|
+
steer_id: steerId,
|
|
30741
|
+
...clientSteerId !== void 0 ? { client_steer_id: clientSteerId } : {}
|
|
30742
|
+
});
|
|
30633
30743
|
const admitSteer = async () => {
|
|
30744
|
+
const acceptedId = clientSteerId === void 0 ? void 0 : state.acceptedRunSteerId(runId, clientSteerId);
|
|
30745
|
+
if (acceptedId) {
|
|
30746
|
+
acknowledge(acceptedId);
|
|
30747
|
+
return;
|
|
30748
|
+
}
|
|
30749
|
+
const input = parseSteerInput(params.input);
|
|
30750
|
+
if ("error" in input) {
|
|
30751
|
+
sendError(id2, {
|
|
30752
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30753
|
+
message: input.error
|
|
30754
|
+
});
|
|
30755
|
+
return;
|
|
30756
|
+
}
|
|
30757
|
+
const initialInput = input.value;
|
|
30634
30758
|
if (!state.canSteerRun(runId)) {
|
|
30635
30759
|
sendError(id2, {
|
|
30636
|
-
code:
|
|
30760
|
+
code: import_protocol33.RPC_ERROR_CODE.RUN_NOT_FOUND,
|
|
30637
30761
|
message: "active run not found"
|
|
30638
30762
|
});
|
|
30639
30763
|
return;
|
|
@@ -30659,7 +30783,7 @@ var createRunHandlers = ({
|
|
|
30659
30783
|
normalizedInput = await state.prepareRunImages(normalizedInput);
|
|
30660
30784
|
} catch (error) {
|
|
30661
30785
|
sendError(id2, {
|
|
30662
|
-
code: error instanceof AttachmentAdmissionError ?
|
|
30786
|
+
code: error instanceof AttachmentAdmissionError ? import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol33.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
30663
30787
|
message: error instanceof Error ? error.message : String(error)
|
|
30664
30788
|
});
|
|
30665
30789
|
return;
|
|
@@ -30673,7 +30797,7 @@ var createRunHandlers = ({
|
|
|
30673
30797
|
);
|
|
30674
30798
|
} catch {
|
|
30675
30799
|
sendError(id2, {
|
|
30676
|
-
code:
|
|
30800
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30677
30801
|
message: "Could not retain the attachments for this conversation. Upload them again."
|
|
30678
30802
|
});
|
|
30679
30803
|
return;
|
|
@@ -30682,7 +30806,7 @@ var createRunHandlers = ({
|
|
|
30682
30806
|
if (!state.canSteerRun(runId)) {
|
|
30683
30807
|
releaseAttachments?.();
|
|
30684
30808
|
sendError(id2, {
|
|
30685
|
-
code:
|
|
30809
|
+
code: import_protocol33.RPC_ERROR_CODE.RUN_NOT_FOUND,
|
|
30686
30810
|
message: "active run ended before steer could be queued"
|
|
30687
30811
|
});
|
|
30688
30812
|
return;
|
|
@@ -30698,10 +30822,7 @@ var createRunHandlers = ({
|
|
|
30698
30822
|
ids: attachmentIds,
|
|
30699
30823
|
release: releaseAttachments
|
|
30700
30824
|
});
|
|
30701
|
-
|
|
30702
|
-
ok: true,
|
|
30703
|
-
steer_id: steerId
|
|
30704
|
-
});
|
|
30825
|
+
acknowledge(steerId);
|
|
30705
30826
|
logRunDebug(log2, runId, `run.steer queued steer_id=${steerId}`);
|
|
30706
30827
|
};
|
|
30707
30828
|
const queued = runSteerQueue.then(admitSteer, admitSteer);
|
|
@@ -30720,28 +30841,33 @@ var createRunHandlers = ({
|
|
|
30720
30841
|
const handleGoal = (id2, method, raw) => {
|
|
30721
30842
|
if (!goals?.enabled) {
|
|
30722
30843
|
sendError(id2, {
|
|
30723
|
-
code:
|
|
30844
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30724
30845
|
message: "Goals are unavailable on this connection."
|
|
30725
30846
|
});
|
|
30726
30847
|
return Promise.resolve();
|
|
30727
30848
|
}
|
|
30849
|
+
const parsed = parseRequestParams(method, raw);
|
|
30850
|
+
if (!parsed.ok) {
|
|
30851
|
+
sendError(id2, parsed.error);
|
|
30852
|
+
return Promise.resolve();
|
|
30853
|
+
}
|
|
30728
30854
|
if (method === "goal.continue") {
|
|
30729
|
-
const params =
|
|
30855
|
+
const params = parsed.params;
|
|
30730
30856
|
return handleRunStart(
|
|
30731
30857
|
id2,
|
|
30732
30858
|
{
|
|
30733
30859
|
input: { type: "text", text: "" },
|
|
30734
|
-
session_id: params
|
|
30735
|
-
tools: params
|
|
30736
|
-
ui_context: params
|
|
30860
|
+
session_id: params.session_id,
|
|
30861
|
+
tools: params.tools,
|
|
30862
|
+
ui_context: params.ui_context
|
|
30737
30863
|
},
|
|
30738
|
-
|
|
30864
|
+
params
|
|
30739
30865
|
);
|
|
30740
30866
|
}
|
|
30741
30867
|
return goals.handle(
|
|
30742
30868
|
id2,
|
|
30743
30869
|
method,
|
|
30744
|
-
|
|
30870
|
+
parsed.params,
|
|
30745
30871
|
serializeAdmission,
|
|
30746
30872
|
interruptRun,
|
|
30747
30873
|
(error) => log2(`goal operation failed: ${String(error)}`)
|
|
@@ -30749,12 +30875,12 @@ var createRunHandlers = ({
|
|
|
30749
30875
|
};
|
|
30750
30876
|
const handleRunCancel = (id2, params) => {
|
|
30751
30877
|
if (interruptRun(params.run_id, params.reason)) {
|
|
30752
|
-
|
|
30878
|
+
sendRequestResult("run.cancel", id2, { ok: true });
|
|
30753
30879
|
log2(`run.cancel ${params.run_id} (${params.reason ?? "no reason"})`);
|
|
30754
30880
|
return;
|
|
30755
30881
|
}
|
|
30756
30882
|
sendError(id2, {
|
|
30757
|
-
code:
|
|
30883
|
+
code: import_protocol33.RPC_ERROR_CODE.RUN_NOT_FOUND,
|
|
30758
30884
|
message: "run not found"
|
|
30759
30885
|
});
|
|
30760
30886
|
};
|
|
@@ -30765,20 +30891,22 @@ var createRunHandlers = ({
|
|
|
30765
30891
|
const open3 = async () => {
|
|
30766
30892
|
if (!sessionId) {
|
|
30767
30893
|
sendError(id2, {
|
|
30768
|
-
code:
|
|
30894
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30769
30895
|
message: "session_id is required"
|
|
30770
30896
|
});
|
|
30771
30897
|
return;
|
|
30772
30898
|
}
|
|
30773
30899
|
if (state.activeRunId) {
|
|
30774
30900
|
sendError(id2, {
|
|
30775
|
-
code:
|
|
30901
|
+
code: import_protocol33.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
30776
30902
|
message: "runtime busy"
|
|
30777
30903
|
});
|
|
30778
30904
|
return;
|
|
30779
30905
|
}
|
|
30780
30906
|
if (sessionId === state.sessionId) {
|
|
30781
|
-
|
|
30907
|
+
sendRequestResult("session.open", id2, {
|
|
30908
|
+
session_id: sessionId
|
|
30909
|
+
});
|
|
30782
30910
|
return;
|
|
30783
30911
|
}
|
|
30784
30912
|
let opened;
|
|
@@ -30786,21 +30914,21 @@ var createRunHandlers = ({
|
|
|
30786
30914
|
opened = await sessionStateStore.load(sessionId);
|
|
30787
30915
|
} catch (error) {
|
|
30788
30916
|
sendError(id2, {
|
|
30789
|
-
code:
|
|
30917
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_LOAD_FAILED,
|
|
30790
30918
|
message: `session load failed: ${String(error)}`
|
|
30791
30919
|
});
|
|
30792
30920
|
return;
|
|
30793
30921
|
}
|
|
30794
30922
|
if (!opened) {
|
|
30795
30923
|
sendError(id2, {
|
|
30796
|
-
code:
|
|
30924
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_NOT_FOUND,
|
|
30797
30925
|
message: "session not found"
|
|
30798
30926
|
});
|
|
30799
30927
|
return;
|
|
30800
30928
|
}
|
|
30801
30929
|
if (opened.meta?.codelia_subagent) {
|
|
30802
30930
|
sendError(id2, {
|
|
30803
|
-
code:
|
|
30931
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30804
30932
|
message: "Delegated sessions cannot be opened as a root session"
|
|
30805
30933
|
});
|
|
30806
30934
|
return;
|
|
@@ -30812,7 +30940,9 @@ var createRunHandlers = ({
|
|
|
30812
30940
|
state.sessionAppend = null;
|
|
30813
30941
|
applySessionModelOverrideFromMeta(state, opened.meta);
|
|
30814
30942
|
state.agent = null;
|
|
30815
|
-
|
|
30943
|
+
sendRequestResult("session.open", id2, {
|
|
30944
|
+
session_id: sessionId
|
|
30945
|
+
});
|
|
30816
30946
|
log2(`session.open ${sessionId}`);
|
|
30817
30947
|
};
|
|
30818
30948
|
const queued = runStartQueue.then(open3, open3);
|
|
@@ -30836,15 +30966,8 @@ var createRunHandlers = ({
|
|
|
30836
30966
|
|
|
30837
30967
|
// src/rpc/sandbox.ts
|
|
30838
30968
|
var import_promises5 = require("fs/promises");
|
|
30839
|
-
var
|
|
30840
|
-
var import_shared_types11 = require("@codelia/shared-types");
|
|
30969
|
+
var import_protocol35 = require("@codelia/protocol");
|
|
30841
30970
|
var import_storage32 = require("@codelia/storage");
|
|
30842
|
-
var import_zod49 = require("zod");
|
|
30843
|
-
var getParams = import_zod49.z.strictObject({});
|
|
30844
|
-
var setParams = import_zod49.z.strictObject({
|
|
30845
|
-
scope: import_zod49.z.literal("project"),
|
|
30846
|
-
mode: import_zod49.z.enum(import_shared_types11.sandboxModes)
|
|
30847
|
-
});
|
|
30848
30971
|
var choices = [
|
|
30849
30972
|
{
|
|
30850
30973
|
id: "readonly",
|
|
@@ -30911,30 +31034,25 @@ var status = async (state, store) => {
|
|
|
30911
31034
|
var handleSandbox = async (state, id2, method, params) => {
|
|
30912
31035
|
if (!supportsSandboxModeManagement(state))
|
|
30913
31036
|
return sendError(id2, {
|
|
30914
|
-
code:
|
|
31037
|
+
code: import_protocol35.RPC_ERROR_CODE.METHOD_NOT_FOUND,
|
|
30915
31038
|
message: "Sandbox management is unavailable."
|
|
30916
31039
|
});
|
|
30917
|
-
const store = new import_storage32.ProjectsPolicyStore();
|
|
30918
31040
|
if (method === "sandbox.get") {
|
|
30919
|
-
|
|
30920
|
-
|
|
30921
|
-
|
|
30922
|
-
|
|
30923
|
-
|
|
30924
|
-
return sendResult(
|
|
31041
|
+
const parsed2 = parseRequestParams(method, params);
|
|
31042
|
+
if (!parsed2.ok) return sendError(id2, parsed2.error);
|
|
31043
|
+
const store2 = new import_storage32.ProjectsPolicyStore();
|
|
31044
|
+
return sendRequestResult(
|
|
31045
|
+
method,
|
|
30925
31046
|
id2,
|
|
30926
|
-
await state.withAdmissionLock(() => status(state,
|
|
31047
|
+
await state.withAdmissionLock(() => status(state, store2))
|
|
30927
31048
|
);
|
|
30928
31049
|
}
|
|
30929
|
-
const parsed =
|
|
30930
|
-
if (!parsed.
|
|
30931
|
-
|
|
30932
|
-
|
|
30933
|
-
message: "Select a sandbox mode with project scope."
|
|
30934
|
-
});
|
|
30935
|
-
const { mode } = parsed.data;
|
|
31050
|
+
const parsed = parseRequestParams(method, params);
|
|
31051
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
31052
|
+
const { mode } = parsed.params;
|
|
31053
|
+
const store = new import_storage32.ProjectsPolicyStore();
|
|
30936
31054
|
const fail = (reason) => sendError(id2, {
|
|
30937
|
-
code: reason === "runtime_busy" || reason === "policy_store_busy" ?
|
|
31055
|
+
code: reason === "runtime_busy" || reason === "policy_store_busy" ? import_protocol35.RPC_ERROR_CODE.RUNTIME_BUSY : import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30938
31056
|
message: `Project sandbox mode could not be changed (${reason}).`,
|
|
30939
31057
|
data: { reason }
|
|
30940
31058
|
});
|
|
@@ -30955,30 +31073,33 @@ var handleSandbox = async (state, id2, method, params) => {
|
|
|
30955
31073
|
state.sandboxMode = { value: mode, source: "project" };
|
|
30956
31074
|
state.approvalMode = null;
|
|
30957
31075
|
state.invalidateAgentCache();
|
|
30958
|
-
return
|
|
31076
|
+
return sendRequestResult(method, id2, await status(state, store));
|
|
30959
31077
|
});
|
|
30960
31078
|
};
|
|
30961
31079
|
|
|
30962
31080
|
// src/rpc/session-lifecycle.ts
|
|
30963
|
-
var
|
|
30964
|
-
var createSessionUpdateHandler = (options) => async (id2,
|
|
31081
|
+
var import_protocol37 = require("@codelia/protocol");
|
|
31082
|
+
var createSessionUpdateHandler = (options) => async (id2, raw) => {
|
|
30965
31083
|
if (!options.sessions.updateMetadata) {
|
|
30966
31084
|
sendError(id2, {
|
|
30967
|
-
code:
|
|
31085
|
+
code: import_protocol37.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30968
31086
|
message: "Session lifecycle updates are unavailable"
|
|
30969
31087
|
});
|
|
30970
31088
|
return;
|
|
30971
31089
|
}
|
|
30972
|
-
|
|
31090
|
+
const parsed = parseRequestParams("session.update", raw);
|
|
31091
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
31092
|
+
const params = parsed.params;
|
|
31093
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(params.session_id) || params.pinned === void 0 && params.archived === void 0) {
|
|
30973
31094
|
sendError(id2, {
|
|
30974
|
-
code:
|
|
31095
|
+
code: import_protocol37.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30975
31096
|
message: "Expected session_id and a boolean pinned or archived update"
|
|
30976
31097
|
});
|
|
30977
31098
|
return;
|
|
30978
31099
|
}
|
|
30979
31100
|
if (params.archived && options.state.activeRunId && options.state.sessionId === params.session_id) {
|
|
30980
31101
|
sendError(id2, {
|
|
30981
|
-
code:
|
|
31102
|
+
code: import_protocol37.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
30982
31103
|
message: "Wait for the active run before archiving this session"
|
|
30983
31104
|
});
|
|
30984
31105
|
return;
|
|
@@ -30996,10 +31117,10 @@ var createSessionUpdateHandler = (options) => async (id2, params) => {
|
|
|
30996
31117
|
}
|
|
30997
31118
|
}
|
|
30998
31119
|
const result = { session };
|
|
30999
|
-
|
|
31120
|
+
sendRequestResult("session.update", id2, result);
|
|
31000
31121
|
} catch (error) {
|
|
31001
31122
|
sendError(id2, {
|
|
31002
|
-
code:
|
|
31123
|
+
code: import_protocol37.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31003
31124
|
message: `Session update failed: ${String(error)}`
|
|
31004
31125
|
});
|
|
31005
31126
|
}
|
|
@@ -31007,7 +31128,7 @@ var createSessionUpdateHandler = (options) => async (id2, params) => {
|
|
|
31007
31128
|
|
|
31008
31129
|
// src/rpc/shell.ts
|
|
31009
31130
|
var import_node_path47 = __toESM(require("path"), 1);
|
|
31010
|
-
var
|
|
31131
|
+
var import_protocol39 = require("@codelia/protocol");
|
|
31011
31132
|
var import_storage33 = require("@codelia/storage");
|
|
31012
31133
|
var COMMAND_PREVIEW_CHARS = 400;
|
|
31013
31134
|
var DEFAULT_TRUNCATED = {
|
|
@@ -31059,7 +31180,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31059
31180
|
if (!taskId) {
|
|
31060
31181
|
return {
|
|
31061
31182
|
error: {
|
|
31062
|
-
code:
|
|
31183
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31063
31184
|
message: "task_id is required"
|
|
31064
31185
|
}
|
|
31065
31186
|
};
|
|
@@ -31067,7 +31188,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31067
31188
|
if (params?.stream !== "stdout" && params?.stream !== "stderr") {
|
|
31068
31189
|
return {
|
|
31069
31190
|
error: {
|
|
31070
|
-
code:
|
|
31191
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31071
31192
|
message: "stream must be stdout or stderr"
|
|
31072
31193
|
}
|
|
31073
31194
|
};
|
|
@@ -31075,7 +31196,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31075
31196
|
if (params.line_number !== void 0 && (params.offset !== void 0 || params.limit !== void 0)) {
|
|
31076
31197
|
return {
|
|
31077
31198
|
error: {
|
|
31078
|
-
code:
|
|
31199
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31079
31200
|
message: "line_number cannot be combined with offset or limit"
|
|
31080
31201
|
}
|
|
31081
31202
|
};
|
|
@@ -31083,7 +31204,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31083
31204
|
if (params.line_number === void 0 && (params.char_offset !== void 0 || params.char_limit !== void 0)) {
|
|
31084
31205
|
return {
|
|
31085
31206
|
error: {
|
|
31086
|
-
code:
|
|
31207
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31087
31208
|
message: "char_offset/char_limit require line_number"
|
|
31088
31209
|
}
|
|
31089
31210
|
};
|
|
@@ -31091,7 +31212,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31091
31212
|
if (params.offset !== void 0 && (!Number.isFinite(params.offset) || params.offset < 0)) {
|
|
31092
31213
|
return {
|
|
31093
31214
|
error: {
|
|
31094
|
-
code:
|
|
31215
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31095
31216
|
message: "offset must be a non-negative number"
|
|
31096
31217
|
}
|
|
31097
31218
|
};
|
|
@@ -31099,7 +31220,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31099
31220
|
if (params.limit !== void 0 && (!Number.isFinite(params.limit) || params.limit <= 0)) {
|
|
31100
31221
|
return {
|
|
31101
31222
|
error: {
|
|
31102
|
-
code:
|
|
31223
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31103
31224
|
message: "limit must be a positive number"
|
|
31104
31225
|
}
|
|
31105
31226
|
};
|
|
@@ -31107,7 +31228,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31107
31228
|
if (params.line_number !== void 0 && (!Number.isFinite(params.line_number) || params.line_number <= 0)) {
|
|
31108
31229
|
return {
|
|
31109
31230
|
error: {
|
|
31110
|
-
code:
|
|
31231
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31111
31232
|
message: "line_number must be a positive number"
|
|
31112
31233
|
}
|
|
31113
31234
|
};
|
|
@@ -31115,7 +31236,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31115
31236
|
if (params.char_offset !== void 0 && (!Number.isFinite(params.char_offset) || params.char_offset < 0)) {
|
|
31116
31237
|
return {
|
|
31117
31238
|
error: {
|
|
31118
|
-
code:
|
|
31239
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31119
31240
|
message: "char_offset must be a non-negative number"
|
|
31120
31241
|
}
|
|
31121
31242
|
};
|
|
@@ -31123,7 +31244,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31123
31244
|
if (params.char_limit !== void 0 && (!Number.isFinite(params.char_limit) || params.char_limit <= 0)) {
|
|
31124
31245
|
return {
|
|
31125
31246
|
error: {
|
|
31126
|
-
code:
|
|
31247
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31127
31248
|
message: "char_limit must be a positive number"
|
|
31128
31249
|
}
|
|
31129
31250
|
};
|
|
@@ -31177,7 +31298,7 @@ var parseTaskId = (value) => {
|
|
|
31177
31298
|
var toTaskRpcError = (error) => {
|
|
31178
31299
|
if (!(error instanceof TaskManagerError)) {
|
|
31179
31300
|
return {
|
|
31180
|
-
code:
|
|
31301
|
+
code: import_protocol39.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31181
31302
|
message: String(error)
|
|
31182
31303
|
};
|
|
31183
31304
|
}
|
|
@@ -31186,17 +31307,17 @@ var toTaskRpcError = (error) => {
|
|
|
31186
31307
|
case "invalid_task_id":
|
|
31187
31308
|
case "unsupported_workspace_mode":
|
|
31188
31309
|
return {
|
|
31189
|
-
code:
|
|
31310
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31190
31311
|
message: error.message
|
|
31191
31312
|
};
|
|
31192
31313
|
case "manager_shutting_down":
|
|
31193
31314
|
return {
|
|
31194
|
-
code:
|
|
31315
|
+
code: import_protocol39.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
31195
31316
|
message: error.message
|
|
31196
31317
|
};
|
|
31197
31318
|
default:
|
|
31198
31319
|
return {
|
|
31199
|
-
code:
|
|
31320
|
+
code: import_protocol39.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31200
31321
|
message: error.message
|
|
31201
31322
|
};
|
|
31202
31323
|
}
|
|
@@ -31220,7 +31341,7 @@ var resolveShellTimeoutSeconds2 = (requestedTimeout, background) => {
|
|
|
31220
31341
|
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
31221
31342
|
return {
|
|
31222
31343
|
error: {
|
|
31223
|
-
code:
|
|
31344
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31224
31345
|
message: "timeout_seconds must be a positive number"
|
|
31225
31346
|
}
|
|
31226
31347
|
};
|
|
@@ -31234,7 +31355,7 @@ var resolveShellTimeoutSeconds2 = (requestedTimeout, background) => {
|
|
|
31234
31355
|
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
31235
31356
|
return {
|
|
31236
31357
|
error: {
|
|
31237
|
-
code:
|
|
31358
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31238
31359
|
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
31239
31360
|
}
|
|
31240
31361
|
};
|
|
@@ -31248,7 +31369,7 @@ var resolveShellWaitTimeoutSeconds2 = (requestedTimeout) => {
|
|
|
31248
31369
|
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
31249
31370
|
return {
|
|
31250
31371
|
error: {
|
|
31251
|
-
code:
|
|
31372
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31252
31373
|
message: "wait_timeout_seconds must be a positive number"
|
|
31253
31374
|
}
|
|
31254
31375
|
};
|
|
@@ -31256,7 +31377,7 @@ var resolveShellWaitTimeoutSeconds2 = (requestedTimeout) => {
|
|
|
31256
31377
|
if (requestedTimeout > MAX_TIMEOUT_SECONDS) {
|
|
31257
31378
|
return {
|
|
31258
31379
|
error: {
|
|
31259
|
-
code:
|
|
31380
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31260
31381
|
message: `wait_timeout_seconds must be ${MAX_TIMEOUT_SECONDS} seconds or less`
|
|
31261
31382
|
}
|
|
31262
31383
|
};
|
|
@@ -31271,7 +31392,7 @@ var parseShellStartRequest = (state, params, options) => {
|
|
|
31271
31392
|
if (!command.trim()) {
|
|
31272
31393
|
return {
|
|
31273
31394
|
error: {
|
|
31274
|
-
code:
|
|
31395
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31275
31396
|
message: "command is required"
|
|
31276
31397
|
}
|
|
31277
31398
|
};
|
|
@@ -31287,7 +31408,7 @@ var parseShellStartRequest = (state, params, options) => {
|
|
|
31287
31408
|
if (!cwd) {
|
|
31288
31409
|
return {
|
|
31289
31410
|
error: {
|
|
31290
|
-
code:
|
|
31411
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31291
31412
|
message: "cwd is outside sandbox root"
|
|
31292
31413
|
}
|
|
31293
31414
|
};
|
|
@@ -31375,7 +31496,7 @@ var createShellHandlers = ({
|
|
|
31375
31496
|
const finished = await shellTaskManager.wait(task.task_id);
|
|
31376
31497
|
assertReceiptScopeCurrent(scope);
|
|
31377
31498
|
const result = toShellExecResult(commandPreview, finished.result);
|
|
31378
|
-
|
|
31499
|
+
sendRequestResult("shell.exec", id2, result);
|
|
31379
31500
|
log2(
|
|
31380
31501
|
`shell.exec.done origin=ui_bang duration_ms=${result.duration_ms} exit_code=${String(result.exit_code)} signal=${result.signal ?? "-"}`
|
|
31381
31502
|
);
|
|
@@ -31396,7 +31517,7 @@ var createShellHandlers = ({
|
|
|
31396
31517
|
try {
|
|
31397
31518
|
const { task } = await spawnShell(id2, params, "shell.start");
|
|
31398
31519
|
assertReceiptScopeCurrent(scope);
|
|
31399
|
-
|
|
31520
|
+
sendRequestResult("shell.start", id2, toShellTaskInfo(task));
|
|
31400
31521
|
} catch (error) {
|
|
31401
31522
|
if (scope.connectionSignal.aborted) return;
|
|
31402
31523
|
if (typeof error === "object" && error !== null && "code" in error && "message" in error) {
|
|
@@ -31413,7 +31534,7 @@ var createShellHandlers = ({
|
|
|
31413
31534
|
const requestedLimit = params?.limit;
|
|
31414
31535
|
if (requestedLimit !== void 0 && (!Number.isFinite(requestedLimit) || requestedLimit <= 0)) {
|
|
31415
31536
|
sendError(id2, {
|
|
31416
|
-
code:
|
|
31537
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31417
31538
|
message: "limit must be a positive number"
|
|
31418
31539
|
});
|
|
31419
31540
|
return;
|
|
@@ -31422,7 +31543,7 @@ var createShellHandlers = ({
|
|
|
31422
31543
|
const limit = requestedLimit ? Math.trunc(requestedLimit) : void 0;
|
|
31423
31544
|
const tasks = (await shellTaskManager.list({ sessionId: state.sessionId })).filter((task) => task.kind === "shell").slice(0, limit).map(toShellTaskInfo);
|
|
31424
31545
|
const result = { tasks };
|
|
31425
|
-
|
|
31546
|
+
sendRequestResult("shell.list", id2, result);
|
|
31426
31547
|
} catch (error) {
|
|
31427
31548
|
sendTaskError(id2, error);
|
|
31428
31549
|
}
|
|
@@ -31431,7 +31552,7 @@ var createShellHandlers = ({
|
|
|
31431
31552
|
const taskId = parseTaskId(params?.task_id);
|
|
31432
31553
|
if (!taskId) {
|
|
31433
31554
|
sendError(id2, {
|
|
31434
|
-
code:
|
|
31555
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31435
31556
|
message: "task_id is required"
|
|
31436
31557
|
});
|
|
31437
31558
|
return;
|
|
@@ -31442,7 +31563,7 @@ var createShellHandlers = ({
|
|
|
31442
31563
|
taskId,
|
|
31443
31564
|
state.sessionId
|
|
31444
31565
|
);
|
|
31445
|
-
|
|
31566
|
+
sendRequestResult("shell.status", id2, toShellTaskInfo(task));
|
|
31446
31567
|
} catch (error) {
|
|
31447
31568
|
sendTaskError(id2, error);
|
|
31448
31569
|
}
|
|
@@ -31467,7 +31588,7 @@ var createShellHandlers = ({
|
|
|
31467
31588
|
);
|
|
31468
31589
|
if (!cacheId && liveContent === null && !isTerminalTaskState(task.state)) {
|
|
31469
31590
|
sendError(id2, {
|
|
31470
|
-
code:
|
|
31591
|
+
code: import_protocol39.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
31471
31592
|
message: `shell output is not retained yet for running task: ${parsed.taskId}`
|
|
31472
31593
|
});
|
|
31473
31594
|
return;
|
|
@@ -31495,7 +31616,7 @@ var createShellHandlers = ({
|
|
|
31495
31616
|
content,
|
|
31496
31617
|
...cacheId ? { ref_id: cacheId } : {}
|
|
31497
31618
|
};
|
|
31498
|
-
|
|
31619
|
+
sendRequestResult("shell.output", id2, result);
|
|
31499
31620
|
} catch (error) {
|
|
31500
31621
|
sendTaskError(id2, error);
|
|
31501
31622
|
}
|
|
@@ -31504,7 +31625,7 @@ var createShellHandlers = ({
|
|
|
31504
31625
|
const taskId = parseTaskId(params?.task_id);
|
|
31505
31626
|
if (!taskId) {
|
|
31506
31627
|
sendError(id2, {
|
|
31507
|
-
code:
|
|
31628
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31508
31629
|
message: "task_id is required"
|
|
31509
31630
|
});
|
|
31510
31631
|
return;
|
|
@@ -31523,7 +31644,7 @@ var createShellHandlers = ({
|
|
|
31523
31644
|
state.sessionId
|
|
31524
31645
|
);
|
|
31525
31646
|
if (isTerminalTaskState(existing.state)) {
|
|
31526
|
-
|
|
31647
|
+
sendRequestResult("shell.wait", id2, toShellTaskInfo(existing));
|
|
31527
31648
|
return;
|
|
31528
31649
|
}
|
|
31529
31650
|
const controller = new AbortController();
|
|
@@ -31563,7 +31684,7 @@ var createShellHandlers = ({
|
|
|
31563
31684
|
timeoutPromise
|
|
31564
31685
|
]);
|
|
31565
31686
|
if (outcome.type === "detached") {
|
|
31566
|
-
|
|
31687
|
+
sendRequestResult("shell.wait", id2, outcome.result);
|
|
31567
31688
|
return;
|
|
31568
31689
|
}
|
|
31569
31690
|
if (outcome.type === "still_running") {
|
|
@@ -31572,7 +31693,7 @@ var createShellHandlers = ({
|
|
|
31572
31693
|
taskId,
|
|
31573
31694
|
state.sessionId
|
|
31574
31695
|
);
|
|
31575
|
-
|
|
31696
|
+
sendRequestResult("shell.wait", id2, {
|
|
31576
31697
|
...toShellTaskInfo(task),
|
|
31577
31698
|
...isTerminalTaskState(task.state) ? {} : { still_running: true }
|
|
31578
31699
|
});
|
|
@@ -31581,7 +31702,7 @@ var createShellHandlers = ({
|
|
|
31581
31702
|
if (outcome.type === "aborted") {
|
|
31582
31703
|
return;
|
|
31583
31704
|
}
|
|
31584
|
-
|
|
31705
|
+
sendRequestResult("shell.wait", id2, toShellTaskInfo(outcome.task));
|
|
31585
31706
|
} finally {
|
|
31586
31707
|
if (timeoutHandle) {
|
|
31587
31708
|
clearTimeout(timeoutHandle);
|
|
@@ -31596,7 +31717,7 @@ var createShellHandlers = ({
|
|
|
31596
31717
|
const taskId = parseTaskId(params?.task_id);
|
|
31597
31718
|
if (!taskId) {
|
|
31598
31719
|
sendError(id2, {
|
|
31599
|
-
code:
|
|
31720
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31600
31721
|
message: "task_id is required"
|
|
31601
31722
|
});
|
|
31602
31723
|
return;
|
|
@@ -31610,7 +31731,7 @@ var createShellHandlers = ({
|
|
|
31610
31731
|
const waits = activeShellWaits.get(taskId);
|
|
31611
31732
|
if (!waits || waits.size === 0) {
|
|
31612
31733
|
sendError(id2, {
|
|
31613
|
-
code:
|
|
31734
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31614
31735
|
message: `no active shell.wait to detach for task: ${taskId}`
|
|
31615
31736
|
});
|
|
31616
31737
|
return;
|
|
@@ -31623,7 +31744,7 @@ var createShellHandlers = ({
|
|
|
31623
31744
|
detached: true,
|
|
31624
31745
|
state: task.state
|
|
31625
31746
|
};
|
|
31626
|
-
|
|
31747
|
+
sendRequestResult("shell.detach", id2, result);
|
|
31627
31748
|
} catch (error) {
|
|
31628
31749
|
sendTaskError(id2, error);
|
|
31629
31750
|
}
|
|
@@ -31632,7 +31753,7 @@ var createShellHandlers = ({
|
|
|
31632
31753
|
const taskId = parseTaskId(params?.task_id);
|
|
31633
31754
|
if (!taskId) {
|
|
31634
31755
|
sendError(id2, {
|
|
31635
|
-
code:
|
|
31756
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31636
31757
|
message: "task_id is required"
|
|
31637
31758
|
});
|
|
31638
31759
|
return;
|
|
@@ -31642,7 +31763,7 @@ var createShellHandlers = ({
|
|
|
31642
31763
|
const task = await shellTaskManager.cancel(taskId, {
|
|
31643
31764
|
reason: "cancelled"
|
|
31644
31765
|
});
|
|
31645
|
-
|
|
31766
|
+
sendRequestResult("shell.cancel", id2, toShellTaskInfo(task));
|
|
31646
31767
|
} catch (error) {
|
|
31647
31768
|
sendTaskError(id2, error);
|
|
31648
31769
|
}
|
|
@@ -31661,7 +31782,7 @@ var createShellHandlers = ({
|
|
|
31661
31782
|
|
|
31662
31783
|
// src/rpc/skills.ts
|
|
31663
31784
|
var import_node_path48 = __toESM(require("path"), 1);
|
|
31664
|
-
var
|
|
31785
|
+
var import_protocol41 = require("@codelia/protocol");
|
|
31665
31786
|
var createSkillsHandlers = ({
|
|
31666
31787
|
state,
|
|
31667
31788
|
log: log2
|
|
@@ -31673,7 +31794,7 @@ var createSkillsHandlers = ({
|
|
|
31673
31794
|
if (!forceReload) {
|
|
31674
31795
|
const cachedCatalog = state.skillsCatalogByCwd.get(workingDir);
|
|
31675
31796
|
if (cachedCatalog) {
|
|
31676
|
-
|
|
31797
|
+
sendRequestResult("skills.list", id2, {
|
|
31677
31798
|
skills: cachedCatalog.skills,
|
|
31678
31799
|
errors: cachedCatalog.errors,
|
|
31679
31800
|
truncated: cachedCatalog.truncated
|
|
@@ -31692,7 +31813,7 @@ var createSkillsHandlers = ({
|
|
|
31692
31813
|
});
|
|
31693
31814
|
} catch (error) {
|
|
31694
31815
|
sendError(id2, {
|
|
31695
|
-
code:
|
|
31816
|
+
code: import_protocol41.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31696
31817
|
message: `skills resolver init failed: ${String(error)}`
|
|
31697
31818
|
});
|
|
31698
31819
|
return;
|
|
@@ -31710,11 +31831,11 @@ var createSkillsHandlers = ({
|
|
|
31710
31831
|
errors: catalog.errors,
|
|
31711
31832
|
truncated: catalog.truncated
|
|
31712
31833
|
};
|
|
31713
|
-
|
|
31834
|
+
sendRequestResult("skills.list", id2, result);
|
|
31714
31835
|
} catch (error) {
|
|
31715
31836
|
log2(`skills.list error: ${String(error)}`);
|
|
31716
31837
|
sendError(id2, {
|
|
31717
|
-
code:
|
|
31838
|
+
code: import_protocol41.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31718
31839
|
message: `skills list failed: ${String(error)}`
|
|
31719
31840
|
});
|
|
31720
31841
|
}
|
|
@@ -31724,7 +31845,7 @@ var createSkillsHandlers = ({
|
|
|
31724
31845
|
|
|
31725
31846
|
// src/rpc/task.ts
|
|
31726
31847
|
var import_node_path49 = __toESM(require("path"), 1);
|
|
31727
|
-
var
|
|
31848
|
+
var import_protocol43 = require("@codelia/protocol");
|
|
31728
31849
|
var import_storage34 = require("@codelia/storage");
|
|
31729
31850
|
var DEFAULT_TRUNCATED2 = {
|
|
31730
31851
|
stdout: false,
|
|
@@ -31774,7 +31895,7 @@ var parseTaskId2 = (value) => {
|
|
|
31774
31895
|
var toTaskRpcError2 = (error) => {
|
|
31775
31896
|
if (!(error instanceof TaskManagerError)) {
|
|
31776
31897
|
return {
|
|
31777
|
-
code:
|
|
31898
|
+
code: import_protocol43.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31778
31899
|
message: String(error)
|
|
31779
31900
|
};
|
|
31780
31901
|
}
|
|
@@ -31783,17 +31904,17 @@ var toTaskRpcError2 = (error) => {
|
|
|
31783
31904
|
case "invalid_task_id":
|
|
31784
31905
|
case "unsupported_workspace_mode":
|
|
31785
31906
|
return {
|
|
31786
|
-
code:
|
|
31907
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31787
31908
|
message: error.message
|
|
31788
31909
|
};
|
|
31789
31910
|
case "manager_shutting_down":
|
|
31790
31911
|
return {
|
|
31791
|
-
code:
|
|
31912
|
+
code: import_protocol43.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
31792
31913
|
message: error.message
|
|
31793
31914
|
};
|
|
31794
31915
|
default:
|
|
31795
31916
|
return {
|
|
31796
|
-
code:
|
|
31917
|
+
code: import_protocol43.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31797
31918
|
message: error.message
|
|
31798
31919
|
};
|
|
31799
31920
|
}
|
|
@@ -31845,7 +31966,7 @@ var resolveShellTimeoutSeconds3 = (requestedTimeout, background) => {
|
|
|
31845
31966
|
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
31846
31967
|
return {
|
|
31847
31968
|
error: {
|
|
31848
|
-
code:
|
|
31969
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31849
31970
|
message: "timeout_seconds must be a positive number"
|
|
31850
31971
|
}
|
|
31851
31972
|
};
|
|
@@ -31859,7 +31980,7 @@ var resolveShellTimeoutSeconds3 = (requestedTimeout, background) => {
|
|
|
31859
31980
|
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
31860
31981
|
return {
|
|
31861
31982
|
error: {
|
|
31862
|
-
code:
|
|
31983
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31863
31984
|
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
31864
31985
|
}
|
|
31865
31986
|
};
|
|
@@ -31874,7 +31995,7 @@ var parseShellSpawnRequest = (state, params, options) => {
|
|
|
31874
31995
|
if (!command.trim()) {
|
|
31875
31996
|
return {
|
|
31876
31997
|
error: {
|
|
31877
|
-
code:
|
|
31998
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31878
31999
|
message: "command is required for shell tasks"
|
|
31879
32000
|
}
|
|
31880
32001
|
};
|
|
@@ -31890,7 +32011,7 @@ var parseShellSpawnRequest = (state, params, options) => {
|
|
|
31890
32011
|
if (!cwd) {
|
|
31891
32012
|
return {
|
|
31892
32013
|
error: {
|
|
31893
|
-
code:
|
|
32014
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31894
32015
|
message: "cwd is outside sandbox root"
|
|
31895
32016
|
}
|
|
31896
32017
|
};
|
|
@@ -31922,11 +32043,10 @@ var subscribeTaskProgress = (state, tasks) => {
|
|
|
31922
32043
|
...task.result?.usage ? { usage: task.result.usage } : {},
|
|
31923
32044
|
updated_at: progress?.updated_at ?? task.updated_at
|
|
31924
32045
|
};
|
|
31925
|
-
void sendNotificationAsync(
|
|
31926
|
-
|
|
31927
|
-
|
|
31928
|
-
|
|
31929
|
-
});
|
|
32046
|
+
void sendNotificationAsync(
|
|
32047
|
+
state,
|
|
32048
|
+
notificationMessage("task.progress", params)
|
|
32049
|
+
);
|
|
31930
32050
|
};
|
|
31931
32051
|
tasks.onTaskUpdate((task) => {
|
|
31932
32052
|
if (!visible(task)) return;
|
|
@@ -31971,12 +32091,19 @@ var createTaskHandlers = ({
|
|
|
31971
32091
|
const handleTaskSpawn = async (id2, params) => {
|
|
31972
32092
|
if (!params || !isTaskKind(params.kind)) {
|
|
31973
32093
|
sendError(id2, {
|
|
31974
|
-
code:
|
|
32094
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31975
32095
|
message: "kind must be shell or subagent"
|
|
31976
32096
|
});
|
|
31977
32097
|
return;
|
|
31978
32098
|
}
|
|
31979
|
-
if (params.kind
|
|
32099
|
+
if (params.kind !== "shell") {
|
|
32100
|
+
if (params.kind !== "subagent" || !subagents?.isAvailable() || !getAgent) {
|
|
32101
|
+
sendError(id2, {
|
|
32102
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32103
|
+
message: `task kind ${params.kind} is not supported yet.`
|
|
32104
|
+
});
|
|
32105
|
+
return;
|
|
32106
|
+
}
|
|
31980
32107
|
try {
|
|
31981
32108
|
await state.withAdmissionLock(getAgent);
|
|
31982
32109
|
if (!state.subagentSpawn)
|
|
@@ -31986,7 +32113,8 @@ var createTaskHandlers = ({
|
|
|
31986
32113
|
...createToolContext(),
|
|
31987
32114
|
signal
|
|
31988
32115
|
});
|
|
31989
|
-
|
|
32116
|
+
sendRequestResult(
|
|
32117
|
+
"task.spawn",
|
|
31990
32118
|
id2,
|
|
31991
32119
|
subagentTaskInfo(
|
|
31992
32120
|
params.background === false ? await tasks.wait(task.task_id, { signal }) : task
|
|
@@ -31997,13 +32125,6 @@ var createTaskHandlers = ({
|
|
|
31997
32125
|
}
|
|
31998
32126
|
return;
|
|
31999
32127
|
}
|
|
32000
|
-
if (params.kind !== "shell") {
|
|
32001
|
-
sendError(id2, {
|
|
32002
|
-
code: import_protocol21.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32003
|
-
message: `task kind ${params.kind} is not supported yet.`
|
|
32004
|
-
});
|
|
32005
|
-
return;
|
|
32006
|
-
}
|
|
32007
32128
|
const background = params.background !== false;
|
|
32008
32129
|
const parsed = parseShellSpawnRequest(state, params, { background });
|
|
32009
32130
|
if ("error" in parsed) {
|
|
@@ -32049,7 +32170,7 @@ var createTaskHandlers = ({
|
|
|
32049
32170
|
await tasks.wait(task.task_id, { signal: state.activeRunSignal })
|
|
32050
32171
|
);
|
|
32051
32172
|
assertReceiptScopeCurrent(scope);
|
|
32052
|
-
|
|
32173
|
+
sendRequestResult("task.spawn", id2, result);
|
|
32053
32174
|
} catch (error) {
|
|
32054
32175
|
if (scope.connectionSignal.aborted) return;
|
|
32055
32176
|
sendTaskError2(
|
|
@@ -32062,21 +32183,21 @@ var createTaskHandlers = ({
|
|
|
32062
32183
|
const requestedLimit = params?.limit;
|
|
32063
32184
|
if (requestedLimit !== void 0 && (!Number.isFinite(requestedLimit) || requestedLimit <= 0)) {
|
|
32064
32185
|
sendError(id2, {
|
|
32065
|
-
code:
|
|
32186
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32066
32187
|
message: "limit must be a positive number"
|
|
32067
32188
|
});
|
|
32068
32189
|
return;
|
|
32069
32190
|
}
|
|
32070
32191
|
if (params?.kind !== void 0 && !isTaskKind(params.kind)) {
|
|
32071
32192
|
sendError(id2, {
|
|
32072
|
-
code:
|
|
32193
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32073
32194
|
message: "kind must be shell or subagent"
|
|
32074
32195
|
});
|
|
32075
32196
|
return;
|
|
32076
32197
|
}
|
|
32077
32198
|
if (params?.state !== void 0 && !isTaskState(params.state)) {
|
|
32078
32199
|
sendError(id2, {
|
|
32079
|
-
code:
|
|
32200
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32080
32201
|
message: "invalid task state"
|
|
32081
32202
|
});
|
|
32082
32203
|
return;
|
|
@@ -32085,7 +32206,7 @@ var createTaskHandlers = ({
|
|
|
32085
32206
|
const limit = requestedLimit ? Math.trunc(requestedLimit) : void 0;
|
|
32086
32207
|
const tasksList = (await tasks.list({ sessionId: state.sessionId })).filter((task) => params?.kind ? task.kind === params.kind : true).filter((task) => params?.state ? task.state === params.state : true).slice(0, limit).map((task) => toTaskSummary(task, tasks.getProgress(task.task_id)));
|
|
32087
32208
|
const result = { tasks: tasksList };
|
|
32088
|
-
|
|
32209
|
+
sendRequestResult("task.list", id2, result);
|
|
32089
32210
|
} catch (error) {
|
|
32090
32211
|
sendTaskError2(id2, error);
|
|
32091
32212
|
}
|
|
@@ -32094,7 +32215,7 @@ var createTaskHandlers = ({
|
|
|
32094
32215
|
const taskId = parseTaskId2(params?.task_id);
|
|
32095
32216
|
if (!taskId) {
|
|
32096
32217
|
sendError(id2, {
|
|
32097
|
-
code:
|
|
32218
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32098
32219
|
message: "task_id is required"
|
|
32099
32220
|
});
|
|
32100
32221
|
return;
|
|
@@ -32105,7 +32226,7 @@ var createTaskHandlers = ({
|
|
|
32105
32226
|
task,
|
|
32106
32227
|
tasks.getProgress(task.task_id)
|
|
32107
32228
|
);
|
|
32108
|
-
|
|
32229
|
+
sendRequestResult("task.status", id2, result);
|
|
32109
32230
|
} catch (error) {
|
|
32110
32231
|
sendTaskError2(id2, error);
|
|
32111
32232
|
}
|
|
@@ -32114,7 +32235,7 @@ var createTaskHandlers = ({
|
|
|
32114
32235
|
const taskId = parseTaskId2(params?.task_id);
|
|
32115
32236
|
if (!taskId) {
|
|
32116
32237
|
sendError(id2, {
|
|
32117
|
-
code:
|
|
32238
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32118
32239
|
message: "task_id is required"
|
|
32119
32240
|
});
|
|
32120
32241
|
return;
|
|
@@ -32126,7 +32247,7 @@ var createTaskHandlers = ({
|
|
|
32126
32247
|
task,
|
|
32127
32248
|
tasks.getProgress(task.task_id)
|
|
32128
32249
|
);
|
|
32129
|
-
|
|
32250
|
+
sendRequestResult("task.wait", id2, result);
|
|
32130
32251
|
} catch (error) {
|
|
32131
32252
|
sendTaskError2(id2, error);
|
|
32132
32253
|
}
|
|
@@ -32135,7 +32256,7 @@ var createTaskHandlers = ({
|
|
|
32135
32256
|
const taskId = parseTaskId2(params?.task_id);
|
|
32136
32257
|
if (!taskId) {
|
|
32137
32258
|
sendError(id2, {
|
|
32138
|
-
code:
|
|
32259
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32139
32260
|
message: "task_id is required"
|
|
32140
32261
|
});
|
|
32141
32262
|
return;
|
|
@@ -32149,7 +32270,7 @@ var createTaskHandlers = ({
|
|
|
32149
32270
|
task,
|
|
32150
32271
|
tasks.getProgress(task.task_id)
|
|
32151
32272
|
);
|
|
32152
|
-
|
|
32273
|
+
sendRequestResult("task.cancel", id2, result);
|
|
32153
32274
|
} catch (error) {
|
|
32154
32275
|
sendTaskError2(id2, error);
|
|
32155
32276
|
}
|
|
@@ -32158,7 +32279,7 @@ var createTaskHandlers = ({
|
|
|
32158
32279
|
const taskId = parseTaskId2(params?.task_id);
|
|
32159
32280
|
if (!taskId) {
|
|
32160
32281
|
sendError(id2, {
|
|
32161
|
-
code:
|
|
32282
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32162
32283
|
message: "task_id is required"
|
|
32163
32284
|
});
|
|
32164
32285
|
return;
|
|
@@ -32166,7 +32287,7 @@ var createTaskHandlers = ({
|
|
|
32166
32287
|
try {
|
|
32167
32288
|
const task = await requireScope(taskId);
|
|
32168
32289
|
const result = task.state === "completed" || task.state === "failed" || task.state === "cancelled" ? toTaskInfo(task, tasks.getProgress(task.task_id)) : null;
|
|
32169
|
-
|
|
32290
|
+
sendRequestResult("task.result", id2, result);
|
|
32170
32291
|
} catch (error) {
|
|
32171
32292
|
sendTaskError2(id2, error);
|
|
32172
32293
|
}
|
|
@@ -32199,31 +32320,10 @@ var isRecord9 = (value) => typeof value === "object" && value !== null && !Array
|
|
|
32199
32320
|
var validateRequestParams = (method, params) => {
|
|
32200
32321
|
if (params !== void 0 && !isRecord9(params))
|
|
32201
32322
|
return "params must be an object";
|
|
32202
|
-
if (method === "initialize" && !isRecord9(params))
|
|
32203
|
-
return "params are required";
|
|
32204
32323
|
if (method === "run.cancel") {
|
|
32205
32324
|
if (!isRecord9(params) || typeof params.run_id !== "string" || !params.run_id.trim()) {
|
|
32206
32325
|
return "run_id is required";
|
|
32207
32326
|
}
|
|
32208
|
-
if (params.reason !== void 0 && typeof params.reason !== "string") {
|
|
32209
|
-
return "reason must be a string";
|
|
32210
|
-
}
|
|
32211
|
-
}
|
|
32212
|
-
if (method === "run.steer") {
|
|
32213
|
-
if (!isRecord9(params) || typeof params.run_id !== "string" || !params.run_id.trim()) {
|
|
32214
|
-
return "run_id is required";
|
|
32215
|
-
}
|
|
32216
|
-
if (!isRecord9(params.input)) {
|
|
32217
|
-
return "input is required";
|
|
32218
|
-
}
|
|
32219
|
-
if (params.client_steer_id !== void 0 && typeof params.client_steer_id !== "string") {
|
|
32220
|
-
return "client_steer_id must be a string";
|
|
32221
|
-
}
|
|
32222
|
-
}
|
|
32223
|
-
if (method === "run.start" && isRecord9(params)) {
|
|
32224
|
-
if (params.session_id !== void 0 && typeof params.session_id !== "string") {
|
|
32225
|
-
return "session_id must be a string";
|
|
32226
|
-
}
|
|
32227
32327
|
}
|
|
32228
32328
|
return null;
|
|
32229
32329
|
};
|
|
@@ -32467,7 +32567,10 @@ var createRuntimeHandlers = ({
|
|
|
32467
32567
|
taskManager: injectedTaskManager,
|
|
32468
32568
|
outputCache: toolOutputCacheStore ?? void 0
|
|
32469
32569
|
}) : null;
|
|
32470
|
-
const handleInitialize = async (id2,
|
|
32570
|
+
const handleInitialize = async (id2, raw) => {
|
|
32571
|
+
const parsed = parseRequestParams("initialize", raw);
|
|
32572
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
32573
|
+
const params = parsed.params;
|
|
32471
32574
|
let resolvedTheme;
|
|
32472
32575
|
const environment2 = state.effectiveEnvironment;
|
|
32473
32576
|
if (isTuiLocalEnvironment(environment2)) {
|
|
@@ -32548,7 +32651,7 @@ var createRuntimeHandlers = ({
|
|
|
32548
32651
|
}
|
|
32549
32652
|
} : resolvedTheme ? { tui: { theme: resolvedTheme } } : {}
|
|
32550
32653
|
};
|
|
32551
|
-
|
|
32654
|
+
sendRequestResult("initialize", id2, result);
|
|
32552
32655
|
log2(`initialize from ${params.client?.name ?? "unknown"}`);
|
|
32553
32656
|
state.lastClientInfo = params.client ?? null;
|
|
32554
32657
|
state.setUiCapabilities(params.ui_capabilities);
|
|
@@ -32561,25 +32664,27 @@ var createRuntimeHandlers = ({
|
|
|
32561
32664
|
`ui.context.update cwd=${params.cwd ?? "-"} file=${params.active_file?.path ?? "-"}`
|
|
32562
32665
|
);
|
|
32563
32666
|
};
|
|
32564
|
-
const handleThemeSet = async (id2,
|
|
32667
|
+
const handleThemeSet = async (id2, raw) => {
|
|
32565
32668
|
if (state.activeRunId) {
|
|
32566
32669
|
sendError(id2, {
|
|
32567
|
-
code:
|
|
32670
|
+
code: import_protocol45.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
32568
32671
|
message: "runtime busy"
|
|
32569
32672
|
});
|
|
32570
32673
|
return;
|
|
32571
32674
|
}
|
|
32572
|
-
const
|
|
32675
|
+
const parsed = parseRequestParams("theme.set", raw);
|
|
32676
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
32677
|
+
const name2 = parsed.params.name.trim().toLowerCase();
|
|
32573
32678
|
if (!name2) {
|
|
32574
32679
|
sendError(id2, {
|
|
32575
|
-
code:
|
|
32680
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32576
32681
|
message: "theme name is required"
|
|
32577
32682
|
});
|
|
32578
32683
|
return;
|
|
32579
32684
|
}
|
|
32580
32685
|
if (!SUPPORTED_TUI_THEMES.has(name2)) {
|
|
32581
32686
|
sendError(id2, {
|
|
32582
|
-
code:
|
|
32687
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32583
32688
|
message: `unsupported theme: ${name2}`
|
|
32584
32689
|
});
|
|
32585
32690
|
return;
|
|
@@ -32587,16 +32692,15 @@ var createRuntimeHandlers = ({
|
|
|
32587
32692
|
const workingDir = state.lastUiContext?.cwd ?? state.runtimeWorkingDir ?? process.cwd();
|
|
32588
32693
|
try {
|
|
32589
32694
|
const target2 = await updateEnvironmentTuiTheme(state, workingDir, name2);
|
|
32590
|
-
|
|
32695
|
+
sendRequestResult("theme.set", id2, {
|
|
32591
32696
|
name: name2,
|
|
32592
32697
|
scope: target2.scope,
|
|
32593
32698
|
path: target2.path
|
|
32594
|
-
};
|
|
32595
|
-
sendResult(id2, result);
|
|
32699
|
+
});
|
|
32596
32700
|
log2(`theme.set ${name2} scope=${target2.scope} path=${target2.path}`);
|
|
32597
32701
|
} catch (error) {
|
|
32598
32702
|
sendError(id2, {
|
|
32599
|
-
code:
|
|
32703
|
+
code: import_protocol45.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
32600
32704
|
message: String(error)
|
|
32601
32705
|
});
|
|
32602
32706
|
}
|
|
@@ -32617,7 +32721,7 @@ var createRuntimeHandlers = ({
|
|
|
32617
32721
|
const skillsEnabled = state.effectiveEnvironment.context.skills === "from-config";
|
|
32618
32722
|
const themeSetEnabled = isTuiLocalEnvironment(state.effectiveEnvironment) && state.effectiveEnvironment.config.source !== "disabled";
|
|
32619
32723
|
const rejectDisabled = (message) => sendError(req.id, {
|
|
32620
|
-
code:
|
|
32724
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32621
32725
|
message
|
|
32622
32726
|
});
|
|
32623
32727
|
switch (req.method) {
|
|
@@ -32635,69 +32739,66 @@ var createRuntimeHandlers = ({
|
|
|
32635
32739
|
case "goal.clear":
|
|
32636
32740
|
case "goal.continue":
|
|
32637
32741
|
return handleGoal(req.id, req.method, req.params);
|
|
32638
|
-
case "run.start":
|
|
32639
|
-
|
|
32640
|
-
|
|
32641
|
-
return
|
|
32642
|
-
|
|
32643
|
-
|
|
32644
|
-
|
|
32645
|
-
return
|
|
32646
|
-
|
|
32647
|
-
|
|
32648
|
-
case "
|
|
32649
|
-
|
|
32742
|
+
case "run.start": {
|
|
32743
|
+
const parsed = parseRequestParams("run.start", req.params);
|
|
32744
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32745
|
+
return handleRunStart(req.id, parsed.params);
|
|
32746
|
+
}
|
|
32747
|
+
case "run.steer": {
|
|
32748
|
+
const parsed = parseRequestParams("run.steer", req.params);
|
|
32749
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32750
|
+
return handleRunSteer(req.id, parsed.params);
|
|
32751
|
+
}
|
|
32752
|
+
case "run.cancel": {
|
|
32753
|
+
const parsed = parseRequestParams("run.cancel", req.params);
|
|
32754
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32755
|
+
return handleRunCancel(req.id, parsed.params);
|
|
32756
|
+
}
|
|
32757
|
+
case "session.list": {
|
|
32758
|
+
const parsed = parseRequestParams("session.list", req.params);
|
|
32759
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32760
|
+
const params = parsed.params;
|
|
32761
|
+
return handleSessionList(req.id, params);
|
|
32762
|
+
}
|
|
32763
|
+
case "session.history": {
|
|
32764
|
+
const parsed = parseRequestParams("session.history", req.params);
|
|
32765
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32766
|
+
const params = parsed.params;
|
|
32767
|
+
return handleSessionHistory(req.id, params);
|
|
32768
|
+
}
|
|
32769
|
+
case "session.open": {
|
|
32770
|
+
const parsed = parseRequestParams("session.open", req.params);
|
|
32771
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32772
|
+
const params = parsed.params;
|
|
32773
|
+
return handleSessionOpen(req.id, params);
|
|
32774
|
+
}
|
|
32650
32775
|
case "session.update":
|
|
32651
32776
|
return handleSessionUpdate(req.id, req.params);
|
|
32652
32777
|
case "auth.logout":
|
|
32653
32778
|
return handleAuthLogout(req.id, req.params);
|
|
32654
32779
|
case "auth.status":
|
|
32655
|
-
return authHandlers.handleStatus(
|
|
32656
|
-
req.id,
|
|
32657
|
-
req.params
|
|
32658
|
-
);
|
|
32780
|
+
return authHandlers.handleStatus(req.id, req.params);
|
|
32659
32781
|
case "auth.login":
|
|
32660
32782
|
return authHandlers.handleLogin(req.id, req.params);
|
|
32661
32783
|
case "auth.login.complete":
|
|
32662
|
-
return authHandlers.handleLoginComplete(
|
|
32663
|
-
req.id,
|
|
32664
|
-
req.params
|
|
32665
|
-
);
|
|
32784
|
+
return authHandlers.handleLoginComplete(req.id, req.params);
|
|
32666
32785
|
case "auth.login.cancel":
|
|
32667
|
-
return authHandlers.handleLoginCancel(
|
|
32668
|
-
req.id,
|
|
32669
|
-
req.params
|
|
32670
|
-
);
|
|
32786
|
+
return authHandlers.handleLoginCancel(req.id, req.params);
|
|
32671
32787
|
case "auth.storage.resolve_conflict":
|
|
32672
|
-
return authHandlers.handleResolveConflict(
|
|
32673
|
-
req.id,
|
|
32674
|
-
req.params
|
|
32675
|
-
);
|
|
32788
|
+
return authHandlers.handleResolveConflict(req.id, req.params);
|
|
32676
32789
|
case "config.get":
|
|
32677
|
-
return configHandlers.handleConfigGet(
|
|
32678
|
-
req.id,
|
|
32679
|
-
req.params
|
|
32680
|
-
);
|
|
32790
|
+
return configHandlers.handleConfigGet(req.id, req.params);
|
|
32681
32791
|
case "config.set":
|
|
32682
|
-
return configHandlers.handleConfigSet(
|
|
32683
|
-
req.id,
|
|
32684
|
-
req.params
|
|
32685
|
-
);
|
|
32792
|
+
return configHandlers.handleConfigSet(req.id, req.params);
|
|
32686
32793
|
case "permissions.list":
|
|
32687
|
-
return permissionsHandlers.handlePermissionsList(
|
|
32688
|
-
req.id,
|
|
32689
|
-
req.params
|
|
32690
|
-
);
|
|
32794
|
+
return permissionsHandlers.handlePermissionsList(req.id, req.params);
|
|
32691
32795
|
case "permissions.projectTrust.set":
|
|
32692
32796
|
return permissionsHandlers.handleProjectAllowTrustSet(
|
|
32693
32797
|
req.id,
|
|
32694
32798
|
req.params
|
|
32695
32799
|
);
|
|
32696
32800
|
case "permissions.remove":
|
|
32697
|
-
return permissionsHandlers.handlePermissionsRemove(
|
|
32698
|
-
req.id,
|
|
32699
|
-
req.params
|
|
32700
|
-
);
|
|
32801
|
+
return permissionsHandlers.handlePermissionsRemove(req.id, req.params);
|
|
32701
32802
|
case "sandbox.get":
|
|
32702
32803
|
case "sandbox.set":
|
|
32703
32804
|
return handleSandbox(state, req.id, req.method, req.params);
|
|
@@ -32712,139 +32813,158 @@ var createRuntimeHandlers = ({
|
|
|
32712
32813
|
case "image.artifact.get":
|
|
32713
32814
|
return imageHandlers.handle(req.id, "artifact", req.params);
|
|
32714
32815
|
case "model.set":
|
|
32715
|
-
return afterSessionOpen(
|
|
32716
|
-
|
|
32717
|
-
);
|
|
32718
|
-
|
|
32719
|
-
return handleToolCall(req.id,
|
|
32720
|
-
|
|
32816
|
+
return afterSessionOpen(() => handleModelSet(req.id, req.params));
|
|
32817
|
+
case "tool.call": {
|
|
32818
|
+
const parsed = parseRequestParams("tool.call", req.params);
|
|
32819
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32820
|
+
return handleToolCall(req.id, parsed.params);
|
|
32821
|
+
}
|
|
32822
|
+
case "shell.exec": {
|
|
32721
32823
|
if (!shellHandlers)
|
|
32722
32824
|
return rejectDisabled("process execution is disabled");
|
|
32723
|
-
|
|
32724
|
-
|
|
32725
|
-
|
|
32726
|
-
|
|
32727
|
-
case "shell.start":
|
|
32825
|
+
const parsed = parseRequestParams("shell.exec", req.params);
|
|
32826
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32827
|
+
return shellHandlers.handleShellExec(req.id, parsed.params);
|
|
32828
|
+
}
|
|
32829
|
+
case "shell.start": {
|
|
32728
32830
|
if (!shellHandlers)
|
|
32729
32831
|
return rejectDisabled("process execution is disabled");
|
|
32730
|
-
|
|
32731
|
-
|
|
32732
|
-
|
|
32733
|
-
|
|
32734
|
-
case "shell.list":
|
|
32832
|
+
const parsed = parseRequestParams("shell.start", req.params);
|
|
32833
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32834
|
+
return shellHandlers.handleShellStart(req.id, parsed.params);
|
|
32835
|
+
}
|
|
32836
|
+
case "shell.list": {
|
|
32735
32837
|
if (!shellHandlers)
|
|
32736
32838
|
return rejectDisabled("process execution is disabled");
|
|
32737
|
-
|
|
32738
|
-
|
|
32739
|
-
|
|
32740
|
-
|
|
32741
|
-
case "shell.status":
|
|
32839
|
+
const parsed = parseRequestParams("shell.list", req.params);
|
|
32840
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32841
|
+
return shellHandlers.handleShellList(req.id, parsed.params);
|
|
32842
|
+
}
|
|
32843
|
+
case "shell.status": {
|
|
32742
32844
|
if (!shellHandlers)
|
|
32743
32845
|
return rejectDisabled("process execution is disabled");
|
|
32744
|
-
|
|
32745
|
-
|
|
32746
|
-
|
|
32747
|
-
|
|
32748
|
-
case "shell.output":
|
|
32846
|
+
const parsed = parseRequestParams("shell.status", req.params);
|
|
32847
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32848
|
+
return shellHandlers.handleShellStatus(req.id, parsed.params);
|
|
32849
|
+
}
|
|
32850
|
+
case "shell.output": {
|
|
32749
32851
|
if (!shellHandlers)
|
|
32750
32852
|
return rejectDisabled("process execution is disabled");
|
|
32751
|
-
|
|
32752
|
-
|
|
32753
|
-
|
|
32754
|
-
|
|
32755
|
-
case "shell.wait":
|
|
32853
|
+
const parsed = parseRequestParams("shell.output", req.params);
|
|
32854
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32855
|
+
return shellHandlers.handleShellOutput(req.id, parsed.params);
|
|
32856
|
+
}
|
|
32857
|
+
case "shell.wait": {
|
|
32756
32858
|
if (!shellHandlers)
|
|
32757
32859
|
return rejectDisabled("process execution is disabled");
|
|
32758
|
-
|
|
32759
|
-
|
|
32760
|
-
|
|
32761
|
-
|
|
32762
|
-
case "shell.detach":
|
|
32860
|
+
const parsed = parseRequestParams("shell.wait", req.params);
|
|
32861
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32862
|
+
return shellHandlers.handleShellWait(req.id, parsed.params);
|
|
32863
|
+
}
|
|
32864
|
+
case "shell.detach": {
|
|
32763
32865
|
if (!shellHandlers)
|
|
32764
32866
|
return rejectDisabled("process execution is disabled");
|
|
32765
|
-
|
|
32766
|
-
|
|
32767
|
-
|
|
32768
|
-
|
|
32769
|
-
case "shell.cancel":
|
|
32867
|
+
const parsed = parseRequestParams("shell.detach", req.params);
|
|
32868
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32869
|
+
return shellHandlers.handleShellDetach(req.id, parsed.params);
|
|
32870
|
+
}
|
|
32871
|
+
case "shell.cancel": {
|
|
32770
32872
|
if (!shellHandlers)
|
|
32771
32873
|
return rejectDisabled("process execution is disabled");
|
|
32772
|
-
|
|
32773
|
-
|
|
32774
|
-
|
|
32775
|
-
|
|
32776
|
-
case "task.spawn":
|
|
32874
|
+
const parsed = parseRequestParams("shell.cancel", req.params);
|
|
32875
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32876
|
+
return shellHandlers.handleShellCancel(req.id, parsed.params);
|
|
32877
|
+
}
|
|
32878
|
+
case "task.spawn": {
|
|
32777
32879
|
if (!taskHandlers)
|
|
32778
32880
|
return rejectDisabled("process execution is disabled");
|
|
32779
|
-
|
|
32780
|
-
|
|
32781
|
-
|
|
32782
|
-
|
|
32783
|
-
case "task.list":
|
|
32881
|
+
const parsed = parseRequestParams("task.spawn", req.params);
|
|
32882
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32883
|
+
return taskHandlers.handleTaskSpawn(req.id, parsed.params);
|
|
32884
|
+
}
|
|
32885
|
+
case "task.list": {
|
|
32784
32886
|
if (!taskHandlers)
|
|
32785
32887
|
return rejectDisabled("process execution is disabled");
|
|
32786
|
-
|
|
32787
|
-
|
|
32788
|
-
|
|
32789
|
-
|
|
32790
|
-
case "task.status":
|
|
32888
|
+
const parsed = parseRequestParams("task.list", req.params);
|
|
32889
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32890
|
+
return taskHandlers.handleTaskList(req.id, parsed.params);
|
|
32891
|
+
}
|
|
32892
|
+
case "task.status": {
|
|
32791
32893
|
if (!taskHandlers)
|
|
32792
32894
|
return rejectDisabled("process execution is disabled");
|
|
32793
|
-
|
|
32794
|
-
|
|
32795
|
-
|
|
32796
|
-
|
|
32797
|
-
case "task.wait":
|
|
32895
|
+
const parsed = parseRequestParams("task.status", req.params);
|
|
32896
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32897
|
+
return taskHandlers.handleTaskStatus(req.id, parsed.params);
|
|
32898
|
+
}
|
|
32899
|
+
case "task.wait": {
|
|
32798
32900
|
if (!taskHandlers)
|
|
32799
32901
|
return rejectDisabled("process execution is disabled");
|
|
32800
|
-
|
|
32801
|
-
|
|
32802
|
-
|
|
32803
|
-
|
|
32804
|
-
case "task.cancel":
|
|
32902
|
+
const parsed = parseRequestParams("task.wait", req.params);
|
|
32903
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32904
|
+
return taskHandlers.handleTaskWait(req.id, parsed.params);
|
|
32905
|
+
}
|
|
32906
|
+
case "task.cancel": {
|
|
32805
32907
|
if (!taskHandlers)
|
|
32806
32908
|
return rejectDisabled("process execution is disabled");
|
|
32807
|
-
|
|
32808
|
-
|
|
32809
|
-
|
|
32810
|
-
|
|
32811
|
-
case "task.result":
|
|
32909
|
+
const parsed = parseRequestParams("task.cancel", req.params);
|
|
32910
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32911
|
+
return taskHandlers.handleTaskCancel(req.id, parsed.params);
|
|
32912
|
+
}
|
|
32913
|
+
case "task.result": {
|
|
32812
32914
|
if (!taskHandlers)
|
|
32813
32915
|
return rejectDisabled("process execution is disabled");
|
|
32814
|
-
|
|
32815
|
-
|
|
32816
|
-
|
|
32817
|
-
|
|
32818
|
-
case "mcp.list":
|
|
32916
|
+
const parsed = parseRequestParams("task.result", req.params);
|
|
32917
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32918
|
+
return taskHandlers.handleTaskResult(req.id, parsed.params);
|
|
32919
|
+
}
|
|
32920
|
+
case "mcp.list": {
|
|
32819
32921
|
if (!mcpEnabled) {
|
|
32820
|
-
return
|
|
32922
|
+
return sendRequestResult("mcp.list", req.id, { servers: [] });
|
|
32821
32923
|
}
|
|
32924
|
+
const parsed = parseRequestParams("mcp.list", req.params);
|
|
32925
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32822
32926
|
await mcpManager.start?.();
|
|
32823
|
-
return
|
|
32927
|
+
return sendRequestResult(
|
|
32928
|
+
"mcp.list",
|
|
32824
32929
|
req.id,
|
|
32825
|
-
mcpManager.list(
|
|
32930
|
+
mcpManager.list(parsed.params.scope)
|
|
32826
32931
|
);
|
|
32827
|
-
|
|
32932
|
+
}
|
|
32933
|
+
case "skills.list": {
|
|
32828
32934
|
if (!skillsEnabled) return rejectDisabled("skills are disabled");
|
|
32829
|
-
|
|
32830
|
-
|
|
32831
|
-
return
|
|
32832
|
-
|
|
32935
|
+
const parsed = parseRequestParams("skills.list", req.params);
|
|
32936
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32937
|
+
return handleSkillsList(req.id, parsed.params);
|
|
32938
|
+
}
|
|
32939
|
+
case "context.inspect": {
|
|
32940
|
+
const parsed = parseRequestParams("context.inspect", req.params);
|
|
32941
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32942
|
+
return handleContextInspect(req.id, parsed.params);
|
|
32943
|
+
}
|
|
32944
|
+
case "context.usage": {
|
|
32945
|
+
const parsed = parseRequestParams("context.usage", req.params);
|
|
32946
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32833
32947
|
return contextUsageHandlers.handleContextUsage(req.id);
|
|
32948
|
+
}
|
|
32834
32949
|
case "theme.set":
|
|
32835
32950
|
if (!themeSetEnabled)
|
|
32836
32951
|
return rejectDisabled("theme setting is disabled");
|
|
32837
32952
|
return handleThemeSet(req.id, req.params);
|
|
32838
32953
|
default:
|
|
32839
32954
|
return sendError(req.id, {
|
|
32840
|
-
code:
|
|
32955
|
+
code: import_protocol45.RPC_ERROR_CODE.METHOD_NOT_FOUND,
|
|
32841
32956
|
message: "method not found"
|
|
32842
32957
|
});
|
|
32843
32958
|
}
|
|
32844
32959
|
};
|
|
32845
32960
|
const handleNotification = (note) => {
|
|
32846
32961
|
if (note.method === "ui.context.update") {
|
|
32847
|
-
|
|
32962
|
+
const params = parseUiNotificationParams(
|
|
32963
|
+
"ui.context.update",
|
|
32964
|
+
note.params
|
|
32965
|
+
);
|
|
32966
|
+
if (params) handleUiContextUpdate(params);
|
|
32967
|
+
else log2("ui.context.update ignored: params do not match the protocol");
|
|
32848
32968
|
}
|
|
32849
32969
|
};
|
|
32850
32970
|
const handleResponse = (res) => {
|
|
@@ -32860,7 +32980,7 @@ var createRuntimeHandlers = ({
|
|
|
32860
32980
|
if (msg.jsonrpc !== "2.0" || "method" in msg && typeof msg.method !== "string") {
|
|
32861
32981
|
if (id2 !== void 0) {
|
|
32862
32982
|
sendError(id2, {
|
|
32863
|
-
code:
|
|
32983
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_REQUEST,
|
|
32864
32984
|
message: "invalid request"
|
|
32865
32985
|
});
|
|
32866
32986
|
} else {
|
|
@@ -32877,7 +32997,7 @@ var createRuntimeHandlers = ({
|
|
|
32877
32997
|
if (invalid) {
|
|
32878
32998
|
if (id2 !== void 0)
|
|
32879
32999
|
sendError(id2, {
|
|
32880
|
-
code:
|
|
33000
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32881
33001
|
message: invalid
|
|
32882
33002
|
});
|
|
32883
33003
|
else log2(`invalid rpc notification: ${msg.method}`);
|
|
@@ -32891,7 +33011,7 @@ var createRuntimeHandlers = ({
|
|
|
32891
33011
|
if (!hasRpcResponse(id2)) {
|
|
32892
33012
|
try {
|
|
32893
33013
|
sendError(id2, {
|
|
32894
|
-
code:
|
|
33014
|
+
code: import_protocol45.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
32895
33015
|
message: "internal runtime error"
|
|
32896
33016
|
});
|
|
32897
33017
|
} catch {
|
|
@@ -32916,7 +33036,7 @@ var createRuntimeHandlers = ({
|
|
|
32916
33036
|
handleResponse(msg);
|
|
32917
33037
|
} else if (id2 !== void 0) {
|
|
32918
33038
|
sendError(id2, {
|
|
32919
|
-
code:
|
|
33039
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_REQUEST,
|
|
32920
33040
|
message: "invalid request"
|
|
32921
33041
|
});
|
|
32922
33042
|
} else {
|
|
@@ -32934,44 +33054,44 @@ var import_node_url4 = require("url");
|
|
|
32934
33054
|
|
|
32935
33055
|
// src/subagents/bootstrap.ts
|
|
32936
33056
|
var import_node_path50 = __toESM(require("path"), 1);
|
|
32937
|
-
var
|
|
32938
|
-
var
|
|
32939
|
-
var permissionRule =
|
|
32940
|
-
tool:
|
|
32941
|
-
command:
|
|
32942
|
-
command_glob:
|
|
32943
|
-
skill_name:
|
|
33057
|
+
var import_shared_types11 = require("@codelia/shared-types");
|
|
33058
|
+
var import_zod47 = require("zod");
|
|
33059
|
+
var permissionRule = import_zod47.z.object({
|
|
33060
|
+
tool: import_zod47.z.string(),
|
|
33061
|
+
command: import_zod47.z.string().optional(),
|
|
33062
|
+
command_glob: import_zod47.z.string().optional(),
|
|
33063
|
+
skill_name: import_zod47.z.string().optional()
|
|
32944
33064
|
}).passthrough();
|
|
32945
|
-
var subagentBootstrapSchema =
|
|
32946
|
-
version:
|
|
32947
|
-
task_id:
|
|
32948
|
-
prompt:
|
|
32949
|
-
workspace_root:
|
|
32950
|
-
protected_paths:
|
|
32951
|
-
lineage:
|
|
33065
|
+
var subagentBootstrapSchema = import_zod47.z.object({
|
|
33066
|
+
version: import_zod47.z.literal(1),
|
|
33067
|
+
task_id: import_zod47.z.string().uuid(),
|
|
33068
|
+
prompt: import_zod47.z.string().min(1).max(32768),
|
|
33069
|
+
workspace_root: import_zod47.z.string().refine(import_node_path50.default.isAbsolute),
|
|
33070
|
+
protected_paths: import_zod47.z.array(import_zod47.z.string().refine(import_node_path50.default.isAbsolute)).optional(),
|
|
33071
|
+
lineage: import_zod47.z.object({
|
|
32952
33072
|
name: subagentNameSchema.optional(),
|
|
32953
|
-
tree_id:
|
|
32954
|
-
node_id:
|
|
32955
|
-
parent_node_id:
|
|
32956
|
-
owner_session_id:
|
|
32957
|
-
depth:
|
|
32958
|
-
spawn_index:
|
|
32959
|
-
context_mode:
|
|
32960
|
-
effective_policy_id:
|
|
32961
|
-
workspace_lease_id:
|
|
33073
|
+
tree_id: import_zod47.z.string().min(1),
|
|
33074
|
+
node_id: import_zod47.z.string().uuid(),
|
|
33075
|
+
parent_node_id: import_zod47.z.string().min(1),
|
|
33076
|
+
owner_session_id: import_zod47.z.string().min(1),
|
|
33077
|
+
depth: import_zod47.z.literal(1),
|
|
33078
|
+
spawn_index: import_zod47.z.number().int().positive(),
|
|
33079
|
+
context_mode: import_zod47.z.literal("fresh"),
|
|
33080
|
+
effective_policy_id: import_zod47.z.string().min(1),
|
|
33081
|
+
workspace_lease_id: import_zod47.z.string().min(1)
|
|
32962
33082
|
}).strict(),
|
|
32963
33083
|
model: subagentModelSchema,
|
|
32964
|
-
permission:
|
|
32965
|
-
tool_allowlist:
|
|
32966
|
-
workspace_access:
|
|
32967
|
-
approval_mode:
|
|
32968
|
-
sandbox_mode:
|
|
32969
|
-
parent_permissions:
|
|
32970
|
-
allow:
|
|
32971
|
-
deny:
|
|
33084
|
+
permission: import_zod47.z.object({
|
|
33085
|
+
tool_allowlist: import_zod47.z.array(import_zod47.z.enum(WRITABLE_TOOLS)).max(WRITABLE_TOOLS.length),
|
|
33086
|
+
workspace_access: import_zod47.z.enum(["read-only", "read-write"]),
|
|
33087
|
+
approval_mode: import_zod47.z.enum(["minimal", "trusted", "full-access"]).optional(),
|
|
33088
|
+
sandbox_mode: import_zod47.z.enum(import_shared_types11.sandboxModes).optional(),
|
|
33089
|
+
parent_permissions: import_zod47.z.object({
|
|
33090
|
+
allow: import_zod47.z.array(permissionRule).optional(),
|
|
33091
|
+
deny: import_zod47.z.array(permissionRule).optional()
|
|
32972
33092
|
}).strict().optional(),
|
|
32973
|
-
max_steps:
|
|
32974
|
-
timeout_seconds:
|
|
33093
|
+
max_steps: import_zod47.z.number().int().min(1).max(200),
|
|
33094
|
+
timeout_seconds: import_zod47.z.number().int().min(1).max(3600).optional()
|
|
32975
33095
|
}).strict()
|
|
32976
33096
|
}).strict().refine(
|
|
32977
33097
|
(input) => input.lineage.node_id === input.task_id && input.lineage.workspace_lease_id === input.task_id && (input.permission.workspace_access === "read-write" || input.permission.tool_allowlist.every(
|