@warmdrift/kgauto-compiler 2.0.0-alpha.3 → 2.0.0-alpha.31

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/profiles.mjs CHANGED
@@ -1,13 +1,17 @@
1
1
  import {
2
2
  ALIASES,
3
+ _setProfileBrainHook,
3
4
  allProfiles,
5
+ allProfilesRaw,
4
6
  getProfile,
5
7
  profilesByProvider,
6
8
  tryGetProfile
7
- } from "./chunk-MBEI5UOM.mjs";
9
+ } from "./chunk-JQGRWJZO.mjs";
8
10
  export {
9
11
  ALIASES,
12
+ _setProfileBrainHook,
10
13
  allProfiles,
14
+ allProfilesRaw,
11
15
  getProfile,
12
16
  profilesByProvider,
13
17
  tryGetProfile
@@ -0,0 +1,131 @@
1
+ import { p as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, l as CallAttempt } from './ir-De2AQtlr.mjs';
2
+
3
+ /**
4
+ * Glass-Box observability types (alpha.17).
5
+ *
6
+ * The substrate for kgauto's in-flight observability surface — a Chrome MV3
7
+ * side panel that renders compile + execute + advisor outputs in real-time.
8
+ * See design doc:
9
+ * ~/.gstack/projects/stue-kgauto/stgreen-claude-serene-williamson-51a105-design-20260518-175356.md
10
+ *
11
+ * Wire shape is intentionally minimal:
12
+ * { kind, at, data } — discriminated union by `kind`.
13
+ *
14
+ * Critical-path safety (L-086 derived): emit MUST NEVER fail the user's
15
+ * `call()` invocation. emit.ts wraps every adapter write in try/catch +
16
+ * silently drops on error. Consumers in Vercel Edge runtimes can lose one
17
+ * event without losing the response.
18
+ */
19
+
20
+ /**
21
+ * Discriminator. Six event kinds cover the v1 substrate. New kinds added
22
+ * additively; the side-panel renderer treats unknown kinds as "ignore".
23
+ */
24
+ type GlassboxEventKind = 'compile.start' | 'compile.done' | 'execute.attempt' | 'execute.success' | 'advisory.fired' | 'fallback.walked';
25
+ /**
26
+ * Wire envelope. Every emit lands as one of these.
27
+ *
28
+ * - kind: discriminator
29
+ * - at: unix milliseconds (Date.now())
30
+ * - data: kind-specific payload
31
+ *
32
+ * `data` typed loosely as Record<string, unknown> for serialization-friendliness;
33
+ * the per-kind builders below populate it with the structured shape expected
34
+ * by the renderer. We deliberately do NOT typescript-narrow `data` by kind on
35
+ * the wire type — the side panel reads JSON from SSE and only the renderer
36
+ * needs the narrowed shape. Internal callers (emit.ts) get type assistance via
37
+ * the typed factory helpers in emit.ts.
38
+ */
39
+ interface GlassboxEvent {
40
+ kind: GlassboxEventKind;
41
+ at: number;
42
+ data: Record<string, unknown>;
43
+ }
44
+ /**
45
+ * Per-kind data shapes. Surfaced as type aids; not enforced at the
46
+ * GlassboxEvent boundary (intentionally — see comment above).
47
+ */
48
+ interface CompileStartData {
49
+ appId: string;
50
+ archetype: string;
51
+ models: string[];
52
+ }
53
+ interface CompileDoneData {
54
+ target: string;
55
+ provider: string;
56
+ fallbackChain: string[];
57
+ tokensIn: number;
58
+ estimatedCostUsd: number;
59
+ mutationsApplied: MutationApplied[];
60
+ advisories: BestPracticeAdvisory[];
61
+ }
62
+ interface ExecuteAttemptData {
63
+ model: string;
64
+ attemptIndex: number;
65
+ }
66
+ interface ExecuteSuccessData {
67
+ model: string;
68
+ tokensIn: number;
69
+ tokensOut: number;
70
+ latencyMs: number;
71
+ }
72
+ interface AdvisoryFiredData {
73
+ code: string;
74
+ message: string;
75
+ }
76
+ interface FallbackWalkedData {
77
+ from: string;
78
+ to: string;
79
+ reason: FallbackReason | 'unknown';
80
+ attempt: CallAttempt;
81
+ }
82
+ /**
83
+ * Pub/sub backend interface. Two adapters implement it: in-memory (dev /
84
+ * single-process) and Upstash Redis Streams (Vercel Edge multi-instance).
85
+ *
86
+ * The choice is made at module load (NOT per-call) based on env-var presence:
87
+ * if (UPSTASH_REDIS_URL && UPSTASH_REDIS_TOKEN) → Upstash
88
+ * else → in-memory
89
+ *
90
+ * Stream TTL: 60s after last event. After that, subscriber stream closes
91
+ * cleanly. The adapter owns its own TTL clock; subscribe() is agnostic.
92
+ */
93
+ interface GlassboxPubSub {
94
+ /**
95
+ * Publish a single event to a channel key. The channel is an opaque
96
+ * namespaced string — callers build it via `traceChannel(traceId)` or
97
+ * `appChannel(appId)` (see pubsub-upstash.ts). Returns a promise that
98
+ * resolves after the event is durably appended (or rejects on adapter
99
+ * failure — callers in emit.ts always swallow rejections).
100
+ *
101
+ * Pre-alpha.26 the parameter was named `traceId` because there was only
102
+ * one channel namespace; alpha.26 added per-app channels for the
103
+ * "tail-all" Live tab subscription. Behavior identical to the adapters —
104
+ * they treat the value as an opaque key — but the rename surfaces the
105
+ * generalization at the type level.
106
+ */
107
+ publish(channelKey: string, event: GlassboxEvent): Promise<void>;
108
+ /**
109
+ * Subscribe to events on a channel key. Returns a ReadableStream that
110
+ * emits GlassboxEvent objects as they're published. The stream closes
111
+ * cleanly after the channel-level TTL elapses since the LAST event
112
+ * (rolling 60s).
113
+ *
114
+ * If no publisher writes to the channel within 60s of subscription, the
115
+ * stream closes empty.
116
+ */
117
+ subscribe(channelKey: string): ReadableStream<GlassboxEvent>;
118
+ /**
119
+ * Test-only escape hatch. Clears any in-memory state. Upstash adapter
120
+ * no-ops (server-side state isn't accessible from here). Tests reach for
121
+ * this between cases to keep adapters hermetic.
122
+ */
123
+ _reset?(): void;
124
+ }
125
+ /**
126
+ * TTL applied to a stream after each event. The design doc names 60s; this
127
+ * constant centralizes it so both adapters + tests agree.
128
+ */
129
+ declare const GLASSBOX_STREAM_TTL_MS = 60000;
130
+
131
+ export { type AdvisoryFiredData as A, type CompileDoneData as C, type ExecuteAttemptData as E, type FallbackWalkedData as F, type GlassboxEvent as G, type CompileStartData as a, type ExecuteSuccessData as b, GLASSBOX_STREAM_TTL_MS as c, type GlassboxEventKind as d, type GlassboxPubSub as e };
@@ -0,0 +1,131 @@
1
+ import { p as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, l as CallAttempt } from './ir-BIAT9gJk.js';
2
+
3
+ /**
4
+ * Glass-Box observability types (alpha.17).
5
+ *
6
+ * The substrate for kgauto's in-flight observability surface — a Chrome MV3
7
+ * side panel that renders compile + execute + advisor outputs in real-time.
8
+ * See design doc:
9
+ * ~/.gstack/projects/stue-kgauto/stgreen-claude-serene-williamson-51a105-design-20260518-175356.md
10
+ *
11
+ * Wire shape is intentionally minimal:
12
+ * { kind, at, data } — discriminated union by `kind`.
13
+ *
14
+ * Critical-path safety (L-086 derived): emit MUST NEVER fail the user's
15
+ * `call()` invocation. emit.ts wraps every adapter write in try/catch +
16
+ * silently drops on error. Consumers in Vercel Edge runtimes can lose one
17
+ * event without losing the response.
18
+ */
19
+
20
+ /**
21
+ * Discriminator. Six event kinds cover the v1 substrate. New kinds added
22
+ * additively; the side-panel renderer treats unknown kinds as "ignore".
23
+ */
24
+ type GlassboxEventKind = 'compile.start' | 'compile.done' | 'execute.attempt' | 'execute.success' | 'advisory.fired' | 'fallback.walked';
25
+ /**
26
+ * Wire envelope. Every emit lands as one of these.
27
+ *
28
+ * - kind: discriminator
29
+ * - at: unix milliseconds (Date.now())
30
+ * - data: kind-specific payload
31
+ *
32
+ * `data` typed loosely as Record<string, unknown> for serialization-friendliness;
33
+ * the per-kind builders below populate it with the structured shape expected
34
+ * by the renderer. We deliberately do NOT typescript-narrow `data` by kind on
35
+ * the wire type — the side panel reads JSON from SSE and only the renderer
36
+ * needs the narrowed shape. Internal callers (emit.ts) get type assistance via
37
+ * the typed factory helpers in emit.ts.
38
+ */
39
+ interface GlassboxEvent {
40
+ kind: GlassboxEventKind;
41
+ at: number;
42
+ data: Record<string, unknown>;
43
+ }
44
+ /**
45
+ * Per-kind data shapes. Surfaced as type aids; not enforced at the
46
+ * GlassboxEvent boundary (intentionally — see comment above).
47
+ */
48
+ interface CompileStartData {
49
+ appId: string;
50
+ archetype: string;
51
+ models: string[];
52
+ }
53
+ interface CompileDoneData {
54
+ target: string;
55
+ provider: string;
56
+ fallbackChain: string[];
57
+ tokensIn: number;
58
+ estimatedCostUsd: number;
59
+ mutationsApplied: MutationApplied[];
60
+ advisories: BestPracticeAdvisory[];
61
+ }
62
+ interface ExecuteAttemptData {
63
+ model: string;
64
+ attemptIndex: number;
65
+ }
66
+ interface ExecuteSuccessData {
67
+ model: string;
68
+ tokensIn: number;
69
+ tokensOut: number;
70
+ latencyMs: number;
71
+ }
72
+ interface AdvisoryFiredData {
73
+ code: string;
74
+ message: string;
75
+ }
76
+ interface FallbackWalkedData {
77
+ from: string;
78
+ to: string;
79
+ reason: FallbackReason | 'unknown';
80
+ attempt: CallAttempt;
81
+ }
82
+ /**
83
+ * Pub/sub backend interface. Two adapters implement it: in-memory (dev /
84
+ * single-process) and Upstash Redis Streams (Vercel Edge multi-instance).
85
+ *
86
+ * The choice is made at module load (NOT per-call) based on env-var presence:
87
+ * if (UPSTASH_REDIS_URL && UPSTASH_REDIS_TOKEN) → Upstash
88
+ * else → in-memory
89
+ *
90
+ * Stream TTL: 60s after last event. After that, subscriber stream closes
91
+ * cleanly. The adapter owns its own TTL clock; subscribe() is agnostic.
92
+ */
93
+ interface GlassboxPubSub {
94
+ /**
95
+ * Publish a single event to a channel key. The channel is an opaque
96
+ * namespaced string — callers build it via `traceChannel(traceId)` or
97
+ * `appChannel(appId)` (see pubsub-upstash.ts). Returns a promise that
98
+ * resolves after the event is durably appended (or rejects on adapter
99
+ * failure — callers in emit.ts always swallow rejections).
100
+ *
101
+ * Pre-alpha.26 the parameter was named `traceId` because there was only
102
+ * one channel namespace; alpha.26 added per-app channels for the
103
+ * "tail-all" Live tab subscription. Behavior identical to the adapters —
104
+ * they treat the value as an opaque key — but the rename surfaces the
105
+ * generalization at the type level.
106
+ */
107
+ publish(channelKey: string, event: GlassboxEvent): Promise<void>;
108
+ /**
109
+ * Subscribe to events on a channel key. Returns a ReadableStream that
110
+ * emits GlassboxEvent objects as they're published. The stream closes
111
+ * cleanly after the channel-level TTL elapses since the LAST event
112
+ * (rolling 60s).
113
+ *
114
+ * If no publisher writes to the channel within 60s of subscription, the
115
+ * stream closes empty.
116
+ */
117
+ subscribe(channelKey: string): ReadableStream<GlassboxEvent>;
118
+ /**
119
+ * Test-only escape hatch. Clears any in-memory state. Upstash adapter
120
+ * no-ops (server-side state isn't accessible from here). Tests reach for
121
+ * this between cases to keep adapters hermetic.
122
+ */
123
+ _reset?(): void;
124
+ }
125
+ /**
126
+ * TTL applied to a stream after each event. The design doc names 60s; this
127
+ * constant centralizes it so both adapters + tests agree.
128
+ */
129
+ declare const GLASSBOX_STREAM_TTL_MS = 60000;
130
+
131
+ export { type AdvisoryFiredData as A, type CompileDoneData as C, type ExecuteAttemptData as E, type FallbackWalkedData as F, type GlassboxEvent as G, type CompileStartData as a, type ExecuteSuccessData as b, GLASSBOX_STREAM_TTL_MS as c, type GlassboxEventKind as d, type GlassboxPubSub as e };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warmdrift/kgauto-compiler",
3
- "version": "2.0.0-alpha.3",
3
+ "version": "2.0.0-alpha.31",
4
4
  "description": "Prompt compiler + central learning brain for multi-model AI apps. Swap models without rewriting prompts.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -20,11 +20,21 @@
20
20
  "types": "./dist/profiles.d.ts",
21
21
  "import": "./dist/profiles.mjs",
22
22
  "require": "./dist/profiles.js"
23
+ },
24
+ "./glassbox": {
25
+ "types": "./dist/glassbox/index.d.ts",
26
+ "import": "./dist/glassbox/index.mjs",
27
+ "require": "./dist/glassbox/index.js"
28
+ },
29
+ "./glassbox-routes": {
30
+ "types": "./dist/glassbox-routes/index.d.ts",
31
+ "import": "./dist/glassbox-routes/index.mjs",
32
+ "require": "./dist/glassbox-routes/index.js"
23
33
  }
24
34
  },
25
35
  "files": ["dist", "README.md"],
26
36
  "scripts": {
27
- "build": "tsup src/index.ts src/dialect.ts src/profiles.ts --format cjs,esm --dts --clean",
37
+ "build": "tsup src/index.ts src/dialect.ts src/profiles.ts src/glassbox/index.ts src/glassbox-routes/index.ts --format cjs,esm --dts --clean",
28
38
  "test": "vitest run",
29
39
  "test:watch": "vitest",
30
40
  "typecheck": "tsc --noEmit",