@tangle-network/agent-app 0.60.132 → 0.60.133

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 (40) hide show
  1. package/dist/app-auth/index.js +3 -3
  2. package/dist/assistant/index.js +10 -10
  3. package/dist/chat-react/index.js +2 -2
  4. package/dist/chat-routes/index.js +10 -10
  5. package/dist/chat-routes/turn-routes.d.ts +6 -2
  6. package/dist/chat-store/index.js +3 -3
  7. package/dist/{chunk-JZUSVGRJ.js → chunk-2GP6JOWE.js} +15 -2
  8. package/dist/chunk-2GP6JOWE.js.map +1 -0
  9. package/dist/chunk-4JUEOVQS.js +134 -0
  10. package/dist/chunk-4JUEOVQS.js.map +1 -0
  11. package/dist/{chunk-5S5ANZBS.js → chunk-HZGKPWVA.js} +6 -6
  12. package/dist/{chunk-NRG2YHGY.js → chunk-IMTU5LCF.js} +1 -1
  13. package/dist/{chunk-XPP653RG.js → chunk-JEM4BKR4.js} +10 -10
  14. package/dist/{chunk-4DEI6QC5.js → chunk-NNNAC3DV.js} +4 -4
  15. package/dist/{chunk-GU7OZFU7.js → chunk-VXWEJ7F2.js} +4 -4
  16. package/dist/{chunk-ZGUXI5SI.js → chunk-XNKLQG26.js} +5 -5
  17. package/dist/design-canvas-react/index.js +4 -4
  18. package/dist/design-canvas-react/lazy.js +1 -1
  19. package/dist/public-consultation/index.js +5 -5
  20. package/dist/rollout/cli.d.ts +25 -0
  21. package/dist/rollout/cli.js +121 -0
  22. package/dist/rollout/cli.js.map +1 -0
  23. package/dist/rollout/d1.d.ts +62 -0
  24. package/dist/rollout/d1.js +89 -0
  25. package/dist/rollout/d1.js.map +1 -0
  26. package/dist/rollout/index.d.ts +116 -0
  27. package/dist/rollout/index.js +19 -0
  28. package/dist/rollout/index.js.map +1 -0
  29. package/dist/stream/index.js +2 -2
  30. package/dist/studio-react/index.js +2 -2
  31. package/dist/web-react/index.js +16 -16
  32. package/dist/workspace-react/index.js +5 -5
  33. package/package.json +12 -1
  34. package/dist/chunk-JZUSVGRJ.js.map +0 -1
  35. /package/dist/{chunk-5S5ANZBS.js.map → chunk-HZGKPWVA.js.map} +0 -0
  36. /package/dist/{chunk-NRG2YHGY.js.map → chunk-IMTU5LCF.js.map} +0 -0
  37. /package/dist/{chunk-XPP653RG.js.map → chunk-JEM4BKR4.js.map} +0 -0
  38. /package/dist/{chunk-4DEI6QC5.js.map → chunk-NNNAC3DV.js.map} +0 -0
  39. /package/dist/{chunk-GU7OZFU7.js.map → chunk-VXWEJ7F2.js.map} +0 -0
  40. /package/dist/{chunk-ZGUXI5SI.js.map → chunk-XNKLQG26.js.map} +0 -0
@@ -0,0 +1,134 @@
1
+ // src/rollout/index.ts
2
+ function parseRolloutList(value) {
3
+ const ids = /* @__PURE__ */ new Set();
4
+ const excluded = /* @__PURE__ */ new Set();
5
+ const newSince = [];
6
+ let all = false;
7
+ for (const raw of (value ?? "").split(",")) {
8
+ const entry = raw.trim();
9
+ if (!entry) continue;
10
+ if (entry === "*") all = true;
11
+ else if (entry.startsWith("!")) excluded.add(entry.slice(1).trim());
12
+ else if (entry.startsWith("new-since:")) {
13
+ const at = Date.parse(entry.slice("new-since:".length));
14
+ if (!Number.isFinite(at)) throw new Error(`rollout list entry ${entry} is not a valid time`);
15
+ newSince.push(at);
16
+ } else ids.add(entry);
17
+ }
18
+ return { all, ids, excluded, newSince };
19
+ }
20
+ function rolloutAdmits(value, workspace) {
21
+ const list = typeof value === "string" ? parseRolloutList(value) : value;
22
+ if (list.excluded.has(workspace.id)) return false;
23
+ if (list.all || list.ids.has(workspace.id)) return true;
24
+ return workspace.createdAt !== void 0 && list.newSince.some((at) => workspace.createdAt >= at);
25
+ }
26
+ function rolloutWidens(fromValue, toValue) {
27
+ const from = parseRolloutList(fromValue);
28
+ const to = parseRolloutList(toValue);
29
+ if (to.all) {
30
+ if (!from.all) return true;
31
+ return [...from.excluded].some((id) => !to.excluded.has(id));
32
+ }
33
+ if ([...to.ids].some((id) => !rolloutAdmits(from, { id }))) return true;
34
+ const earliest = (list) => list.newSince.length ? Math.min(...list.newSince) : Infinity;
35
+ if (to.newSince.length && !from.all && earliest(to) < earliest(from)) return true;
36
+ return false;
37
+ }
38
+ function normalizeRolloutValue(value) {
39
+ return value.split(",").map((entry) => entry.trim()).filter(Boolean).sort().join(",");
40
+ }
41
+ function stageOf(plan, value) {
42
+ const key = normalizeRolloutValue(value);
43
+ return plan.stages.find((stage) => normalizeRolloutValue(stage.value) === key) ?? null;
44
+ }
45
+ function killLineBreaches(stage, measured) {
46
+ if (!measured) return [`stage ${stage.name} has no measurement`];
47
+ if (measured.stage !== stage.name) return [`measurement is for stage ${measured.stage}, not ${stage.name}`];
48
+ const reasons = [];
49
+ if (!(measured.samples >= stage.minSamples)) {
50
+ reasons.push(`stage ${stage.name} has ${measured.samples} measured turns, under its minimum of ${stage.minSamples}`);
51
+ }
52
+ for (const [metric, line] of Object.entries(stage.kill)) {
53
+ const value = measured.metrics[metric];
54
+ if (typeof value !== "number" || !Number.isFinite(value)) {
55
+ reasons.push(`${metric} was not measured`);
56
+ continue;
57
+ }
58
+ if (line.max !== void 0 && value > line.max) reasons.push(`${metric} ${value} over kill line ${line.max}`);
59
+ if (line.min !== void 0 && value < line.min) reasons.push(`${metric} ${value} under kill line ${line.min}`);
60
+ }
61
+ return reasons;
62
+ }
63
+ function validateRolloutPlan(plan) {
64
+ if (!plan.name || !plan.variable) throw new Error("a rollout plan needs a name and a variable");
65
+ if (!plan.stages.length) throw new Error(`rollout ${plan.name} declares no stages`);
66
+ const names = /* @__PURE__ */ new Set();
67
+ const values = /* @__PURE__ */ new Set();
68
+ for (const stage of plan.stages) {
69
+ if (names.has(stage.name)) throw new Error(`rollout ${plan.name} repeats stage ${stage.name}`);
70
+ names.add(stage.name);
71
+ const value = normalizeRolloutValue(stage.value);
72
+ if (values.has(value)) throw new Error(`rollout ${plan.name} gives two stages the value ${stage.value}`);
73
+ values.add(value);
74
+ parseRolloutList(stage.value);
75
+ if (!Number.isInteger(stage.minSamples) || stage.minSamples < 1) {
76
+ throw new Error(`stage ${stage.name} needs minSamples of at least 1`);
77
+ }
78
+ if (!Object.keys(stage.kill).length) throw new Error(`stage ${stage.name} declares no kill lines`);
79
+ }
80
+ for (let index = 1; index < plan.stages.length; index++) {
81
+ const previous = plan.stages[index - 1];
82
+ const stage = plan.stages[index];
83
+ if (!rolloutWidens(previous.value, stage.value)) {
84
+ throw new Error(`stage ${stage.name} does not widen stage ${previous.name}`);
85
+ }
86
+ }
87
+ }
88
+ async function decideRollout(input) {
89
+ const { plan, fromValue, toValue } = input;
90
+ validateRolloutPlan(plan);
91
+ const fromStage = stageOf(plan, fromValue);
92
+ const toStage = stageOf(plan, toValue);
93
+ const widens = rolloutWidens(fromValue, toValue);
94
+ const record = (reasons, measured2) => ({
95
+ rollout: plan.name,
96
+ variable: plan.variable,
97
+ from: { value: fromValue, stage: fromStage?.name ?? null },
98
+ to: { value: toValue, stage: toStage?.name ?? null },
99
+ widens,
100
+ decision: reasons.length ? "refused" : "allowed",
101
+ reasons,
102
+ measured: measured2,
103
+ at: (input.now?.() ?? /* @__PURE__ */ new Date()).toISOString()
104
+ });
105
+ if (!widens) return record([], null);
106
+ if (!toStage) return record([`${toValue} is not a declared stage of ${plan.name}`], null);
107
+ const target = plan.stages.indexOf(toStage);
108
+ if (!fromStage) {
109
+ const empty = !normalizeRolloutValue(fromValue);
110
+ return record(empty && target === 0 ? [] : [`the current value ${fromValue || "(empty)"} is not a declared stage of ${plan.name}`], null);
111
+ }
112
+ const current = plan.stages.indexOf(fromStage);
113
+ if (target > current + 1) {
114
+ return record([`${toStage.name} skips ${plan.stages.slice(current + 1, target).map((stage) => stage.name).join(", ")}`], null);
115
+ }
116
+ let measured;
117
+ try {
118
+ measured = await input.measure(fromStage);
119
+ } catch (error) {
120
+ return record([`measuring stage ${fromStage.name} failed: ${error instanceof Error ? error.message : String(error)}`], null);
121
+ }
122
+ return record(killLineBreaches(fromStage, measured), measured);
123
+ }
124
+
125
+ export {
126
+ parseRolloutList,
127
+ rolloutAdmits,
128
+ rolloutWidens,
129
+ normalizeRolloutValue,
130
+ killLineBreaches,
131
+ validateRolloutPlan,
132
+ decideRollout
133
+ };
134
+ //# sourceMappingURL=chunk-4JUEOVQS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/rollout/index.ts"],"sourcesContent":["/**\n * Rollout guard: a staged rollout widens only when the stage it leaves met\n * that stage's kill lines on measured production numbers.\n *\n * WHY. Hospitality's routed lane widened from two QA workspaces to `*` at a\n * first-words p50 of 3.54 s, past kill lines of 2.5 s and 3.0 s\n * (hospitality-agent #382, 2026-10-11). The numbers existed; nothing read them\n * before the list changed. This module is the one place that reads them.\n *\n * THE LIST. A rollout is one comma-separated value, usually a deploy variable\n * such as `HOSPITALITY_ROUTED_BUSINESS_IDS`: workspace ids, `*` for every\n * workspace, `!<id>` to keep one out whatever else matches, and\n * `new-since:<ISO time>` for workspaces created at or after that time.\n * {@link rolloutAdmits} is the reference reading of that grammar.\n *\n * THE RULE ({@link decideRollout}).\n * - A change that admits no workspace the current value did not (a narrowing,\n * a rollback, the same stage) is always allowed: a guard that can block a\n * rollback is worse than none.\n * - A widening must land on a declared stage, the next one after the current\n * value's stage, never past it.\n * - The stage being left must have at least `minSamples` measured turns and\n * every kill line met. A metric that was not measured fails its line.\n * - A refusal names each reason (`first_words_p50_ms 3540 over kill line 2500`).\n *\n * Every decision, allowed or refused, is returned as one record the caller\n * persists (the CLI appends it to a JSONL ledger and hands it to the\n * config's `record`).\n */\n\n/** A kill line: the measured value must stay at or under `max` and at or over `min`. */\nexport interface RolloutKillLine {\n max?: number\n min?: number\n}\n\nexport interface RolloutStage {\n /** Short name used in refusals and records, e.g. `qa`, `all-but-recenter`. */\n name: string\n /** The exact list value that defines this stage. */\n value: string\n /** Turns the stage must have served, measured, before the rollout may leave it. */\n minSamples: number\n /** Metric name → line. Metric names are the product's, e.g. `first_words_p50_ms`, `failure_rate`. */\n kill: Record<string, RolloutKillLine>\n}\n\nexport interface RolloutPlan {\n /** e.g. `hospitality-routed-chat`. */\n name: string\n /** The deploy variable that carries the list, e.g. `HOSPITALITY_ROUTED_BUSINESS_IDS`. */\n variable: string\n /** In widening order. */\n stages: RolloutStage[]\n}\n\n/** Production numbers for one stage, from the product's own instrument. */\nexport interface StageMeasurement {\n stage: string\n samples: number\n metrics: Record<string, number | null | undefined>\n /** Where the numbers came from (ledger, query, soak), for the record. */\n source?: string\n window?: { from: string; to: string }\n}\n\nexport interface RolloutDecision {\n rollout: string\n variable: string\n from: { value: string; stage: string | null }\n to: { value: string; stage: string | null }\n widens: boolean\n decision: 'allowed' | 'refused'\n /** Empty when allowed; each refusal reason otherwise. */\n reasons: string[]\n measured: StageMeasurement | null\n at: string\n}\n\nexport interface ParsedRolloutList {\n all: boolean\n ids: ReadonlySet<string>\n excluded: ReadonlySet<string>\n /** Epoch ms of each `new-since:` entry. */\n newSince: readonly number[]\n}\n\nexport function parseRolloutList(value: string | null | undefined): ParsedRolloutList {\n const ids = new Set<string>()\n const excluded = new Set<string>()\n const newSince: number[] = []\n let all = false\n for (const raw of (value ?? '').split(',')) {\n const entry = raw.trim()\n if (!entry) continue\n if (entry === '*') all = true\n else if (entry.startsWith('!')) excluded.add(entry.slice(1).trim())\n else if (entry.startsWith('new-since:')) {\n const at = Date.parse(entry.slice('new-since:'.length))\n if (!Number.isFinite(at)) throw new Error(`rollout list entry ${entry} is not a valid time`)\n newSince.push(at)\n } else ids.add(entry)\n }\n return { all, ids, excluded, newSince }\n}\n\n/** Whether a list admits one workspace. `createdAt` (epoch ms) is needed only for `new-since:` entries. */\nexport function rolloutAdmits(value: string | ParsedRolloutList, workspace: { id: string; createdAt?: number }): boolean {\n const list = typeof value === 'string' ? parseRolloutList(value) : value\n if (list.excluded.has(workspace.id)) return false\n if (list.all || list.ids.has(workspace.id)) return true\n return workspace.createdAt !== undefined && list.newSince.some(at => workspace.createdAt! >= at)\n}\n\n/**\n * Whether `to` may admit a workspace `from` does not. Conservative: a change it\n * cannot prove narrower counts as a widening.\n */\nexport function rolloutWidens(fromValue: string, toValue: string): boolean {\n const from = parseRolloutList(fromValue)\n const to = parseRolloutList(toValue)\n if (to.all) {\n if (!from.all) return true\n // Under `*` on both sides, only a dropped exclusion widens.\n return [...from.excluded].some(id => !to.excluded.has(id))\n }\n if ([...to.ids].some(id => !rolloutAdmits(from, { id }))) return true\n // An id `from` admitted only because it was listed, which `to` now excludes, narrows; nothing else here widens.\n const earliest = (list: ParsedRolloutList) => list.newSince.length ? Math.min(...list.newSince) : Infinity\n if (to.newSince.length && !from.all && earliest(to) < earliest(from)) return true\n return false\n}\n\n/** Canonical form for matching a value to a stage: entries trimmed and sorted. */\nexport function normalizeRolloutValue(value: string): string {\n return value.split(',').map(entry => entry.trim()).filter(Boolean).sort().join(',')\n}\n\nfunction stageOf(plan: RolloutPlan, value: string): RolloutStage | null {\n const key = normalizeRolloutValue(value)\n return plan.stages.find(stage => normalizeRolloutValue(stage.value) === key) ?? null\n}\n\n/** Each kill line the measurement misses, as a reason. Empty when every line holds. */\nexport function killLineBreaches(stage: RolloutStage, measured: StageMeasurement | null): string[] {\n if (!measured) return [`stage ${stage.name} has no measurement`]\n if (measured.stage !== stage.name) return [`measurement is for stage ${measured.stage}, not ${stage.name}`]\n const reasons: string[] = []\n if (!(measured.samples >= stage.minSamples)) {\n reasons.push(`stage ${stage.name} has ${measured.samples} measured turns, under its minimum of ${stage.minSamples}`)\n }\n for (const [metric, line] of Object.entries(stage.kill)) {\n const value = measured.metrics[metric]\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n reasons.push(`${metric} was not measured`)\n continue\n }\n if (line.max !== undefined && value > line.max) reasons.push(`${metric} ${value} over kill line ${line.max}`)\n if (line.min !== undefined && value < line.min) reasons.push(`${metric} ${value} under kill line ${line.min}`)\n }\n return reasons\n}\n\nexport function validateRolloutPlan(plan: RolloutPlan): void {\n if (!plan.name || !plan.variable) throw new Error('a rollout plan needs a name and a variable')\n if (!plan.stages.length) throw new Error(`rollout ${plan.name} declares no stages`)\n const names = new Set<string>()\n const values = new Set<string>()\n for (const stage of plan.stages) {\n if (names.has(stage.name)) throw new Error(`rollout ${plan.name} repeats stage ${stage.name}`)\n names.add(stage.name)\n const value = normalizeRolloutValue(stage.value)\n if (values.has(value)) throw new Error(`rollout ${plan.name} gives two stages the value ${stage.value}`)\n values.add(value)\n parseRolloutList(stage.value)\n if (!Number.isInteger(stage.minSamples) || stage.minSamples < 1) {\n throw new Error(`stage ${stage.name} needs minSamples of at least 1`)\n }\n if (!Object.keys(stage.kill).length) throw new Error(`stage ${stage.name} declares no kill lines`)\n }\n for (let index = 1; index < plan.stages.length; index++) {\n const previous = plan.stages[index - 1]!\n const stage = plan.stages[index]!\n if (!rolloutWidens(previous.value, stage.value)) {\n throw new Error(`stage ${stage.name} does not widen stage ${previous.name}`)\n }\n }\n}\n\n/**\n * Decide one change of the list. `measure` is called only for a widening, and\n * only for the stage being left.\n */\nexport async function decideRollout(input: {\n plan: RolloutPlan\n fromValue: string\n toValue: string\n measure(stage: RolloutStage): Promise<StageMeasurement | null>\n now?: () => Date\n}): Promise<RolloutDecision> {\n const { plan, fromValue, toValue } = input\n validateRolloutPlan(plan)\n const fromStage = stageOf(plan, fromValue)\n const toStage = stageOf(plan, toValue)\n const widens = rolloutWidens(fromValue, toValue)\n const record = (reasons: string[], measured: StageMeasurement | null): RolloutDecision => ({\n rollout: plan.name,\n variable: plan.variable,\n from: { value: fromValue, stage: fromStage?.name ?? null },\n to: { value: toValue, stage: toStage?.name ?? null },\n widens,\n decision: reasons.length ? 'refused' : 'allowed',\n reasons,\n measured,\n at: (input.now?.() ?? new Date()).toISOString(),\n })\n if (!widens) return record([], null)\n if (!toStage) return record([`${toValue} is not a declared stage of ${plan.name}`], null)\n const target = plan.stages.indexOf(toStage)\n // An empty list admits nobody, so the first stage is the only widening it may take without numbers.\n if (!fromStage) {\n const empty = !normalizeRolloutValue(fromValue)\n return record(empty && target === 0 ? [] : [`the current value ${fromValue || '(empty)'} is not a declared stage of ${plan.name}`], null)\n }\n const current = plan.stages.indexOf(fromStage)\n if (target > current + 1) {\n return record([`${toStage.name} skips ${plan.stages.slice(current + 1, target).map(stage => stage.name).join(', ')}`], null)\n }\n let measured: StageMeasurement | null\n try {\n measured = await input.measure(fromStage)\n } catch (error) {\n return record([`measuring stage ${fromStage.name} failed: ${error instanceof Error ? error.message : String(error)}`], null)\n }\n return record(killLineBreaches(fromStage, measured), measured)\n}\n"],"mappings":";AAuFO,SAAS,iBAAiB,OAAqD;AACpF,QAAM,MAAM,oBAAI,IAAY;AAC5B,QAAM,WAAW,oBAAI,IAAY;AACjC,QAAM,WAAqB,CAAC;AAC5B,MAAI,MAAM;AACV,aAAW,QAAQ,SAAS,IAAI,MAAM,GAAG,GAAG;AAC1C,UAAM,QAAQ,IAAI,KAAK;AACvB,QAAI,CAAC,MAAO;AACZ,QAAI,UAAU,IAAK,OAAM;AAAA,aAChB,MAAM,WAAW,GAAG,EAAG,UAAS,IAAI,MAAM,MAAM,CAAC,EAAE,KAAK,CAAC;AAAA,aACzD,MAAM,WAAW,YAAY,GAAG;AACvC,YAAM,KAAK,KAAK,MAAM,MAAM,MAAM,aAAa,MAAM,CAAC;AACtD,UAAI,CAAC,OAAO,SAAS,EAAE,EAAG,OAAM,IAAI,MAAM,sBAAsB,KAAK,sBAAsB;AAC3F,eAAS,KAAK,EAAE;AAAA,IAClB,MAAO,KAAI,IAAI,KAAK;AAAA,EACtB;AACA,SAAO,EAAE,KAAK,KAAK,UAAU,SAAS;AACxC;AAGO,SAAS,cAAc,OAAmC,WAAwD;AACvH,QAAM,OAAO,OAAO,UAAU,WAAW,iBAAiB,KAAK,IAAI;AACnE,MAAI,KAAK,SAAS,IAAI,UAAU,EAAE,EAAG,QAAO;AAC5C,MAAI,KAAK,OAAO,KAAK,IAAI,IAAI,UAAU,EAAE,EAAG,QAAO;AACnD,SAAO,UAAU,cAAc,UAAa,KAAK,SA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S;AAC9C,WAAO,OAAO,SAAS,WAAW,IAAI,CAAC,IAAI,CAAC,qBAAqB,aAAa,SAAS,+BAA+B,KAAK,IAAI,EAAE,GAAG,IAAI;AAAA,EAC1I;AACA,QAAM,UAAU,KAAK,OAAO,QAAQ,SAAS;AAC7C,MAAI,SAAS,UAAU,GAAG;AACxB,WAAO,OAAO,CAAC,GAAG,QAAQ,IAAI,UAAU,KAAK,OAAO,MAAM,UAAU,GAAG,MAAM,EAAE,IAAI,WAAS,MAAM,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE,GAAG,IAAI;AAAA,EAC7H;AACA,MAAI;AACJ,MAAI;AACF,eAAW,MAAM,MAAM,QAAQ,SAAS;AAAA,EAC1C,SAAS,OAAO;AACd,WAAO,OAAO,CAAC,mBAAmB,UAAU,IAAI,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE,GAAG,IAAI;AAAA,EAC7H;AACA,SAAO,OAAO,iBAAiB,WAAW,QAAQ,GAAG,QAAQ;AAC/D;","names":["measured"]}
@@ -2,16 +2,16 @@ import {
2
2
  ActionDialog,
3
3
  ActionDialogButton
4
4
  } from "./chunk-NTSZGBHZ.js";
5
- import {
6
- OVERLAY_SHADOW,
7
- PopoverSurface,
8
- usePopover
9
- } from "./chunk-GE7Y7ODP.js";
10
5
  import {
11
6
  UNTITLED_SESSION_LABEL,
12
7
  mergeSessionPages,
13
8
  sessionLabel
14
9
  } from "./chunk-SJWIZT7B.js";
10
+ import {
11
+ OVERLAY_SHADOW,
12
+ PopoverSurface,
13
+ usePopover
14
+ } from "./chunk-GE7Y7ODP.js";
15
15
 
16
16
  // src/web-react/session-history.tsx
17
17
  import {
@@ -745,4 +745,4 @@ export {
745
745
  formatSessionTimestamp,
746
746
  SessionHistoryPanel
747
747
  };
748
- //# sourceMappingURL=chunk-5S5ANZBS.js.map
748
+ //# sourceMappingURL=chunk-HZGKPWVA.js.map
@@ -11,4 +11,4 @@ export {
11
11
  DesignCanvasLazy,
12
12
  DesignCanvasChromeLazy
13
13
  };
14
- //# sourceMappingURL=chunk-NRG2YHGY.js.map
14
+ //# sourceMappingURL=chunk-IMTU5LCF.js.map
@@ -14,6 +14,10 @@ import {
14
14
  import {
15
15
  joinClasses
16
16
  } from "./chunk-L7MB2LLM.js";
17
+ import {
18
+ filterCommandPaletteItems,
19
+ groupCommandPaletteItems
20
+ } from "./chunk-SJWIZT7B.js";
17
21
  import {
18
22
  BrainGlyph,
19
23
  ChevronDown,
@@ -24,16 +28,12 @@ import {
24
28
  usePending,
25
29
  usePopover
26
30
  } from "./chunk-GE7Y7ODP.js";
27
- import {
28
- filterCommandPaletteItems,
29
- groupCommandPaletteItems
30
- } from "./chunk-SJWIZT7B.js";
31
31
  import {
32
32
  AsyncView
33
33
  } from "./chunk-LSUELMHY.js";
34
34
  import {
35
35
  attachmentPartsFromMessageParts
36
- } from "./chunk-GU7OZFU7.js";
36
+ } from "./chunk-VXWEJ7F2.js";
37
37
  import {
38
38
  TURN_INTENT_EVENT,
39
39
  TURN_PHASE_EVENT,
@@ -41,6 +41,10 @@ import {
41
41
  isTurnPhaseEvent,
42
42
  settleTurnResponse
43
43
  } from "./chunk-2NHJNINW.js";
44
+ import {
45
+ parsePlanSubmittedEvent,
46
+ persistedPartToPlan
47
+ } from "./chunk-LQYIBL3G.js";
44
48
  import {
45
49
  cancelStatusFor,
46
50
  fieldAcceptsFreeText,
@@ -51,10 +55,6 @@ import {
51
55
  persistedPartToInteraction,
52
56
  questionInteractionContentSignature
53
57
  } from "./chunk-6VQCFJWP.js";
54
- import {
55
- parsePlanSubmittedEvent,
56
- persistedPartToPlan
57
- } from "./chunk-LQYIBL3G.js";
58
58
 
59
59
  // src/web-react/index.tsx
60
60
  import { useEffect as useEffect14, useMemo as useMemo7, useRef as useRef12, useState as useState19, memo } from "react";
@@ -6804,4 +6804,4 @@ export {
6804
6804
  useThinkingSeconds,
6805
6805
  ChatMessages
6806
6806
  };
6807
- //# sourceMappingURL=chunk-XPP653RG.js.map
6807
+ //# sourceMappingURL=chunk-JEM4BKR4.js.map
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  joinClasses
3
3
  } from "./chunk-L7MB2LLM.js";
4
+ import {
5
+ filterCommandPaletteItems
6
+ } from "./chunk-SJWIZT7B.js";
4
7
  import {
5
8
  AgentSessionControls,
6
9
  acceptRejectionReason,
@@ -13,9 +16,6 @@ import {
13
16
  POPOVER_OPTION_FOCUS,
14
17
  PopoverSurface
15
18
  } from "./chunk-GE7Y7ODP.js";
16
- import {
17
- filterCommandPaletteItems
18
- } from "./chunk-SJWIZT7B.js";
19
19
  import {
20
20
  ATTACHMENT_ACCEPT,
21
21
  ATTACHMENT_MAX_COUNT,
@@ -1552,4 +1552,4 @@ export {
1552
1552
  ComposerModeControls,
1553
1553
  EntryComposer
1554
1554
  };
1555
- //# sourceMappingURL=chunk-4DEI6QC5.js.map
1555
+ //# sourceMappingURL=chunk-NNNAC3DV.js.map
@@ -4,13 +4,13 @@ import {
4
4
  import {
5
5
  mentionKindForPath
6
6
  } from "./chunk-2NHJNINW.js";
7
- import {
8
- persistedPartToInteraction
9
- } from "./chunk-6VQCFJWP.js";
10
7
  import {
11
8
  persistedPartToPlan,
12
9
  planToPersistedPart
13
10
  } from "./chunk-LQYIBL3G.js";
11
+ import {
12
+ persistedPartToInteraction
13
+ } from "./chunk-6VQCFJWP.js";
14
14
 
15
15
  // src/chat-store/parts.ts
16
16
  function toChatMessageParts(parts) {
@@ -135,4 +135,4 @@ export {
135
135
  buildAttachmentPromptBlock,
136
136
  historyContentWithAttachments
137
137
  };
138
- //# sourceMappingURL=chunk-GU7OZFU7.js.map
138
+ //# sourceMappingURL=chunk-VXWEJ7F2.js.map
@@ -1,13 +1,13 @@
1
- import {
2
- canTransitionInteractionStatus,
3
- persistedPartToInteraction
4
- } from "./chunk-6VQCFJWP.js";
5
1
  import {
6
2
  canTransitionPlanStatus,
7
3
  persistedPartToPlan,
8
4
  planPartKey,
9
5
  planToPersistedPart
10
6
  } from "./chunk-LQYIBL3G.js";
7
+ import {
8
+ canTransitionInteractionStatus,
9
+ persistedPartToInteraction
10
+ } from "./chunk-6VQCFJWP.js";
11
11
 
12
12
  // src/stream/stream-normalizer.ts
13
13
  function asRecord(value) {
@@ -406,4 +406,4 @@ export {
406
406
  terminalizeDanglingAssistantToolUpdates,
407
407
  encodeEvent
408
408
  };
409
- //# sourceMappingURL=chunk-ZGUXI5SI.js.map
409
+ //# sourceMappingURL=chunk-XNKLQG26.js.map
@@ -84,15 +84,15 @@ import {
84
84
  setPagePropsCommand,
85
85
  ungroupElementCommand
86
86
  } from "../chunk-6NYVAURR.js";
87
+ import {
88
+ DesignCanvasChromeLazy,
89
+ DesignCanvasLazy
90
+ } from "../chunk-IMTU5LCF.js";
87
91
  import {
88
92
  assertSceneMediaSrc,
89
93
  bleedAwareExportBounds,
90
94
  scaleForPreset
91
95
  } from "../chunk-OHWQUKBP.js";
92
- import {
93
- DesignCanvasChromeLazy,
94
- DesignCanvasLazy
95
- } from "../chunk-NRG2YHGY.js";
96
96
  import "../chunk-UTAIRVOK.js";
97
97
  import "../chunk-RN4WPTBH.js";
98
98
  import "../chunk-3NCPXNBZ.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DesignCanvasChromeLazy,
3
3
  DesignCanvasLazy
4
- } from "../chunk-NRG2YHGY.js";
4
+ } from "../chunk-IMTU5LCF.js";
5
5
  export {
6
6
  DesignCanvasChromeLazy,
7
7
  DesignCanvasLazy
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  createChatTurnRoutes,
3
3
  streamChatRouteAsSandboxEvents
4
- } from "../chunk-JZUSVGRJ.js";
5
- import "../chunk-Q7WEEN7P.js";
4
+ } from "../chunk-2GP6JOWE.js";
6
5
  import "../chunk-UTAIRVOK.js";
7
6
  import "../chunk-RN4WPTBH.js";
7
+ import "../chunk-Q7WEEN7P.js";
8
8
  import "../chunk-3NCPXNBZ.js";
9
- import "../chunk-GU7OZFU7.js";
9
+ import "../chunk-VXWEJ7F2.js";
10
10
  import "../chunk-ZVEEWGDK.js";
11
11
  import "../chunk-2NHJNINW.js";
12
12
  import "../chunk-TXD5HXLE.js";
13
13
  import "../chunk-Z4RD5UF7.js";
14
14
  import "../chunk-YG66IHDU.js";
15
15
  import "../chunk-ISP6ZH3G.js";
16
- import "../chunk-ZGUXI5SI.js";
17
- import "../chunk-6VQCFJWP.js";
16
+ import "../chunk-XNKLQG26.js";
18
17
  import "../chunk-LQYIBL3G.js";
18
+ import "../chunk-6VQCFJWP.js";
19
19
 
20
20
  // src/public-consultation/index.ts
21
21
  import { searchKnowledge } from "@tangle-network/agent-knowledge";
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ import { type RolloutDecision, type RolloutPlan, type RolloutStage, type StageMeasurement } from './index.js';
3
+ export interface RolloutConfig {
4
+ plans: RolloutPlan[];
5
+ measure(input: {
6
+ plan: RolloutPlan;
7
+ stage: RolloutStage;
8
+ }): Promise<StageMeasurement | null>;
9
+ record?(decision: RolloutDecision): Promise<void> | void;
10
+ /** Default `wrangler.toml`. */
11
+ wrangler?: string;
12
+ }
13
+ interface CliArgs {
14
+ appDir: string;
15
+ config?: string;
16
+ base: string;
17
+ from?: string;
18
+ to?: string;
19
+ plan?: string;
20
+ record: string;
21
+ }
22
+ /** A top-level `[vars]` string value from wrangler.toml source; environments are not read. */
23
+ export declare function readWranglerVar(source: string, name: string): string | null;
24
+ export declare function runRolloutCheck(args: CliArgs): Promise<RolloutDecision[]>;
25
+ export {};
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ decideRollout
4
+ } from "../chunk-4JUEOVQS.js";
5
+ import {
6
+ invokedAsScript
7
+ } from "../chunk-C3CAYGGQ.js";
8
+
9
+ // src/rollout/cli.ts
10
+ import { execFileSync } from "child_process";
11
+ import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
12
+ import { dirname, join, resolve } from "path";
13
+ import { pathToFileURL } from "url";
14
+ var CONFIG_NAMES = ["rollout.config.mjs", "rollout.config.js"];
15
+ function parseArgs(argv) {
16
+ const args = { appDir: process.cwd(), base: "origin/main", record: ".rollout/decisions.jsonl" };
17
+ for (let index = 0; index < argv.length; index += 1) {
18
+ const arg = argv[index];
19
+ const value = () => {
20
+ const next = argv[++index];
21
+ if (next === void 0) throw new Error(`${arg} needs a value`);
22
+ return next;
23
+ };
24
+ if (arg === "--config") args.config = value();
25
+ else if (arg === "--base") args.base = value();
26
+ else if (arg === "--from") args.from = value();
27
+ else if (arg === "--to") args.to = value();
28
+ else if (arg === "--plan") args.plan = value();
29
+ else if (arg === "--record") args.record = value();
30
+ else if (arg.startsWith("--")) throw new Error(`unknown option ${arg}`);
31
+ else args.appDir = resolve(arg);
32
+ }
33
+ return args;
34
+ }
35
+ function readWranglerVar(source, name) {
36
+ let inVars = false;
37
+ for (const line of source.split("\n")) {
38
+ const header = line.match(/^\s*\[([^\]]+)\]\s*(?:#.*)?$/);
39
+ if (header) {
40
+ inVars = header[1].trim() === "vars";
41
+ continue;
42
+ }
43
+ if (!inVars) continue;
44
+ const entry = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*"((?:[^"\\]|\\.)*)"/);
45
+ if (entry && entry[1] === name) return JSON.parse(`"${entry[2]}"`);
46
+ }
47
+ return null;
48
+ }
49
+ async function loadConfig(appDir, explicit) {
50
+ const file = explicit ? resolve(appDir, explicit) : CONFIG_NAMES.map((name) => join(appDir, name)).find((path) => existsSync(path));
51
+ if (!file || !existsSync(file)) throw new Error(`no ${CONFIG_NAMES[0]} in ${appDir}`);
52
+ const config = (await import(pathToFileURL(file).href)).default;
53
+ if (!Array.isArray(config?.plans) || typeof config.measure !== "function") {
54
+ throw new Error(`${file} must export { plans, measure }`);
55
+ }
56
+ return config;
57
+ }
58
+ function wranglerAt(appDir, file, ref) {
59
+ try {
60
+ return execFileSync("git", ["show", `${ref}:${file}`], { cwd: appDir, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
61
+ } catch {
62
+ throw new Error(`cannot read ${file} at ${ref}; fetch it or pass --from`);
63
+ }
64
+ }
65
+ async function runRolloutCheck(args) {
66
+ const config = await loadConfig(args.appDir, args.config);
67
+ const file = config.wrangler ?? "wrangler.toml";
68
+ const plans = args.plan ? config.plans.filter((plan) => plan.name === args.plan) : config.plans;
69
+ if (!plans.length) throw new Error(args.plan ? `no plan named ${args.plan}` : "the config declares no plans");
70
+ if (plans.length > 1 && (args.from !== void 0 || args.to !== void 0)) throw new Error("--from and --to need --plan");
71
+ const head = readFileSync(join(args.appDir, file), "utf8");
72
+ const base = args.from === void 0 ? wranglerAt(args.appDir, file, args.base) : null;
73
+ const decisions = [];
74
+ for (const plan of plans) {
75
+ const fromValue = args.from ?? readWranglerVar(base, plan.variable) ?? "";
76
+ const toValue = args.to ?? readWranglerVar(head, plan.variable) ?? "";
77
+ const decision = await decideRollout({ plan, fromValue, toValue, measure: (stage) => config.measure({ plan, stage }) });
78
+ decisions.push(decision);
79
+ const ledger = resolve(args.appDir, args.record);
80
+ mkdirSync(dirname(ledger), { recursive: true });
81
+ appendFileSync(ledger, `${JSON.stringify(decision)}
82
+ `);
83
+ await config.record?.(decision);
84
+ }
85
+ return decisions;
86
+ }
87
+ function describe(decision) {
88
+ const move = `${decision.from.stage ?? decision.from.value ?? "(empty)"} -> ${decision.to.stage ?? decision.to.value}`;
89
+ if (decision.decision === "allowed") {
90
+ return `rollout ${decision.rollout}: allowed ${move}${decision.widens ? "" : " (not a widening)"}`;
91
+ }
92
+ return `rollout ${decision.rollout}: REFUSED ${move}
93
+ ${decision.reasons.map((reason) => ` - ${reason}`).join("\n")}`;
94
+ }
95
+ async function main() {
96
+ let args;
97
+ try {
98
+ args = parseArgs(process.argv.slice(2));
99
+ } catch (error) {
100
+ console.error(error instanceof Error ? error.message : String(error));
101
+ return 2;
102
+ }
103
+ try {
104
+ const decisions = await runRolloutCheck(args);
105
+ for (const decision of decisions) console.log(describe(decision));
106
+ return decisions.some((decision) => decision.decision === "refused") ? 1 : 0;
107
+ } catch (error) {
108
+ console.error(`agent-app-rollout-check: ${error instanceof Error ? error.message : String(error)}`);
109
+ return 2;
110
+ }
111
+ }
112
+ if (invokedAsScript(import.meta.url, process.argv[1])) {
113
+ main().then((code) => {
114
+ process.exitCode = code;
115
+ });
116
+ }
117
+ export {
118
+ readWranglerVar,
119
+ runRolloutCheck
120
+ };
121
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/rollout/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * `agent-app-rollout-check` — refuse a deploy that widens a staged rollout\n * before the stage it leaves met its kill lines.\n *\n * Runs in the app's repo, in the step that ships (ship.sh verify, or the PR\n * check). Add `rollout.config.mjs` at the root:\n *\n * export default {\n * plans: [{\n * name: 'hospitality-routed-chat',\n * variable: 'HOSPITALITY_ROUTED_BUSINESS_IDS',\n * stages: [\n * { name: 'qa', value: 'ws-a,ws-b', minSamples: 30,\n * kill: { first_words_p50_ms: { max: 2500 }, failure_rate: { max: 0 } } },\n * { name: 'all', value: '*', minSamples: 200,\n * kill: { first_words_p50_ms: { max: 1500 }, failure_rate: { max: 0.01 } } },\n * ],\n * }],\n * // The product's own instrument: production numbers for the stage being left.\n * async measure({ plan, stage }) { return { stage: stage.name, samples, metrics: { … }, source } },\n * // Optional: keep the decision somewhere durable as well as the JSONL ledger.\n * async record(decision) {},\n * }\n *\n * The new value is read from the `[vars]` of wrangler.toml; the current one\n * from the same file at `--base` (default `origin/main`), or given with\n * `--from`. `--to` overrides the new value.\n *\n * Usage: agent-app-rollout-check [appDir] [--config <file>] [--base <git ref>]\n * [--from <value>] [--to <value>] [--plan <name>] [--record <jsonl>]\n * Exits 0 when every plan's change is allowed, 1 when one is refused, 2 on a usage error.\n */\nimport { execFileSync } from 'node:child_process'\nimport { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { invokedAsScript } from '../signoff/invoked-as-script.js'\nimport { decideRollout, type RolloutDecision, type RolloutPlan, type RolloutStage, type StageMeasurement } from './index.js'\n\nexport interface RolloutConfig {\n plans: RolloutPlan[]\n measure(input: { plan: RolloutPlan; stage: RolloutStage }): Promise<StageMeasurement | null>\n record?(decision: RolloutDecision): Promise<void> | void\n /** Default `wrangler.toml`. */\n wrangler?: string\n}\n\ninterface CliArgs {\n appDir: string\n config?: string\n base: string\n from?: string\n to?: string\n plan?: string\n record: string\n}\n\nconst CONFIG_NAMES = ['rollout.config.mjs', 'rollout.config.js']\n\nfunction parseArgs(argv: readonly string[]): CliArgs {\n const args: CliArgs = { appDir: process.cwd(), base: 'origin/main', record: '.rollout/decisions.jsonl' }\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index]!\n const value = () => {\n const next = argv[++index]\n if (next === undefined) throw new Error(`${arg} needs a value`)\n return next\n }\n if (arg === '--config') args.config = value()\n else if (arg === '--base') args.base = value()\n else if (arg === '--from') args.from = value()\n else if (arg === '--to') args.to = value()\n else if (arg === '--plan') args.plan = value()\n else if (arg === '--record') args.record = value()\n else if (arg.startsWith('--')) throw new Error(`unknown option ${arg}`)\n else args.appDir = resolve(arg)\n }\n return args\n}\n\n/** A top-level `[vars]` string value from wrangler.toml source; environments are not read. */\nexport function readWranglerVar(source: string, name: string): string | null {\n let inVars = false\n for (const line of source.split('\\n')) {\n const header = line.match(/^\\s*\\[([^\\]]+)\\]\\s*(?:#.*)?$/)\n if (header) {\n inVars = header[1]!.trim() === 'vars'\n continue\n }\n if (!inVars) continue\n const entry = line.match(/^\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*=\\s*\"((?:[^\"\\\\]|\\\\.)*)\"/)\n if (entry && entry[1] === name) return JSON.parse(`\"${entry[2]}\"`) as string\n }\n return null\n}\n\nasync function loadConfig(appDir: string, explicit?: string): Promise<RolloutConfig> {\n const file = explicit ? resolve(appDir, explicit) : CONFIG_NAMES.map(name => join(appDir, name)).find(path => existsSync(path))\n if (!file || !existsSync(file)) throw new Error(`no ${CONFIG_NAMES[0]} in ${appDir}`)\n const config = ((await import(pathToFileURL(file).href)) as { default: RolloutConfig }).default\n if (!Array.isArray(config?.plans) || typeof config.measure !== 'function') {\n throw new Error(`${file} must export { plans, measure }`)\n }\n return config\n}\n\nfunction wranglerAt(appDir: string, file: string, ref: string): string {\n try {\n return execFileSync('git', ['show', `${ref}:${file}`], { cwd: appDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })\n } catch {\n throw new Error(`cannot read ${file} at ${ref}; fetch it or pass --from`)\n }\n}\n\nexport async function runRolloutCheck(args: CliArgs): Promise<RolloutDecision[]> {\n const config = await loadConfig(args.appDir, args.config)\n const file = config.wrangler ?? 'wrangler.toml'\n const plans = args.plan ? config.plans.filter(plan => plan.name === args.plan) : config.plans\n if (!plans.length) throw new Error(args.plan ? `no plan named ${args.plan}` : 'the config declares no plans')\n if (plans.length > 1 && (args.from !== undefined || args.to !== undefined)) throw new Error('--from and --to need --plan')\n const head = readFileSync(join(args.appDir, file), 'utf8')\n const base = args.from === undefined ? wranglerAt(args.appDir, file, args.base) : null\n const decisions: RolloutDecision[] = []\n for (const plan of plans) {\n const fromValue = args.from ?? readWranglerVar(base!, plan.variable) ?? ''\n const toValue = args.to ?? readWranglerVar(head, plan.variable) ?? ''\n const decision = await decideRollout({ plan, fromValue, toValue, measure: stage => config.measure({ plan, stage }) })\n decisions.push(decision)\n const ledger = resolve(args.appDir, args.record)\n mkdirSync(dirname(ledger), { recursive: true })\n appendFileSync(ledger, `${JSON.stringify(decision)}\\n`)\n await config.record?.(decision)\n }\n return decisions\n}\n\nfunction describe(decision: RolloutDecision): string {\n const move = `${decision.from.stage ?? decision.from.value ?? '(empty)'} -> ${decision.to.stage ?? decision.to.value}`\n if (decision.decision === 'allowed') {\n return `rollout ${decision.rollout}: allowed ${move}${decision.widens ? '' : ' (not a widening)'}`\n }\n return `rollout ${decision.rollout}: REFUSED ${move}\\n${decision.reasons.map(reason => ` - ${reason}`).join('\\n')}`\n}\n\nasync function main(): Promise<number> {\n let args: CliArgs\n try {\n args = parseArgs(process.argv.slice(2))\n } catch (error) {\n console.error(error instanceof Error ? error.message : String(error))\n return 2\n }\n try {\n const decisions = await runRolloutCheck(args)\n for (const decision of decisions) console.log(describe(decision))\n return decisions.some(decision => decision.decision === 'refused') ? 1 : 0\n } catch (error) {\n console.error(`agent-app-rollout-check: ${error instanceof Error ? error.message : String(error)}`)\n return 2\n }\n}\n\nif (invokedAsScript(import.meta.url, process.argv[1])) {\n main().then(code => { process.exitCode = code })\n}\n"],"mappings":";;;;;;;;;AAiCA,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB,YAAY,WAAW,oBAAoB;AACpE,SAAS,SAAS,MAAM,eAAe;AACvC,SAAS,qBAAqB;AAsB9B,IAAM,eAAe,CAAC,sBAAsB,mBAAmB;AAE/D,SAAS,UAAU,MAAkC;AACnD,QAAM,OAAgB,EAAE,QAAQ,QAAQ,IAAI,GAAG,MAAM,eAAe,QAAQ,2BAA2B;AACvG,WAAS,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAAG;AACnD,UAAM,MAAM,KAAK,KAAK;AACtB,UAAM,QAAQ,MAAM;AAClB,YAAM,OAAO,KAAK,EAAE,KAAK;AACzB,UAAI,SAAS,OAAW,OAAM,IAAI,MAAM,GAAG,GAAG,gBAAgB;AAC9D,aAAO;AAAA,IACT;AACA,QAAI,QAAQ,WAAY,MAAK,SAAS,MAAM;AAAA,aACnC,QAAQ,SAAU,MAAK,OAAO,MAAM;AAAA,aACpC,QAAQ,SAAU,MAAK,OAAO,MAAM;AAAA,aACpC,QAAQ,OAAQ,MAAK,KAAK,MAAM;AAAA,aAChC,QAAQ,SAAU,MAAK,OAAO,MAAM;AAAA,aACpC,QAAQ,WAAY,MAAK,SAAS,MAAM;AAAA,aACxC,IAAI,WAAW,IAAI,EAAG,OAAM,IAAI,MAAM,kBA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,KAAK;AACpH,MAAI,SAAS,aAAa,WAAW;AACnC,WAAO,WAAW,SAAS,OAAO,aAAa,IAAI,GAAG,SAAS,SAAS,KAAK,mBAAmB;AAAA,EAClG;AACA,SAAO,WAAW,SAAS,OAAO,aAAa,IAAI;AAAA,EAAK,SAAS,QAAQ,IAAI,YAAU,OAAO,MAAM,EAAE,EAAE,KAAK,IAAI,CAAC;AACpH;AAEA,eAAe,OAAwB;AACrC,MAAI;AACJ,MAAI;AACF,WAAO,UAAU,QAAQ,KAAK,MAAM,CAAC,CAAC;AAAA,EACxC,SAAS,OAAO;AACd,YAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AACpE,WAAO;AAAA,EACT;AACA,MAAI;AACF,UAAM,YAAY,MAAM,gBAAgB,IAAI;AAC5C,eAAW,YAAY,UAAW,SAAQ,IAAI,SAAS,QAAQ,CAAC;AAChE,WAAO,UAAU,KAAK,cAAY,SAAS,aAAa,SAAS,IAAI,IAAI;AAAA,EAC3E,SAAS,OAAO;AACd,YAAQ,MAAM,4BAA4B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAClG,WAAO;AAAA,EACT;AACF;AAEA,IAAI,gBAAgB,YAAY,KAAK,QAAQ,KAAK,CAAC,CAAC,GAAG;AACrD,OAAK,EAAE,KAAK,UAAQ;AAAE,YAAQ,WAAW;AAAA,EAAK,CAAC;AACjD;","names":[]}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The measurement a rollout guard reads: one row per turn with its lane, its
3
+ * first visible word and whether it failed, and the stage numbers computed
4
+ * from those rows.
5
+ *
6
+ * Record from the chat route's lifecycle (`onTurnComplete` / `onTurnError`
7
+ * carry `firstTextMs` and `durationMs`), then serve `measureStage` behind an
8
+ * operator endpoint that the deploy's `rollout.config.mjs` calls. A stage is
9
+ * measured on the turns of the workspaces it admits, in the lane being rolled
10
+ * out, since the time it went live.
11
+ */
12
+ import { type RolloutStage, type StageMeasurement } from './index';
13
+ /** Minimal D1 surface (Cloudflare's `D1Database` satisfies it). */
14
+ export interface D1LikeForRollout {
15
+ prepare(sql: string): {
16
+ bind(...values: unknown[]): {
17
+ run(): Promise<unknown>;
18
+ all<T = Record<string, unknown>>(): Promise<{
19
+ results?: T[];
20
+ }>;
21
+ };
22
+ };
23
+ }
24
+ export declare const ROLLOUT_TURN_TIMING_SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS rollout_turn_timing (\n turn_id TEXT PRIMARY KEY,\n rollout TEXT NOT NULL,\n workspace_id TEXT NOT NULL,\n lane TEXT NOT NULL,\n first_text_ms INTEGER,\n settled_ms INTEGER NOT NULL,\n failed INTEGER NOT NULL CHECK (failed IN (0, 1)),\n failure_code TEXT,\n at INTEGER NOT NULL\n);\nCREATE INDEX IF NOT EXISTS rollout_turn_timing_by_lane ON rollout_turn_timing (rollout, lane, at);\n";
25
+ export interface TurnTimingRow {
26
+ turnId: string;
27
+ /** The plan this turn counts toward, e.g. `hospitality-routed-chat`. */
28
+ rollout: string;
29
+ workspaceId: string;
30
+ /** The lane that served the turn, e.g. `routed` or `sandbox`. Only the rolled-out lane is measured. */
31
+ lane: string;
32
+ /** From the lifecycle's `firstTextMs`; absent when no word streamed. */
33
+ firstTextMs?: number;
34
+ settledMs: number;
35
+ failed: boolean;
36
+ failureCode?: string;
37
+ /** Epoch ms; defaults to now. */
38
+ at?: number;
39
+ }
40
+ /** Stage metrics from turn rows: first-words and settled percentiles in ms, and the failure rate. */
41
+ export declare function stageMetrics(rows: ReadonlyArray<Pick<TurnTimingRow, 'firstTextMs' | 'settledMs' | 'failed'>>): {
42
+ first_words_p50_ms: number | null;
43
+ first_words_p90_ms: number | null;
44
+ settled_p50_ms: number | null;
45
+ settled_p90_ms: number | null;
46
+ failure_rate: number | null;
47
+ };
48
+ export declare function createD1TurnTimingStore(options: {
49
+ db: D1LikeForRollout;
50
+ now?: () => number;
51
+ }): {
52
+ /** Record one settled turn. Idempotent on `turnId`. Never throws: telemetry must not fail a turn. */
53
+ record(row: TurnTimingRow): Promise<void>;
54
+ /** The stage's numbers: its admitted workspaces' turns in `lane` since `since` (epoch ms). A row carries no
55
+ * workspace creation time, so a workspace admitted only by a `new-since:` entry is not counted. */
56
+ measureStage(input: {
57
+ rollout: string;
58
+ stage: RolloutStage;
59
+ lane: string;
60
+ since: number;
61
+ }): Promise<StageMeasurement>;
62
+ };