@clinebot/core 0.0.18 → 0.0.21
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/account/cline-account-service.d.ts +3 -2
- package/dist/account/cline-account-service.d.ts.map +1 -0
- package/dist/account/index.d.ts +1 -0
- package/dist/account/index.d.ts.map +1 -0
- package/dist/account/rpc.d.ts +1 -0
- package/dist/account/rpc.d.ts.map +1 -0
- package/dist/account/types.d.ts +1 -0
- package/dist/account/types.d.ts.map +1 -0
- package/dist/agents/agent-config-loader.d.ts +1 -0
- package/dist/agents/agent-config-loader.d.ts.map +1 -0
- package/dist/agents/agent-config-parser.d.ts +1 -0
- package/dist/agents/agent-config-parser.d.ts.map +1 -0
- package/dist/agents/hooks-config-loader.d.ts +1 -0
- package/dist/agents/hooks-config-loader.d.ts.map +1 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/plugin-config-loader.d.ts +1 -0
- package/dist/agents/plugin-config-loader.d.ts.map +1 -0
- package/dist/agents/plugin-loader.d.ts +1 -0
- package/dist/agents/plugin-loader.d.ts.map +1 -0
- package/dist/agents/plugin-sandbox.d.ts +1 -0
- package/dist/agents/plugin-sandbox.d.ts.map +1 -0
- package/dist/agents/unified-config-file-watcher.d.ts +1 -0
- package/dist/agents/unified-config-file-watcher.d.ts.map +1 -0
- package/dist/agents/user-instruction-config-loader.d.ts +1 -0
- package/dist/agents/user-instruction-config-loader.d.ts.map +1 -0
- package/dist/auth/client.d.ts +1 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/cline.d.ts +1 -0
- package/dist/auth/cline.d.ts.map +1 -0
- package/dist/auth/codex.d.ts +1 -0
- package/dist/auth/codex.d.ts.map +1 -0
- package/dist/auth/oca.d.ts +1 -0
- package/dist/auth/oca.d.ts.map +1 -0
- package/dist/auth/server.d.ts +1 -0
- package/dist/auth/server.d.ts.map +1 -0
- package/dist/auth/types.d.ts +1 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/utils.d.ts +1 -0
- package/dist/auth/utils.d.ts.map +1 -0
- package/dist/chat/chat-schema.d.ts +13 -12
- package/dist/chat/chat-schema.d.ts.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.node.d.ts +2 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/index.node.js +303 -302
- package/dist/input/file-indexer.d.ts +1 -0
- package/dist/input/file-indexer.d.ts.map +1 -0
- package/dist/input/index.d.ts +1 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/mention-enricher.d.ts +1 -0
- package/dist/input/mention-enricher.d.ts.map +1 -0
- package/dist/mcp/config-loader.d.ts +1 -0
- package/dist/mcp/config-loader.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/manager.d.ts +1 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/types.d.ts +1 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/providers/local-provider-registry.d.ts +36 -0
- package/dist/providers/local-provider-registry.d.ts.map +1 -0
- package/dist/providers/local-provider-service.d.ts +2 -1
- package/dist/providers/local-provider-service.d.ts.map +1 -0
- package/dist/runtime/commands.d.ts +1 -0
- package/dist/runtime/commands.d.ts.map +1 -0
- package/dist/runtime/hook-file-hooks.d.ts +1 -0
- package/dist/runtime/hook-file-hooks.d.ts.map +1 -0
- package/dist/runtime/rules.d.ts +1 -0
- package/dist/runtime/rules.d.ts.map +1 -0
- package/dist/runtime/runtime-builder.d.ts +1 -0
- package/dist/runtime/runtime-builder.d.ts.map +1 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts +1 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts.map +1 -0
- package/dist/runtime/session-runtime.d.ts +2 -0
- package/dist/runtime/session-runtime.d.ts.map +1 -0
- package/dist/runtime/skills.d.ts +1 -0
- package/dist/runtime/skills.d.ts.map +1 -0
- package/dist/runtime/tool-approval.d.ts +1 -0
- package/dist/runtime/tool-approval.d.ts.map +1 -0
- package/dist/runtime/workflows.d.ts +1 -0
- package/dist/runtime/workflows.d.ts.map +1 -0
- package/dist/session/default-session-manager.d.ts +4 -0
- package/dist/session/default-session-manager.d.ts.map +1 -0
- package/dist/session/file-session-service.d.ts +1 -0
- package/dist/session/file-session-service.d.ts.map +1 -0
- package/dist/session/rpc-session-service.d.ts +1 -0
- package/dist/session/rpc-session-service.d.ts.map +1 -0
- package/dist/session/rpc-spawn-lease.d.ts +1 -0
- package/dist/session/rpc-spawn-lease.d.ts.map +1 -0
- package/dist/session/runtime-oauth-token-manager.d.ts +1 -0
- package/dist/session/runtime-oauth-token-manager.d.ts.map +1 -0
- package/dist/session/session-agent-events.d.ts +20 -1
- package/dist/session/session-agent-events.d.ts.map +1 -0
- package/dist/session/session-artifacts.d.ts +1 -0
- package/dist/session/session-artifacts.d.ts.map +1 -0
- package/dist/session/session-config-builder.d.ts +1 -0
- package/dist/session/session-config-builder.d.ts.map +1 -0
- package/dist/session/session-graph.d.ts +1 -0
- package/dist/session/session-graph.d.ts.map +1 -0
- package/dist/session/session-host.d.ts +1 -0
- package/dist/session/session-host.d.ts.map +1 -0
- package/dist/session/session-manager.d.ts +1 -0
- package/dist/session/session-manager.d.ts.map +1 -0
- package/dist/session/session-manifest.d.ts +2 -1
- package/dist/session/session-manifest.d.ts.map +1 -0
- package/dist/session/session-service.d.ts +1 -0
- package/dist/session/session-service.d.ts.map +1 -0
- package/dist/session/session-team-coordination.d.ts +1 -0
- package/dist/session/session-team-coordination.d.ts.map +1 -0
- package/dist/session/session-telemetry.d.ts +3 -1
- package/dist/session/session-telemetry.d.ts.map +1 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts +1 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts.map +1 -0
- package/dist/session/unified-session-persistence-service.d.ts +1 -0
- package/dist/session/unified-session-persistence-service.d.ts.map +1 -0
- package/dist/session/utils/helpers.d.ts +1 -0
- package/dist/session/utils/helpers.d.ts.map +1 -0
- package/dist/session/utils/types.d.ts +1 -0
- package/dist/session/utils/types.d.ts.map +1 -0
- package/dist/session/utils/usage.d.ts +1 -0
- package/dist/session/utils/usage.d.ts.map +1 -0
- package/dist/session/workspace-manager.d.ts +1 -0
- package/dist/session/workspace-manager.d.ts.map +1 -0
- package/dist/session/workspace-manifest.d.ts +1 -0
- package/dist/session/workspace-manifest.d.ts.map +1 -0
- package/dist/storage/file-team-store.d.ts +1 -0
- package/dist/storage/file-team-store.d.ts.map +1 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts +1 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -0
- package/dist/storage/provider-settings-manager.d.ts +1 -0
- package/dist/storage/provider-settings-manager.d.ts.map +1 -0
- package/dist/storage/sqlite-session-store.d.ts +1 -0
- package/dist/storage/sqlite-session-store.d.ts.map +1 -0
- package/dist/storage/sqlite-team-store.d.ts +1 -0
- package/dist/storage/sqlite-team-store.d.ts.map +1 -0
- package/dist/storage/team-store.d.ts +1 -0
- package/dist/storage/team-store.d.ts.map +1 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/index.d.ts.map +1 -0
- package/dist/team/projections.d.ts +1 -0
- package/dist/team/projections.d.ts.map +1 -0
- package/dist/telemetry/ITelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/ITelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/OpenTelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -0
- package/dist/telemetry/TelemetryService.d.ts +1 -0
- package/dist/telemetry/TelemetryService.d.ts.map +1 -0
- package/dist/telemetry/core-events.d.ts +55 -22
- package/dist/telemetry/core-events.d.ts.map +1 -0
- package/dist/telemetry/opentelemetry.d.ts +1 -0
- package/dist/telemetry/opentelemetry.d.ts.map +1 -0
- package/dist/tools/constants.d.ts +1 -0
- package/dist/tools/constants.d.ts.map +1 -0
- package/dist/tools/definitions.d.ts +8 -1
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/executors/apply-patch-parser.d.ts +1 -0
- package/dist/tools/executors/apply-patch-parser.d.ts.map +1 -0
- package/dist/tools/executors/apply-patch.d.ts +1 -0
- package/dist/tools/executors/apply-patch.d.ts.map +1 -0
- package/dist/tools/executors/bash.d.ts +2 -1
- package/dist/tools/executors/bash.d.ts.map +1 -0
- package/dist/tools/executors/editor.d.ts +1 -0
- package/dist/tools/executors/editor.d.ts.map +1 -0
- package/dist/tools/executors/file-read.d.ts +1 -0
- package/dist/tools/executors/file-read.d.ts.map +1 -0
- package/dist/tools/executors/index.d.ts +14 -7
- package/dist/tools/executors/index.d.ts.map +1 -0
- package/dist/tools/executors/search.d.ts +1 -0
- package/dist/tools/executors/search.d.ts.map +1 -0
- package/dist/tools/executors/web-fetch.d.ts +1 -0
- package/dist/tools/executors/web-fetch.d.ts.map +1 -0
- package/dist/tools/helpers.d.ts +15 -0
- package/dist/tools/helpers.d.ts.map +1 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/model-tool-routing.d.ts +1 -0
- package/dist/tools/model-tool-routing.d.ts.map +1 -0
- package/dist/tools/presets.d.ts +1 -0
- package/dist/tools/presets.d.ts.map +1 -0
- package/dist/tools/schemas.d.ts +41 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/types.d.ts +3 -2
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/types/common.d.ts +1 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/events.d.ts +1 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/provider-settings.d.ts +1 -0
- package/dist/types/provider-settings.d.ts.map +1 -0
- package/dist/types/sessions.d.ts +1 -0
- package/dist/types/sessions.d.ts.map +1 -0
- package/dist/types/storage.d.ts +1 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/workspace.d.ts +1 -0
- package/dist/types/workspace.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +8 -6
- package/src/account/cline-account-service.test.ts +0 -101
- package/src/account/cline-account-service.ts +0 -287
- package/src/account/index.ts +0 -22
- package/src/account/rpc.test.ts +0 -62
- package/src/account/rpc.ts +0 -172
- package/src/account/types.ts +0 -98
- package/src/agents/agent-config-loader.test.ts +0 -236
- package/src/agents/agent-config-loader.ts +0 -108
- package/src/agents/agent-config-parser.ts +0 -198
- package/src/agents/hooks-config-loader.test.ts +0 -20
- package/src/agents/hooks-config-loader.ts +0 -118
- package/src/agents/index.ts +0 -85
- package/src/agents/plugin-config-loader.test.ts +0 -140
- package/src/agents/plugin-config-loader.ts +0 -97
- package/src/agents/plugin-loader.test.ts +0 -228
- package/src/agents/plugin-loader.ts +0 -172
- package/src/agents/plugin-sandbox-bootstrap.ts +0 -445
- package/src/agents/plugin-sandbox.test.ts +0 -317
- package/src/agents/plugin-sandbox.ts +0 -341
- package/src/agents/unified-config-file-watcher.test.ts +0 -196
- package/src/agents/unified-config-file-watcher.ts +0 -483
- package/src/agents/user-instruction-config-loader.test.ts +0 -158
- package/src/agents/user-instruction-config-loader.ts +0 -438
- package/src/auth/client.test.ts +0 -40
- package/src/auth/client.ts +0 -25
- package/src/auth/cline.test.ts +0 -130
- package/src/auth/cline.ts +0 -420
- package/src/auth/codex.test.ts +0 -170
- package/src/auth/codex.ts +0 -491
- package/src/auth/oca.test.ts +0 -215
- package/src/auth/oca.ts +0 -573
- package/src/auth/server.ts +0 -216
- package/src/auth/types.ts +0 -81
- package/src/auth/utils.test.ts +0 -128
- package/src/auth/utils.ts +0 -247
- package/src/chat/chat-schema.ts +0 -82
- package/src/index.node.ts +0 -285
- package/src/index.ts +0 -211
- package/src/input/file-indexer.d.ts +0 -11
- package/src/input/file-indexer.test.ts +0 -127
- package/src/input/file-indexer.ts +0 -327
- package/src/input/index.ts +0 -7
- package/src/input/mention-enricher.test.ts +0 -85
- package/src/input/mention-enricher.ts +0 -122
- package/src/mcp/config-loader.test.ts +0 -238
- package/src/mcp/config-loader.ts +0 -219
- package/src/mcp/index.ts +0 -26
- package/src/mcp/manager.test.ts +0 -106
- package/src/mcp/manager.ts +0 -262
- package/src/mcp/types.ts +0 -88
- package/src/providers/local-provider-service.ts +0 -608
- package/src/runtime/commands.test.ts +0 -98
- package/src/runtime/commands.ts +0 -83
- package/src/runtime/hook-file-hooks.test.ts +0 -237
- package/src/runtime/hook-file-hooks.ts +0 -859
- package/src/runtime/index.ts +0 -37
- package/src/runtime/rules.ts +0 -34
- package/src/runtime/runtime-builder.team-persistence.test.ts +0 -202
- package/src/runtime/runtime-builder.test.ts +0 -371
- package/src/runtime/runtime-builder.ts +0 -589
- package/src/runtime/runtime-parity.test.ts +0 -143
- package/src/runtime/sandbox/subprocess-sandbox.ts +0 -231
- package/src/runtime/session-runtime.ts +0 -46
- package/src/runtime/skills.ts +0 -44
- package/src/runtime/tool-approval.ts +0 -104
- package/src/runtime/workflows.test.ts +0 -119
- package/src/runtime/workflows.ts +0 -45
- package/src/session/default-session-manager.e2e.test.ts +0 -384
- package/src/session/default-session-manager.test.ts +0 -1741
- package/src/session/default-session-manager.ts +0 -1233
- package/src/session/file-session-service.ts +0 -280
- package/src/session/index.ts +0 -42
- package/src/session/rpc-session-service.ts +0 -107
- package/src/session/rpc-spawn-lease.test.ts +0 -49
- package/src/session/rpc-spawn-lease.ts +0 -122
- package/src/session/runtime-oauth-token-manager.test.ts +0 -137
- package/src/session/runtime-oauth-token-manager.ts +0 -272
- package/src/session/session-agent-events.ts +0 -159
- package/src/session/session-artifacts.ts +0 -106
- package/src/session/session-config-builder.ts +0 -113
- package/src/session/session-graph.ts +0 -92
- package/src/session/session-host.test.ts +0 -29
- package/src/session/session-host.ts +0 -242
- package/src/session/session-manager.ts +0 -69
- package/src/session/session-manifest.ts +0 -29
- package/src/session/session-service.team-persistence.test.ts +0 -48
- package/src/session/session-service.ts +0 -673
- package/src/session/session-team-coordination.ts +0 -229
- package/src/session/session-telemetry.ts +0 -95
- package/src/session/sqlite-rpc-session-backend.ts +0 -303
- package/src/session/unified-session-persistence-service.test.ts +0 -85
- package/src/session/unified-session-persistence-service.ts +0 -996
- package/src/session/utils/helpers.ts +0 -139
- package/src/session/utils/types.ts +0 -57
- package/src/session/utils/usage.ts +0 -32
- package/src/session/workspace-manager.ts +0 -98
- package/src/session/workspace-manifest.ts +0 -100
- package/src/storage/artifact-store.ts +0 -1
- package/src/storage/file-team-store.ts +0 -257
- package/src/storage/index.ts +0 -11
- package/src/storage/provider-settings-legacy-migration.test.ts +0 -307
- package/src/storage/provider-settings-legacy-migration.ts +0 -689
- package/src/storage/provider-settings-manager.test.ts +0 -145
- package/src/storage/provider-settings-manager.ts +0 -150
- package/src/storage/session-store.ts +0 -1
- package/src/storage/sqlite-session-store.ts +0 -275
- package/src/storage/sqlite-team-store.ts +0 -454
- package/src/storage/team-store.ts +0 -40
- package/src/team/index.ts +0 -4
- package/src/team/projections.ts +0 -285
- package/src/telemetry/ITelemetryAdapter.ts +0 -94
- package/src/telemetry/LoggerTelemetryAdapter.test.ts +0 -42
- package/src/telemetry/LoggerTelemetryAdapter.ts +0 -114
- package/src/telemetry/OpenTelemetryAdapter.test.ts +0 -157
- package/src/telemetry/OpenTelemetryAdapter.ts +0 -348
- package/src/telemetry/OpenTelemetryProvider.test.ts +0 -113
- package/src/telemetry/OpenTelemetryProvider.ts +0 -322
- package/src/telemetry/TelemetryService.test.ts +0 -134
- package/src/telemetry/TelemetryService.ts +0 -141
- package/src/telemetry/core-events.ts +0 -344
- package/src/telemetry/opentelemetry.ts +0 -20
- package/src/tools/constants.ts +0 -35
- package/src/tools/definitions.test.ts +0 -658
- package/src/tools/definitions.ts +0 -726
- package/src/tools/executors/apply-patch-parser.ts +0 -520
- package/src/tools/executors/apply-patch.ts +0 -359
- package/src/tools/executors/bash.ts +0 -205
- package/src/tools/executors/editor.test.ts +0 -35
- package/src/tools/executors/editor.ts +0 -219
- package/src/tools/executors/file-read.test.ts +0 -49
- package/src/tools/executors/file-read.ts +0 -110
- package/src/tools/executors/index.ts +0 -75
- package/src/tools/executors/search.ts +0 -278
- package/src/tools/executors/web-fetch.ts +0 -259
- package/src/tools/index.ts +0 -168
- package/src/tools/model-tool-routing.test.ts +0 -86
- package/src/tools/model-tool-routing.ts +0 -132
- package/src/tools/presets.test.ts +0 -62
- package/src/tools/presets.ts +0 -168
- package/src/tools/schemas.ts +0 -284
- package/src/tools/types.ts +0 -328
- package/src/types/common.ts +0 -14
- package/src/types/config.ts +0 -84
- package/src/types/events.ts +0 -74
- package/src/types/index.ts +0 -24
- package/src/types/provider-settings.ts +0 -43
- package/src/types/sessions.ts +0 -16
- package/src/types/storage.ts +0 -64
- package/src/types/workspace.ts +0 -7
- package/src/types.ts +0 -128
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import type { AgentConfig, Tool, ToolContext } from "@clinebot/agents";
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
import { loadSandboxedPlugins } from "./plugin-sandbox";
|
|
7
|
-
|
|
8
|
-
function createApiCapture() {
|
|
9
|
-
const tools: Tool[] = [];
|
|
10
|
-
const api = {
|
|
11
|
-
registerTool: (tool: Tool) => tools.push(tool),
|
|
12
|
-
registerCommand: () => {},
|
|
13
|
-
registerShortcut: () => {},
|
|
14
|
-
registerFlag: () => {},
|
|
15
|
-
registerMessageRenderer: () => {},
|
|
16
|
-
registerProvider: () => {},
|
|
17
|
-
};
|
|
18
|
-
return { tools, api };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe("plugin-sandbox", () => {
|
|
22
|
-
it("runs plugin hooks and tool contributions in sandbox process", async () => {
|
|
23
|
-
const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-"));
|
|
24
|
-
try {
|
|
25
|
-
const pluginPath = join(dir, "plugin.mjs");
|
|
26
|
-
await writeFile(
|
|
27
|
-
pluginPath,
|
|
28
|
-
[
|
|
29
|
-
"export default {",
|
|
30
|
-
" name: 'sandbox-test',",
|
|
31
|
-
" manifest: { capabilities: ['hooks','tools'], hookStages: ['input'] },",
|
|
32
|
-
" setup(api) {",
|
|
33
|
-
" api.registerTool({",
|
|
34
|
-
" name: 'sandbox_echo',",
|
|
35
|
-
" description: 'echo',",
|
|
36
|
-
" inputSchema: { type: 'object', properties: { value: { type: 'string' } }, required: ['value'] },",
|
|
37
|
-
" execute: async (input) => ({ echoed: input.value }),",
|
|
38
|
-
" });",
|
|
39
|
-
" },",
|
|
40
|
-
" onInput(ctx) { return { overrideInput: String(ctx.input || '').toUpperCase() }; }",
|
|
41
|
-
"};",
|
|
42
|
-
].join("\n"),
|
|
43
|
-
"utf8",
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const sandboxed = await loadSandboxedPlugins({
|
|
47
|
-
pluginPaths: [pluginPath],
|
|
48
|
-
});
|
|
49
|
-
try {
|
|
50
|
-
expect(sandboxed.extensions).toBeDefined();
|
|
51
|
-
const extension = sandboxed.extensions?.[0];
|
|
52
|
-
expect(extension?.name).toBe("sandbox-test");
|
|
53
|
-
type AgentExtensionInputContext = Parameters<
|
|
54
|
-
NonNullable<NonNullable<AgentConfig["extensions"]>[number]["onInput"]>
|
|
55
|
-
>[0];
|
|
56
|
-
const inputContext: AgentExtensionInputContext = {
|
|
57
|
-
agentId: "agent-1",
|
|
58
|
-
conversationId: "conv-1",
|
|
59
|
-
parentAgentId: null,
|
|
60
|
-
mode: "run",
|
|
61
|
-
input: "hello",
|
|
62
|
-
};
|
|
63
|
-
const control = await extension?.onInput?.(inputContext);
|
|
64
|
-
expect(control?.overrideInput).toBe("HELLO");
|
|
65
|
-
|
|
66
|
-
const { tools, api } = createApiCapture();
|
|
67
|
-
await extension?.setup?.(api);
|
|
68
|
-
expect(tools.map((tool) => tool.name)).toContain("sandbox_echo");
|
|
69
|
-
const echoTool = tools.find((tool) => tool.name === "sandbox_echo");
|
|
70
|
-
expect(echoTool).toBeDefined();
|
|
71
|
-
const result = await echoTool?.execute({ value: "ok" }, {
|
|
72
|
-
agentId: "agent-1",
|
|
73
|
-
conversationId: "conv-1",
|
|
74
|
-
iteration: 1,
|
|
75
|
-
} as ToolContext);
|
|
76
|
-
expect(result).toEqual({ echoed: "ok" });
|
|
77
|
-
} finally {
|
|
78
|
-
await sandboxed.shutdown();
|
|
79
|
-
}
|
|
80
|
-
} finally {
|
|
81
|
-
await rm(dir, { recursive: true, force: true });
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("enforces hook timeout and cancels sandbox process", async () => {
|
|
86
|
-
const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-timeout-"));
|
|
87
|
-
try {
|
|
88
|
-
const pluginPath = join(dir, "plugin-timeout.mjs");
|
|
89
|
-
await writeFile(
|
|
90
|
-
pluginPath,
|
|
91
|
-
[
|
|
92
|
-
"export default {",
|
|
93
|
-
" name: 'sandbox-timeout',",
|
|
94
|
-
" manifest: { capabilities: ['hooks'], hookStages: ['input'] },",
|
|
95
|
-
" onInput() { return new Promise(() => {}); }",
|
|
96
|
-
"};",
|
|
97
|
-
].join("\n"),
|
|
98
|
-
"utf8",
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const sandboxed = await loadSandboxedPlugins({
|
|
102
|
-
pluginPaths: [pluginPath],
|
|
103
|
-
hookTimeoutMs: 50,
|
|
104
|
-
});
|
|
105
|
-
const extension = sandboxed.extensions?.[0];
|
|
106
|
-
await expect(
|
|
107
|
-
extension?.onInput?.({
|
|
108
|
-
agentId: "agent-1",
|
|
109
|
-
conversationId: "conv-1",
|
|
110
|
-
parentAgentId: null,
|
|
111
|
-
mode: "run",
|
|
112
|
-
input: "hello",
|
|
113
|
-
}),
|
|
114
|
-
).rejects.toThrow(/timed out/i);
|
|
115
|
-
await sandboxed.shutdown();
|
|
116
|
-
} finally {
|
|
117
|
-
await rm(dir, { recursive: true, force: true });
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("forwards sandbox plugin events to the host", async () => {
|
|
122
|
-
const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-events-"));
|
|
123
|
-
try {
|
|
124
|
-
const pluginPath = join(dir, "plugin-events.mjs");
|
|
125
|
-
await writeFile(
|
|
126
|
-
pluginPath,
|
|
127
|
-
[
|
|
128
|
-
"export default {",
|
|
129
|
-
" name: 'sandbox-events',",
|
|
130
|
-
" manifest: { capabilities: ['tools'] },",
|
|
131
|
-
" setup(api) {",
|
|
132
|
-
" api.registerTool({",
|
|
133
|
-
" name: 'emit_event',",
|
|
134
|
-
" description: 'emit host event',",
|
|
135
|
-
" inputSchema: { type: 'object', properties: { value: { type: 'string' } }, required: ['value'] },",
|
|
136
|
-
" execute: async (input) => {",
|
|
137
|
-
" globalThis.__clinePluginHost?.emitEvent?.('test_event', { value: input.value });",
|
|
138
|
-
" return { ok: true };",
|
|
139
|
-
" },",
|
|
140
|
-
" });",
|
|
141
|
-
" },",
|
|
142
|
-
"};",
|
|
143
|
-
].join("\n"),
|
|
144
|
-
"utf8",
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const events: Array<{ name: string; payload?: unknown }> = [];
|
|
148
|
-
const sandboxed = await loadSandboxedPlugins({
|
|
149
|
-
pluginPaths: [pluginPath],
|
|
150
|
-
onEvent: (event) => {
|
|
151
|
-
events.push(event);
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
try {
|
|
155
|
-
const extension = sandboxed.extensions?.[0];
|
|
156
|
-
const { tools, api } = createApiCapture();
|
|
157
|
-
await extension?.setup?.(api);
|
|
158
|
-
const tool = tools.find((entry) => entry.name === "emit_event");
|
|
159
|
-
await tool?.execute({ value: "hello" }, {
|
|
160
|
-
agentId: "agent-1",
|
|
161
|
-
conversationId: "conv-1",
|
|
162
|
-
iteration: 1,
|
|
163
|
-
} as ToolContext);
|
|
164
|
-
expect(events).toEqual([
|
|
165
|
-
{
|
|
166
|
-
name: "test_event",
|
|
167
|
-
payload: { value: "hello" },
|
|
168
|
-
},
|
|
169
|
-
]);
|
|
170
|
-
} finally {
|
|
171
|
-
await sandboxed.shutdown();
|
|
172
|
-
}
|
|
173
|
-
} finally {
|
|
174
|
-
await rm(dir, { recursive: true, force: true });
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("loads TypeScript plugins in the sandbox process", async () => {
|
|
179
|
-
const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-ts-"));
|
|
180
|
-
try {
|
|
181
|
-
const pluginPath = join(dir, "plugin-ts.ts");
|
|
182
|
-
await writeFile(
|
|
183
|
-
pluginPath,
|
|
184
|
-
[
|
|
185
|
-
"const TOOL_NAME: string = 'sandbox_ts_echo';",
|
|
186
|
-
"export default {",
|
|
187
|
-
" name: 'sandbox-ts',",
|
|
188
|
-
" manifest: { capabilities: ['tools'] },",
|
|
189
|
-
" setup(api) {",
|
|
190
|
-
" api.registerTool({",
|
|
191
|
-
" name: TOOL_NAME,",
|
|
192
|
-
" description: 'echo',",
|
|
193
|
-
" inputSchema: { type: 'object', properties: { value: { type: 'string' } }, required: ['value'] },",
|
|
194
|
-
" execute: async (input) => ({ echoed: input.value }),",
|
|
195
|
-
" });",
|
|
196
|
-
" },",
|
|
197
|
-
"};",
|
|
198
|
-
].join("\n"),
|
|
199
|
-
"utf8",
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
const sandboxed = await loadSandboxedPlugins({
|
|
203
|
-
pluginPaths: [pluginPath],
|
|
204
|
-
});
|
|
205
|
-
try {
|
|
206
|
-
const extension = sandboxed.extensions?.[0];
|
|
207
|
-
expect(extension?.name).toBe("sandbox-ts");
|
|
208
|
-
const { tools, api } = createApiCapture();
|
|
209
|
-
await extension?.setup?.(api);
|
|
210
|
-
const tool = tools.find((entry) => entry.name === "sandbox_ts_echo");
|
|
211
|
-
expect(tool).toBeDefined();
|
|
212
|
-
const result = await tool?.execute({ value: "ok" }, {
|
|
213
|
-
agentId: "agent-1",
|
|
214
|
-
conversationId: "conv-1",
|
|
215
|
-
iteration: 1,
|
|
216
|
-
} as ToolContext);
|
|
217
|
-
expect(result).toEqual({ echoed: "ok" });
|
|
218
|
-
} finally {
|
|
219
|
-
await sandboxed.shutdown();
|
|
220
|
-
}
|
|
221
|
-
} finally {
|
|
222
|
-
await rm(dir, { recursive: true, force: true });
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("resolves plugin-local dependencies in the sandbox process", async () => {
|
|
227
|
-
const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-deps-"));
|
|
228
|
-
try {
|
|
229
|
-
const depDir = join(dir, "node_modules", "sandbox-local-dep");
|
|
230
|
-
await mkdir(depDir, { recursive: true });
|
|
231
|
-
await writeFile(
|
|
232
|
-
join(depDir, "package.json"),
|
|
233
|
-
JSON.stringify({
|
|
234
|
-
name: "sandbox-local-dep",
|
|
235
|
-
type: "module",
|
|
236
|
-
exports: "./index.js",
|
|
237
|
-
}),
|
|
238
|
-
"utf8",
|
|
239
|
-
);
|
|
240
|
-
await writeFile(
|
|
241
|
-
join(depDir, "index.js"),
|
|
242
|
-
"export const depName = 'sandbox-local-dep';\n",
|
|
243
|
-
"utf8",
|
|
244
|
-
);
|
|
245
|
-
const pluginPath = join(dir, "plugin-dep.ts");
|
|
246
|
-
await writeFile(
|
|
247
|
-
pluginPath,
|
|
248
|
-
[
|
|
249
|
-
"import { depName } from 'sandbox-local-dep';",
|
|
250
|
-
"export default {",
|
|
251
|
-
" name: depName,",
|
|
252
|
-
" manifest: { capabilities: ['tools'] },",
|
|
253
|
-
"};",
|
|
254
|
-
].join("\n"),
|
|
255
|
-
"utf8",
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
const sandboxed = await loadSandboxedPlugins({
|
|
259
|
-
pluginPaths: [pluginPath],
|
|
260
|
-
});
|
|
261
|
-
try {
|
|
262
|
-
expect(sandboxed.extensions?.[0]?.name).toBe("sandbox-local-dep");
|
|
263
|
-
} finally {
|
|
264
|
-
await sandboxed.shutdown();
|
|
265
|
-
}
|
|
266
|
-
} finally {
|
|
267
|
-
await rm(dir, { recursive: true, force: true });
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it("prefers plugin-installed SDK packages in the sandbox process", async () => {
|
|
272
|
-
const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-sdk-"));
|
|
273
|
-
try {
|
|
274
|
-
const depDir = join(dir, "node_modules", "@clinebot", "shared");
|
|
275
|
-
await mkdir(depDir, { recursive: true });
|
|
276
|
-
await writeFile(
|
|
277
|
-
join(depDir, "package.json"),
|
|
278
|
-
JSON.stringify({
|
|
279
|
-
name: "@clinebot/shared",
|
|
280
|
-
type: "module",
|
|
281
|
-
exports: "./index.js",
|
|
282
|
-
}),
|
|
283
|
-
"utf8",
|
|
284
|
-
);
|
|
285
|
-
await writeFile(
|
|
286
|
-
join(depDir, "index.js"),
|
|
287
|
-
"export const sdkMarker = 'sandbox-plugin-installed-sdk';\n",
|
|
288
|
-
"utf8",
|
|
289
|
-
);
|
|
290
|
-
const pluginPath = join(dir, "plugin-sdk.ts");
|
|
291
|
-
await writeFile(
|
|
292
|
-
pluginPath,
|
|
293
|
-
[
|
|
294
|
-
"import { sdkMarker } from '@clinebot/shared';",
|
|
295
|
-
"export default {",
|
|
296
|
-
" name: sdkMarker,",
|
|
297
|
-
" manifest: { capabilities: ['tools'] },",
|
|
298
|
-
"};",
|
|
299
|
-
].join("\n"),
|
|
300
|
-
"utf8",
|
|
301
|
-
);
|
|
302
|
-
|
|
303
|
-
const sandboxed = await loadSandboxedPlugins({
|
|
304
|
-
pluginPaths: [pluginPath],
|
|
305
|
-
});
|
|
306
|
-
try {
|
|
307
|
-
expect(sandboxed.extensions?.[0]?.name).toBe(
|
|
308
|
-
"sandbox-plugin-installed-sdk",
|
|
309
|
-
);
|
|
310
|
-
} finally {
|
|
311
|
-
await sandboxed.shutdown();
|
|
312
|
-
}
|
|
313
|
-
} finally {
|
|
314
|
-
await rm(dir, { recursive: true, force: true });
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
});
|
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import type { AgentConfig, Tool } from "@clinebot/agents";
|
|
5
|
-
import { SubprocessSandbox } from "../runtime/sandbox/subprocess-sandbox";
|
|
6
|
-
|
|
7
|
-
export interface PluginSandboxOptions {
|
|
8
|
-
pluginPaths: string[];
|
|
9
|
-
exportName?: string;
|
|
10
|
-
importTimeoutMs?: number;
|
|
11
|
-
hookTimeoutMs?: number;
|
|
12
|
-
contributionTimeoutMs?: number;
|
|
13
|
-
onEvent?: (event: { name: string; payload?: unknown }) => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type AgentExtension = NonNullable<AgentConfig["extensions"]>[number];
|
|
17
|
-
type AgentExtensionApi = Parameters<NonNullable<AgentExtension["setup"]>>[0];
|
|
18
|
-
type HookStage =
|
|
19
|
-
| "input"
|
|
20
|
-
| "runtime_event"
|
|
21
|
-
| "session_start"
|
|
22
|
-
| "before_agent_start"
|
|
23
|
-
| "tool_call_before"
|
|
24
|
-
| "tool_call_after"
|
|
25
|
-
| "turn_end"
|
|
26
|
-
| "session_shutdown"
|
|
27
|
-
| "error";
|
|
28
|
-
|
|
29
|
-
type SandboxedContributionDescriptor = {
|
|
30
|
-
id: string;
|
|
31
|
-
name: string;
|
|
32
|
-
description?: string;
|
|
33
|
-
inputSchema?: unknown;
|
|
34
|
-
timeoutMs?: number;
|
|
35
|
-
retryable?: boolean;
|
|
36
|
-
value?: string;
|
|
37
|
-
defaultValue?: boolean | string | number;
|
|
38
|
-
metadata?: Record<string, unknown>;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type SandboxedPluginDescriptor = {
|
|
42
|
-
pluginId: string;
|
|
43
|
-
name: string;
|
|
44
|
-
manifest: AgentExtension["manifest"];
|
|
45
|
-
contributions: {
|
|
46
|
-
tools: SandboxedContributionDescriptor[];
|
|
47
|
-
commands: SandboxedContributionDescriptor[];
|
|
48
|
-
shortcuts: SandboxedContributionDescriptor[];
|
|
49
|
-
flags: SandboxedContributionDescriptor[];
|
|
50
|
-
messageRenderers: SandboxedContributionDescriptor[];
|
|
51
|
-
providers: SandboxedContributionDescriptor[];
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Resolve the bootstrap for the sandbox subprocess.
|
|
57
|
-
*
|
|
58
|
-
* In production (bundled), the compiled `.js` file lives next to this module
|
|
59
|
-
* and can be passed directly as a file to spawn. In development/test
|
|
60
|
-
* (unbundled, where only the `.ts` source exists), we load the TypeScript
|
|
61
|
-
* bootstrap through jiti from an inline script.
|
|
62
|
-
*/
|
|
63
|
-
function resolveBootstrap(): { file: string } | { script: string } {
|
|
64
|
-
const dir = dirname(fileURLToPath(import.meta.url));
|
|
65
|
-
// In dev, the bootstrap sits next to this file in src/agents/.
|
|
66
|
-
// In production, the main bundle is at dist/ but bootstrap is at dist/agents/.
|
|
67
|
-
const candidates = [
|
|
68
|
-
join(dir, "plugin-sandbox-bootstrap.js"),
|
|
69
|
-
join(dir, "agents", "plugin-sandbox-bootstrap.js"),
|
|
70
|
-
];
|
|
71
|
-
for (const candidate of candidates) {
|
|
72
|
-
if (existsSync(candidate)) return { file: candidate };
|
|
73
|
-
}
|
|
74
|
-
const tsPath = join(dir, "plugin-sandbox-bootstrap.ts");
|
|
75
|
-
return {
|
|
76
|
-
script: [
|
|
77
|
-
"const createJiti = require('jiti');",
|
|
78
|
-
`const jiti = createJiti(${JSON.stringify(tsPath)}, { cache: false, requireCache: false, esmResolve: true, interopDefault: false });`,
|
|
79
|
-
`Promise.resolve(jiti.import(${JSON.stringify(tsPath)}, {})).catch((error) => {`,
|
|
80
|
-
" console.error(error);",
|
|
81
|
-
" process.exitCode = 1;",
|
|
82
|
-
"});",
|
|
83
|
-
].join("\n"),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const BOOTSTRAP = resolveBootstrap();
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Map from hook stage names in the manifest to the property name on AgentExtension
|
|
91
|
-
* and the corresponding hook method name inside the sandbox subprocess.
|
|
92
|
-
*/
|
|
93
|
-
const HOOK_BINDINGS: Array<{
|
|
94
|
-
stage: HookStage;
|
|
95
|
-
extensionKey: keyof AgentExtension;
|
|
96
|
-
sandboxHookName: string;
|
|
97
|
-
}> = [
|
|
98
|
-
{ stage: "input", extensionKey: "onInput", sandboxHookName: "onInput" },
|
|
99
|
-
{
|
|
100
|
-
stage: "session_start",
|
|
101
|
-
extensionKey: "onSessionStart",
|
|
102
|
-
sandboxHookName: "onSessionStart",
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
stage: "before_agent_start",
|
|
106
|
-
extensionKey: "onBeforeAgentStart",
|
|
107
|
-
sandboxHookName: "onBeforeAgentStart",
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
stage: "tool_call_before",
|
|
111
|
-
extensionKey: "onToolCall",
|
|
112
|
-
sandboxHookName: "onToolCall",
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
stage: "tool_call_after",
|
|
116
|
-
extensionKey: "onToolResult",
|
|
117
|
-
sandboxHookName: "onToolResult",
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
stage: "turn_end",
|
|
121
|
-
extensionKey: "onAgentEnd",
|
|
122
|
-
sandboxHookName: "onAgentEnd",
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
stage: "session_shutdown",
|
|
126
|
-
extensionKey: "onSessionShutdown",
|
|
127
|
-
sandboxHookName: "onSessionShutdown",
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
stage: "runtime_event",
|
|
131
|
-
extensionKey: "onRuntimeEvent",
|
|
132
|
-
sandboxHookName: "onRuntimeEvent",
|
|
133
|
-
},
|
|
134
|
-
{ stage: "error", extensionKey: "onError", sandboxHookName: "onError" },
|
|
135
|
-
];
|
|
136
|
-
|
|
137
|
-
function hasHookStage(extension: AgentExtension, stage: HookStage): boolean {
|
|
138
|
-
return extension.manifest.hookStages?.includes(stage) === true;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function withTimeoutFallback(
|
|
142
|
-
timeoutMs: number | undefined,
|
|
143
|
-
fallback: number,
|
|
144
|
-
): number {
|
|
145
|
-
return typeof timeoutMs === "number" && timeoutMs > 0 ? timeoutMs : fallback;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export async function loadSandboxedPlugins(
|
|
149
|
-
options: PluginSandboxOptions,
|
|
150
|
-
): Promise<{
|
|
151
|
-
extensions: AgentConfig["extensions"];
|
|
152
|
-
shutdown: () => Promise<void>;
|
|
153
|
-
}> {
|
|
154
|
-
const sandbox = new SubprocessSandbox({
|
|
155
|
-
name: "plugin-sandbox",
|
|
156
|
-
...("file" in BOOTSTRAP
|
|
157
|
-
? { bootstrapFile: BOOTSTRAP.file }
|
|
158
|
-
: { bootstrapScript: BOOTSTRAP.script }),
|
|
159
|
-
onEvent: options.onEvent,
|
|
160
|
-
});
|
|
161
|
-
const importTimeoutMs = withTimeoutFallback(options.importTimeoutMs, 4000);
|
|
162
|
-
const hookTimeoutMs = withTimeoutFallback(options.hookTimeoutMs, 3000);
|
|
163
|
-
const contributionTimeoutMs = withTimeoutFallback(
|
|
164
|
-
options.contributionTimeoutMs,
|
|
165
|
-
5000,
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
let descriptors: SandboxedPluginDescriptor[];
|
|
169
|
-
try {
|
|
170
|
-
descriptors = await sandbox.call<SandboxedPluginDescriptor[]>(
|
|
171
|
-
"initialize",
|
|
172
|
-
{
|
|
173
|
-
pluginPaths: options.pluginPaths,
|
|
174
|
-
exportName: options.exportName,
|
|
175
|
-
},
|
|
176
|
-
{ timeoutMs: importTimeoutMs },
|
|
177
|
-
);
|
|
178
|
-
} catch (error) {
|
|
179
|
-
await sandbox.shutdown().catch(() => {
|
|
180
|
-
// Best-effort cleanup when sandbox initialization fails.
|
|
181
|
-
});
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const extensions: NonNullable<AgentConfig["extensions"]> = descriptors.map(
|
|
186
|
-
(descriptor) => {
|
|
187
|
-
const extension: AgentExtension = {
|
|
188
|
-
name: descriptor.name,
|
|
189
|
-
manifest: descriptor.manifest,
|
|
190
|
-
setup: (api: AgentExtensionApi) => {
|
|
191
|
-
registerTools(api, sandbox, descriptor, contributionTimeoutMs);
|
|
192
|
-
registerCommands(api, sandbox, descriptor, contributionTimeoutMs);
|
|
193
|
-
registerSimpleContributions(api, descriptor);
|
|
194
|
-
},
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
bindHooks(extension, sandbox, descriptor.pluginId, hookTimeoutMs);
|
|
198
|
-
|
|
199
|
-
return extension;
|
|
200
|
-
},
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
extensions,
|
|
205
|
-
shutdown: async () => {
|
|
206
|
-
await sandbox.shutdown();
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// ---------------------------------------------------------------------------
|
|
212
|
-
// Contribution registration helpers
|
|
213
|
-
// ---------------------------------------------------------------------------
|
|
214
|
-
|
|
215
|
-
function registerTools(
|
|
216
|
-
api: AgentExtensionApi,
|
|
217
|
-
sandbox: SubprocessSandbox,
|
|
218
|
-
descriptor: SandboxedPluginDescriptor,
|
|
219
|
-
timeoutMs: number,
|
|
220
|
-
): void {
|
|
221
|
-
for (const td of descriptor.contributions.tools) {
|
|
222
|
-
const tool: Tool = {
|
|
223
|
-
name: td.name,
|
|
224
|
-
description: td.description ?? "",
|
|
225
|
-
inputSchema: (td.inputSchema ?? {
|
|
226
|
-
type: "object",
|
|
227
|
-
properties: {},
|
|
228
|
-
}) as Tool["inputSchema"],
|
|
229
|
-
timeoutMs: td.timeoutMs,
|
|
230
|
-
retryable: td.retryable,
|
|
231
|
-
execute: async (input: unknown, context: unknown) =>
|
|
232
|
-
await sandbox.call(
|
|
233
|
-
"executeTool",
|
|
234
|
-
{
|
|
235
|
-
pluginId: descriptor.pluginId,
|
|
236
|
-
contributionId: td.id,
|
|
237
|
-
input,
|
|
238
|
-
context,
|
|
239
|
-
},
|
|
240
|
-
{ timeoutMs },
|
|
241
|
-
),
|
|
242
|
-
};
|
|
243
|
-
api.registerTool(tool);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function registerCommands(
|
|
248
|
-
api: AgentExtensionApi,
|
|
249
|
-
sandbox: SubprocessSandbox,
|
|
250
|
-
descriptor: SandboxedPluginDescriptor,
|
|
251
|
-
timeoutMs: number,
|
|
252
|
-
): void {
|
|
253
|
-
for (const cd of descriptor.contributions.commands) {
|
|
254
|
-
api.registerCommand({
|
|
255
|
-
name: cd.name,
|
|
256
|
-
description: cd.description,
|
|
257
|
-
handler: async (input: string) =>
|
|
258
|
-
await sandbox.call<string>(
|
|
259
|
-
"executeCommand",
|
|
260
|
-
{
|
|
261
|
-
pluginId: descriptor.pluginId,
|
|
262
|
-
contributionId: cd.id,
|
|
263
|
-
input,
|
|
264
|
-
},
|
|
265
|
-
{ timeoutMs },
|
|
266
|
-
),
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function registerSimpleContributions(
|
|
272
|
-
api: AgentExtensionApi,
|
|
273
|
-
descriptor: SandboxedPluginDescriptor,
|
|
274
|
-
): void {
|
|
275
|
-
for (const sd of descriptor.contributions.shortcuts) {
|
|
276
|
-
api.registerShortcut({
|
|
277
|
-
name: sd.name,
|
|
278
|
-
value: sd.value ?? "",
|
|
279
|
-
description: sd.description,
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
for (const fd of descriptor.contributions.flags) {
|
|
284
|
-
api.registerFlag({
|
|
285
|
-
name: fd.name,
|
|
286
|
-
description: fd.description,
|
|
287
|
-
defaultValue: fd.defaultValue,
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
for (const rd of descriptor.contributions.messageRenderers) {
|
|
292
|
-
api.registerMessageRenderer({
|
|
293
|
-
name: rd.name,
|
|
294
|
-
render: () => `[sandbox renderer ${rd.name} requires async bridge]`,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
for (const pd of descriptor.contributions.providers) {
|
|
299
|
-
api.registerProvider({
|
|
300
|
-
name: pd.name,
|
|
301
|
-
description: pd.description,
|
|
302
|
-
metadata: pd.metadata,
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function makeHookHandler(
|
|
308
|
-
sandbox: SubprocessSandbox,
|
|
309
|
-
pluginId: string,
|
|
310
|
-
hookName: string,
|
|
311
|
-
timeoutMs: number,
|
|
312
|
-
): (payload: unknown) => Promise<unknown> {
|
|
313
|
-
return async (payload: unknown) =>
|
|
314
|
-
await sandbox.call(
|
|
315
|
-
"invokeHook",
|
|
316
|
-
{ pluginId, hookName, payload },
|
|
317
|
-
{ timeoutMs },
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function bindHooks(
|
|
322
|
-
extension: AgentExtension,
|
|
323
|
-
sandbox: SubprocessSandbox,
|
|
324
|
-
pluginId: string,
|
|
325
|
-
hookTimeoutMs: number,
|
|
326
|
-
): void {
|
|
327
|
-
for (const { stage, extensionKey, sandboxHookName } of HOOK_BINDINGS) {
|
|
328
|
-
if (hasHookStage(extension, stage)) {
|
|
329
|
-
const handler = makeHookHandler(
|
|
330
|
-
sandbox,
|
|
331
|
-
pluginId,
|
|
332
|
-
sandboxHookName,
|
|
333
|
-
hookTimeoutMs,
|
|
334
|
-
);
|
|
335
|
-
// Each hook property on AgentExtension accepts (payload: unknown) => Promise<unknown>.
|
|
336
|
-
// TypeScript cannot narrow a union of optional callback keys via computed access,
|
|
337
|
-
// so we use Object.assign to set the property safely.
|
|
338
|
-
Object.assign(extension, { [extensionKey]: handler });
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|