@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
|
@@ -0,0 +1,770 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message Router for the Registry Launcher.
|
|
3
|
+
*
|
|
4
|
+
* Routes incoming JSON-RPC messages to the appropriate agent based on agentId.
|
|
5
|
+
* Handles agentId extraction, message transformation, and error response generation.
|
|
6
|
+
* Integrates with AuthManager for OAuth authentication (Requirements 11.2, 11.4).
|
|
7
|
+
*
|
|
8
|
+
* @module router/message-router
|
|
9
|
+
*/
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import type { IRegistryIndex } from '../registry/index.js';
|
|
12
|
+
import type { AgentRuntimeManager } from '../runtime/manager.js';
|
|
13
|
+
import type { AuthManager } from '../auth/auth-manager.js';
|
|
14
|
+
import type { AcpAuthMethod, AuthProviderId } from '../auth/types.js';
|
|
15
|
+
/**
|
|
16
|
+
* JSON-RPC error codes for routing errors.
|
|
17
|
+
*/
|
|
18
|
+
export declare const RoutingErrorCodes: {
|
|
19
|
+
/** Missing agentId in request */
|
|
20
|
+
readonly MISSING_AGENT_ID: -32600;
|
|
21
|
+
/** Agent not found in registry */
|
|
22
|
+
readonly AGENT_NOT_FOUND: -32001;
|
|
23
|
+
/** Platform not supported for binary distribution */
|
|
24
|
+
readonly PLATFORM_NOT_SUPPORTED: -32002;
|
|
25
|
+
/** Agent spawn failed */
|
|
26
|
+
readonly SPAWN_FAILED: -32003;
|
|
27
|
+
/** Authentication required (Requirement 11.2) */
|
|
28
|
+
readonly AUTH_REQUIRED: -32004;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Valid auth method types from agent responses.
|
|
32
|
+
* - 'oauth2': Standard OAuth 2.1 flow (client handles OAuth)
|
|
33
|
+
* - 'agent': Agent handles OAuth internally (ACP-compliant, default)
|
|
34
|
+
* - 'terminal': Interactive terminal auth (TUI)
|
|
35
|
+
* - 'api-key': API key authentication
|
|
36
|
+
*/
|
|
37
|
+
export type AuthMethodType = 'oauth2' | 'agent' | 'terminal' | 'api-key';
|
|
38
|
+
/**
|
|
39
|
+
* Parsed auth method with validated fields.
|
|
40
|
+
* Discriminated union for type-safe handling.
|
|
41
|
+
*/
|
|
42
|
+
export type ParsedAuthMethod = {
|
|
43
|
+
kind: 'oauth2';
|
|
44
|
+
id: string;
|
|
45
|
+
providerId: AuthProviderId;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'agent';
|
|
48
|
+
id: string;
|
|
49
|
+
providerId?: AuthProviderId;
|
|
50
|
+
} | {
|
|
51
|
+
kind: 'terminal';
|
|
52
|
+
id: string;
|
|
53
|
+
args?: string[];
|
|
54
|
+
env?: Record<string, string>;
|
|
55
|
+
} | {
|
|
56
|
+
kind: 'api-key';
|
|
57
|
+
id: string;
|
|
58
|
+
providerId?: AuthProviderId;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Explicit mapping from auth method IDs to provider IDs.
|
|
62
|
+
* Security: Uses explicit allowlist mapping, no substring heuristics.
|
|
63
|
+
*
|
|
64
|
+
* Requirement 3.1: Support OAuth authentication with type "agent" or "oauth2"
|
|
65
|
+
* Requirement 11.2: Map authMethod.id to AuthProviderId
|
|
66
|
+
*/
|
|
67
|
+
export declare const AUTH_METHOD_ID_TO_PROVIDER: Readonly<Record<string, AuthProviderId>>;
|
|
68
|
+
/**
|
|
69
|
+
* Parse and validate auth methods from agent initialize response.
|
|
70
|
+
*
|
|
71
|
+
* Extracts type and providerId from each auth method, using explicit mapping
|
|
72
|
+
* for id-to-provider resolution. Validates all fields and rejects invalid methods.
|
|
73
|
+
*
|
|
74
|
+
* Security considerations:
|
|
75
|
+
* - Uses explicit allowlist for method types
|
|
76
|
+
* - Uses explicit mapping for id-to-provider (no substring heuristics)
|
|
77
|
+
* - Validates providerId against known providers
|
|
78
|
+
* - Limits number of methods processed (DoS protection)
|
|
79
|
+
* - Deduplicates by method ID
|
|
80
|
+
*
|
|
81
|
+
* Requirement 3.1: Identify methods with type "oauth2" or "agent"
|
|
82
|
+
* Requirement 11.2: Map authMethod.id to AuthProviderId using explicit mapping
|
|
83
|
+
*
|
|
84
|
+
* @param raw - Raw auth methods array from agent response (untrusted input)
|
|
85
|
+
* @returns Array of validated and parsed auth methods
|
|
86
|
+
*/
|
|
87
|
+
export declare function parseAuthMethods(raw: unknown): ParsedAuthMethod[];
|
|
88
|
+
/**
|
|
89
|
+
* Filter parsed auth methods to get only OAuth methods.
|
|
90
|
+
*
|
|
91
|
+
* Requirement 3.1: Identify methods with type "oauth2" or "agent"
|
|
92
|
+
*
|
|
93
|
+
* @param methods - Parsed auth methods
|
|
94
|
+
* @returns Only OAuth methods (kind: 'oauth2')
|
|
95
|
+
*/
|
|
96
|
+
export declare function getOAuthMethods(methods: ParsedAuthMethod[]): Array<ParsedAuthMethod & {
|
|
97
|
+
kind: 'oauth2';
|
|
98
|
+
}>;
|
|
99
|
+
/**
|
|
100
|
+
* Filter parsed auth methods to get only Agent Auth methods.
|
|
101
|
+
*
|
|
102
|
+
* AUTH_REQUIREMENTS.md: Agent Auth is the default authentication method
|
|
103
|
+
* where the agent manages the entire OAuth flow independently.
|
|
104
|
+
*
|
|
105
|
+
* @param methods - Parsed auth methods
|
|
106
|
+
* @returns Only Agent Auth methods (kind: 'agent')
|
|
107
|
+
*/
|
|
108
|
+
export declare function getAgentAuthMethods(methods: ParsedAuthMethod[]): Array<ParsedAuthMethod & {
|
|
109
|
+
kind: 'agent';
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* Filter parsed auth methods to get only Terminal Auth methods.
|
|
113
|
+
*
|
|
114
|
+
* AUTH_REQUIREMENTS.md: Terminal Auth enables agents to run an interactive
|
|
115
|
+
* setup experience within a terminal environment.
|
|
116
|
+
*
|
|
117
|
+
* @param methods - Parsed auth methods
|
|
118
|
+
* @returns Only Terminal Auth methods (kind: 'terminal')
|
|
119
|
+
*/
|
|
120
|
+
export declare function getTerminalAuthMethods(methods: ParsedAuthMethod[]): Array<ParsedAuthMethod & {
|
|
121
|
+
kind: 'terminal';
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Filter parsed auth methods to get only API key methods.
|
|
125
|
+
*
|
|
126
|
+
* @param methods - Parsed auth methods
|
|
127
|
+
* @returns Only API key methods (kind: 'api-key')
|
|
128
|
+
*/
|
|
129
|
+
export declare function getApiKeyMethods(methods: ParsedAuthMethod[]): Array<ParsedAuthMethod & {
|
|
130
|
+
kind: 'api-key';
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* JSON-RPC error response structure.
|
|
134
|
+
*/
|
|
135
|
+
export interface ErrorResponse {
|
|
136
|
+
jsonrpc: '2.0';
|
|
137
|
+
id: string | number | null;
|
|
138
|
+
error: {
|
|
139
|
+
code: number;
|
|
140
|
+
message: string;
|
|
141
|
+
data?: unknown;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Authentication state for an agent.
|
|
146
|
+
*
|
|
147
|
+
* State transitions:
|
|
148
|
+
* - none → pending: OAuth flow initiated
|
|
149
|
+
* - pending → authenticated: OAuth flow succeeded
|
|
150
|
+
* - pending → failed: OAuth flow failed or timed out
|
|
151
|
+
* - failed → pending: Retry OAuth flow
|
|
152
|
+
* - authenticated → none: Logout or token invalidation
|
|
153
|
+
*
|
|
154
|
+
* Requirement 3.1: Track auth state during OAuth 2.1 Authorization Code flow
|
|
155
|
+
* Requirement 3.5: Handle timeout transitions to failed state
|
|
156
|
+
*/
|
|
157
|
+
export type AuthState = 'none' | 'pending' | 'authenticated' | 'failed';
|
|
158
|
+
/**
|
|
159
|
+
* Queued request structure for requests waiting on OAuth authentication.
|
|
160
|
+
*
|
|
161
|
+
* When an OAuth flow is pending for an agent, incoming requests are queued
|
|
162
|
+
* and resumed after successful authentication.
|
|
163
|
+
*
|
|
164
|
+
* Requirement 3.1: Queue requests while OAuth flow is in progress
|
|
165
|
+
*/
|
|
166
|
+
export interface QueuedRequest {
|
|
167
|
+
/** The original message to be routed */
|
|
168
|
+
message: object;
|
|
169
|
+
/** Timestamp when the request was queued */
|
|
170
|
+
queuedAt: number;
|
|
171
|
+
/** Resolve function to signal completion */
|
|
172
|
+
resolve: (result: ErrorResponse | undefined) => void;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Pending authenticate request tracking structure.
|
|
176
|
+
*
|
|
177
|
+
* Tracks authenticate JSON-RPC requests sent to agents for Agent Auth flow.
|
|
178
|
+
* Used to correlate authenticate responses with the original auth flow.
|
|
179
|
+
*
|
|
180
|
+
* AUTH_REQUIREMENTS.md: Agent Auth - client calls authenticate method on agent
|
|
181
|
+
*/
|
|
182
|
+
export interface PendingAuthenticateRequest {
|
|
183
|
+
/** The authenticate request ID */
|
|
184
|
+
requestId: string;
|
|
185
|
+
/** The agent ID */
|
|
186
|
+
agentId: string;
|
|
187
|
+
/** The auth method ID from authMethods */
|
|
188
|
+
authMethodId: string;
|
|
189
|
+
/** Timestamp when the request was sent */
|
|
190
|
+
sentAt: number;
|
|
191
|
+
/** Resolve function to signal completion */
|
|
192
|
+
resolve: (success: boolean, error?: string) => void;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Callback type for writing responses to stdout.
|
|
196
|
+
*/
|
|
197
|
+
export type WriteCallback = (message: object) => boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Create a JSON-RPC error response.
|
|
200
|
+
*
|
|
201
|
+
* @param id - Request ID (null for notifications or unknown)
|
|
202
|
+
* @param code - Error code
|
|
203
|
+
* @param message - Error message
|
|
204
|
+
* @param data - Optional additional error data
|
|
205
|
+
* @returns Error response object
|
|
206
|
+
*/
|
|
207
|
+
export declare function createErrorResponse(id: string | number | null, code: number, message: string, data?: unknown): ErrorResponse;
|
|
208
|
+
/**
|
|
209
|
+
* Extract the agentId field from a message.
|
|
210
|
+
*
|
|
211
|
+
* @param message - The message object to extract from
|
|
212
|
+
* @returns The agentId string or undefined if not present
|
|
213
|
+
*/
|
|
214
|
+
export declare function extractAgentId(message: object): string | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Extract the JSON-RPC id field from a message.
|
|
217
|
+
*
|
|
218
|
+
* @param message - The message object to extract from
|
|
219
|
+
* @returns The id (string, number, or null)
|
|
220
|
+
*/
|
|
221
|
+
export declare function extractId(message: object): string | number | null;
|
|
222
|
+
/**
|
|
223
|
+
* Transform a message for forwarding to an agent.
|
|
224
|
+
*
|
|
225
|
+
* Removes the agentId field while preserving all other fields.
|
|
226
|
+
*
|
|
227
|
+
* @param message - The original message
|
|
228
|
+
* @returns A new message object without the agentId field
|
|
229
|
+
*/
|
|
230
|
+
export declare function transformMessage(message: object): object;
|
|
231
|
+
/**
|
|
232
|
+
* Spawn function type for dependency injection in tests.
|
|
233
|
+
*/
|
|
234
|
+
export type SpawnFn = typeof spawn;
|
|
235
|
+
/**
|
|
236
|
+
* Optional dependencies for MessageRouter (for testing).
|
|
237
|
+
*/
|
|
238
|
+
export interface MessageRouterDeps {
|
|
239
|
+
/** Custom spawn function (default: child_process.spawn) */
|
|
240
|
+
spawnFn?: SpawnFn;
|
|
241
|
+
/** Custom function to check if stdin is TTY (default: process.stdin.isTTY) */
|
|
242
|
+
isStdinTTY?: () => boolean;
|
|
243
|
+
/** Custom function to check if stdout is TTY (default: process.stdout.isTTY) */
|
|
244
|
+
isStdoutTTY?: () => boolean;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Message Router implementation.
|
|
248
|
+
*
|
|
249
|
+
* Routes incoming JSON-RPC messages to the appropriate agent based on agentId.
|
|
250
|
+
* Handles message transformation, error generation, and request correlation.
|
|
251
|
+
* Integrates with AuthManager for OAuth authentication (Requirements 11.2, 11.4).
|
|
252
|
+
* Implements auth state machine for pending OAuth flows (Task 21.3).
|
|
253
|
+
*/
|
|
254
|
+
export declare class MessageRouter {
|
|
255
|
+
/** Registry index for agent lookup and resolution */
|
|
256
|
+
private readonly registry;
|
|
257
|
+
/** Runtime manager for agent process lifecycle */
|
|
258
|
+
private readonly runtimeManager;
|
|
259
|
+
/** Callback for writing responses to stdout */
|
|
260
|
+
private readonly writeCallback;
|
|
261
|
+
/** API keys for agent authentication */
|
|
262
|
+
private readonly apiKeys;
|
|
263
|
+
/** Spawn function for Terminal Auth (injectable for testing) */
|
|
264
|
+
private readonly spawnFn;
|
|
265
|
+
/** Function to check if stdin is TTY (injectable for testing) */
|
|
266
|
+
private readonly isStdinTTY;
|
|
267
|
+
/** Function to check if stdout is TTY (injectable for testing) */
|
|
268
|
+
private readonly isStdoutTTY;
|
|
269
|
+
/** Optional AuthManager for OAuth authentication (Requirements 11.2, 11.4) */
|
|
270
|
+
private readonly authManager?;
|
|
271
|
+
/** Map of request ID to pending request info for correlation */
|
|
272
|
+
private readonly pendingRequests;
|
|
273
|
+
/**
|
|
274
|
+
* Map of agent ID to authentication state.
|
|
275
|
+
*
|
|
276
|
+
* State machine (Task 21.3):
|
|
277
|
+
* - none: No authentication in progress
|
|
278
|
+
* - pending: OAuth flow in progress, requests are queued
|
|
279
|
+
* - authenticated: OAuth flow completed successfully
|
|
280
|
+
* - failed: OAuth flow failed or timed out
|
|
281
|
+
*
|
|
282
|
+
* Requirement 3.1: Track auth state during OAuth 2.1 Authorization Code flow
|
|
283
|
+
*/
|
|
284
|
+
private readonly authState;
|
|
285
|
+
/**
|
|
286
|
+
* Map of agent ID to required OAuth provider ID.
|
|
287
|
+
*
|
|
288
|
+
* Tracks which agents require OAuth authentication and with which provider.
|
|
289
|
+
* This is populated when we receive an initialize response with authMethods
|
|
290
|
+
* containing OAuth methods.
|
|
291
|
+
*
|
|
292
|
+
* Requirement 11.2: Track auth requirements to block requests when OAuth
|
|
293
|
+
* is required but credentials are not available.
|
|
294
|
+
*/
|
|
295
|
+
private readonly agentOAuthRequirements;
|
|
296
|
+
/**
|
|
297
|
+
* Map of agent ID to queued requests waiting for OAuth authentication.
|
|
298
|
+
*
|
|
299
|
+
* When an OAuth flow is pending for an agent, incoming requests are queued
|
|
300
|
+
* here and processed after successful authentication.
|
|
301
|
+
*
|
|
302
|
+
* Requirement 3.1: Queue incoming requests while OAuth flow is pending
|
|
303
|
+
*/
|
|
304
|
+
private readonly requestQueue;
|
|
305
|
+
/**
|
|
306
|
+
* Map of authenticate request ID to pending authenticate request info.
|
|
307
|
+
*
|
|
308
|
+
* Tracks authenticate JSON-RPC requests sent to agents for Agent Auth flow.
|
|
309
|
+
* Used to correlate authenticate responses with the original auth flow.
|
|
310
|
+
*
|
|
311
|
+
* AUTH_REQUIREMENTS.md: Agent Auth - client calls authenticate method on agent
|
|
312
|
+
*/
|
|
313
|
+
private readonly pendingAuthenticateRequests;
|
|
314
|
+
/** Map of agent sessionId to client sessionId for notification routing */
|
|
315
|
+
private readonly sessionIdMap;
|
|
316
|
+
/**
|
|
317
|
+
* Whether to automatically trigger OAuth browser flow when agent requires it.
|
|
318
|
+
* When false, returns AUTH_REQUIRED error instead of opening browser.
|
|
319
|
+
* Controlled by AUTH_AUTO_OAUTH environment variable (default: false for safety).
|
|
320
|
+
*/
|
|
321
|
+
private readonly autoOAuth;
|
|
322
|
+
/**
|
|
323
|
+
* Create a new MessageRouter.
|
|
324
|
+
*
|
|
325
|
+
* @param registry - Registry index for agent lookup
|
|
326
|
+
* @param runtimeManager - Runtime manager for agent processes
|
|
327
|
+
* @param writeCallback - Callback for writing responses to stdout
|
|
328
|
+
* @param apiKeys - API keys for agent authentication (optional)
|
|
329
|
+
* @param authManager - AuthManager for OAuth authentication (optional, Requirements 11.2, 11.4)
|
|
330
|
+
* @param autoOAuth - Whether to auto-trigger OAuth browser flow (default: from AUTH_AUTO_OAUTH env, or false)
|
|
331
|
+
* @param deps - Optional dependencies for testing (spawnFn, TTY checks)
|
|
332
|
+
*/
|
|
333
|
+
constructor(registry: IRegistryIndex, runtimeManager: AgentRuntimeManager, writeCallback: WriteCallback, apiKeys?: Record<string, any>, authManager?: AuthManager, autoOAuth?: boolean, deps?: MessageRouterDeps);
|
|
334
|
+
/**
|
|
335
|
+
* Get auto-OAuth setting from environment variable.
|
|
336
|
+
* AUTH_AUTO_OAUTH=true enables auto-OAuth, any other value or unset disables it.
|
|
337
|
+
*/
|
|
338
|
+
private getAutoOAuthFromEnv;
|
|
339
|
+
/**
|
|
340
|
+
* Get supported authentication methods for ACP initialize response.
|
|
341
|
+
*
|
|
342
|
+
* Requirement 11.1: WHEN responding to an initialize request, THE Registry_Launcher
|
|
343
|
+
* SHALL include an `authMethods` array listing supported authentication methods.
|
|
344
|
+
*
|
|
345
|
+
* @returns Array of supported authentication methods
|
|
346
|
+
*/
|
|
347
|
+
getSupportedAuthMethods(): AcpAuthMethod[];
|
|
348
|
+
/**
|
|
349
|
+
* Check if authentication is available for an agent.
|
|
350
|
+
*
|
|
351
|
+
* Requirement 11.2: WHEN an agent requires authentication and credentials are not available,
|
|
352
|
+
* THE Registry_Launcher SHALL return an AUTH_REQUIRED error response.
|
|
353
|
+
*
|
|
354
|
+
* @param agentId - The agent identifier
|
|
355
|
+
* @returns True if authentication is available (OAuth or legacy API key)
|
|
356
|
+
*/
|
|
357
|
+
hasAuthenticationForAgent(agentId: string): Promise<boolean>;
|
|
358
|
+
/**
|
|
359
|
+
* Check if api-key credentials are available for an agent.
|
|
360
|
+
* This is a synchronous check for api-keys.json credentials.
|
|
361
|
+
*
|
|
362
|
+
* @param agentId - The agent identifier
|
|
363
|
+
* @returns True if api-key credentials are available
|
|
364
|
+
*/
|
|
365
|
+
hasCredentialsForAgent(agentId: string): boolean;
|
|
366
|
+
/**
|
|
367
|
+
* Create an AUTH_REQUIRED error response.
|
|
368
|
+
*
|
|
369
|
+
* Requirement 11.2: WHEN an agent requires authentication and credentials are not available,
|
|
370
|
+
* THE Registry_Launcher SHALL return an AUTH_REQUIRED error response with the required
|
|
371
|
+
* authentication method specified.
|
|
372
|
+
*
|
|
373
|
+
* @param id - The request ID
|
|
374
|
+
* @param agentId - The agent identifier
|
|
375
|
+
* @param requiredMethod - The required authentication method
|
|
376
|
+
* @returns AUTH_REQUIRED error response
|
|
377
|
+
*/
|
|
378
|
+
createAuthRequiredError(id: string | number | null, agentId: string, requiredMethod?: string): ErrorResponse;
|
|
379
|
+
/**
|
|
380
|
+
* Inject authentication into a request using AuthManager.
|
|
381
|
+
*
|
|
382
|
+
* Requirement 11.4: WHEN authentication is successful, THE Auth_Module SHALL inject
|
|
383
|
+
* the access token into agent requests according to the provider's token injection method.
|
|
384
|
+
*
|
|
385
|
+
* @param agentId - The agent identifier
|
|
386
|
+
* @param message - The message to inject auth into
|
|
387
|
+
* @returns The message with authentication injected
|
|
388
|
+
*/
|
|
389
|
+
injectAuthentication(agentId: string, message: object): Promise<object>;
|
|
390
|
+
/**
|
|
391
|
+
* Inject mcpServers from registry into session/new request params.
|
|
392
|
+
*
|
|
393
|
+
* If the agent has mcpServers configured in the registry, they are merged
|
|
394
|
+
* with any mcpServers already present in the request params.
|
|
395
|
+
* Registry servers are added first, then request servers (request takes precedence for duplicates).
|
|
396
|
+
*
|
|
397
|
+
* @param message - The transformed message (without agentId)
|
|
398
|
+
* @param agentId - The agent ID to look up in registry
|
|
399
|
+
* @returns Message with mcpServers injected into params
|
|
400
|
+
*/
|
|
401
|
+
private injectMcpServers;
|
|
402
|
+
/**
|
|
403
|
+
* Route an incoming message to the appropriate agent.
|
|
404
|
+
*
|
|
405
|
+
* Extracts agentId, resolves spawn command, and forwards message.
|
|
406
|
+
* If OAuth authentication is pending for the agent, queues the request
|
|
407
|
+
* and resumes it after successful authentication (Task 21.3).
|
|
408
|
+
*
|
|
409
|
+
* Requirement 3.1: Queue incoming requests while OAuth flow is pending
|
|
410
|
+
* Requirement 11.2: Block requests when OAuth required but not authenticated
|
|
411
|
+
*
|
|
412
|
+
* @param message - The incoming JSON-RPC message
|
|
413
|
+
* @returns Error response if routing fails, undefined on success
|
|
414
|
+
*/
|
|
415
|
+
route(message: object): Promise<ErrorResponse | undefined>;
|
|
416
|
+
/**
|
|
417
|
+
* Check if OAuth credentials are available for an agent.
|
|
418
|
+
*
|
|
419
|
+
* Requirement 11.2: Check if credentials are available before routing.
|
|
420
|
+
*
|
|
421
|
+
* @param agentId - The agent identifier
|
|
422
|
+
* @param providerId - The OAuth provider ID
|
|
423
|
+
* @returns True if OAuth credentials are available
|
|
424
|
+
*/
|
|
425
|
+
private hasOAuthCredentialsForAgent;
|
|
426
|
+
/**
|
|
427
|
+
* Create an AUTH_REQUIRED error response with provider information.
|
|
428
|
+
*
|
|
429
|
+
* Requirement 11.2: WHEN an agent requires authentication and credentials are not available,
|
|
430
|
+
* THE Registry_Launcher SHALL return an AUTH_REQUIRED error response with the required
|
|
431
|
+
* authentication method specified.
|
|
432
|
+
*
|
|
433
|
+
* @param id - The request ID
|
|
434
|
+
* @param agentId - The agent identifier
|
|
435
|
+
* @param providerId - The required OAuth provider ID (optional)
|
|
436
|
+
* @returns AUTH_REQUIRED error response with requiredMethod, supportedMethods, providerId
|
|
437
|
+
*/
|
|
438
|
+
private createAuthRequiredErrorWithProvider;
|
|
439
|
+
/**
|
|
440
|
+
* Internal routing logic after auth state checks.
|
|
441
|
+
*
|
|
442
|
+
* @param message - The incoming JSON-RPC message
|
|
443
|
+
* @param agentId - The agent identifier
|
|
444
|
+
* @param id - The request ID
|
|
445
|
+
* @returns Error response if routing fails, undefined on success
|
|
446
|
+
*/
|
|
447
|
+
private routeInternal;
|
|
448
|
+
/**
|
|
449
|
+
* Get the current authentication state for an agent.
|
|
450
|
+
*
|
|
451
|
+
* @param agentId - The agent identifier
|
|
452
|
+
* @returns The current auth state (defaults to 'none')
|
|
453
|
+
*/
|
|
454
|
+
getAuthState(agentId: string): AuthState;
|
|
455
|
+
/**
|
|
456
|
+
* Set the authentication state for an agent.
|
|
457
|
+
*
|
|
458
|
+
* Handles state transitions and triggers appropriate actions:
|
|
459
|
+
* - none → pending: OAuth flow started
|
|
460
|
+
* - pending → authenticated: Resume queued requests
|
|
461
|
+
* - pending → failed: Reject queued requests with AUTH_REQUIRED
|
|
462
|
+
*
|
|
463
|
+
* Requirement 3.1: Track auth state during OAuth flow
|
|
464
|
+
* Requirement 3.5: Handle timeout transitions to failed state
|
|
465
|
+
*
|
|
466
|
+
* @param agentId - The agent identifier
|
|
467
|
+
* @param newState - The new auth state
|
|
468
|
+
*/
|
|
469
|
+
setAuthState(agentId: string, newState: AuthState): void;
|
|
470
|
+
/**
|
|
471
|
+
* Queue a request while OAuth authentication is pending.
|
|
472
|
+
*
|
|
473
|
+
* Returns a promise that resolves when the request is processed
|
|
474
|
+
* (either routed successfully or rejected with an error).
|
|
475
|
+
*
|
|
476
|
+
* Requirement 3.1: Queue incoming requests while OAuth flow is pending
|
|
477
|
+
*
|
|
478
|
+
* @param agentId - The agent identifier
|
|
479
|
+
* @param message - The message to queue
|
|
480
|
+
* @returns Promise that resolves with the routing result
|
|
481
|
+
*/
|
|
482
|
+
private queueRequest;
|
|
483
|
+
/**
|
|
484
|
+
* Handle timeout for a queued request.
|
|
485
|
+
*
|
|
486
|
+
* If the request is still in the queue when timeout fires,
|
|
487
|
+
* remove it and resolve with a timeout error.
|
|
488
|
+
*
|
|
489
|
+
* Requirement 3.5: Handle timeout for queued requests
|
|
490
|
+
*
|
|
491
|
+
* @param agentId - The agent identifier
|
|
492
|
+
* @param queuedRequest - The queued request that timed out
|
|
493
|
+
*/
|
|
494
|
+
private handleQueuedRequestTimeout;
|
|
495
|
+
/**
|
|
496
|
+
* Process queued requests after successful OAuth authentication.
|
|
497
|
+
*
|
|
498
|
+
* Routes all queued requests for the agent now that authentication
|
|
499
|
+
* is complete.
|
|
500
|
+
*
|
|
501
|
+
* Requirement 3.1: Resume queued requests after successful authentication
|
|
502
|
+
*
|
|
503
|
+
* @param agentId - The agent identifier
|
|
504
|
+
*/
|
|
505
|
+
private processQueuedRequests;
|
|
506
|
+
/**
|
|
507
|
+
* Reject all queued requests after OAuth authentication failure.
|
|
508
|
+
*
|
|
509
|
+
* Returns AUTH_REQUIRED error for all queued requests.
|
|
510
|
+
*
|
|
511
|
+
* Requirement 3.5: Handle failed authentication for queued requests
|
|
512
|
+
*
|
|
513
|
+
* @param agentId - The agent identifier
|
|
514
|
+
*/
|
|
515
|
+
private rejectQueuedRequests;
|
|
516
|
+
/**
|
|
517
|
+
* Get the number of queued requests for an agent.
|
|
518
|
+
*
|
|
519
|
+
* @param agentId - The agent identifier
|
|
520
|
+
* @returns The number of queued requests
|
|
521
|
+
*/
|
|
522
|
+
getQueuedRequestCount(agentId: string): number;
|
|
523
|
+
/**
|
|
524
|
+
* Get the total number of queued requests across all agents.
|
|
525
|
+
*
|
|
526
|
+
* @returns The total number of queued requests
|
|
527
|
+
*/
|
|
528
|
+
getTotalQueuedRequestCount(): number;
|
|
529
|
+
/**
|
|
530
|
+
* Handle a response from an agent process.
|
|
531
|
+
*
|
|
532
|
+
* Intercepts initialize responses to trigger automatic authentication and
|
|
533
|
+
* inject authMethods (Requirement 11.1).
|
|
534
|
+
* Handles agent-to-client requests (like session/request_permission) by
|
|
535
|
+
* auto-responding when they cannot be forwarded to the client.
|
|
536
|
+
* Tracks sessionId mapping for proper notification routing.
|
|
537
|
+
* Handles authenticate responses for Agent Auth flow (Task 35.2).
|
|
538
|
+
* Forwards all responses to stdout.
|
|
539
|
+
*
|
|
540
|
+
* @param agentId - The agent that sent the response
|
|
541
|
+
* @param response - The response object from the agent
|
|
542
|
+
*/
|
|
543
|
+
handleAgentResponse(agentId: string, response: object): void;
|
|
544
|
+
/**
|
|
545
|
+
* Handle a request from an agent to the client.
|
|
546
|
+
*
|
|
547
|
+
* Agent-to-client requests (JSON-RPC messages with both `id` and `method`)
|
|
548
|
+
* require a response. Since the Registry Launcher is headless and cannot
|
|
549
|
+
* forward these to a human, we auto-respond to keep the agent unblocked.
|
|
550
|
+
*
|
|
551
|
+
* Known methods:
|
|
552
|
+
* - session/request_permission: Auto-approve with the first "allow" option
|
|
553
|
+
*
|
|
554
|
+
* Unknown methods get a generic success response so the agent continues.
|
|
555
|
+
*
|
|
556
|
+
* @param agentId - The agent that sent the request
|
|
557
|
+
* @param id - The JSON-RPC request id
|
|
558
|
+
* @param method - The JSON-RPC method name
|
|
559
|
+
* @param msg - The full message object
|
|
560
|
+
*/
|
|
561
|
+
private handleAgentRequest;
|
|
562
|
+
/**
|
|
563
|
+
* Build an auto-approve result for session/request_permission.
|
|
564
|
+
*
|
|
565
|
+
* Picks the first "allow" option from the request, preferring
|
|
566
|
+
* allow_always > allow_once > first option as fallback.
|
|
567
|
+
*
|
|
568
|
+
* @param msg - The request_permission message
|
|
569
|
+
* @returns The result object for the response
|
|
570
|
+
*/
|
|
571
|
+
private buildPermissionResponse;
|
|
572
|
+
/**
|
|
573
|
+
* Handle an authenticate response from an agent.
|
|
574
|
+
*
|
|
575
|
+
* Task 35.2: Handle authenticate response
|
|
576
|
+
* - On success: resolve the pending authenticate request with success
|
|
577
|
+
* - On error: resolve with failure and log the error
|
|
578
|
+
*
|
|
579
|
+
* AUTH_REQUIREMENTS.md: Agent Auth - after agent completes OAuth flow,
|
|
580
|
+
* it responds to the authenticate request.
|
|
581
|
+
*
|
|
582
|
+
* @param pendingAuth - The pending authenticate request
|
|
583
|
+
* @param response - The response from the agent
|
|
584
|
+
*/
|
|
585
|
+
private handleAuthenticateResponse;
|
|
586
|
+
/**
|
|
587
|
+
* Send a JSON-RPC message directly to an agent process.
|
|
588
|
+
*
|
|
589
|
+
* @param agentId - The agent to send to
|
|
590
|
+
* @param message - The message to send
|
|
591
|
+
*/
|
|
592
|
+
private sendToAgent;
|
|
593
|
+
/**
|
|
594
|
+
* Attempt automatic authentication for an agent.
|
|
595
|
+
*
|
|
596
|
+
* Selects the best authentication method and initiates authentication.
|
|
597
|
+
* Uses parsed auth methods with validated types and provider IDs.
|
|
598
|
+
*
|
|
599
|
+
* Authentication method precedence (AUTH_REQUIREMENTS.md):
|
|
600
|
+
* 1. Agent Auth (type: "agent" or no type) - agent handles OAuth internally
|
|
601
|
+
* 2. OAuth methods (type: "oauth2") - client handles browser-based flow
|
|
602
|
+
* 3. API key methods - only if no OAuth methods are present
|
|
603
|
+
*
|
|
604
|
+
* AUTH_REQUIREMENTS.md: Agent Auth is the default authentication method
|
|
605
|
+
* where the agent manages the entire OAuth flow independently.
|
|
606
|
+
*
|
|
607
|
+
* @param agentId - The agent to authenticate
|
|
608
|
+
* @param authMethods - Parsed and validated authentication methods (Task 21.1)
|
|
609
|
+
*/
|
|
610
|
+
private attemptAuthentication;
|
|
611
|
+
/**
|
|
612
|
+
* Attempt Agent Auth authentication for an agent.
|
|
613
|
+
*
|
|
614
|
+
* AUTH_REQUIREMENTS.md: Agent Auth - client calls `authenticate` method on agent,
|
|
615
|
+
* agent handles: HTTP server, browser launch, OAuth callback, token storage.
|
|
616
|
+
*
|
|
617
|
+
* Task 35.1: Call `authenticate` JSON-RPC method on agent
|
|
618
|
+
* - Send: { jsonrpc: "2.0", method: "authenticate", params: { id: authMethod.id }, id: requestId }
|
|
619
|
+
* - Wait for response from agent
|
|
620
|
+
*
|
|
621
|
+
* Task 35.2: Handle authenticate response
|
|
622
|
+
* - On success: retry original request (session/new)
|
|
623
|
+
* - On error: return error to client
|
|
624
|
+
*
|
|
625
|
+
* @param agentId - The agent to authenticate
|
|
626
|
+
* @param agentAuthMethods - Agent Auth methods from agent's authMethods
|
|
627
|
+
*/
|
|
628
|
+
private attemptAgentAuthentication;
|
|
629
|
+
/**
|
|
630
|
+
* Call the `authenticate` JSON-RPC method on an agent.
|
|
631
|
+
*
|
|
632
|
+
* AUTH_REQUIREMENTS.md: Agent Auth - client calls authenticate method on agent
|
|
633
|
+
* Send: { jsonrpc: "2.0", method: "authenticate", params: { id: authMethod.id }, id: requestId }
|
|
634
|
+
*
|
|
635
|
+
* Task 35.1: Call `authenticate` JSON-RPC method on agent
|
|
636
|
+
*
|
|
637
|
+
* @param agentId - The agent to authenticate
|
|
638
|
+
* @param authMethodId - The auth method ID from authMethods
|
|
639
|
+
* @param runtime - The agent runtime
|
|
640
|
+
* @returns Promise that resolves to true on success, false on failure
|
|
641
|
+
*/
|
|
642
|
+
private callAgentAuthenticate;
|
|
643
|
+
/**
|
|
644
|
+
* Attempt Terminal Auth authentication for an agent.
|
|
645
|
+
*
|
|
646
|
+
* AUTH_REQUIREMENTS.md: Terminal Auth - client spawns agent binary with args/env
|
|
647
|
+
* from authMethod for interactive TUI setup.
|
|
648
|
+
*
|
|
649
|
+
* Task 36.1: Parse Terminal Auth from authMethods
|
|
650
|
+
* Task 36.2: Launch agent binary with args/env
|
|
651
|
+
* Task 36.3: Retry after Terminal Auth
|
|
652
|
+
*
|
|
653
|
+
* Flow:
|
|
654
|
+
* 1. Stop current agent runtime (if running)
|
|
655
|
+
* 2. Spawn agent with args/env from authMethod (stdio: 'inherit' for TUI)
|
|
656
|
+
* 3. Wait for process exit
|
|
657
|
+
* 4. On exit code 0: restart normal runtime and verify auth
|
|
658
|
+
* 5. On non-zero exit: mark as failed
|
|
659
|
+
*
|
|
660
|
+
* @param agentId - The agent to authenticate
|
|
661
|
+
* @param terminalAuthMethods - Terminal Auth methods from agent's authMethods
|
|
662
|
+
*/
|
|
663
|
+
private attemptTerminalAuthentication;
|
|
664
|
+
/**
|
|
665
|
+
* Run the Terminal Auth process with inherited stdio for interactive TUI.
|
|
666
|
+
*
|
|
667
|
+
* @param command - The command to execute
|
|
668
|
+
* @param args - Command-line arguments
|
|
669
|
+
* @param env - Environment variables
|
|
670
|
+
* @returns Promise that resolves to the exit code
|
|
671
|
+
*/
|
|
672
|
+
private runTerminalAuthProcess;
|
|
673
|
+
/**
|
|
674
|
+
* Verify that Terminal Auth was successful by restarting the agent
|
|
675
|
+
* and checking if authentication is now available.
|
|
676
|
+
*
|
|
677
|
+
* @param agentId - The agent to verify
|
|
678
|
+
* @returns true if auth is now available, false otherwise
|
|
679
|
+
*/
|
|
680
|
+
private verifyTerminalAuthSuccess;
|
|
681
|
+
/**
|
|
682
|
+
* Attempt OAuth authentication for an agent using browser-based flow.
|
|
683
|
+
*
|
|
684
|
+
* Requirement 3.1: WHEN an agent requires OAuth authentication with `type: "agent"`,
|
|
685
|
+
* THE Auth_Module SHALL initiate the OAuth 2.1 Authorization Code flow with PKCE.
|
|
686
|
+
*
|
|
687
|
+
* Requirement 3.2: WHEN initiating the authorization flow, THE Auth_Module SHALL
|
|
688
|
+
* open the system default browser to the provider's authorization URL.
|
|
689
|
+
*
|
|
690
|
+
* @param agentId - The agent to authenticate
|
|
691
|
+
* @param oauthMethods - OAuth methods from agent's authMethods (already validated)
|
|
692
|
+
*/
|
|
693
|
+
private attemptOAuthAuthentication;
|
|
694
|
+
/**
|
|
695
|
+
* Send OAuth credentials to agent after successful browser-based authentication.
|
|
696
|
+
*
|
|
697
|
+
* After the OAuth flow completes successfully, this method retrieves the token
|
|
698
|
+
* from AuthManager and sends an authenticate request to the agent.
|
|
699
|
+
*
|
|
700
|
+
* @param agentId - The agent to send credentials to
|
|
701
|
+
* @param method - The OAuth method used for authentication
|
|
702
|
+
*/
|
|
703
|
+
private sendOAuthCredentialsToAgent;
|
|
704
|
+
/**
|
|
705
|
+
* Attempt API key authentication for an agent.
|
|
706
|
+
*
|
|
707
|
+
* This is the fallback authentication method when no OAuth methods are present.
|
|
708
|
+
* Uses the legacy api-keys.json configuration.
|
|
709
|
+
*
|
|
710
|
+
* @param agentId - The agent to authenticate
|
|
711
|
+
* @param authMethods - Parsed authentication methods (already validated)
|
|
712
|
+
*/
|
|
713
|
+
private attemptApiKeyAuthentication;
|
|
714
|
+
/**
|
|
715
|
+
* Get the number of pending requests.
|
|
716
|
+
*
|
|
717
|
+
* @returns The count of pending requests
|
|
718
|
+
*/
|
|
719
|
+
get pendingCount(): number;
|
|
720
|
+
/**
|
|
721
|
+
* Check if a request ID is pending.
|
|
722
|
+
*
|
|
723
|
+
* @param id - The request ID to check
|
|
724
|
+
* @returns true if the request is pending, false otherwise
|
|
725
|
+
*/
|
|
726
|
+
isPending(id: string | number): boolean;
|
|
727
|
+
/**
|
|
728
|
+
* Clear all pending requests.
|
|
729
|
+
* Useful for cleanup during shutdown.
|
|
730
|
+
*/
|
|
731
|
+
clearPending(): void;
|
|
732
|
+
/**
|
|
733
|
+
* Clear all queued requests and auth state.
|
|
734
|
+
* Useful for cleanup during shutdown.
|
|
735
|
+
*
|
|
736
|
+
* Rejects all queued requests with a shutdown error.
|
|
737
|
+
*/
|
|
738
|
+
clearQueues(): void;
|
|
739
|
+
/**
|
|
740
|
+
* Reset auth state for an agent.
|
|
741
|
+
* Useful for retry scenarios or logout.
|
|
742
|
+
*
|
|
743
|
+
* @param agentId - The agent identifier
|
|
744
|
+
*/
|
|
745
|
+
resetAuthState(agentId: string): void;
|
|
746
|
+
/**
|
|
747
|
+
* Get the OAuth requirement for an agent.
|
|
748
|
+
*
|
|
749
|
+
* Requirement 11.2: Check agent auth requirements.
|
|
750
|
+
*
|
|
751
|
+
* @param agentId - The agent identifier
|
|
752
|
+
* @returns The required OAuth provider ID, or undefined if no OAuth required
|
|
753
|
+
*/
|
|
754
|
+
getAgentOAuthRequirement(agentId: string): AuthProviderId | undefined;
|
|
755
|
+
/**
|
|
756
|
+
* Set the OAuth requirement for an agent.
|
|
757
|
+
*
|
|
758
|
+
* Requirement 11.2: Cache auth requirements per agent.
|
|
759
|
+
*
|
|
760
|
+
* @param agentId - The agent identifier
|
|
761
|
+
* @param providerId - The required OAuth provider ID
|
|
762
|
+
*/
|
|
763
|
+
setAgentOAuthRequirement(agentId: string, providerId: AuthProviderId): void;
|
|
764
|
+
/**
|
|
765
|
+
* Clear the OAuth requirement for an agent.
|
|
766
|
+
*
|
|
767
|
+
* @param agentId - The agent identifier
|
|
768
|
+
*/
|
|
769
|
+
clearAgentOAuthRequirement(agentId: string): void;
|
|
770
|
+
}
|