@capybara-hq/kernel 0.1.0-rc.142 → 0.1.0-rc.144
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/admin/admin-agents.controller.d.ts +3 -5
- package/dist/admin/admin-agents.controller.js +1 -1
- package/dist/admin/admin-connectors.controller.d.ts +3 -5
- package/dist/admin/admin-connectors.controller.js +1 -1
- package/dist/admin/admin-items.schemas.d.ts +6 -6
- package/dist/admin/admin-items.schemas.js +5 -9
- package/dist/admin/admin.controller.d.ts +18 -12
- package/dist/admin/admin.controller.js +29 -15
- package/dist/admin/admin.schemas.d.ts +12 -3
- package/dist/admin/admin.schemas.js +17 -6
- package/dist/agents/admin-agents.d.ts +10 -8
- package/dist/agents/admin-agents.js +13 -9
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.service.js +1 -1
- package/dist/agents/org-templates.d.ts +3 -1
- package/dist/agents/org-templates.js +7 -3
- package/dist/agents/pending-connector-requests.d.ts +10 -4
- package/dist/agents/pending-connector-requests.js +29 -7
- package/dist/automations/automations.controller.d.ts +9 -5
- package/dist/automations/automations.controller.js +21 -4
- package/dist/automations/automations.schemas.d.ts +19 -0
- package/dist/automations/automations.schemas.js +9 -0
- package/dist/automations/automations.service.d.ts +25 -8
- package/dist/automations/automations.service.js +40 -34
- package/dist/automations/events/acceptance.d.ts +6 -1
- package/dist/automations/events/acceptance.js +30 -11
- package/dist/automations/store.d.ts +17 -0
- package/dist/automations/store.js +35 -0
- package/dist/catalog/admin-catalog.controller.d.ts +64 -2
- package/dist/catalog/admin-catalog.controller.js +17 -0
- package/dist/catalog/catalog-import.module.js +3 -0
- package/dist/catalog/catalog-scope.service.d.ts +3 -1
- package/dist/catalog/catalog-scope.service.js +11 -7
- package/dist/catalog/catalog.module.js +3 -0
- package/dist/catalog/catalog.service.d.ts +3 -1
- package/dist/catalog/catalog.service.js +8 -4
- package/dist/catalog/cli.js +2 -2
- package/dist/catalog/component-promotion.d.ts +3 -1
- package/dist/catalog/component-promotion.js +7 -3
- package/dist/catalog/component-scope.service.d.ts +3 -1
- package/dist/catalog/component-scope.service.js +7 -3
- package/dist/catalog/enable-requests.d.ts +10 -8
- package/dist/catalog/enable-requests.js +40 -21
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/owned-items.d.ts +3 -1
- package/dist/catalog/owned-items.js +13 -9
- package/dist/catalog/platform-components.d.ts +6 -1
- package/dist/catalog/platform-components.js +9 -3
- package/dist/catalog/plugin-connectors.d.ts +8 -4
- package/dist/catalog/plugin-connectors.js +12 -6
- package/dist/catalog/plugin-import.d.ts +3 -1
- package/dist/catalog/plugin-import.js +14 -5
- package/dist/catalog/plugin-install.d.ts +3 -1
- package/dist/catalog/plugin-install.js +8 -4
- package/dist/catalog/plugin-package.js +2 -1
- package/dist/catalog/plugin-upgrade.d.ts +3 -1
- package/dist/catalog/plugin-upgrade.js +8 -4
- package/dist/catalog/request-hints.d.ts +19 -0
- package/dist/catalog/request-hints.js +34 -0
- package/dist/catalog/request-rules.d.ts +9 -5
- package/dist/catalog/request-rules.js +16 -9
- package/dist/catalog/requests.service.d.ts +3 -1
- package/dist/catalog/requests.service.js +28 -9
- package/dist/catalog/scope-orgs.d.ts +2 -1
- package/dist/catalog/scope-orgs.js +2 -2
- package/dist/catalog/scope-sync.d.ts +3 -1
- package/dist/catalog/scope-sync.js +12 -2
- package/dist/catalog/scope-writer.d.ts +6 -3
- package/dist/catalog/scope-writer.js +28 -10
- package/dist/catalog/unshare.d.ts +3 -2
- package/dist/catalog/unshare.js +4 -4
- package/dist/client/client-access.service.js +29 -1
- package/dist/config/schema.d.ts +12 -0
- package/dist/config/schema.js +56 -0
- package/dist/ctx/create-ctx.d.ts +2 -19
- package/dist/ctx/create-ctx.js +3 -93
- package/dist/ctx/durable-relay.d.ts +2 -5
- package/dist/ctx/durable-relay.js +56 -29
- package/dist/db/extension-handoff-schema.js +5 -0
- package/dist/db/kernel-schema.d.ts +74 -0
- package/dist/db/migrator.js +36 -0
- package/dist/erasure/account-batches.js +2 -0
- package/dist/erasure/account-residual.js +1 -0
- package/dist/erasure/org-catalog.js +8 -3
- package/dist/erasure/org-rules.js +1 -0
- package/dist/evals/evals.schemas.d.ts +15 -5
- package/dist/evals/evals.schemas.js +17 -10
- package/dist/evals/runs.controller.d.ts +4 -12
- package/dist/evals/runs.controller.js +14 -11
- package/dist/evals/runs.service.d.ts +29 -25
- package/dist/evals/runs.service.js +73 -61
- package/dist/evals/trajectory.controller.d.ts +10 -6
- package/dist/evals/trajectory.controller.js +11 -4
- package/dist/evals/trajectory.service.d.ts +17 -9
- package/dist/evals/trajectory.service.js +52 -35
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +21 -7
- package/dist/extensions/blobs.d.ts +2 -0
- package/dist/extensions/blobs.js +11 -0
- package/dist/extensions/deployment-config.d.ts +6 -1
- package/dist/extensions/deployment-config.js +13 -2
- package/dist/extensions/enabled.d.ts +5 -0
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/grant-epoch.d.ts +108 -0
- package/dist/extensions/grant-epoch.js +214 -0
- package/dist/extensions/host.d.ts +29 -9
- package/dist/extensions/host.js +148 -42
- package/dist/extensions/instance.d.ts +3 -3
- package/dist/extensions/instance.js +1 -1
- package/dist/extensions/isolated/authorization.d.ts +54 -2
- package/dist/extensions/isolated/authorization.js +148 -35
- package/dist/extensions/isolated/child-session.js +0 -1
- package/dist/extensions/isolated/revision.js +1 -1
- package/dist/extensions/org-config.d.ts +3 -1
- package/dist/extensions/org-config.js +13 -4
- package/dist/extensions/org-overrides.d.ts +6 -1
- package/dist/extensions/org-overrides.js +13 -2
- package/dist/extensions/package-digest.job.d.ts +34 -0
- package/dist/extensions/package-digest.job.js +121 -0
- package/dist/extensions/package.js +10 -6
- package/dist/extensions/permission-set.d.ts +14 -78
- package/dist/extensions/permission-set.js +17 -143
- package/dist/extensions/permission-view.d.ts +13 -1
- package/dist/extensions/permission-view.js +20 -0
- package/dist/extensions/registry.js +4 -1
- package/dist/extensions/resolve.d.ts +7 -8
- package/dist/extensions/resolve.js +7 -8
- package/dist/extensions/revision-approvals.d.ts +167 -0
- package/dist/extensions/revision-approvals.js +353 -0
- package/dist/extensions/revision-grants.d.ts +197 -0
- package/dist/extensions/revision-grants.js +584 -0
- package/dist/extensions/state.module.js +12 -1
- package/dist/identity/accounts.d.ts +10 -4
- package/dist/identity/accounts.js +18 -5
- package/dist/inbox/inbox-items.service.d.ts +6 -1
- package/dist/inbox/inbox-items.service.js +29 -10
- package/dist/inbox/inbox.module.js +3 -0
- package/dist/inbox/inbox.service.d.ts +3 -1
- package/dist/inbox/inbox.service.js +9 -2
- package/dist/inbox/org-notices.d.ts +4 -3
- package/dist/inbox/org-notices.js +9 -6
- package/dist/inbox/platform-inbox.service.d.ts +3 -1
- package/dist/inbox/platform-inbox.service.js +11 -3
- package/dist/inbox/platform-notices.d.ts +3 -2
- package/dist/inbox/platform-notices.js +10 -4
- package/dist/infra/config/kernel-config.service.js +4 -1
- package/dist/infra/database/extension-effect-key-lock.js +7 -0
- package/dist/infra/paging/paged-read.d.ts +34 -4
- package/dist/infra/paging/paged-read.js +38 -1
- package/dist/invalidation/audiences.d.ts +32 -0
- package/dist/invalidation/audiences.js +43 -0
- package/dist/invalidation/hints.d.ts +6 -0
- package/dist/invalidation/hints.js +7 -1
- package/dist/invalidation/invalidation-hints.d.ts +12 -1
- package/dist/invalidation/invalidation-hints.js +46 -5
- package/dist/invalidation/invalidation-hints.module.d.ts +2 -0
- package/dist/invalidation/invalidation-hints.module.js +4 -1
- package/dist/invalidation/me-stream.d.ts +1 -11
- package/dist/invalidation/me-stream.js +12 -41
- package/dist/invalidation/org-intent-bridge.d.ts +18 -0
- package/dist/invalidation/org-intent-bridge.js +46 -0
- package/dist/models/enablement.d.ts +3 -1
- package/dist/models/enablement.js +25 -5
- package/dist/orgs/invitations.controller.d.ts +4 -7
- package/dist/orgs/invitations.controller.js +8 -5
- package/dist/orgs/invitations.service.d.ts +17 -3
- package/dist/orgs/invitations.service.js +35 -13
- package/dist/orgs/members.service.d.ts +35 -0
- package/dist/orgs/members.service.js +52 -3
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +7 -3
- package/dist/orgs/orgs.controller.d.ts +11 -4
- package/dist/orgs/orgs.controller.js +25 -5
- package/dist/orgs/orgs.module.js +3 -0
- package/dist/orgs/orgs.schemas.d.ts +14 -0
- package/dist/orgs/orgs.schemas.js +19 -2
- package/dist/orgs/orgs.service.d.ts +24 -2
- package/dist/orgs/orgs.service.js +47 -4
- package/dist/orgs/security-settings.service.d.ts +14 -6
- package/dist/orgs/security-settings.service.js +18 -13
- package/dist/orgs/settings.controller.d.ts +7 -4
- package/dist/platform/exclusions.js +15 -0
- package/dist/platform/ops/accounts.ops.js +7 -16
- package/dist/platform/ops/admin-items.ops.js +7 -7
- package/dist/platform/ops/automations.ops.js +6 -4
- package/dist/platform/ops/evals.ops.js +30 -15
- package/dist/platform/ops/org-settings.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.js +44 -27
- package/dist/push/delivery.d.ts +3 -1
- package/dist/push/delivery.js +7 -3
- package/dist/push/push-processor.js +8 -1
- package/dist/roles/worker.module.js +3 -0
- package/dist/runtime/step-log.d.ts +1 -1
- package/dist/runtime/step-log.js +5 -4
- package/dist/runtime/stream-limit.d.ts +13 -0
- package/dist/runtime/stream-limit.js +40 -0
- package/dist/runtime/stream.controller.d.ts +2 -0
- package/dist/runtime/stream.controller.js +2 -0
- package/dist/runtime/stream.d.ts +1 -0
- package/dist/runtime/stream.js +15 -6
- package/dist/sandbox/permission-authority.module.js +6 -1
- package/dist/sandbox/permission-transitions.d.ts +3 -1
- package/dist/sandbox/permission-transitions.js +17 -2
- package/dist/setup/kernel-checks.d.ts +3 -3
- package/dist/setup/kernel-checks.js +4 -4
- package/dist/setup/setup-check-registry.d.ts +16 -5
- package/dist/setup/setup-check-registry.js +11 -3
- package/dist/setup/setup-checks.service.d.ts +1 -2
- package/dist/setup/setup-checks.service.js +7 -6
- package/dist/skills/agent-skills.service.d.ts +6 -1
- package/dist/skills/agent-skills.service.js +12 -3
- package/dist/skills/changes.service.d.ts +6 -1
- package/dist/skills/changes.service.js +11 -3
- package/dist/skills/conversation-catalog.d.ts +3 -0
- package/dist/skills/conversation-catalog.js +2 -0
- package/dist/skills/skills.module.js +3 -0
- package/dist/skills/skills.service.d.ts +3 -1
- package/dist/skills/skills.service.js +8 -4
- package/dist/tools/admin-connectors.d.ts +10 -8
- package/dist/tools/admin-connectors.js +12 -10
- package/dist/tools/approvals.service.d.ts +12 -1
- package/dist/tools/approvals.service.js +36 -9
- package/dist/tools/builtins/automations.d.ts +1 -1
- package/dist/tools/builtins/automations.js +1 -1
- package/dist/tools/connectors.service.d.ts +3 -1
- package/dist/tools/connectors.service.js +29 -7
- package/dist/tools/tools.module.js +3 -0
- package/dist/ui/admin-ui.controller.d.ts +3 -1
- package/dist/ui/admin-ui.controller.js +3 -1
- package/dist/ui/ui-stream.d.ts +2 -0
- package/dist/ui/ui-stream.js +20 -6
- package/dist/ui/views.controller.d.ts +4 -2
- package/dist/ui/views.controller.js +4 -2
- package/package.json +3 -3
- package/src/migrations/0234_extension_grant_epoch.sql +141 -0
- package/src/migrations/0235_extension_revision_grants.sql +166 -0
- package/src/migrations/0236_paged_table_idx.sql +33 -0
- package/src/migrations/0237_extension_handoff_health.sql +18 -0
|
@@ -10,11 +10,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { EXTENSION_NAME_RE } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
-
import { ConfiguredExtensionDbIdentity } from "../db/extension-db.js";
|
|
14
|
-
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
15
|
-
import { ReplicaStatusStore } from "../extensions/sources.js";
|
|
13
|
+
import { ConfiguredExtensionDbIdentity, pluginSchemaName, } from "../db/extension-db.js";
|
|
16
14
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
17
|
-
import { handoffReference, markHandoffParked, readHandoff, readHandoffRow, readUnreferencedParks, retryHandoff, settleHandoff, } from "../infra/database/extension-handoff.js";
|
|
15
|
+
import { EXTENSION_EFFECT_HANDOFF, handoffReference, handoffTable, markHandoffParked, readHandoff, readHandoffRow, readUnreferencedParks, retryHandoff, settleHandoff, } from "../infra/database/extension-handoff.js";
|
|
18
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
19
17
|
import { asPlatform, withOrgScope } from "../infra/database/org-scope.js";
|
|
20
18
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
@@ -36,19 +34,15 @@ let ExtensionEffectRelay = class ExtensionEffectRelay {
|
|
|
36
34
|
effects;
|
|
37
35
|
keys;
|
|
38
36
|
identity;
|
|
39
|
-
registry;
|
|
40
|
-
status;
|
|
41
37
|
db;
|
|
42
38
|
config;
|
|
43
39
|
lockService;
|
|
44
40
|
log;
|
|
45
|
-
constructor(dispatcher, effects, keys, identity,
|
|
41
|
+
constructor(dispatcher, effects, keys, identity, db, config, lockService, log) {
|
|
46
42
|
this.dispatcher = dispatcher;
|
|
47
43
|
this.effects = effects;
|
|
48
44
|
this.keys = keys;
|
|
49
45
|
this.identity = identity;
|
|
50
|
-
this.registry = registry;
|
|
51
|
-
this.status = status;
|
|
52
46
|
this.db = db;
|
|
53
47
|
this.config = config;
|
|
54
48
|
this.lockService = lockService;
|
|
@@ -61,11 +55,18 @@ let ExtensionEffectRelay = class ExtensionEffectRelay {
|
|
|
61
55
|
await this.keys.retireUnused();
|
|
62
56
|
}
|
|
63
57
|
async relayOnce(signal) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
const tables = await asPlatform("Find provisioned extension handoff tables", async () => {
|
|
59
|
+
// During a rolling upgrade an older provisioner can still create a table without recording it.
|
|
60
|
+
await sql `
|
|
61
|
+
insert into capybara.extension_handoff_tables (schema_name)
|
|
62
|
+
select n.nspname from pg_catalog.pg_class c
|
|
63
|
+
join pg_catalog.pg_namespace n on n.oid = c.relnamespace
|
|
64
|
+
where c.relname = ${EXTENSION_EFFECT_HANDOFF} and c.relkind = 'r'
|
|
65
|
+
and n.nspname ~ '^plugin_[a-z][a-z0-9_]{1,40}$'
|
|
66
|
+
on conflict do nothing
|
|
67
|
+
`.execute(this.db.db);
|
|
68
|
+
return this.db.db.selectFrom("extension_handoff_tables").select("schema_name").execute();
|
|
69
|
+
});
|
|
69
70
|
let loaded;
|
|
70
71
|
let loadedAt = 0;
|
|
71
72
|
let refreshed = false;
|
|
@@ -89,10 +90,11 @@ let ExtensionEffectRelay = class ExtensionEffectRelay {
|
|
|
89
90
|
}
|
|
90
91
|
return keys;
|
|
91
92
|
};
|
|
92
|
-
for (const
|
|
93
|
+
for (const { schema_name: schema } of tables) {
|
|
93
94
|
if (signal?.aborted)
|
|
94
95
|
return;
|
|
95
|
-
|
|
96
|
+
const plugin = schema.slice("plugin_".length).replaceAll("_", "-");
|
|
97
|
+
if (!EXTENSION_NAME_RE.test(plugin) || pluginSchemaName(plugin) !== schema)
|
|
96
98
|
continue;
|
|
97
99
|
const lease = await this.lockService.acquire(`extension-effect-relay-${plugin}`, {
|
|
98
100
|
ttlMs: 30_000,
|
|
@@ -102,6 +104,11 @@ let ExtensionEffectRelay = class ExtensionEffectRelay {
|
|
|
102
104
|
continue;
|
|
103
105
|
const active = signal ? AbortSignal.any([lease.lost, signal]) : lease.lost;
|
|
104
106
|
try {
|
|
107
|
+
const { rows: [table], } = await sql `
|
|
108
|
+
select pg_catalog.to_regclass(${handoffTable(plugin)}) is not null as present
|
|
109
|
+
`.execute(this.db.db);
|
|
110
|
+
if (!table?.present)
|
|
111
|
+
throw new ExtensionEffectFailure("handoff_missing", "The extension handoff table is missing");
|
|
105
112
|
const identity = this.identity.resolve(plugin);
|
|
106
113
|
const login = identity.separate ? identity.login : null;
|
|
107
114
|
await asPlatform("Relay extension handoffs and their outbox references", async () => {
|
|
@@ -109,17 +116,21 @@ let ExtensionEffectRelay = class ExtensionEffectRelay {
|
|
|
109
116
|
await this.ingest(plugin, login, ring, active);
|
|
110
117
|
await this.cleanup(plugin, login, ring, active);
|
|
111
118
|
});
|
|
112
|
-
|
|
119
|
+
if (!active.aborted)
|
|
120
|
+
await this.handoffHealth(schema, plugin, false);
|
|
113
121
|
}
|
|
114
122
|
catch (error) {
|
|
123
|
+
if (active.aborted)
|
|
124
|
+
continue;
|
|
115
125
|
const failure = classifyEffectFailure(error);
|
|
116
126
|
if (failure.code === "handoff_missing") {
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
if (await this.handoffHealth(schema, plugin, true)) {
|
|
128
|
+
this.log.error("Extension handoff health fault", {
|
|
129
|
+
plugin,
|
|
130
|
+
code: failure.code,
|
|
131
|
+
message: failure.message,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
123
134
|
}
|
|
124
135
|
else {
|
|
125
136
|
this.log.warn("Extension handoff relay failed", { plugin, code: failure.code });
|
|
@@ -130,6 +141,24 @@ let ExtensionEffectRelay = class ExtensionEffectRelay {
|
|
|
130
141
|
}
|
|
131
142
|
}
|
|
132
143
|
}
|
|
144
|
+
async handoffHealth(schema, plugin, missing) {
|
|
145
|
+
const transition = await this.db.db
|
|
146
|
+
.updateTable("extension_handoff_tables")
|
|
147
|
+
.set({ missing })
|
|
148
|
+
.where("schema_name", "=", schema)
|
|
149
|
+
.where("missing", "=", !missing)
|
|
150
|
+
.returning("schema_name")
|
|
151
|
+
.executeTakeFirst();
|
|
152
|
+
// Admission and setup errors take precedence over the handoff note.
|
|
153
|
+
await this.db.db
|
|
154
|
+
.updateTable("extension_replica_status")
|
|
155
|
+
.set({ detail: missing ? HANDOFF_MISSING : null })
|
|
156
|
+
.where("plugin", "=", plugin)
|
|
157
|
+
.$if(missing, (query) => query.where("detail", "is", null))
|
|
158
|
+
.$if(!missing, (query) => query.where("detail", "=", HANDOFF_MISSING))
|
|
159
|
+
.execute();
|
|
160
|
+
return transition !== undefined;
|
|
161
|
+
}
|
|
133
162
|
async redrive(plugin, login, ring, signal) {
|
|
134
163
|
// org-filter: deployment-wide outbox scan by plugin; only the verified envelope supplies delivery scope.
|
|
135
164
|
const rows = await asPlatform("Find due extension redrive references", () => this.db.db
|
|
@@ -240,11 +269,9 @@ ExtensionEffectRelay = __decorate([
|
|
|
240
269
|
__param(1, Inject(ExtensionEffects)),
|
|
241
270
|
__param(2, Inject(ExtensionEffectKeys)),
|
|
242
271
|
__param(3, Inject(ConfiguredExtensionDbIdentity)),
|
|
243
|
-
__param(4, Inject(
|
|
244
|
-
__param(5, Inject(
|
|
245
|
-
__param(6, Inject(
|
|
246
|
-
__param(7, Inject(
|
|
247
|
-
__param(8, Inject(LockService)),
|
|
248
|
-
__param(9, Inject(KERNEL_LOGGER))
|
|
272
|
+
__param(4, Inject(KernelDb)),
|
|
273
|
+
__param(5, Inject(KernelConfigService)),
|
|
274
|
+
__param(6, Inject(LockService)),
|
|
275
|
+
__param(7, Inject(KERNEL_LOGGER))
|
|
249
276
|
], ExtensionEffectRelay);
|
|
250
277
|
export { ExtensionEffectRelay };
|
|
@@ -21,6 +21,9 @@ function createHandoffTable(table, ifNotExists = true) {
|
|
|
21
21
|
create index if not exists _capybara_effect_key on ${table} ((envelope->>'keyId'))
|
|
22
22
|
`;
|
|
23
23
|
}
|
|
24
|
+
async function recordHandoffTable(owner, schema) {
|
|
25
|
+
await owner.query("insert into capybara.extension_handoff_tables (schema_name) values ($1) on conflict do nothing", [schema]);
|
|
26
|
+
}
|
|
24
27
|
/** Creates a handoff owned by the one-shot provisioner. The extension can append only. */
|
|
25
28
|
export async function provisionExtensionHandoff(owner, schema, extensionLogin, runtimeLogin, legacyOwner) {
|
|
26
29
|
await lockMigrationSchema(owner, schema, "transaction");
|
|
@@ -79,6 +82,7 @@ export async function provisionExtensionHandoff(owner, schema, extensionLogin, r
|
|
|
79
82
|
await owner.query(`grant usage on schema ${ns} to ${reader}`);
|
|
80
83
|
await owner.query(`grant select, delete on table ${table} to ${reader}`);
|
|
81
84
|
await owner.query(`grant update (attempts, last_error, next_attempt_at, parked_at) on table ${table} to ${reader}`);
|
|
85
|
+
await recordHandoffTable(owner, schema);
|
|
82
86
|
}
|
|
83
87
|
/** Single-login deployments use the kernel's own connection for this table. */
|
|
84
88
|
export async function ensureLocalExtensionHandoff(db, dbUrl, schema, connectTimeoutMs) {
|
|
@@ -102,6 +106,7 @@ export async function ensureLocalExtensionHandoff(db, dbUrl, schema, connectTime
|
|
|
102
106
|
const table = `${ns}.${pg.escapeIdentifier(EXTENSION_EFFECT_HANDOFF)}`;
|
|
103
107
|
await client.query(`create schema if not exists ${ns}`);
|
|
104
108
|
await client.query(createHandoffTable(table));
|
|
109
|
+
await recordHandoffTable(client, schema);
|
|
105
110
|
await client.query("commit");
|
|
106
111
|
}
|
|
107
112
|
finally {
|
|
@@ -1514,6 +1514,8 @@ export interface ExtensionPackagesTable {
|
|
|
1514
1514
|
zh: string;
|
|
1515
1515
|
en: string;
|
|
1516
1516
|
} | null, string | null | undefined, string | null>;
|
|
1517
|
+
/** 0235: lowercase hex sha512 of the archive; filled at ingest and backfilled by plan task 1.2b. */
|
|
1518
|
+
sha512: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1517
1519
|
}
|
|
1518
1520
|
/**
|
|
1519
1521
|
* 0100: catalog display files (plugin icons, connector template icons, setup guide files) by
|
|
@@ -1554,6 +1556,66 @@ export interface ExtensionInstallsTable {
|
|
|
1554
1556
|
* refused) the earliest enabled is the one every replica loads.
|
|
1555
1557
|
*/
|
|
1556
1558
|
enabled_at: TsNullable;
|
|
1559
|
+
/**
|
|
1560
|
+
* 0235: the approved revision and the grant generation it was promoted under, or NULL. The
|
|
1561
|
+
* foreign key guarantees that grant exists; its state is read at admission.
|
|
1562
|
+
*/
|
|
1563
|
+
approved_version: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1564
|
+
approved_sha512: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1565
|
+
approved_generation: ColumnType<number | null, number | null | undefined, number | null>;
|
|
1566
|
+
/** 0235: a candidate revision waiting for review (it may have no grant), or NULL. */
|
|
1567
|
+
candidate_version: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1568
|
+
candidate_sha512: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1569
|
+
}
|
|
1570
|
+
/** 0235: one admin approval bound to an exact package revision (see extensions/revision-grants.ts). */
|
|
1571
|
+
export interface ExtensionRevisionGrantsTable {
|
|
1572
|
+
plugin: string;
|
|
1573
|
+
version: string;
|
|
1574
|
+
/** Lowercase hex sha512 of the package archive. */
|
|
1575
|
+
sha512: string;
|
|
1576
|
+
/** A new review of the same revision after revocation or retirement is the next generation. */
|
|
1577
|
+
generation: number;
|
|
1578
|
+
keys: Json<string[]>;
|
|
1579
|
+
purposes: Json<{
|
|
1580
|
+
key: string;
|
|
1581
|
+
zh: string;
|
|
1582
|
+
en: string;
|
|
1583
|
+
}[]>;
|
|
1584
|
+
purposes_digest: string;
|
|
1585
|
+
realms: ColumnType<Record<string, string[]>, string | undefined, string>;
|
|
1586
|
+
review_hash: string;
|
|
1587
|
+
approval_scope: "all" | "optional" | "named";
|
|
1588
|
+
source: "review" | "operator_config" | "operator_cli" | "auto" | "continuity";
|
|
1589
|
+
authority: "super_admin" | "operator" | "auto";
|
|
1590
|
+
publisher: ColumnType<Record<string, string> | null, string | null | undefined, string | null>;
|
|
1591
|
+
publisher_evidence: "verified" | "pin_only" | "none";
|
|
1592
|
+
continued_version: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1593
|
+
continued_sha512: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1594
|
+
continued_generation: ColumnType<number | null, number | null | undefined, number | null>;
|
|
1595
|
+
state: ColumnType<"approved" | "partially_revoked" | "revoked" | "retired", "approved" | undefined, "approved" | "partially_revoked" | "revoked" | "retired">;
|
|
1596
|
+
disabled_keys: ColumnType<string[], string | undefined, string>;
|
|
1597
|
+
retired_keys: ColumnType<string[], string | undefined, string>;
|
|
1598
|
+
retired_forcing: ColumnType<Record<string, string[]>, string | undefined, string>;
|
|
1599
|
+
approved_by: string | null;
|
|
1600
|
+
approved_at: Ts;
|
|
1601
|
+
state_changed_by: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1602
|
+
state_changed_at: TsNullable;
|
|
1603
|
+
}
|
|
1604
|
+
/** 0235: the orgs of a revision grant whose approval scope is `named`. */
|
|
1605
|
+
export interface ExtensionRevisionGrantOrgsTable {
|
|
1606
|
+
plugin: string;
|
|
1607
|
+
version: string;
|
|
1608
|
+
sha512: string;
|
|
1609
|
+
generation: number;
|
|
1610
|
+
org_id: string;
|
|
1611
|
+
}
|
|
1612
|
+
export interface ExtensionHandoffTablesTable {
|
|
1613
|
+
schema_name: string;
|
|
1614
|
+
missing: Generated<boolean>;
|
|
1615
|
+
}
|
|
1616
|
+
export interface ExtensionAdmissionRefusalsTable {
|
|
1617
|
+
plugin: string;
|
|
1618
|
+
sha256: string;
|
|
1557
1619
|
}
|
|
1558
1620
|
/** Which npm package owns an extension name (Ruling P3): written on first install, kept on uninstall. */
|
|
1559
1621
|
export interface ExtensionNameOwnersTable {
|
|
@@ -1568,6 +1630,13 @@ export interface ExtensionDeploymentConfigsTable {
|
|
|
1568
1630
|
updated_by: string | null;
|
|
1569
1631
|
updated_at: Ts;
|
|
1570
1632
|
}
|
|
1633
|
+
/** The deployment grant epoch (migration 0234): one row, advanced by triggers at commit. */
|
|
1634
|
+
export interface ExtensionGrantEpochTable {
|
|
1635
|
+
id: Generated<number>;
|
|
1636
|
+
/** bigint; pg returns it as a string. */
|
|
1637
|
+
epoch: Generated<string>;
|
|
1638
|
+
changed_at: Generated<Date>;
|
|
1639
|
+
}
|
|
1571
1640
|
export interface ExtensionReplicaStatusTable {
|
|
1572
1641
|
replica_id: string;
|
|
1573
1642
|
plugin: string;
|
|
@@ -2176,8 +2245,13 @@ export interface KernelDatabase {
|
|
|
2176
2245
|
extension_packages: ExtensionPackagesTable;
|
|
2177
2246
|
extension_blobs: ExtensionBlobsTable;
|
|
2178
2247
|
extension_installs: ExtensionInstallsTable;
|
|
2248
|
+
extension_revision_grants: ExtensionRevisionGrantsTable;
|
|
2249
|
+
extension_revision_grant_orgs: ExtensionRevisionGrantOrgsTable;
|
|
2179
2250
|
extension_replica_status: ExtensionReplicaStatusTable;
|
|
2251
|
+
extension_grant_epoch: ExtensionGrantEpochTable;
|
|
2180
2252
|
extension_name_owners: ExtensionNameOwnersTable;
|
|
2253
|
+
extension_handoff_tables: ExtensionHandoffTablesTable;
|
|
2254
|
+
extension_admission_refusals: ExtensionAdmissionRefusalsTable;
|
|
2181
2255
|
extension_deployment_configs: ExtensionDeploymentConfigsTable;
|
|
2182
2256
|
catalog_items: CatalogItemsTable;
|
|
2183
2257
|
catalog_item_versions: CatalogItemVersionsTable;
|
package/dist/db/migrator.js
CHANGED
|
@@ -48,6 +48,37 @@ export async function canMigrateKernel(db) {
|
|
|
48
48
|
return privileges.can_create && (privileges.owns_schema ?? true);
|
|
49
49
|
}
|
|
50
50
|
const migrateHint = "Run capybara migrate with CAPYBARA_DB__MIGRATION_URL set to the schema owner URL for split roles.";
|
|
51
|
+
const eventOrgContract = "0219_event_org_constraint_check.sql";
|
|
52
|
+
/** The rc.159 worker is the last release that can backfill events before 0219. */
|
|
53
|
+
async function checkEventOrgBackfill(client) {
|
|
54
|
+
await client.query("begin read only");
|
|
55
|
+
try {
|
|
56
|
+
await client.query("set local row_security = off");
|
|
57
|
+
const { rows: [table], } = await client.query(`
|
|
58
|
+
select exists (
|
|
59
|
+
select from pg_catalog.pg_attribute
|
|
60
|
+
where attrelid = relation and attname = 'org_id' and attnum > 0 and not attisdropped
|
|
61
|
+
) as has_org_id
|
|
62
|
+
from (select pg_catalog.to_regclass('capybara.conversation_events') as relation) events
|
|
63
|
+
where relation is not null
|
|
64
|
+
`);
|
|
65
|
+
if (!table)
|
|
66
|
+
return;
|
|
67
|
+
// Before 0215, every existing event would receive a null org_id from the expansion.
|
|
68
|
+
const filter = table.has_org_id ? "where org_id is null" : "";
|
|
69
|
+
const { rows: [state], } = await client.query(`select exists (select from capybara.conversation_events ${filter}) as incomplete`);
|
|
70
|
+
if (state?.incomplete) {
|
|
71
|
+
throw new Error("Migration 0219 requires the conversation event organization backfill. " +
|
|
72
|
+
"Upgrade to Capybara 0.1.0-rc.159 and run its worker after older writers have drained. " +
|
|
73
|
+
"Wait for EventOrgBackfillJob to finish, then verify " +
|
|
74
|
+
"SELECT count(*) FROM capybara.conversation_events WHERE org_id IS NULL returns 0 " +
|
|
75
|
+
"before rerunning capybara migrate.");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
await client.query("rollback");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
51
82
|
/** Verify the files expected by this binary without taking a migration lock or writing the journal.
|
|
52
83
|
* Extra entries are valid when a newer release has already migrated a shared database.
|
|
53
84
|
*/
|
|
@@ -178,6 +209,11 @@ export async function migrate(connectionString, owner, opts = {}) {
|
|
|
178
209
|
throw new Error(`Migration ${schema}/${f.name} is out of order: a higher-numbered migration (${String(highest).padStart(4, "0")}) is already applied`);
|
|
179
210
|
}
|
|
180
211
|
}
|
|
212
|
+
if (schema === "capybara" &&
|
|
213
|
+
!done.has(eventOrgContract) &&
|
|
214
|
+
files.some((f) => f.name === eventOrgContract)) {
|
|
215
|
+
await checkEventOrgBackfill(client);
|
|
216
|
+
}
|
|
181
217
|
const applied = [];
|
|
182
218
|
for (const f of files) {
|
|
183
219
|
if (done.has(f.name))
|
|
@@ -123,6 +123,8 @@ const rules = [
|
|
|
123
123
|
clear("extension_installs", "installed_by", deployment, "name"),
|
|
124
124
|
clear("extension_installs", "updated_by", deployment, "name"),
|
|
125
125
|
clear("extension_permission_snapshots", "approved_by", deployment, "plugin,version"),
|
|
126
|
+
clear("extension_revision_grants", "approved_by", deployment, "plugin,version,sha512,generation"),
|
|
127
|
+
clear("extension_revision_grants", "state_changed_by", deployment, "plugin,version,sha512,generation"),
|
|
126
128
|
clear("extension_packages", "uploaded_by", deployment, "sha256"),
|
|
127
129
|
clear("extension_org_configs", "updated_by"),
|
|
128
130
|
clear("extension_org_overrides", "created_by"),
|
|
@@ -46,6 +46,7 @@ const direct = [
|
|
|
46
46
|
["extension_org_overrides", "created_by updated_by"],
|
|
47
47
|
["extension_packages", "uploaded_by"],
|
|
48
48
|
["extension_permission_snapshots", "approved_by"],
|
|
49
|
+
["extension_revision_grants", "approved_by state_changed_by"],
|
|
49
50
|
["file_shares", "created_by revoked_by"],
|
|
50
51
|
["files", "account_id"],
|
|
51
52
|
["identities", "account_id"],
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
|
-
// PostgreSQL 17 after
|
|
3
|
-
//
|
|
2
|
+
// PostgreSQL 17 after 0237. Re-review the ownership map before updating this fingerprint.
|
|
3
|
+
// 0234 adds extension_grant_epoch: deployment state with no org or account reference, so it
|
|
4
|
+
// needs no erasure rule. 0235 adds extension_revision_grants (approver columns cleared by account
|
|
5
|
+
// erasure, deployment scope) and extension_revision_grant_orgs (an org row rule; the org FK
|
|
6
|
+
// cascades), plus the install revision columns, their grant foreign key and extension_packages.sha512.
|
|
7
|
+
// 0237 adds the handoff inventory and admission refusals, both deployment metadata.
|
|
8
|
+
// The fingerprint includes relation/column identities and ordered PK, UNIQUE and inbound/outbound FK
|
|
4
9
|
// columns and actions, including FKs from outside the kernel schema.
|
|
5
10
|
export async function orgCatalogDrift(db) {
|
|
6
11
|
const { rows } = await sql `
|
|
@@ -30,5 +35,5 @@ WITH catalog AS (
|
|
|
30
35
|
)
|
|
31
36
|
SELECT md5(string_agg(entry, chr(10) ORDER BY entry COLLATE "C")) AS fingerprint FROM catalog
|
|
32
37
|
`.execute(db);
|
|
33
|
-
return rows[0]?.fingerprint === "
|
|
38
|
+
return rows[0]?.fingerprint === "a9f59a4747b2fa6ee329121f9a0af5b3" ? undefined : "schema-drift";
|
|
34
39
|
}
|
|
@@ -32,6 +32,7 @@ export const rowRules = [
|
|
|
32
32
|
rule("extension_client_reports", "plugin, build, org_id, contribution, kind"),
|
|
33
33
|
rule("extension_org_configs", "plugin, org_id"),
|
|
34
34
|
rule("extension_org_overrides", "plugin, org_id"),
|
|
35
|
+
rule("extension_revision_grant_orgs", "plugin, version, sha512, generation, org_id"),
|
|
35
36
|
rule("file_previewers", "org_id, plugin, previewer_id"),
|
|
36
37
|
rule("inbox_items", "id"),
|
|
37
38
|
rule("invitations", "id"),
|
|
@@ -71,17 +71,27 @@ export declare const EvalRunStartBody: z.ZodObject<{
|
|
|
71
71
|
tokenCap: z.ZodOptional<z.ZodNumber>;
|
|
72
72
|
}, z.core.$strict>;
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
74
|
+
* A page of a run's results by page number (table pagination spec §2.3, no snapshot: every result
|
|
75
|
+
* exists from the run's start). `view=light`: no content blocks (the results table and its
|
|
76
|
+
* polling, which reads the page again); default `full`.
|
|
76
77
|
*/
|
|
77
78
|
export declare const EvalRunResultsQuery: z.ZodObject<{
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
80
|
+
size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
80
81
|
view: z.ZodDefault<z.ZodEnum<{
|
|
81
82
|
full: "full";
|
|
82
83
|
light: "light";
|
|
83
84
|
}>>;
|
|
84
|
-
|
|
85
|
+
}, z.core.$strict>;
|
|
86
|
+
/**
|
|
87
|
+
* `GET …/eval-sets/:setId/runs`: page numbers on a snapshot (table pagination spec §2.3). Runs are
|
|
88
|
+
* only appended and never move, newest first by `(created_at, id)`; `asOf` is the point in time of
|
|
89
|
+
* the first read, so runs started later stay out and count in `newer`.
|
|
90
|
+
*/
|
|
91
|
+
export declare const EvalSetRunsQuery: z.ZodObject<{
|
|
92
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
93
|
+
size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
94
|
+
asOf: z.ZodOptional<z.ZodISODateTime>;
|
|
85
95
|
}, z.core.$strict>;
|
|
86
96
|
export declare const EvalLabelBody: z.ZodObject<{
|
|
87
97
|
label: z.ZodNullable<z.ZodEnum<{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { ModelRef } from "../agents/definition.js";
|
|
3
|
+
import { PageQueryFields, timeAsOf } from "../infra/paging/paged-read.js";
|
|
3
4
|
const NAME = z.string().trim().min(1).max(200);
|
|
4
5
|
const DESCRIPTION = z.string().max(2000);
|
|
5
6
|
const RUBRIC = z.string().min(1).max(20_000);
|
|
@@ -49,19 +50,25 @@ export const EvalRunEstimateBody = z
|
|
|
49
50
|
.strict();
|
|
50
51
|
export const EvalRunStartBody = EvalRunEstimateBody;
|
|
51
52
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
53
|
+
* A page of a run's results by page number (table pagination spec §2.3, no snapshot: every result
|
|
54
|
+
* exists from the run's start). `view=light`: no content blocks (the results table and its
|
|
55
|
+
* polling, which reads the page again); default `full`.
|
|
54
56
|
*/
|
|
55
57
|
export const EvalRunResultsQuery = z
|
|
56
58
|
.object({
|
|
57
|
-
|
|
58
|
-
limit: z.coerce.number().int().min(1).max(200).default(50),
|
|
59
|
+
...PageQueryFields,
|
|
59
60
|
view: z.enum(["full", "light"]).default("full"),
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
})
|
|
62
|
+
.strict();
|
|
63
|
+
/**
|
|
64
|
+
* `GET …/eval-sets/:setId/runs`: page numbers on a snapshot (table pagination spec §2.3). Runs are
|
|
65
|
+
* only appended and never move, newest first by `(created_at, id)`; `asOf` is the point in time of
|
|
66
|
+
* the first read, so runs started later stay out and count in `newer`.
|
|
67
|
+
*/
|
|
68
|
+
export const EvalSetRunsQuery = z
|
|
69
|
+
.object({
|
|
70
|
+
...PageQueryFields,
|
|
71
|
+
asOf: timeAsOf(),
|
|
65
72
|
})
|
|
66
73
|
.strict();
|
|
67
74
|
export const EvalLabelBody = z
|
|
@@ -98,7 +105,7 @@ export const EVAL_ROUTES = [
|
|
|
98
105
|
body: EvalRunEstimateBody,
|
|
99
106
|
},
|
|
100
107
|
{ route: `POST ${O}/eval-sets/:setId/runs`, params: EvalSetParams, body: EvalRunStartBody },
|
|
101
|
-
{ route: `GET ${O}/eval-sets/:setId/runs`, params: EvalSetParams },
|
|
108
|
+
{ route: `GET ${O}/eval-sets/:setId/runs`, params: EvalSetParams, query: EvalSetRunsQuery },
|
|
102
109
|
{ route: `GET ${O}/eval-runs/:runId`, params: EvalRunParams },
|
|
103
110
|
{ route: `GET ${O}/eval-runs/:runId/results`, params: EvalRunParams, query: EvalRunResultsQuery },
|
|
104
111
|
{ route: `GET ${O}/eval-runs/:runId/results/:resultId`, params: EvalResultParams },
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
2
|
import { type Principal } from "../identity/principal.js";
|
|
3
|
+
import type { Page, Paged } from "../infra/paging/paged-read.js";
|
|
3
4
|
import { type OrgContext } from "../orgs/org.guard.js";
|
|
4
|
-
import { EvalRunEstimateBody as EstimateBody, EvalLabelBody as LabelBody, EvalRunResultsQuery as ResultsQuery, EvalRunStartBody as StartBody } from "./evals.schemas.js";
|
|
5
|
+
import { EvalRunEstimateBody as EstimateBody, EvalLabelBody as LabelBody, EvalRunResultsQuery as ResultsQuery, EvalSetRunsQuery as SetRunsQuery, EvalRunStartBody as StartBody } from "./evals.schemas.js";
|
|
5
6
|
import { type EvalEstimate, type EvalResultLight, type EvalResultView, EvalRunsService, type EvalRunView, type EvalTokenCaps } from "./runs.service.js";
|
|
6
7
|
/**
|
|
7
8
|
* 评测运行(`/api/v1/orgs/:orgId/eval-sets/:setId/runs`、`/api/v1/orgs/:orgId/eval-runs/:runId[/results[/:resultId]]`)与
|
|
@@ -17,20 +18,11 @@ export declare class EvalRunsController {
|
|
|
17
18
|
start(principal: Principal, org: OrgContext, setId: string, body: z.infer<typeof StartBody>): Promise<{
|
|
18
19
|
run: EvalRunView;
|
|
19
20
|
}>;
|
|
20
|
-
list(principal: Principal, org: OrgContext, setId: string): Promise<
|
|
21
|
-
runs: EvalRunView[];
|
|
22
|
-
}>;
|
|
21
|
+
list(principal: Principal, org: OrgContext, setId: string, q: z.infer<typeof SetRunsQuery>): Promise<Paged<EvalRunView>>;
|
|
23
22
|
get(principal: Principal, org: OrgContext, runId: string): Promise<{
|
|
24
23
|
run: EvalRunView;
|
|
25
24
|
}>;
|
|
26
|
-
results(principal: Principal, org: OrgContext, runId: string, q: z.infer<typeof ResultsQuery>): Promise<
|
|
27
|
-
results: EvalResultView[];
|
|
28
|
-
next: string | null;
|
|
29
|
-
} | {
|
|
30
|
-
results: EvalResultLight[];
|
|
31
|
-
next: string | null;
|
|
32
|
-
asOf: string;
|
|
33
|
-
}>;
|
|
25
|
+
results(principal: Principal, org: OrgContext, runId: string, q: z.infer<typeof ResultsQuery>): Promise<Page<EvalResultView> | Page<EvalResultLight>>;
|
|
34
26
|
/** 一条结果的完整行(查看器按需读取)。 */
|
|
35
27
|
result(principal: Principal, org: OrgContext, runId: string, resultId: string): Promise<{
|
|
36
28
|
result: EvalResultView;
|
|
@@ -12,7 +12,7 @@ import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principa
|
|
|
12
12
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
13
13
|
import { ZBody, ZQuery } from "../infra/validation/zod-params.js";
|
|
14
14
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
15
|
-
import { EvalRunEstimateBody as EstimateBody, EvalLabelBody as LabelBody, EvalRunResultsQuery as ResultsQuery, EvalRunStartBody as StartBody, } from "./evals.schemas.js";
|
|
15
|
+
import { EvalRunEstimateBody as EstimateBody, EvalLabelBody as LabelBody, EvalRunResultsQuery as ResultsQuery, EvalSetRunsQuery as SetRunsQuery, EvalRunStartBody as StartBody, } from "./evals.schemas.js";
|
|
16
16
|
import { EvalRunsService, } from "./runs.service.js";
|
|
17
17
|
/** 去掉 zod 输出里值为 undefined 的键(exactOptionalPropertyTypes)。 */
|
|
18
18
|
function candidateOf(c) {
|
|
@@ -29,6 +29,8 @@ class StartBodyDto extends createZodDto(StartBody, "EvalRunStartBody") {
|
|
|
29
29
|
}
|
|
30
30
|
class ResultsQueryDto extends createZodDto(ResultsQuery, "EvalRunResultsQuery") {
|
|
31
31
|
}
|
|
32
|
+
class SetRunsQueryDto extends createZodDto(SetRunsQuery, "EvalSetRunsQuery") {
|
|
33
|
+
}
|
|
32
34
|
class LabelBodyDto extends createZodDto(LabelBody, "EvalRunLabelBody") {
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
@@ -60,9 +62,13 @@ let EvalRunsController = class EvalRunsController {
|
|
|
60
62
|
}, patTokenId(p));
|
|
61
63
|
return { run };
|
|
62
64
|
}
|
|
63
|
-
async list(principal, org, setId) {
|
|
65
|
+
async list(principal, org, setId, q) {
|
|
64
66
|
requireUser(principal);
|
|
65
|
-
return
|
|
67
|
+
return this.runs.listForSet(org.orgId, setId, {
|
|
68
|
+
page: q.page,
|
|
69
|
+
size: q.size,
|
|
70
|
+
...(q.asOf !== undefined && { asOf: q.asOf }),
|
|
71
|
+
});
|
|
66
72
|
}
|
|
67
73
|
async get(principal, org, runId) {
|
|
68
74
|
requireUser(principal);
|
|
@@ -70,14 +76,10 @@ let EvalRunsController = class EvalRunsController {
|
|
|
70
76
|
}
|
|
71
77
|
async results(principal, org, runId, q) {
|
|
72
78
|
const p = requireUser(principal);
|
|
73
|
-
const
|
|
74
|
-
limit: q.limit,
|
|
75
|
-
...(q.after !== undefined && { after: q.after }),
|
|
76
|
-
...(q.updatedSince !== undefined && { updatedSince: q.updatedSince }),
|
|
77
|
-
};
|
|
79
|
+
const page = { page: q.page, size: q.size };
|
|
78
80
|
return q.view === "light"
|
|
79
|
-
? this.runs.resultsLight(org.orgId, p.account.id, runId,
|
|
80
|
-
: this.runs.results(org.orgId, p.account.id, runId,
|
|
81
|
+
? this.runs.resultsLight(org.orgId, p.account.id, runId, page, patTokenId(p))
|
|
82
|
+
: this.runs.results(org.orgId, p.account.id, runId, page, patTokenId(p));
|
|
81
83
|
}
|
|
82
84
|
/** 一条结果的完整行(查看器按需读取)。 */
|
|
83
85
|
async result(principal, org, runId, resultId) {
|
|
@@ -119,7 +121,8 @@ __decorate([
|
|
|
119
121
|
OrgAction("evals.manage"),
|
|
120
122
|
__param(0, CurrentPrincipal()),
|
|
121
123
|
__param(1, CurrentOrg()),
|
|
122
|
-
__param(2, Param("setId"))
|
|
124
|
+
__param(2, Param("setId")),
|
|
125
|
+
__param(3, ZQuery(SetRunsQueryDto))
|
|
123
126
|
], EvalRunsController.prototype, "list", null);
|
|
124
127
|
__decorate([
|
|
125
128
|
Get("eval-runs/:runId"),
|