@ramme-io/kernel 5.0.0 → 6.0.0
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/README.md +87 -53
- package/dist/{AiGateway-DflFS1JW.js → AiGateway-DLGiTtyR.js} +1136 -931
- package/dist/index.es.js +6854 -6532
- package/dist/kernel/src/components/RammeInspector.d.ts +7 -1
- package/dist/kernel/src/components/RammeInspector.d.ts.map +1 -1
- package/dist/kernel/src/components/ThemeStudio.d.ts +116 -0
- package/dist/kernel/src/components/ThemeStudio.d.ts.map +1 -0
- package/dist/kernel/src/events/mockEventSource.d.ts +28 -0
- package/dist/kernel/src/events/mockEventSource.d.ts.map +1 -0
- package/dist/kernel/src/index.d.ts +2 -0
- package/dist/kernel/src/index.d.ts.map +1 -1
- package/dist/kernel/src/stores/useSettingsStore.d.ts +6 -0
- package/dist/kernel/src/stores/useSettingsStore.d.ts.map +1 -1
- package/dist/server.es.js +6 -6
- package/package.json +13 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z as
|
|
2
|
-
const
|
|
1
|
+
import { z as n } from "zod";
|
|
2
|
+
const Jt = {
|
|
3
3
|
// ── ROOM 1: STRATEGY OFFICE ──────────────────────────────────────
|
|
4
4
|
strategist: {
|
|
5
5
|
id: "strategist",
|
|
@@ -114,63 +114,63 @@ Provide a structured audit report with:
|
|
|
114
114
|
`.trim()
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
|
-
var
|
|
117
|
+
var ie = Object.defineProperty, se = (a, e) => {
|
|
118
118
|
for (var r in e)
|
|
119
|
-
|
|
120
|
-
},
|
|
121
|
-
key:
|
|
122
|
-
label:
|
|
123
|
-
type:
|
|
124
|
-
required:
|
|
125
|
-
description:
|
|
126
|
-
defaultValue:
|
|
127
|
-
}),
|
|
128
|
-
id:
|
|
129
|
-
name:
|
|
130
|
-
fields:
|
|
131
|
-
defaultView:
|
|
132
|
-
features:
|
|
133
|
-
searchable:
|
|
134
|
-
creatable:
|
|
135
|
-
editable:
|
|
136
|
-
deletable:
|
|
137
|
-
exportable:
|
|
119
|
+
ie(a, r, { get: e[r], enumerable: !0 });
|
|
120
|
+
}, ce = n.object({
|
|
121
|
+
key: n.string(),
|
|
122
|
+
label: n.string(),
|
|
123
|
+
type: n.enum(["text", "number", "currency", "percent", "delta", "date", "boolean", "status", "email", "image", "textarea"]),
|
|
124
|
+
required: n.boolean().optional(),
|
|
125
|
+
description: n.string().optional(),
|
|
126
|
+
defaultValue: n.any().optional()
|
|
127
|
+
}), le = n.object({
|
|
128
|
+
id: n.string(),
|
|
129
|
+
name: n.string(),
|
|
130
|
+
fields: n.array(ce),
|
|
131
|
+
defaultView: n.enum(["table", "grid", "list"]).optional(),
|
|
132
|
+
features: n.object({
|
|
133
|
+
searchable: n.boolean().optional(),
|
|
134
|
+
creatable: n.boolean().optional(),
|
|
135
|
+
editable: n.boolean().optional(),
|
|
136
|
+
deletable: n.boolean().optional(),
|
|
137
|
+
exportable: n.boolean().optional()
|
|
138
138
|
}).optional()
|
|
139
|
-
}),
|
|
140
|
-
id:
|
|
141
|
-
label:
|
|
142
|
-
description:
|
|
143
|
-
kind:
|
|
144
|
-
source:
|
|
139
|
+
}), ue = n.object({
|
|
140
|
+
id: n.string().min(1, "Signal ID is required"),
|
|
141
|
+
label: n.string(),
|
|
142
|
+
description: n.string().optional(),
|
|
143
|
+
kind: n.enum(["sensor", "actuator", "setpoint", "metric", "status", "kpi"]),
|
|
144
|
+
source: n.enum(["mock", "mqtt", "http", "derived", "local"]),
|
|
145
145
|
// Connectivity
|
|
146
|
-
topic:
|
|
147
|
-
endpoint:
|
|
148
|
-
jsonPath:
|
|
149
|
-
refreshRate:
|
|
146
|
+
topic: n.string().optional(),
|
|
147
|
+
endpoint: n.string().optional(),
|
|
148
|
+
jsonPath: n.string().optional(),
|
|
149
|
+
refreshRate: n.number().optional().default(1e3),
|
|
150
150
|
// Values
|
|
151
|
-
defaultValue:
|
|
152
|
-
unit:
|
|
153
|
-
min:
|
|
154
|
-
max:
|
|
155
|
-
}),
|
|
156
|
-
id:
|
|
157
|
-
name:
|
|
158
|
-
description:
|
|
159
|
-
type:
|
|
160
|
-
category:
|
|
161
|
-
signals:
|
|
162
|
-
ui:
|
|
163
|
-
icon:
|
|
164
|
-
color:
|
|
165
|
-
dashboardComponent:
|
|
151
|
+
defaultValue: n.any().optional(),
|
|
152
|
+
unit: n.string().optional(),
|
|
153
|
+
min: n.number().optional(),
|
|
154
|
+
max: n.number().optional()
|
|
155
|
+
}), me = n.object({
|
|
156
|
+
id: n.string(),
|
|
157
|
+
name: n.string(),
|
|
158
|
+
description: n.string().optional(),
|
|
159
|
+
type: n.string(),
|
|
160
|
+
category: n.string().default("logical"),
|
|
161
|
+
signals: n.array(n.string()),
|
|
162
|
+
ui: n.object({
|
|
163
|
+
icon: n.string().optional(),
|
|
164
|
+
color: n.string().optional(),
|
|
165
|
+
dashboardComponent: n.string().optional()
|
|
166
166
|
}).optional()
|
|
167
|
-
}),
|
|
168
|
-
id:
|
|
169
|
-
type:
|
|
170
|
-
config:
|
|
171
|
-
}),
|
|
172
|
-
id:
|
|
173
|
-
type:
|
|
167
|
+
}), de = n.object({
|
|
168
|
+
id: n.string(),
|
|
169
|
+
type: n.enum(["signal_change", "manual_action", "schedule", "webhook"]),
|
|
170
|
+
config: n.record(n.string(), n.any())
|
|
171
|
+
}), pe = n.object({
|
|
172
|
+
id: n.string(),
|
|
173
|
+
type: n.enum([
|
|
174
174
|
"update_resource",
|
|
175
175
|
"send_notification",
|
|
176
176
|
"mqtt_publish",
|
|
@@ -178,92 +178,92 @@ var te = Object.defineProperty, re = (n, e) => {
|
|
|
178
178
|
"navigate",
|
|
179
179
|
"agent_task"
|
|
180
180
|
]),
|
|
181
|
-
config:
|
|
182
|
-
}),
|
|
183
|
-
id:
|
|
184
|
-
name:
|
|
185
|
-
active:
|
|
186
|
-
trigger:
|
|
187
|
-
actions:
|
|
188
|
-
}),
|
|
189
|
-
id:
|
|
190
|
-
type:
|
|
191
|
-
props:
|
|
192
|
-
layout:
|
|
193
|
-
colSpan:
|
|
194
|
-
rowSpan:
|
|
181
|
+
config: n.record(n.string(), n.any())
|
|
182
|
+
}), ge = n.object({
|
|
183
|
+
id: n.string(),
|
|
184
|
+
name: n.string(),
|
|
185
|
+
active: n.boolean().default(!0),
|
|
186
|
+
trigger: de,
|
|
187
|
+
actions: n.array(pe)
|
|
188
|
+
}), he = n.object({
|
|
189
|
+
id: n.string(),
|
|
190
|
+
type: n.string(),
|
|
191
|
+
props: n.record(n.string(), n.any()),
|
|
192
|
+
layout: n.object({
|
|
193
|
+
colSpan: n.number().optional(),
|
|
194
|
+
rowSpan: n.number().optional()
|
|
195
195
|
}).optional()
|
|
196
|
-
}),
|
|
197
|
-
id:
|
|
198
|
-
title:
|
|
199
|
-
description:
|
|
200
|
-
layout:
|
|
201
|
-
columns:
|
|
202
|
-
variant:
|
|
196
|
+
}), fe = n.object({
|
|
197
|
+
id: n.string(),
|
|
198
|
+
title: n.string().optional(),
|
|
199
|
+
description: n.string().optional(),
|
|
200
|
+
layout: n.object({
|
|
201
|
+
columns: n.number().optional(),
|
|
202
|
+
variant: n.enum(["grid", "stack", "split"]).optional()
|
|
203
203
|
}).optional(),
|
|
204
|
-
blocks:
|
|
205
|
-
}),
|
|
206
|
-
id:
|
|
207
|
-
slug:
|
|
208
|
-
title:
|
|
209
|
-
description:
|
|
210
|
-
icon:
|
|
211
|
-
sections:
|
|
212
|
-
}),
|
|
213
|
-
strategy:
|
|
214
|
-
status:
|
|
215
|
-
}),
|
|
216
|
-
meta:
|
|
217
|
-
name:
|
|
218
|
-
version:
|
|
219
|
-
description:
|
|
220
|
-
author:
|
|
221
|
-
createdAt:
|
|
204
|
+
blocks: n.array(he)
|
|
205
|
+
}), ye = n.object({
|
|
206
|
+
id: n.string(),
|
|
207
|
+
slug: n.string(),
|
|
208
|
+
title: n.string(),
|
|
209
|
+
description: n.string().optional(),
|
|
210
|
+
icon: n.string().optional(),
|
|
211
|
+
sections: n.array(fe)
|
|
212
|
+
}), be = n.enum(["ENVIRONMENT", "SESSION_BYOK", "VAULT"]), we = n.object({
|
|
213
|
+
strategy: be,
|
|
214
|
+
status: n.enum(["VALID", "KEY_EXPIRED", "BYOK_REQUIRED", "DEGRADED", "UNKNOWN"]).default("UNKNOWN")
|
|
215
|
+
}), Kt = n.object({
|
|
216
|
+
meta: n.object({
|
|
217
|
+
name: n.string(),
|
|
218
|
+
version: n.string(),
|
|
219
|
+
description: n.string().optional(),
|
|
220
|
+
author: n.string().optional(),
|
|
221
|
+
createdAt: n.string().optional()
|
|
222
222
|
}),
|
|
223
|
-
config:
|
|
224
|
-
theme:
|
|
225
|
-
layout:
|
|
226
|
-
mockMode:
|
|
227
|
-
brokerUrl:
|
|
228
|
-
aiKeyManifest:
|
|
223
|
+
config: n.object({
|
|
224
|
+
theme: n.enum(["light", "dark", "system", "corporate", "midnight", "blueprint"]).default("system"),
|
|
225
|
+
layout: n.enum(["dashboard", "explorer", "studio", "focus"]).default("dashboard"),
|
|
226
|
+
mockMode: n.boolean().default(!0),
|
|
227
|
+
brokerUrl: n.string().optional(),
|
|
228
|
+
aiKeyManifest: we.optional()
|
|
229
229
|
}),
|
|
230
|
-
modules:
|
|
231
|
-
resources:
|
|
232
|
-
domain:
|
|
233
|
-
signals:
|
|
234
|
-
entities:
|
|
235
|
-
workflows:
|
|
230
|
+
modules: n.array(n.string()).optional(),
|
|
231
|
+
resources: n.array(le).optional(),
|
|
232
|
+
domain: n.object({
|
|
233
|
+
signals: n.array(ue),
|
|
234
|
+
entities: n.array(me),
|
|
235
|
+
workflows: n.array(ge).optional()
|
|
236
236
|
}),
|
|
237
|
-
pages:
|
|
238
|
-
}),
|
|
239
|
-
timestamp:
|
|
240
|
-
soilMoisture:
|
|
241
|
-
ambientLight:
|
|
242
|
-
temperature:
|
|
243
|
-
}),
|
|
244
|
-
id:
|
|
245
|
-
source:
|
|
246
|
-
domain:
|
|
247
|
-
key:
|
|
248
|
-
value:
|
|
249
|
-
unit:
|
|
250
|
-
timestamp:
|
|
251
|
-
meta:
|
|
237
|
+
pages: n.array(ye).optional()
|
|
238
|
+
}), Ft = n.object({
|
|
239
|
+
timestamp: n.number(),
|
|
240
|
+
soilMoisture: n.number().min(0).max(100),
|
|
241
|
+
ambientLight: n.number().min(0).max(1e5),
|
|
242
|
+
temperature: n.number().min(-40).max(125)
|
|
243
|
+
}), Ee = n.object({
|
|
244
|
+
id: n.string(),
|
|
245
|
+
source: n.enum(["mqtt", "http", "ws", "mock"]),
|
|
246
|
+
domain: n.string(),
|
|
247
|
+
key: n.string(),
|
|
248
|
+
value: n.union([n.number(), n.string(), n.boolean()]),
|
|
249
|
+
unit: n.string().optional(),
|
|
250
|
+
timestamp: n.number(),
|
|
251
|
+
meta: n.record(n.unknown()).optional()
|
|
252
252
|
});
|
|
253
|
-
|
|
254
|
-
var
|
|
255
|
-
|
|
253
|
+
n.array(Ee);
|
|
254
|
+
var Ae = n.enum(["telemetry", "market", "system", "logic"]), ke = n.enum(["mqtt", "http", "ws", "mock"]);
|
|
255
|
+
n.object({
|
|
256
256
|
/**
|
|
257
257
|
* Globally unique signal identifier.
|
|
258
258
|
* Convention: '<device-or-entity-id>:<key>'
|
|
259
259
|
* Examples: 'sensor-01:soil_vwc', 'AAPL:price', 'server-01:cpu_pct'
|
|
260
260
|
*/
|
|
261
|
-
id:
|
|
261
|
+
id: n.string(),
|
|
262
262
|
/**
|
|
263
263
|
* The semantic category of this signal.
|
|
264
264
|
* Determines which Methodology Engine processes it.
|
|
265
265
|
*/
|
|
266
|
-
kind:
|
|
266
|
+
kind: Ae,
|
|
267
267
|
/**
|
|
268
268
|
* The specific measurement or metric key within its kind.
|
|
269
269
|
* RULE: Keys MUST be abstract and domain-agnostic where possible.
|
|
@@ -271,108 +271,210 @@ o.object({
|
|
|
271
271
|
* Hardware-specific keys (soil_vwc) MUST be mapped to abstract keys
|
|
272
272
|
* at the adapter layer BEFORE the SignalPacket is created.
|
|
273
273
|
*/
|
|
274
|
-
key:
|
|
274
|
+
key: n.string(),
|
|
275
275
|
/**
|
|
276
276
|
* The scalar value. Accepts number, string, or boolean.
|
|
277
277
|
* Structured data MUST be flattened into multiple SignalPackets,
|
|
278
278
|
* one per measurable dimension.
|
|
279
279
|
*/
|
|
280
|
-
value:
|
|
280
|
+
value: n.union([n.number(), n.string(), n.boolean()]),
|
|
281
281
|
/**
|
|
282
282
|
* Optional unit of measurement.
|
|
283
283
|
* Examples: 'VWC%', 'USD', 'bpm', 'ms', '°C', 'pct'
|
|
284
284
|
*/
|
|
285
|
-
unit:
|
|
285
|
+
unit: n.string().optional(),
|
|
286
286
|
/**
|
|
287
287
|
* Unix timestamp in milliseconds (Date.now() format).
|
|
288
288
|
* MUST represent when the measurement was taken, not when it was received.
|
|
289
289
|
*/
|
|
290
|
-
ts:
|
|
290
|
+
ts: n.number(),
|
|
291
291
|
/**
|
|
292
292
|
* The transport source that produced this signal.
|
|
293
293
|
*/
|
|
294
|
-
source:
|
|
294
|
+
source: ke.optional(),
|
|
295
295
|
/**
|
|
296
296
|
* Optional domain namespace for grouping related signals.
|
|
297
297
|
* Examples: 'bodewell', 'finance', 'infrastructure', 'user_behavior'
|
|
298
298
|
*/
|
|
299
|
-
domain:
|
|
299
|
+
domain: n.string().optional(),
|
|
300
300
|
/**
|
|
301
301
|
* Optional pass-through for source-specific metadata that does NOT
|
|
302
302
|
* belong in the core contract (e.g. device firmware version, exchange name).
|
|
303
303
|
* RULE: If you find yourself reading from meta in UI components, that
|
|
304
304
|
* field should be promoted to the core schema or handled in the adapter.
|
|
305
305
|
*/
|
|
306
|
-
meta:
|
|
306
|
+
meta: n.record(n.unknown()).optional()
|
|
307
307
|
});
|
|
308
|
-
var
|
|
309
|
-
|
|
310
|
-
BodewellCommandSchema: () =>
|
|
311
|
-
BodewellDeviceID: () =>
|
|
312
|
-
BodewellTelemetrySchema: () =>
|
|
308
|
+
var ve = {};
|
|
309
|
+
se(ve, {
|
|
310
|
+
BodewellCommandSchema: () => _e,
|
|
311
|
+
BodewellDeviceID: () => K,
|
|
312
|
+
BodewellTelemetrySchema: () => Se
|
|
313
313
|
});
|
|
314
|
-
var
|
|
314
|
+
var K = n.enum([
|
|
315
315
|
"STK-V1-001",
|
|
316
316
|
"STK-V1-002",
|
|
317
317
|
"STK-V1-003",
|
|
318
318
|
"STK-PRO-001",
|
|
319
319
|
"STK-VIS-001"
|
|
320
|
-
]),
|
|
321
|
-
device_id:
|
|
322
|
-
stick_id:
|
|
323
|
-
timestamp:
|
|
324
|
-
air_temp:
|
|
325
|
-
air_humid:
|
|
326
|
-
humidity:
|
|
327
|
-
air_pressure:
|
|
328
|
-
pressure:
|
|
329
|
-
light_lux:
|
|
330
|
-
soil_temp_stemma:
|
|
331
|
-
soil_vwc:
|
|
332
|
-
soil_moisture:
|
|
333
|
-
soil_moisture_raw:
|
|
334
|
-
}).passthrough(),
|
|
335
|
-
stick_id:
|
|
320
|
+
]), Se = n.object({
|
|
321
|
+
device_id: K,
|
|
322
|
+
stick_id: n.string().optional().describe("Firmware alias for device_id"),
|
|
323
|
+
timestamp: n.number().optional().describe("Epoch timestamp from NTP"),
|
|
324
|
+
air_temp: n.number().optional().describe("Celsius"),
|
|
325
|
+
air_humid: n.number().optional().describe("Relative Humidity %"),
|
|
326
|
+
humidity: n.number().optional().describe("Firmware alias for air_humid"),
|
|
327
|
+
air_pressure: n.number().optional().describe("hPa"),
|
|
328
|
+
pressure: n.number().optional().describe("Firmware alias for air_pressure"),
|
|
329
|
+
light_lux: n.number().optional().describe("Lux level"),
|
|
330
|
+
soil_temp_stemma: n.number().optional().describe("Celsius"),
|
|
331
|
+
soil_vwc: n.number().describe("Volumetric Water Content / Raw Capacitance"),
|
|
332
|
+
soil_moisture: n.number().optional().describe("Firmware alias for raw capacitance"),
|
|
333
|
+
soil_moisture_raw: n.number().optional().describe("Unscaled capacitance (300-1100)")
|
|
334
|
+
}).passthrough(), _e = n.object({
|
|
335
|
+
stick_id: K,
|
|
336
336
|
// Note: Your API uses stick_id here, not device_id
|
|
337
|
-
type:
|
|
338
|
-
value:
|
|
337
|
+
type: n.enum(["dry", "wet"]),
|
|
338
|
+
value: n.number()
|
|
339
|
+
}), Te = n.enum([
|
|
340
|
+
"esp32-touch-28",
|
|
341
|
+
// 2.8" 240x320 resistive touch, the workshop board
|
|
342
|
+
"esp32-headless",
|
|
343
|
+
// no display; sensor node
|
|
344
|
+
"simulator"
|
|
345
|
+
// browser-side stand-in, for building without hardware
|
|
346
|
+
]), X = n.enum([
|
|
347
|
+
"weather",
|
|
348
|
+
"clock",
|
|
349
|
+
"aircraft",
|
|
350
|
+
"sensor",
|
|
351
|
+
"blank"
|
|
352
|
+
]), Oe = n.object({
|
|
353
|
+
/** Postal code is what a person knows; the portal resolves it to coordinates. */
|
|
354
|
+
postalCode: n.string().min(3).max(12),
|
|
355
|
+
latitude: n.number().min(-90).max(90).optional(),
|
|
356
|
+
longitude: n.number().min(-180).max(180).optional(),
|
|
357
|
+
units: n.enum(["imperial", "metric"]).default("imperial"),
|
|
358
|
+
showForecast: n.boolean().default(!0),
|
|
359
|
+
refreshSeconds: n.number().int().min(300).max(86400).default(900)
|
|
360
|
+
}), xe = n.object({
|
|
361
|
+
/** IANA zone, e.g. "America/New_York". */
|
|
362
|
+
timezone: n.string().default("America/New_York"),
|
|
363
|
+
twentyFourHour: n.boolean().default(!1),
|
|
364
|
+
showSeconds: n.boolean().default(!1),
|
|
365
|
+
showDate: n.boolean().default(!0)
|
|
366
|
+
}), Ie = n.object({
|
|
367
|
+
latitude: n.number().min(-90).max(90),
|
|
368
|
+
longitude: n.number().min(-180).max(180),
|
|
369
|
+
radiusKm: n.number().min(5).max(400).default(80),
|
|
370
|
+
/** Rows the list view can show before the screen runs out. */
|
|
371
|
+
maxRows: n.number().int().min(1).max(12).default(8),
|
|
372
|
+
refreshSeconds: n.number().int().min(10).max(600).default(30)
|
|
373
|
+
}), Pe = n.object({
|
|
374
|
+
/** Signal keys to display, in order. Abstract keys per the Signal contract. */
|
|
375
|
+
keys: n.array(n.string()).min(1).max(6),
|
|
376
|
+
refreshSeconds: n.number().int().min(1).max(3600).default(10)
|
|
377
|
+
}), je = n.object({
|
|
378
|
+
weather: Oe.optional(),
|
|
379
|
+
clock: xe.optional(),
|
|
380
|
+
aircraft: Ie.optional(),
|
|
381
|
+
sensor: Pe.optional()
|
|
382
|
+
}), Re = n.object({
|
|
383
|
+
brightness: n.number().int().min(5).max(100).default(80),
|
|
384
|
+
/** Degrees clockwise. The board can sit either way up in a case. */
|
|
385
|
+
rotation: n.union([n.literal(0), n.literal(90), n.literal(180), n.literal(270)]).default(0),
|
|
386
|
+
/** Dim rather than sleep — a desk display that blanks looks broken. */
|
|
387
|
+
dimAfterSeconds: n.number().int().min(0).max(86400).default(0),
|
|
388
|
+
dimBrightness: n.number().int().min(0).max(100).default(15),
|
|
389
|
+
/** Local 24h times, e.g. "22:30". Empty disables night dimming. */
|
|
390
|
+
nightStart: n.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/).optional(),
|
|
391
|
+
nightEnd: n.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/).optional()
|
|
392
|
+
}), C = n.string().regex(
|
|
393
|
+
/^\d{1,3} \d{1,3} \d{1,3}$/,
|
|
394
|
+
'Expected space-separated RGB integers, e.g. "13 110 253"'
|
|
395
|
+
), Ne = n.object({
|
|
396
|
+
preset: n.enum(["light", "dark", "corporate", "midnight", "blueprint", "custom"]).default("dark"),
|
|
397
|
+
background: C.optional(),
|
|
398
|
+
foreground: C.optional(),
|
|
399
|
+
accent: C.optional(),
|
|
400
|
+
muted: C.optional(),
|
|
401
|
+
warning: C.optional()
|
|
339
402
|
});
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
403
|
+
n.object({
|
|
404
|
+
/** Bumped only on breaking shape changes, so old firmware can refuse safely. */
|
|
405
|
+
schemaVersion: n.literal(1),
|
|
406
|
+
deviceId: n.string().min(1),
|
|
407
|
+
/** Monotonic. Portal increments on write; device echoes what it is running. */
|
|
408
|
+
revision: n.number().int().nonnegative(),
|
|
409
|
+
updatedAt: n.string().datetime().optional(),
|
|
410
|
+
activeApp: X,
|
|
411
|
+
apps: je,
|
|
412
|
+
display: Re,
|
|
413
|
+
theme: Ne
|
|
414
|
+
});
|
|
415
|
+
var De = n.enum([
|
|
416
|
+
"unprovisioned",
|
|
417
|
+
"connecting",
|
|
418
|
+
"online",
|
|
419
|
+
"offline",
|
|
420
|
+
"failed"
|
|
421
|
+
]);
|
|
422
|
+
n.object({
|
|
423
|
+
deviceId: n.string().min(1),
|
|
424
|
+
kind: Te,
|
|
425
|
+
firmwareVersion: n.string(),
|
|
426
|
+
/** Shown on the device's own screen at boot — how the user finds it. */
|
|
427
|
+
ipAddress: n.string().optional(),
|
|
428
|
+
provisioning: De,
|
|
429
|
+
/** Revision the device is actually running, not the one it was sent. */
|
|
430
|
+
configRevision: n.number().int().nonnegative(),
|
|
431
|
+
activeApp: X,
|
|
432
|
+
rssi: n.number().int().optional().describe("dBm"),
|
|
433
|
+
uptimeSeconds: n.number().int().nonnegative().optional(),
|
|
434
|
+
freeHeapBytes: n.number().int().nonnegative().optional()
|
|
435
|
+
});
|
|
436
|
+
n.object({
|
|
437
|
+
deviceId: n.string().min(1, "Device ID is required"),
|
|
438
|
+
timeRange: n.enum(["1h", "24h", "7d"], {
|
|
343
439
|
errorMap: () => ({ message: "Time range must be 1h, 24h, or 7d" })
|
|
344
440
|
}),
|
|
345
|
-
metrics:
|
|
346
|
-
|
|
441
|
+
metrics: n.array(
|
|
442
|
+
n.enum(["temperature", "humidity", "vwc", "ec", "ph", "pressure", "co2"])
|
|
347
443
|
).min(1, "At least one metric is required").max(4, "Maximum 4 metrics per graph")
|
|
348
444
|
});
|
|
349
|
-
|
|
350
|
-
ticker:
|
|
351
|
-
timeRange:
|
|
445
|
+
n.object({
|
|
446
|
+
ticker: n.string().min(1).describe("The stock ticker symbol explicitly requested by the user. YOU MUST EXTRACT AND PROVIDE THIS (e.g., 'AAPL', 'MSFT')."),
|
|
447
|
+
timeRange: n.enum(["1D", "1W", "1M", "1Y"], {
|
|
352
448
|
errorMap: () => ({ message: "Time range must be 1D, 1W, 1M, or 1Y" })
|
|
353
449
|
}).describe("The time range for the chart. Choose based on user request or default to '1M'."),
|
|
354
|
-
metrics:
|
|
450
|
+
metrics: n.array(n.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.")
|
|
355
451
|
});
|
|
356
|
-
var
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
452
|
+
var U = n.string().min(1).describe("The stock ticker symbol (e.g., 'AAPL', 'TSLA', 'MSFT').");
|
|
453
|
+
n.object({ ticker: U });
|
|
454
|
+
n.object({ ticker: U });
|
|
455
|
+
n.object({ ticker: U });
|
|
456
|
+
n.object({
|
|
457
|
+
ticker: U,
|
|
458
|
+
hops: n.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.")
|
|
459
|
+
});
|
|
460
|
+
n.object({ ticker: U });
|
|
461
|
+
n.object({});
|
|
462
|
+
var z = "gemini-2.5-flash", Me = "gemini-2.5-flash", $e = "gemini-2.5-pro", Vt = {
|
|
361
463
|
/** The Strategist: high creativity, exploratory conversation */
|
|
362
464
|
STRATEGIST: {
|
|
363
|
-
model:
|
|
465
|
+
model: Me,
|
|
364
466
|
provider: "google-gemini",
|
|
365
467
|
temperature: 0.7
|
|
366
468
|
},
|
|
367
469
|
/** The Architect: data schema and resource modeling — precision required */
|
|
368
470
|
ARCHITECT: {
|
|
369
|
-
model:
|
|
471
|
+
model: z,
|
|
370
472
|
provider: "google-gemini",
|
|
371
473
|
temperature: 0.3
|
|
372
474
|
},
|
|
373
475
|
/** The Designer: UI layout generation — moderate creativity */
|
|
374
476
|
DESIGNER: {
|
|
375
|
-
model:
|
|
477
|
+
model: z,
|
|
376
478
|
provider: "google-gemini",
|
|
377
479
|
temperature: 0.5
|
|
378
480
|
},
|
|
@@ -380,81 +482,81 @@ var U = "gemini-2.5-flash", Ae = "gemini-2.5-flash", ke = "gemini-2.5-pro", vt =
|
|
|
380
482
|
* Uses the Pro tier for superior reasoning on complex structured tasks.
|
|
381
483
|
*/
|
|
382
484
|
REVIEWER: {
|
|
383
|
-
model:
|
|
485
|
+
model: $e,
|
|
384
486
|
provider: "google-gemini",
|
|
385
487
|
temperature: 0.2
|
|
386
488
|
},
|
|
387
489
|
/** The Genesis Engine: one-shot app generation — must be schema-strict */
|
|
388
490
|
GENESIS: {
|
|
389
|
-
model:
|
|
491
|
+
model: z,
|
|
390
492
|
provider: "google-gemini",
|
|
391
493
|
temperature: 0.2
|
|
392
494
|
}
|
|
393
|
-
},
|
|
495
|
+
}, _ = n.string().regex(
|
|
394
496
|
/^\d{1,3}\s+\d{1,3}\s+\d{1,3}$/,
|
|
395
497
|
'Must be space-separated RGB integers (e.g. "13 110 253")'
|
|
396
|
-
),
|
|
498
|
+
), Le = n.object({
|
|
397
499
|
// ── Core Brand ───────────────────────────────────────────────────────────
|
|
398
|
-
"--app-primary-color":
|
|
399
|
-
"--app-primary-foreground-color":
|
|
400
|
-
"--app-secondary-color":
|
|
401
|
-
"--app-secondary-foreground-color":
|
|
402
|
-
"--app-accent-color":
|
|
403
|
-
"--app-accent-foreground-color":
|
|
500
|
+
"--app-primary-color": _.optional(),
|
|
501
|
+
"--app-primary-foreground-color": _.optional(),
|
|
502
|
+
"--app-secondary-color": _.optional(),
|
|
503
|
+
"--app-secondary-foreground-color": _.optional(),
|
|
504
|
+
"--app-accent-color": _.optional(),
|
|
505
|
+
"--app-accent-foreground-color": _.optional(),
|
|
404
506
|
// ── Base Surface ─────────────────────────────────────────────────────────
|
|
405
|
-
"--app-bg-color":
|
|
406
|
-
"--app-card-bg-color":
|
|
407
|
-
"--app-text-color":
|
|
408
|
-
"--app-border-color":
|
|
409
|
-
"--app-muted-bg":
|
|
410
|
-
"--app-muted-text":
|
|
507
|
+
"--app-bg-color": _.optional(),
|
|
508
|
+
"--app-card-bg-color": _.optional(),
|
|
509
|
+
"--app-text-color": _.optional(),
|
|
510
|
+
"--app-border-color": _.optional(),
|
|
511
|
+
"--app-muted-bg": _.optional(),
|
|
512
|
+
"--app-muted-text": _.optional(),
|
|
411
513
|
// ── Shape ────────────────────────────────────────────────────────────────
|
|
412
|
-
"--app-border-radius-sm":
|
|
413
|
-
"--app-border-radius-md":
|
|
414
|
-
"--app-border-radius-lg":
|
|
514
|
+
"--app-border-radius-sm": n.string().optional(),
|
|
515
|
+
"--app-border-radius-md": n.string().optional(),
|
|
516
|
+
"--app-border-radius-lg": n.string().optional(),
|
|
415
517
|
// ── Form Controls ────────────────────────────────────────────────────────
|
|
416
|
-
"--app-input-bg-color":
|
|
417
|
-
"--app-input-text-color":
|
|
418
|
-
"--app-input-border-color":
|
|
419
|
-
"--app-input-focus-ring-color":
|
|
420
|
-
"--app-input-placeholder-color":
|
|
518
|
+
"--app-input-bg-color": _.optional(),
|
|
519
|
+
"--app-input-text-color": _.optional(),
|
|
520
|
+
"--app-input-border-color": _.optional(),
|
|
521
|
+
"--app-input-focus-ring-color": _.optional(),
|
|
522
|
+
"--app-input-placeholder-color": _.optional(),
|
|
421
523
|
// ── Chart Palette ────────────────────────────────────────────────────────
|
|
422
|
-
"--app-chart-1":
|
|
423
|
-
"--app-chart-2":
|
|
424
|
-
"--app-chart-3":
|
|
425
|
-
"--app-chart-4":
|
|
426
|
-
"--app-chart-5":
|
|
427
|
-
}).strict(),
|
|
524
|
+
"--app-chart-1": _.optional(),
|
|
525
|
+
"--app-chart-2": _.optional(),
|
|
526
|
+
"--app-chart-3": _.optional(),
|
|
527
|
+
"--app-chart-4": _.optional(),
|
|
528
|
+
"--app-chart-5": _.optional()
|
|
529
|
+
}).strict(), Ce = n.object({
|
|
428
530
|
/** Google Font name for headings (h1–h4, .font-serif). Example: "Playfair Display" */
|
|
429
|
-
heading:
|
|
531
|
+
heading: n.string(),
|
|
430
532
|
/** Google Font name for body text. Example: "Inter" */
|
|
431
|
-
body:
|
|
533
|
+
body: n.string(),
|
|
432
534
|
/** Optional monospace font. Example: "Roboto Mono" */
|
|
433
|
-
mono:
|
|
535
|
+
mono: n.string().optional()
|
|
434
536
|
});
|
|
435
|
-
|
|
537
|
+
n.object({
|
|
436
538
|
/** Short descriptive theme name. Example: "Midnight Garden" */
|
|
437
|
-
name:
|
|
539
|
+
name: n.string(),
|
|
438
540
|
/** One-sentence vibe description. Example: "Dark indigo with golden accents." */
|
|
439
|
-
description:
|
|
541
|
+
description: n.string(),
|
|
440
542
|
/** Google Font pairing for heading and body text. */
|
|
441
|
-
fonts:
|
|
543
|
+
fonts: Ce.optional(),
|
|
442
544
|
/**
|
|
443
545
|
* CSS variable overrides.
|
|
444
546
|
* Every key must match an --app-* variable name.
|
|
445
547
|
* All color values must be space-separated RGB integers.
|
|
446
548
|
*/
|
|
447
|
-
cssVars:
|
|
549
|
+
cssVars: Le
|
|
448
550
|
});
|
|
449
|
-
|
|
450
|
-
primary:
|
|
451
|
-
neutral:
|
|
452
|
-
success:
|
|
453
|
-
warning:
|
|
454
|
-
destructive:
|
|
455
|
-
radius:
|
|
551
|
+
n.object({
|
|
552
|
+
primary: _,
|
|
553
|
+
neutral: _,
|
|
554
|
+
success: _,
|
|
555
|
+
warning: _,
|
|
556
|
+
destructive: _,
|
|
557
|
+
radius: n.enum(["none", "sm", "md", "lg", "full"])
|
|
456
558
|
});
|
|
457
|
-
var
|
|
559
|
+
var Yt = {
|
|
458
560
|
primary: "13 110 253",
|
|
459
561
|
neutral: "24 24 27",
|
|
460
562
|
success: "34 197 94",
|
|
@@ -462,75 +564,177 @@ var Ot = {
|
|
|
462
564
|
destructive: "239 68 68",
|
|
463
565
|
radius: "md"
|
|
464
566
|
};
|
|
465
|
-
|
|
466
|
-
id:
|
|
467
|
-
name:
|
|
468
|
-
email:
|
|
469
|
-
password:
|
|
470
|
-
role:
|
|
471
|
-
status:
|
|
472
|
-
joinedAt:
|
|
473
|
-
lastActive:
|
|
474
|
-
avatarUrl:
|
|
567
|
+
n.object({
|
|
568
|
+
id: n.string().default(""),
|
|
569
|
+
name: n.string(),
|
|
570
|
+
email: n.string().email(),
|
|
571
|
+
password: n.string().optional(),
|
|
572
|
+
role: n.string(),
|
|
573
|
+
status: n.string().optional(),
|
|
574
|
+
joinedAt: n.string().optional(),
|
|
575
|
+
lastActive: n.string().optional(),
|
|
576
|
+
avatarUrl: n.string().optional()
|
|
475
577
|
});
|
|
476
|
-
var
|
|
578
|
+
var Ue = n.enum([
|
|
477
579
|
"supplier",
|
|
478
580
|
"customer",
|
|
479
581
|
"partner",
|
|
480
582
|
"competitor",
|
|
481
583
|
"regulator",
|
|
482
584
|
"unknown"
|
|
585
|
+
]), Ze = n.enum([
|
|
586
|
+
"public",
|
|
587
|
+
"public_uncovered",
|
|
588
|
+
"private",
|
|
589
|
+
"unresolved"
|
|
483
590
|
]);
|
|
484
|
-
|
|
485
|
-
id:
|
|
486
|
-
ticker:
|
|
487
|
-
name
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
591
|
+
n.object({
|
|
592
|
+
id: n.string(),
|
|
593
|
+
ticker: n.string().nullable(),
|
|
594
|
+
/** Name as it appeared in the source signal — e.g. "Nike". Not the registered name. */
|
|
595
|
+
name: n.string(),
|
|
596
|
+
/** Registered legal name from `profiles` — e.g. "NIKE, Inc.". Null unless `public`. */
|
|
597
|
+
publicName: n.string().nullable(),
|
|
598
|
+
lei: n.string().nullable(),
|
|
599
|
+
resolution: Ze,
|
|
600
|
+
type: Ue,
|
|
601
|
+
confidence: n.number().min(0).max(1),
|
|
602
|
+
sourceSignalIds: n.array(n.number()),
|
|
603
|
+
firstSeenAt: n.string().datetime(),
|
|
604
|
+
lastSeenAt: n.string().datetime()
|
|
493
605
|
});
|
|
494
|
-
var
|
|
606
|
+
var qe = n.enum([
|
|
495
607
|
"supplies_to",
|
|
496
608
|
"purchases_from",
|
|
497
609
|
"partners_with",
|
|
498
610
|
"competes_with",
|
|
499
|
-
"regulated_by"
|
|
611
|
+
"regulated_by",
|
|
612
|
+
"invests_in",
|
|
613
|
+
"acquires",
|
|
614
|
+
/**
|
|
615
|
+
* Identity equivalence, not a business relationship: source and target are
|
|
616
|
+
* the same real-world entity under two different node ids (typically a
|
|
617
|
+
* slug-keyed node that predates LEI resolution, pointing at the canonical
|
|
618
|
+
* LEI-keyed node once resolution succeeds). Never delete/merge either
|
|
619
|
+
* node — this edge exists so a consumer wanting a deduped view can follow
|
|
620
|
+
* it to the canonical id, reversibly.
|
|
621
|
+
*/
|
|
622
|
+
"same_as"
|
|
500
623
|
]);
|
|
501
|
-
|
|
502
|
-
id:
|
|
503
|
-
sourceId:
|
|
504
|
-
targetId:
|
|
505
|
-
edgeType:
|
|
506
|
-
weight:
|
|
507
|
-
evidenceSignalIds:
|
|
508
|
-
updatedAt:
|
|
624
|
+
n.object({
|
|
625
|
+
id: n.string(),
|
|
626
|
+
sourceId: n.string(),
|
|
627
|
+
targetId: n.string(),
|
|
628
|
+
edgeType: qe,
|
|
629
|
+
weight: n.number().min(0).max(1),
|
|
630
|
+
evidenceSignalIds: n.array(n.number()),
|
|
631
|
+
updatedAt: n.string().datetime(),
|
|
632
|
+
validFrom: n.string().datetime(),
|
|
633
|
+
/** null = currently valid. Set when a differently-typed edge supersedes this one. */
|
|
634
|
+
validTo: n.string().datetime().nullable()
|
|
635
|
+
});
|
|
636
|
+
var ze = n.object({
|
|
637
|
+
signalId: n.number(),
|
|
638
|
+
weight: n.number().min(0).max(1),
|
|
639
|
+
reason: n.string().max(280)
|
|
640
|
+
});
|
|
641
|
+
n.object({
|
|
642
|
+
ticker: n.string(),
|
|
643
|
+
// 'operations'/'customer' are current; 'operational'/'ux' are pre-rename
|
|
644
|
+
// values that still exist on rows written before the backend's rename —
|
|
645
|
+
// kept here so reading old rows doesn't fail validation.
|
|
646
|
+
metric: n.enum(["operations", "customer", "operational", "ux"]),
|
|
647
|
+
score: n.number(),
|
|
648
|
+
baseline: n.number(),
|
|
649
|
+
observed: n.number(),
|
|
650
|
+
computedAt: n.string().datetime(),
|
|
651
|
+
contributingSignals: n.array(ze)
|
|
509
652
|
});
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
653
|
+
n.object({
|
|
654
|
+
lei: n.string().nullable(),
|
|
655
|
+
entityName: n.string(),
|
|
656
|
+
jurisdiction: n.string().nullable(),
|
|
657
|
+
registrationStatus: n.string(),
|
|
658
|
+
parentEntityLei: n.string().nullable(),
|
|
659
|
+
materialMetadata: n.record(n.unknown()),
|
|
660
|
+
discoveredAt: n.string().datetime()
|
|
514
661
|
});
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
662
|
+
var q = n.enum(["db", "mock"]), F = n.enum(["news", "filing", "report"]), Q = n.enum(["graded", "binary", "default", "none"]), Be = n.enum(["second", "day"]), Je = n.object({
|
|
663
|
+
/** Namespaced so ids never collide across sources: `news:1234`, `filing:AAPL:2026-07-31`. */
|
|
664
|
+
id: n.string(),
|
|
665
|
+
kind: F,
|
|
666
|
+
/**
|
|
667
|
+
* The producer's own type string, unmodified — `NEWS_YAHOO FINANCE_YAHOO RSS`,
|
|
668
|
+
* `ANNUAL`, `SNAPSHOT`. There are 31 distinct NEWS variants in the live table,
|
|
669
|
+
* so this is for filtering and debugging: never render it raw to a user.
|
|
670
|
+
*/
|
|
671
|
+
subtype: n.string().nullable(),
|
|
672
|
+
ticker: n.string(),
|
|
673
|
+
/** Always `YYYY-MM-DDTHH:MM:SSZ`. Fixed-width, so lexical order == chronological order. */
|
|
674
|
+
occurredAt: n.string(),
|
|
675
|
+
precision: Be,
|
|
676
|
+
title: n.string(),
|
|
677
|
+
summary: n.string().nullable(),
|
|
678
|
+
url: n.string().nullable(),
|
|
679
|
+
impact: n.number().nullable(),
|
|
680
|
+
impactScale: Q,
|
|
681
|
+
/** 0 bearish … 50 neutral … 100 bullish. */
|
|
682
|
+
sentiment: n.number().nullable(),
|
|
683
|
+
/** False for filings, and for any event sitting at exactly neutral. */
|
|
684
|
+
sentimentIsMeaningful: n.boolean(),
|
|
685
|
+
source: q,
|
|
686
|
+
meta: n.record(n.unknown()).nullable()
|
|
523
687
|
});
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
parentEntityLei: o.string().nullable(),
|
|
530
|
-
materialMetadata: o.record(o.unknown()),
|
|
531
|
-
discoveredAt: o.string().datetime()
|
|
688
|
+
n.object({
|
|
689
|
+
total: n.number(),
|
|
690
|
+
page: n.number(),
|
|
691
|
+
page_size: n.number(),
|
|
692
|
+
data: n.array(Je)
|
|
532
693
|
});
|
|
533
|
-
|
|
694
|
+
var Ke = n.enum(["day", "week", "month"]), Fe = n.object({
|
|
695
|
+
bucketStart: n.string(),
|
|
696
|
+
kind: F,
|
|
697
|
+
count: n.number(),
|
|
698
|
+
/** Null when no event in the bucket had meaningful sentiment. */
|
|
699
|
+
avgSentiment: n.number().nullable(),
|
|
700
|
+
maxImpact: n.number().nullable()
|
|
701
|
+
});
|
|
702
|
+
n.object({
|
|
703
|
+
ticker: n.string(),
|
|
704
|
+
bucket: Ke,
|
|
705
|
+
buckets: n.array(Fe),
|
|
706
|
+
/** So the client can set its time domain without a second request. */
|
|
707
|
+
range: n.object({ min: n.string(), max: n.string() }),
|
|
708
|
+
source: q
|
|
709
|
+
});
|
|
710
|
+
var Ve = n.object({
|
|
711
|
+
kind: F,
|
|
712
|
+
count: n.number(),
|
|
713
|
+
earliest: n.string().nullable(),
|
|
714
|
+
latest: n.string().nullable(),
|
|
715
|
+
impactScale: Q,
|
|
716
|
+
sentimentUsable: n.boolean()
|
|
717
|
+
});
|
|
718
|
+
n.object({
|
|
719
|
+
ticker: n.string(),
|
|
720
|
+
facets: n.array(Ve),
|
|
721
|
+
source: q
|
|
722
|
+
});
|
|
723
|
+
var Ye = n.object({
|
|
724
|
+
date: n.string(),
|
|
725
|
+
open: n.number().nullable(),
|
|
726
|
+
high: n.number().nullable(),
|
|
727
|
+
low: n.number().nullable(),
|
|
728
|
+
close: n.number(),
|
|
729
|
+
volume: n.number().nullable()
|
|
730
|
+
});
|
|
731
|
+
n.object({
|
|
732
|
+
ticker: n.string(),
|
|
733
|
+
series: n.array(Ye),
|
|
734
|
+
source: q
|
|
735
|
+
});
|
|
736
|
+
var Gt = 50;
|
|
737
|
+
const Ge = Symbol("Let zodToJsonSchema decide on which parser to use"), G = {
|
|
534
738
|
name: void 0,
|
|
535
739
|
$refStrategy: "root",
|
|
536
740
|
basePath: ["#"],
|
|
@@ -553,23 +757,23 @@ const Ie = Symbol("Let zodToJsonSchema decide on which parser to use"), V = {
|
|
|
553
757
|
base64Strategy: "contentEncoding:base64",
|
|
554
758
|
nameStrategy: "ref",
|
|
555
759
|
openAiAnyTypeName: "OpenAiAnyType"
|
|
556
|
-
},
|
|
557
|
-
...
|
|
558
|
-
name:
|
|
760
|
+
}, We = (a) => typeof a == "string" ? {
|
|
761
|
+
...G,
|
|
762
|
+
name: a
|
|
559
763
|
} : {
|
|
560
|
-
...
|
|
561
|
-
...
|
|
562
|
-
},
|
|
563
|
-
const e =
|
|
764
|
+
...G,
|
|
765
|
+
...a
|
|
766
|
+
}, He = (a) => {
|
|
767
|
+
const e = We(a), r = e.name !== void 0 ? [...e.basePath, e.definitionPath, e.name] : e.basePath;
|
|
564
768
|
return {
|
|
565
769
|
...e,
|
|
566
770
|
flags: { hasReferencedOpenAiAnyType: !1 },
|
|
567
771
|
currentPath: r,
|
|
568
772
|
propertyPath: void 0,
|
|
569
|
-
seen: new Map(Object.entries(e.definitions).map(([t,
|
|
570
|
-
|
|
773
|
+
seen: new Map(Object.entries(e.definitions).map(([t, o]) => [
|
|
774
|
+
o._def,
|
|
571
775
|
{
|
|
572
|
-
def:
|
|
776
|
+
def: o._def,
|
|
573
777
|
path: [...e.basePath, e.definitionPath, t],
|
|
574
778
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
575
779
|
jsonSchema: void 0
|
|
@@ -577,82 +781,82 @@ const Ie = Symbol("Let zodToJsonSchema decide on which parser to use"), V = {
|
|
|
577
781
|
]))
|
|
578
782
|
};
|
|
579
783
|
};
|
|
580
|
-
function
|
|
581
|
-
t != null && t.errorMessages && r && (
|
|
582
|
-
...
|
|
784
|
+
function ee(a, e, r, t) {
|
|
785
|
+
t != null && t.errorMessages && r && (a.errorMessage = {
|
|
786
|
+
...a.errorMessage,
|
|
583
787
|
[e]: r
|
|
584
788
|
});
|
|
585
789
|
}
|
|
586
|
-
function
|
|
587
|
-
|
|
790
|
+
function S(a, e, r, t, o) {
|
|
791
|
+
a[e] = r, ee(a, e, t, o);
|
|
588
792
|
}
|
|
589
|
-
const
|
|
793
|
+
const te = (a, e) => {
|
|
590
794
|
let r = 0;
|
|
591
|
-
for (; r <
|
|
795
|
+
for (; r < a.length && r < e.length && a[r] === e[r]; r++)
|
|
592
796
|
;
|
|
593
|
-
return [(
|
|
797
|
+
return [(a.length - r).toString(), ...e.slice(r)].join("/");
|
|
594
798
|
};
|
|
595
799
|
var y;
|
|
596
|
-
(function(
|
|
597
|
-
|
|
800
|
+
(function(a) {
|
|
801
|
+
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";
|
|
598
802
|
})(y || (y = {}));
|
|
599
|
-
function
|
|
600
|
-
if (
|
|
803
|
+
function x(a) {
|
|
804
|
+
if (a.target !== "openAi")
|
|
601
805
|
return {};
|
|
602
806
|
const e = [
|
|
603
|
-
...
|
|
604
|
-
|
|
605
|
-
|
|
807
|
+
...a.basePath,
|
|
808
|
+
a.definitionPath,
|
|
809
|
+
a.openAiAnyTypeName
|
|
606
810
|
];
|
|
607
|
-
return
|
|
608
|
-
$ref:
|
|
811
|
+
return a.flags.hasReferencedOpenAiAnyType = !0, {
|
|
812
|
+
$ref: a.$refStrategy === "relative" ? te(e, a.currentPath) : e.join("/")
|
|
609
813
|
};
|
|
610
814
|
}
|
|
611
|
-
function
|
|
612
|
-
var t,
|
|
815
|
+
function Xe(a, e) {
|
|
816
|
+
var t, o, i;
|
|
613
817
|
const r = {
|
|
614
818
|
type: "array"
|
|
615
819
|
};
|
|
616
|
-
return (t =
|
|
820
|
+
return (t = a.type) != null && t._def && ((i = (o = a.type) == null ? void 0 : o._def) == null ? void 0 : i.typeName) !== y.ZodAny && (r.items = k(a.type._def, {
|
|
617
821
|
...e,
|
|
618
822
|
currentPath: [...e.currentPath, "items"]
|
|
619
|
-
})),
|
|
823
|
+
})), a.minLength && S(r, "minItems", a.minLength.value, a.minLength.message, e), a.maxLength && S(r, "maxItems", a.maxLength.value, a.maxLength.message, e), a.exactLength && (S(r, "minItems", a.exactLength.value, a.exactLength.message, e), S(r, "maxItems", a.exactLength.value, a.exactLength.message, e)), r;
|
|
620
824
|
}
|
|
621
|
-
function
|
|
825
|
+
function Qe(a, e) {
|
|
622
826
|
const r = {
|
|
623
827
|
type: "integer",
|
|
624
828
|
format: "int64"
|
|
625
829
|
};
|
|
626
|
-
if (!
|
|
830
|
+
if (!a.checks)
|
|
627
831
|
return r;
|
|
628
|
-
for (const t of
|
|
832
|
+
for (const t of a.checks)
|
|
629
833
|
switch (t.kind) {
|
|
630
834
|
case "min":
|
|
631
|
-
e.target === "jsonSchema7" ? t.inclusive ?
|
|
835
|
+
e.target === "jsonSchema7" ? t.inclusive ? S(r, "minimum", t.value, t.message, e) : S(r, "exclusiveMinimum", t.value, t.message, e) : (t.inclusive || (r.exclusiveMinimum = !0), S(r, "minimum", t.value, t.message, e));
|
|
632
836
|
break;
|
|
633
837
|
case "max":
|
|
634
|
-
e.target === "jsonSchema7" ? t.inclusive ?
|
|
838
|
+
e.target === "jsonSchema7" ? t.inclusive ? S(r, "maximum", t.value, t.message, e) : S(r, "exclusiveMaximum", t.value, t.message, e) : (t.inclusive || (r.exclusiveMaximum = !0), S(r, "maximum", t.value, t.message, e));
|
|
635
839
|
break;
|
|
636
840
|
case "multipleOf":
|
|
637
|
-
|
|
841
|
+
S(r, "multipleOf", t.value, t.message, e);
|
|
638
842
|
break;
|
|
639
843
|
}
|
|
640
844
|
return r;
|
|
641
845
|
}
|
|
642
|
-
function
|
|
846
|
+
function et() {
|
|
643
847
|
return {
|
|
644
848
|
type: "boolean"
|
|
645
849
|
};
|
|
646
850
|
}
|
|
647
|
-
function
|
|
648
|
-
return k(
|
|
851
|
+
function re(a, e) {
|
|
852
|
+
return k(a.type._def, e);
|
|
649
853
|
}
|
|
650
|
-
const
|
|
651
|
-
function
|
|
854
|
+
const tt = (a, e) => k(a.innerType._def, e);
|
|
855
|
+
function ne(a, e, r) {
|
|
652
856
|
const t = r ?? e.dateStrategy;
|
|
653
857
|
if (Array.isArray(t))
|
|
654
858
|
return {
|
|
655
|
-
anyOf: t.map((
|
|
859
|
+
anyOf: t.map((o, i) => ne(a, e, o))
|
|
656
860
|
};
|
|
657
861
|
switch (t) {
|
|
658
862
|
case "string":
|
|
@@ -667,20 +871,20 @@ function X(n, e, r) {
|
|
|
667
871
|
format: "date"
|
|
668
872
|
};
|
|
669
873
|
case "integer":
|
|
670
|
-
return
|
|
874
|
+
return rt(a, e);
|
|
671
875
|
}
|
|
672
876
|
}
|
|
673
|
-
const
|
|
877
|
+
const rt = (a, e) => {
|
|
674
878
|
const r = {
|
|
675
879
|
type: "integer",
|
|
676
880
|
format: "unix-time"
|
|
677
881
|
};
|
|
678
882
|
if (e.target === "openApi3")
|
|
679
883
|
return r;
|
|
680
|
-
for (const t of
|
|
884
|
+
for (const t of a.checks)
|
|
681
885
|
switch (t.kind) {
|
|
682
886
|
case "min":
|
|
683
|
-
|
|
887
|
+
S(
|
|
684
888
|
r,
|
|
685
889
|
"minimum",
|
|
686
890
|
t.value,
|
|
@@ -690,7 +894,7 @@ const Me = (n, e) => {
|
|
|
690
894
|
);
|
|
691
895
|
break;
|
|
692
896
|
case "max":
|
|
693
|
-
|
|
897
|
+
S(
|
|
694
898
|
r,
|
|
695
899
|
"maximum",
|
|
696
900
|
t.value,
|
|
@@ -702,38 +906,38 @@ const Me = (n, e) => {
|
|
|
702
906
|
}
|
|
703
907
|
return r;
|
|
704
908
|
};
|
|
705
|
-
function
|
|
909
|
+
function nt(a, e) {
|
|
706
910
|
return {
|
|
707
|
-
...k(
|
|
708
|
-
default:
|
|
911
|
+
...k(a.innerType._def, e),
|
|
912
|
+
default: a.defaultValue()
|
|
709
913
|
};
|
|
710
914
|
}
|
|
711
|
-
function
|
|
712
|
-
return e.effectStrategy === "input" ? k(
|
|
915
|
+
function at(a, e) {
|
|
916
|
+
return e.effectStrategy === "input" ? k(a.schema._def, e) : x(e);
|
|
713
917
|
}
|
|
714
|
-
function
|
|
918
|
+
function ot(a) {
|
|
715
919
|
return {
|
|
716
920
|
type: "string",
|
|
717
|
-
enum: Array.from(
|
|
921
|
+
enum: Array.from(a.values)
|
|
718
922
|
};
|
|
719
923
|
}
|
|
720
|
-
const
|
|
721
|
-
function
|
|
924
|
+
const it = (a) => "type" in a && a.type === "string" ? !1 : "allOf" in a;
|
|
925
|
+
function st(a, e) {
|
|
722
926
|
const r = [
|
|
723
|
-
k(
|
|
927
|
+
k(a.left._def, {
|
|
724
928
|
...e,
|
|
725
929
|
currentPath: [...e.currentPath, "allOf", "0"]
|
|
726
930
|
}),
|
|
727
|
-
k(
|
|
931
|
+
k(a.right._def, {
|
|
728
932
|
...e,
|
|
729
933
|
currentPath: [...e.currentPath, "allOf", "1"]
|
|
730
934
|
})
|
|
731
935
|
].filter((i) => !!i);
|
|
732
936
|
let t = e.target === "jsonSchema2019-09" ? { unevaluatedProperties: !1 } : void 0;
|
|
733
|
-
const
|
|
937
|
+
const o = [];
|
|
734
938
|
return r.forEach((i) => {
|
|
735
|
-
if (
|
|
736
|
-
|
|
939
|
+
if (it(i))
|
|
940
|
+
o.push(...i.allOf), i.unevaluatedProperties === void 0 && (t = void 0);
|
|
737
941
|
else {
|
|
738
942
|
let s = i;
|
|
739
943
|
if ("additionalProperties" in i && i.additionalProperties === !1) {
|
|
@@ -741,27 +945,27 @@ function Ze(n, e) {
|
|
|
741
945
|
s = c;
|
|
742
946
|
} else
|
|
743
947
|
t = void 0;
|
|
744
|
-
|
|
948
|
+
o.push(s);
|
|
745
949
|
}
|
|
746
|
-
}),
|
|
747
|
-
allOf:
|
|
950
|
+
}), o.length ? {
|
|
951
|
+
allOf: o,
|
|
748
952
|
...t
|
|
749
953
|
} : void 0;
|
|
750
954
|
}
|
|
751
|
-
function
|
|
752
|
-
const r = typeof
|
|
955
|
+
function ct(a, e) {
|
|
956
|
+
const r = typeof a.value;
|
|
753
957
|
return r !== "bigint" && r !== "number" && r !== "boolean" && r !== "string" ? {
|
|
754
|
-
type: Array.isArray(
|
|
958
|
+
type: Array.isArray(a.value) ? "array" : "object"
|
|
755
959
|
} : e.target === "openApi3" ? {
|
|
756
960
|
type: r === "bigint" ? "integer" : r,
|
|
757
|
-
enum: [
|
|
961
|
+
enum: [a.value]
|
|
758
962
|
} : {
|
|
759
963
|
type: r === "bigint" ? "integer" : r,
|
|
760
|
-
const:
|
|
964
|
+
const: a.value
|
|
761
965
|
};
|
|
762
966
|
}
|
|
763
|
-
let
|
|
764
|
-
const
|
|
967
|
+
let B;
|
|
968
|
+
const P = {
|
|
765
969
|
/**
|
|
766
970
|
* `c` was changed to `[cC]` to replicate /i flag
|
|
767
971
|
*/
|
|
@@ -783,7 +987,7 @@ const x = {
|
|
|
783
987
|
* Fix in Zod:
|
|
784
988
|
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
785
989
|
*/
|
|
786
|
-
emoji: () => (
|
|
990
|
+
emoji: () => (B === void 0 && (B = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u")), B),
|
|
787
991
|
/**
|
|
788
992
|
* Unused
|
|
789
993
|
*/
|
|
@@ -803,260 +1007,260 @@ const x = {
|
|
|
803
1007
|
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
804
1008
|
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
805
1009
|
};
|
|
806
|
-
function
|
|
1010
|
+
function ae(a, e) {
|
|
807
1011
|
const r = {
|
|
808
1012
|
type: "string"
|
|
809
1013
|
};
|
|
810
|
-
if (
|
|
811
|
-
for (const t of
|
|
1014
|
+
if (a.checks)
|
|
1015
|
+
for (const t of a.checks)
|
|
812
1016
|
switch (t.kind) {
|
|
813
1017
|
case "min":
|
|
814
|
-
|
|
1018
|
+
S(r, "minLength", typeof r.minLength == "number" ? Math.max(r.minLength, t.value) : t.value, t.message, e);
|
|
815
1019
|
break;
|
|
816
1020
|
case "max":
|
|
817
|
-
|
|
1021
|
+
S(r, "maxLength", typeof r.maxLength == "number" ? Math.min(r.maxLength, t.value) : t.value, t.message, e);
|
|
818
1022
|
break;
|
|
819
1023
|
case "email":
|
|
820
1024
|
switch (e.emailStrategy) {
|
|
821
1025
|
case "format:email":
|
|
822
|
-
|
|
1026
|
+
j(r, "email", t.message, e);
|
|
823
1027
|
break;
|
|
824
1028
|
case "format:idn-email":
|
|
825
|
-
|
|
1029
|
+
j(r, "idn-email", t.message, e);
|
|
826
1030
|
break;
|
|
827
1031
|
case "pattern:zod":
|
|
828
|
-
O(r,
|
|
1032
|
+
O(r, P.email, t.message, e);
|
|
829
1033
|
break;
|
|
830
1034
|
}
|
|
831
1035
|
break;
|
|
832
1036
|
case "url":
|
|
833
|
-
|
|
1037
|
+
j(r, "uri", t.message, e);
|
|
834
1038
|
break;
|
|
835
1039
|
case "uuid":
|
|
836
|
-
|
|
1040
|
+
j(r, "uuid", t.message, e);
|
|
837
1041
|
break;
|
|
838
1042
|
case "regex":
|
|
839
1043
|
O(r, t.regex, t.message, e);
|
|
840
1044
|
break;
|
|
841
1045
|
case "cuid":
|
|
842
|
-
O(r,
|
|
1046
|
+
O(r, P.cuid, t.message, e);
|
|
843
1047
|
break;
|
|
844
1048
|
case "cuid2":
|
|
845
|
-
O(r,
|
|
1049
|
+
O(r, P.cuid2, t.message, e);
|
|
846
1050
|
break;
|
|
847
1051
|
case "startsWith":
|
|
848
|
-
O(r, RegExp(`^${
|
|
1052
|
+
O(r, RegExp(`^${J(t.value, e)}`), t.message, e);
|
|
849
1053
|
break;
|
|
850
1054
|
case "endsWith":
|
|
851
|
-
O(r, RegExp(`${
|
|
1055
|
+
O(r, RegExp(`${J(t.value, e)}$`), t.message, e);
|
|
852
1056
|
break;
|
|
853
1057
|
case "datetime":
|
|
854
|
-
|
|
1058
|
+
j(r, "date-time", t.message, e);
|
|
855
1059
|
break;
|
|
856
1060
|
case "date":
|
|
857
|
-
|
|
1061
|
+
j(r, "date", t.message, e);
|
|
858
1062
|
break;
|
|
859
1063
|
case "time":
|
|
860
|
-
|
|
1064
|
+
j(r, "time", t.message, e);
|
|
861
1065
|
break;
|
|
862
1066
|
case "duration":
|
|
863
|
-
|
|
1067
|
+
j(r, "duration", t.message, e);
|
|
864
1068
|
break;
|
|
865
1069
|
case "length":
|
|
866
|
-
|
|
1070
|
+
S(r, "minLength", typeof r.minLength == "number" ? Math.max(r.minLength, t.value) : t.value, t.message, e), S(r, "maxLength", typeof r.maxLength == "number" ? Math.min(r.maxLength, t.value) : t.value, t.message, e);
|
|
867
1071
|
break;
|
|
868
1072
|
case "includes": {
|
|
869
|
-
O(r, RegExp(
|
|
1073
|
+
O(r, RegExp(J(t.value, e)), t.message, e);
|
|
870
1074
|
break;
|
|
871
1075
|
}
|
|
872
1076
|
case "ip": {
|
|
873
|
-
t.version !== "v6" &&
|
|
1077
|
+
t.version !== "v6" && j(r, "ipv4", t.message, e), t.version !== "v4" && j(r, "ipv6", t.message, e);
|
|
874
1078
|
break;
|
|
875
1079
|
}
|
|
876
1080
|
case "base64url":
|
|
877
|
-
O(r,
|
|
1081
|
+
O(r, P.base64url, t.message, e);
|
|
878
1082
|
break;
|
|
879
1083
|
case "jwt":
|
|
880
|
-
O(r,
|
|
1084
|
+
O(r, P.jwt, t.message, e);
|
|
881
1085
|
break;
|
|
882
1086
|
case "cidr": {
|
|
883
|
-
t.version !== "v6" && O(r,
|
|
1087
|
+
t.version !== "v6" && O(r, P.ipv4Cidr, t.message, e), t.version !== "v4" && O(r, P.ipv6Cidr, t.message, e);
|
|
884
1088
|
break;
|
|
885
1089
|
}
|
|
886
1090
|
case "emoji":
|
|
887
|
-
O(r,
|
|
1091
|
+
O(r, P.emoji(), t.message, e);
|
|
888
1092
|
break;
|
|
889
1093
|
case "ulid": {
|
|
890
|
-
O(r,
|
|
1094
|
+
O(r, P.ulid, t.message, e);
|
|
891
1095
|
break;
|
|
892
1096
|
}
|
|
893
1097
|
case "base64": {
|
|
894
1098
|
switch (e.base64Strategy) {
|
|
895
1099
|
case "format:binary": {
|
|
896
|
-
|
|
1100
|
+
j(r, "binary", t.message, e);
|
|
897
1101
|
break;
|
|
898
1102
|
}
|
|
899
1103
|
case "contentEncoding:base64": {
|
|
900
|
-
|
|
1104
|
+
S(r, "contentEncoding", "base64", t.message, e);
|
|
901
1105
|
break;
|
|
902
1106
|
}
|
|
903
1107
|
case "pattern:zod": {
|
|
904
|
-
O(r,
|
|
1108
|
+
O(r, P.base64, t.message, e);
|
|
905
1109
|
break;
|
|
906
1110
|
}
|
|
907
1111
|
}
|
|
908
1112
|
break;
|
|
909
1113
|
}
|
|
910
1114
|
case "nanoid":
|
|
911
|
-
O(r,
|
|
1115
|
+
O(r, P.nanoid, t.message, e);
|
|
912
1116
|
}
|
|
913
1117
|
return r;
|
|
914
1118
|
}
|
|
915
|
-
function
|
|
916
|
-
return e.patternStrategy === "escape" ?
|
|
1119
|
+
function J(a, e) {
|
|
1120
|
+
return e.patternStrategy === "escape" ? ut(a) : a;
|
|
917
1121
|
}
|
|
918
|
-
const
|
|
919
|
-
function
|
|
1122
|
+
const lt = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
1123
|
+
function ut(a) {
|
|
920
1124
|
let e = "";
|
|
921
|
-
for (let r = 0; r <
|
|
922
|
-
|
|
1125
|
+
for (let r = 0; r < a.length; r++)
|
|
1126
|
+
lt.has(a[r]) || (e += "\\"), e += a[r];
|
|
923
1127
|
return e;
|
|
924
1128
|
}
|
|
925
|
-
function
|
|
926
|
-
var
|
|
927
|
-
|
|
928
|
-
format:
|
|
929
|
-
...
|
|
930
|
-
errorMessage: { format:
|
|
931
|
-
}
|
|
932
|
-
}), delete
|
|
1129
|
+
function j(a, e, r, t) {
|
|
1130
|
+
var o;
|
|
1131
|
+
a.format || (o = a.anyOf) != null && o.some((i) => i.format) ? (a.anyOf || (a.anyOf = []), a.format && (a.anyOf.push({
|
|
1132
|
+
format: a.format,
|
|
1133
|
+
...a.errorMessage && t.errorMessages && {
|
|
1134
|
+
errorMessage: { format: a.errorMessage.format }
|
|
1135
|
+
}
|
|
1136
|
+
}), delete a.format, a.errorMessage && (delete a.errorMessage.format, Object.keys(a.errorMessage).length === 0 && delete a.errorMessage)), a.anyOf.push({
|
|
933
1137
|
format: e,
|
|
934
1138
|
...r && t.errorMessages && { errorMessage: { format: r } }
|
|
935
|
-
})) :
|
|
1139
|
+
})) : S(a, "format", e, r, t);
|
|
936
1140
|
}
|
|
937
|
-
function O(
|
|
938
|
-
var
|
|
939
|
-
|
|
940
|
-
pattern:
|
|
941
|
-
...
|
|
942
|
-
errorMessage: { pattern:
|
|
943
|
-
}
|
|
944
|
-
}), delete
|
|
945
|
-
pattern:
|
|
1141
|
+
function O(a, e, r, t) {
|
|
1142
|
+
var o;
|
|
1143
|
+
a.pattern || (o = a.allOf) != null && o.some((i) => i.pattern) ? (a.allOf || (a.allOf = []), a.pattern && (a.allOf.push({
|
|
1144
|
+
pattern: a.pattern,
|
|
1145
|
+
...a.errorMessage && t.errorMessages && {
|
|
1146
|
+
errorMessage: { pattern: a.errorMessage.pattern }
|
|
1147
|
+
}
|
|
1148
|
+
}), delete a.pattern, a.errorMessage && (delete a.errorMessage.pattern, Object.keys(a.errorMessage).length === 0 && delete a.errorMessage)), a.allOf.push({
|
|
1149
|
+
pattern: W(e, t),
|
|
946
1150
|
...r && t.errorMessages && { errorMessage: { pattern: r } }
|
|
947
|
-
})) :
|
|
1151
|
+
})) : S(a, "pattern", W(e, t), r, t);
|
|
948
1152
|
}
|
|
949
|
-
function
|
|
1153
|
+
function W(a, e) {
|
|
950
1154
|
var c;
|
|
951
|
-
if (!e.applyRegexFlags || !
|
|
952
|
-
return
|
|
1155
|
+
if (!e.applyRegexFlags || !a.flags)
|
|
1156
|
+
return a.source;
|
|
953
1157
|
const r = {
|
|
954
|
-
i:
|
|
955
|
-
m:
|
|
956
|
-
s:
|
|
1158
|
+
i: a.flags.includes("i"),
|
|
1159
|
+
m: a.flags.includes("m"),
|
|
1160
|
+
s: a.flags.includes("s")
|
|
957
1161
|
// `.` matches newlines
|
|
958
|
-
}, t = r.i ?
|
|
959
|
-
let
|
|
960
|
-
for (let
|
|
1162
|
+
}, t = r.i ? a.source.toLowerCase() : a.source;
|
|
1163
|
+
let o = "", i = !1, s = !1, l = !1;
|
|
1164
|
+
for (let u = 0; u < t.length; u++) {
|
|
961
1165
|
if (i) {
|
|
962
|
-
|
|
1166
|
+
o += t[u], i = !1;
|
|
963
1167
|
continue;
|
|
964
1168
|
}
|
|
965
1169
|
if (r.i) {
|
|
966
1170
|
if (s) {
|
|
967
|
-
if (t[
|
|
968
|
-
l ? (
|
|
1171
|
+
if (t[u].match(/[a-z]/)) {
|
|
1172
|
+
l ? (o += t[u], o += `${t[u - 2]}-${t[u]}`.toUpperCase(), l = !1) : t[u + 1] === "-" && ((c = t[u + 2]) != null && c.match(/[a-z]/)) ? (o += t[u], l = !0) : o += `${t[u]}${t[u].toUpperCase()}`;
|
|
969
1173
|
continue;
|
|
970
1174
|
}
|
|
971
|
-
} else if (t[
|
|
972
|
-
|
|
1175
|
+
} else if (t[u].match(/[a-z]/)) {
|
|
1176
|
+
o += `[${t[u]}${t[u].toUpperCase()}]`;
|
|
973
1177
|
continue;
|
|
974
1178
|
}
|
|
975
1179
|
}
|
|
976
1180
|
if (r.m) {
|
|
977
|
-
if (t[
|
|
978
|
-
|
|
1181
|
+
if (t[u] === "^") {
|
|
1182
|
+
o += `(^|(?<=[\r
|
|
979
1183
|
]))`;
|
|
980
1184
|
continue;
|
|
981
|
-
} else if (t[
|
|
982
|
-
|
|
1185
|
+
} else if (t[u] === "$") {
|
|
1186
|
+
o += `($|(?=[\r
|
|
983
1187
|
]))`;
|
|
984
1188
|
continue;
|
|
985
1189
|
}
|
|
986
1190
|
}
|
|
987
|
-
if (r.s && t[
|
|
988
|
-
|
|
989
|
-
` : `[${t[
|
|
1191
|
+
if (r.s && t[u] === ".") {
|
|
1192
|
+
o += s ? `${t[u]}\r
|
|
1193
|
+
` : `[${t[u]}\r
|
|
990
1194
|
]`;
|
|
991
1195
|
continue;
|
|
992
1196
|
}
|
|
993
|
-
|
|
1197
|
+
o += t[u], t[u] === "\\" ? i = !0 : s && t[u] === "]" ? s = !1 : !s && t[u] === "[" && (s = !0);
|
|
994
1198
|
}
|
|
995
1199
|
try {
|
|
996
|
-
new RegExp(
|
|
1200
|
+
new RegExp(o);
|
|
997
1201
|
} catch {
|
|
998
|
-
return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),
|
|
1202
|
+
return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`), a.source;
|
|
999
1203
|
}
|
|
1000
|
-
return
|
|
1204
|
+
return o;
|
|
1001
1205
|
}
|
|
1002
|
-
function
|
|
1003
|
-
var t,
|
|
1004
|
-
if (e.target === "openAi" && console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."), e.target === "openApi3" && ((t =
|
|
1206
|
+
function oe(a, e) {
|
|
1207
|
+
var t, o, i, s, l, c;
|
|
1208
|
+
if (e.target === "openAi" && console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."), e.target === "openApi3" && ((t = a.keyType) == null ? void 0 : t._def.typeName) === y.ZodEnum)
|
|
1005
1209
|
return {
|
|
1006
1210
|
type: "object",
|
|
1007
|
-
required:
|
|
1008
|
-
properties:
|
|
1009
|
-
...
|
|
1010
|
-
[
|
|
1211
|
+
required: a.keyType._def.values,
|
|
1212
|
+
properties: a.keyType._def.values.reduce((u, m) => ({
|
|
1213
|
+
...u,
|
|
1214
|
+
[m]: k(a.valueType._def, {
|
|
1011
1215
|
...e,
|
|
1012
|
-
currentPath: [...e.currentPath, "properties",
|
|
1013
|
-
}) ??
|
|
1216
|
+
currentPath: [...e.currentPath, "properties", m]
|
|
1217
|
+
}) ?? x(e)
|
|
1014
1218
|
}), {}),
|
|
1015
1219
|
additionalProperties: e.rejectedAdditionalProperties
|
|
1016
1220
|
};
|
|
1017
1221
|
const r = {
|
|
1018
1222
|
type: "object",
|
|
1019
|
-
additionalProperties: k(
|
|
1223
|
+
additionalProperties: k(a.valueType._def, {
|
|
1020
1224
|
...e,
|
|
1021
1225
|
currentPath: [...e.currentPath, "additionalProperties"]
|
|
1022
1226
|
}) ?? e.allowedAdditionalProperties
|
|
1023
1227
|
};
|
|
1024
1228
|
if (e.target === "openApi3")
|
|
1025
1229
|
return r;
|
|
1026
|
-
if (((
|
|
1027
|
-
const { type:
|
|
1230
|
+
if (((o = a.keyType) == null ? void 0 : o._def.typeName) === y.ZodString && ((i = a.keyType._def.checks) != null && i.length)) {
|
|
1231
|
+
const { type: u, ...m } = ae(a.keyType._def, e);
|
|
1028
1232
|
return {
|
|
1029
1233
|
...r,
|
|
1030
|
-
propertyNames:
|
|
1234
|
+
propertyNames: m
|
|
1031
1235
|
};
|
|
1032
1236
|
} else {
|
|
1033
|
-
if (((s =
|
|
1237
|
+
if (((s = a.keyType) == null ? void 0 : s._def.typeName) === y.ZodEnum)
|
|
1034
1238
|
return {
|
|
1035
1239
|
...r,
|
|
1036
1240
|
propertyNames: {
|
|
1037
|
-
enum:
|
|
1241
|
+
enum: a.keyType._def.values
|
|
1038
1242
|
}
|
|
1039
1243
|
};
|
|
1040
|
-
if (((l =
|
|
1041
|
-
const { type:
|
|
1244
|
+
if (((l = a.keyType) == null ? void 0 : l._def.typeName) === y.ZodBranded && a.keyType._def.type._def.typeName === y.ZodString && ((c = a.keyType._def.type._def.checks) != null && c.length)) {
|
|
1245
|
+
const { type: u, ...m } = re(a.keyType._def, e);
|
|
1042
1246
|
return {
|
|
1043
1247
|
...r,
|
|
1044
|
-
propertyNames:
|
|
1248
|
+
propertyNames: m
|
|
1045
1249
|
};
|
|
1046
1250
|
}
|
|
1047
1251
|
}
|
|
1048
1252
|
return r;
|
|
1049
1253
|
}
|
|
1050
|
-
function
|
|
1254
|
+
function mt(a, e) {
|
|
1051
1255
|
if (e.mapStrategy === "record")
|
|
1052
|
-
return
|
|
1053
|
-
const r = k(
|
|
1256
|
+
return oe(a, e);
|
|
1257
|
+
const r = k(a.keyType._def, {
|
|
1054
1258
|
...e,
|
|
1055
1259
|
currentPath: [...e.currentPath, "items", "items", "0"]
|
|
1056
|
-
}) ||
|
|
1260
|
+
}) || x(e), t = k(a.valueType._def, {
|
|
1057
1261
|
...e,
|
|
1058
1262
|
currentPath: [...e.currentPath, "items", "items", "1"]
|
|
1059
|
-
}) ||
|
|
1263
|
+
}) || x(e);
|
|
1060
1264
|
return {
|
|
1061
1265
|
type: "array",
|
|
1062
1266
|
maxItems: 125,
|
|
@@ -1068,168 +1272,168 @@ function Be(n, e) {
|
|
|
1068
1272
|
}
|
|
1069
1273
|
};
|
|
1070
1274
|
}
|
|
1071
|
-
function
|
|
1072
|
-
const e =
|
|
1275
|
+
function dt(a) {
|
|
1276
|
+
const e = a.values, t = Object.keys(a.values).filter((i) => typeof e[e[i]] != "number").map((i) => e[i]), o = Array.from(new Set(t.map((i) => typeof i)));
|
|
1073
1277
|
return {
|
|
1074
|
-
type:
|
|
1278
|
+
type: o.length === 1 ? o[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1075
1279
|
enum: t
|
|
1076
1280
|
};
|
|
1077
1281
|
}
|
|
1078
|
-
function
|
|
1079
|
-
return
|
|
1080
|
-
not:
|
|
1081
|
-
...
|
|
1082
|
-
currentPath: [...
|
|
1282
|
+
function pt(a) {
|
|
1283
|
+
return a.target === "openAi" ? void 0 : {
|
|
1284
|
+
not: x({
|
|
1285
|
+
...a,
|
|
1286
|
+
currentPath: [...a.currentPath, "not"]
|
|
1083
1287
|
})
|
|
1084
1288
|
};
|
|
1085
1289
|
}
|
|
1086
|
-
function
|
|
1087
|
-
return
|
|
1290
|
+
function gt(a) {
|
|
1291
|
+
return a.target === "openApi3" ? {
|
|
1088
1292
|
enum: ["null"],
|
|
1089
1293
|
nullable: !0
|
|
1090
1294
|
} : {
|
|
1091
1295
|
type: "null"
|
|
1092
1296
|
};
|
|
1093
1297
|
}
|
|
1094
|
-
const
|
|
1298
|
+
const Z = {
|
|
1095
1299
|
ZodString: "string",
|
|
1096
1300
|
ZodNumber: "number",
|
|
1097
1301
|
ZodBigInt: "integer",
|
|
1098
1302
|
ZodBoolean: "boolean",
|
|
1099
1303
|
ZodNull: "null"
|
|
1100
1304
|
};
|
|
1101
|
-
function
|
|
1305
|
+
function ht(a, e) {
|
|
1102
1306
|
if (e.target === "openApi3")
|
|
1103
|
-
return
|
|
1104
|
-
const r =
|
|
1105
|
-
if (r.every((t) => t._def.typeName in
|
|
1106
|
-
const t = r.reduce((
|
|
1107
|
-
const s =
|
|
1108
|
-
return s && !
|
|
1307
|
+
return H(a, e);
|
|
1308
|
+
const r = a.options instanceof Map ? Array.from(a.options.values()) : a.options;
|
|
1309
|
+
if (r.every((t) => t._def.typeName in Z && (!t._def.checks || !t._def.checks.length))) {
|
|
1310
|
+
const t = r.reduce((o, i) => {
|
|
1311
|
+
const s = Z[i._def.typeName];
|
|
1312
|
+
return s && !o.includes(s) ? [...o, s] : o;
|
|
1109
1313
|
}, []);
|
|
1110
1314
|
return {
|
|
1111
1315
|
type: t.length > 1 ? t : t[0]
|
|
1112
1316
|
};
|
|
1113
1317
|
} else if (r.every((t) => t._def.typeName === "ZodLiteral" && !t.description)) {
|
|
1114
|
-
const t = r.reduce((
|
|
1318
|
+
const t = r.reduce((o, i) => {
|
|
1115
1319
|
const s = typeof i._def.value;
|
|
1116
1320
|
switch (s) {
|
|
1117
1321
|
case "string":
|
|
1118
1322
|
case "number":
|
|
1119
1323
|
case "boolean":
|
|
1120
|
-
return [...
|
|
1324
|
+
return [...o, s];
|
|
1121
1325
|
case "bigint":
|
|
1122
|
-
return [...
|
|
1326
|
+
return [...o, "integer"];
|
|
1123
1327
|
case "object":
|
|
1124
1328
|
if (i._def.value === null)
|
|
1125
|
-
return [...
|
|
1329
|
+
return [...o, "null"];
|
|
1126
1330
|
case "symbol":
|
|
1127
1331
|
case "undefined":
|
|
1128
1332
|
case "function":
|
|
1129
1333
|
default:
|
|
1130
|
-
return
|
|
1334
|
+
return o;
|
|
1131
1335
|
}
|
|
1132
1336
|
}, []);
|
|
1133
1337
|
if (t.length === r.length) {
|
|
1134
|
-
const
|
|
1338
|
+
const o = t.filter((i, s, l) => l.indexOf(i) === s);
|
|
1135
1339
|
return {
|
|
1136
|
-
type:
|
|
1340
|
+
type: o.length > 1 ? o : o[0],
|
|
1137
1341
|
enum: r.reduce((i, s) => i.includes(s._def.value) ? i : [...i, s._def.value], [])
|
|
1138
1342
|
};
|
|
1139
1343
|
}
|
|
1140
1344
|
} else if (r.every((t) => t._def.typeName === "ZodEnum"))
|
|
1141
1345
|
return {
|
|
1142
1346
|
type: "string",
|
|
1143
|
-
enum: r.reduce((t,
|
|
1347
|
+
enum: r.reduce((t, o) => [
|
|
1144
1348
|
...t,
|
|
1145
|
-
...
|
|
1349
|
+
...o._def.values.filter((i) => !t.includes(i))
|
|
1146
1350
|
], [])
|
|
1147
1351
|
};
|
|
1148
|
-
return
|
|
1352
|
+
return H(a, e);
|
|
1149
1353
|
}
|
|
1150
|
-
const
|
|
1151
|
-
const r = (
|
|
1354
|
+
const H = (a, e) => {
|
|
1355
|
+
const r = (a.options instanceof Map ? Array.from(a.options.values()) : a.options).map((t, o) => k(t._def, {
|
|
1152
1356
|
...e,
|
|
1153
|
-
currentPath: [...e.currentPath, "anyOf", `${
|
|
1357
|
+
currentPath: [...e.currentPath, "anyOf", `${o}`]
|
|
1154
1358
|
})).filter((t) => !!t && (!e.strictUnions || typeof t == "object" && Object.keys(t).length > 0));
|
|
1155
1359
|
return r.length ? { anyOf: r } : void 0;
|
|
1156
1360
|
};
|
|
1157
|
-
function
|
|
1158
|
-
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(
|
|
1361
|
+
function ft(a, e) {
|
|
1362
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(a.innerType._def.typeName) && (!a.innerType._def.checks || !a.innerType._def.checks.length))
|
|
1159
1363
|
return e.target === "openApi3" ? {
|
|
1160
|
-
type:
|
|
1364
|
+
type: Z[a.innerType._def.typeName],
|
|
1161
1365
|
nullable: !0
|
|
1162
1366
|
} : {
|
|
1163
1367
|
type: [
|
|
1164
|
-
|
|
1368
|
+
Z[a.innerType._def.typeName],
|
|
1165
1369
|
"null"
|
|
1166
1370
|
]
|
|
1167
1371
|
};
|
|
1168
1372
|
if (e.target === "openApi3") {
|
|
1169
|
-
const t = k(
|
|
1373
|
+
const t = k(a.innerType._def, {
|
|
1170
1374
|
...e,
|
|
1171
1375
|
currentPath: [...e.currentPath]
|
|
1172
1376
|
});
|
|
1173
1377
|
return t && "$ref" in t ? { allOf: [t], nullable: !0 } : t && { ...t, nullable: !0 };
|
|
1174
1378
|
}
|
|
1175
|
-
const r = k(
|
|
1379
|
+
const r = k(a.innerType._def, {
|
|
1176
1380
|
...e,
|
|
1177
1381
|
currentPath: [...e.currentPath, "anyOf", "0"]
|
|
1178
1382
|
});
|
|
1179
1383
|
return r && { anyOf: [r, { type: "null" }] };
|
|
1180
1384
|
}
|
|
1181
|
-
function
|
|
1385
|
+
function yt(a, e) {
|
|
1182
1386
|
const r = {
|
|
1183
1387
|
type: "number"
|
|
1184
1388
|
};
|
|
1185
|
-
if (!
|
|
1389
|
+
if (!a.checks)
|
|
1186
1390
|
return r;
|
|
1187
|
-
for (const t of
|
|
1391
|
+
for (const t of a.checks)
|
|
1188
1392
|
switch (t.kind) {
|
|
1189
1393
|
case "int":
|
|
1190
|
-
r.type = "integer",
|
|
1394
|
+
r.type = "integer", ee(r, "type", t.message, e);
|
|
1191
1395
|
break;
|
|
1192
1396
|
case "min":
|
|
1193
|
-
e.target === "jsonSchema7" ? t.inclusive ?
|
|
1397
|
+
e.target === "jsonSchema7" ? t.inclusive ? S(r, "minimum", t.value, t.message, e) : S(r, "exclusiveMinimum", t.value, t.message, e) : (t.inclusive || (r.exclusiveMinimum = !0), S(r, "minimum", t.value, t.message, e));
|
|
1194
1398
|
break;
|
|
1195
1399
|
case "max":
|
|
1196
|
-
e.target === "jsonSchema7" ? t.inclusive ?
|
|
1400
|
+
e.target === "jsonSchema7" ? t.inclusive ? S(r, "maximum", t.value, t.message, e) : S(r, "exclusiveMaximum", t.value, t.message, e) : (t.inclusive || (r.exclusiveMaximum = !0), S(r, "maximum", t.value, t.message, e));
|
|
1197
1401
|
break;
|
|
1198
1402
|
case "multipleOf":
|
|
1199
|
-
|
|
1403
|
+
S(r, "multipleOf", t.value, t.message, e);
|
|
1200
1404
|
break;
|
|
1201
1405
|
}
|
|
1202
1406
|
return r;
|
|
1203
1407
|
}
|
|
1204
|
-
function
|
|
1408
|
+
function bt(a, e) {
|
|
1205
1409
|
const r = e.target === "openAi", t = {
|
|
1206
1410
|
type: "object",
|
|
1207
1411
|
properties: {}
|
|
1208
|
-
},
|
|
1412
|
+
}, o = [], i = a.shape();
|
|
1209
1413
|
for (const l in i) {
|
|
1210
1414
|
let c = i[l];
|
|
1211
1415
|
if (c === void 0 || c._def === void 0)
|
|
1212
1416
|
continue;
|
|
1213
|
-
let
|
|
1214
|
-
|
|
1215
|
-
const
|
|
1417
|
+
let u = Et(c);
|
|
1418
|
+
u && r && (c._def.typeName === "ZodOptional" && (c = c._def.innerType), c.isNullable() || (c = c.nullable()), u = !1);
|
|
1419
|
+
const m = k(c._def, {
|
|
1216
1420
|
...e,
|
|
1217
1421
|
currentPath: [...e.currentPath, "properties", l],
|
|
1218
1422
|
propertyPath: [...e.currentPath, "properties", l]
|
|
1219
1423
|
});
|
|
1220
|
-
|
|
1424
|
+
m !== void 0 && (t.properties[l] = m, u || o.push(l));
|
|
1221
1425
|
}
|
|
1222
|
-
|
|
1223
|
-
const s =
|
|
1426
|
+
o.length && (t.required = o);
|
|
1427
|
+
const s = wt(a, e);
|
|
1224
1428
|
return s !== void 0 && (t.additionalProperties = s), t;
|
|
1225
1429
|
}
|
|
1226
|
-
function
|
|
1227
|
-
if (
|
|
1228
|
-
return k(
|
|
1430
|
+
function wt(a, e) {
|
|
1431
|
+
if (a.catchall._def.typeName !== "ZodNever")
|
|
1432
|
+
return k(a.catchall._def, {
|
|
1229
1433
|
...e,
|
|
1230
1434
|
currentPath: [...e.currentPath, "additionalProperties"]
|
|
1231
1435
|
});
|
|
1232
|
-
switch (
|
|
1436
|
+
switch (a.unknownKeys) {
|
|
1233
1437
|
case "passthrough":
|
|
1234
1438
|
return e.allowedAdditionalProperties;
|
|
1235
1439
|
case "strict":
|
|
@@ -1238,155 +1442,155 @@ function Xe(n, e) {
|
|
|
1238
1442
|
return e.removeAdditionalStrategy === "strict" ? e.allowedAdditionalProperties : e.rejectedAdditionalProperties;
|
|
1239
1443
|
}
|
|
1240
1444
|
}
|
|
1241
|
-
function
|
|
1445
|
+
function Et(a) {
|
|
1242
1446
|
try {
|
|
1243
|
-
return
|
|
1447
|
+
return a.isOptional();
|
|
1244
1448
|
} catch {
|
|
1245
1449
|
return !0;
|
|
1246
1450
|
}
|
|
1247
1451
|
}
|
|
1248
|
-
const
|
|
1452
|
+
const At = (a, e) => {
|
|
1249
1453
|
var t;
|
|
1250
1454
|
if (e.currentPath.toString() === ((t = e.propertyPath) == null ? void 0 : t.toString()))
|
|
1251
|
-
return k(
|
|
1252
|
-
const r = k(
|
|
1455
|
+
return k(a.innerType._def, e);
|
|
1456
|
+
const r = k(a.innerType._def, {
|
|
1253
1457
|
...e,
|
|
1254
1458
|
currentPath: [...e.currentPath, "anyOf", "1"]
|
|
1255
1459
|
});
|
|
1256
1460
|
return r ? {
|
|
1257
1461
|
anyOf: [
|
|
1258
1462
|
{
|
|
1259
|
-
not:
|
|
1463
|
+
not: x(e)
|
|
1260
1464
|
},
|
|
1261
1465
|
r
|
|
1262
1466
|
]
|
|
1263
|
-
} :
|
|
1264
|
-
},
|
|
1467
|
+
} : x(e);
|
|
1468
|
+
}, kt = (a, e) => {
|
|
1265
1469
|
if (e.pipeStrategy === "input")
|
|
1266
|
-
return k(
|
|
1470
|
+
return k(a.in._def, e);
|
|
1267
1471
|
if (e.pipeStrategy === "output")
|
|
1268
|
-
return k(
|
|
1269
|
-
const r = k(
|
|
1472
|
+
return k(a.out._def, e);
|
|
1473
|
+
const r = k(a.in._def, {
|
|
1270
1474
|
...e,
|
|
1271
1475
|
currentPath: [...e.currentPath, "allOf", "0"]
|
|
1272
|
-
}), t = k(
|
|
1476
|
+
}), t = k(a.out._def, {
|
|
1273
1477
|
...e,
|
|
1274
1478
|
currentPath: [...e.currentPath, "allOf", r ? "1" : "0"]
|
|
1275
1479
|
});
|
|
1276
1480
|
return {
|
|
1277
|
-
allOf: [r, t].filter((
|
|
1481
|
+
allOf: [r, t].filter((o) => o !== void 0)
|
|
1278
1482
|
};
|
|
1279
1483
|
};
|
|
1280
|
-
function
|
|
1281
|
-
return k(
|
|
1484
|
+
function vt(a, e) {
|
|
1485
|
+
return k(a.type._def, e);
|
|
1282
1486
|
}
|
|
1283
|
-
function
|
|
1487
|
+
function St(a, e) {
|
|
1284
1488
|
const t = {
|
|
1285
1489
|
type: "array",
|
|
1286
1490
|
uniqueItems: !0,
|
|
1287
|
-
items: k(
|
|
1491
|
+
items: k(a.valueType._def, {
|
|
1288
1492
|
...e,
|
|
1289
1493
|
currentPath: [...e.currentPath, "items"]
|
|
1290
1494
|
})
|
|
1291
1495
|
};
|
|
1292
|
-
return
|
|
1496
|
+
return a.minSize && S(t, "minItems", a.minSize.value, a.minSize.message, e), a.maxSize && S(t, "maxItems", a.maxSize.value, a.maxSize.message, e), t;
|
|
1293
1497
|
}
|
|
1294
|
-
function
|
|
1295
|
-
return
|
|
1498
|
+
function _t(a, e) {
|
|
1499
|
+
return a.rest ? {
|
|
1296
1500
|
type: "array",
|
|
1297
|
-
minItems:
|
|
1298
|
-
items:
|
|
1501
|
+
minItems: a.items.length,
|
|
1502
|
+
items: a.items.map((r, t) => k(r._def, {
|
|
1299
1503
|
...e,
|
|
1300
1504
|
currentPath: [...e.currentPath, "items", `${t}`]
|
|
1301
1505
|
})).reduce((r, t) => t === void 0 ? r : [...r, t], []),
|
|
1302
|
-
additionalItems: k(
|
|
1506
|
+
additionalItems: k(a.rest._def, {
|
|
1303
1507
|
...e,
|
|
1304
1508
|
currentPath: [...e.currentPath, "additionalItems"]
|
|
1305
1509
|
})
|
|
1306
1510
|
} : {
|
|
1307
1511
|
type: "array",
|
|
1308
|
-
minItems:
|
|
1309
|
-
maxItems:
|
|
1310
|
-
items:
|
|
1512
|
+
minItems: a.items.length,
|
|
1513
|
+
maxItems: a.items.length,
|
|
1514
|
+
items: a.items.map((r, t) => k(r._def, {
|
|
1311
1515
|
...e,
|
|
1312
1516
|
currentPath: [...e.currentPath, "items", `${t}`]
|
|
1313
1517
|
})).reduce((r, t) => t === void 0 ? r : [...r, t], [])
|
|
1314
1518
|
};
|
|
1315
1519
|
}
|
|
1316
|
-
function
|
|
1520
|
+
function Tt(a) {
|
|
1317
1521
|
return {
|
|
1318
|
-
not:
|
|
1522
|
+
not: x(a)
|
|
1319
1523
|
};
|
|
1320
1524
|
}
|
|
1321
|
-
function
|
|
1322
|
-
return
|
|
1525
|
+
function Ot(a) {
|
|
1526
|
+
return x(a);
|
|
1323
1527
|
}
|
|
1324
|
-
const
|
|
1528
|
+
const xt = (a, e) => k(a.innerType._def, e), It = (a, e, r) => {
|
|
1325
1529
|
switch (e) {
|
|
1326
1530
|
case y.ZodString:
|
|
1327
|
-
return
|
|
1531
|
+
return ae(a, r);
|
|
1328
1532
|
case y.ZodNumber:
|
|
1329
|
-
return
|
|
1533
|
+
return yt(a, r);
|
|
1330
1534
|
case y.ZodObject:
|
|
1331
|
-
return
|
|
1535
|
+
return bt(a, r);
|
|
1332
1536
|
case y.ZodBigInt:
|
|
1333
|
-
return
|
|
1537
|
+
return Qe(a, r);
|
|
1334
1538
|
case y.ZodBoolean:
|
|
1335
|
-
return
|
|
1539
|
+
return et();
|
|
1336
1540
|
case y.ZodDate:
|
|
1337
|
-
return
|
|
1541
|
+
return ne(a, r);
|
|
1338
1542
|
case y.ZodUndefined:
|
|
1339
|
-
return
|
|
1543
|
+
return Tt(r);
|
|
1340
1544
|
case y.ZodNull:
|
|
1341
|
-
return
|
|
1545
|
+
return gt(r);
|
|
1342
1546
|
case y.ZodArray:
|
|
1343
|
-
return
|
|
1547
|
+
return Xe(a, r);
|
|
1344
1548
|
case y.ZodUnion:
|
|
1345
1549
|
case y.ZodDiscriminatedUnion:
|
|
1346
|
-
return
|
|
1550
|
+
return ht(a, r);
|
|
1347
1551
|
case y.ZodIntersection:
|
|
1348
|
-
return
|
|
1552
|
+
return st(a, r);
|
|
1349
1553
|
case y.ZodTuple:
|
|
1350
|
-
return
|
|
1554
|
+
return _t(a, r);
|
|
1351
1555
|
case y.ZodRecord:
|
|
1352
|
-
return
|
|
1556
|
+
return oe(a, r);
|
|
1353
1557
|
case y.ZodLiteral:
|
|
1354
|
-
return
|
|
1558
|
+
return ct(a, r);
|
|
1355
1559
|
case y.ZodEnum:
|
|
1356
|
-
return
|
|
1560
|
+
return ot(a);
|
|
1357
1561
|
case y.ZodNativeEnum:
|
|
1358
|
-
return
|
|
1562
|
+
return dt(a);
|
|
1359
1563
|
case y.ZodNullable:
|
|
1360
|
-
return
|
|
1564
|
+
return ft(a, r);
|
|
1361
1565
|
case y.ZodOptional:
|
|
1362
|
-
return
|
|
1566
|
+
return At(a, r);
|
|
1363
1567
|
case y.ZodMap:
|
|
1364
|
-
return
|
|
1568
|
+
return mt(a, r);
|
|
1365
1569
|
case y.ZodSet:
|
|
1366
|
-
return
|
|
1570
|
+
return St(a, r);
|
|
1367
1571
|
case y.ZodLazy:
|
|
1368
|
-
return () =>
|
|
1572
|
+
return () => a.getter()._def;
|
|
1369
1573
|
case y.ZodPromise:
|
|
1370
|
-
return
|
|
1574
|
+
return vt(a, r);
|
|
1371
1575
|
case y.ZodNaN:
|
|
1372
1576
|
case y.ZodNever:
|
|
1373
|
-
return
|
|
1577
|
+
return pt(r);
|
|
1374
1578
|
case y.ZodEffects:
|
|
1375
|
-
return
|
|
1579
|
+
return at(a, r);
|
|
1376
1580
|
case y.ZodAny:
|
|
1377
|
-
return
|
|
1581
|
+
return x(r);
|
|
1378
1582
|
case y.ZodUnknown:
|
|
1379
|
-
return
|
|
1583
|
+
return Ot(r);
|
|
1380
1584
|
case y.ZodDefault:
|
|
1381
|
-
return
|
|
1585
|
+
return nt(a, r);
|
|
1382
1586
|
case y.ZodBranded:
|
|
1383
|
-
return
|
|
1587
|
+
return re(a, r);
|
|
1384
1588
|
case y.ZodReadonly:
|
|
1385
|
-
return
|
|
1589
|
+
return xt(a, r);
|
|
1386
1590
|
case y.ZodCatch:
|
|
1387
|
-
return
|
|
1591
|
+
return tt(a, r);
|
|
1388
1592
|
case y.ZodPipeline:
|
|
1389
|
-
return
|
|
1593
|
+
return kt(a, r);
|
|
1390
1594
|
case y.ZodFunction:
|
|
1391
1595
|
case y.ZodVoid:
|
|
1392
1596
|
case y.ZodSymbol:
|
|
@@ -1396,51 +1600,51 @@ const st = (n, e) => k(n.innerType._def, e), ct = (n, e, r) => {
|
|
|
1396
1600
|
})();
|
|
1397
1601
|
}
|
|
1398
1602
|
};
|
|
1399
|
-
function k(
|
|
1603
|
+
function k(a, e, r = !1) {
|
|
1400
1604
|
var l;
|
|
1401
|
-
const t = e.seen.get(
|
|
1605
|
+
const t = e.seen.get(a);
|
|
1402
1606
|
if (e.override) {
|
|
1403
|
-
const c = (l = e.override) == null ? void 0 : l.call(e,
|
|
1404
|
-
if (c !==
|
|
1607
|
+
const c = (l = e.override) == null ? void 0 : l.call(e, a, e, t, r);
|
|
1608
|
+
if (c !== Ge)
|
|
1405
1609
|
return c;
|
|
1406
1610
|
}
|
|
1407
1611
|
if (t && !r) {
|
|
1408
|
-
const c =
|
|
1612
|
+
const c = Pt(t, e);
|
|
1409
1613
|
if (c !== void 0)
|
|
1410
1614
|
return c;
|
|
1411
1615
|
}
|
|
1412
|
-
const
|
|
1413
|
-
e.seen.set(
|
|
1414
|
-
const i =
|
|
1415
|
-
if (s &&
|
|
1416
|
-
const c = e.postProcess(s,
|
|
1417
|
-
return
|
|
1616
|
+
const o = { def: a, path: e.currentPath, jsonSchema: void 0 };
|
|
1617
|
+
e.seen.set(a, o);
|
|
1618
|
+
const i = It(a, a.typeName, e), s = typeof i == "function" ? k(i(), e) : i;
|
|
1619
|
+
if (s && jt(a, e, s), e.postProcess) {
|
|
1620
|
+
const c = e.postProcess(s, a, e);
|
|
1621
|
+
return o.jsonSchema = s, c;
|
|
1418
1622
|
}
|
|
1419
|
-
return
|
|
1623
|
+
return o.jsonSchema = s, s;
|
|
1420
1624
|
}
|
|
1421
|
-
const
|
|
1625
|
+
const Pt = (a, e) => {
|
|
1422
1626
|
switch (e.$refStrategy) {
|
|
1423
1627
|
case "root":
|
|
1424
|
-
return { $ref:
|
|
1628
|
+
return { $ref: a.path.join("/") };
|
|
1425
1629
|
case "relative":
|
|
1426
|
-
return { $ref:
|
|
1630
|
+
return { $ref: te(e.currentPath, a.path) };
|
|
1427
1631
|
case "none":
|
|
1428
1632
|
case "seen":
|
|
1429
|
-
return
|
|
1633
|
+
return a.path.length < e.currentPath.length && a.path.every((r, t) => e.currentPath[t] === r) ? (console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`), x(e)) : e.$refStrategy === "seen" ? x(e) : void 0;
|
|
1430
1634
|
}
|
|
1431
|
-
},
|
|
1432
|
-
const r =
|
|
1433
|
-
let t = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce((c, [
|
|
1635
|
+
}, jt = (a, e, r) => (a.description && (r.description = a.description, e.markdownDescription && (r.markdownDescription = a.description)), r), Rt = (a, e) => {
|
|
1636
|
+
const r = He(e);
|
|
1637
|
+
let t = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce((c, [u, m]) => ({
|
|
1434
1638
|
...c,
|
|
1435
|
-
[
|
|
1639
|
+
[u]: k(m._def, {
|
|
1436
1640
|
...r,
|
|
1437
|
-
currentPath: [...r.basePath, r.definitionPath,
|
|
1438
|
-
}, !0) ??
|
|
1641
|
+
currentPath: [...r.basePath, r.definitionPath, u]
|
|
1642
|
+
}, !0) ?? x(r)
|
|
1439
1643
|
}), {}) : void 0;
|
|
1440
|
-
const
|
|
1644
|
+
const o = typeof e == "string" ? e : (e == null ? void 0 : e.nameStrategy) === "title" || e == null ? void 0 : e.name, i = k(a._def, o === void 0 ? r : {
|
|
1441
1645
|
...r,
|
|
1442
|
-
currentPath: [...r.basePath, r.definitionPath,
|
|
1443
|
-
}, !1) ??
|
|
1646
|
+
currentPath: [...r.basePath, r.definitionPath, o]
|
|
1647
|
+
}, !1) ?? x(r), s = typeof e == "object" && e.name !== void 0 && e.nameStrategy === "title" ? e.name : void 0;
|
|
1444
1648
|
s !== void 0 && (i.title = s), r.flags.hasReferencedOpenAiAnyType && (t || (t = {}), t[r.openAiAnyTypeName] || (t[r.openAiAnyTypeName] = {
|
|
1445
1649
|
// Skipping "object" as no properties can be defined and additionalProperties must be "false"
|
|
1446
1650
|
type: ["string", "number", "integer", "boolean", "array", "null"],
|
|
@@ -1452,52 +1656,52 @@ const lt = (n, e) => {
|
|
|
1452
1656
|
].join("/")
|
|
1453
1657
|
}
|
|
1454
1658
|
}));
|
|
1455
|
-
const l =
|
|
1659
|
+
const l = o === void 0 ? t ? {
|
|
1456
1660
|
...i,
|
|
1457
1661
|
[r.definitionPath]: t
|
|
1458
1662
|
} : i : {
|
|
1459
1663
|
$ref: [
|
|
1460
1664
|
...r.$refStrategy === "relative" ? [] : r.basePath,
|
|
1461
1665
|
r.definitionPath,
|
|
1462
|
-
|
|
1666
|
+
o
|
|
1463
1667
|
].join("/"),
|
|
1464
1668
|
[r.definitionPath]: {
|
|
1465
1669
|
...t,
|
|
1466
|
-
[
|
|
1670
|
+
[o]: i
|
|
1467
1671
|
}
|
|
1468
1672
|
};
|
|
1469
1673
|
return r.target === "jsonSchema7" ? l.$schema = "http://json-schema.org/draft-07/schema#" : (r.target === "jsonSchema2019-09" || r.target === "openAi") && (l.$schema = "https://json-schema.org/draft/2019-09/schema#"), r.target === "openAi" && ("anyOf" in l || "oneOf" in l || "allOf" in l || "type" in l && Array.isArray(l.type)) && console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."), l;
|
|
1470
1674
|
};
|
|
1471
|
-
function
|
|
1472
|
-
const e =
|
|
1675
|
+
function Wt(a) {
|
|
1676
|
+
const e = Rt(a.parameters, { target: "jsonSchema7", $refStrategy: "none" });
|
|
1473
1677
|
return {
|
|
1474
|
-
name:
|
|
1475
|
-
description:
|
|
1678
|
+
name: a.name,
|
|
1679
|
+
description: a.description,
|
|
1476
1680
|
parameters: e
|
|
1477
1681
|
};
|
|
1478
1682
|
}
|
|
1479
|
-
function
|
|
1683
|
+
function Nt(a) {
|
|
1480
1684
|
const e = /* @__PURE__ */ new Set(["$schema", "additionalProperties", "default"]), r = (t) => Array.isArray(t) ? t.map(r) : t && typeof t == "object" ? Object.fromEntries(
|
|
1481
|
-
Object.entries(t).filter(([
|
|
1685
|
+
Object.entries(t).filter(([o]) => !e.has(o)).map(([o, i]) => [o, r(i)])
|
|
1482
1686
|
) : t;
|
|
1483
|
-
return r(
|
|
1687
|
+
return r(a);
|
|
1484
1688
|
}
|
|
1485
|
-
class
|
|
1689
|
+
class Dt {
|
|
1486
1690
|
async *streamChat(e, r, t) {
|
|
1487
1691
|
var g, h, w, f;
|
|
1488
|
-
const { apiKey:
|
|
1489
|
-
if (!
|
|
1692
|
+
const { apiKey: o, model: i = "gemini-1.5-flash" } = r;
|
|
1693
|
+
if (!o) throw new Error("Gemini API key required");
|
|
1490
1694
|
const s = e.find((b) => b.role === "system"), l = e.filter((b) => b.role !== "system").map((b) => ({ role: b.role === "assistant" ? "model" : "user", parts: [{ text: b.content }] })), c = t != null && t.length ? [{
|
|
1491
1695
|
functionDeclarations: t.map((b) => ({
|
|
1492
1696
|
name: b.name,
|
|
1493
1697
|
description: b.description,
|
|
1494
|
-
parameters:
|
|
1698
|
+
parameters: Nt(b.parameters)
|
|
1495
1699
|
}))
|
|
1496
|
-
}] : void 0,
|
|
1700
|
+
}] : void 0, u = await fetch(
|
|
1497
1701
|
`https://generativelanguage.googleapis.com/v1beta/models/${i}:streamGenerateContent?alt=sse`,
|
|
1498
1702
|
{
|
|
1499
1703
|
method: "POST",
|
|
1500
|
-
headers: { "Content-Type": "application/json", "x-goog-api-key":
|
|
1704
|
+
headers: { "Content-Type": "application/json", "x-goog-api-key": o },
|
|
1501
1705
|
body: JSON.stringify({
|
|
1502
1706
|
contents: l,
|
|
1503
1707
|
...s && { systemInstruction: { parts: [{ text: s.content }] } },
|
|
@@ -1505,30 +1709,30 @@ class pt {
|
|
|
1505
1709
|
})
|
|
1506
1710
|
}
|
|
1507
1711
|
);
|
|
1508
|
-
if (!
|
|
1509
|
-
const b = await
|
|
1510
|
-
throw new Error(`Gemini Error ${
|
|
1712
|
+
if (!u.ok) {
|
|
1713
|
+
const b = await u.text();
|
|
1714
|
+
throw new Error(`Gemini Error ${u.status}: ${b}`);
|
|
1511
1715
|
}
|
|
1512
|
-
const
|
|
1513
|
-
if (!
|
|
1514
|
-
const
|
|
1716
|
+
const m = (g = u.body) == null ? void 0 : g.getReader();
|
|
1717
|
+
if (!m) throw new Error("No response body");
|
|
1718
|
+
const d = new TextDecoder();
|
|
1515
1719
|
let p = "";
|
|
1516
1720
|
for (; ; ) {
|
|
1517
|
-
const { done: b, value: A } = await
|
|
1721
|
+
const { done: b, value: A } = await m.read();
|
|
1518
1722
|
if (b) break;
|
|
1519
|
-
p +=
|
|
1520
|
-
const
|
|
1723
|
+
p += d.decode(A, { stream: !0 });
|
|
1724
|
+
const T = p.split(`
|
|
1521
1725
|
`);
|
|
1522
|
-
p =
|
|
1523
|
-
for (const E of
|
|
1524
|
-
const
|
|
1525
|
-
if (!(!
|
|
1726
|
+
p = T.pop() || "";
|
|
1727
|
+
for (const E of T) {
|
|
1728
|
+
const v = E.trim();
|
|
1729
|
+
if (!(!v || !v.startsWith("data: ")))
|
|
1526
1730
|
try {
|
|
1527
|
-
const D = ((f = (w = (h = JSON.parse(
|
|
1528
|
-
for (const
|
|
1529
|
-
|
|
1731
|
+
const D = ((f = (w = (h = JSON.parse(v.slice(6)).candidates) == null ? void 0 : h[0]) == null ? void 0 : w.content) == null ? void 0 : f.parts) ?? [];
|
|
1732
|
+
for (const N of D)
|
|
1733
|
+
N.text && (yield { type: "text-delta", text: N.text }), N.functionCall && (yield {
|
|
1530
1734
|
type: "tool-call",
|
|
1531
|
-
toolCall: { name:
|
|
1735
|
+
toolCall: { name: N.functionCall.name, arguments: N.functionCall.args ?? {} }
|
|
1532
1736
|
});
|
|
1533
1737
|
} catch {
|
|
1534
1738
|
}
|
|
@@ -1536,12 +1740,12 @@ class pt {
|
|
|
1536
1740
|
}
|
|
1537
1741
|
}
|
|
1538
1742
|
async generateText(e, r) {
|
|
1539
|
-
var c,
|
|
1540
|
-
const { apiKey: t, model:
|
|
1743
|
+
var c, u, m, d, p;
|
|
1744
|
+
const { apiKey: t, model: o = "gemini-1.5-flash", temperature: i = 0.7 } = r;
|
|
1541
1745
|
if (!t) throw new Error("Gemini API key required");
|
|
1542
|
-
if (!
|
|
1746
|
+
if (!o) throw new Error("GeminiAdapter: model is required but was undefined");
|
|
1543
1747
|
const s = await fetch(
|
|
1544
|
-
`https://generativelanguage.googleapis.com/v1beta/models/${
|
|
1748
|
+
`https://generativelanguage.googleapis.com/v1beta/models/${o}:generateContent`,
|
|
1545
1749
|
{
|
|
1546
1750
|
method: "POST",
|
|
1547
1751
|
headers: {
|
|
@@ -1558,15 +1762,15 @@ class pt {
|
|
|
1558
1762
|
const g = await s.text();
|
|
1559
1763
|
throw new Error(`Gemini Error ${s.status}: ${g}`);
|
|
1560
1764
|
}
|
|
1561
|
-
return ((p = (
|
|
1765
|
+
return ((p = (d = (m = (u = (c = (await s.json()).candidates) == null ? void 0 : c[0]) == null ? void 0 : u.content) == null ? void 0 : m.parts) == null ? void 0 : d[0]) == null ? void 0 : p.text) || "";
|
|
1562
1766
|
}
|
|
1563
1767
|
async *streamText(e, r) {
|
|
1564
|
-
var
|
|
1565
|
-
const { apiKey: t, model:
|
|
1768
|
+
var u, m, d, p, g, h;
|
|
1769
|
+
const { apiKey: t, model: o = "gemini-1.5-flash" } = r;
|
|
1566
1770
|
if (!t) throw new Error("Gemini API key required");
|
|
1567
|
-
if (!
|
|
1771
|
+
if (!o) throw new Error("GeminiAdapter: model is required but was undefined");
|
|
1568
1772
|
const i = await fetch(
|
|
1569
|
-
`https://generativelanguage.googleapis.com/v1beta/models/${
|
|
1773
|
+
`https://generativelanguage.googleapis.com/v1beta/models/${o}:streamGenerateContent?alt=sse`,
|
|
1570
1774
|
{
|
|
1571
1775
|
method: "POST",
|
|
1572
1776
|
headers: {
|
|
@@ -1582,7 +1786,7 @@ class pt {
|
|
|
1582
1786
|
const w = await i.text();
|
|
1583
1787
|
throw new Error(`Gemini Error ${i.status}: ${w}`);
|
|
1584
1788
|
}
|
|
1585
|
-
const s = (
|
|
1789
|
+
const s = (u = i.body) == null ? void 0 : u.getReader();
|
|
1586
1790
|
if (!s) throw new Error("No response body");
|
|
1587
1791
|
const l = new TextDecoder();
|
|
1588
1792
|
let c = "";
|
|
@@ -1594,11 +1798,11 @@ class pt {
|
|
|
1594
1798
|
`);
|
|
1595
1799
|
c = b.pop() || "";
|
|
1596
1800
|
for (const A of b) {
|
|
1597
|
-
const
|
|
1598
|
-
if (!(!
|
|
1801
|
+
const T = A.trim();
|
|
1802
|
+
if (!(!T || !T.startsWith("data: ")))
|
|
1599
1803
|
try {
|
|
1600
|
-
const
|
|
1601
|
-
|
|
1804
|
+
const v = (h = (g = (p = (d = (m = JSON.parse(T.slice(6)).candidates) == null ? void 0 : m[0]) == null ? void 0 : d.content) == null ? void 0 : p.parts) == null ? void 0 : g[0]) == null ? void 0 : h.text;
|
|
1805
|
+
v && (yield v);
|
|
1602
1806
|
} catch {
|
|
1603
1807
|
continue;
|
|
1604
1808
|
}
|
|
@@ -1606,9 +1810,9 @@ class pt {
|
|
|
1606
1810
|
}
|
|
1607
1811
|
}
|
|
1608
1812
|
async generateObject(e, r, t) {
|
|
1609
|
-
var
|
|
1610
|
-
const { apiKey:
|
|
1611
|
-
if (!
|
|
1813
|
+
var u, m, d, p, g;
|
|
1814
|
+
const { apiKey: o, model: i = "gemini-1.5-flash" } = t;
|
|
1815
|
+
if (!o) throw new Error("Gemini API key required");
|
|
1612
1816
|
if (!i) throw new Error("GeminiAdapter: model is required but was undefined");
|
|
1613
1817
|
const s = await fetch(
|
|
1614
1818
|
`https://generativelanguage.googleapis.com/v1beta/models/${i}:generateContent`,
|
|
@@ -1616,7 +1820,7 @@ class pt {
|
|
|
1616
1820
|
method: "POST",
|
|
1617
1821
|
headers: {
|
|
1618
1822
|
"Content-Type": "application/json",
|
|
1619
|
-
"x-goog-api-key":
|
|
1823
|
+
"x-goog-api-key": o
|
|
1620
1824
|
},
|
|
1621
1825
|
body: JSON.stringify({
|
|
1622
1826
|
contents: [{ parts: [{ text: e }] }],
|
|
@@ -1631,11 +1835,11 @@ class pt {
|
|
|
1631
1835
|
const h = await s.json();
|
|
1632
1836
|
throw this.normalizeError(h, s.status);
|
|
1633
1837
|
}
|
|
1634
|
-
const c = ((g = (p = (
|
|
1838
|
+
const c = ((g = (p = (d = (m = (u = (await s.json()).candidates) == null ? void 0 : u[0]) == null ? void 0 : m.content) == null ? void 0 : d.parts) == null ? void 0 : p[0]) == null ? void 0 : g.text) || "{}";
|
|
1635
1839
|
return JSON.parse(c);
|
|
1636
1840
|
}
|
|
1637
1841
|
async listModels(e) {
|
|
1638
|
-
var
|
|
1842
|
+
var o;
|
|
1639
1843
|
if (!e) throw new Error("API key required to list models");
|
|
1640
1844
|
const r = await fetch(
|
|
1641
1845
|
"https://generativelanguage.googleapis.com/v1beta/models",
|
|
@@ -1645,22 +1849,22 @@ class pt {
|
|
|
1645
1849
|
);
|
|
1646
1850
|
if (!r.ok)
|
|
1647
1851
|
throw new Error("Failed to fetch model list");
|
|
1648
|
-
return ((
|
|
1852
|
+
return ((o = (await r.json()).models) == null ? void 0 : o.map((i) => i.name)) || [];
|
|
1649
1853
|
}
|
|
1650
1854
|
normalizeError(e, r) {
|
|
1651
1855
|
var t;
|
|
1652
1856
|
if (r === 429) {
|
|
1653
|
-
const
|
|
1654
|
-
return
|
|
1857
|
+
const o = new Error("Rate limit exceeded. Please wait 30 seconds before retrying.");
|
|
1858
|
+
return o.code = "RATE_LIMIT", o;
|
|
1655
1859
|
}
|
|
1656
1860
|
if (r === 401 || r === 403) {
|
|
1657
|
-
const
|
|
1658
|
-
return
|
|
1861
|
+
const o = new Error("Invalid API key.");
|
|
1862
|
+
return o.code = "AUTH_ERROR", o;
|
|
1659
1863
|
}
|
|
1660
1864
|
return new Error(((t = e.error) == null ? void 0 : t.message) || "Unknown error");
|
|
1661
1865
|
}
|
|
1662
1866
|
}
|
|
1663
|
-
class
|
|
1867
|
+
class Mt {
|
|
1664
1868
|
/**
|
|
1665
1869
|
* Tool calling requires /api/chat, not /api/generate (which has no tool
|
|
1666
1870
|
* support at all). Tool support itself is model-dependent (llama3.1+,
|
|
@@ -1669,8 +1873,8 @@ class gt {
|
|
|
1669
1873
|
* this degrades gracefully rather than special-casing it.
|
|
1670
1874
|
*/
|
|
1671
1875
|
async *streamChat(e, r, t) {
|
|
1672
|
-
var
|
|
1673
|
-
const { baseUrl:
|
|
1876
|
+
var d, p, g, h, w;
|
|
1877
|
+
const { baseUrl: o = "http://localhost:11434", model: i = "llama3.2" } = r, s = t != null && t.length ? t.map((f) => ({ type: "function", function: { name: f.name, description: f.description, parameters: f.parameters } })) : void 0, l = await fetch(`${o}/api/chat`, {
|
|
1674
1878
|
method: "POST",
|
|
1675
1879
|
headers: { "Content-Type": "application/json" },
|
|
1676
1880
|
body: JSON.stringify({
|
|
@@ -1684,27 +1888,27 @@ class gt {
|
|
|
1684
1888
|
const f = await l.text();
|
|
1685
1889
|
throw new Error(`Ollama Error ${l.status}: ${f}`);
|
|
1686
1890
|
}
|
|
1687
|
-
const c = (
|
|
1891
|
+
const c = (d = l.body) == null ? void 0 : d.getReader();
|
|
1688
1892
|
if (!c) throw new Error("No response body");
|
|
1689
|
-
const
|
|
1690
|
-
let
|
|
1893
|
+
const u = new TextDecoder();
|
|
1894
|
+
let m = "";
|
|
1691
1895
|
for (; ; ) {
|
|
1692
1896
|
const { done: f, value: b } = await c.read();
|
|
1693
1897
|
if (f) break;
|
|
1694
|
-
|
|
1695
|
-
const A =
|
|
1898
|
+
m += u.decode(b, { stream: !0 });
|
|
1899
|
+
const A = m.split(`
|
|
1696
1900
|
`);
|
|
1697
|
-
|
|
1698
|
-
for (const
|
|
1699
|
-
const E =
|
|
1901
|
+
m = A.pop() || "";
|
|
1902
|
+
for (const T of A) {
|
|
1903
|
+
const E = T.trim();
|
|
1700
1904
|
if (E)
|
|
1701
1905
|
try {
|
|
1702
|
-
const
|
|
1703
|
-
if ((p =
|
|
1704
|
-
for (const
|
|
1906
|
+
const v = JSON.parse(E);
|
|
1907
|
+
if ((p = v.message) != null && p.content && (yield { type: "text-delta", text: v.message.content }), (g = v.message) != null && g.tool_calls)
|
|
1908
|
+
for (const R of v.message.tool_calls)
|
|
1705
1909
|
yield {
|
|
1706
1910
|
type: "tool-call",
|
|
1707
|
-
toolCall: { name: (h =
|
|
1911
|
+
toolCall: { name: (h = R.function) == null ? void 0 : h.name, arguments: ((w = R.function) == null ? void 0 : w.arguments) ?? {} }
|
|
1708
1912
|
};
|
|
1709
1913
|
} catch {
|
|
1710
1914
|
}
|
|
@@ -1712,11 +1916,11 @@ class gt {
|
|
|
1712
1916
|
}
|
|
1713
1917
|
}
|
|
1714
1918
|
async generateText(e, r) {
|
|
1715
|
-
const { baseUrl: t = "http://localhost:11434", model:
|
|
1919
|
+
const { baseUrl: t = "http://localhost:11434", model: o = "llama3.2" } = r, i = await fetch(`${t}/api/generate`, {
|
|
1716
1920
|
method: "POST",
|
|
1717
1921
|
headers: { "Content-Type": "application/json" },
|
|
1718
1922
|
body: JSON.stringify({
|
|
1719
|
-
model:
|
|
1923
|
+
model: o,
|
|
1720
1924
|
prompt: e,
|
|
1721
1925
|
stream: !1
|
|
1722
1926
|
})
|
|
@@ -1728,28 +1932,28 @@ class gt {
|
|
|
1728
1932
|
return (await i.json()).response;
|
|
1729
1933
|
}
|
|
1730
1934
|
async *streamText(e, r) {
|
|
1731
|
-
var
|
|
1732
|
-
const { baseUrl: t = "http://localhost:11434", model:
|
|
1935
|
+
var u;
|
|
1936
|
+
const { baseUrl: t = "http://localhost:11434", model: o = "llama3.2" } = r, i = await fetch(`${t}/api/generate`, {
|
|
1733
1937
|
method: "POST",
|
|
1734
1938
|
headers: { "Content-Type": "application/json" },
|
|
1735
1939
|
body: JSON.stringify({
|
|
1736
|
-
model:
|
|
1940
|
+
model: o,
|
|
1737
1941
|
prompt: e,
|
|
1738
1942
|
stream: !0
|
|
1739
1943
|
})
|
|
1740
1944
|
});
|
|
1741
1945
|
if (!i.ok) {
|
|
1742
|
-
const
|
|
1743
|
-
throw new Error(`Ollama Error ${i.status}: ${
|
|
1946
|
+
const m = await i.text();
|
|
1947
|
+
throw new Error(`Ollama Error ${i.status}: ${m}`);
|
|
1744
1948
|
}
|
|
1745
|
-
const s = (
|
|
1949
|
+
const s = (u = i.body) == null ? void 0 : u.getReader();
|
|
1746
1950
|
if (!s) throw new Error("No response body");
|
|
1747
1951
|
const l = new TextDecoder();
|
|
1748
1952
|
let c = "";
|
|
1749
1953
|
for (; ; ) {
|
|
1750
|
-
const { done:
|
|
1751
|
-
if (
|
|
1752
|
-
c += l.decode(
|
|
1954
|
+
const { done: m, value: d } = await s.read();
|
|
1955
|
+
if (m) break;
|
|
1956
|
+
c += l.decode(d, { stream: !0 });
|
|
1753
1957
|
const p = c.split(`
|
|
1754
1958
|
`);
|
|
1755
1959
|
c = p.pop() || "";
|
|
@@ -1766,12 +1970,12 @@ class gt {
|
|
|
1766
1970
|
}
|
|
1767
1971
|
}
|
|
1768
1972
|
async generateObject(e, r, t) {
|
|
1769
|
-
const
|
|
1973
|
+
const o = `${e}
|
|
1770
1974
|
|
|
1771
1975
|
IMPORTANT: Return ONLY valid JSON matching this schema:
|
|
1772
1976
|
${JSON.stringify(r, null, 2)}
|
|
1773
1977
|
|
|
1774
|
-
Do not include any explanation, only the raw JSON object.`, i = await this.generateText(
|
|
1978
|
+
Do not include any explanation, only the raw JSON object.`, i = await this.generateText(o, t), s = i.match(/```json\n?([\s\S]*?)\n?```/) || i.match(/\{[\s\S]*\}/), l = s ? s[1] || s[0] : i;
|
|
1775
1979
|
return JSON.parse(l.trim());
|
|
1776
1980
|
}
|
|
1777
1981
|
async listModels(e, r = "http://localhost:11434") {
|
|
@@ -1782,33 +1986,33 @@ Do not include any explanation, only the raw JSON object.`, i = await this.gener
|
|
|
1782
1986
|
return ((i = (await t.json()).models) == null ? void 0 : i.map((s) => s.name)) || [];
|
|
1783
1987
|
}
|
|
1784
1988
|
}
|
|
1785
|
-
class
|
|
1989
|
+
class $t {
|
|
1786
1990
|
async *streamChat(e, r, t) {
|
|
1787
|
-
var b, A,
|
|
1991
|
+
var b, A, T;
|
|
1788
1992
|
const {
|
|
1789
|
-
apiKey:
|
|
1993
|
+
apiKey: o,
|
|
1790
1994
|
model: i = "claude-sonnet-4-5-20250929",
|
|
1791
1995
|
temperature: s = 0.7,
|
|
1792
1996
|
maxTokens: l = 4096,
|
|
1793
1997
|
baseUrl: c = "https://api.anthropic.com/v1"
|
|
1794
1998
|
} = r;
|
|
1795
|
-
if (!
|
|
1796
|
-
const
|
|
1999
|
+
if (!o) throw new Error("Anthropic API key required");
|
|
2000
|
+
const u = e.find((E) => E.role === "system"), m = e.filter((E) => E.role !== "system").map((E) => ({ role: E.role, content: E.content })), d = t != null && t.length ? t.map((E) => ({ name: E.name, description: E.description, input_schema: E.parameters })) : void 0, p = await fetch(`${c}/messages`, {
|
|
1797
2001
|
method: "POST",
|
|
1798
2002
|
headers: {
|
|
1799
2003
|
"Content-Type": "application/json",
|
|
1800
|
-
"x-api-key":
|
|
2004
|
+
"x-api-key": o,
|
|
1801
2005
|
"anthropic-version": "2023-06-01",
|
|
1802
2006
|
"anthropic-dangerous-direct-browser-access": "true"
|
|
1803
2007
|
},
|
|
1804
2008
|
body: JSON.stringify({
|
|
1805
2009
|
model: i,
|
|
1806
|
-
messages:
|
|
1807
|
-
...
|
|
2010
|
+
messages: m,
|
|
2011
|
+
...u && { system: u.content },
|
|
1808
2012
|
max_tokens: l,
|
|
1809
2013
|
temperature: s,
|
|
1810
2014
|
stream: !0,
|
|
1811
|
-
...
|
|
2015
|
+
...d && { tools: d }
|
|
1812
2016
|
})
|
|
1813
2017
|
});
|
|
1814
2018
|
if (!p.ok) {
|
|
@@ -1820,22 +2024,22 @@ class ht {
|
|
|
1820
2024
|
let w = "", f = null;
|
|
1821
2025
|
try {
|
|
1822
2026
|
for (; ; ) {
|
|
1823
|
-
const { done: E, value:
|
|
2027
|
+
const { done: E, value: v } = await g.read();
|
|
1824
2028
|
if (E) break;
|
|
1825
|
-
w += h.decode(
|
|
1826
|
-
const
|
|
2029
|
+
w += h.decode(v, { stream: !0 });
|
|
2030
|
+
const R = w.split(`
|
|
1827
2031
|
`);
|
|
1828
|
-
w =
|
|
1829
|
-
for (const D of
|
|
1830
|
-
const
|
|
1831
|
-
if (!(!
|
|
2032
|
+
w = R.pop() || "";
|
|
2033
|
+
for (const D of R) {
|
|
2034
|
+
const N = D.trim();
|
|
2035
|
+
if (!(!N || !N.startsWith("data: ")))
|
|
1832
2036
|
try {
|
|
1833
|
-
const
|
|
1834
|
-
if (
|
|
1835
|
-
f = { id:
|
|
1836
|
-
else if (
|
|
1837
|
-
((A =
|
|
1838
|
-
else if (
|
|
2037
|
+
const I = JSON.parse(N.slice(6));
|
|
2038
|
+
if (I.type === "content_block_start" && ((b = I.content_block) == null ? void 0 : b.type) === "tool_use")
|
|
2039
|
+
f = { id: I.content_block.id, name: I.content_block.name, argsBuf: "" };
|
|
2040
|
+
else if (I.type === "content_block_delta")
|
|
2041
|
+
((A = I.delta) == null ? void 0 : A.type) === "text_delta" && I.delta.text ? yield { type: "text-delta", text: I.delta.text } : ((T = I.delta) == null ? void 0 : T.type) === "input_json_delta" && f && (f.argsBuf += I.delta.partial_json ?? "");
|
|
2042
|
+
else if (I.type === "content_block_stop" && f) {
|
|
1839
2043
|
try {
|
|
1840
2044
|
yield {
|
|
1841
2045
|
type: "tool-call",
|
|
@@ -1858,18 +2062,18 @@ class ht {
|
|
|
1858
2062
|
}
|
|
1859
2063
|
}
|
|
1860
2064
|
async generateText(e, r) {
|
|
1861
|
-
var
|
|
2065
|
+
var m, d, p;
|
|
1862
2066
|
const {
|
|
1863
2067
|
apiKey: t,
|
|
1864
|
-
model:
|
|
2068
|
+
model: o = "claude-sonnet-4-5-20250929",
|
|
1865
2069
|
temperature: i = 0.7,
|
|
1866
2070
|
maxTokens: s = 4096,
|
|
1867
2071
|
baseUrl: l = "https://api.anthropic.com/v1"
|
|
1868
2072
|
} = r;
|
|
1869
2073
|
if (!t) throw new Error("Anthropic API key required");
|
|
1870
|
-
if (!
|
|
2074
|
+
if (!o) throw new Error("Model is required but was undefined");
|
|
1871
2075
|
console.log("🔵 Anthropic Request:", {
|
|
1872
|
-
model:
|
|
2076
|
+
model: o,
|
|
1873
2077
|
maxTokens: s,
|
|
1874
2078
|
temperature: i,
|
|
1875
2079
|
endpoint: `${l}/messages`,
|
|
@@ -1885,7 +2089,7 @@ class ht {
|
|
|
1885
2089
|
"anthropic-dangerous-direct-browser-access": "true"
|
|
1886
2090
|
},
|
|
1887
2091
|
body: JSON.stringify({
|
|
1888
|
-
model:
|
|
2092
|
+
model: o,
|
|
1889
2093
|
messages: [{ role: "user", content: e }],
|
|
1890
2094
|
max_tokens: s,
|
|
1891
2095
|
// REQUIRED by Anthropic
|
|
@@ -1894,27 +2098,27 @@ class ht {
|
|
|
1894
2098
|
});
|
|
1895
2099
|
if (!c.ok) {
|
|
1896
2100
|
const g = await c.text();
|
|
1897
|
-
console.error("🔴 RAW ANTHROPIC ERROR:", c.status, g), console.error("🔴 Request was made to:", `${l}/messages`), console.error("🔴 Model requested:",
|
|
2101
|
+
console.error("🔴 RAW ANTHROPIC ERROR:", c.status, g), console.error("🔴 Request was made to:", `${l}/messages`), console.error("🔴 Model requested:", o);
|
|
1898
2102
|
try {
|
|
1899
2103
|
const h = JSON.parse(g);
|
|
1900
|
-
throw new Error(`Anthropic ${c.status}: ${((
|
|
2104
|
+
throw new Error(`Anthropic ${c.status}: ${((m = h.error) == null ? void 0 : m.message) || JSON.stringify(h)}`);
|
|
1901
2105
|
} catch {
|
|
1902
2106
|
throw new Error(`Anthropic ${c.status}: ${g}`);
|
|
1903
2107
|
}
|
|
1904
2108
|
}
|
|
1905
|
-
return ((p = (
|
|
2109
|
+
return ((p = (d = (await c.json()).content) == null ? void 0 : d[0]) == null ? void 0 : p.text) || "";
|
|
1906
2110
|
}
|
|
1907
2111
|
async *streamText(e, r) {
|
|
1908
2112
|
var p, g;
|
|
1909
2113
|
const {
|
|
1910
2114
|
apiKey: t,
|
|
1911
|
-
model:
|
|
2115
|
+
model: o = "claude-sonnet-4-5-20250929",
|
|
1912
2116
|
temperature: i = 0.7,
|
|
1913
2117
|
maxTokens: s = 4096,
|
|
1914
2118
|
baseUrl: l = "https://api.anthropic.com/v1"
|
|
1915
2119
|
} = r;
|
|
1916
2120
|
if (!t) throw new Error("Anthropic API key required");
|
|
1917
|
-
if (!
|
|
2121
|
+
if (!o) throw new Error("Model is required but was undefined");
|
|
1918
2122
|
const c = await fetch(`${l}/messages`, {
|
|
1919
2123
|
method: "POST",
|
|
1920
2124
|
headers: {
|
|
@@ -1924,7 +2128,7 @@ class ht {
|
|
|
1924
2128
|
"anthropic-dangerous-direct-browser-access": "true"
|
|
1925
2129
|
},
|
|
1926
2130
|
body: JSON.stringify({
|
|
1927
|
-
model:
|
|
2131
|
+
model: o,
|
|
1928
2132
|
messages: [{ role: "user", content: e }],
|
|
1929
2133
|
max_tokens: s,
|
|
1930
2134
|
// REQUIRED by Anthropic
|
|
@@ -1934,7 +2138,7 @@ class ht {
|
|
|
1934
2138
|
});
|
|
1935
2139
|
if (!c.ok) {
|
|
1936
2140
|
const h = await c.text();
|
|
1937
|
-
console.error("🔴 RAW ANTHROPIC STREAM ERROR:", c.status, h), console.error("🔴 Request was made to:", `${l}/messages`), console.error("🔴 Model requested:",
|
|
2141
|
+
console.error("🔴 RAW ANTHROPIC STREAM ERROR:", c.status, h), console.error("🔴 Request was made to:", `${l}/messages`), console.error("🔴 Model requested:", o);
|
|
1938
2142
|
try {
|
|
1939
2143
|
const w = JSON.parse(h);
|
|
1940
2144
|
throw new Error(`Anthropic ${c.status}: ${((p = w.error) == null ? void 0 : p.message) || JSON.stringify(w)}`);
|
|
@@ -1943,22 +2147,22 @@ class ht {
|
|
|
1943
2147
|
}
|
|
1944
2148
|
}
|
|
1945
2149
|
if (!c.body) throw new Error("No response body for streaming");
|
|
1946
|
-
const
|
|
1947
|
-
let
|
|
2150
|
+
const u = c.body.getReader(), m = new TextDecoder();
|
|
2151
|
+
let d = "";
|
|
1948
2152
|
try {
|
|
1949
2153
|
for (; ; ) {
|
|
1950
|
-
const { done: h, value: w } = await
|
|
2154
|
+
const { done: h, value: w } = await u.read();
|
|
1951
2155
|
if (h) break;
|
|
1952
|
-
|
|
1953
|
-
const f =
|
|
2156
|
+
d += m.decode(w, { stream: !0 });
|
|
2157
|
+
const f = d.split(`
|
|
1954
2158
|
`);
|
|
1955
|
-
|
|
2159
|
+
d = f.pop() || "";
|
|
1956
2160
|
for (const b of f) {
|
|
1957
2161
|
const A = b.trim();
|
|
1958
2162
|
if (!A || !A.startsWith("data: ")) continue;
|
|
1959
|
-
const
|
|
2163
|
+
const T = A.slice(6);
|
|
1960
2164
|
try {
|
|
1961
|
-
const E = JSON.parse(
|
|
2165
|
+
const E = JSON.parse(T);
|
|
1962
2166
|
E.type === "content_block_delta" && ((g = E.delta) != null && g.text) && (yield E.delta.text);
|
|
1963
2167
|
} catch {
|
|
1964
2168
|
continue;
|
|
@@ -1966,23 +2170,23 @@ class ht {
|
|
|
1966
2170
|
}
|
|
1967
2171
|
}
|
|
1968
2172
|
} finally {
|
|
1969
|
-
|
|
2173
|
+
u.releaseLock();
|
|
1970
2174
|
}
|
|
1971
2175
|
}
|
|
1972
2176
|
async generateObject(e, r) {
|
|
1973
2177
|
var h, w, f;
|
|
1974
2178
|
const {
|
|
1975
2179
|
apiKey: t,
|
|
1976
|
-
model:
|
|
2180
|
+
model: o = "claude-sonnet-4-5-20250929",
|
|
1977
2181
|
temperature: i = 0.7,
|
|
1978
2182
|
maxTokens: s = 4096,
|
|
1979
2183
|
baseUrl: l = "https://api.anthropic.com/v1"
|
|
1980
2184
|
} = r;
|
|
1981
2185
|
if (!t) throw new Error("Anthropic API key required");
|
|
1982
|
-
if (!
|
|
2186
|
+
if (!o) throw new Error("Model is required but was undefined");
|
|
1983
2187
|
const c = `${e}
|
|
1984
2188
|
|
|
1985
|
-
IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the JSON object.`,
|
|
2189
|
+
IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the JSON object.`, u = await fetch(`${l}/messages`, {
|
|
1986
2190
|
method: "POST",
|
|
1987
2191
|
headers: {
|
|
1988
2192
|
"Content-Type": "application/json",
|
|
@@ -1991,24 +2195,24 @@ IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the J
|
|
|
1991
2195
|
"anthropic-dangerous-direct-browser-access": "true"
|
|
1992
2196
|
},
|
|
1993
2197
|
body: JSON.stringify({
|
|
1994
|
-
model:
|
|
2198
|
+
model: o,
|
|
1995
2199
|
messages: [{ role: "user", content: c }],
|
|
1996
2200
|
max_tokens: s,
|
|
1997
2201
|
// REQUIRED by Anthropic
|
|
1998
2202
|
temperature: i
|
|
1999
2203
|
})
|
|
2000
2204
|
});
|
|
2001
|
-
if (!
|
|
2002
|
-
const b = await
|
|
2003
|
-
console.error("🔴 RAW ANTHROPIC OBJECT ERROR:",
|
|
2205
|
+
if (!u.ok) {
|
|
2206
|
+
const b = await u.text();
|
|
2207
|
+
console.error("🔴 RAW ANTHROPIC OBJECT ERROR:", u.status, b), console.error("🔴 Request was made to:", `${l}/messages`), console.error("🔴 Model requested:", o);
|
|
2004
2208
|
try {
|
|
2005
2209
|
const A = JSON.parse(b);
|
|
2006
|
-
throw new Error(`Anthropic ${
|
|
2210
|
+
throw new Error(`Anthropic ${u.status}: ${((h = A.error) == null ? void 0 : h.message) || JSON.stringify(A)}`);
|
|
2007
2211
|
} catch {
|
|
2008
|
-
throw new Error(`Anthropic ${
|
|
2212
|
+
throw new Error(`Anthropic ${u.status}: ${b}`);
|
|
2009
2213
|
}
|
|
2010
2214
|
}
|
|
2011
|
-
const
|
|
2215
|
+
const d = ((f = (w = (await u.json()).content) == null ? void 0 : w[0]) == null ? void 0 : f.text) || "{}", p = d.match(/\{[\s\S]*\}/), g = p ? p[0] : d;
|
|
2012
2216
|
return JSON.parse(g);
|
|
2013
2217
|
}
|
|
2014
2218
|
async listModels(e, r) {
|
|
@@ -2034,30 +2238,30 @@ IMPORTANT: Respond ONLY with valid JSON. No markdown, no explanation, just the J
|
|
|
2034
2238
|
const s = new Error(`Bad request: ${t}`);
|
|
2035
2239
|
return s.code = "INVALID_REQUEST", s.status = 400, s;
|
|
2036
2240
|
}
|
|
2037
|
-
const
|
|
2038
|
-
return
|
|
2241
|
+
const o = new Error(t);
|
|
2242
|
+
return o.code = "API_ERROR", o.status = e, o;
|
|
2039
2243
|
}
|
|
2040
2244
|
}
|
|
2041
|
-
function L(
|
|
2042
|
-
if (!(!
|
|
2043
|
-
return
|
|
2245
|
+
function L(a) {
|
|
2246
|
+
if (!(!a || a.length === 0))
|
|
2247
|
+
return a.map((e) => ({
|
|
2044
2248
|
type: "function",
|
|
2045
2249
|
function: { name: e.name, description: e.description, parameters: e.parameters }
|
|
2046
2250
|
}));
|
|
2047
2251
|
}
|
|
2048
|
-
async function*
|
|
2049
|
-
var
|
|
2050
|
-
const
|
|
2252
|
+
async function* V(a, e, r, t) {
|
|
2253
|
+
var u, m, d, p;
|
|
2254
|
+
const o = await fetch(a, {
|
|
2051
2255
|
method: "POST",
|
|
2052
2256
|
headers: e,
|
|
2053
2257
|
body: JSON.stringify(r)
|
|
2054
2258
|
});
|
|
2055
|
-
if (!
|
|
2056
|
-
const g = await
|
|
2057
|
-
throw t(
|
|
2259
|
+
if (!o.ok) {
|
|
2260
|
+
const g = await o.json().catch(() => ({}));
|
|
2261
|
+
throw t(o.status, g);
|
|
2058
2262
|
}
|
|
2059
|
-
if (!
|
|
2060
|
-
const i =
|
|
2263
|
+
if (!o.body) throw new Error("No response body for streaming");
|
|
2264
|
+
const i = o.body.getReader(), s = new TextDecoder();
|
|
2061
2265
|
let l = "";
|
|
2062
2266
|
const c = /* @__PURE__ */ new Map();
|
|
2063
2267
|
try {
|
|
@@ -2074,12 +2278,12 @@ async function* B(n, e, r, t) {
|
|
|
2074
2278
|
const A = b.slice(6);
|
|
2075
2279
|
if (A !== "[DONE]")
|
|
2076
2280
|
try {
|
|
2077
|
-
const E = (
|
|
2281
|
+
const E = (m = (u = JSON.parse(A).choices) == null ? void 0 : u[0]) == null ? void 0 : m.delta;
|
|
2078
2282
|
if (!E) continue;
|
|
2079
2283
|
if (E.content && (yield { type: "text-delta", text: E.content }), E.tool_calls)
|
|
2080
|
-
for (const
|
|
2081
|
-
const
|
|
2082
|
-
|
|
2284
|
+
for (const v of E.tool_calls) {
|
|
2285
|
+
const R = v.index ?? 0, D = c.get(R) ?? { name: "", args: "" };
|
|
2286
|
+
v.id && (D.id = v.id), (d = v.function) != null && d.name && (D.name += v.function.name), (p = v.function) != null && p.arguments && (D.args += v.function.arguments), c.set(R, D);
|
|
2083
2287
|
}
|
|
2084
2288
|
} catch {
|
|
2085
2289
|
}
|
|
@@ -2102,19 +2306,19 @@ async function* B(n, e, r, t) {
|
|
|
2102
2306
|
} catch {
|
|
2103
2307
|
}
|
|
2104
2308
|
}
|
|
2105
|
-
function
|
|
2106
|
-
return
|
|
2309
|
+
function Y(a) {
|
|
2310
|
+
return a.map((e) => ({ role: e.role, content: e.content }));
|
|
2107
2311
|
}
|
|
2108
|
-
class
|
|
2312
|
+
class Lt {
|
|
2109
2313
|
async *streamChat(e, r, t) {
|
|
2110
|
-
const { apiKey:
|
|
2111
|
-
if (!
|
|
2112
|
-
yield*
|
|
2314
|
+
const { apiKey: o, model: i = "gpt-4o-mini", temperature: s = 0.7, baseUrl: l = "https://api.openai.com/v1" } = r;
|
|
2315
|
+
if (!o) throw new Error("OpenAI API key required");
|
|
2316
|
+
yield* V(
|
|
2113
2317
|
`${l}/chat/completions`,
|
|
2114
|
-
{ "Content-Type": "application/json", Authorization: `Bearer ${
|
|
2318
|
+
{ "Content-Type": "application/json", Authorization: `Bearer ${o}` },
|
|
2115
2319
|
{
|
|
2116
2320
|
model: i,
|
|
2117
|
-
messages:
|
|
2321
|
+
messages: Y(e),
|
|
2118
2322
|
temperature: s,
|
|
2119
2323
|
stream: !0,
|
|
2120
2324
|
...L(t) && { tools: L(t), tool_choice: "auto" }
|
|
@@ -2123,8 +2327,8 @@ class ft {
|
|
|
2123
2327
|
);
|
|
2124
2328
|
}
|
|
2125
2329
|
async generateText(e, r) {
|
|
2126
|
-
var
|
|
2127
|
-
const { apiKey: t, model:
|
|
2330
|
+
var u, m, d;
|
|
2331
|
+
const { apiKey: t, model: o = "gpt-4o-mini", temperature: i = 0.7, baseUrl: s = "https://api.openai.com/v1" } = r;
|
|
2128
2332
|
if (!t) throw new Error("OpenAI API key required");
|
|
2129
2333
|
const l = await fetch(`${s}/chat/completions`, {
|
|
2130
2334
|
method: "POST",
|
|
@@ -2133,7 +2337,7 @@ class ft {
|
|
|
2133
2337
|
Authorization: `Bearer ${t}`
|
|
2134
2338
|
},
|
|
2135
2339
|
body: JSON.stringify({
|
|
2136
|
-
model:
|
|
2340
|
+
model: o,
|
|
2137
2341
|
messages: [{ role: "user", content: e }],
|
|
2138
2342
|
temperature: i
|
|
2139
2343
|
})
|
|
@@ -2142,11 +2346,11 @@ class ft {
|
|
|
2142
2346
|
const p = await l.json();
|
|
2143
2347
|
throw this.normalizeError(l.status, p);
|
|
2144
2348
|
}
|
|
2145
|
-
return ((
|
|
2349
|
+
return ((d = (m = (u = (await l.json()).choices) == null ? void 0 : u[0]) == null ? void 0 : m.message) == null ? void 0 : d.content) || "";
|
|
2146
2350
|
}
|
|
2147
2351
|
async *streamText(e, r) {
|
|
2148
|
-
var
|
|
2149
|
-
const { apiKey: t, model:
|
|
2352
|
+
var d, p, g;
|
|
2353
|
+
const { apiKey: t, model: o = "gpt-4o-mini", temperature: i = 0.7, baseUrl: s = "https://api.openai.com/v1" } = r;
|
|
2150
2354
|
if (!t) throw new Error("OpenAI API key required");
|
|
2151
2355
|
const l = await fetch(`${s}/chat/completions`, {
|
|
2152
2356
|
method: "POST",
|
|
@@ -2155,7 +2359,7 @@ class ft {
|
|
|
2155
2359
|
Authorization: `Bearer ${t}`
|
|
2156
2360
|
},
|
|
2157
2361
|
body: JSON.stringify({
|
|
2158
|
-
model:
|
|
2362
|
+
model: o,
|
|
2159
2363
|
messages: [{ role: "user", content: e }],
|
|
2160
2364
|
temperature: i,
|
|
2161
2365
|
stream: !0
|
|
@@ -2166,24 +2370,24 @@ class ft {
|
|
|
2166
2370
|
throw this.normalizeError(l.status, h);
|
|
2167
2371
|
}
|
|
2168
2372
|
if (!l.body) throw new Error("No response body for streaming");
|
|
2169
|
-
const c = l.body.getReader(),
|
|
2170
|
-
let
|
|
2373
|
+
const c = l.body.getReader(), u = new TextDecoder();
|
|
2374
|
+
let m = "";
|
|
2171
2375
|
try {
|
|
2172
2376
|
for (; ; ) {
|
|
2173
2377
|
const { done: h, value: w } = await c.read();
|
|
2174
2378
|
if (h) break;
|
|
2175
|
-
|
|
2176
|
-
const f =
|
|
2379
|
+
m += u.decode(w, { stream: !0 });
|
|
2380
|
+
const f = m.split(`
|
|
2177
2381
|
`);
|
|
2178
|
-
|
|
2382
|
+
m = f.pop() || "";
|
|
2179
2383
|
for (const b of f) {
|
|
2180
2384
|
const A = b.trim();
|
|
2181
2385
|
if (!A || !A.startsWith("data: ")) continue;
|
|
2182
|
-
const
|
|
2183
|
-
if (
|
|
2386
|
+
const T = A.slice(6);
|
|
2387
|
+
if (T !== "[DONE]")
|
|
2184
2388
|
try {
|
|
2185
|
-
const
|
|
2186
|
-
|
|
2389
|
+
const v = (g = (p = (d = JSON.parse(T).choices) == null ? void 0 : d[0]) == null ? void 0 : p.delta) == null ? void 0 : g.content;
|
|
2390
|
+
v && (yield v);
|
|
2187
2391
|
} catch {
|
|
2188
2392
|
}
|
|
2189
2393
|
}
|
|
@@ -2193,14 +2397,14 @@ class ft {
|
|
|
2193
2397
|
}
|
|
2194
2398
|
}
|
|
2195
2399
|
async generateObject(e, r, t) {
|
|
2196
|
-
var
|
|
2197
|
-
const { apiKey:
|
|
2198
|
-
if (!
|
|
2400
|
+
var d, p, g;
|
|
2401
|
+
const { apiKey: o, model: i = "gpt-4o-mini", temperature: s = 0.7, baseUrl: l = "https://api.openai.com/v1" } = t;
|
|
2402
|
+
if (!o) throw new Error("OpenAI API key required");
|
|
2199
2403
|
const c = await fetch(`${l}/chat/completions`, {
|
|
2200
2404
|
method: "POST",
|
|
2201
2405
|
headers: {
|
|
2202
2406
|
"Content-Type": "application/json",
|
|
2203
|
-
Authorization: `Bearer ${
|
|
2407
|
+
Authorization: `Bearer ${o}`
|
|
2204
2408
|
},
|
|
2205
2409
|
body: JSON.stringify({
|
|
2206
2410
|
model: i,
|
|
@@ -2213,23 +2417,23 @@ class ft {
|
|
|
2213
2417
|
const h = await c.json();
|
|
2214
2418
|
throw this.normalizeError(c.status, h);
|
|
2215
2419
|
}
|
|
2216
|
-
const
|
|
2217
|
-
return JSON.parse(
|
|
2420
|
+
const m = ((g = (p = (d = (await c.json()).choices) == null ? void 0 : d[0]) == null ? void 0 : p.message) == null ? void 0 : g.content) || "{}";
|
|
2421
|
+
return JSON.parse(m);
|
|
2218
2422
|
}
|
|
2219
2423
|
async listModels(e, r) {
|
|
2220
2424
|
var s, l;
|
|
2221
2425
|
const t = r || "https://api.openai.com/v1";
|
|
2222
2426
|
if (!e) throw new Error("OpenAI API key required");
|
|
2223
|
-
const
|
|
2427
|
+
const o = await fetch(`${t}/models`, {
|
|
2224
2428
|
headers: {
|
|
2225
2429
|
Authorization: `Bearer ${e}`
|
|
2226
2430
|
}
|
|
2227
2431
|
});
|
|
2228
|
-
if (!
|
|
2229
|
-
const c = await
|
|
2230
|
-
throw this.normalizeError(
|
|
2432
|
+
if (!o.ok) {
|
|
2433
|
+
const c = await o.json();
|
|
2434
|
+
throw this.normalizeError(o.status, c);
|
|
2231
2435
|
}
|
|
2232
|
-
return ((l = (s = (await
|
|
2436
|
+
return ((l = (s = (await o.json()).data) == null ? void 0 : s.filter((c) => c.id.startsWith("gpt-"))) == null ? void 0 : l.map((c) => c.id)) || [];
|
|
2233
2437
|
}
|
|
2234
2438
|
normalizeError(e, r) {
|
|
2235
2439
|
var i;
|
|
@@ -2242,20 +2446,20 @@ class ft {
|
|
|
2242
2446
|
const s = new Error(`Authentication failed: ${t}`);
|
|
2243
2447
|
return s.code = "AUTH_ERROR", s.status = e, s;
|
|
2244
2448
|
}
|
|
2245
|
-
const
|
|
2246
|
-
return
|
|
2449
|
+
const o = new Error(t);
|
|
2450
|
+
return o.code = "API_ERROR", o.status = e, o;
|
|
2247
2451
|
}
|
|
2248
2452
|
}
|
|
2249
|
-
class
|
|
2453
|
+
class Ct {
|
|
2250
2454
|
async *streamChat(e, r, t) {
|
|
2251
|
-
const { apiKey:
|
|
2252
|
-
if (!
|
|
2253
|
-
yield*
|
|
2455
|
+
const { apiKey: o, model: i = "grok-beta", temperature: s = 0.7, baseUrl: l = "https://api.x.ai/v1" } = r;
|
|
2456
|
+
if (!o) throw new Error("Grok API key required");
|
|
2457
|
+
yield* V(
|
|
2254
2458
|
`${l}/chat/completions`,
|
|
2255
|
-
{ "Content-Type": "application/json", Authorization: `Bearer ${
|
|
2459
|
+
{ "Content-Type": "application/json", Authorization: `Bearer ${o}` },
|
|
2256
2460
|
{
|
|
2257
2461
|
model: i,
|
|
2258
|
-
messages:
|
|
2462
|
+
messages: Y(e),
|
|
2259
2463
|
temperature: s,
|
|
2260
2464
|
stream: !0,
|
|
2261
2465
|
...L(t) && { tools: L(t), tool_choice: "auto" }
|
|
@@ -2264,8 +2468,8 @@ class yt {
|
|
|
2264
2468
|
);
|
|
2265
2469
|
}
|
|
2266
2470
|
async generateText(e, r) {
|
|
2267
|
-
var
|
|
2268
|
-
const { apiKey: t, model:
|
|
2471
|
+
var u, m, d;
|
|
2472
|
+
const { apiKey: t, model: o = "grok-beta", temperature: i = 0.7, baseUrl: s = "https://api.x.ai/v1" } = r;
|
|
2269
2473
|
if (!t) throw new Error("Grok API key required");
|
|
2270
2474
|
const l = await fetch(`${s}/chat/completions`, {
|
|
2271
2475
|
method: "POST",
|
|
@@ -2274,7 +2478,7 @@ class yt {
|
|
|
2274
2478
|
Authorization: `Bearer ${t}`
|
|
2275
2479
|
},
|
|
2276
2480
|
body: JSON.stringify({
|
|
2277
|
-
model:
|
|
2481
|
+
model: o,
|
|
2278
2482
|
messages: [{ role: "user", content: e }],
|
|
2279
2483
|
temperature: i
|
|
2280
2484
|
})
|
|
@@ -2283,11 +2487,11 @@ class yt {
|
|
|
2283
2487
|
const p = await l.json();
|
|
2284
2488
|
throw this.normalizeError(l.status, p);
|
|
2285
2489
|
}
|
|
2286
|
-
return ((
|
|
2490
|
+
return ((d = (m = (u = (await l.json()).choices) == null ? void 0 : u[0]) == null ? void 0 : m.message) == null ? void 0 : d.content) || "";
|
|
2287
2491
|
}
|
|
2288
2492
|
async *streamText(e, r) {
|
|
2289
|
-
var
|
|
2290
|
-
const { apiKey: t, model:
|
|
2493
|
+
var d, p, g;
|
|
2494
|
+
const { apiKey: t, model: o = "grok-beta", temperature: i = 0.7, baseUrl: s = "https://api.x.ai/v1" } = r;
|
|
2291
2495
|
if (!t) throw new Error("Grok API key required");
|
|
2292
2496
|
const l = await fetch(`${s}/chat/completions`, {
|
|
2293
2497
|
method: "POST",
|
|
@@ -2296,7 +2500,7 @@ class yt {
|
|
|
2296
2500
|
Authorization: `Bearer ${t}`
|
|
2297
2501
|
},
|
|
2298
2502
|
body: JSON.stringify({
|
|
2299
|
-
model:
|
|
2503
|
+
model: o,
|
|
2300
2504
|
messages: [{ role: "user", content: e }],
|
|
2301
2505
|
temperature: i,
|
|
2302
2506
|
stream: !0
|
|
@@ -2307,24 +2511,24 @@ class yt {
|
|
|
2307
2511
|
throw this.normalizeError(l.status, h);
|
|
2308
2512
|
}
|
|
2309
2513
|
if (!l.body) throw new Error("No response body for streaming");
|
|
2310
|
-
const c = l.body.getReader(),
|
|
2311
|
-
let
|
|
2514
|
+
const c = l.body.getReader(), u = new TextDecoder();
|
|
2515
|
+
let m = "";
|
|
2312
2516
|
try {
|
|
2313
2517
|
for (; ; ) {
|
|
2314
2518
|
const { done: h, value: w } = await c.read();
|
|
2315
2519
|
if (h) break;
|
|
2316
|
-
|
|
2317
|
-
const f =
|
|
2520
|
+
m += u.decode(w, { stream: !0 });
|
|
2521
|
+
const f = m.split(`
|
|
2318
2522
|
`);
|
|
2319
|
-
|
|
2523
|
+
m = f.pop() || "";
|
|
2320
2524
|
for (const b of f) {
|
|
2321
2525
|
const A = b.trim();
|
|
2322
2526
|
if (!A || !A.startsWith("data: ")) continue;
|
|
2323
|
-
const
|
|
2324
|
-
if (
|
|
2527
|
+
const T = A.slice(6);
|
|
2528
|
+
if (T !== "[DONE]")
|
|
2325
2529
|
try {
|
|
2326
|
-
const
|
|
2327
|
-
|
|
2530
|
+
const v = (g = (p = (d = JSON.parse(T).choices) == null ? void 0 : d[0]) == null ? void 0 : p.delta) == null ? void 0 : g.content;
|
|
2531
|
+
v && (yield v);
|
|
2328
2532
|
} catch {
|
|
2329
2533
|
}
|
|
2330
2534
|
}
|
|
@@ -2335,15 +2539,15 @@ class yt {
|
|
|
2335
2539
|
}
|
|
2336
2540
|
async generateObject(e, r, t) {
|
|
2337
2541
|
var h, w, f;
|
|
2338
|
-
const { apiKey:
|
|
2339
|
-
if (!
|
|
2542
|
+
const { apiKey: o, model: i = "grok-beta", temperature: s = 0.7, baseUrl: l = "https://api.x.ai/v1" } = t;
|
|
2543
|
+
if (!o) throw new Error("Grok API key required");
|
|
2340
2544
|
const c = `${e}
|
|
2341
2545
|
|
|
2342
|
-
Respond with valid JSON only.`,
|
|
2546
|
+
Respond with valid JSON only.`, u = await fetch(`${l}/chat/completions`, {
|
|
2343
2547
|
method: "POST",
|
|
2344
2548
|
headers: {
|
|
2345
2549
|
"Content-Type": "application/json",
|
|
2346
|
-
Authorization: `Bearer ${
|
|
2550
|
+
Authorization: `Bearer ${o}`
|
|
2347
2551
|
},
|
|
2348
2552
|
body: JSON.stringify({
|
|
2349
2553
|
model: i,
|
|
@@ -2351,11 +2555,11 @@ Respond with valid JSON only.`, d = await fetch(`${l}/chat/completions`, {
|
|
|
2351
2555
|
temperature: s
|
|
2352
2556
|
})
|
|
2353
2557
|
});
|
|
2354
|
-
if (!
|
|
2355
|
-
const b = await
|
|
2356
|
-
throw this.normalizeError(
|
|
2558
|
+
if (!u.ok) {
|
|
2559
|
+
const b = await u.json();
|
|
2560
|
+
throw this.normalizeError(u.status, b);
|
|
2357
2561
|
}
|
|
2358
|
-
const
|
|
2562
|
+
const d = ((f = (w = (h = (await u.json()).choices) == null ? void 0 : h[0]) == null ? void 0 : w.message) == null ? void 0 : f.content) || "{}", p = d.match(/\{[\s\S]*\}/), g = p ? p[0] : d;
|
|
2359
2563
|
return JSON.parse(g);
|
|
2360
2564
|
}
|
|
2361
2565
|
async listModels(e, r) {
|
|
@@ -2372,20 +2576,20 @@ Respond with valid JSON only.`, d = await fetch(`${l}/chat/completions`, {
|
|
|
2372
2576
|
const s = new Error(`Authentication failed: ${t}`);
|
|
2373
2577
|
return s.code = "AUTH_ERROR", s.status = e, s;
|
|
2374
2578
|
}
|
|
2375
|
-
const
|
|
2376
|
-
return
|
|
2579
|
+
const o = new Error(t);
|
|
2580
|
+
return o.code = "API_ERROR", o.status = e, o;
|
|
2377
2581
|
}
|
|
2378
2582
|
}
|
|
2379
|
-
class
|
|
2583
|
+
class Ut {
|
|
2380
2584
|
async *streamChat(e, r, t) {
|
|
2381
|
-
const { apiKey:
|
|
2382
|
-
if (!
|
|
2383
|
-
yield*
|
|
2585
|
+
const { apiKey: o, model: i = "deepseek-chat", temperature: s = 0.7, baseUrl: l = "https://api.deepseek.com/v1" } = r;
|
|
2586
|
+
if (!o) throw new Error("DeepSeek API key required");
|
|
2587
|
+
yield* V(
|
|
2384
2588
|
`${l}/chat/completions`,
|
|
2385
|
-
{ "Content-Type": "application/json", Authorization: `Bearer ${
|
|
2589
|
+
{ "Content-Type": "application/json", Authorization: `Bearer ${o}` },
|
|
2386
2590
|
{
|
|
2387
2591
|
model: i,
|
|
2388
|
-
messages:
|
|
2592
|
+
messages: Y(e),
|
|
2389
2593
|
temperature: s,
|
|
2390
2594
|
stream: !0,
|
|
2391
2595
|
...L(t) && { tools: L(t), tool_choice: "auto" }
|
|
@@ -2394,8 +2598,8 @@ class bt {
|
|
|
2394
2598
|
);
|
|
2395
2599
|
}
|
|
2396
2600
|
async generateText(e, r) {
|
|
2397
|
-
var
|
|
2398
|
-
const { apiKey: t, model:
|
|
2601
|
+
var u, m, d;
|
|
2602
|
+
const { apiKey: t, model: o = "deepseek-chat", temperature: i = 0.7, baseUrl: s = "https://api.deepseek.com/v1" } = r;
|
|
2399
2603
|
if (!t) throw new Error("DeepSeek API key required");
|
|
2400
2604
|
const l = await fetch(`${s}/chat/completions`, {
|
|
2401
2605
|
method: "POST",
|
|
@@ -2404,7 +2608,7 @@ class bt {
|
|
|
2404
2608
|
Authorization: `Bearer ${t}`
|
|
2405
2609
|
},
|
|
2406
2610
|
body: JSON.stringify({
|
|
2407
|
-
model:
|
|
2611
|
+
model: o,
|
|
2408
2612
|
messages: [{ role: "user", content: e }],
|
|
2409
2613
|
temperature: i
|
|
2410
2614
|
})
|
|
@@ -2413,11 +2617,11 @@ class bt {
|
|
|
2413
2617
|
const p = await l.json();
|
|
2414
2618
|
throw this.normalizeError(l.status, p);
|
|
2415
2619
|
}
|
|
2416
|
-
return ((
|
|
2620
|
+
return ((d = (m = (u = (await l.json()).choices) == null ? void 0 : u[0]) == null ? void 0 : m.message) == null ? void 0 : d.content) || "";
|
|
2417
2621
|
}
|
|
2418
2622
|
async *streamText(e, r) {
|
|
2419
|
-
var
|
|
2420
|
-
const { apiKey: t, model:
|
|
2623
|
+
var d, p, g;
|
|
2624
|
+
const { apiKey: t, model: o = "deepseek-chat", temperature: i = 0.7, baseUrl: s = "https://api.deepseek.com/v1" } = r;
|
|
2421
2625
|
if (!t) throw new Error("DeepSeek API key required");
|
|
2422
2626
|
const l = await fetch(`${s}/chat/completions`, {
|
|
2423
2627
|
method: "POST",
|
|
@@ -2426,7 +2630,7 @@ class bt {
|
|
|
2426
2630
|
Authorization: `Bearer ${t}`
|
|
2427
2631
|
},
|
|
2428
2632
|
body: JSON.stringify({
|
|
2429
|
-
model:
|
|
2633
|
+
model: o,
|
|
2430
2634
|
messages: [{ role: "user", content: e }],
|
|
2431
2635
|
temperature: i,
|
|
2432
2636
|
stream: !0
|
|
@@ -2437,24 +2641,24 @@ class bt {
|
|
|
2437
2641
|
throw this.normalizeError(l.status, h);
|
|
2438
2642
|
}
|
|
2439
2643
|
if (!l.body) throw new Error("No response body for streaming");
|
|
2440
|
-
const c = l.body.getReader(),
|
|
2441
|
-
let
|
|
2644
|
+
const c = l.body.getReader(), u = new TextDecoder();
|
|
2645
|
+
let m = "";
|
|
2442
2646
|
try {
|
|
2443
2647
|
for (; ; ) {
|
|
2444
2648
|
const { done: h, value: w } = await c.read();
|
|
2445
2649
|
if (h) break;
|
|
2446
|
-
|
|
2447
|
-
const f =
|
|
2650
|
+
m += u.decode(w, { stream: !0 });
|
|
2651
|
+
const f = m.split(`
|
|
2448
2652
|
`);
|
|
2449
|
-
|
|
2653
|
+
m = f.pop() || "";
|
|
2450
2654
|
for (const b of f) {
|
|
2451
2655
|
const A = b.trim();
|
|
2452
2656
|
if (!A || !A.startsWith("data: ")) continue;
|
|
2453
|
-
const
|
|
2454
|
-
if (
|
|
2657
|
+
const T = A.slice(6);
|
|
2658
|
+
if (T !== "[DONE]")
|
|
2455
2659
|
try {
|
|
2456
|
-
const
|
|
2457
|
-
|
|
2660
|
+
const v = (g = (p = (d = JSON.parse(T).choices) == null ? void 0 : d[0]) == null ? void 0 : p.delta) == null ? void 0 : g.content;
|
|
2661
|
+
v && (yield v);
|
|
2458
2662
|
} catch {
|
|
2459
2663
|
}
|
|
2460
2664
|
}
|
|
@@ -2464,14 +2668,14 @@ class bt {
|
|
|
2464
2668
|
}
|
|
2465
2669
|
}
|
|
2466
2670
|
async generateObject(e, r, t) {
|
|
2467
|
-
var
|
|
2468
|
-
const { apiKey:
|
|
2469
|
-
if (!
|
|
2671
|
+
var d, p, g;
|
|
2672
|
+
const { apiKey: o, model: i = "deepseek-chat", temperature: s = 0.7, baseUrl: l = "https://api.deepseek.com/v1" } = t;
|
|
2673
|
+
if (!o) throw new Error("DeepSeek API key required");
|
|
2470
2674
|
const c = await fetch(`${l}/chat/completions`, {
|
|
2471
2675
|
method: "POST",
|
|
2472
2676
|
headers: {
|
|
2473
2677
|
"Content-Type": "application/json",
|
|
2474
|
-
Authorization: `Bearer ${
|
|
2678
|
+
Authorization: `Bearer ${o}`
|
|
2475
2679
|
},
|
|
2476
2680
|
body: JSON.stringify({
|
|
2477
2681
|
model: i,
|
|
@@ -2484,8 +2688,8 @@ class bt {
|
|
|
2484
2688
|
const h = await c.json();
|
|
2485
2689
|
throw this.normalizeError(c.status, h);
|
|
2486
2690
|
}
|
|
2487
|
-
const
|
|
2488
|
-
return JSON.parse(
|
|
2691
|
+
const m = ((g = (p = (d = (await c.json()).choices) == null ? void 0 : d[0]) == null ? void 0 : p.message) == null ? void 0 : g.content) || "{}";
|
|
2692
|
+
return JSON.parse(m);
|
|
2489
2693
|
}
|
|
2490
2694
|
async listModels(e, r) {
|
|
2491
2695
|
return ["deepseek-chat", "deepseek-coder"];
|
|
@@ -2501,11 +2705,11 @@ class bt {
|
|
|
2501
2705
|
const s = new Error(`Authentication failed: ${t}`);
|
|
2502
2706
|
return s.code = "AUTH_ERROR", s.status = e, s;
|
|
2503
2707
|
}
|
|
2504
|
-
const
|
|
2505
|
-
return
|
|
2708
|
+
const o = new Error(t);
|
|
2709
|
+
return o.code = "API_ERROR", o.status = e, o;
|
|
2506
2710
|
}
|
|
2507
2711
|
}
|
|
2508
|
-
let
|
|
2712
|
+
let Zt = class {
|
|
2509
2713
|
constructor(e) {
|
|
2510
2714
|
this.requests = [], this.config = e;
|
|
2511
2715
|
}
|
|
@@ -2523,16 +2727,16 @@ let wt = class {
|
|
|
2523
2727
|
};
|
|
2524
2728
|
class $ {
|
|
2525
2729
|
constructor() {
|
|
2526
|
-
this.rateLimiter = new
|
|
2730
|
+
this.rateLimiter = new Zt({
|
|
2527
2731
|
maxRequests: 10,
|
|
2528
2732
|
windowMs: 6e4
|
|
2529
2733
|
}), this.adapters = /* @__PURE__ */ new Map([
|
|
2530
|
-
["google-gemini", new
|
|
2531
|
-
["ollama", new
|
|
2532
|
-
["anthropic", new
|
|
2533
|
-
["openai", new
|
|
2534
|
-
["grok", new
|
|
2535
|
-
["deepseek", new
|
|
2734
|
+
["google-gemini", new Dt()],
|
|
2735
|
+
["ollama", new Mt()],
|
|
2736
|
+
["anthropic", new $t()],
|
|
2737
|
+
["openai", new Lt()],
|
|
2738
|
+
["grok", new Ct()],
|
|
2739
|
+
["deepseek", new Ut()]
|
|
2536
2740
|
]);
|
|
2537
2741
|
}
|
|
2538
2742
|
static getInstance() {
|
|
@@ -2543,16 +2747,16 @@ class $ {
|
|
|
2543
2747
|
*/
|
|
2544
2748
|
async generateText(e, r) {
|
|
2545
2749
|
if (!this.rateLimiter.checkLimit()) {
|
|
2546
|
-
const
|
|
2547
|
-
throw i.code = "RATE_LIMIT_EXCEEDED", i.resetTime =
|
|
2750
|
+
const o = this.rateLimiter.getResetTime(), i = new Error("Rate limit exceeded. Please wait before making another request.");
|
|
2751
|
+
throw i.code = "RATE_LIMIT_EXCEEDED", i.resetTime = o, i;
|
|
2548
2752
|
}
|
|
2549
2753
|
const t = this.adapters.get(r.provider);
|
|
2550
2754
|
if (!t)
|
|
2551
2755
|
throw new Error(`Provider ${r.provider} not supported yet.`);
|
|
2552
2756
|
try {
|
|
2553
2757
|
return await t.generateText(e, r);
|
|
2554
|
-
} catch (
|
|
2555
|
-
throw console.error("[AiGateway] Error:",
|
|
2758
|
+
} catch (o) {
|
|
2759
|
+
throw console.error("[AiGateway] Error:", o), o;
|
|
2556
2760
|
}
|
|
2557
2761
|
}
|
|
2558
2762
|
/**
|
|
@@ -2560,8 +2764,8 @@ class $ {
|
|
|
2560
2764
|
*/
|
|
2561
2765
|
async *streamText(e, r) {
|
|
2562
2766
|
if (!this.rateLimiter.checkLimit()) {
|
|
2563
|
-
const
|
|
2564
|
-
throw
|
|
2767
|
+
const o = new Error("Rate limit exceeded");
|
|
2768
|
+
throw o.code = "RATE_LIMIT_EXCEEDED", o;
|
|
2565
2769
|
}
|
|
2566
2770
|
const t = this.adapters.get(r.provider);
|
|
2567
2771
|
if (!t)
|
|
@@ -2577,12 +2781,12 @@ class $ {
|
|
|
2577
2781
|
const i = new Error("Rate limit exceeded");
|
|
2578
2782
|
throw i.code = "RATE_LIMIT_EXCEEDED", i;
|
|
2579
2783
|
}
|
|
2580
|
-
const
|
|
2581
|
-
if (!
|
|
2784
|
+
const o = this.adapters.get(r.provider);
|
|
2785
|
+
if (!o)
|
|
2582
2786
|
throw new Error(`Provider ${r.provider} not supported yet.`);
|
|
2583
|
-
if (!
|
|
2787
|
+
if (!o.streamChat)
|
|
2584
2788
|
throw new Error(`Provider ${r.provider} does not implement native chat streaming yet.`);
|
|
2585
|
-
yield*
|
|
2789
|
+
yield* o.streamChat(e, r, t);
|
|
2586
2790
|
}
|
|
2587
2791
|
/**
|
|
2588
2792
|
* Generate structured object (JSON mode)
|
|
@@ -2592,10 +2796,10 @@ class $ {
|
|
|
2592
2796
|
const i = new Error("Rate limit exceeded");
|
|
2593
2797
|
throw i.code = "RATE_LIMIT_EXCEEDED", i;
|
|
2594
2798
|
}
|
|
2595
|
-
const
|
|
2596
|
-
if (!
|
|
2799
|
+
const o = this.adapters.get(t.provider);
|
|
2800
|
+
if (!o)
|
|
2597
2801
|
throw new Error(`Provider ${t.provider} not supported yet.`);
|
|
2598
|
-
return
|
|
2802
|
+
return o.generateObject(e, r, t);
|
|
2599
2803
|
}
|
|
2600
2804
|
/**
|
|
2601
2805
|
* Get remaining requests before rate limit
|
|
@@ -2607,14 +2811,14 @@ class $ {
|
|
|
2607
2811
|
* List available models for a provider
|
|
2608
2812
|
*/
|
|
2609
2813
|
async listModels(e, r, t) {
|
|
2610
|
-
const
|
|
2611
|
-
if (!
|
|
2814
|
+
const o = this.adapters.get(e);
|
|
2815
|
+
if (!o)
|
|
2612
2816
|
throw new Error(`Provider ${e} not supported yet.`);
|
|
2613
|
-
return
|
|
2817
|
+
return o.listModels(r, t);
|
|
2614
2818
|
}
|
|
2615
2819
|
}
|
|
2616
|
-
const
|
|
2617
|
-
class
|
|
2820
|
+
const Xt = $.getInstance(), M = {};
|
|
2821
|
+
class Qt {
|
|
2618
2822
|
/**
|
|
2619
2823
|
* Resolve configuration with 3-tier priority:
|
|
2620
2824
|
* 1. User's localStorage override (highest priority)
|
|
@@ -2622,12 +2826,12 @@ class Rt {
|
|
|
2622
2826
|
* 3. System defaults (fallback)
|
|
2623
2827
|
*/
|
|
2624
2828
|
static resolve(e, r) {
|
|
2625
|
-
const t = (e == null ? void 0 : e.provider) || (r == null ? void 0 : r.provider) || "ollama",
|
|
2829
|
+
const t = (e == null ? void 0 : e.provider) || (r == null ? void 0 : r.provider) || "ollama", o = (e == null ? void 0 : e.model) || (r == null ? void 0 : r.model) || this.getDefaultModel(t), i = (e == null ? void 0 : e.apiKey) || (r == null ? void 0 : r.apiKey), s = (e == null ? void 0 : e.ollamaUrl) || (r == null ? void 0 : r.ollamaUrl) || "/ollama";
|
|
2626
2830
|
if (t !== "ollama" && !i)
|
|
2627
2831
|
throw new Error(`API key required for provider: ${t}`);
|
|
2628
2832
|
return {
|
|
2629
2833
|
provider: t,
|
|
2630
|
-
model:
|
|
2834
|
+
model: o,
|
|
2631
2835
|
apiKey: i,
|
|
2632
2836
|
baseUrl: t === "ollama" ? s : void 0
|
|
2633
2837
|
};
|
|
@@ -2659,21 +2863,21 @@ class Rt {
|
|
|
2659
2863
|
* Never call this from UI components; use hasEnvKey() for status badges.
|
|
2660
2864
|
*/
|
|
2661
2865
|
static getEnvKeyForProvider(e) {
|
|
2662
|
-
var t,
|
|
2866
|
+
var t, o, i, s, l;
|
|
2663
2867
|
if (typeof import.meta < "u" && M) {
|
|
2664
|
-
const c = M,
|
|
2868
|
+
const c = M, u = (d) => (d == null ? void 0 : d.trim()) || void 0;
|
|
2665
2869
|
return {
|
|
2666
|
-
"google-gemini":
|
|
2667
|
-
openai:
|
|
2668
|
-
anthropic:
|
|
2669
|
-
grok:
|
|
2670
|
-
deepseek:
|
|
2870
|
+
"google-gemini": u(c == null ? void 0 : c.VITE_DEFAULT_GEMINI_KEY),
|
|
2871
|
+
openai: u(c == null ? void 0 : c.VITE_DEFAULT_OPENAI_KEY),
|
|
2872
|
+
anthropic: u(c == null ? void 0 : c.VITE_DEFAULT_ANTHROPIC_KEY),
|
|
2873
|
+
grok: u(c == null ? void 0 : c.VITE_DEFAULT_GROK_KEY),
|
|
2874
|
+
deepseek: u(c == null ? void 0 : c.VITE_DEFAULT_DEEPSEEK_KEY)
|
|
2671
2875
|
}[e];
|
|
2672
2876
|
}
|
|
2673
2877
|
if (typeof process < "u" && process.env)
|
|
2674
2878
|
return {
|
|
2675
2879
|
"google-gemini": (t = process.env.VITE_DEFAULT_GEMINI_KEY) == null ? void 0 : t.trim(),
|
|
2676
|
-
openai: (
|
|
2880
|
+
openai: (o = process.env.VITE_DEFAULT_OPENAI_KEY) == null ? void 0 : o.trim(),
|
|
2677
2881
|
anthropic: (i = process.env.VITE_DEFAULT_ANTHROPIC_KEY) == null ? void 0 : i.trim(),
|
|
2678
2882
|
grok: (s = process.env.VITE_DEFAULT_GROK_KEY) == null ? void 0 : s.trim(),
|
|
2679
2883
|
deepseek: (l = process.env.VITE_DEFAULT_DEEPSEEK_KEY) == null ? void 0 : l.trim()
|
|
@@ -2685,13 +2889,13 @@ class Rt {
|
|
|
2685
2889
|
*/
|
|
2686
2890
|
static hasEnvKey(e) {
|
|
2687
2891
|
if (typeof import.meta < "u" && M) {
|
|
2688
|
-
const t = M,
|
|
2892
|
+
const t = M, o = (s) => (s == null ? void 0 : s.trim()) || void 0;
|
|
2689
2893
|
return !!{
|
|
2690
|
-
"google-gemini":
|
|
2691
|
-
openai:
|
|
2692
|
-
anthropic:
|
|
2693
|
-
grok:
|
|
2694
|
-
deepseek:
|
|
2894
|
+
"google-gemini": o(t == null ? void 0 : t.VITE_DEFAULT_GEMINI_KEY),
|
|
2895
|
+
openai: o(t == null ? void 0 : t.VITE_DEFAULT_OPENAI_KEY),
|
|
2896
|
+
anthropic: o(t == null ? void 0 : t.VITE_DEFAULT_ANTHROPIC_KEY),
|
|
2897
|
+
grok: o(t == null ? void 0 : t.VITE_DEFAULT_GROK_KEY),
|
|
2898
|
+
deepseek: o(t == null ? void 0 : t.VITE_DEFAULT_DEEPSEEK_KEY)
|
|
2695
2899
|
}[e];
|
|
2696
2900
|
}
|
|
2697
2901
|
return typeof process < "u" && process.env ? !!{
|
|
@@ -2707,20 +2911,20 @@ class Rt {
|
|
|
2707
2911
|
static loadAppDefaults() {
|
|
2708
2912
|
var r, t;
|
|
2709
2913
|
if (typeof import.meta < "u" && M) {
|
|
2710
|
-
const
|
|
2711
|
-
"google-gemini": s(
|
|
2712
|
-
openai: s(
|
|
2713
|
-
anthropic: s(
|
|
2714
|
-
grok: s(
|
|
2715
|
-
deepseek: s(
|
|
2914
|
+
const o = M, i = (o == null ? void 0 : o.VITE_DEFAULT_AI_PROVIDER) || "", s = (d) => (d == null ? void 0 : d.trim()) || void 0, l = {
|
|
2915
|
+
"google-gemini": s(o == null ? void 0 : o.VITE_DEFAULT_GEMINI_KEY),
|
|
2916
|
+
openai: s(o == null ? void 0 : o.VITE_DEFAULT_OPENAI_KEY),
|
|
2917
|
+
anthropic: s(o == null ? void 0 : o.VITE_DEFAULT_ANTHROPIC_KEY),
|
|
2918
|
+
grok: s(o == null ? void 0 : o.VITE_DEFAULT_GROK_KEY),
|
|
2919
|
+
deepseek: s(o == null ? void 0 : o.VITE_DEFAULT_DEEPSEEK_KEY)
|
|
2716
2920
|
};
|
|
2717
2921
|
let c = i || "ollama";
|
|
2718
|
-
const
|
|
2719
|
-
return c === "ollama" &&
|
|
2922
|
+
const m = ["google-gemini", "anthropic", "openai", "grok", "deepseek"].filter((d) => !!l[d]);
|
|
2923
|
+
return c === "ollama" && m.length > 0 && (c = m[0]), {
|
|
2720
2924
|
provider: c,
|
|
2721
|
-
model:
|
|
2925
|
+
model: o == null ? void 0 : o.VITE_DEFAULT_AI_MODEL,
|
|
2722
2926
|
apiKey: l[c],
|
|
2723
|
-
ollamaUrl:
|
|
2927
|
+
ollamaUrl: o == null ? void 0 : o.VITE_DEFAULT_OLLAMA_URL
|
|
2724
2928
|
};
|
|
2725
2929
|
}
|
|
2726
2930
|
return typeof process < "u" && process.env ? {
|
|
@@ -2729,7 +2933,7 @@ class Rt {
|
|
|
2729
2933
|
} : {};
|
|
2730
2934
|
}
|
|
2731
2935
|
}
|
|
2732
|
-
class
|
|
2936
|
+
class qt {
|
|
2733
2937
|
constructor(e) {
|
|
2734
2938
|
this.requests = [], this.config = e;
|
|
2735
2939
|
}
|
|
@@ -2745,14 +2949,14 @@ class Et {
|
|
|
2745
2949
|
return this.requests.length === 0 ? 0 : this.requests[0] + this.config.windowMs;
|
|
2746
2950
|
}
|
|
2747
2951
|
}
|
|
2748
|
-
class
|
|
2952
|
+
class zt {
|
|
2749
2953
|
constructor(e = { maxRequests: 10, windowMs: 6e4 }) {
|
|
2750
|
-
this.rateLimiter = new
|
|
2954
|
+
this.rateLimiter = new qt(e);
|
|
2751
2955
|
}
|
|
2752
2956
|
async makeRequest(e, r) {
|
|
2753
2957
|
if (!this.rateLimiter.checkLimit()) {
|
|
2754
|
-
const t = this.rateLimiter.getResetTime(),
|
|
2755
|
-
throw
|
|
2958
|
+
const t = this.rateLimiter.getResetTime(), o = new Error("Rate limit exceeded. Please wait before making another request.");
|
|
2959
|
+
throw o.code = "RATE_LIMIT_EXCEEDED", o.resetTime = t, r && r(t), o;
|
|
2756
2960
|
}
|
|
2757
2961
|
return await e();
|
|
2758
2962
|
}
|
|
@@ -2760,37 +2964,38 @@ class At {
|
|
|
2760
2964
|
return this.rateLimiter.getRemainingRequests();
|
|
2761
2965
|
}
|
|
2762
2966
|
}
|
|
2763
|
-
const
|
|
2967
|
+
const er = new zt({ maxRequests: 10, windowMs: 6e4 });
|
|
2764
2968
|
export {
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2969
|
+
Qt as A,
|
|
2970
|
+
he as B,
|
|
2971
|
+
Yt as D,
|
|
2972
|
+
me as E,
|
|
2973
|
+
Ft as F,
|
|
2974
|
+
Dt as G,
|
|
2975
|
+
Zt as I,
|
|
2976
|
+
Mt as O,
|
|
2977
|
+
fe as P,
|
|
2978
|
+
le as R,
|
|
2979
|
+
Ee as S,
|
|
2980
|
+
de as T,
|
|
2981
|
+
ge as W,
|
|
2982
|
+
Me as a,
|
|
2983
|
+
Xt as b,
|
|
2780
2984
|
$ as c,
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2985
|
+
Gt as d,
|
|
2986
|
+
zt as e,
|
|
2987
|
+
er as f,
|
|
2988
|
+
Jt as g,
|
|
2989
|
+
$t as h,
|
|
2990
|
+
Lt as i,
|
|
2991
|
+
Ct as j,
|
|
2992
|
+
Ut as k,
|
|
2789
2993
|
ce as l,
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2994
|
+
pe as m,
|
|
2995
|
+
ye as n,
|
|
2996
|
+
Kt as o,
|
|
2997
|
+
Vt as p,
|
|
2998
|
+
z as q,
|
|
2999
|
+
Nt as s,
|
|
3000
|
+
Wt as t
|
|
2796
3001
|
};
|