@jini-ai/sidecar 0.6.19 → 0.6.21

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @jini-ai/sidecar
2
2
 
3
+ ## 0.6.21
4
+
5
+ - Native IPC carries a handler's explicit public `refusalReason` (1–1024 characters) back to the caller instead of a generic "IPC request refused"; raw handler errors still never cross the channel.
6
+
3
7
  ## 0.6.17
4
8
 
5
9
  ### Patch Changes
@@ -80,7 +80,15 @@ export interface NodeIpcPeer {
80
80
  on(event: "message" | "disconnect", listener: (message: unknown) => void): unknown;
81
81
  removeListener(event: "message" | "disconnect", listener: (message: unknown) => void): unknown;
82
82
  }
83
- /** Native request/reply with bounded pending work. Errors never echo a request, payload or handler error.
83
+ /** Only explicitly public, bounded refusal text may cross IPC. Raw handler messages stay private.
84
+ * @complexity O(1); the caller owns choosing a reason that contains no private data.
85
+ */
86
+ export declare function ipcRefusalReason({ value }: {
87
+ value: unknown;
88
+ }, _optional?: {}): string | undefined;
89
+ /** Native request/reply with bounded pending work. Errors never echo a request, payload or raw handler error.
90
+ * Handlers may opt into public diagnostics by throwing an error with a `refusalReason` string
91
+ * (1–1024 characters), e.g. `Object.assign(new Error(), { refusalReason: "This session ended." })`.
84
92
  * @param required The actual spawned child or inherited process channel.
85
93
  * @param optional Handler, deadline and pending-request cap; construction starts no requests.
86
94
  * @returns Request and idempotent disposal; disconnect rejects and clears every pending request.
@@ -152,7 +152,20 @@ function isIpcEnvelope(message) {
152
152
  return false;
153
153
  return "jiniIpc" in message && message.jiniIpc === 1 && "id" in message && typeof message.id === "string" && "kind" in message;
154
154
  }
155
- /** Native request/reply with bounded pending work. Errors never echo a request, payload or handler error.
155
+ /** Only explicitly public, bounded refusal text may cross IPC. Raw handler messages stay private.
156
+ * @complexity O(1); the caller owns choosing a reason that contains no private data.
157
+ */
158
+ export function ipcRefusalReason({ value }, _optional = {}) {
159
+ if (typeof value !== "object" || value === null || !("refusalReason" in value))
160
+ return undefined;
161
+ const reason = value.refusalReason;
162
+ if (typeof reason !== "string")
163
+ return undefined;
164
+ return reason.length > 0 && reason.length <= 1024 ? reason : undefined;
165
+ }
166
+ /** Native request/reply with bounded pending work. Errors never echo a request, payload or raw handler error.
167
+ * Handlers may opt into public diagnostics by throwing an error with a `refusalReason` string
168
+ * (1–1024 characters), e.g. `Object.assign(new Error(), { refusalReason: "This session ended." })`.
156
169
  * @param required The actual spawned child or inherited process channel.
157
170
  * @param optional Handler, deadline and pending-request cap; construction starts no requests.
158
171
  * @returns Request and idempotent disposal; disconnect rejects and clears every pending request.
@@ -180,12 +193,18 @@ export function createNodeIpcChannel({ peer }, { handle, timeoutMs = 30_000, max
180
193
  dispose({});
181
194
  } // A departing peer cannot receive a refusal.
182
195
  }
196
+ /** Complete only a matching request, preserving explicit public refusals. O(1) lookup. */
197
+ function receiveReply({ message }, _optional = {}) {
198
+ const refusalReason = ipcRefusalReason({ value: message });
199
+ const error = message.ok === true ? null : Object.assign(new Error(refusalReason ?? "IPC request refused"), refusalReason === undefined ? {} : { refusalReason });
200
+ pending.get(message.id)?.finish(error, message.payload);
201
+ }
183
202
  function receive(message) {
184
203
  if (disposed || !isIpcEnvelope(message) || message.channel !== channel)
185
204
  return;
186
205
  const { id } = message;
187
206
  if (message.kind === "reply") {
188
- pending.get(id)?.finish(message.ok === true ? null : new Error("IPC request refused"), message.payload);
207
+ receiveReply({ message });
189
208
  }
190
209
  else if (message.kind === "request" && handle) {
191
210
  if (handling >= maxPending) {
@@ -193,7 +212,10 @@ export function createNodeIpcChannel({ peer }, { handle, timeoutMs = 30_000, max
193
212
  return;
194
213
  }
195
214
  handling++;
196
- void Promise.resolve().then(() => handle(message.payload)).then(payload => reply({ jiniIpc: 1, kind: "reply", id, ok: true, payload }), () => reply({ jiniIpc: 1, kind: "reply", id, ok: false })).catch(() => { }).finally(() => { handling--; }); // A disconnected peer cannot receive its reply.
215
+ void Promise.resolve().then(() => handle(message.payload)).then(payload => reply({ jiniIpc: 1, kind: "reply", id, ok: true, payload }), error => {
216
+ const refusalReason = ipcRefusalReason({ value: error });
217
+ reply({ jiniIpc: 1, kind: "reply", id, ok: false, ...(refusalReason ? { refusalReason } : {}) });
218
+ }).catch(() => { }).finally(() => { handling--; }); // A disconnected peer cannot receive its reply.
197
219
  }
198
220
  }
199
221
  function dispose(_required, _optional = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/sidecar",
3
- "version": "0.6.19",
3
+ "version": "0.6.21",
4
4
  "description": "Sidecar process runtime: JSON-IPC server and client, IPC path validation, namespace/runtime path resolution, port allocation, launch bootstrap, and a local daemon registry.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -63,11 +63,11 @@
63
63
  },
64
64
  "devDependencies": {
65
65
  "@vitest/coverage-v8": "^2.1.9",
66
- "@jini-ai/core": "0.6.19",
66
+ "@jini-ai/core": "0.6.21",
67
67
  "@jini-ai/platform": "0.6.19"
68
68
  },
69
69
  "dependencies": {
70
- "@jini-ai/core": "^0.6.19",
70
+ "@jini-ai/core": "^0.6.21",
71
71
  "@jini-ai/platform": "^0.6.19"
72
72
  },
73
73
  "scripts": {