@stdiobus/workers-registry 1.4.14 → 1.5.0-beta.2
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 +181 -21
- package/out/dist/workers-registry/acp-registry/index.js +128 -2
- package/out/dist/workers-registry/acp-registry/index.js.map +4 -4
- package/out/dist/workers-registry/acp-worker/index.js +1 -3
- package/out/dist/workers-registry/acp-worker/index.js.map +4 -4
- package/out/dist/workers-registry/index.d.ts +1 -0
- package/out/dist/workers-registry/index.js +6 -0
- package/out/dist/workers-registry/openai-agent/index.js +1 -1
- package/out/dist/workers-registry/openai-agent/index.js.map +2 -2
- package/out/dist/workers-registry/registry-launcher/index.js +131 -0
- package/out/dist/workers-registry/registry-launcher/index.js.map +7 -0
- package/out/tsc/workers-registry/acp-worker/src/index.d.ts +0 -10
- package/out/tsc/workers-registry/registry-launcher/src/auth/auth-manager.d.ts +392 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/cli/cli.property.test.d.ts +22 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/cli/index.d.ts +9 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/cli/login-command.d.ts +32 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/cli/logout-command.d.ts +25 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/cli/setup-command.d.ts +25 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/cli/status-command.d.ts +21 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/errors.d.ts +190 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/flows/agent-auth-flow.d.ts +146 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/flows/callback-server.d.ts +131 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/flows/callback-server.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/flows/index.d.ts +11 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/flows/terminal-auth-flow.d.ts +252 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/flows/terminal-auth-flow.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/index.d.ts +33 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/integration.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/anthropic-api-key.d.ts +154 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/index.d.ts +20 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/model-credentials.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/openai-api-key.d.ts +182 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/types.d.ts +186 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/pkce.d.ts +61 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/pkce.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/pkce.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/base-provider.d.ts +138 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/base-provider.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/cognito-provider.d.ts +44 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/concrete-providers.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/entra-provider.d.ts +54 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/github-provider.d.ts +19 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/google-provider.d.ts +19 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/index.d.ts +107 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/index.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/oidc-provider.d.ts +413 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/oidc-provider.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/oidc-provider.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/providers.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/providers/types.d.ts +28 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/session.d.ts +251 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/session.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/session.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/state.d.ts +26 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/state.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/state.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/credential-store.d.ts +98 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/credential-store.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/encrypted-file-backend.d.ts +101 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/encrypted-file-backend.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/index.d.ts +12 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/keychain-backend.d.ts +80 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/keychain-backend.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/memory-backend.d.ts +54 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/storage.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/storage/types.d.ts +44 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/token-manager.d.ts +171 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/token-manager.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/token-manager.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/types.d.ts +369 -0
- package/out/tsc/workers-registry/registry-launcher/src/auth/types.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/config/config.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/config/config.test.d.ts +1 -0
- package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/registry/index.d.ts +51 -2
- package/out/tsc/workers-registry/registry-launcher/src/registry/index.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/registry/index.test.d.ts +1 -0
- package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/registry/types.d.ts +24 -0
- package/out/tsc/workers-registry/registry-launcher/src/router/message-router.d.ts +770 -0
- package/out/tsc/workers-registry/registry-launcher/src/router/message-router.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/router/message-router.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/runtime/manager.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/runtime/manager.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/stream/ndjson-handler.property.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/src/stream/ndjson-handler.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/auth-flow.e2e.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/auth-required-flow.e2e.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/api-keys.d.ts +32 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/index.d.ts +17 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/launcher-harness.d.ts +101 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/registry-server.d.ts +46 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-agent-auth.e2e.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-api-keys.e2e.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-auth-required.e2e.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-cli.e2e.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-concurrent.e2e.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-lifecycle.e2e.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-terminal-auth.e2e.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/integration/agent-auth.integration.test.d.ts +9 -0
- package/out/tsc/workers-registry/registry-launcher/tests/integration/registry-launcher.test.d.ts +1 -0
- package/out/tsc/workers-registry/registry-launcher/tests/integration/terminal-auth.integration.test.d.ts +12 -0
- package/package.json +16 -11
- package/out/tsc/workers-registry/acp-worker/src/registry-launcher/router/message-router.d.ts +0 -199
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/config/config.property.test.d.ts → registry-launcher/src/auth/auth-manager.property.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/config/config.test.d.ts → registry-launcher/src/auth/auth-manager.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/registry/index.property.test.d.ts → registry-launcher/src/auth/cli/cli.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/registry/index.test.d.ts → registry-launcher/src/auth/cli/login-command.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/router/message-router.property.test.d.ts → registry-launcher/src/auth/cli/provider-config.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/router/message-router.test.d.ts → registry-launcher/src/auth/cli/setup-command.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/runtime/manager.property.test.d.ts → registry-launcher/src/auth/cli/status-command.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/runtime/manager.test.d.ts → registry-launcher/src/auth/errors.property.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/stream/ndjson-handler.property.test.d.ts → registry-launcher/src/auth/errors.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/stream/ndjson-handler.test.d.ts → registry-launcher/src/auth/flows/agent-auth-flow.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/tests/integration/registry-launcher.test.d.ts → registry-launcher/src/auth/flows/callback-server.property.test.d.ts} +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/api-keys.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/config.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/index.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/types.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/index.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/log.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/log.test.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/registry/resolver.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/router/index.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/agent-runtime.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/index.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/manager.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/types.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/stream/index.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/stream/ndjson-handler.d.ts +0 -0
- /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/test-utils/index.d.ts +0 -0
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
export type { Platform, BinaryTarget, BinaryDistribution, NpxDistribution, UvxDistribution, Distribution, RegistryAgent, Registry, SpawnCommand, } from './registry-launcher/registry/types.js';
|
|
2
|
-
export type { RegistryIndex, IRegistryIndex, } from './registry-launcher/registry/index.js';
|
|
3
1
|
export { ACPAgent } from './agent.js';
|
|
4
|
-
export { PlatformNotSupportedError, NoDistributionError, getCurrentPlatform, resolve, resolveBinary, resolveNpx, resolveUvx, } from './registry-launcher/registry/resolver.js';
|
|
5
|
-
export { AgentRuntimeManager } from './registry-launcher/runtime/manager.js';
|
|
6
|
-
export { AgentRuntimeImpl } from './registry-launcher/runtime/agent-runtime.js';
|
|
7
|
-
export type { RuntimeState, AgentRuntime } from './registry-launcher/runtime/types.js';
|
|
8
|
-
export { NDJSONHandler, INDJSONHandler, ErrorCallback, MessageCallback, } from './registry-launcher/stream/ndjson-handler.js';
|
|
9
|
-
export { MessageRouter, createErrorResponse, ErrorResponse, RoutingErrorCodes, transformMessage, extractAgentId, extractId, WriteCallback, } from './registry-launcher/router/message-router.js';
|
|
10
|
-
export { loadConfig } from './registry-launcher/config/config.js';
|
|
11
|
-
export type { DEFAULT_CONFIG, LauncherConfig, } from './registry-launcher/config/types.js';
|
|
12
2
|
export { MCPManager, MCPConnection, MCPFactories } from './mcp/manager.js';
|
|
13
3
|
export type { MCPServerConfig, MCPContent, MCPImageContent, MCPBlobResourceContents, MCPEmbeddedResource, MCPResource, MCPTextContent, MCPResourceContents, MCPTextResourceContents, MCPTool, MCPToolCallResult, MCPResourceReadResult, } from './mcp/types.js';
|
|
14
4
|
export { canReadFile, canWriteFile, FileReadResult, FileWriteResult, readFile, canUseTerminal, TerminalResult, writeFile, executeCommand, startCommand, } from './acp/client-capabilities.js';
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main orchestrator for OAuth authentication and model credentials.
|
|
3
|
+
*
|
|
4
|
+
* Coordinates providers, flows, storage, and token management.
|
|
5
|
+
* Clearly separates user identity (OAuth/OIDC) from upstream model credentials (API keys).
|
|
6
|
+
*
|
|
7
|
+
* Requirements: 3.1, 4.1, 7b.3, 10.3, 11.4
|
|
8
|
+
*
|
|
9
|
+
* @module auth-manager
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentApiKeys } from '../config/api-keys.js';
|
|
12
|
+
import type { ICredentialStore } from './storage/types.js';
|
|
13
|
+
import type { ITokenManager } from './token-manager.js';
|
|
14
|
+
import type { IAuthProvider } from './providers/types.js';
|
|
15
|
+
import type { AuthProviderId, AuthResult, AuthStatusMap, AgentAuthOptions, AuthMethodType, AuthMethodPrecedenceConfig } from './types.js';
|
|
16
|
+
import type { ModelProviderId, ModelCredentialResult, ModelCredentialStatusMap } from './model-credentials/index.js';
|
|
17
|
+
import type { IModelCredentialStorage } from './model-credentials/openai-api-key.js';
|
|
18
|
+
/**
|
|
19
|
+
* Marker token used to indicate client credentials are configured but not authenticated.
|
|
20
|
+
* This token should NEVER be sent in actual requests.
|
|
21
|
+
*/
|
|
22
|
+
export declare const CLIENT_CREDENTIALS_MARKER = "__CLIENT_CREDENTIALS_CONFIGURED__";
|
|
23
|
+
/**
|
|
24
|
+
* Check if a token is the client credentials marker (not a real token).
|
|
25
|
+
* @param token - The token to check
|
|
26
|
+
* @returns True if the token is the marker
|
|
27
|
+
*/
|
|
28
|
+
export declare function isMarkerToken(token: string | null | undefined): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Options for creating an AuthManager.
|
|
31
|
+
*/
|
|
32
|
+
export interface AuthManagerOptions {
|
|
33
|
+
/** Credential store for persisting OAuth credentials */
|
|
34
|
+
credentialStore: ICredentialStore;
|
|
35
|
+
/** Token manager for token lifecycle management */
|
|
36
|
+
tokenManager: ITokenManager;
|
|
37
|
+
/** Legacy API keys from api-keys.json */
|
|
38
|
+
legacyApiKeys: Record<string, AgentApiKeys>;
|
|
39
|
+
/** Optional custom provider resolver (for testing) */
|
|
40
|
+
providerResolver?: (providerId: AuthProviderId) => IAuthProvider;
|
|
41
|
+
/**
|
|
42
|
+
* Authentication method precedence configuration.
|
|
43
|
+
* Controls which auth method is preferred when multiple are available.
|
|
44
|
+
* Default: oauth2 > api-key (OAuth preferred when available)
|
|
45
|
+
*
|
|
46
|
+
* Requirements: 3.1, 10.3
|
|
47
|
+
*/
|
|
48
|
+
methodPrecedence?: Partial<AuthMethodPrecedenceConfig>;
|
|
49
|
+
/**
|
|
50
|
+
* Optional model credential storage for API key management.
|
|
51
|
+
* When provided, enables getModelCredential() and related methods.
|
|
52
|
+
*
|
|
53
|
+
* Requirements: 7b.3, 7b.4
|
|
54
|
+
*/
|
|
55
|
+
modelCredentialStorage?: IModelCredentialStorage;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Result of authentication method selection.
|
|
59
|
+
*/
|
|
60
|
+
export interface AuthMethodSelectionResult {
|
|
61
|
+
/** The selected authentication method type */
|
|
62
|
+
methodType: AuthMethodType;
|
|
63
|
+
/** The provider ID to use (for oauth2) */
|
|
64
|
+
providerId?: AuthProviderId;
|
|
65
|
+
/** Whether a valid credential was found */
|
|
66
|
+
hasCredential: boolean;
|
|
67
|
+
/** Error message if selection failed */
|
|
68
|
+
error?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Error thrown when authentication method selection fails.
|
|
72
|
+
*/
|
|
73
|
+
export declare class AuthMethodSelectionError extends Error {
|
|
74
|
+
readonly code: 'UNSUPPORTED_METHOD' | 'AMBIGUOUS_PROVIDER' | 'NO_CREDENTIALS';
|
|
75
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
76
|
+
constructor(message: string, code: 'UNSUPPORTED_METHOD' | 'AMBIGUOUS_PROVIDER' | 'NO_CREDENTIALS', details?: Record<string, unknown> | undefined);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Main orchestrator for OAuth authentication and model credentials.
|
|
80
|
+
* Coordinates providers, flows, storage, and token management.
|
|
81
|
+
*
|
|
82
|
+
* This class clearly separates:
|
|
83
|
+
* - User identity (OAuth/OIDC): getTokenForAgent(), authenticateAgent()
|
|
84
|
+
* - Model API access (API Keys): getModelCredential(), injectModelAuth()
|
|
85
|
+
*
|
|
86
|
+
* Responsibilities:
|
|
87
|
+
* - Orchestrate agent auth flow (browser-based OAuth 2.1 with PKCE)
|
|
88
|
+
* - Orchestrate terminal auth flow (interactive CLI setup)
|
|
89
|
+
* - Manage credential precedence (OAuth over legacy api-keys.json)
|
|
90
|
+
* - Inject authentication into agent requests
|
|
91
|
+
* - Report authentication status
|
|
92
|
+
* - Handle logout operations
|
|
93
|
+
* - Manage model API credentials (OpenAI, Anthropic)
|
|
94
|
+
*
|
|
95
|
+
* Method Precedence Strategy (Requirements 3.1, 10.3):
|
|
96
|
+
* - Default precedence: oauth2 > api-key (OAuth preferred when available)
|
|
97
|
+
* - Configurable via AuthConfig.methodPrecedence
|
|
98
|
+
* - Fail-fast on unsupported or ambiguous providerId (configurable)
|
|
99
|
+
*
|
|
100
|
+
* Requirements: 3.1, 4.1, 7b.3, 10.3, 11.4
|
|
101
|
+
*/
|
|
102
|
+
export declare class AuthManager {
|
|
103
|
+
private readonly credentialStore;
|
|
104
|
+
private readonly tokenManager;
|
|
105
|
+
private readonly legacyApiKeys;
|
|
106
|
+
private readonly providerResolver;
|
|
107
|
+
private readonly methodPrecedenceConfig;
|
|
108
|
+
/**
|
|
109
|
+
* Model credential handlers for API key management.
|
|
110
|
+
* These are separate from OAuth providers - they handle API keys for model providers.
|
|
111
|
+
*
|
|
112
|
+
* Requirements: 7b.3
|
|
113
|
+
*/
|
|
114
|
+
private readonly openAIHandler?;
|
|
115
|
+
private readonly anthropicHandler?;
|
|
116
|
+
/**
|
|
117
|
+
* Tracks in-flight authentication flows per provider.
|
|
118
|
+
* Used to implement single-flight pattern: concurrent auth requests for the same
|
|
119
|
+
* provider share the same Promise and receive the same result.
|
|
120
|
+
*
|
|
121
|
+
* Requirements: 3.1, 6.5
|
|
122
|
+
*/
|
|
123
|
+
private readonly inFlightAuthFlows;
|
|
124
|
+
/**
|
|
125
|
+
* Create a new AuthManager.
|
|
126
|
+
*
|
|
127
|
+
* @param options - Configuration options
|
|
128
|
+
*/
|
|
129
|
+
constructor(options: AuthManagerOptions);
|
|
130
|
+
/**
|
|
131
|
+
* Create a new AuthManager (legacy constructor signature).
|
|
132
|
+
*
|
|
133
|
+
* @param credentialStore - Credential store for persisting OAuth credentials
|
|
134
|
+
* @param tokenManager - Token manager for token lifecycle management
|
|
135
|
+
* @param legacyApiKeys - Legacy API keys from api-keys.json
|
|
136
|
+
*/
|
|
137
|
+
constructor(credentialStore: ICredentialStore, tokenManager: ITokenManager, legacyApiKeys: Record<string, AgentApiKeys>);
|
|
138
|
+
/**
|
|
139
|
+
* Type guard to check if the argument is AuthManagerOptions.
|
|
140
|
+
*/
|
|
141
|
+
private isAuthManagerOptions;
|
|
142
|
+
/**
|
|
143
|
+
* Authenticate with a provider using agent auth flow.
|
|
144
|
+
*
|
|
145
|
+
* Initiates the OAuth 2.1 Authorization Code flow with PKCE.
|
|
146
|
+
* Opens the system browser for user authentication.
|
|
147
|
+
*
|
|
148
|
+
* Implements single-flight pattern: if an auth flow is already in progress
|
|
149
|
+
* for the same provider, subsequent callers wait for and share the same result.
|
|
150
|
+
* This prevents multiple simultaneous browser flows for the same provider.
|
|
151
|
+
*
|
|
152
|
+
* Requirement 3.1: Initiate OAuth 2.1 Authorization Code flow with PKCE
|
|
153
|
+
* Requirement 6.5: Concurrent auth requests share the same flow
|
|
154
|
+
*
|
|
155
|
+
* @param providerId - The provider to authenticate with
|
|
156
|
+
* @param options - Optional flow configuration
|
|
157
|
+
* @returns Authentication result indicating success or failure
|
|
158
|
+
*/
|
|
159
|
+
authenticateAgent(providerId: AuthProviderId, options?: AgentAuthOptions): Promise<AuthResult>;
|
|
160
|
+
/**
|
|
161
|
+
* Execute the actual OAuth authentication flow.
|
|
162
|
+
*
|
|
163
|
+
* This is the internal implementation that performs the browser-based
|
|
164
|
+
* OAuth 2.1 Authorization Code flow with PKCE.
|
|
165
|
+
*
|
|
166
|
+
* @param providerId - The provider to authenticate with
|
|
167
|
+
* @param options - Optional flow configuration
|
|
168
|
+
* @returns Authentication result indicating success or failure
|
|
169
|
+
*/
|
|
170
|
+
private executeAuthFlow;
|
|
171
|
+
/**
|
|
172
|
+
* Run interactive terminal setup for a provider.
|
|
173
|
+
*
|
|
174
|
+
* Starts the Setup_Wizard interactive flow for configuring
|
|
175
|
+
* OAuth credentials in headless environments.
|
|
176
|
+
*
|
|
177
|
+
* Requirement 4.1: Start Setup_Wizard interactive flow
|
|
178
|
+
*
|
|
179
|
+
* @param providerId - The provider to set up
|
|
180
|
+
* @returns Authentication result indicating success or failure
|
|
181
|
+
*/
|
|
182
|
+
setupTerminal(providerId: AuthProviderId): Promise<AuthResult>;
|
|
183
|
+
/**
|
|
184
|
+
* Validate credentials collected during terminal auth flow.
|
|
185
|
+
*
|
|
186
|
+
* Note: Terminal auth flow stores client credentials for later use.
|
|
187
|
+
* The actual token exchange happens when the credentials are used.
|
|
188
|
+
* This validation ensures the credentials are properly formatted.
|
|
189
|
+
*
|
|
190
|
+
* @param providerId - The provider to validate against
|
|
191
|
+
* @param credentials - The collected credentials
|
|
192
|
+
* @returns Validation result with status indicator
|
|
193
|
+
*/
|
|
194
|
+
private validateTerminalCredentials;
|
|
195
|
+
/**
|
|
196
|
+
* Get access token for an agent, preferring OAuth over legacy.
|
|
197
|
+
*
|
|
198
|
+
* Requirement 10.3: Prefer OAuth credentials over legacy api-keys.json
|
|
199
|
+
*
|
|
200
|
+
* Security: When providerId is specified, ONLY that provider is used.
|
|
201
|
+
* No fallback to other providers to prevent credential confusion.
|
|
202
|
+
*
|
|
203
|
+
* @param agentId - The agent identifier
|
|
204
|
+
* @param providerId - Optional provider to get token from (strict binding when specified)
|
|
205
|
+
* @returns Access token or null if not available
|
|
206
|
+
*/
|
|
207
|
+
getTokenForAgent(agentId: string, providerId?: AuthProviderId): Promise<string | null>;
|
|
208
|
+
/**
|
|
209
|
+
* Inject authentication into an agent request.
|
|
210
|
+
*
|
|
211
|
+
* Requirement 11.4: Inject access token according to provider's token injection method
|
|
212
|
+
*
|
|
213
|
+
* Security: Uses strict provider binding based on agent ID to prevent
|
|
214
|
+
* credential confusion between different services.
|
|
215
|
+
*
|
|
216
|
+
* @param agentId - The agent identifier
|
|
217
|
+
* @param request - The request object to inject auth into
|
|
218
|
+
* @returns The request object with authentication injected
|
|
219
|
+
*/
|
|
220
|
+
injectAuth(agentId: string, request: object): Promise<object>;
|
|
221
|
+
/**
|
|
222
|
+
* Validate token injection configuration.
|
|
223
|
+
* Prevents header injection attacks and unsafe configurations.
|
|
224
|
+
*
|
|
225
|
+
* @param injection - The injection configuration to validate
|
|
226
|
+
* @returns Error message if invalid, null if valid
|
|
227
|
+
*/
|
|
228
|
+
private validateInjectionConfig;
|
|
229
|
+
/**
|
|
230
|
+
* Apply token injection to a request object.
|
|
231
|
+
*
|
|
232
|
+
* @param request - The request object
|
|
233
|
+
* @param token - The access token
|
|
234
|
+
* @param injection - The injection method
|
|
235
|
+
* @returns The modified request object, or null if injection failed
|
|
236
|
+
*/
|
|
237
|
+
private applyTokenInjection;
|
|
238
|
+
/**
|
|
239
|
+
* Get authentication status for all providers.
|
|
240
|
+
*
|
|
241
|
+
* @returns Map of provider IDs to their authentication status
|
|
242
|
+
*/
|
|
243
|
+
getStatus(): Promise<AuthStatusMap>;
|
|
244
|
+
/**
|
|
245
|
+
* Logout from a specific provider or all providers.
|
|
246
|
+
*
|
|
247
|
+
* Note: This clears OAuth credentials only. Legacy API keys from api-keys.json
|
|
248
|
+
* are managed separately and are not affected by logout.
|
|
249
|
+
*
|
|
250
|
+
* @param providerId - Optional provider to logout from (all OAuth providers if not specified)
|
|
251
|
+
* @throws Error if an invalid provider ID is specified
|
|
252
|
+
*/
|
|
253
|
+
logout(providerId?: AuthProviderId): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Check if re-authentication is required for a provider.
|
|
256
|
+
*
|
|
257
|
+
* @param providerId - The provider to check
|
|
258
|
+
* @returns True if re-authentication is required
|
|
259
|
+
*/
|
|
260
|
+
requiresReauth(providerId: AuthProviderId): Promise<boolean>;
|
|
261
|
+
/**
|
|
262
|
+
* Get the provider for a given agent ID.
|
|
263
|
+
*
|
|
264
|
+
* Maps agent IDs to their OAuth providers based on keyword matching.
|
|
265
|
+
*
|
|
266
|
+
* WARNING: This is a heuristic-based mapping using keyword matching.
|
|
267
|
+
* Agent IDs with ambiguous names (e.g., containing multiple provider keywords)
|
|
268
|
+
* may be mapped to unexpected providers. For production use, consider
|
|
269
|
+
* implementing explicit agent-to-provider configuration.
|
|
270
|
+
*
|
|
271
|
+
* @param agentId - The agent identifier
|
|
272
|
+
* @returns The provider ID or undefined if not mapped
|
|
273
|
+
*/
|
|
274
|
+
getProviderForAgent(agentId: string): AuthProviderId | undefined;
|
|
275
|
+
/**
|
|
276
|
+
* Get API key credential for a model provider.
|
|
277
|
+
*
|
|
278
|
+
* This method is for retrieving API keys for upstream model providers
|
|
279
|
+
* (OpenAI, Anthropic). These providers do NOT offer public OAuth IdP
|
|
280
|
+
* for third-party login - they use API keys instead.
|
|
281
|
+
*
|
|
282
|
+
* This is clearly separated from getTokenForAgent() which handles
|
|
283
|
+
* OAuth tokens for user identity providers.
|
|
284
|
+
*
|
|
285
|
+
* Requirements: 7b.1, 7b.3
|
|
286
|
+
*
|
|
287
|
+
* @param providerId - The model provider ID ('openai' or 'anthropic')
|
|
288
|
+
* @returns The model credential result with API key if found
|
|
289
|
+
*/
|
|
290
|
+
getModelCredential(providerId: ModelProviderId): Promise<ModelCredentialResult>;
|
|
291
|
+
/**
|
|
292
|
+
* Check if a model credential is configured for a provider.
|
|
293
|
+
*
|
|
294
|
+
* Requirements: 7b.3
|
|
295
|
+
*
|
|
296
|
+
* @param providerId - The model provider ID ('openai' or 'anthropic')
|
|
297
|
+
* @returns True if an API key is configured for the provider
|
|
298
|
+
*/
|
|
299
|
+
hasModelCredential(providerId: ModelProviderId): Promise<boolean>;
|
|
300
|
+
/**
|
|
301
|
+
* Get the status of all model credentials.
|
|
302
|
+
*
|
|
303
|
+
* Requirements: 7b.3
|
|
304
|
+
*
|
|
305
|
+
* @returns Map of model provider IDs to their credential status
|
|
306
|
+
*/
|
|
307
|
+
getModelCredentialStatus(): Promise<ModelCredentialStatusMap>;
|
|
308
|
+
/**
|
|
309
|
+
* Inject model API key into a request.
|
|
310
|
+
*
|
|
311
|
+
* This method injects API keys for model providers (OpenAI, Anthropic)
|
|
312
|
+
* according to their documented injection method:
|
|
313
|
+
* - OpenAI: Authorization header with Bearer token
|
|
314
|
+
* - Anthropic: x-api-key header with raw key
|
|
315
|
+
*
|
|
316
|
+
* This is clearly separated from injectAuth() which handles OAuth tokens.
|
|
317
|
+
*
|
|
318
|
+
* Requirements: 7b.3, 7b.5
|
|
319
|
+
*
|
|
320
|
+
* @param providerId - The model provider ID ('openai' or 'anthropic')
|
|
321
|
+
* @param request - The request object to inject auth into
|
|
322
|
+
* @returns The request object with API key injected, or original if not available
|
|
323
|
+
*/
|
|
324
|
+
injectModelAuth(providerId: ModelProviderId, request: object): Promise<object>;
|
|
325
|
+
/**
|
|
326
|
+
* Get the model provider for a given agent ID.
|
|
327
|
+
*
|
|
328
|
+
* Maps agent IDs to their model providers based on keyword matching.
|
|
329
|
+
* This is separate from getProviderForAgent() which maps to OAuth providers.
|
|
330
|
+
*
|
|
331
|
+
* Requirements: 7b.3
|
|
332
|
+
*
|
|
333
|
+
* @param agentId - The agent identifier
|
|
334
|
+
* @returns The model provider ID or undefined if not mapped
|
|
335
|
+
*/
|
|
336
|
+
getModelProviderForAgent(agentId: string): ModelProviderId | undefined;
|
|
337
|
+
/**
|
|
338
|
+
* Get the appropriate model credential handler for a provider.
|
|
339
|
+
*
|
|
340
|
+
* @param providerId - The model provider ID
|
|
341
|
+
* @returns The handler or undefined if not available
|
|
342
|
+
*/
|
|
343
|
+
private getModelCredentialHandler;
|
|
344
|
+
/**
|
|
345
|
+
* Select the best authentication method for an agent based on precedence configuration.
|
|
346
|
+
*
|
|
347
|
+
* Method Precedence Strategy (Requirements 3.1, 10.3):
|
|
348
|
+
* - Default precedence: oauth2 > api-key (OAuth preferred when available)
|
|
349
|
+
* - Iterates through methods in precedence order
|
|
350
|
+
* - Returns the first method with available credentials
|
|
351
|
+
* - Fail-fast on unsupported or ambiguous providerId (configurable)
|
|
352
|
+
*
|
|
353
|
+
* @param agentId - The agent identifier
|
|
354
|
+
* @param availableMethods - Optional list of methods the agent supports (from authMethods)
|
|
355
|
+
* @param providerId - Optional explicit provider ID (strict binding when specified)
|
|
356
|
+
* @returns Selection result with method type, provider, and credential availability
|
|
357
|
+
* @throws AuthMethodSelectionError if fail-fast is enabled and an error occurs
|
|
358
|
+
*/
|
|
359
|
+
selectAuthMethod(agentId: string, availableMethods?: AuthMethodType[], providerId?: AuthProviderId): Promise<AuthMethodSelectionResult>;
|
|
360
|
+
/**
|
|
361
|
+
* Try a specific authentication method for an agent.
|
|
362
|
+
*
|
|
363
|
+
* @param agentId - The agent identifier
|
|
364
|
+
* @param methodType - The authentication method to try
|
|
365
|
+
* @param providerId - Optional explicit provider ID
|
|
366
|
+
* @returns Selection result for this method
|
|
367
|
+
*/
|
|
368
|
+
private tryAuthMethod;
|
|
369
|
+
/**
|
|
370
|
+
* Check if an agent ID has ambiguous provider mapping.
|
|
371
|
+
*
|
|
372
|
+
* Ambiguity occurs when multiple provider keywords match the agent ID.
|
|
373
|
+
* For example, "azure-openai-agent" matches both "azure" and "openai".
|
|
374
|
+
*
|
|
375
|
+
* @param agentId - The agent identifier
|
|
376
|
+
* @returns Ambiguity check result
|
|
377
|
+
*/
|
|
378
|
+
private checkProviderAmbiguity;
|
|
379
|
+
/**
|
|
380
|
+
* Get the current method precedence configuration.
|
|
381
|
+
*
|
|
382
|
+
* @returns The current method precedence configuration
|
|
383
|
+
*/
|
|
384
|
+
getMethodPrecedenceConfig(): AuthMethodPrecedenceConfig;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Create an AuthManager with the given options.
|
|
388
|
+
*
|
|
389
|
+
* @param options - Configuration options
|
|
390
|
+
* @returns A new AuthManager instance
|
|
391
|
+
*/
|
|
392
|
+
export declare function createAuthManager(options: AuthManagerOptions): AuthManager;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Property-based tests for CLI commands.
|
|
3
|
+
*
|
|
4
|
+
* Feature: oauth-authentication
|
|
5
|
+
* Properties 20-22: Logout Credential Removal, Selective Logout Isolation,
|
|
6
|
+
* CLI Exit Code Success
|
|
7
|
+
*
|
|
8
|
+
* @module cli/cli.property.test
|
|
9
|
+
*/
|
|
10
|
+
import * as fc from 'fast-check';
|
|
11
|
+
import { Readable } from 'stream';
|
|
12
|
+
import type { AuthProviderId, StoredCredentials } from '../types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Create a mock readable stream with predefined input.
|
|
15
|
+
* Exported for potential use in other tests.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createMockInput(lines: string[]): Readable;
|
|
18
|
+
/**
|
|
19
|
+
* Arbitrary generator for stored credentials.
|
|
20
|
+
* Exported for potential use in other tests.
|
|
21
|
+
*/
|
|
22
|
+
export declare const storedCredentialsArb: (providerId: AuthProviderId) => fc.Arbitrary<StoredCredentials>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI command exports.
|
|
3
|
+
*
|
|
4
|
+
* @module cli
|
|
5
|
+
*/
|
|
6
|
+
export { runSetupCommand } from './setup-command.js';
|
|
7
|
+
export { runStatusCommand } from './status-command.js';
|
|
8
|
+
export { runLogoutCommand } from './logout-command.js';
|
|
9
|
+
export { runLoginCommand } from './login-command.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AuthProviderId } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the login command.
|
|
4
|
+
*/
|
|
5
|
+
export interface LoginCommandOptions {
|
|
6
|
+
/** Custom output stream (for testing) */
|
|
7
|
+
output?: NodeJS.WritableStream;
|
|
8
|
+
/** Custom timeout in milliseconds (default: 5 minutes) */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Run the login command.
|
|
13
|
+
*
|
|
14
|
+
* Starts the browser-based OAuth 2.1 Authorization Code flow with PKCE
|
|
15
|
+
* for the specified provider.
|
|
16
|
+
*
|
|
17
|
+
* All output goes to stderr to comply with NDJSON protocol requirements.
|
|
18
|
+
*
|
|
19
|
+
* Requirement 3.1: WHEN an agent requires OAuth authentication with `type: "agent"`,
|
|
20
|
+
* THE Auth_Module SHALL initiate the OAuth 2.1 Authorization Code flow with PKCE.
|
|
21
|
+
*
|
|
22
|
+
* Requirement 3.2: WHEN initiating the authorization flow, THE Auth_Module SHALL
|
|
23
|
+
* open the system default browser to the provider's authorization URL.
|
|
24
|
+
*
|
|
25
|
+
* Requirement 9.5: THE Registry_Launcher SHALL exit with code 0 after successfully
|
|
26
|
+
* completing any auth CLI command.
|
|
27
|
+
*
|
|
28
|
+
* @param providerId - The provider to authenticate with
|
|
29
|
+
* @param options - Command options
|
|
30
|
+
* @returns Exit code (0 for success, 1 for failure)
|
|
31
|
+
*/
|
|
32
|
+
export declare function runLoginCommand(providerId: AuthProviderId, options?: LoginCommandOptions): Promise<number>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AuthProviderId } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the logout command.
|
|
4
|
+
*/
|
|
5
|
+
export interface LogoutCommandOptions {
|
|
6
|
+
/** Custom output stream (for testing) */
|
|
7
|
+
output?: NodeJS.WritableStream;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Run the logout command.
|
|
11
|
+
*
|
|
12
|
+
* Removes stored credentials from the Credential_Store.
|
|
13
|
+
* All output goes to stderr to comply with NDJSON protocol requirements.
|
|
14
|
+
*
|
|
15
|
+
* Requirement 9.3: WHEN the `--logout` flag is provided, THE Registry_Launcher
|
|
16
|
+
* SHALL remove all stored credentials from the Credential_Store.
|
|
17
|
+
*
|
|
18
|
+
* Requirement 9.4: WHEN the `--logout` flag is provided with a provider name,
|
|
19
|
+
* THE Registry_Launcher SHALL remove only the credentials for that specific provider.
|
|
20
|
+
*
|
|
21
|
+
* @param providerId - Optional provider to logout from (all if not specified)
|
|
22
|
+
* @param options - Command options
|
|
23
|
+
* @returns Exit code (0 for success, 1 for failure)
|
|
24
|
+
*/
|
|
25
|
+
export declare function runLogoutCommand(providerId?: AuthProviderId, options?: LogoutCommandOptions): Promise<number>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AuthProviderId } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the setup command.
|
|
4
|
+
*/
|
|
5
|
+
export interface SetupCommandOptions {
|
|
6
|
+
/** Optional pre-selected provider (skips provider selection) */
|
|
7
|
+
providerId?: AuthProviderId;
|
|
8
|
+
/** Custom input stream (for testing) */
|
|
9
|
+
input?: NodeJS.ReadableStream;
|
|
10
|
+
/** Custom output stream (for testing) */
|
|
11
|
+
output?: NodeJS.WritableStream;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Run the setup command.
|
|
15
|
+
*
|
|
16
|
+
* Starts the interactive Setup_Wizard for configuring OAuth credentials.
|
|
17
|
+
* All output goes to stderr to comply with NDJSON protocol requirements.
|
|
18
|
+
*
|
|
19
|
+
* Requirement 9.1: WHEN the `--setup` flag is provided, THE Registry_Launcher
|
|
20
|
+
* SHALL start the interactive authentication Setup_Wizard.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Command options
|
|
23
|
+
* @returns Exit code (0 for success, 1 for failure)
|
|
24
|
+
*/
|
|
25
|
+
export declare function runSetupCommand(options?: SetupCommandOptions): Promise<number>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the status command.
|
|
3
|
+
*/
|
|
4
|
+
export interface StatusCommandOptions {
|
|
5
|
+
/** Custom output stream (for testing) */
|
|
6
|
+
output?: NodeJS.WritableStream;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Run the auth-status command.
|
|
10
|
+
*
|
|
11
|
+
* Displays the current authentication status for all configured providers.
|
|
12
|
+
* All output goes to stderr to comply with NDJSON protocol requirements.
|
|
13
|
+
*
|
|
14
|
+
* Requirement 9.2: WHEN the `--auth-status` flag is provided, THE Registry_Launcher
|
|
15
|
+
* SHALL display the current authentication status for all configured providers
|
|
16
|
+
* (authenticated, expired, not configured).
|
|
17
|
+
*
|
|
18
|
+
* @param options - Command options
|
|
19
|
+
* @returns Exit code (0 for success)
|
|
20
|
+
*/
|
|
21
|
+
export declare function runStatusCommand(options?: StatusCommandOptions): Promise<number>;
|