@ramme-io/kernel 2.1.0 → 2.1.2

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 (53) hide show
  1. package/dist/index-rELWPQV7.js +1157 -0
  2. package/dist/index.es.js +40238 -9287
  3. package/dist/kernel/src/components/AIChatPanel.d.ts +22 -0
  4. package/dist/kernel/src/components/AIChatPanel.d.ts.map +1 -0
  5. package/dist/kernel/src/components/settings/AiSettingsPanel.d.ts +10 -0
  6. package/dist/kernel/src/components/settings/AiSettingsPanel.d.ts.map +1 -0
  7. package/dist/kernel/src/components/settings/SettingsModal.d.ts.map +1 -1
  8. package/dist/kernel/src/engine/runtime/useRammeAI.d.ts +43 -0
  9. package/dist/kernel/src/engine/runtime/useRammeAI.d.ts.map +1 -0
  10. package/dist/kernel/src/index.d.ts +10 -0
  11. package/dist/kernel/src/index.d.ts.map +1 -1
  12. package/dist/kernel/src/server.d.ts +39 -0
  13. package/dist/kernel/src/server.d.ts.map +1 -0
  14. package/dist/kernel/src/services/AiGateway.d.ts +18 -0
  15. package/dist/kernel/src/services/AiGateway.d.ts.map +1 -0
  16. package/dist/kernel/src/services/ai/AiGatewayService.d.ts +31 -0
  17. package/dist/kernel/src/services/ai/AiGatewayService.d.ts.map +1 -0
  18. package/dist/kernel/src/services/ai/ConfigResolver.d.ts +32 -0
  19. package/dist/kernel/src/services/ai/ConfigResolver.d.ts.map +1 -0
  20. package/dist/kernel/src/services/ai/RateLimiter.d.ts +18 -0
  21. package/dist/kernel/src/services/ai/RateLimiter.d.ts.map +1 -0
  22. package/dist/kernel/src/services/ai/adapters/LocalTransportAdapter.d.ts +7 -0
  23. package/dist/kernel/src/services/ai/adapters/LocalTransportAdapter.d.ts.map +1 -0
  24. package/dist/kernel/src/services/ai/adapters/ProxyTransportAdapter.d.ts +9 -0
  25. package/dist/kernel/src/services/ai/adapters/ProxyTransportAdapter.d.ts.map +1 -0
  26. package/dist/kernel/src/services/ai/index.d.ts +18 -0
  27. package/dist/kernel/src/services/ai/index.d.ts.map +1 -0
  28. package/dist/kernel/src/services/ai/models.d.ts +6 -0
  29. package/dist/kernel/src/services/ai/models.d.ts.map +1 -0
  30. package/dist/kernel/src/services/ai/providers/AnthropicAdapter.d.ts +10 -0
  31. package/dist/kernel/src/services/ai/providers/AnthropicAdapter.d.ts.map +1 -0
  32. package/dist/kernel/src/services/ai/providers/DeepSeekAdapter.d.ts +10 -0
  33. package/dist/kernel/src/services/ai/providers/DeepSeekAdapter.d.ts.map +1 -0
  34. package/dist/kernel/src/services/ai/providers/GeminiAdapter.d.ts +10 -0
  35. package/dist/kernel/src/services/ai/providers/GeminiAdapter.d.ts.map +1 -0
  36. package/dist/kernel/src/services/ai/providers/GrokAdapter.d.ts +10 -0
  37. package/dist/kernel/src/services/ai/providers/GrokAdapter.d.ts.map +1 -0
  38. package/dist/kernel/src/services/ai/providers/OllamaAdapter.d.ts +9 -0
  39. package/dist/kernel/src/services/ai/providers/OllamaAdapter.d.ts.map +1 -0
  40. package/dist/kernel/src/services/ai/providers/OpenAIAdapter.d.ts +10 -0
  41. package/dist/kernel/src/services/ai/providers/OpenAIAdapter.d.ts.map +1 -0
  42. package/dist/kernel/src/services/ai/transport.d.ts +37 -0
  43. package/dist/kernel/src/services/ai/transport.d.ts.map +1 -0
  44. package/dist/kernel/src/services/ai/types.d.ts +38 -0
  45. package/dist/kernel/src/services/ai/types.d.ts.map +1 -0
  46. package/dist/kernel/src/stores/spatialStore.d.ts +25 -0
  47. package/dist/kernel/src/stores/spatialStore.d.ts.map +1 -0
  48. package/dist/kernel/src/stores/useSettingsStore.d.ts +17 -0
  49. package/dist/kernel/src/stores/useSettingsStore.d.ts.map +1 -1
  50. package/dist/server.d.ts +1 -0
  51. package/dist/server.es.js +26 -0
  52. package/package.json +14 -8
  53. package/dist/index.umd.js +0 -120
@@ -0,0 +1,1157 @@
1
+ import { z as e } from "zod";
2
+ class R {
3
+ async generateText(o, s) {
4
+ var i, l, m, d, p;
5
+ const { apiKey: r, model: t = "gemini-2.0-flash", temperature: a = 0.7 } = s;
6
+ if (!r) throw new Error("Gemini API key required");
7
+ if (!t) throw new Error("GeminiAdapter: model is required but was undefined");
8
+ const n = await fetch(
9
+ `https://generativelanguage.googleapis.com/v1beta/models/${t}:generateContent?key=${r}`,
10
+ {
11
+ method: "POST",
12
+ headers: { "Content-Type": "application/json" },
13
+ body: JSON.stringify({
14
+ contents: [{ parts: [{ text: o }] }],
15
+ generationConfig: { temperature: a }
16
+ })
17
+ }
18
+ );
19
+ if (!n.ok) {
20
+ const u = await n.text();
21
+ throw new Error(`Gemini Error ${n.status}: ${u}`);
22
+ }
23
+ return ((p = (d = (m = (l = (i = (await n.json()).candidates) == null ? void 0 : i[0]) == null ? void 0 : l.content) == null ? void 0 : m.parts) == null ? void 0 : d[0]) == null ? void 0 : p.text) || "";
24
+ }
25
+ async *streamText(o, s) {
26
+ var l, m, d, p, u, h;
27
+ const { apiKey: r, model: t = "gemini-2.0-flash" } = s;
28
+ if (!r) throw new Error("Gemini API key required");
29
+ if (!t) throw new Error("GeminiAdapter: model is required but was undefined");
30
+ const a = await fetch(
31
+ `https://generativelanguage.googleapis.com/v1beta/models/${t}:streamGenerateContent?alt=sse&key=${r}`,
32
+ {
33
+ method: "POST",
34
+ headers: { "Content-Type": "application/json" },
35
+ body: JSON.stringify({
36
+ contents: [{ parts: [{ text: o }] }]
37
+ })
38
+ }
39
+ );
40
+ if (!a.ok) {
41
+ const g = await a.text();
42
+ throw new Error(`Gemini Error ${a.status}: ${g}`);
43
+ }
44
+ const n = (l = a.body) == null ? void 0 : l.getReader();
45
+ if (!n) throw new Error("No response body");
46
+ const c = new TextDecoder();
47
+ let i = "";
48
+ for (; ; ) {
49
+ const { done: g, value: E } = await n.read();
50
+ if (g) break;
51
+ i += c.decode(E, { stream: !0 });
52
+ const f = i.split(`
53
+ `);
54
+ i = f.pop() || "";
55
+ for (const w of f) {
56
+ const y = w.trim();
57
+ if (!(!y || !y.startsWith("data: ")))
58
+ try {
59
+ const _ = (h = (u = (p = (d = (m = JSON.parse(y.slice(6)).candidates) == null ? void 0 : m[0]) == null ? void 0 : d.content) == null ? void 0 : p.parts) == null ? void 0 : u[0]) == null ? void 0 : h.text;
60
+ _ && (yield _);
61
+ } catch {
62
+ continue;
63
+ }
64
+ }
65
+ }
66
+ }
67
+ async generateObject(o, s, r) {
68
+ var l, m, d, p, u;
69
+ const { apiKey: t, model: a = "gemini-2.0-flash" } = r;
70
+ if (!t) throw new Error("Gemini API key required");
71
+ if (!a) throw new Error("GeminiAdapter: model is required but was undefined");
72
+ const n = await fetch(
73
+ `https://generativelanguage.googleapis.com/v1beta/models/${a}:generateContent?key=${t}`,
74
+ {
75
+ method: "POST",
76
+ headers: { "Content-Type": "application/json" },
77
+ body: JSON.stringify({
78
+ contents: [{ parts: [{ text: o }] }],
79
+ generationConfig: {
80
+ responseMimeType: "application/json",
81
+ responseSchema: s
82
+ }
83
+ })
84
+ }
85
+ );
86
+ if (!n.ok) {
87
+ const h = await n.json();
88
+ throw this.normalizeError(h, n.status);
89
+ }
90
+ const i = ((u = (p = (d = (m = (l = (await n.json()).candidates) == null ? void 0 : l[0]) == null ? void 0 : m.content) == null ? void 0 : d.parts) == null ? void 0 : p[0]) == null ? void 0 : u.text) || "{}";
91
+ return JSON.parse(i);
92
+ }
93
+ async listModels(o) {
94
+ var t;
95
+ if (!o) throw new Error("API key required to list models");
96
+ const s = await fetch(
97
+ `https://generativelanguage.googleapis.com/v1beta/models?key=${o}`
98
+ );
99
+ if (!s.ok)
100
+ throw new Error("Failed to fetch model list");
101
+ return ((t = (await s.json()).models) == null ? void 0 : t.map((a) => a.name)) || [];
102
+ }
103
+ normalizeError(o, s) {
104
+ var r;
105
+ if (s === 429) {
106
+ const t = new Error("Rate limit exceeded. Please wait 30 seconds before retrying.");
107
+ return t.code = "RATE_LIMIT", t;
108
+ }
109
+ if (s === 401 || s === 403) {
110
+ const t = new Error("Invalid API key.");
111
+ return t.code = "AUTH_ERROR", t;
112
+ }
113
+ return new Error(((r = o.error) == null ? void 0 : r.message) || "Unknown error");
114
+ }
115
+ }
116
+ class S {
117
+ async generateText(o, s) {
118
+ const { baseUrl: r = "http://localhost:11434", model: t = "llama3.2" } = s, a = await fetch(`${r}/api/generate`, {
119
+ method: "POST",
120
+ headers: { "Content-Type": "application/json" },
121
+ body: JSON.stringify({
122
+ model: t,
123
+ prompt: o,
124
+ stream: !1
125
+ })
126
+ });
127
+ if (!a.ok) {
128
+ const c = await a.text();
129
+ throw new Error(`Ollama Error ${a.status}: ${c}`);
130
+ }
131
+ return (await a.json()).response;
132
+ }
133
+ async *streamText(o, s) {
134
+ var l;
135
+ const { baseUrl: r = "http://localhost:11434", model: t = "llama3.2" } = s, a = await fetch(`${r}/api/generate`, {
136
+ method: "POST",
137
+ headers: { "Content-Type": "application/json" },
138
+ body: JSON.stringify({
139
+ model: t,
140
+ prompt: o,
141
+ stream: !0
142
+ })
143
+ });
144
+ if (!a.ok) {
145
+ const m = await a.text();
146
+ throw new Error(`Ollama Error ${a.status}: ${m}`);
147
+ }
148
+ const n = (l = a.body) == null ? void 0 : l.getReader();
149
+ if (!n) throw new Error("No response body");
150
+ const c = new TextDecoder();
151
+ let i = "";
152
+ for (; ; ) {
153
+ const { done: m, value: d } = await n.read();
154
+ if (m) break;
155
+ i += c.decode(d, { stream: !0 });
156
+ const p = i.split(`
157
+ `);
158
+ i = p.pop() || "";
159
+ for (const u of p) {
160
+ const h = u.trim();
161
+ if (h)
162
+ try {
163
+ const g = JSON.parse(h);
164
+ g.response && (yield g.response);
165
+ } catch {
166
+ continue;
167
+ }
168
+ }
169
+ }
170
+ }
171
+ async generateObject(o, s, r) {
172
+ const t = `${o}
173
+
174
+ IMPORTANT: Return ONLY valid JSON matching this schema:
175
+ ${JSON.stringify(s, null, 2)}
176
+
177
+ Do not include any explanation, only the raw JSON object.`, a = await this.generateText(t, r), n = a.match(/```json\n?([\s\S]*?)\n?```/) || a.match(/\{[\s\S]*\}/), c = n ? n[1] || n[0] : a;
178
+ return JSON.parse(c.trim());
179
+ }
180
+ async listModels(o, s = "http://localhost:11434") {
181
+ var a;
182
+ const r = await fetch(`${s}/api/tags`);
183
+ if (!r.ok)
184
+ throw new Error(`Failed to fetch Ollama models. Is Ollama running at ${s}?`);
185
+ return ((a = (await r.json()).models) == null ? void 0 : a.map((n) => n.name)) || [];
186
+ }
187
+ }
188
+ class O {
189
+ async generateText(o, s) {
190
+ var m, d, p;
191
+ const {
192
+ apiKey: r,
193
+ model: t = "claude-sonnet-4-5-20250929",
194
+ temperature: a = 0.7,
195
+ maxTokens: n = 4096,
196
+ baseUrl: c = "https://api.anthropic.com/v1"
197
+ } = s;
198
+ if (!r) throw new Error("Anthropic API key required");
199
+ if (!t) throw new Error("Model is required but was undefined");
200
+ console.log("🔵 Anthropic Request:", {
201
+ model: t,
202
+ maxTokens: n,
203
+ temperature: a,
204
+ endpoint: `${c}/messages`,
205
+ keyPrefix: r.slice(0, 12) + "…",
206
+ keyLength: r.length
207
+ });
208
+ const i = await fetch(`${c}/messages`, {
209
+ method: "POST",
210
+ headers: {
211
+ "Content-Type": "application/json",
212
+ "x-api-key": r,
213
+ "anthropic-version": "2023-06-01",
214
+ "anthropic-dangerous-direct-browser-access": "true"
215
+ },
216
+ body: JSON.stringify({
217
+ model: t,
218
+ messages: [{ role: "user", content: o }],
219
+ max_tokens: n,
220
+ // REQUIRED by Anthropic
221
+ temperature: a
222
+ })
223
+ });
224
+ if (!i.ok) {
225
+ const u = await i.text();
226
+ console.error("🔴 RAW ANTHROPIC ERROR:", i.status, u), console.error("🔴 Request was made to:", `${c}/messages`), console.error("🔴 Model requested:", t);
227
+ try {
228
+ const h = JSON.parse(u);
229
+ throw new Error(`Anthropic ${i.status}: ${((m = h.error) == null ? void 0 : m.message) || JSON.stringify(h)}`);
230
+ } catch {
231
+ throw new Error(`Anthropic ${i.status}: ${u}`);
232
+ }
233
+ }
234
+ return ((p = (d = (await i.json()).content) == null ? void 0 : d[0]) == null ? void 0 : p.text) || "";
235
+ }
236
+ async *streamText(o, s) {
237
+ var p, u;
238
+ const {
239
+ apiKey: r,
240
+ model: t = "claude-sonnet-4-5-20250929",
241
+ temperature: a = 0.7,
242
+ maxTokens: n = 4096,
243
+ baseUrl: c = "https://api.anthropic.com/v1"
244
+ } = s;
245
+ if (!r) throw new Error("Anthropic API key required");
246
+ if (!t) throw new Error("Model is required but was undefined");
247
+ const i = await fetch(`${c}/messages`, {
248
+ method: "POST",
249
+ headers: {
250
+ "Content-Type": "application/json",
251
+ "x-api-key": r,
252
+ "anthropic-version": "2023-06-01",
253
+ "anthropic-dangerous-direct-browser-access": "true"
254
+ },
255
+ body: JSON.stringify({
256
+ model: t,
257
+ messages: [{ role: "user", content: o }],
258
+ max_tokens: n,
259
+ // REQUIRED by Anthropic
260
+ temperature: a,
261
+ stream: !0
262
+ })
263
+ });
264
+ if (!i.ok) {
265
+ const h = await i.text();
266
+ console.error("🔴 RAW ANTHROPIC STREAM ERROR:", i.status, h), console.error("🔴 Request was made to:", `${c}/messages`), console.error("🔴 Model requested:", t);
267
+ try {
268
+ const g = JSON.parse(h);
269
+ throw new Error(`Anthropic ${i.status}: ${((p = g.error) == null ? void 0 : p.message) || JSON.stringify(g)}`);
270
+ } catch {
271
+ throw new Error(`Anthropic ${i.status}: ${h}`);
272
+ }
273
+ }
274
+ if (!i.body) throw new Error("No response body for streaming");
275
+ const l = i.body.getReader(), m = new TextDecoder();
276
+ let d = "";
277
+ try {
278
+ for (; ; ) {
279
+ const { done: h, value: g } = await l.read();
280
+ if (h) break;
281
+ d += m.decode(g, { stream: !0 });
282
+ const E = d.split(`
283
+ `);
284
+ d = E.pop() || "";
285
+ for (const f of E) {
286
+ const w = f.trim();
287
+ if (!w || !w.startsWith("data: ")) continue;
288
+ const y = w.slice(6);
289
+ try {
290
+ const T = JSON.parse(y);
291
+ T.type === "content_block_delta" && ((u = T.delta) != null && u.text) && (yield T.delta.text);
292
+ } catch {
293
+ continue;
294
+ }
295
+ }
296
+ }
297
+ } finally {
298
+ l.releaseLock();
299
+ }
300
+ }
301
+ async generateObject(o, s) {
302
+ var h, g, E;
303
+ const {
304
+ apiKey: r,
305
+ model: t = "claude-sonnet-4-5-20250929",
306
+ temperature: a = 0.7,
307
+ maxTokens: n = 4096,
308
+ baseUrl: c = "https://api.anthropic.com/v1"
309
+ } = s;
310
+ if (!r) throw new Error("Anthropic API key required");
311
+ if (!t) throw new Error("Model is required but was undefined");
312
+ const i = `${o}
313
+
314
+ IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the JSON object.`, l = await fetch(`${c}/messages`, {
315
+ method: "POST",
316
+ headers: {
317
+ "Content-Type": "application/json",
318
+ "x-api-key": r,
319
+ "anthropic-version": "2023-06-01",
320
+ "anthropic-dangerous-direct-browser-access": "true"
321
+ },
322
+ body: JSON.stringify({
323
+ model: t,
324
+ messages: [{ role: "user", content: i }],
325
+ max_tokens: n,
326
+ // REQUIRED by Anthropic
327
+ temperature: a
328
+ })
329
+ });
330
+ if (!l.ok) {
331
+ const f = await l.text();
332
+ console.error("🔴 RAW ANTHROPIC OBJECT ERROR:", l.status, f), console.error("🔴 Request was made to:", `${c}/messages`), console.error("🔴 Model requested:", t);
333
+ try {
334
+ const w = JSON.parse(f);
335
+ throw new Error(`Anthropic ${l.status}: ${((h = w.error) == null ? void 0 : h.message) || JSON.stringify(w)}`);
336
+ } catch {
337
+ throw new Error(`Anthropic ${l.status}: ${f}`);
338
+ }
339
+ }
340
+ const d = ((E = (g = (await l.json()).content) == null ? void 0 : g[0]) == null ? void 0 : E.text) || "{}", p = d.match(/\{[\s\S]*\}/), u = p ? p[0] : d;
341
+ return JSON.parse(u);
342
+ }
343
+ async listModels(o, s) {
344
+ return [
345
+ "claude-sonnet-4-5-20250929",
346
+ "claude-3-5-haiku-20241022",
347
+ "claude-3-opus-20240229",
348
+ "claude-3-sonnet-20240229",
349
+ "claude-3-haiku-20240307"
350
+ ];
351
+ }
352
+ normalizeError(o, s) {
353
+ var a;
354
+ const r = ((a = s.error) == null ? void 0 : a.message) || s.message || "Anthropic request failed";
355
+ if (o === 429) {
356
+ const n = new Error(`Rate limit exceeded: ${r}`);
357
+ return n.code = "RATE_LIMIT_EXCEEDED", n.status = 429, n;
358
+ }
359
+ if (o === 401 || o === 403) {
360
+ const n = new Error(`Authentication failed: ${r}`);
361
+ return n.code = "AUTH_ERROR", n.status = o, n;
362
+ }
363
+ if (o === 400) {
364
+ const n = new Error(`Bad request: ${r}`);
365
+ return n.code = "INVALID_REQUEST", n.status = 400, n;
366
+ }
367
+ const t = new Error(r);
368
+ return t.code = "API_ERROR", t.status = o, t;
369
+ }
370
+ }
371
+ class x {
372
+ async generateText(o, s) {
373
+ var l, m, d;
374
+ const { apiKey: r, model: t = "gpt-4o-mini", temperature: a = 0.7, baseUrl: n = "https://api.openai.com/v1" } = s;
375
+ if (!r) throw new Error("OpenAI API key required");
376
+ const c = await fetch(`${n}/chat/completions`, {
377
+ method: "POST",
378
+ headers: {
379
+ "Content-Type": "application/json",
380
+ Authorization: `Bearer ${r}`
381
+ },
382
+ body: JSON.stringify({
383
+ model: t,
384
+ messages: [{ role: "user", content: o }],
385
+ temperature: a
386
+ })
387
+ });
388
+ if (!c.ok) {
389
+ const p = await c.json();
390
+ throw this.normalizeError(c.status, p);
391
+ }
392
+ return ((d = (m = (l = (await c.json()).choices) == null ? void 0 : l[0]) == null ? void 0 : m.message) == null ? void 0 : d.content) || "";
393
+ }
394
+ async *streamText(o, s) {
395
+ var d, p, u;
396
+ const { apiKey: r, model: t = "gpt-4o-mini", temperature: a = 0.7, baseUrl: n = "https://api.openai.com/v1" } = s;
397
+ if (!r) throw new Error("OpenAI API key required");
398
+ const c = await fetch(`${n}/chat/completions`, {
399
+ method: "POST",
400
+ headers: {
401
+ "Content-Type": "application/json",
402
+ Authorization: `Bearer ${r}`
403
+ },
404
+ body: JSON.stringify({
405
+ model: t,
406
+ messages: [{ role: "user", content: o }],
407
+ temperature: a,
408
+ stream: !0
409
+ })
410
+ });
411
+ if (!c.ok) {
412
+ const h = await c.json();
413
+ throw this.normalizeError(c.status, h);
414
+ }
415
+ if (!c.body) throw new Error("No response body for streaming");
416
+ const i = c.body.getReader(), l = new TextDecoder();
417
+ let m = "";
418
+ try {
419
+ for (; ; ) {
420
+ const { done: h, value: g } = await i.read();
421
+ if (h) break;
422
+ m += l.decode(g, { stream: !0 });
423
+ const E = m.split(`
424
+ `);
425
+ m = E.pop() || "";
426
+ for (const f of E) {
427
+ const w = f.trim();
428
+ if (!w || !w.startsWith("data: ")) continue;
429
+ const y = w.slice(6);
430
+ if (y !== "[DONE]")
431
+ try {
432
+ const _ = (u = (p = (d = JSON.parse(y).choices) == null ? void 0 : d[0]) == null ? void 0 : p.delta) == null ? void 0 : u.content;
433
+ _ && (yield _);
434
+ } catch {
435
+ }
436
+ }
437
+ }
438
+ } finally {
439
+ i.releaseLock();
440
+ }
441
+ }
442
+ async generateObject(o, s, r) {
443
+ var d, p, u;
444
+ const { apiKey: t, model: a = "gpt-4o-mini", temperature: n = 0.7, baseUrl: c = "https://api.openai.com/v1" } = r;
445
+ if (!t) throw new Error("OpenAI API key required");
446
+ const i = await fetch(`${c}/chat/completions`, {
447
+ method: "POST",
448
+ headers: {
449
+ "Content-Type": "application/json",
450
+ Authorization: `Bearer ${t}`
451
+ },
452
+ body: JSON.stringify({
453
+ model: a,
454
+ messages: [{ role: "user", content: o }],
455
+ response_format: { type: "json_object" },
456
+ temperature: n
457
+ })
458
+ });
459
+ if (!i.ok) {
460
+ const h = await i.json();
461
+ throw this.normalizeError(i.status, h);
462
+ }
463
+ const m = ((u = (p = (d = (await i.json()).choices) == null ? void 0 : d[0]) == null ? void 0 : p.message) == null ? void 0 : u.content) || "{}";
464
+ return JSON.parse(m);
465
+ }
466
+ async listModels(o, s) {
467
+ var n, c;
468
+ const r = s || "https://api.openai.com/v1";
469
+ if (!o) throw new Error("OpenAI API key required");
470
+ const t = await fetch(`${r}/models`, {
471
+ headers: {
472
+ Authorization: `Bearer ${o}`
473
+ }
474
+ });
475
+ if (!t.ok) {
476
+ const i = await t.json();
477
+ throw this.normalizeError(t.status, i);
478
+ }
479
+ return ((c = (n = (await t.json()).data) == null ? void 0 : n.filter((i) => i.id.startsWith("gpt-"))) == null ? void 0 : c.map((i) => i.id)) || [];
480
+ }
481
+ normalizeError(o, s) {
482
+ var a;
483
+ const r = ((a = s.error) == null ? void 0 : a.message) || s.message || "OpenAI request failed";
484
+ if (o === 429) {
485
+ const n = new Error(`Rate limit exceeded: ${r}`);
486
+ return n.code = "RATE_LIMIT_EXCEEDED", n.status = 429, n;
487
+ }
488
+ if (o === 401 || o === 403) {
489
+ const n = new Error(`Authentication failed: ${r}`);
490
+ return n.code = "AUTH_ERROR", n.status = o, n;
491
+ }
492
+ const t = new Error(r);
493
+ return t.code = "API_ERROR", t.status = o, t;
494
+ }
495
+ }
496
+ class j {
497
+ async generateText(o, s) {
498
+ var l, m, d;
499
+ const { apiKey: r, model: t = "grok-beta", temperature: a = 0.7, baseUrl: n = "https://api.x.ai/v1" } = s;
500
+ if (!r) throw new Error("Grok API key required");
501
+ const c = await fetch(`${n}/chat/completions`, {
502
+ method: "POST",
503
+ headers: {
504
+ "Content-Type": "application/json",
505
+ Authorization: `Bearer ${r}`
506
+ },
507
+ body: JSON.stringify({
508
+ model: t,
509
+ messages: [{ role: "user", content: o }],
510
+ temperature: a
511
+ })
512
+ });
513
+ if (!c.ok) {
514
+ const p = await c.json();
515
+ throw this.normalizeError(c.status, p);
516
+ }
517
+ return ((d = (m = (l = (await c.json()).choices) == null ? void 0 : l[0]) == null ? void 0 : m.message) == null ? void 0 : d.content) || "";
518
+ }
519
+ async *streamText(o, s) {
520
+ var d, p, u;
521
+ const { apiKey: r, model: t = "grok-beta", temperature: a = 0.7, baseUrl: n = "https://api.x.ai/v1" } = s;
522
+ if (!r) throw new Error("Grok API key required");
523
+ const c = await fetch(`${n}/chat/completions`, {
524
+ method: "POST",
525
+ headers: {
526
+ "Content-Type": "application/json",
527
+ Authorization: `Bearer ${r}`
528
+ },
529
+ body: JSON.stringify({
530
+ model: t,
531
+ messages: [{ role: "user", content: o }],
532
+ temperature: a,
533
+ stream: !0
534
+ })
535
+ });
536
+ if (!c.ok) {
537
+ const h = await c.json();
538
+ throw this.normalizeError(c.status, h);
539
+ }
540
+ if (!c.body) throw new Error("No response body for streaming");
541
+ const i = c.body.getReader(), l = new TextDecoder();
542
+ let m = "";
543
+ try {
544
+ for (; ; ) {
545
+ const { done: h, value: g } = await i.read();
546
+ if (h) break;
547
+ m += l.decode(g, { stream: !0 });
548
+ const E = m.split(`
549
+ `);
550
+ m = E.pop() || "";
551
+ for (const f of E) {
552
+ const w = f.trim();
553
+ if (!w || !w.startsWith("data: ")) continue;
554
+ const y = w.slice(6);
555
+ if (y !== "[DONE]")
556
+ try {
557
+ const _ = (u = (p = (d = JSON.parse(y).choices) == null ? void 0 : d[0]) == null ? void 0 : p.delta) == null ? void 0 : u.content;
558
+ _ && (yield _);
559
+ } catch {
560
+ }
561
+ }
562
+ }
563
+ } finally {
564
+ i.releaseLock();
565
+ }
566
+ }
567
+ async generateObject(o, s, r) {
568
+ var h, g, E;
569
+ const { apiKey: t, model: a = "grok-beta", temperature: n = 0.7, baseUrl: c = "https://api.x.ai/v1" } = r;
570
+ if (!t) throw new Error("Grok API key required");
571
+ const i = `${o}
572
+
573
+ Respond with valid JSON only.`, l = await fetch(`${c}/chat/completions`, {
574
+ method: "POST",
575
+ headers: {
576
+ "Content-Type": "application/json",
577
+ Authorization: `Bearer ${t}`
578
+ },
579
+ body: JSON.stringify({
580
+ model: a,
581
+ messages: [{ role: "user", content: i }],
582
+ temperature: n
583
+ })
584
+ });
585
+ if (!l.ok) {
586
+ const f = await l.json();
587
+ throw this.normalizeError(l.status, f);
588
+ }
589
+ const d = ((E = (g = (h = (await l.json()).choices) == null ? void 0 : h[0]) == null ? void 0 : g.message) == null ? void 0 : E.content) || "{}", p = d.match(/\{[\s\S]*\}/), u = p ? p[0] : d;
590
+ return JSON.parse(u);
591
+ }
592
+ async listModels(o, s) {
593
+ return ["grok-beta", "grok-vision-beta"];
594
+ }
595
+ normalizeError(o, s) {
596
+ var a;
597
+ const r = ((a = s.error) == null ? void 0 : a.message) || s.message || "Grok request failed";
598
+ if (o === 429) {
599
+ const n = new Error(`Rate limit exceeded: ${r}`);
600
+ return n.code = "RATE_LIMIT_EXCEEDED", n.status = 429, n;
601
+ }
602
+ if (o === 401 || o === 403) {
603
+ const n = new Error(`Authentication failed: ${r}`);
604
+ return n.code = "AUTH_ERROR", n.status = o, n;
605
+ }
606
+ const t = new Error(r);
607
+ return t.code = "API_ERROR", t.status = o, t;
608
+ }
609
+ }
610
+ class P {
611
+ async generateText(o, s) {
612
+ var l, m, d;
613
+ const { apiKey: r, model: t = "deepseek-chat", temperature: a = 0.7, baseUrl: n = "https://api.deepseek.com/v1" } = s;
614
+ if (!r) throw new Error("DeepSeek API key required");
615
+ const c = await fetch(`${n}/chat/completions`, {
616
+ method: "POST",
617
+ headers: {
618
+ "Content-Type": "application/json",
619
+ Authorization: `Bearer ${r}`
620
+ },
621
+ body: JSON.stringify({
622
+ model: t,
623
+ messages: [{ role: "user", content: o }],
624
+ temperature: a
625
+ })
626
+ });
627
+ if (!c.ok) {
628
+ const p = await c.json();
629
+ throw this.normalizeError(c.status, p);
630
+ }
631
+ return ((d = (m = (l = (await c.json()).choices) == null ? void 0 : l[0]) == null ? void 0 : m.message) == null ? void 0 : d.content) || "";
632
+ }
633
+ async *streamText(o, s) {
634
+ var d, p, u;
635
+ const { apiKey: r, model: t = "deepseek-chat", temperature: a = 0.7, baseUrl: n = "https://api.deepseek.com/v1" } = s;
636
+ if (!r) throw new Error("DeepSeek API key required");
637
+ const c = await fetch(`${n}/chat/completions`, {
638
+ method: "POST",
639
+ headers: {
640
+ "Content-Type": "application/json",
641
+ Authorization: `Bearer ${r}`
642
+ },
643
+ body: JSON.stringify({
644
+ model: t,
645
+ messages: [{ role: "user", content: o }],
646
+ temperature: a,
647
+ stream: !0
648
+ })
649
+ });
650
+ if (!c.ok) {
651
+ const h = await c.json();
652
+ throw this.normalizeError(c.status, h);
653
+ }
654
+ if (!c.body) throw new Error("No response body for streaming");
655
+ const i = c.body.getReader(), l = new TextDecoder();
656
+ let m = "";
657
+ try {
658
+ for (; ; ) {
659
+ const { done: h, value: g } = await i.read();
660
+ if (h) break;
661
+ m += l.decode(g, { stream: !0 });
662
+ const E = m.split(`
663
+ `);
664
+ m = E.pop() || "";
665
+ for (const f of E) {
666
+ const w = f.trim();
667
+ if (!w || !w.startsWith("data: ")) continue;
668
+ const y = w.slice(6);
669
+ if (y !== "[DONE]")
670
+ try {
671
+ const _ = (u = (p = (d = JSON.parse(y).choices) == null ? void 0 : d[0]) == null ? void 0 : p.delta) == null ? void 0 : u.content;
672
+ _ && (yield _);
673
+ } catch {
674
+ }
675
+ }
676
+ }
677
+ } finally {
678
+ i.releaseLock();
679
+ }
680
+ }
681
+ async generateObject(o, s, r) {
682
+ var d, p, u;
683
+ const { apiKey: t, model: a = "deepseek-chat", temperature: n = 0.7, baseUrl: c = "https://api.deepseek.com/v1" } = r;
684
+ if (!t) throw new Error("DeepSeek API key required");
685
+ const i = await fetch(`${c}/chat/completions`, {
686
+ method: "POST",
687
+ headers: {
688
+ "Content-Type": "application/json",
689
+ Authorization: `Bearer ${t}`
690
+ },
691
+ body: JSON.stringify({
692
+ model: a,
693
+ messages: [{ role: "user", content: o }],
694
+ response_format: { type: "json_object" },
695
+ temperature: n
696
+ })
697
+ });
698
+ if (!i.ok) {
699
+ const h = await i.json();
700
+ throw this.normalizeError(i.status, h);
701
+ }
702
+ const m = ((u = (p = (d = (await i.json()).choices) == null ? void 0 : d[0]) == null ? void 0 : p.message) == null ? void 0 : u.content) || "{}";
703
+ return JSON.parse(m);
704
+ }
705
+ async listModels(o, s) {
706
+ return ["deepseek-chat", "deepseek-coder"];
707
+ }
708
+ normalizeError(o, s) {
709
+ var a;
710
+ const r = ((a = s.error) == null ? void 0 : a.message) || s.message || "DeepSeek request failed";
711
+ if (o === 429) {
712
+ const n = new Error(`Rate limit exceeded: ${r}`);
713
+ return n.code = "RATE_LIMIT_EXCEEDED", n.status = 429, n;
714
+ }
715
+ if (o === 401 || o === 403) {
716
+ const n = new Error(`Authentication failed: ${r}`);
717
+ return n.code = "AUTH_ERROR", n.status = o, n;
718
+ }
719
+ const t = new Error(r);
720
+ return t.code = "API_ERROR", t.status = o, t;
721
+ }
722
+ }
723
+ let N = class {
724
+ constructor(o) {
725
+ this.requests = [], this.config = o;
726
+ }
727
+ checkLimit() {
728
+ const o = Date.now(), s = o - this.config.windowMs;
729
+ return this.requests = this.requests.filter((r) => r > s), this.requests.length >= this.config.maxRequests ? !1 : (this.requests.push(o), !0);
730
+ }
731
+ getRemainingRequests() {
732
+ const s = Date.now() - this.config.windowMs;
733
+ return this.requests = this.requests.filter((r) => r > s), Math.max(0, this.config.maxRequests - this.requests.length);
734
+ }
735
+ getResetTime() {
736
+ return this.requests.length === 0 ? 0 : this.requests[0] + this.config.windowMs;
737
+ }
738
+ };
739
+ class k {
740
+ constructor() {
741
+ this.rateLimiter = new N({
742
+ maxRequests: 10,
743
+ windowMs: 6e4
744
+ }), this.adapters = /* @__PURE__ */ new Map([
745
+ ["google-gemini", new R()],
746
+ ["ollama", new S()],
747
+ ["anthropic", new O()],
748
+ ["openai", new x()],
749
+ ["grok", new j()],
750
+ ["deepseek", new P()]
751
+ ]);
752
+ }
753
+ static getInstance() {
754
+ return k.instance || (k.instance = new k()), k.instance;
755
+ }
756
+ /**
757
+ * Generate text with rate limiting and error handling
758
+ */
759
+ async generateText(o, s) {
760
+ if (!this.rateLimiter.checkLimit()) {
761
+ const t = this.rateLimiter.getResetTime(), a = new Error("Rate limit exceeded. Please wait before making another request.");
762
+ throw a.code = "RATE_LIMIT_EXCEEDED", a.resetTime = t, a;
763
+ }
764
+ const r = this.adapters.get(s.provider);
765
+ if (!r)
766
+ throw new Error(`Provider ${s.provider} not supported yet.`);
767
+ try {
768
+ return await r.generateText(o, s);
769
+ } catch (t) {
770
+ throw console.error("[AiGateway] Error:", t), t;
771
+ }
772
+ }
773
+ /**
774
+ * Stream text generation
775
+ */
776
+ async *streamText(o, s) {
777
+ if (!this.rateLimiter.checkLimit()) {
778
+ const t = new Error("Rate limit exceeded");
779
+ throw t.code = "RATE_LIMIT_EXCEEDED", t;
780
+ }
781
+ const r = this.adapters.get(s.provider);
782
+ if (!r)
783
+ throw new Error(`Provider ${s.provider} not supported yet.`);
784
+ yield* r.streamText(o, s);
785
+ }
786
+ /**
787
+ * Generate structured object (JSON mode)
788
+ */
789
+ async generateObject(o, s, r) {
790
+ if (!this.rateLimiter.checkLimit()) {
791
+ const a = new Error("Rate limit exceeded");
792
+ throw a.code = "RATE_LIMIT_EXCEEDED", a;
793
+ }
794
+ const t = this.adapters.get(r.provider);
795
+ if (!t)
796
+ throw new Error(`Provider ${r.provider} not supported yet.`);
797
+ return t.generateObject(o, s, r);
798
+ }
799
+ /**
800
+ * Get remaining requests before rate limit
801
+ */
802
+ getRemainingRequests() {
803
+ return this.rateLimiter.getRemainingRequests();
804
+ }
805
+ /**
806
+ * List available models for a provider
807
+ */
808
+ async listModels(o, s, r) {
809
+ const t = this.adapters.get(o);
810
+ if (!t)
811
+ throw new Error(`Provider ${o} not supported yet.`);
812
+ return t.listModels(s, r);
813
+ }
814
+ }
815
+ const Q = k.getInstance(), A = {};
816
+ class Z {
817
+ /**
818
+ * Resolve configuration with 3-tier priority:
819
+ * 1. User's localStorage override (highest priority)
820
+ * 2. App-level .env defaults
821
+ * 3. System defaults (fallback)
822
+ */
823
+ static resolve(o, s) {
824
+ const r = (o == null ? void 0 : o.provider) || (s == null ? void 0 : s.provider) || "ollama", t = (o == null ? void 0 : o.model) || (s == null ? void 0 : s.model) || this.getDefaultModel(r), a = (o == null ? void 0 : o.apiKey) || (s == null ? void 0 : s.apiKey), n = (o == null ? void 0 : o.ollamaUrl) || (s == null ? void 0 : s.ollamaUrl) || "http://localhost:11434";
825
+ if (r !== "ollama" && !a)
826
+ throw new Error(`API key required for provider: ${r}`);
827
+ return {
828
+ provider: r,
829
+ model: t,
830
+ apiKey: a,
831
+ baseUrl: r === "ollama" ? n : void 0
832
+ };
833
+ }
834
+ static getDefaultModel(o) {
835
+ return {
836
+ "google-gemini": "gemini-2.0-flash",
837
+ openai: "gpt-4o-mini",
838
+ anthropic: "claude-sonnet-4-5-20250929",
839
+ grok: "grok-2-1212",
840
+ deepseek: "deepseek-chat",
841
+ ollama: "llama3.2"
842
+ }[o];
843
+ }
844
+ /**
845
+ * Load user preferences from localStorage (client-side)
846
+ */
847
+ static loadUserConfig() {
848
+ if (!(typeof window > "u"))
849
+ return {
850
+ provider: localStorage.getItem("app_ai_provider"),
851
+ model: localStorage.getItem("app_ai_model") || void 0,
852
+ apiKey: localStorage.getItem("app_ai_api_key") || void 0,
853
+ ollamaUrl: localStorage.getItem("app_ollama_url") || void 0
854
+ };
855
+ }
856
+ /**
857
+ * Returns the env key for a specific provider — for REQUEST FLOW ONLY.
858
+ * Never call this from UI components; use hasEnvKey() for status badges.
859
+ */
860
+ static getEnvKeyForProvider(o) {
861
+ var r, t, a, n, c;
862
+ if (typeof import.meta < "u" && A) {
863
+ const i = A, l = (d) => (d == null ? void 0 : d.trim()) || void 0;
864
+ return {
865
+ "google-gemini": l(i == null ? void 0 : i.VITE_DEFAULT_GEMINI_KEY),
866
+ openai: l(i == null ? void 0 : i.VITE_DEFAULT_OPENAI_KEY),
867
+ anthropic: l(i == null ? void 0 : i.VITE_DEFAULT_ANTHROPIC_KEY),
868
+ grok: l(i == null ? void 0 : i.VITE_DEFAULT_GROK_KEY),
869
+ deepseek: l(i == null ? void 0 : i.VITE_DEFAULT_DEEPSEEK_KEY)
870
+ }[o];
871
+ }
872
+ if (typeof process < "u" && process.env)
873
+ return {
874
+ "google-gemini": (r = process.env.VITE_DEFAULT_GEMINI_KEY) == null ? void 0 : r.trim(),
875
+ openai: (t = process.env.VITE_DEFAULT_OPENAI_KEY) == null ? void 0 : t.trim(),
876
+ anthropic: (a = process.env.VITE_DEFAULT_ANTHROPIC_KEY) == null ? void 0 : a.trim(),
877
+ grok: (n = process.env.VITE_DEFAULT_GROK_KEY) == null ? void 0 : n.trim(),
878
+ deepseek: (c = process.env.VITE_DEFAULT_DEEPSEEK_KEY) == null ? void 0 : c.trim()
879
+ }[o];
880
+ }
881
+ /**
882
+ * Returns true if an env key exists for the given provider — boolean only,
883
+ * value never exposed. Safe to call from UI components for status badges.
884
+ */
885
+ static hasEnvKey(o) {
886
+ if (typeof import.meta < "u" && A) {
887
+ const r = A, t = (n) => (n == null ? void 0 : n.trim()) || void 0;
888
+ return !!{
889
+ "google-gemini": t(r == null ? void 0 : r.VITE_DEFAULT_GEMINI_KEY),
890
+ openai: t(r == null ? void 0 : r.VITE_DEFAULT_OPENAI_KEY),
891
+ anthropic: t(r == null ? void 0 : r.VITE_DEFAULT_ANTHROPIC_KEY),
892
+ grok: t(r == null ? void 0 : r.VITE_DEFAULT_GROK_KEY),
893
+ deepseek: t(r == null ? void 0 : r.VITE_DEFAULT_DEEPSEEK_KEY)
894
+ }[o];
895
+ }
896
+ return typeof process < "u" && process.env ? !!{
897
+ "google-gemini": process.env.VITE_DEFAULT_GEMINI_KEY || process.env.NEXT_PUBLIC_GEMINI_KEY,
898
+ openai: process.env.VITE_DEFAULT_OPENAI_KEY || process.env.NEXT_PUBLIC_OPENAI_KEY,
899
+ anthropic: process.env.VITE_DEFAULT_ANTHROPIC_KEY || process.env.NEXT_PUBLIC_ANTHROPIC_KEY
900
+ }[o] : !1;
901
+ }
902
+ /**
903
+ * Load app defaults from environment variables
904
+ * Note: This works differently in Vite vs Next.js
905
+ */
906
+ static loadAppDefaults() {
907
+ var s, r;
908
+ if (typeof import.meta < "u" && A) {
909
+ const t = A, a = (t == null ? void 0 : t.VITE_DEFAULT_AI_PROVIDER) || "", n = (d) => (d == null ? void 0 : d.trim()) || void 0, c = {
910
+ "google-gemini": n(t == null ? void 0 : t.VITE_DEFAULT_GEMINI_KEY),
911
+ openai: n(t == null ? void 0 : t.VITE_DEFAULT_OPENAI_KEY),
912
+ anthropic: n(t == null ? void 0 : t.VITE_DEFAULT_ANTHROPIC_KEY),
913
+ grok: n(t == null ? void 0 : t.VITE_DEFAULT_GROK_KEY),
914
+ deepseek: n(t == null ? void 0 : t.VITE_DEFAULT_DEEPSEEK_KEY)
915
+ };
916
+ let i = a || "ollama";
917
+ const m = ["google-gemini", "anthropic", "openai", "grok", "deepseek"].filter((d) => !!c[d]);
918
+ return i === "ollama" && m.length > 0 && (i = m[0]), {
919
+ provider: i,
920
+ model: t == null ? void 0 : t.VITE_DEFAULT_AI_MODEL,
921
+ apiKey: c[i],
922
+ ollamaUrl: t == null ? void 0 : t.VITE_DEFAULT_OLLAMA_URL
923
+ };
924
+ }
925
+ return typeof process < "u" && process.env ? {
926
+ provider: (s = process.env) == null ? void 0 : s.NEXT_PUBLIC_DEFAULT_AI_PROVIDER,
927
+ model: (r = process.env) == null ? void 0 : r.NEXT_PUBLIC_DEFAULT_AI_MODEL
928
+ } : {};
929
+ }
930
+ }
931
+ class q {
932
+ constructor(o) {
933
+ this.requests = [], this.config = o;
934
+ }
935
+ checkLimit() {
936
+ const o = Date.now(), s = o - this.config.windowMs;
937
+ return this.requests = this.requests.filter((r) => r > s), this.requests.length >= this.config.maxRequests ? !1 : (this.requests.push(o), !0);
938
+ }
939
+ getRemainingRequests() {
940
+ const s = Date.now() - this.config.windowMs;
941
+ return this.requests = this.requests.filter((r) => r > s), Math.max(0, this.config.maxRequests - this.requests.length);
942
+ }
943
+ getResetTime() {
944
+ return this.requests.length === 0 ? 0 : this.requests[0] + this.config.windowMs;
945
+ }
946
+ }
947
+ class $ {
948
+ constructor(o = { maxRequests: 10, windowMs: 6e4 }) {
949
+ this.rateLimiter = new q(o);
950
+ }
951
+ async makeRequest(o, s) {
952
+ if (!this.rateLimiter.checkLimit()) {
953
+ const r = this.rateLimiter.getResetTime(), t = new Error("Rate limit exceeded. Please wait before making another request.");
954
+ throw t.code = "RATE_LIMIT_EXCEEDED", t.resetTime = r, s && s(r), t;
955
+ }
956
+ return await o();
957
+ }
958
+ getRemainingRequests() {
959
+ return this.rateLimiter.getRemainingRequests();
960
+ }
961
+ }
962
+ const ee = new $({ maxRequests: 10, windowMs: 6e4 });
963
+ var L = Object.defineProperty, M = (b, o) => {
964
+ for (var s in o)
965
+ L(b, s, { get: o[s], enumerable: !0 });
966
+ }, D = e.object({
967
+ key: e.string(),
968
+ label: e.string(),
969
+ type: e.enum(["text", "number", "currency", "date", "boolean", "status", "email", "image", "textarea"]),
970
+ required: e.boolean().optional(),
971
+ description: e.string().optional(),
972
+ defaultValue: e.any().optional()
973
+ }), U = e.object({
974
+ id: e.string(),
975
+ name: e.string(),
976
+ fields: e.array(D),
977
+ defaultView: e.enum(["table", "grid", "list"]).optional(),
978
+ features: e.object({
979
+ searchable: e.boolean().optional(),
980
+ creatable: e.boolean().optional(),
981
+ editable: e.boolean().optional(),
982
+ deletable: e.boolean().optional(),
983
+ exportable: e.boolean().optional()
984
+ }).optional()
985
+ }), K = e.object({
986
+ id: e.string().min(1, "Signal ID is required"),
987
+ label: e.string(),
988
+ description: e.string().optional(),
989
+ kind: e.enum(["sensor", "actuator", "setpoint", "metric", "status", "kpi"]),
990
+ source: e.enum(["mock", "mqtt", "http", "derived", "local"]),
991
+ // Connectivity
992
+ topic: e.string().optional(),
993
+ endpoint: e.string().optional(),
994
+ jsonPath: e.string().optional(),
995
+ refreshRate: e.number().optional().default(1e3),
996
+ // Values
997
+ defaultValue: e.any().optional(),
998
+ unit: e.string().optional(),
999
+ min: e.number().optional(),
1000
+ max: e.number().optional()
1001
+ }), v = e.object({
1002
+ id: e.string(),
1003
+ name: e.string(),
1004
+ description: e.string().optional(),
1005
+ type: e.string(),
1006
+ category: e.string().default("logical"),
1007
+ signals: e.array(e.string()),
1008
+ ui: e.object({
1009
+ icon: e.string().optional(),
1010
+ color: e.string().optional(),
1011
+ dashboardComponent: e.string().optional()
1012
+ }).optional()
1013
+ }), C = e.object({
1014
+ id: e.string(),
1015
+ type: e.enum(["signal_change", "manual_action", "schedule", "webhook"]),
1016
+ config: e.record(e.string(), e.any())
1017
+ }), J = e.object({
1018
+ id: e.string(),
1019
+ type: e.enum([
1020
+ "update_resource",
1021
+ "send_notification",
1022
+ "mqtt_publish",
1023
+ "api_call",
1024
+ "navigate",
1025
+ "agent_task"
1026
+ ]),
1027
+ config: e.record(e.string(), e.any())
1028
+ }), V = e.object({
1029
+ id: e.string(),
1030
+ name: e.string(),
1031
+ active: e.boolean().default(!0),
1032
+ trigger: C,
1033
+ actions: e.array(J)
1034
+ }), F = e.object({
1035
+ id: e.string(),
1036
+ type: e.string(),
1037
+ props: e.record(e.string(), e.any()),
1038
+ layout: e.object({
1039
+ colSpan: e.number().optional(),
1040
+ rowSpan: e.number().optional()
1041
+ }).optional()
1042
+ }), Y = e.object({
1043
+ id: e.string(),
1044
+ title: e.string().optional(),
1045
+ description: e.string().optional(),
1046
+ layout: e.object({
1047
+ columns: e.number().optional(),
1048
+ variant: e.enum(["grid", "stack", "split"]).optional()
1049
+ }).optional(),
1050
+ blocks: e.array(F)
1051
+ }), z = e.object({
1052
+ id: e.string(),
1053
+ slug: e.string(),
1054
+ title: e.string(),
1055
+ description: e.string().optional(),
1056
+ icon: e.string().optional(),
1057
+ sections: e.array(Y)
1058
+ }), te = e.object({
1059
+ meta: e.object({
1060
+ name: e.string(),
1061
+ version: e.string(),
1062
+ description: e.string().optional(),
1063
+ author: e.string().optional(),
1064
+ createdAt: e.string().optional()
1065
+ }),
1066
+ config: e.object({
1067
+ theme: e.enum(["light", "dark", "system", "corporate", "midnight", "blueprint"]).default("system"),
1068
+ mockMode: e.boolean().default(!0),
1069
+ brokerUrl: e.string().optional()
1070
+ }),
1071
+ modules: e.array(e.string()).optional(),
1072
+ resources: e.array(U).optional(),
1073
+ domain: e.object({
1074
+ signals: e.array(K),
1075
+ entities: e.array(v),
1076
+ workflows: e.array(V).optional()
1077
+ }),
1078
+ pages: e.array(z).optional()
1079
+ }), re = e.object({
1080
+ timestamp: e.number(),
1081
+ soilMoisture: e.number().min(0).max(100),
1082
+ ambientLight: e.number().min(0).max(1e5),
1083
+ temperature: e.number().min(-40).max(125)
1084
+ }), G = {};
1085
+ M(G, {
1086
+ BodewellCommandSchema: () => H,
1087
+ BodewellDeviceID: () => I,
1088
+ BodewellTelemetrySchema: () => B
1089
+ });
1090
+ var I = e.enum([
1091
+ "STK-V1-001",
1092
+ "STK-V1-002",
1093
+ "STK-V1-003",
1094
+ "STK-PRO-001",
1095
+ "STK-VIS-001"
1096
+ ]), B = e.object({
1097
+ device_id: I,
1098
+ stick_id: e.string().optional().describe("Firmware alias for device_id"),
1099
+ timestamp: e.number().optional().describe("Epoch timestamp from NTP"),
1100
+ air_temp: e.number().optional().describe("Celsius"),
1101
+ air_humid: e.number().optional().describe("Relative Humidity %"),
1102
+ humidity: e.number().optional().describe("Firmware alias for air_humid"),
1103
+ air_pressure: e.number().optional().describe("hPa"),
1104
+ pressure: e.number().optional().describe("Firmware alias for air_pressure"),
1105
+ light_lux: e.number().optional().describe("Lux level"),
1106
+ soil_temp_stemma: e.number().optional().describe("Celsius"),
1107
+ soil_vwc: e.number().describe("Volumetric Water Content / Raw Capacitance"),
1108
+ soil_moisture: e.number().optional().describe("Firmware alias for raw capacitance"),
1109
+ soil_moisture_raw: e.number().optional().describe("Unscaled capacitance (300-1100)")
1110
+ }).passthrough(), H = e.object({
1111
+ stick_id: I,
1112
+ // Note: Your API uses stick_id here, not device_id
1113
+ type: e.enum(["dry", "wet"]),
1114
+ value: e.number()
1115
+ });
1116
+ e.object({
1117
+ deviceId: e.string().min(1, "Device ID is required"),
1118
+ timeRange: e.enum(["1h", "24h", "7d"], {
1119
+ errorMap: () => ({ message: "Time range must be 1h, 24h, or 7d" })
1120
+ }),
1121
+ metrics: e.array(
1122
+ e.enum(["temperature", "humidity", "vwc", "ec", "ph", "pressure", "co2"])
1123
+ ).min(1, "At least one metric is required").max(4, "Maximum 4 metrics per graph")
1124
+ });
1125
+ e.object({
1126
+ ticker: e.string().min(1).describe("The stock ticker symbol explicitly requested by the user. YOU MUST EXTRACT AND PROVIDE THIS (e.g., 'AAPL', 'MSFT')."),
1127
+ timeRange: e.enum(["1D", "1W", "1M", "1Y"], {
1128
+ errorMap: () => ({ message: "Time range must be 1D, 1W, 1M, or 1Y" })
1129
+ }).describe("The time range for the chart. Choose based on user request or default to '1M'."),
1130
+ metrics: e.array(e.enum(["price", "volume", "moving_average"])).min(1, "At least one metric is required").describe("Array of metrics to display. Always include 'price' and 'volume' unless user specifies otherwise.")
1131
+ });
1132
+ export {
1133
+ k as A,
1134
+ F as B,
1135
+ P as D,
1136
+ v as E,
1137
+ D as F,
1138
+ R as G,
1139
+ N as I,
1140
+ S as O,
1141
+ Y as P,
1142
+ U as R,
1143
+ K as S,
1144
+ C as T,
1145
+ V as W,
1146
+ Q as a,
1147
+ Z as b,
1148
+ O as c,
1149
+ x as d,
1150
+ j as e,
1151
+ $ as f,
1152
+ ee as g,
1153
+ J as h,
1154
+ z as i,
1155
+ te as j,
1156
+ re as k
1157
+ };