@capybara-hq/kernel 0.1.0-rc.2 → 0.1.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/admin.controller.d.ts +9 -4
- package/dist/admin/admin.controller.js +13 -4
- package/dist/admin/extensions.controller.d.ts +8 -1
- package/dist/admin/extensions.controller.js +22 -2
- package/dist/agents/agent-lookup.d.ts +3 -0
- package/dist/agents/agent-lookup.js +20 -2
- package/dist/agents/agent-profile.service.d.ts +29 -0
- package/dist/agents/agent-profile.service.js +117 -0
- package/dist/agents/agents.controller.d.ts +93 -3
- package/dist/agents/agents.controller.js +114 -4
- package/dist/agents/agents.module.js +6 -2
- package/dist/agents/agents.service.d.ts +13 -5
- package/dist/agents/agents.service.js +49 -13
- package/dist/agents/definition.d.ts +35 -8
- package/dist/agents/definition.js +203 -17
- package/dist/agents/instruction-files.d.ts +60 -0
- package/dist/agents/instruction-files.js +111 -0
- package/dist/agents/models.controller.d.ts +9 -3
- package/dist/agents/models.controller.js +19 -4
- package/dist/agents/profile.d.ts +96 -0
- package/dist/agents/profile.js +51 -0
- package/dist/agents/readiness.controller.d.ts +26 -0
- package/dist/agents/readiness.controller.js +56 -0
- package/dist/agents/templates.js +20 -5
- package/dist/background/background.controller.d.ts +38 -0
- package/dist/background/background.controller.js +87 -0
- package/dist/background/background.module.d.ts +10 -0
- package/dist/background/background.module.js +32 -0
- package/dist/background/finish.d.ts +43 -0
- package/dist/background/finish.js +94 -0
- package/dist/background/launch-lock.d.ts +14 -0
- package/dist/background/launch-lock.js +39 -0
- package/dist/background/launch.d.ts +36 -0
- package/dist/background/launch.js +70 -0
- package/dist/background/poll.job.d.ts +53 -0
- package/dist/background/poll.job.js +182 -0
- package/dist/background/render.d.ts +23 -0
- package/dist/background/render.js +48 -0
- package/dist/background/session.d.ts +37 -0
- package/dist/background/session.js +66 -0
- package/dist/background/status.d.ts +35 -0
- package/dist/background/status.js +57 -0
- package/dist/background/stop.d.ts +62 -0
- package/dist/background/stop.js +225 -0
- package/dist/background/store.d.ts +150 -0
- package/dist/background/store.js +351 -0
- package/dist/background/store.module.d.ts +6 -0
- package/dist/background/store.module.js +22 -0
- package/dist/background/tasks.service.d.ts +67 -0
- package/dist/background/tasks.service.js +186 -0
- package/dist/background/wake-rules.d.ts +57 -0
- package/dist/background/wake-rules.js +83 -0
- package/dist/background/wake.d.ts +28 -0
- package/dist/background/wake.js +57 -0
- package/dist/catalog/catalog-content.js +4 -1
- package/dist/catalog/claude/agents.js +15 -10
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-import.js +1 -1
- package/dist/catalog/plugin-upgrade.js +1 -1
- package/dist/channels/cards.d.ts +8 -2
- package/dist/channels/cards.js +17 -9
- package/dist/channels/connections.service.d.ts +16 -1
- package/dist/channels/connections.service.js +38 -4
- package/dist/channels/threads.d.ts +5 -0
- package/dist/channels/threads.js +8 -0
- package/dist/config/schema.d.ts +18 -0
- package/dist/config/schema.js +104 -2
- package/dist/conversations/access.js +2 -0
- package/dist/conversations/artifacts.d.ts +1 -1
- package/dist/conversations/artifacts.js +1 -1
- package/dist/conversations/attachments.service.d.ts +30 -0
- package/dist/conversations/attachments.service.js +130 -5
- package/dist/conversations/conversations.controller.d.ts +36 -5
- package/dist/conversations/conversations.controller.js +62 -12
- package/dist/conversations/conversations.module.js +3 -0
- package/dist/conversations/conversations.service.d.ts +44 -2
- package/dist/conversations/conversations.service.js +140 -12
- package/dist/conversations/event-log.d.ts +12 -1
- package/dist/conversations/event-log.js +29 -1
- package/dist/conversations/events.d.ts +81 -3
- package/dist/conversations/events.js +83 -16
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.js +13 -2
- package/dist/conversations/queue.service.js +3 -1
- package/dist/conversations/titles.d.ts +7 -0
- package/dist/conversations/titles.js +15 -0
- package/dist/db/kernel-schema.d.ts +60 -4
- package/dist/db/pool.d.ts +5 -0
- package/dist/db/pool.js +3 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +8 -0
- package/dist/evals/recorded-tools.d.ts +27 -1
- package/dist/evals/recorded-tools.js +85 -10
- package/dist/evals/run-replay.d.ts +10 -2
- package/dist/evals/run-replay.js +49 -12
- package/dist/evals/step-replay.js +12 -6
- package/dist/evals/trajectory.d.ts +2 -2
- package/dist/evals/trajectory.js +1 -1
- package/dist/extensions/admin-ops.js +2 -0
- package/dist/extensions/admin-view.d.ts +3 -1
- package/dist/extensions/admin-view.js +10 -2
- package/dist/extensions/blobs.js +1 -0
- package/dist/extensions/config-issues.d.ts +13 -1
- package/dist/extensions/config-issues.js +22 -5
- package/dist/extensions/config-json-schema.d.ts +43 -7
- package/dist/extensions/config-json-schema.js +124 -58
- package/dist/extensions/deployment-config-store.d.ts +6 -0
- package/dist/extensions/deployment-config.d.ts +50 -3
- package/dist/extensions/deployment-config.js +125 -28
- package/dist/extensions/display-name.d.ts +22 -0
- package/dist/extensions/display-name.js +77 -0
- package/dist/extensions/extensions.module.js +6 -0
- package/dist/extensions/host.d.ts +26 -1
- package/dist/extensions/host.js +82 -9
- package/dist/extensions/org-config.controller.d.ts +11 -3
- package/dist/extensions/org-config.controller.js +14 -6
- package/dist/extensions/org-config.d.ts +6 -0
- package/dist/extensions/org-config.js +12 -13
- package/dist/extensions/package.d.ts +14 -1
- package/dist/extensions/package.js +51 -2
- package/dist/extensions/permission-view.d.ts +3 -0
- package/dist/extensions/point-defaults.controller.d.ts +34 -0
- package/dist/extensions/point-defaults.controller.js +71 -0
- package/dist/extensions/point-defaults.d.ts +64 -0
- package/dist/extensions/point-defaults.js +206 -0
- package/dist/extensions/registry.d.ts +1 -1
- package/dist/extensions/registry.js +2 -0
- package/dist/http/api.module.js +8 -0
- package/dist/http/nest-logger.d.ts +6 -5
- package/dist/http/nest-logger.js +24 -10
- package/dist/identity/auth.controller.js +9 -5
- package/dist/identity/cookies.d.ts +20 -5
- package/dist/identity/cookies.js +44 -6
- package/dist/identity/me.controller.d.ts +5 -1
- package/dist/identity/me.controller.js +12 -3
- package/dist/identity/sessions.d.ts +12 -0
- package/dist/identity/sessions.js +45 -0
- package/dist/identity/settings.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/infra/config/kernel-config.service.js +6 -0
- package/dist/infra/database/database.module.js +1 -0
- package/dist/infra/events/kernel-events.d.ts +8 -0
- package/dist/infra/lifecycle/process-guards.js +4 -0
- package/dist/infra/logging/logging.module.d.ts +4 -2
- package/dist/infra/logging/logging.module.js +24 -6
- package/dist/infra/queue/redis-connection.d.ts +6 -0
- package/dist/infra/queue/redis-connection.js +7 -0
- package/dist/infra/redis/redis.module.js +6 -2
- package/dist/infra/tokens.d.ts +6 -1
- package/dist/infra/tokens.js +6 -1
- package/dist/lifecycle/kernel-lifecycle.js +5 -0
- package/dist/log.d.ts +13 -1
- package/dist/log.js +93 -17
- package/dist/models/purposes.d.ts +23 -0
- package/dist/models/purposes.js +31 -10
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +26 -16
- package/dist/orgs/settings.service.d.ts +7 -2
- package/dist/orgs/settings.service.js +15 -4
- package/dist/roles/worker.module.js +6 -0
- package/dist/runtime/context/build.d.ts +15 -13
- package/dist/runtime/context/build.js +45 -27
- package/dist/runtime/context/claude-tools.d.ts +3 -1
- package/dist/runtime/context/claude-tools.js +12 -12
- package/dist/runtime/context/compaction.js +4 -0
- package/dist/runtime/context/legacy-text.d.ts +22 -0
- package/dist/runtime/context/legacy-text.js +37 -0
- package/dist/runtime/context/skills.d.ts +29 -11
- package/dist/runtime/context/skills.js +37 -30
- package/dist/runtime/langgraph-loop.js +3 -2
- package/dist/runtime/loop.d.ts +5 -4
- package/dist/runtime/maintenance.d.ts +4 -2
- package/dist/runtime/maintenance.js +17 -5
- package/dist/runtime/model-call.d.ts +17 -1
- package/dist/runtime/model-call.js +4 -3
- package/dist/runtime/providers.d.ts +6 -0
- package/dist/runtime/providers.js +8 -0
- package/dist/runtime/run-finish.d.ts +1 -1
- package/dist/runtime/run-queue.d.ts +28 -5
- package/dist/runtime/run-queue.js +131 -35
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +20 -7
- package/dist/runtime/runtime.module.js +8 -3
- package/dist/runtime/step-log.d.ts +6 -0
- package/dist/runtime/step-log.js +16 -2
- package/dist/runtime/subagents/definition.d.ts +1 -6
- package/dist/runtime/subagents/definition.js +14 -13
- package/dist/runtime/subagents/dispatch.d.ts +2 -2
- package/dist/runtime/subagents/dispatch.js +2 -2
- package/dist/runtime/subagents/org-agents.js +2 -1
- package/dist/runtime/subagents/roster.d.ts +1 -1
- package/dist/runtime/subagents/roster.js +1 -1
- package/dist/runtime/subagents/skill-fork.d.ts +2 -2
- package/dist/runtime/subagents/skill-fork.js +2 -2
- package/dist/runtime/subagents/subagents.service.d.ts +3 -3
- package/dist/runtime/subagents/subagents.service.js +3 -3
- package/dist/runtime/usage-report.d.ts +2 -1
- package/dist/runtime/usage-report.js +2 -1
- package/dist/runtime/waits.d.ts +13 -7
- package/dist/runtime/waits.js +42 -16
- package/dist/sandbox/sandbox.module.js +6 -1
- package/dist/sandbox/sandbox.service.d.ts +61 -3
- package/dist/sandbox/sandbox.service.js +141 -7
- package/dist/skills/catalog.d.ts +4 -4
- package/dist/skills/catalog.js +4 -4
- package/dist/skills/changes.service.d.ts +2 -2
- package/dist/skills/changes.service.js +5 -4
- package/dist/skills/invocation-keys.d.ts +1 -1
- package/dist/skills/invocation-keys.js +1 -1
- package/dist/skills/invoke.d.ts +1 -1
- package/dist/skills/invoke.js +5 -4
- package/dist/tools/approvals.service.d.ts +6 -0
- package/dist/tools/approvals.service.js +21 -1
- package/dist/tools/builtin-names.d.ts +91 -0
- package/dist/tools/builtin-names.js +143 -0
- package/dist/tools/builtins/agent.d.ts +7 -7
- package/dist/tools/builtins/agent.js +7 -11
- package/dist/tools/builtins/ask-user.d.ts +1 -1
- package/dist/tools/builtins/ask-user.js +2 -2
- package/dist/tools/builtins/builtin-tools.d.ts +17 -3
- package/dist/tools/builtins/builtin-tools.js +36 -4
- package/dist/tools/builtins/read-tool-output.d.ts +1 -1
- package/dist/tools/builtins/read-tool-output.js +2 -2
- package/dist/tools/builtins/sandbox/bash.d.ts +4 -4
- package/dist/tools/builtins/sandbox/bash.js +259 -29
- package/dist/tools/builtins/sandbox/common.d.ts +30 -7
- package/dist/tools/builtins/sandbox/common.js +9 -5
- package/dist/tools/builtins/sandbox/deliver.d.ts +1 -1
- package/dist/tools/builtins/sandbox/deliver.js +12 -12
- package/dist/tools/builtins/sandbox/edit.d.ts +1 -1
- package/dist/tools/builtins/sandbox/edit.js +41 -30
- package/dist/tools/builtins/sandbox/file-state.d.ts +34 -0
- package/dist/tools/builtins/sandbox/file-state.js +34 -0
- package/dist/tools/builtins/sandbox/glob-match.d.ts +1 -1
- package/dist/tools/builtins/sandbox/glob-match.js +1 -1
- package/dist/tools/builtins/sandbox/glob.d.ts +1 -1
- package/dist/tools/builtins/sandbox/glob.js +4 -4
- package/dist/tools/builtins/sandbox/grep.d.ts +7 -4
- package/dist/tools/builtins/sandbox/grep.js +147 -30
- package/dist/tools/builtins/sandbox/index.d.ts +3 -1
- package/dist/tools/builtins/sandbox/index.js +7 -1
- package/dist/tools/builtins/sandbox/read.d.ts +2 -2
- package/dist/tools/builtins/sandbox/read.js +21 -14
- package/dist/tools/builtins/sandbox/task-output.d.ts +63 -0
- package/dist/tools/builtins/sandbox/task-output.js +304 -0
- package/dist/tools/builtins/sandbox/task-stop.d.ts +10 -0
- package/dist/tools/builtins/sandbox/task-stop.js +112 -0
- package/dist/tools/builtins/sandbox/write.d.ts +1 -1
- package/dist/tools/builtins/sandbox/write.js +37 -33
- package/dist/tools/builtins/skill-load.d.ts +3 -3
- package/dist/tools/builtins/skill-load.js +32 -16
- package/dist/tools/builtins/skill-write.d.ts +4 -4
- package/dist/tools/builtins/skill-write.js +10 -10
- package/dist/tools/builtins/tool-search.d.ts +13 -9
- package/dist/tools/builtins/tool-search.js +25 -14
- package/dist/tools/builtins/web/errors.d.ts +8 -0
- package/dist/tools/builtins/web/errors.js +53 -0
- package/dist/tools/builtins/web/extract.d.ts +62 -0
- package/dist/tools/builtins/web/extract.js +267 -0
- package/dist/tools/builtins/web/fetch.d.ts +55 -0
- package/dist/tools/builtins/web/fetch.js +174 -0
- package/dist/tools/builtins/web/index.d.ts +13 -0
- package/dist/tools/builtins/web/index.js +12 -0
- package/dist/tools/builtins/web/page-cache.d.ts +25 -0
- package/dist/tools/builtins/web/page-cache.js +77 -0
- package/dist/tools/builtins/web/search.d.ts +25 -0
- package/dist/tools/builtins/web/search.js +209 -0
- package/dist/tools/builtins/web/url.d.ts +17 -0
- package/dist/tools/builtins/web/url.js +43 -0
- package/dist/tools/connectors.service.js +4 -4
- package/dist/tools/display-names.d.ts +9 -0
- package/dist/tools/display-names.js +24 -0
- package/dist/tools/drift.js +5 -5
- package/dist/tools/elicitation.js +1 -1
- package/dist/tools/info.d.ts +20 -4
- package/dist/tools/info.js +55 -32
- package/dist/tools/legacy-data.d.ts +34 -0
- package/dist/tools/legacy-data.js +76 -0
- package/dist/tools/legacy-keys.d.ts +51 -0
- package/dist/tools/legacy-keys.js +115 -0
- package/dist/tools/naming.d.ts +1 -5
- package/dist/tools/naming.js +1 -7
- package/dist/tools/oauth/flow-paths.d.ts +1 -1
- package/dist/tools/oauth/flow-paths.js +1 -1
- package/dist/tools/outputs.js +1 -1
- package/dist/tools/pipeline.d.ts +13 -7
- package/dist/tools/pipeline.js +112 -39
- package/dist/tools/policy.d.ts +1 -14
- package/dist/tools/policy.js +13 -19
- package/dist/tools/questions.controller.d.ts +1 -1
- package/dist/tools/questions.controller.js +1 -1
- package/dist/tools/questions.service.d.ts +1 -1
- package/dist/tools/registry.d.ts +38 -24
- package/dist/tools/registry.js +54 -47
- package/dist/tools/resources.d.ts +1 -1
- package/dist/tools/resources.js +1 -1
- package/dist/tools/tools.module.js +13 -1
- package/dist/tools/validate.js +1 -1
- package/package.json +3 -3
- package/src/migrations/0063_tool_keys_claude_code.sql +220 -0
- package/src/migrations/0064_account_last_org.sql +7 -0
- package/src/migrations/0065_conversation_archive.sql +8 -0
- package/src/migrations/0066_extension_display_name.sql +4 -0
- package/src/migrations/0067_agent_profiles.sql +20 -0
- package/src/migrations/0068_agent_avatar_uploads.sql +7 -0
- package/src/migrations/0069_attachments_agent_idx.sql +3 -0
- package/src/migrations/0070_background_tasks.sql +37 -0
- package/src/migrations/0071_background_tasks_reserve.sql +6 -0
- package/src/migrations/0072_background_tasks_stopping.sql +5 -0
- package/src/migrations/0073_org_extension_point_defaults.sql +11 -0
- package/dist/tools/builtins/sandbox/names.d.ts +0 -7
- package/dist/tools/builtins/sandbox/names.js +0 -20
|
@@ -7,30 +7,59 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { hasControlChars, MEDIA_NAME_MAX_CHARS } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { Controller, Delete, Get, HttpCode, Inject, Param, Patch, Post, Res } from "@nestjs/common";
|
|
11
12
|
import { z } from "zod";
|
|
13
|
+
import { AGENT_AVATAR_CONTENT_TYPES, AGENT_AVATAR_DOWNLOAD_TTL_SECONDS, AGENT_AVATAR_MAX_BYTES, AttachmentsService, } from "../conversations/attachments.service.js";
|
|
14
|
+
import { ApiError } from "../errors.js";
|
|
12
15
|
import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principal.js";
|
|
13
16
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
14
17
|
import { ZBody } from "../infra/validation/zod-params.js";
|
|
15
18
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
19
|
+
import { AgentProfileService } from "./agent-profile.service.js";
|
|
16
20
|
import { AGENT_VISIBILITIES, AgentsService, } from "./agents.service.js";
|
|
17
21
|
import { AgentDefinitionSchema, AgentToolRef, DEFAULT_AGENT_TOOLS } from "./definition.js";
|
|
22
|
+
import { ProfileInputSchema } from "./profile.js";
|
|
18
23
|
const MemberIds = z.array(z.string().min(1).max(100)).max(1000);
|
|
19
24
|
const OwnerBody = z.object({ accountId: z.string().min(1).max(100) }).strict();
|
|
20
25
|
/** 创建时未给 `tools` → 默认工具(Ruling P7);修改请求不注入默认值,版本里总是存显式的 tools。 */
|
|
26
|
+
/**
|
|
27
|
+
* `instructions` has no default in a request: with `instructionFiles` the kernel derives it, and a
|
|
28
|
+
* new agent given neither gets the `AGENTS.md` starter (`deriveInstructions`).
|
|
29
|
+
*/
|
|
30
|
+
const RequestInstructions = z.string().max(100_000).optional();
|
|
21
31
|
const CreateDefinition = AgentDefinitionSchema.extend({
|
|
32
|
+
instructions: RequestInstructions,
|
|
22
33
|
tools: z.array(AgentToolRef).default(() => structuredClone(DEFAULT_AGENT_TOOLS)),
|
|
23
34
|
});
|
|
35
|
+
const UpdateDefinition = AgentDefinitionSchema.extend({ instructions: RequestInstructions });
|
|
24
36
|
const CreateBody = z
|
|
25
37
|
.object({
|
|
26
38
|
definition: CreateDefinition,
|
|
27
39
|
visibility: z.enum(AGENT_VISIBILITIES),
|
|
28
40
|
memberIds: MemberIds.optional(),
|
|
41
|
+
/** Without an avatar the agent gets a random preset. */
|
|
42
|
+
profile: ProfileInputSchema.optional(),
|
|
43
|
+
})
|
|
44
|
+
.strict();
|
|
45
|
+
const ProfileBody = ProfileInputSchema.extend({
|
|
46
|
+
/** The `profile.updatedAt` the client read; a different one → 409 `agent.profile_conflict`. */
|
|
47
|
+
expectedUpdatedAt: z.string().min(1).max(40),
|
|
48
|
+
}).strict();
|
|
49
|
+
const AvatarUploadBody = z
|
|
50
|
+
.object({
|
|
51
|
+
name: z
|
|
52
|
+
.string()
|
|
53
|
+
.min(1)
|
|
54
|
+
.max(MEDIA_NAME_MAX_CHARS)
|
|
55
|
+
.refine((s) => !hasControlChars(s), "name must not contain control characters"),
|
|
56
|
+
contentType: z.enum(AGENT_AVATAR_CONTENT_TYPES),
|
|
57
|
+
size: z.number().int().min(1).max(AGENT_AVATAR_MAX_BYTES),
|
|
29
58
|
})
|
|
30
59
|
.strict();
|
|
31
60
|
const UpdateBody = z
|
|
32
61
|
.object({
|
|
33
|
-
definition:
|
|
62
|
+
definition: UpdateDefinition.optional(),
|
|
34
63
|
visibility: z.enum(AGENT_VISIBILITIES).optional(),
|
|
35
64
|
memberIds: MemberIds.optional(),
|
|
36
65
|
/**
|
|
@@ -46,6 +75,10 @@ class AgentCreateBodyDto extends createZodDto(CreateBody, "AgentCreateBody") {
|
|
|
46
75
|
}
|
|
47
76
|
class AgentUpdateBodyDto extends createZodDto(UpdateBody, "AgentUpdateBody") {
|
|
48
77
|
}
|
|
78
|
+
class AgentProfileBodyDto extends createZodDto(ProfileBody, "AgentProfileBody") {
|
|
79
|
+
}
|
|
80
|
+
class AgentAvatarUploadBodyDto extends createZodDto(AvatarUploadBody, "AgentAvatarUploadBody") {
|
|
81
|
+
}
|
|
49
82
|
class AgentOwnerBodyDto extends createZodDto(OwnerBody, "AgentOwnerBody") {
|
|
50
83
|
}
|
|
51
84
|
/**
|
|
@@ -54,8 +87,12 @@ class AgentOwnerBodyDto extends createZodDto(OwnerBody, "AgentOwnerBody") {
|
|
|
54
87
|
*/
|
|
55
88
|
let AgentsController = class AgentsController {
|
|
56
89
|
agents;
|
|
57
|
-
|
|
90
|
+
profiles;
|
|
91
|
+
attachments;
|
|
92
|
+
constructor(agents, profiles, attachments) {
|
|
58
93
|
this.agents = agents;
|
|
94
|
+
this.profiles = profiles;
|
|
95
|
+
this.attachments = attachments;
|
|
59
96
|
}
|
|
60
97
|
async create(principal, org, body) {
|
|
61
98
|
const p = requireUser(principal);
|
|
@@ -63,6 +100,7 @@ let AgentsController = class AgentsController {
|
|
|
63
100
|
definition: body.definition,
|
|
64
101
|
visibility: body.visibility,
|
|
65
102
|
...(body.memberIds !== undefined && { memberIds: body.memberIds }),
|
|
103
|
+
...(body.profile !== undefined && { profile: body.profile }),
|
|
66
104
|
}, patTokenId(p));
|
|
67
105
|
}
|
|
68
106
|
async list(principal, org) {
|
|
@@ -75,6 +113,52 @@ let AgentsController = class AgentsController {
|
|
|
75
113
|
const p = requireUser(principal);
|
|
76
114
|
return this.agents.update(org.orgId, agentId, p.account.id, body, patTokenId(p));
|
|
77
115
|
}
|
|
116
|
+
/** Display data only: no agent version. Same permission as `PATCH :agentId`. */
|
|
117
|
+
async updateProfile(principal, org, agentId, body) {
|
|
118
|
+
const p = requireUser(principal);
|
|
119
|
+
const { expectedUpdatedAt, ...patch } = body;
|
|
120
|
+
return {
|
|
121
|
+
profile: await this.profiles.update(org.orgId, agentId, p.account.id, patch, expectedUpdatedAt, patTokenId(p)),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Registers an avatar image upload (presigned, like chat attachments and skill packages): the
|
|
126
|
+
* browser uploads straight to the object store, then saves `{ kind: "upload", uploadId }` with
|
|
127
|
+
* the profile PATCH, which finalizes it. 503 `storage.unavailable` without an object store.
|
|
128
|
+
*/
|
|
129
|
+
async createAvatarUpload(principal, org, agentId, body) {
|
|
130
|
+
const p = requireUser(principal);
|
|
131
|
+
// the agent must exist and be visible to the caller (writing is checked when it is saved)
|
|
132
|
+
await this.agents.get(org.orgId, agentId, viewerOf(p));
|
|
133
|
+
return this.attachments.create(org.orgId, p.account.id, body, "agent-avatar");
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The avatar image: 302 to a short-lived presigned URL for an upload avatar, or to the stored
|
|
137
|
+
* URL of an external avatar when it is https; 404 for presets, no avatar, or an agent the
|
|
138
|
+
* reader cannot see.
|
|
139
|
+
*/
|
|
140
|
+
async avatar(principal, org, agentId, reply) {
|
|
141
|
+
const view = await this.agents.get(org.orgId, agentId, viewerOf(principal));
|
|
142
|
+
const avatar = view.profile.avatar;
|
|
143
|
+
let location = null;
|
|
144
|
+
if (avatar?.kind === "upload") {
|
|
145
|
+
location = await this.attachments.agentAvatarUrl(org.orgId, agentId, avatar.uploadId);
|
|
146
|
+
}
|
|
147
|
+
else if (avatar?.kind === "external") {
|
|
148
|
+
try {
|
|
149
|
+
if (new URL(avatar.url).protocol === "https:")
|
|
150
|
+
location = avatar.url;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// a malformed migrated URL: no image
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (location === null)
|
|
157
|
+
throw new ApiError("agent.not_found", "The agent has no avatar image");
|
|
158
|
+
await reply
|
|
159
|
+
.header("cache-control", `private, max-age=${Math.floor(AGENT_AVATAR_DOWNLOAD_TTL_SECONDS / 5)}`)
|
|
160
|
+
.redirect(location, 302);
|
|
161
|
+
}
|
|
78
162
|
async remove(principal, org, agentId) {
|
|
79
163
|
const p = requireUser(principal);
|
|
80
164
|
await this.agents.softDelete(org.orgId, agentId, p.account.id, patTokenId(p));
|
|
@@ -119,6 +203,30 @@ __decorate([
|
|
|
119
203
|
__param(2, Param("agentId")),
|
|
120
204
|
__param(3, ZBody(AgentUpdateBodyDto))
|
|
121
205
|
], AgentsController.prototype, "update", null);
|
|
206
|
+
__decorate([
|
|
207
|
+
Patch(":agentId/profile"),
|
|
208
|
+
OrgAction("agents.create"),
|
|
209
|
+
__param(0, CurrentPrincipal()),
|
|
210
|
+
__param(1, CurrentOrg()),
|
|
211
|
+
__param(2, Param("agentId")),
|
|
212
|
+
__param(3, ZBody(AgentProfileBodyDto))
|
|
213
|
+
], AgentsController.prototype, "updateProfile", null);
|
|
214
|
+
__decorate([
|
|
215
|
+
Post(":agentId/avatar/uploads"),
|
|
216
|
+
OrgAction("agents.create"),
|
|
217
|
+
__param(0, CurrentPrincipal()),
|
|
218
|
+
__param(1, CurrentOrg()),
|
|
219
|
+
__param(2, Param("agentId")),
|
|
220
|
+
__param(3, ZBody(AgentAvatarUploadBodyDto))
|
|
221
|
+
], AgentsController.prototype, "createAvatarUpload", null);
|
|
222
|
+
__decorate([
|
|
223
|
+
Get(":agentId/avatar"),
|
|
224
|
+
OrgAction("agents.use"),
|
|
225
|
+
__param(0, CurrentPrincipal()),
|
|
226
|
+
__param(1, CurrentOrg()),
|
|
227
|
+
__param(2, Param("agentId")),
|
|
228
|
+
__param(3, Res())
|
|
229
|
+
], AgentsController.prototype, "avatar", null);
|
|
122
230
|
__decorate([
|
|
123
231
|
Delete(":agentId"),
|
|
124
232
|
HttpCode(204),
|
|
@@ -145,6 +253,8 @@ __decorate([
|
|
|
145
253
|
], AgentsController.prototype, "versions", null);
|
|
146
254
|
AgentsController = __decorate([
|
|
147
255
|
Controller("api/v1/orgs/:orgId/agents"),
|
|
148
|
-
__param(0, Inject(AgentsService))
|
|
256
|
+
__param(0, Inject(AgentsService)),
|
|
257
|
+
__param(1, Inject(AgentProfileService)),
|
|
258
|
+
__param(2, Inject(AttachmentsService))
|
|
149
259
|
], AgentsController);
|
|
150
260
|
export { AgentsController };
|
|
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
|
+
import { AttachmentsModule } from "../conversations/attachments.module.js";
|
|
8
9
|
import { EvalBudgetModule } from "../evals/budget.js";
|
|
9
10
|
import { OrgLockModule } from "../orgs/org-lock.js";
|
|
10
11
|
import { ProvidersModule } from "../runtime/providers.js";
|
|
@@ -12,6 +13,7 @@ import { SandboxModule } from "../sandbox/sandbox.module.js";
|
|
|
12
13
|
import { SkillsModule } from "../skills/skills.module.js";
|
|
13
14
|
import { ToolsModule } from "../tools/tools.module.js";
|
|
14
15
|
import { AgentLookupModule } from "./agent-lookup.js";
|
|
16
|
+
import { AgentProfileService } from "./agent-profile.service.js";
|
|
15
17
|
import { AgentsService } from "./agents.service.js";
|
|
16
18
|
import { AgentTemplatesService } from "./templates.js";
|
|
17
19
|
/**
|
|
@@ -25,6 +27,8 @@ AgentsModule = __decorate([
|
|
|
25
27
|
Module({
|
|
26
28
|
imports: [
|
|
27
29
|
AgentLookupModule,
|
|
30
|
+
// avatar uploads
|
|
31
|
+
AttachmentsModule,
|
|
28
32
|
OrgLockModule,
|
|
29
33
|
ProvidersModule,
|
|
30
34
|
SkillsModule,
|
|
@@ -34,8 +38,8 @@ AgentsModule = __decorate([
|
|
|
34
38
|
// cancels the deleted agent's eval runs
|
|
35
39
|
EvalBudgetModule,
|
|
36
40
|
],
|
|
37
|
-
providers: [AgentsService, AgentTemplatesService],
|
|
38
|
-
exports: [AgentLookupModule, AgentsService, AgentTemplatesService],
|
|
41
|
+
providers: [AgentsService, AgentProfileService, AgentTemplatesService],
|
|
42
|
+
exports: [AgentLookupModule, AgentsService, AgentProfileService, AgentTemplatesService],
|
|
39
43
|
})
|
|
40
44
|
], AgentsModule);
|
|
41
45
|
export { AgentsModule };
|
|
@@ -10,6 +10,8 @@ import { SkillChangesService } from "../skills/changes.service.js";
|
|
|
10
10
|
import { ToolRegistry } from "../tools/registry.js";
|
|
11
11
|
import { AgentLookup, type AgentView, type AgentVisibility } from "./agent-lookup.js";
|
|
12
12
|
import { type AgentDefinition } from "./definition.js";
|
|
13
|
+
import { type AgentDefinitionInput } from "./instruction-files.js";
|
|
14
|
+
import { type ProfileInput } from "./profile.js";
|
|
13
15
|
export { AGENT_VISIBILITIES, type AgentView, type AgentVisibility, isAgentVisibleTo, visibleTo, } from "./agent-lookup.js";
|
|
14
16
|
export { paramIssues, SUBAGENT_ROSTER_MAX } from "./definition.js";
|
|
15
17
|
export interface AgentVersion {
|
|
@@ -21,6 +23,8 @@ export interface AgentVersion {
|
|
|
21
23
|
export type AgentVersionSummary = Omit<AgentVersion, "definition">;
|
|
22
24
|
/** 创建 / 修改的提示(不拒绝):`fallback_same_provider` = 兜底与主模型同一供应商(spec 4.5)。 */
|
|
23
25
|
export type AgentWarning = "fallback_same_provider";
|
|
26
|
+
/** A new agent has no id to bind an upload to yet: a client can only choose a preset on create. */
|
|
27
|
+
export declare function assertProfileWritable(profile: ProfileInput | undefined): void;
|
|
24
28
|
/** Why a `subagents` block is refused (`agent.subagents_invalid` details). */
|
|
25
29
|
export type SubagentsProblem = "not_found" | "invalid_name" | "duplicate" | "tool_not_selected" | "skill_not_selected" | "agent_not_available" | "self" | "too_many";
|
|
26
30
|
/**
|
|
@@ -104,10 +108,11 @@ export declare class AgentsService {
|
|
|
104
108
|
* 新建 agent(版本 1):在组织行锁内授权 `agents.create`;主模型与兜底都必须可解析
|
|
105
109
|
* (`agent.model_unavailable`);兜底与主模型同一供应商只提示 `fallback_same_provider`。
|
|
106
110
|
*/
|
|
107
|
-
create(orgId: string, actorAccountId: string,
|
|
108
|
-
definition:
|
|
111
|
+
create(orgId: string, actorAccountId: string, request: {
|
|
112
|
+
definition: AgentDefinitionInput;
|
|
109
113
|
visibility: AgentVisibility;
|
|
110
114
|
memberIds?: string[];
|
|
115
|
+
profile?: ProfileInput;
|
|
111
116
|
}, actorTokenId?: string): Promise<{
|
|
112
117
|
agent: AgentView;
|
|
113
118
|
warnings: AgentWarning[];
|
|
@@ -117,13 +122,16 @@ export declare class AgentsService {
|
|
|
117
122
|
* 锁组织行并复核发起人,再锁 agent 行:发起人须仍具备 `agents.create`(member 以上),且是负责人或组织管理员以上;
|
|
118
123
|
* 对发起人不可见的 agent(非管理员)→ `agent.not_found`,可见但无权 → `forbidden`。
|
|
119
124
|
*/
|
|
120
|
-
|
|
125
|
+
lockForWrite(orgId: string, agentId: string, actorAccountId: string): Promise<{
|
|
126
|
+
visibility: AgentVisibility;
|
|
127
|
+
current_version: number;
|
|
128
|
+
}>;
|
|
121
129
|
/**
|
|
122
130
|
* 修改 agent:`definition` 变化时写新版本(`current_version + 1`),只改 visibility / memberIds 不产生新版本。
|
|
123
131
|
* 只有负责人或组织管理员以上可改,在组织行锁内复核。
|
|
124
132
|
*/
|
|
125
|
-
update(orgId: string, agentId: string, actorAccountId: string,
|
|
126
|
-
definition?:
|
|
133
|
+
update(orgId: string, agentId: string, actorAccountId: string, request: {
|
|
134
|
+
definition?: AgentDefinitionInput | undefined;
|
|
127
135
|
visibility?: AgentVisibility | undefined;
|
|
128
136
|
memberIds?: string[] | undefined;
|
|
129
137
|
/**
|
|
@@ -24,13 +24,22 @@ import { ProviderRegistry } from "../runtime/providers.js";
|
|
|
24
24
|
import { SandboxJobs } from "../sandbox/jobs.js";
|
|
25
25
|
import { SkillChangesService } from "../skills/changes.service.js";
|
|
26
26
|
import { assertOrgSkills, assertPinnedSkills } from "../skills/skills.service.js";
|
|
27
|
+
import { legacyKeySaveText } from "../tools/legacy-keys.js";
|
|
27
28
|
import { ToolRegistry } from "../tools/registry.js";
|
|
28
29
|
import { AgentLookup, isAgentVisibleTo, visibleTo, } from "./agent-lookup.js";
|
|
29
30
|
import { normalizeStoredDefinition, paramIssues, SUBAGENT_NAME_RE, SUBAGENT_ROSTER_MAX, } from "./definition.js";
|
|
31
|
+
import { deriveInstructions } from "./instruction-files.js";
|
|
32
|
+
import { randomPreset } from "./profile.js";
|
|
30
33
|
export { AGENT_VISIBILITIES, isAgentVisibleTo, visibleTo, } from "./agent-lookup.js";
|
|
31
34
|
export { paramIssues, SUBAGENT_ROSTER_MAX } from "./definition.js";
|
|
32
35
|
/** 删除 agent 时每个销毁任务带的对话数。 */
|
|
33
36
|
const SANDBOX_DESTROY_BATCH = 500;
|
|
37
|
+
/** A new agent has no id to bind an upload to yet: a client can only choose a preset on create. */
|
|
38
|
+
export function assertProfileWritable(profile) {
|
|
39
|
+
if (profile?.avatar?.kind === "upload") {
|
|
40
|
+
throw new ApiError("validation_failed", "Choose a preset avatar when creating an agent; upload one afterwards", [{ path: "avatar.kind", message: "upload is not supported on create" }]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
34
43
|
const notFound = () => new ApiError("agent.not_found", "Agent not found");
|
|
35
44
|
/** 键排序后的 JSON:jsonb 不保留键顺序,比较定义是否变化时用。 */
|
|
36
45
|
function canonical(v) {
|
|
@@ -67,8 +76,13 @@ export async function assertSubagents(t, a) {
|
|
|
67
76
|
if (sub === undefined)
|
|
68
77
|
return;
|
|
69
78
|
const details = [];
|
|
70
|
-
const add = (reason, path, value) => {
|
|
71
|
-
details.push({
|
|
79
|
+
const add = (reason, path, value, message) => {
|
|
80
|
+
details.push({
|
|
81
|
+
reason,
|
|
82
|
+
path,
|
|
83
|
+
...(value !== undefined && { value }),
|
|
84
|
+
...(message !== undefined && { message }),
|
|
85
|
+
});
|
|
72
86
|
};
|
|
73
87
|
const types = new Set(sub.general === false ? [] : ["general-purpose"]);
|
|
74
88
|
const claim = (type, path) => {
|
|
@@ -123,8 +137,11 @@ export async function assertSubagents(t, a) {
|
|
|
123
137
|
const base = `subagents.inline.${i}`;
|
|
124
138
|
name(x.name, `${base}.name`);
|
|
125
139
|
const tool = (key, path) => {
|
|
126
|
-
if (
|
|
127
|
-
|
|
140
|
+
if (a.toolKeys.has(key))
|
|
141
|
+
return;
|
|
142
|
+
// an rc key names its current key(s) (tool naming spec §8.3)
|
|
143
|
+
const renamed = legacyKeySaveText(key, a.toolKeys);
|
|
144
|
+
add("tool_not_selected", path, key, renamed ?? undefined);
|
|
128
145
|
};
|
|
129
146
|
for (const [j, key] of (x.tools ?? []).entries())
|
|
130
147
|
tool(key, `${base}.tools.${j}`);
|
|
@@ -167,7 +184,9 @@ export async function assertSubagents(t, a) {
|
|
|
167
184
|
if (count > SUBAGENT_ROSTER_MAX)
|
|
168
185
|
add("too_many", "subagents");
|
|
169
186
|
if (details.length > 0) {
|
|
170
|
-
throw new ApiError("agent.subagents_invalid", `Invalid sub-agents: ${details
|
|
187
|
+
throw new ApiError("agent.subagents_invalid", `Invalid sub-agents: ${details
|
|
188
|
+
.map((d) => `${d.path} (${d.reason}${d.message === undefined ? "" : `: ${d.message}`})`)
|
|
189
|
+
.join(", ")}`, details);
|
|
171
190
|
}
|
|
172
191
|
}
|
|
173
192
|
/**
|
|
@@ -220,9 +239,11 @@ let AgentsService = class AgentsService {
|
|
|
220
239
|
const details = [...issues];
|
|
221
240
|
for (const key of Object.keys(def.toolPolicies)) {
|
|
222
241
|
if (!keys.has(key)) {
|
|
242
|
+
// an rc key (tool naming spec §8.3): saving writes current keys only, so name them
|
|
243
|
+
const renamed = legacyKeySaveText(key, keys);
|
|
223
244
|
details.push({
|
|
224
245
|
path: `toolPolicies.${key}`,
|
|
225
|
-
message: `"${key}" is not a tool of this agent`,
|
|
246
|
+
message: renamed ?? `"${key}" is not a tool of this agent`,
|
|
226
247
|
});
|
|
227
248
|
}
|
|
228
249
|
}
|
|
@@ -279,13 +300,15 @@ let AgentsService = class AgentsService {
|
|
|
279
300
|
* 新建 agent(版本 1):在组织行锁内授权 `agents.create`;主模型与兜底都必须可解析
|
|
280
301
|
* (`agent.model_unavailable`);兜底与主模型同一供应商只提示 `fallback_same_provider`。
|
|
281
302
|
*/
|
|
282
|
-
async create(orgId, actorAccountId,
|
|
303
|
+
async create(orgId, actorAccountId, request, actorTokenId) {
|
|
304
|
+
const input = { ...request, definition: deriveInstructions(request.definition, null) };
|
|
283
305
|
// 先解析模型(可能访问供应商),不在持有组织行锁时做
|
|
284
306
|
const warnings = await this.checkModels(input.definition);
|
|
285
307
|
const toolKeys = await this.checkTools(orgId, input.definition);
|
|
286
308
|
if (input.visibility !== "members" && (input.memberIds?.length ?? 0) > 0) {
|
|
287
309
|
throw new ApiError("validation_failed", "memberIds requires visibility 'members'");
|
|
288
310
|
}
|
|
311
|
+
assertProfileWritable(input.profile);
|
|
289
312
|
const agent = await this.createIn(orgId, actorAccountId, input, toolKeys, actorTokenId);
|
|
290
313
|
return { agent, warnings };
|
|
291
314
|
}
|
|
@@ -313,6 +336,9 @@ let AgentsService = class AgentsService {
|
|
|
313
336
|
owner_account_id: actorAccountId,
|
|
314
337
|
visibility: input.visibility,
|
|
315
338
|
current_version: 1,
|
|
339
|
+
profile_avatar: JSON.stringify(input.profile?.avatar ?? { kind: "preset", id: randomPreset() }),
|
|
340
|
+
profile_description: input.profile?.description ?? "",
|
|
341
|
+
profile_quick_actions: JSON.stringify(input.profile?.quickActions ?? []),
|
|
316
342
|
})
|
|
317
343
|
.execute();
|
|
318
344
|
await t
|
|
@@ -370,7 +396,8 @@ let AgentsService = class AgentsService {
|
|
|
370
396
|
* 修改 agent:`definition` 变化时写新版本(`current_version + 1`),只改 visibility / memberIds 不产生新版本。
|
|
371
397
|
* 只有负责人或组织管理员以上可改,在组织行锁内复核。
|
|
372
398
|
*/
|
|
373
|
-
async update(orgId, agentId, actorAccountId,
|
|
399
|
+
async update(orgId, agentId, actorAccountId, request, actorTokenId) {
|
|
400
|
+
const patch = request;
|
|
374
401
|
const warnings = patch.definition ? await this.checkModels(patch.definition) : [];
|
|
375
402
|
const toolKeys = patch.definition ? await this.checkTools(orgId, patch.definition) : null;
|
|
376
403
|
const agent = await this.updateIn(orgId, agentId, actorAccountId, patch, toolKeys, actorTokenId);
|
|
@@ -394,26 +421,28 @@ let AgentsService = class AgentsService {
|
|
|
394
421
|
.where("agent_id", "=", agentId)
|
|
395
422
|
.where("version", "=", before.current_version)
|
|
396
423
|
.executeTakeFirstOrThrow();
|
|
424
|
+
// the prompt: instructionFiles give instructions; a save given neither keeps the current one
|
|
425
|
+
const definition = deriveInstructions(patch.definition, normalizeStoredDefinition(current.definition));
|
|
397
426
|
// 当前版本已有的技能引用保存时合法,不再核对(被删的技能不挡住其他改动);新加的照常核对
|
|
398
427
|
const kept = new Set(current.definition.skills?.orgSkills ?? []);
|
|
399
|
-
await assertOrgSkills(t, orgId,
|
|
400
|
-
await assertPinnedSkills(t, orgId, agentId,
|
|
428
|
+
await assertOrgSkills(t, orgId, definition.skills?.orgSkills ?? [], kept);
|
|
429
|
+
await assertPinnedSkills(t, orgId, agentId, definition.skills, current.definition.skills?.pinned ?? []);
|
|
401
430
|
await assertSubagents(t, {
|
|
402
431
|
orgId,
|
|
403
432
|
agentId,
|
|
404
433
|
actorAccountId,
|
|
405
|
-
definition
|
|
434
|
+
definition,
|
|
406
435
|
toolKeys: toolKeys ?? new Set(),
|
|
407
436
|
kept: current.definition.subagents,
|
|
408
437
|
});
|
|
409
|
-
if (canonical(current.definition) !== canonical(
|
|
438
|
+
if (canonical(current.definition) !== canonical(definition)) {
|
|
410
439
|
toVersion = before.current_version + 1;
|
|
411
440
|
await t
|
|
412
441
|
.insertInto("agent_versions")
|
|
413
442
|
.values({
|
|
414
443
|
agent_id: agentId,
|
|
415
444
|
version: toVersion,
|
|
416
|
-
definition: JSON.stringify(
|
|
445
|
+
definition: JSON.stringify(definition),
|
|
417
446
|
created_by: actorAccountId,
|
|
418
447
|
})
|
|
419
448
|
.execute();
|
|
@@ -460,6 +489,13 @@ let AgentsService = class AgentsService {
|
|
|
460
489
|
.set({ deleted_at: sql `now()`, updated_at: sql `now()` })
|
|
461
490
|
.where("id", "=", agentId)
|
|
462
491
|
.execute();
|
|
492
|
+
// the avatar upload is garbage now: the cleanup job deletes it (and its object) once expired
|
|
493
|
+
await t
|
|
494
|
+
.updateTable("attachments")
|
|
495
|
+
.set({ expires_at: sql `now()` })
|
|
496
|
+
.where("agent_id", "=", agentId)
|
|
497
|
+
.where("purpose", "=", "agent-avatar")
|
|
498
|
+
.execute();
|
|
463
499
|
await audit(t, {
|
|
464
500
|
actorAccountId,
|
|
465
501
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ModelParameter } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { type LegacyScope } from "../tools/legacy-keys.js";
|
|
3
4
|
/** 模型引用:供应商插件名 + 模型 id。 */
|
|
4
5
|
export declare const ModelRef: z.ZodObject<{
|
|
5
6
|
provider: z.ZodString;
|
|
@@ -34,11 +35,7 @@ export declare const AgentToolRef: z.ZodPreprocess<z.ZodDiscriminatedUnion<[z.Zo
|
|
|
34
35
|
tools: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodArray<z.ZodString>]>;
|
|
35
36
|
}, z.core.$strict>], "kind">, unknown>;
|
|
36
37
|
export type AgentToolRef = z.output<typeof AgentToolRef>;
|
|
37
|
-
|
|
38
|
-
* 新建 agent 未给 `tools` 时的默认工具(`tool_search` 由注册表按组织设置自动加入,不进定义)。
|
|
39
|
-
* 只用于创建请求;修改与读出旧版本都不注入默认值。
|
|
40
|
-
*/
|
|
41
|
-
export declare const DEFAULT_AGENT_TOOLS: AgentToolRef[];
|
|
38
|
+
export { DEFAULT_AGENT_TOOLS } from "../tools/builtin-names.js";
|
|
42
39
|
/** Roster names of inline templates and allowlisted org agents (the template name rule). */
|
|
43
40
|
export declare const SUBAGENT_NAME_RE: RegExp;
|
|
44
41
|
/**
|
|
@@ -75,7 +72,7 @@ export declare const InlineAgentTemplate: z.ZodObject<{
|
|
|
75
72
|
}, z.core.$strict>;
|
|
76
73
|
export type InlineAgentTemplate = z.infer<typeof InlineAgentTemplate>;
|
|
77
74
|
/**
|
|
78
|
-
* Sub-agents this agent may dispatch with the builtin `
|
|
75
|
+
* Sub-agents this agent may dispatch with the builtin `Agent` tool (phase C, spec §5.2). No
|
|
79
76
|
* default: definitions without it are unchanged and gain no version.
|
|
80
77
|
*/
|
|
81
78
|
export declare const SubagentsSchema: z.ZodObject<{
|
|
@@ -120,6 +117,10 @@ export declare const AgentDefinitionSchema: z.ZodObject<{
|
|
|
120
117
|
name: z.ZodString;
|
|
121
118
|
avatarUrl: z.ZodDefault<z.ZodNullable<z.ZodURL>>;
|
|
122
119
|
instructions: z.ZodDefault<z.ZodString>;
|
|
120
|
+
instructionFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
121
|
+
name: z.ZodString;
|
|
122
|
+
content: z.ZodString;
|
|
123
|
+
}, z.core.$strict>>>;
|
|
123
124
|
model: z.ZodObject<{
|
|
124
125
|
provider: z.ZodString;
|
|
125
126
|
model: z.ZodString;
|
|
@@ -192,11 +193,37 @@ export declare const AgentDefinitionSchema: z.ZodObject<{
|
|
|
192
193
|
}, z.core.$strict>>;
|
|
193
194
|
}, z.core.$strip>;
|
|
194
195
|
export type AgentDefinition = z.infer<typeof AgentDefinitionSchema>;
|
|
196
|
+
/** The connectors and extensions a definition's own tool refs name (to read an ambiguous rc key). */
|
|
197
|
+
interface OwnRefs {
|
|
198
|
+
connectors: ReadonlySet<string>;
|
|
199
|
+
extensions: ReadonlySet<string>;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Release-candidate tool keys in a stored definition, read as current keys (tool naming spec
|
|
203
|
+
* §8.3), the way {@link normalizeToolRef} reads the app -> connector rename: builtin refs in
|
|
204
|
+
* `tools`, the keys of `toolPolicies`, and the `tools` / `disallowedTools` / `toolPolicies` of a
|
|
205
|
+
* template, the agent's inline sub-agent templates included. Works on an agent definition and on
|
|
206
|
+
* an agent template alike. Old builtin names map without `scope`; an rc `<x>__<tool>` key maps
|
|
207
|
+
* only with one (the org's connector slugs and their ids, the deployment's extension names). When
|
|
208
|
+
* `x` is both a slug and an extension name, the definition's own tool refs decide; when they
|
|
209
|
+
* cannot, a policy or a deny list keeps the restriction on both candidate keys (a deny is never
|
|
210
|
+
* lost) and an allowlist keeps the old key (inert). An unknown key stays as it is. Keys in the
|
|
211
|
+
* current format are never touched. Returns the same object when nothing changes. Saving never
|
|
212
|
+
* goes through this: a new definition with an old key is refused (`AgentsService`).
|
|
213
|
+
*/
|
|
214
|
+
export declare function normalizeToolKeys(definition: unknown, scope?: LegacyScope, inherited?: OwnRefs): unknown;
|
|
215
|
+
/**
|
|
216
|
+
* Does a stored definition or template hold an rc `<x>__<tool>` key, which only a
|
|
217
|
+
* {@link LegacyScope} can map? (Callers load the scope only then.)
|
|
218
|
+
*/
|
|
219
|
+
export declare function needsLegacyScope(definition: unknown): boolean;
|
|
195
220
|
/**
|
|
196
221
|
* 库里读出的定义(`agent_versions.definition`,不经 zod 解析):把改名前的 `{ kind: "app" }` 工具引用规范化为
|
|
197
|
-
* connector 形(C27
|
|
222
|
+
* connector 形(C27),and rc tool keys to current keys ({@link normalizeToolKeys}: builtins
|
|
223
|
+
* always, `<x>__<tool>` keys with `scope`). Other fields are kept; without old forms the same
|
|
224
|
+
* object is returned.
|
|
198
225
|
*/
|
|
199
|
-
export declare function normalizeStoredDefinition(def: unknown): AgentDefinition;
|
|
226
|
+
export declare function normalizeStoredDefinition(def: unknown, scope?: LegacyScope): AgentDefinition;
|
|
200
227
|
/** 按模型声明严格校验一组参数,返回 `{ path: "<field>.<key>", message }[]`(评测候选也用它)。 */
|
|
201
228
|
export declare function paramIssues(field: string, decl: ModelParameter[], params: Record<string, unknown>): {
|
|
202
229
|
path: string;
|