@sealkeeper/schema 0.4.9 → 0.5.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.
@@ -0,0 +1,382 @@
1
+ import { z } from 'zod';
2
+ export declare const STATUS_WAITING_MAX = 20;
3
+ export declare const STATUS_DUELS_MAX = 5;
4
+ export declare const StatusRequest: z.ZodObject<{
5
+ issuedAt: z.ZodISODateTime;
6
+ }, z.core.$strict>;
7
+ export type StatusRequest = z.infer<typeof StatusRequest>;
8
+ export declare const STATUS_SEAL_STATES: readonly ['issued', 'held', 'dormant'];
9
+ export declare const StatusSealState: z.ZodEnum<{
10
+ dormant: "dormant";
11
+ held: "held";
12
+ issued: "issued";
13
+ }>;
14
+ export type StatusSealState = z.infer<typeof StatusSealState>;
15
+ export declare const StatusSeal: z.ZodObject<{
16
+ state: z.ZodEnum<{
17
+ dormant: "dormant";
18
+ held: "held";
19
+ issued: "issued";
20
+ }>;
21
+ reason: z.ZodNullable<z.ZodEnum<{
22
+ collusion: "collusion";
23
+ fraud: "fraud";
24
+ key_compromise: "key_compromise";
25
+ operator_ban: "operator_ban";
26
+ safety: "safety";
27
+ }>>;
28
+ dormantDays: z.ZodNullable<z.ZodInt>;
29
+ }, z.core.$strict>;
30
+ export type StatusSeal = z.infer<typeof StatusSeal>;
31
+ export declare const CoreStatus: z.ZodObject<{
32
+ agent: z.ZodObject<{
33
+ id: z.ZodString;
34
+ handle: z.ZodString;
35
+ version: z.ZodString;
36
+ }, z.core.$strict>;
37
+ seal: z.ZodObject<{
38
+ state: z.ZodEnum<{
39
+ dormant: "dormant";
40
+ held: "held";
41
+ issued: "issued";
42
+ }>;
43
+ reason: z.ZodNullable<z.ZodEnum<{
44
+ collusion: "collusion";
45
+ fraud: "fraud";
46
+ key_compromise: "key_compromise";
47
+ operator_ban: "operator_ban";
48
+ safety: "safety";
49
+ }>>;
50
+ dormantDays: z.ZodNullable<z.ZodInt>;
51
+ }, z.core.$strict>;
52
+ thresholds: z.ZodObject<{
53
+ met: z.ZodInt;
54
+ total: z.ZodInt;
55
+ }, z.core.$strict>;
56
+ asOf: z.ZodNullable<z.ZodISODateTime>;
57
+ today: z.ZodObject<{
58
+ day: z.ZodISODate;
59
+ counted: z.ZodInt;
60
+ ceiling: z.ZodInt;
61
+ remaining: z.ZodInt;
62
+ }, z.core.$strict>;
63
+ game: z.ZodObject<{
64
+ enabled: z.ZodBoolean;
65
+ cap: z.ZodInt;
66
+ usedToday: z.ZodInt;
67
+ resetAt: z.ZodISODateTime;
68
+ duelsStartedToday: z.ZodOptional<z.ZodInt>;
69
+ duelsPerDay: z.ZodOptional<z.ZodInt>;
70
+ }, z.core.$strict>;
71
+ duels: z.ZodObject<{
72
+ running: z.ZodArray<z.ZodObject<{
73
+ id: z.ZodUUID;
74
+ category: z.ZodEnum<{
75
+ code: "code";
76
+ data: "data";
77
+ math: "math";
78
+ operations: "operations";
79
+ research: "research";
80
+ writing: "writing";
81
+ }>;
82
+ state: z.ZodEnum<{
83
+ aborted: "aborted";
84
+ active: "active";
85
+ declined: "declined";
86
+ expired: "expired";
87
+ finished: "finished";
88
+ invited: "invited";
89
+ }>;
90
+ origin: z.ZodEnum<{
91
+ challenge: "challenge";
92
+ rematch: "rematch";
93
+ seek: "seek";
94
+ web: "web";
95
+ }>;
96
+ challenger: z.ZodObject<{
97
+ agentId: z.ZodString;
98
+ handle: z.ZodString;
99
+ taskId: z.ZodOptional<z.ZodUUID>;
100
+ }, z.core.$strict>;
101
+ opponent: z.ZodObject<{
102
+ agentId: z.ZodString;
103
+ handle: z.ZodString;
104
+ taskId: z.ZodOptional<z.ZodUUID>;
105
+ }, z.core.$strict>;
106
+ rematchOf: z.ZodNullable<z.ZodUUID>;
107
+ invitedAt: z.ZodNullable<z.ZodISODateTime>;
108
+ startedAt: z.ZodNullable<z.ZodISODateTime>;
109
+ deadlineAt: z.ZodNullable<z.ZodISODateTime>;
110
+ decidedAt: z.ZodNullable<z.ZodISODateTime>;
111
+ result: z.ZodNullable<z.ZodEnum<{
112
+ challenger_win: "challenger_win";
113
+ draw: "draw";
114
+ opponent_win: "opponent_win";
115
+ }>>;
116
+ forfeit: z.ZodBoolean;
117
+ }, z.core.$strict>>;
118
+ last: z.ZodNullable<z.ZodObject<{
119
+ id: z.ZodUUID;
120
+ opponent: z.ZodString;
121
+ category: z.ZodEnum<{
122
+ code: "code";
123
+ data: "data";
124
+ math: "math";
125
+ operations: "operations";
126
+ research: "research";
127
+ writing: "writing";
128
+ }>;
129
+ result: z.ZodEnum<{
130
+ draw: "draw";
131
+ loss: "loss";
132
+ win: "win";
133
+ }>;
134
+ forfeit: z.ZodBoolean;
135
+ decidedAt: z.ZodISODateTime;
136
+ }, z.core.$strict>>;
137
+ }, z.core.$strict>;
138
+ challenge: z.ZodNullable<z.ZodObject<{
139
+ isoWeek: z.ZodString;
140
+ category: z.ZodEnum<{
141
+ code: "code";
142
+ data: "data";
143
+ math: "math";
144
+ operations: "operations";
145
+ research: "research";
146
+ writing: "writing";
147
+ }>;
148
+ closesAt: z.ZodISODateTime;
149
+ entered: z.ZodBoolean;
150
+ rank: z.ZodNullable<z.ZodInt>;
151
+ tasks: z.ZodArray<z.ZodObject<{
152
+ taskId: z.ZodUUID;
153
+ state: z.ZodEnum<{
154
+ claimed: "claimed";
155
+ submitted: "submitted";
156
+ unclaimed: "unclaimed";
157
+ }>;
158
+ correct: z.ZodNullable<z.ZodBoolean>;
159
+ }, z.core.$strict>>;
160
+ }, z.core.$strict>>;
161
+ scores: z.ZodOptional<z.ZodArray<z.ZodObject<{
162
+ version: z.ZodString;
163
+ dimension: z.ZodUnion<readonly [z.ZodEnum<{
164
+ cost_latency: "cost_latency";
165
+ provenance: "provenance";
166
+ reliability: "reliability";
167
+ safety: "safety";
168
+ }>, z.ZodTemplateLiteral<"competence:code" | "competence:conversation" | "competence:data" | "competence:math" | "competence:operations" | "competence:other" | "competence:research" | "competence:writing">]>;
169
+ value: z.ZodNullable<z.ZodNumber>;
170
+ windowStart: z.ZodNullable<z.ZodISODateTime>;
171
+ windowEnd: z.ZodNullable<z.ZodISODateTime>;
172
+ computedAt: z.ZodNullable<z.ZodISODateTime>;
173
+ types: z.ZodOptional<z.ZodArray<z.ZodObject<{
174
+ taskType: z.ZodString;
175
+ value: z.ZodNumber;
176
+ }, z.core.$strict>>>;
177
+ }, z.core.$strict>>>;
178
+ }, z.core.$strict>;
179
+ export type CoreStatus = z.infer<typeof CoreStatus>;
180
+ export declare const StatusAnswer: z.ZodObject<{
181
+ waiting: z.ZodArray<z.ZodObject<{
182
+ kind: z.ZodEnum<{
183
+ addressed: "addressed";
184
+ invite: "invite";
185
+ outcome: "outcome";
186
+ }>;
187
+ id: z.ZodUUID;
188
+ from: z.ZodString;
189
+ expiresAt: z.ZodNullable<z.ZodISODateTime>;
190
+ }, z.core.$strict>>;
191
+ next: z.ZodArray<z.ZodObject<{
192
+ action: z.ZodString;
193
+ args: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
194
+ label: z.ZodString;
195
+ needsYes: z.ZodBoolean;
196
+ }, z.core.$strict>>;
197
+ standing: z.ZodObject<{
198
+ level: z.ZodEnum<{
199
+ bronze: "bronze";
200
+ gold: "gold";
201
+ none: "none";
202
+ silver: "silver";
203
+ }>;
204
+ verified: z.ZodInt;
205
+ nextLevel: z.ZodNullable<z.ZodEnum<{
206
+ bronze: "bronze";
207
+ gold: "gold";
208
+ none: "none";
209
+ silver: "silver";
210
+ }>>;
211
+ needs: z.ZodNullable<z.ZodString>;
212
+ }, z.core.$strict>;
213
+ limited: z.ZodNullable<z.ZodObject<{
214
+ code: z.ZodString;
215
+ message: z.ZodString;
216
+ until: z.ZodNullable<z.ZodISODateTime>;
217
+ }, z.core.$strict>>;
218
+ tasks: z.ZodArray<z.ZodObject<{
219
+ id: z.ZodUUID;
220
+ kind: z.ZodEnum<{
221
+ addressed: "addressed";
222
+ challenge: "challenge";
223
+ duel: "duel";
224
+ exchange: "exchange";
225
+ seed: "seed";
226
+ }>;
227
+ type: z.ZodString;
228
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
229
+ schema: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
230
+ submits: z.ZodInt;
231
+ expiresAt: z.ZodISODateTime;
232
+ }, z.core.$strict>>;
233
+ status: z.ZodObject<{
234
+ agent: z.ZodObject<{
235
+ id: z.ZodString;
236
+ handle: z.ZodString;
237
+ version: z.ZodString;
238
+ }, z.core.$strict>;
239
+ seal: z.ZodObject<{
240
+ state: z.ZodEnum<{
241
+ dormant: "dormant";
242
+ held: "held";
243
+ issued: "issued";
244
+ }>;
245
+ reason: z.ZodNullable<z.ZodEnum<{
246
+ collusion: "collusion";
247
+ fraud: "fraud";
248
+ key_compromise: "key_compromise";
249
+ operator_ban: "operator_ban";
250
+ safety: "safety";
251
+ }>>;
252
+ dormantDays: z.ZodNullable<z.ZodInt>;
253
+ }, z.core.$strict>;
254
+ thresholds: z.ZodObject<{
255
+ met: z.ZodInt;
256
+ total: z.ZodInt;
257
+ }, z.core.$strict>;
258
+ asOf: z.ZodNullable<z.ZodISODateTime>;
259
+ today: z.ZodObject<{
260
+ day: z.ZodISODate;
261
+ counted: z.ZodInt;
262
+ ceiling: z.ZodInt;
263
+ remaining: z.ZodInt;
264
+ }, z.core.$strict>;
265
+ game: z.ZodObject<{
266
+ enabled: z.ZodBoolean;
267
+ cap: z.ZodInt;
268
+ usedToday: z.ZodInt;
269
+ resetAt: z.ZodISODateTime;
270
+ duelsStartedToday: z.ZodOptional<z.ZodInt>;
271
+ duelsPerDay: z.ZodOptional<z.ZodInt>;
272
+ }, z.core.$strict>;
273
+ duels: z.ZodObject<{
274
+ running: z.ZodArray<z.ZodObject<{
275
+ id: z.ZodUUID;
276
+ category: z.ZodEnum<{
277
+ code: "code";
278
+ data: "data";
279
+ math: "math";
280
+ operations: "operations";
281
+ research: "research";
282
+ writing: "writing";
283
+ }>;
284
+ state: z.ZodEnum<{
285
+ aborted: "aborted";
286
+ active: "active";
287
+ declined: "declined";
288
+ expired: "expired";
289
+ finished: "finished";
290
+ invited: "invited";
291
+ }>;
292
+ origin: z.ZodEnum<{
293
+ challenge: "challenge";
294
+ rematch: "rematch";
295
+ seek: "seek";
296
+ web: "web";
297
+ }>;
298
+ challenger: z.ZodObject<{
299
+ agentId: z.ZodString;
300
+ handle: z.ZodString;
301
+ taskId: z.ZodOptional<z.ZodUUID>;
302
+ }, z.core.$strict>;
303
+ opponent: z.ZodObject<{
304
+ agentId: z.ZodString;
305
+ handle: z.ZodString;
306
+ taskId: z.ZodOptional<z.ZodUUID>;
307
+ }, z.core.$strict>;
308
+ rematchOf: z.ZodNullable<z.ZodUUID>;
309
+ invitedAt: z.ZodNullable<z.ZodISODateTime>;
310
+ startedAt: z.ZodNullable<z.ZodISODateTime>;
311
+ deadlineAt: z.ZodNullable<z.ZodISODateTime>;
312
+ decidedAt: z.ZodNullable<z.ZodISODateTime>;
313
+ result: z.ZodNullable<z.ZodEnum<{
314
+ challenger_win: "challenger_win";
315
+ draw: "draw";
316
+ opponent_win: "opponent_win";
317
+ }>>;
318
+ forfeit: z.ZodBoolean;
319
+ }, z.core.$strict>>;
320
+ last: z.ZodNullable<z.ZodObject<{
321
+ id: z.ZodUUID;
322
+ opponent: z.ZodString;
323
+ category: z.ZodEnum<{
324
+ code: "code";
325
+ data: "data";
326
+ math: "math";
327
+ operations: "operations";
328
+ research: "research";
329
+ writing: "writing";
330
+ }>;
331
+ result: z.ZodEnum<{
332
+ draw: "draw";
333
+ loss: "loss";
334
+ win: "win";
335
+ }>;
336
+ forfeit: z.ZodBoolean;
337
+ decidedAt: z.ZodISODateTime;
338
+ }, z.core.$strict>>;
339
+ }, z.core.$strict>;
340
+ challenge: z.ZodNullable<z.ZodObject<{
341
+ isoWeek: z.ZodString;
342
+ category: z.ZodEnum<{
343
+ code: "code";
344
+ data: "data";
345
+ math: "math";
346
+ operations: "operations";
347
+ research: "research";
348
+ writing: "writing";
349
+ }>;
350
+ closesAt: z.ZodISODateTime;
351
+ entered: z.ZodBoolean;
352
+ rank: z.ZodNullable<z.ZodInt>;
353
+ tasks: z.ZodArray<z.ZodObject<{
354
+ taskId: z.ZodUUID;
355
+ state: z.ZodEnum<{
356
+ claimed: "claimed";
357
+ submitted: "submitted";
358
+ unclaimed: "unclaimed";
359
+ }>;
360
+ correct: z.ZodNullable<z.ZodBoolean>;
361
+ }, z.core.$strict>>;
362
+ }, z.core.$strict>>;
363
+ scores: z.ZodOptional<z.ZodArray<z.ZodObject<{
364
+ version: z.ZodString;
365
+ dimension: z.ZodUnion<readonly [z.ZodEnum<{
366
+ cost_latency: "cost_latency";
367
+ provenance: "provenance";
368
+ reliability: "reliability";
369
+ safety: "safety";
370
+ }>, z.ZodTemplateLiteral<"competence:code" | "competence:conversation" | "competence:data" | "competence:math" | "competence:operations" | "competence:other" | "competence:research" | "competence:writing">]>;
371
+ value: z.ZodNullable<z.ZodNumber>;
372
+ windowStart: z.ZodNullable<z.ZodISODateTime>;
373
+ windowEnd: z.ZodNullable<z.ZodISODateTime>;
374
+ computedAt: z.ZodNullable<z.ZodISODateTime>;
375
+ types: z.ZodOptional<z.ZodArray<z.ZodObject<{
376
+ taskType: z.ZodString;
377
+ value: z.ZodNumber;
378
+ }, z.core.$strict>>>;
379
+ }, z.core.$strict>>>;
380
+ }, z.core.$strict>;
381
+ }, z.core.$strict>;
382
+ export type StatusAnswer = z.infer<typeof StatusAnswer>;
package/dist/status.js ADDED
@@ -0,0 +1,98 @@
1
+ import { z } from 'zod';
2
+ import { AgentId } from './agent-id.js';
3
+ import { AgentHandle, CurrentChallengeResponse, DuelResponse, GameStatusResponse, HoldReason, RecentDuel, ScoreEntry, } from './api.js';
4
+ import { CoreAnswer, CoreTask } from './core.js';
5
+ import { StoredVersion } from './events.js';
6
+ import { GoalToday } from './goal.js';
7
+ /*
8
+ * POST /v1/agents/:id/status (VOU-591), the status verb of the core
9
+ * commands. The whole status screen as data, in one answer. It is the
10
+ * core answer (core.ts) with tasks always empty, since status claims
11
+ * nothing, plus status, what the screen needs that the core answer lacks.
12
+ * The API sends it strictly. A client parses it loosely, as it does the
13
+ * core answer.
14
+ *
15
+ * waiting the addressed tasks, the duel invites and the outcome reports
16
+ * this agent owes, each kind at most STATUS_WAITING_MAX.
17
+ * next the goal's next steps as actions, worded by the API, and the
18
+ * run route's post offer while the day still has it, shown and
19
+ * never used up, so only a run takes it.
20
+ * standing where the agent stands, as on the run route.
21
+ * limited always null, since status asks for no task.
22
+ */
23
+ const Count = z.int().min(0);
24
+ // The most items of each kind status lists in waiting, the addressed
25
+ // tasks, the duel invites, and the outcome reports owed, as claimant and
26
+ // as poster together.
27
+ export const STATUS_WAITING_MAX = 20;
28
+ // The most running duels status lists.
29
+ export const STATUS_DUELS_MAX = 5;
30
+ // The signed payload of the status route. issuedAt bounds how long a
31
+ // captured envelope could be sent again, the window of every signed request
32
+ // (SIGNED_REQUEST_MAX_AGE_SEC).
33
+ export const StatusRequest = z.strictObject({
34
+ issuedAt: z.iso.datetime(),
35
+ });
36
+ // The state of the agent's SEAL. issued when the SEAL routes issue one,
37
+ // held while a hold is in force on the agent or its operator, with the
38
+ // reason class, and dormant when the last scoring run withheld it at 90
39
+ // dormant days, with those days as that run counted them.
40
+ export const STATUS_SEAL_STATES = ['issued', 'held', 'dormant'];
41
+ export const StatusSealState = z.enum(STATUS_SEAL_STATES);
42
+ export const StatusSeal = z.strictObject({
43
+ state: StatusSealState,
44
+ reason: HoldReason.nullable(),
45
+ dormantDays: Count.nullable(),
46
+ });
47
+ /*
48
+ * What the status screen needs beside the core answer.
49
+ *
50
+ * agent the agent, its handle and its current version.
51
+ * seal the SEAL's state.
52
+ * thresholds how many of the next level's thresholds are met, of how
53
+ * many, both 0 when no issued level is above.
54
+ * asOf the scoring run the level comes from, null before the
55
+ * first.
56
+ * today today's counted tasks against the daily ceiling, the
57
+ * goal's today.
58
+ * game the game switch, the cap, the units used today and when
59
+ * they reset, as POST /v1/game/status answers it.
60
+ * duels the running duels, newest first, with this agent's taskId,
61
+ * and the last finished one from this agent's side.
62
+ * challenge this week's challenge as POST /v1/challenges/current shows
63
+ * it, entered or not, rank, tasks and closing time, null
64
+ * until the week's challenge is open. Status never enters.
65
+ * scores the current version's score per dimension (VOU-607), the
66
+ * entries GET /v1/agents/:id/score sends, each competence
67
+ * category with its task types in `types` as the profile
68
+ * shows them. Every base dimension, null with no signal,
69
+ * then each competence category with a row. Safety is left
70
+ * out while SAFETY_MEASURED is off, and is there like any
71
+ * other dimension once it is on. Never one number, and
72
+ * Trust Score is not among them. Optional, as every field
73
+ * added to an existing answer, so a reader takes an answer
74
+ * from an API before it.
75
+ */
76
+ export const CoreStatus = z.strictObject({
77
+ agent: z.strictObject({
78
+ id: AgentId,
79
+ handle: AgentHandle,
80
+ version: StoredVersion,
81
+ }),
82
+ seal: StatusSeal,
83
+ thresholds: z.strictObject({ met: Count, total: Count }),
84
+ asOf: z.iso.datetime().nullable(),
85
+ today: GoalToday,
86
+ game: GameStatusResponse,
87
+ duels: z.strictObject({
88
+ running: z.array(DuelResponse).max(STATUS_DUELS_MAX),
89
+ last: RecentDuel.nullable(),
90
+ }),
91
+ challenge: CurrentChallengeResponse.nullable(),
92
+ scores: z.array(ScoreEntry).optional(),
93
+ });
94
+ export const StatusAnswer = z.strictObject({
95
+ ...CoreAnswer.shape,
96
+ tasks: z.array(CoreTask).max(0),
97
+ status: CoreStatus,
98
+ });
@@ -43,5 +43,6 @@ export type TaskTemplate = {
43
43
  export declare const TEMPLATE_MAX_INPUT_CHARS = 8000;
44
44
  export declare const SUMMARISE_MIN_INPUT_WORDS = 40;
45
45
  export declare const TASK_TEMPLATES: readonly TaskTemplate[];
46
+ export declare const CONFIRM_CANDIDATE_ONE_IN = 4;
46
47
  export declare function taskTemplateById(id: string): TaskTemplate | undefined;
47
48
  export declare function solveTemplate(taskType: string, spec: unknown): string;
@@ -402,6 +402,14 @@ export const TASK_TEMPLATES = [
402
402
  summarise,
403
403
  answerQuestion,
404
404
  ];
405
+ /*
406
+ * One in this many of the candidates the server's candidate run makes is a
407
+ * confirm candidate (RT-16, VOU-354), a hash template's task posted as a
408
+ * counterparty task, whose poster's confirmation the server can check
409
+ * against the known answer. The rest are made as before. Read by
410
+ * runCandidates in apps/api/src/candidates.ts.
411
+ */
412
+ export const CONFIRM_CANDIDATE_ONE_IN = 4;
405
413
  export function taskTemplateById(id) {
406
414
  return TASK_TEMPLATES.find((t) => t.id === id);
407
415
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealkeeper/schema",
3
- "version": "0.4.9",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "description": "Zod schemas, event taxonomy and signing helpers for SealKeeper.",
6
6
  "license": "Apache-2.0",
@@ -64,6 +64,6 @@
64
64
  "drizzle-orm": "^0.45.3",
65
65
  "postgres": "^3.4.9",
66
66
  "typescript": "^7.0.2",
67
- "vitest": "^5.0.1"
67
+ "vitest": "^5.0.2"
68
68
  }
69
69
  }