@clinebot/core 0.0.27 → 0.0.29
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/README.md +7 -0
- package/dist/ClineCore.d.ts +28 -2
- package/dist/ClineCore.d.ts.map +1 -1
- package/dist/account/cline-account-service.d.ts +1 -1
- package/dist/account/cline-account-service.d.ts.map +1 -1
- package/dist/account/index.d.ts +1 -1
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/types.d.ts +5 -0
- package/dist/account/types.d.ts.map +1 -1
- package/dist/auth/bounded-ttl-cache.d.ts +14 -0
- package/dist/auth/bounded-ttl-cache.d.ts.map +1 -0
- package/dist/auth/cline.d.ts +27 -2
- package/dist/auth/cline.d.ts.map +1 -1
- package/dist/auth/oca.d.ts.map +1 -1
- package/dist/chat/chat-schema.d.ts +8 -8
- package/dist/extensions/config/agent-config-loader.d.ts.map +1 -0
- package/dist/{agents → extensions/config}/agent-config-parser.d.ts +2 -2
- package/dist/extensions/config/agent-config-parser.d.ts.map +1 -0
- package/dist/{agents → extensions/config}/hooks-config-loader.d.ts +1 -1
- package/dist/extensions/config/hooks-config-loader.d.ts.map +1 -0
- package/dist/{agents → extensions/config}/index.d.ts +2 -4
- package/dist/extensions/config/index.d.ts.map +1 -0
- package/dist/{runtime/commands.d.ts → extensions/config/runtime-commands.d.ts} +2 -3
- package/dist/extensions/config/runtime-commands.d.ts.map +1 -0
- package/dist/extensions/config/unified-config-file-watcher.d.ts.map +1 -0
- package/dist/extensions/config/user-instruction-config-loader.d.ts.map +1 -0
- package/dist/extensions/context/agentic-compaction.d.ts +13 -0
- package/dist/extensions/context/agentic-compaction.d.ts.map +1 -0
- package/dist/extensions/context/basic-compaction.d.ts +9 -0
- package/dist/extensions/context/basic-compaction.d.ts.map +1 -0
- package/dist/extensions/context/compaction-shared.d.ts +60 -0
- package/dist/extensions/context/compaction-shared.d.ts.map +1 -0
- package/dist/extensions/context/compaction.d.ts +20 -0
- package/dist/extensions/context/compaction.d.ts.map +1 -0
- package/dist/extensions/index.d.ts +5 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/mcp/client.d.ts +3 -0
- package/dist/extensions/mcp/client.d.ts.map +1 -0
- package/dist/extensions/mcp/config-loader.d.ts.map +1 -0
- package/dist/extensions/mcp/index.d.ts +9 -0
- package/dist/extensions/mcp/index.d.ts.map +1 -0
- package/dist/{mcp → extensions/mcp}/manager.d.ts +1 -2
- package/dist/extensions/mcp/manager.d.ts.map +1 -0
- package/dist/extensions/mcp/name-transform.d.ts +3 -0
- package/dist/extensions/mcp/name-transform.d.ts.map +1 -0
- package/dist/extensions/mcp/policies.d.ts +15 -0
- package/dist/extensions/mcp/policies.d.ts.map +1 -0
- package/dist/extensions/mcp/tools.d.ts +4 -0
- package/dist/extensions/mcp/tools.d.ts.map +1 -0
- package/dist/{mcp → extensions/mcp}/types.d.ts +29 -1
- package/dist/extensions/mcp/types.d.ts.map +1 -0
- package/dist/{agents → extensions/plugin}/plugin-config-loader.d.ts +1 -1
- package/dist/extensions/plugin/plugin-config-loader.d.ts.map +1 -0
- package/dist/{agents → extensions/plugin}/plugin-loader.d.ts +1 -1
- package/dist/extensions/plugin/plugin-loader.d.ts.map +1 -0
- package/dist/extensions/plugin/plugin-module-import.d.ts +5 -0
- package/dist/extensions/plugin/plugin-module-import.d.ts.map +1 -0
- package/dist/{agents → extensions/plugin}/plugin-sandbox.d.ts +1 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts.map +1 -0
- package/dist/extensions/plugin-sandbox-bootstrap.js +485 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/persistent.d.ts +64 -0
- package/dist/hooks/persistent.d.ts.map +1 -0
- package/dist/hooks/subprocess-runner.d.ts +22 -0
- package/dist/hooks/subprocess-runner.d.ts.map +1 -0
- package/dist/hooks/subprocess.d.ts +189 -0
- package/dist/hooks/subprocess.d.ts.map +1 -0
- package/dist/index.d.ts +22 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +560 -447
- package/dist/prompt/default-system.d.ts +2 -0
- package/dist/prompt/default-system.d.ts.map +1 -0
- package/dist/providers/local-provider-service.d.ts +1 -1
- package/dist/providers/local-provider-service.d.ts.map +1 -1
- package/dist/runtime/checkpoint-hooks.d.ts +21 -0
- package/dist/runtime/checkpoint-hooks.d.ts.map +1 -0
- package/dist/runtime/hook-file-hooks.d.ts +1 -1
- package/dist/runtime/hook-file-hooks.d.ts.map +1 -1
- package/dist/runtime/rules.d.ts +1 -1
- package/dist/runtime/rules.d.ts.map +1 -1
- package/dist/runtime/runtime-builder.d.ts +1 -1
- package/dist/runtime/runtime-builder.d.ts.map +1 -1
- package/dist/runtime/session-runtime.d.ts +25 -5
- package/dist/runtime/session-runtime.d.ts.map +1 -1
- package/dist/runtime/subprocess-sandbox.d.ts.map +1 -0
- package/dist/runtime/team-runtime-registry.d.ts +1 -1
- package/dist/runtime/team-runtime-registry.d.ts.map +1 -1
- package/dist/runtime/tool-approval.d.ts +1 -1
- package/dist/session/default-session-manager.d.ts +4 -3
- package/dist/session/default-session-manager.d.ts.map +1 -1
- package/dist/session/file-session-service.d.ts +1 -1
- package/dist/session/file-session-service.d.ts.map +1 -1
- package/dist/session/{unified-session-persistence-service.d.ts → persistence-service.d.ts} +11 -42
- package/dist/session/persistence-service.d.ts.map +1 -0
- package/dist/session/rpc-session-service.d.ts +1 -1
- package/dist/session/rpc-session-service.d.ts.map +1 -1
- package/dist/session/session-agent-events.d.ts +1 -1
- package/dist/session/session-artifacts.d.ts.map +1 -1
- package/dist/session/session-config-builder.d.ts.map +1 -1
- package/dist/session/session-graph.d.ts +1 -1
- package/dist/session/session-graph.d.ts.map +1 -1
- package/dist/session/session-host.d.ts.map +1 -1
- package/dist/session/session-manager.d.ts +6 -5
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manifest.d.ts +1 -1
- package/dist/session/session-service.d.ts +3 -2
- package/dist/session/session-service.d.ts.map +1 -1
- package/dist/session/session-team-coordination.d.ts +2 -1
- package/dist/session/session-team-coordination.d.ts.map +1 -1
- package/dist/session/utils/helpers.d.ts +51 -3
- package/dist/session/utils/helpers.d.ts.map +1 -1
- package/dist/session/utils/types.d.ts +41 -7
- package/dist/session/utils/types.d.ts.map +1 -1
- package/dist/session/workspace-manager.d.ts +1 -2
- package/dist/session/workspace-manager.d.ts.map +1 -1
- package/dist/session/workspace-manifest.d.ts +1 -22
- package/dist/session/workspace-manifest.d.ts.map +1 -1
- package/dist/storage/file-team-store.d.ts +2 -1
- package/dist/storage/file-team-store.d.ts.map +1 -1
- package/dist/storage/sqlite-team-store.d.ts +4 -1
- package/dist/storage/sqlite-team-store.d.ts.map +1 -1
- package/dist/storage/team-store.d.ts.map +1 -1
- package/dist/team/delegated-agent.d.ts +44 -0
- package/dist/team/delegated-agent.d.ts.map +1 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/index.d.ts.map +1 -1
- package/dist/team/multi-agent.d.ts +229 -0
- package/dist/team/multi-agent.d.ts.map +1 -0
- package/dist/team/projections.d.ts +2 -2
- package/dist/team/projections.d.ts.map +1 -1
- package/dist/team/runtime.d.ts +5 -0
- package/dist/team/runtime.d.ts.map +1 -0
- package/dist/team/spawn-agent-tool.d.ts +85 -0
- package/dist/team/spawn-agent-tool.d.ts.map +1 -0
- package/dist/team/subagent-prompts.d.ts +4 -0
- package/dist/team/subagent-prompts.d.ts.map +1 -0
- package/dist/team/team-tools.d.ts +35 -0
- package/dist/team/team-tools.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts +11 -1
- package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -1
- package/dist/telemetry/{LoggerTelemetryAdapter.d.ts → TelemetryLoggerSink.d.ts} +10 -4
- package/dist/telemetry/TelemetryLoggerSink.d.ts.map +1 -0
- package/dist/telemetry/TelemetryService.d.ts.map +1 -1
- package/dist/telemetry/index.js +15 -28
- package/dist/tools/definitions.d.ts +4 -3
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/index.d.ts +5 -5
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/model-tool-routing.d.ts.map +1 -1
- package/dist/tools/presets.d.ts +26 -0
- package/dist/tools/presets.d.ts.map +1 -1
- package/dist/tools/schemas.d.ts +8 -0
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/types.d.ts +23 -2
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/types/config.d.ts +47 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/events.d.ts +1 -1
- package/dist/types/provider-settings.d.ts +1 -1
- package/dist/types/provider-settings.d.ts.map +1 -1
- package/dist/types/storage.d.ts +2 -1
- package/dist/types/storage.d.ts.map +1 -1
- package/dist/types.d.ts +7 -16
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -13
- package/src/ClineCore.test.ts +150 -0
- package/src/ClineCore.ts +114 -8
- package/src/account/cline-account-service.test.ts +84 -0
- package/src/account/cline-account-service.ts +2 -2
- package/src/account/index.ts +1 -0
- package/src/account/types.ts +6 -0
- package/src/auth/bounded-ttl-cache.test.ts +38 -0
- package/src/auth/bounded-ttl-cache.ts +53 -0
- package/src/auth/cline.test.ts +173 -36
- package/src/auth/cline.ts +395 -93
- package/src/auth/oca.test.ts +125 -0
- package/src/auth/oca.ts +17 -4
- package/src/{agents → extensions/config}/agent-config-loader.test.ts +1 -1
- package/src/{agents → extensions/config}/agent-config-parser.ts +2 -2
- package/src/{agents → extensions/config}/hooks-config-loader.ts +1 -1
- package/src/{agents → extensions/config}/index.ts +7 -11
- package/src/{runtime/commands.test.ts → extensions/config/runtime-commands.test.ts} +20 -3
- package/src/{runtime/commands.ts → extensions/config/runtime-commands.ts} +1 -8
- package/src/{agents → extensions/config}/unified-config-file-watcher.ts +15 -2
- package/src/{agents → extensions/config}/user-instruction-config-loader.test.ts +90 -2
- package/src/{agents → extensions/config}/user-instruction-config-loader.ts +126 -12
- package/src/extensions/context/agentic-compaction.ts +119 -0
- package/src/extensions/context/basic-compaction.ts +275 -0
- package/src/extensions/context/compaction-shared.ts +458 -0
- package/src/extensions/context/compaction.test.ts +477 -0
- package/src/extensions/context/compaction.ts +203 -0
- package/src/extensions/index.ts +12 -0
- package/src/extensions/mcp/client.ts +420 -0
- package/src/{mcp → extensions/mcp}/index.ts +16 -0
- package/src/{mcp → extensions/mcp}/manager.test.ts +1 -2
- package/src/{mcp → extensions/mcp}/manager.ts +3 -5
- package/src/extensions/mcp/name-transform.ts +33 -0
- package/src/extensions/mcp/policies.ts +47 -0
- package/src/extensions/mcp/tools.ts +47 -0
- package/src/{mcp → extensions/mcp}/types.ts +35 -7
- package/src/{agents → extensions/plugin}/plugin-config-loader.test.ts +18 -13
- package/src/{agents → extensions/plugin}/plugin-config-loader.ts +1 -1
- package/src/{agents → extensions/plugin}/plugin-loader.test.ts +41 -4
- package/src/extensions/plugin/plugin-loader.ts +106 -0
- package/src/extensions/plugin/plugin-module-import.ts +278 -0
- package/src/{agents → extensions/plugin}/plugin-sandbox-bootstrap.ts +30 -92
- package/src/{agents → extensions/plugin}/plugin-sandbox.test.ts +60 -3
- package/src/{agents → extensions/plugin}/plugin-sandbox.ts +146 -56
- package/src/hooks/index.ts +25 -0
- package/src/hooks/persistent.ts +661 -0
- package/src/hooks/subprocess-runner.ts +196 -0
- package/src/hooks/subprocess.ts +669 -0
- package/src/index.ts +200 -118
- package/src/prompt/default-system.ts +21 -0
- package/src/providers/local-provider-registry.ts +1 -1
- package/src/providers/local-provider-service.test.ts +23 -2
- package/src/providers/local-provider-service.ts +2 -2
- package/src/runtime/checkpoint-hooks.test.ts +167 -0
- package/src/runtime/checkpoint-hooks.ts +186 -0
- package/src/runtime/hook-file-hooks.test.ts +40 -1
- package/src/runtime/hook-file-hooks.ts +35 -16
- package/src/runtime/index.ts +4 -19
- package/src/runtime/rules.ts +4 -1
- package/src/runtime/runtime-builder.team-persistence.test.ts +3 -6
- package/src/runtime/runtime-builder.test.ts +266 -160
- package/src/runtime/runtime-builder.ts +120 -47
- package/src/runtime/runtime-parity.test.ts +22 -22
- package/src/runtime/session-runtime.ts +36 -6
- package/src/runtime/{sandbox/subprocess-sandbox.ts → subprocess-sandbox.ts} +24 -3
- package/src/runtime/team-runtime-registry.ts +1 -4
- package/src/runtime/tool-approval.ts +1 -1
- package/src/session/default-session-manager.e2e.test.ts +2 -2
- package/src/session/default-session-manager.test.ts +553 -9
- package/src/session/default-session-manager.ts +140 -46
- package/src/session/file-session-service.ts +3 -3
- package/src/session/index.ts +6 -6
- package/src/session/persistence-service.test.ts +212 -0
- package/src/session/{unified-session-persistence-service.ts → persistence-service.ts} +106 -172
- package/src/session/rpc-session-service.ts +3 -3
- package/src/session/runtime-oauth-token-manager.ts +1 -1
- package/src/session/session-agent-events.ts +1 -1
- package/src/session/session-artifacts.ts +32 -4
- package/src/session/session-config-builder.ts +22 -9
- package/src/session/session-graph.ts +1 -1
- package/src/session/session-host.ts +19 -11
- package/src/session/session-manager.ts +11 -6
- package/src/session/session-service.team-persistence.test.ts +1 -1
- package/src/session/session-service.ts +6 -9
- package/src/session/session-team-coordination.ts +7 -3
- package/src/session/session-telemetry.ts +1 -1
- package/src/session/utils/helpers.test.ts +160 -0
- package/src/session/utils/helpers.ts +289 -42
- package/src/session/utils/types.ts +47 -7
- package/src/session/workspace-manager.ts +5 -3
- package/src/session/workspace-manifest.ts +3 -49
- package/src/storage/file-team-store.ts +2 -5
- package/src/storage/provider-settings-legacy-migration.ts +2 -2
- package/src/storage/provider-settings-manager.test.ts +1 -1
- package/src/storage/sqlite-team-store.ts +212 -125
- package/src/storage/team-store.ts +1 -5
- package/src/team/delegated-agent.ts +131 -0
- package/src/team/index.ts +1 -0
- package/src/team/multi-agent.lifecycle.test.ts +201 -0
- package/src/team/multi-agent.ts +1666 -0
- package/src/team/projections.ts +2 -4
- package/src/team/runtime.ts +54 -0
- package/src/team/spawn-agent-tool.test.ts +387 -0
- package/src/team/spawn-agent-tool.ts +207 -0
- package/src/team/subagent-prompts.ts +41 -0
- package/src/team/team-tools.test.ts +802 -0
- package/src/team/team-tools.ts +792 -0
- package/src/telemetry/OpenTelemetryProvider.test.ts +25 -3
- package/src/telemetry/OpenTelemetryProvider.ts +108 -18
- package/src/telemetry/TelemetryLoggerSink.test.ts +42 -0
- package/src/telemetry/{LoggerTelemetryAdapter.ts → TelemetryLoggerSink.ts} +21 -14
- package/src/telemetry/TelemetryService.test.ts +7 -7
- package/src/telemetry/TelemetryService.ts +2 -4
- package/src/tools/definitions.test.ts +76 -0
- package/src/tools/definitions.ts +41 -2
- package/src/tools/executors/apply-patch.ts +1 -1
- package/src/tools/executors/editor.ts +1 -1
- package/src/tools/executors/file-read.ts +1 -1
- package/src/tools/executors/search.ts +1 -1
- package/src/tools/executors/web-fetch.ts +1 -1
- package/src/tools/index.ts +6 -1
- package/src/tools/model-tool-routing.ts +2 -0
- package/src/tools/presets.test.ts +8 -0
- package/src/tools/presets.ts +40 -2
- package/src/tools/schemas.ts +19 -0
- package/src/tools/types.ts +31 -2
- package/src/types/config.ts +61 -7
- package/src/types/events.ts +1 -1
- package/src/types/index.ts +0 -1
- package/src/types/provider-settings.ts +1 -1
- package/src/types/storage.ts +2 -5
- package/src/types.ts +32 -44
- package/dist/agents/agent-config-loader.d.ts.map +0 -1
- package/dist/agents/agent-config-parser.d.ts.map +0 -1
- package/dist/agents/hooks-config-loader.d.ts.map +0 -1
- package/dist/agents/index.d.ts.map +0 -1
- package/dist/agents/plugin-config-loader.d.ts.map +0 -1
- package/dist/agents/plugin-loader.d.ts.map +0 -1
- package/dist/agents/plugin-sandbox-bootstrap.js +0 -446
- package/dist/agents/plugin-sandbox.d.ts.map +0 -1
- package/dist/agents/unified-config-file-watcher.d.ts.map +0 -1
- package/dist/agents/user-instruction-config-loader.d.ts.map +0 -1
- package/dist/mcp/config-loader.d.ts.map +0 -1
- package/dist/mcp/index.d.ts +0 -5
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/manager.d.ts.map +0 -1
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/runtime/commands.d.ts.map +0 -1
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts.map +0 -1
- package/dist/runtime/skills.d.ts +0 -14
- package/dist/runtime/skills.d.ts.map +0 -1
- package/dist/runtime/workflows.d.ts +0 -14
- package/dist/runtime/workflows.d.ts.map +0 -1
- package/dist/session/unified-session-persistence-service.d.ts.map +0 -1
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts.map +0 -1
- package/dist/types/workspace.d.ts +0 -8
- package/dist/types/workspace.d.ts.map +0 -1
- package/src/agents/plugin-loader.ts +0 -175
- package/src/runtime/skills.ts +0 -44
- package/src/runtime/workflows.test.ts +0 -119
- package/src/runtime/workflows.ts +0 -45
- package/src/session/unified-session-persistence-service.test.ts +0 -85
- package/src/telemetry/LoggerTelemetryAdapter.test.ts +0 -42
- package/src/types/workspace.ts +0 -7
- /package/dist/{agents → extensions/config}/agent-config-loader.d.ts +0 -0
- /package/dist/{agents → extensions/config}/unified-config-file-watcher.d.ts +0 -0
- /package/dist/{agents → extensions/config}/user-instruction-config-loader.d.ts +0 -0
- /package/dist/{mcp → extensions/mcp}/config-loader.d.ts +0 -0
- /package/dist/runtime/{sandbox/subprocess-sandbox.d.ts → subprocess-sandbox.d.ts} +0 -0
- /package/src/{agents → extensions/config}/agent-config-loader.ts +0 -0
- /package/src/{agents → extensions/config}/hooks-config-loader.test.ts +0 -0
- /package/src/{agents → extensions/config}/unified-config-file-watcher.test.ts +0 -0
- /package/src/{mcp → extensions/mcp}/config-loader.test.ts +0 -0
- /package/src/{mcp → extensions/mcp}/config-loader.ts +0 -0
package/src/auth/cline.test.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
import type { ClineOAuthCredentials } from "./cline";
|
|
3
|
-
import { getValidClineCredentials } from "./cline";
|
|
3
|
+
import { getValidClineCredentials, loginClineOAuth } from "./cline";
|
|
4
4
|
|
|
5
5
|
const PROVIDER_OPTIONS = {
|
|
6
6
|
apiBaseUrl: "https://auth.example.com",
|
|
7
7
|
};
|
|
8
|
+
const ORIGINAL_FETCH = globalThis.fetch;
|
|
8
9
|
|
|
9
10
|
function createCredentials(
|
|
10
11
|
overrides: Partial<ClineOAuthCredentials> = {},
|
|
@@ -22,15 +23,15 @@ function createCredentials(
|
|
|
22
23
|
|
|
23
24
|
describe("auth/cline getValidClineCredentials", () => {
|
|
24
25
|
afterEach(() => {
|
|
25
|
-
vi.unstubAllGlobals();
|
|
26
26
|
vi.restoreAllMocks();
|
|
27
|
+
globalThis.fetch = ORIGINAL_FETCH;
|
|
27
28
|
});
|
|
28
29
|
|
|
29
30
|
it("returns existing credentials when not expired", async () => {
|
|
30
31
|
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(10_000);
|
|
31
32
|
const current = createCredentials({ expires: 400_000 });
|
|
32
33
|
const fetchMock = vi.fn();
|
|
33
|
-
|
|
34
|
+
globalThis.fetch = fetchMock as unknown as typeof fetch;
|
|
34
35
|
|
|
35
36
|
const result = await getValidClineCredentials(current, PROVIDER_OPTIONS);
|
|
36
37
|
expect(result).toBe(current);
|
|
@@ -63,7 +64,7 @@ describe("auth/cline getValidClineCredentials", () => {
|
|
|
63
64
|
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
64
65
|
),
|
|
65
66
|
);
|
|
66
|
-
|
|
67
|
+
globalThis.fetch = fetchMock as unknown as typeof fetch;
|
|
67
68
|
|
|
68
69
|
const result = await getValidClineCredentials(current, PROVIDER_OPTIONS);
|
|
69
70
|
expect(result).toMatchObject({
|
|
@@ -78,22 +79,19 @@ describe("auth/cline getValidClineCredentials", () => {
|
|
|
78
79
|
it("returns null when refresh fails with invalid_grant", async () => {
|
|
79
80
|
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
|
|
80
81
|
const current = createCredentials({ expires: 101_000 });
|
|
81
|
-
vi.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
),
|
|
95
|
-
),
|
|
96
|
-
);
|
|
82
|
+
globalThis.fetch = vi.fn(
|
|
83
|
+
async () =>
|
|
84
|
+
new Response(
|
|
85
|
+
JSON.stringify({
|
|
86
|
+
error: "invalid_grant",
|
|
87
|
+
error_description: "refresh expired",
|
|
88
|
+
}),
|
|
89
|
+
{
|
|
90
|
+
status: 401,
|
|
91
|
+
headers: { "Content-Type": "application/json" },
|
|
92
|
+
},
|
|
93
|
+
),
|
|
94
|
+
) as unknown as typeof fetch;
|
|
97
95
|
|
|
98
96
|
const result = await getValidClineCredentials(current, PROVIDER_OPTIONS);
|
|
99
97
|
expect(result).toBeNull();
|
|
@@ -103,22 +101,19 @@ describe("auth/cline getValidClineCredentials", () => {
|
|
|
103
101
|
it("keeps current credentials on transient refresh error while token remains valid", async () => {
|
|
104
102
|
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
|
|
105
103
|
const current = createCredentials({ expires: 150_000 });
|
|
106
|
-
vi.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
{
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
),
|
|
120
|
-
),
|
|
121
|
-
);
|
|
104
|
+
globalThis.fetch = vi.fn(
|
|
105
|
+
async () =>
|
|
106
|
+
new Response(
|
|
107
|
+
JSON.stringify({
|
|
108
|
+
error: "server_error",
|
|
109
|
+
error_description: "temporary issue",
|
|
110
|
+
}),
|
|
111
|
+
{
|
|
112
|
+
status: 500,
|
|
113
|
+
headers: { "Content-Type": "application/json" },
|
|
114
|
+
},
|
|
115
|
+
),
|
|
116
|
+
) as unknown as typeof fetch;
|
|
122
117
|
|
|
123
118
|
const result = await getValidClineCredentials(current, PROVIDER_OPTIONS, {
|
|
124
119
|
refreshBufferMs: 60_000,
|
|
@@ -128,3 +123,145 @@ describe("auth/cline getValidClineCredentials", () => {
|
|
|
128
123
|
nowSpy.mockRestore();
|
|
129
124
|
});
|
|
130
125
|
});
|
|
126
|
+
|
|
127
|
+
describe("auth/cline loginClineOAuth", () => {
|
|
128
|
+
afterEach(() => {
|
|
129
|
+
vi.restoreAllMocks();
|
|
130
|
+
globalThis.fetch = ORIGINAL_FETCH;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("completes WorkOS device auth and registers tokens", async () => {
|
|
134
|
+
const fetchMock = vi
|
|
135
|
+
.fn()
|
|
136
|
+
.mockResolvedValueOnce(
|
|
137
|
+
new Response(
|
|
138
|
+
JSON.stringify({
|
|
139
|
+
device_code: "dev-code-1",
|
|
140
|
+
user_code: "ABCD-EFGH",
|
|
141
|
+
verification_uri: "https://example.com/device",
|
|
142
|
+
verification_uri_complete:
|
|
143
|
+
"https://example.com/device?user_code=ABCD-EFGH",
|
|
144
|
+
expires_in: 300,
|
|
145
|
+
interval: 1,
|
|
146
|
+
}),
|
|
147
|
+
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
148
|
+
),
|
|
149
|
+
)
|
|
150
|
+
.mockResolvedValueOnce(
|
|
151
|
+
new Response(
|
|
152
|
+
JSON.stringify({
|
|
153
|
+
access_token: "workos-access",
|
|
154
|
+
refresh_token: "workos-refresh",
|
|
155
|
+
token_type: "Bearer",
|
|
156
|
+
expires_in: 3600,
|
|
157
|
+
}),
|
|
158
|
+
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
.mockResolvedValueOnce(
|
|
162
|
+
new Response(
|
|
163
|
+
JSON.stringify({
|
|
164
|
+
success: true,
|
|
165
|
+
data: {
|
|
166
|
+
accessToken: "cline-access",
|
|
167
|
+
refreshToken: "cline-refresh",
|
|
168
|
+
tokenType: "Bearer",
|
|
169
|
+
expiresAt: "2030-01-01T00:00:00.000Z",
|
|
170
|
+
userInfo: {
|
|
171
|
+
subject: "sub-1",
|
|
172
|
+
email: "user@example.com",
|
|
173
|
+
name: "User",
|
|
174
|
+
clineUserId: "acct-1",
|
|
175
|
+
accounts: ["acct-1"],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
180
|
+
),
|
|
181
|
+
);
|
|
182
|
+
globalThis.fetch = fetchMock as unknown as typeof fetch;
|
|
183
|
+
|
|
184
|
+
const onAuth = vi.fn();
|
|
185
|
+
const credentials = await loginClineOAuth({
|
|
186
|
+
apiBaseUrl: "https://api.cline.bot",
|
|
187
|
+
useWorkOSDeviceAuth: true,
|
|
188
|
+
callbacks: {
|
|
189
|
+
onAuth,
|
|
190
|
+
onPrompt: async () => "",
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(onAuth).toHaveBeenCalledTimes(1);
|
|
195
|
+
expect(onAuth.mock.calls[0]?.[0]).toMatchObject({
|
|
196
|
+
url: "https://example.com/device?user_code=ABCD-EFGH",
|
|
197
|
+
});
|
|
198
|
+
expect(credentials).toMatchObject({
|
|
199
|
+
access: "cline-access",
|
|
200
|
+
refresh: "cline-refresh",
|
|
201
|
+
accountId: "acct-1",
|
|
202
|
+
email: "user@example.com",
|
|
203
|
+
});
|
|
204
|
+
expect(fetchMock).toHaveBeenCalledTimes(3);
|
|
205
|
+
const registerCallBody = JSON.parse(
|
|
206
|
+
String(fetchMock.mock.calls[2]?.[1]?.body ?? "{}"),
|
|
207
|
+
);
|
|
208
|
+
const deviceAuthBody = String(fetchMock.mock.calls[0]?.[1]?.body ?? "");
|
|
209
|
+
const deviceAuthParams = new URLSearchParams(deviceAuthBody);
|
|
210
|
+
expect(deviceAuthParams.get("client_id")).toMatch(/client_.*/);
|
|
211
|
+
expect(registerCallBody).toMatchObject({
|
|
212
|
+
accessToken: "workos-access",
|
|
213
|
+
refreshToken: "workos-refresh",
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("uses legacy callback OAuth flow by default", async () => {
|
|
218
|
+
const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => {
|
|
219
|
+
const body =
|
|
220
|
+
typeof init?.body === "string"
|
|
221
|
+
? (JSON.parse(init.body) as Record<string, unknown>)
|
|
222
|
+
: {};
|
|
223
|
+
if (body.grant_type === "authorization_code") {
|
|
224
|
+
return new Response(
|
|
225
|
+
JSON.stringify({
|
|
226
|
+
success: true,
|
|
227
|
+
data: {
|
|
228
|
+
accessToken: "legacy-access",
|
|
229
|
+
refreshToken: "legacy-refresh",
|
|
230
|
+
tokenType: "Bearer",
|
|
231
|
+
expiresAt: "2030-01-01T00:00:00.000Z",
|
|
232
|
+
userInfo: {
|
|
233
|
+
subject: "sub-legacy",
|
|
234
|
+
email: "legacy@example.com",
|
|
235
|
+
name: "Legacy User",
|
|
236
|
+
clineUserId: "acct-legacy",
|
|
237
|
+
accounts: ["acct-legacy"],
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
}),
|
|
241
|
+
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return new Response("not-found", { status: 404 });
|
|
245
|
+
});
|
|
246
|
+
globalThis.fetch = fetchMock as unknown as typeof fetch;
|
|
247
|
+
|
|
248
|
+
const credentials = await loginClineOAuth({
|
|
249
|
+
apiBaseUrl: "https://api.cline.bot",
|
|
250
|
+
callbackPorts: [48801],
|
|
251
|
+
callbacks: {
|
|
252
|
+
onAuth: () => {},
|
|
253
|
+
onPrompt: async () => "http://127.0.0.1:48801/auth?code=legacy-code",
|
|
254
|
+
onManualCodeInput: async () =>
|
|
255
|
+
"http://127.0.0.1:48801/auth?code=legacy-code",
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
expect(credentials).toMatchObject({
|
|
260
|
+
access: "legacy-access",
|
|
261
|
+
refresh: "legacy-refresh",
|
|
262
|
+
accountId: "acct-legacy",
|
|
263
|
+
email: "legacy@example.com",
|
|
264
|
+
});
|
|
265
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
266
|
+
});
|
|
267
|
+
});
|