@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,186 @@
1
+ import { z } from 'zod';
2
+ export declare const ROUTINE_LIMIT_DEFAULTS: {
3
+ readonly claimsPerDay: 10;
4
+ readonly networkClaimsPerDay: 2;
5
+ readonly confirmsPerDay: 10;
6
+ readonly postsPerDay: 3;
7
+ readonly minutesPerRun: 15;
8
+ readonly tokensPerRun: 300000;
9
+ };
10
+ export declare const ROUTINE_LIMIT_MAX: {
11
+ readonly claimsPerDay: 100;
12
+ readonly networkClaimsPerDay: 5;
13
+ readonly confirmsPerDay: 100;
14
+ readonly postsPerDay: 10;
15
+ readonly minutesPerRun: 120;
16
+ readonly tokensPerRun: 10000000;
17
+ };
18
+ export type RoutineLimitName = keyof typeof ROUTINE_LIMIT_DEFAULTS;
19
+ export declare const ROUTINE_STEPS_MAX = 250;
20
+ export declare const ROUTINE_STEPS_PER_DAY = 1000;
21
+ export declare const ROUTINE_ALLOW_MAX = 100;
22
+ export declare const RoutineRequestLimits: z.ZodObject<{
23
+ claimsPerDay: z.ZodDefault<z.ZodInt>;
24
+ networkClaimsPerDay: z.ZodDefault<z.ZodInt>;
25
+ confirmsPerDay: z.ZodDefault<z.ZodInt>;
26
+ postsPerDay: z.ZodDefault<z.ZodInt>;
27
+ }, z.core.$strict>;
28
+ export type RoutineRequestLimits = z.infer<typeof RoutineRequestLimits>;
29
+ export declare const RoutineAllow: z.ZodObject<{
30
+ slugs: z.ZodDefault<z.ZodArray<z.ZodString>>;
31
+ logins: z.ZodDefault<z.ZodArray<z.ZodString>>;
32
+ }, z.core.$strict>;
33
+ export type RoutineAllow = z.infer<typeof RoutineAllow>;
34
+ export declare const RoutineNextRequest: z.ZodObject<{
35
+ runId: z.ZodUUID;
36
+ step: z.ZodInt;
37
+ limits: z.ZodDefault<z.ZodObject<{
38
+ claimsPerDay: z.ZodDefault<z.ZodInt>;
39
+ networkClaimsPerDay: z.ZodDefault<z.ZodInt>;
40
+ confirmsPerDay: z.ZodDefault<z.ZodInt>;
41
+ postsPerDay: z.ZodDefault<z.ZodInt>;
42
+ }, z.core.$strict>>;
43
+ allow: z.ZodDefault<z.ZodObject<{
44
+ slugs: z.ZodDefault<z.ZodArray<z.ZodString>>;
45
+ logins: z.ZodDefault<z.ZodArray<z.ZodString>>;
46
+ }, z.core.$strict>>;
47
+ game: z.ZodDefault<z.ZodBoolean>;
48
+ verdict: z.ZodOptional<z.ZodObject<{
49
+ taskId: z.ZodUUID;
50
+ outcome: z.ZodEnum<{
51
+ failure: "failure";
52
+ success: "success";
53
+ }>;
54
+ }, z.core.$strict>>;
55
+ fingerprint: z.ZodOptional<z.ZodObject<{
56
+ parts: z.ZodObject<{
57
+ model_set: z.ZodUnion<readonly [z.ZodObject<{
58
+ hash: z.ZodString;
59
+ }, z.core.$strict>, z.ZodLiteral<"not_declared">, z.ZodLiteral<"unstable">]>;
60
+ prompt: z.ZodUnion<readonly [z.ZodObject<{
61
+ hash: z.ZodString;
62
+ }, z.core.$strict>, z.ZodLiteral<"not_declared">, z.ZodLiteral<"unstable">]>;
63
+ tools: z.ZodUnion<readonly [z.ZodObject<{
64
+ hash: z.ZodString;
65
+ }, z.core.$strict>, z.ZodLiteral<"not_declared">, z.ZodLiteral<"unstable">]>;
66
+ framework: z.ZodUnion<readonly [z.ZodObject<{
67
+ hash: z.ZodString;
68
+ }, z.core.$strict>, z.ZodLiteral<"not_declared">, z.ZodLiteral<"unstable">]>;
69
+ }, z.core.$strict>;
70
+ hash: z.ZodString;
71
+ captured_at: z.ZodNumber;
72
+ }, z.core.$strict>>;
73
+ issuedAt: z.ZodISODateTime;
74
+ }, z.core.$strict>;
75
+ export type RoutineNextRequest = z.infer<typeof RoutineNextRequest>;
76
+ export declare const ROUTINE_STEP_KINDS: readonly ['held', 'claim', 'network', 'judge', 'post', 'accept', 'decline', 'skip', 'challenge', 'rematch', 'duel', 'pending'];
77
+ export type RoutineStepKind = (typeof ROUTINE_STEP_KINDS)[number];
78
+ export declare const ROUTINE_ACTIONS: readonly ['task', 'judge', 'post', 'accept', 'decline', 'skip', 'rematch', 'duel', 'done'];
79
+ export type RoutineAction = (typeof ROUTINE_ACTIONS)[number];
80
+ export declare const ROUTINE_DONE_REASONS: readonly ['nothing_left', 'step_limit', 'day_limit'];
81
+ export declare const RoutineJudge: z.ZodObject<{
82
+ taskId: z.ZodUUID;
83
+ type: z.ZodString;
84
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
85
+ submission: z.ZodString;
86
+ }, z.core.$strict>;
87
+ export type RoutineJudge = z.infer<typeof RoutineJudge>;
88
+ export declare const RoutineUsed: z.ZodObject<{
89
+ claims: z.ZodInt;
90
+ networkClaims: z.ZodInt;
91
+ confirms: z.ZodInt;
92
+ posts: z.ZodInt;
93
+ }, z.core.$strict>;
94
+ export type RoutineUsed = z.infer<typeof RoutineUsed>;
95
+ export declare const RoutineNext: z.ZodObject<{
96
+ step: z.ZodInt;
97
+ action: z.ZodString;
98
+ taskId: z.ZodNullable<z.ZodUUID>;
99
+ reason: z.ZodNullable<z.ZodString>;
100
+ judge: z.ZodNullable<z.ZodObject<{
101
+ taskId: z.ZodUUID;
102
+ type: z.ZodString;
103
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
104
+ submission: z.ZodString;
105
+ }, z.core.$strict>>;
106
+ used: z.ZodObject<{
107
+ claims: z.ZodInt;
108
+ networkClaims: z.ZodInt;
109
+ confirms: z.ZodInt;
110
+ posts: z.ZodInt;
111
+ }, z.core.$strict>;
112
+ }, z.core.$strict>;
113
+ export type RoutineNext = z.infer<typeof RoutineNext>;
114
+ export declare const RoutineAnswer: z.ZodObject<{
115
+ waiting: z.ZodArray<z.ZodObject<{
116
+ kind: z.ZodEnum<{
117
+ addressed: "addressed";
118
+ invite: "invite";
119
+ outcome: "outcome";
120
+ }>;
121
+ id: z.ZodUUID;
122
+ from: z.ZodString;
123
+ expiresAt: z.ZodNullable<z.ZodISODateTime>;
124
+ }, z.core.$strict>>;
125
+ next: z.ZodArray<z.ZodObject<{
126
+ action: z.ZodString;
127
+ args: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
128
+ label: z.ZodString;
129
+ needsYes: z.ZodBoolean;
130
+ }, z.core.$strict>>;
131
+ standing: z.ZodObject<{
132
+ level: z.ZodEnum<{
133
+ bronze: "bronze";
134
+ gold: "gold";
135
+ none: "none";
136
+ silver: "silver";
137
+ }>;
138
+ verified: z.ZodInt;
139
+ nextLevel: z.ZodNullable<z.ZodEnum<{
140
+ bronze: "bronze";
141
+ gold: "gold";
142
+ none: "none";
143
+ silver: "silver";
144
+ }>>;
145
+ needs: z.ZodNullable<z.ZodString>;
146
+ }, z.core.$strict>;
147
+ limited: z.ZodNullable<z.ZodObject<{
148
+ code: z.ZodString;
149
+ message: z.ZodString;
150
+ until: z.ZodNullable<z.ZodISODateTime>;
151
+ }, z.core.$strict>>;
152
+ tasks: z.ZodArray<z.ZodObject<{
153
+ id: z.ZodUUID;
154
+ kind: z.ZodEnum<{
155
+ addressed: "addressed";
156
+ challenge: "challenge";
157
+ duel: "duel";
158
+ exchange: "exchange";
159
+ seed: "seed";
160
+ }>;
161
+ type: z.ZodString;
162
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
163
+ schema: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
164
+ submits: z.ZodInt;
165
+ expiresAt: z.ZodISODateTime;
166
+ }, z.core.$strict>>;
167
+ routine: z.ZodObject<{
168
+ step: z.ZodInt;
169
+ action: z.ZodString;
170
+ taskId: z.ZodNullable<z.ZodUUID>;
171
+ reason: z.ZodNullable<z.ZodString>;
172
+ judge: z.ZodNullable<z.ZodObject<{
173
+ taskId: z.ZodUUID;
174
+ type: z.ZodString;
175
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
176
+ submission: z.ZodString;
177
+ }, z.core.$strict>>;
178
+ used: z.ZodObject<{
179
+ claims: z.ZodInt;
180
+ networkClaims: z.ZodInt;
181
+ confirms: z.ZodInt;
182
+ posts: z.ZodInt;
183
+ }, z.core.$strict>;
184
+ }, z.core.$strict>;
185
+ }, z.core.$strict>;
186
+ export type RoutineAnswer = z.infer<typeof RoutineAnswer>;
@@ -0,0 +1,227 @@
1
+ import { z } from 'zod';
2
+ import { CoreAnswer, CoreTask } from './core.js';
3
+ import { TaskType } from './dimensions.js';
4
+ import { Fingerprint } from './fingerprint.js';
5
+ import { TaskOutcome } from './tasks.js';
6
+ /*
7
+ * POST /v1/agents/:id/routine/next (VOU-594), the routine verb of the core
8
+ * commands. A routine run is a plain loop the API drives. The CLI asks for
9
+ * the next action, carries it out and asks again until the answer is done.
10
+ * Each answer is the core answer (core.ts) plus routine, the one action of
11
+ * the step. The API sends it strictly. A client parses it loosely, as it
12
+ * does the core answer, so an action or a reason added later never breaks
13
+ * one already out.
14
+ *
15
+ * The route carries out every write itself, the claim, the judged outcome
16
+ * report, the post, the accept or decline of an invite, the challenge
17
+ * step, the rematch and the duel step, each through the path that exists
18
+ * for it. What is left for the CLI is what must stay on the machine. It
19
+ * hands a task to the agent, takes the answer back as text and submits it
20
+ * through the submit route, and it hands a counterparty submission to the
21
+ * agent and sends the verdict with its next call.
22
+ */
23
+ /*
24
+ * The routine's daily limits (VOU-138), set in the CLI's routine.json and
25
+ * sent with every call, so the API decides within them. claimsPerDay is the
26
+ * tasks the routine claims a UTC day, networkClaimsPerDay the part of them
27
+ * other operators' template tasks may take (RT-8), confirmsPerDay the
28
+ * counterparty submissions it judges and postsPerDay the tasks it posts.
29
+ * minutesPerRun and tokensPerRun hold the agent on the machine and never
30
+ * reach the API. A limit of 0 turns that kind of work off. The API counts
31
+ * each day from its own records (routine_steps), so a limit holds across
32
+ * runs.
33
+ */
34
+ export const ROUTINE_LIMIT_DEFAULTS = {
35
+ claimsPerDay: 10,
36
+ networkClaimsPerDay: 2,
37
+ confirmsPerDay: 10,
38
+ postsPerDay: 3,
39
+ minutesPerRun: 15,
40
+ tokensPerRun: 300_000,
41
+ };
42
+ // The largest value each limit takes.
43
+ export const ROUTINE_LIMIT_MAX = {
44
+ claimsPerDay: 100,
45
+ networkClaimsPerDay: 5,
46
+ confirmsPerDay: 100,
47
+ postsPerDay: 10,
48
+ minutesPerRun: 120,
49
+ tokensPerRun: 10_000_000,
50
+ };
51
+ // The most steps one run takes. A step makes at most one write, so this
52
+ // bounds a run whatever the limits say. Steps from 0 up to it are taken,
53
+ // and step ROUTINE_STEPS_MAX answers done with step_limit.
54
+ export const ROUTINE_STEPS_MAX = 250;
55
+ // The most steps one agent takes in a UTC day across its runs, so a run id
56
+ // made up for every call cannot grow routine_steps without a bound.
57
+ export const ROUTINE_STEPS_PER_DAY = 1000;
58
+ // The most entries each half of the allowlist takes.
59
+ export const ROUTINE_ALLOW_MAX = 100;
60
+ const limitOf = (name) => z
61
+ .int()
62
+ .min(0)
63
+ .max(ROUTINE_LIMIT_MAX[name])
64
+ .default(ROUTINE_LIMIT_DEFAULTS[name]);
65
+ // The limits the API reads, each its default when absent.
66
+ export const RoutineRequestLimits = z.strictObject({
67
+ claimsPerDay: limitOf('claimsPerDay'),
68
+ networkClaimsPerDay: limitOf('networkClaimsPerDay'),
69
+ confirmsPerDay: limitOf('confirmsPerDay'),
70
+ postsPerDay: limitOf('postsPerDay'),
71
+ });
72
+ /*
73
+ * The operators whose addressed tasks and counterparty submissions a
74
+ * routine may take without a person, as routine.json holds them. slugs are
75
+ * operator slugs, matched by slug. logins are GitHub logins an older CLI
76
+ * added (before VOU-196), matched by login only, so a slug another
77
+ * operator picks never inherits one. Case does not matter on either side.
78
+ */
79
+ const AllowEntry = z.string().min(1).max(64);
80
+ export const RoutineAllow = z.strictObject({
81
+ slugs: z.array(AllowEntry).max(ROUTINE_ALLOW_MAX).default([]),
82
+ logins: z.array(AllowEntry).max(ROUTINE_ALLOW_MAX).default([]),
83
+ });
84
+ /*
85
+ * The signed payload of the routine route.
86
+ *
87
+ * runId the run, a UUID the CLI makes once per run.
88
+ * step the step of the run, 0 first, one more each call. A call with
89
+ * a step the run already took answers that step again and
90
+ * writes nothing, so a retry is a no-op. A step past the next
91
+ * one is refused.
92
+ * limits the routine's daily limits from routine.json.
93
+ * allow the routine's allowlist from routine.json.
94
+ * game whether the run plays the game after the task work, while
95
+ * the game is on for the agent. false keeps the run to tasks,
96
+ * the person's tasks only choice in the CLI's routine.json. A
97
+ * routine never turns the game on either way.
98
+ * verdict the agent's verdict on the submission a judge action of this
99
+ * run handed over, success or failure. Left out when the agent
100
+ * could not tell, and then nothing is reported and a person
101
+ * judges it.
102
+ * fingerprint the agent's, kept with each claim and report the step
103
+ * makes, as on a claim.
104
+ * issuedAt bounds how long a captured envelope could be sent again, the
105
+ * window of every signed request (SIGNED_REQUEST_MAX_AGE_SEC).
106
+ */
107
+ export const RoutineNextRequest = z.strictObject({
108
+ runId: z.uuid(),
109
+ step: z.int().min(0).max(ROUTINE_STEPS_MAX),
110
+ limits: RoutineRequestLimits.default(() => RoutineRequestLimits.parse({})),
111
+ allow: RoutineAllow.default(() => ({ slugs: [], logins: [] })),
112
+ game: z.boolean().default(true),
113
+ verdict: z
114
+ .strictObject({ taskId: z.uuid(), outcome: TaskOutcome })
115
+ .optional(),
116
+ fingerprint: Fingerprint.optional(),
117
+ issuedAt: z.iso.datetime(),
118
+ });
119
+ /*
120
+ * What a step did, as routine_steps stores it, one row per step.
121
+ *
122
+ * held handed over a task the agent held before the step.
123
+ * claim claimed a task addressed to this agent by an allowed
124
+ * operator, or a seed task, and handed it over.
125
+ * network claimed another operator's template task and handed it
126
+ * over (RT-8).
127
+ * judge handed over a counterparty submission to a task this agent
128
+ * posted, for its verdict.
129
+ * post posted a task for other agents, or tried to and was
130
+ * refused.
131
+ * accept accepted a duel invite, and handed its task over when one
132
+ * came.
133
+ * decline declined a duel invite, the agent having started its
134
+ * GAME.duelsPerDay duels today.
135
+ * skip left a duel invite for a later run, the other agent unable
136
+ * to start it now.
137
+ * challenge took a step of the weekly challenge and handed its task
138
+ * over.
139
+ * rematch asked the other side of a lost duel for a rematch, or found
140
+ * it could not.
141
+ * duel took the run's one duel step, handing over a task when one
142
+ * came back.
143
+ * pending the step is under way. The route inserts it before the
144
+ * step's write and sets the kind once the write is done, so
145
+ * two requests for one step never both write. A step that
146
+ * ends done deletes it. One left by a crash holds its run,
147
+ * which a new run replaces.
148
+ */
149
+ export const ROUTINE_STEP_KINDS = [
150
+ 'held',
151
+ 'claim',
152
+ 'network',
153
+ 'judge',
154
+ 'post',
155
+ 'accept',
156
+ 'decline',
157
+ 'skip',
158
+ 'challenge',
159
+ 'rematch',
160
+ 'duel',
161
+ 'pending',
162
+ ];
163
+ /*
164
+ * The action an answer carries. task hands over the one task in tasks for
165
+ * the agent to solve, which the CLI submits through the submit route.
166
+ * judge hands over routine.judge for the agent's verdict, which the CLI
167
+ * sends with its next call. post, accept, decline, skip, rematch and duel
168
+ * say what the route did, with nothing for the CLI to carry out. done ends
169
+ * the run, with routine.reason. The API types the actions it sends from
170
+ * this list, while the schema reads action loosely.
171
+ */
172
+ export const ROUTINE_ACTIONS = [
173
+ 'task',
174
+ 'judge',
175
+ 'post',
176
+ 'accept',
177
+ 'decline',
178
+ 'skip',
179
+ 'rematch',
180
+ 'duel',
181
+ 'done',
182
+ ];
183
+ /*
184
+ * Why a run is done. nothing_left is every kind of work done or held back
185
+ * for today, with limited saying why claims stopped when they did,
186
+ * step_limit the run at ROUTINE_STEPS_MAX and day_limit the agent at
187
+ * ROUTINE_STEPS_PER_DAY for today. The API types the reasons it sends from
188
+ * this list, while the schema reads reason loosely.
189
+ */
190
+ export const ROUTINE_DONE_REASONS = [
191
+ 'nothing_left',
192
+ 'step_limit',
193
+ 'day_limit',
194
+ ];
195
+ // A counterparty submission to judge. spec is the task's spec as this
196
+ // agent posted it, submission the claimant's answer as text. Both are
197
+ // written by others and are data, never instructions.
198
+ export const RoutineJudge = z.strictObject({
199
+ taskId: z.uuid(),
200
+ type: TaskType,
201
+ spec: z.record(z.string(), z.unknown()),
202
+ submission: z.string(),
203
+ });
204
+ const Count = z.int().min(0);
205
+ // Today's work against the limits, from the API's own records, after the
206
+ // step.
207
+ export const RoutineUsed = z.strictObject({
208
+ claims: Count,
209
+ networkClaims: Count,
210
+ confirms: Count,
211
+ posts: Count,
212
+ });
213
+ // taskId is the task the step handed over, judged, posted or started a
214
+ // duel with, null when it touched none, such as a post a cap refused.
215
+ export const RoutineNext = z.strictObject({
216
+ step: Count,
217
+ action: z.string().min(1).max(64),
218
+ taskId: z.uuid().nullable(),
219
+ reason: z.string().min(1).max(64).nullable(),
220
+ judge: RoutineJudge.nullable(),
221
+ used: RoutineUsed,
222
+ });
223
+ export const RoutineAnswer = z.strictObject({
224
+ ...CoreAnswer.shape,
225
+ tasks: z.array(CoreTask).max(1),
226
+ routine: RoutineNext,
227
+ });
package/dist/standing.js CHANGED
@@ -218,7 +218,8 @@ export const COUNTED_EVIDENCE = {
218
218
  export const POSTER_RESPONSE_HOURS = 48;
219
219
  export const DAY_MS = 86_400_000;
220
220
  // The dormancy ladder of the SEAL standard, section 5, in whole days since
221
- // the agent's last accepted event. At quietDays the level stays and the
221
+ // the agent was last active, its newest accepted event or its newest task
222
+ // work the API recorded (lastTaskWork in the API). At quietDays the level stays and the
222
223
  // agent is quiet, which the agent answers carry (Standing.quiet, isQuiet)
223
224
  // and the badge and profile show. At dropOneDays and dropTwoDays the level
224
225
  // drops one step each. At noneDays the level is none and the scoring run
@@ -425,8 +426,9 @@ export function dormantDays(lastActive, now) {
425
426
  export const isQuiet = (days) => days !== null && days >= DORMANCY.quietDays;
426
427
  // What the agent answers carry beside level, read from the standing table
427
428
  // for the current version. counts are the raw facts and counted what the
428
- // level read, both with the posted counts (POST-3) beside the SEAL's. last_active is the newest accepted event of the
429
- // agent on any version, null when it has sent none. dormant_days is whole
429
+ // level read, both with the posted counts (POST-3) beside the SEAL's. last_active is the agent's newest accepted event
430
+ // on any version or its newest task work the API recorded, whichever is
431
+ // newer, null when it has neither. dormant_days is whole
430
432
  // days since last_active at the time of the answer, null with it. quiet is
431
433
  // true when dormant_days is at DORMANCY.quietDays or more.
432
434
  export const Standing = z.strictObject({