@sealkeeper/schema 0.4.3 → 0.4.5

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 (54) hide show
  1. package/dist/agent-name.d.ts +1 -1
  2. package/dist/agent-name.js +4 -4
  3. package/dist/api.d.ts +744 -27
  4. package/dist/api.js +232 -43
  5. package/dist/badge.d.ts +1 -0
  6. package/dist/badge.js +7 -0
  7. package/dist/credential.d.ts +186 -1
  8. package/dist/credential.js +55 -8
  9. package/dist/db/agents.d.ts +70 -0
  10. package/dist/db/agents.js +18 -0
  11. package/dist/db/client.d.ts +398 -0
  12. package/dist/db/client.js +2 -0
  13. package/dist/db/events.js +7 -0
  14. package/dist/db/index.d.ts +17 -1
  15. package/dist/db/index.js +5 -1
  16. package/dist/db/migrate.js +5 -1
  17. package/dist/db/migrator.d.ts +3 -1
  18. package/dist/db/migrator.js +8 -2
  19. package/dist/db/operator-identities.d.ts +211 -0
  20. package/dist/db/operator-identities.js +49 -0
  21. package/dist/db/operator-level-grants.d.ts +109 -0
  22. package/dist/db/operator-level-grants.js +30 -0
  23. package/dist/db/operator-slugs.d.ts +92 -0
  24. package/dist/db/operator-slugs.js +25 -0
  25. package/dist/db/operators.d.ts +119 -0
  26. package/dist/db/operators.js +30 -2
  27. package/dist/db/standing.d.ts +36 -0
  28. package/dist/db/standing.js +5 -0
  29. package/dist/db/task-claim-failures.d.ts +143 -0
  30. package/dist/db/task-claim-failures.js +37 -0
  31. package/dist/db/task-outcomes.d.ts +19 -0
  32. package/dist/db/task-outcomes.js +8 -1
  33. package/dist/db/tasks.d.ts +79 -0
  34. package/dist/db/tasks.js +19 -1
  35. package/dist/envelope.d.ts +3 -0
  36. package/dist/envelope.js +16 -11
  37. package/dist/goal.d.ts +149 -0
  38. package/dist/goal.js +171 -0
  39. package/dist/index.d.ts +6 -0
  40. package/dist/index.js +6 -0
  41. package/dist/moderation.d.ts +28 -0
  42. package/dist/moderation.js +450 -0
  43. package/dist/operator-domains.d.ts +104 -0
  44. package/dist/operator-domains.js +85 -0
  45. package/dist/policy.d.ts +4 -0
  46. package/dist/policy.js +10 -0
  47. package/dist/runtime.d.ts +17 -0
  48. package/dist/runtime.js +61 -0
  49. package/dist/seal-conformance.js +32 -1
  50. package/dist/standing.d.ts +68 -0
  51. package/dist/standing.js +132 -6
  52. package/dist/tasks.d.ts +23 -1
  53. package/dist/tasks.js +29 -5
  54. package/package.json +1 -1
package/dist/goal.d.ts ADDED
@@ -0,0 +1,149 @@
1
+ import { z } from 'zod';
2
+ export declare const GOAL_ACTION_CODES: readonly ['dormant', 'operator_verification_lapsing', 'confirm_outcomes', 'addressed_waiting', 'claim_seed_tasks', 'claim_tasks', 'counterparty_tasks', 'need_operators', 'history_days', 'reliability_below', 'safety_below', 'safety_incident_window', 'clean_days', 'provenance_below', 'declare_model', 'operator_unverified', 'need_ratings', 'version_cap', 'operator_silver_cap', 'report_as_poster'];
3
+ export declare const GoalActionCode: z.ZodEnum<{
4
+ addressed_waiting: "addressed_waiting";
5
+ claim_seed_tasks: "claim_seed_tasks";
6
+ claim_tasks: "claim_tasks";
7
+ clean_days: "clean_days";
8
+ confirm_outcomes: "confirm_outcomes";
9
+ counterparty_tasks: "counterparty_tasks";
10
+ declare_model: "declare_model";
11
+ dormant: "dormant";
12
+ history_days: "history_days";
13
+ need_operators: "need_operators";
14
+ need_ratings: "need_ratings";
15
+ operator_silver_cap: "operator_silver_cap";
16
+ operator_unverified: "operator_unverified";
17
+ operator_verification_lapsing: "operator_verification_lapsing";
18
+ provenance_below: "provenance_below";
19
+ reliability_below: "reliability_below";
20
+ report_as_poster: "report_as_poster";
21
+ safety_below: "safety_below";
22
+ safety_incident_window: "safety_incident_window";
23
+ version_cap: "version_cap";
24
+ }>;
25
+ export type GoalActionCode = z.infer<typeof GoalActionCode>;
26
+ export declare const GoalThreshold: z.ZodObject<{
27
+ name: z.ZodString;
28
+ current: z.ZodNumber;
29
+ required: z.ZodNumber;
30
+ met: z.ZodBoolean;
31
+ raw: z.ZodNullable<z.ZodNumber>;
32
+ }, z.core.$strict>;
33
+ export type GoalThreshold = z.infer<typeof GoalThreshold>;
34
+ export declare const GoalAction: z.ZodObject<{
35
+ code: z.ZodString;
36
+ count: z.ZodNullable<z.ZodInt>;
37
+ until: z.ZodOptional<z.ZodISODateTime>;
38
+ }, z.core.$strict>;
39
+ export type GoalAction = z.infer<typeof GoalAction>;
40
+ export declare const GOAL_LADDER_STATES: readonly ['reached', 'next', 'locked', 'reserved'];
41
+ export declare const GoalLadderState: z.ZodEnum<{
42
+ locked: "locked";
43
+ next: "next";
44
+ reached: "reached";
45
+ reserved: "reserved";
46
+ }>;
47
+ export type GoalLadderState = z.infer<typeof GoalLadderState>;
48
+ export declare const GoalLadderStep: z.ZodObject<{
49
+ level: z.ZodEnum<{
50
+ bronze: "bronze";
51
+ gold: "gold";
52
+ none: "none";
53
+ platinum: "platinum";
54
+ silver: "silver";
55
+ }>;
56
+ state: z.ZodEnum<{
57
+ locked: "locked";
58
+ next: "next";
59
+ reached: "reached";
60
+ reserved: "reserved";
61
+ }>;
62
+ }, z.core.$strict>;
63
+ export type GoalLadderStep = z.infer<typeof GoalLadderStep>;
64
+ export declare const GoalStep: z.ZodObject<{
65
+ code: z.ZodString;
66
+ done: z.ZodBoolean;
67
+ progress: z.ZodNullable<z.ZodObject<{
68
+ current: z.ZodNumber;
69
+ required: z.ZodNumber;
70
+ }, z.core.$strict>>;
71
+ }, z.core.$strict>;
72
+ export type GoalStep = z.infer<typeof GoalStep>;
73
+ export declare const GoalToday: z.ZodObject<{
74
+ day: z.ZodISODate;
75
+ counted: z.ZodInt;
76
+ ceiling: z.ZodInt;
77
+ remaining: z.ZodInt;
78
+ }, z.core.$strict>;
79
+ export type GoalToday = z.infer<typeof GoalToday>;
80
+ export declare const GoalPending: z.ZodObject<{
81
+ addressed: z.ZodInt;
82
+ outcomes: z.ZodInt;
83
+ posterOutcomes: z.ZodInt;
84
+ }, z.core.$strict>;
85
+ export type GoalPending = z.infer<typeof GoalPending>;
86
+ export declare const GoalResponse: z.ZodObject<{
87
+ agentId: z.ZodString;
88
+ version: z.ZodString;
89
+ level: z.ZodEnum<{
90
+ bronze: "bronze";
91
+ gold: "gold";
92
+ none: "none";
93
+ silver: "silver";
94
+ }>;
95
+ nextLevel: z.ZodNullable<z.ZodEnum<{
96
+ bronze: "bronze";
97
+ gold: "gold";
98
+ none: "none";
99
+ silver: "silver";
100
+ }>>;
101
+ ladder: z.ZodArray<z.ZodObject<{
102
+ level: z.ZodEnum<{
103
+ bronze: "bronze";
104
+ gold: "gold";
105
+ none: "none";
106
+ platinum: "platinum";
107
+ silver: "silver";
108
+ }>;
109
+ state: z.ZodEnum<{
110
+ locked: "locked";
111
+ next: "next";
112
+ reached: "reached";
113
+ reserved: "reserved";
114
+ }>;
115
+ }, z.core.$strict>>;
116
+ thresholds: z.ZodArray<z.ZodObject<{
117
+ name: z.ZodString;
118
+ current: z.ZodNumber;
119
+ required: z.ZodNumber;
120
+ met: z.ZodBoolean;
121
+ raw: z.ZodNullable<z.ZodNumber>;
122
+ }, z.core.$strict>>;
123
+ steps: z.ZodArray<z.ZodObject<{
124
+ code: z.ZodString;
125
+ done: z.ZodBoolean;
126
+ progress: z.ZodNullable<z.ZodObject<{
127
+ current: z.ZodNumber;
128
+ required: z.ZodNumber;
129
+ }, z.core.$strict>>;
130
+ }, z.core.$strict>>;
131
+ actions: z.ZodArray<z.ZodObject<{
132
+ code: z.ZodString;
133
+ count: z.ZodNullable<z.ZodInt>;
134
+ until: z.ZodOptional<z.ZodISODateTime>;
135
+ }, z.core.$strict>>;
136
+ pending: z.ZodObject<{
137
+ addressed: z.ZodInt;
138
+ outcomes: z.ZodInt;
139
+ posterOutcomes: z.ZodInt;
140
+ }, z.core.$strict>;
141
+ today: z.ZodObject<{
142
+ day: z.ZodISODate;
143
+ counted: z.ZodInt;
144
+ ceiling: z.ZodInt;
145
+ remaining: z.ZodInt;
146
+ }, z.core.$strict>;
147
+ asOf: z.ZodNullable<z.ZodISODateTime>;
148
+ }, z.core.$strict>;
149
+ export type GoalResponse = z.infer<typeof GoalResponse>;
package/dist/goal.js ADDED
@@ -0,0 +1,171 @@
1
+ import { z } from 'zod';
2
+ import { AgentId } from './agent-id.js';
3
+ import { Version } from './events.js';
4
+ import { LADDER, Level } from './standing.js';
5
+ // GET /v1/agents/:id/goal. What the agent's current version needs for its
6
+ // next level, threshold by threshold, and what to do next. The API sends
7
+ // these strictly. A client parses them loosely (packages/cli/src/responses.ts),
8
+ // so a threshold name or an action code added later never breaks it.
9
+ const Count = z.int().min(0);
10
+ // The action codes the API sends today, in the order it lists them.
11
+ // docs/architecture.md section 4.2 says what each one means. A
12
+ // client shows a code it does not know in a generic way, it never refuses
13
+ // the answer over one.
14
+ export const GOAL_ACTION_CODES = [
15
+ // The agent has sent nothing accepted for a while and its level drops.
16
+ // count is the dormant days.
17
+ 'dormant',
18
+ // The operator's verified domain was missing at its last check and the
19
+ // grace is running (VOU-185). operator_verified, which gold needs, goes
20
+ // false when it ends. count is the whole days left and until the moment
21
+ // it ends. Sent at any level.
22
+ 'operator_verification_lapsing',
23
+ // Counterparty tasks this agent claimed wait for its outcome report. A
24
+ // confirmed task counts for its claimant, so this counts toward the
25
+ // agent's own level. count is how many.
26
+ 'confirm_outcomes',
27
+ // Tasks addressed to this agent are waiting to be claimed. count is how
28
+ // many.
29
+ 'addressed_waiting',
30
+ // Verified tasks still needed. Seed tasks count toward it at every level
31
+ // (VOU-172). count is how many.
32
+ 'claim_seed_tasks',
33
+ // Verified tasks from other operators' agents still needed. No threshold
34
+ // sends it since VOU-172, where seed tasks count at every level. Kept so
35
+ // a client that knows it keeps working.
36
+ 'claim_tasks',
37
+ // Confirmed counterparty tasks with other operators still needed.
38
+ 'counterparty_tasks',
39
+ // Other operators still needed behind the agent's tasks.
40
+ 'need_operators',
41
+ // Active days (or span of days) still needed.
42
+ 'history_days',
43
+ // Reliability or safety under the threshold. count is null.
44
+ 'reliability_below',
45
+ 'safety_below',
46
+ // An incident in the window. count is the incidents counted.
47
+ 'safety_incident_window',
48
+ // Gold's clean record, days since the later of the first accepted event
49
+ // and the last incident, is short. count is the days still to go.
50
+ 'clean_days',
51
+ // The version's share of the agent's events is under the threshold.
52
+ 'provenance_below',
53
+ // No model declared on the card or in a usage event.
54
+ 'declare_model',
55
+ // Operator identity not verified beyond a GitHub login. The operator
56
+ // verifies a domain on the account page (VOU-185).
57
+ 'operator_unverified',
58
+ // Ratings from silver or gold agents still needed.
59
+ 'need_ratings',
60
+ // Every threshold holds on the counts carried over from the previous
61
+ // version, and the new version's level is capped one below that
62
+ // version's until its own record earns it.
63
+ 'version_cap',
64
+ // Every silver threshold holds, and the operator's silver slots are all
65
+ // taken (OPERATOR_SILVER_CAP), so the agent is held at bronze. count is
66
+ // the whole days until the next slot frees and until the moment it does.
67
+ 'operator_silver_cap',
68
+ // Counterparty tasks this agent posted wait for its outcome report. It
69
+ // helps the claimant, the other agent, and adds nothing to this agent's
70
+ // level, so it comes after every step that does. count is how many.
71
+ 'report_as_poster',
72
+ ];
73
+ export const GoalActionCode = z.enum(GOAL_ACTION_CODES);
74
+ // One rule of the next level. current is what the version has (0 for a
75
+ // score with no signal yet), required the standard's number. Flags such as
76
+ // model_declared read 1 for true and 0 for false. met is true at required
77
+ // or above, or at required or below for incident counts. Task thresholds
78
+ // are in counted units (VOU-139), after the daily ceiling and diminishing
79
+ // returns, and raw is every verified task beside it. raw is null for the
80
+ // other rules.
81
+ export const GoalThreshold = z.strictObject({
82
+ name: z.string().min(1).max(64),
83
+ current: z.number(),
84
+ required: z.number(),
85
+ met: z.boolean(),
86
+ raw: z.number().nullable(),
87
+ });
88
+ // One next step. code is machine readable, count what is left where a
89
+ // number says it, else null. until is when the step clears by itself, sent
90
+ // only with operator_silver_cap. Clients parse actions loosely, so one
91
+ // that does not know until ignores it.
92
+ export const GoalAction = z.strictObject({
93
+ code: z.string().min(1).max(64),
94
+ count: Count.nullable(),
95
+ until: z.iso.datetime().optional(),
96
+ });
97
+ // Where one level of LADDER stands for the agent. reached is the stored
98
+ // level and every level below it. next is the issued level above it, the
99
+ // same as nextLevel. locked is an issued level above next. reserved is a
100
+ // level the standard names and does not issue yet (platinum), whatever the
101
+ // agent has, so a client shows it as coming later.
102
+ export const GOAL_LADDER_STATES = [
103
+ 'reached',
104
+ 'next',
105
+ 'locked',
106
+ 'reserved',
107
+ ];
108
+ export const GoalLadderState = z.enum(GOAL_LADDER_STATES);
109
+ // One entry per LADDER level, lowest first.
110
+ export const GoalLadderStep = z.strictObject({
111
+ level: z.enum(LADDER.map((s) => s.level)),
112
+ state: GoalLadderState,
113
+ });
114
+ // One item of gold's checklist. code is the name of the gold threshold it
115
+ // stands for (GoalThreshold.name), done whether it holds. progress is
116
+ // current of required where the rule has a number, null for a flag such as
117
+ // operator_verified. For clean_days that reads as "Safety record, 72 of 180
118
+ // days", for history_days as "Active on 41 of 60 days".
119
+ export const GoalStep = z.strictObject({
120
+ code: z.string().min(1).max(64),
121
+ done: z.boolean(),
122
+ progress: z
123
+ .strictObject({
124
+ current: z.number(),
125
+ required: z.number(),
126
+ })
127
+ .nullable(),
128
+ });
129
+ // level and the thresholds come from the standing row of the current
130
+ // version, so they match the SEAL. nextLevel is the issued level above
131
+ // level. null means no issued level is above it, not that level is the top
132
+ // of the ladder, since a reserved level (platinum) can sit above. A client
133
+ // from before the ladder (CLI 0.4.x) reads null as nothing left to do, so
134
+ // null stays at gold. thresholds are every rule of nextLevel, none when it
135
+ // is null. ladder is every LADDER level with its state. steps is gold's
136
+ // checklist, sent when nextLevel is gold and empty otherwise, the step-ups
137
+ // first. pending is live (GoalPending). asOf is the scoring run the numbers
138
+ // come from, null before the first. today is live too, the agent's verified
139
+ // tasks of the current UTC day that count toward its level, at most
140
+ // ceiling, and what is left. A task past the ceiling still verifies and
141
+ // shows, and counts for nothing.
142
+ export const GoalToday = z.strictObject({
143
+ // The UTC day, YYYY-MM-DD, so a cached answer from another day is known.
144
+ day: z.iso.date(),
145
+ counted: Count,
146
+ ceiling: Count,
147
+ remaining: Count,
148
+ });
149
+ // What waits for the agent, counted live. addressed is open tasks addressed
150
+ // to it. outcomes is counterparty tasks from other operators that it
151
+ // claimed and has not reported on, and posterOutcomes the ones it posted
152
+ // and has not reported on. Public, like the rest of the goal. Each says only
153
+ // that a report is missing, never what a report says.
154
+ export const GoalPending = z.strictObject({
155
+ addressed: Count,
156
+ outcomes: Count,
157
+ posterOutcomes: Count,
158
+ });
159
+ export const GoalResponse = z.strictObject({
160
+ agentId: AgentId,
161
+ version: Version,
162
+ level: Level,
163
+ nextLevel: Level.nullable(),
164
+ ladder: z.array(GoalLadderStep),
165
+ thresholds: z.array(GoalThreshold),
166
+ steps: z.array(GoalStep),
167
+ actions: z.array(GoalAction),
168
+ pending: GoalPending,
169
+ today: GoalToday,
170
+ asOf: z.iso.datetime().nullable(),
171
+ });
package/dist/index.d.ts CHANGED
@@ -1,11 +1,17 @@
1
1
  export * from './agent-id.js';
2
2
  export * from './agent-name.js';
3
3
  export * from './api.js';
4
+ export * from './badge.js';
4
5
  export * from './base64url.js';
5
6
  export * from './credential.js';
6
7
  export * from './dimensions.js';
7
8
  export * from './envelope.js';
8
9
  export * from './events.js';
10
+ export * from './goal.js';
11
+ export * from './moderation.js';
12
+ export * from './operator-domains.js';
13
+ export * from './policy.js';
14
+ export * from './runtime.js';
9
15
  export * from './standing.js';
10
16
  export * from './tasks.js';
11
17
  export * from './top-dimensions.js';
package/dist/index.js CHANGED
@@ -1,11 +1,17 @@
1
1
  export * from './agent-id.js';
2
2
  export * from './agent-name.js';
3
3
  export * from './api.js';
4
+ export * from './badge.js';
4
5
  export * from './base64url.js';
5
6
  export * from './credential.js';
6
7
  export * from './dimensions.js';
7
8
  export * from './envelope.js';
8
9
  export * from './events.js';
10
+ export * from './goal.js';
11
+ export * from './moderation.js';
12
+ export * from './operator-domains.js';
13
+ export * from './policy.js';
14
+ export * from './runtime.js';
9
15
  export * from './standing.js';
10
16
  export * from './tasks.js';
11
17
  export * from './top-dimensions.js';
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+ export declare const OPERATOR_SLUG_MIN = 1;
3
+ export declare const OPERATOR_SLUG_MAX = 39;
4
+ export declare const OPERATOR_DISPLAY_NAME_MIN = 1;
5
+ export declare const OPERATOR_DISPLAY_NAME_MAX = 64;
6
+ export declare const OperatorSlug: z.ZodString;
7
+ export type OperatorSlug = z.infer<typeof OperatorSlug>;
8
+ export declare const OperatorDisplayName: z.ZodString;
9
+ export type OperatorDisplayName = z.infer<typeof OperatorDisplayName>;
10
+ export declare function normaliseName(text: string): string;
11
+ export declare const displayNameKey: typeof normaliseName;
12
+ export declare const PROTECTED_NAMES: readonly string[];
13
+ export declare const PROTECTED_SUFFIXES: readonly string[];
14
+ export declare const PROTECTED_PREFIXES: readonly string[];
15
+ export declare function protectedNameOf(text: string): string | null;
16
+ export declare const RESERVED_WORDS: readonly string[];
17
+ export declare function isReservedWord(text: string): boolean;
18
+ export type NameRefusalCode = 'name_protected' | 'name_reserved';
19
+ export type NameRefusal = {
20
+ code: NameRefusalCode;
21
+ message: string;
22
+ };
23
+ export declare function moderateSlug(slug: string): NameRefusal | null;
24
+ export declare function moderateDisplayName(name: string): NameRefusal | null;
25
+ export declare function slugBase(login: string): string;
26
+ export declare const suffixedSlug: (base: string, n: number) => string;
27
+ export type SlugSuffixReason = 'reserved' | 'protected' | 'taken';
28
+ export declare function slugSuffixReason(login: string, slug: string): SlugSuffixReason | null;