@sixb/server 0.1.20 → 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 (179) hide show
  1. package/dist/artifacts/frame.d.ts +18 -0
  2. package/dist/artifacts/frame.d.ts.map +1 -0
  3. package/dist/auth/browser-origin.d.ts +10 -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/files/content.d.ts +2 -3
  13. package/dist/files/content.d.ts.map +1 -1
  14. package/dist/index.js +10636 -7071
  15. package/dist/index.js.map +56 -38
  16. package/dist/models/display.d.ts +27 -0
  17. package/dist/models/display.d.ts.map +1 -1
  18. package/dist/openapi/components.d.ts +14 -0
  19. package/dist/openapi/components.d.ts.map +1 -0
  20. package/dist/openapi/tags.d.ts +22 -2
  21. package/dist/openapi/tags.d.ts.map +1 -1
  22. package/dist/registerRoutes.d.ts +3 -0
  23. package/dist/registerRoutes.d.ts.map +1 -1
  24. package/dist/routes/actions.d.ts +5 -5
  25. package/dist/routes/activity.d.ts +35 -0
  26. package/dist/routes/activity.d.ts.map +1 -0
  27. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  28. package/dist/routes/agent-approval-gate.d.ts +27 -0
  29. package/dist/routes/agent-approval-gate.d.ts.map +1 -0
  30. package/dist/routes/agent-approvals.d.ts +599 -0
  31. package/dist/routes/agent-approvals.d.ts.map +1 -0
  32. package/dist/routes/agent-children.d.ts +318 -0
  33. package/dist/routes/agent-children.d.ts.map +1 -0
  34. package/dist/routes/agent-memory.d.ts +267 -0
  35. package/dist/routes/agent-memory.d.ts.map +1 -0
  36. package/dist/routes/agents.d.ts +1008 -98
  37. package/dist/routes/agents.d.ts.map +1 -1
  38. package/dist/routes/ai-accounting.d.ts.map +1 -1
  39. package/dist/routes/artifact-frames.d.ts +98 -0
  40. package/dist/routes/artifact-frames.d.ts.map +1 -0
  41. package/dist/routes/artifacts.d.ts +1508 -0
  42. package/dist/routes/artifacts.d.ts.map +1 -0
  43. package/dist/routes/auth.d.ts +117 -11
  44. package/dist/routes/auth.d.ts.map +1 -1
  45. package/dist/routes/connector-connection-runs.d.ts +84 -84
  46. package/dist/routes/connector-connections.d.ts +2 -2
  47. package/dist/routes/connectors.d.ts +2 -2
  48. package/dist/routes/datasets.d.ts +27 -27
  49. package/dist/routes/events.d.ts +5 -5
  50. package/dist/routes/files.d.ts +14 -14
  51. package/dist/routes/files.d.ts.map +1 -1
  52. package/dist/routes/links.d.ts +2 -2
  53. package/dist/routes/logs.d.ts +5 -5
  54. package/dist/routes/model-calls.d.ts +155 -0
  55. package/dist/routes/model-calls.d.ts.map +1 -0
  56. package/dist/routes/model-generations.d.ts +400 -0
  57. package/dist/routes/model-generations.d.ts.map +1 -0
  58. package/dist/routes/models.d.ts +434 -1
  59. package/dist/routes/models.d.ts.map +1 -1
  60. package/dist/routes/objects.d.ts +71 -40
  61. package/dist/routes/objects.d.ts.map +1 -1
  62. package/dist/routes/observed-agent-threads.d.ts +682 -0
  63. package/dist/routes/observed-agent-threads.d.ts.map +1 -0
  64. package/dist/routes/ontology.d.ts +66 -62
  65. package/dist/routes/ontology.d.ts.map +1 -1
  66. package/dist/routes/pipelines.d.ts +53 -53
  67. package/dist/routes/projections.d.ts +63 -63
  68. package/dist/routes/rules.d.ts +2 -2
  69. package/dist/routes/share-grants.d.ts +4 -4
  70. package/dist/routes/syncs.d.ts +18 -18
  71. package/dist/routes/users.d.ts +117 -0
  72. package/dist/routes/users.d.ts.map +1 -0
  73. package/dist/routes/webhook-runs.d.ts +1 -1
  74. package/dist/routes/workflows.d.ts +142 -76
  75. package/dist/routes/workflows.d.ts.map +1 -1
  76. package/dist/routes/ws/agents.d.ts +7 -2
  77. package/dist/routes/ws/agents.d.ts.map +1 -1
  78. package/dist/routes/ws/events.d.ts +6 -6
  79. package/dist/routes/ws/events.d.ts.map +1 -1
  80. package/dist/routes/ws/logs.d.ts +14 -14
  81. package/dist/routes/ws/subscription-hub.d.ts +8 -3
  82. package/dist/routes/ws/subscription-hub.d.ts.map +1 -1
  83. package/dist/schemas/actions.d.ts +15 -15
  84. package/dist/schemas/activity.d.ts +1298 -0
  85. package/dist/schemas/activity.d.ts.map +1 -0
  86. package/dist/schemas/agent-approvals.d.ts +1091 -0
  87. package/dist/schemas/agent-approvals.d.ts.map +1 -0
  88. package/dist/schemas/agent-memory.d.ts +250 -0
  89. package/dist/schemas/agent-memory.d.ts.map +1 -0
  90. package/dist/schemas/agents.d.ts +5485 -460
  91. package/dist/schemas/agents.d.ts.map +1 -1
  92. package/dist/schemas/ai-accounting.d.ts +1315 -436
  93. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  94. package/dist/schemas/ai-limits.d.ts +36 -36
  95. package/dist/schemas/ai-usage.d.ts +12 -0
  96. package/dist/schemas/ai-usage.d.ts.map +1 -1
  97. package/dist/schemas/artifacts.d.ts +1857 -0
  98. package/dist/schemas/artifacts.d.ts.map +1 -0
  99. package/dist/schemas/auth.d.ts +125 -52
  100. package/dist/schemas/auth.d.ts.map +1 -1
  101. package/dist/schemas/connectors.d.ts +42 -42
  102. package/dist/schemas/datasets.d.ts +108 -108
  103. package/dist/schemas/event-payloads.d.ts +6 -6
  104. package/dist/schemas/events.d.ts +32 -32
  105. package/dist/schemas/events.d.ts.map +1 -1
  106. package/dist/schemas/files.d.ts +24 -24
  107. package/dist/schemas/links.d.ts +2 -2
  108. package/dist/schemas/logs.d.ts +32 -32
  109. package/dist/schemas/models.d.ts +8889 -10
  110. package/dist/schemas/models.d.ts.map +1 -1
  111. package/dist/schemas/objects.d.ts +48 -12
  112. package/dist/schemas/objects.d.ts.map +1 -1
  113. package/dist/schemas/ontology.d.ts +127 -104
  114. package/dist/schemas/ontology.d.ts.map +1 -1
  115. package/dist/schemas/pipelines.d.ts +166 -166
  116. package/dist/schemas/projections.d.ts +346 -346
  117. package/dist/schemas/rules.d.ts +4 -4
  118. package/dist/schemas/share-grants.d.ts +14 -14
  119. package/dist/schemas/syncs.d.ts +40 -40
  120. package/dist/schemas/users.d.ts +72 -0
  121. package/dist/schemas/users.d.ts.map +1 -0
  122. package/dist/schemas/webhook-runs.d.ts +6 -6
  123. package/dist/schemas/workflows.d.ts +769 -254
  124. package/dist/schemas/workflows.d.ts.map +1 -1
  125. package/dist/server.d.ts +1 -0
  126. package/dist/server.d.ts.map +1 -1
  127. package/dist/utils/http.d.ts.map +1 -1
  128. package/package.json +7 -7
  129. package/src/artifacts/frame.ts +51 -0
  130. package/src/auth/browser-origin.ts +20 -5
  131. package/src/auth/experience.ts +1 -1
  132. package/src/auth/guard.ts +2 -2
  133. package/src/auth/public-routes.ts +16 -0
  134. package/src/auth/responses.ts +7 -6
  135. package/src/auth/scope.ts +32 -3
  136. package/src/files/content.ts +9 -13
  137. package/src/models/display.ts +61 -16
  138. package/src/openapi/components.ts +54 -0
  139. package/src/openapi/tags.ts +20 -0
  140. package/src/registerRoutes.ts +23 -0
  141. package/src/routes/activity.ts +327 -0
  142. package/src/routes/agent-api-gateway.ts +115 -91
  143. package/src/routes/agent-approval-gate.ts +213 -0
  144. package/src/routes/agent-approvals.ts +299 -0
  145. package/src/routes/agent-children.ts +209 -0
  146. package/src/routes/agent-memory.ts +210 -0
  147. package/src/routes/agents.ts +364 -143
  148. package/src/routes/ai-accounting.ts +4 -0
  149. package/src/routes/artifact-frames.ts +144 -0
  150. package/src/routes/artifacts.ts +717 -0
  151. package/src/routes/auth.ts +306 -13
  152. package/src/routes/file-downloads.ts +1 -3
  153. package/src/routes/files.ts +6 -7
  154. package/src/routes/model-calls.ts +120 -0
  155. package/src/routes/model-generations.ts +245 -0
  156. package/src/routes/models.ts +116 -9
  157. package/src/routes/objects.ts +55 -61
  158. package/src/routes/observed-agent-threads.ts +253 -0
  159. package/src/routes/ontology.ts +1 -0
  160. package/src/routes/users.ts +73 -0
  161. package/src/routes/workflows.ts +6 -9
  162. package/src/routes/ws/agents.ts +10 -5
  163. package/src/routes/ws/events.ts +3 -2
  164. package/src/routes/ws/subscription-hub.ts +53 -20
  165. package/src/schemas/activity.ts +287 -0
  166. package/src/schemas/agent-approvals.ts +129 -0
  167. package/src/schemas/agent-memory.ts +96 -0
  168. package/src/schemas/agents.ts +240 -2
  169. package/src/schemas/ai-accounting.ts +40 -4
  170. package/src/schemas/ai-usage.ts +10 -0
  171. package/src/schemas/artifacts.ts +246 -0
  172. package/src/schemas/auth.ts +25 -0
  173. package/src/schemas/models.ts +197 -1
  174. package/src/schemas/objects.ts +181 -0
  175. package/src/schemas/ontology.ts +1 -0
  176. package/src/schemas/users.ts +24 -0
  177. package/src/schemas/workflows.ts +2 -0
  178. package/src/server.ts +34 -19
  179. package/src/utils/http.ts +2 -0
@@ -0,0 +1,209 @@
1
+ import type { AgentChildRunView, AgentChildView, SixbHostView } from "@sixb/core"
2
+ import { agentRunStreamId } from "@sixb/core/internal/agents/streams"
3
+ import type { Elysia } from "elysia"
4
+ import { z } from "zod"
5
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
6
+ import { requireRequestSixb } from "../auth/scope"
7
+ import {
8
+ createContextualFileContentResponse,
9
+ fileContentGetResponses,
10
+ fileContentHeadResponses,
11
+ handleFileContentQueryValidationError,
12
+ } from "../files/content"
13
+ import { OPENAPI_TAGS } from "../openapi/tags"
14
+ import {
15
+ AgentChildListQuerySchema,
16
+ AgentChildListResponseSchema,
17
+ AgentChildSchema,
18
+ AgentThreadParamsSchema,
19
+ } from "../schemas/agents"
20
+ import { ErrorResponseSchema } from "../schemas/common"
21
+ import { FileContentQuerySchema } from "../schemas/files"
22
+ import { toIsoString, unconfiguredStorageResponse } from "../utils/http"
23
+ import { handleAgentRouteError } from "./agents"
24
+
25
+ /**
26
+ * A file of one run of a sub-agent: one its parent handed it (`/handedFiles/<n>/fileRef`), or one
27
+ * the run returned from `out/` (`/files/<n>/fileRef`). What a tool showed it is a file of its
28
+ * thread's messages.
29
+ */
30
+ export const AgentChildFileContentQuerySchema = FileContentQuerySchema.extend({
31
+ run: z.string().min(1),
32
+ path: z
33
+ .string()
34
+ .min(1)
35
+ .regex(
36
+ /^\/(?:handedFiles|files)(?:\/|$)/,
37
+ "Sub-agent file content paths must start with /handedFiles/ or /files/"
38
+ ),
39
+ })
40
+
41
+ const VISIBILITY =
42
+ "A sub-agent is visible exactly when its conversation is: to the thread's owner and participants; observers read it through the observed routes. What it did is its thread's messages, at `GET /api/agent-threads/:threadId/messages` with its `threadId`."
43
+
44
+ /** A sub-agent as the lists return it. */
45
+ export function serializeAgentChild(
46
+ child: AgentChildView
47
+ ): ReturnType<typeof AgentChildSchema.parse> {
48
+ return AgentChildSchema.parse({
49
+ id: child.id,
50
+ threadId: child.threadId,
51
+ projectId: child.projectId,
52
+ spawnedBy: child.spawnedBy,
53
+ key: child.key,
54
+ task: child.task,
55
+ model: child.model,
56
+ tier: child.tier,
57
+ reasoning: child.reasoning,
58
+ handedFiles: child.handedFiles,
59
+ status: child.status,
60
+ finishReason: child.finishReason,
61
+ error: child.error,
62
+ awaiting: child.awaiting,
63
+ ended: child.ended,
64
+ activeRunId: child.activeRunId,
65
+ createdAt: toIsoString(child.createdAt),
66
+ completedAt: child.completedAt ? toIsoString(child.completedAt) : undefined,
67
+ usage: child.usage,
68
+ cost: child.cost,
69
+ runs: child.runs.map(serializeAgentChildRun),
70
+ })
71
+ }
72
+
73
+ function serializeAgentChildRun(run: AgentChildRunView) {
74
+ return {
75
+ id: run.id,
76
+ parentRunId: run.parentRunId,
77
+ status: run.status,
78
+ finishReason: run.finishReason,
79
+ error: run.error,
80
+ modelId: run.modelId,
81
+ attempt: run.attempt,
82
+ streamId: agentRunStreamId(run.id),
83
+ createdAt: toIsoString(run.createdAt),
84
+ startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
85
+ completedAt: run.completedAt ? toIsoString(run.completedAt) : undefined,
86
+ result: run.result,
87
+ usage: run.usage,
88
+ cost: run.cost,
89
+ }
90
+ }
91
+
92
+ /** A file of a sub-agent's run, read through whoever may read the sub-agent. */
93
+ export function agentChildFileContentResponse(
94
+ host: SixbHostView,
95
+ context: {
96
+ readonly query: unknown
97
+ readonly request: Request
98
+ readonly set: { status?: number | string }
99
+ },
100
+ readChild: () => Promise<AgentChildView | null>,
101
+ options: { readonly head?: boolean } = {}
102
+ ) {
103
+ if (!host.storage.agents) {
104
+ return unconfiguredStorageResponse(context.set, "Agent storage")
105
+ }
106
+
107
+ return createContextualFileContentResponse({
108
+ blobStorage: host.blobStorage,
109
+ query: context.query,
110
+ querySchema: AgentChildFileContentQuerySchema,
111
+ request: context.request,
112
+ set: context.set,
113
+ head: options.head,
114
+ resolveRoot: async (query) => {
115
+ const child = await readChild()
116
+ const run = child?.runs.find((candidate) => candidate.id === query.run)
117
+ return child && run
118
+ ? { handedFiles: child.handedFiles, files: run.result?.files ?? [] }
119
+ : null
120
+ },
121
+ })
122
+ }
123
+
124
+ /**
125
+ * A conversation's sub-agents, and their files. What one did is its thread's: the thread routes
126
+ * read it, and `/api/agent-runs/:runId` its runs.
127
+ */
128
+ export function registerAgentChildRoutes(app: Elysia, host: SixbHostView) {
129
+ const readChild = (context: { readonly params: { readonly threadId: string } }) => () =>
130
+ requireRequestSixb(context).agent.threads.getChild(context.params.threadId)
131
+
132
+ return app
133
+ .get(
134
+ "/api/agent-threads/:threadId/children",
135
+ async (context) => {
136
+ const { params, set } = context
137
+ try {
138
+ if (!host.storage.agents) {
139
+ return unconfiguredStorageResponse(set, "Agent storage")
140
+ }
141
+
142
+ const query = AgentChildListQuerySchema.parse(context.query)
143
+ const result = await requireRequestSixb(context).agent.threads.listChildren(
144
+ params.threadId,
145
+ query.runId === undefined ? {} : { runId: query.runId }
146
+ )
147
+ if (!result) {
148
+ set.status = 404
149
+ return { error: "Agent thread not found" }
150
+ }
151
+
152
+ return AgentChildListResponseSchema.parse({
153
+ children: result.children.map(serializeAgentChild),
154
+ })
155
+ } catch (error) {
156
+ return handleAgentRouteError(error, set)
157
+ }
158
+ },
159
+ {
160
+ params: AgentThreadParamsSchema,
161
+ query: AgentChildListQuerySchema,
162
+ response: {
163
+ 200: AgentChildListResponseSchema,
164
+ 400: ErrorResponseSchema,
165
+ 404: ErrorResponseSchema,
166
+ 501: ErrorResponseSchema,
167
+ },
168
+ detail: {
169
+ summary: "List the sub-agents of an agent conversation",
170
+ description: `${VISIBILITY} \`runId\` keeps those one turn spawned. Each lists every run it took, the one at work by \`activeRunId\`.`,
171
+ tags: [OPENAPI_TAGS.agentThreads.name],
172
+ operationId: "listAgentThreadChildren",
173
+ },
174
+ }
175
+ )
176
+ .get(
177
+ "/api/agent-threads/:threadId/child-files/content",
178
+ (context) => agentChildFileContentResponse(host, context, readChild(context)),
179
+ {
180
+ params: AgentThreadParamsSchema,
181
+ query: AgentChildFileContentQuerySchema,
182
+ error: handleFileContentQueryValidationError,
183
+ detail: {
184
+ summary: "Get a file of a sub-agent",
185
+ description: `${VISIBILITY} \`threadId\` is the sub-agent's thread, \`run\` one of its runs, and \`path\` points into it: \`/handedFiles/0/fileRef\`, or \`/files/0/fileRef\` for what the run returned.`,
186
+ tags: [OPENAPI_TAGS.agentThreads.name],
187
+ operationId: "getAgentChildFileContent",
188
+ security: accessTokenSecurityRequirement("getAgentChildFileContent"),
189
+ responses: fileContentGetResponses({ optionalStorage: true }),
190
+ },
191
+ }
192
+ )
193
+ .head(
194
+ "/api/agent-threads/:threadId/child-files/content",
195
+ (context) => agentChildFileContentResponse(host, context, readChild(context), { head: true }),
196
+ {
197
+ params: AgentThreadParamsSchema,
198
+ query: AgentChildFileContentQuerySchema,
199
+ error: handleFileContentQueryValidationError,
200
+ detail: {
201
+ summary: "Head a file of a sub-agent",
202
+ tags: [OPENAPI_TAGS.agentThreads.name],
203
+ operationId: "headAgentChildFileContent",
204
+ security: accessTokenSecurityRequirement("headAgentChildFileContent"),
205
+ responses: fileContentHeadResponses({ optionalStorage: true }),
206
+ },
207
+ }
208
+ )
209
+ }
@@ -0,0 +1,210 @@
1
+ import { AgentMemoryError, type AgentMemoryRepoName } from "@sixb/core"
2
+ import type { Elysia } from "elysia"
3
+ import { ZodError } from "zod"
4
+ import { accessTokenSecurityRequirement } from "../auth/access-token-boundary"
5
+ import { requestAuthState, requireRequestSixb } from "../auth/scope"
6
+ import { OPENAPI_TAGS } from "../openapi/tags"
7
+ import {
8
+ AgentMemoryConflictResponseSchema,
9
+ AgentMemoryErrorResponseSchema,
10
+ AgentMemoryParamsSchema,
11
+ AgentMemoryRepoQuerySchema,
12
+ AgentMemoryRepoResponseSchema,
13
+ AgentMemoryRevisionListQuerySchema,
14
+ AgentMemoryRevisionListResponseSchema,
15
+ DeleteAgentMemoryResponseSchema,
16
+ SaveAgentMemoryBodySchema,
17
+ SavedAgentMemoryResponseSchema,
18
+ } from "../schemas/agent-memory"
19
+ import { handleRouteError, parseOptionalInt, toIsoString } from "../utils/http"
20
+
21
+ type RouteSet = { status?: number | string }
22
+
23
+ function handleAgentMemoryRouteError(error: unknown, set: RouteSet) {
24
+ if (error instanceof AgentMemoryError) {
25
+ switch (error.code) {
26
+ case "invalid_repo":
27
+ case "invalid_save":
28
+ set.status = 400
29
+ break
30
+ case "not_allowed":
31
+ set.status = 403
32
+ break
33
+ case "storage_unavailable":
34
+ set.status = 501
35
+ break
36
+ }
37
+ // The message says what to change, so the Agent can act on it as it is.
38
+ return { error: error.message, code: error.code }
39
+ }
40
+ if (error instanceof ZodError) {
41
+ set.status = 400
42
+ return { error: "Invalid Agent memory request" }
43
+ }
44
+ return handleRouteError(error, set)
45
+ }
46
+
47
+ function repoParam(params: unknown): AgentMemoryRepoName {
48
+ return AgentMemoryParamsSchema.parse(params).repo
49
+ }
50
+
51
+ export function registerAgentMemoryRoutes(app: Elysia) {
52
+ return app
53
+ .get(
54
+ "/api/agent-memory/:repo",
55
+ async (context) => {
56
+ try {
57
+ const revision = parseOptionalInt(
58
+ AgentMemoryRepoQuerySchema.parse(context.query).revision
59
+ )
60
+ const repo = await requireRequestSixb(context).agent.memory.get(
61
+ repoParam(context.params),
62
+ revision === undefined ? {} : { revision }
63
+ )
64
+ return AgentMemoryRepoResponseSchema.parse(repo)
65
+ } catch (error) {
66
+ return handleAgentMemoryRouteError(error, context.set)
67
+ }
68
+ },
69
+ {
70
+ params: AgentMemoryParamsSchema,
71
+ query: AgentMemoryRepoQuerySchema,
72
+ response: {
73
+ 200: AgentMemoryRepoResponseSchema,
74
+ 400: AgentMemoryErrorResponseSchema,
75
+ 403: AgentMemoryErrorResponseSchema,
76
+ 501: AgentMemoryErrorResponseSchema,
77
+ },
78
+ detail: {
79
+ summary: "Get an Agent memory repo",
80
+ description:
81
+ "Every file of the repo as of its latest revision, or as an earlier revision left it.",
82
+ tags: [OPENAPI_TAGS.agentMemory.name],
83
+ operationId: "getAgentMemory",
84
+ security: accessTokenSecurityRequirement("getAgentMemory"),
85
+ },
86
+ }
87
+ )
88
+ .get(
89
+ "/api/agent-memory/:repo/revisions",
90
+ async (context) => {
91
+ try {
92
+ const query = AgentMemoryRevisionListQuerySchema.parse(context.query)
93
+ const limit = parseOptionalInt(query.limit)
94
+ const offset = parseOptionalInt(query.offset)
95
+ const result = await requireRequestSixb(context).agent.memory.listRevisions(
96
+ repoParam(context.params),
97
+ {
98
+ ...(limit === undefined ? {} : { limit }),
99
+ ...(offset === undefined ? {} : { offset }),
100
+ }
101
+ )
102
+ return AgentMemoryRevisionListResponseSchema.parse({
103
+ ...result,
104
+ revisions: result.revisions.map((revision) => ({
105
+ ...revision,
106
+ createdAt: toIsoString(revision.createdAt),
107
+ })),
108
+ })
109
+ } catch (error) {
110
+ return handleAgentMemoryRouteError(error, context.set)
111
+ }
112
+ },
113
+ {
114
+ params: AgentMemoryParamsSchema,
115
+ query: AgentMemoryRevisionListQuerySchema,
116
+ response: {
117
+ 200: AgentMemoryRevisionListResponseSchema,
118
+ 400: AgentMemoryErrorResponseSchema,
119
+ 403: AgentMemoryErrorResponseSchema,
120
+ 501: AgentMemoryErrorResponseSchema,
121
+ },
122
+ detail: {
123
+ summary: "List an Agent memory repo's revisions",
124
+ description: "Each save is one revision, newest first.",
125
+ tags: [OPENAPI_TAGS.agentMemory.name],
126
+ operationId: "listAgentMemoryRevisions",
127
+ security: accessTokenSecurityRequirement("listAgentMemoryRevisions"),
128
+ },
129
+ }
130
+ )
131
+ .post(
132
+ "/api/agent-memory/:repo/revisions",
133
+ async (context) => {
134
+ try {
135
+ const repo = repoParam(context.params)
136
+ const body = SaveAgentMemoryBodySchema.parse(context.body)
137
+ // The conversation is the run's own, never a value the request supplies.
138
+ const { agentRun } = requestAuthState(context)
139
+ const result = await requireRequestSixb(context).agent.memory.save(repo, {
140
+ ...body,
141
+ ...(agentRun ? { source: `/agents/${agentRun.threadId}` } : {}),
142
+ })
143
+ if (!result.saved) {
144
+ context.set.status = 409
145
+ return AgentMemoryConflictResponseSchema.parse({
146
+ error:
147
+ "Another save changed these files since they were loaded. Merge their contents into yours and save again.",
148
+ code: "conflict",
149
+ revision: result.revision,
150
+ conflicts: result.conflicts,
151
+ })
152
+ }
153
+ context.set.status = 201
154
+ return SavedAgentMemoryResponseSchema.parse({
155
+ repo,
156
+ revision: result.revision,
157
+ warnings: result.warnings,
158
+ })
159
+ } catch (error) {
160
+ return handleAgentMemoryRouteError(error, context.set)
161
+ }
162
+ },
163
+ {
164
+ params: AgentMemoryParamsSchema,
165
+ body: SaveAgentMemoryBodySchema,
166
+ response: {
167
+ 201: SavedAgentMemoryResponseSchema,
168
+ 400: AgentMemoryErrorResponseSchema,
169
+ 403: AgentMemoryErrorResponseSchema,
170
+ 409: AgentMemoryConflictResponseSchema,
171
+ 501: AgentMemoryErrorResponseSchema,
172
+ },
173
+ detail: {
174
+ summary: "Save changes to an Agent memory repo",
175
+ description:
176
+ "Stores the changes as the repo's next revision. When another save changed one of the files after baseRevision, nothing is saved and the response holds those files as they are now.",
177
+ tags: [OPENAPI_TAGS.agentMemory.name],
178
+ operationId: "saveAgentMemory",
179
+ security: accessTokenSecurityRequirement("saveAgentMemory"),
180
+ },
181
+ }
182
+ )
183
+ .delete(
184
+ "/api/agent-memory/:repo",
185
+ async (context) => {
186
+ try {
187
+ await requireRequestSixb(context).agent.memory.delete(repoParam(context.params))
188
+ return DeleteAgentMemoryResponseSchema.parse({ deleted: true })
189
+ } catch (error) {
190
+ return handleAgentMemoryRouteError(error, context.set)
191
+ }
192
+ },
193
+ {
194
+ params: AgentMemoryParamsSchema,
195
+ response: {
196
+ 200: DeleteAgentMemoryResponseSchema,
197
+ 400: AgentMemoryErrorResponseSchema,
198
+ 403: AgentMemoryErrorResponseSchema,
199
+ 501: AgentMemoryErrorResponseSchema,
200
+ },
201
+ detail: {
202
+ summary: "Delete an Agent memory repo",
203
+ description: "Deletes the repo with its history.",
204
+ tags: [OPENAPI_TAGS.agentMemory.name],
205
+ operationId: "deleteAgentMemory",
206
+ security: accessTokenSecurityRequirement("deleteAgentMemory"),
207
+ },
208
+ }
209
+ )
210
+ }