@ramme-io/kernel 7.2.0 → 7.3.1
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/AiGateway-Bdcl3v8h.js +2534 -0
- package/dist/bodewellAdapter-BzbeTSIP.js +214 -0
- package/dist/index-kBkq1FSR.js +1236 -0
- package/dist/index.es.js +3330 -3429
- package/dist/kernel/src/index.d.ts +1 -0
- package/dist/kernel/src/index.d.ts.map +1 -1
- package/dist/kernel/src/services/ai/providers/adapter-errors.test.d.ts +2 -0
- package/dist/kernel/src/services/ai/providers/adapter-errors.test.d.ts.map +1 -0
- package/dist/kernel/src/signals/bodewellAdapter.d.ts +142 -0
- package/dist/kernel/src/signals/bodewellAdapter.d.ts.map +1 -0
- package/dist/kernel/src/signals/bodewellAdapter.test.d.ts +2 -0
- package/dist/kernel/src/signals/bodewellAdapter.test.d.ts.map +1 -0
- package/dist/kernel/src/signals/index.d.ts +21 -0
- package/dist/kernel/src/signals/index.d.ts.map +1 -0
- package/dist/server.es.js +47 -45
- package/dist/signals.d.ts +1 -0
- package/dist/signals.es.js +13 -0
- package/package.json +8 -4
- package/dist/AiGateway-ujqOJuoj.js +0 -3740
|
@@ -1,3740 +0,0 @@
|
|
|
1
|
-
import { z as e } from "zod";
|
|
2
|
-
const qr = {
|
|
3
|
-
// ── ROOM 1: STRATEGY OFFICE ──────────────────────────────────────
|
|
4
|
-
strategist: {
|
|
5
|
-
id: "strategist",
|
|
6
|
-
name: "Strategic Advisor",
|
|
7
|
-
role: "Defines the product vision, user personas, and core value proposition",
|
|
8
|
-
color: "bg-accent-1",
|
|
9
|
-
scope: ["meta"],
|
|
10
|
-
systemPrompt: `
|
|
11
|
-
You are a world-class Strategic Product Advisor embedded in the Ramme Build Kit.
|
|
12
|
-
Your sole mission: help the user achieve clarity on WHAT they are building and WHO it serves.
|
|
13
|
-
|
|
14
|
-
RULES:
|
|
15
|
-
1. Ask one clarifying question at a time. Never ask multiple questions in a single message.
|
|
16
|
-
2. Focus exclusively on: App type, target user, core problem, and success metric.
|
|
17
|
-
3. When you have enough clarity (after 3-5 exchanges), output a structured "## Project Brief"
|
|
18
|
-
markdown section with the following format:
|
|
19
|
-
|
|
20
|
-
## Project Brief
|
|
21
|
-
**App Name:** [Name]
|
|
22
|
-
**Type:** [SaaS / IoT Dashboard / Internal Tool / etc.]
|
|
23
|
-
**Target User:** [Who uses this]
|
|
24
|
-
**Core Problem:** [What problem it solves]
|
|
25
|
-
**Success Metric:** [How we know it's working]
|
|
26
|
-
**Key Entities:** [The 2-4 main data objects, e.g., Users, Invoices, Sensors]
|
|
27
|
-
|
|
28
|
-
4. FORBIDDEN: Do NOT discuss UI layouts, colors, components, or technical implementation.
|
|
29
|
-
That is the Designer's and Architect's domain.
|
|
30
|
-
5. SCOPE: You may ONLY suggest changes to the manifest's \`meta\` field.
|
|
31
|
-
`.trim()
|
|
32
|
-
},
|
|
33
|
-
// ── ROOM 2: ENGINE ROOM ──────────────────────────────────────────
|
|
34
|
-
architect: {
|
|
35
|
-
id: "architect",
|
|
36
|
-
name: "Domain Architect",
|
|
37
|
-
role: "Designs the data schema, resource definitions, signals, and workflow logic",
|
|
38
|
-
color: "bg-accent-3",
|
|
39
|
-
scope: ["resources", "domain", "config"],
|
|
40
|
-
systemPrompt: `
|
|
41
|
-
You are a Domain Architect embedded in the Ramme Build Kit.
|
|
42
|
-
Your mission: design a robust, normalized data schema based on the user's requirements.
|
|
43
|
-
|
|
44
|
-
You operate on the manifest's \`resources\` and \`domain\` fields.
|
|
45
|
-
You respond with a structured JSON patch and a brief explanation.
|
|
46
|
-
|
|
47
|
-
RULES:
|
|
48
|
-
1. Always return a response in this exact JSON structure:
|
|
49
|
-
{ "patch": { "resources": [...], "domain": { ... } }, "reply": "...", "suggestions": ["...", "..."] }
|
|
50
|
-
2. Resources MUST follow the AppSpecification schema:
|
|
51
|
-
- id: snake_case string
|
|
52
|
-
- name: human-readable string
|
|
53
|
-
- fields: array of { key, label, type, required? }
|
|
54
|
-
- Field types: text | number | email | status | date | boolean | currency | image | textarea
|
|
55
|
-
3. When adding a resource, always include an \`id\` field (type: "text").
|
|
56
|
-
4. FORBIDDEN: Do NOT suggest changes to \`pages\`, \`meta\`, or \`theme\`. That is not your domain.
|
|
57
|
-
5. If the user's request is unclear, ask one targeted clarifying question before generating.
|
|
58
|
-
`.trim()
|
|
59
|
-
},
|
|
60
|
-
// ── ROOM 4: INTERFACE ROOM ───────────────────────────────────────
|
|
61
|
-
designer: {
|
|
62
|
-
id: "designer",
|
|
63
|
-
name: "Interface Designer",
|
|
64
|
-
role: "Assembles pages, sections, and blocks from the AppSpecification pattern library",
|
|
65
|
-
color: "bg-accent-2",
|
|
66
|
-
scope: ["pages", "theme"],
|
|
67
|
-
systemPrompt: `
|
|
68
|
-
You are an Interface Designer embedded in the Ramme Build Kit.
|
|
69
|
-
Your mission: assemble UI pages from the available block components and pattern library.
|
|
70
|
-
|
|
71
|
-
You operate exclusively on the manifest's \`pages\` field.
|
|
72
|
-
|
|
73
|
-
RULES:
|
|
74
|
-
1. Use ONLY these block types: SmartTable, StatCard, DeviceCard, BarChart, LineChart,
|
|
75
|
-
PieChart, ActivityFeed, AutoForm, FormTemplate, Card, SectionHeader, PageHeader,
|
|
76
|
-
Accordion, EmptyState, Button, ChatFAB.
|
|
77
|
-
2. Connect blocks to data using \`props.dataId\` (must match a resource.id).
|
|
78
|
-
3. Connect blocks to IoT signals using \`props.signalId\` (must match a domain.signals[].id).
|
|
79
|
-
4. Follow layout conventions from the pattern library:
|
|
80
|
-
- Dashboard → 4-column KPI grid + 2-column chart row
|
|
81
|
-
- Collection → single-column SmartTable
|
|
82
|
-
- Detail → single-column AutoForm
|
|
83
|
-
5. FORBIDDEN: Do NOT invent new block types. Do NOT modify \`resources\` or \`domain\`.
|
|
84
|
-
6. Always return a \`pages\` array patch.
|
|
85
|
-
`.trim()
|
|
86
|
-
},
|
|
87
|
-
// ── AUDIT ROOM ───────────────────────────────────────────────────
|
|
88
|
-
product_owner: {
|
|
89
|
-
id: "product_owner",
|
|
90
|
-
name: "Product Owner",
|
|
91
|
-
role: "Audits the full manifest for consistency, completeness, and quality",
|
|
92
|
-
color: "bg-accent-4",
|
|
93
|
-
scope: ["meta", "config", "resources", "domain", "pages", "theme", "modules"],
|
|
94
|
-
systemPrompt: `
|
|
95
|
-
You are a Product Owner embedded in the Ramme Build Kit.
|
|
96
|
-
Your mission: audit the complete AppSpecification manifest for quality and correctness.
|
|
97
|
-
|
|
98
|
-
You have READ access to all manifest fields. You SUGGEST changes but do not apply them directly.
|
|
99
|
-
|
|
100
|
-
AUDIT CHECKLIST:
|
|
101
|
-
1. Every page block with a \`dataId\` — does the resource exist in \`manifest.resources\`?
|
|
102
|
-
2. Every workflow trigger — does the referenced signal/resource exist?
|
|
103
|
-
3. Is the navigation structure appropriate for the number of pages?
|
|
104
|
-
4. Are field types semantically correct? (e.g., email fields use type "email", not "text")
|
|
105
|
-
5. Is there a Dashboard page with KPI StatCards for the primary resources?
|
|
106
|
-
6. Are there any orphaned resources (defined but never used in any page block)?
|
|
107
|
-
|
|
108
|
-
OUTPUT FORMAT:
|
|
109
|
-
Provide a structured audit report with:
|
|
110
|
-
- ✅ Passing checks
|
|
111
|
-
- ⚠️ Warnings (non-breaking inconsistencies)
|
|
112
|
-
- ❌ Errors (broken references that will cause runtime failures)
|
|
113
|
-
- 💡 Suggestions (improvements not required but recommended)
|
|
114
|
-
`.trim()
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
var Oe = Object.defineProperty, Pe = (a, t) => {
|
|
118
|
-
for (var n in t)
|
|
119
|
-
Oe(a, n, { get: t[n], enumerable: !0 });
|
|
120
|
-
}, Re = e.object({
|
|
121
|
-
key: e.string(),
|
|
122
|
-
label: e.string(),
|
|
123
|
-
type: e.enum(["text", "number", "currency", "percent", "delta", "date", "boolean", "status", "email", "image", "textarea"]),
|
|
124
|
-
required: e.boolean().optional(),
|
|
125
|
-
description: e.string().optional(),
|
|
126
|
-
defaultValue: e.any().optional()
|
|
127
|
-
}), Ie = e.object({
|
|
128
|
-
id: e.string(),
|
|
129
|
-
name: e.string(),
|
|
130
|
-
fields: e.array(Re),
|
|
131
|
-
defaultView: e.enum(["table", "grid", "list"]).optional(),
|
|
132
|
-
features: e.object({
|
|
133
|
-
searchable: e.boolean().optional(),
|
|
134
|
-
creatable: e.boolean().optional(),
|
|
135
|
-
editable: e.boolean().optional(),
|
|
136
|
-
deletable: e.boolean().optional(),
|
|
137
|
-
exportable: e.boolean().optional()
|
|
138
|
-
}).optional()
|
|
139
|
-
}), Ne = e.object({
|
|
140
|
-
id: e.string().min(1, "Signal ID is required"),
|
|
141
|
-
label: e.string(),
|
|
142
|
-
description: e.string().optional(),
|
|
143
|
-
kind: e.enum(["sensor", "actuator", "setpoint", "metric", "status", "kpi"]),
|
|
144
|
-
source: e.enum(["mock", "mqtt", "http", "derived", "local"]),
|
|
145
|
-
// Connectivity
|
|
146
|
-
topic: e.string().optional(),
|
|
147
|
-
endpoint: e.string().optional(),
|
|
148
|
-
jsonPath: e.string().optional(),
|
|
149
|
-
refreshRate: e.number().optional().default(1e3),
|
|
150
|
-
// Values
|
|
151
|
-
defaultValue: e.any().optional(),
|
|
152
|
-
unit: e.string().optional(),
|
|
153
|
-
min: e.number().optional(),
|
|
154
|
-
max: e.number().optional()
|
|
155
|
-
}), $e = e.object({
|
|
156
|
-
id: e.string(),
|
|
157
|
-
name: e.string(),
|
|
158
|
-
description: e.string().optional(),
|
|
159
|
-
type: e.string(),
|
|
160
|
-
category: e.string().default("logical"),
|
|
161
|
-
signals: e.array(e.string()),
|
|
162
|
-
ui: e.object({
|
|
163
|
-
icon: e.string().optional(),
|
|
164
|
-
color: e.string().optional(),
|
|
165
|
-
dashboardComponent: e.string().optional()
|
|
166
|
-
}).optional()
|
|
167
|
-
}), Ce = e.object({
|
|
168
|
-
id: e.string(),
|
|
169
|
-
type: e.enum(["signal_change", "manual_action", "schedule", "webhook"]),
|
|
170
|
-
config: e.record(e.string(), e.any())
|
|
171
|
-
}), De = e.object({
|
|
172
|
-
id: e.string(),
|
|
173
|
-
type: e.enum([
|
|
174
|
-
"update_resource",
|
|
175
|
-
"send_notification",
|
|
176
|
-
"mqtt_publish",
|
|
177
|
-
"api_call",
|
|
178
|
-
"navigate",
|
|
179
|
-
"agent_task"
|
|
180
|
-
]),
|
|
181
|
-
config: e.record(e.string(), e.any())
|
|
182
|
-
}), Me = e.object({
|
|
183
|
-
id: e.string(),
|
|
184
|
-
name: e.string(),
|
|
185
|
-
active: e.boolean().default(!0),
|
|
186
|
-
trigger: Ce,
|
|
187
|
-
actions: e.array(De)
|
|
188
|
-
}), Be = e.object({
|
|
189
|
-
id: e.string(),
|
|
190
|
-
type: e.string(),
|
|
191
|
-
props: e.record(e.string(), e.any()),
|
|
192
|
-
layout: e.object({
|
|
193
|
-
colSpan: e.number().optional(),
|
|
194
|
-
rowSpan: e.number().optional()
|
|
195
|
-
}).optional()
|
|
196
|
-
}), Le = e.object({
|
|
197
|
-
id: e.string(),
|
|
198
|
-
title: e.string().optional(),
|
|
199
|
-
description: e.string().optional(),
|
|
200
|
-
layout: e.object({
|
|
201
|
-
columns: e.number().optional(),
|
|
202
|
-
variant: e.enum(["grid", "stack", "split"]).optional()
|
|
203
|
-
}).optional(),
|
|
204
|
-
blocks: e.array(Be)
|
|
205
|
-
}), qe = e.object({
|
|
206
|
-
id: e.string(),
|
|
207
|
-
slug: e.string(),
|
|
208
|
-
title: e.string(),
|
|
209
|
-
description: e.string().optional(),
|
|
210
|
-
icon: e.string().optional(),
|
|
211
|
-
sections: e.array(Le)
|
|
212
|
-
}), Ue = e.enum(["ENVIRONMENT", "SESSION_BYOK", "VAULT"]), Ze = e.object({
|
|
213
|
-
strategy: Ue,
|
|
214
|
-
status: e.enum(["VALID", "KEY_EXPIRED", "BYOK_REQUIRED", "DEGRADED", "UNKNOWN"]).default("UNKNOWN")
|
|
215
|
-
}), Ur = e.object({
|
|
216
|
-
meta: e.object({
|
|
217
|
-
name: e.string(),
|
|
218
|
-
version: e.string(),
|
|
219
|
-
description: e.string().optional(),
|
|
220
|
-
author: e.string().optional(),
|
|
221
|
-
createdAt: e.string().optional()
|
|
222
|
-
}),
|
|
223
|
-
config: e.object({
|
|
224
|
-
theme: e.enum(["light", "dark", "system", "corporate", "midnight", "blueprint"]).default("system"),
|
|
225
|
-
layout: e.enum(["dashboard", "explorer", "studio", "focus"]).default("dashboard"),
|
|
226
|
-
mockMode: e.boolean().default(!0),
|
|
227
|
-
brokerUrl: e.string().optional(),
|
|
228
|
-
aiKeyManifest: Ze.optional()
|
|
229
|
-
}),
|
|
230
|
-
modules: e.array(e.string()).optional(),
|
|
231
|
-
resources: e.array(Ie).optional(),
|
|
232
|
-
domain: e.object({
|
|
233
|
-
signals: e.array(Ne),
|
|
234
|
-
entities: e.array($e),
|
|
235
|
-
workflows: e.array(Me).optional()
|
|
236
|
-
}),
|
|
237
|
-
pages: e.array(qe).optional()
|
|
238
|
-
}), Zr = e.object({
|
|
239
|
-
timestamp: e.number(),
|
|
240
|
-
soilMoisture: e.number().min(0).max(100),
|
|
241
|
-
ambientLight: e.number().min(0).max(1e5),
|
|
242
|
-
temperature: e.number().min(-40).max(125)
|
|
243
|
-
}), ze = e.object({
|
|
244
|
-
id: e.string(),
|
|
245
|
-
source: e.enum(["mqtt", "http", "ws", "mock"]),
|
|
246
|
-
domain: e.string(),
|
|
247
|
-
key: e.string(),
|
|
248
|
-
value: e.union([e.number(), e.string(), e.boolean()]),
|
|
249
|
-
unit: e.string().optional(),
|
|
250
|
-
timestamp: e.number(),
|
|
251
|
-
meta: e.record(e.unknown()).optional()
|
|
252
|
-
});
|
|
253
|
-
e.array(ze);
|
|
254
|
-
var Fe = e.enum(["telemetry", "market", "system", "logic"]), Je = e.enum(["mqtt", "http", "ws", "mock"]);
|
|
255
|
-
e.object({
|
|
256
|
-
/**
|
|
257
|
-
* Globally unique signal identifier.
|
|
258
|
-
* Convention: '<device-or-entity-id>:<key>'
|
|
259
|
-
* Examples: 'sensor-01:soil_vwc', 'AAPL:price', 'server-01:cpu_pct'
|
|
260
|
-
*/
|
|
261
|
-
id: e.string(),
|
|
262
|
-
/**
|
|
263
|
-
* The semantic category of this signal.
|
|
264
|
-
* Determines which Methodology Engine processes it.
|
|
265
|
-
*/
|
|
266
|
-
kind: Fe,
|
|
267
|
-
/**
|
|
268
|
-
* The specific measurement or metric key within its kind.
|
|
269
|
-
* RULE: Keys MUST be abstract and domain-agnostic where possible.
|
|
270
|
-
* Use 'price' not 'stock_price'. Use 'moisture' not 'soil_vwc'.
|
|
271
|
-
* Hardware-specific keys (soil_vwc) MUST be mapped to abstract keys
|
|
272
|
-
* at the adapter layer BEFORE the SignalPacket is created.
|
|
273
|
-
*/
|
|
274
|
-
key: e.string(),
|
|
275
|
-
/**
|
|
276
|
-
* The scalar value. Accepts number, string, or boolean.
|
|
277
|
-
* Structured data MUST be flattened into multiple SignalPackets,
|
|
278
|
-
* one per measurable dimension.
|
|
279
|
-
*/
|
|
280
|
-
value: e.union([e.number(), e.string(), e.boolean()]),
|
|
281
|
-
/**
|
|
282
|
-
* Optional unit of measurement.
|
|
283
|
-
* Examples: 'VWC%', 'USD', 'bpm', 'ms', '°C', 'pct'
|
|
284
|
-
*/
|
|
285
|
-
unit: e.string().optional(),
|
|
286
|
-
/**
|
|
287
|
-
* Unix timestamp in milliseconds (Date.now() format).
|
|
288
|
-
* MUST represent when the measurement was taken, not when it was received.
|
|
289
|
-
*/
|
|
290
|
-
ts: e.number(),
|
|
291
|
-
/**
|
|
292
|
-
* The transport source that produced this signal.
|
|
293
|
-
*/
|
|
294
|
-
source: Je.optional(),
|
|
295
|
-
/**
|
|
296
|
-
* Optional domain namespace for grouping related signals.
|
|
297
|
-
* Examples: 'bodewell', 'finance', 'infrastructure', 'user_behavior'
|
|
298
|
-
*/
|
|
299
|
-
domain: e.string().optional(),
|
|
300
|
-
/**
|
|
301
|
-
* Optional pass-through for source-specific metadata that does NOT
|
|
302
|
-
* belong in the core contract (e.g. device firmware version, exchange name).
|
|
303
|
-
* RULE: If you find yourself reading from meta in UI components, that
|
|
304
|
-
* field should be promoted to the core schema or handled in the adapter.
|
|
305
|
-
*/
|
|
306
|
-
meta: e.record(e.unknown()).optional()
|
|
307
|
-
});
|
|
308
|
-
var Ge = {};
|
|
309
|
-
Pe(Ge, {
|
|
310
|
-
BodewellCommandSchema: () => We,
|
|
311
|
-
BodewellDeviceID: () => ae,
|
|
312
|
-
BodewellTelemetrySchema: () => Ve
|
|
313
|
-
});
|
|
314
|
-
var ae = e.enum([
|
|
315
|
-
"STK-V1-001",
|
|
316
|
-
"STK-V1-002",
|
|
317
|
-
"STK-V1-003",
|
|
318
|
-
"STK-PRO-001",
|
|
319
|
-
"STK-VIS-001"
|
|
320
|
-
]), Ve = e.object({
|
|
321
|
-
device_id: ae,
|
|
322
|
-
stick_id: e.string().optional().describe("Firmware alias for device_id"),
|
|
323
|
-
timestamp: e.number().optional().describe("Epoch timestamp from NTP"),
|
|
324
|
-
air_temp: e.number().optional().describe("Celsius"),
|
|
325
|
-
air_humid: e.number().optional().describe("Relative Humidity %"),
|
|
326
|
-
humidity: e.number().optional().describe("Firmware alias for air_humid"),
|
|
327
|
-
air_pressure: e.number().optional().describe("hPa"),
|
|
328
|
-
pressure: e.number().optional().describe("Firmware alias for air_pressure"),
|
|
329
|
-
light_lux: e.number().optional().describe("Lux level"),
|
|
330
|
-
soil_temp_stemma: e.number().optional().describe("Celsius"),
|
|
331
|
-
soil_vwc: e.number().describe("Volumetric Water Content / Raw Capacitance"),
|
|
332
|
-
soil_moisture: e.number().optional().describe("Firmware alias for raw capacitance"),
|
|
333
|
-
soil_moisture_raw: e.number().optional().describe("Unscaled capacitance (300-1100)"),
|
|
334
|
-
fw_version: e.string().max(40).optional().describe("Firmware build the board is running; absent on v4 sketches, which cannot be updated over the air")
|
|
335
|
-
}).passthrough(), We = e.object({
|
|
336
|
-
stick_id: ae,
|
|
337
|
-
// Note: Your API uses stick_id here, not device_id
|
|
338
|
-
type: e.enum(["dry", "wet"]),
|
|
339
|
-
value: e.number()
|
|
340
|
-
}), He = e.enum([
|
|
341
|
-
"esp32-touch-28",
|
|
342
|
-
// 2.8" 240x320 resistive touch, the workshop board
|
|
343
|
-
"esp32-headless",
|
|
344
|
-
// no display; sensor node
|
|
345
|
-
"simulator"
|
|
346
|
-
// browser-side stand-in, for building without hardware
|
|
347
|
-
]), fe = e.enum([
|
|
348
|
-
"weather",
|
|
349
|
-
"clock",
|
|
350
|
-
"aircraft",
|
|
351
|
-
"sensor",
|
|
352
|
-
"blank"
|
|
353
|
-
]), Ye = e.object({
|
|
354
|
-
/** Postal code is what a person knows; the portal resolves it to coordinates. */
|
|
355
|
-
postalCode: e.string().min(3).max(12),
|
|
356
|
-
latitude: e.number().min(-90).max(90).optional(),
|
|
357
|
-
longitude: e.number().min(-180).max(180).optional(),
|
|
358
|
-
units: e.enum(["imperial", "metric"]).default("imperial"),
|
|
359
|
-
showForecast: e.boolean().default(!0),
|
|
360
|
-
refreshSeconds: e.number().int().min(300).max(86400).default(900)
|
|
361
|
-
}), Ke = e.object({
|
|
362
|
-
/** IANA zone, e.g. "America/New_York". */
|
|
363
|
-
timezone: e.string().default("America/New_York"),
|
|
364
|
-
twentyFourHour: e.boolean().default(!1),
|
|
365
|
-
showSeconds: e.boolean().default(!1),
|
|
366
|
-
showDate: e.boolean().default(!0)
|
|
367
|
-
}), Xe = e.object({
|
|
368
|
-
latitude: e.number().min(-90).max(90),
|
|
369
|
-
longitude: e.number().min(-180).max(180),
|
|
370
|
-
radiusKm: e.number().min(5).max(400).default(80),
|
|
371
|
-
/** Rows the list view can show before the screen runs out. */
|
|
372
|
-
maxRows: e.number().int().min(1).max(12).default(8),
|
|
373
|
-
refreshSeconds: e.number().int().min(10).max(600).default(30)
|
|
374
|
-
}), Qe = e.object({
|
|
375
|
-
/** Signal keys to display, in order. Abstract keys per the Signal contract. */
|
|
376
|
-
keys: e.array(e.string()).min(1).max(6),
|
|
377
|
-
refreshSeconds: e.number().int().min(1).max(3600).default(10)
|
|
378
|
-
}), et = e.object({
|
|
379
|
-
weather: Ye.optional(),
|
|
380
|
-
clock: Ke.optional(),
|
|
381
|
-
aircraft: Xe.optional(),
|
|
382
|
-
sensor: Qe.optional()
|
|
383
|
-
}), tt = e.object({
|
|
384
|
-
brightness: e.number().int().min(5).max(100).default(80),
|
|
385
|
-
/** Degrees clockwise. The board can sit either way up in a case. */
|
|
386
|
-
rotation: e.union([e.literal(0), e.literal(90), e.literal(180), e.literal(270)]).default(0),
|
|
387
|
-
/** Dim rather than sleep — a desk display that blanks looks broken. */
|
|
388
|
-
dimAfterSeconds: e.number().int().min(0).max(86400).default(0),
|
|
389
|
-
dimBrightness: e.number().int().min(0).max(100).default(15),
|
|
390
|
-
/** Local 24h times, e.g. "22:30". Empty disables night dimming. */
|
|
391
|
-
nightStart: e.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/).optional(),
|
|
392
|
-
nightEnd: e.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/).optional()
|
|
393
|
-
}), Z = e.string().regex(
|
|
394
|
-
/^\d{1,3} \d{1,3} \d{1,3}$/,
|
|
395
|
-
'Expected space-separated RGB integers, e.g. "13 110 253"'
|
|
396
|
-
), rt = e.object({
|
|
397
|
-
preset: e.enum(["light", "dark", "corporate", "midnight", "blueprint", "custom"]).default("dark"),
|
|
398
|
-
background: Z.optional(),
|
|
399
|
-
foreground: Z.optional(),
|
|
400
|
-
accent: Z.optional(),
|
|
401
|
-
muted: Z.optional(),
|
|
402
|
-
warning: Z.optional()
|
|
403
|
-
});
|
|
404
|
-
e.object({
|
|
405
|
-
/** Bumped only on breaking shape changes, so old firmware can refuse safely. */
|
|
406
|
-
schemaVersion: e.literal(1),
|
|
407
|
-
deviceId: e.string().min(1),
|
|
408
|
-
/** Monotonic. Portal increments on write; device echoes what it is running. */
|
|
409
|
-
revision: e.number().int().nonnegative(),
|
|
410
|
-
updatedAt: e.string().datetime().optional(),
|
|
411
|
-
activeApp: fe,
|
|
412
|
-
apps: et,
|
|
413
|
-
display: tt,
|
|
414
|
-
theme: rt
|
|
415
|
-
});
|
|
416
|
-
var nt = e.enum([
|
|
417
|
-
"unprovisioned",
|
|
418
|
-
"connecting",
|
|
419
|
-
"online",
|
|
420
|
-
"offline",
|
|
421
|
-
"failed"
|
|
422
|
-
]);
|
|
423
|
-
e.object({
|
|
424
|
-
deviceId: e.string().min(1),
|
|
425
|
-
kind: He,
|
|
426
|
-
firmwareVersion: e.string(),
|
|
427
|
-
/** Shown on the device's own screen at boot — how the user finds it. */
|
|
428
|
-
ipAddress: e.string().optional(),
|
|
429
|
-
provisioning: nt,
|
|
430
|
-
/** Revision the device is actually running, not the one it was sent. */
|
|
431
|
-
configRevision: e.number().int().nonnegative(),
|
|
432
|
-
activeApp: fe,
|
|
433
|
-
rssi: e.number().int().optional().describe("dBm"),
|
|
434
|
-
uptimeSeconds: e.number().int().nonnegative().optional(),
|
|
435
|
-
freeHeapBytes: e.number().int().nonnegative().optional()
|
|
436
|
-
});
|
|
437
|
-
var at = e.enum([
|
|
438
|
-
"background",
|
|
439
|
-
"foreground",
|
|
440
|
-
"muted",
|
|
441
|
-
"accent",
|
|
442
|
-
"success",
|
|
443
|
-
"warning",
|
|
444
|
-
"danger"
|
|
445
|
-
]), ot = e.string().regex(/^\d{1,3} \d{1,3} \d{1,3}$/, 'RGB must be three space-separated integers, e.g. "13 110 253"'), W = e.union([at, ot]), ye = e.enum(["xs", "sm", "base", "lg", "xl", "display"]), H = e.enum(["start", "center", "end"]), it = e.discriminatedUnion("kind", [
|
|
446
|
-
e.object({
|
|
447
|
-
kind: e.literal("weather"),
|
|
448
|
-
latitude: e.number().min(-90).max(90),
|
|
449
|
-
longitude: e.number().min(-180).max(180),
|
|
450
|
-
units: e.enum(["imperial", "metric"]).default("imperial"),
|
|
451
|
-
refreshSeconds: e.number().int().min(300).max(86400).default(600)
|
|
452
|
-
}),
|
|
453
|
-
e.object({
|
|
454
|
-
kind: e.literal("clock"),
|
|
455
|
-
/** IANA zone, e.g. "America/New_York". */
|
|
456
|
-
timezone: e.string().default("America/New_York"),
|
|
457
|
-
twentyFourHour: e.boolean().default(!1)
|
|
458
|
-
}),
|
|
459
|
-
e.object({
|
|
460
|
-
kind: e.literal("countdown"),
|
|
461
|
-
/** ISO date or datetime, e.g. "2026-12-25" or "2026-12-25T18:00:00Z". */
|
|
462
|
-
target: e.string().min(4),
|
|
463
|
-
label: e.string().max(24).optional()
|
|
464
|
-
}),
|
|
465
|
-
e.object({
|
|
466
|
-
kind: e.literal("static"),
|
|
467
|
-
values: e.record(e.union([e.string(), e.number(), e.boolean()]))
|
|
468
|
-
})
|
|
469
|
-
]), ne = e.union([
|
|
470
|
-
e.object({ literal: e.number() }),
|
|
471
|
-
e.object({ source: e.string().min(1), field: e.string().min(1) })
|
|
472
|
-
]), st = e.object({
|
|
473
|
-
compute: e.enum(["add", "subtract", "multiply", "divide"]),
|
|
474
|
-
of: e.tuple([ne, ne]),
|
|
475
|
-
round: e.boolean().default(!0)
|
|
476
|
-
}), z = e.union([
|
|
477
|
-
e.object({ literal: e.union([e.string(), e.number(), e.boolean()]) }),
|
|
478
|
-
e.object({
|
|
479
|
-
/** Key into the document's `sources` map. */
|
|
480
|
-
source: e.string().min(1),
|
|
481
|
-
/** Field on that source, e.g. "temperature", "high", "condition". */
|
|
482
|
-
field: e.string().min(1)
|
|
483
|
-
}),
|
|
484
|
-
st
|
|
485
|
-
]), Y = e.object({
|
|
486
|
-
value: ne,
|
|
487
|
-
op: e.enum(["<", "<=", ">", ">=", "==", "!="]),
|
|
488
|
-
than: e.union([e.number(), e.string(), e.boolean()])
|
|
489
|
-
}), ct = e.object({
|
|
490
|
-
when: Y,
|
|
491
|
-
color: W.optional(),
|
|
492
|
-
size: ye.optional()
|
|
493
|
-
}), F = {
|
|
494
|
-
color: W.optional(),
|
|
495
|
-
/** Drawn only when this is false, or absent. */
|
|
496
|
-
hideWhen: Y.optional(),
|
|
497
|
-
/** Conditional style. First match wins. */
|
|
498
|
-
rules: e.array(ct).max(4).optional()
|
|
499
|
-
}, lt = e.object({
|
|
500
|
-
type: e.literal("text"),
|
|
501
|
-
value: z,
|
|
502
|
-
size: ye.default("base"),
|
|
503
|
-
align: H.default("start"),
|
|
504
|
-
/** Printed after the value, e.g. a degree symbol. Never itself bound. */
|
|
505
|
-
suffix: e.string().max(8).optional(),
|
|
506
|
-
...F
|
|
507
|
-
}), ut = e.object({
|
|
508
|
-
type: e.literal("dial"),
|
|
509
|
-
value: z,
|
|
510
|
-
min: e.number(),
|
|
511
|
-
max: e.number(),
|
|
512
|
-
label: e.string().max(24).optional(),
|
|
513
|
-
...F
|
|
514
|
-
}), dt = e.object({
|
|
515
|
-
type: e.literal("sparkline"),
|
|
516
|
-
/** A source field holding a series rather than a scalar. */
|
|
517
|
-
series: z,
|
|
518
|
-
...F
|
|
519
|
-
}), mt = e.object({
|
|
520
|
-
type: e.literal("bar"),
|
|
521
|
-
value: z,
|
|
522
|
-
min: e.number(),
|
|
523
|
-
max: e.number(),
|
|
524
|
-
...F
|
|
525
|
-
}), pt = e.object({
|
|
526
|
-
type: e.literal("status"),
|
|
527
|
-
state: z,
|
|
528
|
-
label: e.string().max(24).optional(),
|
|
529
|
-
...F
|
|
530
|
-
}), M = 64, ht = M / 2, gt = Math.ceil(ht * M / 3) * 4, ft = e.object({
|
|
531
|
-
type: e.literal("sprite"),
|
|
532
|
-
width: e.number().int().min(1).max(M),
|
|
533
|
-
height: e.number().int().min(1).max(M),
|
|
534
|
-
/**
|
|
535
|
-
* Up to sixteen colours, in the same form every other colour in a document
|
|
536
|
-
* takes: a semantic token, or literal RGB.
|
|
537
|
-
*
|
|
538
|
-
* Both are allowed on purpose. A token re-colours with the theme, which is
|
|
539
|
-
* what an icon wants; literal RGB does not, which is what a drawing wants.
|
|
540
|
-
* A picture of a dog is content, not chrome, and should not turn teal
|
|
541
|
-
* because somebody switched to the corporate theme.
|
|
542
|
-
*/
|
|
543
|
-
palette: e.array(W).min(1).max(16),
|
|
544
|
-
/** base64 of the packed nibbles. */
|
|
545
|
-
pixels: e.string().min(4).max(gt),
|
|
546
|
-
align: H.default("start"),
|
|
547
|
-
/** Drawn only when this is false, or absent. */
|
|
548
|
-
hideWhen: Y.optional()
|
|
549
|
-
}), be = e.string().regex(/^[0-9a-f]{64}$/, "a lowercase hex SHA-256"), B = { width: 304, height: 224 }, yt = 8, j = {
|
|
550
|
-
/** "RSPR". */
|
|
551
|
-
magic: [82, 83, 80, 82],
|
|
552
|
-
version: 1,
|
|
553
|
-
/** magic 4, version 1, width u16, height u16, bits per pixel 1, palette count 1. */
|
|
554
|
-
headerBytes: 11,
|
|
555
|
-
/** Only 4 today: two pixels per byte, high nibble first, rows padded to a byte. */
|
|
556
|
-
bitsPerPixel: 4,
|
|
557
|
-
maxColors: 16
|
|
558
|
-
}, me = j.headerBytes + j.maxColors * 2 + Math.ceil(B.width / 2) * B.height, bt = e.object({
|
|
559
|
-
type: e.literal("image"),
|
|
560
|
-
asset: be,
|
|
561
|
-
/** The file's own pixels, not the drawn size. */
|
|
562
|
-
width: e.number().int().min(1).max(B.width),
|
|
563
|
-
height: e.number().int().min(1).max(B.height),
|
|
564
|
-
scale: e.number().int().min(1).max(yt).default(1),
|
|
565
|
-
align: H.default("start"),
|
|
566
|
-
/** Drawn only when this is false, or absent. */
|
|
567
|
-
hideWhen: Y.optional()
|
|
568
|
-
}), we = e.discriminatedUnion("type", [
|
|
569
|
-
lt,
|
|
570
|
-
ut,
|
|
571
|
-
dt,
|
|
572
|
-
mt,
|
|
573
|
-
pt,
|
|
574
|
-
ft,
|
|
575
|
-
bt
|
|
576
|
-
]), wt = e.object({
|
|
577
|
-
type: e.literal("group"),
|
|
578
|
-
direction: e.enum(["row", "stack"]),
|
|
579
|
-
gap: e.number().int().min(0).max(64).default(4),
|
|
580
|
-
align: H.default("start"),
|
|
581
|
-
children: e.array(we).min(1).max(8)
|
|
582
|
-
}), vt = e.union([we, wt]), xt = e.preprocess(
|
|
583
|
-
(a) => a === "240x320" ? "320x240" : a,
|
|
584
|
-
e.enum(["320x240"])
|
|
585
|
-
), zr = e.object({
|
|
586
|
-
/** Bumped only for a breaking change; the device checks it before parsing. */
|
|
587
|
-
schemaVersion: e.literal(1),
|
|
588
|
-
id: e.string().regex(/^[a-z0-9][a-z0-9-]{1,38}[a-z0-9]$/, "lowercase slug"),
|
|
589
|
-
name: e.string().min(1).max(48),
|
|
590
|
-
/** Free text. Never an email or anything else identifying — see the plan. */
|
|
591
|
-
author: e.string().max(32).optional(),
|
|
592
|
-
screen: xt.default("320x240"),
|
|
593
|
-
background: W.default("background"),
|
|
594
|
-
/** Named so bindings can refer to them. */
|
|
595
|
-
sources: e.record(it).default({}),
|
|
596
|
-
blocks: e.array(vt).min(1).max(12)
|
|
597
|
-
}).superRefine((a, t) => {
|
|
598
|
-
const n = (i) => Math.ceil(i / 2), r = (i, s) => {
|
|
599
|
-
const c = i;
|
|
600
|
-
if ((c == null ? void 0 : c.type) !== "sprite" || !c.width || !c.height || typeof c.pixels != "string") return;
|
|
601
|
-
const l = n(c.width) * c.height, u = Math.floor(c.pixels.replace(/=+$/, "").length * 3 / 4);
|
|
602
|
-
u !== l && t.addIssue({
|
|
603
|
-
code: e.ZodIssueCode.custom,
|
|
604
|
-
path: [...s, "pixels"],
|
|
605
|
-
message: `${c.width}x${c.height} needs ${l} bytes of pixel data, and this decodes to ${u}. Rows are padded to whole bytes, so the length is ceil(width / 2) * height.`
|
|
606
|
-
});
|
|
607
|
-
}, o = (i, s) => {
|
|
608
|
-
const c = i;
|
|
609
|
-
if ((c == null ? void 0 : c.type) !== "image" || !c.width || !c.height) return;
|
|
610
|
-
const l = c.scale ?? 1, u = c.width * l, d = c.height * l;
|
|
611
|
-
u <= B.width && d <= B.height || t.addIssue({
|
|
612
|
-
code: e.ZodIssueCode.custom,
|
|
613
|
-
path: [...s, "scale"],
|
|
614
|
-
message: `${c.width}x${c.height} at scale ${l} draws ${u}x${d}, and a board draws at most ${B.width}x${B.height} inside its margin.`
|
|
615
|
-
});
|
|
616
|
-
};
|
|
617
|
-
a.blocks.forEach((i, s) => {
|
|
618
|
-
r(i, ["blocks", s]), o(i, ["blocks", s]);
|
|
619
|
-
const c = i.children;
|
|
620
|
-
Array.isArray(c) && c.forEach((l, u) => {
|
|
621
|
-
r(l, ["blocks", s, "children", u]), o(l, ["blocks", s, "children", u]);
|
|
622
|
-
});
|
|
623
|
-
});
|
|
624
|
-
});
|
|
625
|
-
e.object({
|
|
626
|
-
rendition: e.string().min(4),
|
|
627
|
-
original: e.string().min(4)
|
|
628
|
-
});
|
|
629
|
-
e.object({
|
|
630
|
-
hash: be,
|
|
631
|
-
/** The rendition's own pixels. */
|
|
632
|
-
width: e.number().int().positive(),
|
|
633
|
-
height: e.number().int().positive(),
|
|
634
|
-
renditionBytes: e.number().int().positive(),
|
|
635
|
-
originalWidth: e.number().int().positive(),
|
|
636
|
-
originalHeight: e.number().int().positive(),
|
|
637
|
-
originalBytes: e.number().int().positive(),
|
|
638
|
-
uploadedAt: e.number().int()
|
|
639
|
-
});
|
|
640
|
-
var K = e.string().regex(/^[0-9A-HJKMNP-TV-Z]{8}$/, "eight characters, no I L O or U"), oe = e.string().regex(/^\d{4}$/);
|
|
641
|
-
e.object({
|
|
642
|
-
deviceId: K,
|
|
643
|
-
code: oe,
|
|
644
|
-
/** Firmware build, so a support question has an answer. */
|
|
645
|
-
version: e.string().max(40).optional(),
|
|
646
|
-
/** Which board this is, from Boards.h — the two variants need different firmware. */
|
|
647
|
-
board: e.string().max(40).optional(),
|
|
648
|
-
/** dBm, always negative. -50 is across the room; -85 is a complaint. */
|
|
649
|
-
rssi: e.number().int().min(-127).max(0).optional(),
|
|
650
|
-
/** On the owner's own network. Long enough for IPv6, which this does not send yet. */
|
|
651
|
-
ip: e.string().max(45).optional(),
|
|
652
|
-
/** Seconds since boot. Not growing between check-ins means it is restarting. */
|
|
653
|
-
uptime: e.number().int().nonnegative().optional(),
|
|
654
|
-
/** Free heap in bytes. */
|
|
655
|
-
heap: e.number().int().nonnegative().optional(),
|
|
656
|
-
/** The app revision the board has actually drawn. */
|
|
657
|
-
drew: e.number().int().nonnegative().optional(),
|
|
658
|
-
/** Why it last restarted, already mapped to a word by the firmware. */
|
|
659
|
-
reset: e.string().max(40).optional()
|
|
660
|
-
});
|
|
661
|
-
e.object({
|
|
662
|
-
deviceId: K,
|
|
663
|
-
code: oe
|
|
664
|
-
});
|
|
665
|
-
e.object({
|
|
666
|
-
deviceId: K
|
|
667
|
-
});
|
|
668
|
-
e.object({
|
|
669
|
-
revision: e.number().int().nonnegative(),
|
|
670
|
-
sentAt: e.number().int().nonnegative()
|
|
671
|
-
});
|
|
672
|
-
e.object({
|
|
673
|
-
deviceId: K,
|
|
674
|
-
code: oe,
|
|
675
|
-
ownerId: e.string().nullable().default(null),
|
|
676
|
-
version: e.string().max(40).optional(),
|
|
677
|
-
createdAt: e.number().int().nonnegative(),
|
|
678
|
-
lastSeenAt: e.number().int().nonnegative()
|
|
679
|
-
});
|
|
680
|
-
e.enum(["register", "poll", "send"]);
|
|
681
|
-
e.object({
|
|
682
|
-
/** When the board last said any of this, by the server's clock. */
|
|
683
|
-
reportedAt: e.number().int().nonnegative().optional(),
|
|
684
|
-
/**
|
|
685
|
-
* The firmware build. Today every board sends the literal "doc-1", which is a
|
|
686
|
-
* protocol marker rather than a build id — so this is shown as reported and
|
|
687
|
-
* labelled as not yet a version. The real value lives in the published
|
|
688
|
-
* manifest until firmware carries it.
|
|
689
|
-
*/
|
|
690
|
-
firmwareVersion: e.string().max(40).optional(),
|
|
691
|
-
/** Which board this is. Nothing distinguishes a CYD from a Freenove S3 yet. */
|
|
692
|
-
board: e.string().max(40).optional(),
|
|
693
|
-
/** dBm, negative. -50 is across the room, -85 is a complaint. */
|
|
694
|
-
rssi: e.number().int().min(-127).max(0).optional(),
|
|
695
|
-
/** The board's address on its own network, as the board sees it. */
|
|
696
|
-
ip: e.string().max(45).optional(),
|
|
697
|
-
uptimeSeconds: e.number().int().nonnegative().optional(),
|
|
698
|
-
freeHeapBytes: e.number().int().nonnegative().optional(),
|
|
699
|
-
/**
|
|
700
|
-
* The revision the board is actually showing.
|
|
701
|
-
*
|
|
702
|
-
* Distinct from the revision that was sent, and the difference is the whole
|
|
703
|
-
* value: a send that was never drawn looks identical to a successful one until
|
|
704
|
-
* these two numbers disagree.
|
|
705
|
-
*/
|
|
706
|
-
drewRevision: e.number().int().nonnegative().optional(),
|
|
707
|
-
/** Why it last restarted, if it says. A board power-cycling in a loop is a fault. */
|
|
708
|
-
resetReason: e.string().max(40).optional(),
|
|
709
|
-
/** When it last polled — finer-grained than a registration, for liveness only. */
|
|
710
|
-
lastPollAt: e.number().int().nonnegative().optional()
|
|
711
|
-
});
|
|
712
|
-
e.object({
|
|
713
|
-
/** When the board last asked for its app. The freshest signal this system has. */
|
|
714
|
-
lastPollAt: e.number().int().nonnegative(),
|
|
715
|
-
/** The revision it reported drawing at that moment. */
|
|
716
|
-
drewRevision: e.number().int().nonnegative().optional()
|
|
717
|
-
});
|
|
718
|
-
var Fr = "?", Jr = {
|
|
719
|
-
// Accented Latin, CP437 0x80-0xA5 and 0xE1
|
|
720
|
-
Ç: { byte: 128, shows: "Ç" },
|
|
721
|
-
ü: { byte: 129, shows: "ü" },
|
|
722
|
-
é: { byte: 130, shows: "é" },
|
|
723
|
-
â: { byte: 131, shows: "â" },
|
|
724
|
-
ä: { byte: 132, shows: "ä" },
|
|
725
|
-
à: { byte: 133, shows: "à" },
|
|
726
|
-
å: { byte: 134, shows: "å" },
|
|
727
|
-
ç: { byte: 135, shows: "ç" },
|
|
728
|
-
ê: { byte: 136, shows: "ê" },
|
|
729
|
-
ë: { byte: 137, shows: "ë" },
|
|
730
|
-
è: { byte: 138, shows: "è" },
|
|
731
|
-
ï: { byte: 139, shows: "ï" },
|
|
732
|
-
î: { byte: 140, shows: "î" },
|
|
733
|
-
ì: { byte: 141, shows: "ì" },
|
|
734
|
-
Ä: { byte: 142, shows: "Ä" },
|
|
735
|
-
Å: { byte: 143, shows: "Å" },
|
|
736
|
-
É: { byte: 144, shows: "É" },
|
|
737
|
-
æ: { byte: 145, shows: "æ" },
|
|
738
|
-
Æ: { byte: 146, shows: "Æ" },
|
|
739
|
-
ô: { byte: 147, shows: "ô" },
|
|
740
|
-
ö: { byte: 148, shows: "ö" },
|
|
741
|
-
ò: { byte: 149, shows: "ò" },
|
|
742
|
-
û: { byte: 150, shows: "û" },
|
|
743
|
-
ù: { byte: 151, shows: "ù" },
|
|
744
|
-
ÿ: { byte: 152, shows: "ÿ" },
|
|
745
|
-
Ö: { byte: 153, shows: "Ö" },
|
|
746
|
-
Ü: { byte: 154, shows: "Ü" },
|
|
747
|
-
á: { byte: 160, shows: "á" },
|
|
748
|
-
í: { byte: 161, shows: "í" },
|
|
749
|
-
ó: { byte: 162, shows: "ó" },
|
|
750
|
-
ú: { byte: 163, shows: "ú" },
|
|
751
|
-
ñ: { byte: 164, shows: "ñ" },
|
|
752
|
-
Ñ: { byte: 165, shows: "Ñ" },
|
|
753
|
-
ß: { byte: 225, shows: "ß" },
|
|
754
|
-
// Symbols a readout uses
|
|
755
|
-
"¢": { byte: 155, shows: "¢" },
|
|
756
|
-
"£": { byte: 156, shows: "£" },
|
|
757
|
-
"¥": { byte: 157, shows: "¥" },
|
|
758
|
-
ƒ: { byte: 159, shows: "ƒ" },
|
|
759
|
-
ª: { byte: 166, shows: "ª" },
|
|
760
|
-
º: { byte: 167, shows: "º" },
|
|
761
|
-
"¿": { byte: 168, shows: "¿" },
|
|
762
|
-
"¬": { byte: 170, shows: "¬" },
|
|
763
|
-
"½": { byte: 171, shows: "½" },
|
|
764
|
-
"¼": { byte: 172, shows: "¼" },
|
|
765
|
-
"¡": { byte: 173, shows: "¡" },
|
|
766
|
-
"«": { byte: 174, shows: "«" },
|
|
767
|
-
"»": { byte: 175, shows: "»" },
|
|
768
|
-
π: { byte: 227, shows: "π" },
|
|
769
|
-
µ: { byte: 230, shows: "µ" },
|
|
770
|
-
Ω: { byte: 234, shows: "Ω" },
|
|
771
|
-
"∞": { byte: 236, shows: "∞" },
|
|
772
|
-
"±": { byte: 241, shows: "±" },
|
|
773
|
-
"≥": { byte: 242, shows: "≥" },
|
|
774
|
-
"≤": { byte: 243, shows: "≤" },
|
|
775
|
-
"÷": { byte: 246, shows: "÷" },
|
|
776
|
-
"≈": { byte: 247, shows: "≈" },
|
|
777
|
-
"°": { byte: 248, shows: "°" },
|
|
778
|
-
"·": { byte: 250, shows: "·" },
|
|
779
|
-
"√": { byte: 251, shows: "√" },
|
|
780
|
-
"²": { byte: 253, shows: "²" },
|
|
781
|
-
// Punctuation an AI writes without being asked, folded to ASCII
|
|
782
|
-
"‘": { byte: 39, shows: "'" },
|
|
783
|
-
"’": { byte: 39, shows: "'" },
|
|
784
|
-
"“": { byte: 34, shows: '"' },
|
|
785
|
-
"”": { byte: 34, shows: '"' },
|
|
786
|
-
"–": { byte: 45, shows: "-" },
|
|
787
|
-
"—": { byte: 45, shows: "-" },
|
|
788
|
-
"−": { byte: 45, shows: "-" },
|
|
789
|
-
" ": { byte: 32, shows: " " }
|
|
790
|
-
}, Gr = {
|
|
791
|
-
background: "17 17 17",
|
|
792
|
-
foreground: "238 238 238",
|
|
793
|
-
muted: "153 153 153",
|
|
794
|
-
accent: "23 162 184",
|
|
795
|
-
success: "34 197 94",
|
|
796
|
-
warning: "245 158 11",
|
|
797
|
-
danger: "220 53 69"
|
|
798
|
-
};
|
|
799
|
-
e.object({
|
|
800
|
-
deviceId: e.string().min(1, "Device ID is required"),
|
|
801
|
-
timeRange: e.enum(["1h", "24h", "7d"], {
|
|
802
|
-
errorMap: () => ({ message: "Time range must be 1h, 24h, or 7d" })
|
|
803
|
-
}),
|
|
804
|
-
metrics: e.array(
|
|
805
|
-
e.enum(["temperature", "humidity", "vwc", "ec", "ph", "pressure", "co2"])
|
|
806
|
-
).min(1, "At least one metric is required").max(4, "Maximum 4 metrics per graph")
|
|
807
|
-
});
|
|
808
|
-
e.object({
|
|
809
|
-
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')."),
|
|
810
|
-
timeRange: e.enum(["1D", "1W", "1M", "1Y"], {
|
|
811
|
-
errorMap: () => ({ message: "Time range must be 1D, 1W, 1M, or 1Y" })
|
|
812
|
-
}).describe("The time range for the chart. Choose based on user request or default to '1M'."),
|
|
813
|
-
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.")
|
|
814
|
-
});
|
|
815
|
-
var J = e.string().min(1).describe("The stock ticker symbol (e.g., 'AAPL', 'TSLA', 'MSFT').");
|
|
816
|
-
e.object({ ticker: J });
|
|
817
|
-
e.object({ ticker: J });
|
|
818
|
-
e.object({ ticker: J });
|
|
819
|
-
e.object({
|
|
820
|
-
ticker: J,
|
|
821
|
-
hops: e.number().int().min(1).max(2).optional().describe("How many relationship hops to traverse (1 = direct counterparties only, 2 = counterparties-of-counterparties too). Defaults to 1 if omitted.")
|
|
822
|
-
});
|
|
823
|
-
e.object({ ticker: J });
|
|
824
|
-
e.object({});
|
|
825
|
-
var Q = "gemini-2.5-flash", At = "gemini-2.5-flash", kt = "gemini-2.5-pro", T = {
|
|
826
|
-
"google-gemini": "gemini-2.5-flash",
|
|
827
|
-
openai: "gpt-4o-mini",
|
|
828
|
-
anthropic: "claude-haiku-4-5-20251001",
|
|
829
|
-
grok: "grok-2-1212",
|
|
830
|
-
deepseek: "deepseek-chat",
|
|
831
|
-
ollama: "llama3.3"
|
|
832
|
-
}, Vr = {
|
|
833
|
-
/** The Strategist: high creativity, exploratory conversation */
|
|
834
|
-
STRATEGIST: {
|
|
835
|
-
model: At,
|
|
836
|
-
provider: "google-gemini",
|
|
837
|
-
temperature: 0.7
|
|
838
|
-
},
|
|
839
|
-
/** The Architect: data schema and resource modeling — precision required */
|
|
840
|
-
ARCHITECT: {
|
|
841
|
-
model: Q,
|
|
842
|
-
provider: "google-gemini",
|
|
843
|
-
temperature: 0.3
|
|
844
|
-
},
|
|
845
|
-
/** The Designer: UI layout generation — moderate creativity */
|
|
846
|
-
DESIGNER: {
|
|
847
|
-
model: Q,
|
|
848
|
-
provider: "google-gemini",
|
|
849
|
-
temperature: 0.5
|
|
850
|
-
},
|
|
851
|
-
/** The Reviewer/Product Owner: structured plan output — strict adherence.
|
|
852
|
-
* Uses the Pro tier for superior reasoning on complex structured tasks.
|
|
853
|
-
*/
|
|
854
|
-
REVIEWER: {
|
|
855
|
-
model: kt,
|
|
856
|
-
provider: "google-gemini",
|
|
857
|
-
temperature: 0.2
|
|
858
|
-
},
|
|
859
|
-
/** The Genesis Engine: one-shot app generation — must be schema-strict */
|
|
860
|
-
GENESIS: {
|
|
861
|
-
model: Q,
|
|
862
|
-
provider: "google-gemini",
|
|
863
|
-
temperature: 0.2
|
|
864
|
-
}
|
|
865
|
-
}, Wr = `
|
|
866
|
-
You write tiny apps for a small desk device whose screen is 320 pixels wide and
|
|
867
|
-
240 pixels high — landscape.
|
|
868
|
-
|
|
869
|
-
Reply with ONE JSON object and nothing else. No markdown fences, no explanation.
|
|
870
|
-
|
|
871
|
-
THE SHAPE
|
|
872
|
-
|
|
873
|
-
{
|
|
874
|
-
"schemaVersion": 1,
|
|
875
|
-
"id": "lowercase-slug",
|
|
876
|
-
"name": "Short Name",
|
|
877
|
-
"screen": "320x240",
|
|
878
|
-
"background": "background",
|
|
879
|
-
"sources": { },
|
|
880
|
-
"blocks": [ ]
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
BLOCKS — up to 12, drawn top to bottom. Each is one of:
|
|
884
|
-
|
|
885
|
-
{ "type": "text", "value": V, "size": S, "align": A, "color": C, "suffix": "°" }
|
|
886
|
-
{ "type": "dial", "value": V, "min": 0, "max": 100, "label": "CPU", "color": C }
|
|
887
|
-
{ "type": "bar", "value": V, "min": 0, "max": 100, "color": C }
|
|
888
|
-
{ "type": "sparkline", "series": V, "color": C }
|
|
889
|
-
{ "type": "status", "state": V, "label": "Door", "color": C }
|
|
890
|
-
{ "type": "sprite", "palette": [C, ...], "grid": "0011
|
|
891
|
-
0110
|
|
892
|
-
1100
|
|
893
|
-
0011", "align": A }
|
|
894
|
-
{ "type": "group", "direction": "row"|"stack", "gap": 8, "align": A, "children": [ ...leaves... ] }
|
|
895
|
-
|
|
896
|
-
DRAWING A SPRITE — you may, and here is the only form that works.
|
|
897
|
-
|
|
898
|
-
Write a "grid": one line per row, one hex character per pixel, each character
|
|
899
|
-
indexing "palette" (so "0" is the first colour, "1" the second, up to "f").
|
|
900
|
-
Every row must be exactly the same length. Up to 64x64, but 16x16 and 32x32
|
|
901
|
-
look far better — small palettes and bold shapes read on a 320x240 panel, fine
|
|
902
|
-
detail does not.
|
|
903
|
-
|
|
904
|
-
{ "type": "sprite",
|
|
905
|
-
"palette": ["background", "255 214 10", "17 17 17"],
|
|
906
|
-
"grid": "0011110
|
|
907
|
-
0122210
|
|
908
|
-
1222221
|
|
909
|
-
1211121
|
|
910
|
-
1222221
|
|
911
|
-
0122210
|
|
912
|
-
0011110" }
|
|
913
|
-
|
|
914
|
-
Put the background colour FIRST so "0" means empty, and use "." as a synonym
|
|
915
|
-
for "0" if it makes the shape easier to see while you write it.
|
|
916
|
-
|
|
917
|
-
Palette entries are the same colours as everywhere else: a semantic token
|
|
918
|
-
re-colours with the theme, which is what an icon wants, and literal "R G B"
|
|
919
|
-
does not, which is what a picture wants.
|
|
920
|
-
|
|
921
|
-
NEVER write a "pixels" field yourself. That is base64 of packed nibbles, one
|
|
922
|
-
wrong character shifts every pixel after it, and you cannot check it. Write the
|
|
923
|
-
grid; it is converted for you. If a document you are editing already has
|
|
924
|
-
"pixels" and no "grid", leave it exactly as it is.
|
|
925
|
-
|
|
926
|
-
PHOTOS — a document you are editing may hold { "type": "image", "asset": "<64 hex
|
|
927
|
-
characters>", ... }. That is a picture someone uploaded, named by the hash of
|
|
928
|
-
its file. Keep every image block exactly as it is unless asked to remove it, and
|
|
929
|
-
never write one yourself: you cannot make the file it names, so any hash you
|
|
930
|
-
invent draws nothing.
|
|
931
|
-
|
|
932
|
-
Count your rows before you answer. A grid whose rows are different lengths is
|
|
933
|
-
the one mistake that will come back to you.
|
|
934
|
-
|
|
935
|
-
A group holds leaves only. Groups do NOT nest inside groups — the device has no
|
|
936
|
-
layout engine, only computed offsets.
|
|
937
|
-
|
|
938
|
-
CONDITIONS — any block may also carry these:
|
|
939
|
-
|
|
940
|
-
"hideWhen": { "value": O, "op": "<", "than": 32 }
|
|
941
|
-
leave it off the screen entirely while that is true
|
|
942
|
-
|
|
943
|
-
"rules": [ { "when": { "value": O, "op": "<", "than": 32 }, "color": "accent" },
|
|
944
|
-
{ "when": { "value": O, "op": ">", "than": 85 }, "color": "danger" } ]
|
|
945
|
-
style that applies only when something is true. First match wins, so write
|
|
946
|
-
the narrowest band first. At most four. Each may set "color", "size" or both.
|
|
947
|
-
|
|
948
|
-
op is one of "<" "<=" ">" ">=" "==" "!="
|
|
949
|
-
Only == and != work on words; the rest are for numbers.
|
|
950
|
-
|
|
951
|
-
O is an operand: { "literal": 32 } or { "source": "forecast", "field": "temperature" }
|
|
952
|
-
|
|
953
|
-
This is how "make it red when it is freezing" is expressed. Use it whenever a
|
|
954
|
-
request contains "when", "if", "unless", "only", or a colour tied to a value.
|
|
955
|
-
|
|
956
|
-
S (size) "xs" | "sm" | "base" | "lg" | "xl" | "display"
|
|
957
|
-
A (align) "start" | "center" | "end"
|
|
958
|
-
C (color) "background" | "foreground" | "muted" | "accent" | "success" | "warning" | "danger"
|
|
959
|
-
or three space-separated RGB numbers, e.g. "220 53 69"
|
|
960
|
-
|
|
961
|
-
VALUES — every V is one of:
|
|
962
|
-
|
|
963
|
-
{ "literal": "Hello" } text you wrote
|
|
964
|
-
{ "source": "forecast", "field": "temperature" } read from a source
|
|
965
|
-
{ "compute": "subtract", "of": [O, O], "round": true } arithmetic
|
|
966
|
-
|
|
967
|
-
compute is "add" | "subtract" | "multiply" | "divide", exactly two operands,
|
|
968
|
-
and it does NOT nest — an operand is a literal or a source field, never
|
|
969
|
-
another compute. "The difference between the high and the low" is the shape
|
|
970
|
-
this is for.
|
|
971
|
-
|
|
972
|
-
SOURCES — declare what the app reads, then bind to it by name:
|
|
973
|
-
|
|
974
|
-
"forecast": { "kind": "weather", "latitude": 39.95, "longitude": -75.17,
|
|
975
|
-
"units": "imperial", "refreshSeconds": 600 }
|
|
976
|
-
fields: temperature, condition, high, low
|
|
977
|
-
"now": { "kind": "clock", "timezone": "America/New_York", "twentyFourHour": false }
|
|
978
|
-
fields: time, date, weekday, hour (hour is 0-23, for rules about time of day)
|
|
979
|
-
"until": { "kind": "countdown", "target": "2026-12-25", "label": "Christmas" }
|
|
980
|
-
fields: days, hours, minutes, seconds, label
|
|
981
|
-
"fixed": { "kind": "static", "values": { "anything": 1 } }
|
|
982
|
-
fields: whatever you put in values
|
|
983
|
-
|
|
984
|
-
RULES
|
|
985
|
-
|
|
986
|
-
1. 320x240 is small, and it is wider than it is tall. A "display" size text is
|
|
987
|
-
about 56 pixels tall — one of those and two or three smaller lines fill the
|
|
988
|
-
height. Use the width: a "row" group puts two or three things side by side.
|
|
989
|
-
Prefer fewer, bigger things over a dense dashboard.
|
|
990
|
-
2. Use semantic colours unless asked for a specific one. They follow the theme.
|
|
991
|
-
3. There is no scrolling and no text wrapping. Long strings are cut off.
|
|
992
|
-
4. No tables, no forms, no images, no buttons. The screen shows; it does not
|
|
993
|
-
take input.
|
|
994
|
-
5. If the request needs something the vocabulary cannot express, build the
|
|
995
|
-
closest thing it can and do not invent a component.
|
|
996
|
-
6. Prefer a rule over a fixed colour whenever the request ties appearance to a
|
|
997
|
-
value. "Red when cold" is a rule; "red" is not.
|
|
998
|
-
`.trim(), Hr = "Here is the current app. Change only what is asked:", E = e.string().regex(
|
|
999
|
-
/^\d{1,3}\s+\d{1,3}\s+\d{1,3}$/,
|
|
1000
|
-
'Must be space-separated RGB integers (e.g. "13 110 253")'
|
|
1001
|
-
), St = e.object({
|
|
1002
|
-
// ── Core Brand ───────────────────────────────────────────────────────────
|
|
1003
|
-
"--app-primary-color": E.optional(),
|
|
1004
|
-
"--app-primary-foreground-color": E.optional(),
|
|
1005
|
-
"--app-secondary-color": E.optional(),
|
|
1006
|
-
"--app-secondary-foreground-color": E.optional(),
|
|
1007
|
-
"--app-accent-color": E.optional(),
|
|
1008
|
-
"--app-accent-foreground-color": E.optional(),
|
|
1009
|
-
// ── Base Surface ─────────────────────────────────────────────────────────
|
|
1010
|
-
"--app-bg-color": E.optional(),
|
|
1011
|
-
"--app-card-bg-color": E.optional(),
|
|
1012
|
-
"--app-text-color": E.optional(),
|
|
1013
|
-
"--app-border-color": E.optional(),
|
|
1014
|
-
"--app-muted-bg": E.optional(),
|
|
1015
|
-
"--app-muted-text": E.optional(),
|
|
1016
|
-
// ── Shape ────────────────────────────────────────────────────────────────
|
|
1017
|
-
"--app-border-radius-sm": e.string().optional(),
|
|
1018
|
-
"--app-border-radius-md": e.string().optional(),
|
|
1019
|
-
"--app-border-radius-lg": e.string().optional(),
|
|
1020
|
-
// ── Form Controls ────────────────────────────────────────────────────────
|
|
1021
|
-
"--app-input-bg-color": E.optional(),
|
|
1022
|
-
"--app-input-text-color": E.optional(),
|
|
1023
|
-
"--app-input-border-color": E.optional(),
|
|
1024
|
-
"--app-input-focus-ring-color": E.optional(),
|
|
1025
|
-
"--app-input-placeholder-color": E.optional(),
|
|
1026
|
-
// ── Chart Palette ────────────────────────────────────────────────────────
|
|
1027
|
-
"--app-chart-1": E.optional(),
|
|
1028
|
-
"--app-chart-2": E.optional(),
|
|
1029
|
-
"--app-chart-3": E.optional(),
|
|
1030
|
-
"--app-chart-4": E.optional(),
|
|
1031
|
-
"--app-chart-5": E.optional()
|
|
1032
|
-
}).strict(), Et = e.object({
|
|
1033
|
-
/** Google Font name for headings (h1–h4, .font-serif). Example: "Playfair Display" */
|
|
1034
|
-
heading: e.string(),
|
|
1035
|
-
/** Google Font name for body text. Example: "Inter" */
|
|
1036
|
-
body: e.string(),
|
|
1037
|
-
/** Optional monospace font. Example: "Roboto Mono" */
|
|
1038
|
-
mono: e.string().optional()
|
|
1039
|
-
});
|
|
1040
|
-
e.object({
|
|
1041
|
-
/** Short descriptive theme name. Example: "Midnight Garden" */
|
|
1042
|
-
name: e.string(),
|
|
1043
|
-
/** One-sentence vibe description. Example: "Dark indigo with golden accents." */
|
|
1044
|
-
description: e.string(),
|
|
1045
|
-
/** Google Font pairing for heading and body text. */
|
|
1046
|
-
fonts: Et.optional(),
|
|
1047
|
-
/**
|
|
1048
|
-
* CSS variable overrides.
|
|
1049
|
-
* Every key must match an --app-* variable name.
|
|
1050
|
-
* All color values must be space-separated RGB integers.
|
|
1051
|
-
*/
|
|
1052
|
-
cssVars: St
|
|
1053
|
-
});
|
|
1054
|
-
e.object({
|
|
1055
|
-
primary: E,
|
|
1056
|
-
neutral: E,
|
|
1057
|
-
success: E,
|
|
1058
|
-
warning: E,
|
|
1059
|
-
destructive: E,
|
|
1060
|
-
radius: e.enum(["none", "sm", "md", "lg", "full"])
|
|
1061
|
-
});
|
|
1062
|
-
var Yr = {
|
|
1063
|
-
primary: "13 110 253",
|
|
1064
|
-
neutral: "24 24 27",
|
|
1065
|
-
success: "34 197 94",
|
|
1066
|
-
warning: "234 179 8",
|
|
1067
|
-
destructive: "239 68 68",
|
|
1068
|
-
radius: "md"
|
|
1069
|
-
};
|
|
1070
|
-
e.object({
|
|
1071
|
-
id: e.string().default(""),
|
|
1072
|
-
name: e.string(),
|
|
1073
|
-
email: e.string().email(),
|
|
1074
|
-
password: e.string().optional(),
|
|
1075
|
-
role: e.string(),
|
|
1076
|
-
status: e.string().optional(),
|
|
1077
|
-
joinedAt: e.string().optional(),
|
|
1078
|
-
lastActive: e.string().optional(),
|
|
1079
|
-
avatarUrl: e.string().optional()
|
|
1080
|
-
});
|
|
1081
|
-
var q = e.string().regex(/^acct_[0-9a-f]{12}$/, "acct_ and 12 hex digits"), ie = e.enum(["member", "admin"]), ve = e.enum(["active", "suspended"]), _t = e.object({
|
|
1082
|
-
algo: e.literal("scrypt"),
|
|
1083
|
-
n: e.number().int().positive(),
|
|
1084
|
-
r: e.number().int().positive(),
|
|
1085
|
-
p: e.number().int().positive(),
|
|
1086
|
-
keylen: e.number().int().positive(),
|
|
1087
|
-
salt: e.string().min(16),
|
|
1088
|
-
hash: e.string().min(16)
|
|
1089
|
-
});
|
|
1090
|
-
e.object({
|
|
1091
|
-
accountId: q,
|
|
1092
|
-
/** Lowercased on write, because a login must not depend on how it was typed. */
|
|
1093
|
-
email: e.string().email().max(254),
|
|
1094
|
-
name: e.string().min(1).max(64),
|
|
1095
|
-
role: ie,
|
|
1096
|
-
status: ve,
|
|
1097
|
-
password: _t,
|
|
1098
|
-
createdAt: e.number().int().nonnegative(),
|
|
1099
|
-
lastLoginAt: e.number().int().nonnegative().nullable().default(null),
|
|
1100
|
-
/** Which admin approved this, or null for the bootstrap account. */
|
|
1101
|
-
invitedBy: q.nullable().default(null)
|
|
1102
|
-
});
|
|
1103
|
-
e.object({
|
|
1104
|
-
accountId: q,
|
|
1105
|
-
email: e.string().email(),
|
|
1106
|
-
name: e.string(),
|
|
1107
|
-
role: ie,
|
|
1108
|
-
status: ve
|
|
1109
|
-
});
|
|
1110
|
-
e.object({
|
|
1111
|
-
accountId: q,
|
|
1112
|
-
createdAt: e.number().int().nonnegative(),
|
|
1113
|
-
expiresAt: e.number().int().nonnegative(),
|
|
1114
|
-
lastSeenAt: e.number().int().nonnegative()
|
|
1115
|
-
});
|
|
1116
|
-
e.object({
|
|
1117
|
-
email: e.string().email().max(254),
|
|
1118
|
-
role: ie,
|
|
1119
|
-
createdAt: e.number().int().nonnegative(),
|
|
1120
|
-
expiresAt: e.number().int().nonnegative(),
|
|
1121
|
-
invitedBy: q
|
|
1122
|
-
});
|
|
1123
|
-
e.object({
|
|
1124
|
-
email: e.string().email().max(254),
|
|
1125
|
-
name: e.string().min(1).max(64),
|
|
1126
|
-
/** Optional, and never shown publicly. Long enough to be useful, short enough not to be an essay. */
|
|
1127
|
-
reason: e.string().max(500).optional()
|
|
1128
|
-
});
|
|
1129
|
-
var Tt = e.enum(["pending", "approved", "denied"]);
|
|
1130
|
-
e.object({
|
|
1131
|
-
requestId: e.string().regex(/^req_[0-9a-f]{12}$/, "req_ and 12 hex digits"),
|
|
1132
|
-
email: e.string().email().max(254),
|
|
1133
|
-
name: e.string().min(1).max(64),
|
|
1134
|
-
reason: e.string().max(500).optional(),
|
|
1135
|
-
status: Tt,
|
|
1136
|
-
createdAt: e.number().int().nonnegative(),
|
|
1137
|
-
decidedAt: e.number().int().nonnegative().nullable().default(null),
|
|
1138
|
-
decidedBy: q.nullable().default(null)
|
|
1139
|
-
});
|
|
1140
|
-
var jt = e.enum([
|
|
1141
|
-
"supplier",
|
|
1142
|
-
"customer",
|
|
1143
|
-
"partner",
|
|
1144
|
-
"competitor",
|
|
1145
|
-
"regulator",
|
|
1146
|
-
"unknown"
|
|
1147
|
-
]), Ot = e.enum([
|
|
1148
|
-
"public",
|
|
1149
|
-
"public_uncovered",
|
|
1150
|
-
"private",
|
|
1151
|
-
"unresolved"
|
|
1152
|
-
]);
|
|
1153
|
-
e.object({
|
|
1154
|
-
id: e.string(),
|
|
1155
|
-
ticker: e.string().nullable(),
|
|
1156
|
-
/** Name as it appeared in the source signal — e.g. "Nike". Not the registered name. */
|
|
1157
|
-
name: e.string(),
|
|
1158
|
-
/** Registered legal name from `profiles` — e.g. "NIKE, Inc.". Null unless `public`. */
|
|
1159
|
-
publicName: e.string().nullable(),
|
|
1160
|
-
lei: e.string().nullable(),
|
|
1161
|
-
resolution: Ot,
|
|
1162
|
-
type: jt,
|
|
1163
|
-
confidence: e.number().min(0).max(1),
|
|
1164
|
-
sourceSignalIds: e.array(e.number()),
|
|
1165
|
-
firstSeenAt: e.string().datetime(),
|
|
1166
|
-
lastSeenAt: e.string().datetime()
|
|
1167
|
-
});
|
|
1168
|
-
var Pt = e.enum([
|
|
1169
|
-
"supplies_to",
|
|
1170
|
-
"purchases_from",
|
|
1171
|
-
"partners_with",
|
|
1172
|
-
"competes_with",
|
|
1173
|
-
"regulated_by",
|
|
1174
|
-
"invests_in",
|
|
1175
|
-
"acquires",
|
|
1176
|
-
/**
|
|
1177
|
-
* Identity equivalence, not a business relationship: source and target are
|
|
1178
|
-
* the same real-world entity under two different node ids (typically a
|
|
1179
|
-
* slug-keyed node that predates LEI resolution, pointing at the canonical
|
|
1180
|
-
* LEI-keyed node once resolution succeeds). Never delete/merge either
|
|
1181
|
-
* node — this edge exists so a consumer wanting a deduped view can follow
|
|
1182
|
-
* it to the canonical id, reversibly.
|
|
1183
|
-
*/
|
|
1184
|
-
"same_as"
|
|
1185
|
-
]);
|
|
1186
|
-
e.object({
|
|
1187
|
-
id: e.string(),
|
|
1188
|
-
sourceId: e.string(),
|
|
1189
|
-
targetId: e.string(),
|
|
1190
|
-
edgeType: Pt,
|
|
1191
|
-
weight: e.number().min(0).max(1),
|
|
1192
|
-
evidenceSignalIds: e.array(e.number()),
|
|
1193
|
-
updatedAt: e.string().datetime(),
|
|
1194
|
-
validFrom: e.string().datetime(),
|
|
1195
|
-
/** null = currently valid. Set when a differently-typed edge supersedes this one. */
|
|
1196
|
-
validTo: e.string().datetime().nullable()
|
|
1197
|
-
});
|
|
1198
|
-
var Rt = e.object({
|
|
1199
|
-
signalId: e.number(),
|
|
1200
|
-
weight: e.number().min(0).max(1),
|
|
1201
|
-
reason: e.string().max(280)
|
|
1202
|
-
});
|
|
1203
|
-
e.object({
|
|
1204
|
-
ticker: e.string(),
|
|
1205
|
-
// 'operations'/'customer' are current; 'operational'/'ux' are pre-rename
|
|
1206
|
-
// values that still exist on rows written before the backend's rename —
|
|
1207
|
-
// kept here so reading old rows doesn't fail validation.
|
|
1208
|
-
metric: e.enum(["operations", "customer", "operational", "ux"]),
|
|
1209
|
-
score: e.number(),
|
|
1210
|
-
baseline: e.number(),
|
|
1211
|
-
observed: e.number(),
|
|
1212
|
-
computedAt: e.string().datetime(),
|
|
1213
|
-
contributingSignals: e.array(Rt)
|
|
1214
|
-
});
|
|
1215
|
-
e.object({
|
|
1216
|
-
lei: e.string().nullable(),
|
|
1217
|
-
entityName: e.string(),
|
|
1218
|
-
jurisdiction: e.string().nullable(),
|
|
1219
|
-
registrationStatus: e.string(),
|
|
1220
|
-
parentEntityLei: e.string().nullable(),
|
|
1221
|
-
materialMetadata: e.record(e.unknown()),
|
|
1222
|
-
discoveredAt: e.string().datetime()
|
|
1223
|
-
});
|
|
1224
|
-
var X = e.enum(["db", "mock"]), se = e.enum(["news", "filing", "report"]), xe = e.enum(["graded", "binary", "default", "none"]), It = e.enum(["second", "day"]), Nt = e.object({
|
|
1225
|
-
/** Namespaced so ids never collide across sources: `news:1234`, `filing:AAPL:2026-07-31`. */
|
|
1226
|
-
id: e.string(),
|
|
1227
|
-
kind: se,
|
|
1228
|
-
/**
|
|
1229
|
-
* The producer's own type string, unmodified — `NEWS_YAHOO FINANCE_YAHOO RSS`,
|
|
1230
|
-
* `ANNUAL`, `SNAPSHOT`. There are 31 distinct NEWS variants in the live table,
|
|
1231
|
-
* so this is for filtering and debugging: never render it raw to a user.
|
|
1232
|
-
*/
|
|
1233
|
-
subtype: e.string().nullable(),
|
|
1234
|
-
ticker: e.string(),
|
|
1235
|
-
/** Always `YYYY-MM-DDTHH:MM:SSZ`. Fixed-width, so lexical order == chronological order. */
|
|
1236
|
-
occurredAt: e.string(),
|
|
1237
|
-
precision: It,
|
|
1238
|
-
title: e.string(),
|
|
1239
|
-
summary: e.string().nullable(),
|
|
1240
|
-
url: e.string().nullable(),
|
|
1241
|
-
impact: e.number().nullable(),
|
|
1242
|
-
impactScale: xe,
|
|
1243
|
-
/** 0 bearish … 50 neutral … 100 bullish. */
|
|
1244
|
-
sentiment: e.number().nullable(),
|
|
1245
|
-
/** False for filings, and for any event sitting at exactly neutral. */
|
|
1246
|
-
sentimentIsMeaningful: e.boolean(),
|
|
1247
|
-
source: X,
|
|
1248
|
-
meta: e.record(e.unknown()).nullable()
|
|
1249
|
-
});
|
|
1250
|
-
e.object({
|
|
1251
|
-
total: e.number(),
|
|
1252
|
-
page: e.number(),
|
|
1253
|
-
page_size: e.number(),
|
|
1254
|
-
data: e.array(Nt)
|
|
1255
|
-
});
|
|
1256
|
-
var $t = e.enum(["day", "week", "month"]), Ct = e.object({
|
|
1257
|
-
bucketStart: e.string(),
|
|
1258
|
-
kind: se,
|
|
1259
|
-
count: e.number(),
|
|
1260
|
-
/** Null when no event in the bucket had meaningful sentiment. */
|
|
1261
|
-
avgSentiment: e.number().nullable(),
|
|
1262
|
-
maxImpact: e.number().nullable()
|
|
1263
|
-
});
|
|
1264
|
-
e.object({
|
|
1265
|
-
ticker: e.string(),
|
|
1266
|
-
bucket: $t,
|
|
1267
|
-
buckets: e.array(Ct),
|
|
1268
|
-
/** So the client can set its time domain without a second request. */
|
|
1269
|
-
range: e.object({ min: e.string(), max: e.string() }),
|
|
1270
|
-
source: X
|
|
1271
|
-
});
|
|
1272
|
-
var Dt = e.object({
|
|
1273
|
-
kind: se,
|
|
1274
|
-
count: e.number(),
|
|
1275
|
-
earliest: e.string().nullable(),
|
|
1276
|
-
latest: e.string().nullable(),
|
|
1277
|
-
impactScale: xe,
|
|
1278
|
-
sentimentUsable: e.boolean()
|
|
1279
|
-
});
|
|
1280
|
-
e.object({
|
|
1281
|
-
ticker: e.string(),
|
|
1282
|
-
facets: e.array(Dt),
|
|
1283
|
-
source: X
|
|
1284
|
-
});
|
|
1285
|
-
var Mt = e.object({
|
|
1286
|
-
date: e.string(),
|
|
1287
|
-
open: e.number().nullable(),
|
|
1288
|
-
high: e.number().nullable(),
|
|
1289
|
-
low: e.number().nullable(),
|
|
1290
|
-
close: e.number(),
|
|
1291
|
-
volume: e.number().nullable()
|
|
1292
|
-
});
|
|
1293
|
-
e.object({
|
|
1294
|
-
ticker: e.string(),
|
|
1295
|
-
series: e.array(Mt),
|
|
1296
|
-
source: X
|
|
1297
|
-
});
|
|
1298
|
-
var Kr = 50;
|
|
1299
|
-
const ce = {
|
|
1300
|
-
// May 2026 stable series — gemini-2.0-flash is deprecated (404)
|
|
1301
|
-
"google-gemini": ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.5-flash-preview-05-20", "gemini-1.5-flash"],
|
|
1302
|
-
openai: ["gpt-4o", "gpt-4o-mini", "gpt-4-turbo", "gpt-3.5-turbo"],
|
|
1303
|
-
// Verified live via client.models.list() this session — claude-3-5-haiku
|
|
1304
|
-
// and claude-3-opus (the old list) no longer appear in the current
|
|
1305
|
-
// catalog at all. claude-haiku-4-5 leads (used as PROVIDER_MODELS['anthropic'][0],
|
|
1306
|
-
// the auto-selected default) since it's this app's own real Model
|
|
1307
|
-
// Inventory's top performer (avg comparison score 91.6 across every
|
|
1308
|
-
// Compare Models run it's been in).
|
|
1309
|
-
anthropic: ["claude-haiku-4-5-20251001", "claude-sonnet-5", "claude-opus-5"],
|
|
1310
|
-
grok: ["grok-beta", "grok-vision-beta"],
|
|
1311
|
-
deepseek: ["deepseek-chat", "deepseek-coder"],
|
|
1312
|
-
// Real, currently-pulled models on this deployment's Ollama instance
|
|
1313
|
-
// (verified via GET /api/tags, not guessed) — 'llama3.1'/'mistral'/
|
|
1314
|
-
// 'codellama'/'qwen2.5' were never actually pulled locally, so picking
|
|
1315
|
-
// any of them would 404 at request time. llama3.3 leads the list (used
|
|
1316
|
-
// as PROVIDER_MODELS[provider][0], the auto-selected default on
|
|
1317
|
-
// provider switch) since it's already this app's proven-reliable
|
|
1318
|
-
// default for Ollama-backed report generation elsewhere
|
|
1319
|
-
// (core/ai_router.py's DEFAULT_MODELS) — llama3.2 (3B) was found live
|
|
1320
|
-
// to mis-trigger tool calls on plain greetings.
|
|
1321
|
-
ollama: ["llama3.3", "qwen2.5:32b", "qwen2.5-coder:32b", "qwen2.5-coder:14b", "qwen2.5-coder:7b", "llama3.2"]
|
|
1322
|
-
}, Xr = {
|
|
1323
|
-
"google-gemini": "Google Gemini",
|
|
1324
|
-
openai: "OpenAI",
|
|
1325
|
-
anthropic: "Anthropic (Claude)",
|
|
1326
|
-
grok: "xAI Grok",
|
|
1327
|
-
deepseek: "DeepSeek",
|
|
1328
|
-
ollama: "Ollama (Local)"
|
|
1329
|
-
}, Qr = {
|
|
1330
|
-
"google-gemini": "AIzaSy…",
|
|
1331
|
-
openai: "sk-…",
|
|
1332
|
-
anthropic: "sk-ant-…",
|
|
1333
|
-
grok: "xai-…",
|
|
1334
|
-
deepseek: "sk-…"
|
|
1335
|
-
}, Bt = Symbol("Let zodToJsonSchema decide on which parser to use"), pe = {
|
|
1336
|
-
name: void 0,
|
|
1337
|
-
$refStrategy: "root",
|
|
1338
|
-
basePath: ["#"],
|
|
1339
|
-
effectStrategy: "input",
|
|
1340
|
-
pipeStrategy: "all",
|
|
1341
|
-
dateStrategy: "format:date-time",
|
|
1342
|
-
mapStrategy: "entries",
|
|
1343
|
-
removeAdditionalStrategy: "passthrough",
|
|
1344
|
-
allowedAdditionalProperties: !0,
|
|
1345
|
-
rejectedAdditionalProperties: !1,
|
|
1346
|
-
definitionPath: "definitions",
|
|
1347
|
-
target: "jsonSchema7",
|
|
1348
|
-
strictUnions: !1,
|
|
1349
|
-
definitions: {},
|
|
1350
|
-
errorMessages: !1,
|
|
1351
|
-
markdownDescription: !1,
|
|
1352
|
-
patternStrategy: "escape",
|
|
1353
|
-
applyRegexFlags: !1,
|
|
1354
|
-
emailStrategy: "format:email",
|
|
1355
|
-
base64Strategy: "contentEncoding:base64",
|
|
1356
|
-
nameStrategy: "ref",
|
|
1357
|
-
openAiAnyTypeName: "OpenAiAnyType"
|
|
1358
|
-
}, Lt = (a) => typeof a == "string" ? {
|
|
1359
|
-
...pe,
|
|
1360
|
-
name: a
|
|
1361
|
-
} : {
|
|
1362
|
-
...pe,
|
|
1363
|
-
...a
|
|
1364
|
-
}, qt = (a) => {
|
|
1365
|
-
const t = Lt(a), n = t.name !== void 0 ? [...t.basePath, t.definitionPath, t.name] : t.basePath;
|
|
1366
|
-
return {
|
|
1367
|
-
...t,
|
|
1368
|
-
flags: { hasReferencedOpenAiAnyType: !1 },
|
|
1369
|
-
currentPath: n,
|
|
1370
|
-
propertyPath: void 0,
|
|
1371
|
-
seen: new Map(Object.entries(t.definitions).map(([r, o]) => [
|
|
1372
|
-
o._def,
|
|
1373
|
-
{
|
|
1374
|
-
def: o._def,
|
|
1375
|
-
path: [...t.basePath, t.definitionPath, r],
|
|
1376
|
-
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
1377
|
-
jsonSchema: void 0
|
|
1378
|
-
}
|
|
1379
|
-
]))
|
|
1380
|
-
};
|
|
1381
|
-
};
|
|
1382
|
-
function Ae(a, t, n, r) {
|
|
1383
|
-
r != null && r.errorMessages && n && (a.errorMessage = {
|
|
1384
|
-
...a.errorMessage,
|
|
1385
|
-
[t]: n
|
|
1386
|
-
});
|
|
1387
|
-
}
|
|
1388
|
-
function k(a, t, n, r, o) {
|
|
1389
|
-
a[t] = n, Ae(a, t, r, o);
|
|
1390
|
-
}
|
|
1391
|
-
const ke = (a, t) => {
|
|
1392
|
-
let n = 0;
|
|
1393
|
-
for (; n < a.length && n < t.length && a[n] === t[n]; n++)
|
|
1394
|
-
;
|
|
1395
|
-
return [(a.length - n).toString(), ...t.slice(n)].join("/");
|
|
1396
|
-
};
|
|
1397
|
-
var y;
|
|
1398
|
-
(function(a) {
|
|
1399
|
-
a.ZodString = "ZodString", a.ZodNumber = "ZodNumber", a.ZodNaN = "ZodNaN", a.ZodBigInt = "ZodBigInt", a.ZodBoolean = "ZodBoolean", a.ZodDate = "ZodDate", a.ZodSymbol = "ZodSymbol", a.ZodUndefined = "ZodUndefined", a.ZodNull = "ZodNull", a.ZodAny = "ZodAny", a.ZodUnknown = "ZodUnknown", a.ZodNever = "ZodNever", a.ZodVoid = "ZodVoid", a.ZodArray = "ZodArray", a.ZodObject = "ZodObject", a.ZodUnion = "ZodUnion", a.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", a.ZodIntersection = "ZodIntersection", a.ZodTuple = "ZodTuple", a.ZodRecord = "ZodRecord", a.ZodMap = "ZodMap", a.ZodSet = "ZodSet", a.ZodFunction = "ZodFunction", a.ZodLazy = "ZodLazy", a.ZodLiteral = "ZodLiteral", a.ZodEnum = "ZodEnum", a.ZodEffects = "ZodEffects", a.ZodNativeEnum = "ZodNativeEnum", a.ZodOptional = "ZodOptional", a.ZodNullable = "ZodNullable", a.ZodDefault = "ZodDefault", a.ZodCatch = "ZodCatch", a.ZodPromise = "ZodPromise", a.ZodBranded = "ZodBranded", a.ZodPipeline = "ZodPipeline", a.ZodReadonly = "ZodReadonly";
|
|
1400
|
-
})(y || (y = {}));
|
|
1401
|
-
function P(a) {
|
|
1402
|
-
if (a.target !== "openAi")
|
|
1403
|
-
return {};
|
|
1404
|
-
const t = [
|
|
1405
|
-
...a.basePath,
|
|
1406
|
-
a.definitionPath,
|
|
1407
|
-
a.openAiAnyTypeName
|
|
1408
|
-
];
|
|
1409
|
-
return a.flags.hasReferencedOpenAiAnyType = !0, {
|
|
1410
|
-
$ref: a.$refStrategy === "relative" ? ke(t, a.currentPath) : t.join("/")
|
|
1411
|
-
};
|
|
1412
|
-
}
|
|
1413
|
-
function Ut(a, t) {
|
|
1414
|
-
var r, o, i;
|
|
1415
|
-
const n = {
|
|
1416
|
-
type: "array"
|
|
1417
|
-
};
|
|
1418
|
-
return (r = a.type) != null && r._def && ((i = (o = a.type) == null ? void 0 : o._def) == null ? void 0 : i.typeName) !== y.ZodAny && (n.items = v(a.type._def, {
|
|
1419
|
-
...t,
|
|
1420
|
-
currentPath: [...t.currentPath, "items"]
|
|
1421
|
-
})), a.minLength && k(n, "minItems", a.minLength.value, a.minLength.message, t), a.maxLength && k(n, "maxItems", a.maxLength.value, a.maxLength.message, t), a.exactLength && (k(n, "minItems", a.exactLength.value, a.exactLength.message, t), k(n, "maxItems", a.exactLength.value, a.exactLength.message, t)), n;
|
|
1422
|
-
}
|
|
1423
|
-
function Zt(a, t) {
|
|
1424
|
-
const n = {
|
|
1425
|
-
type: "integer",
|
|
1426
|
-
format: "int64"
|
|
1427
|
-
};
|
|
1428
|
-
if (!a.checks)
|
|
1429
|
-
return n;
|
|
1430
|
-
for (const r of a.checks)
|
|
1431
|
-
switch (r.kind) {
|
|
1432
|
-
case "min":
|
|
1433
|
-
t.target === "jsonSchema7" ? r.inclusive ? k(n, "minimum", r.value, r.message, t) : k(n, "exclusiveMinimum", r.value, r.message, t) : (r.inclusive || (n.exclusiveMinimum = !0), k(n, "minimum", r.value, r.message, t));
|
|
1434
|
-
break;
|
|
1435
|
-
case "max":
|
|
1436
|
-
t.target === "jsonSchema7" ? r.inclusive ? k(n, "maximum", r.value, r.message, t) : k(n, "exclusiveMaximum", r.value, r.message, t) : (r.inclusive || (n.exclusiveMaximum = !0), k(n, "maximum", r.value, r.message, t));
|
|
1437
|
-
break;
|
|
1438
|
-
case "multipleOf":
|
|
1439
|
-
k(n, "multipleOf", r.value, r.message, t);
|
|
1440
|
-
break;
|
|
1441
|
-
}
|
|
1442
|
-
return n;
|
|
1443
|
-
}
|
|
1444
|
-
function zt() {
|
|
1445
|
-
return {
|
|
1446
|
-
type: "boolean"
|
|
1447
|
-
};
|
|
1448
|
-
}
|
|
1449
|
-
function Se(a, t) {
|
|
1450
|
-
return v(a.type._def, t);
|
|
1451
|
-
}
|
|
1452
|
-
const Ft = (a, t) => v(a.innerType._def, t);
|
|
1453
|
-
function Ee(a, t, n) {
|
|
1454
|
-
const r = n ?? t.dateStrategy;
|
|
1455
|
-
if (Array.isArray(r))
|
|
1456
|
-
return {
|
|
1457
|
-
anyOf: r.map((o, i) => Ee(a, t, o))
|
|
1458
|
-
};
|
|
1459
|
-
switch (r) {
|
|
1460
|
-
case "string":
|
|
1461
|
-
case "format:date-time":
|
|
1462
|
-
return {
|
|
1463
|
-
type: "string",
|
|
1464
|
-
format: "date-time"
|
|
1465
|
-
};
|
|
1466
|
-
case "format:date":
|
|
1467
|
-
return {
|
|
1468
|
-
type: "string",
|
|
1469
|
-
format: "date"
|
|
1470
|
-
};
|
|
1471
|
-
case "integer":
|
|
1472
|
-
return Jt(a, t);
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
const Jt = (a, t) => {
|
|
1476
|
-
const n = {
|
|
1477
|
-
type: "integer",
|
|
1478
|
-
format: "unix-time"
|
|
1479
|
-
};
|
|
1480
|
-
if (t.target === "openApi3")
|
|
1481
|
-
return n;
|
|
1482
|
-
for (const r of a.checks)
|
|
1483
|
-
switch (r.kind) {
|
|
1484
|
-
case "min":
|
|
1485
|
-
k(
|
|
1486
|
-
n,
|
|
1487
|
-
"minimum",
|
|
1488
|
-
r.value,
|
|
1489
|
-
// This is in milliseconds
|
|
1490
|
-
r.message,
|
|
1491
|
-
t
|
|
1492
|
-
);
|
|
1493
|
-
break;
|
|
1494
|
-
case "max":
|
|
1495
|
-
k(
|
|
1496
|
-
n,
|
|
1497
|
-
"maximum",
|
|
1498
|
-
r.value,
|
|
1499
|
-
// This is in milliseconds
|
|
1500
|
-
r.message,
|
|
1501
|
-
t
|
|
1502
|
-
);
|
|
1503
|
-
break;
|
|
1504
|
-
}
|
|
1505
|
-
return n;
|
|
1506
|
-
};
|
|
1507
|
-
function Gt(a, t) {
|
|
1508
|
-
return {
|
|
1509
|
-
...v(a.innerType._def, t),
|
|
1510
|
-
default: a.defaultValue()
|
|
1511
|
-
};
|
|
1512
|
-
}
|
|
1513
|
-
function Vt(a, t) {
|
|
1514
|
-
return t.effectStrategy === "input" ? v(a.schema._def, t) : P(t);
|
|
1515
|
-
}
|
|
1516
|
-
function Wt(a) {
|
|
1517
|
-
return {
|
|
1518
|
-
type: "string",
|
|
1519
|
-
enum: Array.from(a.values)
|
|
1520
|
-
};
|
|
1521
|
-
}
|
|
1522
|
-
const Ht = (a) => "type" in a && a.type === "string" ? !1 : "allOf" in a;
|
|
1523
|
-
function Yt(a, t) {
|
|
1524
|
-
const n = [
|
|
1525
|
-
v(a.left._def, {
|
|
1526
|
-
...t,
|
|
1527
|
-
currentPath: [...t.currentPath, "allOf", "0"]
|
|
1528
|
-
}),
|
|
1529
|
-
v(a.right._def, {
|
|
1530
|
-
...t,
|
|
1531
|
-
currentPath: [...t.currentPath, "allOf", "1"]
|
|
1532
|
-
})
|
|
1533
|
-
].filter((i) => !!i);
|
|
1534
|
-
let r = t.target === "jsonSchema2019-09" ? { unevaluatedProperties: !1 } : void 0;
|
|
1535
|
-
const o = [];
|
|
1536
|
-
return n.forEach((i) => {
|
|
1537
|
-
if (Ht(i))
|
|
1538
|
-
o.push(...i.allOf), i.unevaluatedProperties === void 0 && (r = void 0);
|
|
1539
|
-
else {
|
|
1540
|
-
let s = i;
|
|
1541
|
-
if ("additionalProperties" in i && i.additionalProperties === !1) {
|
|
1542
|
-
const { additionalProperties: c, ...l } = i;
|
|
1543
|
-
s = l;
|
|
1544
|
-
} else
|
|
1545
|
-
r = void 0;
|
|
1546
|
-
o.push(s);
|
|
1547
|
-
}
|
|
1548
|
-
}), o.length ? {
|
|
1549
|
-
allOf: o,
|
|
1550
|
-
...r
|
|
1551
|
-
} : void 0;
|
|
1552
|
-
}
|
|
1553
|
-
function Kt(a, t) {
|
|
1554
|
-
const n = typeof a.value;
|
|
1555
|
-
return n !== "bigint" && n !== "number" && n !== "boolean" && n !== "string" ? {
|
|
1556
|
-
type: Array.isArray(a.value) ? "array" : "object"
|
|
1557
|
-
} : t.target === "openApi3" ? {
|
|
1558
|
-
type: n === "bigint" ? "integer" : n,
|
|
1559
|
-
enum: [a.value]
|
|
1560
|
-
} : {
|
|
1561
|
-
type: n === "bigint" ? "integer" : n,
|
|
1562
|
-
const: a.value
|
|
1563
|
-
};
|
|
1564
|
-
}
|
|
1565
|
-
let ee;
|
|
1566
|
-
const I = {
|
|
1567
|
-
/**
|
|
1568
|
-
* `c` was changed to `[cC]` to replicate /i flag
|
|
1569
|
-
*/
|
|
1570
|
-
cuid: /^[cC][^\s-]{8,}$/,
|
|
1571
|
-
cuid2: /^[0-9a-z]+$/,
|
|
1572
|
-
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
1573
|
-
/**
|
|
1574
|
-
* `a-z` was added to replicate /i flag
|
|
1575
|
-
*/
|
|
1576
|
-
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
1577
|
-
/**
|
|
1578
|
-
* Constructed a valid Unicode RegExp
|
|
1579
|
-
*
|
|
1580
|
-
* Lazily instantiate since this type of regex isn't supported
|
|
1581
|
-
* in all envs (e.g. React Native).
|
|
1582
|
-
*
|
|
1583
|
-
* See:
|
|
1584
|
-
* https://github.com/colinhacks/zod/issues/2433
|
|
1585
|
-
* Fix in Zod:
|
|
1586
|
-
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
1587
|
-
*/
|
|
1588
|
-
emoji: () => (ee === void 0 && (ee = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u")), ee),
|
|
1589
|
-
/**
|
|
1590
|
-
* Unused
|
|
1591
|
-
*/
|
|
1592
|
-
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
1593
|
-
/**
|
|
1594
|
-
* Unused
|
|
1595
|
-
*/
|
|
1596
|
-
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
1597
|
-
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
1598
|
-
/**
|
|
1599
|
-
* Unused
|
|
1600
|
-
*/
|
|
1601
|
-
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
1602
|
-
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
1603
|
-
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
1604
|
-
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
1605
|
-
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
1606
|
-
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
1607
|
-
};
|
|
1608
|
-
function _e(a, t) {
|
|
1609
|
-
const n = {
|
|
1610
|
-
type: "string"
|
|
1611
|
-
};
|
|
1612
|
-
if (a.checks)
|
|
1613
|
-
for (const r of a.checks)
|
|
1614
|
-
switch (r.kind) {
|
|
1615
|
-
case "min":
|
|
1616
|
-
k(n, "minLength", typeof n.minLength == "number" ? Math.max(n.minLength, r.value) : r.value, r.message, t);
|
|
1617
|
-
break;
|
|
1618
|
-
case "max":
|
|
1619
|
-
k(n, "maxLength", typeof n.maxLength == "number" ? Math.min(n.maxLength, r.value) : r.value, r.message, t);
|
|
1620
|
-
break;
|
|
1621
|
-
case "email":
|
|
1622
|
-
switch (t.emailStrategy) {
|
|
1623
|
-
case "format:email":
|
|
1624
|
-
N(n, "email", r.message, t);
|
|
1625
|
-
break;
|
|
1626
|
-
case "format:idn-email":
|
|
1627
|
-
N(n, "idn-email", r.message, t);
|
|
1628
|
-
break;
|
|
1629
|
-
case "pattern:zod":
|
|
1630
|
-
O(n, I.email, r.message, t);
|
|
1631
|
-
break;
|
|
1632
|
-
}
|
|
1633
|
-
break;
|
|
1634
|
-
case "url":
|
|
1635
|
-
N(n, "uri", r.message, t);
|
|
1636
|
-
break;
|
|
1637
|
-
case "uuid":
|
|
1638
|
-
N(n, "uuid", r.message, t);
|
|
1639
|
-
break;
|
|
1640
|
-
case "regex":
|
|
1641
|
-
O(n, r.regex, r.message, t);
|
|
1642
|
-
break;
|
|
1643
|
-
case "cuid":
|
|
1644
|
-
O(n, I.cuid, r.message, t);
|
|
1645
|
-
break;
|
|
1646
|
-
case "cuid2":
|
|
1647
|
-
O(n, I.cuid2, r.message, t);
|
|
1648
|
-
break;
|
|
1649
|
-
case "startsWith":
|
|
1650
|
-
O(n, RegExp(`^${te(r.value, t)}`), r.message, t);
|
|
1651
|
-
break;
|
|
1652
|
-
case "endsWith":
|
|
1653
|
-
O(n, RegExp(`${te(r.value, t)}$`), r.message, t);
|
|
1654
|
-
break;
|
|
1655
|
-
case "datetime":
|
|
1656
|
-
N(n, "date-time", r.message, t);
|
|
1657
|
-
break;
|
|
1658
|
-
case "date":
|
|
1659
|
-
N(n, "date", r.message, t);
|
|
1660
|
-
break;
|
|
1661
|
-
case "time":
|
|
1662
|
-
N(n, "time", r.message, t);
|
|
1663
|
-
break;
|
|
1664
|
-
case "duration":
|
|
1665
|
-
N(n, "duration", r.message, t);
|
|
1666
|
-
break;
|
|
1667
|
-
case "length":
|
|
1668
|
-
k(n, "minLength", typeof n.minLength == "number" ? Math.max(n.minLength, r.value) : r.value, r.message, t), k(n, "maxLength", typeof n.maxLength == "number" ? Math.min(n.maxLength, r.value) : r.value, r.message, t);
|
|
1669
|
-
break;
|
|
1670
|
-
case "includes": {
|
|
1671
|
-
O(n, RegExp(te(r.value, t)), r.message, t);
|
|
1672
|
-
break;
|
|
1673
|
-
}
|
|
1674
|
-
case "ip": {
|
|
1675
|
-
r.version !== "v6" && N(n, "ipv4", r.message, t), r.version !== "v4" && N(n, "ipv6", r.message, t);
|
|
1676
|
-
break;
|
|
1677
|
-
}
|
|
1678
|
-
case "base64url":
|
|
1679
|
-
O(n, I.base64url, r.message, t);
|
|
1680
|
-
break;
|
|
1681
|
-
case "jwt":
|
|
1682
|
-
O(n, I.jwt, r.message, t);
|
|
1683
|
-
break;
|
|
1684
|
-
case "cidr": {
|
|
1685
|
-
r.version !== "v6" && O(n, I.ipv4Cidr, r.message, t), r.version !== "v4" && O(n, I.ipv6Cidr, r.message, t);
|
|
1686
|
-
break;
|
|
1687
|
-
}
|
|
1688
|
-
case "emoji":
|
|
1689
|
-
O(n, I.emoji(), r.message, t);
|
|
1690
|
-
break;
|
|
1691
|
-
case "ulid": {
|
|
1692
|
-
O(n, I.ulid, r.message, t);
|
|
1693
|
-
break;
|
|
1694
|
-
}
|
|
1695
|
-
case "base64": {
|
|
1696
|
-
switch (t.base64Strategy) {
|
|
1697
|
-
case "format:binary": {
|
|
1698
|
-
N(n, "binary", r.message, t);
|
|
1699
|
-
break;
|
|
1700
|
-
}
|
|
1701
|
-
case "contentEncoding:base64": {
|
|
1702
|
-
k(n, "contentEncoding", "base64", r.message, t);
|
|
1703
|
-
break;
|
|
1704
|
-
}
|
|
1705
|
-
case "pattern:zod": {
|
|
1706
|
-
O(n, I.base64, r.message, t);
|
|
1707
|
-
break;
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
break;
|
|
1711
|
-
}
|
|
1712
|
-
case "nanoid":
|
|
1713
|
-
O(n, I.nanoid, r.message, t);
|
|
1714
|
-
}
|
|
1715
|
-
return n;
|
|
1716
|
-
}
|
|
1717
|
-
function te(a, t) {
|
|
1718
|
-
return t.patternStrategy === "escape" ? Qt(a) : a;
|
|
1719
|
-
}
|
|
1720
|
-
const Xt = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
1721
|
-
function Qt(a) {
|
|
1722
|
-
let t = "";
|
|
1723
|
-
for (let n = 0; n < a.length; n++)
|
|
1724
|
-
Xt.has(a[n]) || (t += "\\"), t += a[n];
|
|
1725
|
-
return t;
|
|
1726
|
-
}
|
|
1727
|
-
function N(a, t, n, r) {
|
|
1728
|
-
var o;
|
|
1729
|
-
a.format || (o = a.anyOf) != null && o.some((i) => i.format) ? (a.anyOf || (a.anyOf = []), a.format && (a.anyOf.push({
|
|
1730
|
-
format: a.format,
|
|
1731
|
-
...a.errorMessage && r.errorMessages && {
|
|
1732
|
-
errorMessage: { format: a.errorMessage.format }
|
|
1733
|
-
}
|
|
1734
|
-
}), delete a.format, a.errorMessage && (delete a.errorMessage.format, Object.keys(a.errorMessage).length === 0 && delete a.errorMessage)), a.anyOf.push({
|
|
1735
|
-
format: t,
|
|
1736
|
-
...n && r.errorMessages && { errorMessage: { format: n } }
|
|
1737
|
-
})) : k(a, "format", t, n, r);
|
|
1738
|
-
}
|
|
1739
|
-
function O(a, t, n, r) {
|
|
1740
|
-
var o;
|
|
1741
|
-
a.pattern || (o = a.allOf) != null && o.some((i) => i.pattern) ? (a.allOf || (a.allOf = []), a.pattern && (a.allOf.push({
|
|
1742
|
-
pattern: a.pattern,
|
|
1743
|
-
...a.errorMessage && r.errorMessages && {
|
|
1744
|
-
errorMessage: { pattern: a.errorMessage.pattern }
|
|
1745
|
-
}
|
|
1746
|
-
}), delete a.pattern, a.errorMessage && (delete a.errorMessage.pattern, Object.keys(a.errorMessage).length === 0 && delete a.errorMessage)), a.allOf.push({
|
|
1747
|
-
pattern: he(t, r),
|
|
1748
|
-
...n && r.errorMessages && { errorMessage: { pattern: n } }
|
|
1749
|
-
})) : k(a, "pattern", he(t, r), n, r);
|
|
1750
|
-
}
|
|
1751
|
-
function he(a, t) {
|
|
1752
|
-
var l;
|
|
1753
|
-
if (!t.applyRegexFlags || !a.flags)
|
|
1754
|
-
return a.source;
|
|
1755
|
-
const n = {
|
|
1756
|
-
i: a.flags.includes("i"),
|
|
1757
|
-
m: a.flags.includes("m"),
|
|
1758
|
-
s: a.flags.includes("s")
|
|
1759
|
-
// `.` matches newlines
|
|
1760
|
-
}, r = n.i ? a.source.toLowerCase() : a.source;
|
|
1761
|
-
let o = "", i = !1, s = !1, c = !1;
|
|
1762
|
-
for (let u = 0; u < r.length; u++) {
|
|
1763
|
-
if (i) {
|
|
1764
|
-
o += r[u], i = !1;
|
|
1765
|
-
continue;
|
|
1766
|
-
}
|
|
1767
|
-
if (n.i) {
|
|
1768
|
-
if (s) {
|
|
1769
|
-
if (r[u].match(/[a-z]/)) {
|
|
1770
|
-
c ? (o += r[u], o += `${r[u - 2]}-${r[u]}`.toUpperCase(), c = !1) : r[u + 1] === "-" && ((l = r[u + 2]) != null && l.match(/[a-z]/)) ? (o += r[u], c = !0) : o += `${r[u]}${r[u].toUpperCase()}`;
|
|
1771
|
-
continue;
|
|
1772
|
-
}
|
|
1773
|
-
} else if (r[u].match(/[a-z]/)) {
|
|
1774
|
-
o += `[${r[u]}${r[u].toUpperCase()}]`;
|
|
1775
|
-
continue;
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
if (n.m) {
|
|
1779
|
-
if (r[u] === "^") {
|
|
1780
|
-
o += `(^|(?<=[\r
|
|
1781
|
-
]))`;
|
|
1782
|
-
continue;
|
|
1783
|
-
} else if (r[u] === "$") {
|
|
1784
|
-
o += `($|(?=[\r
|
|
1785
|
-
]))`;
|
|
1786
|
-
continue;
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
if (n.s && r[u] === ".") {
|
|
1790
|
-
o += s ? `${r[u]}\r
|
|
1791
|
-
` : `[${r[u]}\r
|
|
1792
|
-
]`;
|
|
1793
|
-
continue;
|
|
1794
|
-
}
|
|
1795
|
-
o += r[u], r[u] === "\\" ? i = !0 : s && r[u] === "]" ? s = !1 : !s && r[u] === "[" && (s = !0);
|
|
1796
|
-
}
|
|
1797
|
-
try {
|
|
1798
|
-
new RegExp(o);
|
|
1799
|
-
} catch {
|
|
1800
|
-
return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`), a.source;
|
|
1801
|
-
}
|
|
1802
|
-
return o;
|
|
1803
|
-
}
|
|
1804
|
-
function Te(a, t) {
|
|
1805
|
-
var r, o, i, s, c, l;
|
|
1806
|
-
if (t.target === "openAi" && console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."), t.target === "openApi3" && ((r = a.keyType) == null ? void 0 : r._def.typeName) === y.ZodEnum)
|
|
1807
|
-
return {
|
|
1808
|
-
type: "object",
|
|
1809
|
-
required: a.keyType._def.values,
|
|
1810
|
-
properties: a.keyType._def.values.reduce((u, d) => ({
|
|
1811
|
-
...u,
|
|
1812
|
-
[d]: v(a.valueType._def, {
|
|
1813
|
-
...t,
|
|
1814
|
-
currentPath: [...t.currentPath, "properties", d]
|
|
1815
|
-
}) ?? P(t)
|
|
1816
|
-
}), {}),
|
|
1817
|
-
additionalProperties: t.rejectedAdditionalProperties
|
|
1818
|
-
};
|
|
1819
|
-
const n = {
|
|
1820
|
-
type: "object",
|
|
1821
|
-
additionalProperties: v(a.valueType._def, {
|
|
1822
|
-
...t,
|
|
1823
|
-
currentPath: [...t.currentPath, "additionalProperties"]
|
|
1824
|
-
}) ?? t.allowedAdditionalProperties
|
|
1825
|
-
};
|
|
1826
|
-
if (t.target === "openApi3")
|
|
1827
|
-
return n;
|
|
1828
|
-
if (((o = a.keyType) == null ? void 0 : o._def.typeName) === y.ZodString && ((i = a.keyType._def.checks) != null && i.length)) {
|
|
1829
|
-
const { type: u, ...d } = _e(a.keyType._def, t);
|
|
1830
|
-
return {
|
|
1831
|
-
...n,
|
|
1832
|
-
propertyNames: d
|
|
1833
|
-
};
|
|
1834
|
-
} else {
|
|
1835
|
-
if (((s = a.keyType) == null ? void 0 : s._def.typeName) === y.ZodEnum)
|
|
1836
|
-
return {
|
|
1837
|
-
...n,
|
|
1838
|
-
propertyNames: {
|
|
1839
|
-
enum: a.keyType._def.values
|
|
1840
|
-
}
|
|
1841
|
-
};
|
|
1842
|
-
if (((c = a.keyType) == null ? void 0 : c._def.typeName) === y.ZodBranded && a.keyType._def.type._def.typeName === y.ZodString && ((l = a.keyType._def.type._def.checks) != null && l.length)) {
|
|
1843
|
-
const { type: u, ...d } = Se(a.keyType._def, t);
|
|
1844
|
-
return {
|
|
1845
|
-
...n,
|
|
1846
|
-
propertyNames: d
|
|
1847
|
-
};
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
return n;
|
|
1851
|
-
}
|
|
1852
|
-
function er(a, t) {
|
|
1853
|
-
if (t.mapStrategy === "record")
|
|
1854
|
-
return Te(a, t);
|
|
1855
|
-
const n = v(a.keyType._def, {
|
|
1856
|
-
...t,
|
|
1857
|
-
currentPath: [...t.currentPath, "items", "items", "0"]
|
|
1858
|
-
}) || P(t), r = v(a.valueType._def, {
|
|
1859
|
-
...t,
|
|
1860
|
-
currentPath: [...t.currentPath, "items", "items", "1"]
|
|
1861
|
-
}) || P(t);
|
|
1862
|
-
return {
|
|
1863
|
-
type: "array",
|
|
1864
|
-
maxItems: 125,
|
|
1865
|
-
items: {
|
|
1866
|
-
type: "array",
|
|
1867
|
-
items: [n, r],
|
|
1868
|
-
minItems: 2,
|
|
1869
|
-
maxItems: 2
|
|
1870
|
-
}
|
|
1871
|
-
};
|
|
1872
|
-
}
|
|
1873
|
-
function tr(a) {
|
|
1874
|
-
const t = a.values, r = Object.keys(a.values).filter((i) => typeof t[t[i]] != "number").map((i) => t[i]), o = Array.from(new Set(r.map((i) => typeof i)));
|
|
1875
|
-
return {
|
|
1876
|
-
type: o.length === 1 ? o[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1877
|
-
enum: r
|
|
1878
|
-
};
|
|
1879
|
-
}
|
|
1880
|
-
function rr(a) {
|
|
1881
|
-
return a.target === "openAi" ? void 0 : {
|
|
1882
|
-
not: P({
|
|
1883
|
-
...a,
|
|
1884
|
-
currentPath: [...a.currentPath, "not"]
|
|
1885
|
-
})
|
|
1886
|
-
};
|
|
1887
|
-
}
|
|
1888
|
-
function nr(a) {
|
|
1889
|
-
return a.target === "openApi3" ? {
|
|
1890
|
-
enum: ["null"],
|
|
1891
|
-
nullable: !0
|
|
1892
|
-
} : {
|
|
1893
|
-
type: "null"
|
|
1894
|
-
};
|
|
1895
|
-
}
|
|
1896
|
-
const V = {
|
|
1897
|
-
ZodString: "string",
|
|
1898
|
-
ZodNumber: "number",
|
|
1899
|
-
ZodBigInt: "integer",
|
|
1900
|
-
ZodBoolean: "boolean",
|
|
1901
|
-
ZodNull: "null"
|
|
1902
|
-
};
|
|
1903
|
-
function ar(a, t) {
|
|
1904
|
-
if (t.target === "openApi3")
|
|
1905
|
-
return ge(a, t);
|
|
1906
|
-
const n = a.options instanceof Map ? Array.from(a.options.values()) : a.options;
|
|
1907
|
-
if (n.every((r) => r._def.typeName in V && (!r._def.checks || !r._def.checks.length))) {
|
|
1908
|
-
const r = n.reduce((o, i) => {
|
|
1909
|
-
const s = V[i._def.typeName];
|
|
1910
|
-
return s && !o.includes(s) ? [...o, s] : o;
|
|
1911
|
-
}, []);
|
|
1912
|
-
return {
|
|
1913
|
-
type: r.length > 1 ? r : r[0]
|
|
1914
|
-
};
|
|
1915
|
-
} else if (n.every((r) => r._def.typeName === "ZodLiteral" && !r.description)) {
|
|
1916
|
-
const r = n.reduce((o, i) => {
|
|
1917
|
-
const s = typeof i._def.value;
|
|
1918
|
-
switch (s) {
|
|
1919
|
-
case "string":
|
|
1920
|
-
case "number":
|
|
1921
|
-
case "boolean":
|
|
1922
|
-
return [...o, s];
|
|
1923
|
-
case "bigint":
|
|
1924
|
-
return [...o, "integer"];
|
|
1925
|
-
case "object":
|
|
1926
|
-
if (i._def.value === null)
|
|
1927
|
-
return [...o, "null"];
|
|
1928
|
-
case "symbol":
|
|
1929
|
-
case "undefined":
|
|
1930
|
-
case "function":
|
|
1931
|
-
default:
|
|
1932
|
-
return o;
|
|
1933
|
-
}
|
|
1934
|
-
}, []);
|
|
1935
|
-
if (r.length === n.length) {
|
|
1936
|
-
const o = r.filter((i, s, c) => c.indexOf(i) === s);
|
|
1937
|
-
return {
|
|
1938
|
-
type: o.length > 1 ? o : o[0],
|
|
1939
|
-
enum: n.reduce((i, s) => i.includes(s._def.value) ? i : [...i, s._def.value], [])
|
|
1940
|
-
};
|
|
1941
|
-
}
|
|
1942
|
-
} else if (n.every((r) => r._def.typeName === "ZodEnum"))
|
|
1943
|
-
return {
|
|
1944
|
-
type: "string",
|
|
1945
|
-
enum: n.reduce((r, o) => [
|
|
1946
|
-
...r,
|
|
1947
|
-
...o._def.values.filter((i) => !r.includes(i))
|
|
1948
|
-
], [])
|
|
1949
|
-
};
|
|
1950
|
-
return ge(a, t);
|
|
1951
|
-
}
|
|
1952
|
-
const ge = (a, t) => {
|
|
1953
|
-
const n = (a.options instanceof Map ? Array.from(a.options.values()) : a.options).map((r, o) => v(r._def, {
|
|
1954
|
-
...t,
|
|
1955
|
-
currentPath: [...t.currentPath, "anyOf", `${o}`]
|
|
1956
|
-
})).filter((r) => !!r && (!t.strictUnions || typeof r == "object" && Object.keys(r).length > 0));
|
|
1957
|
-
return n.length ? { anyOf: n } : void 0;
|
|
1958
|
-
};
|
|
1959
|
-
function or(a, t) {
|
|
1960
|
-
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(a.innerType._def.typeName) && (!a.innerType._def.checks || !a.innerType._def.checks.length))
|
|
1961
|
-
return t.target === "openApi3" ? {
|
|
1962
|
-
type: V[a.innerType._def.typeName],
|
|
1963
|
-
nullable: !0
|
|
1964
|
-
} : {
|
|
1965
|
-
type: [
|
|
1966
|
-
V[a.innerType._def.typeName],
|
|
1967
|
-
"null"
|
|
1968
|
-
]
|
|
1969
|
-
};
|
|
1970
|
-
if (t.target === "openApi3") {
|
|
1971
|
-
const r = v(a.innerType._def, {
|
|
1972
|
-
...t,
|
|
1973
|
-
currentPath: [...t.currentPath]
|
|
1974
|
-
});
|
|
1975
|
-
return r && "$ref" in r ? { allOf: [r], nullable: !0 } : r && { ...r, nullable: !0 };
|
|
1976
|
-
}
|
|
1977
|
-
const n = v(a.innerType._def, {
|
|
1978
|
-
...t,
|
|
1979
|
-
currentPath: [...t.currentPath, "anyOf", "0"]
|
|
1980
|
-
});
|
|
1981
|
-
return n && { anyOf: [n, { type: "null" }] };
|
|
1982
|
-
}
|
|
1983
|
-
function ir(a, t) {
|
|
1984
|
-
const n = {
|
|
1985
|
-
type: "number"
|
|
1986
|
-
};
|
|
1987
|
-
if (!a.checks)
|
|
1988
|
-
return n;
|
|
1989
|
-
for (const r of a.checks)
|
|
1990
|
-
switch (r.kind) {
|
|
1991
|
-
case "int":
|
|
1992
|
-
n.type = "integer", Ae(n, "type", r.message, t);
|
|
1993
|
-
break;
|
|
1994
|
-
case "min":
|
|
1995
|
-
t.target === "jsonSchema7" ? r.inclusive ? k(n, "minimum", r.value, r.message, t) : k(n, "exclusiveMinimum", r.value, r.message, t) : (r.inclusive || (n.exclusiveMinimum = !0), k(n, "minimum", r.value, r.message, t));
|
|
1996
|
-
break;
|
|
1997
|
-
case "max":
|
|
1998
|
-
t.target === "jsonSchema7" ? r.inclusive ? k(n, "maximum", r.value, r.message, t) : k(n, "exclusiveMaximum", r.value, r.message, t) : (r.inclusive || (n.exclusiveMaximum = !0), k(n, "maximum", r.value, r.message, t));
|
|
1999
|
-
break;
|
|
2000
|
-
case "multipleOf":
|
|
2001
|
-
k(n, "multipleOf", r.value, r.message, t);
|
|
2002
|
-
break;
|
|
2003
|
-
}
|
|
2004
|
-
return n;
|
|
2005
|
-
}
|
|
2006
|
-
function sr(a, t) {
|
|
2007
|
-
const n = t.target === "openAi", r = {
|
|
2008
|
-
type: "object",
|
|
2009
|
-
properties: {}
|
|
2010
|
-
}, o = [], i = a.shape();
|
|
2011
|
-
for (const c in i) {
|
|
2012
|
-
let l = i[c];
|
|
2013
|
-
if (l === void 0 || l._def === void 0)
|
|
2014
|
-
continue;
|
|
2015
|
-
let u = lr(l);
|
|
2016
|
-
u && n && (l._def.typeName === "ZodOptional" && (l = l._def.innerType), l.isNullable() || (l = l.nullable()), u = !1);
|
|
2017
|
-
const d = v(l._def, {
|
|
2018
|
-
...t,
|
|
2019
|
-
currentPath: [...t.currentPath, "properties", c],
|
|
2020
|
-
propertyPath: [...t.currentPath, "properties", c]
|
|
2021
|
-
});
|
|
2022
|
-
d !== void 0 && (r.properties[c] = d, u || o.push(c));
|
|
2023
|
-
}
|
|
2024
|
-
o.length && (r.required = o);
|
|
2025
|
-
const s = cr(a, t);
|
|
2026
|
-
return s !== void 0 && (r.additionalProperties = s), r;
|
|
2027
|
-
}
|
|
2028
|
-
function cr(a, t) {
|
|
2029
|
-
if (a.catchall._def.typeName !== "ZodNever")
|
|
2030
|
-
return v(a.catchall._def, {
|
|
2031
|
-
...t,
|
|
2032
|
-
currentPath: [...t.currentPath, "additionalProperties"]
|
|
2033
|
-
});
|
|
2034
|
-
switch (a.unknownKeys) {
|
|
2035
|
-
case "passthrough":
|
|
2036
|
-
return t.allowedAdditionalProperties;
|
|
2037
|
-
case "strict":
|
|
2038
|
-
return t.rejectedAdditionalProperties;
|
|
2039
|
-
case "strip":
|
|
2040
|
-
return t.removeAdditionalStrategy === "strict" ? t.allowedAdditionalProperties : t.rejectedAdditionalProperties;
|
|
2041
|
-
}
|
|
2042
|
-
}
|
|
2043
|
-
function lr(a) {
|
|
2044
|
-
try {
|
|
2045
|
-
return a.isOptional();
|
|
2046
|
-
} catch {
|
|
2047
|
-
return !0;
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
const ur = (a, t) => {
|
|
2051
|
-
var r;
|
|
2052
|
-
if (t.currentPath.toString() === ((r = t.propertyPath) == null ? void 0 : r.toString()))
|
|
2053
|
-
return v(a.innerType._def, t);
|
|
2054
|
-
const n = v(a.innerType._def, {
|
|
2055
|
-
...t,
|
|
2056
|
-
currentPath: [...t.currentPath, "anyOf", "1"]
|
|
2057
|
-
});
|
|
2058
|
-
return n ? {
|
|
2059
|
-
anyOf: [
|
|
2060
|
-
{
|
|
2061
|
-
not: P(t)
|
|
2062
|
-
},
|
|
2063
|
-
n
|
|
2064
|
-
]
|
|
2065
|
-
} : P(t);
|
|
2066
|
-
}, dr = (a, t) => {
|
|
2067
|
-
if (t.pipeStrategy === "input")
|
|
2068
|
-
return v(a.in._def, t);
|
|
2069
|
-
if (t.pipeStrategy === "output")
|
|
2070
|
-
return v(a.out._def, t);
|
|
2071
|
-
const n = v(a.in._def, {
|
|
2072
|
-
...t,
|
|
2073
|
-
currentPath: [...t.currentPath, "allOf", "0"]
|
|
2074
|
-
}), r = v(a.out._def, {
|
|
2075
|
-
...t,
|
|
2076
|
-
currentPath: [...t.currentPath, "allOf", n ? "1" : "0"]
|
|
2077
|
-
});
|
|
2078
|
-
return {
|
|
2079
|
-
allOf: [n, r].filter((o) => o !== void 0)
|
|
2080
|
-
};
|
|
2081
|
-
};
|
|
2082
|
-
function mr(a, t) {
|
|
2083
|
-
return v(a.type._def, t);
|
|
2084
|
-
}
|
|
2085
|
-
function pr(a, t) {
|
|
2086
|
-
const r = {
|
|
2087
|
-
type: "array",
|
|
2088
|
-
uniqueItems: !0,
|
|
2089
|
-
items: v(a.valueType._def, {
|
|
2090
|
-
...t,
|
|
2091
|
-
currentPath: [...t.currentPath, "items"]
|
|
2092
|
-
})
|
|
2093
|
-
};
|
|
2094
|
-
return a.minSize && k(r, "minItems", a.minSize.value, a.minSize.message, t), a.maxSize && k(r, "maxItems", a.maxSize.value, a.maxSize.message, t), r;
|
|
2095
|
-
}
|
|
2096
|
-
function hr(a, t) {
|
|
2097
|
-
return a.rest ? {
|
|
2098
|
-
type: "array",
|
|
2099
|
-
minItems: a.items.length,
|
|
2100
|
-
items: a.items.map((n, r) => v(n._def, {
|
|
2101
|
-
...t,
|
|
2102
|
-
currentPath: [...t.currentPath, "items", `${r}`]
|
|
2103
|
-
})).reduce((n, r) => r === void 0 ? n : [...n, r], []),
|
|
2104
|
-
additionalItems: v(a.rest._def, {
|
|
2105
|
-
...t,
|
|
2106
|
-
currentPath: [...t.currentPath, "additionalItems"]
|
|
2107
|
-
})
|
|
2108
|
-
} : {
|
|
2109
|
-
type: "array",
|
|
2110
|
-
minItems: a.items.length,
|
|
2111
|
-
maxItems: a.items.length,
|
|
2112
|
-
items: a.items.map((n, r) => v(n._def, {
|
|
2113
|
-
...t,
|
|
2114
|
-
currentPath: [...t.currentPath, "items", `${r}`]
|
|
2115
|
-
})).reduce((n, r) => r === void 0 ? n : [...n, r], [])
|
|
2116
|
-
};
|
|
2117
|
-
}
|
|
2118
|
-
function gr(a) {
|
|
2119
|
-
return {
|
|
2120
|
-
not: P(a)
|
|
2121
|
-
};
|
|
2122
|
-
}
|
|
2123
|
-
function fr(a) {
|
|
2124
|
-
return P(a);
|
|
2125
|
-
}
|
|
2126
|
-
const yr = (a, t) => v(a.innerType._def, t), br = (a, t, n) => {
|
|
2127
|
-
switch (t) {
|
|
2128
|
-
case y.ZodString:
|
|
2129
|
-
return _e(a, n);
|
|
2130
|
-
case y.ZodNumber:
|
|
2131
|
-
return ir(a, n);
|
|
2132
|
-
case y.ZodObject:
|
|
2133
|
-
return sr(a, n);
|
|
2134
|
-
case y.ZodBigInt:
|
|
2135
|
-
return Zt(a, n);
|
|
2136
|
-
case y.ZodBoolean:
|
|
2137
|
-
return zt();
|
|
2138
|
-
case y.ZodDate:
|
|
2139
|
-
return Ee(a, n);
|
|
2140
|
-
case y.ZodUndefined:
|
|
2141
|
-
return gr(n);
|
|
2142
|
-
case y.ZodNull:
|
|
2143
|
-
return nr(n);
|
|
2144
|
-
case y.ZodArray:
|
|
2145
|
-
return Ut(a, n);
|
|
2146
|
-
case y.ZodUnion:
|
|
2147
|
-
case y.ZodDiscriminatedUnion:
|
|
2148
|
-
return ar(a, n);
|
|
2149
|
-
case y.ZodIntersection:
|
|
2150
|
-
return Yt(a, n);
|
|
2151
|
-
case y.ZodTuple:
|
|
2152
|
-
return hr(a, n);
|
|
2153
|
-
case y.ZodRecord:
|
|
2154
|
-
return Te(a, n);
|
|
2155
|
-
case y.ZodLiteral:
|
|
2156
|
-
return Kt(a, n);
|
|
2157
|
-
case y.ZodEnum:
|
|
2158
|
-
return Wt(a);
|
|
2159
|
-
case y.ZodNativeEnum:
|
|
2160
|
-
return tr(a);
|
|
2161
|
-
case y.ZodNullable:
|
|
2162
|
-
return or(a, n);
|
|
2163
|
-
case y.ZodOptional:
|
|
2164
|
-
return ur(a, n);
|
|
2165
|
-
case y.ZodMap:
|
|
2166
|
-
return er(a, n);
|
|
2167
|
-
case y.ZodSet:
|
|
2168
|
-
return pr(a, n);
|
|
2169
|
-
case y.ZodLazy:
|
|
2170
|
-
return () => a.getter()._def;
|
|
2171
|
-
case y.ZodPromise:
|
|
2172
|
-
return mr(a, n);
|
|
2173
|
-
case y.ZodNaN:
|
|
2174
|
-
case y.ZodNever:
|
|
2175
|
-
return rr(n);
|
|
2176
|
-
case y.ZodEffects:
|
|
2177
|
-
return Vt(a, n);
|
|
2178
|
-
case y.ZodAny:
|
|
2179
|
-
return P(n);
|
|
2180
|
-
case y.ZodUnknown:
|
|
2181
|
-
return fr(n);
|
|
2182
|
-
case y.ZodDefault:
|
|
2183
|
-
return Gt(a, n);
|
|
2184
|
-
case y.ZodBranded:
|
|
2185
|
-
return Se(a, n);
|
|
2186
|
-
case y.ZodReadonly:
|
|
2187
|
-
return yr(a, n);
|
|
2188
|
-
case y.ZodCatch:
|
|
2189
|
-
return Ft(a, n);
|
|
2190
|
-
case y.ZodPipeline:
|
|
2191
|
-
return dr(a, n);
|
|
2192
|
-
case y.ZodFunction:
|
|
2193
|
-
case y.ZodVoid:
|
|
2194
|
-
case y.ZodSymbol:
|
|
2195
|
-
return;
|
|
2196
|
-
default:
|
|
2197
|
-
return /* @__PURE__ */ ((r) => {
|
|
2198
|
-
})();
|
|
2199
|
-
}
|
|
2200
|
-
};
|
|
2201
|
-
function v(a, t, n = !1) {
|
|
2202
|
-
var c;
|
|
2203
|
-
const r = t.seen.get(a);
|
|
2204
|
-
if (t.override) {
|
|
2205
|
-
const l = (c = t.override) == null ? void 0 : c.call(t, a, t, r, n);
|
|
2206
|
-
if (l !== Bt)
|
|
2207
|
-
return l;
|
|
2208
|
-
}
|
|
2209
|
-
if (r && !n) {
|
|
2210
|
-
const l = wr(r, t);
|
|
2211
|
-
if (l !== void 0)
|
|
2212
|
-
return l;
|
|
2213
|
-
}
|
|
2214
|
-
const o = { def: a, path: t.currentPath, jsonSchema: void 0 };
|
|
2215
|
-
t.seen.set(a, o);
|
|
2216
|
-
const i = br(a, a.typeName, t), s = typeof i == "function" ? v(i(), t) : i;
|
|
2217
|
-
if (s && vr(a, t, s), t.postProcess) {
|
|
2218
|
-
const l = t.postProcess(s, a, t);
|
|
2219
|
-
return o.jsonSchema = s, l;
|
|
2220
|
-
}
|
|
2221
|
-
return o.jsonSchema = s, s;
|
|
2222
|
-
}
|
|
2223
|
-
const wr = (a, t) => {
|
|
2224
|
-
switch (t.$refStrategy) {
|
|
2225
|
-
case "root":
|
|
2226
|
-
return { $ref: a.path.join("/") };
|
|
2227
|
-
case "relative":
|
|
2228
|
-
return { $ref: ke(t.currentPath, a.path) };
|
|
2229
|
-
case "none":
|
|
2230
|
-
case "seen":
|
|
2231
|
-
return a.path.length < t.currentPath.length && a.path.every((n, r) => t.currentPath[r] === n) ? (console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`), P(t)) : t.$refStrategy === "seen" ? P(t) : void 0;
|
|
2232
|
-
}
|
|
2233
|
-
}, vr = (a, t, n) => (a.description && (n.description = a.description, t.markdownDescription && (n.markdownDescription = a.description)), n), xr = (a, t) => {
|
|
2234
|
-
const n = qt(t);
|
|
2235
|
-
let r = typeof t == "object" && t.definitions ? Object.entries(t.definitions).reduce((l, [u, d]) => ({
|
|
2236
|
-
...l,
|
|
2237
|
-
[u]: v(d._def, {
|
|
2238
|
-
...n,
|
|
2239
|
-
currentPath: [...n.basePath, n.definitionPath, u]
|
|
2240
|
-
}, !0) ?? P(n)
|
|
2241
|
-
}), {}) : void 0;
|
|
2242
|
-
const o = typeof t == "string" ? t : (t == null ? void 0 : t.nameStrategy) === "title" || t == null ? void 0 : t.name, i = v(a._def, o === void 0 ? n : {
|
|
2243
|
-
...n,
|
|
2244
|
-
currentPath: [...n.basePath, n.definitionPath, o]
|
|
2245
|
-
}, !1) ?? P(n), s = typeof t == "object" && t.name !== void 0 && t.nameStrategy === "title" ? t.name : void 0;
|
|
2246
|
-
s !== void 0 && (i.title = s), n.flags.hasReferencedOpenAiAnyType && (r || (r = {}), r[n.openAiAnyTypeName] || (r[n.openAiAnyTypeName] = {
|
|
2247
|
-
// Skipping "object" as no properties can be defined and additionalProperties must be "false"
|
|
2248
|
-
type: ["string", "number", "integer", "boolean", "array", "null"],
|
|
2249
|
-
items: {
|
|
2250
|
-
$ref: n.$refStrategy === "relative" ? "1" : [
|
|
2251
|
-
...n.basePath,
|
|
2252
|
-
n.definitionPath,
|
|
2253
|
-
n.openAiAnyTypeName
|
|
2254
|
-
].join("/")
|
|
2255
|
-
}
|
|
2256
|
-
}));
|
|
2257
|
-
const c = o === void 0 ? r ? {
|
|
2258
|
-
...i,
|
|
2259
|
-
[n.definitionPath]: r
|
|
2260
|
-
} : i : {
|
|
2261
|
-
$ref: [
|
|
2262
|
-
...n.$refStrategy === "relative" ? [] : n.basePath,
|
|
2263
|
-
n.definitionPath,
|
|
2264
|
-
o
|
|
2265
|
-
].join("/"),
|
|
2266
|
-
[n.definitionPath]: {
|
|
2267
|
-
...r,
|
|
2268
|
-
[o]: i
|
|
2269
|
-
}
|
|
2270
|
-
};
|
|
2271
|
-
return n.target === "jsonSchema7" ? c.$schema = "http://json-schema.org/draft-07/schema#" : (n.target === "jsonSchema2019-09" || n.target === "openAi") && (c.$schema = "https://json-schema.org/draft/2019-09/schema#"), n.target === "openAi" && ("anyOf" in c || "oneOf" in c || "allOf" in c || "type" in c && Array.isArray(c.type)) && console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."), c;
|
|
2272
|
-
};
|
|
2273
|
-
function en(a) {
|
|
2274
|
-
const t = xr(a.parameters, { target: "jsonSchema7", $refStrategy: "none" });
|
|
2275
|
-
return {
|
|
2276
|
-
name: a.name,
|
|
2277
|
-
description: a.description,
|
|
2278
|
-
parameters: t
|
|
2279
|
-
};
|
|
2280
|
-
}
|
|
2281
|
-
function Ar(a) {
|
|
2282
|
-
const t = /* @__PURE__ */ new Set(["$schema", "additionalProperties", "default"]), n = (r) => Array.isArray(r) ? r.map(n) : r && typeof r == "object" ? Object.fromEntries(
|
|
2283
|
-
Object.entries(r).filter(([o]) => !t.has(o)).map(([o, i]) => [o, n(i)])
|
|
2284
|
-
) : r;
|
|
2285
|
-
return n(a);
|
|
2286
|
-
}
|
|
2287
|
-
class kr {
|
|
2288
|
-
async *streamChat(t, n, r) {
|
|
2289
|
-
var h, g, w, f;
|
|
2290
|
-
const { apiKey: o, model: i = T["google-gemini"] } = n;
|
|
2291
|
-
if (!o) throw new Error("Gemini API key required");
|
|
2292
|
-
const s = t.find((b) => b.role === "system"), c = t.filter((b) => b.role !== "system").map((b) => ({ role: b.role === "assistant" ? "model" : "user", parts: [{ text: b.content }] })), l = r != null && r.length ? [{
|
|
2293
|
-
functionDeclarations: r.map((b) => ({
|
|
2294
|
-
name: b.name,
|
|
2295
|
-
description: b.description,
|
|
2296
|
-
parameters: Ar(b.parameters)
|
|
2297
|
-
}))
|
|
2298
|
-
}] : void 0, u = await fetch(
|
|
2299
|
-
`https://generativelanguage.googleapis.com/v1beta/models/${i}:streamGenerateContent?alt=sse`,
|
|
2300
|
-
{
|
|
2301
|
-
method: "POST",
|
|
2302
|
-
headers: { "Content-Type": "application/json", "x-goog-api-key": o },
|
|
2303
|
-
body: JSON.stringify({
|
|
2304
|
-
contents: c,
|
|
2305
|
-
...s && { systemInstruction: { parts: [{ text: s.content }] } },
|
|
2306
|
-
...l && { tools: l }
|
|
2307
|
-
})
|
|
2308
|
-
}
|
|
2309
|
-
);
|
|
2310
|
-
if (!u.ok) {
|
|
2311
|
-
const b = await u.text();
|
|
2312
|
-
throw new Error(`Gemini Error ${u.status}: ${b}`);
|
|
2313
|
-
}
|
|
2314
|
-
const d = (h = u.body) == null ? void 0 : h.getReader();
|
|
2315
|
-
if (!d) throw new Error("No response body");
|
|
2316
|
-
const m = new TextDecoder();
|
|
2317
|
-
let p = "";
|
|
2318
|
-
for (; ; ) {
|
|
2319
|
-
const { done: b, value: A } = await d.read();
|
|
2320
|
-
if (b) break;
|
|
2321
|
-
p += m.decode(A, { stream: !0 });
|
|
2322
|
-
const _ = p.split(`
|
|
2323
|
-
`);
|
|
2324
|
-
p = _.pop() || "";
|
|
2325
|
-
for (const S of _) {
|
|
2326
|
-
const x = S.trim();
|
|
2327
|
-
if (!(!x || !x.startsWith("data: ")))
|
|
2328
|
-
try {
|
|
2329
|
-
const D = ((f = (w = (g = JSON.parse(x.slice(6)).candidates) == null ? void 0 : g[0]) == null ? void 0 : w.content) == null ? void 0 : f.parts) ?? [];
|
|
2330
|
-
for (const C of D)
|
|
2331
|
-
C.text && (yield { type: "text-delta", text: C.text }), C.functionCall && (yield {
|
|
2332
|
-
type: "tool-call",
|
|
2333
|
-
toolCall: { name: C.functionCall.name, arguments: C.functionCall.args ?? {} }
|
|
2334
|
-
});
|
|
2335
|
-
} catch {
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
async generateText(t, n) {
|
|
2341
|
-
var l, u, d, m, p;
|
|
2342
|
-
const { apiKey: r, model: o = T["google-gemini"], temperature: i = 0.7 } = n;
|
|
2343
|
-
if (!r) throw new Error("Gemini API key required");
|
|
2344
|
-
if (!o) throw new Error("GeminiAdapter: model is required but was undefined");
|
|
2345
|
-
const s = await fetch(
|
|
2346
|
-
`https://generativelanguage.googleapis.com/v1beta/models/${o}:generateContent`,
|
|
2347
|
-
{
|
|
2348
|
-
method: "POST",
|
|
2349
|
-
headers: {
|
|
2350
|
-
"Content-Type": "application/json",
|
|
2351
|
-
"x-goog-api-key": r
|
|
2352
|
-
},
|
|
2353
|
-
body: JSON.stringify({
|
|
2354
|
-
contents: [{ parts: [{ text: t }] }],
|
|
2355
|
-
generationConfig: { temperature: i }
|
|
2356
|
-
})
|
|
2357
|
-
}
|
|
2358
|
-
);
|
|
2359
|
-
if (!s.ok) {
|
|
2360
|
-
const h = await s.text();
|
|
2361
|
-
throw new Error(`Gemini Error ${s.status}: ${h}`);
|
|
2362
|
-
}
|
|
2363
|
-
return ((p = (m = (d = (u = (l = (await s.json()).candidates) == null ? void 0 : l[0]) == null ? void 0 : u.content) == null ? void 0 : d.parts) == null ? void 0 : m[0]) == null ? void 0 : p.text) || "";
|
|
2364
|
-
}
|
|
2365
|
-
async *streamText(t, n) {
|
|
2366
|
-
var u, d, m, p, h, g;
|
|
2367
|
-
const { apiKey: r, model: o = T["google-gemini"] } = n;
|
|
2368
|
-
if (!r) throw new Error("Gemini API key required");
|
|
2369
|
-
if (!o) throw new Error("GeminiAdapter: model is required but was undefined");
|
|
2370
|
-
const i = await fetch(
|
|
2371
|
-
`https://generativelanguage.googleapis.com/v1beta/models/${o}:streamGenerateContent?alt=sse`,
|
|
2372
|
-
{
|
|
2373
|
-
method: "POST",
|
|
2374
|
-
headers: {
|
|
2375
|
-
"Content-Type": "application/json",
|
|
2376
|
-
"x-goog-api-key": r
|
|
2377
|
-
},
|
|
2378
|
-
body: JSON.stringify({
|
|
2379
|
-
contents: [{ parts: [{ text: t }] }]
|
|
2380
|
-
})
|
|
2381
|
-
}
|
|
2382
|
-
);
|
|
2383
|
-
if (!i.ok) {
|
|
2384
|
-
const w = await i.text();
|
|
2385
|
-
throw new Error(`Gemini Error ${i.status}: ${w}`);
|
|
2386
|
-
}
|
|
2387
|
-
const s = (u = i.body) == null ? void 0 : u.getReader();
|
|
2388
|
-
if (!s) throw new Error("No response body");
|
|
2389
|
-
const c = new TextDecoder();
|
|
2390
|
-
let l = "";
|
|
2391
|
-
for (; ; ) {
|
|
2392
|
-
const { done: w, value: f } = await s.read();
|
|
2393
|
-
if (w) break;
|
|
2394
|
-
l += c.decode(f, { stream: !0 });
|
|
2395
|
-
const b = l.split(`
|
|
2396
|
-
`);
|
|
2397
|
-
l = b.pop() || "";
|
|
2398
|
-
for (const A of b) {
|
|
2399
|
-
const _ = A.trim();
|
|
2400
|
-
if (!(!_ || !_.startsWith("data: ")))
|
|
2401
|
-
try {
|
|
2402
|
-
const x = (g = (h = (p = (m = (d = JSON.parse(_.slice(6)).candidates) == null ? void 0 : d[0]) == null ? void 0 : m.content) == null ? void 0 : p.parts) == null ? void 0 : h[0]) == null ? void 0 : g.text;
|
|
2403
|
-
x && (yield x);
|
|
2404
|
-
} catch {
|
|
2405
|
-
continue;
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
async generateObject(t, n, r) {
|
|
2411
|
-
var u, d, m, p, h;
|
|
2412
|
-
const { apiKey: o, model: i = T["google-gemini"] } = r;
|
|
2413
|
-
if (!o) throw new Error("Gemini API key required");
|
|
2414
|
-
if (!i) throw new Error("GeminiAdapter: model is required but was undefined");
|
|
2415
|
-
const s = await fetch(
|
|
2416
|
-
`https://generativelanguage.googleapis.com/v1beta/models/${i}:generateContent`,
|
|
2417
|
-
{
|
|
2418
|
-
method: "POST",
|
|
2419
|
-
headers: {
|
|
2420
|
-
"Content-Type": "application/json",
|
|
2421
|
-
"x-goog-api-key": o
|
|
2422
|
-
},
|
|
2423
|
-
body: JSON.stringify({
|
|
2424
|
-
contents: [{ parts: [{ text: t }] }],
|
|
2425
|
-
generationConfig: {
|
|
2426
|
-
responseMimeType: "application/json",
|
|
2427
|
-
responseSchema: n
|
|
2428
|
-
}
|
|
2429
|
-
})
|
|
2430
|
-
}
|
|
2431
|
-
);
|
|
2432
|
-
if (!s.ok) {
|
|
2433
|
-
const g = await s.json();
|
|
2434
|
-
throw this.normalizeError(g, s.status);
|
|
2435
|
-
}
|
|
2436
|
-
const l = ((h = (p = (m = (d = (u = (await s.json()).candidates) == null ? void 0 : u[0]) == null ? void 0 : d.content) == null ? void 0 : m.parts) == null ? void 0 : p[0]) == null ? void 0 : h.text) || "{}";
|
|
2437
|
-
return JSON.parse(l);
|
|
2438
|
-
}
|
|
2439
|
-
async listModels(t) {
|
|
2440
|
-
var o;
|
|
2441
|
-
if (!t) throw new Error("API key required to list models");
|
|
2442
|
-
const n = await fetch(
|
|
2443
|
-
"https://generativelanguage.googleapis.com/v1beta/models",
|
|
2444
|
-
{
|
|
2445
|
-
headers: { "x-goog-api-key": t }
|
|
2446
|
-
}
|
|
2447
|
-
);
|
|
2448
|
-
if (!n.ok)
|
|
2449
|
-
throw new Error("Failed to fetch model list");
|
|
2450
|
-
return ((o = (await n.json()).models) == null ? void 0 : o.map((i) => i.name)) || [];
|
|
2451
|
-
}
|
|
2452
|
-
normalizeError(t, n) {
|
|
2453
|
-
var r;
|
|
2454
|
-
if (n === 429) {
|
|
2455
|
-
const o = new Error("Rate limit exceeded. Please wait 30 seconds before retrying.");
|
|
2456
|
-
return o.code = "RATE_LIMIT", o;
|
|
2457
|
-
}
|
|
2458
|
-
if (n === 401 || n === 403) {
|
|
2459
|
-
const o = new Error("Invalid API key.");
|
|
2460
|
-
return o.code = "AUTH_ERROR", o;
|
|
2461
|
-
}
|
|
2462
|
-
return new Error(((r = t.error) == null ? void 0 : r.message) || "Unknown error");
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
class Sr {
|
|
2466
|
-
/**
|
|
2467
|
-
* Tool calling requires /api/chat, not /api/generate (which has no tool
|
|
2468
|
-
* support at all). Tool support itself is model-dependent (llama3.1+,
|
|
2469
|
-
* qwen2.5, mistral-nemo, etc.) — a non-tool-capable model just replies
|
|
2470
|
-
* with plain text; there's no reliable way to detect that in advance, so
|
|
2471
|
-
* this degrades gracefully rather than special-casing it.
|
|
2472
|
-
*/
|
|
2473
|
-
async *streamChat(t, n, r) {
|
|
2474
|
-
var m, p, h, g, w;
|
|
2475
|
-
const { baseUrl: o = "http://localhost:11434", model: i = T.ollama } = n, s = r != null && r.length ? r.map((f) => ({ type: "function", function: { name: f.name, description: f.description, parameters: f.parameters } })) : void 0, c = await fetch(`${o}/api/chat`, {
|
|
2476
|
-
method: "POST",
|
|
2477
|
-
headers: { "Content-Type": "application/json" },
|
|
2478
|
-
body: JSON.stringify({
|
|
2479
|
-
model: i,
|
|
2480
|
-
messages: t.map((f) => ({ role: f.role, content: f.content })),
|
|
2481
|
-
stream: !0,
|
|
2482
|
-
...s && { tools: s }
|
|
2483
|
-
})
|
|
2484
|
-
});
|
|
2485
|
-
if (!c.ok) {
|
|
2486
|
-
const f = await c.text();
|
|
2487
|
-
throw new Error(`Ollama Error ${c.status}: ${f}`);
|
|
2488
|
-
}
|
|
2489
|
-
const l = (m = c.body) == null ? void 0 : m.getReader();
|
|
2490
|
-
if (!l) throw new Error("No response body");
|
|
2491
|
-
const u = new TextDecoder();
|
|
2492
|
-
let d = "";
|
|
2493
|
-
for (; ; ) {
|
|
2494
|
-
const { done: f, value: b } = await l.read();
|
|
2495
|
-
if (f) break;
|
|
2496
|
-
d += u.decode(b, { stream: !0 });
|
|
2497
|
-
const A = d.split(`
|
|
2498
|
-
`);
|
|
2499
|
-
d = A.pop() || "";
|
|
2500
|
-
for (const _ of A) {
|
|
2501
|
-
const S = _.trim();
|
|
2502
|
-
if (S)
|
|
2503
|
-
try {
|
|
2504
|
-
const x = JSON.parse(S);
|
|
2505
|
-
if ((p = x.message) != null && p.content && (yield { type: "text-delta", text: x.message.content }), (h = x.message) != null && h.tool_calls)
|
|
2506
|
-
for (const $ of x.message.tool_calls)
|
|
2507
|
-
yield {
|
|
2508
|
-
type: "tool-call",
|
|
2509
|
-
toolCall: { name: (g = $.function) == null ? void 0 : g.name, arguments: ((w = $.function) == null ? void 0 : w.arguments) ?? {} }
|
|
2510
|
-
};
|
|
2511
|
-
} catch {
|
|
2512
|
-
}
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
async generateText(t, n) {
|
|
2517
|
-
const { baseUrl: r = "http://localhost:11434", model: o = T.ollama } = n, i = await fetch(`${r}/api/generate`, {
|
|
2518
|
-
method: "POST",
|
|
2519
|
-
headers: { "Content-Type": "application/json" },
|
|
2520
|
-
body: JSON.stringify({
|
|
2521
|
-
model: o,
|
|
2522
|
-
prompt: t,
|
|
2523
|
-
stream: !1
|
|
2524
|
-
})
|
|
2525
|
-
});
|
|
2526
|
-
if (!i.ok) {
|
|
2527
|
-
const c = await i.text();
|
|
2528
|
-
throw new Error(`Ollama Error ${i.status}: ${c}`);
|
|
2529
|
-
}
|
|
2530
|
-
return (await i.json()).response;
|
|
2531
|
-
}
|
|
2532
|
-
async *streamText(t, n) {
|
|
2533
|
-
var u;
|
|
2534
|
-
const { baseUrl: r = "http://localhost:11434", model: o = T.ollama } = n, i = await fetch(`${r}/api/generate`, {
|
|
2535
|
-
method: "POST",
|
|
2536
|
-
headers: { "Content-Type": "application/json" },
|
|
2537
|
-
body: JSON.stringify({
|
|
2538
|
-
model: o,
|
|
2539
|
-
prompt: t,
|
|
2540
|
-
stream: !0
|
|
2541
|
-
})
|
|
2542
|
-
});
|
|
2543
|
-
if (!i.ok) {
|
|
2544
|
-
const d = await i.text();
|
|
2545
|
-
throw new Error(`Ollama Error ${i.status}: ${d}`);
|
|
2546
|
-
}
|
|
2547
|
-
const s = (u = i.body) == null ? void 0 : u.getReader();
|
|
2548
|
-
if (!s) throw new Error("No response body");
|
|
2549
|
-
const c = new TextDecoder();
|
|
2550
|
-
let l = "";
|
|
2551
|
-
for (; ; ) {
|
|
2552
|
-
const { done: d, value: m } = await s.read();
|
|
2553
|
-
if (d) break;
|
|
2554
|
-
l += c.decode(m, { stream: !0 });
|
|
2555
|
-
const p = l.split(`
|
|
2556
|
-
`);
|
|
2557
|
-
l = p.pop() || "";
|
|
2558
|
-
for (const h of p) {
|
|
2559
|
-
const g = h.trim();
|
|
2560
|
-
if (g)
|
|
2561
|
-
try {
|
|
2562
|
-
const w = JSON.parse(g);
|
|
2563
|
-
w.response && (yield w.response);
|
|
2564
|
-
} catch {
|
|
2565
|
-
continue;
|
|
2566
|
-
}
|
|
2567
|
-
}
|
|
2568
|
-
}
|
|
2569
|
-
}
|
|
2570
|
-
async generateObject(t, n, r) {
|
|
2571
|
-
const o = `${t}
|
|
2572
|
-
|
|
2573
|
-
IMPORTANT: Return ONLY valid JSON matching this schema:
|
|
2574
|
-
${JSON.stringify(n, null, 2)}
|
|
2575
|
-
|
|
2576
|
-
Do not include any explanation, only the raw JSON object.`, i = await this.generateText(o, r), s = i.match(/```json\n?([\s\S]*?)\n?```/) || i.match(/\{[\s\S]*\}/), c = s ? s[1] || s[0] : i;
|
|
2577
|
-
return JSON.parse(c.trim());
|
|
2578
|
-
}
|
|
2579
|
-
async listModels(t, n = "http://localhost:11434") {
|
|
2580
|
-
var i;
|
|
2581
|
-
const r = await fetch(`${n}/api/tags`);
|
|
2582
|
-
if (!r.ok)
|
|
2583
|
-
throw new Error(`Failed to fetch Ollama models. Is Ollama running at ${n}?`);
|
|
2584
|
-
return ((i = (await r.json()).models) == null ? void 0 : i.map((s) => s.name)) || [];
|
|
2585
|
-
}
|
|
2586
|
-
}
|
|
2587
|
-
const G = (a) => {
|
|
2588
|
-
try {
|
|
2589
|
-
return JSON.parse(a);
|
|
2590
|
-
} catch {
|
|
2591
|
-
return { error: { message: a } };
|
|
2592
|
-
}
|
|
2593
|
-
}, re = (a) => typeof a == "string" ? a ? [{ type: "text", text: a }] : [] : a, Er = (a) => {
|
|
2594
|
-
var n;
|
|
2595
|
-
const t = [];
|
|
2596
|
-
for (const r of a) {
|
|
2597
|
-
if (r.role === "system") continue;
|
|
2598
|
-
let o;
|
|
2599
|
-
r.role === "tool" ? o = {
|
|
2600
|
-
role: "user",
|
|
2601
|
-
content: [{ type: "tool_result", tool_use_id: r.toolCallId ?? "", content: r.content }]
|
|
2602
|
-
} : r.role === "assistant" && ((n = r.toolCalls) != null && n.length) ? o = {
|
|
2603
|
-
role: "assistant",
|
|
2604
|
-
content: [
|
|
2605
|
-
...re(r.content),
|
|
2606
|
-
...r.toolCalls.map((s) => ({
|
|
2607
|
-
type: "tool_use",
|
|
2608
|
-
id: s.id ?? "",
|
|
2609
|
-
name: s.name,
|
|
2610
|
-
input: s.arguments ?? {}
|
|
2611
|
-
}))
|
|
2612
|
-
]
|
|
2613
|
-
} : o = { role: r.role, content: r.content };
|
|
2614
|
-
const i = t[t.length - 1];
|
|
2615
|
-
i && i.role === o.role ? i.content = [...re(i.content), ...re(o.content)] : t.push(o);
|
|
2616
|
-
}
|
|
2617
|
-
return t;
|
|
2618
|
-
};
|
|
2619
|
-
class _r {
|
|
2620
|
-
async *streamChat(t, n, r) {
|
|
2621
|
-
var b, A, _;
|
|
2622
|
-
const {
|
|
2623
|
-
apiKey: o,
|
|
2624
|
-
model: i = T.anthropic,
|
|
2625
|
-
temperature: s = 0.7,
|
|
2626
|
-
maxTokens: c = 4096,
|
|
2627
|
-
baseUrl: l = "https://api.anthropic.com/v1"
|
|
2628
|
-
} = n;
|
|
2629
|
-
if (!o) throw new Error("Anthropic API key required");
|
|
2630
|
-
const u = t.find((S) => S.role === "system"), d = Er(t), m = r != null && r.length ? r.map((S) => ({ name: S.name, description: S.description, input_schema: S.parameters })) : void 0, p = await fetch(`${l}/messages`, {
|
|
2631
|
-
method: "POST",
|
|
2632
|
-
headers: {
|
|
2633
|
-
"Content-Type": "application/json",
|
|
2634
|
-
"x-api-key": o,
|
|
2635
|
-
"anthropic-version": "2023-06-01",
|
|
2636
|
-
"anthropic-dangerous-direct-browser-access": "true"
|
|
2637
|
-
},
|
|
2638
|
-
body: JSON.stringify({
|
|
2639
|
-
model: i,
|
|
2640
|
-
messages: d,
|
|
2641
|
-
...u && { system: u.content },
|
|
2642
|
-
max_tokens: c,
|
|
2643
|
-
temperature: s,
|
|
2644
|
-
stream: !0,
|
|
2645
|
-
...m && { tools: m }
|
|
2646
|
-
})
|
|
2647
|
-
});
|
|
2648
|
-
if (!p.ok) {
|
|
2649
|
-
const S = await p.text();
|
|
2650
|
-
throw this.normalizeError(p.status, G(S));
|
|
2651
|
-
}
|
|
2652
|
-
if (!p.body) throw new Error("No response body for streaming");
|
|
2653
|
-
const h = p.body.getReader(), g = new TextDecoder();
|
|
2654
|
-
let w = "", f = null;
|
|
2655
|
-
try {
|
|
2656
|
-
for (; ; ) {
|
|
2657
|
-
const { done: S, value: x } = await h.read();
|
|
2658
|
-
if (S) break;
|
|
2659
|
-
w += g.decode(x, { stream: !0 });
|
|
2660
|
-
const $ = w.split(`
|
|
2661
|
-
`);
|
|
2662
|
-
w = $.pop() || "";
|
|
2663
|
-
for (const D of $) {
|
|
2664
|
-
const C = D.trim();
|
|
2665
|
-
if (!(!C || !C.startsWith("data: ")))
|
|
2666
|
-
try {
|
|
2667
|
-
const R = JSON.parse(C.slice(6));
|
|
2668
|
-
if (R.type === "content_block_start" && ((b = R.content_block) == null ? void 0 : b.type) === "tool_use")
|
|
2669
|
-
f = { id: R.content_block.id, name: R.content_block.name, argsBuf: "" };
|
|
2670
|
-
else if (R.type === "content_block_delta")
|
|
2671
|
-
((A = R.delta) == null ? void 0 : A.type) === "text_delta" && R.delta.text ? yield { type: "text-delta", text: R.delta.text } : ((_ = R.delta) == null ? void 0 : _.type) === "input_json_delta" && f && (f.argsBuf += R.delta.partial_json ?? "");
|
|
2672
|
-
else if (R.type === "content_block_stop" && f) {
|
|
2673
|
-
try {
|
|
2674
|
-
yield {
|
|
2675
|
-
type: "tool-call",
|
|
2676
|
-
toolCall: {
|
|
2677
|
-
id: f.id,
|
|
2678
|
-
name: f.name,
|
|
2679
|
-
arguments: f.argsBuf ? JSON.parse(f.argsBuf) : {}
|
|
2680
|
-
}
|
|
2681
|
-
};
|
|
2682
|
-
} catch {
|
|
2683
|
-
}
|
|
2684
|
-
f = null;
|
|
2685
|
-
}
|
|
2686
|
-
} catch {
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
} finally {
|
|
2691
|
-
h.releaseLock();
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
async generateText(t, n) {
|
|
2695
|
-
var d, m;
|
|
2696
|
-
const {
|
|
2697
|
-
apiKey: r,
|
|
2698
|
-
model: o = T.anthropic,
|
|
2699
|
-
temperature: i = 0.7,
|
|
2700
|
-
maxTokens: s = 4096,
|
|
2701
|
-
baseUrl: c = "https://api.anthropic.com/v1"
|
|
2702
|
-
} = n;
|
|
2703
|
-
if (!r) throw new Error("Anthropic API key required");
|
|
2704
|
-
if (!o) throw new Error("Model is required but was undefined");
|
|
2705
|
-
const l = await fetch(`${c}/messages`, {
|
|
2706
|
-
method: "POST",
|
|
2707
|
-
headers: {
|
|
2708
|
-
"Content-Type": "application/json",
|
|
2709
|
-
"x-api-key": r,
|
|
2710
|
-
"anthropic-version": "2023-06-01",
|
|
2711
|
-
"anthropic-dangerous-direct-browser-access": "true"
|
|
2712
|
-
},
|
|
2713
|
-
body: JSON.stringify({
|
|
2714
|
-
model: o,
|
|
2715
|
-
messages: [{ role: "user", content: t }],
|
|
2716
|
-
max_tokens: s,
|
|
2717
|
-
// REQUIRED by Anthropic
|
|
2718
|
-
temperature: i
|
|
2719
|
-
})
|
|
2720
|
-
});
|
|
2721
|
-
if (!l.ok) {
|
|
2722
|
-
const p = await l.text();
|
|
2723
|
-
throw console.error("🔴 RAW ANTHROPIC ERROR:", l.status, p), console.error("🔴 Request was made to:", `${c}/messages`), console.error("🔴 Model requested:", o), this.normalizeError(l.status, G(p));
|
|
2724
|
-
}
|
|
2725
|
-
return ((m = (d = (await l.json()).content) == null ? void 0 : d[0]) == null ? void 0 : m.text) || "";
|
|
2726
|
-
}
|
|
2727
|
-
async *streamText(t, n) {
|
|
2728
|
-
var p;
|
|
2729
|
-
const {
|
|
2730
|
-
apiKey: r,
|
|
2731
|
-
model: o = T.anthropic,
|
|
2732
|
-
temperature: i = 0.7,
|
|
2733
|
-
maxTokens: s = 4096,
|
|
2734
|
-
baseUrl: c = "https://api.anthropic.com/v1"
|
|
2735
|
-
} = n;
|
|
2736
|
-
if (!r) throw new Error("Anthropic API key required");
|
|
2737
|
-
if (!o) throw new Error("Model is required but was undefined");
|
|
2738
|
-
const l = await fetch(`${c}/messages`, {
|
|
2739
|
-
method: "POST",
|
|
2740
|
-
headers: {
|
|
2741
|
-
"Content-Type": "application/json",
|
|
2742
|
-
"x-api-key": r,
|
|
2743
|
-
"anthropic-version": "2023-06-01",
|
|
2744
|
-
"anthropic-dangerous-direct-browser-access": "true"
|
|
2745
|
-
},
|
|
2746
|
-
body: JSON.stringify({
|
|
2747
|
-
model: o,
|
|
2748
|
-
messages: [{ role: "user", content: t }],
|
|
2749
|
-
max_tokens: s,
|
|
2750
|
-
// REQUIRED by Anthropic
|
|
2751
|
-
temperature: i,
|
|
2752
|
-
stream: !0
|
|
2753
|
-
})
|
|
2754
|
-
});
|
|
2755
|
-
if (!l.ok) {
|
|
2756
|
-
const h = await l.text();
|
|
2757
|
-
throw console.error("🔴 RAW ANTHROPIC STREAM ERROR:", l.status, h), console.error("🔴 Request was made to:", `${c}/messages`), console.error("🔴 Model requested:", o), this.normalizeError(l.status, G(h));
|
|
2758
|
-
}
|
|
2759
|
-
if (!l.body) throw new Error("No response body for streaming");
|
|
2760
|
-
const u = l.body.getReader(), d = new TextDecoder();
|
|
2761
|
-
let m = "";
|
|
2762
|
-
try {
|
|
2763
|
-
for (; ; ) {
|
|
2764
|
-
const { done: h, value: g } = await u.read();
|
|
2765
|
-
if (h) break;
|
|
2766
|
-
m += d.decode(g, { stream: !0 });
|
|
2767
|
-
const w = m.split(`
|
|
2768
|
-
`);
|
|
2769
|
-
m = w.pop() || "";
|
|
2770
|
-
for (const f of w) {
|
|
2771
|
-
const b = f.trim();
|
|
2772
|
-
if (!b || !b.startsWith("data: ")) continue;
|
|
2773
|
-
const A = b.slice(6);
|
|
2774
|
-
try {
|
|
2775
|
-
const _ = JSON.parse(A);
|
|
2776
|
-
_.type === "content_block_delta" && ((p = _.delta) != null && p.text) && (yield _.delta.text);
|
|
2777
|
-
} catch {
|
|
2778
|
-
continue;
|
|
2779
|
-
}
|
|
2780
|
-
}
|
|
2781
|
-
}
|
|
2782
|
-
} finally {
|
|
2783
|
-
u.releaseLock();
|
|
2784
|
-
}
|
|
2785
|
-
}
|
|
2786
|
-
/**
|
|
2787
|
-
* NOTE ON THE SIGNATURE
|
|
2788
|
-
*
|
|
2789
|
-
* This took `(prompt, config)` while the AiProvider interface — and every
|
|
2790
|
-
* other adapter — declares `(prompt, schema, config)`. Because `schema` is
|
|
2791
|
-
* typed `unknown`, TypeScript accepted the mismatch at the call site, so
|
|
2792
|
-
* AiGatewayService.generateObject() passed the schema where config belonged.
|
|
2793
|
-
* Destructuring `apiKey` off a schema yields undefined, and the call died
|
|
2794
|
-
* with "Anthropic API key required" — a message pointing at configuration for
|
|
2795
|
-
* a fault that was arity. Structured output was broken on this provider for
|
|
2796
|
-
* anyone who used the gateway.
|
|
2797
|
-
*
|
|
2798
|
-
* Claude has no native JSON mode, so `schema` is folded into the prompt
|
|
2799
|
-
* rather than sent as a parameter.
|
|
2800
|
-
*/
|
|
2801
|
-
async generateObject(t, n, r) {
|
|
2802
|
-
var f, b;
|
|
2803
|
-
const {
|
|
2804
|
-
apiKey: o,
|
|
2805
|
-
model: i = T.anthropic,
|
|
2806
|
-
temperature: s = 0.7,
|
|
2807
|
-
maxTokens: c = 4096,
|
|
2808
|
-
baseUrl: l = "https://api.anthropic.com/v1"
|
|
2809
|
-
} = r;
|
|
2810
|
-
if (!o) throw new Error("Anthropic API key required");
|
|
2811
|
-
if (!i) throw new Error("Model is required but was undefined");
|
|
2812
|
-
const u = n ? `
|
|
2813
|
-
|
|
2814
|
-
It must match this shape:
|
|
2815
|
-
${JSON.stringify(n)}` : "", d = `${t}${u}
|
|
2816
|
-
|
|
2817
|
-
IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the JSON object.`, m = await fetch(`${l}/messages`, {
|
|
2818
|
-
method: "POST",
|
|
2819
|
-
headers: {
|
|
2820
|
-
"Content-Type": "application/json",
|
|
2821
|
-
"x-api-key": o,
|
|
2822
|
-
"anthropic-version": "2023-06-01",
|
|
2823
|
-
"anthropic-dangerous-direct-browser-access": "true"
|
|
2824
|
-
},
|
|
2825
|
-
body: JSON.stringify({
|
|
2826
|
-
model: i,
|
|
2827
|
-
messages: [{ role: "user", content: d }],
|
|
2828
|
-
max_tokens: c,
|
|
2829
|
-
// REQUIRED by Anthropic
|
|
2830
|
-
temperature: s
|
|
2831
|
-
})
|
|
2832
|
-
});
|
|
2833
|
-
if (!m.ok) {
|
|
2834
|
-
const A = await m.text();
|
|
2835
|
-
throw console.error("🔴 RAW ANTHROPIC OBJECT ERROR:", m.status, A), console.error("🔴 Request was made to:", `${l}/messages`), console.error("🔴 Model requested:", i), this.normalizeError(m.status, G(A));
|
|
2836
|
-
}
|
|
2837
|
-
const h = ((b = (f = (await m.json()).content) == null ? void 0 : f[0]) == null ? void 0 : b.text) || "{}", g = h.match(/\{[\s\S]*\}/), w = g ? g[0] : h;
|
|
2838
|
-
return JSON.parse(w);
|
|
2839
|
-
}
|
|
2840
|
-
async listModels(t, n) {
|
|
2841
|
-
return [...ce.anthropic];
|
|
2842
|
-
}
|
|
2843
|
-
normalizeError(t, n) {
|
|
2844
|
-
var i;
|
|
2845
|
-
const r = ((i = n.error) == null ? void 0 : i.message) || n.message || "Anthropic request failed";
|
|
2846
|
-
if (t === 429) {
|
|
2847
|
-
const s = new Error(`Rate limit exceeded: ${r}`);
|
|
2848
|
-
return s.code = "RATE_LIMIT_EXCEEDED", s.status = 429, s;
|
|
2849
|
-
}
|
|
2850
|
-
if (t === 401 || t === 403) {
|
|
2851
|
-
const s = new Error(`Authentication failed: ${r}`);
|
|
2852
|
-
return s.code = "AUTH_ERROR", s.status = t, s;
|
|
2853
|
-
}
|
|
2854
|
-
if (t === 400) {
|
|
2855
|
-
const s = new Error(`Bad request: ${r}`);
|
|
2856
|
-
return s.code = "INVALID_REQUEST", s.status = 400, s;
|
|
2857
|
-
}
|
|
2858
|
-
const o = new Error(r);
|
|
2859
|
-
return o.code = "API_ERROR", o.status = t, o;
|
|
2860
|
-
}
|
|
2861
|
-
}
|
|
2862
|
-
function U(a) {
|
|
2863
|
-
if (!(!a || a.length === 0))
|
|
2864
|
-
return a.map((t) => ({
|
|
2865
|
-
type: "function",
|
|
2866
|
-
function: { name: t.name, description: t.description, parameters: t.parameters }
|
|
2867
|
-
}));
|
|
2868
|
-
}
|
|
2869
|
-
async function* le(a, t, n, r) {
|
|
2870
|
-
var u, d, m, p;
|
|
2871
|
-
const o = await fetch(a, {
|
|
2872
|
-
method: "POST",
|
|
2873
|
-
headers: t,
|
|
2874
|
-
body: JSON.stringify(n)
|
|
2875
|
-
});
|
|
2876
|
-
if (!o.ok) {
|
|
2877
|
-
const h = await o.json().catch(() => ({}));
|
|
2878
|
-
throw r(o.status, h);
|
|
2879
|
-
}
|
|
2880
|
-
if (!o.body) throw new Error("No response body for streaming");
|
|
2881
|
-
const i = o.body.getReader(), s = new TextDecoder();
|
|
2882
|
-
let c = "";
|
|
2883
|
-
const l = /* @__PURE__ */ new Map();
|
|
2884
|
-
try {
|
|
2885
|
-
for (; ; ) {
|
|
2886
|
-
const { done: h, value: g } = await i.read();
|
|
2887
|
-
if (h) break;
|
|
2888
|
-
c += s.decode(g, { stream: !0 });
|
|
2889
|
-
const w = c.split(`
|
|
2890
|
-
`);
|
|
2891
|
-
c = w.pop() || "";
|
|
2892
|
-
for (const f of w) {
|
|
2893
|
-
const b = f.trim();
|
|
2894
|
-
if (!b || !b.startsWith("data: ")) continue;
|
|
2895
|
-
const A = b.slice(6);
|
|
2896
|
-
if (A !== "[DONE]")
|
|
2897
|
-
try {
|
|
2898
|
-
const S = (d = (u = JSON.parse(A).choices) == null ? void 0 : u[0]) == null ? void 0 : d.delta;
|
|
2899
|
-
if (!S) continue;
|
|
2900
|
-
if (S.content && (yield { type: "text-delta", text: S.content }), S.tool_calls)
|
|
2901
|
-
for (const x of S.tool_calls) {
|
|
2902
|
-
const $ = x.index ?? 0, D = l.get($) ?? { name: "", args: "" };
|
|
2903
|
-
x.id && (D.id = x.id), (m = x.function) != null && m.name && (D.name += x.function.name), (p = x.function) != null && p.arguments && (D.args += x.function.arguments), l.set($, D);
|
|
2904
|
-
}
|
|
2905
|
-
} catch {
|
|
2906
|
-
}
|
|
2907
|
-
}
|
|
2908
|
-
}
|
|
2909
|
-
} finally {
|
|
2910
|
-
i.releaseLock();
|
|
2911
|
-
}
|
|
2912
|
-
for (const h of l.values())
|
|
2913
|
-
if (h.name)
|
|
2914
|
-
try {
|
|
2915
|
-
yield {
|
|
2916
|
-
type: "tool-call",
|
|
2917
|
-
toolCall: {
|
|
2918
|
-
id: h.id,
|
|
2919
|
-
name: h.name,
|
|
2920
|
-
arguments: h.args ? JSON.parse(h.args) : {}
|
|
2921
|
-
}
|
|
2922
|
-
};
|
|
2923
|
-
} catch {
|
|
2924
|
-
}
|
|
2925
|
-
}
|
|
2926
|
-
function ue(a) {
|
|
2927
|
-
return a.map((t) => ({ role: t.role, content: t.content }));
|
|
2928
|
-
}
|
|
2929
|
-
class Tr {
|
|
2930
|
-
async *streamChat(t, n, r) {
|
|
2931
|
-
const { apiKey: o, model: i = T.openai, temperature: s = 0.7, baseUrl: c = "https://api.openai.com/v1" } = n;
|
|
2932
|
-
if (!o) throw new Error("OpenAI API key required");
|
|
2933
|
-
yield* le(
|
|
2934
|
-
`${c}/chat/completions`,
|
|
2935
|
-
{ "Content-Type": "application/json", Authorization: `Bearer ${o}` },
|
|
2936
|
-
{
|
|
2937
|
-
model: i,
|
|
2938
|
-
messages: ue(t),
|
|
2939
|
-
temperature: s,
|
|
2940
|
-
stream: !0,
|
|
2941
|
-
...U(r) && { tools: U(r), tool_choice: "auto" }
|
|
2942
|
-
},
|
|
2943
|
-
this.normalizeError
|
|
2944
|
-
);
|
|
2945
|
-
}
|
|
2946
|
-
async generateText(t, n) {
|
|
2947
|
-
var u, d, m;
|
|
2948
|
-
const { apiKey: r, model: o = T.openai, temperature: i = 0.7, baseUrl: s = "https://api.openai.com/v1" } = n;
|
|
2949
|
-
if (!r) throw new Error("OpenAI API key required");
|
|
2950
|
-
const c = await fetch(`${s}/chat/completions`, {
|
|
2951
|
-
method: "POST",
|
|
2952
|
-
headers: {
|
|
2953
|
-
"Content-Type": "application/json",
|
|
2954
|
-
Authorization: `Bearer ${r}`
|
|
2955
|
-
},
|
|
2956
|
-
body: JSON.stringify({
|
|
2957
|
-
model: o,
|
|
2958
|
-
messages: [{ role: "user", content: t }],
|
|
2959
|
-
temperature: i
|
|
2960
|
-
})
|
|
2961
|
-
});
|
|
2962
|
-
if (!c.ok) {
|
|
2963
|
-
const p = await c.json();
|
|
2964
|
-
throw this.normalizeError(c.status, p);
|
|
2965
|
-
}
|
|
2966
|
-
return ((m = (d = (u = (await c.json()).choices) == null ? void 0 : u[0]) == null ? void 0 : d.message) == null ? void 0 : m.content) || "";
|
|
2967
|
-
}
|
|
2968
|
-
async *streamText(t, n) {
|
|
2969
|
-
var m, p, h;
|
|
2970
|
-
const { apiKey: r, model: o = T.openai, temperature: i = 0.7, baseUrl: s = "https://api.openai.com/v1" } = n;
|
|
2971
|
-
if (!r) throw new Error("OpenAI API key required");
|
|
2972
|
-
const c = await fetch(`${s}/chat/completions`, {
|
|
2973
|
-
method: "POST",
|
|
2974
|
-
headers: {
|
|
2975
|
-
"Content-Type": "application/json",
|
|
2976
|
-
Authorization: `Bearer ${r}`
|
|
2977
|
-
},
|
|
2978
|
-
body: JSON.stringify({
|
|
2979
|
-
model: o,
|
|
2980
|
-
messages: [{ role: "user", content: t }],
|
|
2981
|
-
temperature: i,
|
|
2982
|
-
stream: !0
|
|
2983
|
-
})
|
|
2984
|
-
});
|
|
2985
|
-
if (!c.ok) {
|
|
2986
|
-
const g = await c.json();
|
|
2987
|
-
throw this.normalizeError(c.status, g);
|
|
2988
|
-
}
|
|
2989
|
-
if (!c.body) throw new Error("No response body for streaming");
|
|
2990
|
-
const l = c.body.getReader(), u = new TextDecoder();
|
|
2991
|
-
let d = "";
|
|
2992
|
-
try {
|
|
2993
|
-
for (; ; ) {
|
|
2994
|
-
const { done: g, value: w } = await l.read();
|
|
2995
|
-
if (g) break;
|
|
2996
|
-
d += u.decode(w, { stream: !0 });
|
|
2997
|
-
const f = d.split(`
|
|
2998
|
-
`);
|
|
2999
|
-
d = f.pop() || "";
|
|
3000
|
-
for (const b of f) {
|
|
3001
|
-
const A = b.trim();
|
|
3002
|
-
if (!A || !A.startsWith("data: ")) continue;
|
|
3003
|
-
const _ = A.slice(6);
|
|
3004
|
-
if (_ !== "[DONE]")
|
|
3005
|
-
try {
|
|
3006
|
-
const x = (h = (p = (m = JSON.parse(_).choices) == null ? void 0 : m[0]) == null ? void 0 : p.delta) == null ? void 0 : h.content;
|
|
3007
|
-
x && (yield x);
|
|
3008
|
-
} catch {
|
|
3009
|
-
}
|
|
3010
|
-
}
|
|
3011
|
-
}
|
|
3012
|
-
} finally {
|
|
3013
|
-
l.releaseLock();
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
async generateObject(t, n, r) {
|
|
3017
|
-
var m, p, h;
|
|
3018
|
-
const { apiKey: o, model: i = T.openai, temperature: s = 0.7, baseUrl: c = "https://api.openai.com/v1" } = r;
|
|
3019
|
-
if (!o) throw new Error("OpenAI API key required");
|
|
3020
|
-
const l = await fetch(`${c}/chat/completions`, {
|
|
3021
|
-
method: "POST",
|
|
3022
|
-
headers: {
|
|
3023
|
-
"Content-Type": "application/json",
|
|
3024
|
-
Authorization: `Bearer ${o}`
|
|
3025
|
-
},
|
|
3026
|
-
body: JSON.stringify({
|
|
3027
|
-
model: i,
|
|
3028
|
-
messages: [{ role: "user", content: t }],
|
|
3029
|
-
response_format: { type: "json_object" },
|
|
3030
|
-
temperature: s
|
|
3031
|
-
})
|
|
3032
|
-
});
|
|
3033
|
-
if (!l.ok) {
|
|
3034
|
-
const g = await l.json();
|
|
3035
|
-
throw this.normalizeError(l.status, g);
|
|
3036
|
-
}
|
|
3037
|
-
const d = ((h = (p = (m = (await l.json()).choices) == null ? void 0 : m[0]) == null ? void 0 : p.message) == null ? void 0 : h.content) || "{}";
|
|
3038
|
-
return JSON.parse(d);
|
|
3039
|
-
}
|
|
3040
|
-
async listModels(t, n) {
|
|
3041
|
-
var s, c;
|
|
3042
|
-
const r = n || "https://api.openai.com/v1";
|
|
3043
|
-
if (!t) throw new Error("OpenAI API key required");
|
|
3044
|
-
const o = await fetch(`${r}/models`, {
|
|
3045
|
-
headers: {
|
|
3046
|
-
Authorization: `Bearer ${t}`
|
|
3047
|
-
}
|
|
3048
|
-
});
|
|
3049
|
-
if (!o.ok) {
|
|
3050
|
-
const l = await o.json();
|
|
3051
|
-
throw this.normalizeError(o.status, l);
|
|
3052
|
-
}
|
|
3053
|
-
return ((c = (s = (await o.json()).data) == null ? void 0 : s.filter((l) => l.id.startsWith("gpt-"))) == null ? void 0 : c.map((l) => l.id)) || [];
|
|
3054
|
-
}
|
|
3055
|
-
normalizeError(t, n) {
|
|
3056
|
-
var i;
|
|
3057
|
-
const r = ((i = n.error) == null ? void 0 : i.message) || n.message || "OpenAI request failed";
|
|
3058
|
-
if (t === 429) {
|
|
3059
|
-
const s = new Error(`Rate limit exceeded: ${r}`);
|
|
3060
|
-
return s.code = "RATE_LIMIT_EXCEEDED", s.status = 429, s;
|
|
3061
|
-
}
|
|
3062
|
-
if (t === 401 || t === 403) {
|
|
3063
|
-
const s = new Error(`Authentication failed: ${r}`);
|
|
3064
|
-
return s.code = "AUTH_ERROR", s.status = t, s;
|
|
3065
|
-
}
|
|
3066
|
-
const o = new Error(r);
|
|
3067
|
-
return o.code = "API_ERROR", o.status = t, o;
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
class jr {
|
|
3071
|
-
async *streamChat(t, n, r) {
|
|
3072
|
-
const { apiKey: o, model: i = T.grok, temperature: s = 0.7, baseUrl: c = "https://api.x.ai/v1" } = n;
|
|
3073
|
-
if (!o) throw new Error("Grok API key required");
|
|
3074
|
-
yield* le(
|
|
3075
|
-
`${c}/chat/completions`,
|
|
3076
|
-
{ "Content-Type": "application/json", Authorization: `Bearer ${o}` },
|
|
3077
|
-
{
|
|
3078
|
-
model: i,
|
|
3079
|
-
messages: ue(t),
|
|
3080
|
-
temperature: s,
|
|
3081
|
-
stream: !0,
|
|
3082
|
-
...U(r) && { tools: U(r), tool_choice: "auto" }
|
|
3083
|
-
},
|
|
3084
|
-
this.normalizeError
|
|
3085
|
-
);
|
|
3086
|
-
}
|
|
3087
|
-
async generateText(t, n) {
|
|
3088
|
-
var u, d, m;
|
|
3089
|
-
const { apiKey: r, model: o = T.grok, temperature: i = 0.7, baseUrl: s = "https://api.x.ai/v1" } = n;
|
|
3090
|
-
if (!r) throw new Error("Grok API key required");
|
|
3091
|
-
const c = await fetch(`${s}/chat/completions`, {
|
|
3092
|
-
method: "POST",
|
|
3093
|
-
headers: {
|
|
3094
|
-
"Content-Type": "application/json",
|
|
3095
|
-
Authorization: `Bearer ${r}`
|
|
3096
|
-
},
|
|
3097
|
-
body: JSON.stringify({
|
|
3098
|
-
model: o,
|
|
3099
|
-
messages: [{ role: "user", content: t }],
|
|
3100
|
-
temperature: i
|
|
3101
|
-
})
|
|
3102
|
-
});
|
|
3103
|
-
if (!c.ok) {
|
|
3104
|
-
const p = await c.json();
|
|
3105
|
-
throw this.normalizeError(c.status, p);
|
|
3106
|
-
}
|
|
3107
|
-
return ((m = (d = (u = (await c.json()).choices) == null ? void 0 : u[0]) == null ? void 0 : d.message) == null ? void 0 : m.content) || "";
|
|
3108
|
-
}
|
|
3109
|
-
async *streamText(t, n) {
|
|
3110
|
-
var m, p, h;
|
|
3111
|
-
const { apiKey: r, model: o = T.grok, temperature: i = 0.7, baseUrl: s = "https://api.x.ai/v1" } = n;
|
|
3112
|
-
if (!r) throw new Error("Grok API key required");
|
|
3113
|
-
const c = await fetch(`${s}/chat/completions`, {
|
|
3114
|
-
method: "POST",
|
|
3115
|
-
headers: {
|
|
3116
|
-
"Content-Type": "application/json",
|
|
3117
|
-
Authorization: `Bearer ${r}`
|
|
3118
|
-
},
|
|
3119
|
-
body: JSON.stringify({
|
|
3120
|
-
model: o,
|
|
3121
|
-
messages: [{ role: "user", content: t }],
|
|
3122
|
-
temperature: i,
|
|
3123
|
-
stream: !0
|
|
3124
|
-
})
|
|
3125
|
-
});
|
|
3126
|
-
if (!c.ok) {
|
|
3127
|
-
const g = await c.json();
|
|
3128
|
-
throw this.normalizeError(c.status, g);
|
|
3129
|
-
}
|
|
3130
|
-
if (!c.body) throw new Error("No response body for streaming");
|
|
3131
|
-
const l = c.body.getReader(), u = new TextDecoder();
|
|
3132
|
-
let d = "";
|
|
3133
|
-
try {
|
|
3134
|
-
for (; ; ) {
|
|
3135
|
-
const { done: g, value: w } = await l.read();
|
|
3136
|
-
if (g) break;
|
|
3137
|
-
d += u.decode(w, { stream: !0 });
|
|
3138
|
-
const f = d.split(`
|
|
3139
|
-
`);
|
|
3140
|
-
d = f.pop() || "";
|
|
3141
|
-
for (const b of f) {
|
|
3142
|
-
const A = b.trim();
|
|
3143
|
-
if (!A || !A.startsWith("data: ")) continue;
|
|
3144
|
-
const _ = A.slice(6);
|
|
3145
|
-
if (_ !== "[DONE]")
|
|
3146
|
-
try {
|
|
3147
|
-
const x = (h = (p = (m = JSON.parse(_).choices) == null ? void 0 : m[0]) == null ? void 0 : p.delta) == null ? void 0 : h.content;
|
|
3148
|
-
x && (yield x);
|
|
3149
|
-
} catch {
|
|
3150
|
-
}
|
|
3151
|
-
}
|
|
3152
|
-
}
|
|
3153
|
-
} finally {
|
|
3154
|
-
l.releaseLock();
|
|
3155
|
-
}
|
|
3156
|
-
}
|
|
3157
|
-
async generateObject(t, n, r) {
|
|
3158
|
-
var g, w, f;
|
|
3159
|
-
const { apiKey: o, model: i = T.grok, temperature: s = 0.7, baseUrl: c = "https://api.x.ai/v1" } = r;
|
|
3160
|
-
if (!o) throw new Error("Grok API key required");
|
|
3161
|
-
const l = `${t}
|
|
3162
|
-
|
|
3163
|
-
Respond with valid JSON only.`, u = await fetch(`${c}/chat/completions`, {
|
|
3164
|
-
method: "POST",
|
|
3165
|
-
headers: {
|
|
3166
|
-
"Content-Type": "application/json",
|
|
3167
|
-
Authorization: `Bearer ${o}`
|
|
3168
|
-
},
|
|
3169
|
-
body: JSON.stringify({
|
|
3170
|
-
model: i,
|
|
3171
|
-
messages: [{ role: "user", content: l }],
|
|
3172
|
-
temperature: s
|
|
3173
|
-
})
|
|
3174
|
-
});
|
|
3175
|
-
if (!u.ok) {
|
|
3176
|
-
const b = await u.json();
|
|
3177
|
-
throw this.normalizeError(u.status, b);
|
|
3178
|
-
}
|
|
3179
|
-
const m = ((f = (w = (g = (await u.json()).choices) == null ? void 0 : g[0]) == null ? void 0 : w.message) == null ? void 0 : f.content) || "{}", p = m.match(/\{[\s\S]*\}/), h = p ? p[0] : m;
|
|
3180
|
-
return JSON.parse(h);
|
|
3181
|
-
}
|
|
3182
|
-
async listModels(t, n) {
|
|
3183
|
-
return [...ce.grok];
|
|
3184
|
-
}
|
|
3185
|
-
normalizeError(t, n) {
|
|
3186
|
-
var i;
|
|
3187
|
-
const r = ((i = n.error) == null ? void 0 : i.message) || n.message || "Grok request failed";
|
|
3188
|
-
if (t === 429) {
|
|
3189
|
-
const s = new Error(`Rate limit exceeded: ${r}`);
|
|
3190
|
-
return s.code = "RATE_LIMIT_EXCEEDED", s.status = 429, s;
|
|
3191
|
-
}
|
|
3192
|
-
if (t === 401 || t === 403) {
|
|
3193
|
-
const s = new Error(`Authentication failed: ${r}`);
|
|
3194
|
-
return s.code = "AUTH_ERROR", s.status = t, s;
|
|
3195
|
-
}
|
|
3196
|
-
const o = new Error(r);
|
|
3197
|
-
return o.code = "API_ERROR", o.status = t, o;
|
|
3198
|
-
}
|
|
3199
|
-
}
|
|
3200
|
-
class Or {
|
|
3201
|
-
async *streamChat(t, n, r) {
|
|
3202
|
-
const { apiKey: o, model: i = T.deepseek, temperature: s = 0.7, baseUrl: c = "https://api.deepseek.com/v1" } = n;
|
|
3203
|
-
if (!o) throw new Error("DeepSeek API key required");
|
|
3204
|
-
yield* le(
|
|
3205
|
-
`${c}/chat/completions`,
|
|
3206
|
-
{ "Content-Type": "application/json", Authorization: `Bearer ${o}` },
|
|
3207
|
-
{
|
|
3208
|
-
model: i,
|
|
3209
|
-
messages: ue(t),
|
|
3210
|
-
temperature: s,
|
|
3211
|
-
stream: !0,
|
|
3212
|
-
...U(r) && { tools: U(r), tool_choice: "auto" }
|
|
3213
|
-
},
|
|
3214
|
-
this.normalizeError
|
|
3215
|
-
);
|
|
3216
|
-
}
|
|
3217
|
-
async generateText(t, n) {
|
|
3218
|
-
var u, d, m;
|
|
3219
|
-
const { apiKey: r, model: o = T.deepseek, temperature: i = 0.7, baseUrl: s = "https://api.deepseek.com/v1" } = n;
|
|
3220
|
-
if (!r) throw new Error("DeepSeek API key required");
|
|
3221
|
-
const c = await fetch(`${s}/chat/completions`, {
|
|
3222
|
-
method: "POST",
|
|
3223
|
-
headers: {
|
|
3224
|
-
"Content-Type": "application/json",
|
|
3225
|
-
Authorization: `Bearer ${r}`
|
|
3226
|
-
},
|
|
3227
|
-
body: JSON.stringify({
|
|
3228
|
-
model: o,
|
|
3229
|
-
messages: [{ role: "user", content: t }],
|
|
3230
|
-
temperature: i
|
|
3231
|
-
})
|
|
3232
|
-
});
|
|
3233
|
-
if (!c.ok) {
|
|
3234
|
-
const p = await c.json();
|
|
3235
|
-
throw this.normalizeError(c.status, p);
|
|
3236
|
-
}
|
|
3237
|
-
return ((m = (d = (u = (await c.json()).choices) == null ? void 0 : u[0]) == null ? void 0 : d.message) == null ? void 0 : m.content) || "";
|
|
3238
|
-
}
|
|
3239
|
-
async *streamText(t, n) {
|
|
3240
|
-
var m, p, h;
|
|
3241
|
-
const { apiKey: r, model: o = T.deepseek, temperature: i = 0.7, baseUrl: s = "https://api.deepseek.com/v1" } = n;
|
|
3242
|
-
if (!r) throw new Error("DeepSeek API key required");
|
|
3243
|
-
const c = await fetch(`${s}/chat/completions`, {
|
|
3244
|
-
method: "POST",
|
|
3245
|
-
headers: {
|
|
3246
|
-
"Content-Type": "application/json",
|
|
3247
|
-
Authorization: `Bearer ${r}`
|
|
3248
|
-
},
|
|
3249
|
-
body: JSON.stringify({
|
|
3250
|
-
model: o,
|
|
3251
|
-
messages: [{ role: "user", content: t }],
|
|
3252
|
-
temperature: i,
|
|
3253
|
-
stream: !0
|
|
3254
|
-
})
|
|
3255
|
-
});
|
|
3256
|
-
if (!c.ok) {
|
|
3257
|
-
const g = await c.json();
|
|
3258
|
-
throw this.normalizeError(c.status, g);
|
|
3259
|
-
}
|
|
3260
|
-
if (!c.body) throw new Error("No response body for streaming");
|
|
3261
|
-
const l = c.body.getReader(), u = new TextDecoder();
|
|
3262
|
-
let d = "";
|
|
3263
|
-
try {
|
|
3264
|
-
for (; ; ) {
|
|
3265
|
-
const { done: g, value: w } = await l.read();
|
|
3266
|
-
if (g) break;
|
|
3267
|
-
d += u.decode(w, { stream: !0 });
|
|
3268
|
-
const f = d.split(`
|
|
3269
|
-
`);
|
|
3270
|
-
d = f.pop() || "";
|
|
3271
|
-
for (const b of f) {
|
|
3272
|
-
const A = b.trim();
|
|
3273
|
-
if (!A || !A.startsWith("data: ")) continue;
|
|
3274
|
-
const _ = A.slice(6);
|
|
3275
|
-
if (_ !== "[DONE]")
|
|
3276
|
-
try {
|
|
3277
|
-
const x = (h = (p = (m = JSON.parse(_).choices) == null ? void 0 : m[0]) == null ? void 0 : p.delta) == null ? void 0 : h.content;
|
|
3278
|
-
x && (yield x);
|
|
3279
|
-
} catch {
|
|
3280
|
-
}
|
|
3281
|
-
}
|
|
3282
|
-
}
|
|
3283
|
-
} finally {
|
|
3284
|
-
l.releaseLock();
|
|
3285
|
-
}
|
|
3286
|
-
}
|
|
3287
|
-
async generateObject(t, n, r) {
|
|
3288
|
-
var m, p, h;
|
|
3289
|
-
const { apiKey: o, model: i = T.deepseek, temperature: s = 0.7, baseUrl: c = "https://api.deepseek.com/v1" } = r;
|
|
3290
|
-
if (!o) throw new Error("DeepSeek API key required");
|
|
3291
|
-
const l = await fetch(`${c}/chat/completions`, {
|
|
3292
|
-
method: "POST",
|
|
3293
|
-
headers: {
|
|
3294
|
-
"Content-Type": "application/json",
|
|
3295
|
-
Authorization: `Bearer ${o}`
|
|
3296
|
-
},
|
|
3297
|
-
body: JSON.stringify({
|
|
3298
|
-
model: i,
|
|
3299
|
-
messages: [{ role: "user", content: t }],
|
|
3300
|
-
response_format: { type: "json_object" },
|
|
3301
|
-
temperature: s
|
|
3302
|
-
})
|
|
3303
|
-
});
|
|
3304
|
-
if (!l.ok) {
|
|
3305
|
-
const g = await l.json();
|
|
3306
|
-
throw this.normalizeError(l.status, g);
|
|
3307
|
-
}
|
|
3308
|
-
const d = ((h = (p = (m = (await l.json()).choices) == null ? void 0 : m[0]) == null ? void 0 : p.message) == null ? void 0 : h.content) || "{}";
|
|
3309
|
-
return JSON.parse(d);
|
|
3310
|
-
}
|
|
3311
|
-
async listModels(t, n) {
|
|
3312
|
-
return [...ce.deepseek];
|
|
3313
|
-
}
|
|
3314
|
-
normalizeError(t, n) {
|
|
3315
|
-
var i;
|
|
3316
|
-
const r = ((i = n.error) == null ? void 0 : i.message) || n.message || "DeepSeek request failed";
|
|
3317
|
-
if (t === 429) {
|
|
3318
|
-
const s = new Error(`Rate limit exceeded: ${r}`);
|
|
3319
|
-
return s.code = "RATE_LIMIT_EXCEEDED", s.status = 429, s;
|
|
3320
|
-
}
|
|
3321
|
-
if (t === 401 || t === 403) {
|
|
3322
|
-
const s = new Error(`Authentication failed: ${r}`);
|
|
3323
|
-
return s.code = "AUTH_ERROR", s.status = t, s;
|
|
3324
|
-
}
|
|
3325
|
-
const o = new Error(r);
|
|
3326
|
-
return o.code = "API_ERROR", o.status = t, o;
|
|
3327
|
-
}
|
|
3328
|
-
}
|
|
3329
|
-
let Pr = class {
|
|
3330
|
-
constructor(t) {
|
|
3331
|
-
this.requests = [], this.config = t;
|
|
3332
|
-
}
|
|
3333
|
-
checkLimit() {
|
|
3334
|
-
const t = Date.now(), n = t - this.config.windowMs;
|
|
3335
|
-
return this.requests = this.requests.filter((r) => r > n), this.requests.length >= this.config.maxRequests ? !1 : (this.requests.push(t), !0);
|
|
3336
|
-
}
|
|
3337
|
-
getRemainingRequests() {
|
|
3338
|
-
const n = Date.now() - this.config.windowMs;
|
|
3339
|
-
return this.requests = this.requests.filter((r) => r > n), Math.max(0, this.config.maxRequests - this.requests.length);
|
|
3340
|
-
}
|
|
3341
|
-
getResetTime() {
|
|
3342
|
-
return this.requests.length === 0 ? 0 : this.requests[0] + this.config.windowMs;
|
|
3343
|
-
}
|
|
3344
|
-
};
|
|
3345
|
-
class L {
|
|
3346
|
-
constructor() {
|
|
3347
|
-
this.rateLimiter = new Pr({
|
|
3348
|
-
maxRequests: 10,
|
|
3349
|
-
windowMs: 6e4
|
|
3350
|
-
}), this.adapters = /* @__PURE__ */ new Map([
|
|
3351
|
-
["google-gemini", new kr()],
|
|
3352
|
-
["ollama", new Sr()],
|
|
3353
|
-
["anthropic", new _r()],
|
|
3354
|
-
["openai", new Tr()],
|
|
3355
|
-
["grok", new jr()],
|
|
3356
|
-
["deepseek", new Or()]
|
|
3357
|
-
]);
|
|
3358
|
-
}
|
|
3359
|
-
static getInstance() {
|
|
3360
|
-
return L.instance || (L.instance = new L()), L.instance;
|
|
3361
|
-
}
|
|
3362
|
-
/**
|
|
3363
|
-
* Generate text with rate limiting and error handling
|
|
3364
|
-
*/
|
|
3365
|
-
async generateText(t, n) {
|
|
3366
|
-
if (!this.rateLimiter.checkLimit()) {
|
|
3367
|
-
const o = this.rateLimiter.getResetTime(), i = new Error("Rate limit exceeded. Please wait before making another request.");
|
|
3368
|
-
throw i.code = "RATE_LIMIT_EXCEEDED", i.resetTime = o, i;
|
|
3369
|
-
}
|
|
3370
|
-
const r = this.adapters.get(n.provider);
|
|
3371
|
-
if (!r)
|
|
3372
|
-
throw new Error(`Provider ${n.provider} not supported yet.`);
|
|
3373
|
-
try {
|
|
3374
|
-
return await r.generateText(t, n);
|
|
3375
|
-
} catch (o) {
|
|
3376
|
-
throw console.error("[AiGateway] Error:", o), o;
|
|
3377
|
-
}
|
|
3378
|
-
}
|
|
3379
|
-
/**
|
|
3380
|
-
* Stream text generation
|
|
3381
|
-
*/
|
|
3382
|
-
async *streamText(t, n) {
|
|
3383
|
-
if (!this.rateLimiter.checkLimit()) {
|
|
3384
|
-
const o = new Error("Rate limit exceeded");
|
|
3385
|
-
throw o.code = "RATE_LIMIT_EXCEEDED", o;
|
|
3386
|
-
}
|
|
3387
|
-
const r = this.adapters.get(n.provider);
|
|
3388
|
-
if (!r)
|
|
3389
|
-
throw new Error(`Provider ${n.provider} not supported yet.`);
|
|
3390
|
-
yield* r.streamText(t, n);
|
|
3391
|
-
}
|
|
3392
|
-
/**
|
|
3393
|
-
* Multi-turn chat streaming with optional native tool/function-calling.
|
|
3394
|
-
* Additive alongside streamText — does not touch its prompt-flattened path.
|
|
3395
|
-
*/
|
|
3396
|
-
async *streamChat(t, n, r) {
|
|
3397
|
-
if (!this.rateLimiter.checkLimit()) {
|
|
3398
|
-
const i = new Error("Rate limit exceeded");
|
|
3399
|
-
throw i.code = "RATE_LIMIT_EXCEEDED", i;
|
|
3400
|
-
}
|
|
3401
|
-
const o = this.adapters.get(n.provider);
|
|
3402
|
-
if (!o)
|
|
3403
|
-
throw new Error(`Provider ${n.provider} not supported yet.`);
|
|
3404
|
-
if (!o.streamChat)
|
|
3405
|
-
throw new Error(`Provider ${n.provider} does not implement native chat streaming yet.`);
|
|
3406
|
-
yield* o.streamChat(t, n, r);
|
|
3407
|
-
}
|
|
3408
|
-
/**
|
|
3409
|
-
* Generate structured object (JSON mode)
|
|
3410
|
-
*/
|
|
3411
|
-
async generateObject(t, n, r) {
|
|
3412
|
-
if (!this.rateLimiter.checkLimit()) {
|
|
3413
|
-
const i = new Error("Rate limit exceeded");
|
|
3414
|
-
throw i.code = "RATE_LIMIT_EXCEEDED", i;
|
|
3415
|
-
}
|
|
3416
|
-
const o = this.adapters.get(r.provider);
|
|
3417
|
-
if (!o)
|
|
3418
|
-
throw new Error(`Provider ${r.provider} not supported yet.`);
|
|
3419
|
-
return o.generateObject(t, n, r);
|
|
3420
|
-
}
|
|
3421
|
-
/**
|
|
3422
|
-
* Get remaining requests before rate limit
|
|
3423
|
-
*/
|
|
3424
|
-
getRemainingRequests() {
|
|
3425
|
-
return this.rateLimiter.getRemainingRequests();
|
|
3426
|
-
}
|
|
3427
|
-
/**
|
|
3428
|
-
* List available models for a provider
|
|
3429
|
-
*/
|
|
3430
|
-
async listModels(t, n, r) {
|
|
3431
|
-
const o = this.adapters.get(t);
|
|
3432
|
-
if (!o)
|
|
3433
|
-
throw new Error(`Provider ${t} not supported yet.`);
|
|
3434
|
-
return o.listModels(n, r);
|
|
3435
|
-
}
|
|
3436
|
-
}
|
|
3437
|
-
const rn = L.getInstance();
|
|
3438
|
-
class nn {
|
|
3439
|
-
/**
|
|
3440
|
-
* Resolve configuration with 3-tier priority:
|
|
3441
|
-
* 1. User's localStorage override (highest priority)
|
|
3442
|
-
* 2. App-level .env defaults
|
|
3443
|
-
* 3. System defaults (fallback)
|
|
3444
|
-
*/
|
|
3445
|
-
static resolve(t, n) {
|
|
3446
|
-
const r = (t == null ? void 0 : t.provider) || (n == null ? void 0 : n.provider) || "ollama", o = (t == null ? void 0 : t.model) || (n == null ? void 0 : n.model) || this.getDefaultModel(r), i = (t == null ? void 0 : t.apiKey) || (n == null ? void 0 : n.apiKey), s = (t == null ? void 0 : t.ollamaUrl) || (n == null ? void 0 : n.ollamaUrl) || "/ollama";
|
|
3447
|
-
if (r !== "ollama" && !i)
|
|
3448
|
-
throw new Error(`API key required for provider: ${r}`);
|
|
3449
|
-
return {
|
|
3450
|
-
provider: r,
|
|
3451
|
-
model: o,
|
|
3452
|
-
apiKey: i,
|
|
3453
|
-
baseUrl: r === "ollama" ? s : void 0
|
|
3454
|
-
};
|
|
3455
|
-
}
|
|
3456
|
-
static getDefaultModel(t) {
|
|
3457
|
-
return T[t];
|
|
3458
|
-
}
|
|
3459
|
-
/**
|
|
3460
|
-
* Load user preferences from localStorage (client-side)
|
|
3461
|
-
*/
|
|
3462
|
-
static loadUserConfig() {
|
|
3463
|
-
if (!(typeof window > "u"))
|
|
3464
|
-
return {
|
|
3465
|
-
provider: localStorage.getItem("app_ai_provider"),
|
|
3466
|
-
model: localStorage.getItem("app_ai_model") || void 0,
|
|
3467
|
-
apiKey: localStorage.getItem("app_ai_api_key") || void 0,
|
|
3468
|
-
ollamaUrl: localStorage.getItem("app_ollama_url") || void 0
|
|
3469
|
-
};
|
|
3470
|
-
}
|
|
3471
|
-
/**
|
|
3472
|
-
* A provider key from the environment — on a server only. Never in a browser.
|
|
3473
|
-
*
|
|
3474
|
-
* This used to read VITE_DEFAULT_<PROVIDER>_KEY, and on 2026-09-27 ramme.io's
|
|
3475
|
-
* public JavaScript was found carrying live Anthropic, Google and OpenAI keys:
|
|
3476
|
-
* Vite copies every VITE_ variable a browser build refers to into the bundle,
|
|
3477
|
-
* and this read them through import.meta.env as a whole object, which inlines
|
|
3478
|
-
* all of them. A key in the browser is a key anyone can copy. So in a browser
|
|
3479
|
-
* this answers "no key", always; a browser that needs its own key gets it from
|
|
3480
|
-
* the person, in Settings, and a product that wants a shared key keeps it on
|
|
3481
|
-
* its server and proxies (ramme-marketing: lib/aiQuota.ts serverKeyFor).
|
|
3482
|
-
*
|
|
3483
|
-
* On a server it reads the unprefixed names — GEMINI_API_KEY and the rest —
|
|
3484
|
-
* the same names ramme-marketing's routes use, and never a VITE_ or
|
|
3485
|
-
* NEXT_PUBLIC_ one, both of which are browser-visible by design.
|
|
3486
|
-
*/
|
|
3487
|
-
static getEnvKeyForProvider(t) {
|
|
3488
|
-
var r;
|
|
3489
|
-
return typeof window < "u" || typeof process > "u" || !process.env ? void 0 : ((r = {
|
|
3490
|
-
"google-gemini": process.env.GEMINI_API_KEY,
|
|
3491
|
-
openai: process.env.OPENAI_API_KEY,
|
|
3492
|
-
anthropic: process.env.ANTHROPIC_API_KEY,
|
|
3493
|
-
grok: process.env.GROK_API_KEY,
|
|
3494
|
-
deepseek: process.env.DEEPSEEK_API_KEY
|
|
3495
|
-
}[t]) == null ? void 0 : r.trim()) || void 0;
|
|
3496
|
-
}
|
|
3497
|
-
/** Whether a server-side key exists for this provider. Always false in a browser. */
|
|
3498
|
-
static hasEnvKey(t) {
|
|
3499
|
-
return !!this.getEnvKeyForProvider(t);
|
|
3500
|
-
}
|
|
3501
|
-
/**
|
|
3502
|
-
* App defaults that are safe to publish: which provider and model to start
|
|
3503
|
-
* on, and where Ollama is. Never a key — see getEnvKeyForProvider.
|
|
3504
|
-
*
|
|
3505
|
-
* Each value is read as a single named property (import.meta.env.VITE_…),
|
|
3506
|
-
* never through import.meta.env as a whole object: Vite replaces a named
|
|
3507
|
-
* property with that one value, but replaces the whole object with every
|
|
3508
|
-
* VITE_ variable the build can see — which is how keys nobody read by name
|
|
3509
|
-
* still ended up in the bundle.
|
|
3510
|
-
*/
|
|
3511
|
-
static loadAppDefaults() {
|
|
3512
|
-
const t = (i) => {
|
|
3513
|
-
var s;
|
|
3514
|
-
try {
|
|
3515
|
-
return ((s = i()) == null ? void 0 : s.trim()) || void 0;
|
|
3516
|
-
} catch {
|
|
3517
|
-
return;
|
|
3518
|
-
}
|
|
3519
|
-
}, n = t(() => {
|
|
3520
|
-
}), r = t(() => {
|
|
3521
|
-
}), o = t(() => {
|
|
3522
|
-
});
|
|
3523
|
-
return n || r || o ? { provider: n || "ollama", model: r, ollamaUrl: o } : typeof process < "u" && process.env ? {
|
|
3524
|
-
provider: process.env.NEXT_PUBLIC_DEFAULT_AI_PROVIDER,
|
|
3525
|
-
model: process.env.NEXT_PUBLIC_DEFAULT_AI_MODEL
|
|
3526
|
-
} : {};
|
|
3527
|
-
}
|
|
3528
|
-
}
|
|
3529
|
-
const Rr = ([a, t, n]) => a >> 3 << 11 | t >> 2 << 5 | n >> 3, Ir = (a) => {
|
|
3530
|
-
const t = a >> 11 & 31, n = a >> 5 & 63, r = a & 31;
|
|
3531
|
-
return [t << 3 | t >> 2, n << 2 | n >> 4, r << 3 | r >> 2];
|
|
3532
|
-
}, de = (a) => Math.ceil(a / 2), je = (a, t, n) => j.headerBytes + n * 2 + de(a) * t, an = (a) => {
|
|
3533
|
-
const { width: t, height: n, palette: r, indices: o } = a;
|
|
3534
|
-
if (!Number.isInteger(t) || !Number.isInteger(n) || t < 1 || n < 1 || t > 65535 || n > 65535)
|
|
3535
|
-
throw new RangeError(`encodeSpr: bad size ${t}x${n}`);
|
|
3536
|
-
if (r.length < 1 || r.length > j.maxColors)
|
|
3537
|
-
throw new RangeError(`encodeSpr: ${r.length} colours; 1 to ${j.maxColors} allowed`);
|
|
3538
|
-
if (o.length !== t * n)
|
|
3539
|
-
throw new RangeError(`encodeSpr: ${o.length} indices for ${t}x${n}`);
|
|
3540
|
-
const i = new Uint8Array(je(t, n, r.length)), s = new DataView(i.buffer);
|
|
3541
|
-
i.set(j.magic, 0), i[4] = j.version, s.setUint16(5, t, !0), s.setUint16(7, n, !0), i[9] = j.bitsPerPixel, i[10] = r.length;
|
|
3542
|
-
let c = j.headerBytes;
|
|
3543
|
-
for (const u of r)
|
|
3544
|
-
s.setUint16(c, Rr(u), !0), c += 2;
|
|
3545
|
-
const l = de(t);
|
|
3546
|
-
for (let u = 0; u < n; u++)
|
|
3547
|
-
for (let d = 0; d < t; d++) {
|
|
3548
|
-
const m = o[u * t + d];
|
|
3549
|
-
if (!Number.isInteger(m) || m < 0 || m >= r.length)
|
|
3550
|
-
throw new RangeError(`encodeSpr: index ${m} at ${d},${u} is outside a ${r.length}-colour palette`);
|
|
3551
|
-
const p = c + u * l + (d >> 1);
|
|
3552
|
-
i[p] |= d & 1 ? m : m << 4;
|
|
3553
|
-
}
|
|
3554
|
-
return i;
|
|
3555
|
-
}, on = (a) => {
|
|
3556
|
-
const t = (p) => ({ ok: !1, reason: p });
|
|
3557
|
-
if (a.length < j.headerBytes) return t("shorter than the header");
|
|
3558
|
-
if (a.length > me) return t(`${a.length} bytes; at most ${me}`);
|
|
3559
|
-
if (!j.magic.every((p, h) => a[h] === p)) return t("not an .spr file");
|
|
3560
|
-
if (a[4] !== j.version) return t(`version ${a[4]}; this reads ${j.version}`);
|
|
3561
|
-
const n = new DataView(a.buffer, a.byteOffset, a.byteLength), r = n.getUint16(5, !0), o = n.getUint16(7, !0), i = a[9], s = a[10];
|
|
3562
|
-
if (r < 1 || o < 1) return t(`empty image ${r}x${o}`);
|
|
3563
|
-
if (i !== j.bitsPerPixel) return t(`${i} bits a pixel; only ${j.bitsPerPixel} is read`);
|
|
3564
|
-
if (s < 1 || s > j.maxColors) return t(`${s} colours; 1 to ${j.maxColors} allowed`);
|
|
3565
|
-
const c = je(r, o, s);
|
|
3566
|
-
if (a.length !== c) return t(`${a.length} bytes; ${r}x${o} with ${s} colours is ${c}`);
|
|
3567
|
-
const l = [];
|
|
3568
|
-
let u = j.headerBytes;
|
|
3569
|
-
for (let p = 0; p < s; p++, u += 2) l.push(Ir(n.getUint16(u, !0)));
|
|
3570
|
-
const d = de(r), m = new Uint8Array(r * o);
|
|
3571
|
-
for (let p = 0; p < o; p++)
|
|
3572
|
-
for (let h = 0; h < r; h++) {
|
|
3573
|
-
const g = a[u + p * d + (h >> 1)], w = h & 1 ? g & 15 : g >> 4;
|
|
3574
|
-
m[p * r + h] = w < s ? w : 0;
|
|
3575
|
-
}
|
|
3576
|
-
return { ok: !0, image: { width: r, height: o, palette: l, indices: m } };
|
|
3577
|
-
}, Nr = (a) => {
|
|
3578
|
-
let t = "";
|
|
3579
|
-
for (const n of a) t += String.fromCharCode(n);
|
|
3580
|
-
return btoa(t);
|
|
3581
|
-
}, $r = (a) => Uint8Array.from(atob(a), (t) => t.charCodeAt(0)), Cr = (a) => {
|
|
3582
|
-
if (a === "." || a === " " || a === "_") return 0;
|
|
3583
|
-
const t = parseInt(a, 16);
|
|
3584
|
-
return Number.isNaN(t) ? -1 : t;
|
|
3585
|
-
}, Dr = (a, t) => {
|
|
3586
|
-
if (t.length === 0) return { ok: !1, error: "palette is empty" };
|
|
3587
|
-
if (t.length > 16)
|
|
3588
|
-
return { ok: !1, error: `palette has ${t.length} colours and a sprite holds at most 16` };
|
|
3589
|
-
const n = a.split(`
|
|
3590
|
-
`).map((l) => l.trim()).filter((l) => l.length > 0);
|
|
3591
|
-
if (n.length === 0) return { ok: !1, error: "grid has no rows" };
|
|
3592
|
-
const r = n.length, o = n[0].length;
|
|
3593
|
-
if (o > M || r > M)
|
|
3594
|
-
return {
|
|
3595
|
-
ok: !1,
|
|
3596
|
-
error: `grid is ${o}x${r} and the largest sprite is ${M}x${M}`
|
|
3597
|
-
};
|
|
3598
|
-
const i = n.map((l, u) => ({ i: u, len: l.length })).filter((l) => l.len !== o);
|
|
3599
|
-
if (i.length > 0) {
|
|
3600
|
-
const l = i[0];
|
|
3601
|
-
return {
|
|
3602
|
-
ok: !1,
|
|
3603
|
-
error: `row ${l.i + 1} is ${l.len} characters and row 1 is ${o}. Every row must be the same width (${i.length} row(s) differ).`
|
|
3604
|
-
};
|
|
3605
|
-
}
|
|
3606
|
-
const s = Math.ceil(o / 2), c = new Uint8Array(s * r);
|
|
3607
|
-
for (let l = 0; l < r; l++)
|
|
3608
|
-
for (let u = 0; u < o; u++) {
|
|
3609
|
-
const d = Cr(n[l][u]);
|
|
3610
|
-
if (d < 0)
|
|
3611
|
-
return {
|
|
3612
|
-
ok: !1,
|
|
3613
|
-
error: `row ${l + 1}, column ${u + 1}: '${n[l][u]}' is not a hex digit 0-f`
|
|
3614
|
-
};
|
|
3615
|
-
if (d >= t.length)
|
|
3616
|
-
return {
|
|
3617
|
-
ok: !1,
|
|
3618
|
-
error: `row ${l + 1}, column ${u + 1}: index ${d.toString(16)} but the palette has ${t.length} colour(s), so the highest is ${(t.length - 1).toString(16)}`
|
|
3619
|
-
};
|
|
3620
|
-
const m = l * s + (u >> 1);
|
|
3621
|
-
c[m] |= u & 1 ? d : d << 4;
|
|
3622
|
-
}
|
|
3623
|
-
return { ok: !0, sprite: { width: o, height: r, palette: t, pixels: Nr(c) } };
|
|
3624
|
-
}, sn = (a) => {
|
|
3625
|
-
const t = $r(a.pixels), n = Math.ceil(a.width / 2), r = [];
|
|
3626
|
-
for (let o = 0; o < a.height; o++) {
|
|
3627
|
-
let i = "";
|
|
3628
|
-
for (let s = 0; s < a.width; s++) {
|
|
3629
|
-
const c = t[o * n + (s >> 1)] ?? 0;
|
|
3630
|
-
i += ((s & 1 ? c & 15 : c >> 4) & 15).toString(16);
|
|
3631
|
-
}
|
|
3632
|
-
r.push(i);
|
|
3633
|
-
}
|
|
3634
|
-
return r.join(`
|
|
3635
|
-
`);
|
|
3636
|
-
}, cn = (a) => {
|
|
3637
|
-
const t = [];
|
|
3638
|
-
if (!a || typeof a != "object") return { value: a, issues: t };
|
|
3639
|
-
const n = a.blocks;
|
|
3640
|
-
if (!Array.isArray(n)) return { value: a, issues: t };
|
|
3641
|
-
const r = (o, i) => {
|
|
3642
|
-
if (!o || typeof o != "object") return o;
|
|
3643
|
-
const s = o;
|
|
3644
|
-
if (Array.isArray(s.children))
|
|
3645
|
-
return { ...s, children: s.children.map((m, p) => r(m, [...i, "children", p])) };
|
|
3646
|
-
if (s.type !== "sprite" || typeof s.grid != "string") return o;
|
|
3647
|
-
const c = Array.isArray(s.palette) ? s.palette : [], l = Dr(s.grid, c);
|
|
3648
|
-
if (!l.ok)
|
|
3649
|
-
return t.push({ path: [...i, "grid"], message: l.error }), o;
|
|
3650
|
-
const { grid: u, ...d } = s;
|
|
3651
|
-
return { ...d, ...l.sprite };
|
|
3652
|
-
};
|
|
3653
|
-
return {
|
|
3654
|
-
value: { ...a, blocks: n.map((o, i) => r(o, ["blocks", i])) },
|
|
3655
|
-
issues: t
|
|
3656
|
-
};
|
|
3657
|
-
};
|
|
3658
|
-
class Mr {
|
|
3659
|
-
constructor(t) {
|
|
3660
|
-
this.requests = [], this.config = t;
|
|
3661
|
-
}
|
|
3662
|
-
checkLimit() {
|
|
3663
|
-
const t = Date.now(), n = t - this.config.windowMs;
|
|
3664
|
-
return this.requests = this.requests.filter((r) => r > n), this.requests.length >= this.config.maxRequests ? !1 : (this.requests.push(t), !0);
|
|
3665
|
-
}
|
|
3666
|
-
getRemainingRequests() {
|
|
3667
|
-
const n = Date.now() - this.config.windowMs;
|
|
3668
|
-
return this.requests = this.requests.filter((r) => r > n), Math.max(0, this.config.maxRequests - this.requests.length);
|
|
3669
|
-
}
|
|
3670
|
-
getResetTime() {
|
|
3671
|
-
return this.requests.length === 0 ? 0 : this.requests[0] + this.config.windowMs;
|
|
3672
|
-
}
|
|
3673
|
-
}
|
|
3674
|
-
class Br {
|
|
3675
|
-
constructor(t = { maxRequests: 10, windowMs: 6e4 }) {
|
|
3676
|
-
this.rateLimiter = new Mr(t);
|
|
3677
|
-
}
|
|
3678
|
-
async makeRequest(t, n) {
|
|
3679
|
-
if (!this.rateLimiter.checkLimit()) {
|
|
3680
|
-
const r = this.rateLimiter.getResetTime(), o = new Error("Rate limit exceeded. Please wait before making another request.");
|
|
3681
|
-
throw o.code = "RATE_LIMIT_EXCEEDED", o.resetTime = r, n && n(r), o;
|
|
3682
|
-
}
|
|
3683
|
-
return await t();
|
|
3684
|
-
}
|
|
3685
|
-
getRemainingRequests() {
|
|
3686
|
-
return this.rateLimiter.getRemainingRequests();
|
|
3687
|
-
}
|
|
3688
|
-
}
|
|
3689
|
-
const ln = new Br({ maxRequests: 10, windowMs: 6e4 });
|
|
3690
|
-
export {
|
|
3691
|
-
nn as A,
|
|
3692
|
-
Re as B,
|
|
3693
|
-
De as C,
|
|
3694
|
-
Yr as D,
|
|
3695
|
-
$e as E,
|
|
3696
|
-
Zr as F,
|
|
3697
|
-
kr as G,
|
|
3698
|
-
Be as H,
|
|
3699
|
-
Pr as I,
|
|
3700
|
-
Le as J,
|
|
3701
|
-
qe as K,
|
|
3702
|
-
Ur as L,
|
|
3703
|
-
Vr as M,
|
|
3704
|
-
Q as N,
|
|
3705
|
-
Sr as O,
|
|
3706
|
-
ce as P,
|
|
3707
|
-
Wr as Q,
|
|
3708
|
-
Ie as R,
|
|
3709
|
-
ze as S,
|
|
3710
|
-
Ce as T,
|
|
3711
|
-
Hr as U,
|
|
3712
|
-
zr as V,
|
|
3713
|
-
Me as W,
|
|
3714
|
-
At as a,
|
|
3715
|
-
rn as b,
|
|
3716
|
-
Gr as c,
|
|
3717
|
-
Jr as d,
|
|
3718
|
-
Fr as e,
|
|
3719
|
-
on as f,
|
|
3720
|
-
Xr as g,
|
|
3721
|
-
L as h,
|
|
3722
|
-
Kr as i,
|
|
3723
|
-
Br as j,
|
|
3724
|
-
ln as k,
|
|
3725
|
-
qr as l,
|
|
3726
|
-
Dr as m,
|
|
3727
|
-
cn as n,
|
|
3728
|
-
Rr as o,
|
|
3729
|
-
Ir as p,
|
|
3730
|
-
je as q,
|
|
3731
|
-
an as r,
|
|
3732
|
-
sn as s,
|
|
3733
|
-
en as t,
|
|
3734
|
-
Qr as u,
|
|
3735
|
-
_r as v,
|
|
3736
|
-
Tr as w,
|
|
3737
|
-
jr as x,
|
|
3738
|
-
Or as y,
|
|
3739
|
-
Ar as z
|
|
3740
|
-
};
|