@tokenfactory/acc-runner 0.40.19 → 0.40.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/dist/chat-companion.d.ts +28 -0
- package/dist/chat-companion.d.ts.map +1 -1
- package/dist/chat-companion.js +33 -1
- package/dist/chat-companion.js.map +1 -1
- package/dist/chat-lane.d.ts +41 -7
- package/dist/chat-lane.d.ts.map +1 -1
- package/dist/chat-lane.js +50 -9
- package/dist/chat-lane.js.map +1 -1
- package/dist/chat-transport.d.ts +8 -0
- package/dist/chat-transport.d.ts.map +1 -1
- package/dist/chat-transport.js +44 -20
- package/dist/chat-transport.js.map +1 -1
- package/dist/companion-run.d.ts.map +1 -1
- package/dist/companion-run.js +4 -0
- package/dist/companion-run.js.map +1 -1
- package/dist/companion.d.ts +6 -0
- package/dist/companion.d.ts.map +1 -1
- package/dist/companion.js +1 -0
- package/dist/companion.js.map +1 -1
- package/dist/watch-chat/fleet-chat-lane.d.ts +82 -0
- package/dist/watch-chat/fleet-chat-lane.d.ts.map +1 -0
- package/dist/watch-chat/fleet-chat-lane.js +101 -0
- package/dist/watch-chat/fleet-chat-lane.js.map +1 -0
- package/dist/watch-chat/grace-gate.d.ts +93 -0
- package/dist/watch-chat/grace-gate.d.ts.map +1 -0
- package/dist/watch-chat/grace-gate.js +107 -0
- package/dist/watch-chat/grace-gate.js.map +1 -0
- package/dist/watch-chat/grace-gated-transport.d.ts +58 -0
- package/dist/watch-chat/grace-gated-transport.d.ts.map +1 -0
- package/dist/watch-chat/grace-gated-transport.js +62 -0
- package/dist/watch-chat/grace-gated-transport.js.map +1 -0
- package/dist/watch-chat/index.d.ts +17 -0
- package/dist/watch-chat/index.d.ts.map +1 -0
- package/dist/watch-chat/index.js +17 -0
- package/dist/watch-chat/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FLEET-SERVE: the grace-gated claim decorator.
|
|
3
|
+
*
|
|
4
|
+
* Wraps any `ChatLaneTransport` so its `claim` first PROBES the conversation and
|
|
5
|
+
* only delegates to the underlying claim when the companion-preference grace gate
|
|
6
|
+
* (grace-gate.ts) says a fleet runner may take the turn now. Everything else —
|
|
7
|
+
* markStreaming / stream / complete / requeue — passes straight through
|
|
8
|
+
* untouched, so a fleet runner drives a claimed turn through the EXACT same
|
|
9
|
+
* transport, driver (driveChatTurn), and per-turn delegation as a companion. That
|
|
10
|
+
* shared path is what makes delegation scoping + provenance (serving runner_id,
|
|
11
|
+
* engine_id, delegation_jti) IDENTICAL across the companion and fleet paths: the
|
|
12
|
+
* only difference the fleet introduces is WHEN it is allowed to claim, never HOW
|
|
13
|
+
* the turn is served.
|
|
14
|
+
*
|
|
15
|
+
* Reusing the decorator seam means the fleet lane is just a `ChatCompanion` (the
|
|
16
|
+
* shared claim/drive loop) fed a grace-gated transport — no forked drive logic.
|
|
17
|
+
*/
|
|
18
|
+
import type { ChatLaneTransport } from "../chat-lane.js";
|
|
19
|
+
import { type ClaimableTurnProbe, type FleetClaimDecision } from "./grace-gate.js";
|
|
20
|
+
export interface GraceGateOptions {
|
|
21
|
+
/** Probe a conversation for its oldest claimable turn's timing state. */
|
|
22
|
+
probe: (conversationId: string) => Promise<ClaimableTurnProbe>;
|
|
23
|
+
/** Companion-preference window (ms) a fresh queued turn must age past. */
|
|
24
|
+
graceMs: number;
|
|
25
|
+
/** Observability: every claim decision (claimed or skipped), for logs/tests. */
|
|
26
|
+
onDecision?: (info: {
|
|
27
|
+
conversationId: string;
|
|
28
|
+
decision: FleetClaimDecision;
|
|
29
|
+
}) => void;
|
|
30
|
+
/** Best-effort log sink. */
|
|
31
|
+
onLog?: (line: string) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Decorate `inner` with the companion-preference grace gate on `claim`. On a
|
|
35
|
+
* probe FAILURE the decorator returns null (does NOT claim this pump): claiming
|
|
36
|
+
* blind would undercut companion preference, and the turn is never lost — the
|
|
37
|
+
* next pump re-probes and, worst case, the server lease-expiry reclaim (0273)
|
|
38
|
+
* still drains it. A `claim` the gate allows delegates verbatim, so the claimed
|
|
39
|
+
* turn's lease/runner assignment is exactly the companion's.
|
|
40
|
+
*/
|
|
41
|
+
export declare function graceGatedTransport(inner: ChatLaneTransport, opts: GraceGateOptions): ChatLaneTransport;
|
|
42
|
+
/** In-flight statuses the fleet probe reads (queued + reclaimable in-flight). */
|
|
43
|
+
export declare const FLEET_PROBE_STATUSES: readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* Build a Supabase-backed probe: read the conversation's in-flight acc.chat_turns
|
|
46
|
+
* rows (queued/claimed/streaming) and reduce them to a `ClaimableTurnProbe`. The
|
|
47
|
+
* read is org-scoped by the chat_turns SELECT policy (0254); ownership is already
|
|
48
|
+
* guaranteed upstream because the fleet lane only ever probes conversations its
|
|
49
|
+
* owner-affinity source admitted (bound-user-owned). A query error is surfaced as
|
|
50
|
+
* a throw so the decorator's fail-safe (defer, don't claim) engages.
|
|
51
|
+
*/
|
|
52
|
+
export declare function supabaseFleetProbe(client: {
|
|
53
|
+
from: (table: string) => any;
|
|
54
|
+
}, opts?: {
|
|
55
|
+
now?: () => number;
|
|
56
|
+
statuses?: readonly string[];
|
|
57
|
+
}): (conversationId: string) => Promise<ClaimableTurnProbe>;
|
|
58
|
+
//# sourceMappingURL=grace-gated-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grace-gated-transport.d.ts","sourceRoot":"","sources":["../../src/watch-chat/grace-gated-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EAExB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,gBAAgB;IAC/B,yEAAyE;IACzE,KAAK,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/D,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,kBAAkB,CAAA;KAAE,KAAK,IAAI,CAAC;IACtF,4BAA4B;IAC5B,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,iBAAiB,EACxB,IAAI,EAAE,gBAAgB,GACrB,iBAAiB,CAuBnB;AAED,iFAAiF;AACjF,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAAuC,CAAC;AAE1F;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAEhC,MAAM,EAAE;IAAE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAA;CAAE,EACxC,IAAI,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAO,GAC9D,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAezD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { decideFleetClaim, reduceClaimableProbe, } from "./grace-gate.js";
|
|
2
|
+
/**
|
|
3
|
+
* Decorate `inner` with the companion-preference grace gate on `claim`. On a
|
|
4
|
+
* probe FAILURE the decorator returns null (does NOT claim this pump): claiming
|
|
5
|
+
* blind would undercut companion preference, and the turn is never lost — the
|
|
6
|
+
* next pump re-probes and, worst case, the server lease-expiry reclaim (0273)
|
|
7
|
+
* still drains it. A `claim` the gate allows delegates verbatim, so the claimed
|
|
8
|
+
* turn's lease/runner assignment is exactly the companion's.
|
|
9
|
+
*/
|
|
10
|
+
export function graceGatedTransport(inner, opts) {
|
|
11
|
+
return {
|
|
12
|
+
async claim(args) {
|
|
13
|
+
let probe;
|
|
14
|
+
try {
|
|
15
|
+
probe = await opts.probe(args.conversationId);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
opts.onLog?.(`[acc-runner] fleet chat grace-probe(${args.conversationId}) failed: ` +
|
|
19
|
+
`${err.message}; deferring claim`);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const decision = decideFleetClaim(probe, { graceMs: opts.graceMs });
|
|
23
|
+
opts.onDecision?.({ conversationId: args.conversationId, decision });
|
|
24
|
+
if (!decision.claim)
|
|
25
|
+
return null;
|
|
26
|
+
return inner.claim(args);
|
|
27
|
+
},
|
|
28
|
+
...(inner.markStreaming ? { markStreaming: (turn) => inner.markStreaming(turn) } : {}),
|
|
29
|
+
stream: (turn, payload) => inner.stream(turn, payload),
|
|
30
|
+
complete: (turn, payload) => inner.complete(turn, payload),
|
|
31
|
+
requeue: (turn, payload) => inner.requeue(turn, payload),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** In-flight statuses the fleet probe reads (queued + reclaimable in-flight). */
|
|
35
|
+
export const FLEET_PROBE_STATUSES = ["queued", "claimed", "streaming"];
|
|
36
|
+
/**
|
|
37
|
+
* Build a Supabase-backed probe: read the conversation's in-flight acc.chat_turns
|
|
38
|
+
* rows (queued/claimed/streaming) and reduce them to a `ClaimableTurnProbe`. The
|
|
39
|
+
* read is org-scoped by the chat_turns SELECT policy (0254); ownership is already
|
|
40
|
+
* guaranteed upstream because the fleet lane only ever probes conversations its
|
|
41
|
+
* owner-affinity source admitted (bound-user-owned). A query error is surfaced as
|
|
42
|
+
* a throw so the decorator's fail-safe (defer, don't claim) engages.
|
|
43
|
+
*/
|
|
44
|
+
export function supabaseFleetProbe(
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
client, opts = {}) {
|
|
47
|
+
const now = opts.now ?? Date.now;
|
|
48
|
+
const statuses = opts.statuses ?? FLEET_PROBE_STATUSES;
|
|
49
|
+
return async (conversationId) => {
|
|
50
|
+
const res = await client
|
|
51
|
+
.from("chat_turns")
|
|
52
|
+
.select("status, created_at, lease_expires_at")
|
|
53
|
+
.eq("conversation_id", conversationId)
|
|
54
|
+
.in("status", statuses);
|
|
55
|
+
if (res?.error) {
|
|
56
|
+
throw new Error(res.error.message ?? "chat_turns probe failed");
|
|
57
|
+
}
|
|
58
|
+
const rows = (Array.isArray(res?.data) ? res.data : []);
|
|
59
|
+
return reduceClaimableProbe(rows, now());
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=grace-gated-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grace-gated-transport.js","sourceRoot":"","sources":["../../src/watch-chat/grace-gated-transport.ts"],"names":[],"mappings":"AAkBA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,GAIrB,MAAM,iBAAiB,CAAC;AAazB;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAwB,EACxB,IAAsB;IAEtB,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,IAAI;YACd,IAAI,KAAyB,CAAC;YAC9B,IAAI,CAAC;gBACH,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAChD,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,KAAK,EAAE,CACV,uCAAuC,IAAI,CAAC,cAAc,YAAY;oBACpE,GAAI,GAAa,CAAC,OAAO,mBAAmB,CAC/C,CAAC;gBACF,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;YACpE,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC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C,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC1B,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,yBAAyB,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAwB,CAAC;QAC/E,OAAO,oBAAoB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FLEET-SERVE: the fleet-fallback chat-lane barrel.
|
|
3
|
+
*
|
|
4
|
+
* A fleet `watch` runner may serve its bound user's chat turns as the fallback
|
|
5
|
+
* behind their companion. The pieces:
|
|
6
|
+
* - grace-gate.ts — companion-preference timing decision (pure).
|
|
7
|
+
* - grace-gated-transport.ts — the claim decorator + Supabase probe builder.
|
|
8
|
+
* - fleet-chat-lane.ts — the owner-scoped, grace-gated ChatCompanion.
|
|
9
|
+
*
|
|
10
|
+
* Machine-ownership isolation (bound-user turns only) is enforced by the
|
|
11
|
+
* owner-affinity source (runner-side) + the acc.claim_chat_turn owner gate
|
|
12
|
+
* (DB-side); this module never widens who may serve, only WHEN the fleet claims.
|
|
13
|
+
*/
|
|
14
|
+
export { DEFAULT_FLEET_CHAT_GRACE_MS, FLEET_CHAT_GRACE_MS_ENV, MIN_FLEET_CHAT_GRACE_MS, MAX_FLEET_CHAT_GRACE_MS, resolveFleetChatGraceMs, reduceClaimableProbe, decideFleetClaim, type ClaimableTurnProbe, type FleetTurnProbeRow, type FleetClaimReason, type FleetClaimDecision, } from "./grace-gate.js";
|
|
15
|
+
export { graceGatedTransport, supabaseFleetProbe, FLEET_PROBE_STATUSES, type GraceGateOptions, } from "./grace-gated-transport.js";
|
|
16
|
+
export { FleetChatLane, type FleetChatLaneDeps } from "./fleet-chat-lane.js";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/watch-chat/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,gBAAgB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FLEET-SERVE: the fleet-fallback chat-lane barrel.
|
|
3
|
+
*
|
|
4
|
+
* A fleet `watch` runner may serve its bound user's chat turns as the fallback
|
|
5
|
+
* behind their companion. The pieces:
|
|
6
|
+
* - grace-gate.ts — companion-preference timing decision (pure).
|
|
7
|
+
* - grace-gated-transport.ts — the claim decorator + Supabase probe builder.
|
|
8
|
+
* - fleet-chat-lane.ts — the owner-scoped, grace-gated ChatCompanion.
|
|
9
|
+
*
|
|
10
|
+
* Machine-ownership isolation (bound-user turns only) is enforced by the
|
|
11
|
+
* owner-affinity source (runner-side) + the acc.claim_chat_turn owner gate
|
|
12
|
+
* (DB-side); this module never widens who may serve, only WHEN the fleet claims.
|
|
13
|
+
*/
|
|
14
|
+
export { DEFAULT_FLEET_CHAT_GRACE_MS, FLEET_CHAT_GRACE_MS_ENV, MIN_FLEET_CHAT_GRACE_MS, MAX_FLEET_CHAT_GRACE_MS, resolveFleetChatGraceMs, reduceClaimableProbe, decideFleetClaim, } from "./grace-gate.js";
|
|
15
|
+
export { graceGatedTransport, supabaseFleetProbe, FLEET_PROBE_STATUSES, } from "./grace-gated-transport.js";
|
|
16
|
+
export { FleetChatLane } from "./fleet-chat-lane.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/watch-chat/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,GAKjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,GAErB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,aAAa,EAA0B,MAAM,sBAAsB,CAAC"}
|