@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.
Files changed (129) hide show
  1. package/README.md +181 -21
  2. package/out/dist/workers-registry/acp-registry/index.js +128 -2
  3. package/out/dist/workers-registry/acp-registry/index.js.map +4 -4
  4. package/out/dist/workers-registry/acp-worker/index.js +1 -3
  5. package/out/dist/workers-registry/acp-worker/index.js.map +4 -4
  6. package/out/dist/workers-registry/index.d.ts +1 -0
  7. package/out/dist/workers-registry/index.js +6 -0
  8. package/out/dist/workers-registry/openai-agent/index.js +1 -1
  9. package/out/dist/workers-registry/openai-agent/index.js.map +2 -2
  10. package/out/dist/workers-registry/registry-launcher/index.js +131 -0
  11. package/out/dist/workers-registry/registry-launcher/index.js.map +7 -0
  12. package/out/tsc/workers-registry/acp-worker/src/index.d.ts +0 -10
  13. package/out/tsc/workers-registry/registry-launcher/src/auth/auth-manager.d.ts +392 -0
  14. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/cli.property.test.d.ts +22 -0
  15. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/index.d.ts +9 -0
  16. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/login-command.d.ts +32 -0
  17. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/logout-command.d.ts +25 -0
  18. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/setup-command.d.ts +25 -0
  19. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/status-command.d.ts +21 -0
  20. package/out/tsc/workers-registry/registry-launcher/src/auth/errors.d.ts +190 -0
  21. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/agent-auth-flow.d.ts +146 -0
  22. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/callback-server.d.ts +131 -0
  23. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/callback-server.test.d.ts +1 -0
  24. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/index.d.ts +11 -0
  25. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/terminal-auth-flow.d.ts +252 -0
  26. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/terminal-auth-flow.test.d.ts +1 -0
  27. package/out/tsc/workers-registry/registry-launcher/src/auth/index.d.ts +33 -0
  28. package/out/tsc/workers-registry/registry-launcher/src/auth/integration.test.d.ts +1 -0
  29. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/anthropic-api-key.d.ts +154 -0
  30. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/index.d.ts +20 -0
  31. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/model-credentials.test.d.ts +1 -0
  32. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/openai-api-key.d.ts +182 -0
  33. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/types.d.ts +186 -0
  34. package/out/tsc/workers-registry/registry-launcher/src/auth/pkce.d.ts +61 -0
  35. package/out/tsc/workers-registry/registry-launcher/src/auth/pkce.property.test.d.ts +1 -0
  36. package/out/tsc/workers-registry/registry-launcher/src/auth/pkce.test.d.ts +1 -0
  37. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/base-provider.d.ts +138 -0
  38. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/base-provider.test.d.ts +1 -0
  39. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/cognito-provider.d.ts +44 -0
  40. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/concrete-providers.test.d.ts +1 -0
  41. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/entra-provider.d.ts +54 -0
  42. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/github-provider.d.ts +19 -0
  43. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/google-provider.d.ts +19 -0
  44. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/index.d.ts +107 -0
  45. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/index.test.d.ts +1 -0
  46. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/oidc-provider.d.ts +413 -0
  47. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/oidc-provider.property.test.d.ts +1 -0
  48. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/oidc-provider.test.d.ts +1 -0
  49. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/providers.property.test.d.ts +1 -0
  50. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/types.d.ts +28 -0
  51. package/out/tsc/workers-registry/registry-launcher/src/auth/session.d.ts +251 -0
  52. package/out/tsc/workers-registry/registry-launcher/src/auth/session.property.test.d.ts +1 -0
  53. package/out/tsc/workers-registry/registry-launcher/src/auth/session.test.d.ts +1 -0
  54. package/out/tsc/workers-registry/registry-launcher/src/auth/state.d.ts +26 -0
  55. package/out/tsc/workers-registry/registry-launcher/src/auth/state.property.test.d.ts +1 -0
  56. package/out/tsc/workers-registry/registry-launcher/src/auth/state.test.d.ts +1 -0
  57. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/credential-store.d.ts +98 -0
  58. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/credential-store.test.d.ts +1 -0
  59. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/encrypted-file-backend.d.ts +101 -0
  60. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/encrypted-file-backend.test.d.ts +1 -0
  61. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/index.d.ts +12 -0
  62. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/keychain-backend.d.ts +80 -0
  63. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/keychain-backend.test.d.ts +1 -0
  64. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/memory-backend.d.ts +54 -0
  65. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/storage.property.test.d.ts +1 -0
  66. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/types.d.ts +44 -0
  67. package/out/tsc/workers-registry/registry-launcher/src/auth/token-manager.d.ts +171 -0
  68. package/out/tsc/workers-registry/registry-launcher/src/auth/token-manager.property.test.d.ts +1 -0
  69. package/out/tsc/workers-registry/registry-launcher/src/auth/token-manager.test.d.ts +1 -0
  70. package/out/tsc/workers-registry/registry-launcher/src/auth/types.d.ts +369 -0
  71. package/out/tsc/workers-registry/registry-launcher/src/auth/types.test.d.ts +1 -0
  72. package/out/tsc/workers-registry/registry-launcher/src/config/config.property.test.d.ts +1 -0
  73. package/out/tsc/workers-registry/registry-launcher/src/config/config.test.d.ts +1 -0
  74. package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/registry/index.d.ts +51 -2
  75. package/out/tsc/workers-registry/registry-launcher/src/registry/index.property.test.d.ts +1 -0
  76. package/out/tsc/workers-registry/registry-launcher/src/registry/index.test.d.ts +1 -0
  77. package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/registry/types.d.ts +24 -0
  78. package/out/tsc/workers-registry/registry-launcher/src/router/message-router.d.ts +770 -0
  79. package/out/tsc/workers-registry/registry-launcher/src/router/message-router.property.test.d.ts +1 -0
  80. package/out/tsc/workers-registry/registry-launcher/src/router/message-router.test.d.ts +1 -0
  81. package/out/tsc/workers-registry/registry-launcher/src/runtime/manager.property.test.d.ts +1 -0
  82. package/out/tsc/workers-registry/registry-launcher/src/runtime/manager.test.d.ts +1 -0
  83. package/out/tsc/workers-registry/registry-launcher/src/stream/ndjson-handler.property.test.d.ts +1 -0
  84. package/out/tsc/workers-registry/registry-launcher/src/stream/ndjson-handler.test.d.ts +1 -0
  85. package/out/tsc/workers-registry/registry-launcher/tests/e2e/auth-flow.e2e.test.d.ts +1 -0
  86. package/out/tsc/workers-registry/registry-launcher/tests/e2e/auth-required-flow.e2e.test.d.ts +1 -0
  87. package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/api-keys.d.ts +32 -0
  88. package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/index.d.ts +17 -0
  89. package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/launcher-harness.d.ts +101 -0
  90. package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/registry-server.d.ts +46 -0
  91. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-agent-auth.e2e.test.d.ts +1 -0
  92. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-api-keys.e2e.test.d.ts +1 -0
  93. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-auth-required.e2e.test.d.ts +1 -0
  94. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-cli.e2e.test.d.ts +1 -0
  95. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-concurrent.e2e.test.d.ts +1 -0
  96. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-lifecycle.e2e.test.d.ts +1 -0
  97. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-terminal-auth.e2e.test.d.ts +1 -0
  98. package/out/tsc/workers-registry/registry-launcher/tests/integration/agent-auth.integration.test.d.ts +9 -0
  99. package/out/tsc/workers-registry/registry-launcher/tests/integration/registry-launcher.test.d.ts +1 -0
  100. package/out/tsc/workers-registry/registry-launcher/tests/integration/terminal-auth.integration.test.d.ts +12 -0
  101. package/package.json +16 -11
  102. package/out/tsc/workers-registry/acp-worker/src/registry-launcher/router/message-router.d.ts +0 -199
  103. /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
  104. /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
  105. /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
  106. /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
  107. /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
  108. /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
  109. /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
  110. /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
  111. /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
  112. /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
  113. /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
  114. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/api-keys.d.ts +0 -0
  115. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/config.d.ts +0 -0
  116. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/index.d.ts +0 -0
  117. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/types.d.ts +0 -0
  118. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/index.d.ts +0 -0
  119. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/log.d.ts +0 -0
  120. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/log.test.d.ts +0 -0
  121. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/registry/resolver.d.ts +0 -0
  122. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/router/index.d.ts +0 -0
  123. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/agent-runtime.d.ts +0 -0
  124. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/index.d.ts +0 -0
  125. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/manager.d.ts +0 -0
  126. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/types.d.ts +0 -0
  127. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/stream/index.d.ts +0 -0
  128. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/stream/ndjson-handler.d.ts +0 -0
  129. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/test-utils/index.d.ts +0 -0
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Error handling module for OAuth 2.1 authentication.
3
+ *
4
+ * Provides error classes for each AuthErrorCode, provider error response parsing,
5
+ * and error response formatting that excludes sensitive data.
6
+ *
7
+ * Requirements: 13.1, 13.2, 13.3, 13.4, 13.5
8
+ *
9
+ * @module errors
10
+ */
11
+ import type { AuthErrorCode, AuthError, AuthProviderId } from './types.js';
12
+ /**
13
+ * Redact sensitive data from a string.
14
+ *
15
+ * @param text - The text to redact
16
+ * @returns The text with sensitive data replaced with [REDACTED]
17
+ */
18
+ export declare function redactSensitiveData(text: string): string;
19
+ /**
20
+ * Base error class for authentication errors.
21
+ *
22
+ * Provides a structured error with code, message, and optional details.
23
+ * Ensures sensitive data is never included in error messages.
24
+ */
25
+ export declare class AuthenticationError extends Error {
26
+ readonly code: AuthErrorCode;
27
+ readonly details?: Record<string, unknown>;
28
+ /**
29
+ * Create a new AuthenticationError.
30
+ *
31
+ * @param code - The error code
32
+ * @param message - The error message (will be redacted for sensitive data)
33
+ * @param details - Optional additional details (will be sanitized)
34
+ */
35
+ constructor(code: AuthErrorCode, message: string, details?: Record<string, unknown>);
36
+ /**
37
+ * Convert to AuthError interface.
38
+ */
39
+ toAuthError(): AuthError;
40
+ }
41
+ /**
42
+ * Error thrown when state parameter validation fails.
43
+ *
44
+ * Requirement 13.1: Parse error and return descriptive message
45
+ */
46
+ export declare class InvalidStateError extends AuthenticationError {
47
+ constructor(message?: string);
48
+ }
49
+ /**
50
+ * Error thrown when an operation times out.
51
+ *
52
+ * Requirement 13.1: Parse error and return descriptive message
53
+ */
54
+ export declare class TimeoutError extends AuthenticationError {
55
+ constructor(message?: string, details?: {
56
+ timeoutMs?: number;
57
+ });
58
+ }
59
+ /**
60
+ * Error thrown when a network error occurs.
61
+ *
62
+ * Requirement 13.2: Return error indicating network failure and affected endpoint
63
+ */
64
+ export declare class NetworkError extends AuthenticationError {
65
+ constructor(message: string, endpoint?: string);
66
+ }
67
+ /**
68
+ * Error thrown when credentials are invalid.
69
+ *
70
+ * Requirement 13.1: Parse error and return descriptive message
71
+ */
72
+ export declare class InvalidCredentialsError extends AuthenticationError {
73
+ constructor(message?: string);
74
+ }
75
+ /**
76
+ * Error thrown when credential storage fails.
77
+ *
78
+ * Requirement 13.3: Return error indicating storage backend and failure reason
79
+ */
80
+ export declare class StorageError extends AuthenticationError {
81
+ constructor(message: string, backend?: string);
82
+ }
83
+ /**
84
+ * Error thrown when an OAuth provider returns an error.
85
+ *
86
+ * Requirement 13.1: Parse error and return descriptive message including error code and description
87
+ */
88
+ export declare class ProviderError extends AuthenticationError {
89
+ constructor(message: string, details?: {
90
+ errorCode?: string;
91
+ errorDescription?: string;
92
+ providerId?: AuthProviderId;
93
+ });
94
+ }
95
+ /**
96
+ * Error thrown when an unsupported provider is specified.
97
+ *
98
+ * Requirement 13.4: Return error listing supported providers
99
+ */
100
+ export declare class UnsupportedProviderError extends AuthenticationError {
101
+ constructor(providerId: string);
102
+ }
103
+ /**
104
+ * Error thrown when the callback server encounters an error.
105
+ *
106
+ * Requirement 13.1: Parse error and return descriptive message
107
+ */
108
+ export declare class CallbackError extends AuthenticationError {
109
+ constructor(message: string, details?: Record<string, unknown>);
110
+ }
111
+ /**
112
+ * Error thrown when token refresh fails.
113
+ *
114
+ * Requirement 13.1: Parse error and return descriptive message
115
+ */
116
+ export declare class TokenRefreshError extends AuthenticationError {
117
+ constructor(message?: string, providerId?: AuthProviderId);
118
+ }
119
+ /**
120
+ * Standard OAuth 2.0 error response structure.
121
+ */
122
+ export interface OAuthErrorResponse {
123
+ error: string;
124
+ error_description?: string;
125
+ error_uri?: string;
126
+ }
127
+ /**
128
+ * Check if an object is an OAuth error response.
129
+ *
130
+ * @param obj - The object to check
131
+ * @returns True if the object is an OAuth error response
132
+ */
133
+ export declare function isOAuthErrorResponse(obj: unknown): obj is OAuthErrorResponse;
134
+ /**
135
+ * Parse an OAuth provider error response into an AuthError.
136
+ *
137
+ * Requirement 13.1: Parse error and return descriptive message including error code and description
138
+ *
139
+ * @param response - The error response from the provider
140
+ * @param providerId - The provider that returned the error
141
+ * @returns A structured AuthError
142
+ */
143
+ export declare function parseProviderErrorResponse(response: unknown, providerId?: AuthProviderId): AuthError;
144
+ /**
145
+ * Parse an HTTP error response from a provider.
146
+ *
147
+ * @param status - The HTTP status code
148
+ * @param body - The response body (string or object)
149
+ * @param providerId - The provider that returned the error
150
+ * @returns A structured AuthError
151
+ */
152
+ export declare function parseHttpErrorResponse(status: number, body: unknown, providerId?: AuthProviderId): AuthError;
153
+ /**
154
+ * Format an error for response, ensuring no sensitive data is exposed.
155
+ *
156
+ * Requirement 13.5: Never include sensitive information in error messages
157
+ *
158
+ * @param error - The error to format
159
+ * @returns A formatted AuthError safe for response
160
+ */
161
+ export declare function formatErrorResponse(error: unknown): AuthError;
162
+ /**
163
+ * Create an error for an unsupported provider.
164
+ *
165
+ * Requirement 13.4: Return error listing supported providers
166
+ *
167
+ * @param providerId - The unsupported provider ID
168
+ * @returns An AuthError with supported providers listed
169
+ */
170
+ export declare function createUnsupportedProviderError(providerId: string): AuthError;
171
+ /**
172
+ * Create an error for a network failure.
173
+ *
174
+ * Requirement 13.2: Return error indicating network failure and affected endpoint
175
+ *
176
+ * @param message - The error message
177
+ * @param endpoint - The affected endpoint
178
+ * @returns An AuthError with endpoint information
179
+ */
180
+ export declare function createNetworkError(message: string, endpoint?: string): AuthError;
181
+ /**
182
+ * Create an error for storage failure.
183
+ *
184
+ * Requirement 13.3: Return error indicating storage backend and failure reason
185
+ *
186
+ * @param message - The error message
187
+ * @param backend - The storage backend that failed
188
+ * @returns An AuthError with backend information
189
+ */
190
+ export declare function createStorageError(message: string, backend?: string): AuthError;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Browser-based OAuth 2.1 Authorization Code flow with PKCE.
3
+ *
4
+ * Orchestrates the complete agent authentication flow:
5
+ * 1. Generate PKCE code verifier and challenge
6
+ * 2. Generate state parameter for CSRF protection
7
+ * 3. Start the callback server on loopback address
8
+ * 4. Build the authorization URL with all required parameters
9
+ * 5. Launch the system default browser to the authorization URL
10
+ * 6. Wait for the callback with the authorization code
11
+ * 7. Validate the state parameter
12
+ * 8. Exchange the authorization code for tokens
13
+ * 9. Return the authentication result
14
+ *
15
+ * Requirements: 3.1, 3.2, 3.3, 3.4
16
+ *
17
+ * @module flows/agent-auth-flow
18
+ */
19
+ import type { AuthProviderId, AuthResult, AgentAuthOptions, TokenResponse } from '../types.js';
20
+ import type { IAuthProvider } from '../providers/types.js';
21
+ /**
22
+ * Default timeout for the agent auth flow in milliseconds (5 minutes).
23
+ */
24
+ export declare const DEFAULT_AUTH_TIMEOUT_MS: number;
25
+ /**
26
+ * Detect if the current environment is headless (no display/browser available).
27
+ *
28
+ * A headless environment is detected when any of the following conditions are true:
29
+ * 1. CI environment variables are set (CI, GITHUB_ACTIONS, GITLAB_CI, JENKINS, etc.)
30
+ * 2. HEADLESS environment variable is set to a truthy value
31
+ * 3. SSH_TTY environment variable is set (indicates SSH session without display)
32
+ * 4. stdout or stderr are not TTY (indicates non-interactive environment)
33
+ *
34
+ * This detection is used to prevent browser launch in environments where
35
+ * it would fail or be inappropriate (CI pipelines, SSH sessions, etc.).
36
+ *
37
+ * Requirements: 3.1, 4.1
38
+ *
39
+ * @returns true if running in a headless environment, false otherwise
40
+ */
41
+ export declare function isHeadlessEnvironment(): boolean;
42
+ /**
43
+ * Dependencies for the agent auth flow.
44
+ */
45
+ export interface AgentAuthFlowDependencies {
46
+ /** Function to get a provider by ID */
47
+ getProvider: (providerId: AuthProviderId) => IAuthProvider;
48
+ /** Function to store tokens after successful authentication */
49
+ storeTokens: (providerId: AuthProviderId, tokens: TokenResponse) => Promise<void>;
50
+ /** Optional custom browser launcher (for testing) */
51
+ launchBrowser?: (url: string) => Promise<void>;
52
+ }
53
+ /**
54
+ * Agent auth flow - browser-based OAuth 2.1 Authorization Code flow with PKCE.
55
+ *
56
+ * This class orchestrates the complete OAuth 2.1 agent authentication flow,
57
+ * handling PKCE generation, browser launch, callback handling, and token exchange.
58
+ */
59
+ export declare class AgentAuthFlow {
60
+ private readonly getProvider;
61
+ private readonly storeTokens;
62
+ private readonly launchBrowser;
63
+ /**
64
+ * Create a new agent auth flow.
65
+ *
66
+ * @param dependencies - Flow dependencies including provider resolver and token storage
67
+ */
68
+ constructor(dependencies: AgentAuthFlowDependencies);
69
+ /**
70
+ * Execute the agent auth flow.
71
+ *
72
+ * Performs the complete OAuth 2.1 Authorization Code flow with PKCE:
73
+ * 1. Checks for headless environment (fails fast if detected)
74
+ * 2. Creates an auth session with PKCE and state parameters
75
+ * 3. Starts a callback server on loopback address
76
+ * 4. Builds and opens the authorization URL in the system browser
77
+ * 5. Waits for the OAuth callback
78
+ * 6. Validates the state parameter
79
+ * 7. Exchanges the authorization code for tokens
80
+ * 8. Stores the tokens and returns the result
81
+ *
82
+ * @param providerId - The provider to authenticate with
83
+ * @param options - Optional flow configuration
84
+ * @returns Authentication result indicating success or failure
85
+ */
86
+ execute(providerId: AuthProviderId, options?: AgentAuthOptions): Promise<AuthResult>;
87
+ /**
88
+ * Validate provider configuration before starting OAuth flow.
89
+ *
90
+ * Checks:
91
+ * - Client ID is present and valid
92
+ * - Provider endpoints are HTTPS (via provider.validateConfig())
93
+ * - Provider supports PKCE with S256
94
+ *
95
+ * @param providerId - The provider identifier
96
+ * @param provider - The provider instance
97
+ * @param clientId - The client ID to validate
98
+ * @returns Validation result with error details if invalid
99
+ */
100
+ private validateProviderConfig;
101
+ /**
102
+ * Get the default client ID for a provider.
103
+ *
104
+ * This is a placeholder that should be overridden with actual client IDs
105
+ * from configuration or environment variables.
106
+ *
107
+ * @param providerId - The provider identifier
108
+ * @returns The default client ID for the provider
109
+ */
110
+ private getDefaultClientId;
111
+ }
112
+ /**
113
+ * Redact sensitive parameters from a URL for safe logging.
114
+ *
115
+ * @param url - The URL to redact
116
+ * @returns URL string with sensitive parameters replaced with [REDACTED]
117
+ */
118
+ export declare function redactUrlForLogging(url: string): string;
119
+ /**
120
+ * Open a URL in the system default browser.
121
+ *
122
+ * Uses platform-specific commands to launch the browser:
123
+ * - macOS: `open`
124
+ * - Windows: `start`
125
+ * - Linux: `xdg-open`
126
+ *
127
+ * Security measures:
128
+ * - Uses execFile with argument arrays to prevent command injection
129
+ * - Validates URL is HTTPS only (OAuth authorization URLs must use HTTPS)
130
+ * - Disallows userinfo (username:password) in URL
131
+ * - Validates no control characters in URL (checked before URL parsing)
132
+ * - Logs redacted URL for security
133
+ *
134
+ * Requirements: 3.6, 8.1
135
+ *
136
+ * @param url - The URL to open
137
+ * @throws Error if the browser cannot be launched or URL is invalid
138
+ */
139
+ export declare function openSystemBrowser(url: string): Promise<void>;
140
+ /**
141
+ * Create an agent auth flow with the given dependencies.
142
+ *
143
+ * @param dependencies - Flow dependencies
144
+ * @returns A new AgentAuthFlow instance
145
+ */
146
+ export declare function createAgentAuthFlow(dependencies: AgentAuthFlowDependencies): AgentAuthFlow;
@@ -0,0 +1,131 @@
1
+ import type { CallbackResult } from '../types.js';
2
+ /**
3
+ * Loopback HTTP server for OAuth callbacks.
4
+ */
5
+ export interface ICallbackServer {
6
+ /** Start the server and return the redirect URI */
7
+ start(): Promise<string>;
8
+ /** Wait for the authorization callback */
9
+ waitForCallback(timeoutMs: number): Promise<CallbackResult>;
10
+ /** Stop the server and clean up resources */
11
+ stop(): Promise<void>;
12
+ /** Get the current server port (0 if not started) */
13
+ getPort(): number;
14
+ /** Check if server is running */
15
+ isRunning(): boolean;
16
+ }
17
+ /**
18
+ * Check if an address is a loopback address.
19
+ * Supports both IPv4 (127.x.x.x) and IPv6 (::1) loopback addresses.
20
+ *
21
+ * @param address - The IP address to check
22
+ * @returns True if the address is a loopback address
23
+ */
24
+ export declare function isLoopbackAddress(address: string | undefined): boolean;
25
+ /**
26
+ * Validate the Host header against allowed loopback hosts.
27
+ * Prevents DNS rebinding and host confusion attacks.
28
+ *
29
+ * @param hostHeader - The Host header value from the request
30
+ * @param expectedPort - The expected port number
31
+ * @returns True if the Host header is valid
32
+ */
33
+ export declare function isValidHostHeader(hostHeader: string | undefined, expectedPort: number): boolean;
34
+ /**
35
+ * Callback server implementation.
36
+ * Creates an HTTP server on a loopback address with dynamic port allocation
37
+ * to receive OAuth authorization callbacks.
38
+ *
39
+ * @implements {ICallbackServer}
40
+ */
41
+ export declare class CallbackServer implements ICallbackServer {
42
+ private server;
43
+ private port;
44
+ private running;
45
+ private callbackPath;
46
+ private callbackPromise;
47
+ private callbackResolve;
48
+ private callbackReject;
49
+ private timeoutId;
50
+ private callbackHandled;
51
+ /** Minimum timeout in milliseconds (1 second) */
52
+ private static readonly MIN_TIMEOUT_MS;
53
+ /** Maximum timeout in milliseconds (10 minutes) */
54
+ private static readonly MAX_TIMEOUT_MS;
55
+ /**
56
+ * Creates a new CallbackServer instance.
57
+ * @param callbackPath - The path to listen for callbacks (default: '/callback')
58
+ */
59
+ constructor(callbackPath?: string);
60
+ /**
61
+ * Start the server and return the redirect URI.
62
+ * The server binds to a loopback address (127.0.0.1) with a dynamically allocated port.
63
+ *
64
+ * @returns The redirect URI to use for OAuth callbacks
65
+ * @throws Error if the server is already running or fails to start
66
+ */
67
+ start(): Promise<string>;
68
+ /**
69
+ * Wait for the authorization callback.
70
+ * Returns when a callback is received or the timeout is reached.
71
+ *
72
+ * @param timeoutMs - Maximum time to wait for the callback in milliseconds
73
+ * @returns The callback result containing the authorization code and state
74
+ * @throws Error if the server is not running, timeout is reached, or callback fails
75
+ */
76
+ waitForCallback(timeoutMs: number): Promise<CallbackResult>;
77
+ /**
78
+ * Stop the server and clean up resources.
79
+ */
80
+ stop(): Promise<void>;
81
+ /**
82
+ * Get the current server port.
83
+ * @returns The port number, or 0 if the server is not started
84
+ */
85
+ getPort(): number;
86
+ /**
87
+ * Check if the server is running.
88
+ * @returns True if the server is running
89
+ */
90
+ isRunning(): boolean;
91
+ /**
92
+ * Handle incoming HTTP requests.
93
+ * Parses the callback URL and extracts the authorization code and state.
94
+ * Rejects connections from non-loopback addresses for security.
95
+ */
96
+ private handleRequest;
97
+ /**
98
+ * Send an error response with security headers.
99
+ */
100
+ private sendErrorResponse;
101
+ /**
102
+ * Send an HTML response with security headers.
103
+ */
104
+ private sendHtmlResponse;
105
+ /**
106
+ * Stop accepting new connections without fully closing the server.
107
+ * This ensures the server stops accepting new requests after processing the callback
108
+ * while allowing the current response to complete.
109
+ *
110
+ * @remarks
111
+ * This implements Requirement 8.3: The Callback_Server SHALL immediately close
112
+ * after processing the single expected request.
113
+ */
114
+ private stopAcceptingConnections;
115
+ /**
116
+ * Clean up timeout and callback state.
117
+ */
118
+ private cleanup;
119
+ /**
120
+ * Build a success HTML page to display in the browser.
121
+ */
122
+ private buildSuccessPage;
123
+ /**
124
+ * Build an error HTML page to display in the browser.
125
+ */
126
+ private buildErrorPage;
127
+ /**
128
+ * Escape HTML special characters to prevent XSS.
129
+ */
130
+ private escapeHtml;
131
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Authentication flow exports.
3
+ *
4
+ * @module flows
5
+ */
6
+ export type { ICallbackServer } from './callback-server.js';
7
+ export { CallbackServer } from './callback-server.js';
8
+ export { AgentAuthFlow, createAgentAuthFlow, openSystemBrowser, isHeadlessEnvironment, DEFAULT_AUTH_TIMEOUT_MS, } from './agent-auth-flow.js';
9
+ export type { AgentAuthFlowDependencies } from './agent-auth-flow.js';
10
+ export { TerminalAuthFlow, createTerminalAuthFlow, getProviderInfo, getAllProviderInfo, } from './terminal-auth-flow.js';
11
+ export type { TerminalAuthFlowDependencies, CollectedCredentials, } from './terminal-auth-flow.js';