@capybara-hq/kernel 0.1.0-rc.6 → 0.1.0-rc.8
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/bootstrap.json +27 -3
- package/dist/admin/admin.controller.d.ts +8 -72
- package/dist/admin/admin.controller.js +21 -46
- package/dist/admin/admin.schemas.d.ts +57 -0
- package/dist/admin/admin.schemas.js +50 -0
- package/dist/admin/extensions.controller.d.ts +10 -0
- package/dist/admin/extensions.controller.js +18 -0
- package/dist/admin/extensions.schemas.d.ts +7 -0
- package/dist/admin/extensions.schemas.js +10 -0
- package/dist/admin/limit-defaults.d.ts +20 -0
- package/dist/admin/limit-defaults.js +10 -0
- package/dist/agents/agent-profile.service.d.ts +7 -5
- package/dist/agents/agent-profile.service.js +14 -9
- package/dist/agents/agents.controller.d.ts +7 -287
- package/dist/agents/agents.controller.js +7 -67
- package/dist/agents/agents.schemas.d.ts +389 -0
- package/dist/agents/agents.schemas.js +126 -0
- package/dist/agents/agents.service.d.ts +13 -5
- package/dist/agents/agents.service.js +67 -13
- package/dist/agents/definition.d.ts +47 -19
- package/dist/agents/definition.js +119 -38
- package/dist/agents/from-template.d.ts +2 -2
- package/dist/agents/from-template.js +76 -45
- package/dist/agents/from-template.service.d.ts +12 -0
- package/dist/agents/from-template.service.js +20 -3
- package/dist/agents/models.controller.d.ts +1 -2
- package/dist/agents/models.controller.js +1 -1
- package/dist/agents/org-templates.d.ts +13 -3
- package/dist/agents/org-templates.js +69 -28
- package/dist/agents/pending-connector-requests.d.ts +2 -0
- package/dist/agents/pending-connector-requests.js +1 -1
- package/dist/agents/pending-connectors.controller.d.ts +1 -1
- package/dist/agents/pending-connectors.controller.js +2 -2
- package/dist/agents/pending-connectors.service.d.ts +2 -2
- package/dist/agents/pending-connectors.service.js +19 -19
- package/dist/agents/profile.d.ts +18 -0
- package/dist/agents/profile.js +5 -1
- package/dist/agents/templates.controller.d.ts +8 -17
- package/dist/agents/templates.controller.js +13 -31
- package/dist/agents/templates.schemas.d.ts +20 -0
- package/dist/agents/templates.schemas.js +45 -0
- package/dist/background/background.controller.js +3 -2
- package/dist/background/background.schemas.d.ts +10 -0
- package/dist/background/background.schemas.js +16 -0
- package/dist/background/tasks.service.d.ts +1 -1
- package/dist/background/tasks.service.js +7 -2
- package/dist/catalog/admin-catalog.controller.d.ts +4 -57
- package/dist/catalog/admin-catalog.controller.js +8 -45
- package/dist/catalog/admin-catalog.schemas.d.ts +72 -0
- package/dist/catalog/admin-catalog.schemas.js +92 -0
- package/dist/catalog/catalog-content.d.ts +12 -2
- package/dist/catalog/catalog-scope.service.js +8 -2
- package/dist/catalog/catalog.service.d.ts +2 -0
- package/dist/catalog/catalog.service.js +3 -0
- package/dist/catalog/component-scope.controller.d.ts +3 -65
- package/dist/catalog/component-scope.controller.js +3 -56
- package/dist/catalog/component-scope.schemas.d.ts +114 -0
- package/dist/catalog/component-scope.schemas.js +97 -0
- package/dist/catalog/component-scope.service.d.ts +28 -4
- package/dist/catalog/component-scope.service.js +55 -3
- package/dist/catalog/component-state.d.ts +9 -2
- package/dist/catalog/component-state.js +22 -13
- package/dist/catalog/marketplaces.controller.d.ts +5 -35
- package/dist/catalog/marketplaces.controller.js +6 -34
- package/dist/catalog/marketplaces.schemas.d.ts +48 -0
- package/dist/catalog/marketplaces.schemas.js +53 -0
- package/dist/catalog/marketplaces.service.d.ts +15 -1
- package/dist/catalog/marketplaces.service.js +22 -1
- package/dist/catalog/org-catalog.controller.d.ts +6 -62
- package/dist/catalog/org-catalog.controller.js +12 -66
- package/dist/catalog/org-catalog.schemas.d.ts +79 -0
- package/dist/catalog/org-catalog.schemas.js +82 -0
- package/dist/catalog/org-catalog.service.d.ts +9 -2
- package/dist/catalog/org-catalog.service.js +38 -5
- package/dist/catalog/org-extension.controller.d.ts +1 -12
- package/dist/catalog/org-extension.controller.js +1 -10
- package/dist/catalog/org-extension.schemas.d.ts +15 -0
- package/dist/catalog/org-extension.schemas.js +22 -0
- package/dist/catalog/org-plugin-uploads.controller.d.ts +2 -19
- package/dist/catalog/org-plugin-uploads.controller.js +15 -28
- package/dist/catalog/org-plugin-uploads.schemas.d.ts +20 -0
- package/dist/catalog/org-plugin-uploads.schemas.js +32 -0
- package/dist/catalog/owned-items.d.ts +6 -2
- package/dist/catalog/owned-items.js +16 -4
- package/dist/catalog/platform-components.d.ts +2 -0
- package/dist/catalog/platform-components.js +2 -0
- package/dist/catalog/plugin-import.js +1 -0
- package/dist/catalog/plugin-install.js +1 -1
- package/dist/catalog/requests.service.d.ts +2 -1
- package/dist/catalog/requests.service.js +6 -2
- package/dist/channels/channels.schemas.d.ts +33 -0
- package/dist/channels/channels.schemas.js +34 -0
- package/dist/channels/connections.controller.d.ts +2 -29
- package/dist/channels/connections.controller.js +1 -23
- package/dist/channels/connections.service.d.ts +8 -2
- package/dist/channels/connections.service.js +23 -5
- package/dist/channels/inbound.js +4 -0
- package/dist/conversations/conversations.controller.d.ts +16 -37
- package/dist/conversations/conversations.controller.js +16 -56
- package/dist/conversations/conversations.schemas.d.ts +52 -0
- package/dist/conversations/conversations.schemas.js +79 -0
- package/dist/conversations/conversations.service.d.ts +9 -1
- package/dist/conversations/conversations.service.js +23 -18
- package/dist/conversations/events.d.ts +80 -6
- package/dist/conversations/events.js +60 -5
- package/dist/conversations/message-context.d.ts +28 -0
- package/dist/conversations/message-context.js +56 -0
- package/dist/conversations/queue.d.ts +2 -1
- package/dist/conversations/queue.js +11 -2
- package/dist/db/kernel-schema.d.ts +20 -0
- package/dist/environments/environments.schemas.d.ts +3 -0
- package/dist/environments/environments.schemas.js +14 -0
- package/dist/environments/environments.service.d.ts +16 -4
- package/dist/environments/environments.service.js +58 -13
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +3 -0
- package/dist/evals/evals.schemas.d.ts +110 -0
- package/dist/evals/evals.schemas.js +107 -0
- package/dist/evals/reconstruct.js +18 -11
- package/dist/evals/recorded-tools.d.ts +2 -1
- package/dist/evals/recorded-tools.js +11 -3
- package/dist/evals/run-replay.d.ts +8 -1
- package/dist/evals/run-replay.js +13 -0
- package/dist/evals/runs.controller.d.ts +2 -57
- package/dist/evals/runs.controller.js +1 -42
- package/dist/evals/runs.service.d.ts +6 -6
- package/dist/evals/runs.service.js +32 -18
- package/dist/evals/sets.controller.d.ts +2 -28
- package/dist/evals/sets.controller.js +1 -31
- package/dist/evals/sets.service.d.ts +7 -7
- package/dist/evals/sets.service.js +23 -17
- package/dist/evals/snapshot.d.ts +3 -2
- package/dist/evals/snapshot.js +17 -4
- package/dist/extensions/admin-ops.d.ts +5 -3
- package/dist/extensions/admin-ops.js +17 -12
- package/dist/extensions/deployment-config.d.ts +16 -1
- package/dist/extensions/deployment-config.js +83 -0
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +33 -2
- package/dist/extensions/host.js +107 -1
- package/dist/extensions/installs.d.ts +5 -0
- package/dist/extensions/installs.js +12 -0
- package/dist/extensions/org-config.d.ts +17 -2
- package/dist/extensions/org-config.js +23 -4
- package/dist/extensions/point-defaults.controller.d.ts +2 -8
- package/dist/extensions/point-defaults.controller.js +1 -3
- package/dist/extensions/point-defaults.d.ts +3 -1
- package/dist/extensions/point-defaults.js +4 -2
- package/dist/extensions/point-defaults.schemas.d.ts +9 -0
- package/dist/extensions/point-defaults.schemas.js +14 -0
- package/dist/extensions/unavailable.d.ts +49 -0
- package/dist/extensions/unavailable.js +113 -0
- package/dist/files/previewers.controller.js +2 -3
- package/dist/files/previewers.d.ts +1 -1
- package/dist/files/previewers.js +4 -4
- package/dist/files/previewers.schemas.d.ts +10 -0
- package/dist/files/previewers.schemas.js +9 -0
- package/dist/http/api.module.js +2 -0
- package/dist/identity/accounts.d.ts +43 -4
- package/dist/identity/accounts.js +74 -6
- package/dist/identity/auth.guard.js +10 -1
- package/dist/identity/cookies.d.ts +6 -0
- package/dist/identity/cookies.js +14 -0
- package/dist/identity/identity.module.js +3 -0
- package/dist/identity/initial-passwords.controller.d.ts +22 -0
- package/dist/identity/initial-passwords.controller.js +49 -0
- package/dist/identity/initial-passwords.d.ts +61 -0
- package/dist/identity/initial-passwords.job.d.ts +16 -0
- package/dist/identity/initial-passwords.job.js +46 -0
- package/dist/identity/initial-passwords.js +159 -0
- package/dist/identity/me.controller.d.ts +12 -0
- package/dist/identity/me.controller.js +31 -1
- package/dist/identity/me.schemas.d.ts +14 -0
- package/dist/identity/me.schemas.js +17 -0
- package/dist/identity/principal.d.ts +8 -0
- package/dist/identity/principal.js +8 -0
- package/dist/identity/settings.d.ts +3 -1
- package/dist/identity/settings.js +6 -4
- package/dist/inbox/inbox.schemas.d.ts +8 -0
- package/dist/inbox/inbox.schemas.js +11 -0
- package/dist/inbox/platform-inbox.controller.d.ts +1 -1
- package/dist/inbox/platform-inbox.controller.js +2 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +6 -0
- package/dist/lifecycle/kernel-lifecycle.js +4 -0
- package/dist/models/enablement.d.ts +2 -0
- package/dist/models/enablement.js +1 -0
- package/dist/models/org-models.schemas.d.ts +8 -0
- package/dist/models/org-models.schemas.js +22 -0
- package/dist/models/prices.d.ts +3 -1
- package/dist/models/prices.js +7 -5
- package/dist/models/purposes.d.ts +12 -2
- package/dist/models/purposes.js +22 -8
- package/dist/orgs/orgs.controller.d.ts +2 -5
- package/dist/orgs/orgs.controller.js +3 -6
- package/dist/orgs/orgs.schemas.d.ts +8 -0
- package/dist/orgs/orgs.schemas.js +16 -0
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +6 -4
- package/dist/orgs/settings.service.d.ts +9 -1
- package/dist/orgs/settings.service.js +20 -5
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/errors.d.ts +21 -4
- package/dist/platform/errors.js +45 -6
- package/dist/platform/exclusions.d.ts +2 -3
- package/dist/platform/exclusions.js +58 -849
- package/dist/platform/method.js +1 -1
- package/dist/platform/operation.d.ts +82 -5
- package/dist/platform/operation.js +63 -8
- package/dist/platform/ops/accounts.ops.d.ts +32 -0
- package/dist/platform/ops/accounts.ops.js +291 -0
- package/dist/platform/ops/admin.ops.d.ts +36 -0
- package/dist/platform/ops/admin.ops.js +389 -0
- package/dist/platform/ops/agent-skills.ops.d.ts +24 -0
- package/dist/platform/ops/agent-skills.ops.js +226 -0
- package/dist/platform/ops/agent-templates.ops.d.ts +4 -1
- package/dist/platform/ops/agent-templates.ops.js +194 -14
- package/dist/platform/ops/agents.ops.d.ts +19 -1
- package/dist/platform/ops/agents.ops.js +481 -58
- package/dist/platform/ops/approvals.ops.d.ts +30 -0
- package/dist/platform/ops/approvals.ops.js +116 -0
- package/dist/platform/ops/background.ops.d.ts +14 -0
- package/dist/platform/ops/background.ops.js +134 -0
- package/dist/platform/ops/catalog-admin.ops.d.ts +74 -0
- package/dist/platform/ops/catalog-admin.ops.js +587 -0
- package/dist/platform/ops/channels.ops.d.ts +16 -0
- package/dist/platform/ops/channels.ops.js +195 -0
- package/dist/platform/ops/components.ops.d.ts +46 -0
- package/dist/platform/ops/components.ops.js +853 -0
- package/dist/platform/ops/connectors.ops.d.ts +4 -2
- package/dist/platform/ops/connectors.ops.js +68 -6
- package/dist/platform/ops/conversations.ops.d.ts +30 -0
- package/dist/platform/ops/conversations.ops.js +470 -0
- package/dist/platform/ops/environments.ops.d.ts +26 -0
- package/dist/platform/ops/environments.ops.js +289 -0
- package/dist/platform/ops/errors.d.ts +10 -5
- package/dist/platform/ops/errors.js +19 -11
- package/dist/platform/ops/evals.ops.d.ts +28 -0
- package/dist/platform/ops/evals.ops.js +783 -0
- package/dist/platform/ops/extensions-admin.ops.d.ts +25 -0
- package/dist/platform/ops/extensions-admin.ops.js +344 -0
- package/dist/platform/ops/extensions.ops.d.ts +7 -1
- package/dist/platform/ops/extensions.ops.js +248 -17
- package/dist/platform/ops/inbox.ops.d.ts +25 -0
- package/dist/platform/ops/inbox.ops.js +378 -0
- package/dist/platform/ops/marketplaces.ops.d.ts +7 -1
- package/dist/platform/ops/marketplaces.ops.js +326 -17
- package/dist/platform/ops/models.ops.d.ts +25 -0
- package/dist/platform/ops/models.ops.js +232 -0
- package/dist/platform/ops/org-plugins.ops.d.ts +29 -0
- package/dist/platform/ops/org-plugins.ops.js +329 -0
- package/dist/platform/ops/org-settings.ops.d.ts +16 -0
- package/dist/platform/ops/org-settings.ops.js +102 -0
- package/dist/platform/ops/orgs.ops.d.ts +28 -0
- package/dist/platform/ops/orgs.ops.js +295 -0
- package/dist/platform/ops/other-orgs.d.ts +20 -0
- package/dist/platform/ops/other-orgs.js +72 -0
- package/dist/platform/ops/platform.ops.d.ts +11 -6
- package/dist/platform/ops/platform.ops.js +73 -27
- package/dist/platform/ops/plugins.ops.d.ts +10 -8
- package/dist/platform/ops/plugins.ops.js +176 -77
- package/dist/platform/ops/previewers.ops.d.ts +14 -0
- package/dist/platform/ops/previewers.ops.js +109 -0
- package/dist/platform/ops/requests.ops.js +57 -19
- package/dist/platform/ops/skills.ops.d.ts +5 -1
- package/dist/platform/ops/skills.ops.js +129 -11
- package/dist/platform/ops/unavailable.d.ts +23 -0
- package/dist/platform/ops/unavailable.js +111 -0
- package/dist/platform/parity.d.ts +33 -0
- package/dist/platform/parity.js +272 -0
- package/dist/platform/platform-ops.module.d.ts +32 -0
- package/dist/platform/platform-ops.module.js +78 -11
- package/dist/platform/route-schemas.d.ts +18 -0
- package/dist/platform/route-schemas.js +63 -0
- package/dist/roles/worker.module.js +2 -0
- package/dist/runtime/context/build.d.ts +2 -0
- package/dist/runtime/context/build.js +28 -2
- package/dist/runtime/context/compaction.js +10 -1
- package/dist/runtime/context/run-context.d.ts +65 -0
- package/dist/runtime/context/run-context.js +215 -0
- package/dist/runtime/model-call.js +2 -1
- package/dist/runtime/providers.js +8 -1
- package/dist/runtime/run-context.service.d.ts +65 -0
- package/dist/runtime/run-context.service.js +220 -0
- package/dist/runtime/run-worker.d.ts +5 -0
- package/dist/runtime/run-worker.js +31 -6
- package/dist/runtime/runtime.module.js +2 -0
- package/dist/runtime/subagents/definition.d.ts +15 -15
- package/dist/runtime/subagents/definition.js +46 -115
- package/dist/skills/changes.controller.js +2 -1
- package/dist/skills/changes.service.d.ts +1 -1
- package/dist/skills/changes.service.js +4 -4
- package/dist/skills/invocable.controller.d.ts +1 -1
- package/dist/skills/invocable.controller.js +2 -2
- package/dist/skills/invoke.d.ts +2 -2
- package/dist/skills/invoke.js +8 -1
- package/dist/skills/skills.controller.d.ts +4 -13
- package/dist/skills/skills.controller.js +8 -24
- package/dist/skills/skills.schemas.d.ts +48 -0
- package/dist/skills/skills.schemas.js +61 -0
- package/dist/skills/skills.service.d.ts +11 -1
- package/dist/skills/skills.service.js +37 -14
- package/dist/time-zone.d.ts +5 -0
- package/dist/time-zone.js +19 -0
- package/dist/tools/approvals.controller.js +2 -3
- package/dist/tools/approvals.schemas.d.ts +21 -0
- package/dist/tools/approvals.schemas.js +15 -0
- package/dist/tools/builtin-names.d.ts +10 -8
- package/dist/tools/builtin-names.js +16 -11
- package/dist/tools/builtins/builtin-tools.d.ts +3 -1
- package/dist/tools/builtins/builtin-tools.js +15 -3
- package/dist/tools/builtins/current-time.d.ts +26 -0
- package/dist/tools/builtins/current-time.js +99 -0
- package/dist/tools/builtins/platform.d.ts +19 -2
- package/dist/tools/builtins/platform.js +105 -16
- package/dist/tools/connectors.controller.d.ts +1 -2
- package/dist/tools/connectors.controller.js +1 -4
- package/dist/tools/connectors.schemas.d.ts +12 -0
- package/dist/tools/connectors.schemas.js +19 -0
- package/dist/tools/connectors.service.d.ts +5 -2
- package/dist/tools/connectors.service.js +7 -5
- package/dist/tools/org-tool-switches.d.ts +16 -2
- package/dist/tools/org-tool-switches.js +26 -9
- package/dist/tools/pipeline.js +3 -1
- package/dist/tools/registry.d.ts +48 -51
- package/dist/tools/registry.js +222 -233
- package/package.json +3 -3
- package/src/migrations/0090_initial_passwords.sql +27 -0
- package/src/migrations/0091_account_time_zone.sql +4 -0
- package/src/migrations/0092_tools_default_on.sql +27 -0
- package/dist/platform/redact-orgs.d.ts +0 -7
- package/dist/platform/redact-orgs.js +0 -52
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ModelRef } from "../agents/definition.js";
|
|
3
|
+
const NAME = z.string().trim().min(1).max(200);
|
|
4
|
+
const DESCRIPTION = z.string().max(2000);
|
|
5
|
+
const RUBRIC = z.string().min(1).max(20_000);
|
|
6
|
+
export const EvalSetCreateBody = z
|
|
7
|
+
.object({
|
|
8
|
+
agentId: z.string().min(1).max(100),
|
|
9
|
+
name: NAME,
|
|
10
|
+
description: DESCRIPTION.optional(),
|
|
11
|
+
rubric: RUBRIC.optional(),
|
|
12
|
+
})
|
|
13
|
+
.strict();
|
|
14
|
+
export const EvalSetPatchBody = z
|
|
15
|
+
.object({
|
|
16
|
+
name: NAME.optional(),
|
|
17
|
+
description: DESCRIPTION.optional(),
|
|
18
|
+
rubric: RUBRIC.nullable().optional(),
|
|
19
|
+
})
|
|
20
|
+
.strict();
|
|
21
|
+
export const EvalAddCaseBody = z
|
|
22
|
+
.object({ conversationId: z.string().min(1).max(100), runId: z.string().min(1).max(100) })
|
|
23
|
+
.strict();
|
|
24
|
+
export const EvalSampleBody = z
|
|
25
|
+
.object({
|
|
26
|
+
from: z.iso.datetime({ offset: true }).optional(),
|
|
27
|
+
to: z.iso.datetime({ offset: true }).optional(),
|
|
28
|
+
count: z.number().int().min(1).max(50),
|
|
29
|
+
status: z.enum(["completed", "failed", "any"]).optional(),
|
|
30
|
+
minToolCalls: z.number().int().min(0).max(1000).optional(),
|
|
31
|
+
})
|
|
32
|
+
.strict();
|
|
33
|
+
export const EvalCandidateSchema = z
|
|
34
|
+
.object({
|
|
35
|
+
agentVersion: z.number().int().min(1).optional(),
|
|
36
|
+
model: ModelRef.strict().optional(),
|
|
37
|
+
modelParams: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
38
|
+
instructions: z.string().max(100_000).optional(),
|
|
39
|
+
})
|
|
40
|
+
.strict();
|
|
41
|
+
/** `tokenCap` is only type-checked here; the service judges the range (`eval.token_cap_invalid`). */
|
|
42
|
+
export const EvalRunEstimateBody = z
|
|
43
|
+
.object({
|
|
44
|
+
mode: z.enum(["step", "run"]),
|
|
45
|
+
candidate: EvalCandidateSchema,
|
|
46
|
+
judge: z.boolean().default(false),
|
|
47
|
+
tokenCap: z.number().int().optional(),
|
|
48
|
+
})
|
|
49
|
+
.strict();
|
|
50
|
+
export const EvalRunStartBody = EvalRunEstimateBody;
|
|
51
|
+
/**
|
|
52
|
+
* `view=light`: no content blocks (result tables and polling; the response carries `asOf`);
|
|
53
|
+
* default `full`. `updatedSince` (ISO time) takes only what changed after it.
|
|
54
|
+
*/
|
|
55
|
+
export const EvalRunResultsQuery = z
|
|
56
|
+
.object({
|
|
57
|
+
after: z.string().max(100).optional(),
|
|
58
|
+
limit: z.coerce.number().int().min(1).max(200).default(50),
|
|
59
|
+
view: z.enum(["full", "light"]).default("full"),
|
|
60
|
+
updatedSince: z
|
|
61
|
+
.string()
|
|
62
|
+
.max(64)
|
|
63
|
+
.refine((v) => !Number.isNaN(Date.parse(v)), { message: "must be an ISO timestamp" })
|
|
64
|
+
.optional(),
|
|
65
|
+
})
|
|
66
|
+
.strict();
|
|
67
|
+
export const EvalLabelBody = z
|
|
68
|
+
.object({
|
|
69
|
+
label: z.enum(["pass", "fail"]).nullable(),
|
|
70
|
+
note: z.string().max(2000).optional(),
|
|
71
|
+
})
|
|
72
|
+
.strict();
|
|
73
|
+
/** The path params the eval routes read (`@Param`), bounded as the operations take them. */
|
|
74
|
+
const Id = z.string().min(1).max(100);
|
|
75
|
+
export const EvalSetParams = z.object({ setId: Id });
|
|
76
|
+
export const EvalCaseParams = z.object({ setId: Id, caseId: Id });
|
|
77
|
+
export const EvalRunParams = z.object({ runId: Id });
|
|
78
|
+
export const EvalResultParams = z.object({ runId: Id, resultId: Id });
|
|
79
|
+
export const EvalLabelParams = z.object({ resultId: Id });
|
|
80
|
+
const O = "/api/v1/orgs/:orgId";
|
|
81
|
+
export const EVAL_ROUTES = [
|
|
82
|
+
{ route: `POST ${O}/eval-sets`, body: EvalSetCreateBody },
|
|
83
|
+
{ route: `GET ${O}/eval-sets` },
|
|
84
|
+
{ route: `GET ${O}/eval-sets/:setId`, params: EvalSetParams },
|
|
85
|
+
{ route: `PATCH ${O}/eval-sets/:setId`, params: EvalSetParams, body: EvalSetPatchBody },
|
|
86
|
+
{ route: `DELETE ${O}/eval-sets/:setId`, params: EvalSetParams },
|
|
87
|
+
{ route: `POST ${O}/eval-sets/:setId/cases`, params: EvalSetParams, body: EvalAddCaseBody },
|
|
88
|
+
{
|
|
89
|
+
route: `POST ${O}/eval-sets/:setId/cases/sample`,
|
|
90
|
+
params: EvalSetParams,
|
|
91
|
+
body: EvalSampleBody,
|
|
92
|
+
},
|
|
93
|
+
{ route: `GET ${O}/eval-sets/:setId/cases/:caseId`, params: EvalCaseParams },
|
|
94
|
+
{ route: `DELETE ${O}/eval-sets/:setId/cases/:caseId`, params: EvalCaseParams },
|
|
95
|
+
{
|
|
96
|
+
route: `POST ${O}/eval-sets/:setId/runs/estimate`,
|
|
97
|
+
params: EvalSetParams,
|
|
98
|
+
body: EvalRunEstimateBody,
|
|
99
|
+
},
|
|
100
|
+
{ route: `POST ${O}/eval-sets/:setId/runs`, params: EvalSetParams, body: EvalRunStartBody },
|
|
101
|
+
{ route: `GET ${O}/eval-sets/:setId/runs`, params: EvalSetParams },
|
|
102
|
+
{ route: `GET ${O}/eval-runs/:runId`, params: EvalRunParams },
|
|
103
|
+
{ route: `GET ${O}/eval-runs/:runId/results`, params: EvalRunParams, query: EvalRunResultsQuery },
|
|
104
|
+
{ route: `GET ${O}/eval-runs/:runId/results/:resultId`, params: EvalResultParams },
|
|
105
|
+
{ route: `POST ${O}/eval-runs/:runId/cancel`, params: EvalRunParams },
|
|
106
|
+
{ route: `PUT ${O}/eval-results/:resultId/label`, params: EvalLabelParams, body: EvalLabelBody },
|
|
107
|
+
];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sanitizeParams, } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import { AgentDefinitionSchema, normalizeStoredDefinition, } from "../agents/definition.js";
|
|
2
|
+
import { AgentDefinitionSchema, builtinDisabled, canonicalDisabledTools, normalizeStoredDefinition, } from "../agents/definition.js";
|
|
3
3
|
import { sameModel, selectionAt } from "../conversations/selection.js";
|
|
4
4
|
import { ApiError } from "../errors.js";
|
|
5
5
|
import { mediaRefs, planMedia, } from "../runtime/context/build.js";
|
|
@@ -217,18 +217,25 @@ const sameTemplate = (logged, t) => logged.source !== "plugin" ||
|
|
|
217
217
|
(logged.platformTemplateId ?? null) === (t.platformTemplateId ?? null));
|
|
218
218
|
const pinsOf = (d) => [...new Set(d.skills?.pinned ?? [])].slice(0, PINNED_SKILLS_LIMITS.count);
|
|
219
219
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
220
|
+
* A sub-agent's tools without template narrowing (general and org agents), as compared: its
|
|
221
|
+
* turned-off tools (tools default-on spec §4) and its key filter's allowlist and `deny` keys,
|
|
222
|
+
* {@link CHILD_REMOVED_TOOLS} left out. `Agent` depends on the child's depth, not on the
|
|
223
|
+
* definition (agent map spec §4.1): a `deny` of it never counts, and a turned-off `Agent` counts
|
|
224
|
+
* only when the logged child had it (`keepAgent`), so a child logged without it (at the depth
|
|
225
|
+
* limit, or before nesting) compares equal to a candidate that offers it.
|
|
224
226
|
*/
|
|
225
|
-
const childToolsOf = (d, keepAgent) => canonicalJson(
|
|
226
|
-
(
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
const childToolsOf = (d, keepAgent) => canonicalJson({
|
|
228
|
+
disabled: canonicalDisabledTools((d.disabledTools ?? []).filter((r) => keepAgent || r.kind !== "builtin" || r.name !== AGENT_TOOL)),
|
|
229
|
+
allow: d.subagentTools?.allow ?? null,
|
|
230
|
+
deny: (d.subagentTools?.deny ?? []).filter((k) => !CHILD_REMOVED_TOOLS.includes(k) && k !== AGENT_TOOL),
|
|
231
|
+
});
|
|
232
|
+
/** Does the child have `Agent` by its definition (not turned off, not removed by its filter)? */
|
|
233
|
+
const hasAgent = (d) => !builtinDisabled(d.disabledTools, AGENT_TOOL) &&
|
|
234
|
+
!(d.subagentTools?.deny ?? []).includes(AGENT_TOOL) &&
|
|
235
|
+
(d.subagentTools?.allow === undefined || d.subagentTools.allow.includes(AGENT_TOOL));
|
|
229
236
|
/** The parent's selection a template child depends on: its tools, org skills and roster entry. */
|
|
230
237
|
const parentSide = (d, started) => canonicalJson({
|
|
231
|
-
|
|
238
|
+
disabledTools: canonicalDisabledTools(d.disabledTools ?? []),
|
|
232
239
|
orgSkills: d.skills?.orgSkills ?? [],
|
|
233
240
|
listed: started.template.source === "general"
|
|
234
241
|
? d.subagents?.general !== false
|
|
@@ -264,7 +271,7 @@ original) {
|
|
|
264
271
|
(pinned !== null && canonicalJson(pinned) !== canonicalJson(pinsOf(logged))) ||
|
|
265
272
|
(tools !== null && tools !== childTools(logged));
|
|
266
273
|
if (sameVersion) {
|
|
267
|
-
return differs(candidate.instructions, pinsOf(candidate),
|
|
274
|
+
return differs(candidate.instructions, pinsOf(candidate), childTools(candidate));
|
|
268
275
|
}
|
|
269
276
|
switch (started.template.source) {
|
|
270
277
|
case "agent":
|
|
@@ -31,7 +31,8 @@ export interface RecordedCall {
|
|
|
31
31
|
* - a connector: the tool definition the key was recorded with (`toolSpecs`, found by the specHash of
|
|
32
32
|
* its `tool_call_started` or its `model_call` tools / catalog entry) has `connectorData`;
|
|
33
33
|
* - an extension: that definition exists without `connectorData` and its name is the key's tool
|
|
34
|
-
* part, or an agent definition names exactly that tool as a `{ kind: "plugin", plugin: x, name }`
|
|
34
|
+
* part, or an rc-era agent definition names exactly that tool as a `{ kind: "plugin", plugin: x, name }`
|
|
35
|
+
* ref.
|
|
35
36
|
*/
|
|
36
37
|
export declare function legacyScopeOf(s: CaseSnapshot): LegacyScope;
|
|
37
38
|
/**
|
|
@@ -16,7 +16,8 @@ export const REPLAY_NO_RECORDING = "[replay] No recorded result matches this too
|
|
|
16
16
|
* - a connector: the tool definition the key was recorded with (`toolSpecs`, found by the specHash of
|
|
17
17
|
* its `tool_call_started` or its `model_call` tools / catalog entry) has `connectorData`;
|
|
18
18
|
* - an extension: that definition exists without `connectorData` and its name is the key's tool
|
|
19
|
-
* part, or an agent definition names exactly that tool as a `{ kind: "plugin", plugin: x, name }`
|
|
19
|
+
* part, or an rc-era agent definition names exactly that tool as a `{ kind: "plugin", plugin: x, name }`
|
|
20
|
+
* ref.
|
|
20
21
|
*/
|
|
21
22
|
export function legacyScopeOf(s) {
|
|
22
23
|
const hashes = new Map();
|
|
@@ -42,10 +43,17 @@ export function legacyScopeOf(s) {
|
|
|
42
43
|
const extensionNames = new Set();
|
|
43
44
|
const connectorSlugs = new Set();
|
|
44
45
|
const planted = new Set();
|
|
46
|
+
// rc-era snapshots hold definitions from before tools were on by default: an enabled `tools`
|
|
47
|
+
// list of refs (tools default-on spec §2)
|
|
45
48
|
for (const def of Object.values(s.definitions)) {
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
const refs = def.tools;
|
|
50
|
+
if (!Array.isArray(refs))
|
|
51
|
+
continue;
|
|
52
|
+
for (const t of refs) {
|
|
53
|
+
if (t?.kind === "plugin" && typeof t.plugin === "string" && typeof t.name === "string") {
|
|
48
54
|
planted.add(`${t.plugin}__${t.name}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
for (const [key, set] of hashes) {
|
|
51
59
|
const i = key.indexOf("__");
|
|
@@ -18,7 +18,7 @@ import type { ResolvedCandidate } from "./step-replay.js";
|
|
|
18
18
|
* {@link RecordedToolPipeline}(只回放记录的结果,不执行任何工具、沙箱、连接器或审批)。
|
|
19
19
|
*
|
|
20
20
|
* - 种子:原运行 `run_started` 之前的事件按原 seq 插入(`last_seq` 停在其前一位,新的 `run_started` 因此与原来同 seq),
|
|
21
|
-
* 原运行开始时的 `skills_catalog` 照抄;然后写 `runs` 行与 `run_started`,`agent` 用候选定义。
|
|
21
|
+
* 原运行开始时的 `skills_catalog` 与 `run_context` 照抄;然后写 `runs` 行与 `run_started`,`agent` 用候选定义。
|
|
22
22
|
* - 插话:原运行中途吸收的可吸收事件(user_message, and finished background tasks: background Bash
|
|
23
23
|
* spec §4.4),在「原吸收步骤 ≤ 当前步骤」时追加进评测对话并交给 loop(a recorded finish is
|
|
24
24
|
* appended as recorded: no task starts, polls or stops; likewise a sub-agent's delivery, agent map
|
|
@@ -114,6 +114,13 @@ export interface ReplaySeed {
|
|
|
114
114
|
catalog: {
|
|
115
115
|
payload: unknown;
|
|
116
116
|
} | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* The original run's `run_context` event (run context spec §8), copied as is: a candidate sees
|
|
119
|
+
* the original date, names and org, never the eval day's.
|
|
120
|
+
*/
|
|
121
|
+
runContext: {
|
|
122
|
+
payload: unknown;
|
|
123
|
+
} | undefined;
|
|
117
124
|
}
|
|
118
125
|
/**
|
|
119
126
|
* The seed of a full-run replay (C6): the `kind = 'eval'` conversation with the events before the
|
package/dist/evals/run-replay.js
CHANGED
|
@@ -20,6 +20,7 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
|
20
20
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
21
21
|
import { estimateTokens } from "../runtime/context/tokens.js";
|
|
22
22
|
import { RunError } from "../runtime/model-call.js";
|
|
23
|
+
import { runContextIdemKey } from "../runtime/run-context.service.js";
|
|
23
24
|
import { recordedSkillForks } from "../runtime/subagents/skill-fork.js";
|
|
24
25
|
import { skillsCatalogIdemKey } from "../skills/catalog.js";
|
|
25
26
|
import { ACTIVE_EVAL_STATUSES, addUsage, consumeTokens, TOO_MANY_ERRORS, usageTokens, } from "./budget.js";
|
|
@@ -121,6 +122,16 @@ let EvalReplaySeeder = class EvalReplaySeeder {
|
|
|
121
122
|
},
|
|
122
123
|
]
|
|
123
124
|
: []),
|
|
125
|
+
...(p.runContext
|
|
126
|
+
? [
|
|
127
|
+
{
|
|
128
|
+
type: "run_context",
|
|
129
|
+
runId,
|
|
130
|
+
idemKey: runContextIdemKey(runId),
|
|
131
|
+
payload: p.runContext.payload,
|
|
132
|
+
},
|
|
133
|
+
]
|
|
134
|
+
: []),
|
|
124
135
|
]);
|
|
125
136
|
if (onSeeded && !(await onSeeded(conversationId)))
|
|
126
137
|
throw new ReplayClaimLost();
|
|
@@ -320,6 +331,7 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
|
|
|
320
331
|
}
|
|
321
332
|
const trigger = replayTrigger(start.payload, seeds, consumed);
|
|
322
333
|
const catalog = s.events.find((e) => e.runId === s.runId && e.type === "skills_catalog" && e.seq > R);
|
|
334
|
+
const runContext = s.events.find((e) => e.runId === s.runId && e.type === "run_context" && e.seq > R);
|
|
323
335
|
// a sub-agent's case (spec §15.3) runs the effective definition frozen in its subagent_started
|
|
324
336
|
// (the request renders that event's preamble and instructions; its tools come from it too), with
|
|
325
337
|
// only the candidate's model and params, and the logged step limit
|
|
@@ -351,6 +363,7 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
|
|
|
351
363
|
agentVersion: candidate.agentVersion,
|
|
352
364
|
model: agent.model,
|
|
353
365
|
catalog,
|
|
366
|
+
runContext,
|
|
354
367
|
}, d.onSeeded);
|
|
355
368
|
await d.hooks?.afterRunSeeded?.(evalRunId, conversationId);
|
|
356
369
|
// 停止:取消 / 越限 / 熔断 / 失去认领 / 截止时间 → 中止 loop(进行中的请求立即停下,loop 以 aborted 返回)
|
|
@@ -1,62 +1,8 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
1
|
+
import type { z } from "zod";
|
|
2
2
|
import { type Principal } from "../identity/principal.js";
|
|
3
3
|
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";
|
|
4
5
|
import { type EvalEstimate, type EvalResultLight, type EvalResultView, EvalRunsService, type EvalRunView, type EvalTokenCaps } from "./runs.service.js";
|
|
5
|
-
/** `tokenCap` 只校验类型,范围由服务判定(`eval.token_cap_invalid`)。 */
|
|
6
|
-
declare const EstimateBody: z.ZodObject<{
|
|
7
|
-
mode: z.ZodEnum<{
|
|
8
|
-
run: "run";
|
|
9
|
-
step: "step";
|
|
10
|
-
}>;
|
|
11
|
-
candidate: z.ZodObject<{
|
|
12
|
-
agentVersion: z.ZodOptional<z.ZodNumber>;
|
|
13
|
-
model: z.ZodOptional<z.ZodObject<{
|
|
14
|
-
provider: z.ZodString;
|
|
15
|
-
model: z.ZodString;
|
|
16
|
-
}, z.core.$strict>>;
|
|
17
|
-
modelParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
18
|
-
instructions: z.ZodOptional<z.ZodString>;
|
|
19
|
-
}, z.core.$strict>;
|
|
20
|
-
judge: z.ZodDefault<z.ZodBoolean>;
|
|
21
|
-
tokenCap: z.ZodOptional<z.ZodNumber>;
|
|
22
|
-
}, z.core.$strict>;
|
|
23
|
-
declare const StartBody: z.ZodObject<{
|
|
24
|
-
mode: z.ZodEnum<{
|
|
25
|
-
run: "run";
|
|
26
|
-
step: "step";
|
|
27
|
-
}>;
|
|
28
|
-
candidate: z.ZodObject<{
|
|
29
|
-
agentVersion: z.ZodOptional<z.ZodNumber>;
|
|
30
|
-
model: z.ZodOptional<z.ZodObject<{
|
|
31
|
-
provider: z.ZodString;
|
|
32
|
-
model: z.ZodString;
|
|
33
|
-
}, z.core.$strict>>;
|
|
34
|
-
modelParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
35
|
-
instructions: z.ZodOptional<z.ZodString>;
|
|
36
|
-
}, z.core.$strict>;
|
|
37
|
-
judge: z.ZodDefault<z.ZodBoolean>;
|
|
38
|
-
tokenCap: z.ZodOptional<z.ZodNumber>;
|
|
39
|
-
}, z.core.$strict>;
|
|
40
|
-
/**
|
|
41
|
-
* `view=light`:不含内容块(结果表与轮询用,响应带 `asOf`);缺省 `full`。`updatedSince`(ISO 时间)只取之后有变化的,
|
|
42
|
-
* 轮询时传上一次的 `asOf`。
|
|
43
|
-
*/
|
|
44
|
-
declare const ResultsQuery: z.ZodObject<{
|
|
45
|
-
after: z.ZodOptional<z.ZodString>;
|
|
46
|
-
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
47
|
-
view: z.ZodDefault<z.ZodEnum<{
|
|
48
|
-
full: "full";
|
|
49
|
-
light: "light";
|
|
50
|
-
}>>;
|
|
51
|
-
updatedSince: z.ZodOptional<z.ZodString>;
|
|
52
|
-
}, z.core.$strict>;
|
|
53
|
-
declare const LabelBody: z.ZodObject<{
|
|
54
|
-
label: z.ZodNullable<z.ZodEnum<{
|
|
55
|
-
fail: "fail";
|
|
56
|
-
pass: "pass";
|
|
57
|
-
}>>;
|
|
58
|
-
note: z.ZodOptional<z.ZodString>;
|
|
59
|
-
}, z.core.$strict>;
|
|
60
6
|
/**
|
|
61
7
|
* 评测运行(`/api/v1/orgs/:orgId/eval-sets/:setId/runs`、`/api/v1/orgs/:orgId/eval-runs/:runId[/results[/:resultId]]`)与
|
|
62
8
|
* 结果的人工标注(`/api/v1/orgs/:orgId/eval-results/:resultId/label`):
|
|
@@ -97,4 +43,3 @@ export declare class EvalRunsController {
|
|
|
97
43
|
result: EvalResultView;
|
|
98
44
|
}>;
|
|
99
45
|
}
|
|
100
|
-
export {};
|
|
@@ -8,53 +8,12 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { Controller, Get, HttpCode, Inject, Param, Post, Put } from "@nestjs/common";
|
|
11
|
-
import { z } from "zod";
|
|
12
|
-
import { ModelRef } from "../agents/definition.js";
|
|
13
11
|
import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principal.js";
|
|
14
12
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
15
13
|
import { ZBody, ZQuery } from "../infra/validation/zod-params.js";
|
|
16
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";
|
|
17
16
|
import { EvalRunsService, } from "./runs.service.js";
|
|
18
|
-
const Candidate = z
|
|
19
|
-
.object({
|
|
20
|
-
agentVersion: z.number().int().min(1).optional(),
|
|
21
|
-
model: ModelRef.strict().optional(),
|
|
22
|
-
modelParams: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
23
|
-
instructions: z.string().max(100_000).optional(),
|
|
24
|
-
})
|
|
25
|
-
.strict();
|
|
26
|
-
/** `tokenCap` 只校验类型,范围由服务判定(`eval.token_cap_invalid`)。 */
|
|
27
|
-
const EstimateBody = z
|
|
28
|
-
.object({
|
|
29
|
-
mode: z.enum(["step", "run"]),
|
|
30
|
-
candidate: Candidate,
|
|
31
|
-
judge: z.boolean().default(false),
|
|
32
|
-
tokenCap: z.number().int().optional(),
|
|
33
|
-
})
|
|
34
|
-
.strict();
|
|
35
|
-
const StartBody = EstimateBody;
|
|
36
|
-
/**
|
|
37
|
-
* `view=light`:不含内容块(结果表与轮询用,响应带 `asOf`);缺省 `full`。`updatedSince`(ISO 时间)只取之后有变化的,
|
|
38
|
-
* 轮询时传上一次的 `asOf`。
|
|
39
|
-
*/
|
|
40
|
-
const ResultsQuery = z
|
|
41
|
-
.object({
|
|
42
|
-
after: z.string().max(100).optional(),
|
|
43
|
-
limit: z.coerce.number().int().min(1).max(200).default(50),
|
|
44
|
-
view: z.enum(["full", "light"]).default("full"),
|
|
45
|
-
updatedSince: z
|
|
46
|
-
.string()
|
|
47
|
-
.max(64)
|
|
48
|
-
.refine((v) => !Number.isNaN(Date.parse(v)), { message: "must be an ISO timestamp" })
|
|
49
|
-
.optional(),
|
|
50
|
-
})
|
|
51
|
-
.strict();
|
|
52
|
-
const LabelBody = z
|
|
53
|
-
.object({
|
|
54
|
-
label: z.enum(["pass", "fail"]).nullable(),
|
|
55
|
-
note: z.string().max(2000).optional(),
|
|
56
|
-
})
|
|
57
|
-
.strict();
|
|
58
17
|
/** 去掉 zod 输出里值为 undefined 的键(exactOptionalPropertyTypes)。 */
|
|
59
18
|
function candidateOf(c) {
|
|
60
19
|
return {
|
|
@@ -195,7 +195,7 @@ export declare class EvalRunsService {
|
|
|
195
195
|
candidate: EvalCandidate;
|
|
196
196
|
judge: boolean;
|
|
197
197
|
tokenCap?: number;
|
|
198
|
-
}, actorTokenId?: string): Promise<EvalRunView>;
|
|
198
|
+
}, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<EvalRunView>;
|
|
199
199
|
/** The run row and its pending results, in a transaction of their own (enqueued after the commit). */
|
|
200
200
|
private startIn;
|
|
201
201
|
/** The enqueue failed: the run is `failed`, its pending results `skipped`. */
|
|
@@ -217,7 +217,7 @@ export declare class EvalRunsService {
|
|
|
217
217
|
after?: string;
|
|
218
218
|
limit: number;
|
|
219
219
|
updatedSince?: string;
|
|
220
|
-
}, actorTokenId?: string): Promise<{
|
|
220
|
+
}, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<{
|
|
221
221
|
results: EvalResultView[];
|
|
222
222
|
next: string | null;
|
|
223
223
|
}>;
|
|
@@ -229,18 +229,18 @@ export declare class EvalRunsService {
|
|
|
229
229
|
after?: string;
|
|
230
230
|
limit: number;
|
|
231
231
|
updatedSince?: string;
|
|
232
|
-
}, actorTokenId?: string): Promise<{
|
|
232
|
+
}, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<{
|
|
233
233
|
results: EvalResultLight[];
|
|
234
234
|
next: string | null;
|
|
235
235
|
asOf: string;
|
|
236
236
|
}>;
|
|
237
237
|
/** 一条结果的完整行(查看器按需读取);不在该运行 / 本组织 → `eval.result_not_found`。写查看审计(去重)。 */
|
|
238
|
-
result(orgId: string, actor: string, runId: string, resultId: string, actorTokenId?: string): Promise<EvalResultView>;
|
|
238
|
+
result(orgId: string, actor: string, runId: string, resultId: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<EvalResultView>;
|
|
239
239
|
/**
|
|
240
240
|
* 取消:queued / running → cancelled,尚未开始的结果立即 skipped;在途请求做完照常写入(C7 在途可超出),
|
|
241
241
|
* 之后的请求不再发。已结束 → `eval.run_finished`。
|
|
242
242
|
*/
|
|
243
|
-
cancel(orgId: string, actor: string, runId: string, actorTokenId?: string): Promise<EvalRunView>;
|
|
243
|
+
cancel(orgId: string, actor: string, runId: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<EvalRunView>;
|
|
244
244
|
/**
|
|
245
245
|
* 人工标注(D3):标通过 / 不通过(附可选备注),`label: null` 清除标注与备注。评测集已删除、结果不属于本组织 →
|
|
246
246
|
* `eval.result_not_found`。事务内锁组织并复核 `evals.manage`,写审计 `eval.result_labeled`(不含备注全文)。
|
|
@@ -248,7 +248,7 @@ export declare class EvalRunsService {
|
|
|
248
248
|
label(orgId: string, actor: string, resultId: string, input: {
|
|
249
249
|
label: "pass" | "fail" | null;
|
|
250
250
|
note?: string;
|
|
251
|
-
}, actorTokenId?: string): Promise<EvalResultView>;
|
|
251
|
+
}, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<EvalResultView>;
|
|
252
252
|
private cancelIn;
|
|
253
253
|
private labelIn;
|
|
254
254
|
}
|
|
@@ -418,7 +418,7 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
418
418
|
* 没有可回放的 → `eval.nothing_to_replay`。事务内建运行行、预建 pending 结果,提交后每个用例入队一个任务;
|
|
419
419
|
* 入队失败 → 运行标 failed、结果 skipped,错误照常抛出。
|
|
420
420
|
*/
|
|
421
|
-
async start(orgId, actor, setId, input, actorTokenId) {
|
|
421
|
+
async start(orgId, actor, setId, input, actorTokenId, auditDetail) {
|
|
422
422
|
const set = await this.liveSet(orgId, setId);
|
|
423
423
|
await this.assertAgentLive(set.agent_id);
|
|
424
424
|
const tokenCap = this.tokenCaps(input.tokenCap).effectiveTokenCap;
|
|
@@ -435,7 +435,7 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
435
435
|
if (firstProblem) {
|
|
436
436
|
throw candidateInvalid(firstProblem.message, firstProblem.details ?? []);
|
|
437
437
|
}
|
|
438
|
-
const { runId, plans } = await this.startIn(orgId, actor, setId, set.agent_id, input, tokenCap, planned, judge, actorTokenId);
|
|
438
|
+
const { runId, plans } = await this.startIn(orgId, actor, setId, set.agent_id, input, tokenCap, planned, judge, actorTokenId, auditDetail);
|
|
439
439
|
try {
|
|
440
440
|
await this.d.queue.enqueue(plans.map((p) => ({ runId, caseId: p.caseId, orgId })));
|
|
441
441
|
}
|
|
@@ -446,7 +446,7 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
446
446
|
return this.get(orgId, runId);
|
|
447
447
|
}
|
|
448
448
|
/** The run row and its pending results, in a transaction of their own (enqueued after the commit). */
|
|
449
|
-
async startIn(orgId, actor, setId, agentId, input, tokenCap, planned, judge, actorTokenId) {
|
|
449
|
+
async startIn(orgId, actor, setId, agentId, input, tokenCap, planned, judge, actorTokenId, auditDetail) {
|
|
450
450
|
const db = this.d.db;
|
|
451
451
|
await this.d.orgLock.lockAndAuthorize(orgId, actor, "evals.manage");
|
|
452
452
|
// 与删除用例(锁集合行 FOR UPDATE)互斥:之后读到的用例在提交前不会被删
|
|
@@ -511,7 +511,14 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
511
511
|
orgId,
|
|
512
512
|
action: "eval.run_started",
|
|
513
513
|
target: run.id,
|
|
514
|
-
detail: {
|
|
514
|
+
detail: {
|
|
515
|
+
setId,
|
|
516
|
+
mode: input.mode,
|
|
517
|
+
judge: input.judge,
|
|
518
|
+
tokenCap,
|
|
519
|
+
cases: plans.length,
|
|
520
|
+
...auditDetail,
|
|
521
|
+
},
|
|
515
522
|
});
|
|
516
523
|
await this.d.budget.recountCases(run.id);
|
|
517
524
|
return { runId: run.id, plans: plans.filter((p) => p.problem === null) };
|
|
@@ -632,7 +639,7 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
632
639
|
* 查看结果的审计 `eval.results_viewed`(结果里有回放出来的对话内容):每位查看者每次运行每小时一条——Redis
|
|
633
640
|
* `SET NX EX` 去重(多副本共享),轻量轮询因此不会刷审计。Redis 不可用时照写(宁多不漏)。
|
|
634
641
|
*/
|
|
635
|
-
async viewed(orgId, runId, actor, actorTokenId) {
|
|
642
|
+
async viewed(orgId, runId, actor, actorTokenId, auditDetail) {
|
|
636
643
|
let first = true;
|
|
637
644
|
try {
|
|
638
645
|
first = await this.d.locks.lease(resultsViewedKey(runId, actor), "1", RESULTS_VIEWED_TTL_SECONDS * 1000);
|
|
@@ -648,6 +655,7 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
648
655
|
orgId,
|
|
649
656
|
action: "eval.results_viewed",
|
|
650
657
|
target: runId,
|
|
658
|
+
...(auditDetail !== undefined && { detail: auditDetail }),
|
|
651
659
|
});
|
|
652
660
|
}
|
|
653
661
|
/** 结果分页的公共部分:按 id 升序,`after` 为上一页最后一条的 id;`updatedSince` 只取之后有变化的。 */
|
|
@@ -673,11 +681,11 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
673
681
|
return query;
|
|
674
682
|
}
|
|
675
683
|
/** 结果分页(完整行):按 id 升序,`after` 为上一页最后一条的 id。写查看审计(去重见 {@link viewed})。 */
|
|
676
|
-
async results(orgId, actor, runId, q, actorTokenId) {
|
|
684
|
+
async results(orgId, actor, runId, q, actorTokenId, auditDetail) {
|
|
677
685
|
await this.get(orgId, runId);
|
|
678
686
|
const rows = await this.resultsQuery(orgId, runId, q).selectAll().execute();
|
|
679
687
|
const page = rows.slice(0, q.limit);
|
|
680
|
-
await this.viewed(orgId, runId, actor, actorTokenId);
|
|
688
|
+
await this.viewed(orgId, runId, actor, actorTokenId, auditDetail);
|
|
681
689
|
return {
|
|
682
690
|
results: page.map(resultView),
|
|
683
691
|
next: rows.length > q.limit ? (page.at(-1)?.id ?? null) : null,
|
|
@@ -687,13 +695,13 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
687
695
|
* 结果分页(轻量,结果表与轮询用):不含内容块。`asOf` 作为下一次轮询的 `updatedSince`(已留余量,
|
|
688
696
|
* 见 {@link RESULTS_ASOF_OVERLAP_MS};重复的行由调用方按 id 合并)。
|
|
689
697
|
*/
|
|
690
|
-
async resultsLight(orgId, actor, runId, q, actorTokenId) {
|
|
698
|
+
async resultsLight(orgId, actor, runId, q, actorTokenId, auditDetail) {
|
|
691
699
|
await this.get(orgId, runId);
|
|
692
700
|
const now = await sql `SELECT now() AS now`.execute(this.d.db);
|
|
693
701
|
const asOf = new Date(new Date(now.rows[0]?.now ?? Date.now()).getTime() - RESULTS_ASOF_OVERLAP_MS);
|
|
694
702
|
const rows = await this.resultsQuery(orgId, runId, q).select(LIGHT_COLUMNS).execute();
|
|
695
703
|
const page = rows.slice(0, q.limit);
|
|
696
|
-
await this.viewed(orgId, runId, actor, actorTokenId);
|
|
704
|
+
await this.viewed(orgId, runId, actor, actorTokenId, auditDetail);
|
|
697
705
|
return {
|
|
698
706
|
results: page.map((r) => ({
|
|
699
707
|
id: r.id,
|
|
@@ -715,7 +723,7 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
715
723
|
};
|
|
716
724
|
}
|
|
717
725
|
/** 一条结果的完整行(查看器按需读取);不在该运行 / 本组织 → `eval.result_not_found`。写查看审计(去重)。 */
|
|
718
|
-
async result(orgId, actor, runId, resultId, actorTokenId) {
|
|
726
|
+
async result(orgId, actor, runId, resultId, actorTokenId, auditDetail) {
|
|
719
727
|
await this.get(orgId, runId);
|
|
720
728
|
if (!UUID.test(resultId))
|
|
721
729
|
throw resultNotFound();
|
|
@@ -728,31 +736,31 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
728
736
|
.executeTakeFirst();
|
|
729
737
|
if (!row)
|
|
730
738
|
throw resultNotFound();
|
|
731
|
-
await this.viewed(orgId, runId, actor, actorTokenId);
|
|
739
|
+
await this.viewed(orgId, runId, actor, actorTokenId, auditDetail);
|
|
732
740
|
return resultView(row);
|
|
733
741
|
}
|
|
734
742
|
/**
|
|
735
743
|
* 取消:queued / running → cancelled,尚未开始的结果立即 skipped;在途请求做完照常写入(C7 在途可超出),
|
|
736
744
|
* 之后的请求不再发。已结束 → `eval.run_finished`。
|
|
737
745
|
*/
|
|
738
|
-
async cancel(orgId, actor, runId, actorTokenId) {
|
|
746
|
+
async cancel(orgId, actor, runId, actorTokenId, auditDetail) {
|
|
739
747
|
if (!UUID.test(runId))
|
|
740
748
|
throw runNotFound();
|
|
741
749
|
await this.get(orgId, runId);
|
|
742
|
-
await this.cancelIn(orgId, actor, runId, actorTokenId);
|
|
750
|
+
await this.cancelIn(orgId, actor, runId, actorTokenId, auditDetail);
|
|
743
751
|
return this.get(orgId, runId);
|
|
744
752
|
}
|
|
745
753
|
/**
|
|
746
754
|
* 人工标注(D3):标通过 / 不通过(附可选备注),`label: null` 清除标注与备注。评测集已删除、结果不属于本组织 →
|
|
747
755
|
* `eval.result_not_found`。事务内锁组织并复核 `evals.manage`,写审计 `eval.result_labeled`(不含备注全文)。
|
|
748
756
|
*/
|
|
749
|
-
async label(orgId, actor, resultId, input, actorTokenId) {
|
|
757
|
+
async label(orgId, actor, resultId, input, actorTokenId, auditDetail) {
|
|
750
758
|
if (!UUID.test(resultId))
|
|
751
759
|
throw resultNotFound();
|
|
752
|
-
const row = await this.labelIn(orgId, actor, resultId, input, actorTokenId);
|
|
760
|
+
const row = await this.labelIn(orgId, actor, resultId, input, actorTokenId, auditDetail);
|
|
753
761
|
return resultView(row);
|
|
754
762
|
}
|
|
755
|
-
async cancelIn(orgId, actor, runId, actorTokenId) {
|
|
763
|
+
async cancelIn(orgId, actor, runId, actorTokenId, auditDetail) {
|
|
756
764
|
await this.d.orgLock.lockAndAuthorize(orgId, actor, "evals.manage");
|
|
757
765
|
const r = await this.d.db
|
|
758
766
|
.updateTable("eval_runs")
|
|
@@ -772,9 +780,10 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
772
780
|
orgId,
|
|
773
781
|
action: "eval.run_cancelled",
|
|
774
782
|
target: runId,
|
|
783
|
+
...(auditDetail !== undefined && { detail: auditDetail }),
|
|
775
784
|
});
|
|
776
785
|
}
|
|
777
|
-
async labelIn(orgId, actor, resultId, input, actorTokenId) {
|
|
786
|
+
async labelIn(orgId, actor, resultId, input, actorTokenId, auditDetail) {
|
|
778
787
|
await this.d.orgLock.lockAndAuthorize(orgId, actor, "evals.manage");
|
|
779
788
|
// 先锁住这条结果、读出原标注(写进审计)
|
|
780
789
|
const before = await this.d.db
|
|
@@ -814,7 +823,12 @@ let EvalRunsService = EvalRunsService_1 = class EvalRunsService {
|
|
|
814
823
|
orgId,
|
|
815
824
|
action: "eval.result_labeled",
|
|
816
825
|
target: resultId,
|
|
817
|
-
detail: {
|
|
826
|
+
detail: {
|
|
827
|
+
runId: r.run_id,
|
|
828
|
+
label: input.label,
|
|
829
|
+
previousLabel: before.label,
|
|
830
|
+
...auditDetail,
|
|
831
|
+
},
|
|
818
832
|
});
|
|
819
833
|
return r;
|
|
820
834
|
}
|
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
1
|
+
import type { z } from "zod";
|
|
2
2
|
import { type Principal } from "../identity/principal.js";
|
|
3
3
|
import { type OrgContext } from "../orgs/org.guard.js";
|
|
4
|
+
import { EvalAddCaseBody as AddCaseBody, EvalSetCreateBody as CreateBody, EvalSetPatchBody as PatchBody, EvalSampleBody as SampleBody } from "./evals.schemas.js";
|
|
4
5
|
import { type EvalCaseDetail, type EvalCaseView, type EvalSetDetail, EvalSetsService, type EvalSetView } from "./sets.service.js";
|
|
5
|
-
declare const CreateBody: z.ZodObject<{
|
|
6
|
-
agentId: z.ZodString;
|
|
7
|
-
name: z.ZodString;
|
|
8
|
-
description: z.ZodOptional<z.ZodString>;
|
|
9
|
-
rubric: z.ZodOptional<z.ZodString>;
|
|
10
|
-
}, z.core.$strict>;
|
|
11
|
-
declare const PatchBody: z.ZodObject<{
|
|
12
|
-
name: z.ZodOptional<z.ZodString>;
|
|
13
|
-
description: z.ZodOptional<z.ZodString>;
|
|
14
|
-
rubric: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
15
|
-
}, z.core.$strict>;
|
|
16
|
-
declare const AddCaseBody: z.ZodObject<{
|
|
17
|
-
conversationId: z.ZodString;
|
|
18
|
-
runId: z.ZodString;
|
|
19
|
-
}, z.core.$strict>;
|
|
20
|
-
declare const SampleBody: z.ZodObject<{
|
|
21
|
-
from: z.ZodOptional<z.ZodISODateTime>;
|
|
22
|
-
to: z.ZodOptional<z.ZodISODateTime>;
|
|
23
|
-
count: z.ZodNumber;
|
|
24
|
-
status: z.ZodOptional<z.ZodEnum<{
|
|
25
|
-
any: "any";
|
|
26
|
-
completed: "completed";
|
|
27
|
-
failed: "failed";
|
|
28
|
-
}>>;
|
|
29
|
-
minToolCalls: z.ZodOptional<z.ZodNumber>;
|
|
30
|
-
}, z.core.$strict>;
|
|
31
6
|
/**
|
|
32
7
|
* 评测集与用例(`/api/v1/orgs/:orgId/eval-sets`):全部 `evals.manage`(admin 起、只给人)。
|
|
33
8
|
* 用例详情返回快照还原的轨迹,每次写审计 `trajectory.viewed`。
|
|
@@ -58,4 +33,3 @@ export declare class EvalSetsController {
|
|
|
58
33
|
getCase(principal: Principal, org: OrgContext, setId: string, caseId: string): Promise<EvalCaseDetail>;
|
|
59
34
|
removeCase(principal: Principal, org: OrgContext, setId: string, caseId: string): Promise<void>;
|
|
60
35
|
}
|
|
61
|
-
export {};
|