@sixb/server 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/experience.d.ts +33 -0
  3. package/dist/auth/experience.d.ts.map +1 -0
  4. package/dist/auth/public-routes.d.ts.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2122 -1391
  8. package/dist/index.js.map +24 -19
  9. package/dist/openapi/tags.d.ts +10 -2
  10. package/dist/openapi/tags.d.ts.map +1 -1
  11. package/dist/registerRoutes.d.ts.map +1 -1
  12. package/dist/routes/action-runs.d.ts +6 -6
  13. package/dist/routes/actions.d.ts +3 -3
  14. package/dist/routes/agents.d.ts +164 -77
  15. package/dist/routes/agents.d.ts.map +1 -1
  16. package/dist/routes/ai-accounting.d.ts +31 -0
  17. package/dist/routes/ai-accounting.d.ts.map +1 -0
  18. package/dist/routes/auth.d.ts +110 -53
  19. package/dist/routes/auth.d.ts.map +1 -1
  20. package/dist/routes/connector-connection-runs.d.ts +56 -56
  21. package/dist/routes/connector-connections.d.ts +14 -14
  22. package/dist/routes/datasets.d.ts +12 -12
  23. package/dist/routes/events.d.ts +1 -1
  24. package/dist/routes/files.d.ts +8 -8
  25. package/dist/routes/links.d.ts +6 -57
  26. package/dist/routes/links.d.ts.map +1 -1
  27. package/dist/routes/logs.d.ts +3 -3
  28. package/dist/routes/models.d.ts +60 -0
  29. package/dist/routes/models.d.ts.map +1 -0
  30. package/dist/routes/objects.d.ts +51 -3
  31. package/dist/routes/objects.d.ts.map +1 -1
  32. package/dist/routes/pipelines.d.ts +10 -10
  33. package/dist/routes/projections.d.ts +150 -136
  34. package/dist/routes/projections.d.ts.map +1 -1
  35. package/dist/routes/syncs.d.ts +38 -38
  36. package/dist/routes/telemetry.d.ts +7 -7
  37. package/dist/routes/webhook-runs.d.ts +2 -2
  38. package/dist/routes/workflows.d.ts +142 -57
  39. package/dist/routes/workflows.d.ts.map +1 -1
  40. package/dist/routes/ws/logs.d.ts +10 -10
  41. package/dist/schemas/actions.d.ts +16 -16
  42. package/dist/schemas/agents.d.ts +586 -142
  43. package/dist/schemas/agents.d.ts.map +1 -1
  44. package/dist/schemas/ai-accounting.d.ts +2393 -0
  45. package/dist/schemas/ai-accounting.d.ts.map +1 -0
  46. package/dist/schemas/auth.d.ts +96 -96
  47. package/dist/schemas/connectors.d.ts +35 -25
  48. package/dist/schemas/connectors.d.ts.map +1 -1
  49. package/dist/schemas/event-payloads.d.ts +6 -6
  50. package/dist/schemas/events.d.ts +6 -6
  51. package/dist/schemas/links.d.ts +0 -41
  52. package/dist/schemas/links.d.ts.map +1 -1
  53. package/dist/schemas/logs.d.ts +22 -22
  54. package/dist/schemas/models.d.ts +50 -0
  55. package/dist/schemas/models.d.ts.map +1 -0
  56. package/dist/schemas/objects.d.ts +22 -0
  57. package/dist/schemas/objects.d.ts.map +1 -1
  58. package/dist/schemas/pipelines.d.ts +20 -20
  59. package/dist/schemas/projections.d.ts +947 -806
  60. package/dist/schemas/projections.d.ts.map +1 -1
  61. package/dist/schemas/status.d.ts +2 -2
  62. package/dist/schemas/syncs.d.ts +33 -33
  63. package/dist/schemas/webhook-runs.d.ts +12 -12
  64. package/dist/schemas/workflows.d.ts +833 -162
  65. package/dist/schemas/workflows.d.ts.map +1 -1
  66. package/dist/server.d.ts +5 -0
  67. package/dist/server.d.ts.map +1 -1
  68. package/package.json +5 -5
  69. package/src/auth/experience.ts +190 -0
  70. package/src/auth/public-routes.ts +7 -0
  71. package/src/index.ts +1 -0
  72. package/src/openapi/tags.ts +8 -0
  73. package/src/registerRoutes.ts +4 -0
  74. package/src/routes/agents.ts +22 -3
  75. package/src/routes/ai-accounting.ts +166 -0
  76. package/src/routes/auth.ts +188 -32
  77. package/src/routes/links.ts +2 -53
  78. package/src/routes/models.ts +31 -0
  79. package/src/routes/objects.ts +103 -0
  80. package/src/routes/projections.ts +18 -4
  81. package/src/routes/workflows.ts +16 -0
  82. package/src/schemas/agents.ts +19 -9
  83. package/src/schemas/ai-accounting.ts +182 -0
  84. package/src/schemas/connectors.ts +13 -3
  85. package/src/schemas/links.ts +0 -17
  86. package/src/schemas/models.ts +15 -0
  87. package/src/schemas/objects.ts +104 -0
  88. package/src/schemas/projections.ts +12 -3
  89. package/src/schemas/workflows.ts +8 -3
  90. package/src/server.ts +10 -0
package/dist/index.js CHANGED
@@ -317,6 +317,9 @@ function isPublicRoute(pathname, method) {
317
317
  if (pathname === "/api/auth/sign-out" && normalizedMethod === "POST") {
318
318
  return true;
319
319
  }
320
+ if (pathname.startsWith("/auth/assets/") && (normalizedMethod === "GET" || normalizedMethod === "HEAD")) {
321
+ return true;
322
+ }
320
323
  if (pathname === "/auth/sign-in" && (normalizedMethod === "GET" || normalizedMethod === "POST")) {
321
324
  return true;
322
325
  }
@@ -584,6 +587,10 @@ var OPENAPI_TAGS = {
584
587
  name: "Status",
585
588
  description: "Runtime status"
586
589
  },
590
+ aiAccounting: {
591
+ name: "AI Accounting",
592
+ description: "Project AI token usage, cost analytics, and model-call accounting"
593
+ },
587
594
  ontology: {
588
595
  name: "Ontology",
589
596
  description: "Object type definitions"
@@ -680,6 +687,10 @@ var OPENAPI_TAGS = {
680
687
  name: "Agents",
681
688
  description: "Agent catalog"
682
689
  },
690
+ models: {
691
+ name: "Models",
692
+ description: "Project model catalog"
693
+ },
683
694
  agentThreads: {
684
695
  name: "Agent Threads",
685
696
  description: "Agent conversation threads and messages"
@@ -2451,14 +2462,18 @@ import { publishAgentRunCancel, publishAgentRunFinished } from "@sixb/core/inter
2451
2462
  import {
2452
2463
  AgentStorageError
2453
2464
  } from "@sixb/core/storage";
2454
- import { ZodError as ZodError2, z as z8 } from "zod";
2465
+ import { ZodError as ZodError2, z as z9 } from "zod";
2455
2466
 
2456
2467
  // src/schemas/agents.ts
2457
2468
  import { AGENT_REASONING_LEVELS, MAX_AGENT_CONTEXT_ENTRIES } from "@sixb/core";
2458
2469
  import {
2459
2470
  AGENT_RUN_DIAGNOSTIC_CODES,
2460
- AGENT_RUN_FAILURE_CODES
2471
+ AGENT_RUN_FAILURE_CODES,
2472
+ AGENT_RUN_FINISH_REASONS
2461
2473
  } from "@sixb/core/storage";
2474
+ import { z as z8 } from "zod";
2475
+
2476
+ // src/schemas/ai-accounting.ts
2462
2477
  import { z as z7 } from "zod";
2463
2478
 
2464
2479
  // src/schemas/ai-usage.ts
@@ -2476,140 +2491,300 @@ var AiUsageSummarySchema = z6.object({
2476
2491
  reportingStatus: z6.enum(["complete", "partial", "unavailable"])
2477
2492
  });
2478
2493
 
2494
+ // src/schemas/ai-accounting.ts
2495
+ var IntegerStringSchema = z7.string().regex(/^\d+$/);
2496
+ var IsoDateSchema = z7.string().datetime({ offset: true });
2497
+ var AiAccountingBucketSchema = z7.enum(["hour", "day", "week"]);
2498
+ var AiValuationStatusSchema = z7.enum(["rated", "unpriceable", "unvalued"]);
2499
+ var AiAccountingRangeQuerySchema = z7.object({
2500
+ from: IsoDateSchema,
2501
+ to: IsoDateSchema,
2502
+ providerId: z7.string().trim().min(1).optional(),
2503
+ modelId: z7.string().trim().min(1).optional()
2504
+ });
2505
+ var AiAccountingOverviewQuerySchema = AiAccountingRangeQuerySchema.extend({
2506
+ bucket: AiAccountingBucketSchema
2507
+ });
2508
+ var AiModelCallAccountingListQuerySchema = AiAccountingRangeQuerySchema.extend({
2509
+ executionId: z7.string().trim().min(1).optional(),
2510
+ valuationStatus: AiValuationStatusSchema.optional(),
2511
+ limit: IntegerStringSchema.optional(),
2512
+ offset: IntegerStringSchema.optional()
2513
+ });
2514
+ var AiMoneySchema = z7.object({
2515
+ currency: z7.string().regex(/^[A-Z]{3}$/),
2516
+ amountNanos: IntegerStringSchema
2517
+ });
2518
+ var AiCostSummarySchema = z7.object({
2519
+ amounts: z7.array(AiMoneySchema),
2520
+ ratedCallCount: z7.number().int().nonnegative(),
2521
+ unpriceableCallCount: z7.number().int().nonnegative(),
2522
+ unvaluedCallCount: z7.number().int().nonnegative()
2523
+ });
2524
+ var AiAccountingAggregateSchema = z7.object({
2525
+ modelCallCount: z7.number().int().nonnegative(),
2526
+ usage: AiUsageSummarySchema,
2527
+ costs: AiCostSummarySchema
2528
+ });
2529
+ var AiAccountingOverviewResponseSchema = z7.object({
2530
+ range: z7.object({ from: IsoDateSchema, to: IsoDateSchema }),
2531
+ bucket: AiAccountingBucketSchema,
2532
+ totals: AiAccountingAggregateSchema,
2533
+ series: z7.array(AiAccountingAggregateSchema.extend({
2534
+ start: IsoDateSchema,
2535
+ end: IsoDateSchema
2536
+ })),
2537
+ models: z7.array(AiAccountingAggregateSchema.extend({
2538
+ providerId: z7.string(),
2539
+ modelId: z7.string()
2540
+ })),
2541
+ agents: z7.array(AiAccountingAggregateSchema.extend({
2542
+ agentId: z7.string()
2543
+ })),
2544
+ workflows: z7.array(AiAccountingAggregateSchema.extend({
2545
+ workflowId: z7.string()
2546
+ }))
2547
+ });
2548
+ var AiPricingContextSchema = z7.object({
2549
+ serviceTier: z7.string().optional(),
2550
+ batch: z7.boolean().optional(),
2551
+ region: z7.string().optional(),
2552
+ inferenceGeo: z7.string().optional(),
2553
+ routedProviderId: z7.string().optional(),
2554
+ deploymentId: z7.string().optional(),
2555
+ inferenceProfileId: z7.string().optional(),
2556
+ cacheWriteTtlSeconds: z7.number().int().positive().optional(),
2557
+ mode: z7.string().optional()
2558
+ });
2559
+ var AiCostComponentSchema = z7.object({
2560
+ meter: z7.enum([
2561
+ "tokens.input.total",
2562
+ "tokens.input.uncached",
2563
+ "tokens.input.cacheRead",
2564
+ "tokens.input.cacheWrite",
2565
+ "tokens.output.total",
2566
+ "tokens.output.text",
2567
+ "tokens.output.reasoning"
2568
+ ]),
2569
+ quantity: IntegerStringSchema,
2570
+ rateAmountNanosPerMillion: IntegerStringSchema,
2571
+ chargeAmountNanos: IntegerStringSchema
2572
+ });
2573
+ var AiBillingIdentitySchema = z7.object({
2574
+ providerId: z7.string(),
2575
+ modelId: z7.string()
2576
+ });
2577
+ var AiPriceSourceSchema = z7.object({
2578
+ sourceId: z7.string(),
2579
+ sourceEntryId: z7.string(),
2580
+ sourceVersion: z7.string(),
2581
+ sourceUrl: z7.string().url(),
2582
+ observedAt: IsoDateSchema
2583
+ });
2584
+ var AiModelCallCostSchema = z7.discriminatedUnion("status", [
2585
+ z7.object({
2586
+ status: z7.literal("rated"),
2587
+ billingIdentity: AiBillingIdentitySchema,
2588
+ pricingContext: AiPricingContextSchema,
2589
+ priceSource: AiPriceSourceSchema,
2590
+ money: AiMoneySchema,
2591
+ components: z7.array(AiCostComponentSchema),
2592
+ ratedAt: IsoDateSchema
2593
+ }),
2594
+ z7.object({
2595
+ status: z7.literal("unpriceable"),
2596
+ billingIdentity: AiBillingIdentitySchema.optional(),
2597
+ pricingContext: AiPricingContextSchema,
2598
+ priceSource: AiPriceSourceSchema,
2599
+ reason: z7.enum([
2600
+ "missingBillingIdentity",
2601
+ "missingCatalogEntry",
2602
+ "missingUsageMeter",
2603
+ "unsupportedPricingDimension",
2604
+ "invalidUsageForFormula"
2605
+ ]),
2606
+ missingMeters: z7.array(AiCostComponentSchema.shape.meter).optional(),
2607
+ ratedAt: IsoDateSchema
2608
+ })
2609
+ ]);
2610
+ var AiModelCallUsageRecordSchema = z7.object({
2611
+ id: z7.string(),
2612
+ executionId: z7.string(),
2613
+ attempt: z7.number().int().positive(),
2614
+ callId: z7.string(),
2615
+ providerId: z7.string(),
2616
+ requestedModelId: z7.string(),
2617
+ responseModelId: z7.string().optional(),
2618
+ responseId: z7.string(),
2619
+ usage: AiUsageSummarySchema,
2620
+ occurredAt: IsoDateSchema,
2621
+ recordedAt: IsoDateSchema
2622
+ });
2623
+ var AiModelCallAccountingItemSchema = z7.object({
2624
+ usage: AiModelCallUsageRecordSchema,
2625
+ attribution: z7.discriminatedUnion("kind", [
2626
+ z7.object({
2627
+ kind: z7.literal("agent"),
2628
+ agentId: z7.string(),
2629
+ agentRunId: z7.string(),
2630
+ threadId: z7.string()
2631
+ }),
2632
+ z7.object({
2633
+ kind: z7.literal("workflowAgent"),
2634
+ agentId: z7.string(),
2635
+ nodeRunId: z7.string(),
2636
+ workflowId: z7.string(),
2637
+ workflowRunId: z7.string()
2638
+ })
2639
+ ]).optional(),
2640
+ cost: AiModelCallCostSchema.optional(),
2641
+ valuationStatus: AiValuationStatusSchema
2642
+ });
2643
+ var AiModelCallAccountingListResponseSchema = z7.object({
2644
+ items: z7.array(AiModelCallAccountingItemSchema),
2645
+ hasMore: z7.boolean(),
2646
+ total: z7.number().int().nonnegative()
2647
+ });
2648
+
2479
2649
  // src/schemas/agents.ts
2480
2650
  var AgentRunFailureSchema = sixbFailureSchema(AGENT_RUN_FAILURE_CODES);
2481
- var AgentIdParamsSchema = z7.object({
2482
- agentId: z7.string().min(1)
2651
+ var AgentIdParamsSchema = z8.object({
2652
+ agentId: z8.string().min(1)
2483
2653
  });
2484
- var AgentThreadParamsSchema = z7.object({
2485
- threadId: z7.string().min(1)
2654
+ var AgentThreadParamsSchema = z8.object({
2655
+ threadId: z8.string().min(1)
2486
2656
  });
2487
- var AgentRunParamsSchema = z7.object({
2488
- runId: z7.string().min(1)
2657
+ var AgentRunParamsSchema = z8.object({
2658
+ runId: z8.string().min(1)
2489
2659
  });
2490
2660
  var AgentMessageFileContentParamsSchema = AgentThreadParamsSchema.extend({
2491
- messageId: z7.string().min(1)
2661
+ messageId: z8.string().min(1)
2492
2662
  });
2493
- var AgentPrincipalSchema = z7.object({
2494
- type: z7.enum(["user", "serviceAccount", "system"]),
2495
- id: z7.string().min(1)
2663
+ var AgentPrincipalSchema = z8.object({
2664
+ type: z8.enum(["user", "serviceAccount", "system"]),
2665
+ id: z8.string().min(1)
2496
2666
  });
2497
- var AgentAuthorizablePrincipalSchema = z7.object({
2498
- type: z7.enum(["user", "serviceAccount"]),
2499
- id: z7.string().min(1)
2667
+ var AgentAuthorizablePrincipalSchema = z8.object({
2668
+ type: z8.enum(["user", "serviceAccount"]),
2669
+ id: z8.string().min(1)
2500
2670
  });
2501
- var AgentObjectContextSchema = z7.object({
2502
- kind: z7.literal("object"),
2503
- ref: z7.object({
2504
- objectTypeId: z7.string().min(1),
2505
- primaryId: z7.string().min(1)
2671
+ var AgentObjectContextSchema = z8.object({
2672
+ kind: z8.literal("object"),
2673
+ ref: z8.object({
2674
+ objectTypeId: z8.string().min(1),
2675
+ primaryId: z8.string().min(1)
2506
2676
  })
2507
2677
  });
2508
- var AgentAppStateContextSchema = z7.object({
2509
- kind: z7.literal("app-state"),
2510
- id: z7.string().min(1),
2511
- label: z7.string().min(1),
2512
- description: z7.string().min(1),
2678
+ var AgentAppStateContextSchema = z8.object({
2679
+ kind: z8.literal("app-state"),
2680
+ id: z8.string().min(1),
2681
+ label: z8.string().min(1),
2682
+ description: z8.string().min(1),
2513
2683
  value: JsonValueSchema
2514
2684
  });
2515
- var AgentContextInputSchema = z7.discriminatedUnion("kind", [
2685
+ var AgentContextInputSchema = z8.discriminatedUnion("kind", [
2516
2686
  AgentObjectContextSchema,
2517
2687
  AgentAppStateContextSchema
2518
2688
  ]);
2519
- var AgentContextOriginSchema = z7.enum(["ambient", "explicit"]);
2520
- var AgentContextEntryInputSchema = z7.object({
2689
+ var AgentContextOriginSchema = z8.enum(["ambient", "explicit"]);
2690
+ var AgentContextEntryInputSchema = z8.object({
2521
2691
  context: AgentContextInputSchema,
2522
2692
  origin: AgentContextOriginSchema
2523
2693
  });
2524
2694
  var AgentContextPartSchema = AgentContextEntryInputSchema.extend({
2525
- type: z7.literal("context")
2695
+ type: z8.literal("context")
2526
2696
  });
2527
- var AgentLoopConfigSchema = z7.object({
2528
- stopWhen: z7.object({
2529
- maxSteps: z7.number().int().positive().optional()
2697
+ var AgentLoopConfigSchema = z8.object({
2698
+ stopWhen: z8.object({
2699
+ maxSteps: z8.number().int().positive().optional()
2700
+ }).optional(),
2701
+ context: z8.object({
2702
+ windowTokens: z8.number().int().positive().optional(),
2703
+ reserveTokens: z8.number().int().positive().optional(),
2704
+ keepRecentTokens: z8.number().int().positive().optional()
2530
2705
  }).optional()
2531
2706
  });
2532
- var AgentReasoningLevelSchema = z7.enum(AGENT_REASONING_LEVELS);
2533
- var AgentCatalogItemSchema = z7.object({
2534
- id: z7.string(),
2535
- name: z7.string(),
2536
- description: z7.string().optional(),
2537
- modelId: z7.string().optional(),
2707
+ var AgentReasoningLevelSchema = z8.enum(AGENT_REASONING_LEVELS);
2708
+ var AgentCatalogItemSchema = z8.object({
2709
+ id: z8.string(),
2710
+ name: z8.string(),
2711
+ description: z8.string().optional(),
2712
+ modelId: z8.string().optional(),
2538
2713
  reasoning: AgentReasoningLevelSchema.optional(),
2539
- groupIds: z7.array(z7.string()),
2714
+ groupIds: z8.array(z8.string()),
2540
2715
  loop: AgentLoopConfigSchema.optional()
2541
2716
  });
2542
- var AgentThreadStatusSchema = z7.enum(["active", "archived"]);
2543
- var AgentThreadListQuerySchema = z7.object({
2544
- agentId: z7.string().optional(),
2717
+ var AgentThreadStatusSchema = z8.enum(["active", "archived"]);
2718
+ var AgentThreadListQuerySchema = z8.object({
2719
+ agentId: z8.string().optional(),
2545
2720
  status: AgentThreadStatusSchema.optional(),
2546
- limit: z7.string().optional(),
2547
- offset: z7.string().optional(),
2548
- order: z7.enum(["asc", "desc"]).optional()
2549
- });
2550
- var CreateAgentThreadBodySchema = z7.object({
2551
- agentId: z7.string().min(1),
2552
- title: z7.string().trim().min(1).optional(),
2553
- threadId: z7.string().trim().min(1).optional()
2554
- });
2555
- var AgentThreadSchema = z7.object({
2556
- id: z7.string(),
2557
- projectId: z7.string(),
2558
- agentId: z7.string(),
2721
+ limit: z8.string().optional(),
2722
+ offset: z8.string().optional(),
2723
+ order: z8.enum(["asc", "desc"]).optional()
2724
+ });
2725
+ var CreateAgentThreadBodySchema = z8.object({
2726
+ agentId: z8.string().min(1),
2727
+ title: z8.string().trim().min(1).optional(),
2728
+ threadId: z8.string().trim().min(1).optional()
2729
+ });
2730
+ var AgentThreadSchema = z8.object({
2731
+ id: z8.string(),
2732
+ projectId: z8.string(),
2733
+ agentId: z8.string(),
2559
2734
  ownerPrincipal: AgentPrincipalSchema,
2560
- title: z7.string().optional(),
2735
+ title: z8.string().optional(),
2561
2736
  status: AgentThreadStatusSchema,
2562
- activeRunId: z7.string().nullable(),
2563
- lastMessageAt: z7.string().optional(),
2564
- messageCount: z7.number(),
2565
- createdAt: z7.string(),
2566
- updatedAt: z7.string()
2567
- });
2568
- var AgentThreadListResponseSchema = z7.object({
2569
- threads: z7.array(AgentThreadSchema),
2570
- hasMore: z7.boolean(),
2571
- total: z7.number()
2572
- });
2573
- var CreateAgentThreadResponseSchema = z7.object({
2737
+ activeRunId: z8.string().nullable(),
2738
+ lastMessageAt: z8.string().optional(),
2739
+ messageCount: z8.number(),
2740
+ createdAt: z8.string(),
2741
+ updatedAt: z8.string()
2742
+ });
2743
+ var AgentThreadListResponseSchema = z8.object({
2744
+ threads: z8.array(AgentThreadSchema),
2745
+ hasMore: z8.boolean(),
2746
+ total: z8.number()
2747
+ });
2748
+ var CreateAgentThreadResponseSchema = z8.object({
2574
2749
  thread: AgentThreadSchema
2575
2750
  });
2576
- var AgentMessageRoleSchema = z7.enum(["system", "user", "assistant"]);
2577
- var AgentTextPartSchema = z7.object({
2578
- type: z7.literal("text"),
2579
- text: z7.string(),
2751
+ var AgentMessageRoleSchema = z8.enum(["system", "user", "assistant"]);
2752
+ var AgentTextPartSchema = z8.object({
2753
+ type: z8.literal("text"),
2754
+ text: z8.string(),
2580
2755
  providerMetadata: JsonValueSchema.optional()
2581
2756
  });
2582
- var AgentReasoningPartSchema = z7.object({
2583
- type: z7.literal("reasoning"),
2584
- text: z7.string(),
2757
+ var AgentReasoningPartSchema = z8.object({
2758
+ type: z8.literal("reasoning"),
2759
+ text: z8.string(),
2585
2760
  providerMetadata: JsonValueSchema.optional()
2586
2761
  });
2587
- var AgentStepStartPartSchema = z7.object({
2588
- type: z7.literal("step-start")
2762
+ var AgentStepStartPartSchema = z8.object({
2763
+ type: z8.literal("step-start")
2589
2764
  });
2590
- var AgentFilePartSchema = z7.object({
2591
- type: z7.literal("file"),
2765
+ var AgentFilePartSchema = z8.object({
2766
+ type: z8.literal("file"),
2592
2767
  fileRef: FileRefSchema,
2593
2768
  providerMetadata: JsonValueSchema.optional()
2594
2769
  });
2595
- var AgentToolCallBaseSchema = z7.object({
2596
- type: z7.literal("tool-call"),
2597
- toolCallId: z7.string(),
2598
- toolName: z7.string(),
2599
- dynamic: z7.boolean().optional(),
2600
- providerExecuted: z7.boolean().optional(),
2770
+ var AgentToolCallBaseSchema = z8.object({
2771
+ type: z8.literal("tool-call"),
2772
+ toolCallId: z8.string(),
2773
+ toolName: z8.string(),
2774
+ dynamic: z8.boolean().optional(),
2775
+ providerExecuted: z8.boolean().optional(),
2601
2776
  input: JsonValueSchema,
2602
2777
  providerMetadata: JsonValueSchema.optional()
2603
2778
  });
2604
2779
  var AgentToolCallOutputSchema = AgentToolCallBaseSchema.extend({
2605
- state: z7.literal("output-available"),
2780
+ state: z8.literal("output-available"),
2606
2781
  output: JsonValueSchema
2607
2782
  });
2608
2783
  var AgentToolCallErrorSchema = AgentToolCallBaseSchema.extend({
2609
- state: z7.literal("output-error"),
2610
- errorText: z7.string()
2784
+ state: z8.literal("output-error"),
2785
+ errorText: z8.string()
2611
2786
  });
2612
- var AgentMessagePartSchema = z7.union([
2787
+ var AgentMessagePartSchema = z8.union([
2613
2788
  AgentTextPartSchema,
2614
2789
  AgentReasoningPartSchema,
2615
2790
  AgentStepStartPartSchema,
@@ -2618,107 +2793,106 @@ var AgentMessagePartSchema = z7.union([
2618
2793
  AgentToolCallOutputSchema,
2619
2794
  AgentToolCallErrorSchema
2620
2795
  ]);
2621
- var AgentRunDiagnosticSchema = z7.object({
2622
- code: z7.enum(AGENT_RUN_DIAGNOSTIC_CODES),
2623
- severity: z7.enum(["warning", "error"]),
2624
- scope: z7.literal("output"),
2625
- path: z7.string().optional(),
2626
- message: z7.string()
2627
- });
2628
- var AgentMessageSchema = z7.object({
2629
- id: z7.string(),
2630
- projectId: z7.string(),
2631
- threadId: z7.string(),
2632
- runId: z7.string().nullable(),
2796
+ var AgentRunDiagnosticSchema = z8.object({
2797
+ code: z8.enum(AGENT_RUN_DIAGNOSTIC_CODES),
2798
+ severity: z8.enum(["warning", "error"]),
2799
+ scope: z8.literal("output"),
2800
+ path: z8.string().optional(),
2801
+ message: z8.string()
2802
+ });
2803
+ var AgentMessageCompactionSchema = z8.object({
2804
+ checkpointId: z8.string(),
2805
+ summary: z8.string(),
2806
+ createdAt: z8.string()
2807
+ });
2808
+ var AgentMessageSchema = z8.object({
2809
+ id: z8.string(),
2810
+ projectId: z8.string(),
2811
+ threadId: z8.string(),
2812
+ runId: z8.string().nullable(),
2633
2813
  role: AgentMessageRoleSchema,
2634
2814
  authorPrincipal: AgentPrincipalSchema.optional(),
2635
- seq: z7.number(),
2636
- parts: z7.array(AgentMessagePartSchema),
2637
- annotations: z7.array(AgentRunDiagnosticSchema),
2815
+ seq: z8.number(),
2816
+ parts: z8.array(AgentMessagePartSchema),
2817
+ annotations: z8.array(AgentRunDiagnosticSchema),
2818
+ compaction: AgentMessageCompactionSchema.optional(),
2638
2819
  metadata: JsonValueSchema.optional(),
2639
- contentVersion: z7.number(),
2640
- createdAt: z7.string(),
2641
- completedAt: z7.string().optional()
2820
+ contentVersion: z8.number(),
2821
+ createdAt: z8.string(),
2822
+ completedAt: z8.string().optional()
2642
2823
  });
2643
- var AgentMessagesQuerySchema = z7.object({
2824
+ var AgentMessagesQuerySchema = z8.object({
2644
2825
  role: AgentMessageRoleSchema.optional(),
2645
- limit: z7.string().optional(),
2646
- offset: z7.string().optional(),
2647
- order: z7.enum(["asc", "desc"]).optional()
2826
+ limit: z8.string().optional(),
2827
+ offset: z8.string().optional(),
2828
+ order: z8.enum(["asc", "desc"]).optional()
2648
2829
  });
2649
- var AgentMessageListResponseSchema = z7.object({
2650
- messages: z7.array(AgentMessageSchema),
2651
- hasMore: z7.boolean(),
2652
- total: z7.number()
2830
+ var AgentMessageListResponseSchema = z8.object({
2831
+ messages: z8.array(AgentMessageSchema),
2832
+ hasMore: z8.boolean(),
2833
+ total: z8.number()
2653
2834
  });
2654
- var PostAgentMessageBodySchema = z7.object({
2655
- text: z7.string().trim().min(1),
2656
- attachments: z7.array(FileRefSchema).optional(),
2657
- context: z7.array(AgentContextEntryInputSchema).max(MAX_AGENT_CONTEXT_ENTRIES).optional(),
2658
- messageId: z7.string().trim().min(1).optional()
2835
+ var PostAgentMessageBodySchema = z8.object({
2836
+ text: z8.string().trim().min(1),
2837
+ attachments: z8.array(FileRefSchema).optional(),
2838
+ context: z8.array(AgentContextEntryInputSchema).max(MAX_AGENT_CONTEXT_ENTRIES).optional(),
2839
+ messageId: z8.string().trim().min(1).optional()
2659
2840
  });
2660
- var CancelAgentRunBodySchema = z7.object({
2661
- runId: z7.string().trim().min(1)
2841
+ var CancelAgentRunBodySchema = z8.object({
2842
+ runId: z8.string().trim().min(1)
2662
2843
  });
2663
- var AgentRunStatusSchema = z7.enum([
2844
+ var AgentRunStatusSchema = z8.enum([
2664
2845
  "queued",
2665
2846
  "running",
2666
2847
  "succeeded",
2667
2848
  "failed",
2668
2849
  "cancelled"
2669
2850
  ]);
2670
- var AgentRunFinishReasonSchema = z7.enum([
2671
- "stop",
2672
- "length",
2673
- "content-filter",
2674
- "tool-calls",
2675
- "error",
2676
- "other",
2677
- "unknown"
2678
- ]);
2679
- var AgentRunSchema = z7.object({
2680
- id: z7.string(),
2681
- projectId: z7.string(),
2682
- threadId: z7.string(),
2683
- agentId: z7.string(),
2684
- triggerMessageId: z7.string(),
2851
+ var AgentRunFinishReasonSchema = z8.enum(AGENT_RUN_FINISH_REASONS);
2852
+ var AgentRunSchema = z8.object({
2853
+ id: z8.string(),
2854
+ projectId: z8.string(),
2855
+ threadId: z8.string(),
2856
+ agentId: z8.string(),
2857
+ triggerMessageId: z8.string(),
2685
2858
  requestedBy: AgentAuthorizablePrincipalSchema.optional(),
2686
2859
  status: AgentRunStatusSchema,
2687
- modelId: z7.string().optional(),
2860
+ modelId: z8.string().optional(),
2688
2861
  finishReason: AgentRunFinishReasonSchema.optional(),
2689
2862
  usage: AiUsageSummarySchema.optional(),
2690
- diagnostics: z7.array(AgentRunDiagnosticSchema).optional(),
2863
+ cost: AiCostSummarySchema.optional(),
2864
+ diagnostics: z8.array(AgentRunDiagnosticSchema).optional(),
2691
2865
  error: AgentRunFailureSchema.optional(),
2692
- attempt: z7.number(),
2693
- streamId: z7.string(),
2694
- createdAt: z7.string(),
2695
- startedAt: z7.string().optional(),
2696
- completedAt: z7.string().optional()
2866
+ attempt: z8.number(),
2867
+ streamId: z8.string(),
2868
+ createdAt: z8.string(),
2869
+ startedAt: z8.string().optional(),
2870
+ completedAt: z8.string().optional()
2697
2871
  });
2698
- var PostAgentMessageResponseSchema = z7.object({
2872
+ var PostAgentMessageResponseSchema = z8.object({
2699
2873
  run: AgentRunSchema
2700
2874
  });
2701
- var CancelAgentRunResponseSchema = z7.object({
2875
+ var CancelAgentRunResponseSchema = z8.object({
2702
2876
  run: AgentRunSchema
2703
2877
  });
2704
- var RetryAgentRunResponseSchema = z7.object({
2878
+ var RetryAgentRunResponseSchema = z8.object({
2705
2879
  run: AgentRunSchema
2706
2880
  });
2707
- var AgentRunListQuerySchema = z7.object({
2881
+ var AgentRunListQuerySchema = z8.object({
2708
2882
  status: AgentRunStatusSchema.optional(),
2709
- limit: z7.string().optional(),
2710
- offset: z7.string().optional(),
2711
- order: z7.enum(["asc", "desc"]).optional()
2883
+ limit: z8.string().optional(),
2884
+ offset: z8.string().optional(),
2885
+ order: z8.enum(["asc", "desc"]).optional()
2712
2886
  });
2713
- var AgentRunListResponseSchema = z7.object({
2714
- runs: z7.array(AgentRunSchema),
2715
- hasMore: z7.boolean(),
2716
- total: z7.number()
2887
+ var AgentRunListResponseSchema = z8.object({
2888
+ runs: z8.array(AgentRunSchema),
2889
+ hasMore: z8.boolean(),
2890
+ total: z8.number()
2717
2891
  });
2718
2892
 
2719
2893
  // src/routes/agents.ts
2720
2894
  var AgentMessageFileContentQuerySchema = FileContentQuerySchema.extend({
2721
- path: z8.string().min(1).regex(/^\/parts(?:\/|$)/, "Agent message file content paths must start with /parts/")
2895
+ path: z9.string().min(1).regex(/^\/parts(?:\/|$)/, "Agent message file content paths must start with /parts/")
2722
2896
  });
2723
2897
  function serializeAgent(agent) {
2724
2898
  return AgentCatalogItemSchema.parse({
@@ -2746,7 +2920,7 @@ function serializeThread(thread) {
2746
2920
  updatedAt: toIsoString(thread.updatedAt)
2747
2921
  });
2748
2922
  }
2749
- function serializeMessage(message, annotations = []) {
2923
+ function serializeMessage(message, annotations = [], checkpoint) {
2750
2924
  return AgentMessageSchema.parse({
2751
2925
  id: message.id,
2752
2926
  projectId: message.projectId,
@@ -2757,6 +2931,11 @@ function serializeMessage(message, annotations = []) {
2757
2931
  seq: message.seq,
2758
2932
  parts: message.parts,
2759
2933
  annotations,
2934
+ compaction: checkpoint ? {
2935
+ checkpointId: checkpoint.id,
2936
+ summary: checkpoint.summary,
2937
+ createdAt: toIsoString(checkpoint.createdAt)
2938
+ } : undefined,
2760
2939
  metadata: message.metadata,
2761
2940
  contentVersion: message.contentVersion,
2762
2941
  createdAt: toIsoString(message.createdAt),
@@ -2775,6 +2954,7 @@ function serializeAgentRun(run) {
2775
2954
  modelId: run.modelId,
2776
2955
  finishReason: run.finishReason,
2777
2956
  usage: run.usage,
2957
+ cost: run.cost,
2778
2958
  diagnostics: run.diagnostics,
2779
2959
  error: run.error,
2780
2960
  attempt: run.attempt,
@@ -3040,10 +3220,14 @@ function registerAgentRoutes(app, host) {
3040
3220
  order: parsed.order
3041
3221
  });
3042
3222
  const runIds = result.messages.flatMap((message) => message.runId === null ? [] : [message.runId]);
3043
- const runs = await storage.runs.getByIds({ projectId: host.id, ids: runIds });
3223
+ const [runs, checkpoints] = await Promise.all([
3224
+ storage.runs.getByIds({ projectId: host.id, ids: runIds }),
3225
+ storage.checkpoints.getByRunIds({ projectId: host.id, runIds })
3226
+ ]);
3044
3227
  const diagnosticsByRunId = new Map(runs.filter((run) => run.threadId === thread.id).map((run) => [run.id, run.diagnostics ?? []]));
3228
+ const checkpointsByRunId = new Map(checkpoints.filter((checkpoint) => checkpoint.threadId === thread.id).map((checkpoint) => [checkpoint.createdByRunId, checkpoint]));
3045
3229
  return AgentMessageListResponseSchema.parse({
3046
- messages: result.messages.map((message) => serializeMessage(message, message.runId === null ? [] : diagnosticsByRunId.get(message.runId) ?? [])),
3230
+ messages: result.messages.map((message) => serializeMessage(message, message.runId === null ? [] : diagnosticsByRunId.get(message.runId) ?? [], message.runId === null ? undefined : checkpointsByRunId.get(message.runId))),
3047
3231
  hasMore: result.hasMore,
3048
3232
  total: result.total
3049
3233
  });
@@ -3239,7 +3423,7 @@ function registerAgentRoutes(app, host) {
3239
3423
  return handleAgentRouteError(error, set);
3240
3424
  }
3241
3425
  }, {
3242
- params: AgentRunParamsSchema.extend({ threadId: z8.string().trim().min(1) }),
3426
+ params: AgentRunParamsSchema.extend({ threadId: z9.string().trim().min(1) }),
3243
3427
  response: {
3244
3428
  202: RetryAgentRunResponseSchema,
3245
3429
  400: ErrorResponseSchema,
@@ -3327,6 +3511,143 @@ function registerAgentRoutes(app, host) {
3327
3511
  });
3328
3512
  }
3329
3513
 
3514
+ // src/routes/ai-accounting.ts
3515
+ function serializeAggregate(aggregate) {
3516
+ return {
3517
+ modelCallCount: aggregate.modelCallCount,
3518
+ usage: aggregate.usage,
3519
+ costs: aggregate.costs
3520
+ };
3521
+ }
3522
+ function serializeOverview(overview) {
3523
+ return AiAccountingOverviewResponseSchema.parse({
3524
+ range: {
3525
+ from: overview.range.from.toISOString(),
3526
+ to: overview.range.to.toISOString()
3527
+ },
3528
+ bucket: overview.bucket,
3529
+ totals: serializeAggregate(overview.totals),
3530
+ series: overview.series.map((period) => ({
3531
+ start: period.start.toISOString(),
3532
+ end: period.end.toISOString(),
3533
+ ...serializeAggregate(period)
3534
+ })),
3535
+ models: overview.models.map((model) => ({
3536
+ providerId: model.providerId,
3537
+ modelId: model.modelId,
3538
+ ...serializeAggregate(model)
3539
+ })),
3540
+ agents: overview.agents.map((agent) => ({
3541
+ agentId: agent.agentId,
3542
+ ...serializeAggregate(agent)
3543
+ })),
3544
+ workflows: overview.workflows.map((workflow) => ({
3545
+ workflowId: workflow.workflowId,
3546
+ ...serializeAggregate(workflow)
3547
+ }))
3548
+ });
3549
+ }
3550
+ function serializeModelCall(item) {
3551
+ return AiModelCallAccountingListResponseSchema.shape.items.element.parse({
3552
+ usage: {
3553
+ id: item.usage.id,
3554
+ executionId: item.usage.executionId,
3555
+ attempt: item.usage.attempt,
3556
+ callId: item.usage.callId,
3557
+ providerId: item.usage.providerId,
3558
+ requestedModelId: item.usage.requestedModelId,
3559
+ responseModelId: item.usage.responseModelId,
3560
+ responseId: item.usage.responseId,
3561
+ usage: item.usage.usage,
3562
+ occurredAt: item.usage.occurredAt.toISOString(),
3563
+ recordedAt: item.usage.recordedAt.toISOString()
3564
+ },
3565
+ attribution: item.attribution,
3566
+ cost: item.cost === undefined ? undefined : {
3567
+ ...item.cost,
3568
+ priceSource: {
3569
+ ...item.cost.priceSource,
3570
+ observedAt: item.cost.priceSource.observedAt.toISOString()
3571
+ },
3572
+ ratedAt: item.cost.ratedAt.toISOString()
3573
+ },
3574
+ valuationStatus: item.valuationStatus
3575
+ });
3576
+ }
3577
+ function registerAiAccountingRoutes(app, host) {
3578
+ app.get("/api/ai/accounting/overview", async ({ query, set }) => {
3579
+ try {
3580
+ const parsed = AiAccountingOverviewQuerySchema.parse(query);
3581
+ const storage = host.storage.aiCosts;
3582
+ if (!storage)
3583
+ return unconfiguredStorageResponse2(set, "AI cost storage");
3584
+ const overview = await storage.queryProjectOverview({
3585
+ projectId: host.id,
3586
+ from: new Date(parsed.from),
3587
+ to: new Date(parsed.to),
3588
+ bucket: parsed.bucket,
3589
+ providerId: parsed.providerId,
3590
+ modelId: parsed.modelId
3591
+ });
3592
+ return serializeOverview(overview);
3593
+ } catch (error) {
3594
+ return handleRouteError(error, set);
3595
+ }
3596
+ }, {
3597
+ query: AiAccountingOverviewQuerySchema,
3598
+ response: {
3599
+ 200: AiAccountingOverviewResponseSchema,
3600
+ 400: ErrorResponseSchema,
3601
+ 501: ErrorResponseSchema
3602
+ },
3603
+ detail: {
3604
+ summary: "Get project AI usage and cost analytics",
3605
+ tags: [OPENAPI_TAGS.aiAccounting.name],
3606
+ operationId: "getAiAccountingOverview"
3607
+ }
3608
+ });
3609
+ app.get("/api/ai/model-calls", async ({ query, set }) => {
3610
+ try {
3611
+ const parsed = AiModelCallAccountingListQuerySchema.parse(query);
3612
+ const storage = host.storage.aiCosts;
3613
+ if (!storage)
3614
+ return unconfiguredStorageResponse2(set, "AI cost storage");
3615
+ const result = await storage.listModelCalls({
3616
+ projectId: host.id,
3617
+ from: new Date(parsed.from),
3618
+ to: new Date(parsed.to),
3619
+ providerId: parsed.providerId,
3620
+ modelId: parsed.modelId,
3621
+ executionId: parsed.executionId,
3622
+ valuationStatus: parsed.valuationStatus,
3623
+ limit: parseOptionalInt(parsed.limit),
3624
+ offset: parseOptionalInt(parsed.offset)
3625
+ });
3626
+ const items = result.items.map(serializeModelCall);
3627
+ return AiModelCallAccountingListResponseSchema.parse({
3628
+ items,
3629
+ hasMore: result.hasMore,
3630
+ total: result.total
3631
+ });
3632
+ } catch (error) {
3633
+ return handleRouteError(error, set);
3634
+ }
3635
+ }, {
3636
+ query: AiModelCallAccountingListQuerySchema,
3637
+ response: {
3638
+ 200: AiModelCallAccountingListResponseSchema,
3639
+ 400: ErrorResponseSchema,
3640
+ 501: ErrorResponseSchema
3641
+ },
3642
+ detail: {
3643
+ summary: "List project AI model-call accounting records",
3644
+ tags: [OPENAPI_TAGS.aiAccounting.name],
3645
+ operationId: "listAiModelCalls"
3646
+ }
3647
+ });
3648
+ return app;
3649
+ }
3650
+
3330
3651
  // src/routes/connector-connection-runs.ts
3331
3652
  import { getConnectorConnectionCallbackProcess } from "@sixb/core/internal/connector-connections";
3332
3653
 
@@ -3406,7 +3727,7 @@ import { createSixbError as createSixbError2 } from "@sixb/core/internal/errors"
3406
3727
  import {
3407
3728
  CONNECTOR_CONNECTION_RUN_FAILURE_CODES
3408
3729
  } from "@sixb/core/storage";
3409
- import { z as z9 } from "zod";
3730
+ import { z as z10 } from "zod";
3410
3731
  var CONNECTOR_HTTP_ERROR_CODES = [
3411
3732
  "internal.unexpected",
3412
3733
  "connector.adapter_invalid",
@@ -3447,114 +3768,116 @@ var ConnectorUnavailableResponseSchema = connectorRouteErrorResponseSchema([
3447
3768
  "connector.credentials_unavailable",
3448
3769
  "connector.provider_unavailable"
3449
3770
  ]);
3450
- var ConnectorParamsSchema = z9.object({
3451
- connectorId: z9.string().min(1)
3771
+ var ConnectorParamsSchema = z10.object({
3772
+ connectorId: z10.string().min(1)
3452
3773
  });
3453
3774
  var ConnectorConnectionParamsSchema = ConnectorParamsSchema.extend({
3454
- connectionId: z9.string().min(1)
3775
+ connectionId: z10.string().min(1)
3455
3776
  });
3456
3777
  var ConnectorConnectionRunParamsSchema = ConnectorParamsSchema.extend({
3457
- runId: z9.string().min(1)
3458
- });
3459
- var ConnectorWebhookSchema = z9.object({
3460
- id: z9.string(),
3461
- method: z9.literal("POST"),
3462
- route: z9.string(),
3463
- bodyFormat: z9.enum(["json", "text", "raw"]),
3464
- hasVerify: z9.boolean(),
3465
- hasIdempotency: z9.boolean()
3466
- });
3467
- var ConnectorSchema = z9.object({
3468
- id: z9.string(),
3469
- type: z9.string(),
3470
- connection: z9.object({ authentication: z9.literal("oauth2") }).nullable(),
3471
- syncIds: z9.array(z9.string()),
3472
- webhooks: z9.array(ConnectorWebhookSchema)
3473
- });
3474
- var ConnectorAccountSchema = z9.object({
3475
- id: z9.string(),
3476
- label: z9.string(),
3477
- description: z9.string().optional(),
3478
- avatarUrl: z9.string().url().optional()
3479
- });
3480
- var ConnectorConnectionSchema = z9.object({
3481
- id: z9.string(),
3482
- connectorId: z9.string(),
3483
- owner: z9.object({ type: z9.literal("project") }),
3484
- slot: z9.string(),
3778
+ runId: z10.string().min(1)
3779
+ });
3780
+ var ConnectorWebhookSchema = z10.object({
3781
+ id: z10.string(),
3782
+ method: z10.literal("POST"),
3783
+ route: z10.string(),
3784
+ bodyFormat: z10.enum(["json", "text", "raw"]),
3785
+ hasVerify: z10.boolean(),
3786
+ hasIdempotency: z10.boolean()
3787
+ });
3788
+ var ConnectorSchema = z10.object({
3789
+ id: z10.string(),
3790
+ type: z10.string(),
3791
+ connection: z10.object({ authentication: z10.literal("oauth2") }).nullable(),
3792
+ syncIds: z10.array(z10.string()),
3793
+ webhooks: z10.array(ConnectorWebhookSchema)
3794
+ });
3795
+ var ConnectorAccountSchema = z10.object({
3796
+ id: z10.string(),
3797
+ label: z10.string(),
3798
+ description: z10.string().optional(),
3799
+ avatarUrl: z10.string().url().optional()
3800
+ });
3801
+ var ConnectorConnectionSchema = z10.object({
3802
+ id: z10.string(),
3803
+ connectorId: z10.string(),
3804
+ owner: z10.object({ type: z10.literal("project") }),
3805
+ slot: z10.string(),
3485
3806
  account: ConnectorAccountSchema,
3486
- status: z9.enum(["connected", "needs_reauthorization", "disconnected"])
3807
+ status: z10.enum(["connected", "needs_reauthorization", "disconnected"])
3487
3808
  });
3488
3809
  var ConnectorConnectionRunFailureSchema = sixbFailureSchema(CONNECTOR_CONNECTION_RUN_FAILURE_CODES);
3489
- var ConnectorConnectionRunBaseSchema = z9.object({
3490
- id: z9.string(),
3491
- connectorId: z9.string(),
3492
- kind: z9.enum(["connect", "reauthorize"]),
3493
- owner: z9.object({ type: z9.literal("project") }),
3494
- slot: z9.string(),
3495
- createdAt: z9.string().datetime(),
3496
- updatedAt: z9.string().datetime()
3497
- });
3498
- var ConnectorConnectionRunSchema = z9.union([
3810
+ var ConnectorConnectionRunBaseSchema = z10.object({
3811
+ id: z10.string(),
3812
+ connectorId: z10.string(),
3813
+ kind: z10.enum(["connect", "reauthorize"]),
3814
+ owner: z10.object({ type: z10.literal("project") }),
3815
+ slot: z10.string(),
3816
+ createdAt: z10.string().datetime(),
3817
+ updatedAt: z10.string().datetime()
3818
+ });
3819
+ var ConnectorConnectionRunSchema = z10.union([
3499
3820
  ConnectorConnectionRunBaseSchema.extend({
3500
- status: z9.literal("waiting"),
3501
- waitingFor: z9.literal("provider_authorization"),
3502
- expiresAt: z9.string().datetime()
3821
+ status: z10.literal("waiting"),
3822
+ waitingFor: z10.literal("provider_authorization"),
3823
+ expiresAt: z10.string().datetime()
3503
3824
  }),
3504
3825
  ConnectorConnectionRunBaseSchema.extend({
3505
- status: z9.literal("running")
3826
+ status: z10.literal("running")
3506
3827
  }),
3507
3828
  ConnectorConnectionRunBaseSchema.extend({
3508
- status: z9.literal("waiting"),
3509
- waitingFor: z9.literal("account_selection"),
3510
- accounts: z9.array(ConnectorAccountSchema),
3511
- expiresAt: z9.string().datetime()
3829
+ status: z10.literal("waiting"),
3830
+ waitingFor: z10.literal("account_selection"),
3831
+ accounts: z10.array(ConnectorAccountSchema),
3832
+ expiresAt: z10.string().datetime()
3512
3833
  }),
3513
3834
  ConnectorConnectionRunBaseSchema.extend({
3514
- status: z9.literal("succeeded"),
3515
- connections: z9.array(ConnectorConnectionSchema),
3516
- finishedAt: z9.string().datetime()
3835
+ status: z10.literal("succeeded"),
3836
+ connections: z10.array(ConnectorConnectionSchema),
3837
+ finishedAt: z10.string().datetime()
3517
3838
  }),
3518
3839
  ConnectorConnectionRunBaseSchema.extend({
3519
- status: z9.literal("failed"),
3840
+ status: z10.literal("failed"),
3520
3841
  error: ConnectorConnectionRunFailureSchema,
3521
- finishedAt: z9.string().datetime()
3842
+ finishedAt: z10.string().datetime()
3522
3843
  }),
3523
3844
  ConnectorConnectionRunBaseSchema.extend({
3524
- status: z9.enum(["cancelled", "expired"]),
3525
- finishedAt: z9.string().datetime()
3845
+ status: z10.enum(["cancelled", "expired"]),
3846
+ finishedAt: z10.string().datetime()
3526
3847
  })
3527
3848
  ]);
3528
- var StartConnectorConnectionRunBodySchema = z9.object({
3529
- slot: z9.string().trim().min(1),
3530
- returnTo: z9.string().url()
3531
- });
3532
- var AddConnectorConnectionBodySchema = z9.object({
3533
- slot: z9.string().trim().min(1)
3534
- });
3535
- var StartConnectorReauthorizationBodySchema = z9.object({
3536
- returnTo: z9.string().url()
3537
- });
3538
- var StartConnectorConnectionRunResponseSchema = z9.object({
3539
- runId: z9.string(),
3540
- authorizationUrl: z9.string().url(),
3541
- affectedConnections: z9.array(ConnectorConnectionSchema)
3542
- });
3543
- var SelectConnectorConnectionRunAccountBodySchema = z9.object({
3544
- accountId: z9.string().trim().min(1),
3545
- replace: z9.boolean().optional()
3546
- });
3547
- var ConnectorOAuthCallbackQuerySchema = z9.object({
3548
- state: z9.string().min(1),
3549
- code: z9.string().min(1).optional(),
3550
- auth_code: z9.string().min(1).optional(),
3551
- error: z9.string().min(1).optional()
3552
- }).refine((query) => [query.code, query.auth_code, query.error].filter(Boolean).length === 1, {
3553
- message: "OAuth callback must contain exactly one of code, auth_code, or error."
3554
- }).transform(({ auth_code, ...query }) => ({ ...query, code: query.code ?? auth_code }));
3849
+ var StartConnectorConnectionRunBodySchema = z10.object({
3850
+ slot: z10.string().trim().min(1),
3851
+ returnTo: z10.string().url()
3852
+ });
3853
+ var AddConnectorConnectionBodySchema = z10.object({
3854
+ slot: z10.string().trim().min(1)
3855
+ });
3856
+ var StartConnectorReauthorizationBodySchema = z10.object({
3857
+ returnTo: z10.string().url()
3858
+ });
3859
+ var StartConnectorConnectionRunResponseSchema = z10.object({
3860
+ runId: z10.string(),
3861
+ authorizationUrl: z10.string().url(),
3862
+ affectedConnections: z10.array(ConnectorConnectionSchema)
3863
+ });
3864
+ var SelectConnectorConnectionRunAccountBodySchema = z10.object({
3865
+ accountId: z10.string().trim().min(1),
3866
+ replace: z10.boolean().optional()
3867
+ });
3868
+ var ConnectorOAuthCallbackQuerySchema = z10.object({
3869
+ state: z10.string().min(1),
3870
+ code: z10.string().min(1).optional(),
3871
+ auth_code: z10.string().min(1).optional(),
3872
+ error: z10.string().min(1).optional()
3873
+ }).refine((query) => {
3874
+ const hasAuthorizationCode = query.code !== undefined || query.auth_code !== undefined;
3875
+ const hasProviderError = query.error !== undefined;
3876
+ return hasAuthorizationCode !== hasProviderError;
3877
+ }, { message: "OAuth callback must contain exactly one of an authorization code or error." }).refine((query) => query.code === undefined || query.auth_code === undefined || query.code === query.auth_code, { message: "OAuth callback code and auth_code must match when both are present." }).transform(({ auth_code, ...query }) => ({ ...query, code: query.code ?? auth_code }));
3555
3878
  function connectorRouteErrorResponseSchema(codes) {
3556
3879
  return ErrorResponseSchema.extend({
3557
- code: z9.enum(codes).optional().describe("Stable machine-readable failure code for programmatic handling.")
3880
+ code: z10.enum(codes).optional().describe("Stable machine-readable failure code for programmatic handling.")
3558
3881
  });
3559
3882
  }
3560
3883
 
@@ -3998,25 +4321,25 @@ function registerConnectorRoutes(app, host) {
3998
4321
  import { createSixbError as createSixbError3 } from "@sixb/core/internal/errors";
3999
4322
 
4000
4323
  // src/schemas/datasets.ts
4001
- import { z as z10 } from "zod";
4002
- var DatasetParamsSchema = z10.object({
4003
- datasetId: z10.string().min(1)
4324
+ import { z as z11 } from "zod";
4325
+ var DatasetParamsSchema = z11.object({
4326
+ datasetId: z11.string().min(1)
4004
4327
  });
4005
4328
  var DatasetVersionParamsSchema = DatasetParamsSchema.extend({
4006
- versionId: z10.string().min(1)
4329
+ versionId: z11.string().min(1)
4007
4330
  });
4008
- var DatasetVersionsQuerySchema = z10.object({
4009
- limit: z10.string().optional()
4331
+ var DatasetVersionsQuerySchema = z11.object({
4332
+ limit: z11.string().optional()
4010
4333
  });
4011
- var DatasetRowsQuerySchema = z10.object({
4012
- versionId: z10.string().optional(),
4013
- columns: z10.string().optional(),
4014
- limit: z10.string().optional(),
4015
- offset: z10.string().optional()
4334
+ var DatasetRowsQuerySchema = z11.object({
4335
+ versionId: z11.string().optional(),
4336
+ columns: z11.string().optional(),
4337
+ limit: z11.string().optional(),
4338
+ offset: z11.string().optional()
4016
4339
  });
4017
- var DatasetColumnSchema = z10.object({
4018
- name: z10.string(),
4019
- type: z10.enum([
4340
+ var DatasetColumnSchema = z11.object({
4341
+ name: z11.string(),
4342
+ type: z11.enum([
4020
4343
  "string",
4021
4344
  "boolean",
4022
4345
  "int64",
@@ -4027,70 +4350,70 @@ var DatasetColumnSchema = z10.object({
4027
4350
  "json",
4028
4351
  "fileRef"
4029
4352
  ]),
4030
- nullable: z10.boolean().optional()
4353
+ nullable: z11.boolean().optional()
4031
4354
  });
4032
- var DatasetSchema = z10.object({
4033
- columns: z10.array(DatasetColumnSchema)
4355
+ var DatasetSchema = z11.object({
4356
+ columns: z11.array(DatasetColumnSchema)
4034
4357
  });
4035
- var DatasetDefinitionSchema = z10.object({
4036
- id: z10.string(),
4037
- description: z10.string().optional(),
4038
- primaryKey: z10.union([z10.string(), z10.array(z10.string()).min(2)]).optional(),
4039
- partitionBy: z10.array(z10.string()).optional(),
4358
+ var DatasetDefinitionSchema = z11.object({
4359
+ id: z11.string(),
4360
+ description: z11.string().optional(),
4361
+ primaryKey: z11.union([z11.string(), z11.array(z11.string()).min(2)]).optional(),
4362
+ partitionBy: z11.array(z11.string()).optional(),
4040
4363
  schema: DatasetSchema
4041
4364
  });
4042
- var DatasetVersionRefSchema = z10.object({
4043
- datasetId: z10.string(),
4044
- versionId: z10.string()
4045
- });
4046
- var DatasetProducerSchema = z10.object({
4047
- kind: z10.enum(["sync", "pipeline"]),
4048
- id: z10.string().optional(),
4049
- runId: z10.string().optional()
4050
- });
4051
- var DatasetVersionSchema = z10.object({
4052
- datasetId: z10.string(),
4053
- versionId: z10.string(),
4054
- parentVersionId: z10.string().optional(),
4055
- mode: z10.enum(["snapshot", "append", "merge", "schema"]),
4056
- createdAt: z10.string(),
4365
+ var DatasetVersionRefSchema = z11.object({
4366
+ datasetId: z11.string(),
4367
+ versionId: z11.string()
4368
+ });
4369
+ var DatasetProducerSchema = z11.object({
4370
+ kind: z11.enum(["sync", "pipeline"]),
4371
+ id: z11.string().optional(),
4372
+ runId: z11.string().optional()
4373
+ });
4374
+ var DatasetVersionSchema = z11.object({
4375
+ datasetId: z11.string(),
4376
+ versionId: z11.string(),
4377
+ parentVersionId: z11.string().optional(),
4378
+ mode: z11.enum(["snapshot", "append", "merge", "schema"]),
4379
+ createdAt: z11.string(),
4057
4380
  schema: DatasetSchema,
4058
4381
  producer: DatasetProducerSchema.optional(),
4059
- inputs: z10.array(DatasetVersionRefSchema).optional(),
4060
- rowCount: z10.number().optional(),
4061
- sizeBytes: z10.number().optional()
4382
+ inputs: z11.array(DatasetVersionRefSchema).optional(),
4383
+ rowCount: z11.number().optional(),
4384
+ sizeBytes: z11.number().optional()
4062
4385
  });
4063
- var DatasetLatestVersionSummarySchema = z10.object({
4064
- datasetId: z10.string(),
4065
- versionId: z10.string(),
4066
- mode: z10.enum(["snapshot", "append", "merge", "schema"]),
4067
- createdAt: z10.string(),
4068
- rowCount: z10.number().optional()
4386
+ var DatasetLatestVersionSummarySchema = z11.object({
4387
+ datasetId: z11.string(),
4388
+ versionId: z11.string(),
4389
+ mode: z11.enum(["snapshot", "append", "merge", "schema"]),
4390
+ createdAt: z11.string(),
4391
+ rowCount: z11.number().optional()
4069
4392
  });
4070
4393
  var DatasetCatalogItemSchema = DatasetDefinitionSchema.extend({
4071
- kind: z10.literal("dataset"),
4072
- materialized: z10.boolean(),
4394
+ kind: z11.literal("dataset"),
4395
+ materialized: z11.boolean(),
4073
4396
  latestVersion: DatasetLatestVersionSummarySchema.nullable(),
4074
- syncIds: z10.array(z10.string()),
4075
- sourcePipelineIds: z10.array(z10.string()),
4076
- targetPipelineIds: z10.array(z10.string()),
4077
- projectionIds: z10.array(z10.string())
4078
- });
4079
- var DatasetVersionListResponseSchema = z10.object({
4080
- versions: z10.array(DatasetVersionSchema),
4081
- count: z10.number()
4082
- });
4083
- var DatasetRowsResponseSchema = z10.object({
4084
- datasetId: z10.string(),
4085
- versionId: z10.string(),
4397
+ syncIds: z11.array(z11.string()),
4398
+ sourcePipelineIds: z11.array(z11.string()),
4399
+ targetPipelineIds: z11.array(z11.string()),
4400
+ projectionIds: z11.array(z11.string())
4401
+ });
4402
+ var DatasetVersionListResponseSchema = z11.object({
4403
+ versions: z11.array(DatasetVersionSchema),
4404
+ count: z11.number()
4405
+ });
4406
+ var DatasetRowsResponseSchema = z11.object({
4407
+ datasetId: z11.string(),
4408
+ versionId: z11.string(),
4086
4409
  version: DatasetVersionSchema,
4087
- columns: z10.array(z10.string()),
4088
- rows: z10.array(z10.record(z10.unknown())),
4089
- count: z10.number(),
4090
- limit: z10.number(),
4091
- offset: z10.number(),
4092
- total: z10.number().optional(),
4093
- hasMore: z10.boolean()
4410
+ columns: z11.array(z11.string()),
4411
+ rows: z11.array(z11.record(z11.unknown())),
4412
+ count: z11.number(),
4413
+ limit: z11.number(),
4414
+ offset: z11.number(),
4415
+ total: z11.number().optional(),
4416
+ hasMore: z11.boolean()
4094
4417
  });
4095
4418
 
4096
4419
  // src/routes/datasets.ts
@@ -4393,44 +4716,44 @@ import {
4393
4716
  EVENT_DEFINITIONS,
4394
4717
  isOntologyFactType
4395
4718
  } from "@sixb/core/internal/events";
4396
- import { z as z12 } from "zod";
4719
+ import { z as z13 } from "zod";
4397
4720
 
4398
4721
  // src/schemas/event-payloads.ts
4399
- import { z as z11 } from "zod";
4400
- var PropertyChangeSchema = z11.discriminatedUnion("operation", [
4401
- z11.object({ operation: z11.literal("created"), after: JsonValueSchema }),
4402
- z11.object({
4403
- operation: z11.literal("updated"),
4722
+ import { z as z12 } from "zod";
4723
+ var PropertyChangeSchema = z12.discriminatedUnion("operation", [
4724
+ z12.object({ operation: z12.literal("created"), after: JsonValueSchema }),
4725
+ z12.object({
4726
+ operation: z12.literal("updated"),
4404
4727
  before: JsonValueSchema,
4405
4728
  after: JsonValueSchema
4406
4729
  }),
4407
- z11.object({
4408
- operation: z11.literal("cleared"),
4730
+ z12.object({
4731
+ operation: z12.literal("cleared"),
4409
4732
  before: JsonValueSchema,
4410
4733
  after: JsonNullSchema
4411
4734
  })
4412
4735
  ]);
4413
- var PropertyChangesSchema = z11.record(PropertyChangeSchema);
4414
- var ObjectMutationPayloadSchema = z11.object({
4415
- objectTypeId: z11.string(),
4416
- primaryId: z11.string(),
4417
- properties: z11.record(JsonValueSchema),
4736
+ var PropertyChangesSchema = z12.record(PropertyChangeSchema);
4737
+ var ObjectMutationPayloadSchema = z12.object({
4738
+ objectTypeId: z12.string(),
4739
+ primaryId: z12.string(),
4740
+ properties: z12.record(JsonValueSchema),
4418
4741
  propertyChanges: PropertyChangesSchema
4419
4742
  });
4420
- var ObjectDeletedPayloadSchema = z11.object({
4421
- objectTypeId: z11.string(),
4422
- primaryId: z11.string(),
4743
+ var ObjectDeletedPayloadSchema = z12.object({
4744
+ objectTypeId: z12.string(),
4745
+ primaryId: z12.string(),
4423
4746
  propertyChanges: PropertyChangesSchema
4424
4747
  });
4425
- var LinkSubjectSchema = z11.object({
4426
- sourceTypeId: z11.string(),
4427
- sourceId: z11.string(),
4428
- linkId: z11.string(),
4429
- targetTypeId: z11.string(),
4430
- targetId: z11.string()
4748
+ var LinkSubjectSchema = z12.object({
4749
+ sourceTypeId: z12.string(),
4750
+ sourceId: z12.string(),
4751
+ linkId: z12.string(),
4752
+ targetTypeId: z12.string(),
4753
+ targetId: z12.string()
4431
4754
  });
4432
4755
  var LinkMutationPayloadSchema = LinkSubjectSchema.extend({
4433
- properties: z11.record(JsonValueSchema).optional(),
4756
+ properties: z12.record(JsonValueSchema).optional(),
4434
4757
  propertyChanges: PropertyChangesSchema
4435
4758
  });
4436
4759
  var LinkDeletedPayloadSchema = LinkSubjectSchema.extend({
@@ -4443,91 +4766,91 @@ var ONTOLOGY_EVENT_PAYLOAD_SCHEMAS = {
4443
4766
  "link.created": LinkMutationPayloadSchema,
4444
4767
  "link.updated": LinkMutationPayloadSchema,
4445
4768
  "link.deleted": LinkDeletedPayloadSchema,
4446
- "telemetry.appended": z11.object({
4447
- objectTypeId: z11.string(),
4448
- objectId: z11.string(),
4449
- propertyId: z11.string(),
4769
+ "telemetry.appended": z12.object({
4770
+ objectTypeId: z12.string(),
4771
+ objectId: z12.string(),
4772
+ propertyId: z12.string(),
4450
4773
  value: JsonValueSchema,
4451
- unit: z11.string().optional(),
4452
- at: z11.string()
4774
+ unit: z12.string().optional(),
4775
+ at: z12.string()
4453
4776
  })
4454
4777
  };
4455
4778
 
4456
4779
  // src/schemas/events.ts
4457
4780
  var EVENT_TOPICS = CORE_EVENT_TOPICS;
4458
4781
  var EVENT_TYPES = CORE_EVENT_TYPES;
4459
- var EventTopicSchema = z12.enum(EVENT_TOPICS);
4460
- var EventTypeSchema = z12.enum(EVENT_TYPES);
4461
- var ProjectionEventOriginSchema = z12.object({
4462
- kind: z12.literal("projection"),
4463
- projectionId: z12.string(),
4464
- projectionRunId: z12.string(),
4465
- datasetId: z12.string(),
4466
- datasetVersionId: z12.string()
4467
- });
4468
- var EventOriginSchema = z12.union([
4469
- z12.object({
4470
- kind: z12.literal("action"),
4471
- actionId: z12.string(),
4472
- runId: z12.string()
4782
+ var EventTopicSchema = z13.enum(EVENT_TOPICS);
4783
+ var EventTypeSchema = z13.enum(EVENT_TYPES);
4784
+ var ProjectionEventOriginSchema = z13.object({
4785
+ kind: z13.literal("projection"),
4786
+ projectionId: z13.string(),
4787
+ projectionRunId: z13.string(),
4788
+ datasetId: z13.string(),
4789
+ datasetVersionId: z13.string()
4790
+ });
4791
+ var EventOriginSchema = z13.union([
4792
+ z13.object({
4793
+ kind: z13.literal("action"),
4794
+ actionId: z13.string(),
4795
+ runId: z13.string()
4473
4796
  }),
4474
- z12.object({ kind: z12.literal("runtime"), requestId: z12.string() }),
4797
+ z13.object({ kind: z13.literal("runtime"), requestId: z13.string() }),
4475
4798
  ProjectionEventOriginSchema,
4476
- z12.object({
4477
- kind: z12.literal("telemetry"),
4478
- source: z12.union([
4479
- z12.object({ kind: z12.literal("runtime"), requestId: z12.string() }),
4480
- ProjectionEventOriginSchema.extend({ batchOrdinal: z12.number() })
4799
+ z13.object({
4800
+ kind: z13.literal("telemetry"),
4801
+ source: z13.union([
4802
+ z13.object({ kind: z13.literal("runtime"), requestId: z13.string() }),
4803
+ ProjectionEventOriginSchema.extend({ batchOrdinal: z13.number() })
4481
4804
  ])
4482
4805
  })
4483
4806
  ]);
4484
- var EventsQuerySchema = z12.object({
4807
+ var EventsQuerySchema = z13.object({
4485
4808
  topic: EventTopicSchema.optional(),
4486
4809
  type: EventTypeSchema.optional(),
4487
- afterCursor: z12.string().optional(),
4488
- limit: z12.string().optional()
4489
- });
4490
- var StoredEventBaseSchema = z12.object({
4491
- id: z12.string(),
4492
- cursor: z12.string(),
4493
- schemaVersion: z12.literal(1),
4494
- projectId: z12.string(),
4495
- occurredAt: z12.string(),
4496
- actor: z12.object({
4497
- type: z12.enum(["user", "serviceAccount", "system"]),
4498
- id: z12.string()
4810
+ afterCursor: z13.string().optional(),
4811
+ limit: z13.string().optional()
4812
+ });
4813
+ var StoredEventBaseSchema = z13.object({
4814
+ id: z13.string(),
4815
+ cursor: z13.string(),
4816
+ schemaVersion: z13.literal(1),
4817
+ projectId: z13.string(),
4818
+ occurredAt: z13.string(),
4819
+ actor: z13.object({
4820
+ type: z13.enum(["user", "serviceAccount", "system"]),
4821
+ id: z13.string()
4499
4822
  }).optional(),
4500
- partitionKey: z12.string()
4823
+ partitionKey: z13.string()
4501
4824
  });
4502
4825
  var StoredAuthorableEventBaseSchema = StoredEventBaseSchema.extend({
4503
- correlationId: z12.string().optional(),
4504
- causationId: z12.string().optional(),
4505
- idempotencyKey: z12.string().optional(),
4826
+ correlationId: z13.string().optional(),
4827
+ causationId: z13.string().optional(),
4828
+ idempotencyKey: z13.string().optional(),
4506
4829
  origin: EventOriginSchema.optional(),
4507
- metadata: z12.record(JsonValueSchema).optional()
4830
+ metadata: z13.record(JsonValueSchema).optional()
4508
4831
  });
4509
4832
  var StoredOntologyEventBaseSchema = StoredEventBaseSchema.extend({
4510
4833
  origin: EventOriginSchema,
4511
- commitId: z12.string(),
4512
- commitOrdinal: z12.number().int().nonnegative()
4834
+ commitId: z13.string(),
4835
+ commitOrdinal: z13.number().int().nonnegative()
4513
4836
  });
4514
4837
  var ontologyEventTypes = EVENT_TYPES.filter(isOntologyFactType);
4515
4838
  var ontologyEventSchemas = ontologyEventTypes.map((type) => StoredOntologyEventBaseSchema.extend({
4516
- type: z12.literal(type),
4517
- topic: z12.literal(EVENT_DEFINITIONS[type].topic),
4839
+ type: z13.literal(type),
4840
+ topic: z13.literal(EVENT_DEFINITIONS[type].topic),
4518
4841
  payload: ONTOLOGY_EVENT_PAYLOAD_SCHEMAS[type]
4519
4842
  }));
4520
4843
  var authorableEventTypes = EVENT_TYPES.filter((type) => !isOntologyFactType(type));
4521
4844
  var StoredAuthorableEventSchema = StoredAuthorableEventBaseSchema.extend({
4522
- type: z12.enum(authorableEventTypes),
4845
+ type: z13.enum(authorableEventTypes),
4523
4846
  topic: EventTopicSchema,
4524
- payload: z12.record(z12.unknown())
4847
+ payload: z13.record(z13.unknown())
4525
4848
  });
4526
- var StoredOntologyEventSchema = z12.discriminatedUnion("type", ontologyEventSchemas);
4527
- var EventSchema = z12.union([StoredOntologyEventSchema, StoredAuthorableEventSchema]);
4528
- var EventsResponseSchema = z12.object({
4529
- count: z12.number(),
4530
- events: z12.array(EventSchema)
4849
+ var StoredOntologyEventSchema = z13.discriminatedUnion("type", ontologyEventSchemas);
4850
+ var EventSchema = z13.union([StoredOntologyEventSchema, StoredAuthorableEventSchema]);
4851
+ var EventsResponseSchema = z13.object({
4852
+ count: z13.number(),
4853
+ events: z13.array(EventSchema)
4531
4854
  });
4532
4855
 
4533
4856
  // src/routes/events.ts
@@ -4573,80 +4896,27 @@ function registerEventRoutes(app, _host) {
4573
4896
  }
4574
4897
 
4575
4898
  // src/schemas/links.ts
4576
- import { z as z13 } from "zod";
4577
- var LinkSourceParamsSchema = z13.object({
4578
- objectTypeId: z13.string().min(1),
4579
- objectId: z13.string().min(1)
4899
+ import { z as z14 } from "zod";
4900
+ var LinkSourceParamsSchema = z14.object({
4901
+ objectTypeId: z14.string().min(1),
4902
+ objectId: z14.string().min(1)
4580
4903
  });
4581
4904
  var LinkParamsSchema = LinkSourceParamsSchema.extend({
4582
- linkId: z13.string().min(1)
4583
- });
4584
- var LinkQuerySchema = z13.object({
4585
- linkId: z13.string().optional(),
4586
- direction: z13.enum(["outgoing", "incoming", "both"]).default("outgoing")
4587
- });
4588
- var RemoveLinkQuerySchema = z13.object({
4589
- targetTypeId: z13.string().min(1),
4590
- targetId: z13.string().min(1)
4905
+ linkId: z14.string().min(1)
4591
4906
  });
4592
- var UpsertLinkBodySchema = z13.object({
4593
- targetTypeId: z13.string().min(1),
4594
- targetId: z13.string().min(1),
4595
- properties: z13.record(z13.unknown()).optional()
4907
+ var RemoveLinkQuerySchema = z14.object({
4908
+ targetTypeId: z14.string().min(1),
4909
+ targetId: z14.string().min(1)
4596
4910
  });
4597
- var ObjectLinkSchema = z13.object({
4598
- projectId: z13.string(),
4599
- sourceTypeId: z13.string(),
4600
- sourceId: z13.string(),
4601
- linkId: z13.string(),
4602
- targetTypeId: z13.string(),
4603
- targetId: z13.string(),
4604
- properties: z13.record(z13.unknown()).optional(),
4605
- createdAt: z13.string(),
4606
- updatedAt: z13.string()
4911
+ var UpsertLinkBodySchema = z14.object({
4912
+ targetTypeId: z14.string().min(1),
4913
+ targetId: z14.string().min(1),
4914
+ properties: z14.record(z14.unknown()).optional()
4607
4915
  });
4608
4916
 
4609
4917
  // src/routes/links.ts
4610
4918
  function registerLinkRoutes(app, _host) {
4611
- return app.get("/api/objects/:objectTypeId/:objectId/links", async (context) => {
4612
- const { params, query, set } = context;
4613
- try {
4614
- const sixb = requireRequestSixb(context);
4615
- if (!sixb.objects.getTypeById(params.objectTypeId)) {
4616
- set.status = 404;
4617
- return { error: "Object not found" };
4618
- }
4619
- const parsedQuery = LinkQuerySchema.parse(query);
4620
- const links = await sixb.objects.listLinks({
4621
- objectTypeId: params.objectTypeId,
4622
- objectId: params.objectId,
4623
- linkId: parsedQuery.linkId,
4624
- direction: parsedQuery.direction
4625
- });
4626
- return links.map((link) => ({
4627
- ...link,
4628
- createdAt: toIsoString(link.createdAt),
4629
- updatedAt: toIsoString(link.updatedAt)
4630
- }));
4631
- } catch (error) {
4632
- set.status = 400;
4633
- return { error: error instanceof Error ? error.message : String(error) };
4634
- }
4635
- }, {
4636
- params: LinkSourceParamsSchema,
4637
- query: LinkQuerySchema,
4638
- response: {
4639
- 200: ObjectLinkSchema.array(),
4640
- 400: ErrorResponseSchema,
4641
- 404: ErrorResponseSchema
4642
- },
4643
- detail: {
4644
- summary: "List object links",
4645
- tags: [OPENAPI_TAGS.links.name],
4646
- operationId: "listObjectLinks",
4647
- security: bearerSecurityRequirement("listObjectLinks")
4648
- }
4649
- }).put("/api/objects/:objectTypeId/:objectId/links/:linkId", async (context) => {
4919
+ return app.put("/api/objects/:objectTypeId/:objectId/links/:linkId", async (context) => {
4650
4920
  const { params, body, set } = context;
4651
4921
  try {
4652
4922
  const parsedBody = UpsertLinkBodySchema.parse(body);
@@ -4709,71 +4979,71 @@ import { logLevelsAtOrAbove } from "@sixb/core";
4709
4979
 
4710
4980
  // src/schemas/logs.ts
4711
4981
  import { LOG_LEVELS, SIXB_RUN_KINDS } from "@sixb/core";
4712
- import { z as z14 } from "zod";
4713
- var SixbRunKindSchema = z14.enum(SIXB_RUN_KINDS);
4714
- var LogLevelSchema = z14.enum(LOG_LEVELS);
4715
- var LogRunIdSchema = z14.string().regex(/\S/, "run id must not be blank");
4982
+ import { z as z15 } from "zod";
4983
+ var SixbRunKindSchema = z15.enum(SIXB_RUN_KINDS);
4984
+ var LogLevelSchema = z15.enum(LOG_LEVELS);
4985
+ var LogRunIdSchema = z15.string().regex(/\S/, "run id must not be blank");
4716
4986
  var DEFAULT_LOGS_PAGE_LIMIT = 200;
4717
4987
  var MAX_LOGS_PAGE_LIMIT = 1000;
4718
- var LogsLimitSchema = z14.coerce.number().int().positive().max(MAX_LOGS_PAGE_LIMIT);
4719
- var LogsQuerySchema = z14.object({
4988
+ var LogsLimitSchema = z15.coerce.number().int().positive().max(MAX_LOGS_PAGE_LIMIT);
4989
+ var LogsQuerySchema = z15.object({
4720
4990
  kind: SixbRunKindSchema.optional(),
4721
4991
  runId: LogRunIdSchema.optional(),
4722
4992
  level: LogLevelSchema.optional(),
4723
- direction: z14.enum(["forward", "backward"]).optional(),
4724
- afterCursor: z14.string().optional(),
4725
- beforeCursor: z14.string().optional(),
4993
+ direction: z15.enum(["forward", "backward"]).optional(),
4994
+ afterCursor: z15.string().optional(),
4995
+ beforeCursor: z15.string().optional(),
4726
4996
  limit: LogsLimitSchema.optional()
4727
4997
  }).superRefine((query, context) => {
4728
4998
  if (query.runId !== undefined && query.kind === undefined) {
4729
4999
  context.addIssue({
4730
- code: z14.ZodIssueCode.custom,
5000
+ code: z15.ZodIssueCode.custom,
4731
5001
  path: ["runId"],
4732
5002
  message: "kind is required when runId is provided"
4733
5003
  });
4734
5004
  }
4735
5005
  if (query.afterCursor && query.beforeCursor) {
4736
5006
  context.addIssue({
4737
- code: z14.ZodIssueCode.custom,
5007
+ code: z15.ZodIssueCode.custom,
4738
5008
  message: "afterCursor and beforeCursor are mutually exclusive"
4739
5009
  });
4740
5010
  }
4741
5011
  if (query.direction === "backward" && query.afterCursor) {
4742
5012
  context.addIssue({
4743
- code: z14.ZodIssueCode.custom,
5013
+ code: z15.ZodIssueCode.custom,
4744
5014
  path: ["afterCursor"],
4745
5015
  message: "afterCursor cannot be used with backward reads"
4746
5016
  });
4747
5017
  }
4748
5018
  if (query.direction !== "backward" && query.beforeCursor) {
4749
5019
  context.addIssue({
4750
- code: z14.ZodIssueCode.custom,
5020
+ code: z15.ZodIssueCode.custom,
4751
5021
  path: ["beforeCursor"],
4752
5022
  message: "beforeCursor requires direction=backward"
4753
5023
  });
4754
5024
  }
4755
5025
  });
4756
- var LogLineSchema = z14.object({
5026
+ var LogLineSchema = z15.object({
4757
5027
  level: LogLevelSchema,
4758
- message: z14.string(),
4759
- fields: z14.record(z14.unknown()).optional(),
4760
- at: z14.string(),
4761
- context: z14.object({
4762
- run: z14.object({
5028
+ message: z15.string(),
5029
+ fields: z15.record(z15.unknown()).optional(),
5030
+ at: z15.string(),
5031
+ context: z15.object({
5032
+ run: z15.object({
4763
5033
  kind: SixbRunKindSchema,
4764
- id: z14.string()
5034
+ id: z15.string()
4765
5035
  }),
4766
- stepId: z14.string().optional(),
4767
- phase: z14.string().optional(),
4768
- attempt: z14.number().optional()
5036
+ stepId: z15.string().optional(),
5037
+ phase: z15.string().optional(),
5038
+ attempt: z15.number().optional()
4769
5039
  }),
4770
- cursor: z14.string()
5040
+ cursor: z15.string()
4771
5041
  });
4772
- var LogsResponseSchema = z14.object({
4773
- count: z14.number(),
4774
- lines: z14.array(LogLineSchema),
4775
- cursor: z14.string().optional(),
4776
- hasMore: z14.boolean()
5042
+ var LogsResponseSchema = z15.object({
5043
+ count: z15.number(),
5044
+ lines: z15.array(LogLineSchema),
5045
+ cursor: z15.string().optional(),
5046
+ hasMore: z15.boolean()
4777
5047
  });
4778
5048
 
4779
5049
  // src/routes/logs.ts
@@ -4817,6 +5087,37 @@ function registerLogRoutes(app, _host) {
4817
5087
  });
4818
5088
  }
4819
5089
 
5090
+ // src/schemas/models.ts
5091
+ import { z as z16 } from "zod";
5092
+ var LanguageModelSchema = z16.object({
5093
+ provider: z16.string(),
5094
+ modelId: z16.string(),
5095
+ isDefault: z16.boolean()
5096
+ });
5097
+ var ModelCatalogSchema = z16.object({
5098
+ language: z16.array(LanguageModelSchema)
5099
+ });
5100
+
5101
+ // src/routes/models.ts
5102
+ function serializeLanguageModel(entry, defaultRef) {
5103
+ return { provider: entry.provider, modelId: entry.modelId, isDefault: entry.ref === defaultRef };
5104
+ }
5105
+ function registerModelRoutes(app, host) {
5106
+ return app.get("/api/models", () => {
5107
+ const language = host.definitions.models?.language;
5108
+ return ModelCatalogSchema.parse({
5109
+ language: language === undefined ? [] : language.list().map((entry) => serializeLanguageModel(entry, language.default.ref))
5110
+ });
5111
+ }, {
5112
+ response: { 200: ModelCatalogSchema },
5113
+ detail: {
5114
+ summary: "List the project model catalog",
5115
+ tags: [OPENAPI_TAGS.models.name],
5116
+ operationId: "listModels"
5117
+ }
5118
+ });
5119
+ }
5120
+
4820
5121
  // src/routes/objects.ts
4821
5122
  import {
4822
5123
  AuthorizationError as AuthorizationError3,
@@ -4824,35 +5125,35 @@ import {
4824
5125
  ObjectQueryPlanningError,
4825
5126
  ObjectQueryValidationError
4826
5127
  } from "@sixb/core";
4827
- import { ZodError as ZodError3, z as z16 } from "zod";
5128
+ import { ZodError as ZodError3, z as z18 } from "zod";
4828
5129
 
4829
5130
  // src/schemas/objects.ts
4830
- import { z as z15 } from "zod";
4831
- var ObjectParamsSchema = z15.object({
4832
- objectTypeId: z15.string().min(1),
4833
- objectId: z15.string().min(1)
4834
- });
4835
- var ObjectSearchQuerySchema = z15.object({
4836
- q: z15.string().trim().min(1).max(200),
4837
- limit: z15.string().regex(/^\d+$/).optional()
4838
- });
4839
- var ObjectSearchResponseSchema = z15.object({
4840
- items: z15.array(z15.object({
4841
- ref: z15.object({
4842
- objectTypeId: z15.string(),
4843
- primaryId: z15.string()
5131
+ import { z as z17 } from "zod";
5132
+ var ObjectParamsSchema = z17.object({
5133
+ objectTypeId: z17.string().min(1),
5134
+ objectId: z17.string().min(1)
5135
+ });
5136
+ var ObjectSearchQuerySchema = z17.object({
5137
+ q: z17.string().trim().min(1).max(200),
5138
+ limit: z17.string().regex(/^\d+$/).optional()
5139
+ });
5140
+ var ObjectSearchResponseSchema = z17.object({
5141
+ items: z17.array(z17.object({
5142
+ ref: z17.object({
5143
+ objectTypeId: z17.string(),
5144
+ primaryId: z17.string()
4844
5145
  }),
4845
- label: z15.string()
5146
+ label: z17.string()
4846
5147
  }))
4847
5148
  });
4848
5149
  var OBJECT_LIST_MAX_LIMIT = 1000;
4849
- var Rfc3339DateSchema = z15.string().datetime({ offset: true });
5150
+ var Rfc3339DateSchema = z17.string().datetime({ offset: true });
4850
5151
  function objectListDateSchema(parameter) {
4851
- return z15.string().refine((value) => Rfc3339DateSchema.safeParse(value).success, {
5152
+ return z17.string().refine((value) => Rfc3339DateSchema.safeParse(value).success, {
4852
5153
  message: `Invalid query parameter '${parameter}': expected an RFC 3339 timestamp.`
4853
5154
  }).transform((value) => new Date(value));
4854
5155
  }
4855
- var ObjectListLimitSchema = z15.string().refine((value) => {
5156
+ var ObjectListLimitSchema = z17.string().refine((value) => {
4856
5157
  if (!/^\d+$/.test(value))
4857
5158
  return false;
4858
5159
  const parsed = Number(value);
@@ -4860,25 +5161,25 @@ var ObjectListLimitSchema = z15.string().refine((value) => {
4860
5161
  }, {
4861
5162
  message: `Invalid query parameter 'limit': expected an integer between 0 and ${OBJECT_LIST_MAX_LIMIT}.`
4862
5163
  }).transform(Number);
4863
- var ObjectListOffsetSchema = z15.string().refine((value) => /^\d+$/.test(value) && Number.isSafeInteger(Number(value)), {
5164
+ var ObjectListOffsetSchema = z17.string().refine((value) => /^\d+$/.test(value) && Number.isSafeInteger(Number(value)), {
4864
5165
  message: "Invalid query parameter 'offset': expected a non-negative safe integer."
4865
5166
  }).transform(Number);
4866
- var ObjectsQuerySchema = z15.object({
4867
- objectTypeId: z15.string().optional(),
4868
- idPrefix: z15.string().optional(),
4869
- idSuffix: z15.string().optional(),
5167
+ var ObjectsQuerySchema = z17.object({
5168
+ objectTypeId: z17.string().optional(),
5169
+ idPrefix: z17.string().optional(),
5170
+ idSuffix: z17.string().optional(),
4870
5171
  updatedAfter: objectListDateSchema("updatedAfter").optional(),
4871
5172
  updatedBefore: objectListDateSchema("updatedBefore").optional(),
4872
5173
  createdAfter: objectListDateSchema("createdAfter").optional(),
4873
5174
  createdBefore: objectListDateSchema("createdBefore").optional(),
4874
5175
  limit: ObjectListLimitSchema.optional(),
4875
5176
  offset: ObjectListOffsetSchema.optional(),
4876
- orderBy: z15.enum(["createdAt", "updatedAt", "primaryId"], {
5177
+ orderBy: z17.enum(["createdAt", "updatedAt", "primaryId"], {
4877
5178
  errorMap: () => ({
4878
5179
  message: "Invalid query parameter 'orderBy': expected one of createdAt, updatedAt, or primaryId."
4879
5180
  })
4880
5181
  }).optional(),
4881
- order: z15.enum(["asc", "desc"], {
5182
+ order: z17.enum(["asc", "desc"], {
4882
5183
  errorMap: () => ({
4883
5184
  message: "Invalid query parameter 'order': expected 'asc' or 'desc'."
4884
5185
  })
@@ -4886,163 +5187,178 @@ var ObjectsQuerySchema = z15.object({
4886
5187
  }).superRefine((query, context) => {
4887
5188
  if (query.updatedAfter && query.updatedBefore && query.updatedAfter > query.updatedBefore) {
4888
5189
  context.addIssue({
4889
- code: z15.ZodIssueCode.custom,
5190
+ code: z17.ZodIssueCode.custom,
4890
5191
  path: ["updatedAfter"],
4891
5192
  message: "Invalid query parameter range: 'updatedAfter' must be before or equal to 'updatedBefore'."
4892
5193
  });
4893
5194
  }
4894
5195
  if (query.createdAfter && query.createdBefore && query.createdAfter > query.createdBefore) {
4895
5196
  context.addIssue({
4896
- code: z15.ZodIssueCode.custom,
5197
+ code: z17.ZodIssueCode.custom,
4897
5198
  path: ["createdAfter"],
4898
5199
  message: "Invalid query parameter range: 'createdAfter' must be before or equal to 'createdBefore'."
4899
5200
  });
4900
5201
  }
4901
5202
  });
4902
- var UpsertObjectBodySchema = z15.object({
4903
- properties: z15.record(z15.unknown())
5203
+ var UpsertObjectBodySchema = z17.object({
5204
+ properties: z17.record(z17.unknown())
4904
5205
  });
4905
- var ObjectQueryPredicateSchema = z15.lazy(() => z15.union([
4906
- z15.object({
4907
- op: z15.enum(["and", "or"]),
4908
- items: z15.array(ObjectQueryPredicateSchema)
5206
+ var ObjectQueryPredicateSchema = z17.lazy(() => z17.union([
5207
+ z17.object({
5208
+ op: z17.enum(["and", "or"]),
5209
+ items: z17.array(ObjectQueryPredicateSchema)
4909
5210
  }).strict(),
4910
- z15.object({
4911
- op: z15.literal("not"),
5211
+ z17.object({
5212
+ op: z17.literal("not"),
4912
5213
  item: ObjectQueryPredicateSchema
4913
5214
  }).strict(),
4914
- z15.object({
4915
- op: z15.enum(["eq", "neq", "lt", "lte", "gt", "gte"]),
4916
- propertyId: z15.string().min(1),
5215
+ z17.object({
5216
+ op: z17.enum(["eq", "neq", "lt", "lte", "gt", "gte"]),
5217
+ propertyId: z17.string().min(1),
4917
5218
  value: JsonValueSchema
4918
5219
  }).strict(),
4919
- z15.object({
4920
- op: z15.literal("in"),
4921
- propertyId: z15.string().min(1),
4922
- values: z15.array(JsonValueSchema)
5220
+ z17.object({
5221
+ op: z17.literal("in"),
5222
+ propertyId: z17.string().min(1),
5223
+ values: z17.array(JsonValueSchema)
4923
5224
  }).strict(),
4924
- z15.object({
4925
- op: z15.literal("exists"),
4926
- propertyId: z15.string().min(1),
4927
- value: z15.boolean()
5225
+ z17.object({
5226
+ op: z17.literal("exists"),
5227
+ propertyId: z17.string().min(1),
5228
+ value: z17.boolean()
4928
5229
  }).strict(),
4929
- z15.object({
4930
- op: z15.literal("contains"),
4931
- propertyId: z15.string().min(1),
5230
+ z17.object({
5231
+ op: z17.literal("contains"),
5232
+ propertyId: z17.string().min(1),
4932
5233
  value: JsonValueSchema
4933
5234
  }).strict()
4934
5235
  ]));
4935
- var ObjectQuerySortFieldSchema = z15.union([
4936
- z15.object({
4937
- kind: z15.literal("property"),
4938
- propertyId: z15.string().min(1),
4939
- direction: z15.enum(["asc", "desc"]).optional()
5236
+ var ObjectQuerySortFieldSchema = z17.union([
5237
+ z17.object({
5238
+ kind: z17.literal("property"),
5239
+ propertyId: z17.string().min(1),
5240
+ direction: z17.enum(["asc", "desc"]).optional()
4940
5241
  }).strict(),
4941
- z15.object({
4942
- kind: z15.literal("relevance"),
4943
- direction: z15.enum(["asc", "desc"]).optional()
5242
+ z17.object({
5243
+ kind: z17.literal("relevance"),
5244
+ direction: z17.enum(["asc", "desc"]).optional()
4944
5245
  }).strict()
4945
5246
  ]);
4946
- var ObjectExpansionSchema = z15.lazy(() => z15.object({
4947
- linkId: z15.string().min(1),
4948
- direction: z15.enum(["outgoing", "incoming"]),
4949
- sourceObjectTypeId: z15.string().min(1).optional(),
4950
- limit: z15.number().int().nonnegative().optional(),
4951
- orderBy: z15.array(ObjectQuerySortFieldSchema).optional(),
4952
- expand: z15.array(ObjectExpansionSchema).optional()
5247
+ var ObjectExpansionSchema = z17.lazy(() => z17.object({
5248
+ linkId: z17.string().min(1),
5249
+ direction: z17.enum(["outgoing", "incoming"]),
5250
+ sourceObjectTypeId: z17.string().min(1).optional(),
5251
+ limit: z17.number().int().nonnegative().optional(),
5252
+ orderBy: z17.array(ObjectQuerySortFieldSchema).optional(),
5253
+ expand: z17.array(ObjectExpansionSchema).optional()
4953
5254
  }).strict());
4954
- var ObjectQuerySchema = z15.lazy(() => z15.discriminatedUnion("kind", [
4955
- z15.object({
4956
- kind: z15.literal("start"),
4957
- objectTypeId: z15.string().min(1),
4958
- includeSubtypes: z15.boolean().optional()
5255
+ var ObjectQuerySchema = z17.lazy(() => z17.discriminatedUnion("kind", [
5256
+ z17.object({
5257
+ kind: z17.literal("start"),
5258
+ objectTypeId: z17.string().min(1),
5259
+ includeSubtypes: z17.boolean().optional()
4959
5260
  }).strict(),
4960
- z15.object({
4961
- kind: z15.literal("filter"),
5261
+ z17.object({
5262
+ kind: z17.literal("refs"),
5263
+ refs: z17.array(z17.object({
5264
+ objectTypeId: z17.string().min(1),
5265
+ primaryId: z17.string().min(1)
5266
+ }).strict())
5267
+ }).strict(),
5268
+ z17.object({
5269
+ kind: z17.literal("filter"),
4962
5270
  input: ObjectQuerySchema,
4963
5271
  predicate: ObjectQueryPredicateSchema
4964
5272
  }).strict(),
4965
- z15.object({
4966
- kind: z15.literal("text"),
5273
+ z17.object({
5274
+ kind: z17.literal("text"),
4967
5275
  input: ObjectQuerySchema,
4968
- query: z15.string(),
4969
- fields: z15.array(z15.string().min(1)).optional()
5276
+ query: z17.string(),
5277
+ fields: z17.array(z17.string().min(1)).optional()
4970
5278
  }).strict(),
4971
- z15.object({
4972
- kind: z15.literal("vector"),
5279
+ z17.object({
5280
+ kind: z17.literal("vector"),
4973
5281
  input: ObjectQuerySchema,
4974
- vector: z15.array(z15.number().finite()),
4975
- propertyId: z15.string().min(1),
4976
- k: z15.number().int().positive()
5282
+ vector: z17.array(z17.number().finite()),
5283
+ propertyId: z17.string().min(1),
5284
+ k: z17.number().int().positive()
4977
5285
  }).strict(),
4978
- z15.object({
4979
- kind: z15.literal("traverse"),
5286
+ z17.object({
5287
+ kind: z17.literal("traverse"),
4980
5288
  input: ObjectQuerySchema,
4981
- linkId: z15.string().min(1),
4982
- direction: z15.enum(["outgoing", "incoming"]),
4983
- sourceObjectTypeId: z15.string().min(1).optional()
5289
+ linkId: z17.string().min(1),
5290
+ direction: z17.enum(["outgoing", "incoming"]),
5291
+ sourceObjectTypeId: z17.string().min(1).optional()
4984
5292
  }).strict(),
4985
- z15.object({
4986
- kind: z15.literal("set"),
4987
- op: z15.enum(["union", "intersect", "subtract"]),
4988
- inputs: z15.array(ObjectQuerySchema)
5293
+ z17.object({
5294
+ kind: z17.literal("set"),
5295
+ op: z17.enum(["union", "intersect", "subtract"]),
5296
+ inputs: z17.array(ObjectQuerySchema)
4989
5297
  }).strict(),
4990
- z15.object({
4991
- kind: z15.literal("sort"),
5298
+ z17.object({
5299
+ kind: z17.literal("sort"),
4992
5300
  input: ObjectQuerySchema,
4993
- fields: z15.array(ObjectQuerySortFieldSchema)
5301
+ fields: z17.array(ObjectQuerySortFieldSchema)
4994
5302
  }).strict(),
4995
- z15.object({
4996
- kind: z15.literal("limit"),
5303
+ z17.object({
5304
+ kind: z17.literal("limit"),
4997
5305
  input: ObjectQuerySchema,
4998
- limit: z15.number().int().nonnegative()
5306
+ limit: z17.number().int().nonnegative()
4999
5307
  }).strict(),
5000
- z15.object({
5001
- kind: z15.literal("page"),
5308
+ z17.object({
5309
+ kind: z17.literal("page"),
5002
5310
  input: ObjectQuerySchema,
5003
- pageSize: z15.number().int().positive(),
5004
- pageToken: z15.string().optional()
5311
+ pageSize: z17.number().int().positive(),
5312
+ pageToken: z17.string().optional()
5005
5313
  }).strict(),
5006
- z15.object({
5007
- kind: z15.literal("project"),
5314
+ z17.object({
5315
+ kind: z17.literal("project"),
5008
5316
  input: ObjectQuerySchema,
5009
- properties: z15.array(z15.string().min(1)).optional()
5317
+ properties: z17.array(z17.string().min(1)).optional()
5010
5318
  }).strict(),
5011
- z15.object({
5012
- kind: z15.literal("expand"),
5319
+ z17.object({
5320
+ kind: z17.literal("expand"),
5013
5321
  input: ObjectQuerySchema,
5014
- expansions: z15.array(ObjectExpansionSchema)
5322
+ expansions: z17.array(ObjectExpansionSchema)
5015
5323
  }).strict()
5016
5324
  ]));
5017
- var ObjectQueryRequestSchema = z15.object({
5325
+ var ObjectQueryRequestSchema = z17.object({
5018
5326
  query: ObjectQuerySchema,
5019
- includeTotal: z15.boolean().optional()
5327
+ includeTotal: z17.boolean().optional()
5020
5328
  }).strict();
5021
- var ObjectQueryCountRequestSchema = z15.object({
5329
+ var ObjectQueryCountRequestSchema = z17.object({
5022
5330
  query: ObjectQuerySchema
5023
5331
  }).strict();
5024
- var ObjectQueryExistsRequestSchema = z15.object({
5332
+ var ObjectQueryExistsRequestSchema = z17.object({
5025
5333
  query: ObjectQuerySchema
5026
5334
  }).strict();
5027
- var ObjectQueryFacetRequestSchema = z15.object({
5028
- propertyId: z15.string().min(1),
5029
- limit: z15.number().int().positive()
5335
+ var ObjectQueryFacetRequestSchema = z17.object({
5336
+ propertyId: z17.string().min(1),
5337
+ limit: z17.number().int().positive()
5030
5338
  }).strict();
5031
- var ObjectQueryFacetsRequestSchema = z15.object({
5339
+ var ObjectQueryFacetsRequestSchema = z17.object({
5032
5340
  query: ObjectQuerySchema,
5033
- facets: z15.array(ObjectQueryFacetRequestSchema).min(1)
5341
+ facets: z17.array(ObjectQueryFacetRequestSchema).min(1)
5034
5342
  }).strict();
5035
- var TwinObjectSchema = z15.object({
5036
- primaryId: z15.string(),
5037
- objectTypeId: z15.string(),
5038
- properties: z15.record(z15.unknown()),
5039
- createdAt: z15.string(),
5040
- updatedAt: z15.string()
5041
- });
5042
- var ObjectListResponseSchema = z15.object({
5043
- objects: z15.array(TwinObjectSchema),
5044
- hasMore: z15.boolean(),
5045
- total: z15.number()
5343
+ var ObjectQueryLinksRequestSchema = z17.object({
5344
+ query: ObjectQuerySchema,
5345
+ direction: z17.enum(["outgoing", "incoming", "both"]).default("both"),
5346
+ linkId: z17.string().min(1).optional(),
5347
+ includeObjects: z17.boolean().default(false),
5348
+ pageSize: z17.number().int().positive().max(1000).default(100),
5349
+ pageToken: z17.string().min(1).optional()
5350
+ }).strict();
5351
+ var TwinObjectSchema = z17.object({
5352
+ primaryId: z17.string(),
5353
+ objectTypeId: z17.string(),
5354
+ properties: z17.record(z17.unknown()),
5355
+ createdAt: z17.string(),
5356
+ updatedAt: z17.string()
5357
+ });
5358
+ var ObjectListResponseSchema = z17.object({
5359
+ objects: z17.array(TwinObjectSchema),
5360
+ hasMore: z17.boolean(),
5361
+ total: z17.number()
5046
5362
  });
5047
5363
  var anyJsonValueSchema = {};
5048
5364
  var stringArraySchema = { type: "array", items: { type: "string", minLength: 1 } };
@@ -5050,6 +5366,7 @@ var objectQueryRef = { $ref: "#/components/schemas/ObjectQuery" };
5050
5366
  var objectQueryPredicateRef = { $ref: "#/components/schemas/ObjectQueryPredicate" };
5051
5367
  var objectQuerySortFieldRef = { $ref: "#/components/schemas/ObjectQuerySortField" };
5052
5368
  var objectExpansionRef = { $ref: "#/components/schemas/ObjectExpansion" };
5369
+ var objectRefSchemaRef = { $ref: "#/components/schemas/ObjectRef" };
5053
5370
  var ObjectQueryOpenApiSchemas = {
5054
5371
  ErrorResponse: {
5055
5372
  type: "object",
@@ -5188,6 +5505,38 @@ var ObjectQueryOpenApiSchemas = {
5188
5505
  plan: { $ref: "#/components/schemas/ObjectQueryPlanSummary" }
5189
5506
  }
5190
5507
  },
5508
+ ObjectQueryLink: {
5509
+ type: "object",
5510
+ required: ["source", "linkId", "target", "createdAt", "updatedAt"],
5511
+ additionalProperties: false,
5512
+ properties: {
5513
+ source: objectRefSchemaRef,
5514
+ linkId: { type: "string" },
5515
+ target: objectRefSchemaRef,
5516
+ properties: { type: "object", additionalProperties: true },
5517
+ createdAt: { type: "string" },
5518
+ updatedAt: { type: "string" }
5519
+ }
5520
+ },
5521
+ ObjectQueryLinksResponse: {
5522
+ type: "object",
5523
+ required: ["objects", "links", "hasMore"],
5524
+ additionalProperties: false,
5525
+ properties: {
5526
+ objects: {
5527
+ type: "array",
5528
+ description: "Selected objects followed by visible endpoint objects from this link page, de-duplicated. Empty unless includeObjects is true.",
5529
+ items: { $ref: "#/components/schemas/ObjectQueryObject" }
5530
+ },
5531
+ links: {
5532
+ type: "array",
5533
+ description: "Visible physical links in deterministic identity order.",
5534
+ items: { $ref: "#/components/schemas/ObjectQueryLink" }
5535
+ },
5536
+ hasMore: { type: "boolean" },
5537
+ nextPageToken: { type: "string" }
5538
+ }
5539
+ },
5191
5540
  ObjectQueryErrorResponse: {
5192
5541
  type: "object",
5193
5542
  required: ["error"],
@@ -5247,6 +5596,36 @@ var ObjectQueryOpenApiSchemas = {
5247
5596
  }
5248
5597
  }
5249
5598
  },
5599
+ ObjectQueryLinksRequest: {
5600
+ type: "object",
5601
+ required: ["query"],
5602
+ additionalProperties: false,
5603
+ properties: {
5604
+ query: objectQueryRef,
5605
+ direction: { type: "string", enum: ["outgoing", "incoming", "both"], default: "both" },
5606
+ linkId: { type: "string", minLength: 1 },
5607
+ includeObjects: {
5608
+ type: "boolean",
5609
+ default: false,
5610
+ description: "Include selected objects and visible endpoints from the current link page."
5611
+ },
5612
+ pageSize: { type: "integer", minimum: 1, maximum: 1000, default: 100 },
5613
+ pageToken: {
5614
+ type: "string",
5615
+ minLength: 1,
5616
+ description: "Opaque token from the previous page. The project, normalized query, direction, and linkId must remain unchanged."
5617
+ }
5618
+ }
5619
+ },
5620
+ ObjectRef: {
5621
+ type: "object",
5622
+ required: ["objectTypeId", "primaryId"],
5623
+ additionalProperties: false,
5624
+ properties: {
5625
+ objectTypeId: { type: "string", minLength: 1 },
5626
+ primaryId: { type: "string", minLength: 1 }
5627
+ }
5628
+ },
5250
5629
  ObjectQuery: {
5251
5630
  oneOf: [
5252
5631
  {
@@ -5259,6 +5638,20 @@ var ObjectQueryOpenApiSchemas = {
5259
5638
  includeSubtypes: { type: "boolean" }
5260
5639
  }
5261
5640
  },
5641
+ {
5642
+ type: "object",
5643
+ required: ["kind", "refs"],
5644
+ additionalProperties: false,
5645
+ properties: {
5646
+ kind: { type: "string", enum: ["refs"] },
5647
+ refs: {
5648
+ type: "array",
5649
+ minItems: 1,
5650
+ description: "One to 1,000 unique identities after normalization; duplicate entries are accepted and removed.",
5651
+ items: objectRefSchemaRef
5652
+ }
5653
+ }
5654
+ },
5262
5655
  {
5263
5656
  type: "object",
5264
5657
  required: ["kind", "input", "predicate"],
@@ -5472,7 +5865,7 @@ var ObjectQueryOpenApiSchemas = {
5472
5865
 
5473
5866
  // src/routes/objects.ts
5474
5867
  var ObjectFileContentQuerySchema = FileContentQuerySchema.extend({
5475
- path: z16.string().min(1).regex(/^\/properties(?:\/|$)/, "Object file content paths must start with /properties/")
5868
+ path: z18.string().min(1).regex(/^\/properties(?:\/|$)/, "Object file content paths must start with /properties/")
5476
5869
  });
5477
5870
  function serializeObject(row) {
5478
5871
  return {
@@ -5483,6 +5876,22 @@ function serializeObject(row) {
5483
5876
  updatedAt: toIsoString(row.updatedAt)
5484
5877
  };
5485
5878
  }
5879
+ function serializeObjectLink(link) {
5880
+ return {
5881
+ source: {
5882
+ objectTypeId: link.sourceTypeId,
5883
+ primaryId: link.sourceId
5884
+ },
5885
+ linkId: link.linkId,
5886
+ target: {
5887
+ objectTypeId: link.targetTypeId,
5888
+ primaryId: link.targetId
5889
+ },
5890
+ ...link.properties === undefined ? {} : { properties: link.properties },
5891
+ createdAt: toIsoString(link.createdAt),
5892
+ updatedAt: toIsoString(link.updatedAt)
5893
+ };
5894
+ }
5486
5895
  function serializeExpandedObject(row) {
5487
5896
  const serialized = serializeObject(row);
5488
5897
  if (row.links)
@@ -5702,35 +6111,98 @@ function registerObjectRoutes(app, host) {
5702
6111
  operationId: "listObjects",
5703
6112
  security: bearerSecurityRequirement("listObjects")
5704
6113
  }
5705
- }).post("/api/objects/query", async (context) => {
6114
+ }).post("/api/objects/query", async (context) => {
6115
+ const { body, set } = context;
6116
+ try {
6117
+ const parsed = ObjectQueryRequestSchema.parse(body);
6118
+ const result = await requireRequestSixb(context).objects.executeQuery({
6119
+ query: parsed.query,
6120
+ includeTotal: parsed.includeTotal
6121
+ });
6122
+ return {
6123
+ objects: result.objects.map(serializeExpandedObject),
6124
+ hasMore: result.hasMore,
6125
+ nextPageToken: result.nextPageToken,
6126
+ plan: serializePlan(result.plan),
6127
+ ...result.total === undefined ? {} : { total: result.total }
6128
+ };
6129
+ } catch (error) {
6130
+ return handleObjectQueryError(error, set);
6131
+ }
6132
+ }, {
6133
+ detail: {
6134
+ summary: "Query objects",
6135
+ tags: [OPENAPI_TAGS.objects.name],
6136
+ operationId: "queryObjects",
6137
+ security: bearerSecurityRequirement("queryObjects"),
6138
+ requestBody: {
6139
+ required: true,
6140
+ content: {
6141
+ "application/json": {
6142
+ schema: { $ref: "#/components/schemas/ObjectQueryRequest" }
6143
+ }
6144
+ }
6145
+ },
6146
+ responses: {
6147
+ 200: {
6148
+ description: "Response for status 200",
6149
+ content: {
6150
+ "application/json": {
6151
+ schema: { $ref: "#/components/schemas/ObjectQueryResponse" }
6152
+ }
6153
+ }
6154
+ },
6155
+ 400: {
6156
+ description: "Response for status 400",
6157
+ content: {
6158
+ "application/json": {
6159
+ schema: { $ref: "#/components/schemas/ObjectQueryErrorResponse" }
6160
+ }
6161
+ }
6162
+ },
6163
+ 403: {
6164
+ description: "Response for status 403",
6165
+ content: {
6166
+ "application/json": {
6167
+ schema: { $ref: "#/components/schemas/ErrorResponse" }
6168
+ }
6169
+ }
6170
+ },
6171
+ 500: {
6172
+ description: "Response for status 500",
6173
+ content: {
6174
+ "application/json": {
6175
+ schema: { $ref: "#/components/schemas/ErrorResponse" }
6176
+ }
6177
+ }
6178
+ }
6179
+ }
6180
+ }
6181
+ }).post("/api/objects/query/links", async (context) => {
5706
6182
  const { body, set } = context;
5707
6183
  try {
5708
- const parsed = ObjectQueryRequestSchema.parse(body);
5709
- const result = await requireRequestSixb(context).objects.executeQuery({
5710
- query: parsed.query,
5711
- includeTotal: parsed.includeTotal
5712
- });
6184
+ const parsed = ObjectQueryLinksRequestSchema.parse(body);
6185
+ const result = await requireRequestSixb(context).objects.queryLinks(parsed);
5713
6186
  return {
5714
- objects: result.objects.map(serializeExpandedObject),
6187
+ objects: result.objects.map(serializeObject),
6188
+ links: result.links.map(serializeObjectLink),
5715
6189
  hasMore: result.hasMore,
5716
- nextPageToken: result.nextPageToken,
5717
- plan: serializePlan(result.plan),
5718
- ...result.total === undefined ? {} : { total: result.total }
6190
+ ...result.nextPageToken === undefined ? {} : { nextPageToken: result.nextPageToken }
5719
6191
  };
5720
6192
  } catch (error) {
5721
6193
  return handleObjectQueryError(error, set);
5722
6194
  }
5723
6195
  }, {
5724
6196
  detail: {
5725
- summary: "Query objects",
5726
- tags: [OPENAPI_TAGS.objects.name],
5727
- operationId: "queryObjects",
5728
- security: bearerSecurityRequirement("queryObjects"),
6197
+ summary: "Query object links",
6198
+ tags: [OPENAPI_TAGS.links.name],
6199
+ operationId: "queryObjectLinks",
6200
+ security: bearerSecurityRequirement("queryObjectLinks"),
5729
6201
  requestBody: {
5730
6202
  required: true,
5731
6203
  content: {
5732
6204
  "application/json": {
5733
- schema: { $ref: "#/components/schemas/ObjectQueryRequest" }
6205
+ schema: { $ref: "#/components/schemas/ObjectQueryLinksRequest" }
5734
6206
  }
5735
6207
  }
5736
6208
  },
@@ -5739,7 +6211,7 @@ function registerObjectRoutes(app, host) {
5739
6211
  description: "Response for status 200",
5740
6212
  content: {
5741
6213
  "application/json": {
5742
- schema: { $ref: "#/components/schemas/ObjectQueryResponse" }
6214
+ schema: { $ref: "#/components/schemas/ObjectQueryLinksResponse" }
5743
6215
  }
5744
6216
  }
5745
6217
  },
@@ -6129,111 +6601,111 @@ function registerOntologyRoutes(app, _host) {
6129
6601
  import {
6130
6602
  PIPELINE_RUN_FAILURE_CODES
6131
6603
  } from "@sixb/core/storage";
6132
- import { z as z17 } from "zod";
6604
+ import { z as z19 } from "zod";
6133
6605
  var PipelineRunFailureSchema = sixbFailureSchema(PIPELINE_RUN_FAILURE_CODES);
6134
- var PipelineParamsSchema = z17.object({
6135
- pipelineId: z17.string().min(1)
6606
+ var PipelineParamsSchema = z19.object({
6607
+ pipelineId: z19.string().min(1)
6136
6608
  });
6137
- var PipelineRunParamsSchema = z17.object({
6138
- runId: z17.string().min(1)
6609
+ var PipelineRunParamsSchema = z19.object({
6610
+ runId: z19.string().min(1)
6139
6611
  });
6140
- var PipelineRunStatusSchema = z17.enum([
6612
+ var PipelineRunStatusSchema = z19.enum([
6141
6613
  "queued",
6142
6614
  "running",
6143
6615
  "succeeded",
6144
6616
  "failed",
6145
6617
  "cancelled"
6146
6618
  ]);
6147
- var PipelineStepRunStatusSchema = z17.enum(["running", "succeeded", "failed", "cancelled"]);
6148
- var PipelineRunsQuerySchema = z17.object({
6149
- pipelineId: z17.string().optional(),
6619
+ var PipelineStepRunStatusSchema = z19.enum(["running", "succeeded", "failed", "cancelled"]);
6620
+ var PipelineRunsQuerySchema = z19.object({
6621
+ pipelineId: z19.string().optional(),
6150
6622
  status: PipelineRunStatusSchema.optional(),
6151
- startedAfter: z17.string().optional(),
6152
- startedBefore: z17.string().optional(),
6153
- limit: z17.string().optional(),
6154
- offset: z17.string().optional(),
6155
- order: z17.enum(["asc", "desc"]).optional()
6623
+ startedAfter: z19.string().optional(),
6624
+ startedBefore: z19.string().optional(),
6625
+ limit: z19.string().optional(),
6626
+ offset: z19.string().optional(),
6627
+ order: z19.enum(["asc", "desc"]).optional()
6156
6628
  });
6157
- var DatasetVersionRefSchema2 = z17.object({
6158
- datasetId: z17.string(),
6159
- versionId: z17.string()
6629
+ var DatasetVersionRefSchema2 = z19.object({
6630
+ datasetId: z19.string(),
6631
+ versionId: z19.string()
6160
6632
  });
6161
- var PipelineTriggerSchema = z17.object({
6162
- type: z17.literal("schedule"),
6163
- scheduleId: z17.string()
6633
+ var PipelineTriggerSchema = z19.object({
6634
+ type: z19.literal("schedule"),
6635
+ scheduleId: z19.string()
6164
6636
  });
6165
- var PipelineStepExecutorSchema = z17.union([
6166
- z17.object({
6167
- kind: z17.literal("sql"),
6168
- dialect: z17.literal("duckdb")
6637
+ var PipelineStepExecutorSchema = z19.union([
6638
+ z19.object({
6639
+ kind: z19.literal("sql"),
6640
+ dialect: z19.literal("duckdb")
6169
6641
  }),
6170
- z17.object({
6171
- kind: z17.literal("run")
6642
+ z19.object({
6643
+ kind: z19.literal("run")
6172
6644
  })
6173
6645
  ]);
6174
- var PipelineRunSchema = z17.object({
6175
- id: z17.string(),
6176
- projectId: z17.string(),
6177
- pipelineId: z17.string(),
6646
+ var PipelineRunSchema = z19.object({
6647
+ id: z19.string(),
6648
+ projectId: z19.string(),
6649
+ pipelineId: z19.string(),
6178
6650
  status: PipelineRunStatusSchema,
6179
- queuedAt: z17.string(),
6180
- startedAt: z17.string().optional(),
6181
- finishedAt: z17.string().optional(),
6651
+ queuedAt: z19.string(),
6652
+ startedAt: z19.string().optional(),
6653
+ finishedAt: z19.string().optional(),
6182
6654
  output: DatasetVersionRefSchema2.optional(),
6183
6655
  error: PipelineRunFailureSchema.optional()
6184
6656
  });
6185
- var PipelineStepRunSchema = z17.object({
6186
- id: z17.string(),
6187
- projectId: z17.string(),
6188
- pipelineRunId: z17.string(),
6189
- pipelineId: z17.string(),
6190
- stepId: z17.string(),
6191
- datasetId: z17.string(),
6192
- mode: z17.enum(["snapshot", "append"]),
6657
+ var PipelineStepRunSchema = z19.object({
6658
+ id: z19.string(),
6659
+ projectId: z19.string(),
6660
+ pipelineRunId: z19.string(),
6661
+ pipelineId: z19.string(),
6662
+ stepId: z19.string(),
6663
+ datasetId: z19.string(),
6664
+ mode: z19.enum(["snapshot", "append"]),
6193
6665
  status: PipelineStepRunStatusSchema,
6194
- startedAt: z17.string(),
6195
- finishedAt: z17.string().optional(),
6196
- inputs: z17.array(DatasetVersionRefSchema2),
6666
+ startedAt: z19.string(),
6667
+ finishedAt: z19.string().optional(),
6668
+ inputs: z19.array(DatasetVersionRefSchema2),
6197
6669
  output: DatasetVersionRefSchema2.optional(),
6198
- rowsWritten: z17.number().optional(),
6670
+ rowsWritten: z19.number().optional(),
6199
6671
  error: PipelineRunFailureSchema.optional()
6200
6672
  });
6201
- var PipelineStepSchema = z17.object({
6202
- id: z17.string(),
6203
- mode: z17.enum(["snapshot", "append"]),
6673
+ var PipelineStepSchema = z19.object({
6674
+ id: z19.string(),
6675
+ mode: z19.enum(["snapshot", "append"]),
6204
6676
  executor: PipelineStepExecutorSchema,
6205
- inputs: z17.array(z17.object({
6206
- name: z17.string(),
6677
+ inputs: z19.array(z19.object({
6678
+ name: z19.string(),
6207
6679
  dataset: DatasetDefinitionSchema
6208
6680
  })),
6209
6681
  output: DatasetDefinitionSchema
6210
6682
  });
6211
- var PipelineSchema = z17.object({
6212
- id: z17.string(),
6213
- triggers: z17.array(PipelineTriggerSchema),
6214
- graph: z17.object({
6215
- kind: z17.literal("sequence"),
6216
- nodes: z17.array(z17.object({
6217
- kind: z17.literal("step"),
6683
+ var PipelineSchema = z19.object({
6684
+ id: z19.string(),
6685
+ triggers: z19.array(PipelineTriggerSchema),
6686
+ graph: z19.object({
6687
+ kind: z19.literal("sequence"),
6688
+ nodes: z19.array(z19.object({
6689
+ kind: z19.literal("step"),
6218
6690
  step: PipelineStepSchema
6219
6691
  }))
6220
6692
  }),
6221
6693
  latestRun: PipelineRunSchema.nullable()
6222
6694
  });
6223
- var PipelineRunListResponseSchema = z17.object({
6224
- runs: z17.array(PipelineRunSchema),
6225
- hasMore: z17.boolean(),
6226
- total: z17.number()
6695
+ var PipelineRunListResponseSchema = z19.object({
6696
+ runs: z19.array(PipelineRunSchema),
6697
+ hasMore: z19.boolean(),
6698
+ total: z19.number()
6227
6699
  });
6228
- var PipelineRunDetailResponseSchema = z17.object({
6700
+ var PipelineRunDetailResponseSchema = z19.object({
6229
6701
  run: PipelineRunSchema,
6230
- steps: z17.array(PipelineStepRunSchema)
6702
+ steps: z19.array(PipelineStepRunSchema)
6231
6703
  });
6232
- var RequestPipelineRunResponseSchema = z17.object({
6233
- runId: z17.string(),
6234
- jobId: z17.string(),
6235
- pipelineId: z17.string(),
6236
- queuedAt: z17.string()
6704
+ var RequestPipelineRunResponseSchema = z19.object({
6705
+ runId: z19.string(),
6706
+ jobId: z19.string(),
6707
+ pipelineId: z19.string(),
6708
+ queuedAt: z19.string()
6237
6709
  });
6238
6710
 
6239
6711
  // src/routes/pipelines.ts
@@ -6455,9 +6927,9 @@ function registerPipelineRoutes(app, host) {
6455
6927
  }
6456
6928
 
6457
6929
  // src/schemas/project.ts
6458
- import { z as z18 } from "zod";
6459
- var ProjectInfoResponseSchema = z18.object({
6460
- id: z18.string()
6930
+ import { z as z20 } from "zod";
6931
+ var ProjectInfoResponseSchema = z20.object({
6932
+ id: z20.string()
6461
6933
  });
6462
6934
 
6463
6935
  // src/routes/project.ts
@@ -6475,141 +6947,147 @@ function registerProjectRoutes(app, host) {
6475
6947
 
6476
6948
  // src/schemas/projections.ts
6477
6949
  import { PROJECTION_RUN_FAILURE_CODES } from "@sixb/core/storage";
6478
- import { z as z19 } from "zod";
6950
+ import { z as z21 } from "zod";
6479
6951
  var ProjectionRunFailureSchema = sixbFailureSchema(PROJECTION_RUN_FAILURE_CODES);
6480
- var ProjectionKindSchema = z19.enum(["object", "link", "telemetry"]);
6481
- var ProjectionRunStatusSchema = z19.enum([
6952
+ var ProjectionKindSchema = z21.enum(["object", "link", "telemetry"]);
6953
+ var ProjectionRunStatusSchema = z21.enum([
6482
6954
  "queued",
6483
6955
  "running",
6484
6956
  "succeeded",
6485
6957
  "failed",
6486
6958
  "cancelled"
6487
6959
  ]);
6488
- var ProjectionRunIdentityBaseSchema = z19.object({
6489
- projectionId: z19.string(),
6490
- datasetVersion: z19.object({
6491
- datasetId: z19.string(),
6492
- versionId: z19.string(),
6493
- createdAt: z19.string()
6960
+ var ProjectionRunIdentityBaseSchema = z21.object({
6961
+ projectionId: z21.string(),
6962
+ datasetVersion: z21.object({
6963
+ datasetId: z21.string(),
6964
+ versionId: z21.string(),
6965
+ createdAt: z21.string()
6494
6966
  }),
6495
- ontologyRevision: z19.string(),
6496
- projectionRevision: z19.string(),
6497
- ownershipHash: z19.string()
6498
- });
6499
- var ProjectionRunBaseSchema = z19.object({
6500
- id: z19.string(),
6501
- projectId: z19.string(),
6502
- executionId: z19.string(),
6967
+ ontologyRevision: z21.string(),
6968
+ projectionRevision: z21.string(),
6969
+ ownershipHash: z21.string()
6970
+ });
6971
+ var ProjectionRunBaseSchema = z21.object({
6972
+ id: z21.string(),
6973
+ projectId: z21.string(),
6974
+ executionId: z21.string(),
6503
6975
  status: ProjectionRunStatusSchema,
6504
- attempt: z19.number(),
6505
- progress: z19.object({
6506
- sourceRowsRead: z19.number(),
6507
- sourceRowsSkipped: z19.number()
6976
+ attempt: z21.number(),
6977
+ progress: z21.object({
6978
+ sourceRowsRead: z21.number(),
6979
+ sourceRowsSkipped: z21.number()
6508
6980
  }),
6509
- queuedAt: z19.string(),
6510
- startedAt: z19.string().optional(),
6511
- finishedAt: z19.string().optional(),
6981
+ queuedAt: z21.string(),
6982
+ startedAt: z21.string().optional(),
6983
+ finishedAt: z21.string().optional(),
6512
6984
  error: ProjectionRunFailureSchema.optional()
6513
6985
  });
6514
6986
  var ObjectProjectionRunSchema = ProjectionRunBaseSchema.extend({
6515
6987
  identity: ProjectionRunIdentityBaseSchema.extend({
6516
- projectionKind: z19.literal("object"),
6517
- protocol: z19.literal("replacement")
6988
+ projectionKind: z21.literal("object"),
6989
+ protocol: z21.literal("replacement")
6518
6990
  }),
6519
- target: z19.object({ objectTypeId: z19.string() })
6991
+ target: z21.object({ objectTypeId: z21.string() })
6520
6992
  });
6521
6993
  var LinkProjectionRunSchema = ProjectionRunBaseSchema.extend({
6522
6994
  identity: ProjectionRunIdentityBaseSchema.extend({
6523
- projectionKind: z19.literal("link"),
6524
- protocol: z19.literal("replacement")
6995
+ projectionKind: z21.literal("link"),
6996
+ protocol: z21.literal("replacement")
6525
6997
  }),
6526
- target: z19.object({
6527
- sourceObjectTypeId: z19.string(),
6528
- targetObjectTypeId: z19.string()
6998
+ target: z21.object({
6999
+ sourceObjectTypeId: z21.string(),
7000
+ targetObjectTypeId: z21.string()
6529
7001
  })
6530
7002
  });
6531
7003
  var TelemetryProjectionRunSchema = ProjectionRunBaseSchema.extend({
6532
7004
  identity: ProjectionRunIdentityBaseSchema.extend({
6533
- projectionKind: z19.literal("telemetry"),
6534
- protocol: z19.literal("telemetry")
7005
+ projectionKind: z21.literal("telemetry"),
7006
+ protocol: z21.literal("telemetry")
6535
7007
  }),
6536
- target: z19.object({ objectTypeId: z19.string() })
7008
+ target: z21.object({ objectTypeId: z21.string() })
6537
7009
  });
6538
- var ProjectionRunSchema = z19.union([
7010
+ var ProjectionRunSchema = z21.union([
6539
7011
  ObjectProjectionRunSchema,
6540
7012
  LinkProjectionRunSchema,
6541
7013
  TelemetryProjectionRunSchema
6542
7014
  ]);
6543
- var ForeignKeyDescriptorSchema = z19.object({
6544
- linkId: z19.string(),
6545
- sourcePropertyId: z19.string().optional(),
6546
- sourceField: z19.string().optional(),
6547
- targetObjectTypeId: z19.string()
6548
- });
6549
- var ObjectProjectionSchema = z19.object({
6550
- _tag: z19.literal("ObjectProjectionDefinition"),
6551
- id: z19.string(),
6552
- objectTypeId: z19.string(),
6553
- datasetId: z19.string(),
6554
- properties: z19.record(z19.string()),
6555
- links: z19.record(ForeignKeyDescriptorSchema),
7015
+ var ForeignKeyDescriptorSchema = z21.object({
7016
+ linkId: z21.string(),
7017
+ sourcePropertyId: z21.string().optional(),
7018
+ sourceField: z21.string().optional(),
7019
+ targetObjectTypeId: z21.string()
7020
+ });
7021
+ var SourceEditConflictResolutionSchema = z21.union([
7022
+ z21.object({ strategy: z21.literal("editsWin") }),
7023
+ z21.object({ strategy: z21.literal("mostRecent"), sourceTimestamp: z21.string() })
7024
+ ]);
7025
+ var ObjectProjectionSchema = z21.object({
7026
+ _tag: z21.literal("ObjectProjectionDefinition"),
7027
+ id: z21.string(),
7028
+ objectTypeId: z21.string(),
7029
+ datasetId: z21.string(),
7030
+ properties: z21.record(z21.string()),
7031
+ links: z21.record(ForeignKeyDescriptorSchema),
7032
+ conflictResolution: SourceEditConflictResolutionSchema,
6556
7033
  latestRun: ProjectionRunSchema.nullable()
6557
7034
  });
6558
- var LinkProjectionSchema = z19.object({
6559
- _tag: z19.literal("LinkProjectionDefinition"),
6560
- id: z19.string(),
6561
- linkId: z19.string(),
6562
- sourceObjectTypeId: z19.string(),
6563
- targetObjectTypeId: z19.string(),
6564
- datasetId: z19.string(),
6565
- sourceField: z19.string(),
6566
- targetField: z19.string(),
7035
+ var LinkProjectionSchema = z21.object({
7036
+ _tag: z21.literal("LinkProjectionDefinition"),
7037
+ id: z21.string(),
7038
+ linkId: z21.string(),
7039
+ sourceObjectTypeId: z21.string(),
7040
+ targetObjectTypeId: z21.string(),
7041
+ datasetId: z21.string(),
7042
+ sourceField: z21.string(),
7043
+ targetField: z21.string(),
6567
7044
  latestRun: ProjectionRunSchema.nullable()
6568
7045
  });
6569
- var TelemetryProjectionSchema = z19.object({
6570
- _tag: z19.literal("TelemetryProjectionDefinition"),
6571
- id: z19.string(),
6572
- objectTypeId: z19.string(),
6573
- propertyId: z19.string(),
6574
- datasetId: z19.string(),
6575
- objectIdField: z19.string(),
6576
- atField: z19.string(),
6577
- valueField: z19.string(),
6578
- unitField: z19.string().optional(),
7046
+ var TelemetryProjectionSchema = z21.object({
7047
+ _tag: z21.literal("TelemetryProjectionDefinition"),
7048
+ id: z21.string(),
7049
+ objectTypeId: z21.string(),
7050
+ datasetId: z21.string(),
7051
+ objectIdField: z21.string(),
7052
+ atField: z21.string(),
7053
+ properties: z21.record(z21.object({
7054
+ valueField: z21.string(),
7055
+ unitField: z21.string().optional()
7056
+ })),
6579
7057
  latestRun: ProjectionRunSchema.nullable()
6580
7058
  });
6581
- var ProjectionListResponseSchema = z19.object({
6582
- objectProjections: z19.array(ObjectProjectionSchema),
6583
- linkProjections: z19.array(LinkProjectionSchema),
6584
- telemetryProjections: z19.array(TelemetryProjectionSchema)
7059
+ var ProjectionListResponseSchema = z21.object({
7060
+ objectProjections: z21.array(ObjectProjectionSchema),
7061
+ linkProjections: z21.array(LinkProjectionSchema),
7062
+ telemetryProjections: z21.array(TelemetryProjectionSchema)
6585
7063
  });
6586
- var ProjectionParamsSchema = z19.object({
6587
- projectionId: z19.string().min(1)
7064
+ var ProjectionParamsSchema = z21.object({
7065
+ projectionId: z21.string().min(1)
6588
7066
  });
6589
- var ProjectionResponseSchema = z19.union([
7067
+ var ProjectionResponseSchema = z21.union([
6590
7068
  ObjectProjectionSchema,
6591
7069
  LinkProjectionSchema,
6592
7070
  TelemetryProjectionSchema
6593
7071
  ]);
6594
- var ProjectionRunParamsSchema = z19.object({
6595
- runId: z19.string().min(1)
7072
+ var ProjectionRunParamsSchema = z21.object({
7073
+ runId: z21.string().min(1)
6596
7074
  });
6597
- var ProjectionRunsQuerySchema = z19.object({
6598
- projectionId: z19.string().optional(),
7075
+ var ProjectionRunsQuerySchema = z21.object({
7076
+ projectionId: z21.string().optional(),
6599
7077
  projectionKind: ProjectionKindSchema.optional(),
6600
- datasetId: z19.string().optional(),
6601
- datasetVersionId: z19.string().optional(),
7078
+ datasetId: z21.string().optional(),
7079
+ datasetVersionId: z21.string().optional(),
6602
7080
  status: ProjectionRunStatusSchema.optional(),
6603
- startedAfter: z19.string().optional(),
6604
- startedBefore: z19.string().optional(),
6605
- limit: z19.string().optional(),
6606
- offset: z19.string().optional(),
6607
- order: z19.enum(["asc", "desc"]).optional()
7081
+ startedAfter: z21.string().optional(),
7082
+ startedBefore: z21.string().optional(),
7083
+ limit: z21.string().optional(),
7084
+ offset: z21.string().optional(),
7085
+ order: z21.enum(["asc", "desc"]).optional()
6608
7086
  });
6609
- var ProjectionRunListResponseSchema = z19.object({
6610
- runs: z19.array(ProjectionRunSchema),
6611
- hasMore: z19.boolean(),
6612
- total: z19.number()
7087
+ var ProjectionRunListResponseSchema = z21.object({
7088
+ runs: z21.array(ProjectionRunSchema),
7089
+ hasMore: z21.boolean(),
7090
+ total: z21.number()
6613
7091
  });
6614
7092
 
6615
7093
  // src/routes/projections.ts
@@ -6651,10 +7129,15 @@ function projectionCatalogIds(catalog) {
6651
7129
  ].map((projection) => projection.id);
6652
7130
  }
6653
7131
  function serializeProjection(projection, latestRuns) {
6654
- return {
6655
- ...projection,
6656
- latestRun: latestRuns.get(projection.id) ?? null
6657
- };
7132
+ const latestRun = latestRuns.get(projection.id) ?? null;
7133
+ if (projection._tag === "ObjectProjectionDefinition") {
7134
+ return {
7135
+ ...projection,
7136
+ conflictResolution: projection.conflictResolution ?? { strategy: "editsWin" },
7137
+ latestRun
7138
+ };
7139
+ }
7140
+ return { ...projection, latestRun };
6658
7141
  }
6659
7142
  function serializeProjectionCatalog(catalog, latestRuns) {
6660
7143
  return {
@@ -6772,88 +7255,88 @@ function registerProjectionRoutes(app, host) {
6772
7255
  import { deriveRuleEventDependencies } from "@sixb/core/internal/rules";
6773
7256
 
6774
7257
  // src/schemas/rules.ts
6775
- import { z as z20 } from "zod";
6776
- var RuleParamsSchema = z20.object({
6777
- ruleId: z20.string().min(1)
6778
- });
6779
- var RuleStatesQuerySchema = z20.object({
6780
- ruleId: z20.string().optional(),
6781
- objectTypeId: z20.string().optional(),
6782
- primaryId: z20.string().optional(),
6783
- limit: z20.string().optional(),
6784
- offset: z20.string().optional(),
6785
- order: z20.enum(["asc", "desc"]).optional()
6786
- });
6787
- var RuleValueSchema = z20.union([z20.string(), z20.number(), z20.boolean()]).nullable();
6788
- var RuleSubjectSchema = z20.object({
6789
- kind: z20.literal("object"),
6790
- objectTypeId: z20.string()
6791
- });
6792
- var RuleEventSubjectSchema = z20.object({
6793
- kind: z20.literal("object"),
6794
- objectTypeId: z20.string(),
6795
- primaryId: z20.string()
6796
- });
6797
- var RulePropertyPredicateSchema = z20.object({
6798
- kind: z20.literal("property"),
6799
- propertyId: z20.string(),
6800
- op: z20.enum(["eq", "notEq", "gt", "gte", "lt", "lte", "isPresent", "isMissing"]),
7258
+ import { z as z22 } from "zod";
7259
+ var RuleParamsSchema = z22.object({
7260
+ ruleId: z22.string().min(1)
7261
+ });
7262
+ var RuleStatesQuerySchema = z22.object({
7263
+ ruleId: z22.string().optional(),
7264
+ objectTypeId: z22.string().optional(),
7265
+ primaryId: z22.string().optional(),
7266
+ limit: z22.string().optional(),
7267
+ offset: z22.string().optional(),
7268
+ order: z22.enum(["asc", "desc"]).optional()
7269
+ });
7270
+ var RuleValueSchema = z22.union([z22.string(), z22.number(), z22.boolean()]).nullable();
7271
+ var RuleSubjectSchema = z22.object({
7272
+ kind: z22.literal("object"),
7273
+ objectTypeId: z22.string()
7274
+ });
7275
+ var RuleEventSubjectSchema = z22.object({
7276
+ kind: z22.literal("object"),
7277
+ objectTypeId: z22.string(),
7278
+ primaryId: z22.string()
7279
+ });
7280
+ var RulePropertyPredicateSchema = z22.object({
7281
+ kind: z22.literal("property"),
7282
+ propertyId: z22.string(),
7283
+ op: z22.enum(["eq", "notEq", "gt", "gte", "lt", "lte", "isPresent", "isMissing"]),
6801
7284
  value: RuleValueSchema.optional()
6802
7285
  });
6803
- var RuleLinkPredicateSchema = z20.object({
6804
- kind: z20.literal("link"),
6805
- linkId: z20.string(),
6806
- op: z20.enum(["exists", "isMissing"])
7286
+ var RuleLinkPredicateSchema = z22.object({
7287
+ kind: z22.literal("link"),
7288
+ linkId: z22.string(),
7289
+ op: z22.enum(["exists", "isMissing"])
6807
7290
  });
6808
7291
  function createRulePredicateSchema(childPredicateSchema) {
6809
- return z20.union([
6810
- z20.object({
6811
- kind: z20.literal("all"),
6812
- predicates: z20.array(childPredicateSchema)
7292
+ return z22.union([
7293
+ z22.object({
7294
+ kind: z22.literal("all"),
7295
+ predicates: z22.array(childPredicateSchema)
6813
7296
  }),
6814
- z20.object({
6815
- kind: z20.literal("any"),
6816
- predicates: z20.array(childPredicateSchema)
7297
+ z22.object({
7298
+ kind: z22.literal("any"),
7299
+ predicates: z22.array(childPredicateSchema)
6817
7300
  }),
6818
- z20.object({
6819
- kind: z20.literal("not"),
7301
+ z22.object({
7302
+ kind: z22.literal("not"),
6820
7303
  predicate: childPredicateSchema
6821
7304
  }),
6822
7305
  RulePropertyPredicateSchema,
6823
7306
  RuleLinkPredicateSchema
6824
7307
  ]);
6825
7308
  }
6826
- var DeepRulePredicateSchema = createRulePredicateSchema(z20.unknown());
7309
+ var DeepRulePredicateSchema = createRulePredicateSchema(z22.unknown());
6827
7310
  var NestedRulePredicateSchema = createRulePredicateSchema(DeepRulePredicateSchema);
6828
7311
  var RulePredicateSchema = NestedRulePredicateSchema;
6829
- var RuleEventDependencySchema = z20.union([
6830
- z20.object({
6831
- type: z20.enum(["object.created", "object.updated", "object.deleted"]),
6832
- objectTypeId: z20.string()
7312
+ var RuleEventDependencySchema = z22.union([
7313
+ z22.object({
7314
+ type: z22.enum(["object.created", "object.updated", "object.deleted"]),
7315
+ objectTypeId: z22.string()
6833
7316
  }),
6834
- z20.object({
6835
- type: z20.enum(["link.created", "link.updated", "link.deleted"]),
6836
- sourceTypeId: z20.string(),
6837
- linkId: z20.string()
7317
+ z22.object({
7318
+ type: z22.enum(["link.created", "link.updated", "link.deleted"]),
7319
+ sourceTypeId: z22.string(),
7320
+ linkId: z22.string()
6838
7321
  })
6839
7322
  ]);
6840
- var RuleSchema = z20.object({
6841
- kind: z20.literal("rule"),
6842
- id: z20.string(),
7323
+ var RuleSchema = z22.object({
7324
+ kind: z22.literal("rule"),
7325
+ id: z22.string(),
6843
7326
  subject: RuleSubjectSchema,
6844
7327
  predicate: RulePredicateSchema,
6845
- dependencies: z20.array(RuleEventDependencySchema)
7328
+ dependencies: z22.array(RuleEventDependencySchema)
6846
7329
  });
6847
- var RuleStateSchema = z20.object({
6848
- projectId: z20.string(),
6849
- ruleId: z20.string(),
7330
+ var RuleStateSchema = z22.object({
7331
+ projectId: z22.string(),
7332
+ ruleId: z22.string(),
6850
7333
  subject: RuleEventSubjectSchema,
6851
- triggeredAt: z20.string()
7334
+ triggeredAt: z22.string()
6852
7335
  });
6853
- var RuleStateListResponseSchema = z20.object({
6854
- states: z20.array(RuleStateSchema),
6855
- hasMore: z20.boolean(),
6856
- total: z20.number()
7336
+ var RuleStateListResponseSchema = z22.object({
7337
+ states: z22.array(RuleStateSchema),
7338
+ hasMore: z22.boolean(),
7339
+ total: z22.number()
6857
7340
  });
6858
7341
 
6859
7342
  // src/routes/rules.ts
@@ -6933,44 +7416,44 @@ function registerRuleRoutes(app, host) {
6933
7416
  }
6934
7417
 
6935
7418
  // src/schemas/status.ts
6936
- import { z as z21 } from "zod";
6937
- var HealthResponseSchema = z21.object({ status: z21.literal("ok") });
6938
- var StorageReadinessSchema = z21.object({
6939
- reachable: z21.boolean(),
6940
- schemaValid: z21.boolean()
7419
+ import { z as z23 } from "zod";
7420
+ var HealthResponseSchema = z23.object({ status: z23.literal("ok") });
7421
+ var StorageReadinessSchema = z23.object({
7422
+ reachable: z23.boolean(),
7423
+ schemaValid: z23.boolean()
6941
7424
  });
6942
- var ReadinessResponseSchema = z21.object({
6943
- status: z21.enum(["ready", "unready"]),
7425
+ var ReadinessResponseSchema = z23.object({
7426
+ status: z23.enum(["ready", "unready"]),
6944
7427
  storage: StorageReadinessSchema,
6945
- reason: z21.string().optional()
6946
- });
6947
- var MaintenanceSummarySchema = z21.object({
6948
- running: z21.boolean(),
6949
- intervalMs: z21.number().int().positive(),
6950
- lastStartedAt: z21.string().nullable(),
6951
- lastCompletedAt: z21.string().nullable(),
6952
- lastDurationMs: z21.number().nonnegative().nullable(),
6953
- consecutiveFailures: z21.number().int().nonnegative(),
6954
- lastError: z21.string().nullable(),
6955
- outbox: z21.object({
6956
- pendingCount: z21.number().int().nonnegative(),
6957
- oldestPendingAt: z21.string().nullable(),
6958
- retryingCount: z21.number().int().nonnegative(),
6959
- maxAttempts: z21.number().int().nonnegative()
7428
+ reason: z23.string().optional()
7429
+ });
7430
+ var MaintenanceSummarySchema = z23.object({
7431
+ running: z23.boolean(),
7432
+ intervalMs: z23.number().int().positive(),
7433
+ lastStartedAt: z23.string().nullable(),
7434
+ lastCompletedAt: z23.string().nullable(),
7435
+ lastDurationMs: z23.number().nonnegative().nullable(),
7436
+ consecutiveFailures: z23.number().int().nonnegative(),
7437
+ lastError: z23.string().nullable(),
7438
+ outbox: z23.object({
7439
+ pendingCount: z23.number().int().nonnegative(),
7440
+ oldestPendingAt: z23.string().nullable(),
7441
+ retryingCount: z23.number().int().nonnegative(),
7442
+ maxAttempts: z23.number().int().nonnegative()
6960
7443
  }).nullable(),
6961
- terminalSources: z21.object({
6962
- count: z21.number().int().nonnegative(),
6963
- oldestTerminalAt: z21.string().nullable()
7444
+ terminalSources: z23.object({
7445
+ count: z23.number().int().nonnegative(),
7446
+ oldestTerminalAt: z23.string().nullable()
6964
7447
  }).nullable(),
6965
- cleanup: z21.object({
6966
- publishedOutboxRowsDeleted: z21.number().int().nonnegative(),
6967
- terminalSourceRowsDeleted: z21.number().int().nonnegative(),
6968
- terminalSourceMaterializationsDeleted: z21.number().int().nonnegative()
7448
+ cleanup: z23.object({
7449
+ publishedOutboxRowsDeleted: z23.number().int().nonnegative(),
7450
+ terminalSourceRowsDeleted: z23.number().int().nonnegative(),
7451
+ terminalSourceMaterializationsDeleted: z23.number().int().nonnegative()
6969
7452
  }).nullable()
6970
7453
  });
6971
- var StatusResponseSchema = z21.object({
6972
- status: z21.enum(["ok", "degraded"]),
6973
- objectTypes: z21.number().int().nonnegative(),
7454
+ var StatusResponseSchema = z23.object({
7455
+ status: z23.enum(["ok", "degraded"]),
7456
+ objectTypes: z23.number().int().nonnegative(),
6974
7457
  maintenance: MaintenanceSummarySchema
6975
7458
  });
6976
7459
 
@@ -7016,74 +7499,74 @@ function registerStatusRoutes(app, host) {
7016
7499
  import {
7017
7500
  SYNC_RUN_FAILURE_CODES
7018
7501
  } from "@sixb/core/storage";
7019
- import { z as z22 } from "zod";
7502
+ import { z as z24 } from "zod";
7020
7503
  var SyncRunFailureSchema = sixbFailureSchema(SYNC_RUN_FAILURE_CODES);
7021
- var SyncParamsSchema = z22.object({
7022
- syncId: z22.string().min(1)
7023
- });
7024
- var SyncRunStatusSchema = z22.enum(["queued", "running", "succeeded", "failed", "cancelled"]);
7025
- var SyncModeSchema = z22.enum(["snapshot", "append", "merge"]);
7026
- var SyncRunsQuerySchema = z22.object({
7027
- syncId: z22.string().optional(),
7028
- datasetId: z22.string().optional(),
7504
+ var SyncParamsSchema = z24.object({
7505
+ syncId: z24.string().min(1)
7506
+ });
7507
+ var SyncRunStatusSchema = z24.enum(["queued", "running", "succeeded", "failed", "cancelled"]);
7508
+ var SyncModeSchema = z24.enum(["snapshot", "append", "merge"]);
7509
+ var SyncRunsQuerySchema = z24.object({
7510
+ syncId: z24.string().optional(),
7511
+ datasetId: z24.string().optional(),
7029
7512
  status: SyncRunStatusSchema.optional(),
7030
- startedAfter: z22.string().optional(),
7031
- startedBefore: z22.string().optional(),
7032
- limit: z22.string().optional(),
7033
- offset: z22.string().optional(),
7034
- order: z22.enum(["asc", "desc"]).optional()
7513
+ startedAfter: z24.string().optional(),
7514
+ startedBefore: z24.string().optional(),
7515
+ limit: z24.string().optional(),
7516
+ offset: z24.string().optional(),
7517
+ order: z24.enum(["asc", "desc"]).optional()
7035
7518
  });
7036
- var RequestSyncRunBodySchema = z22.object({
7037
- expectedLatestVersionId: z22.string().optional(),
7038
- commitMessage: z22.string().optional()
7519
+ var RequestSyncRunBodySchema = z24.object({
7520
+ expectedLatestVersionId: z24.string().optional(),
7521
+ commitMessage: z24.string().optional()
7039
7522
  });
7040
- var SyncTriggerSchema = z22.object({
7041
- type: z22.literal("schedule"),
7042
- scheduleId: z22.string()
7523
+ var SyncTriggerSchema = z24.object({
7524
+ type: z24.literal("schedule"),
7525
+ scheduleId: z24.string()
7043
7526
  });
7044
- var SyncRunSchema = z22.object({
7045
- id: z22.string(),
7046
- projectId: z22.string(),
7047
- syncId: z22.string(),
7048
- datasetId: z22.string(),
7527
+ var SyncRunSchema = z24.object({
7528
+ id: z24.string(),
7529
+ projectId: z24.string(),
7530
+ syncId: z24.string(),
7531
+ datasetId: z24.string(),
7049
7532
  mode: SyncModeSchema,
7050
7533
  status: SyncRunStatusSchema,
7051
- queuedAt: z22.string(),
7052
- startedAt: z22.string().optional(),
7053
- finishedAt: z22.string().optional(),
7054
- rowsRead: z22.number().optional(),
7055
- output: z22.object({
7056
- datasetId: z22.string(),
7057
- versionId: z22.string()
7534
+ queuedAt: z24.string(),
7535
+ startedAt: z24.string().optional(),
7536
+ finishedAt: z24.string().optional(),
7537
+ rowsRead: z24.number().optional(),
7538
+ output: z24.object({
7539
+ datasetId: z24.string(),
7540
+ versionId: z24.string()
7058
7541
  }).optional(),
7059
- expectedLatestVersionId: z22.string().optional(),
7060
- commitMessage: z22.string().optional(),
7542
+ expectedLatestVersionId: z24.string().optional(),
7543
+ commitMessage: z24.string().optional(),
7061
7544
  error: SyncRunFailureSchema.optional()
7062
7545
  });
7063
- var SyncSchema = z22.object({
7064
- id: z22.string(),
7546
+ var SyncSchema = z24.object({
7547
+ id: z24.string(),
7065
7548
  mode: SyncModeSchema,
7066
- connector: z22.object({
7067
- id: z22.string(),
7068
- type: z22.string()
7549
+ connector: z24.object({
7550
+ id: z24.string(),
7551
+ type: z24.string()
7069
7552
  }),
7070
- target: z22.object({
7071
- kind: z22.literal("dataset"),
7553
+ target: z24.object({
7554
+ kind: z24.literal("dataset"),
7072
7555
  dataset: DatasetDefinitionSchema
7073
7556
  }),
7074
- triggers: z22.array(SyncTriggerSchema),
7557
+ triggers: z24.array(SyncTriggerSchema),
7075
7558
  latestRun: SyncRunSchema.nullable()
7076
7559
  });
7077
- var SyncRunListResponseSchema = z22.object({
7078
- runs: z22.array(SyncRunSchema),
7079
- hasMore: z22.boolean(),
7080
- total: z22.number()
7560
+ var SyncRunListResponseSchema = z24.object({
7561
+ runs: z24.array(SyncRunSchema),
7562
+ hasMore: z24.boolean(),
7563
+ total: z24.number()
7081
7564
  });
7082
- var RequestSyncRunResponseSchema = z22.object({
7083
- runId: z22.string(),
7084
- jobId: z22.string(),
7085
- syncId: z22.string(),
7086
- queuedAt: z22.string()
7565
+ var RequestSyncRunResponseSchema = z24.object({
7566
+ runId: z24.string(),
7567
+ jobId: z24.string(),
7568
+ syncId: z24.string(),
7569
+ queuedAt: z24.string()
7087
7570
  });
7088
7571
 
7089
7572
  // src/routes/syncs.ts
@@ -7237,52 +7720,52 @@ function registerSyncRoutes(app, host) {
7237
7720
  }
7238
7721
 
7239
7722
  // src/schemas/telemetry.ts
7240
- import { z as z23 } from "zod";
7241
- var TelemetryParamsSchema = z23.object({
7242
- objectTypeId: z23.string().min(1),
7243
- objectId: z23.string().min(1),
7244
- propertyId: z23.string().min(1)
7245
- });
7246
- var TelemetryHistoryQuerySchema = z23.object({
7247
- from: z23.string().optional(),
7248
- to: z23.string().optional(),
7249
- limit: z23.string().optional(),
7250
- order: z23.enum(["asc", "desc"]).optional()
7251
- });
7252
- var BulkTelemetryHistorySeriesInputSchema = z23.object({
7253
- objectTypeId: z23.string().min(1),
7254
- objectId: z23.string().min(1),
7255
- propertyId: z23.string().min(1)
7723
+ import { z as z25 } from "zod";
7724
+ var TelemetryParamsSchema = z25.object({
7725
+ objectTypeId: z25.string().min(1),
7726
+ objectId: z25.string().min(1),
7727
+ propertyId: z25.string().min(1)
7728
+ });
7729
+ var TelemetryHistoryQuerySchema = z25.object({
7730
+ from: z25.string().optional(),
7731
+ to: z25.string().optional(),
7732
+ limit: z25.string().optional(),
7733
+ order: z25.enum(["asc", "desc"]).optional()
7734
+ });
7735
+ var BulkTelemetryHistorySeriesInputSchema = z25.object({
7736
+ objectTypeId: z25.string().min(1),
7737
+ objectId: z25.string().min(1),
7738
+ propertyId: z25.string().min(1)
7256
7739
  }).strict();
7257
- var BulkTelemetryHistoryBodySchema = z23.object({
7258
- series: z23.array(BulkTelemetryHistorySeriesInputSchema).min(1),
7259
- from: z23.string().optional(),
7260
- to: z23.string().optional(),
7261
- limitPerSeries: z23.number().int().nonnegative().optional(),
7262
- order: z23.enum(["asc", "desc"]).optional()
7740
+ var BulkTelemetryHistoryBodySchema = z25.object({
7741
+ series: z25.array(BulkTelemetryHistorySeriesInputSchema).min(1),
7742
+ from: z25.string().optional(),
7743
+ to: z25.string().optional(),
7744
+ limitPerSeries: z25.number().int().nonnegative().optional(),
7745
+ order: z25.enum(["asc", "desc"]).optional()
7263
7746
  }).strict();
7264
- var AppendTelemetryBodySchema = z23.object({
7265
- value: z23.unknown(),
7266
- unit: z23.string().optional(),
7267
- at: z23.string().optional()
7268
- });
7269
- var TelemetryPointSchema = z23.object({
7270
- projectId: z23.string(),
7271
- objectTypeId: z23.string(),
7272
- objectId: z23.string(),
7273
- propertyId: z23.string(),
7274
- value: z23.unknown(),
7275
- unit: z23.string().optional(),
7276
- at: z23.string()
7277
- });
7278
- var BulkTelemetryHistorySeriesSchema = z23.object({
7279
- objectTypeId: z23.string(),
7280
- objectId: z23.string(),
7281
- propertyId: z23.string(),
7282
- points: z23.array(TelemetryPointSchema)
7283
- });
7284
- var BulkTelemetryHistoryResponseSchema = z23.object({
7285
- series: z23.array(BulkTelemetryHistorySeriesSchema)
7747
+ var AppendTelemetryBodySchema = z25.object({
7748
+ value: z25.unknown(),
7749
+ unit: z25.string().optional(),
7750
+ at: z25.string().optional()
7751
+ });
7752
+ var TelemetryPointSchema = z25.object({
7753
+ projectId: z25.string(),
7754
+ objectTypeId: z25.string(),
7755
+ objectId: z25.string(),
7756
+ propertyId: z25.string(),
7757
+ value: z25.unknown(),
7758
+ unit: z25.string().optional(),
7759
+ at: z25.string()
7760
+ });
7761
+ var BulkTelemetryHistorySeriesSchema = z25.object({
7762
+ objectTypeId: z25.string(),
7763
+ objectId: z25.string(),
7764
+ propertyId: z25.string(),
7765
+ points: z25.array(TelemetryPointSchema)
7766
+ });
7767
+ var BulkTelemetryHistoryResponseSchema = z25.object({
7768
+ series: z25.array(BulkTelemetryHistorySeriesSchema)
7286
7769
  });
7287
7770
 
7288
7771
  // src/routes/telemetry.ts
@@ -7440,40 +7923,40 @@ function registerTelemetryRoutes(app, _host) {
7440
7923
 
7441
7924
  // src/schemas/webhook-runs.ts
7442
7925
  import { WEBHOOK_RUN_FAILURE_CODES } from "@sixb/core/storage";
7443
- import { z as z24 } from "zod";
7926
+ import { z as z26 } from "zod";
7444
7927
  var WebhookRunFailureSchema = sixbFailureSchema(WEBHOOK_RUN_FAILURE_CODES);
7445
- var WebhookRunStatusSchema = z24.enum(["running", "succeeded", "failed"]);
7446
- var WebhookRunsQuerySchema = z24.object({
7447
- connectorId: z24.string().optional(),
7448
- webhookId: z24.string().optional(),
7928
+ var WebhookRunStatusSchema = z26.enum(["running", "succeeded", "failed"]);
7929
+ var WebhookRunsQuerySchema = z26.object({
7930
+ connectorId: z26.string().optional(),
7931
+ webhookId: z26.string().optional(),
7449
7932
  status: WebhookRunStatusSchema.optional(),
7450
- idempotencyKey: z24.string().optional(),
7451
- startedAfter: z24.string().optional(),
7452
- startedBefore: z24.string().optional(),
7453
- limit: z24.string().optional(),
7454
- offset: z24.string().optional(),
7455
- order: z24.enum(["asc", "desc"]).optional()
7456
- });
7457
- var WebhookRunSchema = z24.object({
7458
- id: z24.string(),
7459
- projectId: z24.string(),
7460
- executionId: z24.string(),
7461
- connectorId: z24.string(),
7462
- webhookId: z24.string(),
7933
+ idempotencyKey: z26.string().optional(),
7934
+ startedAfter: z26.string().optional(),
7935
+ startedBefore: z26.string().optional(),
7936
+ limit: z26.string().optional(),
7937
+ offset: z26.string().optional(),
7938
+ order: z26.enum(["asc", "desc"]).optional()
7939
+ });
7940
+ var WebhookRunSchema = z26.object({
7941
+ id: z26.string(),
7942
+ projectId: z26.string(),
7943
+ executionId: z26.string(),
7944
+ connectorId: z26.string(),
7945
+ webhookId: z26.string(),
7463
7946
  status: WebhookRunStatusSchema,
7464
- method: z24.string(),
7465
- route: z24.string(),
7466
- startedAt: z24.string(),
7467
- finishedAt: z24.string().optional(),
7468
- requestBodyBytes: z24.number(),
7469
- responseStatus: z24.number().optional(),
7470
- idempotencyKey: z24.string().optional(),
7947
+ method: z26.string(),
7948
+ route: z26.string(),
7949
+ startedAt: z26.string(),
7950
+ finishedAt: z26.string().optional(),
7951
+ requestBodyBytes: z26.number(),
7952
+ responseStatus: z26.number().optional(),
7953
+ idempotencyKey: z26.string().optional(),
7471
7954
  error: WebhookRunFailureSchema.optional()
7472
7955
  });
7473
- var WebhookRunListResponseSchema = z24.object({
7474
- runs: z24.array(WebhookRunSchema),
7475
- hasMore: z24.boolean(),
7476
- total: z24.number()
7956
+ var WebhookRunListResponseSchema = z26.object({
7957
+ runs: z26.array(WebhookRunSchema),
7958
+ hasMore: z26.boolean(),
7959
+ total: z26.number()
7477
7960
  });
7478
7961
 
7479
7962
  // src/routes/webhook-runs.ts
@@ -7548,25 +8031,25 @@ import {
7548
8031
  snapshotWorkflowInterventionResponse
7549
8032
  } from "@sixb/core/internal/workflows";
7550
8033
  import { AGENT_RUN_FAILURE_CODES as AGENT_RUN_FAILURE_CODES2, WORKFLOW_RUN_FAILURE_CODES as WORKFLOW_RUN_FAILURE_CODES2 } from "@sixb/core/storage";
7551
- import { z as z26 } from "zod";
8034
+ import { z as z28 } from "zod";
7552
8035
 
7553
8036
  // src/schemas/workflows.ts
7554
8037
  import {
7555
8038
  WORKFLOW_RUN_FAILURE_CODES
7556
8039
  } from "@sixb/core/storage";
7557
- import { z as z25 } from "zod";
7558
- var WorkflowIOSnapshotSchema = z25.record(JsonValueSchema);
8040
+ import { z as z27 } from "zod";
8041
+ var WorkflowIOSnapshotSchema = z27.record(JsonValueSchema);
7559
8042
  var WorkflowRunFailureSchema = sixbFailureSchema(WORKFLOW_RUN_FAILURE_CODES);
7560
- var WorkflowParamsSchema = z25.object({
7561
- workflowId: z25.string().min(1)
8043
+ var WorkflowParamsSchema = z27.object({
8044
+ workflowId: z27.string().min(1)
7562
8045
  });
7563
- var WorkflowRunParamsSchema = z25.object({
7564
- runId: z25.string().min(1)
8046
+ var WorkflowRunParamsSchema = z27.object({
8047
+ runId: z27.string().min(1)
7565
8048
  });
7566
- var WorkflowInterventionParamsSchema = z25.object({
7567
- interventionId: z25.string().min(1)
8049
+ var WorkflowInterventionParamsSchema = z27.object({
8050
+ interventionId: z27.string().min(1)
7568
8051
  });
7569
- var WorkflowRunStatusSchema = z25.enum([
8052
+ var WorkflowRunStatusSchema = z27.enum([
7570
8053
  "queued",
7571
8054
  "running",
7572
8055
  "waiting",
@@ -7574,91 +8057,91 @@ var WorkflowRunStatusSchema = z25.enum([
7574
8057
  "failed",
7575
8058
  "cancelled"
7576
8059
  ]);
7577
- var WorkflowInterventionStatusSchema = z25.enum([
8060
+ var WorkflowInterventionStatusSchema = z27.enum([
7578
8061
  "pending",
7579
8062
  "submitted",
7580
8063
  "cancelled",
7581
8064
  "expired"
7582
8065
  ]);
7583
- var WorkflowRunsQuerySchema = z25.object({
7584
- workflowId: z25.string().optional(),
8066
+ var WorkflowRunsQuerySchema = z27.object({
8067
+ workflowId: z27.string().optional(),
7585
8068
  status: WorkflowRunStatusSchema.optional(),
7586
- startedAfter: z25.string().optional(),
7587
- startedBefore: z25.string().optional(),
7588
- limit: z25.string().optional(),
7589
- offset: z25.string().optional(),
7590
- order: z25.enum(["asc", "desc"]).optional()
8069
+ startedAfter: z27.string().optional(),
8070
+ startedBefore: z27.string().optional(),
8071
+ limit: z27.string().optional(),
8072
+ offset: z27.string().optional(),
8073
+ order: z27.enum(["asc", "desc"]).optional()
7591
8074
  });
7592
- var WorkflowInterventionsQuerySchema = z25.object({
7593
- workflowId: z25.string().optional(),
7594
- workflowRunId: z25.string().optional(),
7595
- nodeRunId: z25.string().optional(),
7596
- nodeId: z25.string().optional(),
7597
- nodeKey: z25.string().optional(),
7598
- interventionId: z25.string().optional(),
8075
+ var WorkflowInterventionsQuerySchema = z27.object({
8076
+ workflowId: z27.string().optional(),
8077
+ workflowRunId: z27.string().optional(),
8078
+ nodeRunId: z27.string().optional(),
8079
+ nodeId: z27.string().optional(),
8080
+ nodeKey: z27.string().optional(),
8081
+ interventionId: z27.string().optional(),
7599
8082
  status: WorkflowInterventionStatusSchema.optional(),
7600
- requestedAfter: z25.string().optional(),
7601
- requestedBefore: z25.string().optional(),
7602
- limit: z25.string().optional(),
7603
- offset: z25.string().optional(),
7604
- order: z25.enum(["asc", "desc"]).optional()
8083
+ requestedAfter: z27.string().optional(),
8084
+ requestedBefore: z27.string().optional(),
8085
+ limit: z27.string().optional(),
8086
+ offset: z27.string().optional(),
8087
+ order: z27.enum(["asc", "desc"]).optional()
7605
8088
  });
7606
- var RequestWorkflowRunBodySchema = z25.object({
8089
+ var RequestWorkflowRunBodySchema = z27.object({
7607
8090
  input: WorkflowIOSnapshotSchema.optional()
7608
8091
  }).default({});
7609
- var WorkflowInterventionActorSchema = z25.object({
7610
- principalType: z25.enum(["user", "serviceAccount", "system"]),
7611
- principalId: z25.string().min(1)
8092
+ var WorkflowInterventionActorSchema = z27.object({
8093
+ principalType: z27.enum(["user", "serviceAccount", "system"]),
8094
+ principalId: z27.string().min(1)
7612
8095
  });
7613
- var CancelWorkflowRunBodySchema = z25.object({}).default({});
7614
- var SubmitWorkflowInterventionBodySchema = z25.object({
8096
+ var CancelWorkflowRunBodySchema = z27.object({}).default({});
8097
+ var SubmitWorkflowInterventionBodySchema = z27.object({
7615
8098
  response: WorkflowIOSnapshotSchema
7616
8099
  });
7617
- var CancelWorkflowInterventionBodySchema = z25.object({}).default({});
7618
- var WorkflowTriggerSchema = z25.object({
7619
- type: z25.literal("schedule"),
7620
- scheduleId: z25.string()
8100
+ var CancelWorkflowInterventionBodySchema = z27.object({}).default({});
8101
+ var WorkflowTriggerSchema = z27.object({
8102
+ type: z27.literal("schedule"),
8103
+ scheduleId: z27.string()
7621
8104
  });
7622
- var WorkflowNodeSchema = z25.union([
7623
- z25.object({
7624
- type: z25.literal("step"),
7625
- id: z25.string(),
7626
- key: z25.string(),
8105
+ var WorkflowNodeSchema = z27.union([
8106
+ z27.object({
8107
+ type: z27.literal("step"),
8108
+ id: z27.string(),
8109
+ key: z27.string(),
7627
8110
  input: WorkflowIOSnapshotSchema,
7628
8111
  output: WorkflowIOSnapshotSchema
7629
8112
  }),
7630
- z25.object({
7631
- type: z25.literal("action"),
7632
- id: z25.string(),
7633
- key: z25.string(),
7634
- objectTypeId: z25.string().optional(),
8113
+ z27.object({
8114
+ type: z27.literal("action"),
8115
+ id: z27.string(),
8116
+ key: z27.string(),
8117
+ objectTypeId: z27.string().optional(),
7635
8118
  params: WorkflowIOSnapshotSchema
7636
8119
  }),
7637
- z25.object({
7638
- type: z25.literal("intervention"),
7639
- id: z25.string(),
7640
- key: z25.string(),
8120
+ z27.object({
8121
+ type: z27.literal("intervention"),
8122
+ id: z27.string(),
8123
+ key: z27.string(),
7641
8124
  input: WorkflowIOSnapshotSchema,
7642
8125
  response: WorkflowIOSnapshotSchema,
7643
- description: z25.string().optional()
8126
+ description: z27.string().optional()
7644
8127
  }),
7645
- z25.object({
7646
- type: z25.literal("agent"),
7647
- id: z25.string(),
7648
- key: z25.string(),
7649
- agentId: z25.string(),
8128
+ z27.object({
8129
+ type: z27.literal("agent"),
8130
+ id: z27.string(),
8131
+ key: z27.string(),
8132
+ agentId: z27.string(),
7650
8133
  input: WorkflowIOSnapshotSchema,
7651
8134
  output: WorkflowIOSnapshotSchema
7652
8135
  })
7653
8136
  ]);
7654
- var WorkflowRunSummarySchema = z25.object({
7655
- id: z25.string(),
7656
- projectId: z25.string(),
7657
- workflowId: z25.string(),
8137
+ var WorkflowRunSummarySchema = z27.object({
8138
+ id: z27.string(),
8139
+ projectId: z27.string(),
8140
+ workflowId: z27.string(),
7658
8141
  status: WorkflowRunStatusSchema,
7659
- queuedAt: z25.string().optional(),
7660
- startedAt: z25.string(),
7661
- finishedAt: z25.string().optional(),
8142
+ queuedAt: z27.string().optional(),
8143
+ startedAt: z27.string(),
8144
+ finishedAt: z27.string().optional(),
7662
8145
  error: WorkflowRunFailureSchema.optional(),
7663
8146
  requestedBy: WorkflowInterventionActorSchema
7664
8147
  });
@@ -7666,108 +8149,111 @@ var WorkflowRunDetailSchema = WorkflowRunSummarySchema.extend({
7666
8149
  input: WorkflowIOSnapshotSchema,
7667
8150
  output: WorkflowIOSnapshotSchema.optional()
7668
8151
  });
7669
- var WorkflowAgentNodeExecutionSummarySchema = z25.object({
7670
- agentId: z25.string(),
7671
- status: z25.enum(["queued", "running", "succeeded", "failed", "cancelled"]),
7672
- attempt: z25.number().int().nonnegative(),
7673
- modelId: z25.string().optional(),
7674
- finishReason: z25.string().optional(),
8152
+ var WorkflowAgentNodeExecutionSummarySchema = z27.object({
8153
+ agentId: z27.string(),
8154
+ status: z27.enum(["queued", "running", "succeeded", "failed", "cancelled"]),
8155
+ attempt: z27.number().int().nonnegative(),
8156
+ modelId: z27.string().optional(),
8157
+ finishReason: z27.string().optional(),
7675
8158
  usage: AiUsageSummarySchema.optional(),
7676
- startedAt: z25.string().optional(),
7677
- completedAt: z25.string().optional()
8159
+ cost: AiCostSummarySchema.optional(),
8160
+ startedAt: z27.string().optional(),
8161
+ completedAt: z27.string().optional()
7678
8162
  });
8163
+ var WorkflowAgentFailurePhaseSchema = z27.enum(["agent-loop", "structured-finalizer"]);
7679
8164
  var WorkflowAgentNodeExecutionSchema = WorkflowAgentNodeExecutionSummarySchema.extend({
7680
- nodeRunId: z25.string(),
7681
- prompt: z25.string(),
7682
- trace: z25.array(z25.unknown()).optional(),
7683
- diagnostics: z25.array(z25.unknown()).optional(),
8165
+ nodeRunId: z27.string(),
8166
+ prompt: z27.string(),
8167
+ trace: z27.array(AgentMessagePartSchema).optional(),
8168
+ diagnostics: z27.array(JsonValueSchema).optional(),
8169
+ failurePhase: WorkflowAgentFailurePhaseSchema.optional(),
7684
8170
  error: AgentRunFailureSchema.optional(),
7685
- createdAt: z25.string()
8171
+ createdAt: z27.string()
7686
8172
  });
7687
- var WorkflowNodeRunSchema = z25.object({
7688
- id: z25.string(),
7689
- projectId: z25.string(),
7690
- workflowRunId: z25.string(),
7691
- workflowId: z25.string(),
7692
- nodeIndex: z25.number(),
7693
- nodeType: z25.enum(["step", "action", "intervention", "agent"]),
7694
- nodeId: z25.string(),
7695
- nodeKey: z25.string(),
7696
- status: z25.enum(["running", "waiting", "succeeded", "failed", "cancelled"]),
8173
+ var WorkflowNodeRunSchema = z27.object({
8174
+ id: z27.string(),
8175
+ projectId: z27.string(),
8176
+ workflowRunId: z27.string(),
8177
+ workflowId: z27.string(),
8178
+ nodeIndex: z27.number(),
8179
+ nodeType: z27.enum(["step", "action", "intervention", "agent"]),
8180
+ nodeId: z27.string(),
8181
+ nodeKey: z27.string(),
8182
+ status: z27.enum(["running", "waiting", "succeeded", "failed", "cancelled"]),
7697
8183
  input: WorkflowIOSnapshotSchema,
7698
- startedAt: z25.string(),
7699
- finishedAt: z25.string().optional(),
8184
+ startedAt: z27.string(),
8185
+ finishedAt: z27.string().optional(),
7700
8186
  output: WorkflowIOSnapshotSchema.optional(),
7701
8187
  error: WorkflowRunFailureSchema.optional(),
7702
8188
  agentExecution: WorkflowAgentNodeExecutionSummarySchema.optional()
7703
8189
  });
7704
- var WorkflowInterventionSchema = z25.object({
7705
- id: z25.string(),
7706
- projectId: z25.string(),
7707
- workflowId: z25.string(),
7708
- workflowRunId: z25.string(),
7709
- nodeRunId: z25.string(),
7710
- nodeIndex: z25.number(),
7711
- nodeId: z25.string(),
7712
- nodeKey: z25.string(),
7713
- interventionId: z25.string(),
8190
+ var WorkflowInterventionSchema = z27.object({
8191
+ id: z27.string(),
8192
+ projectId: z27.string(),
8193
+ workflowId: z27.string(),
8194
+ workflowRunId: z27.string(),
8195
+ nodeRunId: z27.string(),
8196
+ nodeIndex: z27.number(),
8197
+ nodeId: z27.string(),
8198
+ nodeKey: z27.string(),
8199
+ interventionId: z27.string(),
7714
8200
  input: WorkflowIOSnapshotSchema,
7715
8201
  defaultResponse: WorkflowIOSnapshotSchema,
7716
8202
  status: WorkflowInterventionStatusSchema,
7717
- requestedAt: z25.string(),
7718
- expiresAt: z25.string().optional(),
7719
- submittedAt: z25.string().optional(),
8203
+ requestedAt: z27.string(),
8204
+ expiresAt: z27.string().optional(),
8205
+ submittedAt: z27.string().optional(),
7720
8206
  submittedBy: WorkflowInterventionActorSchema.optional(),
7721
8207
  response: WorkflowIOSnapshotSchema.optional(),
7722
- cancelledAt: z25.string().optional(),
8208
+ cancelledAt: z27.string().optional(),
7723
8209
  cancelledBy: WorkflowInterventionActorSchema.optional(),
7724
- expiredAt: z25.string().optional()
8210
+ expiredAt: z27.string().optional()
7725
8211
  });
7726
- var WorkflowSchema = z25.object({
7727
- id: z25.string(),
8212
+ var WorkflowSchema = z27.object({
8213
+ id: z27.string(),
7728
8214
  input: WorkflowIOSnapshotSchema,
7729
- triggers: z25.array(WorkflowTriggerSchema),
7730
- nodes: z25.array(WorkflowNodeSchema),
8215
+ triggers: z27.array(WorkflowTriggerSchema),
8216
+ nodes: z27.array(WorkflowNodeSchema),
7731
8217
  latestRun: WorkflowRunSummarySchema.nullable()
7732
8218
  });
7733
- var WorkflowRunListResponseSchema = z25.object({
7734
- runs: z25.array(WorkflowRunSummarySchema),
7735
- hasMore: z25.boolean(),
7736
- total: z25.number()
8219
+ var WorkflowRunListResponseSchema = z27.object({
8220
+ runs: z27.array(WorkflowRunSummarySchema),
8221
+ hasMore: z27.boolean(),
8222
+ total: z27.number()
7737
8223
  });
7738
- var WorkflowRunDetailResponseSchema = z25.object({
8224
+ var WorkflowRunDetailResponseSchema = z27.object({
7739
8225
  run: WorkflowRunDetailSchema,
7740
- nodes: z25.array(WorkflowNodeRunSchema)
8226
+ nodes: z27.array(WorkflowNodeRunSchema)
7741
8227
  });
7742
8228
  var CancelWorkflowRunResponseSchema = WorkflowRunDetailResponseSchema;
7743
- var WorkflowInterventionListResponseSchema = z25.object({
7744
- interventions: z25.array(WorkflowInterventionSchema),
7745
- hasMore: z25.boolean(),
7746
- total: z25.number()
8229
+ var WorkflowInterventionListResponseSchema = z27.object({
8230
+ interventions: z27.array(WorkflowInterventionSchema),
8231
+ hasMore: z27.boolean(),
8232
+ total: z27.number()
7747
8233
  });
7748
- var SubmitWorkflowInterventionResponseSchema = z25.object({
8234
+ var SubmitWorkflowInterventionResponseSchema = z27.object({
7749
8235
  intervention: WorkflowInterventionSchema,
7750
- jobId: z25.string()
8236
+ jobId: z27.string()
7751
8237
  });
7752
- var CancelWorkflowInterventionResponseSchema = z25.object({
8238
+ var CancelWorkflowInterventionResponseSchema = z27.object({
7753
8239
  intervention: WorkflowInterventionSchema
7754
8240
  });
7755
- var RequestWorkflowRunResponseSchema = z25.object({
7756
- runId: z25.string(),
7757
- jobId: z25.string(),
7758
- workflowId: z25.string(),
7759
- queuedAt: z25.string()
8241
+ var RequestWorkflowRunResponseSchema = z27.object({
8242
+ runId: z27.string(),
8243
+ jobId: z27.string(),
8244
+ workflowId: z27.string(),
8245
+ queuedAt: z27.string()
7760
8246
  });
7761
8247
 
7762
8248
  // src/routes/workflows.ts
7763
8249
  var WorkflowRunFileContentQuerySchema = FileContentQuerySchema.extend({
7764
- path: z26.string().min(1).regex(/^\/(?:input|output)(?:\/|$)/, "Workflow run file content paths must start with /input/ or /output/")
8250
+ path: z28.string().min(1).regex(/^\/(?:input|output)(?:\/|$)/, "Workflow run file content paths must start with /input/ or /output/")
7765
8251
  });
7766
8252
  var WorkflowNodeFileContentQuerySchema = FileContentQuerySchema.extend({
7767
- path: z26.string().min(1).regex(/^\/(?:input|output)(?:\/|$)/, "Workflow node file content paths must start with /input/ or /output/")
8253
+ path: z28.string().min(1).regex(/^\/(?:input|output)(?:\/|$)/, "Workflow node file content paths must start with /input/ or /output/")
7768
8254
  });
7769
8255
  var WorkflowNodeFileContentParamsSchema = WorkflowRunParamsSchema.extend({
7770
- nodeKey: z26.string().min(1)
8256
+ nodeKey: z28.string().min(1)
7771
8257
  });
7772
8258
  function serializeWorkflowRunSummary(run) {
7773
8259
  return {
@@ -7819,6 +8305,7 @@ function serializeWorkflowAgentExecutionSummary(execution) {
7819
8305
  modelId: execution.modelId,
7820
8306
  finishReason: execution.finishReason,
7821
8307
  usage: execution.usage,
8308
+ cost: execution.cost,
7822
8309
  startedAt: execution.startedAt ? toIsoString(execution.startedAt) : undefined,
7823
8310
  completedAt: execution.completedAt ? toIsoString(execution.completedAt) : undefined
7824
8311
  };
@@ -7830,10 +8317,21 @@ function serializeWorkflowAgentExecution(execution) {
7830
8317
  prompt: execution.prompt,
7831
8318
  trace: execution.trace,
7832
8319
  diagnostics: execution.diagnostics,
8320
+ failurePhase: workflowAgentFailurePhase(execution),
7833
8321
  error: execution.error,
7834
8322
  createdAt: toIsoString(execution.createdAt)
7835
8323
  };
7836
8324
  }
8325
+ function workflowAgentFailurePhase(execution) {
8326
+ const details = execution.error?.details;
8327
+ if (!isRecord(details))
8328
+ return;
8329
+ const phase = details.failurePhase;
8330
+ return phase === "agent-loop" || phase === "structured-finalizer" ? phase : undefined;
8331
+ }
8332
+ function isRecord(value) {
8333
+ return value !== null && typeof value === "object" && !Array.isArray(value);
8334
+ }
7837
8335
  function principalForExecution(sixb) {
7838
8336
  return sixb.execution.requestedBy ?? SYSTEM_PRINCIPAL2;
7839
8337
  }
@@ -8780,6 +9278,7 @@ function registerWorkflowRoutes(app, host) {
8780
9278
  // src/registerRoutes.ts
8781
9279
  function registerHttpRoutes(app, host, options) {
8782
9280
  registerAgentApiGatewayRoutes(app, host);
9281
+ registerAiAccountingRoutes(app, host);
8783
9282
  registerProjectRoutes(app, host);
8784
9283
  registerStatusRoutes(app, host);
8785
9284
  registerConnectorRoutes(app, host);
@@ -8796,6 +9295,7 @@ function registerHttpRoutes(app, host, options) {
8796
9295
  registerFileRoutes(app, host);
8797
9296
  registerActionRunRoutes(app, host);
8798
9297
  registerAgentRoutes(app, host);
9298
+ registerModelRoutes(app, host);
8799
9299
  registerLinkRoutes(app, host);
8800
9300
  registerTelemetryRoutes(app, host);
8801
9301
  registerEventRoutes(app, host);
@@ -8826,275 +9326,405 @@ import {
8826
9326
  } from "@sixb/core/storage";
8827
9327
  import { t } from "elysia";
8828
9328
 
9329
+ // src/auth/experience.ts
9330
+ import { resolve } from "path";
9331
+ var AUTH_BOOTSTRAP_PLACEHOLDER = "__SIXB_AUTH_BOOTSTRAP__";
9332
+ var AUTH_ASSET_PREFIX = "/auth/assets/";
9333
+ async function customAuthExperienceResponse(options, input) {
9334
+ if (!options || input.audience !== (options.audience ?? "app")) {
9335
+ return null;
9336
+ }
9337
+ const template = Bun.file(resolve(options.outdir, "index.html"));
9338
+ if (!await template.exists()) {
9339
+ return null;
9340
+ }
9341
+ const html = await template.text();
9342
+ if (!html.includes(AUTH_BOOTSTRAP_PLACEHOLDER)) {
9343
+ console.warn(`[SixbServer] Custom auth experience in ${options.outdir} is missing its bootstrap placeholder. Using the generic page.`);
9344
+ return null;
9345
+ }
9346
+ const bootstrap = Buffer.from(JSON.stringify({
9347
+ state: input.state,
9348
+ signInUrl: input.signInUrl,
9349
+ ...input.submission ? { submission: input.submission } : {}
9350
+ })).toString("base64url");
9351
+ const formAction = ["'self'", ...(input.formActionOrigins ?? []).map(normalizeCspOrigin)].join(" ");
9352
+ return new Response(html.replace(AUTH_BOOTSTRAP_PLACEHOLDER, bootstrap), {
9353
+ status: input.status ?? 200,
9354
+ headers: {
9355
+ "content-type": "text/html; charset=utf-8",
9356
+ "cache-control": "no-store",
9357
+ "content-security-policy": [
9358
+ "default-src 'none'",
9359
+ "script-src 'self'",
9360
+ "style-src 'self' 'unsafe-inline'",
9361
+ "img-src 'self' data:",
9362
+ "font-src 'self'",
9363
+ "base-uri 'none'",
9364
+ `form-action ${formAction}`,
9365
+ "frame-ancestors 'none'"
9366
+ ].join("; "),
9367
+ "referrer-policy": input.referrerPolicy ?? "no-referrer",
9368
+ "x-content-type-options": "nosniff"
9369
+ }
9370
+ });
9371
+ }
9372
+ function normalizeCspOrigin(value) {
9373
+ let url;
9374
+ try {
9375
+ url = new URL(value);
9376
+ } catch {
9377
+ throw new Error(`[SixbServer] Invalid custom auth form-action origin: '${value}'.`);
9378
+ }
9379
+ if (url.protocol !== "http:" && url.protocol !== "https:" || url.origin !== value) {
9380
+ throw new Error(`[SixbServer] Invalid custom auth form-action origin: '${value}'.`);
9381
+ }
9382
+ return url.origin;
9383
+ }
9384
+ async function customAuthExperienceAssetResponse(options, request) {
9385
+ const method = request.method.toUpperCase();
9386
+ if (!options || method !== "GET" && method !== "HEAD") {
9387
+ return notFoundResponse();
9388
+ }
9389
+ const url = new URL(request.url);
9390
+ if (!url.pathname.startsWith(AUTH_ASSET_PREFIX)) {
9391
+ return notFoundResponse();
9392
+ }
9393
+ let fileName;
9394
+ try {
9395
+ fileName = decodeURIComponent(url.pathname.slice(AUTH_ASSET_PREFIX.length));
9396
+ } catch {
9397
+ return notFoundResponse();
9398
+ }
9399
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(fileName)) {
9400
+ return notFoundResponse();
9401
+ }
9402
+ const path = resolve(options.outdir, "assets", fileName);
9403
+ const source = Bun.file(path);
9404
+ if (!await source.exists()) {
9405
+ return notFoundResponse();
9406
+ }
9407
+ const encoding = await resolvePrecompressedAsset(request, path);
9408
+ const body = encoding ? Bun.file(`${path}.${encoding === "br" ? "br" : "gz"}`) : source;
9409
+ const headers = new Headers({
9410
+ "content-type": source.type || "application/octet-stream",
9411
+ "cache-control": "public, max-age=31536000, immutable",
9412
+ "x-content-type-options": "nosniff"
9413
+ });
9414
+ if (encoding) {
9415
+ headers.set("content-encoding", encoding);
9416
+ headers.set("vary", "Accept-Encoding");
9417
+ }
9418
+ return new Response(method === "HEAD" ? null : body, { headers });
9419
+ }
9420
+ async function resolvePrecompressedAsset(request, sourcePath) {
9421
+ for (const encoding of acceptedPrecompressedEncodings(request)) {
9422
+ const suffix = encoding === "br" ? "br" : "gz";
9423
+ if (await Bun.file(`${sourcePath}.${suffix}`).exists()) {
9424
+ return encoding;
9425
+ }
9426
+ }
9427
+ return null;
9428
+ }
9429
+ function acceptedPrecompressedEncodings(request) {
9430
+ const header = request.headers.get("accept-encoding");
9431
+ if (!header)
9432
+ return [];
9433
+ const qualities = new Map;
9434
+ for (const item of header.split(",")) {
9435
+ const [rawName, ...parameters] = item.trim().split(";");
9436
+ const name = rawName.toLowerCase();
9437
+ let quality = 1;
9438
+ for (const parameter of parameters) {
9439
+ const match = parameter.trim().match(/^q=(0(?:\.\d+)?|1(?:\.0+)?)$/);
9440
+ if (match)
9441
+ quality = Number(match[1]);
9442
+ }
9443
+ qualities.set(name, quality);
9444
+ }
9445
+ const wildcard = qualities.get("*") ?? 0;
9446
+ return ["br", "gzip"].map((encoding, preference) => ({
9447
+ encoding,
9448
+ preference,
9449
+ quality: qualities.get(encoding) ?? wildcard
9450
+ })).filter((candidate) => candidate.quality > 0).sort((left, right) => right.quality - left.quality || left.preference - right.preference).map((candidate) => candidate.encoding);
9451
+ }
9452
+ function notFoundResponse() {
9453
+ return new Response("Not Found", {
9454
+ status: 404,
9455
+ headers: { "content-type": "text/plain; charset=utf-8" }
9456
+ });
9457
+ }
9458
+
8829
9459
  // src/schemas/auth.ts
8830
- import { z as z27 } from "zod";
8831
- var AuthInvitationStatusSchema = z27.enum(["pending", "accepted", "revoked"]);
8832
- var AuthGroupOptionSchema = z27.object({
8833
- id: z27.string(),
8834
- label: z27.string().optional(),
8835
- description: z27.string().optional()
8836
- });
8837
- var AuthInvitationSchema = z27.object({
8838
- id: z27.string(),
8839
- email: z27.string(),
8840
- groupIds: z27.array(z27.string()),
9460
+ import { z as z29 } from "zod";
9461
+ var AuthInvitationStatusSchema = z29.enum(["pending", "accepted", "revoked"]);
9462
+ var AuthGroupOptionSchema = z29.object({
9463
+ id: z29.string(),
9464
+ label: z29.string().optional(),
9465
+ description: z29.string().optional()
9466
+ });
9467
+ var AuthInvitationSchema = z29.object({
9468
+ id: z29.string(),
9469
+ email: z29.string(),
9470
+ groupIds: z29.array(z29.string()),
8841
9471
  status: AuthInvitationStatusSchema,
8842
- createdAt: z27.string(),
8843
- updatedAt: z27.string(),
8844
- expiresAt: z27.string(),
8845
- acceptedAt: z27.string().optional(),
8846
- revokedAt: z27.string().optional()
9472
+ createdAt: z29.string(),
9473
+ updatedAt: z29.string(),
9474
+ expiresAt: z29.string(),
9475
+ acceptedAt: z29.string().optional(),
9476
+ revokedAt: z29.string().optional()
8847
9477
  });
8848
- var AuthInvitationDeliverySchema = z27.object({
8849
- status: z27.enum(["sent", "skipped", "rate_limited", "not_supported"])
9478
+ var AuthInvitationDeliverySchema = z29.object({
9479
+ status: z29.enum(["sent", "skipped", "rate_limited", "not_supported"])
8850
9480
  });
8851
9481
  var AuthInvitationGroupOptionSchema = AuthGroupOptionSchema;
8852
- var AuthAccessTokenKindSchema = z27.enum(["personal", "serviceAccount"]);
8853
- var AuthAccessTokenSubjectTypeSchema = z27.enum(["user", "serviceAccount"]);
8854
- var AuthAccessTokenStatusSchema = z27.enum(["active", "expired", "revoked"]);
8855
- var AuthServiceAccountStatusSchema = z27.enum(["active", "suspended"]);
8856
- var AuthUserStatusSchema = z27.enum(["active", "suspended"]);
8857
- var AuthAccessTokenSchema = z27.object({
8858
- id: z27.string(),
8859
- name: z27.string(),
9482
+ var AuthAccessTokenKindSchema = z29.enum(["personal", "serviceAccount"]);
9483
+ var AuthAccessTokenSubjectTypeSchema = z29.enum(["user", "serviceAccount"]);
9484
+ var AuthAccessTokenStatusSchema = z29.enum(["active", "expired", "revoked"]);
9485
+ var AuthServiceAccountStatusSchema = z29.enum(["active", "suspended"]);
9486
+ var AuthUserStatusSchema = z29.enum(["active", "suspended"]);
9487
+ var AuthAccessTokenSchema = z29.object({
9488
+ id: z29.string(),
9489
+ name: z29.string(),
8860
9490
  kind: AuthAccessTokenKindSchema,
8861
9491
  status: AuthAccessTokenStatusSchema,
8862
9492
  subjectType: AuthAccessTokenSubjectTypeSchema,
8863
- subjectId: z27.string(),
8864
- subjectLabel: z27.string().optional(),
8865
- groupIds: z27.array(z27.string()).optional(),
8866
- createdAt: z27.string(),
8867
- expiresAt: z27.string(),
8868
- revokedAt: z27.string().optional(),
8869
- lastUsedAt: z27.string().optional(),
8870
- lastUsedUserAgent: z27.string().optional(),
8871
- lastUsedIpAddress: z27.string().optional()
8872
- });
8873
- var AuthServiceAccountSchema = z27.object({
8874
- id: z27.string(),
8875
- name: z27.string(),
8876
- description: z27.string().optional(),
9493
+ subjectId: z29.string(),
9494
+ subjectLabel: z29.string().optional(),
9495
+ groupIds: z29.array(z29.string()).optional(),
9496
+ createdAt: z29.string(),
9497
+ expiresAt: z29.string(),
9498
+ revokedAt: z29.string().optional(),
9499
+ lastUsedAt: z29.string().optional(),
9500
+ lastUsedUserAgent: z29.string().optional(),
9501
+ lastUsedIpAddress: z29.string().optional()
9502
+ });
9503
+ var AuthServiceAccountSchema = z29.object({
9504
+ id: z29.string(),
9505
+ name: z29.string(),
9506
+ description: z29.string().optional(),
8877
9507
  status: AuthServiceAccountStatusSchema,
8878
- groupIds: z27.array(z27.string()),
8879
- createdAt: z27.string(),
8880
- updatedAt: z27.string()
8881
- });
8882
- var AuthMemberUserSchema = z27.object({
8883
- id: z27.string(),
8884
- email: z27.string(),
8885
- displayName: z27.string().optional(),
8886
- avatarUrl: z27.string().optional(),
9508
+ groupIds: z29.array(z29.string()),
9509
+ createdAt: z29.string(),
9510
+ updatedAt: z29.string()
9511
+ });
9512
+ var AuthMemberUserSchema = z29.object({
9513
+ id: z29.string(),
9514
+ email: z29.string(),
9515
+ displayName: z29.string().optional(),
9516
+ avatarUrl: z29.string().optional(),
8887
9517
  status: AuthUserStatusSchema,
8888
- createdAt: z27.string(),
8889
- updatedAt: z27.string()
9518
+ createdAt: z29.string(),
9519
+ updatedAt: z29.string()
8890
9520
  });
8891
- var AuthManagedMemberSchema = z27.object({
9521
+ var AuthManagedMemberSchema = z29.object({
8892
9522
  user: AuthMemberUserSchema,
8893
- groupIds: z27.array(z27.string())
9523
+ groupIds: z29.array(z29.string())
8894
9524
  });
8895
- var AuthMemberCapabilitiesSchema = z27.object({
8896
- assignGroups: z27.boolean(),
8897
- suspend: z27.boolean(),
8898
- reactivate: z27.boolean()
9525
+ var AuthMemberCapabilitiesSchema = z29.object({
9526
+ assignGroups: z29.boolean(),
9527
+ suspend: z29.boolean(),
9528
+ reactivate: z29.boolean()
8899
9529
  });
8900
9530
  var AuthMemberSchema = AuthManagedMemberSchema.extend({
8901
9531
  capabilities: AuthMemberCapabilitiesSchema
8902
9532
  });
8903
- var GetAuthAccessManagementOptionsResponseSchema = z27.object({
8904
- groups: z27.array(AuthGroupOptionSchema)
9533
+ var GetAuthAccessManagementOptionsResponseSchema = z29.object({
9534
+ groups: z29.array(AuthGroupOptionSchema)
8905
9535
  });
8906
- var ListAuthAccessTokensResponseSchema = z27.object({
8907
- accessTokens: z27.array(AuthAccessTokenSchema)
9536
+ var ListAuthAccessTokensResponseSchema = z29.object({
9537
+ accessTokens: z29.array(AuthAccessTokenSchema)
8908
9538
  });
8909
- var CreateAuthPersonalAccessTokenBodySchema = z27.object({
8910
- name: z27.string().trim().min(1),
8911
- expiresAt: z27.string().min(1),
8912
- groupIds: z27.array(z27.string().min(1)).optional()
9539
+ var CreateAuthPersonalAccessTokenBodySchema = z29.object({
9540
+ name: z29.string().trim().min(1),
9541
+ expiresAt: z29.string().min(1),
9542
+ groupIds: z29.array(z29.string().min(1)).optional()
8913
9543
  });
8914
- var CreateAuthPersonalAccessTokenResponseSchema = z27.object({
9544
+ var CreateAuthPersonalAccessTokenResponseSchema = z29.object({
8915
9545
  accessToken: AuthAccessTokenSchema,
8916
- tokenValue: z27.string()
9546
+ tokenValue: z29.string()
8917
9547
  });
8918
- var RevokeAuthAccessTokenParamsSchema = z27.object({
8919
- tokenId: z27.string().min(1)
9548
+ var RevokeAuthAccessTokenParamsSchema = z29.object({
9549
+ tokenId: z29.string().min(1)
8920
9550
  });
8921
- var RevokeAuthAccessTokenResponseSchema = z27.object({
9551
+ var RevokeAuthAccessTokenResponseSchema = z29.object({
8922
9552
  accessToken: AuthAccessTokenSchema
8923
9553
  });
8924
- var ListAuthServiceAccountsResponseSchema = z27.object({
8925
- serviceAccounts: z27.array(AuthServiceAccountSchema)
9554
+ var ListAuthServiceAccountsResponseSchema = z29.object({
9555
+ serviceAccounts: z29.array(AuthServiceAccountSchema)
8926
9556
  });
8927
- var CreateAuthServiceAccountBodySchema = z27.object({
8928
- id: z27.string().trim().min(1).optional(),
8929
- name: z27.string().trim().min(1),
8930
- description: z27.string().trim().optional(),
8931
- groupIds: z27.array(z27.string().min(1)).optional()
9557
+ var CreateAuthServiceAccountBodySchema = z29.object({
9558
+ id: z29.string().trim().min(1).optional(),
9559
+ name: z29.string().trim().min(1),
9560
+ description: z29.string().trim().optional(),
9561
+ groupIds: z29.array(z29.string().min(1)).optional()
8932
9562
  });
8933
- var CreateAuthServiceAccountResponseSchema = z27.object({
9563
+ var CreateAuthServiceAccountResponseSchema = z29.object({
8934
9564
  serviceAccount: AuthServiceAccountSchema
8935
9565
  });
8936
- var AuthServiceAccountParamsSchema = z27.object({
8937
- serviceAccountId: z27.string().min(1)
9566
+ var AuthServiceAccountParamsSchema = z29.object({
9567
+ serviceAccountId: z29.string().min(1)
8938
9568
  });
8939
- var DisableAuthServiceAccountResponseSchema = z27.object({
9569
+ var DisableAuthServiceAccountResponseSchema = z29.object({
8940
9570
  serviceAccount: AuthServiceAccountSchema
8941
9571
  });
8942
- var ListAuthServiceAccountAccessTokensResponseSchema = z27.object({
8943
- accessTokens: z27.array(AuthAccessTokenSchema)
9572
+ var ListAuthServiceAccountAccessTokensResponseSchema = z29.object({
9573
+ accessTokens: z29.array(AuthAccessTokenSchema)
8944
9574
  });
8945
- var CreateAuthServiceAccountAccessTokenBodySchema = z27.object({
8946
- name: z27.string().trim().min(1),
8947
- expiresAt: z27.string().min(1),
8948
- groupIds: z27.array(z27.string().min(1)).optional()
9575
+ var CreateAuthServiceAccountAccessTokenBodySchema = z29.object({
9576
+ name: z29.string().trim().min(1),
9577
+ expiresAt: z29.string().min(1),
9578
+ groupIds: z29.array(z29.string().min(1)).optional()
8949
9579
  });
8950
- var CreateAuthServiceAccountAccessTokenResponseSchema = z27.object({
9580
+ var CreateAuthServiceAccountAccessTokenResponseSchema = z29.object({
8951
9581
  accessToken: AuthAccessTokenSchema,
8952
- tokenValue: z27.string()
9582
+ tokenValue: z29.string()
8953
9583
  });
8954
9584
  var RevokeAuthServiceAccountAccessTokenParamsSchema = AuthServiceAccountParamsSchema.extend({
8955
- tokenId: z27.string().min(1)
9585
+ tokenId: z29.string().min(1)
8956
9586
  });
8957
- var RevokeAuthServiceAccountAccessTokenResponseSchema = z27.object({
9587
+ var RevokeAuthServiceAccountAccessTokenResponseSchema = z29.object({
8958
9588
  accessToken: AuthAccessTokenSchema
8959
9589
  });
8960
- var AuthCreateInvitationCapabilitySchema = z27.union([
8961
- z27.object({
8962
- state: z27.literal("enabled")
9590
+ var AuthCreateInvitationCapabilitySchema = z29.union([
9591
+ z29.object({
9592
+ state: z29.literal("enabled")
8963
9593
  }),
8964
- z27.object({
8965
- state: z27.literal("disabled"),
8966
- reason: z27.enum(["missing_membership_policy", "invitation_delivery_not_supported"])
9594
+ z29.object({
9595
+ state: z29.literal("disabled"),
9596
+ reason: z29.enum(["missing_membership_policy", "invitation_delivery_not_supported"])
8967
9597
  })
8968
9598
  ]);
8969
- var AuthInvitationDestinationSchema = z27.object({
8970
- id: z27.enum(["atlas", "app"]),
8971
- label: z27.string()
8972
- });
8973
- var GetAuthInvitationOptionsResponseSchema = z27.object({
8974
- groups: z27.array(AuthInvitationGroupOptionSchema),
8975
- destinations: z27.array(AuthInvitationDestinationSchema),
8976
- defaultDestinationId: z27.enum(["atlas", "app"]).optional(),
8977
- canInviteWithoutGroups: z27.boolean(),
8978
- capabilities: z27.object({
9599
+ var AuthInvitationDestinationSchema = z29.object({
9600
+ id: z29.enum(["atlas", "app"]),
9601
+ label: z29.string()
9602
+ });
9603
+ var GetAuthInvitationOptionsResponseSchema = z29.object({
9604
+ groups: z29.array(AuthInvitationGroupOptionSchema),
9605
+ destinations: z29.array(AuthInvitationDestinationSchema),
9606
+ defaultDestinationId: z29.enum(["atlas", "app"]).optional(),
9607
+ canInviteWithoutGroups: z29.boolean(),
9608
+ capabilities: z29.object({
8979
9609
  createInvitation: AuthCreateInvitationCapabilitySchema
8980
9610
  })
8981
9611
  });
8982
- var GetAuthMembershipOptionsResponseSchema = z27.object({
8983
- groups: z27.array(AuthGroupOptionSchema),
8984
- capabilities: z27.object({
8985
- invite: z27.boolean(),
8986
- assignGroups: z27.boolean(),
8987
- suspend: z27.boolean()
9612
+ var GetAuthMembershipOptionsResponseSchema = z29.object({
9613
+ groups: z29.array(AuthGroupOptionSchema),
9614
+ capabilities: z29.object({
9615
+ invite: z29.boolean(),
9616
+ assignGroups: z29.boolean(),
9617
+ suspend: z29.boolean()
8988
9618
  })
8989
9619
  });
8990
- var ListAuthMembersQuerySchema = z27.object({
8991
- limit: z27.string().optional(),
8992
- offset: z27.string().optional(),
8993
- order: z27.enum(["asc", "desc"]).optional()
9620
+ var ListAuthMembersQuerySchema = z29.object({
9621
+ limit: z29.string().optional(),
9622
+ offset: z29.string().optional(),
9623
+ order: z29.enum(["asc", "desc"]).optional()
8994
9624
  });
8995
- var ListAuthMembersResponseSchema = z27.object({
8996
- members: z27.array(AuthMemberSchema),
8997
- hasMore: z27.boolean(),
8998
- total: z27.number()
9625
+ var ListAuthMembersResponseSchema = z29.object({
9626
+ members: z29.array(AuthMemberSchema),
9627
+ hasMore: z29.boolean(),
9628
+ total: z29.number()
8999
9629
  });
9000
- var AuthMemberParamsSchema = z27.object({
9001
- userId: z27.string().min(1)
9630
+ var AuthMemberParamsSchema = z29.object({
9631
+ userId: z29.string().min(1)
9002
9632
  });
9003
- var UpdateAuthMemberGroupsBodySchema = z27.object({
9004
- groupIds: z27.array(z27.string().min(1))
9633
+ var UpdateAuthMemberGroupsBodySchema = z29.object({
9634
+ groupIds: z29.array(z29.string().min(1))
9005
9635
  });
9006
- var UpdateAuthMemberGroupsResponseSchema = z27.object({
9636
+ var UpdateAuthMemberGroupsResponseSchema = z29.object({
9007
9637
  member: AuthManagedMemberSchema
9008
9638
  });
9009
- var SuspendAuthMemberResponseSchema = z27.object({
9639
+ var SuspendAuthMemberResponseSchema = z29.object({
9010
9640
  member: AuthManagedMemberSchema
9011
9641
  });
9012
- var ReactivateAuthMemberResponseSchema = z27.object({
9642
+ var ReactivateAuthMemberResponseSchema = z29.object({
9013
9643
  member: AuthManagedMemberSchema
9014
9644
  });
9015
- var CreateAuthInvitationBodySchema = z27.object({
9016
- email: z27.string().min(1),
9017
- groupIds: z27.array(z27.string().min(1)).optional(),
9018
- destinationId: z27.enum(["atlas", "app"]).optional(),
9019
- expiresAt: z27.string().optional(),
9020
- returnTo: z27.string().optional()
9645
+ var CreateAuthInvitationBodySchema = z29.object({
9646
+ email: z29.string().min(1),
9647
+ groupIds: z29.array(z29.string().min(1)).optional(),
9648
+ destinationId: z29.enum(["atlas", "app"]).optional(),
9649
+ expiresAt: z29.string().optional(),
9650
+ returnTo: z29.string().optional()
9021
9651
  });
9022
- var CreateAuthInvitationResponseSchema = z27.object({
9652
+ var CreateAuthInvitationResponseSchema = z29.object({
9023
9653
  invitation: AuthInvitationSchema,
9024
9654
  delivery: AuthInvitationDeliverySchema
9025
9655
  });
9026
- var ListAuthInvitationsQuerySchema = z27.object({
9027
- email: z27.string().optional(),
9656
+ var ListAuthInvitationsQuerySchema = z29.object({
9657
+ email: z29.string().optional(),
9028
9658
  status: AuthInvitationStatusSchema.optional(),
9029
- limit: z27.string().optional(),
9030
- offset: z27.string().optional(),
9031
- order: z27.enum(["asc", "desc"]).optional()
9659
+ limit: z29.string().optional(),
9660
+ offset: z29.string().optional(),
9661
+ order: z29.enum(["asc", "desc"]).optional()
9032
9662
  });
9033
- var ListAuthInvitationsResponseSchema = z27.object({
9034
- invitations: z27.array(AuthInvitationSchema),
9035
- hasMore: z27.boolean(),
9036
- total: z27.number()
9663
+ var ListAuthInvitationsResponseSchema = z29.object({
9664
+ invitations: z29.array(AuthInvitationSchema),
9665
+ hasMore: z29.boolean(),
9666
+ total: z29.number()
9037
9667
  });
9038
- var RevokeAuthInvitationParamsSchema = z27.object({
9039
- invitationId: z27.string().min(1)
9668
+ var RevokeAuthInvitationParamsSchema = z29.object({
9669
+ invitationId: z29.string().min(1)
9040
9670
  });
9041
- var RevokeAuthInvitationResponseSchema = z27.object({
9671
+ var RevokeAuthInvitationResponseSchema = z29.object({
9042
9672
  invitation: AuthInvitationSchema
9043
9673
  });
9044
- var AuthSessionResponseSchema = z27.union([
9045
- z27.object({
9046
- authenticated: z27.literal(false)
9674
+ var AuthSessionResponseSchema = z29.union([
9675
+ z29.object({
9676
+ authenticated: z29.literal(false)
9047
9677
  }),
9048
- z27.object({
9049
- authenticated: z27.literal(true),
9050
- csrfToken: z27.string(),
9051
- applicationAccess: z27.object({
9052
- allowed: z27.boolean(),
9053
- audience: z27.enum(["atlas", "app"])
9678
+ z29.object({
9679
+ authenticated: z29.literal(true),
9680
+ csrfToken: z29.string(),
9681
+ applicationAccess: z29.object({
9682
+ allowed: z29.boolean(),
9683
+ audience: z29.enum(["atlas", "app"])
9054
9684
  }),
9055
- user: z27.object({
9056
- id: z27.string(),
9057
- email: z27.string(),
9058
- displayName: z27.string().optional(),
9059
- avatarUrl: z27.string().optional(),
9060
- groupIds: z27.array(z27.string())
9685
+ user: z29.object({
9686
+ id: z29.string(),
9687
+ email: z29.string(),
9688
+ displayName: z29.string().optional(),
9689
+ avatarUrl: z29.string().optional(),
9690
+ groupIds: z29.array(z29.string())
9061
9691
  }),
9062
- session: z27.object({
9063
- id: z27.string(),
9064
- expiresAt: z27.string()
9692
+ session: z29.object({
9693
+ id: z29.string(),
9694
+ expiresAt: z29.string()
9065
9695
  })
9066
9696
  })
9067
9697
  ]);
9068
- var AuthSignOutResponseSchema = z27.object({
9069
- success: z27.boolean()
9698
+ var AuthSignOutResponseSchema = z29.object({
9699
+ success: z29.boolean()
9070
9700
  });
9071
- var AuthSessionSummarySchema = z27.object({
9072
- id: z27.string(),
9073
- audience: z27.enum(["atlas", "app"]),
9074
- current: z27.boolean(),
9075
- createdAt: z27.string(),
9076
- expiresAt: z27.string(),
9077
- lastSeenAt: z27.string().optional(),
9078
- userAgent: z27.string().optional(),
9079
- ipAddress: z27.string().optional()
9701
+ var AuthSessionSummarySchema = z29.object({
9702
+ id: z29.string(),
9703
+ audience: z29.enum(["atlas", "app"]),
9704
+ current: z29.boolean(),
9705
+ createdAt: z29.string(),
9706
+ expiresAt: z29.string(),
9707
+ lastSeenAt: z29.string().optional(),
9708
+ userAgent: z29.string().optional(),
9709
+ ipAddress: z29.string().optional()
9080
9710
  });
9081
- var ListAuthSessionsResponseSchema = z27.object({
9082
- sessions: z27.array(AuthSessionSummarySchema)
9711
+ var ListAuthSessionsResponseSchema = z29.object({
9712
+ sessions: z29.array(AuthSessionSummarySchema)
9083
9713
  });
9084
- var RevokeAuthSessionParamsSchema = z27.object({
9085
- sessionId: z27.string().min(1)
9714
+ var RevokeAuthSessionParamsSchema = z29.object({
9715
+ sessionId: z29.string().min(1)
9086
9716
  });
9087
- var RevokeAuthSessionResponseSchema = z27.object({
9088
- success: z27.boolean()
9717
+ var RevokeAuthSessionResponseSchema = z29.object({
9718
+ success: z29.boolean()
9089
9719
  });
9090
- var SignOutAllResponseSchema = z27.object({
9091
- success: z27.boolean(),
9092
- revokedCount: z27.number()
9720
+ var SignOutAllResponseSchema = z29.object({
9721
+ success: z29.boolean(),
9722
+ revokedCount: z29.number()
9093
9723
  });
9094
9724
 
9095
9725
  // src/routes/auth.ts
9096
9726
  function registerAuthRoutes(app, host, options) {
9097
- return app.get("/api/auth/session", async ({ request }) => {
9727
+ return app.get("/auth/assets/*", async ({ request }) => customAuthExperienceAssetResponse(options.authExperience, request), { detail: { hide: true } }).head("/auth/assets/*", async ({ request }) => customAuthExperienceAssetResponse(options.authExperience, request), { detail: { hide: true } }).get("/api/auth/session", async ({ request }) => {
9098
9728
  const authOptions = resolveAuthOptions(options, request);
9099
9729
  let session = await host.auth.getSession(request, authOptions);
9100
9730
  if (!session.authenticated) {
@@ -9888,7 +10518,7 @@ function registerAuthRoutes(app, host, options) {
9888
10518
  requestOrigin: authRedirect.requestOrigin,
9889
10519
  requesterHash: pending.hash
9890
10520
  });
9891
- const response = htmlMessageResponse("If this email can sign in, we sent a link. Check your inbox to continue.", 200, "Check your email");
10521
+ const response = await magicLinkRequestedResponse(options, authRedirect);
9892
10522
  const existingPending = getCookie3(request, MAGIC_LINK_PENDING_COOKIE_NAME)?.trim();
9893
10523
  response.headers.append("set-cookie", magicLinkPendingCookieHeader({
9894
10524
  request,
@@ -9928,7 +10558,7 @@ function registerAuthRoutes(app, host, options) {
9928
10558
  return authRedirect;
9929
10559
  }
9930
10560
  if (isMagicLinkAuthStrategy(strategy)) {
9931
- return signInFormResponse(authRedirect);
10561
+ return await signInFormResponse(options, authRedirect);
9932
10562
  }
9933
10563
  if (isOidcAuthStrategy(strategy)) {
9934
10564
  const result = await strategy.startOidcSignIn({
@@ -9947,8 +10577,9 @@ function registerAuthRoutes(app, host, options) {
9947
10577
  const url = new URL(request.url);
9948
10578
  const magicLinkId = url.searchParams.get("magicLinkId")?.trim();
9949
10579
  const token = url.searchParams.get("token")?.trim();
10580
+ const authRedirectHint = resolveAuthExperienceRedirectHint(options, request, url.searchParams.get("audience"));
9950
10581
  if (!magicLinkId || !token) {
9951
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10582
+ return await invalidMagicLinkResponse(options, authRedirectHint);
9952
10583
  }
9953
10584
  let email;
9954
10585
  if (strategy.peekMagicLink) {
@@ -9960,11 +10591,12 @@ function registerAuthRoutes(app, host, options) {
9960
10591
  token
9961
10592
  });
9962
10593
  if (!peeked) {
9963
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10594
+ return await invalidMagicLinkResponse(options, authRedirectHint);
9964
10595
  }
9965
10596
  email = peeked.email;
9966
- } catch {
9967
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10597
+ } catch (error) {
10598
+ logAuthCallbackError("Magic-link", error);
10599
+ return await authExperienceErrorResponse(options, authRedirectHint);
9968
10600
  }
9969
10601
  }
9970
10602
  const requesterHash = url.searchParams.get("requester")?.trim();
@@ -9977,10 +10609,16 @@ function registerAuthRoutes(app, host, options) {
9977
10609
  request,
9978
10610
  magicLinkId,
9979
10611
  token,
9980
- clearPendingCookie: true
10612
+ clearPendingCookie: true,
10613
+ authRedirectHint
9981
10614
  });
9982
10615
  }
9983
- return magicLinkConfirmResponse({ magicLinkId, token, email });
10616
+ return await magicLinkConfirmResponse(options, {
10617
+ magicLinkId,
10618
+ token,
10619
+ email,
10620
+ authRedirect: authRedirectHint
10621
+ });
9984
10622
  }
9985
10623
  if (isOidcAuthStrategy(strategy)) {
9986
10624
  const now = new Date;
@@ -10024,14 +10662,24 @@ function registerAuthRoutes(app, host, options) {
10024
10662
  }
10025
10663
  const magicLinkId = body.magicLinkId?.trim();
10026
10664
  const token = body.token?.trim();
10665
+ const authRedirectHint = resolveAuthExperienceRedirectHint(options, request, body.audience);
10027
10666
  if (!magicLinkId || !token) {
10028
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10667
+ return await invalidMagicLinkResponse(options, authRedirectHint);
10029
10668
  }
10030
- return completeMagicLinkCallback({ host, strategy, options, request, magicLinkId, token });
10669
+ return completeMagicLinkCallback({
10670
+ host,
10671
+ strategy,
10672
+ options,
10673
+ request,
10674
+ magicLinkId,
10675
+ token,
10676
+ authRedirectHint
10677
+ });
10031
10678
  }, {
10032
10679
  body: t.Object({
10033
10680
  magicLinkId: t.Optional(t.String()),
10034
- token: t.Optional(t.String())
10681
+ token: t.Optional(t.String()),
10682
+ audience: t.Optional(t.String())
10035
10683
  }),
10036
10684
  parse: "urlencoded",
10037
10685
  detail: { hide: true }
@@ -10106,7 +10754,7 @@ async function completeMagicLinkCallback(input) {
10106
10754
  }
10107
10755
  return response;
10108
10756
  } catch {
10109
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10757
+ return await invalidMagicLinkResponse(input.options, input.authRedirectHint);
10110
10758
  }
10111
10759
  }
10112
10760
  function resolveSessionDevice(request) {
@@ -10377,8 +11025,18 @@ function authPageResponse(body, status = 200) {
10377
11025
  }
10378
11026
  });
10379
11027
  }
10380
- function signInFormResponse(context) {
10381
- return authPageResponse([
11028
+ async function signInFormResponse(options, context) {
11029
+ return await customAuthExperienceResponse(options.authExperience, {
11030
+ audience: context.audience,
11031
+ state: { kind: "signIn" },
11032
+ signInUrl: authExperienceSignInUrl(context),
11033
+ submission: {
11034
+ kind: "requestMagicLink",
11035
+ action: "/auth/sign-in",
11036
+ fields: { audience: context.audience, returnTo: context.returnTo }
11037
+ },
11038
+ referrerPolicy: "same-origin"
11039
+ }) ?? authPageResponse([
10382
11040
  "<h1>Sign in</h1>",
10383
11041
  "<p>We'll email you a sign-in link.</p>",
10384
11042
  '<form method="post" action="/auth/sign-in">',
@@ -10389,13 +11047,80 @@ function signInFormResponse(context) {
10389
11047
  "</form>"
10390
11048
  ].join(""));
10391
11049
  }
10392
- function magicLinkConfirmResponse(input) {
11050
+ async function magicLinkRequestedResponse(options, context) {
11051
+ return await customAuthExperienceResponse(options.authExperience, {
11052
+ audience: context.audience,
11053
+ state: { kind: "checkEmail" },
11054
+ signInUrl: authExperienceSignInUrl(context)
11055
+ }) ?? htmlMessageResponse("If this email can sign in, we sent a link. Check your inbox to continue.", 200, "Check your email");
11056
+ }
11057
+ async function invalidMagicLinkResponse(options, context) {
11058
+ if (context) {
11059
+ const custom = await customAuthExperienceResponse(options.authExperience, {
11060
+ audience: context.audience,
11061
+ state: { kind: "invalidLink" },
11062
+ signInUrl: authExperienceSignInUrl(context),
11063
+ status: 400
11064
+ });
11065
+ if (custom)
11066
+ return custom;
11067
+ }
11068
+ return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
11069
+ }
11070
+ async function authExperienceErrorResponse(options, context) {
11071
+ if (context) {
11072
+ const custom = await customAuthExperienceResponse(options.authExperience, {
11073
+ audience: context.audience,
11074
+ state: { kind: "error" },
11075
+ signInUrl: authExperienceSignInUrl(context),
11076
+ status: 500
11077
+ });
11078
+ if (custom)
11079
+ return custom;
11080
+ }
11081
+ return await invalidMagicLinkResponse(options, undefined);
11082
+ }
11083
+ function authExperienceSignInUrl(context) {
11084
+ const params = new URLSearchParams({ audience: context.audience, returnTo: context.returnTo });
11085
+ return `/auth/sign-in?${params.toString()}`;
11086
+ }
11087
+ function resolveAuthExperienceRedirectHint(options, request, audience) {
11088
+ if (audience !== "app" && audience !== "atlas") {
11089
+ return;
11090
+ }
11091
+ const context = resolveInvitationDeliveryContext(options, request, { destinationId: audience });
11092
+ return context instanceof Response ? undefined : context;
11093
+ }
11094
+ async function magicLinkConfirmResponse(options, input) {
11095
+ if (input.authRedirect) {
11096
+ const custom = await customAuthExperienceResponse(options.authExperience, {
11097
+ audience: input.authRedirect.audience,
11098
+ state: { kind: "confirm", ...input.email ? { email: input.email } : {} },
11099
+ signInUrl: authExperienceSignInUrl(input.authRedirect),
11100
+ submission: {
11101
+ kind: "confirmSignIn",
11102
+ action: "/auth/callback",
11103
+ fields: {
11104
+ magicLinkId: input.magicLinkId,
11105
+ token: input.token,
11106
+ audience: input.authRedirect.audience
11107
+ }
11108
+ },
11109
+ referrerPolicy: "same-origin",
11110
+ formActionOrigins: [new URL(input.authRedirect.returnTo).origin]
11111
+ });
11112
+ if (custom)
11113
+ return custom;
11114
+ }
10393
11115
  const response = authPageResponse([
10394
11116
  "<h1>Sign in</h1>",
10395
11117
  input.email ? `<p>You're signing in as <strong>${escapeHtml(input.email)}</strong>.</p>` : "<p>Click continue to finish signing in.</p>",
10396
11118
  '<form method="post" action="/auth/callback" id="confirm">',
10397
11119
  `<input type="hidden" name="magicLinkId" value="${escapeHtml(input.magicLinkId)}">`,
10398
11120
  `<input type="hidden" name="token" value="${escapeHtml(input.token)}">`,
11121
+ ...input.authRedirect ? [
11122
+ `<input type="hidden" name="audience" value="${escapeHtml(input.authRedirect.audience)}">`
11123
+ ] : [],
10399
11124
  '<button type="submit" id="confirm-button">Continue</button>',
10400
11125
  "</form>",
10401
11126
  "<script>",
@@ -10876,7 +11601,7 @@ import {
10876
11601
  isAgentRunActivityEvent
10877
11602
  } from "@sixb/core/agents/streams";
10878
11603
  import { BrokerCursorExpiredError } from "@sixb/core/broker";
10879
- import { z as z28 } from "zod";
11604
+ import { z as z30 } from "zod";
10880
11605
 
10881
11606
  // src/utils/ws.ts
10882
11607
  function safeSend(target, payload) {
@@ -10924,25 +11649,25 @@ async function decodeWsMessage(message) {
10924
11649
  }
10925
11650
 
10926
11651
  // src/routes/ws/agents.ts
10927
- var SubscribeSchema = z28.object({
10928
- type: z28.literal("subscribe"),
10929
- runId: z28.string().min(1),
10930
- afterCursor: z28.string().min(1).optional()
11652
+ var SubscribeSchema = z30.object({
11653
+ type: z30.literal("subscribe"),
11654
+ runId: z30.string().min(1),
11655
+ afterCursor: z30.string().min(1).optional()
10931
11656
  });
10932
- var SubscribeActivitySchema = z28.object({
10933
- type: z28.literal("subscribe.activity")
11657
+ var SubscribeActivitySchema = z30.object({
11658
+ type: z30.literal("subscribe.activity")
10934
11659
  });
10935
- var ReplaySchema = z28.object({
10936
- type: z28.literal("replay"),
10937
- runId: z28.string().min(1),
10938
- afterCursor: z28.string().min(1).optional(),
10939
- limit: z28.number().int().positive().max(500).optional()
11660
+ var ReplaySchema = z30.object({
11661
+ type: z30.literal("replay"),
11662
+ runId: z30.string().min(1),
11663
+ afterCursor: z30.string().min(1).optional(),
11664
+ limit: z30.number().int().positive().max(500).optional()
10940
11665
  });
10941
- var UnsubscribeSchema = z28.object({
10942
- type: z28.literal("unsubscribe"),
10943
- runId: z28.string().min(1).optional()
11666
+ var UnsubscribeSchema = z30.object({
11667
+ type: z30.literal("unsubscribe"),
11668
+ runId: z30.string().min(1).optional()
10944
11669
  });
10945
- var AgentStreamMessageSchema = z28.union([
11670
+ var AgentStreamMessageSchema = z30.union([
10946
11671
  SubscribeSchema,
10947
11672
  SubscribeActivitySchema,
10948
11673
  ReplaySchema,
@@ -11228,22 +11953,22 @@ function errorMessage(error) {
11228
11953
 
11229
11954
  // src/routes/ws/events.ts
11230
11955
  import { scopeKeysForEvent } from "@sixb/core/events/scope";
11231
- import { z as z29 } from "zod";
11232
- var SubscribeSchema2 = z29.object({
11233
- type: z29.literal("subscribe"),
11234
- topic: z29.enum(EVENT_TOPICS).optional(),
11235
- types: z29.array(z29.enum(EVENT_TYPES)).optional(),
11236
- objectTypeId: z29.string().optional(),
11237
- primaryId: z29.string().optional(),
11238
- actionId: z29.string().optional(),
11239
- runId: z29.string().optional(),
11240
- afterCursor: z29.string().optional(),
11241
- limit: z29.number().int().positive().max(500).optional()
11242
- });
11243
- var UnsubscribeSchema2 = z29.object({
11244
- type: z29.literal("unsubscribe")
11245
- });
11246
- var SubscriptionMessageSchema = z29.union([SubscribeSchema2, UnsubscribeSchema2]);
11956
+ import { z as z31 } from "zod";
11957
+ var SubscribeSchema2 = z31.object({
11958
+ type: z31.literal("subscribe"),
11959
+ topic: z31.enum(EVENT_TOPICS).optional(),
11960
+ types: z31.array(z31.enum(EVENT_TYPES)).optional(),
11961
+ objectTypeId: z31.string().optional(),
11962
+ primaryId: z31.string().optional(),
11963
+ actionId: z31.string().optional(),
11964
+ runId: z31.string().optional(),
11965
+ afterCursor: z31.string().optional(),
11966
+ limit: z31.number().int().positive().max(500).optional()
11967
+ });
11968
+ var UnsubscribeSchema2 = z31.object({
11969
+ type: z31.literal("unsubscribe")
11970
+ });
11971
+ var SubscriptionMessageSchema = z31.union([SubscribeSchema2, UnsubscribeSchema2]);
11247
11972
  function parseSubscriptionMessage(payload) {
11248
11973
  if (!payload || typeof payload !== "object") {
11249
11974
  return { ok: false, error: "Message must be a JSON object." };
@@ -11433,7 +12158,7 @@ function eventMatchesScope(event, filter) {
11433
12158
  }
11434
12159
 
11435
12160
  // src/routes/ws/logs.ts
11436
- import { z as z30 } from "zod";
12161
+ import { z as z32 } from "zod";
11437
12162
 
11438
12163
  // src/routes/ws/log-subscription-hub.ts
11439
12164
  import { BrokerCursorExpiredError as BrokerCursorExpiredError2 } from "@sixb/core/broker";
@@ -11683,13 +12408,13 @@ class LogSubscriptionHub {
11683
12408
  this.scheduleFlush(state);
11684
12409
  }
11685
12410
  waitForQueueProgress(state) {
11686
- return new Promise((resolve) => state.queueProgressWaiters.add(resolve));
12411
+ return new Promise((resolve2) => state.queueProgressWaiters.add(resolve2));
11687
12412
  }
11688
12413
  notifyQueueProgress(state) {
11689
12414
  const waiters = [...state.queueProgressWaiters];
11690
12415
  state.queueProgressWaiters.clear();
11691
- for (const resolve of waiters)
11692
- resolve();
12416
+ for (const resolve2 of waiters)
12417
+ resolve2();
11693
12418
  }
11694
12419
  send(state, payload) {
11695
12420
  if (state.closed)
@@ -11746,26 +12471,26 @@ function socketBufferedAmount(ws) {
11746
12471
  }
11747
12472
 
11748
12473
  // src/routes/ws/logs.ts
11749
- var SubscribeSchema3 = z30.object({
11750
- type: z30.literal("subscribe"),
11751
- kinds: z30.array(z30.enum(SIXB_RUN_KINDS)).min(1).optional(),
11752
- levels: z30.array(z30.enum(LOG_LEVELS)).min(1).optional(),
11753
- run: z30.object({
11754
- kind: z30.enum(SIXB_RUN_KINDS),
12474
+ var SubscribeSchema3 = z32.object({
12475
+ type: z32.literal("subscribe"),
12476
+ kinds: z32.array(z32.enum(SIXB_RUN_KINDS)).min(1).optional(),
12477
+ levels: z32.array(z32.enum(LOG_LEVELS)).min(1).optional(),
12478
+ run: z32.object({
12479
+ kind: z32.enum(SIXB_RUN_KINDS),
11755
12480
  id: LogRunIdSchema
11756
12481
  }).optional(),
11757
- afterCursor: z30.string().optional()
12482
+ afterCursor: z32.string().optional()
11758
12483
  }).superRefine((value, context) => {
11759
12484
  if (value.run && value.kinds && !value.kinds.includes(value.run.kind)) {
11760
12485
  context.addIssue({
11761
- code: z30.ZodIssueCode.custom,
12486
+ code: z32.ZodIssueCode.custom,
11762
12487
  path: ["run"],
11763
12488
  message: "run.kind must be included in kinds"
11764
12489
  });
11765
12490
  }
11766
12491
  });
11767
- var UnsubscribeSchema3 = z30.object({ type: z30.literal("unsubscribe") });
11768
- var SubscriptionMessageSchema2 = z30.union([SubscribeSchema3, UnsubscribeSchema3]);
12492
+ var UnsubscribeSchema3 = z32.object({ type: z32.literal("unsubscribe") });
12493
+ var SubscriptionMessageSchema2 = z32.union([SubscribeSchema3, UnsubscribeSchema3]);
11769
12494
  function parseLogSubscriptionMessage(payload) {
11770
12495
  if (!payload || typeof payload !== "object") {
11771
12496
  return { ok: false, error: "Message must be a JSON object." };
@@ -11866,6 +12591,7 @@ class SixbServer {
11866
12591
  apiBrowserPolicy;
11867
12592
  authContextResolver;
11868
12593
  authRedirectContextResolver;
12594
+ authExperience;
11869
12595
  app = null;
11870
12596
  bunServer = null;
11871
12597
  maintenance = null;
@@ -11877,6 +12603,7 @@ class SixbServer {
11877
12603
  this.apiBrowserPolicy = resolveApiBrowserPolicy(options.browser);
11878
12604
  this.authContextResolver = createApiBrowserAuthContextResolver(this.apiBrowserPolicy);
11879
12605
  this.authRedirectContextResolver = createApiBrowserAuthRedirectContextResolver(this.apiBrowserPolicy);
12606
+ this.authExperience = options.authExperience;
11880
12607
  }
11881
12608
  getHost() {
11882
12609
  return this.hostRuntime;
@@ -11902,6 +12629,9 @@ class SixbServer {
11902
12629
  getApiBrowserPolicy() {
11903
12630
  return this.apiBrowserPolicy;
11904
12631
  }
12632
+ getAuthExperience() {
12633
+ return this.authExperience;
12634
+ }
11905
12635
  async start() {
11906
12636
  if (this.app !== null || this.bunServer !== null || this.maintenance !== null) {
11907
12637
  throw new Error("[SixbServer] Server is already running.");
@@ -12051,6 +12781,7 @@ function createSixbApi(server) {
12051
12781
  resolveAuthRedirectContext: (request, input) => server.resolveAuthRedirectContext(request, input),
12052
12782
  getInvitationDestinationOptions: (request) => server.getInvitationDestinationOptions(request),
12053
12783
  resolveAuthRequestOrigin: (request) => server.resolveAuthRequestOrigin(request),
12784
+ authExperience: server.getAuthExperience(),
12054
12785
  resolveInvitationRedirectContext: (request, input) => server.resolveInvitationRedirectContext(request, input)
12055
12786
  });
12056
12787
  registerHttpRoutes(app, host, {
@@ -12142,4 +12873,4 @@ export {
12142
12873
  SixbServer
12143
12874
  };
12144
12875
 
12145
- //# debugId=3097F504C06B251564756E2164756E21
12876
+ //# debugId=7EBA739DF50836F764756E2164756E21