@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.
- package/dist/artifacts/frame.d.ts +18 -0
- package/dist/artifacts/frame.d.ts.map +1 -0
- package/dist/auth/browser-origin.d.ts +10 -1
- package/dist/auth/browser-origin.d.ts.map +1 -1
- package/dist/auth/experience.d.ts +1 -0
- package/dist/auth/experience.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/responses.d.ts +1 -1
- package/dist/auth/responses.d.ts.map +1 -1
- package/dist/auth/scope.d.ts +19 -3
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/files/content.d.ts +2 -3
- package/dist/files/content.d.ts.map +1 -1
- package/dist/index.js +10636 -7071
- package/dist/index.js.map +56 -38
- package/dist/models/display.d.ts +27 -0
- package/dist/models/display.d.ts.map +1 -1
- package/dist/openapi/components.d.ts +14 -0
- package/dist/openapi/components.d.ts.map +1 -0
- package/dist/openapi/tags.d.ts +22 -2
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +3 -0
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +5 -5
- package/dist/routes/activity.d.ts +35 -0
- package/dist/routes/activity.d.ts.map +1 -0
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agent-approval-gate.d.ts +27 -0
- package/dist/routes/agent-approval-gate.d.ts.map +1 -0
- package/dist/routes/agent-approvals.d.ts +599 -0
- package/dist/routes/agent-approvals.d.ts.map +1 -0
- package/dist/routes/agent-children.d.ts +318 -0
- package/dist/routes/agent-children.d.ts.map +1 -0
- package/dist/routes/agent-memory.d.ts +267 -0
- package/dist/routes/agent-memory.d.ts.map +1 -0
- package/dist/routes/agents.d.ts +1008 -98
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/ai-accounting.d.ts.map +1 -1
- package/dist/routes/artifact-frames.d.ts +98 -0
- package/dist/routes/artifact-frames.d.ts.map +1 -0
- package/dist/routes/artifacts.d.ts +1508 -0
- package/dist/routes/artifacts.d.ts.map +1 -0
- package/dist/routes/auth.d.ts +117 -11
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +84 -84
- package/dist/routes/connector-connections.d.ts +2 -2
- package/dist/routes/connectors.d.ts +2 -2
- package/dist/routes/datasets.d.ts +27 -27
- package/dist/routes/events.d.ts +5 -5
- package/dist/routes/files.d.ts +14 -14
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/links.d.ts +2 -2
- package/dist/routes/logs.d.ts +5 -5
- package/dist/routes/model-calls.d.ts +155 -0
- package/dist/routes/model-calls.d.ts.map +1 -0
- package/dist/routes/model-generations.d.ts +400 -0
- package/dist/routes/model-generations.d.ts.map +1 -0
- package/dist/routes/models.d.ts +434 -1
- package/dist/routes/models.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +71 -40
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/observed-agent-threads.d.ts +682 -0
- package/dist/routes/observed-agent-threads.d.ts.map +1 -0
- package/dist/routes/ontology.d.ts +66 -62
- package/dist/routes/ontology.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +53 -53
- package/dist/routes/projections.d.ts +63 -63
- package/dist/routes/rules.d.ts +2 -2
- package/dist/routes/share-grants.d.ts +4 -4
- package/dist/routes/syncs.d.ts +18 -18
- package/dist/routes/users.d.ts +117 -0
- package/dist/routes/users.d.ts.map +1 -0
- package/dist/routes/webhook-runs.d.ts +1 -1
- package/dist/routes/workflows.d.ts +142 -76
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/agents.d.ts +7 -2
- package/dist/routes/ws/agents.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts +6 -6
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +14 -14
- package/dist/routes/ws/subscription-hub.d.ts +8 -3
- package/dist/routes/ws/subscription-hub.d.ts.map +1 -1
- package/dist/schemas/actions.d.ts +15 -15
- package/dist/schemas/activity.d.ts +1298 -0
- package/dist/schemas/activity.d.ts.map +1 -0
- package/dist/schemas/agent-approvals.d.ts +1091 -0
- package/dist/schemas/agent-approvals.d.ts.map +1 -0
- package/dist/schemas/agent-memory.d.ts +250 -0
- package/dist/schemas/agent-memory.d.ts.map +1 -0
- package/dist/schemas/agents.d.ts +5485 -460
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +1315 -436
- package/dist/schemas/ai-accounting.d.ts.map +1 -1
- package/dist/schemas/ai-limits.d.ts +36 -36
- package/dist/schemas/ai-usage.d.ts +12 -0
- package/dist/schemas/ai-usage.d.ts.map +1 -1
- package/dist/schemas/artifacts.d.ts +1857 -0
- package/dist/schemas/artifacts.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +125 -52
- package/dist/schemas/auth.d.ts.map +1 -1
- package/dist/schemas/connectors.d.ts +42 -42
- package/dist/schemas/datasets.d.ts +108 -108
- package/dist/schemas/event-payloads.d.ts +6 -6
- package/dist/schemas/events.d.ts +32 -32
- package/dist/schemas/events.d.ts.map +1 -1
- package/dist/schemas/files.d.ts +24 -24
- package/dist/schemas/links.d.ts +2 -2
- package/dist/schemas/logs.d.ts +32 -32
- package/dist/schemas/models.d.ts +8889 -10
- package/dist/schemas/models.d.ts.map +1 -1
- package/dist/schemas/objects.d.ts +48 -12
- package/dist/schemas/objects.d.ts.map +1 -1
- package/dist/schemas/ontology.d.ts +127 -104
- package/dist/schemas/ontology.d.ts.map +1 -1
- package/dist/schemas/pipelines.d.ts +166 -166
- package/dist/schemas/projections.d.ts +346 -346
- package/dist/schemas/rules.d.ts +4 -4
- package/dist/schemas/share-grants.d.ts +14 -14
- package/dist/schemas/syncs.d.ts +40 -40
- package/dist/schemas/users.d.ts +72 -0
- package/dist/schemas/users.d.ts.map +1 -0
- package/dist/schemas/webhook-runs.d.ts +6 -6
- package/dist/schemas/workflows.d.ts +769 -254
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/artifacts/frame.ts +51 -0
- package/src/auth/browser-origin.ts +20 -5
- package/src/auth/experience.ts +1 -1
- package/src/auth/guard.ts +2 -2
- package/src/auth/public-routes.ts +16 -0
- package/src/auth/responses.ts +7 -6
- package/src/auth/scope.ts +32 -3
- package/src/files/content.ts +9 -13
- package/src/models/display.ts +61 -16
- package/src/openapi/components.ts +54 -0
- package/src/openapi/tags.ts +20 -0
- package/src/registerRoutes.ts +23 -0
- package/src/routes/activity.ts +327 -0
- package/src/routes/agent-api-gateway.ts +115 -91
- package/src/routes/agent-approval-gate.ts +213 -0
- package/src/routes/agent-approvals.ts +299 -0
- package/src/routes/agent-children.ts +209 -0
- package/src/routes/agent-memory.ts +210 -0
- package/src/routes/agents.ts +364 -143
- package/src/routes/ai-accounting.ts +4 -0
- package/src/routes/artifact-frames.ts +144 -0
- package/src/routes/artifacts.ts +717 -0
- package/src/routes/auth.ts +306 -13
- package/src/routes/file-downloads.ts +1 -3
- package/src/routes/files.ts +6 -7
- package/src/routes/model-calls.ts +120 -0
- package/src/routes/model-generations.ts +245 -0
- package/src/routes/models.ts +116 -9
- package/src/routes/objects.ts +55 -61
- package/src/routes/observed-agent-threads.ts +253 -0
- package/src/routes/ontology.ts +1 -0
- package/src/routes/users.ts +73 -0
- package/src/routes/workflows.ts +6 -9
- package/src/routes/ws/agents.ts +10 -5
- package/src/routes/ws/events.ts +3 -2
- package/src/routes/ws/subscription-hub.ts +53 -20
- package/src/schemas/activity.ts +287 -0
- package/src/schemas/agent-approvals.ts +129 -0
- package/src/schemas/agent-memory.ts +96 -0
- package/src/schemas/agents.ts +240 -2
- package/src/schemas/ai-accounting.ts +40 -4
- package/src/schemas/ai-usage.ts +10 -0
- package/src/schemas/artifacts.ts +246 -0
- package/src/schemas/auth.ts +25 -0
- package/src/schemas/models.ts +197 -1
- package/src/schemas/objects.ts +181 -0
- package/src/schemas/ontology.ts +1 -0
- package/src/schemas/users.ts +24 -0
- package/src/schemas/workflows.ts +2 -0
- package/src/server.ts +34 -19
- package/src/utils/http.ts +2 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACTIVITY_BATCH_LIMIT,
|
|
3
|
+
ACTIVITY_EVENT_ID_PATTERN,
|
|
4
|
+
ACTIVITY_HOSTNAME_PATTERN,
|
|
5
|
+
ACTIVITY_ID_MAX_LENGTH,
|
|
6
|
+
ACTIVITY_INTERACTION_NAME_MAX_LENGTH,
|
|
7
|
+
ACTIVITY_INTERACTION_NAME_PATTERN,
|
|
8
|
+
ACTIVITY_LABEL_MAX_LENGTH,
|
|
9
|
+
ACTIVITY_LABEL_PATTERN,
|
|
10
|
+
ACTIVITY_MAX_PAGE_SIZE,
|
|
11
|
+
ACTIVITY_MAX_PERIOD_MS,
|
|
12
|
+
ACTIVITY_REFERRER_MAX_LENGTH,
|
|
13
|
+
ACTIVITY_ROUTE_MAX_LENGTH,
|
|
14
|
+
ACTIVITY_VISIT_ID_PATTERN,
|
|
15
|
+
isActivityRoutePattern,
|
|
16
|
+
} from "@sixb/core/internal/storage"
|
|
17
|
+
import { z } from "zod"
|
|
18
|
+
import { ActionRunStatusSchema } from "./actions"
|
|
19
|
+
import { AgentRunStatusSchema } from "./agents"
|
|
20
|
+
import { AiCostSummarySchema } from "./ai-accounting"
|
|
21
|
+
import { WorkflowRunStatusSchema } from "./workflows"
|
|
22
|
+
|
|
23
|
+
// The limits come from the activity policy, so the API refuses what the providers would.
|
|
24
|
+
const VisitIdSchema = z.string().regex(ACTIVITY_VISIT_ID_PATTERN)
|
|
25
|
+
|
|
26
|
+
const UserIdSchema = z
|
|
27
|
+
.string()
|
|
28
|
+
.min(1)
|
|
29
|
+
.max(ACTIVITY_ID_MAX_LENGTH)
|
|
30
|
+
.refine((value) => value.trim().length > 0, "Expected a user id")
|
|
31
|
+
|
|
32
|
+
const RouteSchema = z
|
|
33
|
+
.string()
|
|
34
|
+
.min(1)
|
|
35
|
+
.max(ACTIVITY_ROUTE_MAX_LENGTH)
|
|
36
|
+
.startsWith("/")
|
|
37
|
+
.refine(isActivityRoutePattern, "Expected a normalized route pattern")
|
|
38
|
+
|
|
39
|
+
const LabelSchema = z
|
|
40
|
+
.string()
|
|
41
|
+
.min(1)
|
|
42
|
+
.max(ACTIVITY_LABEL_MAX_LENGTH)
|
|
43
|
+
.regex(ACTIVITY_LABEL_PATTERN)
|
|
44
|
+
.refine((value) => value === value.trim(), "Expected a trimmed label")
|
|
45
|
+
|
|
46
|
+
const ActivityAttributionSchema = z
|
|
47
|
+
.object({
|
|
48
|
+
source: LabelSchema.optional(),
|
|
49
|
+
medium: LabelSchema.optional(),
|
|
50
|
+
campaign: LabelSchema.optional(),
|
|
51
|
+
referrer: z
|
|
52
|
+
.string()
|
|
53
|
+
.min(1)
|
|
54
|
+
.max(ACTIVITY_REFERRER_MAX_LENGTH)
|
|
55
|
+
.regex(ACTIVITY_HOSTNAME_PATTERN)
|
|
56
|
+
.optional(),
|
|
57
|
+
})
|
|
58
|
+
.strict()
|
|
59
|
+
|
|
60
|
+
export const ActivityEventInputSchema = z.discriminatedUnion("type", [
|
|
61
|
+
z
|
|
62
|
+
.object({
|
|
63
|
+
id: z.string().regex(ACTIVITY_EVENT_ID_PATTERN),
|
|
64
|
+
type: z.enum(["page.view", "visit.activity"]),
|
|
65
|
+
route: RouteSchema,
|
|
66
|
+
attribution: ActivityAttributionSchema.optional(),
|
|
67
|
+
})
|
|
68
|
+
.strict(),
|
|
69
|
+
z
|
|
70
|
+
.object({
|
|
71
|
+
id: z.string().regex(ACTIVITY_EVENT_ID_PATTERN),
|
|
72
|
+
type: z.literal("ui.interaction"),
|
|
73
|
+
name: z
|
|
74
|
+
.string()
|
|
75
|
+
.min(1)
|
|
76
|
+
.max(ACTIVITY_INTERACTION_NAME_MAX_LENGTH)
|
|
77
|
+
.regex(ACTIVITY_INTERACTION_NAME_PATTERN),
|
|
78
|
+
route: RouteSchema,
|
|
79
|
+
})
|
|
80
|
+
.strict(),
|
|
81
|
+
])
|
|
82
|
+
|
|
83
|
+
export const CaptureActivityBodySchema = z
|
|
84
|
+
.object({ events: z.array(ActivityEventInputSchema).min(1).max(ACTIVITY_BATCH_LIMIT) })
|
|
85
|
+
.strict()
|
|
86
|
+
.refine(
|
|
87
|
+
(body) => new Set(body.events.map((event) => event.id)).size === body.events.length,
|
|
88
|
+
"Event ids must be unique"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
export const ActivityCaptureOptionsSchema = z.object({
|
|
92
|
+
enabled: z.boolean(),
|
|
93
|
+
idleTimeoutMs: z.number(),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
export const ActivityCaptureResultSchema = z.object({
|
|
97
|
+
status: z.enum(["accepted", "disabled", "throttled"]),
|
|
98
|
+
accepted: z.number(),
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const ActivityActorSchema = z.discriminatedUnion("type", [
|
|
102
|
+
z.object({ type: z.literal("user"), userId: z.string() }),
|
|
103
|
+
z.object({
|
|
104
|
+
type: z.literal("share"),
|
|
105
|
+
grantId: z.string(),
|
|
106
|
+
definitionId: z.string().optional(),
|
|
107
|
+
}),
|
|
108
|
+
])
|
|
109
|
+
|
|
110
|
+
const ActivityVisitSchema = z.object({
|
|
111
|
+
id: VisitIdSchema,
|
|
112
|
+
actor: ActivityActorSchema,
|
|
113
|
+
attribution: ActivityAttributionSchema.nullable(),
|
|
114
|
+
startedAt: z.string().datetime(),
|
|
115
|
+
lastSeenAt: z.string().datetime(),
|
|
116
|
+
pageViews: z.number(),
|
|
117
|
+
interactions: z.number(),
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
export const ActivityVisitsPageSchema = z.object({
|
|
121
|
+
visits: z.array(ActivityVisitSchema),
|
|
122
|
+
hasMore: z.boolean(),
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
export const ActivityUsersPageSchema = z.object({
|
|
126
|
+
users: z.array(
|
|
127
|
+
z.object({
|
|
128
|
+
userId: z.string(),
|
|
129
|
+
displayName: z.string().optional(),
|
|
130
|
+
lastSeenAt: z.string().datetime(),
|
|
131
|
+
visits: z.number(),
|
|
132
|
+
pageViews: z.number(),
|
|
133
|
+
})
|
|
134
|
+
),
|
|
135
|
+
hasMore: z.boolean(),
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
export const ActivitySummarySchema = z.object({
|
|
139
|
+
users: z.number(),
|
|
140
|
+
visits: z.number(),
|
|
141
|
+
sharedVisits: z.number(),
|
|
142
|
+
pageViews: z.number(),
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
const ActivityConnectionStatusSchema = z.enum(["active", "expired", "revoked"])
|
|
146
|
+
|
|
147
|
+
const ActivitySessionConnectionSchema = z.object({
|
|
148
|
+
type: z.literal("session"),
|
|
149
|
+
device: z.object({ browser: z.string().optional(), os: z.string().optional() }),
|
|
150
|
+
clientName: z.string().optional(),
|
|
151
|
+
status: ActivityConnectionStatusSchema,
|
|
152
|
+
createdAt: z.string().datetime(),
|
|
153
|
+
lastSeenAt: z.string().datetime().optional(),
|
|
154
|
+
revokedAt: z.string().datetime().optional(),
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const ActivityShareConnectionSchema = z.object({
|
|
158
|
+
type: z.literal("share"),
|
|
159
|
+
grantId: z.string(),
|
|
160
|
+
definitionId: z.string().optional(),
|
|
161
|
+
status: ActivityConnectionStatusSchema,
|
|
162
|
+
createdAt: z.string().datetime(),
|
|
163
|
+
revokedAt: z.string().datetime().optional(),
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
const ActivityTimelineEntrySchema = z.discriminatedUnion("kind", [
|
|
167
|
+
z.object({
|
|
168
|
+
kind: z.literal("page"),
|
|
169
|
+
at: z.string().datetime(),
|
|
170
|
+
sequence: z.number(),
|
|
171
|
+
route: z.string(),
|
|
172
|
+
}),
|
|
173
|
+
z.object({
|
|
174
|
+
kind: z.literal("interaction"),
|
|
175
|
+
at: z.string().datetime(),
|
|
176
|
+
sequence: z.number(),
|
|
177
|
+
name: z.string(),
|
|
178
|
+
route: z.string(),
|
|
179
|
+
}),
|
|
180
|
+
z.object({
|
|
181
|
+
kind: z.literal("action"),
|
|
182
|
+
at: z.string().datetime(),
|
|
183
|
+
executionId: z.string(),
|
|
184
|
+
actionId: z.string(),
|
|
185
|
+
runId: z.string(),
|
|
186
|
+
status: z.union([ActionRunStatusSchema, z.literal("incomplete")]),
|
|
187
|
+
runVisible: z.boolean().describe("Whether the viewer may read the run itself."),
|
|
188
|
+
object: z.object({ objectTypeId: z.string(), primaryId: z.string() }).optional(),
|
|
189
|
+
}),
|
|
190
|
+
z.object({
|
|
191
|
+
kind: z.literal("workflow"),
|
|
192
|
+
at: z.string().datetime(),
|
|
193
|
+
executionId: z.string(),
|
|
194
|
+
workflowId: z.string(),
|
|
195
|
+
runId: z.string(),
|
|
196
|
+
status: z.union([WorkflowRunStatusSchema, z.literal("incomplete")]),
|
|
197
|
+
runVisible: z.boolean().describe("Whether the viewer may read the run itself."),
|
|
198
|
+
}),
|
|
199
|
+
z.object({
|
|
200
|
+
kind: z.literal("agent"),
|
|
201
|
+
at: z.string().datetime(),
|
|
202
|
+
executionId: z.string(),
|
|
203
|
+
runId: z.string(),
|
|
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(),
|
|
207
|
+
status: AgentRunStatusSchema,
|
|
208
|
+
messages: z.number(),
|
|
209
|
+
cost: AiCostSummarySchema.optional(),
|
|
210
|
+
}),
|
|
211
|
+
])
|
|
212
|
+
|
|
213
|
+
export const ActivityVisitTimelineSchema = z.object({
|
|
214
|
+
visit: ActivityVisitSchema,
|
|
215
|
+
connection: z
|
|
216
|
+
.discriminatedUnion("type", [ActivitySessionConnectionSchema, ActivityShareConnectionSchema])
|
|
217
|
+
.optional(),
|
|
218
|
+
entries: z.array(ActivityTimelineEntrySchema),
|
|
219
|
+
truncated: z.boolean(),
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
export const ActivityConnectionsPageSchema = z.object({
|
|
223
|
+
connections: z.array(
|
|
224
|
+
ActivitySessionConnectionSchema.extend({
|
|
225
|
+
visits: z.number(),
|
|
226
|
+
latestVisits: z.array(ActivityVisitSchema),
|
|
227
|
+
})
|
|
228
|
+
),
|
|
229
|
+
nextCursor: z.string().optional(),
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
export const ActivityCalendarSchema = z.object({
|
|
233
|
+
userId: z.string(),
|
|
234
|
+
year: z.number(),
|
|
235
|
+
days: z.array(z.object({ day: z.string(), visits: z.number(), pageViews: z.number() })),
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
const periodFields = {
|
|
239
|
+
from: z.string().datetime(),
|
|
240
|
+
to: z.string().datetime(),
|
|
241
|
+
userId: UserIdSchema.optional(),
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const PageSizeSchema = z.coerce.number().int().min(1).max(ACTIVITY_MAX_PAGE_SIZE)
|
|
245
|
+
|
|
246
|
+
const pageFields = {
|
|
247
|
+
limit: PageSizeSchema.optional(),
|
|
248
|
+
beforeAt: z.string().datetime().optional(),
|
|
249
|
+
beforeId: z.string().min(1).max(ACTIVITY_ID_MAX_LENGTH).optional(),
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function isBoundedPeriod(input: { readonly from: string; readonly to: string }): boolean {
|
|
253
|
+
const span = Date.parse(input.to) - Date.parse(input.from)
|
|
254
|
+
return span > 0 && span <= ACTIVITY_MAX_PERIOD_MS
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function hasWholeCursor(input: { readonly beforeAt?: string; readonly beforeId?: string }) {
|
|
258
|
+
return (input.beforeAt === undefined) === (input.beforeId === undefined)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export const ActivityPeriodQuerySchema = z
|
|
262
|
+
.object(periodFields)
|
|
263
|
+
.refine(isBoundedPeriod, "Expected an ordered period of at most 31 days")
|
|
264
|
+
|
|
265
|
+
export const ActivityPageQuerySchema = z
|
|
266
|
+
.object({ ...periodFields, ...pageFields })
|
|
267
|
+
.refine(isBoundedPeriod, "Expected an ordered period of at most 31 days")
|
|
268
|
+
.refine(hasWholeCursor, "beforeAt and beforeId go together")
|
|
269
|
+
|
|
270
|
+
export const ActivityCalendarQuerySchema = z.object({
|
|
271
|
+
userId: UserIdSchema,
|
|
272
|
+
year: z.coerce.number().int().min(1970).max(9998),
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
export const ActivityConnectionsQuerySchema = z.object({
|
|
276
|
+
userId: UserIdSchema,
|
|
277
|
+
limit: PageSizeSchema.optional(),
|
|
278
|
+
cursor: z
|
|
279
|
+
.string()
|
|
280
|
+
.min(1)
|
|
281
|
+
.max(200)
|
|
282
|
+
.regex(/^[A-Za-z0-9_-]+$/)
|
|
283
|
+
.optional()
|
|
284
|
+
.describe("The previous page's nextCursor."),
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
export const ActivityVisitParamsSchema = z.object({ visitId: VisitIdSchema })
|
|
@@ -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) })
|