@plurnk/plurnk-service 0.12.0 → 0.13.0

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.
@@ -0,0 +1,10 @@
1
+ import type { SubscriptionCaps, SubscriptionHandle } from "@plurnk/plurnk-schemes";
2
+ import type { PlurnkSchemeContext } from "../scheme-types.ts";
3
+ export default class DbSubscriptionCaps implements SubscriptionCaps {
4
+ #private;
5
+ constructor(ctx: PlurnkSchemeContext, scheme: string | null);
6
+ open(pathname: string, handle: SubscriptionHandle): Promise<AbortSignal>;
7
+ notifyChunk(channel: string, chunk: string): Promise<void>;
8
+ close(reason: "done" | "error", outcome?: string): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=DbSubscriptionCaps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DbSubscriptionCaps.d.ts","sourceRoot":"","sources":["../../../src/core/caps/DbSubscriptionCaps.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAgB,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAK9D,MAAM,CAAC,OAAO,OAAO,kBAAmB,YAAW,gBAAgB;;gBAQnD,GAAG,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAKrD,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBxE,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1D,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAyBzE"}
@@ -0,0 +1,86 @@
1
+ // db-backed SubscriptionCaps (@plurnk/plurnk-schemes) — keystone PR-2 seam (#180).
2
+ // The streaming lifecycle a sibling drives:
3
+ // open(pathname, handle) → registers the subscription and hands back a
4
+ // run+teardown-composed AbortSignal; a run abort also force-cancels the
5
+ // sibling's handle (mirrors the exec scheme's #activeAborts).
6
+ // notifyChunk(channel, chunk) → FUSED append-to-channel + stream/event.
7
+ // close(reason, outcome?) → composites every channel's terminal state, the
8
+ // registry close, and the rich run-wake (the only place with the close
9
+ // context to populate it — which is why NotifyCaps dropped wakeRun, #180).
10
+ // Stateful: open() binds the entry + subscription that notifyChunk()/close()
11
+ // operate on. Models src/schemes/Exec.ts over the same ChannelWrite primitives.
12
+ import ChannelWrite from "../ChannelWrite.js";
13
+ import CapsResolve from "./CapsResolve.js";
14
+ export default class DbSubscriptionCaps {
15
+ #ctx;
16
+ #scheme;
17
+ #pathname = null;
18
+ #entryId = null;
19
+ #subscriptionId = null;
20
+ #unlink = () => { };
21
+ constructor(ctx, scheme) {
22
+ this.#ctx = ctx;
23
+ this.#scheme = scheme;
24
+ }
25
+ async open(pathname, handle) {
26
+ const entryId = await CapsResolve.entryId(this.#ctx, this.#scheme, pathname);
27
+ if (entryId === null)
28
+ throw new Error(`subscriptions.open: no entry at ${pathname}`);
29
+ const subscriptionId = await ChannelWrite.openSubscription(this.#ctx.db, {
30
+ runId: this.#ctx.runId, entryId, scheme: this.#scheme ?? "file", handle: pathname,
31
+ });
32
+ // Compose the run signal with a fresh controller; a run abort also
33
+ // force-cancels the sibling's handle.
34
+ const controller = new AbortController();
35
+ const parent = this.#ctx.signal;
36
+ if (parent !== undefined) {
37
+ if (parent.aborted) {
38
+ void handle.cancel();
39
+ controller.abort(parent.reason);
40
+ }
41
+ else {
42
+ const onAbort = () => { void handle.cancel(); controller.abort(parent.reason); };
43
+ parent.addEventListener("abort", onAbort, { once: true });
44
+ this.#unlink = () => parent.removeEventListener("abort", onAbort);
45
+ }
46
+ }
47
+ this.#pathname = pathname;
48
+ this.#entryId = entryId;
49
+ this.#subscriptionId = subscriptionId;
50
+ return controller.signal;
51
+ }
52
+ async notifyChunk(channel, chunk) {
53
+ if (this.#entryId === null)
54
+ throw new Error("subscriptions.notifyChunk: no open subscription");
55
+ await ChannelWrite.appendToChannel(this.#ctx.db, {
56
+ entryId: this.#entryId, channel, chunk, notify: this.#ctx.streamEventNotify,
57
+ });
58
+ }
59
+ async close(reason, outcome) {
60
+ const entryId = this.#entryId;
61
+ const subscriptionId = this.#subscriptionId;
62
+ if (entryId === null || subscriptionId === null)
63
+ throw new Error("subscriptions.close: no open subscription");
64
+ const state = reason === "error" ? "errored" : "closed";
65
+ const closeStatus = reason === "error" ? 500 : 200;
66
+ // Every channel of the entry → terminal state, then the registry row
67
+ // closes, then the run wakes with the scheme's summary.
68
+ const channels = await this.#ctx.db.crud_read_channels.all({ entry_id: entryId });
69
+ for (const { name } of channels) {
70
+ await ChannelWrite.setChannelState(this.#ctx.db, { entryId, channel: name, state, notify: this.#ctx.streamEventNotify });
71
+ }
72
+ await ChannelWrite.closeSubscription(this.#ctx.db, { subscriptionId, status: closeStatus });
73
+ this.#unlink();
74
+ const target = this.#scheme === null ? `file://${this.#pathname}` : `${this.#scheme}://${this.#pathname}`;
75
+ this.#ctx.wakeRunNotify?.({
76
+ sessionId: this.#ctx.sessionId, runId: this.#ctx.runId,
77
+ entryId, target, subscriptionId, closeStatus,
78
+ scheme: this.#scheme ?? "file", summary: outcome ?? "",
79
+ });
80
+ this.#pathname = null;
81
+ this.#entryId = null;
82
+ this.#subscriptionId = null;
83
+ this.#unlink = () => { };
84
+ }
85
+ }
86
+ //# sourceMappingURL=DbSubscriptionCaps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DbSubscriptionCaps.js","sourceRoot":"","sources":["../../../src/core/caps/DbSubscriptionCaps.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,4CAA4C;AAC5C,yEAAyE;AACzE,4EAA4E;AAC5E,kEAAkE;AAClE,0EAA0E;AAC1E,6EAA6E;AAC7E,2EAA2E;AAC3E,+EAA+E;AA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AC,OAAO,IAAI,MAAM,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE;SACzD,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC;IAClC,CAAC;CACJ"}
@@ -0,0 +1,18 @@
1
+ import type { SchemeCtx, EntryCaps, ChannelCaps, TagCaps, NotifyCaps, SubscriptionCaps, CrossSchemeCaps, WriterTier } from "@plurnk/plurnk-schemes";
2
+ import type { PlurnkSchemeContext } from "../scheme-types.ts";
3
+ export default class SchemeCtxImpl implements SchemeCtx {
4
+ readonly sessionId: number;
5
+ readonly runId: number;
6
+ readonly loopId: number;
7
+ readonly turnId: number;
8
+ readonly writer: WriterTier;
9
+ readonly signal: AbortSignal | undefined;
10
+ readonly entries: EntryCaps;
11
+ readonly channels: ChannelCaps;
12
+ readonly tags: TagCaps;
13
+ readonly notify: NotifyCaps;
14
+ readonly subscriptions: SubscriptionCaps;
15
+ readonly crossScheme: CrossSchemeCaps;
16
+ constructor(ctx: PlurnkSchemeContext, scheme: string | null);
17
+ }
18
+ //# sourceMappingURL=SchemeCtxImpl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemeCtxImpl.d.ts","sourceRoot":"","sources":["../../../src/core/caps/SchemeCtxImpl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,UAAU,EACxG,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAW9D,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,SAAS;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,gBAAgB,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAqB;gBAE9C,GAAG,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAa9D"}
@@ -0,0 +1,42 @@
1
+ // db-backed SchemeCtx (@plurnk/plurnk-schemes) — keystone PR-2 (#180). Assembles
2
+ // the capability surface a third-party @plurnk/plurnk-schemes-* sibling receives:
3
+ // identity fields lifted off the PlurnkSchemeContext, the five db-backed caps,
4
+ // and the deferred crossScheme stub. A sibling reaches the substrate ONLY through
5
+ // this — never the raw ctx.db (schemes SPEC §5). `visibility` is absent: entry
6
+ // visibility is gone post-teardown, so schemes dropped the cap (0.4.3).
7
+ import DbEntryCaps from "./DbEntryCaps.js";
8
+ import DbChannelCaps from "./DbChannelCaps.js";
9
+ import DbTagCaps from "./DbTagCaps.js";
10
+ import DbNotifyCaps from "./DbNotifyCaps.js";
11
+ import DbSubscriptionCaps from "./DbSubscriptionCaps.js";
12
+ const CROSS_SCHEME_STUB = {
13
+ _deferred: "see plurnk-service#180 — designed when first cross-scheme COPY/MOVE forces the FROM/TO shape",
14
+ };
15
+ export default class SchemeCtxImpl {
16
+ sessionId;
17
+ runId;
18
+ loopId;
19
+ turnId;
20
+ writer;
21
+ signal;
22
+ entries;
23
+ channels;
24
+ tags;
25
+ notify;
26
+ subscriptions;
27
+ crossScheme = CROSS_SCHEME_STUB;
28
+ constructor(ctx, scheme) {
29
+ this.sessionId = ctx.sessionId;
30
+ this.runId = ctx.runId;
31
+ this.loopId = ctx.loopId;
32
+ this.turnId = ctx.turnId;
33
+ this.writer = ctx.writer;
34
+ this.signal = ctx.signal;
35
+ this.entries = new DbEntryCaps(ctx, scheme);
36
+ this.channels = new DbChannelCaps(ctx, scheme);
37
+ this.tags = new DbTagCaps(ctx, scheme);
38
+ this.notify = new DbNotifyCaps(ctx, scheme);
39
+ this.subscriptions = new DbSubscriptionCaps(ctx, scheme);
40
+ }
41
+ }
42
+ //# sourceMappingURL=SchemeCtxImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemeCtxImpl.js","sourceRoot":"","sources":["../../../src/core/caps/SchemeCtxImpl.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,kFAAkF;AAClF,+EAA+E;AAC/E,kFAAkF;AAClF,+EAA+E;AAC/E,wEAAwE;AAMxE,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAC/C,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AAEzD,MAAM,iBAAiB,GAAoB;IACvC,SAAS,EAAE,8FAA8F;CAC5G,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,aAAa;IACrB,SAAS,CAAS;IAClB,KAAK,CAAS;IACd,MAAM,CAAS;IACf,MAAM,CAAS;IACf,MAAM,CAAa;IACnB,MAAM,CAA0B;IAChC,OAAO,CAAY;IACnB,QAAQ,CAAc;IACtB,IAAI,CAAU;IACd,MAAM,CAAa;IACnB,aAAa,CAAmB;IAChC,WAAW,GAAoB,iBAAiB,CAAC;IAE1D,YAAY,GAAwB,EAAE,MAAqB;QACvD,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ,GAAG,IAAI,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,aAAa,GAAG,IAAI,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC7D,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plurnk/plurnk-service",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Plurnk agent runtime — the server / engine / core. Implements the @plurnk/plurnk-grammar contract.",
5
5
  "type": "module",
6
6
  "license": "MIT",