@mnmal-ai/cortext-omp 1.0.0-alpha.20 → 1.0.0-alpha.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.
Files changed (2) hide show
  1. package/dist/extension.js +75 -31
  2. package/package.json +2 -2
package/dist/extension.js CHANGED
@@ -2467,7 +2467,7 @@ const unpack = (...args) => unpack$1(...args);
2467
2467
  const createUnpackr = (options) => new Unpackr(options);
2468
2468
 
2469
2469
  //#endregion
2470
- //#region ../../node_modules/@mnmal-ai/substrate/dist/src-B_kHkbsr.js
2470
+ //#region ../../node_modules/@mnmal-ai/substrate/dist/src-DjIW8yvR.js
2471
2471
  /**
2472
2472
  * Exhaustiveness guard for the `default:` arm of a `switch` over a
2473
2473
  * discriminated union. An unhandled variant makes the call fail to
@@ -2523,6 +2523,19 @@ const EXPR_FUNCTIONS = [
2523
2523
  sig$1("case", "variadic", "any", "Pairs [cond, then] then a final else; branches share a type."),
2524
2524
  sig$1("coalesce", "variadic", "any", "First non-null of one or more arguments sharing a type.")
2525
2525
  ];
2526
+ /**
2527
+ * `JSON.stringify` that writes a bigint as a decimal string, so an `int64`
2528
+ * keeps every digit on the JSON wire. The plain call runs first, so a value
2529
+ * with no bigint pays nothing for the replacer.
2530
+ */
2531
+ function stringifyJson(value, space) {
2532
+ try {
2533
+ return JSON.stringify(value, null, space);
2534
+ } catch (e) {
2535
+ if (!(e instanceof TypeError) || !/BigInt/.test(e.message)) throw e;
2536
+ return JSON.stringify(value, (_k, v) => typeof v === "bigint" ? v.toString() : v, space);
2537
+ }
2538
+ }
2526
2539
  function parseQualifiedKey(key) {
2527
2540
  const slash = key.indexOf("/");
2528
2541
  if (slash <= 0 || slash === key.length - 1) return null;
@@ -2541,17 +2554,25 @@ function walkSlot(name, sel, fieldMap) {
2541
2554
  };
2542
2555
  const walk = sel._walk;
2543
2556
  if (!isObj(walk)) return void 0;
2544
- let type;
2545
- if (typeof walk.in === "string") type = /^[^/]+\/([^./]+)\./.exec(walk.in)?.[1];
2546
- else if (typeof walk.out === "string") {
2557
+ let far;
2558
+ if (typeof walk.in === "string") {
2559
+ const m = /^([^/]+)\/([^./]+)\./.exec(walk.in);
2560
+ if (m !== null) far = {
2561
+ ns: m[1],
2562
+ type: m[2]
2563
+ };
2564
+ } else if (typeof walk.out === "string") {
2547
2565
  const def = Object.hasOwn(fieldMap, walk.out) ? fieldMap[walk.out] : void 0;
2548
- if (def?.kind === "crossRef") type = def.type;
2566
+ if (def?.kind === "crossRef") far = {
2567
+ ns: def.ns,
2568
+ type: def.type
2569
+ };
2549
2570
  }
2550
- if (type === void 0) return void 0;
2571
+ if (far === void 0) return void 0;
2551
2572
  const fields = isObj(sel.fields) ? sel.fields : {};
2552
2573
  return {
2553
2574
  kind: "nested",
2554
- type,
2575
+ ...far,
2555
2576
  fields: {
2556
2577
  id: true,
2557
2578
  ...fields
@@ -2872,10 +2893,11 @@ function decodeWalkSlot(cell, slot, schema, path, ctx) {
2872
2893
  return Object.fromEntries(slot.names.map((n, i) => [n, cell[i] ?? null]));
2873
2894
  case "nested": {
2874
2895
  if (!Array.isArray(cell)) throw new PackDecodeError("expected array for nested selection", path);
2875
- const plan = getRowPlan(slot.fields, resolveFieldMap(schema, slot.type, path));
2896
+ const [far, at] = inNamespace(slot.ns, slot.type, "walk", schema, path, ctx);
2897
+ const plan = getRowPlan(slot.fields, resolveFieldMap(far, slot.type, path));
2876
2898
  return cell.map((tuple, idx) => {
2877
2899
  path.push(`[${idx}]`);
2878
- const out = decodeRowWithPlan(tuple, plan, schema, path, ctx);
2900
+ const out = decodeRowWithPlan(tuple, plan, far, path, at);
2879
2901
  path.pop();
2880
2902
  return out;
2881
2903
  });
@@ -2936,15 +2958,24 @@ function decodeListElement(elem, selection, inner, schema, elemPath, ctx, struct
2936
2958
  }
2937
2959
  }
2938
2960
  function decodeCrossRef(cell, selection, def, schema, path, ctx) {
2939
- if (def.ns === ctx.currentNs) return decodeRowWithPlan(cell, getRowPlan(selection, resolveFieldMap(schema, def.type, path)), schema, path, ctx);
2961
+ const [target, at] = inNamespace(def.ns, def.type, "crossRef", schema, path, ctx);
2962
+ return decodeRowWithPlan(cell, getRowPlan(selection, resolveFieldMap(target, def.type, path)), target, path, at);
2963
+ }
2964
+ /**
2965
+ * The schema rows of `ns` decode under, and the context to decode them in:
2966
+ * the current ones when `ns` is current, else `ctx.schemas[ns]`. `hop` names
2967
+ * what crossed into `ns` when its schema is missing.
2968
+ */
2969
+ function inNamespace(ns, type, hop, schema, path, ctx) {
2970
+ if (ns === ctx.currentNs) return [schema, ctx];
2940
2971
  const schemas = ctx.schemas;
2941
- if (schemas === void 0) throw new PackDecodeError(`cross-namespace crossRef '${def.ns}/${def.type}' requires ctx.schemas`, path);
2942
- const targetSchema = schemas[def.ns];
2943
- if (targetSchema === void 0) throw new PackDecodeError(`cross-namespace crossRef target namespace '${def.ns}' not in ctx.schemas`, path);
2944
- return decodeRowWithPlan(cell, getRowPlan(selection, resolveFieldMap(targetSchema, def.type, path)), targetSchema, path, {
2972
+ if (schemas === void 0) throw new PackDecodeError(`cross-namespace ${hop} '${ns}/${type}' requires ctx.schemas`, path);
2973
+ const target = Object.hasOwn(schemas, ns) ? schemas[ns] : void 0;
2974
+ if (target === void 0) throw new PackDecodeError(`cross-namespace ${hop} target namespace '${ns}' not in ctx.schemas`, path);
2975
+ return [target, {
2945
2976
  ...ctx,
2946
- currentNs: def.ns
2947
- });
2977
+ currentNs: ns
2978
+ }];
2948
2979
  }
2949
2980
  function decodeFieldDef(value, def, schema, path, ctx) {
2950
2981
  if (value === null || value === void 0) return null;
@@ -3609,7 +3640,7 @@ function j(i, t) {
3609
3640
  }
3610
3641
 
3611
3642
  //#endregion
3612
- //#region ../../node_modules/@mnmal-ai/substrate/dist/src-BNdhH_Hx.js
3643
+ //#region ../../node_modules/@mnmal-ai/substrate/dist/src-CyeuukOh.js
3613
3644
  /**
3614
3645
  * A fetch-shaped function over `node:http2`: the transport seam's HTTP/2
3615
3646
  * adapter for Node and Bun (Todo #1850, Decision #625).
@@ -4044,7 +4075,10 @@ function createAdminApi(t) {
4044
4075
  const out = [];
4045
4076
  let cursor;
4046
4077
  for (;;) {
4047
- const qs = cursor === void 0 ? "" : `?cursor=${encodeURIComponent(cursor)}`;
4078
+ const q = new URLSearchParams();
4079
+ if (opts.filter === "all") q.set("filter", "all");
4080
+ if (cursor !== void 0) q.set("cursor", cursor);
4081
+ const qs = q.toString() === "" ? "" : `?${q.toString()}`;
4048
4082
  const page = await (await t.raw(`/substrate/v1/_system/keys${qs}`, {
4049
4083
  method: "GET",
4050
4084
  ...opts.signal !== void 0 ? { signal: opts.signal } : {}
@@ -4462,16 +4496,6 @@ var ReconnectScheduler = class {
4462
4496
  reset() {
4463
4497
  this.#attempt = 0;
4464
4498
  }
4465
- /**
4466
- * Resolve after `nextDelay()` ms. Callers must use this serially — the
4467
- * `#attempt` counter is shared across calls, so overlapping `schedule()`
4468
- * invocations will produce incorrect delays. The stream reconnect loop awaits
4469
- * each `schedule()` before firing the next attempt.
4470
- */
4471
- async schedule() {
4472
- const d = this.nextDelay();
4473
- await new Promise((resolve) => setTimeout(resolve, d));
4474
- }
4475
4499
  };
4476
4500
  /** Server response frames as the subscribe and stream iterables yield them. */
4477
4501
  const DEFAULT_RECONNECT = {
@@ -4614,7 +4638,6 @@ async function* run(http, path, frame, opts, signal) {
4614
4638
  const idleMs = opts.idleMs ?? 65e3;
4615
4639
  for await (const payload of decodeStreamFrames(idleMs > 0 ? withIdleTimeout(body, idleMs) : body)) {
4616
4640
  const msg = decodeFrame(payload, opts.wire);
4617
- if (Date.now() - openedAt >= reconnect.maxDelayMs) backoff.reset();
4618
4641
  if (subscribe && msg.kind === "error" && msg.errors?.[0]?.code === OVERLOADED && overload.enabled) {
4619
4642
  const now = Date.now();
4620
4643
  if (lastOverloadAt !== null && now - lastOverloadAt > overload.healthyResetMs) overloadAttempts = 0;
@@ -4639,6 +4662,7 @@ async function* run(http, path, frame, opts, signal) {
4639
4662
  if (err instanceof SubscribeError || err instanceof NetworkError && err.code === "stream_interrupted") throw err;
4640
4663
  if (!subscribe) throw err instanceof NetworkError ? err : new NetworkError(`POST ${path}: the stream broke before its end frame`, err);
4641
4664
  }
4665
+ if (Date.now() - openedAt >= reconnect.maxDelayMs) backoff.reset();
4642
4666
  if (next === "stop") return;
4643
4667
  if (next === void 0) {
4644
4668
  if (signal.aborted) return;
@@ -4871,7 +4895,7 @@ var HttpTransport = class {
4871
4895
  res = await this.#fetch(url, {
4872
4896
  method: "POST",
4873
4897
  headers,
4874
- body: JSON.stringify(body),
4898
+ body: stringifyJson(body),
4875
4899
  ...opts.signal !== void 0 ? { signal: opts.signal } : {}
4876
4900
  });
4877
4901
  } catch (err) {
@@ -4907,7 +4931,9 @@ var HttpTransport = class {
4907
4931
  };
4908
4932
  throw new AuthError(`${res.status === 401 ? "Unauthorised" : "Forbidden"}: ${url}`, res.status, info);
4909
4933
  }
4910
- throw new NetworkError(`${res.status} from ${url}`, null, await errorInfo(res));
4934
+ const info = await errorInfo(res);
4935
+ const reason = [info.code, info.serverMessage].filter((s) => s !== void 0).join(": ");
4936
+ throw new NetworkError(`${res.status} from ${url}${reason ? `: ${reason}` : ""}`, null, info);
4911
4937
  }
4912
4938
  };
4913
4939
  /** The status plus whatever a JSON body says: the whole object as `body`, the first string of `error.message` (the recall plugin's nested shape), `error`, `message` as the message, and the first string of `error.code`, `code` as the code. Non-JSON bodies leave the status alone. */
@@ -5100,6 +5126,24 @@ var SubstrateClient = class {
5100
5126
  ...opts.signal !== void 0 ? { signal: opts.signal } : {}
5101
5127
  })).json();
5102
5128
  }
5129
+ /** Runs a sketch. Resolves with the reply for any 200, refusals and failures included. */
5130
+ async act(req, opts = {}) {
5131
+ this.#ensureOpen();
5132
+ return await (await this.#http.raw("/substrate/v1/act", {
5133
+ method: "POST",
5134
+ body: req,
5135
+ accept: "application/json",
5136
+ ...opts.signal !== void 0 ? { signal: opts.signal } : {}
5137
+ })).json();
5138
+ }
5139
+ /** A stored act result. A missing or foreign id throws a `NetworkError` with status 404. */
5140
+ async actResult(id, opts = {}) {
5141
+ this.#ensureOpen();
5142
+ return await (await this.#http.raw(`/substrate/v1/act/results/${encodeURIComponent(id)}`, {
5143
+ method: "GET",
5144
+ ...opts.signal !== void 0 ? { signal: opts.signal } : {}
5145
+ })).json();
5146
+ }
5103
5147
  async close() {
5104
5148
  if (this.#closed) return;
5105
5149
  this.#closed = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mnmal-ai/cortext-omp",
3
- "version": "1.0.0-alpha.20",
3
+ "version": "1.0.0-alpha.21",
4
4
  "description": "Cortext — the OMP (oh-my-pi) skin: cold-start and inbox seams as an OMP extension, bundling the @mnmal-ai/synoptic host into a committed dist artifact.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "devDependencies": {
26
- "@mnmal-ai/synoptic": "1.0.0-alpha.20",
26
+ "@mnmal-ai/synoptic": "1.0.0-alpha.21",
27
27
  "@types/node": "^26.6.4",
28
28
  "tsdown": "^0.23.0",
29
29
  "typescript": "^7.0.2",