@sixb/server 0.1.25 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/public-routes.d.ts.map +1 -1
  3. package/dist/auth/run-token.d.ts +28 -0
  4. package/dist/auth/run-token.d.ts.map +1 -0
  5. package/dist/auth/scope.d.ts +11 -13
  6. package/dist/auth/scope.d.ts.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +4999 -4151
  10. package/dist/index.js.map +47 -43
  11. package/dist/registerRoutes.d.ts.map +1 -1
  12. package/dist/routes/actions.d.ts +1 -1
  13. package/dist/routes/agent-approval-gate.d.ts +7 -4
  14. package/dist/routes/agent-approval-gate.d.ts.map +1 -1
  15. package/dist/routes/agent-approvals.d.ts +14 -5
  16. package/dist/routes/agent-approvals.d.ts.map +1 -1
  17. package/dist/routes/agent-children.d.ts +2 -2
  18. package/dist/routes/agent-computers.d.ts +338 -0
  19. package/dist/routes/agent-computers.d.ts.map +1 -0
  20. package/dist/routes/agent-runners.d.ts +74 -0
  21. package/dist/routes/agent-runners.d.ts.map +1 -0
  22. package/dist/routes/agents.d.ts +250 -16
  23. package/dist/routes/agents.d.ts.map +1 -1
  24. package/dist/routes/ai-accounting.d.ts.map +1 -1
  25. package/dist/routes/artifacts.d.ts +5 -28
  26. package/dist/routes/artifacts.d.ts.map +1 -1
  27. package/dist/routes/auth.d.ts +10 -1
  28. package/dist/routes/auth.d.ts.map +1 -1
  29. package/dist/routes/datasets.d.ts +93 -17
  30. package/dist/routes/datasets.d.ts.map +1 -1
  31. package/dist/routes/events.d.ts +1 -1
  32. package/dist/routes/links.d.ts +121 -81
  33. package/dist/routes/links.d.ts.map +1 -1
  34. package/dist/routes/logs.d.ts +3 -3
  35. package/dist/routes/objects.d.ts +149 -58
  36. package/dist/routes/objects.d.ts.map +1 -1
  37. package/dist/routes/observed-agent-threads.d.ts +25 -4
  38. package/dist/routes/observed-agent-threads.d.ts.map +1 -1
  39. package/dist/routes/pipelines.d.ts +2 -2
  40. package/dist/routes/pipelines.d.ts.map +1 -1
  41. package/dist/routes/projections.d.ts +124 -122
  42. package/dist/routes/projections.d.ts.map +1 -1
  43. package/dist/routes/rules.d.ts +2 -2
  44. package/dist/routes/shared-access.d.ts +2 -2
  45. package/dist/routes/syncs.d.ts +34 -34
  46. package/dist/routes/syncs.d.ts.map +1 -1
  47. package/dist/routes/telemetry.d.ts +0 -50
  48. package/dist/routes/telemetry.d.ts.map +1 -1
  49. package/dist/routes/users.d.ts +1 -0
  50. package/dist/routes/users.d.ts.map +1 -1
  51. package/dist/routes/webhook-runs.d.ts +1 -1
  52. package/dist/routes/workflows.d.ts +25 -14
  53. package/dist/routes/workflows.d.ts.map +1 -1
  54. package/dist/routes/ws/agents.d.ts +4 -1
  55. package/dist/routes/ws/agents.d.ts.map +1 -1
  56. package/dist/routes/ws/logs.d.ts +10 -10
  57. package/dist/schemas/actions.d.ts +3 -3
  58. package/dist/schemas/activity.d.ts +4 -4
  59. package/dist/schemas/agent-approvals.d.ts +21 -21
  60. package/dist/schemas/agents.d.ts +819 -88
  61. package/dist/schemas/agents.d.ts.map +1 -1
  62. package/dist/schemas/ai-accounting.d.ts +1114 -6
  63. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  64. package/dist/schemas/auth.d.ts +49 -2
  65. package/dist/schemas/auth.d.ts.map +1 -1
  66. package/dist/schemas/datasets.d.ts +303 -60
  67. package/dist/schemas/datasets.d.ts.map +1 -1
  68. package/dist/schemas/event-payloads.d.ts +6 -6
  69. package/dist/schemas/events.d.ts +8 -8
  70. package/dist/schemas/lineage.d.ts +1272 -0
  71. package/dist/schemas/lineage.d.ts.map +1 -0
  72. package/dist/schemas/links.d.ts +4 -27
  73. package/dist/schemas/links.d.ts.map +1 -1
  74. package/dist/schemas/logs.d.ts +22 -22
  75. package/dist/schemas/objects.d.ts +7 -26
  76. package/dist/schemas/objects.d.ts.map +1 -1
  77. package/dist/schemas/pipelines.d.ts +12 -12
  78. package/dist/schemas/projections.d.ts +747 -733
  79. package/dist/schemas/projections.d.ts.map +1 -1
  80. package/dist/schemas/rules.d.ts +4 -4
  81. package/dist/schemas/shared-access.d.ts +2 -2
  82. package/dist/schemas/syncs.d.ts +24 -24
  83. package/dist/schemas/telemetry.d.ts +0 -13
  84. package/dist/schemas/telemetry.d.ts.map +1 -1
  85. package/dist/schemas/users.d.ts +8 -0
  86. package/dist/schemas/users.d.ts.map +1 -1
  87. package/dist/schemas/webhook-runs.d.ts +2 -2
  88. package/dist/schemas/workflows.d.ts +133 -44
  89. package/dist/schemas/workflows.d.ts.map +1 -1
  90. package/dist/server.d.ts +5 -0
  91. package/dist/server.d.ts.map +1 -1
  92. package/dist/utils/request-body.d.ts +5 -0
  93. package/dist/utils/request-body.d.ts.map +1 -1
  94. package/dist/utils/request-timing.d.ts +18 -0
  95. package/dist/utils/request-timing.d.ts.map +1 -0
  96. package/package.json +7 -7
  97. package/src/auth/public-routes.ts +0 -6
  98. package/src/auth/run-token.ts +327 -0
  99. package/src/auth/scope.ts +16 -37
  100. package/src/index.ts +1 -0
  101. package/src/registerRoutes.ts +4 -2
  102. package/src/routes/agent-approval-gate.ts +40 -14
  103. package/src/routes/agent-approvals.ts +3 -3
  104. package/src/routes/agent-computers.ts +348 -0
  105. package/src/routes/agent-runners.ts +205 -0
  106. package/src/routes/agents.ts +193 -26
  107. package/src/routes/ai-accounting.ts +149 -12
  108. package/src/routes/artifacts.ts +55 -11
  109. package/src/routes/auth.ts +24 -2
  110. package/src/routes/datasets.ts +60 -5
  111. package/src/routes/links.ts +43 -76
  112. package/src/routes/objects.ts +49 -42
  113. package/src/routes/observed-agent-threads.ts +2 -2
  114. package/src/routes/pipelines.ts +5 -0
  115. package/src/routes/syncs.ts +4 -0
  116. package/src/routes/telemetry.ts +1 -42
  117. package/src/routes/users.ts +15 -2
  118. package/src/routes/ws/agents.ts +10 -1
  119. package/src/schemas/agents.ts +131 -1
  120. package/src/schemas/ai-accounting.ts +78 -15
  121. package/src/schemas/artifacts.ts +1 -1
  122. package/src/schemas/auth.ts +19 -0
  123. package/src/schemas/datasets.ts +36 -0
  124. package/src/schemas/lineage.ts +115 -0
  125. package/src/schemas/links.ts +3 -11
  126. package/src/schemas/objects.ts +6 -10
  127. package/src/schemas/projections.ts +2 -0
  128. package/src/schemas/telemetry.ts +0 -6
  129. package/src/schemas/users.ts +6 -0
  130. package/src/server.ts +53 -15
  131. package/src/utils/request-body.ts +10 -4
  132. package/src/utils/request-timing.ts +136 -0
  133. package/dist/routes/agent-api-gateway.d.ts +0 -4
  134. package/dist/routes/agent-api-gateway.d.ts.map +0 -1
  135. package/src/routes/agent-api-gateway.ts +0 -404
@@ -1,5 +1,6 @@
1
1
  import { MAX_AGENT_CONTEXT_ENTRIES } from "@sixb/core"
2
2
  import { MAX_AGENT_CONTEXT_LABEL_LENGTH } from "@sixb/core/agents/context"
3
+ import { CONTROL_CHARACTER } from "@sixb/core/internal/agent-run-storage-provider"
3
4
  import { LANGUAGE_MODEL_TIERS } from "@sixb/core/models"
4
5
  import {
5
6
  AGENT_RUN_DIAGNOSTIC_CODES,
@@ -104,11 +105,31 @@ export const AgentThreadListQuerySchema = z
104
105
  })
105
106
  .strict()
106
107
 
108
+ /** Shown back to its owner as written, so it holds no control character. */
109
+ const plainText = (schema: z.ZodString) =>
110
+ schema.refine((text) => !CONTROL_CHARACTER.test(text), "has a control character")
111
+
112
+ /** Where on your computer a thread runs: the computer `sixb` is open on, and its folder there. */
113
+ export const AgentThreadComputerInputSchema = z
114
+ .object({
115
+ /** The id `sixb` keeps for the computer, beside its sign-in. */
116
+ id: plainText(z.string().trim().min(1).max(200)),
117
+ /** What you call the computer, such as "Anthony's MacBook Pro". */
118
+ name: plainText(z.string().trim().min(1).max(120)),
119
+ /** The absolute path its turns work in. */
120
+ folder: plainText(z.string().min(1).max(4096)),
121
+ })
122
+ .strict()
123
+
107
124
  export const CreateAgentThreadBodySchema = z
108
125
  .object({
109
126
  title: z.string().trim().min(1).optional(),
110
127
  threadId: z.string().trim().min(1).optional(),
111
128
  sandbox: z.record(z.string(), JsonValueSchema).optional(),
129
+ /** Run its turns on your computer, which claims them, instead of in the cloud. */
130
+ runsOn: z.literal("computer").optional(),
131
+ /** The computer and folder its turns run in: required with `runsOn: "computer"`. */
132
+ computer: AgentThreadComputerInputSchema.optional(),
112
133
  })
113
134
  .strict()
114
135
 
@@ -151,6 +172,22 @@ export const AgentThreadSchema = z.object({
151
172
  participants: z.array(AgentThreadParticipantSchema),
152
173
  title: z.string().optional(),
153
174
  sandboxParams: z.record(z.string(), JsonValueSchema).optional(),
175
+ /** Its turns run on its owner's computer; absent, in the cloud. */
176
+ runsOn: z.literal("computer").optional(),
177
+ /**
178
+ * Where on its owner's computer it runs, and whether `sixb` is open there now: shown to its owner
179
+ * alone. Absent for a computer's thread from before folders were kept, until its owner moves it.
180
+ */
181
+ computer: z
182
+ .object({
183
+ id: z.string(),
184
+ name: z.string(),
185
+ folder: z.string(),
186
+ online: z.boolean(),
187
+ })
188
+ .optional(),
189
+ /** When its turns last moved to where they run now: the files earlier turns used are not here. */
190
+ movedAt: z.string().optional(),
154
191
  status: AgentThreadStatusSchema,
155
192
  activeRunId: z.string().nullable(),
156
193
  lastMessageAt: z.string().optional(),
@@ -176,6 +213,25 @@ export const CreateAgentThreadResponseSchema = z.object({
176
213
  thread: AgentThreadSchema,
177
214
  })
178
215
 
216
+ export const MoveAgentThreadToComputerBodySchema = z
217
+ .object({ computer: AgentThreadComputerInputSchema })
218
+ .strict()
219
+
220
+ export const AgentComputerSessionParamsSchema = z.object({
221
+ sessionId: z.string().trim().min(1).max(200),
222
+ })
223
+
224
+ export const HoldAgentComputerSessionBodySchema = z
225
+ .object({ computer: AgentThreadComputerInputSchema })
226
+ .strict()
227
+
228
+ export const HoldAgentComputerSessionResponseSchema = z.object({
229
+ /** Renew before then, or the session lapses and its threads read as offline. */
230
+ expiresAt: z.string(),
231
+ /** Queued turns of your threads on this computer, in this folder, for it to claim. */
232
+ waiting: z.array(z.string()),
233
+ })
234
+
179
235
  export const AddAgentThreadParticipantsBodySchema = z
180
236
  .object({
181
237
  /**
@@ -241,6 +297,11 @@ const AgentToolCallBaseSchema = z.object({
241
297
  const AgentToolCallOutputSchema = AgentToolCallBaseSchema.extend({
242
298
  state: z.literal("output-available"),
243
299
  output: JsonValueSchema,
300
+ /**
301
+ * The whole output, when it was too large for the model's context: `output` is then a bounded
302
+ * copy. Its content is served at `/parts/<index>/outputFile/fileRef` of the message.
303
+ */
304
+ outputFile: z.object({ fileRef: FileRefSchema, path: z.string() }).optional(),
244
305
  })
245
306
 
246
307
  const AgentToolCallErrorSchema = AgentToolCallBaseSchema.extend({
@@ -307,8 +368,15 @@ export const AgentRunDiagnosticSchema = z.object({
307
368
  message: z.string(),
308
369
  })
309
370
 
371
+ const AgentContextCheckpointReasonSchema = z
372
+ .enum(["threshold", "overflow"])
373
+ .describe(
374
+ "`threshold`: the conversation reached its model's limit, or came back large after its cache expired. `overflow`: the provider refused a request as too long, and the turn went on condensed."
375
+ )
376
+
310
377
  export const AgentMessageCompactionSchema = z.object({
311
378
  checkpointId: z.string(),
379
+ reason: AgentContextCheckpointReasonSchema,
312
380
  summary: z.string(),
313
381
  createdAt: z.string(),
314
382
  })
@@ -349,7 +417,7 @@ export const AgentMessageListResponseSchema = z.object({
349
417
 
350
418
  export const PostAgentMessageBodySchema = z
351
419
  .object({
352
- /** Required unless `continue` is set. */
420
+ /** Required unless `continue` is set or `attachments` are the whole message. */
353
421
  text: z.string().trim().min(1).optional(),
354
422
  /** Continue the previous answer after it reached the turn limit, without text of its own. */
355
423
  continue: z.literal(true).optional(),
@@ -403,6 +471,8 @@ export const AgentRunSchema = z.object({
403
471
  reasoning: ModelReasoningSchema.optional(),
404
472
  /** What the turn could change without asking. Absent on turns from before approval modes. */
405
473
  approvalMode: AgentApprovalModeSchema.optional(),
474
+ /** Its owner's computer claims it; absent, the cloud runs it. */
475
+ runsOn: z.literal("computer").optional(),
406
476
  modelId: z.string().optional(),
407
477
  /**
408
478
  * `awaiting_approval`: the turn succeeded and paused on calls waiting for its requester. It stays
@@ -451,6 +521,66 @@ export const RetryAgentRunResponseSchema = z.object({
451
521
  run: AgentRunSchema,
452
522
  })
453
523
 
524
+ export const AgentThreadContextQuerySchema = z.object({
525
+ /** The model to measure the conversation against, with `modelId`. Omitted: its latest turn's. */
526
+ provider: z.string().min(1).optional(),
527
+ modelId: z.string().min(1).optional(),
528
+ })
529
+
530
+ export const AgentThreadContextSchema = z.object({
531
+ /** The model the limits are this one's: the one asked for, else the latest turn's or the default. */
532
+ model: LanguageModelRefSchema,
533
+ windowTokens: z.number().int().positive(),
534
+ /** The window less the output reserve: past it, the conversation is condensed before a call. */
535
+ limitTokens: z.number().int().positive(),
536
+ /** What the next request weighs, as the worker estimates it. Absent before the first answer. */
537
+ usedTokens: z.number().int().nonnegative().optional(),
538
+ /**
539
+ * `usedTokens` by part, in a fixed order: the prompt's parts, the tools, then the history's.
540
+ * They add up to `usedTokens`, which is counted; the split is an estimate by each part's size.
541
+ */
542
+ parts: z
543
+ .array(
544
+ z.object({
545
+ part: z
546
+ .enum([
547
+ "system",
548
+ "instructions",
549
+ "memory",
550
+ "skills",
551
+ "ontology",
552
+ "tools",
553
+ "summary",
554
+ "messages",
555
+ "toolResults",
556
+ "files",
557
+ ])
558
+ .describe(
559
+ "`system`: Sixb's own prompt. `instructions`: the project's SIXB.md. `memory`, `skills`, `ontology`: their index in the prompt and the files the agent read. `tools`: the tool definitions. `summary`: what a condensed conversation keeps of its earlier part. `messages`: the conversation's text. `toolResults`: every other tool result. `files`: attachments and images."
560
+ ),
561
+ tokens: z.number().int().positive(),
562
+ })
563
+ )
564
+ .optional(),
565
+ /** The call the conversation's history ends with, as the provider counted it. */
566
+ lastCall: z
567
+ .object({
568
+ inputTokens: z.number().int().nonnegative(),
569
+ outputTokens: z.number().int().nonnegative().optional(),
570
+ cacheReadInputTokens: z.number().int().nonnegative().optional(),
571
+ occurredAt: z.string(),
572
+ })
573
+ .optional(),
574
+ lastCompaction: z
575
+ .object({
576
+ reason: AgentContextCheckpointReasonSchema,
577
+ createdAt: z.string(),
578
+ estimatedInputTokensBefore: z.number().int().nonnegative(),
579
+ estimatedInputTokensAfter: z.number().int().nonnegative(),
580
+ })
581
+ .optional(),
582
+ })
583
+
454
584
  export const AgentRunListQuerySchema = z.object({
455
585
  status: AgentRunStatusSchema.optional(),
456
586
  limit: z.string().optional(),
@@ -14,11 +14,37 @@ export const AiMoneySchema = z.object({
14
14
  export const AiAccountingBucketSchema = z.enum(["hour", "day", "week"])
15
15
  export const AiValuationStatusSchema = z.enum(["rated", "unpriceable", "unvalued"])
16
16
 
17
+ const ModelKindSchema = z.enum([
18
+ "language",
19
+ "image",
20
+ "video",
21
+ "embedding",
22
+ "decision",
23
+ "transcription",
24
+ "speech",
25
+ "reranking",
26
+ ])
27
+
17
28
  export const AiAccountingRangeQuerySchema = z.object({
18
29
  from: IsoDateSchema,
19
30
  to: IsoDateSchema,
20
31
  providerId: z.string().trim().min(1).optional(),
21
32
  modelId: z.string().trim().min(1).optional(),
33
+ person: z
34
+ .string()
35
+ .regex(/^(none|user:.+|serviceAccount:.+)$/)
36
+ .optional()
37
+ .describe(
38
+ "Calls one person or service account asked for, as user:<id> or serviceAccount:<id>, or none for those nobody did, such as a schedule's"
39
+ ),
40
+ source: z
41
+ .string()
42
+ .regex(/^(agent|action|other|workflow|workflow:.+)$/)
43
+ .optional()
44
+ .describe(
45
+ "Calls from agent conversations and their sub-agents, actions, workflows or one as workflow:<id>, or other"
46
+ ),
47
+ kind: ModelKindSchema.optional().describe("Calls to one kind of model"),
22
48
  })
23
49
 
24
50
  export const AiAccountingOverviewQuerySchema = AiAccountingRangeQuerySchema.extend({
@@ -39,16 +65,12 @@ export const AiCostSummarySchema = z.object({
39
65
  unvaluedCallCount: z.number().int().nonnegative(),
40
66
  })
41
67
 
42
- const ModelKindSchema = z.enum([
43
- "language",
44
- "image",
45
- "video",
46
- "embedding",
47
- "decision",
48
- "transcription",
49
- "speech",
50
- "reranking",
51
- ])
68
+ const AiAccountingRequesterSchema = z.object({
69
+ type: z.enum(["user", "serviceAccount"]),
70
+ id: z.string(),
71
+ name: z.string().optional().describe("Their name, or a service account's"),
72
+ email: z.string().optional(),
73
+ })
52
74
 
53
75
  const AiAccountingAggregateSchema = z.object({
54
76
  modelCallCount: z.number().int().nonnegative(),
@@ -89,12 +111,32 @@ export const AiAccountingOverviewResponseSchema = z.object({
89
111
  end: IsoDateSchema,
90
112
  })
91
113
  ),
114
+ modelSeries: z
115
+ .array(
116
+ z.object({
117
+ providerId: z.string(),
118
+ modelId: z.string(),
119
+ series: z.array(
120
+ AiAccountingAggregateSchema.extend({ start: IsoDateSchema, end: IsoDateSchema })
121
+ ),
122
+ })
123
+ )
124
+ .describe("Each model's own series, every period included"),
92
125
  models: z.array(
93
126
  AiAccountingAggregateSchema.extend({
94
127
  providerId: z.string(),
95
128
  modelId: z.string(),
96
129
  })
97
130
  ),
131
+ people: z
132
+ .array(
133
+ AiAccountingAggregateSchema.extend({
134
+ requester: AiAccountingRequesterSchema.optional().describe(
135
+ "Absent for the calls nobody asked for, such as a schedule's"
136
+ ),
137
+ })
138
+ )
139
+ .describe("Who asked for the calls"),
98
140
  kinds: z.array(
99
141
  AiAccountingAggregateSchema.extend({
100
142
  modelKind: ModelKindSchema.optional().describe(
@@ -278,6 +320,11 @@ export const AiModelCallAccountingListResponseSchema = z.object({
278
320
 
279
321
  export const AiModelCallGroupsQuerySchema = AiModelCallAccountingListQuerySchema.omit({
280
322
  executionId: true,
323
+ }).extend({
324
+ sort: z
325
+ .enum(["recent", "cost"])
326
+ .optional()
327
+ .describe("Most recent first, the default, or costliest first"),
281
328
  })
282
329
 
283
330
  const AiModelCallExecutionSummarySchema = z.object({
@@ -290,23 +337,39 @@ const AiModelCallExecutionSummarySchema = z.object({
290
337
  .nonnegative()
291
338
  .optional()
292
339
  .describe("Present when every call that reports tokens did; images and speech don't."),
340
+ inputTokens: z.number().int().nonnegative().optional(),
341
+ cacheReadInputTokens: z.number().int().nonnegative().optional(),
293
342
  outputImages: z.number().int().nonnegative().optional(),
294
343
  inputCharacters: z.number().int().nonnegative().optional(),
295
344
  audioDurationMs: z.number().int().nonnegative().optional(),
296
345
  costs: AiCostSummarySchema,
297
346
  firstCallAt: IsoDateSchema,
298
347
  lastCallAt: IsoDateSchema,
299
- models: z.array(AiBillingIdentitySchema),
348
+ models: z.array(
349
+ AiBillingIdentitySchema.extend({
350
+ modelCallCount: z.number().int().nonnegative(),
351
+ costs: AiCostSummarySchema,
352
+ })
353
+ ),
300
354
  /** Present only when the caller can read the initiating conversation. */
301
355
  label: z.string().optional(),
356
+ prompt: z
357
+ .string()
358
+ .optional()
359
+ .describe("What a turn was asked, when the caller can read its conversation"),
302
360
  })
303
361
 
304
362
  export const AiModelCallGroupsResponseSchema = z.object({
305
363
  items: z.array(
306
- AiModelCallExecutionSummarySchema.omit({ models: true }).extend({
307
- executions: z.array(AiModelCallExecutionSummarySchema),
308
- canOpenThread: z.boolean(),
309
- })
364
+ AiModelCallExecutionSummarySchema.omit({ models: true, prompt: true })
365
+ .extend({
366
+ executions: z
367
+ .array(AiModelCallExecutionSummarySchema)
368
+ .describe("A conversation's turns and sub-agents, or a workflow run's agent steps"),
369
+ canOpenThread: z.boolean(),
370
+ requester: AiAccountingRequesterSchema.optional().describe("Who started it"),
371
+ })
372
+ .describe("One conversation, workflow run, or other execution that called models")
310
373
  ),
311
374
  total: z.number().int().nonnegative(),
312
375
  hasMore: z.boolean(),
@@ -237,7 +237,7 @@ export const ArtifactErrorResponseSchema = ErrorResponseSchema.extend({
237
237
  .string()
238
238
  .optional()
239
239
  .describe(
240
- "Stable machine-readable failure code: artifact_not_found, artifact_kind_mismatch, artifact_moved, invalid_artifact, invalid_state, state_full, not_allowed, not_shared (it exists but no conversation you read shares it), read_only (you observe the conversation that shares it), query_not_found, query_invalid (the ontology no longer admits the query), or storage_unavailable."
240
+ "Stable machine-readable failure code: artifact_not_found, artifact_kind_mismatch, artifact_moved, invalid_artifact, invalid_state, state_full, not_allowed, not_shared (it exists but no conversation you read shares it), read_only (you observe the conversation that shares it), query_not_found, query_invalid (the ontology no longer admits the query), execution_lost (a run token's run ended or moved to another runner), or storage_unavailable."
241
241
  ),
242
242
  latest: z
243
243
  .object({ version: z.number().int(), author: PrincipalSchema })
@@ -102,6 +102,12 @@ export const AuthMemberCapabilitiesSchema = z.object({
102
102
 
103
103
  export const AuthMemberSchema = AuthManagedMemberSchema.extend({
104
104
  capabilities: AuthMemberCapabilitiesSchema,
105
+ lastActiveAt: z
106
+ .string()
107
+ .optional()
108
+ .describe(
109
+ "Their latest session's last request, or its sign-in; absent if they never signed in"
110
+ ),
105
111
  })
106
112
 
107
113
  export const GetAuthAccessManagementOptionsResponseSchema = z.object({
@@ -294,6 +300,19 @@ export const AuthSessionResponseSchema = z.union([
294
300
  avatarUrl: z.string().optional(),
295
301
  groupIds: z.array(z.string()),
296
302
  }),
303
+ /** The Console, and the Settings pages about the project, this person may open. */
304
+ access: z.object({
305
+ members: z
306
+ .boolean()
307
+ .describe("Members: a membership policy lets them invite, assign groups or suspend"),
308
+ serviceAccounts: z
309
+ .boolean()
310
+ .describe("Service accounts: a membership policy lets them manage them"),
311
+ usage: z.boolean().describe("Usage: they hold can.observe(agent.usage)"),
312
+ activity: z.boolean().describe("Activity: they hold can.observe(project.activity)"),
313
+ console: z.boolean().describe("The Console: they hold can.observe(project.console)"),
314
+ logs: z.boolean().describe("Console › Logs: they hold can.observe(project.logs)"),
315
+ }),
297
316
  session: z.object({
298
317
  id: z.string(),
299
318
  expiresAt: z.string(),
@@ -13,6 +13,10 @@ export const DatasetVersionsQuerySchema = z.object({
13
13
  limit: z.string().optional(),
14
14
  })
15
15
 
16
+ export const DatasetLineageQuerySchema = z.object({
17
+ depth: z.string().optional(),
18
+ })
19
+
16
20
  /**
17
21
  * Elysia's query parser splits any comma-separated value into an array before validation, and
18
22
  * pushes a repeated key's value into the existing array as-is. `?columns=id`, `?columns=id,title`,
@@ -72,10 +76,16 @@ export const DatasetVersionRefSchema = z.object({
72
76
  versionId: z.string(),
73
77
  })
74
78
 
79
+ export const DatasetColumnRefSchema = z.object({
80
+ datasetId: z.string(),
81
+ column: z.string(),
82
+ })
83
+
75
84
  export const DatasetProducerSchema = z.object({
76
85
  kind: z.enum(["sync", "pipeline", "ingest"]),
77
86
  id: z.string().optional(),
78
87
  runId: z.string().optional(),
88
+ stepId: z.string().optional(),
79
89
  })
80
90
 
81
91
  export const DatasetVersionSchema = z.object({
@@ -109,6 +119,32 @@ export const DatasetCatalogItemSchema = DatasetDefinitionSchema.extend({
109
119
  projectionIds: z.array(z.string()),
110
120
  })
111
121
 
122
+ const DatasetLineageVersionSchema = DatasetVersionSchema.pick({
123
+ datasetId: true,
124
+ versionId: true,
125
+ parentVersionId: true,
126
+ mode: true,
127
+ createdAt: true,
128
+ producer: true,
129
+ })
130
+
131
+ /** An input version the lake no longer holds, for example one that expired. */
132
+ const DatasetLineageExpiredVersionSchema = DatasetVersionRefSchema.extend({
133
+ expired: z.literal(true),
134
+ })
135
+
136
+ /** Mirrors the core `DatasetLineage`: the starting version first, then upstream, nearest first. */
137
+ export const DatasetLineageResponseSchema = z.object({
138
+ nodes: z.array(z.union([DatasetLineageVersionSchema, DatasetLineageExpiredVersionSchema])),
139
+ edges: z.array(z.object({ from: DatasetVersionRefSchema, to: DatasetVersionRefSchema })),
140
+ restricted: z
141
+ .number()
142
+ .int()
143
+ .nonnegative()
144
+ .describe("Versions left out because the caller cannot view their dataset."),
145
+ truncated: z.boolean().describe("Whether the walk stopped at `depth` or at the node cap."),
146
+ })
147
+
112
148
  export const DatasetVersionListResponseSchema = z.object({
113
149
  versions: z.array(DatasetVersionSchema),
114
150
  count: z.number(),
@@ -0,0 +1,115 @@
1
+ import { z } from "zod"
2
+ import { JsonValueSchema } from "./common"
3
+ import { DatasetColumnRefSchema, DatasetVersionRefSchema } from "./datasets"
4
+ import { EventExecutorSchema } from "./events"
5
+
6
+ // Mirrors the core `ObjectLineage` and `LinkLineage`: sources are described once, keyed, and the
7
+ // existence and each property point at one by its key.
8
+
9
+ const RequestedBySchema = z
10
+ .object({ type: z.enum(["user", "serviceAccount"]), id: z.string() })
11
+ .describe("Principal on whose behalf the commit ran; absent for automatic or anonymous work.")
12
+
13
+ const LineageSourceSchema = z.discriminatedUnion("kind", [
14
+ z.object({
15
+ kind: z.literal("projection"),
16
+ projectionId: z.string(),
17
+ projectionRunId: z
18
+ .string()
19
+ .optional()
20
+ .describe("Absent for a caller who cannot view the projection's runs."),
21
+ datasetVersion: DatasetVersionRefSchema.optional().describe(
22
+ "The dataset version applied. Absent for a caller who cannot view the dataset."
23
+ ),
24
+ rowOrigins: z
25
+ .array(DatasetColumnRefSchema)
26
+ .optional()
27
+ .describe(
28
+ "Upstream columns that decide which rows the version holds, which every value depends on. Absent when the version records no lineage or the caller cannot view it."
29
+ ),
30
+ }),
31
+ z.object({
32
+ kind: z.literal("edit"),
33
+ commitId: z
34
+ .string()
35
+ .nullable()
36
+ .describe("Null when the commits made at that instant cannot be told apart."),
37
+ committedAt: z.string(),
38
+ requestedBy: RequestedBySchema.optional(),
39
+ executor: EventExecutorSchema.optional(),
40
+ action: z
41
+ .object({ actionId: z.string(), runId: z.string() })
42
+ .optional()
43
+ .describe("Absent for a direct write, and for an Action run the caller cannot view."),
44
+ }),
45
+ z.object({
46
+ kind: z.literal("telemetry"),
47
+ commitId: z.string(),
48
+ committedAt: z.string(),
49
+ projectionId: z.string().optional(),
50
+ requestedBy: RequestedBySchema.optional(),
51
+ executor: EventExecutorSchema.optional(),
52
+ }),
53
+ z.object({ kind: z.literal("identity") }),
54
+ ])
55
+
56
+ const LineageSourcesSchema = z
57
+ .record(LineageSourceSchema)
58
+ .describe(
59
+ "Keyed `projection:<id>`, `commit:<id>`, `commit@<instant>` when the commit is unknown, `telemetry:<commitId>` and `identity`."
60
+ )
61
+
62
+ const RestrictedSchema = z
63
+ .number()
64
+ .int()
65
+ .nonnegative()
66
+ .describe("Steps left out because the caller cannot view them.")
67
+
68
+ const PropertyLineageSchema = z.object({
69
+ source: z.string().describe("The source that decided the value: a key of `sources`."),
70
+ column: z.string().optional(),
71
+ origins: z.array(DatasetColumnRefSchema).optional(),
72
+ removed: z.literal(true).optional(),
73
+ at: z.string().optional(),
74
+ replaced: z
75
+ .object({
76
+ source: z.string(),
77
+ column: z.string().optional(),
78
+ value: JsonValueSchema.optional(),
79
+ })
80
+ .optional(),
81
+ resolution: z
82
+ .discriminatedUnion("strategy", [
83
+ z.object({ strategy: z.literal("editsWin") }),
84
+ z.object({
85
+ strategy: z.literal("mostRecent"),
86
+ sourceUpdatedAt: z.string(),
87
+ editedAt: z.string().optional(),
88
+ }),
89
+ ])
90
+ .optional(),
91
+ })
92
+
93
+ export const ObjectLineageSchema = z.object({
94
+ objectTypeId: z.string(),
95
+ primaryId: z.string(),
96
+ existence: z.object({ source: z.string() }),
97
+ sources: LineageSourcesSchema,
98
+ properties: z.record(PropertyLineageSchema),
99
+ restricted: RestrictedSchema,
100
+ })
101
+
102
+ export const LinkLineageSchema = z.object({
103
+ sourceTypeId: z.string(),
104
+ sourceId: z.string(),
105
+ linkId: z.string(),
106
+ targetTypeId: z.string(),
107
+ targetId: z.string(),
108
+ existence: z.object({
109
+ source: z.string(),
110
+ columns: z.array(z.string()).optional(),
111
+ origins: z.array(DatasetColumnRefSchema).optional(),
112
+ }),
113
+ sources: LineageSourcesSchema,
114
+ restricted: RestrictedSchema,
115
+ })
@@ -1,21 +1,13 @@
1
1
  import { z } from "zod"
2
2
 
3
- export const LinkSourceParamsSchema = z.object({
3
+ export const LinkParamsSchema = z.object({
4
4
  objectTypeId: z.string().min(1),
5
5
  objectId: z.string().min(1),
6
- })
7
-
8
- export const LinkParamsSchema = LinkSourceParamsSchema.extend({
9
6
  linkId: z.string().min(1),
10
7
  })
11
8
 
12
- export const RemoveLinkQuerySchema = z.object({
13
- targetTypeId: z.string().min(1),
14
- targetId: z.string().min(1),
15
- })
16
-
17
- export const UpsertLinkBodySchema = z.object({
9
+ /** A link is named by its target. */
10
+ export const LinkLineageQuerySchema = z.object({
18
11
  targetTypeId: z.string().min(1),
19
12
  targetId: z.string().min(1),
20
- properties: z.record(z.unknown()).optional(),
21
13
  })
@@ -6,7 +6,6 @@ import { ArtifactErrorResponseSchema } from "./artifacts"
6
6
  import { UserProfileSchema } from "./auth"
7
7
  import {
8
8
  AiUsageLimitErrorResponseSchema,
9
- codedErrorResponseSchema,
10
9
  ErrorResponseSchema,
11
10
  JsonValueSchema,
12
11
  jsonValueOpenApiOverride,
@@ -121,10 +120,6 @@ export const ObjectsQuerySchema = z
121
120
  }
122
121
  })
123
122
 
124
- export const UpsertObjectBodySchema = z.object({
125
- properties: z.record(z.unknown()),
126
- })
127
-
128
123
  export const UniquePropertyParamsSchema = z.object({
129
124
  objectTypeId: z.string().min(1),
130
125
  propertyId: z.string().min(1),
@@ -501,6 +496,12 @@ export const ObjectQueryOpenApiSchemas: OpenApiSchemas = {
501
496
  required: ["mode", "providerIssues", "fallbackIssues", "issues"],
502
497
  additionalProperties: false,
503
498
  properties: {
499
+ readObjectTypeIds: {
500
+ type: "array",
501
+ items: { type: "string" },
502
+ description:
503
+ "Every object type the query reads: where it starts, and what it traverses or expands",
504
+ },
504
505
  mode: { type: "string", enum: ["pushdown", "fallback", "pipeline", "rejected"] },
505
506
  providerIssues: {
506
507
  type: "array",
@@ -1094,8 +1095,3 @@ export const ObjectLookupNotFoundResponseSchema = ErrorResponseSchema.extend({
1094
1095
  "`object.not_found` when no object visible to the caller holds the value. Other 404s, such as an unknown type, have no code."
1095
1096
  ),
1096
1097
  })
1097
-
1098
- /** A write would give a unique property's value to a second object of the type. */
1099
- export const UniqueViolationErrorResponseSchema = codedErrorResponseSchema([
1100
- "object.unique_violation",
1101
- ])
@@ -96,6 +96,8 @@ export const ObjectProjectionSchema = z.object({
96
96
  objectTypeId: z.string(),
97
97
  datasetId: z.string(),
98
98
  properties: z.record(z.string()),
99
+ /** The `ref.user()` properties whose column holds a member's email. */
100
+ users: z.record(z.literal("email")).optional(),
99
101
  links: z.record(ForeignKeyDescriptorSchema),
100
102
  conflictResolution: SourceEditConflictResolutionSchema,
101
103
  latestRun: ProjectionRunSchema.nullable(),
@@ -31,12 +31,6 @@ export const BulkTelemetryHistoryBodySchema = z
31
31
  })
32
32
  .strict()
33
33
 
34
- export const AppendTelemetryBodySchema = z.object({
35
- value: z.unknown(),
36
- unit: z.string().optional(),
37
- at: z.string().optional(),
38
- })
39
-
40
34
  export const TelemetryPointSchema = z.object({
41
35
  projectId: z.string(),
42
36
  objectTypeId: z.string(),
@@ -3,6 +3,7 @@ import { UserProfileSchema } from "./auth"
3
3
 
4
4
  export const MAX_USERS_PAGE_LIMIT = 200
5
5
  export const MAX_USERS_SEARCH_LENGTH = 200
6
+ export const MAX_USER_EMAIL_LENGTH = 320
6
7
 
7
8
  export const ListUsersQuerySchema = z.object({
8
9
  /** Which members to list. Defaults to `active`. */
@@ -11,6 +12,11 @@ export const ListUsersQuerySchema = z.object({
11
12
  search: z.string().max(MAX_USERS_SEARCH_LENGTH).optional(),
12
13
  limit: z.coerce.number().int().min(1).max(MAX_USERS_PAGE_LIMIT).optional(),
13
14
  offset: z.coerce.number().int().min(0).optional(),
15
+ /**
16
+ * The member with exactly this email, ignoring case, suspended or not: a page of at most one.
17
+ * Takes no other option.
18
+ */
19
+ email: z.string().min(1).max(MAX_USER_EMAIL_LENGTH).optional(),
14
20
  })
15
21
 
16
22
  export const ListUsersResponseSchema = z.object({