@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.37
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 +5 -5
- package/dist/admin/admin.module.d.ts +3 -3
- package/dist/admin/admin.module.js +6 -6
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +4 -12
- package/dist/agents/readiness.controller.js +4 -12
- package/dist/agents/readiness.service.d.ts +23 -11
- package/dist/agents/readiness.service.js +31 -14
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +53 -47
- package/dist/config/schema.js +190 -40
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.js +1 -2
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +17 -6
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +5 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/host.d.ts +2 -3
- package/dist/extensions/host.js +1 -5
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +2 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/orgs/orgs.module.d.ts +2 -2
- package/dist/orgs/orgs.module.js +2 -2
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +3 -7
- package/dist/overrides.js +2 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +5 -3
- package/dist/platform/ops/orgs.ops.js +19 -4
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +1 -0
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.js +4 -3
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +56 -0
- package/dist/tools/drift.d.ts +1 -1
- package/dist/tools/drift.js +1 -1
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +16 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
|
@@ -19,13 +19,13 @@ const RefMediaSourceSchema = z.object({
|
|
|
19
19
|
attachmentId: AttachmentIdSchema,
|
|
20
20
|
});
|
|
21
21
|
/**
|
|
22
|
-
* Who may decide an approval, as the approval row says (display only
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Who may decide an approval, as the approval row says (display only): the assigned account
|
|
23
|
+
* (`requestedFor`), else the escalation role (`approverRole`). Pages word the waiting state with it
|
|
24
|
+
* ("Waiting for Alice to approve") for viewers who cannot decide.
|
|
25
25
|
*/
|
|
26
26
|
const ApproverFields = {
|
|
27
|
-
requestedFor: z.string().nullable()
|
|
28
|
-
approverRole: z.enum(ORG_ROLES).nullable()
|
|
27
|
+
requestedFor: z.string().nullable(),
|
|
28
|
+
approverRole: z.enum(ORG_ROLES).nullable(),
|
|
29
29
|
};
|
|
30
30
|
/** The most hosts one network ask (and one `network_blocked` event) lists. */
|
|
31
31
|
export const NETWORK_ASK_MAX_HOSTS = 20;
|
|
@@ -87,8 +87,6 @@ export const CommandAskSchema = z
|
|
|
87
87
|
export const MEDIA_EXCLUDED_MAX_IDS = 50;
|
|
88
88
|
/** 一份 `skills_catalog` 快照最多的技能数(组织技能引用上限 100,余量给 agent 自己的技能)。 */
|
|
89
89
|
export const SKILLS_CATALOG_MAX = 1000;
|
|
90
|
-
/** The longest pinned skill body in a `skills_catalog` snapshot (the pinned total is ≤ 32768 bytes). */
|
|
91
|
-
export const PINNED_BODY_MAX_CHARS = 32768;
|
|
92
90
|
/** 媒体块的名字:与 plugin-sdk `validateMediaBlock` 同规则(≤255 字符、不含控制字符)。 */
|
|
93
91
|
const MediaNameSchema = z
|
|
94
92
|
.string()
|
|
@@ -98,8 +96,18 @@ const ArtifactNameSchema = MediaNameSchema.min(1);
|
|
|
98
96
|
/** 产物名(`artifact_created.name`)是否合法:与日志 schema 同一规则(非空、≤255、不含控制字符)。 */
|
|
99
97
|
export const isValidArtifactName = (name) => ArtifactNameSchema.safeParse(name).success;
|
|
100
98
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
99
|
+
* A `file` block's media type: any non-empty `type/subtype` with no whitespace or control
|
|
100
|
+
* characters, the rule of plugin-sdk's `validateMediaBlock`.
|
|
101
|
+
*/
|
|
102
|
+
const FileMediaTypeSchema = z
|
|
103
|
+
.string()
|
|
104
|
+
.regex(/^[^/\s]+\/[^/\s]+$/, "mediaType must be a non-empty type/subtype string")
|
|
105
|
+
.refine((s) => !hasControlChars(s), "mediaType must not contain control characters");
|
|
106
|
+
/** `size` on a media block: display metadata (the UI chip, the reference line), never sent. */
|
|
107
|
+
const MediaBlockSizeSchema = z.number().int().nonnegative().optional();
|
|
108
|
+
/**
|
|
109
|
+
* A content block as the log carries it: plugin-sdk's `ContentBlock`, but the source of an image,
|
|
110
|
+
* document or file block may only be a `ref` (blocks written with a `base64` source are rejected).
|
|
103
111
|
*/
|
|
104
112
|
export const ContentBlockSchema = z.discriminatedUnion("type", [
|
|
105
113
|
z.object({ type: z.literal("text"), text: z.string(), opaque: ProviderOpaqueSchema.optional() }),
|
|
@@ -126,12 +134,21 @@ export const ContentBlockSchema = z.discriminatedUnion("type", [
|
|
|
126
134
|
mediaType: z.enum(IMAGE_MEDIA_TYPES),
|
|
127
135
|
source: RefMediaSourceSchema,
|
|
128
136
|
name: MediaNameSchema.optional(),
|
|
137
|
+
size: MediaBlockSizeSchema,
|
|
129
138
|
}),
|
|
130
139
|
z.object({
|
|
131
140
|
type: z.literal("document"),
|
|
132
141
|
mediaType: z.enum(DOCUMENT_MEDIA_TYPES),
|
|
133
142
|
source: RefMediaSourceSchema,
|
|
134
143
|
name: MediaNameSchema.optional(),
|
|
144
|
+
size: MediaBlockSizeSchema,
|
|
145
|
+
}),
|
|
146
|
+
z.object({
|
|
147
|
+
type: z.literal("file"),
|
|
148
|
+
mediaType: FileMediaTypeSchema,
|
|
149
|
+
source: RefMediaSourceSchema,
|
|
150
|
+
name: MediaNameSchema.optional(),
|
|
151
|
+
size: MediaBlockSizeSchema,
|
|
135
152
|
}),
|
|
136
153
|
]);
|
|
137
154
|
const STOP_REASONS = ["end_turn", "tool_use", "max_tokens", "refusal", "other"];
|
|
@@ -283,8 +300,8 @@ export const RunContextSchema = z.object({
|
|
|
283
300
|
/**
|
|
284
301
|
* The attribution a run's requests carry for git commits and pull requests it creates (spec
|
|
285
302
|
* 2026-11-14-agent-attribution): the effective values fixed at run start (platform defaults or
|
|
286
|
-
* the agent's override), so request building never reads config or the database. Absent
|
|
287
|
-
*
|
|
303
|
+
* the agent's override), so request building never reads config or the database. Absent when it
|
|
304
|
+
* did not change (as every field here). An empty `commit` / `pr` turns that line off; `sessionUrl` is the resolved conversation
|
|
288
305
|
* link, or null.
|
|
289
306
|
*/
|
|
290
307
|
attribution: z
|
|
@@ -312,21 +329,6 @@ export const PluginContextSchema = z.object({
|
|
|
312
329
|
}),
|
|
313
330
|
hash: z.string().regex(/^[0-9a-f]{64}$/),
|
|
314
331
|
});
|
|
315
|
-
/**
|
|
316
|
-
* An agent definition frozen into a log (`subagent_started`): the current schema, with the
|
|
317
|
-
* selected and pinned skills of older logs still accepted (skills default-on spec §4: history
|
|
318
|
-
* keeps the old fields; new definitions never carry them).
|
|
319
|
-
*/
|
|
320
|
-
const LoggedAgentDefinition = AgentDefinitionSchema.extend({
|
|
321
|
-
skills: z
|
|
322
|
-
.object({
|
|
323
|
-
writePolicy: z.enum(["allow", "ask"]).optional(),
|
|
324
|
-
orgSkills: z.array(z.string()).optional(),
|
|
325
|
-
pinned: z.array(z.string()).optional(),
|
|
326
|
-
})
|
|
327
|
-
.strict()
|
|
328
|
-
.optional(),
|
|
329
|
-
});
|
|
330
332
|
/**
|
|
331
333
|
* 会话事件(`type` + `payload`)的判别联合。事件日志只追加,写入前用它校验 payload;
|
|
332
334
|
* 读出时按写入时的形状原样返回。
|
|
@@ -345,8 +347,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
345
347
|
authorAccountId: z.string(),
|
|
346
348
|
/**
|
|
347
349
|
* Who wrote the message, at send time (run context spec §3.2): display name and org role
|
|
348
|
-
* only (never email or ids). Absent
|
|
349
|
-
* message. Model-visible only through the sender line, written when the sender changes
|
|
350
|
+
* only (never email or ids). Absent on a sub-agent's task or `SendMessage` message. Model-visible only through the sender line, written when the sender changes
|
|
350
351
|
* (`senderLines`, runtime/context/run-context.ts).
|
|
351
352
|
*/
|
|
352
353
|
sender: MessageSenderSchema.optional(),
|
|
@@ -365,10 +366,15 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
365
366
|
*/
|
|
366
367
|
retryOf: seqNo.optional(),
|
|
367
368
|
/**
|
|
368
|
-
* A
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
369
|
+
* A skill invocation: which skill version was rendered into `content[0]`, with the
|
|
370
|
+
* arguments (trimmed). Not model-visible (the rendered text is). `name` is the skill's bare
|
|
371
|
+
* name, `plugin` its catalog item; `agentType` is set for `mode: "fork"`.
|
|
372
|
+
* - A person's (`/name args`, phase D spec §4.3): the arguments as typed; the web renders
|
|
373
|
+
* the chip and the arguments from it.
|
|
374
|
+
* - `template: true`: written by the kernel at a template sub-agent's dispatch, after its
|
|
375
|
+
* task, for each of the template's skills (`runtime/subagents/template-skills.ts`;
|
|
376
|
+
* `mode: "inline"`, no arguments, `authorAccountId` the person whose run dispatched it);
|
|
377
|
+
* nobody typed it: the web shows it with the task, never as a person's message.
|
|
372
378
|
*/
|
|
373
379
|
skill: z
|
|
374
380
|
.object({
|
|
@@ -380,8 +386,17 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
380
386
|
arguments: z.string(),
|
|
381
387
|
mode: z.enum(["inline", "fork"]),
|
|
382
388
|
agentType: z.string().optional(),
|
|
389
|
+
template: z.literal(true).optional(),
|
|
383
390
|
})
|
|
384
391
|
.optional(),
|
|
392
|
+
/**
|
|
393
|
+
* The kernel's notice, written at a template sub-agent's dispatch in place of a template
|
|
394
|
+
* skill's invocation, that the skill (`name`) could not be read
|
|
395
|
+
* (`runtime/subagents/template-skills.ts`). Display only (the model sees the text): nobody
|
|
396
|
+
* typed it, so the web shows it with the task and eval case titles skip it, as a `template`
|
|
397
|
+
* invocation. It carries no `skill` record: nothing was rendered from a version.
|
|
398
|
+
*/
|
|
399
|
+
templateSkillNotice: z.object({ name: z.string() }).optional(),
|
|
385
400
|
/**
|
|
386
401
|
* A scheduled task's message (scheduled tasks spec §6, §12): which task and tick posted it.
|
|
387
402
|
* Not model-visible as such: request building renders only `taskName` and `localTime`, fixed
|
|
@@ -406,24 +421,13 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
406
421
|
kind: z.enum(["task", "message"]).optional(),
|
|
407
422
|
/**
|
|
408
423
|
* A follow-up (`resume`, final review I1): the frozen and the current version's
|
|
409
|
-
* turned-off tools and skills together (`narrowFollowUp
|
|
410
|
-
*
|
|
411
|
-
* frozen ones.
|
|
412
|
-
* Absent on a first dispatch and in older logs; logs from before tools were on by
|
|
413
|
-
* default carry an enabled `tools` list instead of `disabledTools` (read as no tool
|
|
414
|
-
* narrowing).
|
|
424
|
+
* turned-off tools and skills together (`narrowFollowUp`); the child's run uses these
|
|
425
|
+
* instead of the frozen ones. Absent on a first dispatch.
|
|
415
426
|
*/
|
|
416
427
|
narrowed: z
|
|
417
428
|
.object({
|
|
418
|
-
disabledTools: z.array(DisabledToolRef)
|
|
419
|
-
|
|
420
|
-
* Skills default-on (spec §6.1): the frozen and the current version's turned-off
|
|
421
|
-
* skills together. Logs from before carry `skills` (`orgSkills` / `pinned`) instead.
|
|
422
|
-
*/
|
|
423
|
-
disabledSkills: z.array(DisabledSkillRef).optional(),
|
|
424
|
-
skills: z
|
|
425
|
-
.object({ orgSkills: z.array(z.string()), pinned: z.array(z.string()).optional() })
|
|
426
|
-
.optional(),
|
|
429
|
+
disabledTools: z.array(DisabledToolRef),
|
|
430
|
+
disabledSkills: z.array(DisabledSkillRef),
|
|
427
431
|
})
|
|
428
432
|
.optional(),
|
|
429
433
|
})
|
|
@@ -470,52 +474,73 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
470
474
|
provider: z.string(),
|
|
471
475
|
model: z.string(),
|
|
472
476
|
fallback: z.boolean(),
|
|
473
|
-
request: z
|
|
477
|
+
request: z
|
|
478
|
+
.object({
|
|
474
479
|
fromSeq: seqNo,
|
|
475
480
|
toSeq: seqNo,
|
|
476
481
|
summarySeq: seqNo.nullable(),
|
|
477
482
|
systemHash: z.string(),
|
|
478
483
|
reminderSeqs: z.array(seqNo),
|
|
479
|
-
/** 本次请求的输出上限(`min(模型上限, maxOutputTokens 旋钮 ?? runtime.maxOutputTokens)`)。较早的事件可能没有。 */
|
|
480
|
-
maxOutputTokens: count.optional(),
|
|
481
484
|
/**
|
|
482
|
-
*
|
|
483
|
-
*
|
|
485
|
+
* The request's output cap: `min(model cap, maxOutputTokens knob ??
|
|
486
|
+
* runtime.maxOutputTokens)`, clamped by the hard fit guard.
|
|
487
|
+
*/
|
|
488
|
+
maxOutputTokens: count,
|
|
489
|
+
/**
|
|
490
|
+
* The request's model parameters (`ModelRequest.params`): the agent's saved parameters
|
|
491
|
+
* sanitized against the model's declarations (defaults filled in), from `modelParams` for
|
|
492
|
+
* the agent's model and `fallbackParams` for a fallback attempt.
|
|
484
493
|
*/
|
|
485
|
-
params: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
|
|
486
|
-
/**
|
|
494
|
+
params: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
|
|
495
|
+
/** Parameter keys sanitizing dropped (undeclared or no longer valid, e.g. after a plugin upgrade); absent when none were dropped. */
|
|
487
496
|
droppedParams: z.array(z.string()).optional(),
|
|
488
497
|
/**
|
|
489
|
-
*
|
|
490
|
-
* `
|
|
498
|
+
* The input token estimate (uncalibrated) when the request went out. With the later
|
|
499
|
+
* `usage.inputTokens` it feeds the next `calibrate`. The runtime always writes it; calls
|
|
500
|
+
* logged before it was recorded lack it, and no value would stand in for them (a made-up
|
|
501
|
+
* estimate would skew the calibration), so it stays optional and such a call calibrates
|
|
502
|
+
* nothing.
|
|
491
503
|
*/
|
|
492
504
|
estimatedInputTokens: count.optional(),
|
|
493
505
|
/**
|
|
494
|
-
*
|
|
495
|
-
*
|
|
506
|
+
* The largest absorbable event seq the loop had taken in when the request went out (R31):
|
|
507
|
+
* absorbable events with a larger seq are not in this request (a later step takes them in
|
|
508
|
+
* or they start the next run). Reconstruction places and leaves out messages by it.
|
|
509
|
+
*/
|
|
510
|
+
absorbedUpToSeq: seqNo,
|
|
511
|
+
/**
|
|
512
|
+
* The tools the request carried, in sending order (sorted by key without ToolSearch; with
|
|
513
|
+
* it, the builtin tools sorted by key, then the loaded tools in first-load order), with
|
|
514
|
+
* their definition fingerprints (`ResolvedTool.specHash`). Empty when the model has no
|
|
515
|
+
* tool support (see `toolsOmitted`).
|
|
496
516
|
*/
|
|
497
|
-
|
|
517
|
+
tools: z.array(z.object({ key: z.string(), specHash: z.string() })),
|
|
498
518
|
/**
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
519
|
+
* The kernel left this step's tools out because the model has no tool support
|
|
520
|
+
* (`capabilities.tools` false while the step had tools): `tools` is empty and says nothing
|
|
521
|
+
* about the step's resolved set. Absent when the request carried the step's tools.
|
|
502
522
|
*/
|
|
503
|
-
|
|
523
|
+
toolsOmitted: z.literal(true).optional(),
|
|
504
524
|
/**
|
|
505
|
-
*
|
|
506
|
-
* `capybara.tool_specs
|
|
525
|
+
* With ToolSearch on, the tools of the catalog in the system's second block (sorted by
|
|
526
|
+
* key) with their definition fingerprints; the definitions are in `capybara.tool_specs`
|
|
527
|
+
* too, so the catalog text can be rebuilt from them. Absent without ToolSearch.
|
|
507
528
|
*/
|
|
508
529
|
catalog: z.array(z.object({ key: z.string(), specHash: z.string() })).optional(),
|
|
509
530
|
/**
|
|
510
|
-
*
|
|
511
|
-
*
|
|
531
|
+
* The request's `toolChoice`: `"none"` on the wrap-up call (tools carried as usual, but
|
|
532
|
+
* none may be called); absent on ordinary steps (the model decides). The definitions
|
|
533
|
+
* themselves are in `capybara.tool_specs` by specHash.
|
|
512
534
|
*/
|
|
513
535
|
toolChoice: z.enum(["auto", "none"]).optional(),
|
|
514
536
|
/**
|
|
515
|
-
*
|
|
516
|
-
* etag
|
|
517
|
-
*
|
|
518
|
-
*
|
|
537
|
+
* What became of each attachment in the request (Ruling M8, in first-seen order, one
|
|
538
|
+
* entry per attachment): bytes sent (`bytes`, with the etag at finalize), inline text, a
|
|
539
|
+
* reference line only (`reference`: a `file` block, or text over the inline cap), a
|
|
540
|
+
* placeholder for an unsupported kind, left out for the request's media budget
|
|
541
|
+
* (`omitted`), too many images (`too_many_images`), one over the provider's limit
|
|
542
|
+
* (`too_large`), no longer available, too many PDF pages, or excluded by
|
|
543
|
+
* `media_excluded`. Absent without media; written together with `mediaBudgetBytes`.
|
|
519
544
|
*/
|
|
520
545
|
media: z
|
|
521
546
|
.array(z.object({
|
|
@@ -523,6 +548,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
523
548
|
outcome: z.enum([
|
|
524
549
|
"bytes",
|
|
525
550
|
"inline",
|
|
551
|
+
"reference",
|
|
526
552
|
"placeholder_unsupported",
|
|
527
553
|
"omitted",
|
|
528
554
|
"too_many_images",
|
|
@@ -535,8 +561,9 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
535
561
|
}))
|
|
536
562
|
.optional(),
|
|
537
563
|
/**
|
|
538
|
-
*
|
|
539
|
-
*
|
|
564
|
+
* The request's media byte budget (`attachments.requestMediaBytes`, see planMedia):
|
|
565
|
+
* written only when the request has media (together with `media`); reconstruction uses
|
|
566
|
+
* it to repeat the same omissions.
|
|
540
567
|
*/
|
|
541
568
|
mediaBudgetBytes: count.optional(),
|
|
542
569
|
/**
|
|
@@ -553,6 +580,9 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
553
580
|
truncated: z.array(z.object({ messageIndex: count, block: count, note: z.string() })),
|
|
554
581
|
})
|
|
555
582
|
.optional(),
|
|
583
|
+
})
|
|
584
|
+
.refine((r) => (r.media === undefined) === (r.mediaBudgetBytes === undefined), {
|
|
585
|
+
message: "media and mediaBudgetBytes are recorded together",
|
|
556
586
|
}),
|
|
557
587
|
})),
|
|
558
588
|
ev("assistant_message", z.object({
|
|
@@ -579,7 +609,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
579
609
|
/**
|
|
580
610
|
* The chunk a chunked compaction call summarised (1-based), with the number of calls the
|
|
581
611
|
* compaction attempted (the full chunk count on a completed one; on a failed or hook-denied
|
|
582
|
-
* run only the calls that were made). Absent on a single-call compaction
|
|
612
|
+
* run only the calls that were made). Absent on a single-call compaction.
|
|
583
613
|
*/
|
|
584
614
|
chunk: count.optional(),
|
|
585
615
|
chunks: count.optional(),
|
|
@@ -771,7 +801,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
771
801
|
approvalId: z.string(),
|
|
772
802
|
toolKey: z.string(),
|
|
773
803
|
expiresAt: z.string(),
|
|
774
|
-
/** Which rule asked (UI refresh B; display only
|
|
804
|
+
/** Which rule asked a tool approval (UI refresh B; display only; absent on the other asks). */
|
|
775
805
|
policy: z.enum(["agent", "connector", "default", "role", "org", "fixed"]).optional(),
|
|
776
806
|
/**
|
|
777
807
|
* A network ask (network ask-to-allow spec §6.1): the hosts the device owner is asked to
|
|
@@ -904,21 +934,6 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
904
934
|
nameOnly: z.literal(true).optional(),
|
|
905
935
|
}))
|
|
906
936
|
.max(SKILLS_CATALOG_MAX),
|
|
907
|
-
/**
|
|
908
|
-
* Pinned skills (phase B, spec §9.1) in the agent's order: each a skill of `skills` (same
|
|
909
|
-
* id, version and source) with its SKILL.md body as read at run start or written by
|
|
910
|
-
* a skill registration. Absent means none (every snapshot before phase B).
|
|
911
|
-
*/
|
|
912
|
-
pinned: z
|
|
913
|
-
.array(z.object({
|
|
914
|
-
id: z.string().min(1).max(100),
|
|
915
|
-
version: z.number().int().positive(),
|
|
916
|
-
name: z.string().refine(isSkillName, "invalid skill name"),
|
|
917
|
-
source: z.string().min(1).max(512),
|
|
918
|
-
body: z.string().max(PINNED_BODY_MAX_CHARS),
|
|
919
|
-
}))
|
|
920
|
-
.max(3)
|
|
921
|
-
.optional(),
|
|
922
937
|
/**
|
|
923
938
|
* The Claude Code tool-name map text (`CLAUDE_CODE_TOOL_MAP`), present iff a skill in
|
|
924
939
|
* `skills` came from a Claude Code plugin.
|
|
@@ -993,7 +1008,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
993
1008
|
/**
|
|
994
1009
|
* Plugin scope phase 2: the platform template whose content a `plugin` child ran (a
|
|
995
1010
|
* platform template, or an org copy linked to one, recorded under the copy's `id`). Absent
|
|
996
|
-
* = the org's own template
|
|
1011
|
+
* = the org's own template. Eval metadata, not model-visible.
|
|
997
1012
|
*/
|
|
998
1013
|
platformTemplateId: z.string().optional(),
|
|
999
1014
|
/**
|
|
@@ -1004,14 +1019,12 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1004
1019
|
.object({ id: z.string(), version: z.number().int(), name: z.string() })
|
|
1005
1020
|
.optional(),
|
|
1006
1021
|
}),
|
|
1022
|
+
/** The effective (narrowed) definition, frozen at dispatch. */
|
|
1023
|
+
definition: AgentDefinitionSchema,
|
|
1007
1024
|
/**
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
|
|
1011
|
-
definition: LoggedAgentDefinition,
|
|
1012
|
-
/**
|
|
1013
|
-
* `SUBAGENT_PREAMBLE` at dispatch time; since skills were on by default, followed by the line
|
|
1014
|
-
* naming a template's skills the child loads first (skills default-on spec §6.1).
|
|
1025
|
+
* `SUBAGENT_PREAMBLE` at dispatch time. Children dispatched between skills default-on and
|
|
1026
|
+
* template skills written as invocations end it with the line naming a template's skills
|
|
1027
|
+
* the child loads first (`Before you start, load these skills with Skill: …`).
|
|
1015
1028
|
*/
|
|
1016
1029
|
preamble: z.string(),
|
|
1017
1030
|
/** The child's step limit; 0 = no limit (`runtime.maxSteps` 0, no template limit). */
|
|
@@ -1054,8 +1067,9 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1054
1067
|
questionId: z.string().optional(),
|
|
1055
1068
|
toolKey: z.string(),
|
|
1056
1069
|
expiresAt: z.string().optional(),
|
|
1057
|
-
/** An approval's approver (`kind: "approval"`), as in `approval_requested`. */
|
|
1058
|
-
|
|
1070
|
+
/** An approval's approver (`kind: "approval"` only), as in `approval_requested`. */
|
|
1071
|
+
requestedFor: ApproverFields.requestedFor.optional(),
|
|
1072
|
+
approverRole: ApproverFields.approverRole.optional(),
|
|
1059
1073
|
})),
|
|
1060
1074
|
/** Parent log: a sub-agent's run ended. Not model-visible (its reply is the call's tool_result). */
|
|
1061
1075
|
ev("subagent_finished", z.object({
|
|
@@ -1074,8 +1088,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1074
1088
|
* `childRunId` finished. **Model-visible**: absorbed like an interjection and rendered as a system
|
|
1075
1089
|
* message (`renderSubagentDelivery`). A finish after a handback carries `text: ""` and
|
|
1076
1090
|
* `handedBack: true` and renders as one status line, except that a run that handed back and
|
|
1077
|
-
* `completed` writes no finished delivery at all (acceptance 2026-11-07;
|
|
1078
|
-
* keep rendering it); a finish without a handback carries the child's
|
|
1091
|
+
* `completed` writes no finished delivery at all (acceptance 2026-11-07); a finish without a handback carries the child's
|
|
1079
1092
|
* final reply, a failed finish its error message (`errorCode` the code), an aborted one no text
|
|
1080
1093
|
* (`abortedBy` who stopped it), with `subagent_finished`'s vocabulary. `status` is present exactly
|
|
1081
1094
|
* on `kind: "finished"`. `triggerAccountId`: the child run's trigger account, the one a wake runs
|
|
@@ -1150,29 +1163,28 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1150
1163
|
text: z.string(),
|
|
1151
1164
|
/**
|
|
1152
1165
|
* The estimated transcript input minus the stored summary output (context compaction spec
|
|
1153
|
-
* §4.9), so the UI needs no chunked usage to show what compaction saved.
|
|
1154
|
-
* logs have none.
|
|
1166
|
+
* §4.9), so the UI needs no chunked usage to show what compaction saved.
|
|
1155
1167
|
*/
|
|
1156
|
-
savedTokens: count
|
|
1168
|
+
savedTokens: count,
|
|
1157
1169
|
/**
|
|
1158
1170
|
* The user messages that started the run being compacted, when the summary covers them
|
|
1159
1171
|
* (context compaction spec §4.2, revision 2026-11-15), in seq order: request building
|
|
1160
1172
|
* re-renders exactly these after the summary text. Decided when the summary is written, so a
|
|
1161
|
-
* request never depends on later events.
|
|
1162
|
-
*
|
|
1173
|
+
* request never depends on later events. Absent when the summary covers no opening message
|
|
1174
|
+
* (nothing re-rendered).
|
|
1163
1175
|
*/
|
|
1164
1176
|
openingSeqs: z.array(seqNo).optional(),
|
|
1165
1177
|
/**
|
|
1166
1178
|
* The step the compaction ran in (0 for a manual compact run), so a later compaction in the
|
|
1167
|
-
* same step takes the next idempotency key.
|
|
1179
|
+
* same step takes the next idempotency key.
|
|
1168
1180
|
*/
|
|
1169
|
-
step: count
|
|
1181
|
+
step: count,
|
|
1170
1182
|
})),
|
|
1171
1183
|
ev("compaction_failed", z.object({
|
|
1172
1184
|
attempt: count,
|
|
1173
1185
|
reason: z.string(),
|
|
1174
|
-
/** The step the compaction ran in, as on `compaction_summary`.
|
|
1175
|
-
step: count
|
|
1186
|
+
/** The step the compaction ran in, as on `compaction_summary`. */
|
|
1187
|
+
step: count,
|
|
1176
1188
|
})),
|
|
1177
1189
|
ev("run_finished", z.object({
|
|
1178
1190
|
/** `budget`: a sub-agent stopped at its parent run's token cap (phase C, spec §8.3). */
|
|
@@ -1183,7 +1195,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1183
1195
|
ev("run_aborted", z.object({
|
|
1184
1196
|
byAccountId: z.string().nullable(),
|
|
1185
1197
|
/** `eval_stopped`:评测整轮回放被评测运行停下(只出现在 `kind = 'eval'` 的对话里),原因见 `detail`。 */
|
|
1186
|
-
reason: z.enum(["user", "shutdown_exhausted", "eval_stopped"]),
|
|
1198
|
+
reason: z.enum(["user", "shutdown_exhausted", "eval_stopped", "org_deleted"]),
|
|
1187
1199
|
/**
|
|
1188
1200
|
* Why an eval replay stopped (`eval_stopped`), or `wait_timeout`: a sub-agent run stopped
|
|
1189
1201
|
* (`user`, no account) because its parent's sub-agents wait timed out (phase C).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a chat attachment with this content type becomes an `image` block: one of the four image
|
|
3
|
+
* types a model can view.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isImageContentType(ct: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the model can consume the content itself, so the attachment becomes an `image` or
|
|
8
|
+
* `document` block: the image types, a PDF, and the text types (inlined, or sent as a document).
|
|
9
|
+
* Every other accepted type is a `file` attachment the model only ever gets a reference to.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isMediaContentType(ct: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The extension of a file name, lower case and without the dot: `null` when it has none or when the
|
|
14
|
+
* suffix is not an extension-shaped word (`a.`, `a.verylongsuffix`).
|
|
15
|
+
*/
|
|
16
|
+
export declare function attachmentExtension(name: string): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Whether a chat upload is accepted: its declared content type, or else the extension of its file
|
|
19
|
+
* name (`attachments.allowedExtensions`, for source files and office documents whose content types
|
|
20
|
+
* disagree across browsers and systems). The web applies the same rule before uploading.
|
|
21
|
+
*/
|
|
22
|
+
export declare function acceptedContent(cfg: {
|
|
23
|
+
allowedTypes: readonly string[];
|
|
24
|
+
allowedExtensions: readonly string[];
|
|
25
|
+
}, name: string, contentType: string): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DOCUMENT_MEDIA_TYPES, IMAGE_MEDIA_TYPES } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a chat attachment with this content type becomes an `image` block: one of the four image
|
|
4
|
+
* types a model can view.
|
|
5
|
+
*/
|
|
6
|
+
export function isImageContentType(ct) {
|
|
7
|
+
return IMAGE_MEDIA_TYPES.includes(ct);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether the model can consume the content itself, so the attachment becomes an `image` or
|
|
11
|
+
* `document` block: the image types, a PDF, and the text types (inlined, or sent as a document).
|
|
12
|
+
* Every other accepted type is a `file` attachment the model only ever gets a reference to.
|
|
13
|
+
*/
|
|
14
|
+
export function isMediaContentType(ct) {
|
|
15
|
+
return isImageContentType(ct) || DOCUMENT_MEDIA_TYPES.includes(ct);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The extension of a file name, lower case and without the dot: `null` when it has none or when the
|
|
19
|
+
* suffix is not an extension-shaped word (`a.`, `a.verylongsuffix`).
|
|
20
|
+
*/
|
|
21
|
+
export function attachmentExtension(name) {
|
|
22
|
+
const dot = name.lastIndexOf(".");
|
|
23
|
+
if (dot <= 0 || dot === name.length - 1)
|
|
24
|
+
return null;
|
|
25
|
+
const ext = name.slice(dot + 1).toLowerCase();
|
|
26
|
+
return /^[a-z0-9]{1,12}$/.test(ext) ? ext : null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether a chat upload is accepted: its declared content type, or else the extension of its file
|
|
30
|
+
* name (`attachments.allowedExtensions`, for source files and office documents whose content types
|
|
31
|
+
* disagree across browsers and systems). The web applies the same rule before uploading.
|
|
32
|
+
*/
|
|
33
|
+
export function acceptedContent(cfg, name, contentType) {
|
|
34
|
+
if (cfg.allowedTypes.includes(contentType))
|
|
35
|
+
return true;
|
|
36
|
+
const ext = attachmentExtension(name);
|
|
37
|
+
return ext !== null && cfg.allowedExtensions.includes(ext);
|
|
38
|
+
}
|
|
@@ -73,8 +73,10 @@ export interface QueuedFile {
|
|
|
73
73
|
attachmentId: string;
|
|
74
74
|
name: string;
|
|
75
75
|
mediaType: string;
|
|
76
|
+
/** The attachment's size in bytes when the block carries it (the chip shows it). */
|
|
77
|
+
size?: number;
|
|
76
78
|
}
|
|
77
|
-
/**
|
|
79
|
+
/** A queued message's fields (leftover items; tests seed them through the service). */
|
|
78
80
|
export interface QueueInput {
|
|
79
81
|
text: string;
|
|
80
82
|
clientMessageId: string;
|
|
@@ -135,8 +135,15 @@ let ConversationQueue = class ConversationQueue {
|
|
|
135
135
|
if (Number(n) >= QUEUE_MAX_ITEMS)
|
|
136
136
|
throw queueFull();
|
|
137
137
|
const blocks = await this.conversations.bindIn(orgId, conversationId, accountId, files);
|
|
138
|
-
const fileMeta = blocks.flatMap((b) => (b.type === "image" || b.type === "document") && b.source.kind === "ref"
|
|
139
|
-
? [
|
|
138
|
+
const fileMeta = blocks.flatMap((b) => (b.type === "image" || b.type === "document" || b.type === "file") && b.source.kind === "ref"
|
|
139
|
+
? [
|
|
140
|
+
{
|
|
141
|
+
attachmentId: b.source.attachmentId,
|
|
142
|
+
name: b.name ?? "",
|
|
143
|
+
mediaType: b.mediaType,
|
|
144
|
+
...(b.size !== undefined && { size: b.size }),
|
|
145
|
+
},
|
|
146
|
+
]
|
|
140
147
|
: []);
|
|
141
148
|
const row = await t
|
|
142
149
|
.insertInto("conversation_queue")
|
|
@@ -506,6 +506,12 @@ let TitleQueue = class TitleQueue {
|
|
|
506
506
|
const attempt = await titleAttemptDue(this.kdb.db, conversationId);
|
|
507
507
|
if (attempt === null)
|
|
508
508
|
return;
|
|
509
|
+
// The previous attempt claims its number before calling the model, so a run completing
|
|
510
|
+
// while that call is in flight would see the next attempt due and pay for a second title
|
|
511
|
+
// call. Its job stays in the shared queue until it finishes (removeOnComplete/Fail): wait
|
|
512
|
+
// for it; if it fails, the next completed run enqueues the next attempt.
|
|
513
|
+
if (attempt > 0 && (await this.queue.getJob(titleJobId(conversationId, attempt - 1))))
|
|
514
|
+
return;
|
|
509
515
|
await this.queue.add(JOB, { conversationId, attempt }, {
|
|
510
516
|
jobId: titleJobId(conversationId, attempt),
|
|
511
517
|
attempts: 1,
|
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -705,8 +705,7 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
|
|
|
705
705
|
/**
|
|
706
706
|
* A `file-preview@1` provider must be valid when it is provided (setup fails otherwise): the shape
|
|
707
707
|
* ({@link validateFilePreviewProvider}), and every `embed` names a ui contribution of this extension
|
|
708
|
-
* with `kind: "embed"` that resolved to the slot `file.preview
|
|
709
|
-
* `place`). A previewer whose embed names an embed contribution dropped at load (unknown slot or
|
|
708
|
+
* with `kind: "embed"` that resolved to the slot `file.preview`. A previewer whose embed names an embed contribution dropped at load (unknown slot or
|
|
710
709
|
* slot version, UI slots spec §3.2) is left out instead, with one warn per load: the returned
|
|
711
710
|
* provider is what the kernel serves.
|
|
712
711
|
*/
|
package/dist/ctx/secrets.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import type
|
|
2
|
+
import { type Kysely } from "kysely";
|
|
3
3
|
import type { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
4
|
import type { TransactionHost } from "../infra/database/transaction-host.js";
|
|
5
5
|
/** 主密钥环:current 用于新包装,previous 仅用于解包。原始密钥只存在于闭包内。 */
|
|
@@ -42,12 +42,29 @@ export type KernelSecrets = ExtensionContext["secrets"] & {
|
|
|
42
42
|
* `db` 可以是 Kysely 事务:此时读写(含首次创建组织数据密钥)都在该事务内。
|
|
43
43
|
*/
|
|
44
44
|
export declare function createSecrets(db: AnyDb, keyring: Keyring, namespace: string): KernelSecrets;
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
/** What {@link rewrapToCurrentMasterKey} rewrapped. */
|
|
46
|
+
export interface RewrapResult {
|
|
47
|
+
/** Org data keys (`org_data_keys`) now wrapped with the current master key. */
|
|
48
|
+
dataKeys: number;
|
|
49
|
+
/** Unexpired one-time initial passwords (`account_initial_passwords`) now sealed with it. */
|
|
50
|
+
initialPasswords: number;
|
|
51
|
+
}
|
|
52
|
+
/** Rows rewrapped per transaction by default. */
|
|
53
|
+
export declare const REWRAP_BATCH_SIZE = 500;
|
|
54
|
+
/** The AAD binding a sealed initial password to its account (a row moved to another one fails). */
|
|
55
|
+
export declare const initialPasswordAad: (accountId: string) => string;
|
|
56
|
+
type RewrapHandles = {
|
|
50
57
|
db: Pick<KernelDb, "db">;
|
|
51
58
|
txHost: Pick<TransactionHost, "run">;
|
|
52
|
-
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Rewraps everything sealed with a master key other than the keyring's current one (org data keys
|
|
62
|
+
* and unexpired initial passwords) with the current key, `batchSize` rows per transaction, until
|
|
63
|
+
* none is left. Checks first that the keyring holds every master key in use and throws (naming row
|
|
64
|
+
* ids and key ids, never key material) before writing anything when it does not. Idempotent: a
|
|
65
|
+
* second run finds nothing; concurrent runs lock the same rows and skip the ones already done.
|
|
66
|
+
*/
|
|
67
|
+
export declare function rewrapToCurrentMasterKey(handles: RewrapHandles, keyring: Keyring, opts?: {
|
|
68
|
+
batchSize?: number;
|
|
69
|
+
}): Promise<RewrapResult>;
|
|
53
70
|
export {};
|