@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,137 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
OAuthReauthRequiredError,
|
|
4
|
-
RuntimeOAuthTokenManager,
|
|
5
|
-
} from "./runtime-oauth-token-manager";
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
getValidOpenAICodexCredentials,
|
|
9
|
-
getValidClineCredentials,
|
|
10
|
-
getValidOcaCredentials,
|
|
11
|
-
} = vi.hoisted(() => ({
|
|
12
|
-
getValidOpenAICodexCredentials: vi.fn(),
|
|
13
|
-
getValidClineCredentials: vi.fn(),
|
|
14
|
-
getValidOcaCredentials: vi.fn(),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
vi.mock("../auth/codex", () => ({
|
|
18
|
-
getValidOpenAICodexCredentials,
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
vi.mock("../auth/cline", () => ({
|
|
22
|
-
getValidClineCredentials,
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
vi.mock("../auth/oca", () => ({
|
|
26
|
-
getValidOcaCredentials,
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
describe("RuntimeOAuthTokenManager", () => {
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
vi.clearAllMocks();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("refreshes and persists OpenAI Codex OAuth credentials", async () => {
|
|
35
|
-
const getProviderSettings = vi.fn().mockReturnValue({
|
|
36
|
-
provider: "openai-codex",
|
|
37
|
-
auth: {
|
|
38
|
-
accessToken: "access-old",
|
|
39
|
-
refreshToken: "refresh-old",
|
|
40
|
-
expiresAt: Date.now() - 1_000,
|
|
41
|
-
accountId: "acct-old",
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
const saveProviderSettings = vi.fn();
|
|
45
|
-
|
|
46
|
-
getValidOpenAICodexCredentials.mockResolvedValueOnce({
|
|
47
|
-
access: "access-new",
|
|
48
|
-
refresh: "refresh-new",
|
|
49
|
-
expires: 4_000_000_000_000,
|
|
50
|
-
accountId: "acct-new",
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const manager = new RuntimeOAuthTokenManager({
|
|
54
|
-
providerSettingsManager: {
|
|
55
|
-
getProviderSettings,
|
|
56
|
-
saveProviderSettings,
|
|
57
|
-
} as never,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const result = await manager.resolveProviderApiKey({
|
|
61
|
-
providerId: "openai-codex",
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
expect(result).toMatchObject({
|
|
65
|
-
providerId: "openai-codex",
|
|
66
|
-
apiKey: "access-new",
|
|
67
|
-
accountId: "acct-new",
|
|
68
|
-
refreshed: true,
|
|
69
|
-
});
|
|
70
|
-
expect(saveProviderSettings).toHaveBeenCalledWith(
|
|
71
|
-
expect.objectContaining({
|
|
72
|
-
auth: expect.objectContaining({
|
|
73
|
-
accessToken: "access-new",
|
|
74
|
-
refreshToken: "refresh-new",
|
|
75
|
-
accountId: "acct-new",
|
|
76
|
-
expiresAt: 4_000_000_000_000,
|
|
77
|
-
}),
|
|
78
|
-
}),
|
|
79
|
-
{ setLastUsed: false, tokenSource: "oauth" },
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("throws re-auth required when refresh returns null", async () => {
|
|
84
|
-
getValidOpenAICodexCredentials.mockResolvedValueOnce(null);
|
|
85
|
-
const manager = new RuntimeOAuthTokenManager({
|
|
86
|
-
providerSettingsManager: {
|
|
87
|
-
getProviderSettings: vi.fn().mockReturnValue({
|
|
88
|
-
provider: "openai-codex",
|
|
89
|
-
auth: {
|
|
90
|
-
accessToken: "access-old",
|
|
91
|
-
refreshToken: "refresh-old",
|
|
92
|
-
expiresAt: Date.now() - 1_000,
|
|
93
|
-
},
|
|
94
|
-
}),
|
|
95
|
-
saveProviderSettings: vi.fn(),
|
|
96
|
-
} as never,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
await expect(
|
|
100
|
-
manager.resolveProviderApiKey({ providerId: "openai-codex" }),
|
|
101
|
-
).rejects.toBeInstanceOf(OAuthReauthRequiredError);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("de-duplicates concurrent refresh calls per provider", async () => {
|
|
105
|
-
const refreshBarrier = Promise.resolve().then(() => ({
|
|
106
|
-
access: "access-new",
|
|
107
|
-
refresh: "refresh-new",
|
|
108
|
-
expires: Date.now() + 60_000,
|
|
109
|
-
}));
|
|
110
|
-
getValidOpenAICodexCredentials.mockImplementationOnce(
|
|
111
|
-
async () => refreshBarrier,
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
const manager = new RuntimeOAuthTokenManager({
|
|
115
|
-
providerSettingsManager: {
|
|
116
|
-
getProviderSettings: vi.fn().mockReturnValue({
|
|
117
|
-
provider: "openai-codex",
|
|
118
|
-
auth: {
|
|
119
|
-
accessToken: "access-old",
|
|
120
|
-
refreshToken: "refresh-old",
|
|
121
|
-
expiresAt: Date.now() - 1_000,
|
|
122
|
-
},
|
|
123
|
-
}),
|
|
124
|
-
saveProviderSettings: vi.fn(),
|
|
125
|
-
} as never,
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const [first, second] = await Promise.all([
|
|
129
|
-
manager.resolveProviderApiKey({ providerId: "openai-codex" }),
|
|
130
|
-
manager.resolveProviderApiKey({ providerId: "openai-codex" }),
|
|
131
|
-
]);
|
|
132
|
-
|
|
133
|
-
expect(first?.apiKey).toBe("access-new");
|
|
134
|
-
expect(second?.apiKey).toBe("access-new");
|
|
135
|
-
expect(getValidOpenAICodexCredentials).toHaveBeenCalledTimes(1);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import type { LlmsProviders } from "@clinebot/llms";
|
|
2
|
-
import {
|
|
3
|
-
type ITelemetryService,
|
|
4
|
-
isOAuthProviderId,
|
|
5
|
-
type OAuthProviderId,
|
|
6
|
-
} from "@clinebot/shared";
|
|
7
|
-
import {
|
|
8
|
-
type ClineOAuthCredentials,
|
|
9
|
-
getValidClineCredentials,
|
|
10
|
-
} from "../auth/cline";
|
|
11
|
-
import { getValidOpenAICodexCredentials } from "../auth/codex";
|
|
12
|
-
import { getValidOcaCredentials } from "../auth/oca";
|
|
13
|
-
import { decodeJwtPayload } from "../auth/utils";
|
|
14
|
-
import { ProviderSettingsManager } from "../storage/provider-settings-manager";
|
|
15
|
-
|
|
16
|
-
const DEFAULT_CLINE_API_BASE_URL = "https://api.cline.bot";
|
|
17
|
-
const WORKOS_TOKEN_PREFIX = "workos:";
|
|
18
|
-
|
|
19
|
-
type ManagedOAuthProviderId = OAuthProviderId;
|
|
20
|
-
|
|
21
|
-
function toStoredAccessToken(
|
|
22
|
-
providerId: ManagedOAuthProviderId,
|
|
23
|
-
accessToken: string,
|
|
24
|
-
): string {
|
|
25
|
-
if (providerId === "cline") {
|
|
26
|
-
return `${WORKOS_TOKEN_PREFIX}${accessToken}`;
|
|
27
|
-
}
|
|
28
|
-
return accessToken;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function fromStoredAccessToken(
|
|
32
|
-
providerId: ManagedOAuthProviderId,
|
|
33
|
-
accessToken: string,
|
|
34
|
-
): string {
|
|
35
|
-
if (
|
|
36
|
-
providerId === "cline" &&
|
|
37
|
-
accessToken.toLowerCase().startsWith(WORKOS_TOKEN_PREFIX)
|
|
38
|
-
) {
|
|
39
|
-
return accessToken.slice(WORKOS_TOKEN_PREFIX.length);
|
|
40
|
-
}
|
|
41
|
-
return accessToken;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function readExpiryFromToken(accessToken: string): number | null {
|
|
45
|
-
const payload = decodeJwtPayload(accessToken);
|
|
46
|
-
const exp = payload?.exp;
|
|
47
|
-
if (typeof exp === "number" && exp > 0) {
|
|
48
|
-
return exp * 1000;
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function deriveCredentialExpiry(
|
|
54
|
-
settings: LlmsProviders.ProviderSettings,
|
|
55
|
-
normalizedAccessToken: string,
|
|
56
|
-
): number {
|
|
57
|
-
const explicitExpiry = (
|
|
58
|
-
settings.auth as
|
|
59
|
-
| (LlmsProviders.ProviderSettings["auth"] & { expiresAt?: number })
|
|
60
|
-
| undefined
|
|
61
|
-
)?.expiresAt;
|
|
62
|
-
if (
|
|
63
|
-
typeof explicitExpiry === "number" &&
|
|
64
|
-
Number.isFinite(explicitExpiry) &&
|
|
65
|
-
explicitExpiry > 0
|
|
66
|
-
) {
|
|
67
|
-
return explicitExpiry;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const jwtExpiry = readExpiryFromToken(normalizedAccessToken);
|
|
71
|
-
if (jwtExpiry) {
|
|
72
|
-
return jwtExpiry;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Unknown expiry should trigger refresh on next resolution.
|
|
76
|
-
return Date.now() - 1;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function toCredentials(
|
|
80
|
-
providerId: ManagedOAuthProviderId,
|
|
81
|
-
settings: LlmsProviders.ProviderSettings,
|
|
82
|
-
): ClineOAuthCredentials | null {
|
|
83
|
-
const rawAccess = settings.auth?.accessToken?.trim();
|
|
84
|
-
const refreshToken = settings.auth?.refreshToken?.trim();
|
|
85
|
-
if (!rawAccess || !refreshToken) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
const access = fromStoredAccessToken(providerId, rawAccess);
|
|
89
|
-
if (!access) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
access,
|
|
95
|
-
refresh: refreshToken,
|
|
96
|
-
expires: deriveCredentialExpiry(settings, access),
|
|
97
|
-
accountId: settings.auth?.accountId,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function authSettingsEqual(
|
|
102
|
-
a: LlmsProviders.ProviderSettings["auth"] | undefined,
|
|
103
|
-
b: LlmsProviders.ProviderSettings["auth"] | undefined,
|
|
104
|
-
): boolean {
|
|
105
|
-
const aExpiry = (
|
|
106
|
-
a as
|
|
107
|
-
| (LlmsProviders.ProviderSettings["auth"] & { expiresAt?: number })
|
|
108
|
-
| undefined
|
|
109
|
-
)?.expiresAt;
|
|
110
|
-
const bExpiry = (
|
|
111
|
-
b as
|
|
112
|
-
| (LlmsProviders.ProviderSettings["auth"] & { expiresAt?: number })
|
|
113
|
-
| undefined
|
|
114
|
-
)?.expiresAt;
|
|
115
|
-
return (
|
|
116
|
-
a?.accessToken === b?.accessToken &&
|
|
117
|
-
a?.refreshToken === b?.refreshToken &&
|
|
118
|
-
a?.accountId === b?.accountId &&
|
|
119
|
-
aExpiry === bExpiry
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export class OAuthReauthRequiredError extends Error {
|
|
124
|
-
public readonly providerId: ManagedOAuthProviderId;
|
|
125
|
-
|
|
126
|
-
constructor(providerId: ManagedOAuthProviderId) {
|
|
127
|
-
super(
|
|
128
|
-
`OAuth credentials for provider "${providerId}" are no longer valid. Re-run authentication for this provider.`,
|
|
129
|
-
);
|
|
130
|
-
this.name = "OAuthReauthRequiredError";
|
|
131
|
-
this.providerId = providerId;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export type RuntimeOAuthResolution = {
|
|
136
|
-
providerId: ManagedOAuthProviderId;
|
|
137
|
-
apiKey: string;
|
|
138
|
-
accountId?: string;
|
|
139
|
-
refreshed: boolean;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export class RuntimeOAuthTokenManager {
|
|
143
|
-
private readonly providerSettingsManager: ProviderSettingsManager;
|
|
144
|
-
private readonly telemetry?: ITelemetryService;
|
|
145
|
-
private readonly refreshInFlight = new Map<
|
|
146
|
-
ManagedOAuthProviderId,
|
|
147
|
-
Promise<RuntimeOAuthResolution | null>
|
|
148
|
-
>();
|
|
149
|
-
|
|
150
|
-
constructor(options?: {
|
|
151
|
-
providerSettingsManager?: ProviderSettingsManager;
|
|
152
|
-
telemetry?: ITelemetryService;
|
|
153
|
-
}) {
|
|
154
|
-
this.providerSettingsManager =
|
|
155
|
-
options?.providerSettingsManager ?? new ProviderSettingsManager();
|
|
156
|
-
this.telemetry = options?.telemetry;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
public async resolveProviderApiKey(input: {
|
|
160
|
-
providerId: string;
|
|
161
|
-
forceRefresh?: boolean;
|
|
162
|
-
}): Promise<RuntimeOAuthResolution | null> {
|
|
163
|
-
if (!isOAuthProviderId(input.providerId)) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
return this.resolveWithSingleFlight(input.providerId, input.forceRefresh);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
private async resolveWithSingleFlight(
|
|
170
|
-
providerId: ManagedOAuthProviderId,
|
|
171
|
-
forceRefresh = false,
|
|
172
|
-
): Promise<RuntimeOAuthResolution | null> {
|
|
173
|
-
const currentInFlight = this.refreshInFlight.get(providerId);
|
|
174
|
-
if (currentInFlight) {
|
|
175
|
-
return currentInFlight;
|
|
176
|
-
}
|
|
177
|
-
const pending = this.resolveProviderApiKeyInternal(providerId, forceRefresh)
|
|
178
|
-
.catch((error) => {
|
|
179
|
-
throw error;
|
|
180
|
-
})
|
|
181
|
-
.finally(() => {
|
|
182
|
-
this.refreshInFlight.delete(providerId);
|
|
183
|
-
});
|
|
184
|
-
this.refreshInFlight.set(providerId, pending);
|
|
185
|
-
return pending;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
private async resolveProviderApiKeyInternal(
|
|
189
|
-
providerId: ManagedOAuthProviderId,
|
|
190
|
-
forceRefresh: boolean,
|
|
191
|
-
): Promise<RuntimeOAuthResolution | null> {
|
|
192
|
-
const settings =
|
|
193
|
-
this.providerSettingsManager.getProviderSettings(providerId);
|
|
194
|
-
if (!settings) {
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const currentCredentials = toCredentials(providerId, settings);
|
|
199
|
-
if (!currentCredentials) {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const nextCredentials = await this.resolveCredentials(
|
|
204
|
-
providerId,
|
|
205
|
-
settings,
|
|
206
|
-
currentCredentials,
|
|
207
|
-
forceRefresh,
|
|
208
|
-
);
|
|
209
|
-
if (!nextCredentials) {
|
|
210
|
-
throw new OAuthReauthRequiredError(providerId);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const persistedAccessToken = toStoredAccessToken(
|
|
214
|
-
providerId,
|
|
215
|
-
nextCredentials.access,
|
|
216
|
-
);
|
|
217
|
-
const nextAuth = {
|
|
218
|
-
...(settings.auth ?? {}),
|
|
219
|
-
accessToken: persistedAccessToken,
|
|
220
|
-
refreshToken: nextCredentials.refresh,
|
|
221
|
-
accountId: nextCredentials.accountId,
|
|
222
|
-
} as LlmsProviders.ProviderSettings["auth"] & { expiresAt?: number };
|
|
223
|
-
nextAuth.expiresAt = nextCredentials.expires;
|
|
224
|
-
const nextSettings: LlmsProviders.ProviderSettings = {
|
|
225
|
-
...settings,
|
|
226
|
-
auth: nextAuth,
|
|
227
|
-
};
|
|
228
|
-
const wasRefreshed = !authSettingsEqual(settings.auth, nextSettings.auth);
|
|
229
|
-
if (wasRefreshed) {
|
|
230
|
-
this.providerSettingsManager.saveProviderSettings(nextSettings, {
|
|
231
|
-
setLastUsed: false,
|
|
232
|
-
tokenSource: "oauth",
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
providerId,
|
|
238
|
-
apiKey: persistedAccessToken,
|
|
239
|
-
accountId: nextCredentials.accountId,
|
|
240
|
-
refreshed: wasRefreshed,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
private async resolveCredentials(
|
|
245
|
-
providerId: ManagedOAuthProviderId,
|
|
246
|
-
settings: LlmsProviders.ProviderSettings,
|
|
247
|
-
currentCredentials: ClineOAuthCredentials,
|
|
248
|
-
forceRefresh: boolean,
|
|
249
|
-
): Promise<ClineOAuthCredentials | null> {
|
|
250
|
-
if (providerId === "cline") {
|
|
251
|
-
return getValidClineCredentials(
|
|
252
|
-
currentCredentials,
|
|
253
|
-
{
|
|
254
|
-
apiBaseUrl: settings.baseUrl?.trim() || DEFAULT_CLINE_API_BASE_URL,
|
|
255
|
-
telemetry: this.telemetry,
|
|
256
|
-
},
|
|
257
|
-
{ forceRefresh },
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
if (providerId === "oca") {
|
|
261
|
-
return getValidOcaCredentials(
|
|
262
|
-
currentCredentials,
|
|
263
|
-
{ forceRefresh, telemetry: this.telemetry },
|
|
264
|
-
{ mode: settings.oca?.mode, telemetry: this.telemetry },
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
return getValidOpenAICodexCredentials(currentCredentials, {
|
|
268
|
-
forceRefresh,
|
|
269
|
-
telemetry: this.telemetry,
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import type { AgentEvent } from "@clinebot/agents";
|
|
2
|
-
import {
|
|
3
|
-
captureConversationTurnEvent,
|
|
4
|
-
captureDiffEditFailure,
|
|
5
|
-
captureProviderApiError,
|
|
6
|
-
captureSkillUsed,
|
|
7
|
-
captureTokenUsage,
|
|
8
|
-
captureToolUsage,
|
|
9
|
-
} from "../telemetry/core-events";
|
|
10
|
-
import type { CoreSessionConfig } from "../types/config";
|
|
11
|
-
import type { CoreSessionEvent } from "../types/events";
|
|
12
|
-
import type { SessionAccumulatedUsage } from "./session-manager";
|
|
13
|
-
import { serializeAgentEvent } from "./utils/helpers";
|
|
14
|
-
import type { ActiveSession } from "./utils/types";
|
|
15
|
-
import { accumulateUsageTotals } from "./utils/usage";
|
|
16
|
-
|
|
17
|
-
export function extractSkillNameFromToolInput(
|
|
18
|
-
input: unknown,
|
|
19
|
-
): string | undefined {
|
|
20
|
-
if (!input || typeof input !== "object") return undefined;
|
|
21
|
-
const record = input as Record<string, unknown>;
|
|
22
|
-
const skillName = record.skill ?? record.skill_name ?? record.skillName;
|
|
23
|
-
if (typeof skillName !== "string") return undefined;
|
|
24
|
-
const trimmed = skillName.trim();
|
|
25
|
-
return trimmed.length > 0 ? trimmed : undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface AgentEventContext {
|
|
29
|
-
sessionId: string;
|
|
30
|
-
config: CoreSessionConfig;
|
|
31
|
-
liveSession: ActiveSession | undefined;
|
|
32
|
-
usageBySession: Map<string, SessionAccumulatedUsage>;
|
|
33
|
-
persistMessages: (
|
|
34
|
-
sessionId: string,
|
|
35
|
-
messages: unknown[],
|
|
36
|
-
systemPrompt?: string,
|
|
37
|
-
) => void;
|
|
38
|
-
emit: (event: CoreSessionEvent) => void;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function handleAgentEvent(
|
|
42
|
-
ctx: AgentEventContext,
|
|
43
|
-
event: AgentEvent,
|
|
44
|
-
): void {
|
|
45
|
-
const { sessionId, config, liveSession, emit } = ctx;
|
|
46
|
-
const telemetry = config.telemetry;
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
event.type === "content_start" &&
|
|
50
|
-
event.contentType === "tool" &&
|
|
51
|
-
event.toolName === "skills"
|
|
52
|
-
) {
|
|
53
|
-
const skillName = extractSkillNameFromToolInput(event.input);
|
|
54
|
-
if (skillName) {
|
|
55
|
-
captureSkillUsed(telemetry, {
|
|
56
|
-
ulid: sessionId,
|
|
57
|
-
skillName,
|
|
58
|
-
skillSource: "project",
|
|
59
|
-
skillsAvailableGlobal: 0,
|
|
60
|
-
skillsAvailableProject: 0,
|
|
61
|
-
provider: config.providerId,
|
|
62
|
-
modelId: config.modelId,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (event.type === "content_end" && event.contentType === "tool") {
|
|
68
|
-
const toolName = event.toolName ?? "unknown";
|
|
69
|
-
const success = !event.error;
|
|
70
|
-
captureToolUsage(telemetry, {
|
|
71
|
-
ulid: sessionId,
|
|
72
|
-
tool: toolName,
|
|
73
|
-
autoApproved: undefined,
|
|
74
|
-
success,
|
|
75
|
-
modelId: config.modelId,
|
|
76
|
-
provider: config.providerId,
|
|
77
|
-
isNativeToolCall: false,
|
|
78
|
-
});
|
|
79
|
-
if (!success && (toolName === "editor" || toolName === "apply_patch")) {
|
|
80
|
-
captureDiffEditFailure(telemetry, {
|
|
81
|
-
ulid: sessionId,
|
|
82
|
-
modelId: config.modelId,
|
|
83
|
-
provider: config.providerId,
|
|
84
|
-
errorType: event.error,
|
|
85
|
-
isNativeToolCall: false,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (event.type === "notice" && event.reason === "api_error") {
|
|
91
|
-
captureProviderApiError(telemetry, {
|
|
92
|
-
ulid: sessionId,
|
|
93
|
-
model: config.modelId,
|
|
94
|
-
provider: config.providerId,
|
|
95
|
-
errorMessage: event.message,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (event.type === "error") {
|
|
100
|
-
captureProviderApiError(telemetry, {
|
|
101
|
-
ulid: sessionId,
|
|
102
|
-
model: config.modelId,
|
|
103
|
-
provider: config.providerId,
|
|
104
|
-
errorMessage: event.error?.message ?? "unknown error",
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (event.type === "usage" && liveSession?.turnUsageBaseline) {
|
|
109
|
-
ctx.usageBySession.set(
|
|
110
|
-
sessionId,
|
|
111
|
-
accumulateUsageTotals(liveSession.turnUsageBaseline, {
|
|
112
|
-
inputTokens: event.totalInputTokens,
|
|
113
|
-
outputTokens: event.totalOutputTokens,
|
|
114
|
-
totalCost: event.totalCost,
|
|
115
|
-
}),
|
|
116
|
-
);
|
|
117
|
-
captureConversationTurnEvent(telemetry, {
|
|
118
|
-
ulid: sessionId,
|
|
119
|
-
provider: config.providerId,
|
|
120
|
-
model: config.modelId,
|
|
121
|
-
source: "assistant",
|
|
122
|
-
mode: config.mode,
|
|
123
|
-
tokensIn: event.inputTokens,
|
|
124
|
-
tokensOut: event.outputTokens,
|
|
125
|
-
cacheWriteTokens: event.cacheWriteTokens,
|
|
126
|
-
cacheReadTokens: event.cacheReadTokens,
|
|
127
|
-
totalCost: event.cost,
|
|
128
|
-
isNativeToolCall: false,
|
|
129
|
-
});
|
|
130
|
-
captureTokenUsage(telemetry, {
|
|
131
|
-
ulid: sessionId,
|
|
132
|
-
tokensIn: event.inputTokens,
|
|
133
|
-
tokensOut: event.outputTokens,
|
|
134
|
-
model: config.modelId,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (event.type === "iteration_end") {
|
|
139
|
-
ctx.persistMessages(
|
|
140
|
-
sessionId,
|
|
141
|
-
liveSession?.agent.getMessages() ?? [],
|
|
142
|
-
liveSession?.config.systemPrompt,
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
emit({
|
|
147
|
-
type: "agent_event",
|
|
148
|
-
payload: { sessionId, event },
|
|
149
|
-
});
|
|
150
|
-
emit({
|
|
151
|
-
type: "chunk",
|
|
152
|
-
payload: {
|
|
153
|
-
sessionId,
|
|
154
|
-
stream: "agent",
|
|
155
|
-
chunk: serializeAgentEvent(event),
|
|
156
|
-
ts: Date.now(),
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync,
|
|
3
|
-
mkdirSync,
|
|
4
|
-
readdirSync,
|
|
5
|
-
rmdirSync,
|
|
6
|
-
unlinkSync,
|
|
7
|
-
} from "node:fs";
|
|
8
|
-
import { dirname, join } from "node:path";
|
|
9
|
-
|
|
10
|
-
export function nowIso(): string {
|
|
11
|
-
return new Date().toISOString();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function unlinkIfExists(path: string | null | undefined): void {
|
|
15
|
-
if (!path || !existsSync(path)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
unlinkSync(path);
|
|
20
|
-
} catch {
|
|
21
|
-
// Best effort cleanup.
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface SessionArtifactPaths {
|
|
26
|
-
transcriptPath: string;
|
|
27
|
-
hookPath: string;
|
|
28
|
-
messagesPath: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class SessionArtifacts {
|
|
32
|
-
constructor(private readonly ensureSessionsDir: () => string) {}
|
|
33
|
-
|
|
34
|
-
public sessionArtifactsDir(sessionId: string): string {
|
|
35
|
-
return join(this.ensureSessionsDir(), sessionId);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public ensureSessionArtifactsDir(sessionId: string): string {
|
|
39
|
-
const dir = this.sessionArtifactsDir(sessionId);
|
|
40
|
-
if (!existsSync(dir)) {
|
|
41
|
-
mkdirSync(dir, { recursive: true });
|
|
42
|
-
}
|
|
43
|
-
return dir;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public sessionTranscriptPath(sessionId: string): string {
|
|
47
|
-
return join(this.ensureSessionArtifactsDir(sessionId), `${sessionId}.log`);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public sessionHookPath(sessionId: string): string {
|
|
51
|
-
return join(
|
|
52
|
-
this.ensureSessionArtifactsDir(sessionId),
|
|
53
|
-
`${sessionId}.hooks.jsonl`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public sessionMessagesPath(sessionId: string): string {
|
|
58
|
-
return join(
|
|
59
|
-
this.ensureSessionArtifactsDir(sessionId),
|
|
60
|
-
`${sessionId}.messages.json`,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public sessionManifestPath(sessionId: string, ensureDir = true): string {
|
|
65
|
-
const base = ensureDir
|
|
66
|
-
? this.ensureSessionArtifactsDir(sessionId)
|
|
67
|
-
: this.sessionArtifactsDir(sessionId);
|
|
68
|
-
return join(base, `${sessionId}.json`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public removeSessionDirIfEmpty(sessionId: string): void {
|
|
72
|
-
let dir = this.sessionArtifactsDir(sessionId);
|
|
73
|
-
const sessionsDir = this.ensureSessionsDir();
|
|
74
|
-
while (dir.startsWith(sessionsDir) && dir !== sessionsDir) {
|
|
75
|
-
if (!existsSync(dir)) {
|
|
76
|
-
dir = dirname(dir);
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
if (readdirSync(dir).length > 0) {
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
rmdirSync(dir);
|
|
84
|
-
} catch {
|
|
85
|
-
// Best-effort cleanup.
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
dir = dirname(dir);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public subagentArtifactPaths(
|
|
93
|
-
sessionId: string,
|
|
94
|
-
subAgentId: string,
|
|
95
|
-
activeTeamTaskSessionId?: string,
|
|
96
|
-
): SessionArtifactPaths {
|
|
97
|
-
void subAgentId;
|
|
98
|
-
void activeTeamTaskSessionId;
|
|
99
|
-
const dir = this.ensureSessionArtifactsDir(sessionId);
|
|
100
|
-
return {
|
|
101
|
-
transcriptPath: join(dir, `${sessionId}.log`),
|
|
102
|
-
hookPath: join(dir, `${sessionId}.hooks.jsonl`),
|
|
103
|
-
messagesPath: join(dir, `${sessionId}.messages.json`),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|