expandai 0.0.4 → 0.0.6
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 +2 -2
- package/build/{esm/Install/Opencode → assets/opencode}/expandai-webfetch.js +22 -4
- package/build/dts/Mcp/RequestHeaders.d.ts +0 -1
- package/build/dts/Mcp/Server.d.ts +1 -2
- package/build/dts/index.d.ts +0 -1
- package/build/esm/index.js +193 -2
- package/build/esm/main.js +691 -200
- package/build/skills/expandai/SKILL.md +100 -8
- package/package.json +20 -12
- package/build/dts/ApiClient.d.ts +0 -165
- package/build/dts/ApiClient.d.ts.map +0 -1
- package/build/dts/Auth/Domain.d.ts +0 -95
- package/build/dts/Auth/Domain.d.ts.map +0 -1
- package/build/dts/Auth/ManualAuthorization.d.ts +0 -107
- package/build/dts/Auth/ManualAuthorization.d.ts.map +0 -1
- package/build/dts/Auth/PendingInit.d.ts +0 -35
- package/build/dts/Auth/PendingInit.d.ts.map +0 -1
- package/build/dts/Auth/Pkce.d.ts +0 -10
- package/build/dts/Auth/Pkce.d.ts.map +0 -1
- package/build/dts/Auth/SetupGrantAuthorization.d.ts +0 -34
- package/build/dts/Auth/SetupGrantAuthorization.d.ts.map +0 -1
- package/build/dts/Authentication.d.ts +0 -24
- package/build/dts/Authentication.d.ts.map +0 -1
- package/build/dts/BrowserOAuth.d.ts +0 -99
- package/build/dts/BrowserOAuth.d.ts.map +0 -1
- package/build/dts/CommandPath.d.ts +0 -2
- package/build/dts/CommandPath.d.ts.map +0 -1
- package/build/dts/Commands/Fetch.d.ts +0 -30
- package/build/dts/Commands/Fetch.d.ts.map +0 -1
- package/build/dts/Commands/Hook.d.ts +0 -17
- package/build/dts/Commands/Hook.d.ts.map +0 -1
- package/build/dts/Commands/Init.d.ts +0 -55
- package/build/dts/Commands/Init.d.ts.map +0 -1
- package/build/dts/Commands/Mcp.d.ts +0 -11
- package/build/dts/Commands/Mcp.d.ts.map +0 -1
- package/build/dts/Commands/McpRun.d.ts +0 -5
- package/build/dts/Commands/McpRun.d.ts.map +0 -1
- package/build/dts/Commands/Search.d.ts +0 -21
- package/build/dts/Commands/Search.d.ts.map +0 -1
- package/build/dts/Commands/Skill.d.ts +0 -12
- package/build/dts/Commands/Skill.d.ts.map +0 -1
- package/build/dts/Commands/Status.d.ts +0 -27
- package/build/dts/Commands/Status.d.ts.map +0 -1
- package/build/dts/Commands/Telemetry.d.ts +0 -7
- package/build/dts/Commands/Telemetry.d.ts.map +0 -1
- package/build/dts/Commands/Uninstall.d.ts +0 -9
- package/build/dts/Commands/Uninstall.d.ts.map +0 -1
- package/build/dts/Config.d.ts +0 -196
- package/build/dts/Config.d.ts.map +0 -1
- package/build/dts/Hook/Claude.d.ts +0 -13
- package/build/dts/Hook/Claude.d.ts.map +0 -1
- package/build/dts/Hook/Errors.d.ts +0 -20
- package/build/dts/Hook/Errors.d.ts.map +0 -1
- package/build/dts/Hook/Opencode.d.ts +0 -13
- package/build/dts/Hook/Opencode.d.ts.map +0 -1
- package/build/dts/Hook/SnapshotNote.d.ts +0 -12
- package/build/dts/Hook/SnapshotNote.d.ts.map +0 -1
- package/build/dts/Init/ClaudeAdapter.d.ts +0 -61
- package/build/dts/Init/ClaudeAdapter.d.ts.map +0 -1
- package/build/dts/Init/ClaudeProfile.d.ts +0 -77
- package/build/dts/Init/ClaudeProfile.d.ts.map +0 -1
- package/build/dts/Init/Domain.d.ts +0 -139
- package/build/dts/Init/Domain.d.ts.map +0 -1
- package/build/dts/Init/HarnessAdapter.d.ts +0 -33
- package/build/dts/Init/HarnessAdapter.d.ts.map +0 -1
- package/build/dts/Init/HarnessDetector.d.ts +0 -19
- package/build/dts/Init/HarnessDetector.d.ts.map +0 -1
- package/build/dts/Init/HarnessRegistry.d.ts +0 -50
- package/build/dts/Init/HarnessRegistry.d.ts.map +0 -1
- package/build/dts/Init/MutationTransaction.d.ts +0 -96
- package/build/dts/Init/MutationTransaction.d.ts.map +0 -1
- package/build/dts/Init/Service.d.ts +0 -72
- package/build/dts/Init/Service.d.ts.map +0 -1
- package/build/dts/Init/StandardAdapters.d.ts +0 -42
- package/build/dts/Init/StandardAdapters.d.ts.map +0 -1
- package/build/dts/Init/Status.d.ts +0 -149
- package/build/dts/Init/Status.d.ts.map +0 -1
- package/build/dts/Install/Claude/Hook.d.ts +0 -88
- package/build/dts/Install/Claude/Hook.d.ts.map +0 -1
- package/build/dts/Install/Claude/Mcp.d.ts +0 -48
- package/build/dts/Install/Claude/Mcp.d.ts.map +0 -1
- package/build/dts/Install/Claude/Skill.d.ts +0 -23
- package/build/dts/Install/Claude/Skill.d.ts.map +0 -1
- package/build/dts/Install/Codex/Mcp.d.ts +0 -45
- package/build/dts/Install/Codex/Mcp.d.ts.map +0 -1
- package/build/dts/Install/Codex/Skill.d.ts +0 -22
- package/build/dts/Install/Codex/Skill.d.ts.map +0 -1
- package/build/dts/Install/Cursor/Mcp.d.ts +0 -45
- package/build/dts/Install/Cursor/Mcp.d.ts.map +0 -1
- package/build/dts/Install/Cursor/Skill.d.ts +0 -29
- package/build/dts/Install/Cursor/Skill.d.ts.map +0 -1
- package/build/dts/Install/Domain.d.ts +0 -103
- package/build/dts/Install/Domain.d.ts.map +0 -1
- package/build/dts/Install/Hook.d.ts +0 -30
- package/build/dts/Install/Hook.d.ts.map +0 -1
- package/build/dts/Install/Mcp.d.ts +0 -28
- package/build/dts/Install/Mcp.d.ts.map +0 -1
- package/build/dts/Install/Opencode/Hook.d.ts +0 -24
- package/build/dts/Install/Opencode/Hook.d.ts.map +0 -1
- package/build/dts/Install/Opencode/Mcp.d.ts +0 -47
- package/build/dts/Install/Opencode/Mcp.d.ts.map +0 -1
- package/build/dts/Install/Opencode/Skill.d.ts +0 -26
- package/build/dts/Install/Opencode/Skill.d.ts.map +0 -1
- package/build/dts/Install/Skill.d.ts +0 -32
- package/build/dts/Install/Skill.d.ts.map +0 -1
- package/build/dts/Install/Uninstall.d.ts +0 -32
- package/build/dts/Install/Uninstall.d.ts.map +0 -1
- package/build/dts/MarkdownAnsi.d.ts +0 -29
- package/build/dts/MarkdownAnsi.d.ts.map +0 -1
- package/build/dts/Mcp/ExpandDocs.d.ts +0 -19
- package/build/dts/Mcp/ExpandDocs.d.ts.map +0 -1
- package/build/dts/Mcp/RequestHeaders.d.ts.map +0 -1
- package/build/dts/Mcp/Server.d.ts.map +0 -1
- package/build/dts/Mcp/Toolkit.d.ts +0 -3
- package/build/dts/Mcp/Toolkit.d.ts.map +0 -1
- package/build/dts/Mcp/tools/Citations.d.ts +0 -266
- package/build/dts/Mcp/tools/Citations.d.ts.map +0 -1
- package/build/dts/Mcp/tools/Fetch.d.ts +0 -168
- package/build/dts/Mcp/tools/Fetch.d.ts.map +0 -1
- package/build/dts/SecureFile.d.ts +0 -23
- package/build/dts/SecureFile.d.ts.map +0 -1
- package/build/dts/Snippets.d.ts +0 -18
- package/build/dts/Snippets.d.ts.map +0 -1
- package/build/dts/Telemetry.d.ts +0 -30
- package/build/dts/Telemetry.d.ts.map +0 -1
- package/build/dts/Version.d.ts +0 -2
- package/build/dts/Version.d.ts.map +0 -1
- package/build/dts/Xdg.d.ts +0 -11
- package/build/dts/Xdg.d.ts.map +0 -1
- package/build/dts/index.d.ts.map +0 -1
- package/build/dts/main.d.ts +0 -3
- package/build/dts/main.d.ts.map +0 -1
- package/build/esm/ApiClient.js +0 -305
- package/build/esm/ApiClient.js.map +0 -1
- package/build/esm/Auth/Domain.js +0 -56
- package/build/esm/Auth/Domain.js.map +0 -1
- package/build/esm/Auth/ManualAuthorization.js +0 -253
- package/build/esm/Auth/ManualAuthorization.js.map +0 -1
- package/build/esm/Auth/PendingInit.js +0 -267
- package/build/esm/Auth/PendingInit.js.map +0 -1
- package/build/esm/Auth/Pkce.js +0 -23
- package/build/esm/Auth/Pkce.js.map +0 -1
- package/build/esm/Auth/SetupGrantAuthorization.js +0 -91
- package/build/esm/Auth/SetupGrantAuthorization.js.map +0 -1
- package/build/esm/Authentication.js +0 -143
- package/build/esm/Authentication.js.map +0 -1
- package/build/esm/BrowserOAuth.js +0 -251
- package/build/esm/BrowserOAuth.js.map +0 -1
- package/build/esm/CommandPath.js +0 -31
- package/build/esm/CommandPath.js.map +0 -1
- package/build/esm/Commands/Fetch.js +0 -119
- package/build/esm/Commands/Fetch.js.map +0 -1
- package/build/esm/Commands/Hook.js +0 -20
- package/build/esm/Commands/Hook.js.map +0 -1
- package/build/esm/Commands/Init.js +0 -371
- package/build/esm/Commands/Init.js.map +0 -1
- package/build/esm/Commands/Mcp.js +0 -19
- package/build/esm/Commands/Mcp.js.map +0 -1
- package/build/esm/Commands/McpRun.js +0 -15
- package/build/esm/Commands/McpRun.js.map +0 -1
- package/build/esm/Commands/Search.js +0 -46
- package/build/esm/Commands/Search.js.map +0 -1
- package/build/esm/Commands/Skill.js +0 -17
- package/build/esm/Commands/Skill.js.map +0 -1
- package/build/esm/Commands/Status.js +0 -186
- package/build/esm/Commands/Status.js.map +0 -1
- package/build/esm/Commands/Telemetry.js +0 -23
- package/build/esm/Commands/Telemetry.js.map +0 -1
- package/build/esm/Commands/Uninstall.js +0 -28
- package/build/esm/Commands/Uninstall.js.map +0 -1
- package/build/esm/Config.js +0 -619
- package/build/esm/Config.js.map +0 -1
- package/build/esm/Hook/Claude.js +0 -74
- package/build/esm/Hook/Claude.js.map +0 -1
- package/build/esm/Hook/Errors.js +0 -18
- package/build/esm/Hook/Errors.js.map +0 -1
- package/build/esm/Hook/Opencode.js +0 -50
- package/build/esm/Hook/Opencode.js.map +0 -1
- package/build/esm/Hook/SnapshotNote.js +0 -65
- package/build/esm/Hook/SnapshotNote.js.map +0 -1
- package/build/esm/Init/ClaudeAdapter.js +0 -137
- package/build/esm/Init/ClaudeAdapter.js.map +0 -1
- package/build/esm/Init/ClaudeProfile.js +0 -344
- package/build/esm/Init/ClaudeProfile.js.map +0 -1
- package/build/esm/Init/Domain.js +0 -118
- package/build/esm/Init/Domain.js.map +0 -1
- package/build/esm/Init/HarnessAdapter.js +0 -21
- package/build/esm/Init/HarnessAdapter.js.map +0 -1
- package/build/esm/Init/HarnessDetector.js +0 -65
- package/build/esm/Init/HarnessDetector.js.map +0 -1
- package/build/esm/Init/HarnessRegistry.js +0 -58
- package/build/esm/Init/HarnessRegistry.js.map +0 -1
- package/build/esm/Init/MutationTransaction.js +0 -494
- package/build/esm/Init/MutationTransaction.js.map +0 -1
- package/build/esm/Init/Service.js +0 -319
- package/build/esm/Init/Service.js.map +0 -1
- package/build/esm/Init/StandardAdapters.js +0 -116
- package/build/esm/Init/StandardAdapters.js.map +0 -1
- package/build/esm/Init/Status.js +0 -215
- package/build/esm/Init/Status.js.map +0 -1
- package/build/esm/Install/Claude/Hook.js +0 -77
- package/build/esm/Install/Claude/Hook.js.map +0 -1
- package/build/esm/Install/Claude/Mcp.js +0 -101
- package/build/esm/Install/Claude/Mcp.js.map +0 -1
- package/build/esm/Install/Claude/Skill.js +0 -56
- package/build/esm/Install/Claude/Skill.js.map +0 -1
- package/build/esm/Install/Codex/Mcp.js +0 -97
- package/build/esm/Install/Codex/Mcp.js.map +0 -1
- package/build/esm/Install/Codex/Skill.js +0 -33
- package/build/esm/Install/Codex/Skill.js.map +0 -1
- package/build/esm/Install/Cursor/Mcp.js +0 -74
- package/build/esm/Install/Cursor/Mcp.js.map +0 -1
- package/build/esm/Install/Cursor/Skill.js +0 -40
- package/build/esm/Install/Cursor/Skill.js.map +0 -1
- package/build/esm/Install/Domain.js +0 -162
- package/build/esm/Install/Domain.js.map +0 -1
- package/build/esm/Install/Hook.js +0 -38
- package/build/esm/Install/Hook.js.map +0 -1
- package/build/esm/Install/Mcp.js +0 -40
- package/build/esm/Install/Mcp.js.map +0 -1
- package/build/esm/Install/Opencode/Hook.js +0 -44
- package/build/esm/Install/Opencode/Hook.js.map +0 -1
- package/build/esm/Install/Opencode/Mcp.js +0 -76
- package/build/esm/Install/Opencode/Mcp.js.map +0 -1
- package/build/esm/Install/Opencode/Skill.js +0 -37
- package/build/esm/Install/Opencode/Skill.js.map +0 -1
- package/build/esm/Install/Skill.js +0 -41
- package/build/esm/Install/Skill.js.map +0 -1
- package/build/esm/Install/Uninstall.js +0 -49
- package/build/esm/Install/Uninstall.js.map +0 -1
- package/build/esm/MarkdownAnsi.js +0 -142
- package/build/esm/MarkdownAnsi.js.map +0 -1
- package/build/esm/Mcp/ExpandDocs.js +0 -56
- package/build/esm/Mcp/ExpandDocs.js.map +0 -1
- package/build/esm/Mcp/RequestHeaders.js +0 -13
- package/build/esm/Mcp/RequestHeaders.js.map +0 -1
- package/build/esm/Mcp/Server.js +0 -12
- package/build/esm/Mcp/Server.js.map +0 -1
- package/build/esm/Mcp/Toolkit.js +0 -16
- package/build/esm/Mcp/Toolkit.js.map +0 -1
- package/build/esm/Mcp/tools/Citations.js +0 -193
- package/build/esm/Mcp/tools/Citations.js.map +0 -1
- package/build/esm/Mcp/tools/Fetch.js +0 -165
- package/build/esm/Mcp/tools/Fetch.js.map +0 -1
- package/build/esm/SecureFile.js +0 -36
- package/build/esm/SecureFile.js.map +0 -1
- package/build/esm/Snippets.js +0 -29
- package/build/esm/Snippets.js.map +0 -1
- package/build/esm/Telemetry.js +0 -157
- package/build/esm/Telemetry.js.map +0 -1
- package/build/esm/Version.js +0 -4
- package/build/esm/Version.js.map +0 -1
- package/build/esm/Xdg.js +0 -15
- package/build/esm/Xdg.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/esm/main.js.map +0 -1
- package/src/ApiClient.ts +0 -450
- package/src/Auth/Domain.ts +0 -63
- package/src/Auth/ManualAuthorization.ts +0 -296
- package/src/Auth/PendingInit.ts +0 -338
- package/src/Auth/Pkce.ts +0 -26
- package/src/Auth/SetupGrantAuthorization.ts +0 -116
- package/src/Authentication.ts +0 -202
- package/src/BrowserOAuth.ts +0 -359
- package/src/CommandPath.ts +0 -30
- package/src/Commands/Fetch.ts +0 -188
- package/src/Commands/Hook.ts +0 -48
- package/src/Commands/Init.ts +0 -489
- package/src/Commands/Mcp.ts +0 -30
- package/src/Commands/McpRun.ts +0 -25
- package/src/Commands/Search.ts +0 -97
- package/src/Commands/Skill.ts +0 -30
- package/src/Commands/Status.ts +0 -228
- package/src/Commands/Telemetry.ts +0 -42
- package/src/Commands/Uninstall.ts +0 -38
- package/src/Config.ts +0 -840
- package/src/Hook/Claude.ts +0 -81
- package/src/Hook/Errors.ts +0 -19
- package/src/Hook/Opencode.ts +0 -58
- package/src/Hook/SnapshotNote.ts +0 -66
- package/src/Init/ClaudeAdapter.ts +0 -191
- package/src/Init/ClaudeProfile.ts +0 -453
- package/src/Init/Domain.ts +0 -153
- package/src/Init/HarnessAdapter.ts +0 -35
- package/src/Init/HarnessDetector.ts +0 -77
- package/src/Init/HarnessRegistry.ts +0 -87
- package/src/Init/MutationTransaction.ts +0 -747
- package/src/Init/Service.ts +0 -385
- package/src/Init/StandardAdapters.ts +0 -141
- package/src/Init/Status.ts +0 -253
- package/src/Install/Claude/Hook.ts +0 -123
- package/src/Install/Claude/Mcp.ts +0 -129
- package/src/Install/Claude/Skill.ts +0 -77
- package/src/Install/Codex/Mcp.ts +0 -114
- package/src/Install/Codex/Skill.ts +0 -44
- package/src/Install/Cursor/Mcp.ts +0 -85
- package/src/Install/Cursor/Skill.ts +0 -51
- package/src/Install/Domain.ts +0 -221
- package/src/Install/Hook.ts +0 -50
- package/src/Install/Mcp.ts +0 -71
- package/src/Install/Opencode/Hook.ts +0 -55
- package/src/Install/Opencode/Mcp.ts +0 -87
- package/src/Install/Opencode/Skill.ts +0 -48
- package/src/Install/Opencode/expandai-webfetch.d.ts +0 -23
- package/src/Install/Opencode/expandai-webfetch.js +0 -56
- package/src/Install/Skill.ts +0 -57
- package/src/Install/Uninstall.ts +0 -82
- package/src/MarkdownAnsi.ts +0 -162
- package/src/Mcp/ExpandDocs.ts +0 -62
- package/src/Mcp/RequestHeaders.ts +0 -16
- package/src/Mcp/Server.ts +0 -15
- package/src/Mcp/Toolkit.ts +0 -21
- package/src/Mcp/tools/Citations.ts +0 -219
- package/src/Mcp/tools/Fetch.ts +0 -203
- package/src/SecureFile.ts +0 -70
- package/src/Snippets.ts +0 -39
- package/src/Telemetry.ts +0 -186
- package/src/Version.ts +0 -3
- package/src/Xdg.ts +0 -18
- package/src/index.ts +0 -1
- package/src/main.ts +0 -305
package/build/esm/ApiClient.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import { HttpClient, HttpClientRequest, HttpClientResponse } from '@effect/platform';
|
|
2
|
-
import { NodeHttpClient } from '@effect/platform-node';
|
|
3
|
-
import { fetchObjectModeJson, fetchSnapshotSearch } from '@expandai/sdk/FetchJson';
|
|
4
|
-
import * as Generated from '@expandai/sdk/Generated';
|
|
5
|
-
import { decodeError, unexpectedStatus } from '@expandai/sdk/HttpClientHelpers';
|
|
6
|
-
import { Data, DateTime, Duration, Effect, flow, Match, Option, Redacted, Schema } from 'effect';
|
|
7
|
-
import { CLI_AUTHORIZATION_CLIENT_ID } from './Auth/Domain.js';
|
|
8
|
-
import { BrowserOAuthService } from './BrowserOAuth.js';
|
|
9
|
-
import { ConfigManager, OAuthConfig, OAuthTokenExpired } from './Config.js';
|
|
10
|
-
import { CurrentRequestHeaders } from './Mcp/RequestHeaders.js';
|
|
11
|
-
export class DeviceAuthorizationCreated extends Schema.Class('DeviceAuthorizationCreated')({
|
|
12
|
-
deviceCode: Schema.Redacted(Schema.NonEmptyString),
|
|
13
|
-
userCode: Schema.NonEmptyString,
|
|
14
|
-
// `Schema.URL` decodes to a `URL`; the wire form stays a string. The CLI
|
|
15
|
-
// hands this to the user to open, so a malformed `appUrls.app` should fail
|
|
16
|
-
// here rather than in a browser.
|
|
17
|
-
verificationUri: Schema.URL,
|
|
18
|
-
// Whole seconds. A zero or negative `expiresIn` is a window that has already
|
|
19
|
-
// closed, so it must be positive.
|
|
20
|
-
expiresIn: Schema.Int.pipe(Schema.positive()),
|
|
21
|
-
// `interval` is RFC 8628's *minimum* wait between polls, so zero is
|
|
22
|
-
// meaningful — poll without delay. Only negative is nonsense, and it would
|
|
23
|
-
// make `nextPollAt` drift backwards forever.
|
|
24
|
-
interval: Schema.Int.pipe(Schema.nonNegative()),
|
|
25
|
-
}) {
|
|
26
|
-
}
|
|
27
|
-
const ManualAuthorizationTokenResponse = Schema.Struct({
|
|
28
|
-
access_token: Schema.Redacted(Schema.NonEmptyString),
|
|
29
|
-
refresh_token: Schema.Redacted(Schema.NonEmptyString),
|
|
30
|
-
token_type: Schema.NonEmptyString,
|
|
31
|
-
expires_in: Schema.Number.pipe(Schema.positive()),
|
|
32
|
-
scope: Schema.optional(Schema.String),
|
|
33
|
-
});
|
|
34
|
-
const ManualAuthorizationOperation = Schema.Literal('create', 'poll');
|
|
35
|
-
export class ManualAuthorizationApiError extends Schema.TaggedError()('ManualAuthorizationApiError', {
|
|
36
|
-
operation: ManualAuthorizationOperation,
|
|
37
|
-
kind: Schema.Literal('request_failed', 'rejected', 'invalid_response'),
|
|
38
|
-
status: Schema.optional(Schema.Number),
|
|
39
|
-
recoverable: Schema.Boolean,
|
|
40
|
-
}) {
|
|
41
|
-
get message() {
|
|
42
|
-
return this.kind === 'rejected'
|
|
43
|
-
? `Manual authorization ${this.operation} was rejected. Restart authorization if the problem persists.`
|
|
44
|
-
: `Manual authorization ${this.operation} could not be completed safely. Try again.`;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Single user-facing error for any failure crossing the API boundary. The
|
|
49
|
-
* generated client raises a half-dozen status-specific tagged classes plus
|
|
50
|
-
* transport/decode errors; we collapse them here so the rest of the app sees
|
|
51
|
-
* one tag with a ready-made `.message` and never has to know about
|
|
52
|
-
* `Generated.ts` types.
|
|
53
|
-
*/
|
|
54
|
-
export class ApiRequestFailed extends Schema.TaggedError()('ApiRequestFailed', {
|
|
55
|
-
detail: Schema.String,
|
|
56
|
-
}) {
|
|
57
|
-
get message() {
|
|
58
|
-
return this.detail;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const OAUTH_REFRESH_SKEW = Duration.minutes(1);
|
|
62
|
-
class OAuthAuthMethodChanged extends Data.TaggedError('OAuthAuthMethodChanged') {
|
|
63
|
-
}
|
|
64
|
-
function getField(value, key) {
|
|
65
|
-
return typeof value === 'object' && value !== null && key in value ? value[key] : undefined;
|
|
66
|
-
}
|
|
67
|
-
function getStringField(value, key) {
|
|
68
|
-
const field = getField(value, key);
|
|
69
|
-
return typeof field === 'string' ? field : undefined;
|
|
70
|
-
}
|
|
71
|
-
function getIssueList(value) {
|
|
72
|
-
const issues = getField(value, 'issues');
|
|
73
|
-
return Array.isArray(issues) ? issues : [];
|
|
74
|
-
}
|
|
75
|
-
function getUnsupportedFields(value) {
|
|
76
|
-
const unsupportedFields = getField(value, 'unsupportedFields');
|
|
77
|
-
return Array.isArray(unsupportedFields) ? unsupportedFields.filter((field) => typeof field === 'string') : [];
|
|
78
|
-
}
|
|
79
|
-
function formatIssue({ path, message }) {
|
|
80
|
-
const prefix = path.map((segment) => (typeof segment === 'object' ? segment.key : String(segment))).join('.');
|
|
81
|
-
return prefix ? `${prefix}: ${message}` : message;
|
|
82
|
-
}
|
|
83
|
-
function formatApiFailure(error) {
|
|
84
|
-
switch (getStringField(error, '_tag')) {
|
|
85
|
-
case 'HttpApiDecodeError': {
|
|
86
|
-
const issues = getIssueList(error);
|
|
87
|
-
return issues.length === 0
|
|
88
|
-
? (getStringField(error, 'message') ?? 'Invalid request')
|
|
89
|
-
: issues.map(formatIssue).join('; ');
|
|
90
|
-
}
|
|
91
|
-
case 'AuthFailed':
|
|
92
|
-
return `Authentication failed (${getStringField(error, 'reason') ?? 'unknown'}). Run \`expandai login\` to re-authenticate.`;
|
|
93
|
-
case 'AccessBlocked':
|
|
94
|
-
return 'Access blocked. Check your billing status or contact support.';
|
|
95
|
-
case 'BatchedIncludeUnsupported':
|
|
96
|
-
return `Unsupported batched include fields: ${getUnsupportedFields(error).join(', ')}.`;
|
|
97
|
-
case 'FetchSnapshotSearchNotFound':
|
|
98
|
-
return 'Fetch snapshot not found.';
|
|
99
|
-
case 'PayloadTooLarge':
|
|
100
|
-
return 'Request payload is too large.';
|
|
101
|
-
case 'TooManyRequests':
|
|
102
|
-
return 'Rate limit exceeded — try again in a moment.';
|
|
103
|
-
case 'InternalError':
|
|
104
|
-
return 'The expand.ai API returned an internal error. Try again or contact support.';
|
|
105
|
-
case 'ServiceUnavailable':
|
|
106
|
-
return 'The expand.ai API is temporarily unavailable. Try again shortly.';
|
|
107
|
-
default:
|
|
108
|
-
return error instanceof Error ? error.message : (getStringField(error, 'message') ?? 'Expand API request failed.');
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const liftApiError = (self) => self.pipe(Effect.catchAll((error) => new ApiRequestFailed({ detail: formatApiFailure(error) })));
|
|
112
|
-
/** Public, unauthenticated HTTP boundary for device-flow CLI authorization. */
|
|
113
|
-
export class ManualAuthorizationApiClient extends Effect.Service()('@expandai/cli/ManualAuthorizationApiClient', {
|
|
114
|
-
dependencies: [NodeHttpClient.layer, ConfigManager.Default],
|
|
115
|
-
effect: Effect.gen(function* () {
|
|
116
|
-
const httpClient = yield* HttpClient.HttpClient;
|
|
117
|
-
const configManager = yield* ConfigManager;
|
|
118
|
-
const apiError = (operation, kind, status) => new ManualAuthorizationApiError({
|
|
119
|
-
operation,
|
|
120
|
-
kind,
|
|
121
|
-
status,
|
|
122
|
-
recoverable: kind !== 'invalid_response',
|
|
123
|
-
});
|
|
124
|
-
const create = Effect.fn('ManualAuthorizationApiClient.create')(function* (input) {
|
|
125
|
-
const apiUrl = yield* configManager.getApiUrl();
|
|
126
|
-
const request = yield* HttpClientRequest.post(new URL('/v1/cli-authorization/device', apiUrl)).pipe(HttpClientRequest.bodyJson(input), Effect.mapError(() => apiError('create', 'request_failed')));
|
|
127
|
-
return yield* httpClient.execute(request).pipe(Effect.flatMap((response) => response.status >= 200 && response.status < 300
|
|
128
|
-
? HttpClientResponse.schemaBodyJson(DeviceAuthorizationCreated)(response).pipe(Effect.mapError(() => apiError('create', 'invalid_response')))
|
|
129
|
-
: Effect.fail(apiError('create', 'rejected', response.status))), Effect.catchAll((error) => error instanceof ManualAuthorizationApiError
|
|
130
|
-
? Effect.fail(error)
|
|
131
|
-
: Effect.fail(apiError('create', 'request_failed'))));
|
|
132
|
-
});
|
|
133
|
-
const PollErrorBody = Schema.Struct({
|
|
134
|
-
error: Schema.String,
|
|
135
|
-
error_description: Schema.optional(Schema.String),
|
|
136
|
-
});
|
|
137
|
-
/**
|
|
138
|
-
* RFC 6749/8628 errors that describe the *request* rather than the state
|
|
139
|
-
* of this particular code. Re-minting produces a code that fails
|
|
140
|
-
* identically, so treating these as "expired" is what turns a
|
|
141
|
-
* misconfiguration into an endless approve loop.
|
|
142
|
-
*/
|
|
143
|
-
const PERMANENT_REFUSALS = new Set([
|
|
144
|
-
'invalid_target',
|
|
145
|
-
'invalid_client',
|
|
146
|
-
'invalid_scope',
|
|
147
|
-
'unsupported_grant_type',
|
|
148
|
-
'unauthorized_client',
|
|
149
|
-
'invalid_request',
|
|
150
|
-
]);
|
|
151
|
-
/**
|
|
152
|
-
* One poll of the OAuth token endpoint (RFC 8628). Form-encoded, and
|
|
153
|
-
* always against `/oauth2/token`: `/device/token` is the first-party
|
|
154
|
-
* session path and the server rejects our client there by design.
|
|
155
|
-
*/
|
|
156
|
-
const poll = Effect.fn('ManualAuthorizationApiClient.poll')(function* (deviceCode) {
|
|
157
|
-
const apiUrl = yield* configManager.getApiUrl();
|
|
158
|
-
const request = HttpClientRequest.post(new URL('/api/auth/oauth2/token', apiUrl)).pipe(HttpClientRequest.bodyUrlParams({
|
|
159
|
-
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
160
|
-
device_code: Redacted.value(deviceCode),
|
|
161
|
-
client_id: CLI_AUTHORIZATION_CLIENT_ID,
|
|
162
|
-
}));
|
|
163
|
-
return yield* httpClient.execute(request).pipe(Effect.flatMap(Effect.fnUntraced(function* (response) {
|
|
164
|
-
if (response.status >= 200 && response.status < 300) {
|
|
165
|
-
const token = yield* HttpClientResponse.schemaBodyJson(ManualAuthorizationTokenResponse)(response).pipe(Effect.mapError(() => apiError('poll', 'invalid_response')));
|
|
166
|
-
return { _tag: 'Tokens', token };
|
|
167
|
-
}
|
|
168
|
-
if (response.status >= 500)
|
|
169
|
-
return yield* apiError('poll', 'rejected', response.status);
|
|
170
|
-
const body = yield* HttpClientResponse.schemaBodyJson(PollErrorBody)(response).pipe(Effect.mapError(() => apiError('poll', 'invalid_response')));
|
|
171
|
-
switch (body.error) {
|
|
172
|
-
case 'authorization_pending':
|
|
173
|
-
return { _tag: 'Pending' };
|
|
174
|
-
case 'slow_down':
|
|
175
|
-
return { _tag: 'SlowDown' };
|
|
176
|
-
case 'access_denied':
|
|
177
|
-
return { _tag: 'Denied' };
|
|
178
|
-
case 'expired_token':
|
|
179
|
-
return { _tag: 'Expired' };
|
|
180
|
-
default:
|
|
181
|
-
return PERMANENT_REFUSALS.has(body.error)
|
|
182
|
-
? {
|
|
183
|
-
_tag: 'Refused',
|
|
184
|
-
error: body.error,
|
|
185
|
-
...(body.error_description === undefined ? {} : { description: body.error_description }),
|
|
186
|
-
}
|
|
187
|
-
: { _tag: 'Invalid' };
|
|
188
|
-
}
|
|
189
|
-
})), Effect.catchAll((error) => error instanceof ManualAuthorizationApiError
|
|
190
|
-
? Effect.fail(error)
|
|
191
|
-
: Effect.fail(apiError('poll', 'request_failed'))));
|
|
192
|
-
});
|
|
193
|
-
return { create, poll };
|
|
194
|
-
}),
|
|
195
|
-
}) {
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Resolves outgoing API auth per call. When the current request scope carries
|
|
199
|
-
* an `Authorization` header (via `CurrentRequestHeaders`), that value is
|
|
200
|
-
* forwarded; otherwise auth comes from `~/.config/expandai/config.json`.
|
|
201
|
-
*/
|
|
202
|
-
export class ApiClient extends Effect.Service()('@expandai/cli/ApiClient', {
|
|
203
|
-
dependencies: [NodeHttpClient.layer, ConfigManager.Default, BrowserOAuthService.Default],
|
|
204
|
-
scoped: Effect.gen(function* () {
|
|
205
|
-
const configManager = yield* ConfigManager;
|
|
206
|
-
const browserOAuth = yield* BrowserOAuthService;
|
|
207
|
-
const baseClient = yield* HttpClient.HttpClient;
|
|
208
|
-
const refreshLock = yield* Effect.makeSemaphore(1);
|
|
209
|
-
const freshOAuthAccessToken = Effect.fn('ApiClient.freshOAuthAccessToken')(function* ({ accessToken, expiresAt, refreshToken, }) {
|
|
210
|
-
const now = yield* DateTime.now;
|
|
211
|
-
const refreshThreshold = refreshToken === undefined ? now : DateTime.addDuration(now, OAUTH_REFRESH_SKEW);
|
|
212
|
-
if (DateTime.lessThan(refreshThreshold, expiresAt)) {
|
|
213
|
-
return Option.some(Redacted.value(accessToken));
|
|
214
|
-
}
|
|
215
|
-
return Option.none();
|
|
216
|
-
});
|
|
217
|
-
const refreshOAuthToken = Effect.fn('ApiClient.refreshOAuthToken')(function* ({ refreshToken, expiresAt, clientId, }) {
|
|
218
|
-
if (refreshToken === undefined) {
|
|
219
|
-
return yield* new OAuthTokenExpired({ expiredAt: expiresAt });
|
|
220
|
-
}
|
|
221
|
-
const now = yield* DateTime.now;
|
|
222
|
-
const token = yield* browserOAuth.refreshToken(Redacted.value(refreshToken), clientId);
|
|
223
|
-
if (token === undefined) {
|
|
224
|
-
return yield* new OAuthTokenExpired({ expiredAt: expiresAt });
|
|
225
|
-
}
|
|
226
|
-
const refreshedExpiresAt = DateTime.addDuration(now, token.expires_in);
|
|
227
|
-
const nextRefreshToken = token.refresh_token === undefined ? refreshToken : Redacted.make(token.refresh_token);
|
|
228
|
-
yield* configManager.updateConfig({
|
|
229
|
-
authMethod: OAuthConfig.make({
|
|
230
|
-
accessToken: Redacted.make(token.access_token),
|
|
231
|
-
refreshToken: nextRefreshToken,
|
|
232
|
-
expiresAt: refreshedExpiresAt,
|
|
233
|
-
clientId,
|
|
234
|
-
}),
|
|
235
|
-
});
|
|
236
|
-
return token.access_token;
|
|
237
|
-
});
|
|
238
|
-
const oauthBearerToken = Effect.fn('ApiClient.oauthBearerToken')(function* (authMethod) {
|
|
239
|
-
const alreadyFresh = yield* freshOAuthAccessToken(authMethod);
|
|
240
|
-
if (Option.isSome(alreadyFresh)) {
|
|
241
|
-
return alreadyFresh.value;
|
|
242
|
-
}
|
|
243
|
-
return yield* refreshLock.withPermits(1)(Effect.gen(function* () {
|
|
244
|
-
const { authMethod: persistedAuthMethod } = yield* configManager.loadConfig();
|
|
245
|
-
if (persistedAuthMethod._tag !== 'OAuth') {
|
|
246
|
-
return yield* new OAuthAuthMethodChanged({});
|
|
247
|
-
}
|
|
248
|
-
const persistedFresh = yield* freshOAuthAccessToken(persistedAuthMethod);
|
|
249
|
-
if (Option.isSome(persistedFresh)) {
|
|
250
|
-
return persistedFresh.value;
|
|
251
|
-
}
|
|
252
|
-
return yield* refreshOAuthToken(persistedAuthMethod);
|
|
253
|
-
}));
|
|
254
|
-
});
|
|
255
|
-
// Resolved per call, not at construction. Effect Layers are globally
|
|
256
|
-
// memoized, so capturing CurrentRequestHeaders here once would freeze
|
|
257
|
-
// auth resolution to whatever was on the first request. Reading per
|
|
258
|
-
// call also keeps the OAuth `expiresAt` check live against `DateTime.now`.
|
|
259
|
-
// `Effect.serviceOption` reads the tag from the outer fiber context
|
|
260
|
-
// without leaking it into our R, so the API's per-request
|
|
261
|
-
// `Context.make(CurrentRequestHeaders, headers)` flows through and the
|
|
262
|
-
// stdio MCP path simply gets `Option.none` → empty headers.
|
|
263
|
-
const buildAuthedClientOnce = () => Effect.gen(function* () {
|
|
264
|
-
const forwardedHeaders = yield* Effect.serviceOption(CurrentRequestHeaders).pipe(Effect.map(Option.getOrElse(() => ({}))));
|
|
265
|
-
// header keys are lowercase per WHATWG Headers spec.
|
|
266
|
-
const forwardedAuth = Option.fromNullable(forwardedHeaders['authorization']);
|
|
267
|
-
if (Option.isSome(forwardedAuth)) {
|
|
268
|
-
// Forwarded path: caller owns the token's lifecycle (their session,
|
|
269
|
-
// their bearer). We don't re-check expiry — if it's stale the API
|
|
270
|
-
// will return 401. `OAuthTokenExpired` is for the *persisted*
|
|
271
|
-
// OAuth in the loadConfig branch only.
|
|
272
|
-
const apiUrl = yield* configManager.getApiUrl();
|
|
273
|
-
const mapRequest = flow(HttpClientRequest.prependUrl(apiUrl.toString()), HttpClientRequest.setHeader('authorization', forwardedAuth.value));
|
|
274
|
-
return baseClient.pipe(HttpClient.mapRequest(mapRequest));
|
|
275
|
-
}
|
|
276
|
-
const { authMethod, apiUrl } = yield* configManager.loadConfig();
|
|
277
|
-
const applyAuth = yield* Match.value(authMethod).pipe(Match.tag('ApiKey', ({ apiKey }) => Effect.succeed(HttpClientRequest.setHeader('x-expand-api-key', Redacted.value(apiKey)))), Match.tag('OAuth', (authMethod) => oauthBearerToken(authMethod).pipe(Effect.map((accessToken) => HttpClientRequest.bearerToken(accessToken)))), Match.exhaustive);
|
|
278
|
-
const mapRequest = flow(HttpClientRequest.prependUrl(apiUrl.toString()), applyAuth);
|
|
279
|
-
return baseClient.pipe(HttpClient.mapRequest(mapRequest));
|
|
280
|
-
});
|
|
281
|
-
const buildAuthedClient = () => buildAuthedClientOnce().pipe(Effect.catchTag('OAuthAuthMethodChanged', () => buildAuthedClientOnce()));
|
|
282
|
-
const buildAuthed = () => buildAuthedClient().pipe(Effect.map(Generated.make));
|
|
283
|
-
const fetchMarkdown = (client, options) => HttpClientRequest.make('POST')('/v1/fetch').pipe(HttpClientRequest.setUrlParams(options.params.include !== undefined ? { include: options.params.include } : {}), (req) => Effect.orDie(HttpClientRequest.bodyJson(req, options.payload)), Effect.flatMap((request) => Effect.flatMap(client.execute(request), HttpClientResponse.matchStatus({
|
|
284
|
-
'200': (response) => response.text,
|
|
285
|
-
'400': (response) => decodeError(response, Generated.FetchFetch400),
|
|
286
|
-
'401': (response) => decodeError(response, Generated.AuthFailed),
|
|
287
|
-
'403': (response) => decodeError(response, Generated.FetchFetch403),
|
|
288
|
-
'413': (response) => decodeError(response, Generated.PayloadTooLarge),
|
|
289
|
-
'429': (response) => decodeError(response, Generated.TooManyRequests),
|
|
290
|
-
'500': (response) => decodeError(response, Generated.InternalError),
|
|
291
|
-
'503': (response) => decodeError(response, Generated.ServiceUnavailable),
|
|
292
|
-
orElse: (response) => unexpectedStatus(request, response),
|
|
293
|
-
}))));
|
|
294
|
-
return {
|
|
295
|
-
fetchFetch: (...args) => buildAuthedClient().pipe(Effect.flatMap((client) => fetchMarkdown(client, ...args).pipe(liftApiError))),
|
|
296
|
-
fetchFetchResult: (...args) => buildAuthedClient().pipe(Effect.flatMap((client) => fetchObjectModeJson(client, ...args).pipe(liftApiError))),
|
|
297
|
-
fetchFetchJson: (...args) => buildAuthedClient().pipe(Effect.flatMap((client) => fetchObjectModeJson(client, ...args).pipe(liftApiError))),
|
|
298
|
-
fetchFetchSearch: (...args) => buildAuthedClient().pipe(Effect.flatMap((client) => fetchSnapshotSearch(client, ...args).pipe(liftApiError))),
|
|
299
|
-
fetchBatched: (...args) => buildAuthed().pipe(Effect.flatMap((client) => client.fetchBatched(...args).pipe(liftApiError))),
|
|
300
|
-
fetchGetBatched: (...args) => buildAuthed().pipe(Effect.flatMap((client) => client.fetchGetBatched(...args).pipe(liftApiError))),
|
|
301
|
-
};
|
|
302
|
-
}),
|
|
303
|
-
}) {
|
|
304
|
-
}
|
|
305
|
-
//# sourceMappingURL=ApiClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiClient.js","sourceRoot":"","sources":["../../src/ApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAClF,OAAO,KAAK,SAAS,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM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,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;YAC9G,YAAY,EAAE,CAAC,GAAG,IAAkD,EAAE,EAAE,CACvE,WAAW,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;YAChG,eAAe,EAAE,CAAC,GAAG,IAAqD,EAAE,EAAE,CAC7E,WAAW,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;SAC1F,CAAA;IACX,CAAC,CAAC;CACF,CAAC;CAAG"}
|
package/build/esm/Auth/Domain.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'effect';
|
|
2
|
-
/**
|
|
3
|
-
* The OAuth client for browser-approved CLI setup. Distinct from the
|
|
4
|
-
* `expandai-cli` client that `expandai login` uses: that one keeps loopback
|
|
5
|
-
* redirect URIs and must keep showing a consent screen, because Better Auth
|
|
6
|
-
* matches loopback URIs without comparing the port.
|
|
7
|
-
*/
|
|
8
|
-
export const CLI_AUTHORIZATION_CLIENT_ID = 'expandai-cli-browser';
|
|
9
|
-
export const PendingInitKey = Schema.Struct({
|
|
10
|
-
apiOrigin: Schema.String,
|
|
11
|
-
clientId: Schema.Literal(CLI_AUTHORIZATION_CLIENT_ID),
|
|
12
|
-
harness: Schema.Literal('agent-harnesses'),
|
|
13
|
-
scope: Schema.Literal('project', 'global'),
|
|
14
|
-
canonicalScopeRoot: Schema.String,
|
|
15
|
-
});
|
|
16
|
-
/**
|
|
17
|
-
* One pending RFC 8628 device authorization. The `deviceCode` is the whole
|
|
18
|
-
* credential — better-auth binds it to our client id server-side and it never
|
|
19
|
-
* leaves this machine — so the record keeps the same 0600/no-symlink storage
|
|
20
|
-
* discipline the PKCE verifier had.
|
|
21
|
-
*/
|
|
22
|
-
export class PendingInitRecord extends Schema.Class('PendingInitRecord')({
|
|
23
|
-
key: PendingInitKey,
|
|
24
|
-
deviceCode: Schema.Redacted(Schema.String),
|
|
25
|
-
userCode: Schema.String,
|
|
26
|
-
verificationUri: Schema.String,
|
|
27
|
-
// RFC 8628 §3.5: current polling interval in seconds. `slow_down` adds five,
|
|
28
|
-
// permanently, so the backoff has to be persisted — each `init` invocation
|
|
29
|
-
// polls at most once and exits.
|
|
30
|
-
intervalSeconds: Schema.Number,
|
|
31
|
-
// Earliest wall-clock time the next poll may hit the network. An agent
|
|
32
|
-
// re-running `init` faster than the interval gets a local "still pending"
|
|
33
|
-
// instead of a request the server would answer with `slow_down`.
|
|
34
|
-
nextPollAt: Schema.DateTimeUtc,
|
|
35
|
-
approvalExpiresAt: Schema.DateTimeUtc,
|
|
36
|
-
}) {
|
|
37
|
-
}
|
|
38
|
-
export class PendingInitCorrupt extends Schema.TaggedError()('PendingInitCorrupt', {
|
|
39
|
-
path: Schema.String,
|
|
40
|
-
error: Schema.Defect,
|
|
41
|
-
}) {
|
|
42
|
-
recoverable = true;
|
|
43
|
-
get message() {
|
|
44
|
-
return `Pending authorization state at ${this.path} is corrupt and was left unchanged.`;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export class PendingInitStorageError extends Schema.TaggedError()('PendingInitStorageError', {
|
|
48
|
-
path: Schema.String,
|
|
49
|
-
error: Schema.Defect,
|
|
50
|
-
}) {
|
|
51
|
-
recoverable = true;
|
|
52
|
-
get message() {
|
|
53
|
-
return `Could not access pending authorization state at ${this.path}.`;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=Domain.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Domain.js","sourceRoot":"","sources":["../../../src/Auth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IACxF,CAAC;CACD;AAED,MAAM,OAAO,uBAAwB,SAAQ,MAAM,CAAC,WAAW,EAA2B,CAAC,yBAAyB,EAAE;IACrH,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,KAAK,EAAE,MAAM,CAAC,MAAM;CACpB,CAAC;IACQ,WAAW,GAAG,IAAI,CAAA;IAE3B,IAAI,OAAO;QACV,OAAO,mDAAmD,IAAI,CAAC,IAAI,GAAG,CAAA;IACvE,CAAC;CACD"}
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { DateTime, Duration, Effect, Either, Option, Schema } from 'effect';
|
|
2
|
-
import { ManualAuthorizationApiClient, ManualAuthorizationApiError } from '../ApiClient.js';
|
|
3
|
-
import { ConfigManager, OAuthConfig } from '../Config.js';
|
|
4
|
-
import { InitScope } from '../Init/Domain.js';
|
|
5
|
-
import { CLI_VERSION } from '../Version.js';
|
|
6
|
-
import { CLI_AUTHORIZATION_CLIENT_ID, PendingInitRecord } from './Domain.js';
|
|
7
|
-
import { PendingInitStore } from './PendingInit.js';
|
|
8
|
-
export { ALREADY_AUTHENTICATED_MESSAGE, AUTHORIZATION_CONSUMED_MESSAGE, AUTHORIZATION_REQUIRED_MESSAGE, } from '../Init/Domain.js';
|
|
9
|
-
const CLIENT_ID = CLI_AUTHORIZATION_CLIENT_ID;
|
|
10
|
-
/** RFC 8628 §3.5: `slow_down` permanently adds five seconds to the interval. */
|
|
11
|
-
const SLOW_DOWN_INCREMENT_SECONDS = 5;
|
|
12
|
-
export class ManualAuthorizationInput extends Schema.Class('ManualAuthorizationInput')({
|
|
13
|
-
harness: Schema.Literal('agent-harnesses'),
|
|
14
|
-
scope: InitScope,
|
|
15
|
-
cwd: Schema.optional(Schema.String),
|
|
16
|
-
platform: Schema.optional(Schema.String),
|
|
17
|
-
}) {
|
|
18
|
-
}
|
|
19
|
-
/** What the agent relays: where to approve, and the code to type there. */
|
|
20
|
-
export class ManualAuthorizationRequired extends Schema.Class('ManualAuthorizationRequired')({
|
|
21
|
-
verificationUri: Schema.String,
|
|
22
|
-
userCode: Schema.NonEmptyString,
|
|
23
|
-
approvalExpiresAt: Schema.DateTimeUtc,
|
|
24
|
-
}) {
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* One `advance` call moves the flow as far as it can without blocking, then
|
|
28
|
-
* returns. RFC 8628's polling loop is inverted: the agent re-invokes the CLI,
|
|
29
|
-
* and each invocation polls the token endpoint at most once — or not at all,
|
|
30
|
-
* when the persisted interval says the server would answer `slow_down`.
|
|
31
|
-
*/
|
|
32
|
-
export class TokensSaved extends Schema.TaggedClass()('TokensSaved', {}) {
|
|
33
|
-
}
|
|
34
|
-
export class AuthorizationPending extends Schema.TaggedClass()('AuthorizationPending', {
|
|
35
|
-
pending: ManualAuthorizationRequired,
|
|
36
|
-
}) {
|
|
37
|
-
}
|
|
38
|
-
export const ManualAuthorizationOutcome = Schema.Union(TokensSaved, AuthorizationPending);
|
|
39
|
-
export class ManualAuthorizationDenied extends Schema.TaggedError()('ManualAuthorizationDenied', {
|
|
40
|
-
recoverable: Schema.Literal(true),
|
|
41
|
-
}) {
|
|
42
|
-
get message() {
|
|
43
|
-
return 'The authorization request was denied in the browser. Run the same command again to start a new one.';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The server refused redemption for a reason a fresh code cannot fix. Kept
|
|
48
|
-
* separate from every other failure because the correct response is the
|
|
49
|
-
* opposite of the usual one: do not start over, stop and report. Re-minting
|
|
50
|
-
* here is what produced an endless approve loop — each new code is approved by
|
|
51
|
-
* the user and then refused identically, with nothing surfaced.
|
|
52
|
-
*/
|
|
53
|
-
export class ManualAuthorizationRefused extends Schema.TaggedError()('ManualAuthorizationRefused', {
|
|
54
|
-
error: Schema.String,
|
|
55
|
-
description: Schema.optional(Schema.String),
|
|
56
|
-
recoverable: Schema.Literal(false),
|
|
57
|
-
}) {
|
|
58
|
-
get message() {
|
|
59
|
-
const detail = this.description === undefined ? '' : ` — ${this.description}`;
|
|
60
|
-
return `Expand refused to complete this authorization: ${this.error}${detail}. This is a server-side configuration problem, not something a new code can fix. Do not start setup again; report this error.`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export class ManualAuthorizationCredentialSaveFailed extends Schema.TaggedError()('ManualAuthorizationCredentialSaveFailed', {
|
|
64
|
-
recoverable: Schema.Literal(false),
|
|
65
|
-
}) {
|
|
66
|
-
get message() {
|
|
67
|
-
return 'Authorization succeeded, but credentials could not be saved. Start authorization again.';
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function platformName(input) {
|
|
71
|
-
return input.platform ?? process.platform;
|
|
72
|
-
}
|
|
73
|
-
function required(record) {
|
|
74
|
-
return new ManualAuthorizationRequired({
|
|
75
|
-
verificationUri: record.verificationUri,
|
|
76
|
-
userCode: record.userCode,
|
|
77
|
-
approvalExpiresAt: record.approvalExpiresAt,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
export class ManualAuthorization extends Effect.Service()('@expandai/cli/Auth/ManualAuthorization', {
|
|
81
|
-
dependencies: [ConfigManager.Default, PendingInitStore.Default, ManualAuthorizationApiClient.Default],
|
|
82
|
-
effect: Effect.gen(function* () {
|
|
83
|
-
const configManager = yield* ConfigManager;
|
|
84
|
-
const pendingStore = yield* PendingInitStore;
|
|
85
|
-
const apiClient = yield* ManualAuthorizationApiClient;
|
|
86
|
-
const preflight = Effect.fnUntraced(function* (input) {
|
|
87
|
-
yield* configManager.ensureSecureStorage();
|
|
88
|
-
yield* pendingStore.pruneExpired();
|
|
89
|
-
const apiUrl = yield* configManager.getApiUrl();
|
|
90
|
-
const canonicalScopeRoot = yield* pendingStore.canonicalScopeRoot(input.scope, input.cwd);
|
|
91
|
-
const key = {
|
|
92
|
-
apiOrigin: apiUrl.origin,
|
|
93
|
-
clientId: CLIENT_ID,
|
|
94
|
-
harness: input.harness,
|
|
95
|
-
scope: input.scope,
|
|
96
|
-
canonicalScopeRoot,
|
|
97
|
-
};
|
|
98
|
-
return key;
|
|
99
|
-
});
|
|
100
|
-
const create = Effect.fnUntraced(function* (input, key) {
|
|
101
|
-
const created = yield* apiClient.create({
|
|
102
|
-
harness: input.harness,
|
|
103
|
-
scope: input.scope,
|
|
104
|
-
platform: platformName(input),
|
|
105
|
-
machineLabel: `${platformName(input)}-${process.arch}`,
|
|
106
|
-
cliVersion: CLI_VERSION,
|
|
107
|
-
});
|
|
108
|
-
const now = yield* DateTime.now;
|
|
109
|
-
const record = new PendingInitRecord({
|
|
110
|
-
key,
|
|
111
|
-
deviceCode: created.deviceCode,
|
|
112
|
-
userCode: created.userCode,
|
|
113
|
-
// The stored record is JSON on disk, so the decoded `URL` goes back to
|
|
114
|
-
// its string form here rather than at the schema boundary.
|
|
115
|
-
verificationUri: created.verificationUri.toString(),
|
|
116
|
-
intervalSeconds: created.interval,
|
|
117
|
-
nextPollAt: DateTime.addDuration(now, Duration.seconds(created.interval)),
|
|
118
|
-
approvalExpiresAt: DateTime.addDuration(now, Duration.seconds(created.expiresIn)),
|
|
119
|
-
});
|
|
120
|
-
const stored = yield* Effect.either(pendingStore.putIfAbsent(record));
|
|
121
|
-
if (Either.isLeft(stored))
|
|
122
|
-
return yield* stored.left;
|
|
123
|
-
// A concurrent process may have won the write; its record is the live one.
|
|
124
|
-
return stored.right;
|
|
125
|
-
});
|
|
126
|
-
const saveTokens = Effect.fnUntraced(function* (token) {
|
|
127
|
-
const now = yield* DateTime.now;
|
|
128
|
-
const saved = yield* Effect.either(configManager.updateConfig({
|
|
129
|
-
authMethod: OAuthConfig.make({
|
|
130
|
-
accessToken: token.access_token,
|
|
131
|
-
refreshToken: token.refresh_token,
|
|
132
|
-
expiresAt: DateTime.addDuration(now, Duration.seconds(token.expires_in)),
|
|
133
|
-
clientId: CLIENT_ID,
|
|
134
|
-
}),
|
|
135
|
-
}));
|
|
136
|
-
if (Either.isLeft(saved)) {
|
|
137
|
-
return yield* new ManualAuthorizationCredentialSaveFailed({ recoverable: false });
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
const updateAfterPoll = Effect.fnUntraced(function* (record, slowDown) {
|
|
141
|
-
const now = yield* DateTime.now;
|
|
142
|
-
const intervalSeconds = record.intervalSeconds + (slowDown ? SLOW_DOWN_INCREMENT_SECONDS : 0);
|
|
143
|
-
const next = new PendingInitRecord({
|
|
144
|
-
...record,
|
|
145
|
-
intervalSeconds,
|
|
146
|
-
nextPollAt: DateTime.addDuration(now, Duration.seconds(intervalSeconds)),
|
|
147
|
-
});
|
|
148
|
-
// One atomic publish, not delete-then-create: an interrupt between those
|
|
149
|
-
// two lost the device code entirely, and this runs on every poll.
|
|
150
|
-
const replaced = yield* Effect.either(pendingStore.replaceIfMatch(record, next));
|
|
151
|
-
if (Either.isLeft(replaced))
|
|
152
|
-
return record;
|
|
153
|
-
return replaced.right ? next : record;
|
|
154
|
-
});
|
|
155
|
-
const advance = Effect.fn('ManualAuthorization.advance')(function* (input) {
|
|
156
|
-
const key = yield* preflight(input);
|
|
157
|
-
const existing = yield* pendingStore.get(key);
|
|
158
|
-
if (Option.isNone(existing)) {
|
|
159
|
-
const record = yield* create(input, key);
|
|
160
|
-
return new AuthorizationPending({ pending: required(record) });
|
|
161
|
-
}
|
|
162
|
-
const record = existing.value;
|
|
163
|
-
const now = yield* DateTime.now;
|
|
164
|
-
if (DateTime.greaterThan(now, record.approvalExpiresAt)) {
|
|
165
|
-
// Expired locally: start over transparently. The user sees a fresh
|
|
166
|
-
// code, not an error about a code they never got to use.
|
|
167
|
-
yield* pendingStore.removeIfMatch(record);
|
|
168
|
-
const fresh = yield* create(input, key);
|
|
169
|
-
return new AuthorizationPending({ pending: required(fresh) });
|
|
170
|
-
}
|
|
171
|
-
if (DateTime.lessThan(now, record.nextPollAt)) {
|
|
172
|
-
// Inside the polling interval — answering locally is what keeps an
|
|
173
|
-
// eagerly re-running agent from earning `slow_down` penalties.
|
|
174
|
-
return new AuthorizationPending({ pending: required(record) });
|
|
175
|
-
}
|
|
176
|
-
const outcome = yield* apiClient.poll(record.deviceCode);
|
|
177
|
-
switch (outcome._tag) {
|
|
178
|
-
case 'Tokens': {
|
|
179
|
-
yield* saveTokens(outcome.token);
|
|
180
|
-
yield* pendingStore.removeIfMatch(record);
|
|
181
|
-
return new TokensSaved();
|
|
182
|
-
}
|
|
183
|
-
case 'Pending': {
|
|
184
|
-
const next = yield* updateAfterPoll(record, false);
|
|
185
|
-
return new AuthorizationPending({ pending: required(next) });
|
|
186
|
-
}
|
|
187
|
-
case 'SlowDown': {
|
|
188
|
-
const next = yield* updateAfterPoll(record, true);
|
|
189
|
-
return new AuthorizationPending({ pending: required(next) });
|
|
190
|
-
}
|
|
191
|
-
case 'Denied': {
|
|
192
|
-
yield* pendingStore.removeIfMatch(record);
|
|
193
|
-
return yield* new ManualAuthorizationDenied({ recoverable: true });
|
|
194
|
-
}
|
|
195
|
-
case 'Refused': {
|
|
196
|
-
// Deliberately keeps the pending record. Discarding it would mint a
|
|
197
|
-
// fresh code on the next run, which the server refuses identically —
|
|
198
|
-
// so the user approves again, and again. Holding the record means a
|
|
199
|
-
// re-run reports the same error instead of asking for more approvals.
|
|
200
|
-
return yield* new ManualAuthorizationRefused({
|
|
201
|
-
error: outcome.error,
|
|
202
|
-
...(outcome.description === undefined ? {} : { description: outcome.description }),
|
|
203
|
-
recoverable: false,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
case 'Expired':
|
|
207
|
-
case 'Invalid': {
|
|
208
|
-
// The server no longer honours this code — expired, already consumed
|
|
209
|
-
// by a response we never received, or unknown. All three recover the
|
|
210
|
-
// same way: a fresh request and a fresh approval.
|
|
211
|
-
yield* pendingStore.removeIfMatch(record);
|
|
212
|
-
const fresh = yield* create(input, key);
|
|
213
|
-
return new AuthorizationPending({ pending: required(fresh) });
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
/**
|
|
218
|
-
* Redeems a device code that arrived out of band — the dashboard's
|
|
219
|
-
* pre-approved setup token. No pending record is kept: the code is
|
|
220
|
-
* single-use and either redeems on this first poll or never will.
|
|
221
|
-
*/
|
|
222
|
-
const redeemPreApproved = Effect.fn('ManualAuthorization.redeemPreApproved')(function* (deviceCode) {
|
|
223
|
-
const outcome = yield* apiClient.poll(deviceCode);
|
|
224
|
-
switch (outcome._tag) {
|
|
225
|
-
case 'Tokens':
|
|
226
|
-
return yield* saveTokens(outcome.token);
|
|
227
|
-
case 'Denied':
|
|
228
|
-
return yield* new ManualAuthorizationDenied({ recoverable: true });
|
|
229
|
-
case 'Refused':
|
|
230
|
-
return yield* new ManualAuthorizationRefused({
|
|
231
|
-
error: outcome.error,
|
|
232
|
-
...(outcome.description === undefined ? {} : { description: outcome.description }),
|
|
233
|
-
recoverable: false,
|
|
234
|
-
});
|
|
235
|
-
case 'Pending':
|
|
236
|
-
case 'SlowDown':
|
|
237
|
-
case 'Expired':
|
|
238
|
-
case 'Invalid':
|
|
239
|
-
// A dashboard token is minted approved; anything else means it was
|
|
240
|
-
// not produced by that flow, expired, or is already spent.
|
|
241
|
-
return yield* new ManualAuthorizationApiError({
|
|
242
|
-
operation: 'poll',
|
|
243
|
-
kind: 'rejected',
|
|
244
|
-
status: 400,
|
|
245
|
-
recoverable: false,
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
return { advance, redeemPreApproved };
|
|
250
|
-
}),
|
|
251
|
-
}) {
|
|
252
|
-
}
|
|
253
|
-
//# sourceMappingURL=ManualAuthorization.js.map
|