@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/sdk.js CHANGED
@@ -6,10 +6,10 @@ import {
6
6
  mcpEntryMatchesServer,
7
7
  resolveMcpServerBinding,
8
8
  startRuntime
9
- } from "./chunk-LNUGYGST.js";
9
+ } from "./chunk-QWJ4JW4T.js";
10
10
  import {
11
11
  createMacMxcShellBackend
12
- } from "./chunk-NPCH2IMV.js";
12
+ } from "./chunk-DSYHEFZM.js";
13
13
 
14
14
  // src/permissions/brokered-mutation.ts
15
15
  var runBrokeredMutation = async (request, adapter, signal) => {
@@ -47,6 +47,7 @@ var resolveConfigPath = () => {
47
47
  return storage.resolvePaths().configFile;
48
48
  };
49
49
  var resolveProjectConfigPath = (workingDir) => import_node_path.default.resolve(workingDir, ".codelia", "config.json");
50
+ var normalizeModelLevel = (value) => value.trim().toLowerCase();
50
51
  var resolveReasoningEffort = (value) => {
51
52
  return resolveModelLevelOption(value, "model.reasoning", {
52
53
  allowXhigh: true
@@ -59,7 +60,7 @@ var resolveTextVerbosity = (value) => {
59
60
  };
60
61
  function resolveModelLevelOption(value, fieldName, options) {
61
62
  if (!value) return void 0;
62
- const normalized = value.trim().toLowerCase();
63
+ const normalized = normalizeModelLevel(value);
63
64
  if (normalized === "low" || normalized === "medium" || normalized === "high") {
64
65
  return normalized;
65
66
  }
@@ -71,15 +72,16 @@ function resolveModelLevelOption(value, fieldName, options) {
71
72
  }
72
73
 
73
74
  // src/rpc/ui-requests.ts
74
- var import_protocol = require("@codelia/protocol");
75
-
76
- // src/rpc/transport.ts
77
- var import_node_async_hooks = require("async_hooks");
75
+ var import_protocol3 = require("@codelia/protocol");
78
76
 
79
77
  // src/logger.ts
80
78
  var import_logger = require("@codelia/logger");
81
79
 
80
+ // src/rpc/protocol.ts
81
+ var import_protocol2 = require("@codelia/protocol");
82
+
82
83
  // src/rpc/transport.ts
84
+ var import_node_async_hooks = require("async_hooks");
83
85
  var responseContext = new import_node_async_hooks.AsyncLocalStorage();
84
86
  var describeRpcMessage = (msg) => {
85
87
  if ("method" in msg && typeof msg.method === "string") {
@@ -110,16 +112,47 @@ var send = (msg) => {
110
112
  }
111
113
  };
112
114
 
115
+ // src/rpc/protocol.ts
116
+ var MAX_ISSUES = 10;
117
+ var describeIssues = (error) => error.issues.slice(0, MAX_ISSUES).map((issue) => ({
118
+ path: issue.path.map(String).join("."),
119
+ code: issue.code,
120
+ message: issue.message
121
+ }));
122
+ var schemaFor = (method, slot) => {
123
+ const spec = import_protocol2.protocolMethods[method];
124
+ if (slot === "params") return spec.params;
125
+ if (!("result" in spec))
126
+ throw new Error(`${method} is a notification without a result`);
127
+ return spec.result;
128
+ };
129
+ var assertOutgoing = (method, slot, value) => {
130
+ if (process.env.CODELIA_PROTOCOL_ASSERT !== "1") return;
131
+ const result = schemaFor(method, slot).safeParse(value);
132
+ if (!result.success)
133
+ throw new Error(
134
+ `protocol assertion failed for ${method} ${slot}: ${JSON.stringify(describeIssues(result.error))}`
135
+ );
136
+ };
137
+ var notificationMessage = (method, params) => {
138
+ assertOutgoing(method, "params", params);
139
+ return { jsonrpc: "2.0", method, params };
140
+ };
141
+ var requestMessage = (method, id, params) => {
142
+ assertOutgoing(method, "params", params);
143
+ return { jsonrpc: "2.0", id, method, params };
144
+ };
145
+ var parseUiResult = (method, raw) => {
146
+ const result = schemaFor(method, "result").safeParse(raw);
147
+ if (result.success) return { ok: true, result: result.data };
148
+ return { ok: false, issues: describeIssues(result.error) };
149
+ };
150
+
113
151
  // src/rpc/ui-requests.ts
114
152
  var requestUi = async (state, method, params, signal) => {
115
153
  if (signal?.aborted) return null;
116
154
  const id = state.nextUiRequestId();
117
- const request = {
118
- jsonrpc: "2.0",
119
- id,
120
- method,
121
- params
122
- };
155
+ const request = requestMessage(method, id, params);
123
156
  const response = state.waitForUiResponse(id);
124
157
  let sent = false;
125
158
  const abort = () => {
@@ -127,13 +160,12 @@ var requestUi = async (state, method, params, signal) => {
127
160
  jsonrpc: "2.0",
128
161
  id,
129
162
  error: {
130
- code: import_protocol.RPC_ERROR_CODE.RUNTIME_INTERNAL,
163
+ code: import_protocol3.RPC_ERROR_CODE.RUNTIME_INTERNAL,
131
164
  message: "UI request cancelled"
132
165
  }
133
166
  });
134
- if (cancelled && sent && method === "ui.pick.request") {
135
- send({ jsonrpc: "2.0", method: "ui.pick.cancelled", params: { id } });
136
- }
167
+ if (!cancelled || !sent || method !== "ui.pick.request") return;
168
+ send(notificationMessage("ui.pick.cancelled", { id }));
137
169
  };
138
170
  signal?.addEventListener("abort", abort, { once: true });
139
171
  try {
@@ -142,7 +174,12 @@ var requestUi = async (state, method, params, signal) => {
142
174
  send(request);
143
175
  sent = true;
144
176
  }
145
- return await response;
177
+ const parsed = parseUiResult(method, await response);
178
+ if (parsed.ok) return parsed.result;
179
+ (0, import_logger.log)(
180
+ `protocol mismatch: ${method} result: ${JSON.stringify(parsed.issues)}`
181
+ );
182
+ return null;
146
183
  } catch {
147
184
  return null;
148
185
  } finally {
@@ -2699,6 +2736,7 @@ var RuntimeState = class {
2699
2736
  authority
2700
2737
  ]);
2701
2738
  }
2739
+ acceptedSteerIds = /* @__PURE__ */ new Map();
2702
2740
  pendingSteersByRun = /* @__PURE__ */ new Map();
2703
2741
  steerClosedRuns = /* @__PURE__ */ new Set();
2704
2742
  uiRequestCounter = 0;
@@ -2833,6 +2871,7 @@ var RuntimeState = class {
2833
2871
  this.lastContextLeftPercent = null;
2834
2872
  this.runSeq.delete(runId);
2835
2873
  this.pendingSteersByRun.delete(runId);
2874
+ this.acceptedSteerIds.delete(runId);
2836
2875
  this.steerClosedRuns.delete(runId);
2837
2876
  if (this.activeRunId === null) {
2838
2877
  this.sessionAppend = null;
@@ -2845,10 +2884,18 @@ var RuntimeState = class {
2845
2884
  canSteerRun(runId) {
2846
2885
  return this.activeRunId === runId && !this.cancelRequested && !this.steerClosedRuns.has(runId);
2847
2886
  }
2887
+ acceptedRunSteerId(runId, clientSteerId) {
2888
+ return this.acceptedSteerIds.get(runId)?.get(clientSteerId);
2889
+ }
2848
2890
  enqueueRunSteer(runId, content, clientSteerId, approvalUserText) {
2849
2891
  this.signalApprovalChange();
2850
2892
  this.runSteerCounter += 1;
2851
2893
  const steerId = `s${this.runSteerCounter}`;
2894
+ if (clientSteerId !== void 0) {
2895
+ const accepted = this.acceptedSteerIds.get(runId) ?? /* @__PURE__ */ new Map();
2896
+ accepted.set(clientSteerId, steerId);
2897
+ this.acceptedSteerIds.set(runId, accepted);
2898
+ }
2852
2899
  if (this.approvalIntent?.runId === runId) {
2853
2900
  this.approvalIntent.steers.push({
2854
2901
  id: steerId,
@@ -2859,7 +2906,7 @@ var RuntimeState = class {
2859
2906
  const queue = this.pendingSteersByRun.get(runId) ?? [];
2860
2907
  queue.push({
2861
2908
  steer_id: steerId,
2862
- ...clientSteerId ? { client_steer_id: clientSteerId } : {},
2909
+ ...clientSteerId !== void 0 ? { client_steer_id: clientSteerId } : {},
2863
2910
  content
2864
2911
  });
2865
2912
  this.pendingSteersByRun.set(runId, queue);
@@ -16,7 +16,7 @@ import {
16
16
  redactSubagentJson,
17
17
  redactSubagentText,
18
18
  subagentBootstrapSchema
19
- } from "../chunk-NPCH2IMV.js";
19
+ } from "../chunk-DSYHEFZM.js";
20
20
 
21
21
  // src/subagents/child-entry.ts
22
22
  import { createReadStream } from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelia/runtime",
3
- "version": "0.1.89",
3
+ "version": "0.1.90",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -29,14 +29,14 @@
29
29
  "typecheck": "tsc --noEmit"
30
30
  },
31
31
  "dependencies": {
32
- "@codelia/config": "0.1.89",
33
- "@codelia/config-loader": "0.1.89",
34
- "@codelia/core": "0.1.89",
35
- "@codelia/logger": "0.1.89",
36
- "@codelia/model-metadata": "0.1.89",
37
- "@codelia/protocol": "0.1.89",
38
- "@codelia/shared-types": "0.1.89",
39
- "@codelia/storage": "0.1.89",
32
+ "@codelia/config": "0.1.90",
33
+ "@codelia/config-loader": "0.1.90",
34
+ "@codelia/core": "0.1.90",
35
+ "@codelia/logger": "0.1.90",
36
+ "@codelia/model-metadata": "0.1.90",
37
+ "@codelia/protocol": "0.1.90",
38
+ "@codelia/shared-types": "0.1.90",
39
+ "@codelia/storage": "0.1.90",
40
40
  "@google/genai": "2.32.0",
41
41
  "eventsource-parser": "^3.0.6",
42
42
  "image-size": "^2.0.2",
@@ -44,7 +44,7 @@
44
44
  "zod": "^4.3.5"
45
45
  },
46
46
  "optionalDependencies": {
47
- "@codelia/tui-darwin-arm64": "0.1.89"
47
+ "@codelia/tui-darwin-arm64": "0.1.90"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"