@ramme-io/shared 3.1.1 → 3.2.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 +2 -2
- package/dist/index.cjs +1330 -81
- package/dist/index.d.cts +18449 -24
- package/dist/index.d.ts +18449 -24
- package/dist/index.js +1210 -81
- package/package.json +7 -5
package/dist/index.js
CHANGED
|
@@ -264,7 +264,8 @@ var BodewellTelemetrySchema = z4.object({
|
|
|
264
264
|
soil_temp_stemma: z4.number().optional().describe("Celsius"),
|
|
265
265
|
soil_vwc: z4.number().describe("Volumetric Water Content / Raw Capacitance"),
|
|
266
266
|
soil_moisture: z4.number().optional().describe("Firmware alias for raw capacitance"),
|
|
267
|
-
soil_moisture_raw: z4.number().optional().describe("Unscaled capacitance (300-1100)")
|
|
267
|
+
soil_moisture_raw: z4.number().optional().describe("Unscaled capacitance (300-1100)"),
|
|
268
|
+
fw_version: z4.string().max(40).optional().describe("Firmware build the board is running; absent on v4 sketches, which cannot be updated over the air")
|
|
268
269
|
}).passthrough();
|
|
269
270
|
var BodewellCommandSchema = z4.object({
|
|
270
271
|
stick_id: BodewellDeviceID,
|
|
@@ -273,28 +274,669 @@ var BodewellCommandSchema = z4.object({
|
|
|
273
274
|
value: z4.number()
|
|
274
275
|
});
|
|
275
276
|
|
|
276
|
-
// src/
|
|
277
|
+
// src/device/schema.ts
|
|
277
278
|
import { z as z5 } from "zod";
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
var DeviceKindSchema = z5.enum([
|
|
280
|
+
"esp32-touch-28",
|
|
281
|
+
// 2.8" 240x320 resistive touch, the workshop board
|
|
282
|
+
"esp32-headless",
|
|
283
|
+
// no display; sensor node
|
|
284
|
+
"simulator"
|
|
285
|
+
// browser-side stand-in, for building without hardware
|
|
286
|
+
]);
|
|
287
|
+
var DeviceAppIdSchema = z5.enum([
|
|
288
|
+
"weather",
|
|
289
|
+
"clock",
|
|
290
|
+
"aircraft",
|
|
291
|
+
"sensor",
|
|
292
|
+
"blank"
|
|
293
|
+
]);
|
|
294
|
+
var WeatherAppConfigSchema = z5.object({
|
|
295
|
+
/** Postal code is what a person knows; the portal resolves it to coordinates. */
|
|
296
|
+
postalCode: z5.string().min(3).max(12),
|
|
297
|
+
latitude: z5.number().min(-90).max(90).optional(),
|
|
298
|
+
longitude: z5.number().min(-180).max(180).optional(),
|
|
299
|
+
units: z5.enum(["imperial", "metric"]).default("imperial"),
|
|
300
|
+
showForecast: z5.boolean().default(true),
|
|
301
|
+
refreshSeconds: z5.number().int().min(300).max(86400).default(900)
|
|
302
|
+
});
|
|
303
|
+
var ClockAppConfigSchema = z5.object({
|
|
304
|
+
/** IANA zone, e.g. "America/New_York". */
|
|
305
|
+
timezone: z5.string().default("America/New_York"),
|
|
306
|
+
twentyFourHour: z5.boolean().default(false),
|
|
307
|
+
showSeconds: z5.boolean().default(false),
|
|
308
|
+
showDate: z5.boolean().default(true)
|
|
309
|
+
});
|
|
310
|
+
var AircraftAppConfigSchema = z5.object({
|
|
311
|
+
latitude: z5.number().min(-90).max(90),
|
|
312
|
+
longitude: z5.number().min(-180).max(180),
|
|
313
|
+
radiusKm: z5.number().min(5).max(400).default(80),
|
|
314
|
+
/** Rows the list view can show before the screen runs out. */
|
|
315
|
+
maxRows: z5.number().int().min(1).max(12).default(8),
|
|
316
|
+
refreshSeconds: z5.number().int().min(10).max(600).default(30)
|
|
317
|
+
});
|
|
318
|
+
var SensorAppConfigSchema = z5.object({
|
|
319
|
+
/** Signal keys to display, in order. Abstract keys per the Signal contract. */
|
|
320
|
+
keys: z5.array(z5.string()).min(1).max(6),
|
|
321
|
+
refreshSeconds: z5.number().int().min(1).max(3600).default(10)
|
|
322
|
+
});
|
|
323
|
+
var DeviceAppsSchema = z5.object({
|
|
324
|
+
weather: WeatherAppConfigSchema.optional(),
|
|
325
|
+
clock: ClockAppConfigSchema.optional(),
|
|
326
|
+
aircraft: AircraftAppConfigSchema.optional(),
|
|
327
|
+
sensor: SensorAppConfigSchema.optional()
|
|
328
|
+
});
|
|
329
|
+
var DeviceDisplayConfigSchema = z5.object({
|
|
330
|
+
brightness: z5.number().int().min(5).max(100).default(80),
|
|
331
|
+
/** Degrees clockwise. The board can sit either way up in a case. */
|
|
332
|
+
rotation: z5.union([z5.literal(0), z5.literal(90), z5.literal(180), z5.literal(270)]).default(0),
|
|
333
|
+
/** Dim rather than sleep — a desk display that blanks looks broken. */
|
|
334
|
+
dimAfterSeconds: z5.number().int().min(0).max(86400).default(0),
|
|
335
|
+
dimBrightness: z5.number().int().min(0).max(100).default(15),
|
|
336
|
+
/** Local 24h times, e.g. "22:30". Empty disables night dimming. */
|
|
337
|
+
nightStart: z5.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/).optional(),
|
|
338
|
+
nightEnd: z5.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/).optional()
|
|
339
|
+
});
|
|
340
|
+
var RgbTripletSchema = z5.string().regex(
|
|
341
|
+
/^\d{1,3} \d{1,3} \d{1,3}$/,
|
|
342
|
+
'Expected space-separated RGB integers, e.g. "13 110 253"'
|
|
343
|
+
);
|
|
344
|
+
var DeviceThemeSchema = z5.object({
|
|
345
|
+
preset: z5.enum(["light", "dark", "corporate", "midnight", "blueprint", "custom"]).default("dark"),
|
|
346
|
+
background: RgbTripletSchema.optional(),
|
|
347
|
+
foreground: RgbTripletSchema.optional(),
|
|
348
|
+
accent: RgbTripletSchema.optional(),
|
|
349
|
+
muted: RgbTripletSchema.optional(),
|
|
350
|
+
warning: RgbTripletSchema.optional()
|
|
351
|
+
});
|
|
352
|
+
var DeviceConfigSchema = z5.object({
|
|
353
|
+
/** Bumped only on breaking shape changes, so old firmware can refuse safely. */
|
|
354
|
+
schemaVersion: z5.literal(1),
|
|
355
|
+
deviceId: z5.string().min(1),
|
|
356
|
+
/** Monotonic. Portal increments on write; device echoes what it is running. */
|
|
357
|
+
revision: z5.number().int().nonnegative(),
|
|
358
|
+
updatedAt: z5.string().datetime().optional(),
|
|
359
|
+
activeApp: DeviceAppIdSchema,
|
|
360
|
+
apps: DeviceAppsSchema,
|
|
361
|
+
display: DeviceDisplayConfigSchema,
|
|
362
|
+
theme: DeviceThemeSchema
|
|
363
|
+
});
|
|
364
|
+
var ProvisioningStateSchema = z5.enum([
|
|
365
|
+
"unprovisioned",
|
|
366
|
+
"connecting",
|
|
367
|
+
"online",
|
|
368
|
+
"offline",
|
|
369
|
+
"failed"
|
|
370
|
+
]);
|
|
371
|
+
var DeviceStatusSchema = z5.object({
|
|
372
|
+
deviceId: z5.string().min(1),
|
|
373
|
+
kind: DeviceKindSchema,
|
|
374
|
+
firmwareVersion: z5.string(),
|
|
375
|
+
/** Shown on the device's own screen at boot — how the user finds it. */
|
|
376
|
+
ipAddress: z5.string().optional(),
|
|
377
|
+
provisioning: ProvisioningStateSchema,
|
|
378
|
+
/** Revision the device is actually running, not the one it was sent. */
|
|
379
|
+
configRevision: z5.number().int().nonnegative(),
|
|
380
|
+
activeApp: DeviceAppIdSchema,
|
|
381
|
+
rssi: z5.number().int().optional().describe("dBm"),
|
|
382
|
+
uptimeSeconds: z5.number().int().nonnegative().optional(),
|
|
383
|
+
freeHeapBytes: z5.number().int().nonnegative().optional()
|
|
384
|
+
});
|
|
385
|
+
var DEVICE_ENDPOINTS = {
|
|
386
|
+
/** GET → DeviceStatus */
|
|
387
|
+
status: "/api/status",
|
|
388
|
+
/** GET → DeviceConfig · POST DeviceConfig → applied + persisted */
|
|
389
|
+
config: "/api/config",
|
|
390
|
+
/** POST → clears stored credentials and returns to AP mode */
|
|
391
|
+
forget: "/api/forget"
|
|
392
|
+
};
|
|
393
|
+
var DEVICE_AP_SSID_PREFIX = "ramme-setup-";
|
|
394
|
+
var DEFAULT_DEVICE_CONFIG = {
|
|
395
|
+
schemaVersion: 1,
|
|
396
|
+
revision: 0,
|
|
397
|
+
activeApp: "clock",
|
|
398
|
+
apps: {},
|
|
399
|
+
display: {
|
|
400
|
+
brightness: 80,
|
|
401
|
+
rotation: 0,
|
|
402
|
+
dimAfterSeconds: 0,
|
|
403
|
+
dimBrightness: 15
|
|
404
|
+
},
|
|
405
|
+
theme: { preset: "dark" }
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
// src/apps/schema.ts
|
|
409
|
+
import { z as z6 } from "zod";
|
|
410
|
+
var AppColorTokenSchema = z6.enum([
|
|
411
|
+
"background",
|
|
412
|
+
"foreground",
|
|
413
|
+
"muted",
|
|
414
|
+
"accent",
|
|
415
|
+
"success",
|
|
416
|
+
"warning",
|
|
417
|
+
"danger"
|
|
418
|
+
]);
|
|
419
|
+
var AppRgbSchema = z6.string().regex(/^\d{1,3} \d{1,3} \d{1,3}$/, 'RGB must be three space-separated integers, e.g. "13 110 253"');
|
|
420
|
+
var AppColorSchema = z6.union([AppColorTokenSchema, AppRgbSchema]);
|
|
421
|
+
var AppTextSizeSchema = z6.enum(["xs", "sm", "base", "lg", "xl", "display"]);
|
|
422
|
+
var AppAlignSchema = z6.enum(["start", "center", "end"]);
|
|
423
|
+
var AppSourceSchema = z6.discriminatedUnion("kind", [
|
|
424
|
+
z6.object({
|
|
425
|
+
kind: z6.literal("weather"),
|
|
426
|
+
latitude: z6.number().min(-90).max(90),
|
|
427
|
+
longitude: z6.number().min(-180).max(180),
|
|
428
|
+
units: z6.enum(["imperial", "metric"]).default("imperial"),
|
|
429
|
+
refreshSeconds: z6.number().int().min(300).max(86400).default(600)
|
|
430
|
+
}),
|
|
431
|
+
z6.object({
|
|
432
|
+
kind: z6.literal("clock"),
|
|
433
|
+
/** IANA zone, e.g. "America/New_York". */
|
|
434
|
+
timezone: z6.string().default("America/New_York"),
|
|
435
|
+
twentyFourHour: z6.boolean().default(false)
|
|
436
|
+
}),
|
|
437
|
+
z6.object({
|
|
438
|
+
kind: z6.literal("countdown"),
|
|
439
|
+
/** ISO date or datetime, e.g. "2026-12-25" or "2026-12-25T18:00:00Z". */
|
|
440
|
+
target: z6.string().min(4),
|
|
441
|
+
label: z6.string().max(24).optional()
|
|
442
|
+
}),
|
|
443
|
+
z6.object({
|
|
444
|
+
kind: z6.literal("static"),
|
|
445
|
+
values: z6.record(z6.union([z6.string(), z6.number(), z6.boolean()]))
|
|
446
|
+
})
|
|
447
|
+
]);
|
|
448
|
+
var AppOperandSchema = z6.union([
|
|
449
|
+
z6.object({ literal: z6.number() }),
|
|
450
|
+
z6.object({ source: z6.string().min(1), field: z6.string().min(1) })
|
|
451
|
+
]);
|
|
452
|
+
var AppComputeSchema = z6.object({
|
|
453
|
+
compute: z6.enum(["add", "subtract", "multiply", "divide"]),
|
|
454
|
+
of: z6.tuple([AppOperandSchema, AppOperandSchema]),
|
|
455
|
+
round: z6.boolean().default(true)
|
|
456
|
+
});
|
|
457
|
+
var AppBindingSchema = z6.union([
|
|
458
|
+
z6.object({ literal: z6.union([z6.string(), z6.number(), z6.boolean()]) }),
|
|
459
|
+
z6.object({
|
|
460
|
+
/** Key into the document's `sources` map. */
|
|
461
|
+
source: z6.string().min(1),
|
|
462
|
+
/** Field on that source, e.g. "temperature", "high", "condition". */
|
|
463
|
+
field: z6.string().min(1)
|
|
464
|
+
}),
|
|
465
|
+
AppComputeSchema
|
|
466
|
+
]);
|
|
467
|
+
var AppConditionSchema = z6.object({
|
|
468
|
+
value: AppOperandSchema,
|
|
469
|
+
op: z6.enum(["<", "<=", ">", ">=", "==", "!="]),
|
|
470
|
+
than: z6.union([z6.number(), z6.string(), z6.boolean()])
|
|
471
|
+
});
|
|
472
|
+
var AppStyleRuleSchema = z6.object({
|
|
473
|
+
when: AppConditionSchema,
|
|
474
|
+
color: AppColorSchema.optional(),
|
|
475
|
+
size: AppTextSizeSchema.optional()
|
|
476
|
+
});
|
|
477
|
+
var leafBase = {
|
|
478
|
+
color: AppColorSchema.optional(),
|
|
479
|
+
/** Drawn only when this is false, or absent. */
|
|
480
|
+
hideWhen: AppConditionSchema.optional(),
|
|
481
|
+
/** Conditional style. First match wins. */
|
|
482
|
+
rules: z6.array(AppStyleRuleSchema).max(4).optional()
|
|
483
|
+
};
|
|
484
|
+
var AppTextSchema = z6.object({
|
|
485
|
+
type: z6.literal("text"),
|
|
486
|
+
value: AppBindingSchema,
|
|
487
|
+
size: AppTextSizeSchema.default("base"),
|
|
488
|
+
align: AppAlignSchema.default("start"),
|
|
489
|
+
/** Printed after the value, e.g. a degree symbol. Never itself bound. */
|
|
490
|
+
suffix: z6.string().max(8).optional(),
|
|
491
|
+
...leafBase
|
|
492
|
+
});
|
|
493
|
+
var AppDialSchema = z6.object({
|
|
494
|
+
type: z6.literal("dial"),
|
|
495
|
+
value: AppBindingSchema,
|
|
496
|
+
min: z6.number(),
|
|
497
|
+
max: z6.number(),
|
|
498
|
+
label: z6.string().max(24).optional(),
|
|
499
|
+
...leafBase
|
|
500
|
+
});
|
|
501
|
+
var AppSparklineSchema = z6.object({
|
|
502
|
+
type: z6.literal("sparkline"),
|
|
503
|
+
/** A source field holding a series rather than a scalar. */
|
|
504
|
+
series: AppBindingSchema,
|
|
505
|
+
...leafBase
|
|
506
|
+
});
|
|
507
|
+
var AppBarSchema = z6.object({
|
|
508
|
+
type: z6.literal("bar"),
|
|
509
|
+
value: AppBindingSchema,
|
|
510
|
+
min: z6.number(),
|
|
511
|
+
max: z6.number(),
|
|
512
|
+
...leafBase
|
|
513
|
+
});
|
|
514
|
+
var AppStatusSchema = z6.object({
|
|
515
|
+
type: z6.literal("status"),
|
|
516
|
+
state: AppBindingSchema,
|
|
517
|
+
label: z6.string().max(24).optional(),
|
|
518
|
+
...leafBase
|
|
519
|
+
});
|
|
520
|
+
var SPRITE_MAX_SIDE = 64;
|
|
521
|
+
var SPRITE_MAX_ROW_BYTES = SPRITE_MAX_SIDE / 2;
|
|
522
|
+
var SPRITE_MAX_BASE64 = Math.ceil(SPRITE_MAX_ROW_BYTES * SPRITE_MAX_SIDE / 3) * 4;
|
|
523
|
+
var AppSpriteSchema = z6.object({
|
|
524
|
+
type: z6.literal("sprite"),
|
|
525
|
+
width: z6.number().int().min(1).max(SPRITE_MAX_SIDE),
|
|
526
|
+
height: z6.number().int().min(1).max(SPRITE_MAX_SIDE),
|
|
527
|
+
/**
|
|
528
|
+
* Up to sixteen colours, in the same form every other colour in a document
|
|
529
|
+
* takes: a semantic token, or literal RGB.
|
|
530
|
+
*
|
|
531
|
+
* Both are allowed on purpose. A token re-colours with the theme, which is
|
|
532
|
+
* what an icon wants; literal RGB does not, which is what a drawing wants.
|
|
533
|
+
* A picture of a dog is content, not chrome, and should not turn teal
|
|
534
|
+
* because somebody switched to the corporate theme.
|
|
535
|
+
*/
|
|
536
|
+
palette: z6.array(AppColorSchema).min(1).max(16),
|
|
537
|
+
/** base64 of the packed nibbles. */
|
|
538
|
+
pixels: z6.string().min(4).max(SPRITE_MAX_BASE64),
|
|
539
|
+
align: AppAlignSchema.default("start"),
|
|
540
|
+
/** Drawn only when this is false, or absent. */
|
|
541
|
+
hideWhen: AppConditionSchema.optional()
|
|
542
|
+
});
|
|
543
|
+
var AssetHashSchema = z6.string().regex(/^[0-9a-f]{64}$/, "a lowercase hex SHA-256");
|
|
544
|
+
var IMAGE_MAX_DRAWN = { width: 304, height: 224 };
|
|
545
|
+
var IMAGE_MAX_SCALE = 8;
|
|
546
|
+
var RETRO_RENDITION = { width: 76, height: 56, scale: 4, colors: 16 };
|
|
547
|
+
var SPR_FORMAT = {
|
|
548
|
+
/** "RSPR". */
|
|
549
|
+
magic: [82, 83, 80, 82],
|
|
550
|
+
version: 1,
|
|
551
|
+
/** magic 4, version 1, width u16, height u16, bits per pixel 1, palette count 1. */
|
|
552
|
+
headerBytes: 11,
|
|
553
|
+
/** Only 4 today: two pixels per byte, high nibble first, rows padded to a byte. */
|
|
554
|
+
bitsPerPixel: 4,
|
|
555
|
+
maxColors: 16
|
|
556
|
+
};
|
|
557
|
+
var SPR_MAX_BYTES = SPR_FORMAT.headerBytes + SPR_FORMAT.maxColors * 2 + Math.ceil(IMAGE_MAX_DRAWN.width / 2) * IMAGE_MAX_DRAWN.height;
|
|
558
|
+
var AppImageSchema = z6.object({
|
|
559
|
+
type: z6.literal("image"),
|
|
560
|
+
asset: AssetHashSchema,
|
|
561
|
+
/** The file's own pixels, not the drawn size. */
|
|
562
|
+
width: z6.number().int().min(1).max(IMAGE_MAX_DRAWN.width),
|
|
563
|
+
height: z6.number().int().min(1).max(IMAGE_MAX_DRAWN.height),
|
|
564
|
+
scale: z6.number().int().min(1).max(IMAGE_MAX_SCALE).default(1),
|
|
565
|
+
align: AppAlignSchema.default("start"),
|
|
566
|
+
/** Drawn only when this is false, or absent. */
|
|
567
|
+
hideWhen: AppConditionSchema.optional()
|
|
568
|
+
});
|
|
569
|
+
var AppLeafSchema = z6.discriminatedUnion("type", [
|
|
570
|
+
AppTextSchema,
|
|
571
|
+
AppDialSchema,
|
|
572
|
+
AppSparklineSchema,
|
|
573
|
+
AppBarSchema,
|
|
574
|
+
AppStatusSchema,
|
|
575
|
+
AppSpriteSchema,
|
|
576
|
+
AppImageSchema
|
|
577
|
+
]);
|
|
578
|
+
var AppGroupSchema = z6.object({
|
|
579
|
+
type: z6.literal("group"),
|
|
580
|
+
direction: z6.enum(["row", "stack"]),
|
|
581
|
+
gap: z6.number().int().min(0).max(64).default(4),
|
|
582
|
+
align: AppAlignSchema.default("start"),
|
|
583
|
+
children: z6.array(AppLeafSchema).min(1).max(8)
|
|
584
|
+
});
|
|
585
|
+
var AppBlockSchema = z6.union([AppLeafSchema, AppGroupSchema]);
|
|
586
|
+
var AppScreenSizeSchema = z6.preprocess(
|
|
587
|
+
(value) => value === "240x320" ? "320x240" : value,
|
|
588
|
+
z6.enum(["320x240"])
|
|
589
|
+
);
|
|
590
|
+
var AppDocumentSchema = z6.object({
|
|
591
|
+
/** Bumped only for a breaking change; the device checks it before parsing. */
|
|
592
|
+
schemaVersion: z6.literal(1),
|
|
593
|
+
id: z6.string().regex(/^[a-z0-9][a-z0-9-]{1,38}[a-z0-9]$/, "lowercase slug"),
|
|
594
|
+
name: z6.string().min(1).max(48),
|
|
595
|
+
/** Free text. Never an email or anything else identifying — see the plan. */
|
|
596
|
+
author: z6.string().max(32).optional(),
|
|
597
|
+
screen: AppScreenSizeSchema.default("320x240"),
|
|
598
|
+
background: AppColorSchema.default("background"),
|
|
599
|
+
/** Named so bindings can refer to them. */
|
|
600
|
+
sources: z6.record(AppSourceSchema).default({}),
|
|
601
|
+
blocks: z6.array(AppBlockSchema).min(1).max(12)
|
|
602
|
+
}).superRefine((doc, ctx) => {
|
|
603
|
+
const bytesPerRow = (width) => Math.ceil(width / 2);
|
|
604
|
+
const check = (block, path) => {
|
|
605
|
+
const b = block;
|
|
606
|
+
if (b?.type !== "sprite" || !b.width || !b.height || typeof b.pixels !== "string") return;
|
|
607
|
+
const want = bytesPerRow(b.width) * b.height;
|
|
608
|
+
const got = Math.floor(b.pixels.replace(/=+$/, "").length * 3 / 4);
|
|
609
|
+
if (got === want) return;
|
|
610
|
+
ctx.addIssue({
|
|
611
|
+
code: z6.ZodIssueCode.custom,
|
|
612
|
+
path: [...path, "pixels"],
|
|
613
|
+
message: `${b.width}x${b.height} needs ${want} bytes of pixel data, and this decodes to ${got}. Rows are padded to whole bytes, so the length is ceil(width / 2) * height.`
|
|
614
|
+
});
|
|
615
|
+
};
|
|
616
|
+
const checkImage = (block, path) => {
|
|
617
|
+
const b = block;
|
|
618
|
+
if (b?.type !== "image" || !b.width || !b.height) return;
|
|
619
|
+
const scale = b.scale ?? 1;
|
|
620
|
+
const w = b.width * scale;
|
|
621
|
+
const h = b.height * scale;
|
|
622
|
+
if (w <= IMAGE_MAX_DRAWN.width && h <= IMAGE_MAX_DRAWN.height) return;
|
|
623
|
+
ctx.addIssue({
|
|
624
|
+
code: z6.ZodIssueCode.custom,
|
|
625
|
+
path: [...path, "scale"],
|
|
626
|
+
message: `${b.width}x${b.height} at scale ${scale} draws ${w}x${h}, and a board draws at most ${IMAGE_MAX_DRAWN.width}x${IMAGE_MAX_DRAWN.height} inside its margin.`
|
|
627
|
+
});
|
|
628
|
+
};
|
|
629
|
+
doc.blocks.forEach((block, i) => {
|
|
630
|
+
check(block, ["blocks", i]);
|
|
631
|
+
checkImage(block, ["blocks", i]);
|
|
632
|
+
const children = block.children;
|
|
633
|
+
if (Array.isArray(children)) {
|
|
634
|
+
children.forEach((child, j) => {
|
|
635
|
+
check(child, ["blocks", i, "children", j]);
|
|
636
|
+
checkImage(child, ["blocks", i, "children", j]);
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
// src/apps/photos.ts
|
|
643
|
+
import { z as z7 } from "zod";
|
|
644
|
+
var ORIGINAL_MAX_SIDE = 3072;
|
|
645
|
+
var ORIGINAL_MAX_BYTES = 3e6;
|
|
646
|
+
var PHOTOS_PER_ACCOUNT = 50;
|
|
647
|
+
var PHOTO_UPLOADS_PER_HOUR = 30;
|
|
648
|
+
var PhotoUploadSchema = z7.object({
|
|
649
|
+
rendition: z7.string().min(4),
|
|
650
|
+
original: z7.string().min(4)
|
|
651
|
+
});
|
|
652
|
+
var PhotoSummarySchema = z7.object({
|
|
653
|
+
hash: AssetHashSchema,
|
|
654
|
+
/** The rendition's own pixels. */
|
|
655
|
+
width: z7.number().int().positive(),
|
|
656
|
+
height: z7.number().int().positive(),
|
|
657
|
+
renditionBytes: z7.number().int().positive(),
|
|
658
|
+
originalWidth: z7.number().int().positive(),
|
|
659
|
+
originalHeight: z7.number().int().positive(),
|
|
660
|
+
originalBytes: z7.number().int().positive(),
|
|
661
|
+
uploadedAt: z7.number().int()
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
// src/apps/delivery.ts
|
|
665
|
+
import { z as z8 } from "zod";
|
|
666
|
+
var DeviceIdSchema = z8.string().regex(/^[0-9A-HJKMNP-TV-Z]{8}$/, "eight characters, no I L O or U");
|
|
667
|
+
var PairCodeSchema = z8.string().regex(/^\d{4}$/);
|
|
668
|
+
var DeviceRegistrationSchema = z8.object({
|
|
669
|
+
deviceId: DeviceIdSchema,
|
|
670
|
+
code: PairCodeSchema,
|
|
671
|
+
/** Firmware build, so a support question has an answer. */
|
|
672
|
+
version: z8.string().max(40).optional(),
|
|
673
|
+
/** Which board this is, from Boards.h — the two variants need different firmware. */
|
|
674
|
+
board: z8.string().max(40).optional(),
|
|
675
|
+
/** dBm, always negative. -50 is across the room; -85 is a complaint. */
|
|
676
|
+
rssi: z8.number().int().min(-127).max(0).optional(),
|
|
677
|
+
/** On the owner's own network. Long enough for IPv6, which this does not send yet. */
|
|
678
|
+
ip: z8.string().max(45).optional(),
|
|
679
|
+
/** Seconds since boot. Not growing between check-ins means it is restarting. */
|
|
680
|
+
uptime: z8.number().int().nonnegative().optional(),
|
|
681
|
+
/** Free heap in bytes. */
|
|
682
|
+
heap: z8.number().int().nonnegative().optional(),
|
|
683
|
+
/** The app revision the board has actually drawn. */
|
|
684
|
+
drew: z8.number().int().nonnegative().optional(),
|
|
685
|
+
/** Why it last restarted, already mapped to a word by the firmware. */
|
|
686
|
+
reset: z8.string().max(40).optional()
|
|
687
|
+
});
|
|
688
|
+
var SendRequestSchema = z8.object({
|
|
689
|
+
deviceId: DeviceIdSchema,
|
|
690
|
+
code: PairCodeSchema
|
|
691
|
+
});
|
|
692
|
+
var OwnedSendRequestSchema = z8.object({
|
|
693
|
+
deviceId: DeviceIdSchema
|
|
694
|
+
});
|
|
695
|
+
var DeliveredAppSchema = z8.object({
|
|
696
|
+
revision: z8.number().int().nonnegative(),
|
|
697
|
+
sentAt: z8.number().int().nonnegative()
|
|
698
|
+
});
|
|
699
|
+
var DeviceRecordSchema = z8.object({
|
|
700
|
+
deviceId: DeviceIdSchema,
|
|
701
|
+
code: PairCodeSchema,
|
|
702
|
+
ownerId: z8.string().nullable().default(null),
|
|
703
|
+
version: z8.string().max(40).optional(),
|
|
704
|
+
createdAt: z8.number().int().nonnegative(),
|
|
705
|
+
lastSeenAt: z8.number().int().nonnegative()
|
|
706
|
+
});
|
|
707
|
+
var DEVICE_LABEL_MAX = 48;
|
|
708
|
+
var DEVICE_TTL_SECONDS = 60 * 60 * 24 * 30;
|
|
709
|
+
var CLAIMED_DEVICE_TTL_SECONDS = 60 * 60 * 24 * 400;
|
|
710
|
+
|
|
711
|
+
// src/apps/vitals.ts
|
|
712
|
+
import { z as z9 } from "zod";
|
|
713
|
+
var VitalSourceSchema = z9.enum(["register", "poll", "send"]);
|
|
714
|
+
var DeviceVitalsSchema = z9.object({
|
|
715
|
+
/** When the board last said any of this, by the server's clock. */
|
|
716
|
+
reportedAt: z9.number().int().nonnegative().optional(),
|
|
717
|
+
/**
|
|
718
|
+
* The firmware build. Today every board sends the literal "doc-1", which is a
|
|
719
|
+
* protocol marker rather than a build id — so this is shown as reported and
|
|
720
|
+
* labelled as not yet a version. The real value lives in the published
|
|
721
|
+
* manifest until firmware carries it.
|
|
722
|
+
*/
|
|
723
|
+
firmwareVersion: z9.string().max(40).optional(),
|
|
724
|
+
/** Which board this is. Nothing distinguishes a CYD from a Freenove S3 yet. */
|
|
725
|
+
board: z9.string().max(40).optional(),
|
|
726
|
+
/** dBm, negative. -50 is across the room, -85 is a complaint. */
|
|
727
|
+
rssi: z9.number().int().min(-127).max(0).optional(),
|
|
728
|
+
/** The board's address on its own network, as the board sees it. */
|
|
729
|
+
ip: z9.string().max(45).optional(),
|
|
730
|
+
uptimeSeconds: z9.number().int().nonnegative().optional(),
|
|
731
|
+
freeHeapBytes: z9.number().int().nonnegative().optional(),
|
|
732
|
+
/**
|
|
733
|
+
* The revision the board is actually showing.
|
|
734
|
+
*
|
|
735
|
+
* Distinct from the revision that was sent, and the difference is the whole
|
|
736
|
+
* value: a send that was never drawn looks identical to a successful one until
|
|
737
|
+
* these two numbers disagree.
|
|
738
|
+
*/
|
|
739
|
+
drewRevision: z9.number().int().nonnegative().optional(),
|
|
740
|
+
/** Why it last restarted, if it says. A board power-cycling in a loop is a fault. */
|
|
741
|
+
resetReason: z9.string().max(40).optional(),
|
|
742
|
+
/** When it last polled — finer-grained than a registration, for liveness only. */
|
|
743
|
+
lastPollAt: z9.number().int().nonnegative().optional()
|
|
744
|
+
});
|
|
745
|
+
var DeviceSeenSchema = z9.object({
|
|
746
|
+
/** When the board last asked for its app. The freshest signal this system has. */
|
|
747
|
+
lastPollAt: z9.number().int().nonnegative(),
|
|
748
|
+
/** The revision it reported drawing at that moment. */
|
|
749
|
+
drewRevision: z9.number().int().nonnegative().optional()
|
|
750
|
+
});
|
|
751
|
+
var DEVICE_VITALS_FIELDS = [
|
|
752
|
+
{
|
|
753
|
+
key: "firmwareVersion",
|
|
754
|
+
label: "Firmware",
|
|
755
|
+
source: "register",
|
|
756
|
+
reportedByFirmware: true,
|
|
757
|
+
note: 'A build stamped in by CI. Boards flashed before that report the marker "doc-1".'
|
|
758
|
+
},
|
|
759
|
+
{ key: "board", label: "Board", source: "register", reportedByFirmware: true },
|
|
760
|
+
{ key: "drewRevision", label: "Showing revision", source: "poll", reportedByFirmware: true },
|
|
761
|
+
{ key: "rssi", label: "Wi-Fi signal", unit: "dBm", source: "register", reportedByFirmware: true },
|
|
762
|
+
{ key: "ip", label: "Address on your network", source: "register", reportedByFirmware: true },
|
|
763
|
+
{ key: "uptimeSeconds", label: "Uptime", unit: "s", source: "register", reportedByFirmware: true },
|
|
764
|
+
{
|
|
765
|
+
key: "freeHeapBytes",
|
|
766
|
+
label: "Free memory",
|
|
767
|
+
unit: "bytes",
|
|
768
|
+
source: "register",
|
|
769
|
+
reportedByFirmware: true
|
|
770
|
+
},
|
|
771
|
+
{ key: "resetReason", label: "Last restart", source: "register", reportedByFirmware: true }
|
|
772
|
+
];
|
|
773
|
+
var DEVICE_FRESH_MS = 7 * 60 * 60 * 1e3;
|
|
774
|
+
var DEVICE_STALE_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
775
|
+
|
|
776
|
+
// src/apps/glyphs.ts
|
|
777
|
+
var DEVICE_UNKNOWN_GLYPH = "?";
|
|
778
|
+
var DEVICE_GLYPHS = {
|
|
779
|
+
// Accented Latin, CP437 0x80-0xA5 and 0xE1
|
|
780
|
+
"\xC7": { byte: 128, shows: "\xC7" },
|
|
781
|
+
"\xFC": { byte: 129, shows: "\xFC" },
|
|
782
|
+
"\xE9": { byte: 130, shows: "\xE9" },
|
|
783
|
+
"\xE2": { byte: 131, shows: "\xE2" },
|
|
784
|
+
"\xE4": { byte: 132, shows: "\xE4" },
|
|
785
|
+
"\xE0": { byte: 133, shows: "\xE0" },
|
|
786
|
+
"\xE5": { byte: 134, shows: "\xE5" },
|
|
787
|
+
"\xE7": { byte: 135, shows: "\xE7" },
|
|
788
|
+
"\xEA": { byte: 136, shows: "\xEA" },
|
|
789
|
+
"\xEB": { byte: 137, shows: "\xEB" },
|
|
790
|
+
"\xE8": { byte: 138, shows: "\xE8" },
|
|
791
|
+
"\xEF": { byte: 139, shows: "\xEF" },
|
|
792
|
+
"\xEE": { byte: 140, shows: "\xEE" },
|
|
793
|
+
"\xEC": { byte: 141, shows: "\xEC" },
|
|
794
|
+
"\xC4": { byte: 142, shows: "\xC4" },
|
|
795
|
+
"\xC5": { byte: 143, shows: "\xC5" },
|
|
796
|
+
"\xC9": { byte: 144, shows: "\xC9" },
|
|
797
|
+
"\xE6": { byte: 145, shows: "\xE6" },
|
|
798
|
+
"\xC6": { byte: 146, shows: "\xC6" },
|
|
799
|
+
"\xF4": { byte: 147, shows: "\xF4" },
|
|
800
|
+
"\xF6": { byte: 148, shows: "\xF6" },
|
|
801
|
+
"\xF2": { byte: 149, shows: "\xF2" },
|
|
802
|
+
"\xFB": { byte: 150, shows: "\xFB" },
|
|
803
|
+
"\xF9": { byte: 151, shows: "\xF9" },
|
|
804
|
+
"\xFF": { byte: 152, shows: "\xFF" },
|
|
805
|
+
"\xD6": { byte: 153, shows: "\xD6" },
|
|
806
|
+
"\xDC": { byte: 154, shows: "\xDC" },
|
|
807
|
+
"\xE1": { byte: 160, shows: "\xE1" },
|
|
808
|
+
"\xED": { byte: 161, shows: "\xED" },
|
|
809
|
+
"\xF3": { byte: 162, shows: "\xF3" },
|
|
810
|
+
"\xFA": { byte: 163, shows: "\xFA" },
|
|
811
|
+
"\xF1": { byte: 164, shows: "\xF1" },
|
|
812
|
+
"\xD1": { byte: 165, shows: "\xD1" },
|
|
813
|
+
"\xDF": { byte: 225, shows: "\xDF" },
|
|
814
|
+
// Symbols a readout uses
|
|
815
|
+
"\xA2": { byte: 155, shows: "\xA2" },
|
|
816
|
+
"\xA3": { byte: 156, shows: "\xA3" },
|
|
817
|
+
"\xA5": { byte: 157, shows: "\xA5" },
|
|
818
|
+
"\u0192": { byte: 159, shows: "\u0192" },
|
|
819
|
+
"\xAA": { byte: 166, shows: "\xAA" },
|
|
820
|
+
"\xBA": { byte: 167, shows: "\xBA" },
|
|
821
|
+
"\xBF": { byte: 168, shows: "\xBF" },
|
|
822
|
+
"\xAC": { byte: 170, shows: "\xAC" },
|
|
823
|
+
"\xBD": { byte: 171, shows: "\xBD" },
|
|
824
|
+
"\xBC": { byte: 172, shows: "\xBC" },
|
|
825
|
+
"\xA1": { byte: 173, shows: "\xA1" },
|
|
826
|
+
"\xAB": { byte: 174, shows: "\xAB" },
|
|
827
|
+
"\xBB": { byte: 175, shows: "\xBB" },
|
|
828
|
+
"\u03C0": { byte: 227, shows: "\u03C0" },
|
|
829
|
+
"\xB5": { byte: 230, shows: "\xB5" },
|
|
830
|
+
"\u03A9": { byte: 234, shows: "\u03A9" },
|
|
831
|
+
"\u221E": { byte: 236, shows: "\u221E" },
|
|
832
|
+
"\xB1": { byte: 241, shows: "\xB1" },
|
|
833
|
+
"\u2265": { byte: 242, shows: "\u2265" },
|
|
834
|
+
"\u2264": { byte: 243, shows: "\u2264" },
|
|
835
|
+
"\xF7": { byte: 246, shows: "\xF7" },
|
|
836
|
+
"\u2248": { byte: 247, shows: "\u2248" },
|
|
837
|
+
"\xB0": { byte: 248, shows: "\xB0" },
|
|
838
|
+
"\xB7": { byte: 250, shows: "\xB7" },
|
|
839
|
+
"\u221A": { byte: 251, shows: "\u221A" },
|
|
840
|
+
"\xB2": { byte: 253, shows: "\xB2" },
|
|
841
|
+
// Punctuation an AI writes without being asked, folded to ASCII
|
|
842
|
+
"\u2018": { byte: 39, shows: "'" },
|
|
843
|
+
"\u2019": { byte: 39, shows: "'" },
|
|
844
|
+
"\u201C": { byte: 34, shows: '"' },
|
|
845
|
+
"\u201D": { byte: 34, shows: '"' },
|
|
846
|
+
"\u2013": { byte: 45, shows: "-" },
|
|
847
|
+
"\u2014": { byte: 45, shows: "-" },
|
|
848
|
+
"\u2212": { byte: 45, shows: "-" },
|
|
849
|
+
"\xA0": { byte: 32, shows: " " }
|
|
850
|
+
};
|
|
851
|
+
var DEVICE_PALETTE = {
|
|
852
|
+
background: "17 17 17",
|
|
853
|
+
foreground: "238 238 238",
|
|
854
|
+
muted: "153 153 153",
|
|
855
|
+
accent: "23 162 184",
|
|
856
|
+
success: "34 197 94",
|
|
857
|
+
warning: "245 158 11",
|
|
858
|
+
danger: "220 53 69"
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
// src/apps/timezones.ts
|
|
862
|
+
var DEVICE_TIMEZONES = [
|
|
863
|
+
// North America
|
|
864
|
+
{ iana: "America/New_York", posix: "EST5EDT,M3.2.0,M11.1.0" },
|
|
865
|
+
{ iana: "America/Toronto", posix: "EST5EDT,M3.2.0,M11.1.0" },
|
|
866
|
+
{ iana: "America/Chicago", posix: "CST6CDT,M3.2.0,M11.1.0" },
|
|
867
|
+
{ iana: "America/Denver", posix: "MST7MDT,M3.2.0,M11.1.0" },
|
|
868
|
+
{ iana: "America/Phoenix", posix: "MST7" },
|
|
869
|
+
{ iana: "America/Los_Angeles", posix: "PST8PDT,M3.2.0,M11.1.0" },
|
|
870
|
+
{ iana: "America/Vancouver", posix: "PST8PDT,M3.2.0,M11.1.0" },
|
|
871
|
+
{ iana: "America/Anchorage", posix: "AKST9AKDT,M3.2.0,M11.1.0" },
|
|
872
|
+
{ iana: "Pacific/Honolulu", posix: "HST10" },
|
|
873
|
+
{ iana: "America/Mexico_City", posix: "CST6" },
|
|
874
|
+
{ iana: "America/Sao_Paulo", posix: "BRT3" },
|
|
875
|
+
// Europe
|
|
876
|
+
{ iana: "Europe/London", posix: "GMT0BST,M3.5.0/1,M10.5.0" },
|
|
877
|
+
{ iana: "Europe/Dublin", posix: "GMT0IST,M3.5.0/1,M10.5.0" },
|
|
878
|
+
{ iana: "Europe/Lisbon", posix: "WET0WEST,M3.5.0/1,M10.5.0" },
|
|
879
|
+
{ iana: "Europe/Paris", posix: "CET-1CEST,M3.5.0,M10.5.0/3" },
|
|
880
|
+
{ iana: "Europe/Berlin", posix: "CET-1CEST,M3.5.0,M10.5.0/3" },
|
|
881
|
+
{ iana: "Europe/Madrid", posix: "CET-1CEST,M3.5.0,M10.5.0/3" },
|
|
882
|
+
{ iana: "Europe/Rome", posix: "CET-1CEST,M3.5.0,M10.5.0/3" },
|
|
883
|
+
{ iana: "Europe/Amsterdam", posix: "CET-1CEST,M3.5.0,M10.5.0/3" },
|
|
884
|
+
{ iana: "Europe/Stockholm", posix: "CET-1CEST,M3.5.0,M10.5.0/3" },
|
|
885
|
+
{ iana: "Europe/Warsaw", posix: "CET-1CEST,M3.5.0,M10.5.0/3" },
|
|
886
|
+
{ iana: "Europe/Zurich", posix: "CET-1CEST,M3.5.0,M10.5.0/3" },
|
|
887
|
+
{ iana: "Europe/Athens", posix: "EET-2EEST,M3.5.0/3,M10.5.0/4" },
|
|
888
|
+
{ iana: "Europe/Helsinki", posix: "EET-2EEST,M3.5.0/3,M10.5.0/4" },
|
|
889
|
+
{ iana: "Europe/Kyiv", posix: "EET-2EEST,M3.5.0/3,M10.5.0/4" },
|
|
890
|
+
{ iana: "Europe/Moscow", posix: "MSK-3" },
|
|
891
|
+
// Asia and the Middle East
|
|
892
|
+
{ iana: "Asia/Jerusalem", posix: "IST-2IDT,M3.5.5/2,M10.5.0" },
|
|
893
|
+
{ iana: "Asia/Dubai", posix: "GST-4" },
|
|
894
|
+
{ iana: "Asia/Kolkata", posix: "IST-5:30" },
|
|
895
|
+
{ iana: "Asia/Bangkok", posix: "ICT-7" },
|
|
896
|
+
{ iana: "Asia/Shanghai", posix: "CST-8" },
|
|
897
|
+
{ iana: "Asia/Hong_Kong", posix: "HKT-8" },
|
|
898
|
+
{ iana: "Asia/Singapore", posix: "SGT-8" },
|
|
899
|
+
{ iana: "Asia/Tokyo", posix: "JST-9" },
|
|
900
|
+
{ iana: "Asia/Seoul", posix: "KST-9" },
|
|
901
|
+
// Oceania
|
|
902
|
+
{ iana: "Australia/Perth", posix: "AWST-8" },
|
|
903
|
+
{ iana: "Australia/Brisbane", posix: "AEST-10" },
|
|
904
|
+
{ iana: "Australia/Adelaide", posix: "ACST-9:30ACDT,M10.1.0,M4.1.0/3" },
|
|
905
|
+
{ iana: "Australia/Sydney", posix: "AEST-10AEDT,M10.1.0,M4.1.0/3" },
|
|
906
|
+
{ iana: "Australia/Melbourne", posix: "AEST-10AEDT,M10.1.0,M4.1.0/3" },
|
|
907
|
+
{ iana: "Pacific/Auckland", posix: "NZST-12NZDT,M9.5.0,M4.1.0/3" },
|
|
908
|
+
{ iana: "UTC", posix: "UTC0" }
|
|
909
|
+
];
|
|
910
|
+
var DEVICE_TIMEZONE_FALLBACK = "UTC0";
|
|
911
|
+
|
|
912
|
+
// src/ai/tools.ts
|
|
913
|
+
import { z as z10 } from "zod";
|
|
914
|
+
var telemetryGraphParameters = z10.object({
|
|
915
|
+
deviceId: z10.string().min(1, "Device ID is required"),
|
|
916
|
+
timeRange: z10.enum(["1h", "24h", "7d"], {
|
|
281
917
|
errorMap: () => ({ message: "Time range must be 1h, 24h, or 7d" })
|
|
282
918
|
}),
|
|
283
|
-
metrics:
|
|
284
|
-
|
|
919
|
+
metrics: z10.array(
|
|
920
|
+
z10.enum(["temperature", "humidity", "vwc", "ec", "ph", "pressure", "co2"])
|
|
285
921
|
).min(1, "At least one metric is required").max(4, "Maximum 4 metrics per graph")
|
|
286
922
|
});
|
|
287
|
-
var stockChartParameters =
|
|
288
|
-
ticker:
|
|
289
|
-
timeRange:
|
|
923
|
+
var stockChartParameters = z10.object({
|
|
924
|
+
ticker: z10.string().min(1).describe("The stock ticker symbol explicitly requested by the user. YOU MUST EXTRACT AND PROVIDE THIS (e.g., 'AAPL', 'MSFT')."),
|
|
925
|
+
timeRange: z10.enum(["1D", "1W", "1M", "1Y"], {
|
|
290
926
|
errorMap: () => ({ message: "Time range must be 1D, 1W, 1M, or 1Y" })
|
|
291
927
|
}).describe("The time range for the chart. Choose based on user request or default to '1M'."),
|
|
292
|
-
metrics:
|
|
928
|
+
metrics: z10.array(z10.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.")
|
|
293
929
|
});
|
|
294
|
-
var tickerParam =
|
|
295
|
-
var liveQuoteParameters =
|
|
296
|
-
var companyNewsParameters =
|
|
297
|
-
var companyProfileParameters =
|
|
930
|
+
var tickerParam = z10.string().min(1).describe("The stock ticker symbol (e.g., 'AAPL', 'TSLA', 'MSFT').");
|
|
931
|
+
var liveQuoteParameters = z10.object({ ticker: tickerParam });
|
|
932
|
+
var companyNewsParameters = z10.object({ ticker: tickerParam });
|
|
933
|
+
var companyProfileParameters = z10.object({ ticker: tickerParam });
|
|
934
|
+
var counterpartyGraphParameters = z10.object({
|
|
935
|
+
ticker: tickerParam,
|
|
936
|
+
hops: z10.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.")
|
|
937
|
+
});
|
|
938
|
+
var divergenceMetricsParameters = z10.object({ ticker: tickerParam });
|
|
939
|
+
var architectureReferenceParameters = z10.object({});
|
|
298
940
|
var AI_TOOLS = {
|
|
299
941
|
get_telemetry_graph: {
|
|
300
942
|
name: "get_telemetry_graph",
|
|
@@ -320,6 +962,21 @@ var AI_TOOLS = {
|
|
|
320
962
|
name: "get_company_profile",
|
|
321
963
|
description: "Fetches fundamental company data including the business description, sector, industry, market cap, and P/E ratio.",
|
|
322
964
|
parameters: companyProfileParameters
|
|
965
|
+
},
|
|
966
|
+
get_counterparty_graph: {
|
|
967
|
+
name: "get_counterparty_graph",
|
|
968
|
+
description: "Displays the inferred counterparty relationship graph for a company \u2014 suppliers, customers, partners, competitors, regulators, and investment/acquisition relationships that Fleet-Brain-Deep has extracted from alternative signals. Use this when the user asks about a company's business relationships, supply chain, competitors, or who it partners/invests with. Not for corporate ownership structure (parent/subsidiary) \u2014 use company profile data for that.",
|
|
969
|
+
parameters: counterpartyGraphParameters
|
|
970
|
+
},
|
|
971
|
+
get_divergence_metrics: {
|
|
972
|
+
name: "get_divergence_metrics",
|
|
973
|
+
description: "Displays Fleet-Brain-Deep's operational and customer divergence scores for a company \u2014 a signed delta between expected (baseline) and observed performance, inferred from recent signals. Use this when the user asks whether something is going better or worse than expected operationally or from a customer-experience standpoint.",
|
|
974
|
+
parameters: divergenceMetricsParameters
|
|
975
|
+
},
|
|
976
|
+
get_architecture_reference: {
|
|
977
|
+
name: "get_architecture_reference",
|
|
978
|
+
description: "Explains THIS PLATFORM'S OWN data architecture \u2014 its tech stack, database schema and data modeling, AI/LLM integration points, and background worker (sentinel) fleet. Use this for questions about how the system itself is built, not about a company or the market. Takes no parameters.",
|
|
979
|
+
parameters: architectureReferenceParameters
|
|
323
980
|
}
|
|
324
981
|
};
|
|
325
982
|
|
|
@@ -327,6 +984,16 @@ var AI_TOOLS = {
|
|
|
327
984
|
var DEFAULT_SCHEMA_MODEL = "gemini-2.5-flash";
|
|
328
985
|
var DEFAULT_CHAT_MODEL = "gemini-2.5-flash";
|
|
329
986
|
var DEFAULT_PRO_MODEL = "gemini-2.5-pro";
|
|
987
|
+
var PROVIDER_DEFAULT_MODEL = {
|
|
988
|
+
"google-gemini": "gemini-2.5-flash",
|
|
989
|
+
"openai": "gpt-4o-mini",
|
|
990
|
+
"anthropic": "claude-haiku-4-5-20251001",
|
|
991
|
+
"grok": "grok-2-1212",
|
|
992
|
+
"deepseek": "deepseek-chat",
|
|
993
|
+
"ollama": "llama3.3"
|
|
994
|
+
};
|
|
995
|
+
var ASSISTANT_PROVIDER = "anthropic";
|
|
996
|
+
var ASSISTANT_MODEL = PROVIDER_DEFAULT_MODEL[ASSISTANT_PROVIDER];
|
|
330
997
|
var AI_ROSTER = {
|
|
331
998
|
/** The Strategist: high creativity, exploratory conversation */
|
|
332
999
|
STRATEGIST: {
|
|
@@ -504,13 +1171,150 @@ RULE: If you cannot express a UI intent with a semantic token from the \u2705 li
|
|
|
504
1171
|
use bg-card or bg-background as a safe fallback. NEVER invent raw colors.
|
|
505
1172
|
`;
|
|
506
1173
|
|
|
1174
|
+
// src/ai/prompts/appDocument.prompt.ts
|
|
1175
|
+
var APP_DOCUMENT_SYSTEM_PROMPT = `
|
|
1176
|
+
You write tiny apps for a small desk device whose screen is 320 pixels wide and
|
|
1177
|
+
240 pixels high \u2014 landscape.
|
|
1178
|
+
|
|
1179
|
+
Reply with ONE JSON object and nothing else. No markdown fences, no explanation.
|
|
1180
|
+
|
|
1181
|
+
THE SHAPE
|
|
1182
|
+
|
|
1183
|
+
{
|
|
1184
|
+
"schemaVersion": 1,
|
|
1185
|
+
"id": "lowercase-slug",
|
|
1186
|
+
"name": "Short Name",
|
|
1187
|
+
"screen": "320x240",
|
|
1188
|
+
"background": "background",
|
|
1189
|
+
"sources": { },
|
|
1190
|
+
"blocks": [ ]
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
BLOCKS \u2014 up to 12, drawn top to bottom. Each is one of:
|
|
1194
|
+
|
|
1195
|
+
{ "type": "text", "value": V, "size": S, "align": A, "color": C, "suffix": "\xB0" }
|
|
1196
|
+
{ "type": "dial", "value": V, "min": 0, "max": 100, "label": "CPU", "color": C }
|
|
1197
|
+
{ "type": "bar", "value": V, "min": 0, "max": 100, "color": C }
|
|
1198
|
+
{ "type": "sparkline", "series": V, "color": C }
|
|
1199
|
+
{ "type": "status", "state": V, "label": "Door", "color": C }
|
|
1200
|
+
{ "type": "sprite", "palette": [C, ...], "grid": "0011
|
|
1201
|
+
0110
|
|
1202
|
+
1100
|
|
1203
|
+
0011", "align": A }
|
|
1204
|
+
{ "type": "group", "direction": "row"|"stack", "gap": 8, "align": A, "children": [ ...leaves... ] }
|
|
1205
|
+
|
|
1206
|
+
DRAWING A SPRITE \u2014 you may, and here is the only form that works.
|
|
1207
|
+
|
|
1208
|
+
Write a "grid": one line per row, one hex character per pixel, each character
|
|
1209
|
+
indexing "palette" (so "0" is the first colour, "1" the second, up to "f").
|
|
1210
|
+
Every row must be exactly the same length. Up to 64x64, but 16x16 and 32x32
|
|
1211
|
+
look far better \u2014 small palettes and bold shapes read on a 320x240 panel, fine
|
|
1212
|
+
detail does not.
|
|
1213
|
+
|
|
1214
|
+
{ "type": "sprite",
|
|
1215
|
+
"palette": ["background", "255 214 10", "17 17 17"],
|
|
1216
|
+
"grid": "0011110
|
|
1217
|
+
0122210
|
|
1218
|
+
1222221
|
|
1219
|
+
1211121
|
|
1220
|
+
1222221
|
|
1221
|
+
0122210
|
|
1222
|
+
0011110" }
|
|
1223
|
+
|
|
1224
|
+
Put the background colour FIRST so "0" means empty, and use "." as a synonym
|
|
1225
|
+
for "0" if it makes the shape easier to see while you write it.
|
|
1226
|
+
|
|
1227
|
+
Palette entries are the same colours as everywhere else: a semantic token
|
|
1228
|
+
re-colours with the theme, which is what an icon wants, and literal "R G B"
|
|
1229
|
+
does not, which is what a picture wants.
|
|
1230
|
+
|
|
1231
|
+
NEVER write a "pixels" field yourself. That is base64 of packed nibbles, one
|
|
1232
|
+
wrong character shifts every pixel after it, and you cannot check it. Write the
|
|
1233
|
+
grid; it is converted for you. If a document you are editing already has
|
|
1234
|
+
"pixels" and no "grid", leave it exactly as it is.
|
|
1235
|
+
|
|
1236
|
+
PHOTOS \u2014 a document you are editing may hold { "type": "image", "asset": "<64 hex
|
|
1237
|
+
characters>", ... }. That is a picture someone uploaded, named by the hash of
|
|
1238
|
+
its file. Keep every image block exactly as it is unless asked to remove it, and
|
|
1239
|
+
never write one yourself: you cannot make the file it names, so any hash you
|
|
1240
|
+
invent draws nothing.
|
|
1241
|
+
|
|
1242
|
+
Count your rows before you answer. A grid whose rows are different lengths is
|
|
1243
|
+
the one mistake that will come back to you.
|
|
1244
|
+
|
|
1245
|
+
A group holds leaves only. Groups do NOT nest inside groups \u2014 the device has no
|
|
1246
|
+
layout engine, only computed offsets.
|
|
1247
|
+
|
|
1248
|
+
CONDITIONS \u2014 any block may also carry these:
|
|
1249
|
+
|
|
1250
|
+
"hideWhen": { "value": O, "op": "<", "than": 32 }
|
|
1251
|
+
leave it off the screen entirely while that is true
|
|
1252
|
+
|
|
1253
|
+
"rules": [ { "when": { "value": O, "op": "<", "than": 32 }, "color": "accent" },
|
|
1254
|
+
{ "when": { "value": O, "op": ">", "than": 85 }, "color": "danger" } ]
|
|
1255
|
+
style that applies only when something is true. First match wins, so write
|
|
1256
|
+
the narrowest band first. At most four. Each may set "color", "size" or both.
|
|
1257
|
+
|
|
1258
|
+
op is one of "<" "<=" ">" ">=" "==" "!="
|
|
1259
|
+
Only == and != work on words; the rest are for numbers.
|
|
1260
|
+
|
|
1261
|
+
O is an operand: { "literal": 32 } or { "source": "forecast", "field": "temperature" }
|
|
1262
|
+
|
|
1263
|
+
This is how "make it red when it is freezing" is expressed. Use it whenever a
|
|
1264
|
+
request contains "when", "if", "unless", "only", or a colour tied to a value.
|
|
1265
|
+
|
|
1266
|
+
S (size) "xs" | "sm" | "base" | "lg" | "xl" | "display"
|
|
1267
|
+
A (align) "start" | "center" | "end"
|
|
1268
|
+
C (color) "background" | "foreground" | "muted" | "accent" | "success" | "warning" | "danger"
|
|
1269
|
+
or three space-separated RGB numbers, e.g. "220 53 69"
|
|
1270
|
+
|
|
1271
|
+
VALUES \u2014 every V is one of:
|
|
1272
|
+
|
|
1273
|
+
{ "literal": "Hello" } text you wrote
|
|
1274
|
+
{ "source": "forecast", "field": "temperature" } read from a source
|
|
1275
|
+
{ "compute": "subtract", "of": [O, O], "round": true } arithmetic
|
|
1276
|
+
|
|
1277
|
+
compute is "add" | "subtract" | "multiply" | "divide", exactly two operands,
|
|
1278
|
+
and it does NOT nest \u2014 an operand is a literal or a source field, never
|
|
1279
|
+
another compute. "The difference between the high and the low" is the shape
|
|
1280
|
+
this is for.
|
|
1281
|
+
|
|
1282
|
+
SOURCES \u2014 declare what the app reads, then bind to it by name:
|
|
1283
|
+
|
|
1284
|
+
"forecast": { "kind": "weather", "latitude": 39.95, "longitude": -75.17,
|
|
1285
|
+
"units": "imperial", "refreshSeconds": 600 }
|
|
1286
|
+
fields: temperature, condition, high, low
|
|
1287
|
+
"now": { "kind": "clock", "timezone": "America/New_York", "twentyFourHour": false }
|
|
1288
|
+
fields: time, date, weekday, hour (hour is 0-23, for rules about time of day)
|
|
1289
|
+
"until": { "kind": "countdown", "target": "2026-12-25", "label": "Christmas" }
|
|
1290
|
+
fields: days, hours, minutes, seconds, label
|
|
1291
|
+
"fixed": { "kind": "static", "values": { "anything": 1 } }
|
|
1292
|
+
fields: whatever you put in values
|
|
1293
|
+
|
|
1294
|
+
RULES
|
|
1295
|
+
|
|
1296
|
+
1. 320x240 is small, and it is wider than it is tall. A "display" size text is
|
|
1297
|
+
about 56 pixels tall \u2014 one of those and two or three smaller lines fill the
|
|
1298
|
+
height. Use the width: a "row" group puts two or three things side by side.
|
|
1299
|
+
Prefer fewer, bigger things over a dense dashboard.
|
|
1300
|
+
2. Use semantic colours unless asked for a specific one. They follow the theme.
|
|
1301
|
+
3. There is no scrolling and no text wrapping. Long strings are cut off.
|
|
1302
|
+
4. No tables, no forms, no images, no buttons. The screen shows; it does not
|
|
1303
|
+
take input.
|
|
1304
|
+
5. If the request needs something the vocabulary cannot express, build the
|
|
1305
|
+
closest thing it can and do not invent a component.
|
|
1306
|
+
6. Prefer a rule over a fixed colour whenever the request ties appearance to a
|
|
1307
|
+
value. "Red when cold" is a rule; "red" is not.
|
|
1308
|
+
`.trim();
|
|
1309
|
+
var APP_DOCUMENT_EDIT_PREFIX = "Here is the current app. Change only what is asked:";
|
|
1310
|
+
|
|
507
1311
|
// src/theme/schema.ts
|
|
508
|
-
import { z as
|
|
509
|
-
var RGBString =
|
|
1312
|
+
import { z as z11 } from "zod";
|
|
1313
|
+
var RGBString = z11.string().regex(
|
|
510
1314
|
/^\d{1,3}\s+\d{1,3}\s+\d{1,3}$/,
|
|
511
1315
|
'Must be space-separated RGB integers (e.g. "13 110 253")'
|
|
512
1316
|
);
|
|
513
|
-
var ThemeOverridesSchema =
|
|
1317
|
+
var ThemeOverridesSchema = z11.object({
|
|
514
1318
|
// ── Core Brand ───────────────────────────────────────────────────────────
|
|
515
1319
|
"--app-primary-color": RGBString.optional(),
|
|
516
1320
|
"--app-primary-foreground-color": RGBString.optional(),
|
|
@@ -526,9 +1330,9 @@ var ThemeOverridesSchema = z6.object({
|
|
|
526
1330
|
"--app-muted-bg": RGBString.optional(),
|
|
527
1331
|
"--app-muted-text": RGBString.optional(),
|
|
528
1332
|
// ── Shape ────────────────────────────────────────────────────────────────
|
|
529
|
-
"--app-border-radius-sm":
|
|
530
|
-
"--app-border-radius-md":
|
|
531
|
-
"--app-border-radius-lg":
|
|
1333
|
+
"--app-border-radius-sm": z11.string().optional(),
|
|
1334
|
+
"--app-border-radius-md": z11.string().optional(),
|
|
1335
|
+
"--app-border-radius-lg": z11.string().optional(),
|
|
532
1336
|
// ── Form Controls ────────────────────────────────────────────────────────
|
|
533
1337
|
"--app-input-bg-color": RGBString.optional(),
|
|
534
1338
|
"--app-input-text-color": RGBString.optional(),
|
|
@@ -542,19 +1346,19 @@ var ThemeOverridesSchema = z6.object({
|
|
|
542
1346
|
"--app-chart-4": RGBString.optional(),
|
|
543
1347
|
"--app-chart-5": RGBString.optional()
|
|
544
1348
|
}).strict();
|
|
545
|
-
var ThemeFontsSchema =
|
|
1349
|
+
var ThemeFontsSchema = z11.object({
|
|
546
1350
|
/** Google Font name for headings (h1–h4, .font-serif). Example: "Playfair Display" */
|
|
547
|
-
heading:
|
|
1351
|
+
heading: z11.string(),
|
|
548
1352
|
/** Google Font name for body text. Example: "Inter" */
|
|
549
|
-
body:
|
|
1353
|
+
body: z11.string(),
|
|
550
1354
|
/** Optional monospace font. Example: "Roboto Mono" */
|
|
551
|
-
mono:
|
|
1355
|
+
mono: z11.string().optional()
|
|
552
1356
|
});
|
|
553
|
-
var AIThemeSchema =
|
|
1357
|
+
var AIThemeSchema = z11.object({
|
|
554
1358
|
/** Short descriptive theme name. Example: "Midnight Garden" */
|
|
555
|
-
name:
|
|
1359
|
+
name: z11.string(),
|
|
556
1360
|
/** One-sentence vibe description. Example: "Dark indigo with golden accents." */
|
|
557
|
-
description:
|
|
1361
|
+
description: z11.string(),
|
|
558
1362
|
/** Google Font pairing for heading and body text. */
|
|
559
1363
|
fonts: ThemeFontsSchema.optional(),
|
|
560
1364
|
/**
|
|
@@ -565,13 +1369,13 @@ var AIThemeSchema = z6.object({
|
|
|
565
1369
|
cssVars: ThemeOverridesSchema
|
|
566
1370
|
});
|
|
567
1371
|
var THEME_PRESETS = ["light", "dark", "system", "corporate", "midnight", "blueprint"];
|
|
568
|
-
var ThemeTokensSchema =
|
|
1372
|
+
var ThemeTokensSchema = z11.object({
|
|
569
1373
|
primary: RGBString,
|
|
570
1374
|
neutral: RGBString,
|
|
571
1375
|
success: RGBString,
|
|
572
1376
|
warning: RGBString,
|
|
573
1377
|
destructive: RGBString,
|
|
574
|
-
radius:
|
|
1378
|
+
radius: z11.enum(["none", "sm", "md", "lg", "full"])
|
|
575
1379
|
});
|
|
576
1380
|
var DEFAULT_THEME_TOKENS = {
|
|
577
1381
|
primary: "13 110 253",
|
|
@@ -583,22 +1387,101 @@ var DEFAULT_THEME_TOKENS = {
|
|
|
583
1387
|
};
|
|
584
1388
|
|
|
585
1389
|
// src/auth/schema.ts
|
|
586
|
-
import { z as
|
|
587
|
-
var UserSchema =
|
|
588
|
-
id:
|
|
589
|
-
name:
|
|
590
|
-
email:
|
|
591
|
-
password:
|
|
592
|
-
role:
|
|
593
|
-
status:
|
|
594
|
-
joinedAt:
|
|
595
|
-
lastActive:
|
|
596
|
-
avatarUrl:
|
|
1390
|
+
import { z as z12 } from "zod";
|
|
1391
|
+
var UserSchema = z12.object({
|
|
1392
|
+
id: z12.string().default(""),
|
|
1393
|
+
name: z12.string(),
|
|
1394
|
+
email: z12.string().email(),
|
|
1395
|
+
password: z12.string().optional(),
|
|
1396
|
+
role: z12.string(),
|
|
1397
|
+
status: z12.string().optional(),
|
|
1398
|
+
joinedAt: z12.string().optional(),
|
|
1399
|
+
lastActive: z12.string().optional(),
|
|
1400
|
+
avatarUrl: z12.string().optional()
|
|
1401
|
+
});
|
|
1402
|
+
|
|
1403
|
+
// src/auth/accounts.ts
|
|
1404
|
+
import { z as z13 } from "zod";
|
|
1405
|
+
var AccountIdSchema = z13.string().regex(/^acct_[0-9a-f]{12}$/, "acct_ and 12 hex digits");
|
|
1406
|
+
var AccountRoleSchema = z13.enum(["member", "admin"]);
|
|
1407
|
+
var AccountStatusSchema = z13.enum(["active", "suspended"]);
|
|
1408
|
+
var ScryptHashSchema = z13.object({
|
|
1409
|
+
algo: z13.literal("scrypt"),
|
|
1410
|
+
n: z13.number().int().positive(),
|
|
1411
|
+
r: z13.number().int().positive(),
|
|
1412
|
+
p: z13.number().int().positive(),
|
|
1413
|
+
keylen: z13.number().int().positive(),
|
|
1414
|
+
salt: z13.string().min(16),
|
|
1415
|
+
hash: z13.string().min(16)
|
|
1416
|
+
});
|
|
1417
|
+
var AccountRecordSchema = z13.object({
|
|
1418
|
+
accountId: AccountIdSchema,
|
|
1419
|
+
/** Lowercased on write, because a login must not depend on how it was typed. */
|
|
1420
|
+
email: z13.string().email().max(254),
|
|
1421
|
+
name: z13.string().min(1).max(64),
|
|
1422
|
+
role: AccountRoleSchema,
|
|
1423
|
+
status: AccountStatusSchema,
|
|
1424
|
+
password: ScryptHashSchema,
|
|
1425
|
+
createdAt: z13.number().int().nonnegative(),
|
|
1426
|
+
lastLoginAt: z13.number().int().nonnegative().nullable().default(null),
|
|
1427
|
+
/** Which admin approved this, or null for the bootstrap account. */
|
|
1428
|
+
invitedBy: AccountIdSchema.nullable().default(null)
|
|
1429
|
+
});
|
|
1430
|
+
var PublicAccountSchema = z13.object({
|
|
1431
|
+
accountId: AccountIdSchema,
|
|
1432
|
+
email: z13.string().email(),
|
|
1433
|
+
name: z13.string(),
|
|
1434
|
+
role: AccountRoleSchema,
|
|
1435
|
+
status: AccountStatusSchema
|
|
1436
|
+
});
|
|
1437
|
+
var SessionRecordSchema = z13.object({
|
|
1438
|
+
accountId: AccountIdSchema,
|
|
1439
|
+
createdAt: z13.number().int().nonnegative(),
|
|
1440
|
+
expiresAt: z13.number().int().nonnegative(),
|
|
1441
|
+
lastSeenAt: z13.number().int().nonnegative()
|
|
1442
|
+
});
|
|
1443
|
+
var InviteRecordSchema = z13.object({
|
|
1444
|
+
email: z13.string().email().max(254),
|
|
1445
|
+
role: AccountRoleSchema,
|
|
1446
|
+
createdAt: z13.number().int().nonnegative(),
|
|
1447
|
+
expiresAt: z13.number().int().nonnegative(),
|
|
1448
|
+
invitedBy: AccountIdSchema
|
|
597
1449
|
});
|
|
1450
|
+
var AccessRequestSchema = z13.object({
|
|
1451
|
+
email: z13.string().email().max(254),
|
|
1452
|
+
name: z13.string().min(1).max(64),
|
|
1453
|
+
/** Optional, and never shown publicly. Long enough to be useful, short enough not to be an essay. */
|
|
1454
|
+
reason: z13.string().max(500).optional()
|
|
1455
|
+
});
|
|
1456
|
+
var AccessRequestStatusSchema = z13.enum(["pending", "approved", "denied"]);
|
|
1457
|
+
var AccessRequestRecordSchema = z13.object({
|
|
1458
|
+
requestId: z13.string().regex(/^req_[0-9a-f]{12}$/, "req_ and 12 hex digits"),
|
|
1459
|
+
email: z13.string().email().max(254),
|
|
1460
|
+
name: z13.string().min(1).max(64),
|
|
1461
|
+
reason: z13.string().max(500).optional(),
|
|
1462
|
+
status: AccessRequestStatusSchema,
|
|
1463
|
+
createdAt: z13.number().int().nonnegative(),
|
|
1464
|
+
decidedAt: z13.number().int().nonnegative().nullable().default(null),
|
|
1465
|
+
decidedBy: AccountIdSchema.nullable().default(null)
|
|
1466
|
+
});
|
|
1467
|
+
var SCRYPT_PARAMS = {
|
|
1468
|
+
n: 32768,
|
|
1469
|
+
r: 8,
|
|
1470
|
+
p: 1,
|
|
1471
|
+
keylen: 64,
|
|
1472
|
+
maxmem: 64 * 1024 * 1024
|
|
1473
|
+
};
|
|
1474
|
+
var MIN_PASSWORD_LENGTH = 12;
|
|
1475
|
+
var MAX_PASSWORD_LENGTH = 200;
|
|
1476
|
+
var SESSION_COOKIE_NAME = "ramme_session";
|
|
1477
|
+
var SESSION_TTL_SECONDS = 60 * 60 * 24 * 30;
|
|
1478
|
+
var ACCOUNT_TTL_SECONDS = 60 * 60 * 24 * 400;
|
|
1479
|
+
var INVITE_TTL_SECONDS = 60 * 60 * 24 * 14;
|
|
1480
|
+
var ACCESS_REQUEST_TTL_SECONDS = 60 * 60 * 24 * 90;
|
|
598
1481
|
|
|
599
1482
|
// src/counterparty/schema.ts
|
|
600
|
-
import { z as
|
|
601
|
-
var CounterpartyTypeSchema =
|
|
1483
|
+
import { z as z14 } from "zod";
|
|
1484
|
+
var CounterpartyTypeSchema = z14.enum([
|
|
602
1485
|
"supplier",
|
|
603
1486
|
"customer",
|
|
604
1487
|
"partner",
|
|
@@ -606,91 +1489,331 @@ var CounterpartyTypeSchema = z8.enum([
|
|
|
606
1489
|
"regulator",
|
|
607
1490
|
"unknown"
|
|
608
1491
|
]);
|
|
609
|
-
var
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
1492
|
+
var CounterpartyResolutionSchema = z14.enum([
|
|
1493
|
+
"public",
|
|
1494
|
+
"public_uncovered",
|
|
1495
|
+
"private",
|
|
1496
|
+
"unresolved"
|
|
1497
|
+
]);
|
|
1498
|
+
var CounterpartyNodeSchema = z14.object({
|
|
1499
|
+
id: z14.string(),
|
|
1500
|
+
ticker: z14.string().nullable(),
|
|
1501
|
+
/** Name as it appeared in the source signal — e.g. "Nike". Not the registered name. */
|
|
1502
|
+
name: z14.string(),
|
|
1503
|
+
/** Registered legal name from `profiles` — e.g. "NIKE, Inc.". Null unless `public`. */
|
|
1504
|
+
publicName: z14.string().nullable(),
|
|
1505
|
+
lei: z14.string().nullable(),
|
|
1506
|
+
resolution: CounterpartyResolutionSchema,
|
|
613
1507
|
type: CounterpartyTypeSchema,
|
|
614
|
-
confidence:
|
|
615
|
-
sourceSignalIds:
|
|
616
|
-
firstSeenAt:
|
|
617
|
-
lastSeenAt:
|
|
1508
|
+
confidence: z14.number().min(0).max(1),
|
|
1509
|
+
sourceSignalIds: z14.array(z14.number()),
|
|
1510
|
+
firstSeenAt: z14.string().datetime(),
|
|
1511
|
+
lastSeenAt: z14.string().datetime()
|
|
618
1512
|
});
|
|
619
|
-
var RelationshipEdgeTypeSchema =
|
|
1513
|
+
var RelationshipEdgeTypeSchema = z14.enum([
|
|
620
1514
|
"supplies_to",
|
|
621
1515
|
"purchases_from",
|
|
622
1516
|
"partners_with",
|
|
623
1517
|
"competes_with",
|
|
624
|
-
"regulated_by"
|
|
1518
|
+
"regulated_by",
|
|
1519
|
+
"invests_in",
|
|
1520
|
+
"acquires",
|
|
1521
|
+
/**
|
|
1522
|
+
* Identity equivalence, not a business relationship: source and target are
|
|
1523
|
+
* the same real-world entity under two different node ids (typically a
|
|
1524
|
+
* slug-keyed node that predates LEI resolution, pointing at the canonical
|
|
1525
|
+
* LEI-keyed node once resolution succeeds). Never delete/merge either
|
|
1526
|
+
* node — this edge exists so a consumer wanting a deduped view can follow
|
|
1527
|
+
* it to the canonical id, reversibly.
|
|
1528
|
+
*/
|
|
1529
|
+
"same_as"
|
|
625
1530
|
]);
|
|
626
|
-
var RelationshipEdgeSchema =
|
|
627
|
-
id:
|
|
628
|
-
sourceId:
|
|
629
|
-
targetId:
|
|
1531
|
+
var RelationshipEdgeSchema = z14.object({
|
|
1532
|
+
id: z14.string(),
|
|
1533
|
+
sourceId: z14.string(),
|
|
1534
|
+
targetId: z14.string(),
|
|
630
1535
|
edgeType: RelationshipEdgeTypeSchema,
|
|
631
|
-
weight:
|
|
632
|
-
evidenceSignalIds:
|
|
633
|
-
updatedAt:
|
|
1536
|
+
weight: z14.number().min(0).max(1),
|
|
1537
|
+
evidenceSignalIds: z14.array(z14.number()),
|
|
1538
|
+
updatedAt: z14.string().datetime(),
|
|
1539
|
+
validFrom: z14.string().datetime(),
|
|
1540
|
+
/** null = currently valid. Set when a differently-typed edge supersedes this one. */
|
|
1541
|
+
validTo: z14.string().datetime().nullable()
|
|
634
1542
|
});
|
|
635
|
-
var SignalWeightSchema =
|
|
636
|
-
signalId:
|
|
637
|
-
weight:
|
|
638
|
-
reason:
|
|
1543
|
+
var SignalWeightSchema = z14.object({
|
|
1544
|
+
signalId: z14.number(),
|
|
1545
|
+
weight: z14.number().min(0).max(1),
|
|
1546
|
+
reason: z14.string().max(280)
|
|
639
1547
|
});
|
|
640
|
-
var DivergenceMetricSchema =
|
|
641
|
-
ticker:
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
1548
|
+
var DivergenceMetricSchema = z14.object({
|
|
1549
|
+
ticker: z14.string(),
|
|
1550
|
+
// 'operations'/'customer' are current; 'operational'/'ux' are pre-rename
|
|
1551
|
+
// values that still exist on rows written before the backend's rename —
|
|
1552
|
+
// kept here so reading old rows doesn't fail validation.
|
|
1553
|
+
metric: z14.enum(["operations", "customer", "operational", "ux"]),
|
|
1554
|
+
score: z14.number(),
|
|
1555
|
+
baseline: z14.number(),
|
|
1556
|
+
observed: z14.number(),
|
|
1557
|
+
computedAt: z14.string().datetime(),
|
|
1558
|
+
contributingSignals: z14.array(SignalWeightSchema)
|
|
648
1559
|
});
|
|
649
1560
|
|
|
650
1561
|
// src/non-public-entity/schema.ts
|
|
651
|
-
import { z as
|
|
652
|
-
var NonPublicEntitySchema =
|
|
653
|
-
lei:
|
|
654
|
-
entityName:
|
|
655
|
-
jurisdiction:
|
|
656
|
-
registrationStatus:
|
|
657
|
-
parentEntityLei:
|
|
658
|
-
materialMetadata:
|
|
659
|
-
discoveredAt:
|
|
1562
|
+
import { z as z15 } from "zod";
|
|
1563
|
+
var NonPublicEntitySchema = z15.object({
|
|
1564
|
+
lei: z15.string().nullable(),
|
|
1565
|
+
entityName: z15.string(),
|
|
1566
|
+
jurisdiction: z15.string().nullable(),
|
|
1567
|
+
registrationStatus: z15.string(),
|
|
1568
|
+
parentEntityLei: z15.string().nullable(),
|
|
1569
|
+
materialMetadata: z15.record(z15.unknown()),
|
|
1570
|
+
discoveredAt: z15.string().datetime()
|
|
1571
|
+
});
|
|
1572
|
+
|
|
1573
|
+
// src/events/schema.ts
|
|
1574
|
+
import { z as z16 } from "zod";
|
|
1575
|
+
var EventSourceSchema = z16.enum(["db", "mock"]);
|
|
1576
|
+
var EntityEventKindSchema = z16.enum(["news", "filing", "report"]);
|
|
1577
|
+
var ImpactScaleSchema = z16.enum(["graded", "binary", "default", "none"]);
|
|
1578
|
+
var TimestampPrecisionSchema = z16.enum(["second", "day"]);
|
|
1579
|
+
var EntityEventSchema = z16.object({
|
|
1580
|
+
/** Namespaced so ids never collide across sources: `news:1234`, `filing:AAPL:2026-07-31`. */
|
|
1581
|
+
id: z16.string(),
|
|
1582
|
+
kind: EntityEventKindSchema,
|
|
1583
|
+
/**
|
|
1584
|
+
* The producer's own type string, unmodified — `NEWS_YAHOO FINANCE_YAHOO RSS`,
|
|
1585
|
+
* `ANNUAL`, `SNAPSHOT`. There are 31 distinct NEWS variants in the live table,
|
|
1586
|
+
* so this is for filtering and debugging: never render it raw to a user.
|
|
1587
|
+
*/
|
|
1588
|
+
subtype: z16.string().nullable(),
|
|
1589
|
+
ticker: z16.string(),
|
|
1590
|
+
/** Always `YYYY-MM-DDTHH:MM:SSZ`. Fixed-width, so lexical order == chronological order. */
|
|
1591
|
+
occurredAt: z16.string(),
|
|
1592
|
+
precision: TimestampPrecisionSchema,
|
|
1593
|
+
title: z16.string(),
|
|
1594
|
+
summary: z16.string().nullable(),
|
|
1595
|
+
url: z16.string().nullable(),
|
|
1596
|
+
impact: z16.number().nullable(),
|
|
1597
|
+
impactScale: ImpactScaleSchema,
|
|
1598
|
+
/** 0 bearish … 50 neutral … 100 bullish. */
|
|
1599
|
+
sentiment: z16.number().nullable(),
|
|
1600
|
+
/** False for filings, and for any event sitting at exactly neutral. */
|
|
1601
|
+
sentimentIsMeaningful: z16.boolean(),
|
|
1602
|
+
source: EventSourceSchema,
|
|
1603
|
+
meta: z16.record(z16.unknown()).nullable()
|
|
1604
|
+
});
|
|
1605
|
+
var PaginatedEntityEventsSchema = z16.object({
|
|
1606
|
+
total: z16.number(),
|
|
1607
|
+
page: z16.number(),
|
|
1608
|
+
page_size: z16.number(),
|
|
1609
|
+
data: z16.array(EntityEventSchema)
|
|
660
1610
|
});
|
|
1611
|
+
var EventBucketSizeSchema = z16.enum(["day", "week", "month"]);
|
|
1612
|
+
var EntityEventDensityBucketSchema = z16.object({
|
|
1613
|
+
bucketStart: z16.string(),
|
|
1614
|
+
kind: EntityEventKindSchema,
|
|
1615
|
+
count: z16.number(),
|
|
1616
|
+
/** Null when no event in the bucket had meaningful sentiment. */
|
|
1617
|
+
avgSentiment: z16.number().nullable(),
|
|
1618
|
+
maxImpact: z16.number().nullable()
|
|
1619
|
+
});
|
|
1620
|
+
var EntityEventDensitySchema = z16.object({
|
|
1621
|
+
ticker: z16.string(),
|
|
1622
|
+
bucket: EventBucketSizeSchema,
|
|
1623
|
+
buckets: z16.array(EntityEventDensityBucketSchema),
|
|
1624
|
+
/** So the client can set its time domain without a second request. */
|
|
1625
|
+
range: z16.object({ min: z16.string(), max: z16.string() }),
|
|
1626
|
+
source: EventSourceSchema
|
|
1627
|
+
});
|
|
1628
|
+
var EntityEventFacetSchema = z16.object({
|
|
1629
|
+
kind: EntityEventKindSchema,
|
|
1630
|
+
count: z16.number(),
|
|
1631
|
+
earliest: z16.string().nullable(),
|
|
1632
|
+
latest: z16.string().nullable(),
|
|
1633
|
+
impactScale: ImpactScaleSchema,
|
|
1634
|
+
sentimentUsable: z16.boolean()
|
|
1635
|
+
});
|
|
1636
|
+
var EntityEventFacetsSchema = z16.object({
|
|
1637
|
+
ticker: z16.string(),
|
|
1638
|
+
facets: z16.array(EntityEventFacetSchema),
|
|
1639
|
+
source: EventSourceSchema
|
|
1640
|
+
});
|
|
1641
|
+
var DailyPricePointSchema = z16.object({
|
|
1642
|
+
date: z16.string(),
|
|
1643
|
+
open: z16.number().nullable(),
|
|
1644
|
+
high: z16.number().nullable(),
|
|
1645
|
+
low: z16.number().nullable(),
|
|
1646
|
+
close: z16.number(),
|
|
1647
|
+
volume: z16.number().nullable()
|
|
1648
|
+
});
|
|
1649
|
+
var EntityPriceSeriesSchema = z16.object({
|
|
1650
|
+
ticker: z16.string(),
|
|
1651
|
+
series: z16.array(DailyPricePointSchema),
|
|
1652
|
+
source: EventSourceSchema
|
|
1653
|
+
});
|
|
1654
|
+
var EVENT_KIND_LABELS = {
|
|
1655
|
+
news: "News",
|
|
1656
|
+
filing: "Filing",
|
|
1657
|
+
report: "Analyst report"
|
|
1658
|
+
};
|
|
1659
|
+
var IMPACT_FLAG_THRESHOLD = 7;
|
|
1660
|
+
var SENTIMENT_NEUTRAL = 50;
|
|
1661
|
+
var DEFAULT_HORIZON_QUARTERS = 5;
|
|
1662
|
+
var EXCLUDED_SOURCES = {
|
|
1663
|
+
insights: "insights.ANALYSIS is a verbatim 1:1 mirror of signals \u2014 every AAPL ANALYSIS row contains a news description verbatim and lands within 2s of it. Including it doubles every event.",
|
|
1664
|
+
divergence_metrics: "A continuously recomputed annotation, not an event: 524 AAPL rows in 2 days.",
|
|
1665
|
+
counterparty_edges: "No history exists \u2014 all rows were created within a 2-day window, so nothing can be placed on a time axis without fabricating it.",
|
|
1666
|
+
raw_filings: "Stale since April, superseded by signals.",
|
|
1667
|
+
market_metrics: "Two rows total.",
|
|
1668
|
+
job_log: "24.5M rows with no ticker index \u2014 never touch it in a request path."
|
|
1669
|
+
};
|
|
661
1670
|
export {
|
|
1671
|
+
ACCESS_REQUEST_TTL_SECONDS,
|
|
1672
|
+
ACCOUNT_TTL_SECONDS,
|
|
662
1673
|
AIKeyManifestSchema,
|
|
663
1674
|
AIThemeSchema,
|
|
664
1675
|
AI_ROSTER,
|
|
665
1676
|
AI_TOOLS,
|
|
1677
|
+
APP_DOCUMENT_EDIT_PREFIX,
|
|
1678
|
+
APP_DOCUMENT_SYSTEM_PROMPT,
|
|
1679
|
+
ASSISTANT_MODEL,
|
|
1680
|
+
ASSISTANT_PROVIDER,
|
|
1681
|
+
AccessRequestRecordSchema,
|
|
1682
|
+
AccessRequestSchema,
|
|
1683
|
+
AccessRequestStatusSchema,
|
|
1684
|
+
AccountIdSchema,
|
|
1685
|
+
AccountRecordSchema,
|
|
1686
|
+
AccountRoleSchema,
|
|
1687
|
+
AccountStatusSchema,
|
|
666
1688
|
ActionSchema,
|
|
1689
|
+
AircraftAppConfigSchema,
|
|
1690
|
+
AppAlignSchema,
|
|
1691
|
+
AppBarSchema,
|
|
1692
|
+
AppBindingSchema,
|
|
1693
|
+
AppBlockSchema,
|
|
1694
|
+
AppColorSchema,
|
|
1695
|
+
AppColorTokenSchema,
|
|
1696
|
+
AppComputeSchema,
|
|
1697
|
+
AppConditionSchema,
|
|
1698
|
+
AppDialSchema,
|
|
1699
|
+
AppDocumentSchema,
|
|
1700
|
+
AppGroupSchema,
|
|
1701
|
+
AppImageSchema,
|
|
1702
|
+
AppLeafSchema,
|
|
1703
|
+
AppOperandSchema,
|
|
1704
|
+
AppRgbSchema,
|
|
1705
|
+
AppScreenSizeSchema,
|
|
667
1706
|
AppSignalSchema,
|
|
1707
|
+
AppSourceSchema,
|
|
1708
|
+
AppSparklineSchema,
|
|
668
1709
|
AppSpecificationSchema,
|
|
1710
|
+
AppSpriteSchema,
|
|
1711
|
+
AppStatusSchema,
|
|
1712
|
+
AppStyleRuleSchema,
|
|
1713
|
+
AppTextSchema,
|
|
1714
|
+
AppTextSizeSchema,
|
|
1715
|
+
AssetHashSchema,
|
|
669
1716
|
AuthStrategySchema,
|
|
670
1717
|
BlockSchema,
|
|
671
1718
|
schema_exports as Bodewell,
|
|
1719
|
+
CLAIMED_DEVICE_TTL_SECONDS,
|
|
1720
|
+
ClockAppConfigSchema,
|
|
672
1721
|
CounterpartyNodeSchema,
|
|
1722
|
+
CounterpartyResolutionSchema,
|
|
673
1723
|
CounterpartyTypeSchema,
|
|
674
1724
|
DEFAULT_CHAT_MODEL,
|
|
1725
|
+
DEFAULT_DEVICE_CONFIG,
|
|
1726
|
+
DEFAULT_HORIZON_QUARTERS,
|
|
675
1727
|
DEFAULT_PRO_MODEL,
|
|
676
1728
|
DEFAULT_SCHEMA_MODEL,
|
|
677
1729
|
DEFAULT_THEME_TOKENS,
|
|
1730
|
+
DEVICE_AP_SSID_PREFIX,
|
|
1731
|
+
DEVICE_ENDPOINTS,
|
|
1732
|
+
DEVICE_FRESH_MS,
|
|
1733
|
+
DEVICE_GLYPHS,
|
|
1734
|
+
DEVICE_LABEL_MAX,
|
|
1735
|
+
DEVICE_PALETTE,
|
|
1736
|
+
DEVICE_STALE_MS,
|
|
1737
|
+
DEVICE_TIMEZONES,
|
|
1738
|
+
DEVICE_TIMEZONE_FALLBACK,
|
|
1739
|
+
DEVICE_TTL_SECONDS,
|
|
1740
|
+
DEVICE_UNKNOWN_GLYPH,
|
|
1741
|
+
DEVICE_VITALS_FIELDS,
|
|
1742
|
+
DailyPricePointSchema,
|
|
1743
|
+
DeliveredAppSchema,
|
|
1744
|
+
DeviceAppIdSchema,
|
|
1745
|
+
DeviceAppsSchema,
|
|
1746
|
+
DeviceConfigSchema,
|
|
1747
|
+
DeviceDisplayConfigSchema,
|
|
1748
|
+
DeviceIdSchema,
|
|
1749
|
+
DeviceKindSchema,
|
|
1750
|
+
DeviceRecordSchema,
|
|
1751
|
+
DeviceRegistrationSchema,
|
|
1752
|
+
DeviceSeenSchema,
|
|
1753
|
+
DeviceStatusSchema,
|
|
1754
|
+
DeviceThemeSchema,
|
|
1755
|
+
DeviceVitalsSchema,
|
|
678
1756
|
DivergenceMetricSchema,
|
|
1757
|
+
EVENT_KIND_LABELS,
|
|
1758
|
+
EXCLUDED_SOURCES,
|
|
1759
|
+
EntityEventDensityBucketSchema,
|
|
1760
|
+
EntityEventDensitySchema,
|
|
1761
|
+
EntityEventFacetSchema,
|
|
1762
|
+
EntityEventFacetsSchema,
|
|
1763
|
+
EntityEventKindSchema,
|
|
1764
|
+
EntityEventSchema,
|
|
1765
|
+
EntityPriceSeriesSchema,
|
|
679
1766
|
EntitySchema,
|
|
1767
|
+
EventBucketSizeSchema,
|
|
1768
|
+
EventSourceSchema,
|
|
680
1769
|
FieldSchema,
|
|
681
1770
|
FloraTelemetrySchema,
|
|
682
1771
|
GENESIS_LIBRARY_CONTEXT,
|
|
683
1772
|
GENESIS_VALID_COMPONENTS,
|
|
1773
|
+
IMAGE_MAX_DRAWN,
|
|
1774
|
+
IMAGE_MAX_SCALE,
|
|
1775
|
+
IMPACT_FLAG_THRESHOLD,
|
|
1776
|
+
INVITE_TTL_SECONDS,
|
|
1777
|
+
ImpactScaleSchema,
|
|
1778
|
+
InviteRecordSchema,
|
|
1779
|
+
MAX_PASSWORD_LENGTH,
|
|
1780
|
+
MIN_PASSWORD_LENGTH,
|
|
684
1781
|
NonPublicEntitySchema,
|
|
1782
|
+
ORIGINAL_MAX_BYTES,
|
|
1783
|
+
ORIGINAL_MAX_SIDE,
|
|
1784
|
+
OwnedSendRequestSchema,
|
|
1785
|
+
PHOTOS_PER_ACCOUNT,
|
|
1786
|
+
PHOTO_UPLOADS_PER_HOUR,
|
|
1787
|
+
PROVIDER_DEFAULT_MODEL,
|
|
685
1788
|
PageSchema,
|
|
686
1789
|
PageSectionSchema,
|
|
1790
|
+
PaginatedEntityEventsSchema,
|
|
1791
|
+
PairCodeSchema,
|
|
1792
|
+
PhotoSummarySchema,
|
|
1793
|
+
PhotoUploadSchema,
|
|
1794
|
+
ProvisioningStateSchema,
|
|
1795
|
+
PublicAccountSchema,
|
|
1796
|
+
RETRO_RENDITION,
|
|
687
1797
|
RelationshipEdgeSchema,
|
|
688
1798
|
RelationshipEdgeTypeSchema,
|
|
689
1799
|
ResourceSchema,
|
|
1800
|
+
SCRYPT_PARAMS,
|
|
1801
|
+
SENTIMENT_NEUTRAL,
|
|
1802
|
+
SESSION_COOKIE_NAME,
|
|
1803
|
+
SESSION_TTL_SECONDS,
|
|
690
1804
|
SIGNAL_DOMAINS,
|
|
691
1805
|
SIGNAL_KINDS,
|
|
692
1806
|
SIGNAL_KIND_LABELS,
|
|
693
1807
|
SIGNAL_SOURCES,
|
|
1808
|
+
SPRITE_MAX_BASE64,
|
|
1809
|
+
SPRITE_MAX_ROW_BYTES,
|
|
1810
|
+
SPRITE_MAX_SIDE,
|
|
1811
|
+
SPR_FORMAT,
|
|
1812
|
+
SPR_MAX_BYTES,
|
|
1813
|
+
ScryptHashSchema,
|
|
1814
|
+
SendRequestSchema,
|
|
1815
|
+
SensorAppConfigSchema,
|
|
1816
|
+
SessionRecordSchema,
|
|
694
1817
|
SignalArraySchema,
|
|
695
1818
|
SignalKindSchema,
|
|
696
1819
|
SignalPacketSchema,
|
|
@@ -702,11 +1825,17 @@ export {
|
|
|
702
1825
|
ThemeFontsSchema,
|
|
703
1826
|
ThemeOverridesSchema,
|
|
704
1827
|
ThemeTokensSchema,
|
|
1828
|
+
TimestampPrecisionSchema,
|
|
705
1829
|
TriggerSchema,
|
|
706
1830
|
UserSchema,
|
|
1831
|
+
VitalSourceSchema,
|
|
1832
|
+
WeatherAppConfigSchema,
|
|
707
1833
|
WorkflowSchema,
|
|
1834
|
+
architectureReferenceParameters,
|
|
708
1835
|
companyNewsParameters,
|
|
709
1836
|
companyProfileParameters,
|
|
1837
|
+
counterpartyGraphParameters,
|
|
1838
|
+
divergenceMetricsParameters,
|
|
710
1839
|
liveQuoteParameters,
|
|
711
1840
|
stockChartParameters,
|
|
712
1841
|
telemetryGraphParameters
|