@clinebot/core 0.0.20 → 0.0.22
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,113 +0,0 @@
|
|
|
1
|
-
import type { LlmsProviders } from "@clinebot/llms";
|
|
2
|
-
import type { ITelemetryService } from "@clinebot/shared";
|
|
3
|
-
import { resolveAndLoadAgentPlugins } from "../agents/plugin-config-loader";
|
|
4
|
-
import {
|
|
5
|
-
createHookAuditHooks,
|
|
6
|
-
createHookConfigFileHooks,
|
|
7
|
-
mergeAgentHooks,
|
|
8
|
-
} from "../runtime/hook-file-hooks";
|
|
9
|
-
import type { ProviderSettingsManager } from "../storage/provider-settings-manager";
|
|
10
|
-
import type { CoreSessionConfig } from "../types/config";
|
|
11
|
-
import {
|
|
12
|
-
type ProviderSettings,
|
|
13
|
-
toProviderConfig,
|
|
14
|
-
} from "../types/provider-settings";
|
|
15
|
-
import type { StartSessionInput } from "./session-manager";
|
|
16
|
-
import { hasRuntimeHooks, mergeAgentExtensions } from "./utils/helpers";
|
|
17
|
-
|
|
18
|
-
export function resolveWorkspacePath(config: CoreSessionConfig): string {
|
|
19
|
-
return config.workspaceRoot ?? config.cwd;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function buildEffectiveConfig(
|
|
23
|
-
input: StartSessionInput,
|
|
24
|
-
hookPath: string,
|
|
25
|
-
sessionId: string,
|
|
26
|
-
defaultTelemetry: ITelemetryService | undefined,
|
|
27
|
-
onPluginEvent?: (event: { name: string; payload?: unknown }) => void,
|
|
28
|
-
): Promise<{
|
|
29
|
-
config: CoreSessionConfig;
|
|
30
|
-
pluginSandboxShutdown?: () => Promise<void>;
|
|
31
|
-
}> {
|
|
32
|
-
const workspacePath = resolveWorkspacePath(input.config);
|
|
33
|
-
|
|
34
|
-
const fileHooks = createHookConfigFileHooks({
|
|
35
|
-
cwd: input.config.cwd,
|
|
36
|
-
workspacePath,
|
|
37
|
-
rootSessionId: sessionId,
|
|
38
|
-
hookLogPath: hookPath,
|
|
39
|
-
logger: input.config.logger,
|
|
40
|
-
});
|
|
41
|
-
const auditHooks = hasRuntimeHooks(input.config.hooks)
|
|
42
|
-
? undefined
|
|
43
|
-
: createHookAuditHooks({
|
|
44
|
-
hookLogPath: hookPath,
|
|
45
|
-
rootSessionId: sessionId,
|
|
46
|
-
workspacePath,
|
|
47
|
-
});
|
|
48
|
-
const effectiveHooks = mergeAgentHooks([
|
|
49
|
-
input.config.hooks,
|
|
50
|
-
fileHooks,
|
|
51
|
-
auditHooks,
|
|
52
|
-
]);
|
|
53
|
-
|
|
54
|
-
const loadedPlugins = await resolveAndLoadAgentPlugins({
|
|
55
|
-
pluginPaths: input.config.pluginPaths,
|
|
56
|
-
workspacePath,
|
|
57
|
-
cwd: input.config.cwd,
|
|
58
|
-
onEvent: onPluginEvent,
|
|
59
|
-
});
|
|
60
|
-
const effectiveExtensions = mergeAgentExtensions(
|
|
61
|
-
input.config.extensions,
|
|
62
|
-
loadedPlugins.extensions,
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
config: {
|
|
67
|
-
...input.config,
|
|
68
|
-
hooks: effectiveHooks,
|
|
69
|
-
extensions: effectiveExtensions,
|
|
70
|
-
telemetry: input.config.telemetry ?? defaultTelemetry,
|
|
71
|
-
},
|
|
72
|
-
pluginSandboxShutdown: loadedPlugins.shutdown,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function buildResolvedProviderConfig(
|
|
77
|
-
config: CoreSessionConfig,
|
|
78
|
-
providerSettingsManager: ProviderSettingsManager,
|
|
79
|
-
resolveReasoningFn: (
|
|
80
|
-
config: CoreSessionConfig,
|
|
81
|
-
storedReasoning: ProviderSettings["reasoning"],
|
|
82
|
-
) => ProviderSettings["reasoning"],
|
|
83
|
-
): LlmsProviders.ProviderConfig {
|
|
84
|
-
const stored = providerSettingsManager.getProviderSettings(config.providerId);
|
|
85
|
-
const settings: ProviderSettings = {
|
|
86
|
-
...(stored ?? {}),
|
|
87
|
-
provider: config.providerId,
|
|
88
|
-
model: config.modelId,
|
|
89
|
-
apiKey: config.apiKey ?? stored?.apiKey,
|
|
90
|
-
baseUrl: config.baseUrl ?? stored?.baseUrl,
|
|
91
|
-
headers: config.headers ?? stored?.headers,
|
|
92
|
-
reasoning: resolveReasoningFn(config, stored?.reasoning),
|
|
93
|
-
};
|
|
94
|
-
const providerConfig = toProviderConfig(settings);
|
|
95
|
-
if (config.knownModels) {
|
|
96
|
-
providerConfig.knownModels = config.knownModels;
|
|
97
|
-
}
|
|
98
|
-
return providerConfig;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function resolveReasoningSettings(
|
|
102
|
-
config: CoreSessionConfig,
|
|
103
|
-
storedReasoning: ProviderSettings["reasoning"],
|
|
104
|
-
): ProviderSettings["reasoning"] {
|
|
105
|
-
const hasThinking = typeof config.thinking === "boolean";
|
|
106
|
-
const hasEffort = typeof config.reasoningEffort === "string";
|
|
107
|
-
if (!hasThinking && !hasEffort) return storedReasoning;
|
|
108
|
-
return {
|
|
109
|
-
...(storedReasoning ?? {}),
|
|
110
|
-
...(hasThinking ? { enabled: config.thinking } : {}),
|
|
111
|
-
...(hasEffort ? { effort: config.reasoningEffort } : {}),
|
|
112
|
-
};
|
|
113
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { HookEventPayload } from "@clinebot/agents";
|
|
2
|
-
import { nanoid } from "nanoid";
|
|
3
|
-
import type { SessionStatus } from "../types/common";
|
|
4
|
-
|
|
5
|
-
export function sanitizeSessionToken(value: string): string {
|
|
6
|
-
return value.replace(/[^a-zA-Z0-9._-]+/g, "_");
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function makeSubSessionId(
|
|
10
|
-
rootSessionId: string,
|
|
11
|
-
agentId: string,
|
|
12
|
-
): string {
|
|
13
|
-
const root = sanitizeSessionToken(rootSessionId);
|
|
14
|
-
const agent = sanitizeSessionToken(agentId);
|
|
15
|
-
const joined = `${root}__${agent}`;
|
|
16
|
-
return joined.length > 180 ? joined.slice(0, 180) : joined;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function makeTeamTaskSubSessionId(
|
|
20
|
-
rootSessionId: string,
|
|
21
|
-
agentId: string,
|
|
22
|
-
): string {
|
|
23
|
-
const root = sanitizeSessionToken(rootSessionId);
|
|
24
|
-
const agent = sanitizeSessionToken(agentId);
|
|
25
|
-
return `${root}__teamtask__${agent}__${nanoid(6)}`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function parseTeamTaskSubSessionId(
|
|
29
|
-
sessionId: string,
|
|
30
|
-
): { rootSessionId: string; agentId: string; teamTaskId: string } | null {
|
|
31
|
-
const marker = "__teamtask__";
|
|
32
|
-
const markerIndex = sessionId.indexOf(marker);
|
|
33
|
-
if (markerIndex <= 0) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
const rootSessionId = sessionId.slice(0, markerIndex);
|
|
37
|
-
const remainder = sessionId.slice(markerIndex + marker.length);
|
|
38
|
-
const lastSeparator = remainder.lastIndexOf("__");
|
|
39
|
-
if (lastSeparator <= 0) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
const agentId = remainder.slice(0, lastSeparator);
|
|
43
|
-
const teamTaskId = remainder.slice(lastSeparator + 2);
|
|
44
|
-
if (!rootSessionId || !agentId || !teamTaskId) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return { rootSessionId, agentId, teamTaskId };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function parseSubSessionId(
|
|
51
|
-
sessionId: string,
|
|
52
|
-
): { rootSessionId: string; agentId: string } | null {
|
|
53
|
-
if (parseTeamTaskSubSessionId(sessionId)) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
const separator = "__";
|
|
57
|
-
const separatorIndex = sessionId.indexOf(separator);
|
|
58
|
-
if (separatorIndex <= 0) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
const rootSessionId = sessionId.slice(0, separatorIndex);
|
|
62
|
-
const agentId = sessionId.slice(separatorIndex + separator.length);
|
|
63
|
-
if (!rootSessionId || !agentId) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return { rootSessionId, agentId };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function deriveSubsessionStatus(event: HookEventPayload): SessionStatus {
|
|
70
|
-
switch (event.hookName) {
|
|
71
|
-
case "agent_end":
|
|
72
|
-
return "completed";
|
|
73
|
-
case "agent_error":
|
|
74
|
-
return "failed";
|
|
75
|
-
case "session_shutdown": {
|
|
76
|
-
const reason = String(event.reason ?? "").toLowerCase();
|
|
77
|
-
if (
|
|
78
|
-
reason.includes("cancel") ||
|
|
79
|
-
reason.includes("abort") ||
|
|
80
|
-
reason.includes("interrupt")
|
|
81
|
-
) {
|
|
82
|
-
return "cancelled";
|
|
83
|
-
}
|
|
84
|
-
if (reason.includes("fail") || reason.includes("error")) {
|
|
85
|
-
return "failed";
|
|
86
|
-
}
|
|
87
|
-
return "completed";
|
|
88
|
-
}
|
|
89
|
-
default:
|
|
90
|
-
return "running";
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
vi.mock("@clinebot/rpc", () => ({
|
|
4
|
-
getRpcServerDefaultAddress: () => "ws://127.0.0.1:0",
|
|
5
|
-
getRpcServerHealth: vi.fn(async () => undefined),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
describe("resolveSessionBackend", () => {
|
|
9
|
-
afterEach(() => {
|
|
10
|
-
vi.resetModules();
|
|
11
|
-
vi.restoreAllMocks();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("falls back to file session storage when sqlite initialization fails", async () => {
|
|
15
|
-
vi.doMock("../storage/sqlite-session-store", () => ({
|
|
16
|
-
SqliteSessionStore: class {
|
|
17
|
-
init(): void {
|
|
18
|
-
throw new Error("sqlite unavailable");
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
const { resolveSessionBackend } = await import("./session-host");
|
|
24
|
-
const { FileSessionService } = await import("./file-session-service");
|
|
25
|
-
|
|
26
|
-
const backend = await resolveSessionBackend({ backendMode: "local" });
|
|
27
|
-
expect(backend).toBeInstanceOf(FileSessionService);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
|
-
import type {
|
|
5
|
-
AgentConfig,
|
|
6
|
-
ToolApprovalRequest,
|
|
7
|
-
ToolApprovalResult,
|
|
8
|
-
} from "@clinebot/agents";
|
|
9
|
-
import { getRpcServerDefaultAddress, getRpcServerHealth } from "@clinebot/rpc";
|
|
10
|
-
import type { ITelemetryService } from "@clinebot/shared";
|
|
11
|
-
import { resolveSessionDataDir } from "@clinebot/shared/storage";
|
|
12
|
-
import { nanoid } from "nanoid";
|
|
13
|
-
import { SqliteSessionStore } from "../storage/sqlite-session-store";
|
|
14
|
-
import type { ToolExecutors } from "../tools";
|
|
15
|
-
import { DefaultSessionManager } from "./default-session-manager";
|
|
16
|
-
import { FileSessionService } from "./file-session-service";
|
|
17
|
-
import { RpcCoreSessionService } from "./rpc-session-service";
|
|
18
|
-
import { tryAcquireRpcSpawnLease } from "./rpc-spawn-lease";
|
|
19
|
-
import type { SessionManager } from "./session-manager";
|
|
20
|
-
import { CoreSessionService } from "./session-service";
|
|
21
|
-
|
|
22
|
-
const DEFAULT_RPC_ADDRESS =
|
|
23
|
-
process.env.CLINE_RPC_ADDRESS?.trim() || getRpcServerDefaultAddress();
|
|
24
|
-
|
|
25
|
-
export type SessionBackend =
|
|
26
|
-
| RpcCoreSessionService
|
|
27
|
-
| CoreSessionService
|
|
28
|
-
| FileSessionService;
|
|
29
|
-
|
|
30
|
-
let cachedBackend: SessionBackend | undefined;
|
|
31
|
-
let backendInitPromise: Promise<SessionBackend> | undefined;
|
|
32
|
-
|
|
33
|
-
export interface CreateSessionHostOptions {
|
|
34
|
-
distinctId?: string;
|
|
35
|
-
sessionService?: SessionBackend;
|
|
36
|
-
backendMode?: "auto" | "rpc" | "local";
|
|
37
|
-
rpcAddress?: string;
|
|
38
|
-
autoStartRpcServer?: boolean;
|
|
39
|
-
rpcConnectAttempts?: number;
|
|
40
|
-
rpcConnectDelayMs?: number;
|
|
41
|
-
defaultToolExecutors?: Partial<ToolExecutors>;
|
|
42
|
-
telemetry?: ITelemetryService;
|
|
43
|
-
toolPolicies?: AgentConfig["toolPolicies"];
|
|
44
|
-
requestToolApproval?: (
|
|
45
|
-
request: ToolApprovalRequest,
|
|
46
|
-
) => Promise<ToolApprovalResult>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type SessionHost = SessionManager;
|
|
50
|
-
|
|
51
|
-
async function reconcileDeadSessionsIfSupported(
|
|
52
|
-
backend: SessionBackend,
|
|
53
|
-
): Promise<void> {
|
|
54
|
-
const service = backend as SessionBackend & {
|
|
55
|
-
reconcileDeadSessions?: (limit?: number) => Promise<number>;
|
|
56
|
-
};
|
|
57
|
-
await service.reconcileDeadSessions?.().catch(() => {});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function startRpcServerInBackground(address: string): void {
|
|
61
|
-
const lease = tryAcquireRpcSpawnLease(address);
|
|
62
|
-
if (!lease) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const launcher = process.execPath;
|
|
66
|
-
const entryArg = process.argv[1]?.trim();
|
|
67
|
-
if (!entryArg) {
|
|
68
|
-
lease.release();
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const entry = resolve(process.cwd(), entryArg);
|
|
72
|
-
if (!existsSync(entry)) {
|
|
73
|
-
lease.release();
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const conditionsArg = process.execArgv.find((arg) =>
|
|
77
|
-
arg.startsWith("--conditions="),
|
|
78
|
-
);
|
|
79
|
-
const args = [
|
|
80
|
-
...(conditionsArg ? [conditionsArg] : []),
|
|
81
|
-
entry,
|
|
82
|
-
"rpc",
|
|
83
|
-
"start",
|
|
84
|
-
"--address",
|
|
85
|
-
address,
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
const child = spawn(launcher, args, {
|
|
89
|
-
detached: true,
|
|
90
|
-
stdio: "ignore",
|
|
91
|
-
env: {
|
|
92
|
-
...process.env,
|
|
93
|
-
CLINE_NO_INTERACTIVE: "1",
|
|
94
|
-
},
|
|
95
|
-
cwd: process.cwd(),
|
|
96
|
-
});
|
|
97
|
-
child.unref();
|
|
98
|
-
setTimeout(() => lease.release(), 10_000).unref();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async function tryConnectRpcBackend(
|
|
102
|
-
address: string,
|
|
103
|
-
): Promise<RpcCoreSessionService | undefined> {
|
|
104
|
-
try {
|
|
105
|
-
const health = await getRpcServerHealth(address);
|
|
106
|
-
if (!health) {
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
return new RpcCoreSessionService({
|
|
110
|
-
address,
|
|
111
|
-
sessionsDir: resolveSessionDataDir(),
|
|
112
|
-
});
|
|
113
|
-
} catch {
|
|
114
|
-
return undefined;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function createLocalBackend(): SessionBackend {
|
|
119
|
-
try {
|
|
120
|
-
const store = new SqliteSessionStore();
|
|
121
|
-
store.init();
|
|
122
|
-
return new CoreSessionService(store);
|
|
123
|
-
} catch (error) {
|
|
124
|
-
console.warn(
|
|
125
|
-
"SQLite session persistence unavailable, falling back to file-based session storage.",
|
|
126
|
-
error,
|
|
127
|
-
);
|
|
128
|
-
return new FileSessionService();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function resolveHostDistinctId(explicitDistinctId: string | undefined): string {
|
|
133
|
-
if (
|
|
134
|
-
typeof explicitDistinctId === "string" &&
|
|
135
|
-
explicitDistinctId.trim().length > 0
|
|
136
|
-
) {
|
|
137
|
-
return explicitDistinctId.trim();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const sessionDataDir = resolveSessionDataDir();
|
|
141
|
-
const distinctIdPath = resolve(sessionDataDir, "machine-id");
|
|
142
|
-
try {
|
|
143
|
-
if (existsSync(distinctIdPath)) {
|
|
144
|
-
const savedDistinctId = readFileSync(distinctIdPath, "utf8").trim();
|
|
145
|
-
if (savedDistinctId.length > 0) {
|
|
146
|
-
return savedDistinctId;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
} catch {
|
|
150
|
-
// Ignore read errors and generate a fresh fallback ID.
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const generatedDistinctId = nanoid();
|
|
154
|
-
try {
|
|
155
|
-
mkdirSync(sessionDataDir, { recursive: true });
|
|
156
|
-
writeFileSync(distinctIdPath, generatedDistinctId, "utf8");
|
|
157
|
-
} catch {
|
|
158
|
-
// Ignore write errors and continue with in-memory fallback.
|
|
159
|
-
}
|
|
160
|
-
return generatedDistinctId;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export async function resolveSessionBackend(
|
|
164
|
-
options: CreateSessionHostOptions,
|
|
165
|
-
): Promise<SessionBackend> {
|
|
166
|
-
if (cachedBackend) {
|
|
167
|
-
return cachedBackend;
|
|
168
|
-
}
|
|
169
|
-
if (backendInitPromise) {
|
|
170
|
-
return await backendInitPromise;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const mode = options.backendMode ?? "auto";
|
|
174
|
-
const address = options.rpcAddress?.trim() || DEFAULT_RPC_ADDRESS;
|
|
175
|
-
const attempts = Math.max(1, options.rpcConnectAttempts ?? 5);
|
|
176
|
-
const delayMs = Math.max(0, options.rpcConnectDelayMs ?? 100);
|
|
177
|
-
const autoStartRpc = options.autoStartRpcServer !== false;
|
|
178
|
-
|
|
179
|
-
backendInitPromise = (async () => {
|
|
180
|
-
if (mode === "local") {
|
|
181
|
-
cachedBackend = createLocalBackend();
|
|
182
|
-
await reconcileDeadSessionsIfSupported(cachedBackend);
|
|
183
|
-
return cachedBackend;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const existingRpcBackend = await tryConnectRpcBackend(address);
|
|
187
|
-
if (existingRpcBackend) {
|
|
188
|
-
cachedBackend = existingRpcBackend;
|
|
189
|
-
await reconcileDeadSessionsIfSupported(cachedBackend);
|
|
190
|
-
return cachedBackend;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (mode === "rpc") {
|
|
194
|
-
throw new Error(`RPC backend unavailable at ${address}`);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (autoStartRpc) {
|
|
198
|
-
try {
|
|
199
|
-
startRpcServerInBackground(address);
|
|
200
|
-
} catch {
|
|
201
|
-
// Ignore launch failures and fall back to local backend.
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
205
|
-
const rpcBackend = await tryConnectRpcBackend(address);
|
|
206
|
-
if (rpcBackend) {
|
|
207
|
-
cachedBackend = rpcBackend;
|
|
208
|
-
await reconcileDeadSessionsIfSupported(cachedBackend);
|
|
209
|
-
return cachedBackend;
|
|
210
|
-
}
|
|
211
|
-
if (delayMs > 0) {
|
|
212
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
cachedBackend = createLocalBackend();
|
|
218
|
-
await reconcileDeadSessionsIfSupported(cachedBackend);
|
|
219
|
-
return cachedBackend;
|
|
220
|
-
})().finally(() => {
|
|
221
|
-
backendInitPromise = undefined;
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
return await backendInitPromise;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export async function createSessionHost(
|
|
228
|
-
options: CreateSessionHostOptions,
|
|
229
|
-
): Promise<SessionHost> {
|
|
230
|
-
const distinctId = resolveHostDistinctId(options.distinctId);
|
|
231
|
-
options.telemetry?.setDistinctId(distinctId);
|
|
232
|
-
const backend =
|
|
233
|
-
options.sessionService ?? (await resolveSessionBackend(options));
|
|
234
|
-
return new DefaultSessionManager({
|
|
235
|
-
sessionService: backend,
|
|
236
|
-
defaultToolExecutors: options.defaultToolExecutors,
|
|
237
|
-
telemetry: options.telemetry,
|
|
238
|
-
toolPolicies: options.toolPolicies,
|
|
239
|
-
requestToolApproval: options.requestToolApproval,
|
|
240
|
-
distinctId,
|
|
241
|
-
});
|
|
242
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { AgentResult } from "@clinebot/agents";
|
|
2
|
-
import type { LlmsProviders } from "@clinebot/llms";
|
|
3
|
-
import type { SessionSource } from "../types/common";
|
|
4
|
-
import type { CoreSessionConfig } from "../types/config";
|
|
5
|
-
import type { CoreSessionEvent } from "../types/events";
|
|
6
|
-
import type { SessionRecord } from "../types/sessions";
|
|
7
|
-
import type { SessionManifest } from "./session-manifest";
|
|
8
|
-
|
|
9
|
-
export interface StartSessionInput {
|
|
10
|
-
config: CoreSessionConfig;
|
|
11
|
-
source?: SessionSource;
|
|
12
|
-
prompt?: string;
|
|
13
|
-
interactive?: boolean;
|
|
14
|
-
initialMessages?: LlmsProviders.Message[];
|
|
15
|
-
userImages?: string[];
|
|
16
|
-
userFiles?: string[];
|
|
17
|
-
userInstructionWatcher?: import("../agents").UserInstructionConfigWatcher;
|
|
18
|
-
onTeamRestored?: () => void;
|
|
19
|
-
defaultToolExecutors?: Partial<import("../tools").ToolExecutors>;
|
|
20
|
-
toolPolicies?: import("@clinebot/agents").AgentConfig["toolPolicies"];
|
|
21
|
-
requestToolApproval?: (
|
|
22
|
-
request: import("@clinebot/agents").ToolApprovalRequest,
|
|
23
|
-
) => Promise<import("@clinebot/agents").ToolApprovalResult>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface StartSessionResult {
|
|
27
|
-
sessionId: string;
|
|
28
|
-
manifest: SessionManifest;
|
|
29
|
-
manifestPath: string;
|
|
30
|
-
transcriptPath: string;
|
|
31
|
-
hookPath: string;
|
|
32
|
-
messagesPath: string;
|
|
33
|
-
result?: AgentResult;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface SendSessionInput {
|
|
37
|
-
sessionId: string;
|
|
38
|
-
prompt: string;
|
|
39
|
-
userImages?: string[];
|
|
40
|
-
userFiles?: string[];
|
|
41
|
-
delivery?: "queue" | "steer";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface SessionAccumulatedUsage {
|
|
45
|
-
inputTokens: number;
|
|
46
|
-
outputTokens: number;
|
|
47
|
-
cacheReadTokens: number;
|
|
48
|
-
cacheWriteTokens: number;
|
|
49
|
-
totalCost: number;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface SessionManager {
|
|
53
|
-
start(input: StartSessionInput): Promise<StartSessionResult>;
|
|
54
|
-
send(input: SendSessionInput): Promise<AgentResult | undefined>;
|
|
55
|
-
getAccumulatedUsage(
|
|
56
|
-
sessionId: string,
|
|
57
|
-
): Promise<SessionAccumulatedUsage | undefined>;
|
|
58
|
-
abort(sessionId: string, reason?: unknown): Promise<void>;
|
|
59
|
-
stop(sessionId: string): Promise<void>;
|
|
60
|
-
dispose(reason?: string): Promise<void>;
|
|
61
|
-
get(sessionId: string): Promise<SessionRecord | undefined>;
|
|
62
|
-
list(limit?: number): Promise<SessionRecord[]>;
|
|
63
|
-
delete(sessionId: string): Promise<boolean>;
|
|
64
|
-
readMessages(sessionId: string): Promise<LlmsProviders.Message[]>;
|
|
65
|
-
readTranscript(sessionId: string, maxChars?: number): Promise<string>;
|
|
66
|
-
readHooks(sessionId: string, limit?: number): Promise<unknown[]>;
|
|
67
|
-
subscribe(listener: (event: CoreSessionEvent) => void): () => void;
|
|
68
|
-
updateSessionModel?(sessionId: string, modelId: string): Promise<void>;
|
|
69
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { SESSION_STATUSES, SessionSource } from "../types/common";
|
|
3
|
-
|
|
4
|
-
const SessionStatusSchema = z.enum(SESSION_STATUSES);
|
|
5
|
-
|
|
6
|
-
export const SessionManifestSchema = z.object({
|
|
7
|
-
version: z.literal(1),
|
|
8
|
-
session_id: z.string().min(1),
|
|
9
|
-
source: z.enum(SessionSource),
|
|
10
|
-
pid: z.number().int(),
|
|
11
|
-
started_at: z.string().min(1),
|
|
12
|
-
ended_at: z.string().min(1).optional(),
|
|
13
|
-
exit_code: z.number().int().nullable().optional(),
|
|
14
|
-
status: SessionStatusSchema,
|
|
15
|
-
interactive: z.boolean(),
|
|
16
|
-
provider: z.string().min(1),
|
|
17
|
-
model: z.string().min(1),
|
|
18
|
-
cwd: z.string().min(1),
|
|
19
|
-
workspace_root: z.string().min(1),
|
|
20
|
-
team_name: z.string().min(1).optional(),
|
|
21
|
-
enable_tools: z.boolean(),
|
|
22
|
-
enable_spawn: z.boolean(),
|
|
23
|
-
enable_teams: z.boolean(),
|
|
24
|
-
prompt: z.string().optional(),
|
|
25
|
-
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
26
|
-
messages_path: z.string().min(1).optional(),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
export type SessionManifest = z.infer<typeof SessionManifestSchema>;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdtempSync } from "node:fs";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { AgentTeamsRuntime } from "@clinebot/agents";
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
import { FileTeamPersistenceStore } from "./session-service";
|
|
7
|
-
|
|
8
|
-
describe("FileTeamPersistenceStore", () => {
|
|
9
|
-
it("does not create state.json for an empty runtime", () => {
|
|
10
|
-
const baseDir = mkdtempSync(join(tmpdir(), "team-store-"));
|
|
11
|
-
const store = new FileTeamPersistenceStore({
|
|
12
|
-
teamName: "agent-team-nmnn9",
|
|
13
|
-
baseDir,
|
|
14
|
-
});
|
|
15
|
-
const runtime = new AgentTeamsRuntime({ teamName: "agent-team-nmnn9" });
|
|
16
|
-
|
|
17
|
-
store.persist(runtime);
|
|
18
|
-
|
|
19
|
-
expect(
|
|
20
|
-
existsSync(join(baseDir, "agent-team-nmnn9", "state.json")),
|
|
21
|
-
).toBeFalsy();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("removes persisted state when runtime becomes empty again", () => {
|
|
25
|
-
const baseDir = mkdtempSync(join(tmpdir(), "team-store-"));
|
|
26
|
-
const store = new FileTeamPersistenceStore({
|
|
27
|
-
teamName: "agent-team-cleanup",
|
|
28
|
-
baseDir,
|
|
29
|
-
});
|
|
30
|
-
const runtime = new AgentTeamsRuntime({ teamName: "agent-team-cleanup" });
|
|
31
|
-
|
|
32
|
-
store.upsertTeammateSpec({
|
|
33
|
-
agentId: "worker",
|
|
34
|
-
rolePrompt: "Implement tasks",
|
|
35
|
-
});
|
|
36
|
-
store.persist(runtime);
|
|
37
|
-
expect(
|
|
38
|
-
existsSync(join(baseDir, "agent-team-cleanup", "state.json")),
|
|
39
|
-
).toBeTruthy();
|
|
40
|
-
|
|
41
|
-
store.removeTeammateSpec("worker");
|
|
42
|
-
runtime.cleanup();
|
|
43
|
-
store.persist(runtime);
|
|
44
|
-
expect(
|
|
45
|
-
existsSync(join(baseDir, "agent-team-cleanup", "state.json")),
|
|
46
|
-
).toBeFalsy();
|
|
47
|
-
});
|
|
48
|
-
});
|