@sixb/server 0.1.2 → 0.1.3

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 (72) hide show
  1. package/dist/auth/experience.d.ts +33 -0
  2. package/dist/auth/experience.d.ts.map +1 -0
  3. package/dist/auth/public-routes.d.ts.map +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1891 -1337
  7. package/dist/index.js.map +17 -14
  8. package/dist/openapi/tags.d.ts +6 -2
  9. package/dist/openapi/tags.d.ts.map +1 -1
  10. package/dist/registerRoutes.d.ts.map +1 -1
  11. package/dist/routes/action-runs.d.ts +6 -6
  12. package/dist/routes/actions.d.ts +3 -3
  13. package/dist/routes/agents.d.ts +149 -77
  14. package/dist/routes/agents.d.ts.map +1 -1
  15. package/dist/routes/ai-accounting.d.ts +31 -0
  16. package/dist/routes/ai-accounting.d.ts.map +1 -0
  17. package/dist/routes/auth.d.ts +110 -53
  18. package/dist/routes/auth.d.ts.map +1 -1
  19. package/dist/routes/connector-connection-runs.d.ts +56 -56
  20. package/dist/routes/connector-connections.d.ts +14 -14
  21. package/dist/routes/datasets.d.ts +12 -12
  22. package/dist/routes/events.d.ts +1 -1
  23. package/dist/routes/files.d.ts +8 -8
  24. package/dist/routes/links.d.ts +9 -9
  25. package/dist/routes/logs.d.ts +2 -2
  26. package/dist/routes/objects.d.ts +3 -3
  27. package/dist/routes/pipelines.d.ts +10 -10
  28. package/dist/routes/projections.d.ts +62 -50
  29. package/dist/routes/projections.d.ts.map +1 -1
  30. package/dist/routes/syncs.d.ts +6 -6
  31. package/dist/routes/telemetry.d.ts +7 -7
  32. package/dist/routes/webhook-runs.d.ts +2 -2
  33. package/dist/routes/workflows.d.ts +142 -57
  34. package/dist/routes/workflows.d.ts.map +1 -1
  35. package/dist/routes/ws/logs.d.ts +10 -10
  36. package/dist/schemas/actions.d.ts +16 -16
  37. package/dist/schemas/agents.d.ts +459 -142
  38. package/dist/schemas/agents.d.ts.map +1 -1
  39. package/dist/schemas/ai-accounting.d.ts +2393 -0
  40. package/dist/schemas/ai-accounting.d.ts.map +1 -0
  41. package/dist/schemas/auth.d.ts +96 -96
  42. package/dist/schemas/connectors.d.ts +24 -24
  43. package/dist/schemas/event-payloads.d.ts +6 -6
  44. package/dist/schemas/events.d.ts +6 -6
  45. package/dist/schemas/links.d.ts +2 -2
  46. package/dist/schemas/logs.d.ts +18 -18
  47. package/dist/schemas/pipelines.d.ts +20 -20
  48. package/dist/schemas/projections.d.ts +400 -288
  49. package/dist/schemas/projections.d.ts.map +1 -1
  50. package/dist/schemas/status.d.ts +2 -2
  51. package/dist/schemas/syncs.d.ts +10 -10
  52. package/dist/schemas/webhook-runs.d.ts +12 -12
  53. package/dist/schemas/workflows.d.ts +833 -162
  54. package/dist/schemas/workflows.d.ts.map +1 -1
  55. package/dist/server.d.ts +5 -0
  56. package/dist/server.d.ts.map +1 -1
  57. package/package.json +5 -5
  58. package/src/auth/experience.ts +190 -0
  59. package/src/auth/public-routes.ts +7 -0
  60. package/src/index.ts +1 -0
  61. package/src/openapi/tags.ts +4 -0
  62. package/src/registerRoutes.ts +2 -0
  63. package/src/routes/agents.ts +1 -0
  64. package/src/routes/ai-accounting.ts +166 -0
  65. package/src/routes/auth.ts +188 -32
  66. package/src/routes/projections.ts +18 -4
  67. package/src/routes/workflows.ts +16 -0
  68. package/src/schemas/agents.ts +4 -9
  69. package/src/schemas/ai-accounting.ts +182 -0
  70. package/src/schemas/projections.ts +6 -0
  71. package/src/schemas/workflows.ts +8 -3
  72. 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"
@@ -2451,14 +2458,18 @@ import { publishAgentRunCancel, publishAgentRunFinished } from "@sixb/core/inter
2451
2458
  import {
2452
2459
  AgentStorageError
2453
2460
  } from "@sixb/core/storage";
2454
- import { ZodError as ZodError2, z as z8 } from "zod";
2461
+ import { ZodError as ZodError2, z as z9 } from "zod";
2455
2462
 
2456
2463
  // src/schemas/agents.ts
2457
2464
  import { AGENT_REASONING_LEVELS, MAX_AGENT_CONTEXT_ENTRIES } from "@sixb/core";
2458
2465
  import {
2459
2466
  AGENT_RUN_DIAGNOSTIC_CODES,
2460
- AGENT_RUN_FAILURE_CODES
2467
+ AGENT_RUN_FAILURE_CODES,
2468
+ AGENT_RUN_FINISH_REASONS
2461
2469
  } from "@sixb/core/storage";
2470
+ import { z as z8 } from "zod";
2471
+
2472
+ // src/schemas/ai-accounting.ts
2462
2473
  import { z as z7 } from "zod";
2463
2474
 
2464
2475
  // src/schemas/ai-usage.ts
@@ -2476,140 +2487,295 @@ var AiUsageSummarySchema = z6.object({
2476
2487
  reportingStatus: z6.enum(["complete", "partial", "unavailable"])
2477
2488
  });
2478
2489
 
2490
+ // src/schemas/ai-accounting.ts
2491
+ var IntegerStringSchema = z7.string().regex(/^\d+$/);
2492
+ var IsoDateSchema = z7.string().datetime({ offset: true });
2493
+ var AiAccountingBucketSchema = z7.enum(["hour", "day", "week"]);
2494
+ var AiValuationStatusSchema = z7.enum(["rated", "unpriceable", "unvalued"]);
2495
+ var AiAccountingRangeQuerySchema = z7.object({
2496
+ from: IsoDateSchema,
2497
+ to: IsoDateSchema,
2498
+ providerId: z7.string().trim().min(1).optional(),
2499
+ modelId: z7.string().trim().min(1).optional()
2500
+ });
2501
+ var AiAccountingOverviewQuerySchema = AiAccountingRangeQuerySchema.extend({
2502
+ bucket: AiAccountingBucketSchema
2503
+ });
2504
+ var AiModelCallAccountingListQuerySchema = AiAccountingRangeQuerySchema.extend({
2505
+ executionId: z7.string().trim().min(1).optional(),
2506
+ valuationStatus: AiValuationStatusSchema.optional(),
2507
+ limit: IntegerStringSchema.optional(),
2508
+ offset: IntegerStringSchema.optional()
2509
+ });
2510
+ var AiMoneySchema = z7.object({
2511
+ currency: z7.string().regex(/^[A-Z]{3}$/),
2512
+ amountNanos: IntegerStringSchema
2513
+ });
2514
+ var AiCostSummarySchema = z7.object({
2515
+ amounts: z7.array(AiMoneySchema),
2516
+ ratedCallCount: z7.number().int().nonnegative(),
2517
+ unpriceableCallCount: z7.number().int().nonnegative(),
2518
+ unvaluedCallCount: z7.number().int().nonnegative()
2519
+ });
2520
+ var AiAccountingAggregateSchema = z7.object({
2521
+ modelCallCount: z7.number().int().nonnegative(),
2522
+ usage: AiUsageSummarySchema,
2523
+ costs: AiCostSummarySchema
2524
+ });
2525
+ var AiAccountingOverviewResponseSchema = z7.object({
2526
+ range: z7.object({ from: IsoDateSchema, to: IsoDateSchema }),
2527
+ bucket: AiAccountingBucketSchema,
2528
+ totals: AiAccountingAggregateSchema,
2529
+ series: z7.array(AiAccountingAggregateSchema.extend({
2530
+ start: IsoDateSchema,
2531
+ end: IsoDateSchema
2532
+ })),
2533
+ models: z7.array(AiAccountingAggregateSchema.extend({
2534
+ providerId: z7.string(),
2535
+ modelId: z7.string()
2536
+ })),
2537
+ agents: z7.array(AiAccountingAggregateSchema.extend({
2538
+ agentId: z7.string()
2539
+ })),
2540
+ workflows: z7.array(AiAccountingAggregateSchema.extend({
2541
+ workflowId: z7.string()
2542
+ }))
2543
+ });
2544
+ var AiPricingContextSchema = z7.object({
2545
+ serviceTier: z7.string().optional(),
2546
+ batch: z7.boolean().optional(),
2547
+ region: z7.string().optional(),
2548
+ inferenceGeo: z7.string().optional(),
2549
+ routedProviderId: z7.string().optional(),
2550
+ deploymentId: z7.string().optional(),
2551
+ inferenceProfileId: z7.string().optional(),
2552
+ cacheWriteTtlSeconds: z7.number().int().positive().optional(),
2553
+ mode: z7.string().optional()
2554
+ });
2555
+ var AiCostComponentSchema = z7.object({
2556
+ meter: z7.enum([
2557
+ "tokens.input.total",
2558
+ "tokens.input.uncached",
2559
+ "tokens.input.cacheRead",
2560
+ "tokens.input.cacheWrite",
2561
+ "tokens.output.total",
2562
+ "tokens.output.text",
2563
+ "tokens.output.reasoning"
2564
+ ]),
2565
+ quantity: IntegerStringSchema,
2566
+ rateAmountNanosPerMillion: IntegerStringSchema,
2567
+ chargeAmountNanos: IntegerStringSchema
2568
+ });
2569
+ var AiBillingIdentitySchema = z7.object({
2570
+ providerId: z7.string(),
2571
+ modelId: z7.string()
2572
+ });
2573
+ var AiPriceSourceSchema = z7.object({
2574
+ sourceId: z7.string(),
2575
+ sourceEntryId: z7.string(),
2576
+ sourceVersion: z7.string(),
2577
+ sourceUrl: z7.string().url(),
2578
+ observedAt: IsoDateSchema
2579
+ });
2580
+ var AiModelCallCostSchema = z7.discriminatedUnion("status", [
2581
+ z7.object({
2582
+ status: z7.literal("rated"),
2583
+ billingIdentity: AiBillingIdentitySchema,
2584
+ pricingContext: AiPricingContextSchema,
2585
+ priceSource: AiPriceSourceSchema,
2586
+ money: AiMoneySchema,
2587
+ components: z7.array(AiCostComponentSchema),
2588
+ ratedAt: IsoDateSchema
2589
+ }),
2590
+ z7.object({
2591
+ status: z7.literal("unpriceable"),
2592
+ billingIdentity: AiBillingIdentitySchema.optional(),
2593
+ pricingContext: AiPricingContextSchema,
2594
+ priceSource: AiPriceSourceSchema,
2595
+ reason: z7.enum([
2596
+ "missingBillingIdentity",
2597
+ "missingCatalogEntry",
2598
+ "missingUsageMeter",
2599
+ "unsupportedPricingDimension",
2600
+ "invalidUsageForFormula"
2601
+ ]),
2602
+ missingMeters: z7.array(AiCostComponentSchema.shape.meter).optional(),
2603
+ ratedAt: IsoDateSchema
2604
+ })
2605
+ ]);
2606
+ var AiModelCallUsageRecordSchema = z7.object({
2607
+ id: z7.string(),
2608
+ executionId: z7.string(),
2609
+ attempt: z7.number().int().positive(),
2610
+ callId: z7.string(),
2611
+ providerId: z7.string(),
2612
+ requestedModelId: z7.string(),
2613
+ responseModelId: z7.string().optional(),
2614
+ responseId: z7.string(),
2615
+ usage: AiUsageSummarySchema,
2616
+ occurredAt: IsoDateSchema,
2617
+ recordedAt: IsoDateSchema
2618
+ });
2619
+ var AiModelCallAccountingItemSchema = z7.object({
2620
+ usage: AiModelCallUsageRecordSchema,
2621
+ attribution: z7.discriminatedUnion("kind", [
2622
+ z7.object({
2623
+ kind: z7.literal("agent"),
2624
+ agentId: z7.string(),
2625
+ agentRunId: z7.string(),
2626
+ threadId: z7.string()
2627
+ }),
2628
+ z7.object({
2629
+ kind: z7.literal("workflowAgent"),
2630
+ agentId: z7.string(),
2631
+ nodeRunId: z7.string(),
2632
+ workflowId: z7.string(),
2633
+ workflowRunId: z7.string()
2634
+ })
2635
+ ]).optional(),
2636
+ cost: AiModelCallCostSchema.optional(),
2637
+ valuationStatus: AiValuationStatusSchema
2638
+ });
2639
+ var AiModelCallAccountingListResponseSchema = z7.object({
2640
+ items: z7.array(AiModelCallAccountingItemSchema),
2641
+ hasMore: z7.boolean(),
2642
+ total: z7.number().int().nonnegative()
2643
+ });
2644
+
2479
2645
  // src/schemas/agents.ts
2480
2646
  var AgentRunFailureSchema = sixbFailureSchema(AGENT_RUN_FAILURE_CODES);
2481
- var AgentIdParamsSchema = z7.object({
2482
- agentId: z7.string().min(1)
2647
+ var AgentIdParamsSchema = z8.object({
2648
+ agentId: z8.string().min(1)
2483
2649
  });
2484
- var AgentThreadParamsSchema = z7.object({
2485
- threadId: z7.string().min(1)
2650
+ var AgentThreadParamsSchema = z8.object({
2651
+ threadId: z8.string().min(1)
2486
2652
  });
2487
- var AgentRunParamsSchema = z7.object({
2488
- runId: z7.string().min(1)
2653
+ var AgentRunParamsSchema = z8.object({
2654
+ runId: z8.string().min(1)
2489
2655
  });
2490
2656
  var AgentMessageFileContentParamsSchema = AgentThreadParamsSchema.extend({
2491
- messageId: z7.string().min(1)
2657
+ messageId: z8.string().min(1)
2492
2658
  });
2493
- var AgentPrincipalSchema = z7.object({
2494
- type: z7.enum(["user", "serviceAccount", "system"]),
2495
- id: z7.string().min(1)
2659
+ var AgentPrincipalSchema = z8.object({
2660
+ type: z8.enum(["user", "serviceAccount", "system"]),
2661
+ id: z8.string().min(1)
2496
2662
  });
2497
- var AgentAuthorizablePrincipalSchema = z7.object({
2498
- type: z7.enum(["user", "serviceAccount"]),
2499
- id: z7.string().min(1)
2663
+ var AgentAuthorizablePrincipalSchema = z8.object({
2664
+ type: z8.enum(["user", "serviceAccount"]),
2665
+ id: z8.string().min(1)
2500
2666
  });
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)
2667
+ var AgentObjectContextSchema = z8.object({
2668
+ kind: z8.literal("object"),
2669
+ ref: z8.object({
2670
+ objectTypeId: z8.string().min(1),
2671
+ primaryId: z8.string().min(1)
2506
2672
  })
2507
2673
  });
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),
2674
+ var AgentAppStateContextSchema = z8.object({
2675
+ kind: z8.literal("app-state"),
2676
+ id: z8.string().min(1),
2677
+ label: z8.string().min(1),
2678
+ description: z8.string().min(1),
2513
2679
  value: JsonValueSchema
2514
2680
  });
2515
- var AgentContextInputSchema = z7.discriminatedUnion("kind", [
2681
+ var AgentContextInputSchema = z8.discriminatedUnion("kind", [
2516
2682
  AgentObjectContextSchema,
2517
2683
  AgentAppStateContextSchema
2518
2684
  ]);
2519
- var AgentContextOriginSchema = z7.enum(["ambient", "explicit"]);
2520
- var AgentContextEntryInputSchema = z7.object({
2685
+ var AgentContextOriginSchema = z8.enum(["ambient", "explicit"]);
2686
+ var AgentContextEntryInputSchema = z8.object({
2521
2687
  context: AgentContextInputSchema,
2522
2688
  origin: AgentContextOriginSchema
2523
2689
  });
2524
2690
  var AgentContextPartSchema = AgentContextEntryInputSchema.extend({
2525
- type: z7.literal("context")
2691
+ type: z8.literal("context")
2526
2692
  });
2527
- var AgentLoopConfigSchema = z7.object({
2528
- stopWhen: z7.object({
2529
- maxSteps: z7.number().int().positive().optional()
2693
+ var AgentLoopConfigSchema = z8.object({
2694
+ stopWhen: z8.object({
2695
+ maxSteps: z8.number().int().positive().optional()
2530
2696
  }).optional()
2531
2697
  });
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(),
2698
+ var AgentReasoningLevelSchema = z8.enum(AGENT_REASONING_LEVELS);
2699
+ var AgentCatalogItemSchema = z8.object({
2700
+ id: z8.string(),
2701
+ name: z8.string(),
2702
+ description: z8.string().optional(),
2703
+ modelId: z8.string().optional(),
2538
2704
  reasoning: AgentReasoningLevelSchema.optional(),
2539
- groupIds: z7.array(z7.string()),
2705
+ groupIds: z8.array(z8.string()),
2540
2706
  loop: AgentLoopConfigSchema.optional()
2541
2707
  });
2542
- var AgentThreadStatusSchema = z7.enum(["active", "archived"]);
2543
- var AgentThreadListQuerySchema = z7.object({
2544
- agentId: z7.string().optional(),
2708
+ var AgentThreadStatusSchema = z8.enum(["active", "archived"]);
2709
+ var AgentThreadListQuerySchema = z8.object({
2710
+ agentId: z8.string().optional(),
2545
2711
  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(),
2712
+ limit: z8.string().optional(),
2713
+ offset: z8.string().optional(),
2714
+ order: z8.enum(["asc", "desc"]).optional()
2715
+ });
2716
+ var CreateAgentThreadBodySchema = z8.object({
2717
+ agentId: z8.string().min(1),
2718
+ title: z8.string().trim().min(1).optional(),
2719
+ threadId: z8.string().trim().min(1).optional()
2720
+ });
2721
+ var AgentThreadSchema = z8.object({
2722
+ id: z8.string(),
2723
+ projectId: z8.string(),
2724
+ agentId: z8.string(),
2559
2725
  ownerPrincipal: AgentPrincipalSchema,
2560
- title: z7.string().optional(),
2726
+ title: z8.string().optional(),
2561
2727
  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({
2728
+ activeRunId: z8.string().nullable(),
2729
+ lastMessageAt: z8.string().optional(),
2730
+ messageCount: z8.number(),
2731
+ createdAt: z8.string(),
2732
+ updatedAt: z8.string()
2733
+ });
2734
+ var AgentThreadListResponseSchema = z8.object({
2735
+ threads: z8.array(AgentThreadSchema),
2736
+ hasMore: z8.boolean(),
2737
+ total: z8.number()
2738
+ });
2739
+ var CreateAgentThreadResponseSchema = z8.object({
2574
2740
  thread: AgentThreadSchema
2575
2741
  });
2576
- var AgentMessageRoleSchema = z7.enum(["system", "user", "assistant"]);
2577
- var AgentTextPartSchema = z7.object({
2578
- type: z7.literal("text"),
2579
- text: z7.string(),
2742
+ var AgentMessageRoleSchema = z8.enum(["system", "user", "assistant"]);
2743
+ var AgentTextPartSchema = z8.object({
2744
+ type: z8.literal("text"),
2745
+ text: z8.string(),
2580
2746
  providerMetadata: JsonValueSchema.optional()
2581
2747
  });
2582
- var AgentReasoningPartSchema = z7.object({
2583
- type: z7.literal("reasoning"),
2584
- text: z7.string(),
2748
+ var AgentReasoningPartSchema = z8.object({
2749
+ type: z8.literal("reasoning"),
2750
+ text: z8.string(),
2585
2751
  providerMetadata: JsonValueSchema.optional()
2586
2752
  });
2587
- var AgentStepStartPartSchema = z7.object({
2588
- type: z7.literal("step-start")
2753
+ var AgentStepStartPartSchema = z8.object({
2754
+ type: z8.literal("step-start")
2589
2755
  });
2590
- var AgentFilePartSchema = z7.object({
2591
- type: z7.literal("file"),
2756
+ var AgentFilePartSchema = z8.object({
2757
+ type: z8.literal("file"),
2592
2758
  fileRef: FileRefSchema,
2593
2759
  providerMetadata: JsonValueSchema.optional()
2594
2760
  });
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(),
2761
+ var AgentToolCallBaseSchema = z8.object({
2762
+ type: z8.literal("tool-call"),
2763
+ toolCallId: z8.string(),
2764
+ toolName: z8.string(),
2765
+ dynamic: z8.boolean().optional(),
2766
+ providerExecuted: z8.boolean().optional(),
2601
2767
  input: JsonValueSchema,
2602
2768
  providerMetadata: JsonValueSchema.optional()
2603
2769
  });
2604
2770
  var AgentToolCallOutputSchema = AgentToolCallBaseSchema.extend({
2605
- state: z7.literal("output-available"),
2771
+ state: z8.literal("output-available"),
2606
2772
  output: JsonValueSchema
2607
2773
  });
2608
2774
  var AgentToolCallErrorSchema = AgentToolCallBaseSchema.extend({
2609
- state: z7.literal("output-error"),
2610
- errorText: z7.string()
2775
+ state: z8.literal("output-error"),
2776
+ errorText: z8.string()
2611
2777
  });
2612
- var AgentMessagePartSchema = z7.union([
2778
+ var AgentMessagePartSchema = z8.union([
2613
2779
  AgentTextPartSchema,
2614
2780
  AgentReasoningPartSchema,
2615
2781
  AgentStepStartPartSchema,
@@ -2618,107 +2784,100 @@ var AgentMessagePartSchema = z7.union([
2618
2784
  AgentToolCallOutputSchema,
2619
2785
  AgentToolCallErrorSchema
2620
2786
  ]);
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(),
2787
+ var AgentRunDiagnosticSchema = z8.object({
2788
+ code: z8.enum(AGENT_RUN_DIAGNOSTIC_CODES),
2789
+ severity: z8.enum(["warning", "error"]),
2790
+ scope: z8.literal("output"),
2791
+ path: z8.string().optional(),
2792
+ message: z8.string()
2793
+ });
2794
+ var AgentMessageSchema = z8.object({
2795
+ id: z8.string(),
2796
+ projectId: z8.string(),
2797
+ threadId: z8.string(),
2798
+ runId: z8.string().nullable(),
2633
2799
  role: AgentMessageRoleSchema,
2634
2800
  authorPrincipal: AgentPrincipalSchema.optional(),
2635
- seq: z7.number(),
2636
- parts: z7.array(AgentMessagePartSchema),
2637
- annotations: z7.array(AgentRunDiagnosticSchema),
2801
+ seq: z8.number(),
2802
+ parts: z8.array(AgentMessagePartSchema),
2803
+ annotations: z8.array(AgentRunDiagnosticSchema),
2638
2804
  metadata: JsonValueSchema.optional(),
2639
- contentVersion: z7.number(),
2640
- createdAt: z7.string(),
2641
- completedAt: z7.string().optional()
2805
+ contentVersion: z8.number(),
2806
+ createdAt: z8.string(),
2807
+ completedAt: z8.string().optional()
2642
2808
  });
2643
- var AgentMessagesQuerySchema = z7.object({
2809
+ var AgentMessagesQuerySchema = z8.object({
2644
2810
  role: AgentMessageRoleSchema.optional(),
2645
- limit: z7.string().optional(),
2646
- offset: z7.string().optional(),
2647
- order: z7.enum(["asc", "desc"]).optional()
2811
+ limit: z8.string().optional(),
2812
+ offset: z8.string().optional(),
2813
+ order: z8.enum(["asc", "desc"]).optional()
2648
2814
  });
2649
- var AgentMessageListResponseSchema = z7.object({
2650
- messages: z7.array(AgentMessageSchema),
2651
- hasMore: z7.boolean(),
2652
- total: z7.number()
2815
+ var AgentMessageListResponseSchema = z8.object({
2816
+ messages: z8.array(AgentMessageSchema),
2817
+ hasMore: z8.boolean(),
2818
+ total: z8.number()
2653
2819
  });
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()
2820
+ var PostAgentMessageBodySchema = z8.object({
2821
+ text: z8.string().trim().min(1),
2822
+ attachments: z8.array(FileRefSchema).optional(),
2823
+ context: z8.array(AgentContextEntryInputSchema).max(MAX_AGENT_CONTEXT_ENTRIES).optional(),
2824
+ messageId: z8.string().trim().min(1).optional()
2659
2825
  });
2660
- var CancelAgentRunBodySchema = z7.object({
2661
- runId: z7.string().trim().min(1)
2826
+ var CancelAgentRunBodySchema = z8.object({
2827
+ runId: z8.string().trim().min(1)
2662
2828
  });
2663
- var AgentRunStatusSchema = z7.enum([
2829
+ var AgentRunStatusSchema = z8.enum([
2664
2830
  "queued",
2665
2831
  "running",
2666
2832
  "succeeded",
2667
2833
  "failed",
2668
2834
  "cancelled"
2669
2835
  ]);
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(),
2836
+ var AgentRunFinishReasonSchema = z8.enum(AGENT_RUN_FINISH_REASONS);
2837
+ var AgentRunSchema = z8.object({
2838
+ id: z8.string(),
2839
+ projectId: z8.string(),
2840
+ threadId: z8.string(),
2841
+ agentId: z8.string(),
2842
+ triggerMessageId: z8.string(),
2685
2843
  requestedBy: AgentAuthorizablePrincipalSchema.optional(),
2686
2844
  status: AgentRunStatusSchema,
2687
- modelId: z7.string().optional(),
2845
+ modelId: z8.string().optional(),
2688
2846
  finishReason: AgentRunFinishReasonSchema.optional(),
2689
2847
  usage: AiUsageSummarySchema.optional(),
2690
- diagnostics: z7.array(AgentRunDiagnosticSchema).optional(),
2848
+ cost: AiCostSummarySchema.optional(),
2849
+ diagnostics: z8.array(AgentRunDiagnosticSchema).optional(),
2691
2850
  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()
2851
+ attempt: z8.number(),
2852
+ streamId: z8.string(),
2853
+ createdAt: z8.string(),
2854
+ startedAt: z8.string().optional(),
2855
+ completedAt: z8.string().optional()
2697
2856
  });
2698
- var PostAgentMessageResponseSchema = z7.object({
2857
+ var PostAgentMessageResponseSchema = z8.object({
2699
2858
  run: AgentRunSchema
2700
2859
  });
2701
- var CancelAgentRunResponseSchema = z7.object({
2860
+ var CancelAgentRunResponseSchema = z8.object({
2702
2861
  run: AgentRunSchema
2703
2862
  });
2704
- var RetryAgentRunResponseSchema = z7.object({
2863
+ var RetryAgentRunResponseSchema = z8.object({
2705
2864
  run: AgentRunSchema
2706
2865
  });
2707
- var AgentRunListQuerySchema = z7.object({
2866
+ var AgentRunListQuerySchema = z8.object({
2708
2867
  status: AgentRunStatusSchema.optional(),
2709
- limit: z7.string().optional(),
2710
- offset: z7.string().optional(),
2711
- order: z7.enum(["asc", "desc"]).optional()
2868
+ limit: z8.string().optional(),
2869
+ offset: z8.string().optional(),
2870
+ order: z8.enum(["asc", "desc"]).optional()
2712
2871
  });
2713
- var AgentRunListResponseSchema = z7.object({
2714
- runs: z7.array(AgentRunSchema),
2715
- hasMore: z7.boolean(),
2716
- total: z7.number()
2872
+ var AgentRunListResponseSchema = z8.object({
2873
+ runs: z8.array(AgentRunSchema),
2874
+ hasMore: z8.boolean(),
2875
+ total: z8.number()
2717
2876
  });
2718
2877
 
2719
2878
  // src/routes/agents.ts
2720
2879
  var AgentMessageFileContentQuerySchema = FileContentQuerySchema.extend({
2721
- path: z8.string().min(1).regex(/^\/parts(?:\/|$)/, "Agent message file content paths must start with /parts/")
2880
+ path: z9.string().min(1).regex(/^\/parts(?:\/|$)/, "Agent message file content paths must start with /parts/")
2722
2881
  });
2723
2882
  function serializeAgent(agent) {
2724
2883
  return AgentCatalogItemSchema.parse({
@@ -2775,6 +2934,7 @@ function serializeAgentRun(run) {
2775
2934
  modelId: run.modelId,
2776
2935
  finishReason: run.finishReason,
2777
2936
  usage: run.usage,
2937
+ cost: run.cost,
2778
2938
  diagnostics: run.diagnostics,
2779
2939
  error: run.error,
2780
2940
  attempt: run.attempt,
@@ -3239,7 +3399,7 @@ function registerAgentRoutes(app, host) {
3239
3399
  return handleAgentRouteError(error, set);
3240
3400
  }
3241
3401
  }, {
3242
- params: AgentRunParamsSchema.extend({ threadId: z8.string().trim().min(1) }),
3402
+ params: AgentRunParamsSchema.extend({ threadId: z9.string().trim().min(1) }),
3243
3403
  response: {
3244
3404
  202: RetryAgentRunResponseSchema,
3245
3405
  400: ErrorResponseSchema,
@@ -3327,6 +3487,143 @@ function registerAgentRoutes(app, host) {
3327
3487
  });
3328
3488
  }
3329
3489
 
3490
+ // src/routes/ai-accounting.ts
3491
+ function serializeAggregate(aggregate) {
3492
+ return {
3493
+ modelCallCount: aggregate.modelCallCount,
3494
+ usage: aggregate.usage,
3495
+ costs: aggregate.costs
3496
+ };
3497
+ }
3498
+ function serializeOverview(overview) {
3499
+ return AiAccountingOverviewResponseSchema.parse({
3500
+ range: {
3501
+ from: overview.range.from.toISOString(),
3502
+ to: overview.range.to.toISOString()
3503
+ },
3504
+ bucket: overview.bucket,
3505
+ totals: serializeAggregate(overview.totals),
3506
+ series: overview.series.map((period) => ({
3507
+ start: period.start.toISOString(),
3508
+ end: period.end.toISOString(),
3509
+ ...serializeAggregate(period)
3510
+ })),
3511
+ models: overview.models.map((model) => ({
3512
+ providerId: model.providerId,
3513
+ modelId: model.modelId,
3514
+ ...serializeAggregate(model)
3515
+ })),
3516
+ agents: overview.agents.map((agent) => ({
3517
+ agentId: agent.agentId,
3518
+ ...serializeAggregate(agent)
3519
+ })),
3520
+ workflows: overview.workflows.map((workflow) => ({
3521
+ workflowId: workflow.workflowId,
3522
+ ...serializeAggregate(workflow)
3523
+ }))
3524
+ });
3525
+ }
3526
+ function serializeModelCall(item) {
3527
+ return AiModelCallAccountingListResponseSchema.shape.items.element.parse({
3528
+ usage: {
3529
+ id: item.usage.id,
3530
+ executionId: item.usage.executionId,
3531
+ attempt: item.usage.attempt,
3532
+ callId: item.usage.callId,
3533
+ providerId: item.usage.providerId,
3534
+ requestedModelId: item.usage.requestedModelId,
3535
+ responseModelId: item.usage.responseModelId,
3536
+ responseId: item.usage.responseId,
3537
+ usage: item.usage.usage,
3538
+ occurredAt: item.usage.occurredAt.toISOString(),
3539
+ recordedAt: item.usage.recordedAt.toISOString()
3540
+ },
3541
+ attribution: item.attribution,
3542
+ cost: item.cost === undefined ? undefined : {
3543
+ ...item.cost,
3544
+ priceSource: {
3545
+ ...item.cost.priceSource,
3546
+ observedAt: item.cost.priceSource.observedAt.toISOString()
3547
+ },
3548
+ ratedAt: item.cost.ratedAt.toISOString()
3549
+ },
3550
+ valuationStatus: item.valuationStatus
3551
+ });
3552
+ }
3553
+ function registerAiAccountingRoutes(app, host) {
3554
+ app.get("/api/ai/accounting/overview", async ({ query, set }) => {
3555
+ try {
3556
+ const parsed = AiAccountingOverviewQuerySchema.parse(query);
3557
+ const storage = host.storage.aiCosts;
3558
+ if (!storage)
3559
+ return unconfiguredStorageResponse2(set, "AI cost storage");
3560
+ const overview = await storage.queryProjectOverview({
3561
+ projectId: host.id,
3562
+ from: new Date(parsed.from),
3563
+ to: new Date(parsed.to),
3564
+ bucket: parsed.bucket,
3565
+ providerId: parsed.providerId,
3566
+ modelId: parsed.modelId
3567
+ });
3568
+ return serializeOverview(overview);
3569
+ } catch (error) {
3570
+ return handleRouteError(error, set);
3571
+ }
3572
+ }, {
3573
+ query: AiAccountingOverviewQuerySchema,
3574
+ response: {
3575
+ 200: AiAccountingOverviewResponseSchema,
3576
+ 400: ErrorResponseSchema,
3577
+ 501: ErrorResponseSchema
3578
+ },
3579
+ detail: {
3580
+ summary: "Get project AI usage and cost analytics",
3581
+ tags: [OPENAPI_TAGS.aiAccounting.name],
3582
+ operationId: "getAiAccountingOverview"
3583
+ }
3584
+ });
3585
+ app.get("/api/ai/model-calls", async ({ query, set }) => {
3586
+ try {
3587
+ const parsed = AiModelCallAccountingListQuerySchema.parse(query);
3588
+ const storage = host.storage.aiCosts;
3589
+ if (!storage)
3590
+ return unconfiguredStorageResponse2(set, "AI cost storage");
3591
+ const result = await storage.listModelCalls({
3592
+ projectId: host.id,
3593
+ from: new Date(parsed.from),
3594
+ to: new Date(parsed.to),
3595
+ providerId: parsed.providerId,
3596
+ modelId: parsed.modelId,
3597
+ executionId: parsed.executionId,
3598
+ valuationStatus: parsed.valuationStatus,
3599
+ limit: parseOptionalInt(parsed.limit),
3600
+ offset: parseOptionalInt(parsed.offset)
3601
+ });
3602
+ const items = result.items.map(serializeModelCall);
3603
+ return AiModelCallAccountingListResponseSchema.parse({
3604
+ items,
3605
+ hasMore: result.hasMore,
3606
+ total: result.total
3607
+ });
3608
+ } catch (error) {
3609
+ return handleRouteError(error, set);
3610
+ }
3611
+ }, {
3612
+ query: AiModelCallAccountingListQuerySchema,
3613
+ response: {
3614
+ 200: AiModelCallAccountingListResponseSchema,
3615
+ 400: ErrorResponseSchema,
3616
+ 501: ErrorResponseSchema
3617
+ },
3618
+ detail: {
3619
+ summary: "List project AI model-call accounting records",
3620
+ tags: [OPENAPI_TAGS.aiAccounting.name],
3621
+ operationId: "listAiModelCalls"
3622
+ }
3623
+ });
3624
+ return app;
3625
+ }
3626
+
3330
3627
  // src/routes/connector-connection-runs.ts
3331
3628
  import { getConnectorConnectionCallbackProcess } from "@sixb/core/internal/connector-connections";
3332
3629
 
@@ -3406,7 +3703,7 @@ import { createSixbError as createSixbError2 } from "@sixb/core/internal/errors"
3406
3703
  import {
3407
3704
  CONNECTOR_CONNECTION_RUN_FAILURE_CODES
3408
3705
  } from "@sixb/core/storage";
3409
- import { z as z9 } from "zod";
3706
+ import { z as z10 } from "zod";
3410
3707
  var CONNECTOR_HTTP_ERROR_CODES = [
3411
3708
  "internal.unexpected",
3412
3709
  "connector.adapter_invalid",
@@ -3447,114 +3744,114 @@ var ConnectorUnavailableResponseSchema = connectorRouteErrorResponseSchema([
3447
3744
  "connector.credentials_unavailable",
3448
3745
  "connector.provider_unavailable"
3449
3746
  ]);
3450
- var ConnectorParamsSchema = z9.object({
3451
- connectorId: z9.string().min(1)
3747
+ var ConnectorParamsSchema = z10.object({
3748
+ connectorId: z10.string().min(1)
3452
3749
  });
3453
3750
  var ConnectorConnectionParamsSchema = ConnectorParamsSchema.extend({
3454
- connectionId: z9.string().min(1)
3751
+ connectionId: z10.string().min(1)
3455
3752
  });
3456
3753
  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(),
3754
+ runId: z10.string().min(1)
3755
+ });
3756
+ var ConnectorWebhookSchema = z10.object({
3757
+ id: z10.string(),
3758
+ method: z10.literal("POST"),
3759
+ route: z10.string(),
3760
+ bodyFormat: z10.enum(["json", "text", "raw"]),
3761
+ hasVerify: z10.boolean(),
3762
+ hasIdempotency: z10.boolean()
3763
+ });
3764
+ var ConnectorSchema = z10.object({
3765
+ id: z10.string(),
3766
+ type: z10.string(),
3767
+ connection: z10.object({ authentication: z10.literal("oauth2") }).nullable(),
3768
+ syncIds: z10.array(z10.string()),
3769
+ webhooks: z10.array(ConnectorWebhookSchema)
3770
+ });
3771
+ var ConnectorAccountSchema = z10.object({
3772
+ id: z10.string(),
3773
+ label: z10.string(),
3774
+ description: z10.string().optional(),
3775
+ avatarUrl: z10.string().url().optional()
3776
+ });
3777
+ var ConnectorConnectionSchema = z10.object({
3778
+ id: z10.string(),
3779
+ connectorId: z10.string(),
3780
+ owner: z10.object({ type: z10.literal("project") }),
3781
+ slot: z10.string(),
3485
3782
  account: ConnectorAccountSchema,
3486
- status: z9.enum(["connected", "needs_reauthorization", "disconnected"])
3783
+ status: z10.enum(["connected", "needs_reauthorization", "disconnected"])
3487
3784
  });
3488
3785
  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([
3786
+ var ConnectorConnectionRunBaseSchema = z10.object({
3787
+ id: z10.string(),
3788
+ connectorId: z10.string(),
3789
+ kind: z10.enum(["connect", "reauthorize"]),
3790
+ owner: z10.object({ type: z10.literal("project") }),
3791
+ slot: z10.string(),
3792
+ createdAt: z10.string().datetime(),
3793
+ updatedAt: z10.string().datetime()
3794
+ });
3795
+ var ConnectorConnectionRunSchema = z10.union([
3499
3796
  ConnectorConnectionRunBaseSchema.extend({
3500
- status: z9.literal("waiting"),
3501
- waitingFor: z9.literal("provider_authorization"),
3502
- expiresAt: z9.string().datetime()
3797
+ status: z10.literal("waiting"),
3798
+ waitingFor: z10.literal("provider_authorization"),
3799
+ expiresAt: z10.string().datetime()
3503
3800
  }),
3504
3801
  ConnectorConnectionRunBaseSchema.extend({
3505
- status: z9.literal("running")
3802
+ status: z10.literal("running")
3506
3803
  }),
3507
3804
  ConnectorConnectionRunBaseSchema.extend({
3508
- status: z9.literal("waiting"),
3509
- waitingFor: z9.literal("account_selection"),
3510
- accounts: z9.array(ConnectorAccountSchema),
3511
- expiresAt: z9.string().datetime()
3805
+ status: z10.literal("waiting"),
3806
+ waitingFor: z10.literal("account_selection"),
3807
+ accounts: z10.array(ConnectorAccountSchema),
3808
+ expiresAt: z10.string().datetime()
3512
3809
  }),
3513
3810
  ConnectorConnectionRunBaseSchema.extend({
3514
- status: z9.literal("succeeded"),
3515
- connections: z9.array(ConnectorConnectionSchema),
3516
- finishedAt: z9.string().datetime()
3811
+ status: z10.literal("succeeded"),
3812
+ connections: z10.array(ConnectorConnectionSchema),
3813
+ finishedAt: z10.string().datetime()
3517
3814
  }),
3518
3815
  ConnectorConnectionRunBaseSchema.extend({
3519
- status: z9.literal("failed"),
3816
+ status: z10.literal("failed"),
3520
3817
  error: ConnectorConnectionRunFailureSchema,
3521
- finishedAt: z9.string().datetime()
3818
+ finishedAt: z10.string().datetime()
3522
3819
  }),
3523
3820
  ConnectorConnectionRunBaseSchema.extend({
3524
- status: z9.enum(["cancelled", "expired"]),
3525
- finishedAt: z9.string().datetime()
3821
+ status: z10.enum(["cancelled", "expired"]),
3822
+ finishedAt: z10.string().datetime()
3526
3823
  })
3527
3824
  ]);
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()
3825
+ var StartConnectorConnectionRunBodySchema = z10.object({
3826
+ slot: z10.string().trim().min(1),
3827
+ returnTo: z10.string().url()
3828
+ });
3829
+ var AddConnectorConnectionBodySchema = z10.object({
3830
+ slot: z10.string().trim().min(1)
3831
+ });
3832
+ var StartConnectorReauthorizationBodySchema = z10.object({
3833
+ returnTo: z10.string().url()
3834
+ });
3835
+ var StartConnectorConnectionRunResponseSchema = z10.object({
3836
+ runId: z10.string(),
3837
+ authorizationUrl: z10.string().url(),
3838
+ affectedConnections: z10.array(ConnectorConnectionSchema)
3839
+ });
3840
+ var SelectConnectorConnectionRunAccountBodySchema = z10.object({
3841
+ accountId: z10.string().trim().min(1),
3842
+ replace: z10.boolean().optional()
3843
+ });
3844
+ var ConnectorOAuthCallbackQuerySchema = z10.object({
3845
+ state: z10.string().min(1),
3846
+ code: z10.string().min(1).optional(),
3847
+ auth_code: z10.string().min(1).optional(),
3848
+ error: z10.string().min(1).optional()
3552
3849
  }).refine((query) => [query.code, query.auth_code, query.error].filter(Boolean).length === 1, {
3553
3850
  message: "OAuth callback must contain exactly one of code, auth_code, or error."
3554
3851
  }).transform(({ auth_code, ...query }) => ({ ...query, code: query.code ?? auth_code }));
3555
3852
  function connectorRouteErrorResponseSchema(codes) {
3556
3853
  return ErrorResponseSchema.extend({
3557
- code: z9.enum(codes).optional().describe("Stable machine-readable failure code for programmatic handling.")
3854
+ code: z10.enum(codes).optional().describe("Stable machine-readable failure code for programmatic handling.")
3558
3855
  });
3559
3856
  }
3560
3857
 
@@ -3998,25 +4295,25 @@ function registerConnectorRoutes(app, host) {
3998
4295
  import { createSixbError as createSixbError3 } from "@sixb/core/internal/errors";
3999
4296
 
4000
4297
  // src/schemas/datasets.ts
4001
- import { z as z10 } from "zod";
4002
- var DatasetParamsSchema = z10.object({
4003
- datasetId: z10.string().min(1)
4298
+ import { z as z11 } from "zod";
4299
+ var DatasetParamsSchema = z11.object({
4300
+ datasetId: z11.string().min(1)
4004
4301
  });
4005
4302
  var DatasetVersionParamsSchema = DatasetParamsSchema.extend({
4006
- versionId: z10.string().min(1)
4303
+ versionId: z11.string().min(1)
4007
4304
  });
4008
- var DatasetVersionsQuerySchema = z10.object({
4009
- limit: z10.string().optional()
4305
+ var DatasetVersionsQuerySchema = z11.object({
4306
+ limit: z11.string().optional()
4010
4307
  });
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()
4308
+ var DatasetRowsQuerySchema = z11.object({
4309
+ versionId: z11.string().optional(),
4310
+ columns: z11.string().optional(),
4311
+ limit: z11.string().optional(),
4312
+ offset: z11.string().optional()
4016
4313
  });
4017
- var DatasetColumnSchema = z10.object({
4018
- name: z10.string(),
4019
- type: z10.enum([
4314
+ var DatasetColumnSchema = z11.object({
4315
+ name: z11.string(),
4316
+ type: z11.enum([
4020
4317
  "string",
4021
4318
  "boolean",
4022
4319
  "int64",
@@ -4027,70 +4324,70 @@ var DatasetColumnSchema = z10.object({
4027
4324
  "json",
4028
4325
  "fileRef"
4029
4326
  ]),
4030
- nullable: z10.boolean().optional()
4327
+ nullable: z11.boolean().optional()
4031
4328
  });
4032
- var DatasetSchema = z10.object({
4033
- columns: z10.array(DatasetColumnSchema)
4329
+ var DatasetSchema = z11.object({
4330
+ columns: z11.array(DatasetColumnSchema)
4034
4331
  });
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(),
4332
+ var DatasetDefinitionSchema = z11.object({
4333
+ id: z11.string(),
4334
+ description: z11.string().optional(),
4335
+ primaryKey: z11.union([z11.string(), z11.array(z11.string()).min(2)]).optional(),
4336
+ partitionBy: z11.array(z11.string()).optional(),
4040
4337
  schema: DatasetSchema
4041
4338
  });
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(),
4339
+ var DatasetVersionRefSchema = z11.object({
4340
+ datasetId: z11.string(),
4341
+ versionId: z11.string()
4342
+ });
4343
+ var DatasetProducerSchema = z11.object({
4344
+ kind: z11.enum(["sync", "pipeline"]),
4345
+ id: z11.string().optional(),
4346
+ runId: z11.string().optional()
4347
+ });
4348
+ var DatasetVersionSchema = z11.object({
4349
+ datasetId: z11.string(),
4350
+ versionId: z11.string(),
4351
+ parentVersionId: z11.string().optional(),
4352
+ mode: z11.enum(["snapshot", "append", "merge", "schema"]),
4353
+ createdAt: z11.string(),
4057
4354
  schema: DatasetSchema,
4058
4355
  producer: DatasetProducerSchema.optional(),
4059
- inputs: z10.array(DatasetVersionRefSchema).optional(),
4060
- rowCount: z10.number().optional(),
4061
- sizeBytes: z10.number().optional()
4356
+ inputs: z11.array(DatasetVersionRefSchema).optional(),
4357
+ rowCount: z11.number().optional(),
4358
+ sizeBytes: z11.number().optional()
4062
4359
  });
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()
4360
+ var DatasetLatestVersionSummarySchema = z11.object({
4361
+ datasetId: z11.string(),
4362
+ versionId: z11.string(),
4363
+ mode: z11.enum(["snapshot", "append", "merge", "schema"]),
4364
+ createdAt: z11.string(),
4365
+ rowCount: z11.number().optional()
4069
4366
  });
4070
4367
  var DatasetCatalogItemSchema = DatasetDefinitionSchema.extend({
4071
- kind: z10.literal("dataset"),
4072
- materialized: z10.boolean(),
4368
+ kind: z11.literal("dataset"),
4369
+ materialized: z11.boolean(),
4073
4370
  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(),
4371
+ syncIds: z11.array(z11.string()),
4372
+ sourcePipelineIds: z11.array(z11.string()),
4373
+ targetPipelineIds: z11.array(z11.string()),
4374
+ projectionIds: z11.array(z11.string())
4375
+ });
4376
+ var DatasetVersionListResponseSchema = z11.object({
4377
+ versions: z11.array(DatasetVersionSchema),
4378
+ count: z11.number()
4379
+ });
4380
+ var DatasetRowsResponseSchema = z11.object({
4381
+ datasetId: z11.string(),
4382
+ versionId: z11.string(),
4086
4383
  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()
4384
+ columns: z11.array(z11.string()),
4385
+ rows: z11.array(z11.record(z11.unknown())),
4386
+ count: z11.number(),
4387
+ limit: z11.number(),
4388
+ offset: z11.number(),
4389
+ total: z11.number().optional(),
4390
+ hasMore: z11.boolean()
4094
4391
  });
4095
4392
 
4096
4393
  // src/routes/datasets.ts
@@ -4393,44 +4690,44 @@ import {
4393
4690
  EVENT_DEFINITIONS,
4394
4691
  isOntologyFactType
4395
4692
  } from "@sixb/core/internal/events";
4396
- import { z as z12 } from "zod";
4693
+ import { z as z13 } from "zod";
4397
4694
 
4398
4695
  // 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"),
4696
+ import { z as z12 } from "zod";
4697
+ var PropertyChangeSchema = z12.discriminatedUnion("operation", [
4698
+ z12.object({ operation: z12.literal("created"), after: JsonValueSchema }),
4699
+ z12.object({
4700
+ operation: z12.literal("updated"),
4404
4701
  before: JsonValueSchema,
4405
4702
  after: JsonValueSchema
4406
4703
  }),
4407
- z11.object({
4408
- operation: z11.literal("cleared"),
4704
+ z12.object({
4705
+ operation: z12.literal("cleared"),
4409
4706
  before: JsonValueSchema,
4410
4707
  after: JsonNullSchema
4411
4708
  })
4412
4709
  ]);
4413
- var PropertyChangesSchema = z11.record(PropertyChangeSchema);
4414
- var ObjectMutationPayloadSchema = z11.object({
4415
- objectTypeId: z11.string(),
4416
- primaryId: z11.string(),
4417
- properties: z11.record(JsonValueSchema),
4710
+ var PropertyChangesSchema = z12.record(PropertyChangeSchema);
4711
+ var ObjectMutationPayloadSchema = z12.object({
4712
+ objectTypeId: z12.string(),
4713
+ primaryId: z12.string(),
4714
+ properties: z12.record(JsonValueSchema),
4418
4715
  propertyChanges: PropertyChangesSchema
4419
4716
  });
4420
- var ObjectDeletedPayloadSchema = z11.object({
4421
- objectTypeId: z11.string(),
4422
- primaryId: z11.string(),
4717
+ var ObjectDeletedPayloadSchema = z12.object({
4718
+ objectTypeId: z12.string(),
4719
+ primaryId: z12.string(),
4423
4720
  propertyChanges: PropertyChangesSchema
4424
4721
  });
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()
4722
+ var LinkSubjectSchema = z12.object({
4723
+ sourceTypeId: z12.string(),
4724
+ sourceId: z12.string(),
4725
+ linkId: z12.string(),
4726
+ targetTypeId: z12.string(),
4727
+ targetId: z12.string()
4431
4728
  });
4432
4729
  var LinkMutationPayloadSchema = LinkSubjectSchema.extend({
4433
- properties: z11.record(JsonValueSchema).optional(),
4730
+ properties: z12.record(JsonValueSchema).optional(),
4434
4731
  propertyChanges: PropertyChangesSchema
4435
4732
  });
4436
4733
  var LinkDeletedPayloadSchema = LinkSubjectSchema.extend({
@@ -4443,91 +4740,91 @@ var ONTOLOGY_EVENT_PAYLOAD_SCHEMAS = {
4443
4740
  "link.created": LinkMutationPayloadSchema,
4444
4741
  "link.updated": LinkMutationPayloadSchema,
4445
4742
  "link.deleted": LinkDeletedPayloadSchema,
4446
- "telemetry.appended": z11.object({
4447
- objectTypeId: z11.string(),
4448
- objectId: z11.string(),
4449
- propertyId: z11.string(),
4743
+ "telemetry.appended": z12.object({
4744
+ objectTypeId: z12.string(),
4745
+ objectId: z12.string(),
4746
+ propertyId: z12.string(),
4450
4747
  value: JsonValueSchema,
4451
- unit: z11.string().optional(),
4452
- at: z11.string()
4748
+ unit: z12.string().optional(),
4749
+ at: z12.string()
4453
4750
  })
4454
4751
  };
4455
4752
 
4456
4753
  // src/schemas/events.ts
4457
4754
  var EVENT_TOPICS = CORE_EVENT_TOPICS;
4458
4755
  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()
4756
+ var EventTopicSchema = z13.enum(EVENT_TOPICS);
4757
+ var EventTypeSchema = z13.enum(EVENT_TYPES);
4758
+ var ProjectionEventOriginSchema = z13.object({
4759
+ kind: z13.literal("projection"),
4760
+ projectionId: z13.string(),
4761
+ projectionRunId: z13.string(),
4762
+ datasetId: z13.string(),
4763
+ datasetVersionId: z13.string()
4764
+ });
4765
+ var EventOriginSchema = z13.union([
4766
+ z13.object({
4767
+ kind: z13.literal("action"),
4768
+ actionId: z13.string(),
4769
+ runId: z13.string()
4473
4770
  }),
4474
- z12.object({ kind: z12.literal("runtime"), requestId: z12.string() }),
4771
+ z13.object({ kind: z13.literal("runtime"), requestId: z13.string() }),
4475
4772
  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() })
4773
+ z13.object({
4774
+ kind: z13.literal("telemetry"),
4775
+ source: z13.union([
4776
+ z13.object({ kind: z13.literal("runtime"), requestId: z13.string() }),
4777
+ ProjectionEventOriginSchema.extend({ batchOrdinal: z13.number() })
4481
4778
  ])
4482
4779
  })
4483
4780
  ]);
4484
- var EventsQuerySchema = z12.object({
4781
+ var EventsQuerySchema = z13.object({
4485
4782
  topic: EventTopicSchema.optional(),
4486
4783
  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()
4784
+ afterCursor: z13.string().optional(),
4785
+ limit: z13.string().optional()
4786
+ });
4787
+ var StoredEventBaseSchema = z13.object({
4788
+ id: z13.string(),
4789
+ cursor: z13.string(),
4790
+ schemaVersion: z13.literal(1),
4791
+ projectId: z13.string(),
4792
+ occurredAt: z13.string(),
4793
+ actor: z13.object({
4794
+ type: z13.enum(["user", "serviceAccount", "system"]),
4795
+ id: z13.string()
4499
4796
  }).optional(),
4500
- partitionKey: z12.string()
4797
+ partitionKey: z13.string()
4501
4798
  });
4502
4799
  var StoredAuthorableEventBaseSchema = StoredEventBaseSchema.extend({
4503
- correlationId: z12.string().optional(),
4504
- causationId: z12.string().optional(),
4505
- idempotencyKey: z12.string().optional(),
4800
+ correlationId: z13.string().optional(),
4801
+ causationId: z13.string().optional(),
4802
+ idempotencyKey: z13.string().optional(),
4506
4803
  origin: EventOriginSchema.optional(),
4507
- metadata: z12.record(JsonValueSchema).optional()
4804
+ metadata: z13.record(JsonValueSchema).optional()
4508
4805
  });
4509
4806
  var StoredOntologyEventBaseSchema = StoredEventBaseSchema.extend({
4510
4807
  origin: EventOriginSchema,
4511
- commitId: z12.string(),
4512
- commitOrdinal: z12.number().int().nonnegative()
4808
+ commitId: z13.string(),
4809
+ commitOrdinal: z13.number().int().nonnegative()
4513
4810
  });
4514
4811
  var ontologyEventTypes = EVENT_TYPES.filter(isOntologyFactType);
4515
4812
  var ontologyEventSchemas = ontologyEventTypes.map((type) => StoredOntologyEventBaseSchema.extend({
4516
- type: z12.literal(type),
4517
- topic: z12.literal(EVENT_DEFINITIONS[type].topic),
4813
+ type: z13.literal(type),
4814
+ topic: z13.literal(EVENT_DEFINITIONS[type].topic),
4518
4815
  payload: ONTOLOGY_EVENT_PAYLOAD_SCHEMAS[type]
4519
4816
  }));
4520
4817
  var authorableEventTypes = EVENT_TYPES.filter((type) => !isOntologyFactType(type));
4521
4818
  var StoredAuthorableEventSchema = StoredAuthorableEventBaseSchema.extend({
4522
- type: z12.enum(authorableEventTypes),
4819
+ type: z13.enum(authorableEventTypes),
4523
4820
  topic: EventTopicSchema,
4524
- payload: z12.record(z12.unknown())
4821
+ payload: z13.record(z13.unknown())
4525
4822
  });
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)
4823
+ var StoredOntologyEventSchema = z13.discriminatedUnion("type", ontologyEventSchemas);
4824
+ var EventSchema = z13.union([StoredOntologyEventSchema, StoredAuthorableEventSchema]);
4825
+ var EventsResponseSchema = z13.object({
4826
+ count: z13.number(),
4827
+ events: z13.array(EventSchema)
4531
4828
  });
4532
4829
 
4533
4830
  // src/routes/events.ts
@@ -4573,37 +4870,37 @@ function registerEventRoutes(app, _host) {
4573
4870
  }
4574
4871
 
4575
4872
  // 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)
4873
+ import { z as z14 } from "zod";
4874
+ var LinkSourceParamsSchema = z14.object({
4875
+ objectTypeId: z14.string().min(1),
4876
+ objectId: z14.string().min(1)
4580
4877
  });
4581
4878
  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)
4591
- });
4592
- var UpsertLinkBodySchema = z13.object({
4593
- targetTypeId: z13.string().min(1),
4594
- targetId: z13.string().min(1),
4595
- properties: z13.record(z13.unknown()).optional()
4596
- });
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()
4879
+ linkId: z14.string().min(1)
4880
+ });
4881
+ var LinkQuerySchema = z14.object({
4882
+ linkId: z14.string().optional(),
4883
+ direction: z14.enum(["outgoing", "incoming", "both"]).default("outgoing")
4884
+ });
4885
+ var RemoveLinkQuerySchema = z14.object({
4886
+ targetTypeId: z14.string().min(1),
4887
+ targetId: z14.string().min(1)
4888
+ });
4889
+ var UpsertLinkBodySchema = z14.object({
4890
+ targetTypeId: z14.string().min(1),
4891
+ targetId: z14.string().min(1),
4892
+ properties: z14.record(z14.unknown()).optional()
4893
+ });
4894
+ var ObjectLinkSchema = z14.object({
4895
+ projectId: z14.string(),
4896
+ sourceTypeId: z14.string(),
4897
+ sourceId: z14.string(),
4898
+ linkId: z14.string(),
4899
+ targetTypeId: z14.string(),
4900
+ targetId: z14.string(),
4901
+ properties: z14.record(z14.unknown()).optional(),
4902
+ createdAt: z14.string(),
4903
+ updatedAt: z14.string()
4607
4904
  });
4608
4905
 
4609
4906
  // src/routes/links.ts
@@ -4709,71 +5006,71 @@ import { logLevelsAtOrAbove } from "@sixb/core";
4709
5006
 
4710
5007
  // src/schemas/logs.ts
4711
5008
  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");
5009
+ import { z as z15 } from "zod";
5010
+ var SixbRunKindSchema = z15.enum(SIXB_RUN_KINDS);
5011
+ var LogLevelSchema = z15.enum(LOG_LEVELS);
5012
+ var LogRunIdSchema = z15.string().regex(/\S/, "run id must not be blank");
4716
5013
  var DEFAULT_LOGS_PAGE_LIMIT = 200;
4717
5014
  var MAX_LOGS_PAGE_LIMIT = 1000;
4718
- var LogsLimitSchema = z14.coerce.number().int().positive().max(MAX_LOGS_PAGE_LIMIT);
4719
- var LogsQuerySchema = z14.object({
5015
+ var LogsLimitSchema = z15.coerce.number().int().positive().max(MAX_LOGS_PAGE_LIMIT);
5016
+ var LogsQuerySchema = z15.object({
4720
5017
  kind: SixbRunKindSchema.optional(),
4721
5018
  runId: LogRunIdSchema.optional(),
4722
5019
  level: LogLevelSchema.optional(),
4723
- direction: z14.enum(["forward", "backward"]).optional(),
4724
- afterCursor: z14.string().optional(),
4725
- beforeCursor: z14.string().optional(),
5020
+ direction: z15.enum(["forward", "backward"]).optional(),
5021
+ afterCursor: z15.string().optional(),
5022
+ beforeCursor: z15.string().optional(),
4726
5023
  limit: LogsLimitSchema.optional()
4727
5024
  }).superRefine((query, context) => {
4728
5025
  if (query.runId !== undefined && query.kind === undefined) {
4729
5026
  context.addIssue({
4730
- code: z14.ZodIssueCode.custom,
5027
+ code: z15.ZodIssueCode.custom,
4731
5028
  path: ["runId"],
4732
5029
  message: "kind is required when runId is provided"
4733
5030
  });
4734
5031
  }
4735
5032
  if (query.afterCursor && query.beforeCursor) {
4736
5033
  context.addIssue({
4737
- code: z14.ZodIssueCode.custom,
5034
+ code: z15.ZodIssueCode.custom,
4738
5035
  message: "afterCursor and beforeCursor are mutually exclusive"
4739
5036
  });
4740
5037
  }
4741
5038
  if (query.direction === "backward" && query.afterCursor) {
4742
5039
  context.addIssue({
4743
- code: z14.ZodIssueCode.custom,
5040
+ code: z15.ZodIssueCode.custom,
4744
5041
  path: ["afterCursor"],
4745
5042
  message: "afterCursor cannot be used with backward reads"
4746
5043
  });
4747
5044
  }
4748
5045
  if (query.direction !== "backward" && query.beforeCursor) {
4749
5046
  context.addIssue({
4750
- code: z14.ZodIssueCode.custom,
5047
+ code: z15.ZodIssueCode.custom,
4751
5048
  path: ["beforeCursor"],
4752
5049
  message: "beforeCursor requires direction=backward"
4753
5050
  });
4754
5051
  }
4755
5052
  });
4756
- var LogLineSchema = z14.object({
5053
+ var LogLineSchema = z15.object({
4757
5054
  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({
5055
+ message: z15.string(),
5056
+ fields: z15.record(z15.unknown()).optional(),
5057
+ at: z15.string(),
5058
+ context: z15.object({
5059
+ run: z15.object({
4763
5060
  kind: SixbRunKindSchema,
4764
- id: z14.string()
5061
+ id: z15.string()
4765
5062
  }),
4766
- stepId: z14.string().optional(),
4767
- phase: z14.string().optional(),
4768
- attempt: z14.number().optional()
5063
+ stepId: z15.string().optional(),
5064
+ phase: z15.string().optional(),
5065
+ attempt: z15.number().optional()
4769
5066
  }),
4770
- cursor: z14.string()
5067
+ cursor: z15.string()
4771
5068
  });
4772
- var LogsResponseSchema = z14.object({
4773
- count: z14.number(),
4774
- lines: z14.array(LogLineSchema),
4775
- cursor: z14.string().optional(),
4776
- hasMore: z14.boolean()
5069
+ var LogsResponseSchema = z15.object({
5070
+ count: z15.number(),
5071
+ lines: z15.array(LogLineSchema),
5072
+ cursor: z15.string().optional(),
5073
+ hasMore: z15.boolean()
4777
5074
  });
4778
5075
 
4779
5076
  // src/routes/logs.ts
@@ -4824,35 +5121,35 @@ import {
4824
5121
  ObjectQueryPlanningError,
4825
5122
  ObjectQueryValidationError
4826
5123
  } from "@sixb/core";
4827
- import { ZodError as ZodError3, z as z16 } from "zod";
5124
+ import { ZodError as ZodError3, z as z17 } from "zod";
4828
5125
 
4829
5126
  // 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()
5127
+ import { z as z16 } from "zod";
5128
+ var ObjectParamsSchema = z16.object({
5129
+ objectTypeId: z16.string().min(1),
5130
+ objectId: z16.string().min(1)
5131
+ });
5132
+ var ObjectSearchQuerySchema = z16.object({
5133
+ q: z16.string().trim().min(1).max(200),
5134
+ limit: z16.string().regex(/^\d+$/).optional()
5135
+ });
5136
+ var ObjectSearchResponseSchema = z16.object({
5137
+ items: z16.array(z16.object({
5138
+ ref: z16.object({
5139
+ objectTypeId: z16.string(),
5140
+ primaryId: z16.string()
4844
5141
  }),
4845
- label: z15.string()
5142
+ label: z16.string()
4846
5143
  }))
4847
5144
  });
4848
5145
  var OBJECT_LIST_MAX_LIMIT = 1000;
4849
- var Rfc3339DateSchema = z15.string().datetime({ offset: true });
5146
+ var Rfc3339DateSchema = z16.string().datetime({ offset: true });
4850
5147
  function objectListDateSchema(parameter) {
4851
- return z15.string().refine((value) => Rfc3339DateSchema.safeParse(value).success, {
5148
+ return z16.string().refine((value) => Rfc3339DateSchema.safeParse(value).success, {
4852
5149
  message: `Invalid query parameter '${parameter}': expected an RFC 3339 timestamp.`
4853
5150
  }).transform((value) => new Date(value));
4854
5151
  }
4855
- var ObjectListLimitSchema = z15.string().refine((value) => {
5152
+ var ObjectListLimitSchema = z16.string().refine((value) => {
4856
5153
  if (!/^\d+$/.test(value))
4857
5154
  return false;
4858
5155
  const parsed = Number(value);
@@ -4860,25 +5157,25 @@ var ObjectListLimitSchema = z15.string().refine((value) => {
4860
5157
  }, {
4861
5158
  message: `Invalid query parameter 'limit': expected an integer between 0 and ${OBJECT_LIST_MAX_LIMIT}.`
4862
5159
  }).transform(Number);
4863
- var ObjectListOffsetSchema = z15.string().refine((value) => /^\d+$/.test(value) && Number.isSafeInteger(Number(value)), {
5160
+ var ObjectListOffsetSchema = z16.string().refine((value) => /^\d+$/.test(value) && Number.isSafeInteger(Number(value)), {
4864
5161
  message: "Invalid query parameter 'offset': expected a non-negative safe integer."
4865
5162
  }).transform(Number);
4866
- var ObjectsQuerySchema = z15.object({
4867
- objectTypeId: z15.string().optional(),
4868
- idPrefix: z15.string().optional(),
4869
- idSuffix: z15.string().optional(),
5163
+ var ObjectsQuerySchema = z16.object({
5164
+ objectTypeId: z16.string().optional(),
5165
+ idPrefix: z16.string().optional(),
5166
+ idSuffix: z16.string().optional(),
4870
5167
  updatedAfter: objectListDateSchema("updatedAfter").optional(),
4871
5168
  updatedBefore: objectListDateSchema("updatedBefore").optional(),
4872
5169
  createdAfter: objectListDateSchema("createdAfter").optional(),
4873
5170
  createdBefore: objectListDateSchema("createdBefore").optional(),
4874
5171
  limit: ObjectListLimitSchema.optional(),
4875
5172
  offset: ObjectListOffsetSchema.optional(),
4876
- orderBy: z15.enum(["createdAt", "updatedAt", "primaryId"], {
5173
+ orderBy: z16.enum(["createdAt", "updatedAt", "primaryId"], {
4877
5174
  errorMap: () => ({
4878
5175
  message: "Invalid query parameter 'orderBy': expected one of createdAt, updatedAt, or primaryId."
4879
5176
  })
4880
5177
  }).optional(),
4881
- order: z15.enum(["asc", "desc"], {
5178
+ order: z16.enum(["asc", "desc"], {
4882
5179
  errorMap: () => ({
4883
5180
  message: "Invalid query parameter 'order': expected 'asc' or 'desc'."
4884
5181
  })
@@ -4886,163 +5183,163 @@ var ObjectsQuerySchema = z15.object({
4886
5183
  }).superRefine((query, context) => {
4887
5184
  if (query.updatedAfter && query.updatedBefore && query.updatedAfter > query.updatedBefore) {
4888
5185
  context.addIssue({
4889
- code: z15.ZodIssueCode.custom,
5186
+ code: z16.ZodIssueCode.custom,
4890
5187
  path: ["updatedAfter"],
4891
5188
  message: "Invalid query parameter range: 'updatedAfter' must be before or equal to 'updatedBefore'."
4892
5189
  });
4893
5190
  }
4894
5191
  if (query.createdAfter && query.createdBefore && query.createdAfter > query.createdBefore) {
4895
5192
  context.addIssue({
4896
- code: z15.ZodIssueCode.custom,
5193
+ code: z16.ZodIssueCode.custom,
4897
5194
  path: ["createdAfter"],
4898
5195
  message: "Invalid query parameter range: 'createdAfter' must be before or equal to 'createdBefore'."
4899
5196
  });
4900
5197
  }
4901
5198
  });
4902
- var UpsertObjectBodySchema = z15.object({
4903
- properties: z15.record(z15.unknown())
5199
+ var UpsertObjectBodySchema = z16.object({
5200
+ properties: z16.record(z16.unknown())
4904
5201
  });
4905
- var ObjectQueryPredicateSchema = z15.lazy(() => z15.union([
4906
- z15.object({
4907
- op: z15.enum(["and", "or"]),
4908
- items: z15.array(ObjectQueryPredicateSchema)
5202
+ var ObjectQueryPredicateSchema = z16.lazy(() => z16.union([
5203
+ z16.object({
5204
+ op: z16.enum(["and", "or"]),
5205
+ items: z16.array(ObjectQueryPredicateSchema)
4909
5206
  }).strict(),
4910
- z15.object({
4911
- op: z15.literal("not"),
5207
+ z16.object({
5208
+ op: z16.literal("not"),
4912
5209
  item: ObjectQueryPredicateSchema
4913
5210
  }).strict(),
4914
- z15.object({
4915
- op: z15.enum(["eq", "neq", "lt", "lte", "gt", "gte"]),
4916
- propertyId: z15.string().min(1),
5211
+ z16.object({
5212
+ op: z16.enum(["eq", "neq", "lt", "lte", "gt", "gte"]),
5213
+ propertyId: z16.string().min(1),
4917
5214
  value: JsonValueSchema
4918
5215
  }).strict(),
4919
- z15.object({
4920
- op: z15.literal("in"),
4921
- propertyId: z15.string().min(1),
4922
- values: z15.array(JsonValueSchema)
5216
+ z16.object({
5217
+ op: z16.literal("in"),
5218
+ propertyId: z16.string().min(1),
5219
+ values: z16.array(JsonValueSchema)
4923
5220
  }).strict(),
4924
- z15.object({
4925
- op: z15.literal("exists"),
4926
- propertyId: z15.string().min(1),
4927
- value: z15.boolean()
5221
+ z16.object({
5222
+ op: z16.literal("exists"),
5223
+ propertyId: z16.string().min(1),
5224
+ value: z16.boolean()
4928
5225
  }).strict(),
4929
- z15.object({
4930
- op: z15.literal("contains"),
4931
- propertyId: z15.string().min(1),
5226
+ z16.object({
5227
+ op: z16.literal("contains"),
5228
+ propertyId: z16.string().min(1),
4932
5229
  value: JsonValueSchema
4933
5230
  }).strict()
4934
5231
  ]));
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()
5232
+ var ObjectQuerySortFieldSchema = z16.union([
5233
+ z16.object({
5234
+ kind: z16.literal("property"),
5235
+ propertyId: z16.string().min(1),
5236
+ direction: z16.enum(["asc", "desc"]).optional()
4940
5237
  }).strict(),
4941
- z15.object({
4942
- kind: z15.literal("relevance"),
4943
- direction: z15.enum(["asc", "desc"]).optional()
5238
+ z16.object({
5239
+ kind: z16.literal("relevance"),
5240
+ direction: z16.enum(["asc", "desc"]).optional()
4944
5241
  }).strict()
4945
5242
  ]);
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()
5243
+ var ObjectExpansionSchema = z16.lazy(() => z16.object({
5244
+ linkId: z16.string().min(1),
5245
+ direction: z16.enum(["outgoing", "incoming"]),
5246
+ sourceObjectTypeId: z16.string().min(1).optional(),
5247
+ limit: z16.number().int().nonnegative().optional(),
5248
+ orderBy: z16.array(ObjectQuerySortFieldSchema).optional(),
5249
+ expand: z16.array(ObjectExpansionSchema).optional()
4953
5250
  }).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()
5251
+ var ObjectQuerySchema = z16.lazy(() => z16.discriminatedUnion("kind", [
5252
+ z16.object({
5253
+ kind: z16.literal("start"),
5254
+ objectTypeId: z16.string().min(1),
5255
+ includeSubtypes: z16.boolean().optional()
4959
5256
  }).strict(),
4960
- z15.object({
4961
- kind: z15.literal("filter"),
5257
+ z16.object({
5258
+ kind: z16.literal("filter"),
4962
5259
  input: ObjectQuerySchema,
4963
5260
  predicate: ObjectQueryPredicateSchema
4964
5261
  }).strict(),
4965
- z15.object({
4966
- kind: z15.literal("text"),
5262
+ z16.object({
5263
+ kind: z16.literal("text"),
4967
5264
  input: ObjectQuerySchema,
4968
- query: z15.string(),
4969
- fields: z15.array(z15.string().min(1)).optional()
5265
+ query: z16.string(),
5266
+ fields: z16.array(z16.string().min(1)).optional()
4970
5267
  }).strict(),
4971
- z15.object({
4972
- kind: z15.literal("vector"),
5268
+ z16.object({
5269
+ kind: z16.literal("vector"),
4973
5270
  input: ObjectQuerySchema,
4974
- vector: z15.array(z15.number().finite()),
4975
- propertyId: z15.string().min(1),
4976
- k: z15.number().int().positive()
5271
+ vector: z16.array(z16.number().finite()),
5272
+ propertyId: z16.string().min(1),
5273
+ k: z16.number().int().positive()
4977
5274
  }).strict(),
4978
- z15.object({
4979
- kind: z15.literal("traverse"),
5275
+ z16.object({
5276
+ kind: z16.literal("traverse"),
4980
5277
  input: ObjectQuerySchema,
4981
- linkId: z15.string().min(1),
4982
- direction: z15.enum(["outgoing", "incoming"]),
4983
- sourceObjectTypeId: z15.string().min(1).optional()
5278
+ linkId: z16.string().min(1),
5279
+ direction: z16.enum(["outgoing", "incoming"]),
5280
+ sourceObjectTypeId: z16.string().min(1).optional()
4984
5281
  }).strict(),
4985
- z15.object({
4986
- kind: z15.literal("set"),
4987
- op: z15.enum(["union", "intersect", "subtract"]),
4988
- inputs: z15.array(ObjectQuerySchema)
5282
+ z16.object({
5283
+ kind: z16.literal("set"),
5284
+ op: z16.enum(["union", "intersect", "subtract"]),
5285
+ inputs: z16.array(ObjectQuerySchema)
4989
5286
  }).strict(),
4990
- z15.object({
4991
- kind: z15.literal("sort"),
5287
+ z16.object({
5288
+ kind: z16.literal("sort"),
4992
5289
  input: ObjectQuerySchema,
4993
- fields: z15.array(ObjectQuerySortFieldSchema)
5290
+ fields: z16.array(ObjectQuerySortFieldSchema)
4994
5291
  }).strict(),
4995
- z15.object({
4996
- kind: z15.literal("limit"),
5292
+ z16.object({
5293
+ kind: z16.literal("limit"),
4997
5294
  input: ObjectQuerySchema,
4998
- limit: z15.number().int().nonnegative()
5295
+ limit: z16.number().int().nonnegative()
4999
5296
  }).strict(),
5000
- z15.object({
5001
- kind: z15.literal("page"),
5297
+ z16.object({
5298
+ kind: z16.literal("page"),
5002
5299
  input: ObjectQuerySchema,
5003
- pageSize: z15.number().int().positive(),
5004
- pageToken: z15.string().optional()
5300
+ pageSize: z16.number().int().positive(),
5301
+ pageToken: z16.string().optional()
5005
5302
  }).strict(),
5006
- z15.object({
5007
- kind: z15.literal("project"),
5303
+ z16.object({
5304
+ kind: z16.literal("project"),
5008
5305
  input: ObjectQuerySchema,
5009
- properties: z15.array(z15.string().min(1)).optional()
5306
+ properties: z16.array(z16.string().min(1)).optional()
5010
5307
  }).strict(),
5011
- z15.object({
5012
- kind: z15.literal("expand"),
5308
+ z16.object({
5309
+ kind: z16.literal("expand"),
5013
5310
  input: ObjectQuerySchema,
5014
- expansions: z15.array(ObjectExpansionSchema)
5311
+ expansions: z16.array(ObjectExpansionSchema)
5015
5312
  }).strict()
5016
5313
  ]));
5017
- var ObjectQueryRequestSchema = z15.object({
5314
+ var ObjectQueryRequestSchema = z16.object({
5018
5315
  query: ObjectQuerySchema,
5019
- includeTotal: z15.boolean().optional()
5316
+ includeTotal: z16.boolean().optional()
5020
5317
  }).strict();
5021
- var ObjectQueryCountRequestSchema = z15.object({
5318
+ var ObjectQueryCountRequestSchema = z16.object({
5022
5319
  query: ObjectQuerySchema
5023
5320
  }).strict();
5024
- var ObjectQueryExistsRequestSchema = z15.object({
5321
+ var ObjectQueryExistsRequestSchema = z16.object({
5025
5322
  query: ObjectQuerySchema
5026
5323
  }).strict();
5027
- var ObjectQueryFacetRequestSchema = z15.object({
5028
- propertyId: z15.string().min(1),
5029
- limit: z15.number().int().positive()
5324
+ var ObjectQueryFacetRequestSchema = z16.object({
5325
+ propertyId: z16.string().min(1),
5326
+ limit: z16.number().int().positive()
5030
5327
  }).strict();
5031
- var ObjectQueryFacetsRequestSchema = z15.object({
5328
+ var ObjectQueryFacetsRequestSchema = z16.object({
5032
5329
  query: ObjectQuerySchema,
5033
- facets: z15.array(ObjectQueryFacetRequestSchema).min(1)
5330
+ facets: z16.array(ObjectQueryFacetRequestSchema).min(1)
5034
5331
  }).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()
5332
+ var TwinObjectSchema = z16.object({
5333
+ primaryId: z16.string(),
5334
+ objectTypeId: z16.string(),
5335
+ properties: z16.record(z16.unknown()),
5336
+ createdAt: z16.string(),
5337
+ updatedAt: z16.string()
5338
+ });
5339
+ var ObjectListResponseSchema = z16.object({
5340
+ objects: z16.array(TwinObjectSchema),
5341
+ hasMore: z16.boolean(),
5342
+ total: z16.number()
5046
5343
  });
5047
5344
  var anyJsonValueSchema = {};
5048
5345
  var stringArraySchema = { type: "array", items: { type: "string", minLength: 1 } };
@@ -5472,7 +5769,7 @@ var ObjectQueryOpenApiSchemas = {
5472
5769
 
5473
5770
  // src/routes/objects.ts
5474
5771
  var ObjectFileContentQuerySchema = FileContentQuerySchema.extend({
5475
- path: z16.string().min(1).regex(/^\/properties(?:\/|$)/, "Object file content paths must start with /properties/")
5772
+ path: z17.string().min(1).regex(/^\/properties(?:\/|$)/, "Object file content paths must start with /properties/")
5476
5773
  });
5477
5774
  function serializeObject(row) {
5478
5775
  return {
@@ -6129,111 +6426,111 @@ function registerOntologyRoutes(app, _host) {
6129
6426
  import {
6130
6427
  PIPELINE_RUN_FAILURE_CODES
6131
6428
  } from "@sixb/core/storage";
6132
- import { z as z17 } from "zod";
6429
+ import { z as z18 } from "zod";
6133
6430
  var PipelineRunFailureSchema = sixbFailureSchema(PIPELINE_RUN_FAILURE_CODES);
6134
- var PipelineParamsSchema = z17.object({
6135
- pipelineId: z17.string().min(1)
6431
+ var PipelineParamsSchema = z18.object({
6432
+ pipelineId: z18.string().min(1)
6136
6433
  });
6137
- var PipelineRunParamsSchema = z17.object({
6138
- runId: z17.string().min(1)
6434
+ var PipelineRunParamsSchema = z18.object({
6435
+ runId: z18.string().min(1)
6139
6436
  });
6140
- var PipelineRunStatusSchema = z17.enum([
6437
+ var PipelineRunStatusSchema = z18.enum([
6141
6438
  "queued",
6142
6439
  "running",
6143
6440
  "succeeded",
6144
6441
  "failed",
6145
6442
  "cancelled"
6146
6443
  ]);
6147
- var PipelineStepRunStatusSchema = z17.enum(["running", "succeeded", "failed", "cancelled"]);
6148
- var PipelineRunsQuerySchema = z17.object({
6149
- pipelineId: z17.string().optional(),
6444
+ var PipelineStepRunStatusSchema = z18.enum(["running", "succeeded", "failed", "cancelled"]);
6445
+ var PipelineRunsQuerySchema = z18.object({
6446
+ pipelineId: z18.string().optional(),
6150
6447
  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()
6156
- });
6157
- var DatasetVersionRefSchema2 = z17.object({
6158
- datasetId: z17.string(),
6159
- versionId: z17.string()
6160
- });
6161
- var PipelineTriggerSchema = z17.object({
6162
- type: z17.literal("schedule"),
6163
- scheduleId: z17.string()
6164
- });
6165
- var PipelineStepExecutorSchema = z17.union([
6166
- z17.object({
6167
- kind: z17.literal("sql"),
6168
- dialect: z17.literal("duckdb")
6448
+ startedAfter: z18.string().optional(),
6449
+ startedBefore: z18.string().optional(),
6450
+ limit: z18.string().optional(),
6451
+ offset: z18.string().optional(),
6452
+ order: z18.enum(["asc", "desc"]).optional()
6453
+ });
6454
+ var DatasetVersionRefSchema2 = z18.object({
6455
+ datasetId: z18.string(),
6456
+ versionId: z18.string()
6457
+ });
6458
+ var PipelineTriggerSchema = z18.object({
6459
+ type: z18.literal("schedule"),
6460
+ scheduleId: z18.string()
6461
+ });
6462
+ var PipelineStepExecutorSchema = z18.union([
6463
+ z18.object({
6464
+ kind: z18.literal("sql"),
6465
+ dialect: z18.literal("duckdb")
6169
6466
  }),
6170
- z17.object({
6171
- kind: z17.literal("run")
6467
+ z18.object({
6468
+ kind: z18.literal("run")
6172
6469
  })
6173
6470
  ]);
6174
- var PipelineRunSchema = z17.object({
6175
- id: z17.string(),
6176
- projectId: z17.string(),
6177
- pipelineId: z17.string(),
6471
+ var PipelineRunSchema = z18.object({
6472
+ id: z18.string(),
6473
+ projectId: z18.string(),
6474
+ pipelineId: z18.string(),
6178
6475
  status: PipelineRunStatusSchema,
6179
- queuedAt: z17.string(),
6180
- startedAt: z17.string().optional(),
6181
- finishedAt: z17.string().optional(),
6476
+ queuedAt: z18.string(),
6477
+ startedAt: z18.string().optional(),
6478
+ finishedAt: z18.string().optional(),
6182
6479
  output: DatasetVersionRefSchema2.optional(),
6183
6480
  error: PipelineRunFailureSchema.optional()
6184
6481
  });
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"]),
6482
+ var PipelineStepRunSchema = z18.object({
6483
+ id: z18.string(),
6484
+ projectId: z18.string(),
6485
+ pipelineRunId: z18.string(),
6486
+ pipelineId: z18.string(),
6487
+ stepId: z18.string(),
6488
+ datasetId: z18.string(),
6489
+ mode: z18.enum(["snapshot", "append"]),
6193
6490
  status: PipelineStepRunStatusSchema,
6194
- startedAt: z17.string(),
6195
- finishedAt: z17.string().optional(),
6196
- inputs: z17.array(DatasetVersionRefSchema2),
6491
+ startedAt: z18.string(),
6492
+ finishedAt: z18.string().optional(),
6493
+ inputs: z18.array(DatasetVersionRefSchema2),
6197
6494
  output: DatasetVersionRefSchema2.optional(),
6198
- rowsWritten: z17.number().optional(),
6495
+ rowsWritten: z18.number().optional(),
6199
6496
  error: PipelineRunFailureSchema.optional()
6200
6497
  });
6201
- var PipelineStepSchema = z17.object({
6202
- id: z17.string(),
6203
- mode: z17.enum(["snapshot", "append"]),
6498
+ var PipelineStepSchema = z18.object({
6499
+ id: z18.string(),
6500
+ mode: z18.enum(["snapshot", "append"]),
6204
6501
  executor: PipelineStepExecutorSchema,
6205
- inputs: z17.array(z17.object({
6206
- name: z17.string(),
6502
+ inputs: z18.array(z18.object({
6503
+ name: z18.string(),
6207
6504
  dataset: DatasetDefinitionSchema
6208
6505
  })),
6209
6506
  output: DatasetDefinitionSchema
6210
6507
  });
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"),
6508
+ var PipelineSchema = z18.object({
6509
+ id: z18.string(),
6510
+ triggers: z18.array(PipelineTriggerSchema),
6511
+ graph: z18.object({
6512
+ kind: z18.literal("sequence"),
6513
+ nodes: z18.array(z18.object({
6514
+ kind: z18.literal("step"),
6218
6515
  step: PipelineStepSchema
6219
6516
  }))
6220
6517
  }),
6221
6518
  latestRun: PipelineRunSchema.nullable()
6222
6519
  });
6223
- var PipelineRunListResponseSchema = z17.object({
6224
- runs: z17.array(PipelineRunSchema),
6225
- hasMore: z17.boolean(),
6226
- total: z17.number()
6520
+ var PipelineRunListResponseSchema = z18.object({
6521
+ runs: z18.array(PipelineRunSchema),
6522
+ hasMore: z18.boolean(),
6523
+ total: z18.number()
6227
6524
  });
6228
- var PipelineRunDetailResponseSchema = z17.object({
6525
+ var PipelineRunDetailResponseSchema = z18.object({
6229
6526
  run: PipelineRunSchema,
6230
- steps: z17.array(PipelineStepRunSchema)
6527
+ steps: z18.array(PipelineStepRunSchema)
6231
6528
  });
6232
- var RequestPipelineRunResponseSchema = z17.object({
6233
- runId: z17.string(),
6234
- jobId: z17.string(),
6235
- pipelineId: z17.string(),
6236
- queuedAt: z17.string()
6529
+ var RequestPipelineRunResponseSchema = z18.object({
6530
+ runId: z18.string(),
6531
+ jobId: z18.string(),
6532
+ pipelineId: z18.string(),
6533
+ queuedAt: z18.string()
6237
6534
  });
6238
6535
 
6239
6536
  // src/routes/pipelines.ts
@@ -6455,9 +6752,9 @@ function registerPipelineRoutes(app, host) {
6455
6752
  }
6456
6753
 
6457
6754
  // src/schemas/project.ts
6458
- import { z as z18 } from "zod";
6459
- var ProjectInfoResponseSchema = z18.object({
6460
- id: z18.string()
6755
+ import { z as z19 } from "zod";
6756
+ var ProjectInfoResponseSchema = z19.object({
6757
+ id: z19.string()
6461
6758
  });
6462
6759
 
6463
6760
  // src/routes/project.ts
@@ -6475,141 +6772,146 @@ function registerProjectRoutes(app, host) {
6475
6772
 
6476
6773
  // src/schemas/projections.ts
6477
6774
  import { PROJECTION_RUN_FAILURE_CODES } from "@sixb/core/storage";
6478
- import { z as z19 } from "zod";
6775
+ import { z as z20 } from "zod";
6479
6776
  var ProjectionRunFailureSchema = sixbFailureSchema(PROJECTION_RUN_FAILURE_CODES);
6480
- var ProjectionKindSchema = z19.enum(["object", "link", "telemetry"]);
6481
- var ProjectionRunStatusSchema = z19.enum([
6777
+ var ProjectionKindSchema = z20.enum(["object", "link", "telemetry"]);
6778
+ var ProjectionRunStatusSchema = z20.enum([
6482
6779
  "queued",
6483
6780
  "running",
6484
6781
  "succeeded",
6485
6782
  "failed",
6486
6783
  "cancelled"
6487
6784
  ]);
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()
6785
+ var ProjectionRunIdentityBaseSchema = z20.object({
6786
+ projectionId: z20.string(),
6787
+ datasetVersion: z20.object({
6788
+ datasetId: z20.string(),
6789
+ versionId: z20.string(),
6790
+ createdAt: z20.string()
6494
6791
  }),
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(),
6792
+ ontologyRevision: z20.string(),
6793
+ projectionRevision: z20.string(),
6794
+ ownershipHash: z20.string()
6795
+ });
6796
+ var ProjectionRunBaseSchema = z20.object({
6797
+ id: z20.string(),
6798
+ projectId: z20.string(),
6799
+ executionId: z20.string(),
6503
6800
  status: ProjectionRunStatusSchema,
6504
- attempt: z19.number(),
6505
- progress: z19.object({
6506
- sourceRowsRead: z19.number(),
6507
- sourceRowsSkipped: z19.number()
6801
+ attempt: z20.number(),
6802
+ progress: z20.object({
6803
+ sourceRowsRead: z20.number(),
6804
+ sourceRowsSkipped: z20.number()
6508
6805
  }),
6509
- queuedAt: z19.string(),
6510
- startedAt: z19.string().optional(),
6511
- finishedAt: z19.string().optional(),
6806
+ queuedAt: z20.string(),
6807
+ startedAt: z20.string().optional(),
6808
+ finishedAt: z20.string().optional(),
6512
6809
  error: ProjectionRunFailureSchema.optional()
6513
6810
  });
6514
6811
  var ObjectProjectionRunSchema = ProjectionRunBaseSchema.extend({
6515
6812
  identity: ProjectionRunIdentityBaseSchema.extend({
6516
- projectionKind: z19.literal("object"),
6517
- protocol: z19.literal("replacement")
6813
+ projectionKind: z20.literal("object"),
6814
+ protocol: z20.literal("replacement")
6518
6815
  }),
6519
- target: z19.object({ objectTypeId: z19.string() })
6816
+ target: z20.object({ objectTypeId: z20.string() })
6520
6817
  });
6521
6818
  var LinkProjectionRunSchema = ProjectionRunBaseSchema.extend({
6522
6819
  identity: ProjectionRunIdentityBaseSchema.extend({
6523
- projectionKind: z19.literal("link"),
6524
- protocol: z19.literal("replacement")
6820
+ projectionKind: z20.literal("link"),
6821
+ protocol: z20.literal("replacement")
6525
6822
  }),
6526
- target: z19.object({
6527
- sourceObjectTypeId: z19.string(),
6528
- targetObjectTypeId: z19.string()
6823
+ target: z20.object({
6824
+ sourceObjectTypeId: z20.string(),
6825
+ targetObjectTypeId: z20.string()
6529
6826
  })
6530
6827
  });
6531
6828
  var TelemetryProjectionRunSchema = ProjectionRunBaseSchema.extend({
6532
6829
  identity: ProjectionRunIdentityBaseSchema.extend({
6533
- projectionKind: z19.literal("telemetry"),
6534
- protocol: z19.literal("telemetry")
6830
+ projectionKind: z20.literal("telemetry"),
6831
+ protocol: z20.literal("telemetry")
6535
6832
  }),
6536
- target: z19.object({ objectTypeId: z19.string() })
6833
+ target: z20.object({ objectTypeId: z20.string() })
6537
6834
  });
6538
- var ProjectionRunSchema = z19.union([
6835
+ var ProjectionRunSchema = z20.union([
6539
6836
  ObjectProjectionRunSchema,
6540
6837
  LinkProjectionRunSchema,
6541
6838
  TelemetryProjectionRunSchema
6542
6839
  ]);
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),
6840
+ var ForeignKeyDescriptorSchema = z20.object({
6841
+ linkId: z20.string(),
6842
+ sourcePropertyId: z20.string().optional(),
6843
+ sourceField: z20.string().optional(),
6844
+ targetObjectTypeId: z20.string()
6845
+ });
6846
+ var SourceEditConflictResolutionSchema = z20.union([
6847
+ z20.object({ strategy: z20.literal("editsWin") }),
6848
+ z20.object({ strategy: z20.literal("mostRecent"), sourceTimestamp: z20.string() })
6849
+ ]);
6850
+ var ObjectProjectionSchema = z20.object({
6851
+ _tag: z20.literal("ObjectProjectionDefinition"),
6852
+ id: z20.string(),
6853
+ objectTypeId: z20.string(),
6854
+ datasetId: z20.string(),
6855
+ properties: z20.record(z20.string()),
6856
+ links: z20.record(ForeignKeyDescriptorSchema),
6857
+ conflictResolution: SourceEditConflictResolutionSchema,
6556
6858
  latestRun: ProjectionRunSchema.nullable()
6557
6859
  });
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(),
6860
+ var LinkProjectionSchema = z20.object({
6861
+ _tag: z20.literal("LinkProjectionDefinition"),
6862
+ id: z20.string(),
6863
+ linkId: z20.string(),
6864
+ sourceObjectTypeId: z20.string(),
6865
+ targetObjectTypeId: z20.string(),
6866
+ datasetId: z20.string(),
6867
+ sourceField: z20.string(),
6868
+ targetField: z20.string(),
6567
6869
  latestRun: ProjectionRunSchema.nullable()
6568
6870
  });
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(),
6871
+ var TelemetryProjectionSchema = z20.object({
6872
+ _tag: z20.literal("TelemetryProjectionDefinition"),
6873
+ id: z20.string(),
6874
+ objectTypeId: z20.string(),
6875
+ propertyId: z20.string(),
6876
+ datasetId: z20.string(),
6877
+ objectIdField: z20.string(),
6878
+ atField: z20.string(),
6879
+ valueField: z20.string(),
6880
+ unitField: z20.string().optional(),
6579
6881
  latestRun: ProjectionRunSchema.nullable()
6580
6882
  });
6581
- var ProjectionListResponseSchema = z19.object({
6582
- objectProjections: z19.array(ObjectProjectionSchema),
6583
- linkProjections: z19.array(LinkProjectionSchema),
6584
- telemetryProjections: z19.array(TelemetryProjectionSchema)
6883
+ var ProjectionListResponseSchema = z20.object({
6884
+ objectProjections: z20.array(ObjectProjectionSchema),
6885
+ linkProjections: z20.array(LinkProjectionSchema),
6886
+ telemetryProjections: z20.array(TelemetryProjectionSchema)
6585
6887
  });
6586
- var ProjectionParamsSchema = z19.object({
6587
- projectionId: z19.string().min(1)
6888
+ var ProjectionParamsSchema = z20.object({
6889
+ projectionId: z20.string().min(1)
6588
6890
  });
6589
- var ProjectionResponseSchema = z19.union([
6891
+ var ProjectionResponseSchema = z20.union([
6590
6892
  ObjectProjectionSchema,
6591
6893
  LinkProjectionSchema,
6592
6894
  TelemetryProjectionSchema
6593
6895
  ]);
6594
- var ProjectionRunParamsSchema = z19.object({
6595
- runId: z19.string().min(1)
6896
+ var ProjectionRunParamsSchema = z20.object({
6897
+ runId: z20.string().min(1)
6596
6898
  });
6597
- var ProjectionRunsQuerySchema = z19.object({
6598
- projectionId: z19.string().optional(),
6899
+ var ProjectionRunsQuerySchema = z20.object({
6900
+ projectionId: z20.string().optional(),
6599
6901
  projectionKind: ProjectionKindSchema.optional(),
6600
- datasetId: z19.string().optional(),
6601
- datasetVersionId: z19.string().optional(),
6902
+ datasetId: z20.string().optional(),
6903
+ datasetVersionId: z20.string().optional(),
6602
6904
  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()
6905
+ startedAfter: z20.string().optional(),
6906
+ startedBefore: z20.string().optional(),
6907
+ limit: z20.string().optional(),
6908
+ offset: z20.string().optional(),
6909
+ order: z20.enum(["asc", "desc"]).optional()
6608
6910
  });
6609
- var ProjectionRunListResponseSchema = z19.object({
6610
- runs: z19.array(ProjectionRunSchema),
6611
- hasMore: z19.boolean(),
6612
- total: z19.number()
6911
+ var ProjectionRunListResponseSchema = z20.object({
6912
+ runs: z20.array(ProjectionRunSchema),
6913
+ hasMore: z20.boolean(),
6914
+ total: z20.number()
6613
6915
  });
6614
6916
 
6615
6917
  // src/routes/projections.ts
@@ -6651,10 +6953,15 @@ function projectionCatalogIds(catalog) {
6651
6953
  ].map((projection) => projection.id);
6652
6954
  }
6653
6955
  function serializeProjection(projection, latestRuns) {
6654
- return {
6655
- ...projection,
6656
- latestRun: latestRuns.get(projection.id) ?? null
6657
- };
6956
+ const latestRun = latestRuns.get(projection.id) ?? null;
6957
+ if (projection._tag === "ObjectProjectionDefinition") {
6958
+ return {
6959
+ ...projection,
6960
+ conflictResolution: projection.conflictResolution ?? { strategy: "editsWin" },
6961
+ latestRun
6962
+ };
6963
+ }
6964
+ return { ...projection, latestRun };
6658
6965
  }
6659
6966
  function serializeProjectionCatalog(catalog, latestRuns) {
6660
6967
  return {
@@ -6772,88 +7079,88 @@ function registerProjectionRoutes(app, host) {
6772
7079
  import { deriveRuleEventDependencies } from "@sixb/core/internal/rules";
6773
7080
 
6774
7081
  // 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"]),
7082
+ import { z as z21 } from "zod";
7083
+ var RuleParamsSchema = z21.object({
7084
+ ruleId: z21.string().min(1)
7085
+ });
7086
+ var RuleStatesQuerySchema = z21.object({
7087
+ ruleId: z21.string().optional(),
7088
+ objectTypeId: z21.string().optional(),
7089
+ primaryId: z21.string().optional(),
7090
+ limit: z21.string().optional(),
7091
+ offset: z21.string().optional(),
7092
+ order: z21.enum(["asc", "desc"]).optional()
7093
+ });
7094
+ var RuleValueSchema = z21.union([z21.string(), z21.number(), z21.boolean()]).nullable();
7095
+ var RuleSubjectSchema = z21.object({
7096
+ kind: z21.literal("object"),
7097
+ objectTypeId: z21.string()
7098
+ });
7099
+ var RuleEventSubjectSchema = z21.object({
7100
+ kind: z21.literal("object"),
7101
+ objectTypeId: z21.string(),
7102
+ primaryId: z21.string()
7103
+ });
7104
+ var RulePropertyPredicateSchema = z21.object({
7105
+ kind: z21.literal("property"),
7106
+ propertyId: z21.string(),
7107
+ op: z21.enum(["eq", "notEq", "gt", "gte", "lt", "lte", "isPresent", "isMissing"]),
6801
7108
  value: RuleValueSchema.optional()
6802
7109
  });
6803
- var RuleLinkPredicateSchema = z20.object({
6804
- kind: z20.literal("link"),
6805
- linkId: z20.string(),
6806
- op: z20.enum(["exists", "isMissing"])
7110
+ var RuleLinkPredicateSchema = z21.object({
7111
+ kind: z21.literal("link"),
7112
+ linkId: z21.string(),
7113
+ op: z21.enum(["exists", "isMissing"])
6807
7114
  });
6808
7115
  function createRulePredicateSchema(childPredicateSchema) {
6809
- return z20.union([
6810
- z20.object({
6811
- kind: z20.literal("all"),
6812
- predicates: z20.array(childPredicateSchema)
7116
+ return z21.union([
7117
+ z21.object({
7118
+ kind: z21.literal("all"),
7119
+ predicates: z21.array(childPredicateSchema)
6813
7120
  }),
6814
- z20.object({
6815
- kind: z20.literal("any"),
6816
- predicates: z20.array(childPredicateSchema)
7121
+ z21.object({
7122
+ kind: z21.literal("any"),
7123
+ predicates: z21.array(childPredicateSchema)
6817
7124
  }),
6818
- z20.object({
6819
- kind: z20.literal("not"),
7125
+ z21.object({
7126
+ kind: z21.literal("not"),
6820
7127
  predicate: childPredicateSchema
6821
7128
  }),
6822
7129
  RulePropertyPredicateSchema,
6823
7130
  RuleLinkPredicateSchema
6824
7131
  ]);
6825
7132
  }
6826
- var DeepRulePredicateSchema = createRulePredicateSchema(z20.unknown());
7133
+ var DeepRulePredicateSchema = createRulePredicateSchema(z21.unknown());
6827
7134
  var NestedRulePredicateSchema = createRulePredicateSchema(DeepRulePredicateSchema);
6828
7135
  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()
7136
+ var RuleEventDependencySchema = z21.union([
7137
+ z21.object({
7138
+ type: z21.enum(["object.created", "object.updated", "object.deleted"]),
7139
+ objectTypeId: z21.string()
6833
7140
  }),
6834
- z20.object({
6835
- type: z20.enum(["link.created", "link.updated", "link.deleted"]),
6836
- sourceTypeId: z20.string(),
6837
- linkId: z20.string()
7141
+ z21.object({
7142
+ type: z21.enum(["link.created", "link.updated", "link.deleted"]),
7143
+ sourceTypeId: z21.string(),
7144
+ linkId: z21.string()
6838
7145
  })
6839
7146
  ]);
6840
- var RuleSchema = z20.object({
6841
- kind: z20.literal("rule"),
6842
- id: z20.string(),
7147
+ var RuleSchema = z21.object({
7148
+ kind: z21.literal("rule"),
7149
+ id: z21.string(),
6843
7150
  subject: RuleSubjectSchema,
6844
7151
  predicate: RulePredicateSchema,
6845
- dependencies: z20.array(RuleEventDependencySchema)
7152
+ dependencies: z21.array(RuleEventDependencySchema)
6846
7153
  });
6847
- var RuleStateSchema = z20.object({
6848
- projectId: z20.string(),
6849
- ruleId: z20.string(),
7154
+ var RuleStateSchema = z21.object({
7155
+ projectId: z21.string(),
7156
+ ruleId: z21.string(),
6850
7157
  subject: RuleEventSubjectSchema,
6851
- triggeredAt: z20.string()
7158
+ triggeredAt: z21.string()
6852
7159
  });
6853
- var RuleStateListResponseSchema = z20.object({
6854
- states: z20.array(RuleStateSchema),
6855
- hasMore: z20.boolean(),
6856
- total: z20.number()
7160
+ var RuleStateListResponseSchema = z21.object({
7161
+ states: z21.array(RuleStateSchema),
7162
+ hasMore: z21.boolean(),
7163
+ total: z21.number()
6857
7164
  });
6858
7165
 
6859
7166
  // src/routes/rules.ts
@@ -6933,44 +7240,44 @@ function registerRuleRoutes(app, host) {
6933
7240
  }
6934
7241
 
6935
7242
  // 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()
7243
+ import { z as z22 } from "zod";
7244
+ var HealthResponseSchema = z22.object({ status: z22.literal("ok") });
7245
+ var StorageReadinessSchema = z22.object({
7246
+ reachable: z22.boolean(),
7247
+ schemaValid: z22.boolean()
6941
7248
  });
6942
- var ReadinessResponseSchema = z21.object({
6943
- status: z21.enum(["ready", "unready"]),
7249
+ var ReadinessResponseSchema = z22.object({
7250
+ status: z22.enum(["ready", "unready"]),
6944
7251
  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()
7252
+ reason: z22.string().optional()
7253
+ });
7254
+ var MaintenanceSummarySchema = z22.object({
7255
+ running: z22.boolean(),
7256
+ intervalMs: z22.number().int().positive(),
7257
+ lastStartedAt: z22.string().nullable(),
7258
+ lastCompletedAt: z22.string().nullable(),
7259
+ lastDurationMs: z22.number().nonnegative().nullable(),
7260
+ consecutiveFailures: z22.number().int().nonnegative(),
7261
+ lastError: z22.string().nullable(),
7262
+ outbox: z22.object({
7263
+ pendingCount: z22.number().int().nonnegative(),
7264
+ oldestPendingAt: z22.string().nullable(),
7265
+ retryingCount: z22.number().int().nonnegative(),
7266
+ maxAttempts: z22.number().int().nonnegative()
6960
7267
  }).nullable(),
6961
- terminalSources: z21.object({
6962
- count: z21.number().int().nonnegative(),
6963
- oldestTerminalAt: z21.string().nullable()
7268
+ terminalSources: z22.object({
7269
+ count: z22.number().int().nonnegative(),
7270
+ oldestTerminalAt: z22.string().nullable()
6964
7271
  }).nullable(),
6965
- cleanup: z21.object({
6966
- publishedOutboxRowsDeleted: z21.number().int().nonnegative(),
6967
- terminalSourceRowsDeleted: z21.number().int().nonnegative(),
6968
- terminalSourceMaterializationsDeleted: z21.number().int().nonnegative()
7272
+ cleanup: z22.object({
7273
+ publishedOutboxRowsDeleted: z22.number().int().nonnegative(),
7274
+ terminalSourceRowsDeleted: z22.number().int().nonnegative(),
7275
+ terminalSourceMaterializationsDeleted: z22.number().int().nonnegative()
6969
7276
  }).nullable()
6970
7277
  });
6971
- var StatusResponseSchema = z21.object({
6972
- status: z21.enum(["ok", "degraded"]),
6973
- objectTypes: z21.number().int().nonnegative(),
7278
+ var StatusResponseSchema = z22.object({
7279
+ status: z22.enum(["ok", "degraded"]),
7280
+ objectTypes: z22.number().int().nonnegative(),
6974
7281
  maintenance: MaintenanceSummarySchema
6975
7282
  });
6976
7283
 
@@ -7016,74 +7323,74 @@ function registerStatusRoutes(app, host) {
7016
7323
  import {
7017
7324
  SYNC_RUN_FAILURE_CODES
7018
7325
  } from "@sixb/core/storage";
7019
- import { z as z22 } from "zod";
7326
+ import { z as z23 } from "zod";
7020
7327
  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(),
7328
+ var SyncParamsSchema = z23.object({
7329
+ syncId: z23.string().min(1)
7330
+ });
7331
+ var SyncRunStatusSchema = z23.enum(["queued", "running", "succeeded", "failed", "cancelled"]);
7332
+ var SyncModeSchema = z23.enum(["snapshot", "append", "merge"]);
7333
+ var SyncRunsQuerySchema = z23.object({
7334
+ syncId: z23.string().optional(),
7335
+ datasetId: z23.string().optional(),
7029
7336
  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()
7035
- });
7036
- var RequestSyncRunBodySchema = z22.object({
7037
- expectedLatestVersionId: z22.string().optional(),
7038
- commitMessage: z22.string().optional()
7039
- });
7040
- var SyncTriggerSchema = z22.object({
7041
- type: z22.literal("schedule"),
7042
- scheduleId: z22.string()
7043
- });
7044
- var SyncRunSchema = z22.object({
7045
- id: z22.string(),
7046
- projectId: z22.string(),
7047
- syncId: z22.string(),
7048
- datasetId: z22.string(),
7337
+ startedAfter: z23.string().optional(),
7338
+ startedBefore: z23.string().optional(),
7339
+ limit: z23.string().optional(),
7340
+ offset: z23.string().optional(),
7341
+ order: z23.enum(["asc", "desc"]).optional()
7342
+ });
7343
+ var RequestSyncRunBodySchema = z23.object({
7344
+ expectedLatestVersionId: z23.string().optional(),
7345
+ commitMessage: z23.string().optional()
7346
+ });
7347
+ var SyncTriggerSchema = z23.object({
7348
+ type: z23.literal("schedule"),
7349
+ scheduleId: z23.string()
7350
+ });
7351
+ var SyncRunSchema = z23.object({
7352
+ id: z23.string(),
7353
+ projectId: z23.string(),
7354
+ syncId: z23.string(),
7355
+ datasetId: z23.string(),
7049
7356
  mode: SyncModeSchema,
7050
7357
  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()
7358
+ queuedAt: z23.string(),
7359
+ startedAt: z23.string().optional(),
7360
+ finishedAt: z23.string().optional(),
7361
+ rowsRead: z23.number().optional(),
7362
+ output: z23.object({
7363
+ datasetId: z23.string(),
7364
+ versionId: z23.string()
7058
7365
  }).optional(),
7059
- expectedLatestVersionId: z22.string().optional(),
7060
- commitMessage: z22.string().optional(),
7366
+ expectedLatestVersionId: z23.string().optional(),
7367
+ commitMessage: z23.string().optional(),
7061
7368
  error: SyncRunFailureSchema.optional()
7062
7369
  });
7063
- var SyncSchema = z22.object({
7064
- id: z22.string(),
7370
+ var SyncSchema = z23.object({
7371
+ id: z23.string(),
7065
7372
  mode: SyncModeSchema,
7066
- connector: z22.object({
7067
- id: z22.string(),
7068
- type: z22.string()
7373
+ connector: z23.object({
7374
+ id: z23.string(),
7375
+ type: z23.string()
7069
7376
  }),
7070
- target: z22.object({
7071
- kind: z22.literal("dataset"),
7377
+ target: z23.object({
7378
+ kind: z23.literal("dataset"),
7072
7379
  dataset: DatasetDefinitionSchema
7073
7380
  }),
7074
- triggers: z22.array(SyncTriggerSchema),
7381
+ triggers: z23.array(SyncTriggerSchema),
7075
7382
  latestRun: SyncRunSchema.nullable()
7076
7383
  });
7077
- var SyncRunListResponseSchema = z22.object({
7078
- runs: z22.array(SyncRunSchema),
7079
- hasMore: z22.boolean(),
7080
- total: z22.number()
7384
+ var SyncRunListResponseSchema = z23.object({
7385
+ runs: z23.array(SyncRunSchema),
7386
+ hasMore: z23.boolean(),
7387
+ total: z23.number()
7081
7388
  });
7082
- var RequestSyncRunResponseSchema = z22.object({
7083
- runId: z22.string(),
7084
- jobId: z22.string(),
7085
- syncId: z22.string(),
7086
- queuedAt: z22.string()
7389
+ var RequestSyncRunResponseSchema = z23.object({
7390
+ runId: z23.string(),
7391
+ jobId: z23.string(),
7392
+ syncId: z23.string(),
7393
+ queuedAt: z23.string()
7087
7394
  });
7088
7395
 
7089
7396
  // src/routes/syncs.ts
@@ -7237,52 +7544,52 @@ function registerSyncRoutes(app, host) {
7237
7544
  }
7238
7545
 
7239
7546
  // 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()
7547
+ import { z as z24 } from "zod";
7548
+ var TelemetryParamsSchema = z24.object({
7549
+ objectTypeId: z24.string().min(1),
7550
+ objectId: z24.string().min(1),
7551
+ propertyId: z24.string().min(1)
7552
+ });
7553
+ var TelemetryHistoryQuerySchema = z24.object({
7554
+ from: z24.string().optional(),
7555
+ to: z24.string().optional(),
7556
+ limit: z24.string().optional(),
7557
+ order: z24.enum(["asc", "desc"]).optional()
7251
7558
  });
7252
- var BulkTelemetryHistorySeriesInputSchema = z23.object({
7253
- objectTypeId: z23.string().min(1),
7254
- objectId: z23.string().min(1),
7255
- propertyId: z23.string().min(1)
7559
+ var BulkTelemetryHistorySeriesInputSchema = z24.object({
7560
+ objectTypeId: z24.string().min(1),
7561
+ objectId: z24.string().min(1),
7562
+ propertyId: z24.string().min(1)
7256
7563
  }).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()
7564
+ var BulkTelemetryHistoryBodySchema = z24.object({
7565
+ series: z24.array(BulkTelemetryHistorySeriesInputSchema).min(1),
7566
+ from: z24.string().optional(),
7567
+ to: z24.string().optional(),
7568
+ limitPerSeries: z24.number().int().nonnegative().optional(),
7569
+ order: z24.enum(["asc", "desc"]).optional()
7263
7570
  }).strict();
7264
- var AppendTelemetryBodySchema = z23.object({
7265
- value: z23.unknown(),
7266
- unit: z23.string().optional(),
7267
- at: z23.string().optional()
7571
+ var AppendTelemetryBodySchema = z24.object({
7572
+ value: z24.unknown(),
7573
+ unit: z24.string().optional(),
7574
+ at: z24.string().optional()
7268
7575
  });
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)
7576
+ var TelemetryPointSchema = z24.object({
7577
+ projectId: z24.string(),
7578
+ objectTypeId: z24.string(),
7579
+ objectId: z24.string(),
7580
+ propertyId: z24.string(),
7581
+ value: z24.unknown(),
7582
+ unit: z24.string().optional(),
7583
+ at: z24.string()
7584
+ });
7585
+ var BulkTelemetryHistorySeriesSchema = z24.object({
7586
+ objectTypeId: z24.string(),
7587
+ objectId: z24.string(),
7588
+ propertyId: z24.string(),
7589
+ points: z24.array(TelemetryPointSchema)
7590
+ });
7591
+ var BulkTelemetryHistoryResponseSchema = z24.object({
7592
+ series: z24.array(BulkTelemetryHistorySeriesSchema)
7286
7593
  });
7287
7594
 
7288
7595
  // src/routes/telemetry.ts
@@ -7440,40 +7747,40 @@ function registerTelemetryRoutes(app, _host) {
7440
7747
 
7441
7748
  // src/schemas/webhook-runs.ts
7442
7749
  import { WEBHOOK_RUN_FAILURE_CODES } from "@sixb/core/storage";
7443
- import { z as z24 } from "zod";
7750
+ import { z as z25 } from "zod";
7444
7751
  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(),
7752
+ var WebhookRunStatusSchema = z25.enum(["running", "succeeded", "failed"]);
7753
+ var WebhookRunsQuerySchema = z25.object({
7754
+ connectorId: z25.string().optional(),
7755
+ webhookId: z25.string().optional(),
7449
7756
  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()
7757
+ idempotencyKey: z25.string().optional(),
7758
+ startedAfter: z25.string().optional(),
7759
+ startedBefore: z25.string().optional(),
7760
+ limit: z25.string().optional(),
7761
+ offset: z25.string().optional(),
7762
+ order: z25.enum(["asc", "desc"]).optional()
7456
7763
  });
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(),
7764
+ var WebhookRunSchema = z25.object({
7765
+ id: z25.string(),
7766
+ projectId: z25.string(),
7767
+ executionId: z25.string(),
7768
+ connectorId: z25.string(),
7769
+ webhookId: z25.string(),
7463
7770
  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(),
7771
+ method: z25.string(),
7772
+ route: z25.string(),
7773
+ startedAt: z25.string(),
7774
+ finishedAt: z25.string().optional(),
7775
+ requestBodyBytes: z25.number(),
7776
+ responseStatus: z25.number().optional(),
7777
+ idempotencyKey: z25.string().optional(),
7471
7778
  error: WebhookRunFailureSchema.optional()
7472
7779
  });
7473
- var WebhookRunListResponseSchema = z24.object({
7474
- runs: z24.array(WebhookRunSchema),
7475
- hasMore: z24.boolean(),
7476
- total: z24.number()
7780
+ var WebhookRunListResponseSchema = z25.object({
7781
+ runs: z25.array(WebhookRunSchema),
7782
+ hasMore: z25.boolean(),
7783
+ total: z25.number()
7477
7784
  });
7478
7785
 
7479
7786
  // src/routes/webhook-runs.ts
@@ -7548,25 +7855,25 @@ import {
7548
7855
  snapshotWorkflowInterventionResponse
7549
7856
  } from "@sixb/core/internal/workflows";
7550
7857
  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";
7858
+ import { z as z27 } from "zod";
7552
7859
 
7553
7860
  // src/schemas/workflows.ts
7554
7861
  import {
7555
7862
  WORKFLOW_RUN_FAILURE_CODES
7556
7863
  } from "@sixb/core/storage";
7557
- import { z as z25 } from "zod";
7558
- var WorkflowIOSnapshotSchema = z25.record(JsonValueSchema);
7864
+ import { z as z26 } from "zod";
7865
+ var WorkflowIOSnapshotSchema = z26.record(JsonValueSchema);
7559
7866
  var WorkflowRunFailureSchema = sixbFailureSchema(WORKFLOW_RUN_FAILURE_CODES);
7560
- var WorkflowParamsSchema = z25.object({
7561
- workflowId: z25.string().min(1)
7867
+ var WorkflowParamsSchema = z26.object({
7868
+ workflowId: z26.string().min(1)
7562
7869
  });
7563
- var WorkflowRunParamsSchema = z25.object({
7564
- runId: z25.string().min(1)
7870
+ var WorkflowRunParamsSchema = z26.object({
7871
+ runId: z26.string().min(1)
7565
7872
  });
7566
- var WorkflowInterventionParamsSchema = z25.object({
7567
- interventionId: z25.string().min(1)
7873
+ var WorkflowInterventionParamsSchema = z26.object({
7874
+ interventionId: z26.string().min(1)
7568
7875
  });
7569
- var WorkflowRunStatusSchema = z25.enum([
7876
+ var WorkflowRunStatusSchema = z26.enum([
7570
7877
  "queued",
7571
7878
  "running",
7572
7879
  "waiting",
@@ -7574,91 +7881,91 @@ var WorkflowRunStatusSchema = z25.enum([
7574
7881
  "failed",
7575
7882
  "cancelled"
7576
7883
  ]);
7577
- var WorkflowInterventionStatusSchema = z25.enum([
7884
+ var WorkflowInterventionStatusSchema = z26.enum([
7578
7885
  "pending",
7579
7886
  "submitted",
7580
7887
  "cancelled",
7581
7888
  "expired"
7582
7889
  ]);
7583
- var WorkflowRunsQuerySchema = z25.object({
7584
- workflowId: z25.string().optional(),
7890
+ var WorkflowRunsQuerySchema = z26.object({
7891
+ workflowId: z26.string().optional(),
7585
7892
  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()
7591
- });
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(),
7893
+ startedAfter: z26.string().optional(),
7894
+ startedBefore: z26.string().optional(),
7895
+ limit: z26.string().optional(),
7896
+ offset: z26.string().optional(),
7897
+ order: z26.enum(["asc", "desc"]).optional()
7898
+ });
7899
+ var WorkflowInterventionsQuerySchema = z26.object({
7900
+ workflowId: z26.string().optional(),
7901
+ workflowRunId: z26.string().optional(),
7902
+ nodeRunId: z26.string().optional(),
7903
+ nodeId: z26.string().optional(),
7904
+ nodeKey: z26.string().optional(),
7905
+ interventionId: z26.string().optional(),
7599
7906
  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()
7907
+ requestedAfter: z26.string().optional(),
7908
+ requestedBefore: z26.string().optional(),
7909
+ limit: z26.string().optional(),
7910
+ offset: z26.string().optional(),
7911
+ order: z26.enum(["asc", "desc"]).optional()
7605
7912
  });
7606
- var RequestWorkflowRunBodySchema = z25.object({
7913
+ var RequestWorkflowRunBodySchema = z26.object({
7607
7914
  input: WorkflowIOSnapshotSchema.optional()
7608
7915
  }).default({});
7609
- var WorkflowInterventionActorSchema = z25.object({
7610
- principalType: z25.enum(["user", "serviceAccount", "system"]),
7611
- principalId: z25.string().min(1)
7916
+ var WorkflowInterventionActorSchema = z26.object({
7917
+ principalType: z26.enum(["user", "serviceAccount", "system"]),
7918
+ principalId: z26.string().min(1)
7612
7919
  });
7613
- var CancelWorkflowRunBodySchema = z25.object({}).default({});
7614
- var SubmitWorkflowInterventionBodySchema = z25.object({
7920
+ var CancelWorkflowRunBodySchema = z26.object({}).default({});
7921
+ var SubmitWorkflowInterventionBodySchema = z26.object({
7615
7922
  response: WorkflowIOSnapshotSchema
7616
7923
  });
7617
- var CancelWorkflowInterventionBodySchema = z25.object({}).default({});
7618
- var WorkflowTriggerSchema = z25.object({
7619
- type: z25.literal("schedule"),
7620
- scheduleId: z25.string()
7924
+ var CancelWorkflowInterventionBodySchema = z26.object({}).default({});
7925
+ var WorkflowTriggerSchema = z26.object({
7926
+ type: z26.literal("schedule"),
7927
+ scheduleId: z26.string()
7621
7928
  });
7622
- var WorkflowNodeSchema = z25.union([
7623
- z25.object({
7624
- type: z25.literal("step"),
7625
- id: z25.string(),
7626
- key: z25.string(),
7929
+ var WorkflowNodeSchema = z26.union([
7930
+ z26.object({
7931
+ type: z26.literal("step"),
7932
+ id: z26.string(),
7933
+ key: z26.string(),
7627
7934
  input: WorkflowIOSnapshotSchema,
7628
7935
  output: WorkflowIOSnapshotSchema
7629
7936
  }),
7630
- z25.object({
7631
- type: z25.literal("action"),
7632
- id: z25.string(),
7633
- key: z25.string(),
7634
- objectTypeId: z25.string().optional(),
7937
+ z26.object({
7938
+ type: z26.literal("action"),
7939
+ id: z26.string(),
7940
+ key: z26.string(),
7941
+ objectTypeId: z26.string().optional(),
7635
7942
  params: WorkflowIOSnapshotSchema
7636
7943
  }),
7637
- z25.object({
7638
- type: z25.literal("intervention"),
7639
- id: z25.string(),
7640
- key: z25.string(),
7944
+ z26.object({
7945
+ type: z26.literal("intervention"),
7946
+ id: z26.string(),
7947
+ key: z26.string(),
7641
7948
  input: WorkflowIOSnapshotSchema,
7642
7949
  response: WorkflowIOSnapshotSchema,
7643
- description: z25.string().optional()
7950
+ description: z26.string().optional()
7644
7951
  }),
7645
- z25.object({
7646
- type: z25.literal("agent"),
7647
- id: z25.string(),
7648
- key: z25.string(),
7649
- agentId: z25.string(),
7952
+ z26.object({
7953
+ type: z26.literal("agent"),
7954
+ id: z26.string(),
7955
+ key: z26.string(),
7956
+ agentId: z26.string(),
7650
7957
  input: WorkflowIOSnapshotSchema,
7651
7958
  output: WorkflowIOSnapshotSchema
7652
7959
  })
7653
7960
  ]);
7654
- var WorkflowRunSummarySchema = z25.object({
7655
- id: z25.string(),
7656
- projectId: z25.string(),
7657
- workflowId: z25.string(),
7961
+ var WorkflowRunSummarySchema = z26.object({
7962
+ id: z26.string(),
7963
+ projectId: z26.string(),
7964
+ workflowId: z26.string(),
7658
7965
  status: WorkflowRunStatusSchema,
7659
- queuedAt: z25.string().optional(),
7660
- startedAt: z25.string(),
7661
- finishedAt: z25.string().optional(),
7966
+ queuedAt: z26.string().optional(),
7967
+ startedAt: z26.string(),
7968
+ finishedAt: z26.string().optional(),
7662
7969
  error: WorkflowRunFailureSchema.optional(),
7663
7970
  requestedBy: WorkflowInterventionActorSchema
7664
7971
  });
@@ -7666,108 +7973,111 @@ var WorkflowRunDetailSchema = WorkflowRunSummarySchema.extend({
7666
7973
  input: WorkflowIOSnapshotSchema,
7667
7974
  output: WorkflowIOSnapshotSchema.optional()
7668
7975
  });
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(),
7976
+ var WorkflowAgentNodeExecutionSummarySchema = z26.object({
7977
+ agentId: z26.string(),
7978
+ status: z26.enum(["queued", "running", "succeeded", "failed", "cancelled"]),
7979
+ attempt: z26.number().int().nonnegative(),
7980
+ modelId: z26.string().optional(),
7981
+ finishReason: z26.string().optional(),
7675
7982
  usage: AiUsageSummarySchema.optional(),
7676
- startedAt: z25.string().optional(),
7677
- completedAt: z25.string().optional()
7983
+ cost: AiCostSummarySchema.optional(),
7984
+ startedAt: z26.string().optional(),
7985
+ completedAt: z26.string().optional()
7678
7986
  });
7987
+ var WorkflowAgentFailurePhaseSchema = z26.enum(["agent-loop", "structured-finalizer"]);
7679
7988
  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(),
7989
+ nodeRunId: z26.string(),
7990
+ prompt: z26.string(),
7991
+ trace: z26.array(AgentMessagePartSchema).optional(),
7992
+ diagnostics: z26.array(JsonValueSchema).optional(),
7993
+ failurePhase: WorkflowAgentFailurePhaseSchema.optional(),
7684
7994
  error: AgentRunFailureSchema.optional(),
7685
- createdAt: z25.string()
7686
- });
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"]),
7995
+ createdAt: z26.string()
7996
+ });
7997
+ var WorkflowNodeRunSchema = z26.object({
7998
+ id: z26.string(),
7999
+ projectId: z26.string(),
8000
+ workflowRunId: z26.string(),
8001
+ workflowId: z26.string(),
8002
+ nodeIndex: z26.number(),
8003
+ nodeType: z26.enum(["step", "action", "intervention", "agent"]),
8004
+ nodeId: z26.string(),
8005
+ nodeKey: z26.string(),
8006
+ status: z26.enum(["running", "waiting", "succeeded", "failed", "cancelled"]),
7697
8007
  input: WorkflowIOSnapshotSchema,
7698
- startedAt: z25.string(),
7699
- finishedAt: z25.string().optional(),
8008
+ startedAt: z26.string(),
8009
+ finishedAt: z26.string().optional(),
7700
8010
  output: WorkflowIOSnapshotSchema.optional(),
7701
8011
  error: WorkflowRunFailureSchema.optional(),
7702
8012
  agentExecution: WorkflowAgentNodeExecutionSummarySchema.optional()
7703
8013
  });
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(),
8014
+ var WorkflowInterventionSchema = z26.object({
8015
+ id: z26.string(),
8016
+ projectId: z26.string(),
8017
+ workflowId: z26.string(),
8018
+ workflowRunId: z26.string(),
8019
+ nodeRunId: z26.string(),
8020
+ nodeIndex: z26.number(),
8021
+ nodeId: z26.string(),
8022
+ nodeKey: z26.string(),
8023
+ interventionId: z26.string(),
7714
8024
  input: WorkflowIOSnapshotSchema,
7715
8025
  defaultResponse: WorkflowIOSnapshotSchema,
7716
8026
  status: WorkflowInterventionStatusSchema,
7717
- requestedAt: z25.string(),
7718
- expiresAt: z25.string().optional(),
7719
- submittedAt: z25.string().optional(),
8027
+ requestedAt: z26.string(),
8028
+ expiresAt: z26.string().optional(),
8029
+ submittedAt: z26.string().optional(),
7720
8030
  submittedBy: WorkflowInterventionActorSchema.optional(),
7721
8031
  response: WorkflowIOSnapshotSchema.optional(),
7722
- cancelledAt: z25.string().optional(),
8032
+ cancelledAt: z26.string().optional(),
7723
8033
  cancelledBy: WorkflowInterventionActorSchema.optional(),
7724
- expiredAt: z25.string().optional()
8034
+ expiredAt: z26.string().optional()
7725
8035
  });
7726
- var WorkflowSchema = z25.object({
7727
- id: z25.string(),
8036
+ var WorkflowSchema = z26.object({
8037
+ id: z26.string(),
7728
8038
  input: WorkflowIOSnapshotSchema,
7729
- triggers: z25.array(WorkflowTriggerSchema),
7730
- nodes: z25.array(WorkflowNodeSchema),
8039
+ triggers: z26.array(WorkflowTriggerSchema),
8040
+ nodes: z26.array(WorkflowNodeSchema),
7731
8041
  latestRun: WorkflowRunSummarySchema.nullable()
7732
8042
  });
7733
- var WorkflowRunListResponseSchema = z25.object({
7734
- runs: z25.array(WorkflowRunSummarySchema),
7735
- hasMore: z25.boolean(),
7736
- total: z25.number()
8043
+ var WorkflowRunListResponseSchema = z26.object({
8044
+ runs: z26.array(WorkflowRunSummarySchema),
8045
+ hasMore: z26.boolean(),
8046
+ total: z26.number()
7737
8047
  });
7738
- var WorkflowRunDetailResponseSchema = z25.object({
8048
+ var WorkflowRunDetailResponseSchema = z26.object({
7739
8049
  run: WorkflowRunDetailSchema,
7740
- nodes: z25.array(WorkflowNodeRunSchema)
8050
+ nodes: z26.array(WorkflowNodeRunSchema)
7741
8051
  });
7742
8052
  var CancelWorkflowRunResponseSchema = WorkflowRunDetailResponseSchema;
7743
- var WorkflowInterventionListResponseSchema = z25.object({
7744
- interventions: z25.array(WorkflowInterventionSchema),
7745
- hasMore: z25.boolean(),
7746
- total: z25.number()
8053
+ var WorkflowInterventionListResponseSchema = z26.object({
8054
+ interventions: z26.array(WorkflowInterventionSchema),
8055
+ hasMore: z26.boolean(),
8056
+ total: z26.number()
7747
8057
  });
7748
- var SubmitWorkflowInterventionResponseSchema = z25.object({
8058
+ var SubmitWorkflowInterventionResponseSchema = z26.object({
7749
8059
  intervention: WorkflowInterventionSchema,
7750
- jobId: z25.string()
8060
+ jobId: z26.string()
7751
8061
  });
7752
- var CancelWorkflowInterventionResponseSchema = z25.object({
8062
+ var CancelWorkflowInterventionResponseSchema = z26.object({
7753
8063
  intervention: WorkflowInterventionSchema
7754
8064
  });
7755
- var RequestWorkflowRunResponseSchema = z25.object({
7756
- runId: z25.string(),
7757
- jobId: z25.string(),
7758
- workflowId: z25.string(),
7759
- queuedAt: z25.string()
8065
+ var RequestWorkflowRunResponseSchema = z26.object({
8066
+ runId: z26.string(),
8067
+ jobId: z26.string(),
8068
+ workflowId: z26.string(),
8069
+ queuedAt: z26.string()
7760
8070
  });
7761
8071
 
7762
8072
  // src/routes/workflows.ts
7763
8073
  var WorkflowRunFileContentQuerySchema = FileContentQuerySchema.extend({
7764
- path: z26.string().min(1).regex(/^\/(?:input|output)(?:\/|$)/, "Workflow run file content paths must start with /input/ or /output/")
8074
+ path: z27.string().min(1).regex(/^\/(?:input|output)(?:\/|$)/, "Workflow run file content paths must start with /input/ or /output/")
7765
8075
  });
7766
8076
  var WorkflowNodeFileContentQuerySchema = FileContentQuerySchema.extend({
7767
- path: z26.string().min(1).regex(/^\/(?:input|output)(?:\/|$)/, "Workflow node file content paths must start with /input/ or /output/")
8077
+ path: z27.string().min(1).regex(/^\/(?:input|output)(?:\/|$)/, "Workflow node file content paths must start with /input/ or /output/")
7768
8078
  });
7769
8079
  var WorkflowNodeFileContentParamsSchema = WorkflowRunParamsSchema.extend({
7770
- nodeKey: z26.string().min(1)
8080
+ nodeKey: z27.string().min(1)
7771
8081
  });
7772
8082
  function serializeWorkflowRunSummary(run) {
7773
8083
  return {
@@ -7819,6 +8129,7 @@ function serializeWorkflowAgentExecutionSummary(execution) {
7819
8129
  modelId: execution.modelId,
7820
8130
  finishReason: execution.finishReason,
7821
8131
  usage: execution.usage,
8132
+ cost: execution.cost,
7822
8133
  startedAt: execution.startedAt ? toIsoString(execution.startedAt) : undefined,
7823
8134
  completedAt: execution.completedAt ? toIsoString(execution.completedAt) : undefined
7824
8135
  };
@@ -7830,10 +8141,21 @@ function serializeWorkflowAgentExecution(execution) {
7830
8141
  prompt: execution.prompt,
7831
8142
  trace: execution.trace,
7832
8143
  diagnostics: execution.diagnostics,
8144
+ failurePhase: workflowAgentFailurePhase(execution),
7833
8145
  error: execution.error,
7834
8146
  createdAt: toIsoString(execution.createdAt)
7835
8147
  };
7836
8148
  }
8149
+ function workflowAgentFailurePhase(execution) {
8150
+ const details = execution.error?.details;
8151
+ if (!isRecord(details))
8152
+ return;
8153
+ const phase = details.failurePhase;
8154
+ return phase === "agent-loop" || phase === "structured-finalizer" ? phase : undefined;
8155
+ }
8156
+ function isRecord(value) {
8157
+ return value !== null && typeof value === "object" && !Array.isArray(value);
8158
+ }
7837
8159
  function principalForExecution(sixb) {
7838
8160
  return sixb.execution.requestedBy ?? SYSTEM_PRINCIPAL2;
7839
8161
  }
@@ -8780,6 +9102,7 @@ function registerWorkflowRoutes(app, host) {
8780
9102
  // src/registerRoutes.ts
8781
9103
  function registerHttpRoutes(app, host, options) {
8782
9104
  registerAgentApiGatewayRoutes(app, host);
9105
+ registerAiAccountingRoutes(app, host);
8783
9106
  registerProjectRoutes(app, host);
8784
9107
  registerStatusRoutes(app, host);
8785
9108
  registerConnectorRoutes(app, host);
@@ -8826,275 +9149,405 @@ import {
8826
9149
  } from "@sixb/core/storage";
8827
9150
  import { t } from "elysia";
8828
9151
 
9152
+ // src/auth/experience.ts
9153
+ import { resolve } from "path";
9154
+ var AUTH_BOOTSTRAP_PLACEHOLDER = "__SIXB_AUTH_BOOTSTRAP__";
9155
+ var AUTH_ASSET_PREFIX = "/auth/assets/";
9156
+ async function customAuthExperienceResponse(options, input) {
9157
+ if (!options || input.audience !== (options.audience ?? "app")) {
9158
+ return null;
9159
+ }
9160
+ const template = Bun.file(resolve(options.outdir, "index.html"));
9161
+ if (!await template.exists()) {
9162
+ return null;
9163
+ }
9164
+ const html = await template.text();
9165
+ if (!html.includes(AUTH_BOOTSTRAP_PLACEHOLDER)) {
9166
+ console.warn(`[SixbServer] Custom auth experience in ${options.outdir} is missing its bootstrap placeholder. Using the generic page.`);
9167
+ return null;
9168
+ }
9169
+ const bootstrap = Buffer.from(JSON.stringify({
9170
+ state: input.state,
9171
+ signInUrl: input.signInUrl,
9172
+ ...input.submission ? { submission: input.submission } : {}
9173
+ })).toString("base64url");
9174
+ const formAction = ["'self'", ...(input.formActionOrigins ?? []).map(normalizeCspOrigin)].join(" ");
9175
+ return new Response(html.replace(AUTH_BOOTSTRAP_PLACEHOLDER, bootstrap), {
9176
+ status: input.status ?? 200,
9177
+ headers: {
9178
+ "content-type": "text/html; charset=utf-8",
9179
+ "cache-control": "no-store",
9180
+ "content-security-policy": [
9181
+ "default-src 'none'",
9182
+ "script-src 'self'",
9183
+ "style-src 'self' 'unsafe-inline'",
9184
+ "img-src 'self' data:",
9185
+ "font-src 'self'",
9186
+ "base-uri 'none'",
9187
+ `form-action ${formAction}`,
9188
+ "frame-ancestors 'none'"
9189
+ ].join("; "),
9190
+ "referrer-policy": input.referrerPolicy ?? "no-referrer",
9191
+ "x-content-type-options": "nosniff"
9192
+ }
9193
+ });
9194
+ }
9195
+ function normalizeCspOrigin(value) {
9196
+ let url;
9197
+ try {
9198
+ url = new URL(value);
9199
+ } catch {
9200
+ throw new Error(`[SixbServer] Invalid custom auth form-action origin: '${value}'.`);
9201
+ }
9202
+ if (url.protocol !== "http:" && url.protocol !== "https:" || url.origin !== value) {
9203
+ throw new Error(`[SixbServer] Invalid custom auth form-action origin: '${value}'.`);
9204
+ }
9205
+ return url.origin;
9206
+ }
9207
+ async function customAuthExperienceAssetResponse(options, request) {
9208
+ const method = request.method.toUpperCase();
9209
+ if (!options || method !== "GET" && method !== "HEAD") {
9210
+ return notFoundResponse();
9211
+ }
9212
+ const url = new URL(request.url);
9213
+ if (!url.pathname.startsWith(AUTH_ASSET_PREFIX)) {
9214
+ return notFoundResponse();
9215
+ }
9216
+ let fileName;
9217
+ try {
9218
+ fileName = decodeURIComponent(url.pathname.slice(AUTH_ASSET_PREFIX.length));
9219
+ } catch {
9220
+ return notFoundResponse();
9221
+ }
9222
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(fileName)) {
9223
+ return notFoundResponse();
9224
+ }
9225
+ const path = resolve(options.outdir, "assets", fileName);
9226
+ const source = Bun.file(path);
9227
+ if (!await source.exists()) {
9228
+ return notFoundResponse();
9229
+ }
9230
+ const encoding = await resolvePrecompressedAsset(request, path);
9231
+ const body = encoding ? Bun.file(`${path}.${encoding === "br" ? "br" : "gz"}`) : source;
9232
+ const headers = new Headers({
9233
+ "content-type": source.type || "application/octet-stream",
9234
+ "cache-control": "public, max-age=31536000, immutable",
9235
+ "x-content-type-options": "nosniff"
9236
+ });
9237
+ if (encoding) {
9238
+ headers.set("content-encoding", encoding);
9239
+ headers.set("vary", "Accept-Encoding");
9240
+ }
9241
+ return new Response(method === "HEAD" ? null : body, { headers });
9242
+ }
9243
+ async function resolvePrecompressedAsset(request, sourcePath) {
9244
+ for (const encoding of acceptedPrecompressedEncodings(request)) {
9245
+ const suffix = encoding === "br" ? "br" : "gz";
9246
+ if (await Bun.file(`${sourcePath}.${suffix}`).exists()) {
9247
+ return encoding;
9248
+ }
9249
+ }
9250
+ return null;
9251
+ }
9252
+ function acceptedPrecompressedEncodings(request) {
9253
+ const header = request.headers.get("accept-encoding");
9254
+ if (!header)
9255
+ return [];
9256
+ const qualities = new Map;
9257
+ for (const item of header.split(",")) {
9258
+ const [rawName, ...parameters] = item.trim().split(";");
9259
+ const name = rawName.toLowerCase();
9260
+ let quality = 1;
9261
+ for (const parameter of parameters) {
9262
+ const match = parameter.trim().match(/^q=(0(?:\.\d+)?|1(?:\.0+)?)$/);
9263
+ if (match)
9264
+ quality = Number(match[1]);
9265
+ }
9266
+ qualities.set(name, quality);
9267
+ }
9268
+ const wildcard = qualities.get("*") ?? 0;
9269
+ return ["br", "gzip"].map((encoding, preference) => ({
9270
+ encoding,
9271
+ preference,
9272
+ quality: qualities.get(encoding) ?? wildcard
9273
+ })).filter((candidate) => candidate.quality > 0).sort((left, right) => right.quality - left.quality || left.preference - right.preference).map((candidate) => candidate.encoding);
9274
+ }
9275
+ function notFoundResponse() {
9276
+ return new Response("Not Found", {
9277
+ status: 404,
9278
+ headers: { "content-type": "text/plain; charset=utf-8" }
9279
+ });
9280
+ }
9281
+
8829
9282
  // 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()),
9283
+ import { z as z28 } from "zod";
9284
+ var AuthInvitationStatusSchema = z28.enum(["pending", "accepted", "revoked"]);
9285
+ var AuthGroupOptionSchema = z28.object({
9286
+ id: z28.string(),
9287
+ label: z28.string().optional(),
9288
+ description: z28.string().optional()
9289
+ });
9290
+ var AuthInvitationSchema = z28.object({
9291
+ id: z28.string(),
9292
+ email: z28.string(),
9293
+ groupIds: z28.array(z28.string()),
8841
9294
  status: AuthInvitationStatusSchema,
8842
- createdAt: z27.string(),
8843
- updatedAt: z27.string(),
8844
- expiresAt: z27.string(),
8845
- acceptedAt: z27.string().optional(),
8846
- revokedAt: z27.string().optional()
9295
+ createdAt: z28.string(),
9296
+ updatedAt: z28.string(),
9297
+ expiresAt: z28.string(),
9298
+ acceptedAt: z28.string().optional(),
9299
+ revokedAt: z28.string().optional()
8847
9300
  });
8848
- var AuthInvitationDeliverySchema = z27.object({
8849
- status: z27.enum(["sent", "skipped", "rate_limited", "not_supported"])
9301
+ var AuthInvitationDeliverySchema = z28.object({
9302
+ status: z28.enum(["sent", "skipped", "rate_limited", "not_supported"])
8850
9303
  });
8851
9304
  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(),
9305
+ var AuthAccessTokenKindSchema = z28.enum(["personal", "serviceAccount"]);
9306
+ var AuthAccessTokenSubjectTypeSchema = z28.enum(["user", "serviceAccount"]);
9307
+ var AuthAccessTokenStatusSchema = z28.enum(["active", "expired", "revoked"]);
9308
+ var AuthServiceAccountStatusSchema = z28.enum(["active", "suspended"]);
9309
+ var AuthUserStatusSchema = z28.enum(["active", "suspended"]);
9310
+ var AuthAccessTokenSchema = z28.object({
9311
+ id: z28.string(),
9312
+ name: z28.string(),
8860
9313
  kind: AuthAccessTokenKindSchema,
8861
9314
  status: AuthAccessTokenStatusSchema,
8862
9315
  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(),
9316
+ subjectId: z28.string(),
9317
+ subjectLabel: z28.string().optional(),
9318
+ groupIds: z28.array(z28.string()).optional(),
9319
+ createdAt: z28.string(),
9320
+ expiresAt: z28.string(),
9321
+ revokedAt: z28.string().optional(),
9322
+ lastUsedAt: z28.string().optional(),
9323
+ lastUsedUserAgent: z28.string().optional(),
9324
+ lastUsedIpAddress: z28.string().optional()
9325
+ });
9326
+ var AuthServiceAccountSchema = z28.object({
9327
+ id: z28.string(),
9328
+ name: z28.string(),
9329
+ description: z28.string().optional(),
8877
9330
  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(),
9331
+ groupIds: z28.array(z28.string()),
9332
+ createdAt: z28.string(),
9333
+ updatedAt: z28.string()
9334
+ });
9335
+ var AuthMemberUserSchema = z28.object({
9336
+ id: z28.string(),
9337
+ email: z28.string(),
9338
+ displayName: z28.string().optional(),
9339
+ avatarUrl: z28.string().optional(),
8887
9340
  status: AuthUserStatusSchema,
8888
- createdAt: z27.string(),
8889
- updatedAt: z27.string()
9341
+ createdAt: z28.string(),
9342
+ updatedAt: z28.string()
8890
9343
  });
8891
- var AuthManagedMemberSchema = z27.object({
9344
+ var AuthManagedMemberSchema = z28.object({
8892
9345
  user: AuthMemberUserSchema,
8893
- groupIds: z27.array(z27.string())
9346
+ groupIds: z28.array(z28.string())
8894
9347
  });
8895
- var AuthMemberCapabilitiesSchema = z27.object({
8896
- assignGroups: z27.boolean(),
8897
- suspend: z27.boolean(),
8898
- reactivate: z27.boolean()
9348
+ var AuthMemberCapabilitiesSchema = z28.object({
9349
+ assignGroups: z28.boolean(),
9350
+ suspend: z28.boolean(),
9351
+ reactivate: z28.boolean()
8899
9352
  });
8900
9353
  var AuthMemberSchema = AuthManagedMemberSchema.extend({
8901
9354
  capabilities: AuthMemberCapabilitiesSchema
8902
9355
  });
8903
- var GetAuthAccessManagementOptionsResponseSchema = z27.object({
8904
- groups: z27.array(AuthGroupOptionSchema)
9356
+ var GetAuthAccessManagementOptionsResponseSchema = z28.object({
9357
+ groups: z28.array(AuthGroupOptionSchema)
8905
9358
  });
8906
- var ListAuthAccessTokensResponseSchema = z27.object({
8907
- accessTokens: z27.array(AuthAccessTokenSchema)
9359
+ var ListAuthAccessTokensResponseSchema = z28.object({
9360
+ accessTokens: z28.array(AuthAccessTokenSchema)
8908
9361
  });
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()
9362
+ var CreateAuthPersonalAccessTokenBodySchema = z28.object({
9363
+ name: z28.string().trim().min(1),
9364
+ expiresAt: z28.string().min(1),
9365
+ groupIds: z28.array(z28.string().min(1)).optional()
8913
9366
  });
8914
- var CreateAuthPersonalAccessTokenResponseSchema = z27.object({
9367
+ var CreateAuthPersonalAccessTokenResponseSchema = z28.object({
8915
9368
  accessToken: AuthAccessTokenSchema,
8916
- tokenValue: z27.string()
9369
+ tokenValue: z28.string()
8917
9370
  });
8918
- var RevokeAuthAccessTokenParamsSchema = z27.object({
8919
- tokenId: z27.string().min(1)
9371
+ var RevokeAuthAccessTokenParamsSchema = z28.object({
9372
+ tokenId: z28.string().min(1)
8920
9373
  });
8921
- var RevokeAuthAccessTokenResponseSchema = z27.object({
9374
+ var RevokeAuthAccessTokenResponseSchema = z28.object({
8922
9375
  accessToken: AuthAccessTokenSchema
8923
9376
  });
8924
- var ListAuthServiceAccountsResponseSchema = z27.object({
8925
- serviceAccounts: z27.array(AuthServiceAccountSchema)
9377
+ var ListAuthServiceAccountsResponseSchema = z28.object({
9378
+ serviceAccounts: z28.array(AuthServiceAccountSchema)
8926
9379
  });
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()
9380
+ var CreateAuthServiceAccountBodySchema = z28.object({
9381
+ id: z28.string().trim().min(1).optional(),
9382
+ name: z28.string().trim().min(1),
9383
+ description: z28.string().trim().optional(),
9384
+ groupIds: z28.array(z28.string().min(1)).optional()
8932
9385
  });
8933
- var CreateAuthServiceAccountResponseSchema = z27.object({
9386
+ var CreateAuthServiceAccountResponseSchema = z28.object({
8934
9387
  serviceAccount: AuthServiceAccountSchema
8935
9388
  });
8936
- var AuthServiceAccountParamsSchema = z27.object({
8937
- serviceAccountId: z27.string().min(1)
9389
+ var AuthServiceAccountParamsSchema = z28.object({
9390
+ serviceAccountId: z28.string().min(1)
8938
9391
  });
8939
- var DisableAuthServiceAccountResponseSchema = z27.object({
9392
+ var DisableAuthServiceAccountResponseSchema = z28.object({
8940
9393
  serviceAccount: AuthServiceAccountSchema
8941
9394
  });
8942
- var ListAuthServiceAccountAccessTokensResponseSchema = z27.object({
8943
- accessTokens: z27.array(AuthAccessTokenSchema)
9395
+ var ListAuthServiceAccountAccessTokensResponseSchema = z28.object({
9396
+ accessTokens: z28.array(AuthAccessTokenSchema)
8944
9397
  });
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()
9398
+ var CreateAuthServiceAccountAccessTokenBodySchema = z28.object({
9399
+ name: z28.string().trim().min(1),
9400
+ expiresAt: z28.string().min(1),
9401
+ groupIds: z28.array(z28.string().min(1)).optional()
8949
9402
  });
8950
- var CreateAuthServiceAccountAccessTokenResponseSchema = z27.object({
9403
+ var CreateAuthServiceAccountAccessTokenResponseSchema = z28.object({
8951
9404
  accessToken: AuthAccessTokenSchema,
8952
- tokenValue: z27.string()
9405
+ tokenValue: z28.string()
8953
9406
  });
8954
9407
  var RevokeAuthServiceAccountAccessTokenParamsSchema = AuthServiceAccountParamsSchema.extend({
8955
- tokenId: z27.string().min(1)
9408
+ tokenId: z28.string().min(1)
8956
9409
  });
8957
- var RevokeAuthServiceAccountAccessTokenResponseSchema = z27.object({
9410
+ var RevokeAuthServiceAccountAccessTokenResponseSchema = z28.object({
8958
9411
  accessToken: AuthAccessTokenSchema
8959
9412
  });
8960
- var AuthCreateInvitationCapabilitySchema = z27.union([
8961
- z27.object({
8962
- state: z27.literal("enabled")
9413
+ var AuthCreateInvitationCapabilitySchema = z28.union([
9414
+ z28.object({
9415
+ state: z28.literal("enabled")
8963
9416
  }),
8964
- z27.object({
8965
- state: z27.literal("disabled"),
8966
- reason: z27.enum(["missing_membership_policy", "invitation_delivery_not_supported"])
9417
+ z28.object({
9418
+ state: z28.literal("disabled"),
9419
+ reason: z28.enum(["missing_membership_policy", "invitation_delivery_not_supported"])
8967
9420
  })
8968
9421
  ]);
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({
9422
+ var AuthInvitationDestinationSchema = z28.object({
9423
+ id: z28.enum(["atlas", "app"]),
9424
+ label: z28.string()
9425
+ });
9426
+ var GetAuthInvitationOptionsResponseSchema = z28.object({
9427
+ groups: z28.array(AuthInvitationGroupOptionSchema),
9428
+ destinations: z28.array(AuthInvitationDestinationSchema),
9429
+ defaultDestinationId: z28.enum(["atlas", "app"]).optional(),
9430
+ canInviteWithoutGroups: z28.boolean(),
9431
+ capabilities: z28.object({
8979
9432
  createInvitation: AuthCreateInvitationCapabilitySchema
8980
9433
  })
8981
9434
  });
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()
9435
+ var GetAuthMembershipOptionsResponseSchema = z28.object({
9436
+ groups: z28.array(AuthGroupOptionSchema),
9437
+ capabilities: z28.object({
9438
+ invite: z28.boolean(),
9439
+ assignGroups: z28.boolean(),
9440
+ suspend: z28.boolean()
8988
9441
  })
8989
9442
  });
8990
- var ListAuthMembersQuerySchema = z27.object({
8991
- limit: z27.string().optional(),
8992
- offset: z27.string().optional(),
8993
- order: z27.enum(["asc", "desc"]).optional()
9443
+ var ListAuthMembersQuerySchema = z28.object({
9444
+ limit: z28.string().optional(),
9445
+ offset: z28.string().optional(),
9446
+ order: z28.enum(["asc", "desc"]).optional()
8994
9447
  });
8995
- var ListAuthMembersResponseSchema = z27.object({
8996
- members: z27.array(AuthMemberSchema),
8997
- hasMore: z27.boolean(),
8998
- total: z27.number()
9448
+ var ListAuthMembersResponseSchema = z28.object({
9449
+ members: z28.array(AuthMemberSchema),
9450
+ hasMore: z28.boolean(),
9451
+ total: z28.number()
8999
9452
  });
9000
- var AuthMemberParamsSchema = z27.object({
9001
- userId: z27.string().min(1)
9453
+ var AuthMemberParamsSchema = z28.object({
9454
+ userId: z28.string().min(1)
9002
9455
  });
9003
- var UpdateAuthMemberGroupsBodySchema = z27.object({
9004
- groupIds: z27.array(z27.string().min(1))
9456
+ var UpdateAuthMemberGroupsBodySchema = z28.object({
9457
+ groupIds: z28.array(z28.string().min(1))
9005
9458
  });
9006
- var UpdateAuthMemberGroupsResponseSchema = z27.object({
9459
+ var UpdateAuthMemberGroupsResponseSchema = z28.object({
9007
9460
  member: AuthManagedMemberSchema
9008
9461
  });
9009
- var SuspendAuthMemberResponseSchema = z27.object({
9462
+ var SuspendAuthMemberResponseSchema = z28.object({
9010
9463
  member: AuthManagedMemberSchema
9011
9464
  });
9012
- var ReactivateAuthMemberResponseSchema = z27.object({
9465
+ var ReactivateAuthMemberResponseSchema = z28.object({
9013
9466
  member: AuthManagedMemberSchema
9014
9467
  });
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()
9468
+ var CreateAuthInvitationBodySchema = z28.object({
9469
+ email: z28.string().min(1),
9470
+ groupIds: z28.array(z28.string().min(1)).optional(),
9471
+ destinationId: z28.enum(["atlas", "app"]).optional(),
9472
+ expiresAt: z28.string().optional(),
9473
+ returnTo: z28.string().optional()
9021
9474
  });
9022
- var CreateAuthInvitationResponseSchema = z27.object({
9475
+ var CreateAuthInvitationResponseSchema = z28.object({
9023
9476
  invitation: AuthInvitationSchema,
9024
9477
  delivery: AuthInvitationDeliverySchema
9025
9478
  });
9026
- var ListAuthInvitationsQuerySchema = z27.object({
9027
- email: z27.string().optional(),
9479
+ var ListAuthInvitationsQuerySchema = z28.object({
9480
+ email: z28.string().optional(),
9028
9481
  status: AuthInvitationStatusSchema.optional(),
9029
- limit: z27.string().optional(),
9030
- offset: z27.string().optional(),
9031
- order: z27.enum(["asc", "desc"]).optional()
9482
+ limit: z28.string().optional(),
9483
+ offset: z28.string().optional(),
9484
+ order: z28.enum(["asc", "desc"]).optional()
9032
9485
  });
9033
- var ListAuthInvitationsResponseSchema = z27.object({
9034
- invitations: z27.array(AuthInvitationSchema),
9035
- hasMore: z27.boolean(),
9036
- total: z27.number()
9486
+ var ListAuthInvitationsResponseSchema = z28.object({
9487
+ invitations: z28.array(AuthInvitationSchema),
9488
+ hasMore: z28.boolean(),
9489
+ total: z28.number()
9037
9490
  });
9038
- var RevokeAuthInvitationParamsSchema = z27.object({
9039
- invitationId: z27.string().min(1)
9491
+ var RevokeAuthInvitationParamsSchema = z28.object({
9492
+ invitationId: z28.string().min(1)
9040
9493
  });
9041
- var RevokeAuthInvitationResponseSchema = z27.object({
9494
+ var RevokeAuthInvitationResponseSchema = z28.object({
9042
9495
  invitation: AuthInvitationSchema
9043
9496
  });
9044
- var AuthSessionResponseSchema = z27.union([
9045
- z27.object({
9046
- authenticated: z27.literal(false)
9497
+ var AuthSessionResponseSchema = z28.union([
9498
+ z28.object({
9499
+ authenticated: z28.literal(false)
9047
9500
  }),
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"])
9501
+ z28.object({
9502
+ authenticated: z28.literal(true),
9503
+ csrfToken: z28.string(),
9504
+ applicationAccess: z28.object({
9505
+ allowed: z28.boolean(),
9506
+ audience: z28.enum(["atlas", "app"])
9054
9507
  }),
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())
9508
+ user: z28.object({
9509
+ id: z28.string(),
9510
+ email: z28.string(),
9511
+ displayName: z28.string().optional(),
9512
+ avatarUrl: z28.string().optional(),
9513
+ groupIds: z28.array(z28.string())
9061
9514
  }),
9062
- session: z27.object({
9063
- id: z27.string(),
9064
- expiresAt: z27.string()
9515
+ session: z28.object({
9516
+ id: z28.string(),
9517
+ expiresAt: z28.string()
9065
9518
  })
9066
9519
  })
9067
9520
  ]);
9068
- var AuthSignOutResponseSchema = z27.object({
9069
- success: z27.boolean()
9521
+ var AuthSignOutResponseSchema = z28.object({
9522
+ success: z28.boolean()
9070
9523
  });
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()
9524
+ var AuthSessionSummarySchema = z28.object({
9525
+ id: z28.string(),
9526
+ audience: z28.enum(["atlas", "app"]),
9527
+ current: z28.boolean(),
9528
+ createdAt: z28.string(),
9529
+ expiresAt: z28.string(),
9530
+ lastSeenAt: z28.string().optional(),
9531
+ userAgent: z28.string().optional(),
9532
+ ipAddress: z28.string().optional()
9080
9533
  });
9081
- var ListAuthSessionsResponseSchema = z27.object({
9082
- sessions: z27.array(AuthSessionSummarySchema)
9534
+ var ListAuthSessionsResponseSchema = z28.object({
9535
+ sessions: z28.array(AuthSessionSummarySchema)
9083
9536
  });
9084
- var RevokeAuthSessionParamsSchema = z27.object({
9085
- sessionId: z27.string().min(1)
9537
+ var RevokeAuthSessionParamsSchema = z28.object({
9538
+ sessionId: z28.string().min(1)
9086
9539
  });
9087
- var RevokeAuthSessionResponseSchema = z27.object({
9088
- success: z27.boolean()
9540
+ var RevokeAuthSessionResponseSchema = z28.object({
9541
+ success: z28.boolean()
9089
9542
  });
9090
- var SignOutAllResponseSchema = z27.object({
9091
- success: z27.boolean(),
9092
- revokedCount: z27.number()
9543
+ var SignOutAllResponseSchema = z28.object({
9544
+ success: z28.boolean(),
9545
+ revokedCount: z28.number()
9093
9546
  });
9094
9547
 
9095
9548
  // src/routes/auth.ts
9096
9549
  function registerAuthRoutes(app, host, options) {
9097
- return app.get("/api/auth/session", async ({ request }) => {
9550
+ 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
9551
  const authOptions = resolveAuthOptions(options, request);
9099
9552
  let session = await host.auth.getSession(request, authOptions);
9100
9553
  if (!session.authenticated) {
@@ -9888,7 +10341,7 @@ function registerAuthRoutes(app, host, options) {
9888
10341
  requestOrigin: authRedirect.requestOrigin,
9889
10342
  requesterHash: pending.hash
9890
10343
  });
9891
- const response = htmlMessageResponse("If this email can sign in, we sent a link. Check your inbox to continue.", 200, "Check your email");
10344
+ const response = await magicLinkRequestedResponse(options, authRedirect);
9892
10345
  const existingPending = getCookie3(request, MAGIC_LINK_PENDING_COOKIE_NAME)?.trim();
9893
10346
  response.headers.append("set-cookie", magicLinkPendingCookieHeader({
9894
10347
  request,
@@ -9928,7 +10381,7 @@ function registerAuthRoutes(app, host, options) {
9928
10381
  return authRedirect;
9929
10382
  }
9930
10383
  if (isMagicLinkAuthStrategy(strategy)) {
9931
- return signInFormResponse(authRedirect);
10384
+ return await signInFormResponse(options, authRedirect);
9932
10385
  }
9933
10386
  if (isOidcAuthStrategy(strategy)) {
9934
10387
  const result = await strategy.startOidcSignIn({
@@ -9947,8 +10400,9 @@ function registerAuthRoutes(app, host, options) {
9947
10400
  const url = new URL(request.url);
9948
10401
  const magicLinkId = url.searchParams.get("magicLinkId")?.trim();
9949
10402
  const token = url.searchParams.get("token")?.trim();
10403
+ const authRedirectHint = resolveAuthExperienceRedirectHint(options, request, url.searchParams.get("audience"));
9950
10404
  if (!magicLinkId || !token) {
9951
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10405
+ return await invalidMagicLinkResponse(options, authRedirectHint);
9952
10406
  }
9953
10407
  let email;
9954
10408
  if (strategy.peekMagicLink) {
@@ -9960,11 +10414,12 @@ function registerAuthRoutes(app, host, options) {
9960
10414
  token
9961
10415
  });
9962
10416
  if (!peeked) {
9963
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10417
+ return await invalidMagicLinkResponse(options, authRedirectHint);
9964
10418
  }
9965
10419
  email = peeked.email;
9966
- } catch {
9967
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10420
+ } catch (error) {
10421
+ logAuthCallbackError("Magic-link", error);
10422
+ return await authExperienceErrorResponse(options, authRedirectHint);
9968
10423
  }
9969
10424
  }
9970
10425
  const requesterHash = url.searchParams.get("requester")?.trim();
@@ -9977,10 +10432,16 @@ function registerAuthRoutes(app, host, options) {
9977
10432
  request,
9978
10433
  magicLinkId,
9979
10434
  token,
9980
- clearPendingCookie: true
10435
+ clearPendingCookie: true,
10436
+ authRedirectHint
9981
10437
  });
9982
10438
  }
9983
- return magicLinkConfirmResponse({ magicLinkId, token, email });
10439
+ return await magicLinkConfirmResponse(options, {
10440
+ magicLinkId,
10441
+ token,
10442
+ email,
10443
+ authRedirect: authRedirectHint
10444
+ });
9984
10445
  }
9985
10446
  if (isOidcAuthStrategy(strategy)) {
9986
10447
  const now = new Date;
@@ -10024,14 +10485,24 @@ function registerAuthRoutes(app, host, options) {
10024
10485
  }
10025
10486
  const magicLinkId = body.magicLinkId?.trim();
10026
10487
  const token = body.token?.trim();
10488
+ const authRedirectHint = resolveAuthExperienceRedirectHint(options, request, body.audience);
10027
10489
  if (!magicLinkId || !token) {
10028
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10490
+ return await invalidMagicLinkResponse(options, authRedirectHint);
10029
10491
  }
10030
- return completeMagicLinkCallback({ host, strategy, options, request, magicLinkId, token });
10492
+ return completeMagicLinkCallback({
10493
+ host,
10494
+ strategy,
10495
+ options,
10496
+ request,
10497
+ magicLinkId,
10498
+ token,
10499
+ authRedirectHint
10500
+ });
10031
10501
  }, {
10032
10502
  body: t.Object({
10033
10503
  magicLinkId: t.Optional(t.String()),
10034
- token: t.Optional(t.String())
10504
+ token: t.Optional(t.String()),
10505
+ audience: t.Optional(t.String())
10035
10506
  }),
10036
10507
  parse: "urlencoded",
10037
10508
  detail: { hide: true }
@@ -10106,7 +10577,7 @@ async function completeMagicLinkCallback(input) {
10106
10577
  }
10107
10578
  return response;
10108
10579
  } catch {
10109
- return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10580
+ return await invalidMagicLinkResponse(input.options, input.authRedirectHint);
10110
10581
  }
10111
10582
  }
10112
10583
  function resolveSessionDevice(request) {
@@ -10377,8 +10848,18 @@ function authPageResponse(body, status = 200) {
10377
10848
  }
10378
10849
  });
10379
10850
  }
10380
- function signInFormResponse(context) {
10381
- return authPageResponse([
10851
+ async function signInFormResponse(options, context) {
10852
+ return await customAuthExperienceResponse(options.authExperience, {
10853
+ audience: context.audience,
10854
+ state: { kind: "signIn" },
10855
+ signInUrl: authExperienceSignInUrl(context),
10856
+ submission: {
10857
+ kind: "requestMagicLink",
10858
+ action: "/auth/sign-in",
10859
+ fields: { audience: context.audience, returnTo: context.returnTo }
10860
+ },
10861
+ referrerPolicy: "same-origin"
10862
+ }) ?? authPageResponse([
10382
10863
  "<h1>Sign in</h1>",
10383
10864
  "<p>We'll email you a sign-in link.</p>",
10384
10865
  '<form method="post" action="/auth/sign-in">',
@@ -10389,13 +10870,80 @@ function signInFormResponse(context) {
10389
10870
  "</form>"
10390
10871
  ].join(""));
10391
10872
  }
10392
- function magicLinkConfirmResponse(input) {
10873
+ async function magicLinkRequestedResponse(options, context) {
10874
+ return await customAuthExperienceResponse(options.authExperience, {
10875
+ audience: context.audience,
10876
+ state: { kind: "checkEmail" },
10877
+ signInUrl: authExperienceSignInUrl(context)
10878
+ }) ?? htmlMessageResponse("If this email can sign in, we sent a link. Check your inbox to continue.", 200, "Check your email");
10879
+ }
10880
+ async function invalidMagicLinkResponse(options, context) {
10881
+ if (context) {
10882
+ const custom = await customAuthExperienceResponse(options.authExperience, {
10883
+ audience: context.audience,
10884
+ state: { kind: "invalidLink" },
10885
+ signInUrl: authExperienceSignInUrl(context),
10886
+ status: 400
10887
+ });
10888
+ if (custom)
10889
+ return custom;
10890
+ }
10891
+ return htmlMessageResponse("This sign-in link is invalid or expired.", 400);
10892
+ }
10893
+ async function authExperienceErrorResponse(options, context) {
10894
+ if (context) {
10895
+ const custom = await customAuthExperienceResponse(options.authExperience, {
10896
+ audience: context.audience,
10897
+ state: { kind: "error" },
10898
+ signInUrl: authExperienceSignInUrl(context),
10899
+ status: 500
10900
+ });
10901
+ if (custom)
10902
+ return custom;
10903
+ }
10904
+ return await invalidMagicLinkResponse(options, undefined);
10905
+ }
10906
+ function authExperienceSignInUrl(context) {
10907
+ const params = new URLSearchParams({ audience: context.audience, returnTo: context.returnTo });
10908
+ return `/auth/sign-in?${params.toString()}`;
10909
+ }
10910
+ function resolveAuthExperienceRedirectHint(options, request, audience) {
10911
+ if (audience !== "app" && audience !== "atlas") {
10912
+ return;
10913
+ }
10914
+ const context = resolveInvitationDeliveryContext(options, request, { destinationId: audience });
10915
+ return context instanceof Response ? undefined : context;
10916
+ }
10917
+ async function magicLinkConfirmResponse(options, input) {
10918
+ if (input.authRedirect) {
10919
+ const custom = await customAuthExperienceResponse(options.authExperience, {
10920
+ audience: input.authRedirect.audience,
10921
+ state: { kind: "confirm", ...input.email ? { email: input.email } : {} },
10922
+ signInUrl: authExperienceSignInUrl(input.authRedirect),
10923
+ submission: {
10924
+ kind: "confirmSignIn",
10925
+ action: "/auth/callback",
10926
+ fields: {
10927
+ magicLinkId: input.magicLinkId,
10928
+ token: input.token,
10929
+ audience: input.authRedirect.audience
10930
+ }
10931
+ },
10932
+ referrerPolicy: "same-origin",
10933
+ formActionOrigins: [new URL(input.authRedirect.returnTo).origin]
10934
+ });
10935
+ if (custom)
10936
+ return custom;
10937
+ }
10393
10938
  const response = authPageResponse([
10394
10939
  "<h1>Sign in</h1>",
10395
10940
  input.email ? `<p>You're signing in as <strong>${escapeHtml(input.email)}</strong>.</p>` : "<p>Click continue to finish signing in.</p>",
10396
10941
  '<form method="post" action="/auth/callback" id="confirm">',
10397
10942
  `<input type="hidden" name="magicLinkId" value="${escapeHtml(input.magicLinkId)}">`,
10398
10943
  `<input type="hidden" name="token" value="${escapeHtml(input.token)}">`,
10944
+ ...input.authRedirect ? [
10945
+ `<input type="hidden" name="audience" value="${escapeHtml(input.authRedirect.audience)}">`
10946
+ ] : [],
10399
10947
  '<button type="submit" id="confirm-button">Continue</button>',
10400
10948
  "</form>",
10401
10949
  "<script>",
@@ -10876,7 +11424,7 @@ import {
10876
11424
  isAgentRunActivityEvent
10877
11425
  } from "@sixb/core/agents/streams";
10878
11426
  import { BrokerCursorExpiredError } from "@sixb/core/broker";
10879
- import { z as z28 } from "zod";
11427
+ import { z as z29 } from "zod";
10880
11428
 
10881
11429
  // src/utils/ws.ts
10882
11430
  function safeSend(target, payload) {
@@ -10924,25 +11472,25 @@ async function decodeWsMessage(message) {
10924
11472
  }
10925
11473
 
10926
11474
  // 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()
11475
+ var SubscribeSchema = z29.object({
11476
+ type: z29.literal("subscribe"),
11477
+ runId: z29.string().min(1),
11478
+ afterCursor: z29.string().min(1).optional()
10931
11479
  });
10932
- var SubscribeActivitySchema = z28.object({
10933
- type: z28.literal("subscribe.activity")
11480
+ var SubscribeActivitySchema = z29.object({
11481
+ type: z29.literal("subscribe.activity")
10934
11482
  });
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()
11483
+ var ReplaySchema = z29.object({
11484
+ type: z29.literal("replay"),
11485
+ runId: z29.string().min(1),
11486
+ afterCursor: z29.string().min(1).optional(),
11487
+ limit: z29.number().int().positive().max(500).optional()
10940
11488
  });
10941
- var UnsubscribeSchema = z28.object({
10942
- type: z28.literal("unsubscribe"),
10943
- runId: z28.string().min(1).optional()
11489
+ var UnsubscribeSchema = z29.object({
11490
+ type: z29.literal("unsubscribe"),
11491
+ runId: z29.string().min(1).optional()
10944
11492
  });
10945
- var AgentStreamMessageSchema = z28.union([
11493
+ var AgentStreamMessageSchema = z29.union([
10946
11494
  SubscribeSchema,
10947
11495
  SubscribeActivitySchema,
10948
11496
  ReplaySchema,
@@ -11228,22 +11776,22 @@ function errorMessage(error) {
11228
11776
 
11229
11777
  // src/routes/ws/events.ts
11230
11778
  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]);
11779
+ import { z as z30 } from "zod";
11780
+ var SubscribeSchema2 = z30.object({
11781
+ type: z30.literal("subscribe"),
11782
+ topic: z30.enum(EVENT_TOPICS).optional(),
11783
+ types: z30.array(z30.enum(EVENT_TYPES)).optional(),
11784
+ objectTypeId: z30.string().optional(),
11785
+ primaryId: z30.string().optional(),
11786
+ actionId: z30.string().optional(),
11787
+ runId: z30.string().optional(),
11788
+ afterCursor: z30.string().optional(),
11789
+ limit: z30.number().int().positive().max(500).optional()
11790
+ });
11791
+ var UnsubscribeSchema2 = z30.object({
11792
+ type: z30.literal("unsubscribe")
11793
+ });
11794
+ var SubscriptionMessageSchema = z30.union([SubscribeSchema2, UnsubscribeSchema2]);
11247
11795
  function parseSubscriptionMessage(payload) {
11248
11796
  if (!payload || typeof payload !== "object") {
11249
11797
  return { ok: false, error: "Message must be a JSON object." };
@@ -11433,7 +11981,7 @@ function eventMatchesScope(event, filter) {
11433
11981
  }
11434
11982
 
11435
11983
  // src/routes/ws/logs.ts
11436
- import { z as z30 } from "zod";
11984
+ import { z as z31 } from "zod";
11437
11985
 
11438
11986
  // src/routes/ws/log-subscription-hub.ts
11439
11987
  import { BrokerCursorExpiredError as BrokerCursorExpiredError2 } from "@sixb/core/broker";
@@ -11683,13 +12231,13 @@ class LogSubscriptionHub {
11683
12231
  this.scheduleFlush(state);
11684
12232
  }
11685
12233
  waitForQueueProgress(state) {
11686
- return new Promise((resolve) => state.queueProgressWaiters.add(resolve));
12234
+ return new Promise((resolve2) => state.queueProgressWaiters.add(resolve2));
11687
12235
  }
11688
12236
  notifyQueueProgress(state) {
11689
12237
  const waiters = [...state.queueProgressWaiters];
11690
12238
  state.queueProgressWaiters.clear();
11691
- for (const resolve of waiters)
11692
- resolve();
12239
+ for (const resolve2 of waiters)
12240
+ resolve2();
11693
12241
  }
11694
12242
  send(state, payload) {
11695
12243
  if (state.closed)
@@ -11746,26 +12294,26 @@ function socketBufferedAmount(ws) {
11746
12294
  }
11747
12295
 
11748
12296
  // 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),
12297
+ var SubscribeSchema3 = z31.object({
12298
+ type: z31.literal("subscribe"),
12299
+ kinds: z31.array(z31.enum(SIXB_RUN_KINDS)).min(1).optional(),
12300
+ levels: z31.array(z31.enum(LOG_LEVELS)).min(1).optional(),
12301
+ run: z31.object({
12302
+ kind: z31.enum(SIXB_RUN_KINDS),
11755
12303
  id: LogRunIdSchema
11756
12304
  }).optional(),
11757
- afterCursor: z30.string().optional()
12305
+ afterCursor: z31.string().optional()
11758
12306
  }).superRefine((value, context) => {
11759
12307
  if (value.run && value.kinds && !value.kinds.includes(value.run.kind)) {
11760
12308
  context.addIssue({
11761
- code: z30.ZodIssueCode.custom,
12309
+ code: z31.ZodIssueCode.custom,
11762
12310
  path: ["run"],
11763
12311
  message: "run.kind must be included in kinds"
11764
12312
  });
11765
12313
  }
11766
12314
  });
11767
- var UnsubscribeSchema3 = z30.object({ type: z30.literal("unsubscribe") });
11768
- var SubscriptionMessageSchema2 = z30.union([SubscribeSchema3, UnsubscribeSchema3]);
12315
+ var UnsubscribeSchema3 = z31.object({ type: z31.literal("unsubscribe") });
12316
+ var SubscriptionMessageSchema2 = z31.union([SubscribeSchema3, UnsubscribeSchema3]);
11769
12317
  function parseLogSubscriptionMessage(payload) {
11770
12318
  if (!payload || typeof payload !== "object") {
11771
12319
  return { ok: false, error: "Message must be a JSON object." };
@@ -11866,6 +12414,7 @@ class SixbServer {
11866
12414
  apiBrowserPolicy;
11867
12415
  authContextResolver;
11868
12416
  authRedirectContextResolver;
12417
+ authExperience;
11869
12418
  app = null;
11870
12419
  bunServer = null;
11871
12420
  maintenance = null;
@@ -11877,6 +12426,7 @@ class SixbServer {
11877
12426
  this.apiBrowserPolicy = resolveApiBrowserPolicy(options.browser);
11878
12427
  this.authContextResolver = createApiBrowserAuthContextResolver(this.apiBrowserPolicy);
11879
12428
  this.authRedirectContextResolver = createApiBrowserAuthRedirectContextResolver(this.apiBrowserPolicy);
12429
+ this.authExperience = options.authExperience;
11880
12430
  }
11881
12431
  getHost() {
11882
12432
  return this.hostRuntime;
@@ -11902,6 +12452,9 @@ class SixbServer {
11902
12452
  getApiBrowserPolicy() {
11903
12453
  return this.apiBrowserPolicy;
11904
12454
  }
12455
+ getAuthExperience() {
12456
+ return this.authExperience;
12457
+ }
11905
12458
  async start() {
11906
12459
  if (this.app !== null || this.bunServer !== null || this.maintenance !== null) {
11907
12460
  throw new Error("[SixbServer] Server is already running.");
@@ -12051,6 +12604,7 @@ function createSixbApi(server) {
12051
12604
  resolveAuthRedirectContext: (request, input) => server.resolveAuthRedirectContext(request, input),
12052
12605
  getInvitationDestinationOptions: (request) => server.getInvitationDestinationOptions(request),
12053
12606
  resolveAuthRequestOrigin: (request) => server.resolveAuthRequestOrigin(request),
12607
+ authExperience: server.getAuthExperience(),
12054
12608
  resolveInvitationRedirectContext: (request, input) => server.resolveInvitationRedirectContext(request, input)
12055
12609
  });
12056
12610
  registerHttpRoutes(app, host, {
@@ -12142,4 +12696,4 @@ export {
12142
12696
  SixbServer
12143
12697
  };
12144
12698
 
12145
- //# debugId=3097F504C06B251564756E2164756E21
12699
+ //# debugId=16E192D0EFF3C5F064756E2164756E21