@warmdrift/kgauto-compiler 2.0.0-alpha.7 → 2.0.0-alpha.71

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 (55) hide show
  1. package/README.md +176 -46
  2. package/dist/brain-proxy.d.mts +113 -0
  3. package/dist/brain-proxy.d.ts +113 -0
  4. package/dist/brain-proxy.js +193 -0
  5. package/dist/brain-proxy.mjs +6 -0
  6. package/dist/chunk-4UO4CCSP.mjs +1620 -0
  7. package/dist/chunk-65ZMX5OT.mjs +169 -0
  8. package/dist/{chunk-5TI6PNSK.mjs → chunk-BVEXV5KC.mjs} +11 -0
  9. package/dist/chunk-NBO4R5PC.mjs +313 -0
  10. package/dist/chunk-P3TOAEG4.mjs +56 -0
  11. package/dist/chunk-RO22VFIF.mjs +29 -0
  12. package/dist/chunk-SBFSYCQG.mjs +719 -0
  13. package/dist/chunk-URFQR3SB.mjs +203 -0
  14. package/dist/dialect.d.mts +41 -3
  15. package/dist/dialect.d.ts +41 -3
  16. package/dist/dialect.js +14 -2
  17. package/dist/dialect.mjs +5 -3
  18. package/dist/glassbox/index.d.mts +59 -0
  19. package/dist/glassbox/index.d.ts +59 -0
  20. package/dist/glassbox/index.js +312 -0
  21. package/dist/glassbox/index.mjs +12 -0
  22. package/dist/glassbox-routes/format.d.mts +24 -0
  23. package/dist/glassbox-routes/format.d.ts +24 -0
  24. package/dist/glassbox-routes/format.js +86 -0
  25. package/dist/glassbox-routes/format.mjs +18 -0
  26. package/dist/glassbox-routes/index.d.mts +191 -0
  27. package/dist/glassbox-routes/index.d.ts +191 -0
  28. package/dist/glassbox-routes/index.js +2888 -0
  29. package/dist/glassbox-routes/index.mjs +667 -0
  30. package/dist/glassbox-routes/react/index.d.mts +74 -0
  31. package/dist/glassbox-routes/react/index.d.ts +74 -0
  32. package/dist/glassbox-routes/react/index.js +819 -0
  33. package/dist/glassbox-routes/react/index.mjs +754 -0
  34. package/dist/index.d.mts +2745 -17
  35. package/dist/index.d.ts +2745 -17
  36. package/dist/index.js +9006 -1651
  37. package/dist/index.mjs +5103 -367
  38. package/dist/ir-BEQ28muo.d.ts +1608 -0
  39. package/dist/ir-CnnJST_N.d.mts +1608 -0
  40. package/dist/key-health.d.mts +131 -0
  41. package/dist/key-health.d.ts +131 -0
  42. package/dist/key-health.js +228 -0
  43. package/dist/key-health.mjs +6 -0
  44. package/dist/profiles.d.mts +292 -2
  45. package/dist/profiles.d.ts +292 -2
  46. package/dist/profiles.js +1231 -16
  47. package/dist/profiles.mjs +9 -1
  48. package/dist/types-B--CYzMo.d.ts +131 -0
  49. package/dist/types-BDFrJkma.d.mts +131 -0
  50. package/dist/types-DSeJJ6tt.d.ts +149 -0
  51. package/dist/types-DeGRCTlJ.d.mts +149 -0
  52. package/package.json +54 -8
  53. package/dist/chunk-MBEI5UOM.mjs +0 -409
  54. package/dist/profiles-B3eNQ2py.d.ts +0 -619
  55. package/dist/profiles-Py8c7zjJ.d.mts +0 -619
@@ -0,0 +1,203 @@
1
+ // src/version.ts
2
+ var LIBRARY_VERSION = "2.0.0-alpha.71";
3
+
4
+ // src/key-health.ts
5
+ var JSON_HEADERS = { "Content-Type": "application/json" };
6
+ function jsonResponse(status, body) {
7
+ return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS });
8
+ }
9
+ function bearerOf(req) {
10
+ const header = req.headers.get("Authorization") ?? "";
11
+ const match = /^Bearer\s+(.+)$/i.exec(header);
12
+ return match?.[1]?.trim() ?? "";
13
+ }
14
+ function requireString(name, value) {
15
+ if (typeof value !== "string" || value.length === 0) {
16
+ throw new Error(`createKeyHealthRoute: ${name} is required`);
17
+ }
18
+ return value;
19
+ }
20
+ function envKey(env, name) {
21
+ const v = env[name];
22
+ if (typeof v !== "string") return void 0;
23
+ const trimmed = v.trim();
24
+ return trimmed.length > 0 ? trimmed : void 0;
25
+ }
26
+ var PROBE_SPECS = [
27
+ {
28
+ provider: "anthropic",
29
+ canonicalEnvName: "ANTHROPIC_API_KEY",
30
+ buildRequest: (key) => ({
31
+ url: "https://api.anthropic.com/v1/models?limit=1",
32
+ headers: { "x-api-key": key, "anthropic-version": "2023-06-01" }
33
+ })
34
+ },
35
+ {
36
+ provider: "deepseek",
37
+ canonicalEnvName: "DEEPSEEK_API_KEY",
38
+ buildRequest: (key) => ({
39
+ url: "https://api.deepseek.com/user/balance",
40
+ headers: { Authorization: `Bearer ${key}` }
41
+ }),
42
+ parseBalanceUsd: (body) => {
43
+ const infos = body?.balance_infos;
44
+ if (!Array.isArray(infos) || infos.length === 0) return void 0;
45
+ const first = infos[0];
46
+ if (first?.currency !== "USD") return void 0;
47
+ const n = Number(first.total_balance);
48
+ return Number.isFinite(n) ? n : void 0;
49
+ }
50
+ },
51
+ {
52
+ provider: "moonshot",
53
+ canonicalEnvName: "MOONSHOT_API_KEY",
54
+ buildRequest: (key) => ({
55
+ url: "https://api.moonshot.ai/v1/models",
56
+ headers: { Authorization: `Bearer ${key}` }
57
+ })
58
+ },
59
+ {
60
+ provider: "google",
61
+ canonicalEnvName: "GEMINI_API_KEY",
62
+ buildRequest: (key) => ({
63
+ url: `https://generativelanguage.googleapis.com/v1beta/models?pageSize=1&key=${encodeURIComponent(key)}`,
64
+ headers: {}
65
+ })
66
+ },
67
+ {
68
+ provider: "openai",
69
+ canonicalEnvName: "OPENAI_API_KEY",
70
+ buildRequest: (key) => ({
71
+ url: "https://api.openai.com/v1/models",
72
+ headers: { Authorization: `Bearer ${key}` }
73
+ })
74
+ }
75
+ ];
76
+ function createKeyHealthRoute(config) {
77
+ const appId = requireString("appId", config.appId);
78
+ const ingestSecret = requireString("ingestSecret", config.ingestSecret);
79
+ const fetchFn = config.fetchImpl ?? fetch;
80
+ const timeoutMs = config.timeoutMs ?? 3e3;
81
+ async function probeProvider(spec, env) {
82
+ let key;
83
+ let envName = spec.canonicalEnvName;
84
+ if (spec.provider === "google") {
85
+ const gemini = envKey(env, "GEMINI_API_KEY");
86
+ const google = envKey(env, "GOOGLE_API_KEY");
87
+ const aiSdk = envKey(env, "GOOGLE_GENERATIVE_AI_API_KEY");
88
+ key = gemini ?? google ?? aiSdk;
89
+ envName = gemini ? "GEMINI_API_KEY" : google ? "GOOGLE_API_KEY" : aiSdk ? "GOOGLE_GENERATIVE_AI_API_KEY" : "GEMINI_API_KEY";
90
+ } else if (spec.provider === "moonshot") {
91
+ const moonshot = envKey(env, "MOONSHOT_API_KEY");
92
+ const kimi = envKey(env, "KIMI_API_KEY");
93
+ key = moonshot ?? kimi;
94
+ envName = moonshot ? "MOONSHOT_API_KEY" : kimi ? "KIMI_API_KEY" : "MOONSHOT_API_KEY";
95
+ } else {
96
+ key = envKey(env, spec.canonicalEnvName);
97
+ }
98
+ if (!key) {
99
+ return {
100
+ provider: spec.provider,
101
+ env: envName,
102
+ present: false,
103
+ valid: null,
104
+ detail: "key_absent"
105
+ };
106
+ }
107
+ const base = {
108
+ provider: spec.provider,
109
+ env: envName,
110
+ present: true,
111
+ valid: null
112
+ };
113
+ const { url, headers } = spec.buildRequest(key);
114
+ const started = Date.now();
115
+ let res;
116
+ try {
117
+ res = await fetchFn(url, {
118
+ method: "GET",
119
+ headers,
120
+ signal: AbortSignal.timeout(timeoutMs)
121
+ });
122
+ } catch (err) {
123
+ const isTimeout = err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError");
124
+ return {
125
+ ...base,
126
+ latency_ms: Date.now() - started,
127
+ // NEVER echo err.message — provider errors could theoretically carry
128
+ // request context; a fixed vocabulary keeps key material impossible.
129
+ detail: isTimeout ? "timeout" : "network_error"
130
+ };
131
+ }
132
+ const latencyMs = Date.now() - started;
133
+ if (res.ok) {
134
+ const result = {
135
+ ...base,
136
+ valid: true,
137
+ status: res.status,
138
+ latency_ms: latencyMs
139
+ };
140
+ if (spec.parseBalanceUsd) {
141
+ try {
142
+ const body = await res.json();
143
+ const balance = spec.parseBalanceUsd(body);
144
+ if (balance !== void 0) result.balance_usd = balance;
145
+ } catch {
146
+ }
147
+ }
148
+ return result;
149
+ }
150
+ if (res.status === 401 || res.status === 403) {
151
+ return { ...base, valid: false, status: res.status, latency_ms: latencyMs };
152
+ }
153
+ return {
154
+ ...base,
155
+ valid: null,
156
+ status: res.status,
157
+ latency_ms: latencyMs,
158
+ detail: `http_${res.status}`
159
+ };
160
+ }
161
+ async function handle(req) {
162
+ try {
163
+ if (req.method !== "GET") {
164
+ return jsonResponse(405, { error: "method_not_allowed" });
165
+ }
166
+ if (bearerOf(req) !== ingestSecret) {
167
+ return jsonResponse(401, { error: "unauthorized" });
168
+ }
169
+ const env = config.env ?? process.env;
170
+ const settled = await Promise.allSettled(
171
+ PROBE_SPECS.map((spec) => probeProvider(spec, env))
172
+ );
173
+ const keys = settled.map((s, i) => {
174
+ if (s.status === "fulfilled") return s.value;
175
+ const spec = PROBE_SPECS[i];
176
+ return {
177
+ provider: spec.provider,
178
+ env: spec.canonicalEnvName,
179
+ present: true,
180
+ valid: null,
181
+ detail: "probe_failed"
182
+ };
183
+ });
184
+ keys.sort((a, b) => a.provider.localeCompare(b.provider));
185
+ const body = {
186
+ app_id: appId,
187
+ checked_at: (/* @__PURE__ */ new Date()).toISOString(),
188
+ library_version: LIBRARY_VERSION,
189
+ keys
190
+ };
191
+ return jsonResponse(200, body);
192
+ } catch (err) {
193
+ void err;
194
+ return jsonResponse(500, { error: "key_health_internal_error" });
195
+ }
196
+ }
197
+ return { handle };
198
+ }
199
+
200
+ export {
201
+ LIBRARY_VERSION,
202
+ createKeyHealthRoute
203
+ };
@@ -12,8 +12,15 @@
12
12
  * The brain learns by `(archetype, model, shape)` tuples. Apps that declare
13
13
  * the same tuple inherit each other's mutations.
14
14
  *
15
- * v1 is intentionally small (9 archetypes, 5 shape dimensions). New entries
16
- * arrive in v2/v3 from real usage signals — never speculatively.
15
+ * v1 is intentionally small (10 archetypes, 5 shape dimensions). New entries
16
+ * arrive from real usage signals — never speculatively.
17
+ *
18
+ * Versioning note (alpha.62): `judge` was added as an ADDITIVE 10th entry
19
+ * under dialect-v1 rather than bumping to v2. Bumping the version string
20
+ * would fragment every existing learning key (`v1::…` → `v2::…`) for a
21
+ * purely additive vocabulary change; existing keys are untouched and judge
22
+ * keys are new, so no collision is possible. A v2 bump is reserved for
23
+ * changes that alter the MEANING of existing entries or the shape hash.
17
24
  */
18
25
  declare const DIALECT_VERSION: "v1";
19
26
  declare const INTENT_ARCHETYPES: {
@@ -62,6 +69,11 @@ declare const INTENT_ARCHETYPES: {
62
69
  readonly description: "Change format or style while preserving content";
63
70
  readonly examples: ["markdown → html", "formal → casual", "translate"];
64
71
  };
72
+ readonly judge: {
73
+ readonly name: "judge";
74
+ readonly description: "Pairwise comparison of two candidate outputs for the same input";
75
+ readonly examples: ["golden-set eval A/B verdict", "model-swap non-inferiority check", "response bake-off"];
76
+ };
65
77
  };
66
78
  type IntentArchetypeName = keyof typeof INTENT_ARCHETYPES;
67
79
  declare const ALL_ARCHETYPES: IntentArchetypeName[];
@@ -82,6 +94,32 @@ interface ShapeSignature {
82
94
  /** Whether the prompt includes few-shot examples. */
83
95
  hasExamples: boolean;
84
96
  }
97
+ /**
98
+ * SINGLE source of truth for a call's output shape.
99
+ *
100
+ * Two independent expressions of this concept used to exist — `computeShape`
101
+ * (three-valued, feeding `compile_outcomes.shape_key`) and compile()'s Factor C
102
+ * screen (two-valued). They disagreed on exactly one case: tools present with
103
+ * no `structuredOutput`, which the shape signature calls `tool_call` and the
104
+ * screen called `text`. That gap let alpha.68's shape-altering discipline gates
105
+ * fire on tool-call surfaces — the surface class the design contract names as
106
+ * forbidden, because labelling claims inside a tool-call envelope manufactures
107
+ * the structured-output violations alpha.66 ships a retry for.
108
+ *
109
+ * A consumer `declared` value WINS over inference. The inference cannot see
110
+ * that an agentic surface carrying tools ultimately emits prose, so it is
111
+ * deliberately conservative — wrongly firing a shape-altering rule breaks a
112
+ * parser, wrongly withholding one only forgoes a lift. `constraints.outputMode`
113
+ * is the escape hatch for surfaces that know better.
114
+ *
115
+ * Takes the facts rather than a `PromptIR` so `dialect.ts` stays
116
+ * dependency-free (`ir.ts` imports THIS module, not the reverse).
117
+ */
118
+ declare function resolveOutputMode(args: {
119
+ declared?: OutputMode;
120
+ structuredOutput?: boolean;
121
+ toolCount: number;
122
+ }): OutputMode;
85
123
  declare function bucketContext(tokens: number): ContextBucket;
86
124
  declare function bucketToolCount(count: number): ToolCountBucket;
87
125
  declare function bucketHistory(turnCount: number): HistoryDepth;
@@ -96,4 +134,4 @@ declare function hashShape(s: ShapeSignature): string;
96
134
  */
97
135
  declare function learningKey(archetype: IntentArchetypeName, model: string, shape: ShapeSignature): string;
98
136
 
99
- export { ALL_ARCHETYPES, type ContextBucket, DIALECT_VERSION, type HistoryDepth, INTENT_ARCHETYPES, type IntentArchetypeName, type OutputMode, type ShapeSignature, type ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey };
137
+ export { ALL_ARCHETYPES, type ContextBucket, DIALECT_VERSION, type HistoryDepth, INTENT_ARCHETYPES, type IntentArchetypeName, type OutputMode, type ShapeSignature, type ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey, resolveOutputMode };
package/dist/dialect.d.ts CHANGED
@@ -12,8 +12,15 @@
12
12
  * The brain learns by `(archetype, model, shape)` tuples. Apps that declare
13
13
  * the same tuple inherit each other's mutations.
14
14
  *
15
- * v1 is intentionally small (9 archetypes, 5 shape dimensions). New entries
16
- * arrive in v2/v3 from real usage signals — never speculatively.
15
+ * v1 is intentionally small (10 archetypes, 5 shape dimensions). New entries
16
+ * arrive from real usage signals — never speculatively.
17
+ *
18
+ * Versioning note (alpha.62): `judge` was added as an ADDITIVE 10th entry
19
+ * under dialect-v1 rather than bumping to v2. Bumping the version string
20
+ * would fragment every existing learning key (`v1::…` → `v2::…`) for a
21
+ * purely additive vocabulary change; existing keys are untouched and judge
22
+ * keys are new, so no collision is possible. A v2 bump is reserved for
23
+ * changes that alter the MEANING of existing entries or the shape hash.
17
24
  */
18
25
  declare const DIALECT_VERSION: "v1";
19
26
  declare const INTENT_ARCHETYPES: {
@@ -62,6 +69,11 @@ declare const INTENT_ARCHETYPES: {
62
69
  readonly description: "Change format or style while preserving content";
63
70
  readonly examples: ["markdown → html", "formal → casual", "translate"];
64
71
  };
72
+ readonly judge: {
73
+ readonly name: "judge";
74
+ readonly description: "Pairwise comparison of two candidate outputs for the same input";
75
+ readonly examples: ["golden-set eval A/B verdict", "model-swap non-inferiority check", "response bake-off"];
76
+ };
65
77
  };
66
78
  type IntentArchetypeName = keyof typeof INTENT_ARCHETYPES;
67
79
  declare const ALL_ARCHETYPES: IntentArchetypeName[];
@@ -82,6 +94,32 @@ interface ShapeSignature {
82
94
  /** Whether the prompt includes few-shot examples. */
83
95
  hasExamples: boolean;
84
96
  }
97
+ /**
98
+ * SINGLE source of truth for a call's output shape.
99
+ *
100
+ * Two independent expressions of this concept used to exist — `computeShape`
101
+ * (three-valued, feeding `compile_outcomes.shape_key`) and compile()'s Factor C
102
+ * screen (two-valued). They disagreed on exactly one case: tools present with
103
+ * no `structuredOutput`, which the shape signature calls `tool_call` and the
104
+ * screen called `text`. That gap let alpha.68's shape-altering discipline gates
105
+ * fire on tool-call surfaces — the surface class the design contract names as
106
+ * forbidden, because labelling claims inside a tool-call envelope manufactures
107
+ * the structured-output violations alpha.66 ships a retry for.
108
+ *
109
+ * A consumer `declared` value WINS over inference. The inference cannot see
110
+ * that an agentic surface carrying tools ultimately emits prose, so it is
111
+ * deliberately conservative — wrongly firing a shape-altering rule breaks a
112
+ * parser, wrongly withholding one only forgoes a lift. `constraints.outputMode`
113
+ * is the escape hatch for surfaces that know better.
114
+ *
115
+ * Takes the facts rather than a `PromptIR` so `dialect.ts` stays
116
+ * dependency-free (`ir.ts` imports THIS module, not the reverse).
117
+ */
118
+ declare function resolveOutputMode(args: {
119
+ declared?: OutputMode;
120
+ structuredOutput?: boolean;
121
+ toolCount: number;
122
+ }): OutputMode;
85
123
  declare function bucketContext(tokens: number): ContextBucket;
86
124
  declare function bucketToolCount(count: number): ToolCountBucket;
87
125
  declare function bucketHistory(turnCount: number): HistoryDepth;
@@ -96,4 +134,4 @@ declare function hashShape(s: ShapeSignature): string;
96
134
  */
97
135
  declare function learningKey(archetype: IntentArchetypeName, model: string, shape: ShapeSignature): string;
98
136
 
99
- export { ALL_ARCHETYPES, type ContextBucket, DIALECT_VERSION, type HistoryDepth, INTENT_ARCHETYPES, type IntentArchetypeName, type OutputMode, type ShapeSignature, type ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey };
137
+ export { ALL_ARCHETYPES, type ContextBucket, DIALECT_VERSION, type HistoryDepth, INTENT_ARCHETYPES, type IntentArchetypeName, type OutputMode, type ShapeSignature, type ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey, resolveOutputMode };
package/dist/dialect.js CHANGED
@@ -28,7 +28,8 @@ __export(dialect_exports, {
28
28
  bucketToolCount: () => bucketToolCount,
29
29
  hashShape: () => hashShape,
30
30
  isArchetype: () => isArchetype,
31
- learningKey: () => learningKey
31
+ learningKey: () => learningKey,
32
+ resolveOutputMode: () => resolveOutputMode
32
33
  });
33
34
  module.exports = __toCommonJS(dialect_exports);
34
35
  var DIALECT_VERSION = "v1";
@@ -77,12 +78,22 @@ var INTENT_ARCHETYPES = {
77
78
  name: "transform",
78
79
  description: "Change format or style while preserving content",
79
80
  examples: ["markdown \u2192 html", "formal \u2192 casual", "translate"]
81
+ },
82
+ judge: {
83
+ name: "judge",
84
+ description: "Pairwise comparison of two candidate outputs for the same input",
85
+ examples: ["golden-set eval A/B verdict", "model-swap non-inferiority check", "response bake-off"]
80
86
  }
81
87
  };
82
88
  var ALL_ARCHETYPES = Object.keys(INTENT_ARCHETYPES);
83
89
  function isArchetype(name) {
84
90
  return name in INTENT_ARCHETYPES;
85
91
  }
92
+ function resolveOutputMode(args) {
93
+ if (args.declared) return args.declared;
94
+ if (args.structuredOutput === true) return "json";
95
+ return args.toolCount > 0 ? "tool_call" : "text";
96
+ }
86
97
  function bucketContext(tokens) {
87
98
  if (tokens < 1e3) return "tiny";
88
99
  if (tokens < 4e3) return "small";
@@ -123,5 +134,6 @@ function learningKey(archetype, model, shape) {
123
134
  bucketToolCount,
124
135
  hashShape,
125
136
  isArchetype,
126
- learningKey
137
+ learningKey,
138
+ resolveOutputMode
127
139
  });
package/dist/dialect.mjs CHANGED
@@ -7,8 +7,9 @@ import {
7
7
  bucketToolCount,
8
8
  hashShape,
9
9
  isArchetype,
10
- learningKey
11
- } from "./chunk-5TI6PNSK.mjs";
10
+ learningKey,
11
+ resolveOutputMode
12
+ } from "./chunk-BVEXV5KC.mjs";
12
13
  export {
13
14
  ALL_ARCHETYPES,
14
15
  DIALECT_VERSION,
@@ -18,5 +19,6 @@ export {
18
19
  bucketToolCount,
19
20
  hashShape,
20
21
  isArchetype,
21
- learningKey
22
+ learningKey,
23
+ resolveOutputMode
22
24
  };
@@ -0,0 +1,59 @@
1
+ import { G as GlassboxEvent } from '../types-BDFrJkma.mjs';
2
+ export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-BDFrJkma.mjs';
3
+ import '../ir-CnnJST_N.mjs';
4
+ import '../dialect.mjs';
5
+
6
+ /**
7
+ * subscribe(traceId) — public Glass-Box subscription export.
8
+ *
9
+ * Consumer route handlers (e.g. Vercel Edge `/api/glassbox/stream`) import
10
+ * this and bridge the ReadableStream to SSE. The browser-side panel then
11
+ * renders events in real time:
12
+ *
13
+ * import { subscribe } from '@warmdrift/kgauto-compiler/glassbox';
14
+ *
15
+ * export async function GET(req: Request) {
16
+ * const { searchParams } = new URL(req.url);
17
+ * const traceId = searchParams.get('traceId');
18
+ * if (!traceId) return new Response('missing traceId', { status: 400 });
19
+ * const stream = subscribe(traceId);
20
+ * // ... bridge ReadableStream<GlassboxEvent> → SSE here ...
21
+ * }
22
+ *
23
+ * Stream behavior:
24
+ * - Emits events for `traceId` as they're published.
25
+ * - Closes cleanly 60s after the last event (rolling TTL).
26
+ * - If no events arrive within 60s of subscription, closes empty.
27
+ * - Multiple subscribers on the same traceId all fan out.
28
+ *
29
+ * No replay: subscribe() picks up only events published AFTER subscription.
30
+ * Replay is the brain-poll surface's job (see design doc).
31
+ */
32
+
33
+ /**
34
+ * Subscribe to Glass-Box events for a traceId. Returns a ReadableStream
35
+ * that yields GlassboxEvent objects until the per-trace TTL elapses.
36
+ *
37
+ * Cancelling the stream (consumer disconnect, AbortController, etc.) tears
38
+ * down the subscription cleanly via the underlying adapter.
39
+ */
40
+ declare function subscribe(traceId: string): ReadableStream<GlassboxEvent>;
41
+ /**
42
+ * Subscribe to Glass-Box events for ALL traces under an appId — the
43
+ * "tail-all" surface (alpha.26). Backs the extension's default Live mode:
44
+ * rather than needing a specific traceId ahead of time, the panel sees
45
+ * every event for the configured consumer as calls happen.
46
+ *
47
+ * Per-app routing fires only when emit call-sites pass `appId` (the typed
48
+ * builders thread `ir.appId` automatically). Per-trace channel continues to
49
+ * fire for `subscribe(traceId)` callers — both arms are independent.
50
+ *
51
+ * Cross-tenant isolation: the consumer's `/api/glassbox/stream` uses the
52
+ * factory's configured appId — no caller-supplied `?appId=` URL parameter,
53
+ * so a consumer cannot subscribe to another consumer's stream.
54
+ */
55
+ declare function subscribeApp({ appId, }: {
56
+ appId: string;
57
+ }): ReadableStream<GlassboxEvent>;
58
+
59
+ export { GlassboxEvent, subscribe, subscribeApp };
@@ -0,0 +1,59 @@
1
+ import { G as GlassboxEvent } from '../types-B--CYzMo.js';
2
+ export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-B--CYzMo.js';
3
+ import '../ir-BEQ28muo.js';
4
+ import '../dialect.js';
5
+
6
+ /**
7
+ * subscribe(traceId) — public Glass-Box subscription export.
8
+ *
9
+ * Consumer route handlers (e.g. Vercel Edge `/api/glassbox/stream`) import
10
+ * this and bridge the ReadableStream to SSE. The browser-side panel then
11
+ * renders events in real time:
12
+ *
13
+ * import { subscribe } from '@warmdrift/kgauto-compiler/glassbox';
14
+ *
15
+ * export async function GET(req: Request) {
16
+ * const { searchParams } = new URL(req.url);
17
+ * const traceId = searchParams.get('traceId');
18
+ * if (!traceId) return new Response('missing traceId', { status: 400 });
19
+ * const stream = subscribe(traceId);
20
+ * // ... bridge ReadableStream<GlassboxEvent> → SSE here ...
21
+ * }
22
+ *
23
+ * Stream behavior:
24
+ * - Emits events for `traceId` as they're published.
25
+ * - Closes cleanly 60s after the last event (rolling TTL).
26
+ * - If no events arrive within 60s of subscription, closes empty.
27
+ * - Multiple subscribers on the same traceId all fan out.
28
+ *
29
+ * No replay: subscribe() picks up only events published AFTER subscription.
30
+ * Replay is the brain-poll surface's job (see design doc).
31
+ */
32
+
33
+ /**
34
+ * Subscribe to Glass-Box events for a traceId. Returns a ReadableStream
35
+ * that yields GlassboxEvent objects until the per-trace TTL elapses.
36
+ *
37
+ * Cancelling the stream (consumer disconnect, AbortController, etc.) tears
38
+ * down the subscription cleanly via the underlying adapter.
39
+ */
40
+ declare function subscribe(traceId: string): ReadableStream<GlassboxEvent>;
41
+ /**
42
+ * Subscribe to Glass-Box events for ALL traces under an appId — the
43
+ * "tail-all" surface (alpha.26). Backs the extension's default Live mode:
44
+ * rather than needing a specific traceId ahead of time, the panel sees
45
+ * every event for the configured consumer as calls happen.
46
+ *
47
+ * Per-app routing fires only when emit call-sites pass `appId` (the typed
48
+ * builders thread `ir.appId` automatically). Per-trace channel continues to
49
+ * fire for `subscribe(traceId)` callers — both arms are independent.
50
+ *
51
+ * Cross-tenant isolation: the consumer's `/api/glassbox/stream` uses the
52
+ * factory's configured appId — no caller-supplied `?appId=` URL parameter,
53
+ * so a consumer cannot subscribe to another consumer's stream.
54
+ */
55
+ declare function subscribeApp({ appId, }: {
56
+ appId: string;
57
+ }): ReadableStream<GlassboxEvent>;
58
+
59
+ export { GlassboxEvent, subscribe, subscribeApp };