@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,193 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/brain-proxy.ts
21
+ var brain_proxy_exports = {};
22
+ __export(brain_proxy_exports, {
23
+ createBrainForwardRoutes: () => createBrainForwardRoutes
24
+ });
25
+ module.exports = __toCommonJS(brain_proxy_exports);
26
+ var SEGMENT_TO_TABLE = {
27
+ outcomes: "compile_outcomes",
28
+ compile_outcome_advisories: "compile_outcome_advisories",
29
+ compile_outcome_quality: "compile_outcome_quality",
30
+ probe_outcomes: "probe_outcomes",
31
+ // alpha.62 (eval spine): golden-set capture. Only receives rows when the
32
+ // consumer has explicitly opted in via KGAUTO_GOLDEN_CAPTURE — the segment
33
+ // existing here does not by itself store anything.
34
+ golden_irs: "kgauto_golden_irs"
35
+ };
36
+ var KNOWN_SEGMENTS = Object.keys(SEGMENT_TO_TABLE);
37
+ var JSON_HEADERS = { "Content-Type": "application/json" };
38
+ function jsonResponse(status, body) {
39
+ return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS });
40
+ }
41
+ function bearerOf(req) {
42
+ const header = req.headers.get("Authorization") ?? "";
43
+ const match = /^Bearer\s+(.+)$/i.exec(header);
44
+ return match?.[1]?.trim() ?? "";
45
+ }
46
+ function requireString(name, value) {
47
+ if (typeof value !== "string" || value.length === 0) {
48
+ throw new Error(`createBrainForwardRoutes: ${name} is required`);
49
+ }
50
+ return value;
51
+ }
52
+ function isNumericOutcomeId(value) {
53
+ return typeof value === "number" || typeof value === "string" && /^\d+$/.test(value);
54
+ }
55
+ function createBrainForwardRoutes(config) {
56
+ const ingestSecret = requireString("ingestSecret", config.ingestSecret);
57
+ const brainUrl = requireString("brainUrl", config.brainUrl).replace(/\/+$/, "");
58
+ const serviceKey = requireString("serviceKey", config.serviceKey);
59
+ const fetchFn = config.fetchImpl ?? fetch;
60
+ async function resolveQualityOutcomeIds(body) {
61
+ const rows = Array.isArray(body) ? body : [body];
62
+ const handles = [
63
+ ...new Set(
64
+ rows.map((r) => r?.outcome_id).filter(
65
+ (v) => typeof v === "string" && !isNumericOutcomeId(v)
66
+ )
67
+ )
68
+ ];
69
+ if (handles.length === 0) return body;
70
+ const list = handles.map((h) => `"${h.replace(/"/g, "")}"`).join(",");
71
+ const url = `${brainUrl}/rest/v1/compile_outcomes?select=id,handle&handle=in.(${encodeURIComponent(list)})&order=id.desc`;
72
+ let idByHandle;
73
+ try {
74
+ const res = await fetchFn(url, {
75
+ headers: { apikey: serviceKey, Authorization: `Bearer ${serviceKey}` }
76
+ });
77
+ if (!res.ok) {
78
+ const text = await res.text().catch(() => "<no body>");
79
+ return jsonResponse(502, {
80
+ error: "handle-resolution-failed",
81
+ table: "compile_outcome_quality",
82
+ status: res.status,
83
+ detail: text
84
+ });
85
+ }
86
+ const found = await res.json();
87
+ idByHandle = /* @__PURE__ */ new Map();
88
+ for (const r of found) {
89
+ if (!idByHandle.has(r.handle)) idByHandle.set(r.handle, r.id);
90
+ }
91
+ } catch (err) {
92
+ return jsonResponse(502, {
93
+ error: "handle-resolution-failed",
94
+ table: "compile_outcome_quality",
95
+ detail: err instanceof Error ? err.message : String(err)
96
+ });
97
+ }
98
+ const unresolved = handles.filter((h) => !idByHandle.has(h));
99
+ if (unresolved.length > 0) {
100
+ return jsonResponse(404, {
101
+ error: "handle_not_found",
102
+ table: "compile_outcome_quality",
103
+ unresolved
104
+ });
105
+ }
106
+ const rewritten = rows.map(
107
+ (r) => typeof r?.outcome_id === "string" && idByHandle.has(r.outcome_id) ? { ...r, outcome_id: idByHandle.get(r.outcome_id) } : r
108
+ );
109
+ return Array.isArray(body) ? rewritten : rewritten[0];
110
+ }
111
+ async function handle(req, segment) {
112
+ try {
113
+ if (req.method !== "POST") {
114
+ return jsonResponse(405, {
115
+ error: "method-not-allowed",
116
+ method: req.method,
117
+ allowed: ["POST"]
118
+ });
119
+ }
120
+ const table = SEGMENT_TO_TABLE[segment];
121
+ if (!table) {
122
+ return jsonResponse(404, {
123
+ error: "unknown-brain-forward-segment",
124
+ segment,
125
+ known: KNOWN_SEGMENTS
126
+ });
127
+ }
128
+ if (bearerOf(req) !== ingestSecret) {
129
+ return jsonResponse(401, { error: "unauthorized" });
130
+ }
131
+ let body;
132
+ try {
133
+ body = await req.json();
134
+ } catch {
135
+ return jsonResponse(400, { error: "invalid-json" });
136
+ }
137
+ let row = Array.isArray(body) ? body : { ...body };
138
+ if (table === "compile_outcome_quality") {
139
+ const outcome = await resolveQualityOutcomeIds(row);
140
+ if (outcome instanceof Response) return outcome;
141
+ row = outcome;
142
+ }
143
+ const wantsRepresentation = /return=representation/i.test(
144
+ req.headers.get("Prefer") ?? ""
145
+ );
146
+ let brainRes;
147
+ try {
148
+ brainRes = await fetchFn(`${brainUrl}/rest/v1/${table}`, {
149
+ method: "POST",
150
+ headers: {
151
+ apikey: serviceKey,
152
+ Authorization: `Bearer ${serviceKey}`,
153
+ "Content-Type": "application/json",
154
+ Prefer: wantsRepresentation ? "return=representation" : "return=minimal"
155
+ },
156
+ body: JSON.stringify(row)
157
+ });
158
+ } catch (err) {
159
+ return jsonResponse(502, {
160
+ error: "brain-unreachable",
161
+ table,
162
+ detail: err instanceof Error ? err.message : String(err)
163
+ });
164
+ }
165
+ if (brainRes.ok) {
166
+ if (wantsRepresentation) {
167
+ const text2 = await brainRes.text().catch(() => "");
168
+ if (text2.length > 0) {
169
+ return new Response(text2, { status: 201, headers: JSON_HEADERS });
170
+ }
171
+ }
172
+ return jsonResponse(201, { ok: true });
173
+ }
174
+ const text = await brainRes.text().catch(() => "<no body>");
175
+ return jsonResponse(brainRes.status, {
176
+ error: "brain-write-failed",
177
+ table,
178
+ status: brainRes.status,
179
+ detail: text
180
+ });
181
+ } catch (err) {
182
+ return jsonResponse(500, {
183
+ error: "brain-forward-internal-error",
184
+ detail: err instanceof Error ? err.message : String(err)
185
+ });
186
+ }
187
+ }
188
+ return { handle, segments: KNOWN_SEGMENTS };
189
+ }
190
+ // Annotate the CommonJS export names for ESM import in node:
191
+ 0 && (module.exports = {
192
+ createBrainForwardRoutes
193
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ createBrainForwardRoutes
3
+ } from "./chunk-65ZMX5OT.mjs";
4
+ export {
5
+ createBrainForwardRoutes
6
+ };