@sixb/server 0.1.21 → 0.1.22

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 (165) hide show
  1. package/dist/artifacts/frame.d.ts +5 -0
  2. package/dist/artifacts/frame.d.ts.map +1 -1
  3. package/dist/auth/browser-origin.d.ts +5 -1
  4. package/dist/auth/browser-origin.d.ts.map +1 -1
  5. package/dist/auth/experience.d.ts +1 -0
  6. package/dist/auth/experience.d.ts.map +1 -1
  7. package/dist/auth/public-routes.d.ts.map +1 -1
  8. package/dist/auth/responses.d.ts +1 -1
  9. package/dist/auth/responses.d.ts.map +1 -1
  10. package/dist/auth/scope.d.ts +19 -3
  11. package/dist/auth/scope.d.ts.map +1 -1
  12. package/dist/index.js +10093 -7553
  13. package/dist/index.js.map +51 -39
  14. package/dist/models/display.d.ts +27 -0
  15. package/dist/models/display.d.ts.map +1 -1
  16. package/dist/openapi/components.d.ts +14 -0
  17. package/dist/openapi/components.d.ts.map +1 -0
  18. package/dist/openapi/tags.d.ts +14 -2
  19. package/dist/openapi/tags.d.ts.map +1 -1
  20. package/dist/registerRoutes.d.ts.map +1 -1
  21. package/dist/routes/actions.d.ts +5 -5
  22. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  23. package/dist/routes/agent-approval-gate.d.ts +27 -0
  24. package/dist/routes/agent-approval-gate.d.ts.map +1 -0
  25. package/dist/routes/agent-approvals.d.ts +599 -0
  26. package/dist/routes/agent-approvals.d.ts.map +1 -0
  27. package/dist/routes/agent-children.d.ts +318 -0
  28. package/dist/routes/agent-children.d.ts.map +1 -0
  29. package/dist/routes/agent-memory.d.ts +267 -0
  30. package/dist/routes/agent-memory.d.ts.map +1 -0
  31. package/dist/routes/agents.d.ts +999 -80
  32. package/dist/routes/agents.d.ts.map +1 -1
  33. package/dist/routes/ai-accounting.d.ts.map +1 -1
  34. package/dist/routes/artifact-frames.d.ts +3 -3
  35. package/dist/routes/artifact-frames.d.ts.map +1 -1
  36. package/dist/routes/artifacts.d.ts +790 -134
  37. package/dist/routes/artifacts.d.ts.map +1 -1
  38. package/dist/routes/auth.d.ts +116 -10
  39. package/dist/routes/auth.d.ts.map +1 -1
  40. package/dist/routes/connector-connection-runs.d.ts +50 -50
  41. package/dist/routes/connectors.d.ts +2 -2
  42. package/dist/routes/datasets.d.ts +20 -20
  43. package/dist/routes/events.d.ts +4 -4
  44. package/dist/routes/files.d.ts +14 -14
  45. package/dist/routes/files.d.ts.map +1 -1
  46. package/dist/routes/links.d.ts +2 -2
  47. package/dist/routes/logs.d.ts +5 -5
  48. package/dist/routes/model-calls.d.ts +155 -0
  49. package/dist/routes/model-calls.d.ts.map +1 -0
  50. package/dist/routes/model-generations.d.ts +400 -0
  51. package/dist/routes/model-generations.d.ts.map +1 -0
  52. package/dist/routes/models.d.ts +434 -1
  53. package/dist/routes/models.d.ts.map +1 -1
  54. package/dist/routes/objects.d.ts +71 -40
  55. package/dist/routes/objects.d.ts.map +1 -1
  56. package/dist/routes/observed-agent-threads.d.ts +682 -0
  57. package/dist/routes/observed-agent-threads.d.ts.map +1 -0
  58. package/dist/routes/ontology.d.ts +66 -62
  59. package/dist/routes/ontology.d.ts.map +1 -1
  60. package/dist/routes/pipelines.d.ts +24 -24
  61. package/dist/routes/projections.d.ts +55 -55
  62. package/dist/routes/rules.d.ts +2 -2
  63. package/dist/routes/share-grants.d.ts +9 -9
  64. package/dist/routes/syncs.d.ts +46 -46
  65. package/dist/routes/users.d.ts +117 -0
  66. package/dist/routes/users.d.ts.map +1 -0
  67. package/dist/routes/webhook-runs.d.ts +1 -1
  68. package/dist/routes/workflows.d.ts +118 -52
  69. package/dist/routes/workflows.d.ts.map +1 -1
  70. package/dist/routes/ws/agents.d.ts +7 -2
  71. package/dist/routes/ws/agents.d.ts.map +1 -1
  72. package/dist/routes/ws/events.d.ts +6 -6
  73. package/dist/routes/ws/logs.d.ts +14 -14
  74. package/dist/schemas/actions.d.ts +15 -15
  75. package/dist/schemas/activity.d.ts +48 -28
  76. package/dist/schemas/activity.d.ts.map +1 -1
  77. package/dist/schemas/agent-approvals.d.ts +1091 -0
  78. package/dist/schemas/agent-approvals.d.ts.map +1 -0
  79. package/dist/schemas/agent-memory.d.ts +250 -0
  80. package/dist/schemas/agent-memory.d.ts.map +1 -0
  81. package/dist/schemas/agents.d.ts +5442 -369
  82. package/dist/schemas/agents.d.ts.map +1 -1
  83. package/dist/schemas/ai-accounting.d.ts +1290 -411
  84. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  85. package/dist/schemas/ai-limits.d.ts +10 -10
  86. package/dist/schemas/ai-usage.d.ts +12 -0
  87. package/dist/schemas/ai-usage.d.ts.map +1 -1
  88. package/dist/schemas/artifacts.d.ts +650 -98
  89. package/dist/schemas/artifacts.d.ts.map +1 -1
  90. package/dist/schemas/auth.d.ts +119 -46
  91. package/dist/schemas/auth.d.ts.map +1 -1
  92. package/dist/schemas/connectors.d.ts +22 -22
  93. package/dist/schemas/datasets.d.ts +98 -98
  94. package/dist/schemas/event-payloads.d.ts +6 -6
  95. package/dist/schemas/events.d.ts +26 -26
  96. package/dist/schemas/events.d.ts.map +1 -1
  97. package/dist/schemas/files.d.ts +24 -24
  98. package/dist/schemas/links.d.ts +2 -2
  99. package/dist/schemas/logs.d.ts +32 -32
  100. package/dist/schemas/models.d.ts +8889 -10
  101. package/dist/schemas/models.d.ts.map +1 -1
  102. package/dist/schemas/objects.d.ts +48 -12
  103. package/dist/schemas/objects.d.ts.map +1 -1
  104. package/dist/schemas/ontology.d.ts +127 -104
  105. package/dist/schemas/ontology.d.ts.map +1 -1
  106. package/dist/schemas/pipelines.d.ts +132 -132
  107. package/dist/schemas/projections.d.ts +314 -314
  108. package/dist/schemas/rules.d.ts +4 -4
  109. package/dist/schemas/share-grants.d.ts +30 -30
  110. package/dist/schemas/syncs.d.ts +49 -49
  111. package/dist/schemas/users.d.ts +72 -0
  112. package/dist/schemas/users.d.ts.map +1 -0
  113. package/dist/schemas/webhook-runs.d.ts +6 -6
  114. package/dist/schemas/workflows.d.ts +701 -186
  115. package/dist/schemas/workflows.d.ts.map +1 -1
  116. package/dist/server.d.ts +1 -0
  117. package/dist/server.d.ts.map +1 -1
  118. package/dist/utils/http.d.ts.map +1 -1
  119. package/package.json +7 -7
  120. package/src/artifacts/frame.ts +6 -1
  121. package/src/auth/browser-origin.ts +8 -3
  122. package/src/auth/experience.ts +1 -1
  123. package/src/auth/guard.ts +2 -2
  124. package/src/auth/public-routes.ts +6 -0
  125. package/src/auth/responses.ts +7 -6
  126. package/src/auth/scope.ts +32 -3
  127. package/src/models/display.ts +61 -16
  128. package/src/openapi/components.ts +54 -0
  129. package/src/openapi/tags.ts +12 -0
  130. package/src/registerRoutes.ts +14 -0
  131. package/src/routes/agent-api-gateway.ts +115 -91
  132. package/src/routes/agent-approval-gate.ts +213 -0
  133. package/src/routes/agent-approvals.ts +299 -0
  134. package/src/routes/agent-children.ts +209 -0
  135. package/src/routes/agent-memory.ts +210 -0
  136. package/src/routes/agents.ts +363 -142
  137. package/src/routes/ai-accounting.ts +4 -0
  138. package/src/routes/artifact-frames.ts +14 -8
  139. package/src/routes/artifacts.ts +297 -22
  140. package/src/routes/auth.ts +306 -13
  141. package/src/routes/files.ts +6 -7
  142. package/src/routes/model-calls.ts +120 -0
  143. package/src/routes/model-generations.ts +245 -0
  144. package/src/routes/models.ts +116 -9
  145. package/src/routes/objects.ts +55 -61
  146. package/src/routes/observed-agent-threads.ts +253 -0
  147. package/src/routes/ontology.ts +1 -0
  148. package/src/routes/users.ts +73 -0
  149. package/src/routes/workflows.ts +6 -9
  150. package/src/routes/ws/agents.ts +10 -5
  151. package/src/schemas/activity.ts +2 -0
  152. package/src/schemas/agent-approvals.ts +129 -0
  153. package/src/schemas/agent-memory.ts +96 -0
  154. package/src/schemas/agents.ts +239 -0
  155. package/src/schemas/ai-accounting.ts +40 -4
  156. package/src/schemas/ai-usage.ts +10 -0
  157. package/src/schemas/artifacts.ts +91 -3
  158. package/src/schemas/auth.ts +25 -0
  159. package/src/schemas/models.ts +197 -1
  160. package/src/schemas/objects.ts +181 -0
  161. package/src/schemas/ontology.ts +1 -0
  162. package/src/schemas/users.ts +24 -0
  163. package/src/schemas/workflows.ts +2 -0
  164. package/src/server.ts +9 -10
  165. package/src/utils/http.ts +2 -0
@@ -0,0 +1,253 @@
1
+ import type { AgentThreadView, SixbHostView } from "@sixb/core"
2
+ import type { Elysia } from "elysia"
3
+ import { requireRequestSixb } from "../auth/scope"
4
+ import { fileContentGetResponses, handleFileContentQueryValidationError } from "../files/content"
5
+ import { OPENAPI_TAGS } from "../openapi/tags"
6
+ import {
7
+ AgentChildListQuerySchema,
8
+ AgentChildListResponseSchema,
9
+ AgentMessageFileContentParamsSchema,
10
+ AgentMessageListResponseSchema,
11
+ AgentMessagesQuerySchema,
12
+ AgentRunListQuerySchema,
13
+ AgentRunListResponseSchema,
14
+ AgentThreadParamsSchema,
15
+ AgentThreadSchema,
16
+ } from "../schemas/agents"
17
+ import { ErrorResponseSchema } from "../schemas/common"
18
+ import { FileContentQuerySchema } from "../schemas/files"
19
+ import { parseOptionalInt, unconfiguredStorageResponse } from "../utils/http"
20
+ import {
21
+ AgentChildFileContentQuerySchema,
22
+ agentChildFileContentResponse,
23
+ serializeAgentChild,
24
+ } from "./agent-children"
25
+ import {
26
+ agentMessageFileContentResponse,
27
+ handleAgentRouteError,
28
+ readThreadMessages,
29
+ serializeAgentRun,
30
+ serializeThread,
31
+ } from "./agents"
32
+
33
+ const errors = {
34
+ 400: ErrorResponseSchema,
35
+ 403: ErrorResponseSchema,
36
+ 404: ErrorResponseSchema,
37
+ 501: ErrorResponseSchema,
38
+ }
39
+
40
+ const OBSERVED =
41
+ "Read-only, whoever owns the thread. Takes can.observe(agent.threads); the response matches the owner's route."
42
+
43
+ /**
44
+ * Any user's conversation, read-only, with `can.observe(agent.threads)`. These routes are apart
45
+ * from `/api/agent-threads`, which stay the owner's: nothing here writes, and a reader without the
46
+ * grant gets 403 rather than the owner routes' 404.
47
+ */
48
+ export function registerObservedAgentThreadRoutes(app: Elysia, host: SixbHostView) {
49
+ return app
50
+ .get(
51
+ "/api/observed-agent-threads/:threadId",
52
+ async (context) => {
53
+ try {
54
+ const thread = await readObservedThread(context)
55
+ if (!host.storage.agents) {
56
+ return unconfiguredStorageResponse(context.set, "Agent storage")
57
+ }
58
+ if (!thread) {
59
+ return threadNotFound(context.set)
60
+ }
61
+
62
+ return await serializeThread(host, thread)
63
+ } catch (error) {
64
+ return handleAgentRouteError(error, context.set)
65
+ }
66
+ },
67
+ {
68
+ params: AgentThreadParamsSchema,
69
+ response: { 200: AgentThreadSchema, ...errors },
70
+ detail: {
71
+ summary: "Read another user's agent thread",
72
+ description: OBSERVED,
73
+ tags: [OPENAPI_TAGS.agentThreads.name],
74
+ operationId: "getObservedAgentThread",
75
+ },
76
+ }
77
+ )
78
+ .get(
79
+ "/api/observed-agent-threads/:threadId/messages",
80
+ async (context) => {
81
+ try {
82
+ const thread = await readObservedThread(context)
83
+ const storage = host.storage.agents
84
+ if (!storage) {
85
+ return unconfiguredStorageResponse(context.set, "Agent storage")
86
+ }
87
+ if (!thread) {
88
+ return threadNotFound(context.set)
89
+ }
90
+
91
+ const query = AgentMessagesQuerySchema.parse(context.query)
92
+ return AgentMessageListResponseSchema.parse(
93
+ await readThreadMessages(host, storage, thread, query)
94
+ )
95
+ } catch (error) {
96
+ return handleAgentRouteError(error, context.set)
97
+ }
98
+ },
99
+ {
100
+ params: AgentThreadParamsSchema,
101
+ query: AgentMessagesQuerySchema,
102
+ response: { 200: AgentMessageListResponseSchema, ...errors },
103
+ detail: {
104
+ summary: "List another user's agent thread messages",
105
+ description: `${OBSERVED} \`authors\` names who wrote the page's messages.`,
106
+ tags: [OPENAPI_TAGS.agentThreads.name],
107
+ operationId: "listObservedAgentThreadMessages",
108
+ },
109
+ }
110
+ )
111
+ .get(
112
+ "/api/observed-agent-threads/:threadId/messages/:messageId/files/content",
113
+ async (context) => {
114
+ try {
115
+ const thread = await readObservedThread(context)
116
+ return await agentMessageFileContentResponse(host, context, {
117
+ readThread: async () => thread,
118
+ })
119
+ } catch (error) {
120
+ return handleAgentRouteError(error, context.set)
121
+ }
122
+ },
123
+ {
124
+ params: AgentMessageFileContentParamsSchema,
125
+ query: FileContentQuerySchema,
126
+ detail: {
127
+ summary: "Get a file of another user's agent message",
128
+ description: OBSERVED,
129
+ tags: [OPENAPI_TAGS.agentThreads.name],
130
+ operationId: "getObservedAgentMessageFileContent",
131
+ responses: fileContentGetResponses({ optionalStorage: true }),
132
+ },
133
+ }
134
+ )
135
+ .get(
136
+ "/api/observed-agent-threads/:threadId/runs",
137
+ async (context) => {
138
+ try {
139
+ const thread = await readObservedThread(context)
140
+ if (!host.storage.agents) {
141
+ return unconfiguredStorageResponse(context.set, "Agent storage")
142
+ }
143
+ if (!thread) {
144
+ return threadNotFound(context.set)
145
+ }
146
+
147
+ const query = AgentRunListQuerySchema.parse(context.query)
148
+ const result = await requireRequestSixb(context).agent.observed.listRuns(
149
+ context.params.threadId,
150
+ {
151
+ statuses: query.status ? [query.status] : undefined,
152
+ limit: parseOptionalInt(query.limit),
153
+ offset: parseOptionalInt(query.offset),
154
+ order: query.order,
155
+ }
156
+ )
157
+ if (!result) {
158
+ return threadNotFound(context.set)
159
+ }
160
+
161
+ return AgentRunListResponseSchema.parse({
162
+ runs: result.runs.map(serializeAgentRun),
163
+ hasMore: result.hasMore,
164
+ total: result.total,
165
+ })
166
+ } catch (error) {
167
+ return handleAgentRouteError(error, context.set)
168
+ }
169
+ },
170
+ {
171
+ params: AgentThreadParamsSchema,
172
+ query: AgentRunListQuerySchema,
173
+ response: { 200: AgentRunListResponseSchema, ...errors },
174
+ detail: {
175
+ summary: "List another user's agent thread runs",
176
+ description: OBSERVED,
177
+ tags: [OPENAPI_TAGS.agentRuns.name],
178
+ operationId: "listObservedAgentThreadRuns",
179
+ },
180
+ }
181
+ )
182
+ .get(
183
+ "/api/observed-agent-threads/:threadId/children",
184
+ async (context) => {
185
+ try {
186
+ const query = AgentChildListQuerySchema.parse(context.query)
187
+ const result = await requireRequestSixb(context).agent.observed.listChildren(
188
+ context.params.threadId,
189
+ query.runId === undefined ? {} : { runId: query.runId }
190
+ )
191
+ if (!host.storage.agents) {
192
+ return unconfiguredStorageResponse(context.set, "Agent storage")
193
+ }
194
+ if (!result) {
195
+ return threadNotFound(context.set)
196
+ }
197
+
198
+ return AgentChildListResponseSchema.parse({
199
+ children: result.children.map(serializeAgentChild),
200
+ })
201
+ } catch (error) {
202
+ return handleAgentRouteError(error, context.set)
203
+ }
204
+ },
205
+ {
206
+ params: AgentThreadParamsSchema,
207
+ query: AgentChildListQuerySchema,
208
+ response: { 200: AgentChildListResponseSchema, ...errors },
209
+ detail: {
210
+ summary: "List the sub-agents of another user's agent conversation",
211
+ description: OBSERVED,
212
+ tags: [OPENAPI_TAGS.agentThreads.name],
213
+ operationId: "listObservedAgentThreadChildren",
214
+ },
215
+ }
216
+ )
217
+ .get(
218
+ "/api/observed-agent-threads/:threadId/child-files/content",
219
+ async (context) => {
220
+ try {
221
+ return await agentChildFileContentResponse(host, context, () =>
222
+ requireRequestSixb(context).agent.observed.getChild(context.params.threadId)
223
+ )
224
+ } catch (error) {
225
+ return handleAgentRouteError(error, context.set)
226
+ }
227
+ },
228
+ {
229
+ params: AgentThreadParamsSchema,
230
+ query: AgentChildFileContentQuerySchema,
231
+ error: handleFileContentQueryValidationError,
232
+ detail: {
233
+ summary: "Get a file of another user's sub-agent",
234
+ description: OBSERVED,
235
+ tags: [OPENAPI_TAGS.agentThreads.name],
236
+ operationId: "getObservedAgentChildFileContent",
237
+ responses: fileContentGetResponses({ optionalStorage: true }),
238
+ },
239
+ }
240
+ )
241
+ }
242
+
243
+ /** The thread, read as an observer: this authorizes, so a refusal comes before anything else. */
244
+ function readObservedThread(context: {
245
+ readonly params: { readonly threadId: string }
246
+ }): Promise<AgentThreadView | null> {
247
+ return requireRequestSixb(context).agent.observed.getById(context.params.threadId)
248
+ }
249
+
250
+ function threadNotFound(set: { status?: number | string }) {
251
+ set.status = 404
252
+ return { error: "Agent thread not found" }
253
+ }
@@ -21,6 +21,7 @@ function serializeProperty(
21
21
  required: property.required,
22
22
  nullable: property.nullable,
23
23
  primary: property.primary,
24
+ unique: property.unique,
24
25
  semanticType: property.semanticType,
25
26
  schema: property.schema,
26
27
  query: property.query ? { ...property.query } : undefined,
@@ -0,0 +1,73 @@
1
+ import { type SixbHostView, userRef } from "@sixb/core"
2
+ import type { Elysia } from "elysia"
3
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
4
+ import { requireRequestSixb } from "../auth/scope"
5
+ import { OPENAPI_TAGS } from "../openapi/tags"
6
+ import { UserProfileSchema } from "../schemas/auth"
7
+ import { ErrorResponseSchema } from "../schemas/common"
8
+ import { ListUsersQuerySchema, ListUsersResponseSchema, UserParamsSchema } from "../schemas/users"
9
+ import { handleRouteError } from "../utils/http"
10
+
11
+ export function registerUserRoutes(app: Elysia, _host: SixbHostView) {
12
+ return app
13
+ .get(
14
+ "/api/users",
15
+ async (context) => {
16
+ const { query, set } = context
17
+ const sixb = requireRequestSixb(context)
18
+
19
+ try {
20
+ const page = await sixb.users.list(ListUsersQuerySchema.parse(query))
21
+ return { users: [...page.users], hasMore: page.hasMore, total: page.total }
22
+ } catch (error) {
23
+ return handleRouteError(error, set)
24
+ }
25
+ },
26
+ {
27
+ query: ListUsersQuerySchema,
28
+ response: {
29
+ 200: ListUsersResponseSchema,
30
+ 400: ErrorResponseSchema,
31
+ 403: ErrorResponseSchema,
32
+ },
33
+ detail: {
34
+ summary: "List project members",
35
+ tags: [OPENAPI_TAGS.users.name],
36
+ operationId: "listUsers",
37
+ security: accessTokenSecurityRequirement("listUsers"),
38
+ },
39
+ }
40
+ )
41
+ .get(
42
+ "/api/users/:userId",
43
+ async (context) => {
44
+ const { params, set } = context
45
+ const sixb = requireRequestSixb(context)
46
+
47
+ try {
48
+ const profile = await sixb.users.get(userRef(params.userId))
49
+ if (profile) return profile
50
+
51
+ set.status = 404
52
+ return { error: `[SixbServer] User '${params.userId}' not found.` }
53
+ } catch (error) {
54
+ return handleRouteError(error, set)
55
+ }
56
+ },
57
+ {
58
+ params: UserParamsSchema,
59
+ response: {
60
+ 200: UserProfileSchema,
61
+ 400: ErrorResponseSchema,
62
+ 403: ErrorResponseSchema,
63
+ 404: ErrorResponseSchema,
64
+ },
65
+ detail: {
66
+ summary: "Get a project member",
67
+ tags: [OPENAPI_TAGS.users.name],
68
+ operationId: "getUser",
69
+ security: accessTokenSecurityRequirement("getUser"),
70
+ },
71
+ }
72
+ )
73
+ }
@@ -9,7 +9,7 @@ import {
9
9
  import { publishAgentRunCancel } from "@sixb/core/internal/agents"
10
10
  import { createSixbError, toSixbFailure } from "@sixb/core/internal/errors"
11
11
  import { assertValidFileRefs } from "@sixb/core/internal/ontology"
12
- import type { Sixb, WorkflowRunView } from "@sixb/core/internal/request-execution"
12
+ import type { WorkflowRunView } from "@sixb/core/internal/request-execution"
13
13
  import {
14
14
  snapshotWorkflowInterventionResponse,
15
15
  type WorkflowInterventionNodeDefinition,
@@ -23,7 +23,7 @@ import { AGENT_RUN_FAILURE_CODES, WORKFLOW_RUN_FAILURE_CODES } from "@sixb/core/
23
23
  import type { Elysia } from "elysia"
24
24
  import { z } from "zod"
25
25
  import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
26
- import { requestAuthState, requireRequestSixb } from "../auth/scope"
26
+ import { requestActor, requestAuthState, requireRequestSixb } from "../auth/scope"
27
27
  import {
28
28
  createContextualFileContentResponse,
29
29
  fileContentGetResponses,
@@ -177,10 +177,6 @@ function isRecord(value: unknown): value is Readonly<Record<string, unknown>> {
177
177
  return value !== null && typeof value === "object" && !Array.isArray(value)
178
178
  }
179
179
 
180
- function principalForExecution(sixb: Sixb): Principal {
181
- return sixb.execution.requestedBy ?? SYSTEM_PRINCIPAL
182
- }
183
-
184
180
  function toWorkflowCancellationFailure(input: {
185
181
  readonly message: string
186
182
  readonly at: Date
@@ -741,7 +737,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
741
737
  projectId: host.id,
742
738
  id: intervention.id,
743
739
  response,
744
- submittedBy: serializePrincipal(principalForExecution(sixb)),
740
+ submittedBy: serializePrincipal(requestActor(sixb)),
745
741
  })
746
742
 
747
743
  const [job] = await host.queues.workflows.enqueue({
@@ -850,7 +846,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
850
846
  projectId: host.id,
851
847
  id: intervention.id,
852
848
  cancelledAt,
853
- cancelledBy: serializePrincipal(principalForExecution(sixb)),
849
+ cancelledBy: serializePrincipal(requestActor(sixb)),
854
850
  })
855
851
  const cancelledNode = await tx.workflowRuns.nodes.finish({
856
852
  projectId: host.id,
@@ -1156,7 +1152,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1156
1152
  projectId: host.id,
1157
1153
  id: intervention.id,
1158
1154
  cancelledAt,
1159
- cancelledBy: serializePrincipal(principalForExecution(sixb)),
1155
+ cancelledBy: serializePrincipal(requestActor(sixb)),
1160
1156
  })
1161
1157
  }
1162
1158
  }
@@ -1316,6 +1312,7 @@ export function registerWorkflowRoutes(app: Elysia, host: SixbHostView) {
1316
1312
  const input = {
1317
1313
  workflowId: params.workflowId,
1318
1314
  input: parsedBody.input ?? {},
1315
+ ...(parsedBody.runId === undefined ? {} : { runId: parsedBody.runId }),
1319
1316
  source: { type: "manual" } as const,
1320
1317
  }
1321
1318
  const result = await sixb.workflows.requestById(input)
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AGENT_ACTIVITY_STREAM_ID,
3
- type AgentRunActivityEvent,
4
- isAgentRunActivityEvent,
3
+ type AgentActivityEvent,
4
+ isAgentActivityEvent,
5
5
  } from "@sixb/core/agents/streams"
6
6
  import { BrokerCursorExpiredError, type BrokerRecord } from "@sixb/core/broker"
7
7
  import {
@@ -79,6 +79,10 @@ export function parseAgentStreamMessage(payload: unknown):
79
79
  return { ok: true, data: parsed.data }
80
80
  }
81
81
 
82
+ /**
83
+ * A run's stream reaches whoever reads its thread: a turn's conversation, or a sub-agent's, which
84
+ * is read through its conversation. Either starts with the run's snapshot.
85
+ */
82
86
  export async function canAccessAgentRunStream(
83
87
  sixb: Sixb,
84
88
  runId: string
@@ -90,9 +94,10 @@ export async function canAccessAgentRunStream(
90
94
  return { ok: true }
91
95
  }
92
96
 
97
+ /** A run's or an approval's activity reaches whoever reads the turn it belongs to. */
93
98
  export async function canAccessAgentThreadActivity(
94
99
  sixb: Sixb,
95
- event: AgentRunActivityEvent
100
+ event: AgentActivityEvent
96
101
  ): Promise<boolean> {
97
102
  const run = await sixb.agent.runs.getById(event.runId)
98
103
  return run?.projectId === event.projectId && run.threadId === event.threadId
@@ -311,9 +316,9 @@ async function sendVisibleActivityRecords(
311
316
  ws: { send: (message: string) => void },
312
317
  records: readonly BrokerRecord[]
313
318
  ): Promise<void> {
314
- const events: AgentRunActivityEvent[] = []
319
+ const events: AgentActivityEvent[] = []
315
320
  for (const record of records) {
316
- if (isAgentRunActivityEvent(record.payload)) events.push(record.payload)
321
+ if (isAgentActivityEvent(record.payload)) events.push(record.payload)
317
322
  }
318
323
  const visible = await Promise.all(
319
324
  events.map((event) => canAccessAgentThreadActivity(sixb, event))
@@ -202,6 +202,8 @@ const ActivityTimelineEntrySchema = z.discriminatedUnion("kind", [
202
202
  executionId: z.string(),
203
203
  runId: z.string(),
204
204
  threadId: z.string(),
205
+ /** Only for a reader with can.observe(agent.threads), who can open the conversation. */
206
+ thread: z.object({ title: z.string().optional() }).optional(),
205
207
  status: AgentRunStatusSchema,
206
208
  messages: z.number(),
207
209
  cost: AiCostSummarySchema.optional(),
@@ -0,0 +1,129 @@
1
+ import { SIXB_ERROR_CODES } from "@sixb/core/internal/errors"
2
+ import {
3
+ AGENT_APPROVAL_MODES,
4
+ AGENT_APPROVAL_STATUSES,
5
+ AGENT_HOLDING_APPROVAL_MODES,
6
+ } from "@sixb/core/storage"
7
+ import { z } from "zod"
8
+ import { ActionRunFailureSchema, ActionSubjectSchema } from "./actions"
9
+ import { JsonValueSchema, PrincipalSchema, sixbFailureSchema } from "./common"
10
+
11
+ /**
12
+ * What the Agent may change without asking: `manual` asks for every action and workflow,
13
+ * `accept-edits` runs the actions that only change Sixb, `auto` runs everything.
14
+ */
15
+ export const AgentApprovalModeSchema = z.enum(AGENT_APPROVAL_MODES)
16
+
17
+ export const AgentApprovalStatusSchema = z.enum(AGENT_APPROVAL_STATUSES)
18
+
19
+ /** Where your mode comes from: your choice in the thread, your default, or none yet. */
20
+ export const AgentApprovalModeSourceSchema = z.enum(["thread", "default", "fallback", "run"])
21
+
22
+ /** The held call as the Agent asked for it, without its params. */
23
+ export const AgentApprovalCallSummarySchema = z.discriminatedUnion("kind", [
24
+ z.object({ kind: z.literal("action"), actionId: z.string(), subject: ActionSubjectSchema }),
25
+ z.object({ kind: z.literal("workflow"), workflowId: z.string() }),
26
+ ])
27
+
28
+ /** The held call, as it runs once approved. */
29
+ export const AgentApprovalCallSchema = z.discriminatedUnion("kind", [
30
+ z.object({
31
+ kind: z.literal("action"),
32
+ actionId: z.string(),
33
+ subject: ActionSubjectSchema,
34
+ /** Normalized: what runs once approved. */
35
+ params: z.record(JsonValueSchema),
36
+ actionRunId: z.string(),
37
+ /** `external` when the action has a writeback or effects. */
38
+ effect: z.enum(["ontology", "external"]),
39
+ }),
40
+ z.object({
41
+ kind: z.literal("workflow"),
42
+ workflowId: z.string(),
43
+ /** As the run stores it. */
44
+ input: z.record(JsonValueSchema),
45
+ workflowRunId: z.string(),
46
+ }),
47
+ ])
48
+
49
+ /** What the approved call gave when it ran. */
50
+ export const AgentApprovalOutcomeSchema = z.discriminatedUnion("kind", [
51
+ z.object({
52
+ kind: z.literal("action-run"),
53
+ runId: z.string(),
54
+ status: z.enum(["succeeded", "failed"]),
55
+ error: ActionRunFailureSchema.optional(),
56
+ }),
57
+ z.object({ kind: z.literal("workflow-run"), runId: z.string(), queuedAt: z.string() }),
58
+ z.object({ kind: z.literal("error"), error: sixbFailureSchema(SIXB_ERROR_CODES) }),
59
+ ])
60
+
61
+ export const AgentApprovalSchema = z.object({
62
+ id: z.string(),
63
+ threadId: z.string(),
64
+ /** The turn that made the call. */
65
+ runId: z.string(),
66
+ /** The turn itself, or the child of it that made the call. */
67
+ callerRunId: z.string(),
68
+ /** The child that made the call, by the key the turn spawned it with; absent for the turn's own. */
69
+ caller: z.object({ runId: z.string(), key: z.string() }).optional(),
70
+ /** Who asked for the turn: the only one who decides. */
71
+ requestedBy: PrincipalSchema,
72
+ /** The mode that held the call. */
73
+ mode: z.enum(AGENT_HOLDING_APPROVAL_MODES),
74
+ status: AgentApprovalStatusSchema,
75
+ call: AgentApprovalCallSchema,
76
+ createdAt: z.string(),
77
+ expiresAt: z.string(),
78
+ decidedAt: z.string().optional(),
79
+ decidedBy: PrincipalSchema.optional(),
80
+ outcome: AgentApprovalOutcomeSchema.optional(),
81
+ /** Whether a later message told the Agent how it ended. */
82
+ reported: z.boolean(),
83
+ })
84
+
85
+ export const AgentApprovalListQuerySchema = z.object({
86
+ status: AgentApprovalStatusSchema.optional(),
87
+ runId: z.string().min(1).optional(),
88
+ limit: z.string().optional(),
89
+ offset: z.string().optional(),
90
+ })
91
+
92
+ export const MyAgentApprovalListQuerySchema = AgentApprovalListQuerySchema.omit({ runId: true })
93
+
94
+ export const AgentApprovalListResponseSchema = z.object({
95
+ approvals: z.array(AgentApprovalSchema),
96
+ hasMore: z.boolean(),
97
+ total: z.number(),
98
+ })
99
+
100
+ export const AgentApprovalParamsSchema = z.object({
101
+ threadId: z.string().min(1),
102
+ approvalId: z.string().min(1),
103
+ })
104
+
105
+ export const DecideAgentApprovalBodySchema = z
106
+ .object({
107
+ decision: z.enum(["approve", "deny"]),
108
+ /** With `approve`: also let your turns in this thread run such calls without asking. */
109
+ always: z.literal(true).optional(),
110
+ })
111
+ .strict()
112
+
113
+ export const AgentPreferencesBodySchema = z
114
+ .object({ approvalMode: AgentApprovalModeSchema })
115
+ .strict()
116
+
117
+ export const AgentThreadApprovalModeBodySchema = z
118
+ .object({
119
+ /** `null` clears your choice: your turns in the thread follow your default again. */
120
+ approvalMode: AgentApprovalModeSchema.nullable(),
121
+ })
122
+ .strict()
123
+
124
+ export const AgentPreferencesSchema = z.object({
125
+ /** The mode of your turns in threads where you chose none. */
126
+ approvalMode: AgentApprovalModeSchema,
127
+ /** `fallback` until you choose a default. */
128
+ approvalModeSource: AgentApprovalModeSourceSchema.exclude(["thread", "run"]),
129
+ })
@@ -0,0 +1,96 @@
1
+ import { z } from "zod"
2
+ import { ErrorResponseSchema, PrincipalSchema } from "./common"
3
+
4
+ const AgentMemoryFileSchema = z.object({
5
+ path: z.string().describe("The file's path from the repo root, such as projects/payments.md"),
6
+ contents: z.string(),
7
+ })
8
+
9
+ const AgentMemoryChangeSchema = z.object({
10
+ path: z.string().min(1).describe("The file's path from the repo root"),
11
+ contents: z.string().nullable().describe("The file's new contents, or null to delete it"),
12
+ })
13
+
14
+ export const AgentMemoryParamsSchema = z.object({
15
+ repo: z
16
+ .enum(["user", "project"])
17
+ .describe("user: the caller's own memory. project: the memory the whole project shares."),
18
+ })
19
+
20
+ export const AgentMemoryRepoResponseSchema = z.object({
21
+ repo: z.enum(["user", "project"]),
22
+ revision: z.number().int().nonnegative().describe("0 before the first save"),
23
+ files: z.array(AgentMemoryFileSchema).describe("Ordered by path"),
24
+ })
25
+
26
+ export const AgentMemoryRepoQuerySchema = z
27
+ .object({
28
+ revision: z
29
+ .string()
30
+ .regex(/^\d+$/)
31
+ .optional()
32
+ .describe("Read the repo as this revision left it, such as one listed in its history"),
33
+ })
34
+ .strict()
35
+
36
+ export const AgentMemoryRevisionListQuerySchema = z
37
+ .object({ limit: z.string().optional(), offset: z.string().optional() })
38
+ .strict()
39
+
40
+ export const AgentMemoryRevisionListResponseSchema = z.object({
41
+ revisions: z
42
+ .array(
43
+ z.object({
44
+ revision: z.number().int().positive(),
45
+ message: z.string(),
46
+ author: PrincipalSchema,
47
+ source: z.string().optional().describe("The conversation the save came from"),
48
+ changes: z
49
+ .array(z.object({ path: z.string(), deleted: z.boolean() }))
50
+ .describe("The paths the revision wrote, ordered by path"),
51
+ createdAt: z.string(),
52
+ })
53
+ )
54
+ .describe("Newest first"),
55
+ hasMore: z.boolean(),
56
+ total: z.number().int(),
57
+ })
58
+
59
+ export const SaveAgentMemoryBodySchema = z
60
+ .object({
61
+ baseRevision: z
62
+ .number()
63
+ .int()
64
+ .nonnegative()
65
+ .describe("The revision the changes were made against"),
66
+ message: z.string().describe("What was learned, as the revision's entry in the history"),
67
+ changes: z.array(AgentMemoryChangeSchema).min(1),
68
+ })
69
+ .strict()
70
+
71
+ export const SavedAgentMemoryResponseSchema = z.object({
72
+ repo: z.enum(["user", "project"]),
73
+ revision: z.number().int().positive(),
74
+ warnings: z
75
+ .array(z.object({ path: z.string(), link: z.string() }))
76
+ .describe("Links in the saved repo that point at no file"),
77
+ })
78
+
79
+ export const AgentMemoryErrorResponseSchema = ErrorResponseSchema.extend({
80
+ code: z
81
+ .string()
82
+ .optional()
83
+ .describe(
84
+ "Stable machine-readable failure code: invalid_save, not_allowed, conflict, or storage_unavailable."
85
+ ),
86
+ })
87
+
88
+ export const AgentMemoryConflictResponseSchema = ErrorResponseSchema.extend({
89
+ code: z.literal("conflict"),
90
+ revision: z.number().int().nonnegative().describe("The repo's latest revision"),
91
+ conflicts: z
92
+ .array(AgentMemoryChangeSchema)
93
+ .describe("Files another save changed after the base revision, as they are now"),
94
+ })
95
+
96
+ export const DeleteAgentMemoryResponseSchema = z.object({ deleted: z.literal(true) })