@kodax-ai/kodax 0.7.63 → 0.7.67

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 (84) hide show
  1. package/CHANGELOG.md +2390 -2189
  2. package/README.md +118 -16
  3. package/README_CN.md +78 -12
  4. package/dist/chunks/{agent-SL444XLN.js → agent-E4V5SLX6.js} +1 -1
  5. package/dist/chunks/argument-completer-N6RT5KYT.js +2 -0
  6. package/dist/chunks/{chunk-ARUWXX25.js → chunk-35P7QL2Q.js} +1 -1
  7. package/dist/chunks/chunk-AKMXJSGM.js +56 -0
  8. package/dist/chunks/{chunk-L3MF5V64.js → chunk-CW32NQFO.js} +1 -1
  9. package/dist/chunks/{chunk-KCFVGXVK.js → chunk-DEICMTHO.js} +9 -9
  10. package/dist/chunks/{chunk-7MPU7TP6.js → chunk-EN3O2C43.js} +270 -270
  11. package/dist/chunks/chunk-KBBGDRER.js +22 -0
  12. package/dist/chunks/chunk-NVDK375I.js +729 -0
  13. package/dist/chunks/{chunk-S4GVQO3W.js → chunk-O7N22GJ3.js} +1 -1
  14. package/dist/chunks/chunk-ONUPGMER.js +2 -0
  15. package/dist/chunks/{chunk-ZL5CEANW.js → chunk-PZTG2C33.js} +1 -1
  16. package/dist/chunks/chunk-QI6SQ2UQ.js +306 -0
  17. package/dist/chunks/{chunk-6OZ5KWG3.js → chunk-QJJKMNZF.js} +1 -1
  18. package/dist/chunks/chunk-RS2GAABJ.js +328 -0
  19. package/dist/chunks/chunk-W2XMNYLK.js +15 -0
  20. package/dist/chunks/chunk-WCSSXBHR.js +419 -0
  21. package/dist/chunks/chunk-YH5BTUQO.js +343 -0
  22. package/dist/chunks/{chunk-UA744TZM.js → chunk-YRBNXFHY.js} +1 -1
  23. package/dist/chunks/compaction-config-56NO42ZI.js +2 -0
  24. package/dist/chunks/{construction-bootstrap-EFZBONTK.js → construction-bootstrap-GLEHQ2KB.js} +1 -1
  25. package/dist/chunks/{devtools-4CRULTR2.js → devtools-CD6KSIHE.js} +1 -1
  26. package/dist/chunks/{devtools-YINBSZC7.js → devtools-XR5F2C6T.js} +1 -1
  27. package/dist/chunks/{dist-73L4OYPD.js → dist-4PXB7U22.js} +1 -1
  28. package/dist/chunks/dist-4UIRSSFS.js +2 -0
  29. package/dist/chunks/host-DMREFNSO.js +2 -0
  30. package/dist/chunks/{paste-FDYM7SZX.js → paste-C33GZQV5.js} +1 -1
  31. package/dist/chunks/run-manager-P5XMSGZ7.js +2 -0
  32. package/dist/chunks/utils-JENPFKAE.js +2 -0
  33. package/dist/constructed-handler-worker.js +2 -0
  34. package/dist/index.d.ts +25 -11
  35. package/dist/index.js +6 -6
  36. package/dist/kodax_cli.js +1282 -1232
  37. package/dist/runtime-worker.js +2872 -0
  38. package/dist/sdk-agent.d.ts +46 -10
  39. package/dist/sdk-agent.js +1 -1
  40. package/dist/sdk-coding.d.ts +337 -1020
  41. package/dist/sdk-coding.js +1 -1
  42. package/dist/sdk-llm.js +1 -1
  43. package/dist/sdk-mcp.d.ts +2 -1
  44. package/dist/sdk-mcp.js +1 -1
  45. package/dist/sdk-media.js +1 -1
  46. package/dist/sdk-repl.d.ts +208 -185
  47. package/dist/sdk-repl.js +2 -2
  48. package/dist/sdk-runtime.d.ts +1070 -0
  49. package/dist/sdk-runtime.js +2 -0
  50. package/dist/sdk-session.d.ts +4 -4
  51. package/dist/sdk-session.js +1 -1
  52. package/dist/sdk-skills.js +1 -1
  53. package/dist/semantic-worker.js +191 -10
  54. package/dist/types-chunks/{bash-prefix-extractor.d-CZW9fRoa.d.ts → bash-prefix-extractor.d-D57Gt6n8.d.ts} +186 -12
  55. package/dist/types-chunks/{run-manager.d-CYTnWhZY.d.ts → capsule.d-BZmqu_HL.d.ts} +5 -92
  56. package/dist/types-chunks/commands.d-Cg26ud-Y.d.ts +213 -0
  57. package/dist/types-chunks/{types.d-1CnTg7Sd.d.ts → guardrail.d-Ds7JHxR1.d.ts} +3 -128
  58. package/dist/types-chunks/{guardrail.d-MR6LwMB2.d.ts → guardrail.d-vSaBe64I.d.ts} +3 -3
  59. package/dist/types-chunks/{manager.d-DBD7SOTT.d.ts → manager.d-Zum9cGHU.d.ts} +3 -173
  60. package/dist/types-chunks/oauth-login.d-Bgb4rdLN.d.ts +174 -0
  61. package/dist/types-chunks/public-api.d-CPBMPDiU.d.ts +602 -0
  62. package/dist/types-chunks/run-manager.d-lnwnfyNC.d.ts +91 -0
  63. package/dist/types-chunks/{sdk-session-RBSBBKol.d.ts → sdk-session-ByoMLoUS.d.ts} +8 -306
  64. package/dist/types-chunks/{process.d-CY2g03Mb.d.ts → types.d-DG9B4SMm.d.ts} +369 -4
  65. package/dist/types-chunks/types.d-DU9lLkmE.d.ts +128 -0
  66. package/dist/types-chunks/types.d-DYv3a1ka.d.ts +975 -0
  67. package/dist/types-chunks/{utils.d-C14jZ9ZM.d.ts → utils.d-DMI-9GTR.d.ts} +88 -72
  68. package/docs/SDK_EMBEDDER_GUIDE.md +3079 -0
  69. package/package.json +8 -1
  70. package/dist/chunks/argument-completer-EN63ZVJK.js +0 -2
  71. package/dist/chunks/chunk-4MIHVNB7.js +0 -405
  72. package/dist/chunks/chunk-HP4FXMEM.js +0 -18
  73. package/dist/chunks/chunk-KHICMJIR.js +0 -310
  74. package/dist/chunks/chunk-LGR7ACBQ.js +0 -326
  75. package/dist/chunks/chunk-RR7W7UF6.js +0 -341
  76. package/dist/chunks/chunk-UGTK2JIJ.js +0 -731
  77. package/dist/chunks/chunk-V4WSBIXB.js +0 -2
  78. package/dist/chunks/chunk-VSWROENP.js +0 -52
  79. package/dist/chunks/compaction-config-4VIONMFB.js +0 -2
  80. package/dist/chunks/dist-EDF2YUF6.js +0 -2
  81. package/dist/chunks/host-J4HPDLFC.js +0 -2
  82. package/dist/chunks/run-manager-ZVSW2OWM.js +0 -2
  83. package/dist/chunks/utils-5HDLYTZJ.js +0 -2
  84. package/dist/types-chunks/storage.d-C6kkAEch.d.ts +0 -280
@@ -1,5 +1,4 @@
1
- import { J as Guardrail, bq as RunnerToolCall, f as Agent, h as AgentMessage, bt as RunnerToolResult, bC as Span, a2 as KodaXInputArtifact } from './process.d-CY2g03Mb.js';
2
- import { R as KodaXTaskResultMetadata } from './types.d-Bp4Lm1jv.js';
1
+ import { aw as Guardrail, cf as RunnerToolCall, f as Agent, I as AgentMessage, ci as RunnerToolResult, cr as Span } from './types.d-DG9B4SMm.js';
3
2
 
4
3
  /**
5
4
  * Guardrail Runtime — FEATURE_085 (v0.7.26).
@@ -152,129 +151,5 @@ declare function runToolBeforeGuardrails(call: RunnerToolCall, guardrails: reado
152
151
  */
153
152
  declare function runToolAfterGuardrails(call: RunnerToolCall, result: RunnerToolResult, guardrails: readonly ToolGuardrail[], ctx: GuardrailContext, agentSpan: Span | null): Promise<RunnerToolResult>;
154
153
 
155
- /**
156
- * @kodax-ai/agent/messaging Message queue types
157
- *
158
- * FEATURE_115 (v0.7.36): agentId-scoped 2-tier priority queue infrastructure.
159
- *
160
- * Per ADR-021: messaging is a generic agent-platform primitive (not coding-
161
- * specific). Downstream consumers:
162
- * - @kodax-ai/coding runner-driven mid-turn drain
163
- * - @kodax-ai/repl InkREPL ESC soft-pause + text injection (FEATURE_111 absorbed)
164
- * - subagent task-notification routing (FEATURE_155 idle-yield wakeup)
165
- *
166
- * Phase 0.6 study (`c:/tmp/claude-code-actual-usage.md`): Claude Code's
167
- * `'now'` priority has zero production usage; KodaX simplifies to 2 tiers.
168
- */
169
-
170
- type MessagePriority = 'user' | 'background';
171
- type MessageMode = 'prompt' | 'task-notification' | 'system-reminder';
172
- type QueuedInputArtifact = KodaXInputArtifact;
173
- interface QueuedMessage {
174
- /** Stable id for tracing / dedup. Format: `msg-<sequence>`. */
175
- readonly id: string;
176
- readonly priority: MessagePriority;
177
- /**
178
- * Routing key:
179
- * undefined = main thread / coordinator agent
180
- * 'agent-id-XYZ' = subagent / specific consumer
181
- *
182
- * Drain consumers MUST filter by agentId match — undefined matches only
183
- * undefined-agentId messages, not "any agent".
184
- */
185
- readonly agentId?: string;
186
- readonly mode: MessageMode;
187
- readonly content: string;
188
- readonly inputArtifacts?: readonly QueuedInputArtifact[];
189
- readonly taskResult?: KodaXTaskResultMetadata;
190
- /** Wall-clock timestamp (`Date.now()`) for tracing only — not used for ordering. */
191
- readonly enqueuedAt: number;
192
- }
193
- interface DequeueFilter {
194
- /**
195
- * Only return messages with this agentId.
196
- * undefined matches messages with no agentId (main-thread messages only).
197
- */
198
- readonly agentId?: string;
199
- /**
200
- * Highest priority level included in the drain.
201
- * 'user' → only user priority drained, background stays queued
202
- * 'background' → both user + background drained (Sleep-gated case)
203
- */
204
- readonly maxPriority: MessagePriority;
205
- /**
206
- * Optional cap on number of messages drained in this call.
207
- * Defaults to unlimited (drains all matching).
208
- */
209
- readonly limit?: number;
210
- /**
211
- * FEATURE_159 (v0.7.40) — optional mode filter. Lets REPL split the
212
- * single queue into mode-typed views (e.g. `mode:'prompt'` for user
213
- * input vs `mode:'task-notification'` for child completion banners)
214
- * without separate queues. When omitted, all modes match.
215
- */
216
- readonly mode?: MessageMode;
217
- /**
218
- * FEATURE_159 (v0.7.40) — optional precise-id filter. Single-message
219
- * targeted removal — drives Esc-pop-this-uuid in REPL. When set, all
220
- * other filters still apply (agentId / priority / mode mismatches still
221
- * skip the message), so callers can't accidentally remove a message
222
- * outside their scope.
223
- */
224
- readonly id?: string;
225
- /**
226
- * FEATURE_159 (v0.7.40) — optional escape-hatch predicate, AND-ed with
227
- * the structured filters. Lets SDK consumers express conditions the
228
- * typed fields don't cover (e.g. timestamp ranges, content-match) without
229
- * forcing every new use case to extend `DequeueFilter`. KodaX-internal
230
- * code should prefer the typed fields for readability; this is the
231
- * "data-driven main path + predicate escape" pattern.
232
- *
233
- * Evaluated AFTER the typed filters succeed — so a `predicate` that
234
- * inspects `message.content` never runs on messages outside the
235
- * caller's `agentId` / `mode` / `id` scope.
236
- */
237
- readonly predicate?: (message: QueuedMessage) => boolean;
238
- }
239
- /**
240
- * FEATURE_159 (v0.7.40) — structured queue event emitted to subscribers.
241
- *
242
- * Replaces the prior `() => void` bare-notify signal. Carries the kind +
243
- * affected messages so SDK observability consumers (logging, tracing,
244
- * metrics) can react per-event without re-diffing snapshots.
245
- *
246
- * Event granularity rules:
247
- * - `enqueued` fires ONCE per `enqueue()` call (always 1 message).
248
- * - `dequeued` fires ONCE per `dequeue()` call that removed ≥1 message,
249
- * carrying ALL drained messages in priority+FIFO order. No-op drains
250
- * (filter matched nothing) fire no event — quiet by design so the
251
- * `waitForWakeEvent` 100ms poll doesn't spam idle subscribers.
252
- * - `cleared` fires ONCE per `clear()` call that removed ≥1 message,
253
- * carrying the pre-clear messages. Empty-queue clear fires nothing.
254
- *
255
- * The `useSyncExternalStore` React hook ignores the event payload (it
256
- * only needs the change signal); SDK / tracer consumers read the event.
257
- */
258
- type QueueEvent = {
259
- readonly kind: 'enqueued';
260
- readonly message: QueuedMessage;
261
- } | {
262
- readonly kind: 'dequeued';
263
- readonly messages: readonly QueuedMessage[];
264
- } | {
265
- readonly kind: 'cleared';
266
- readonly messages: readonly QueuedMessage[];
267
- };
268
- /** FEATURE_159 — `MessageQueue.subscribe` listener signature. */
269
- type QueueEventListener = (event: QueueEvent) => void;
270
- interface EnqueueInput {
271
- readonly priority: MessagePriority;
272
- readonly mode: MessageMode;
273
- readonly content: string;
274
- readonly agentId?: string;
275
- readonly inputArtifacts?: readonly QueuedInputArtifact[];
276
- readonly taskResult?: KodaXTaskResultMetadata;
277
- }
278
-
279
- export { GuardrailBlockedError as G, GuardrailEscalateError as b, collectGuardrails as h, runOutputGuardrails as i, runToolAfterGuardrails as j, runToolBeforeGuardrails as k, runInputGuardrails as r };
280
- export type { DequeueFilter as D, EnqueueInput as E, InputGuardrail as I, MessageMode as M, OutputGuardrail as O, QueueEventListener as Q, ToolBeforeOutcome as T, GuardrailContext as a, GuardrailVerdict as c, MessagePriority as d, QueuedInputArtifact as e, QueuedMessage as f, ToolGuardrail as g };
154
+ export { GuardrailBlockedError as G, GuardrailEscalateError as b, collectGuardrails as e, runOutputGuardrails as f, runToolAfterGuardrails as g, runToolBeforeGuardrails as h, runInputGuardrails as r };
155
+ export type { InputGuardrail as I, OutputGuardrail as O, ToolBeforeOutcome as T, GuardrailContext as a, GuardrailVerdict as c, ToolGuardrail as d };
@@ -1,8 +1,8 @@
1
- import { M as McpConnectMode, a as McpServerConfig, b as McpServersConfig, c as McpTransportKind } from './config.d-CJy1WENT.js';
1
+ import { b as McpServersConfig, M as McpConnectMode, a as McpServerConfig, c as McpTransportKind } from './config.d-CJy1WENT.js';
2
2
  import { K as KodaXBaseProvider } from './base.d-DalIRhbb.js';
3
3
  import { a as CostTracker } from './cost-tracker.d-CBLk1fiD.js';
4
- import { bq as RunnerToolCall } from './process.d-CY2g03Mb.js';
5
- import { g as ToolGuardrail } from './types.d-1CnTg7Sd.js';
4
+ import { cf as RunnerToolCall } from './types.d-DG9B4SMm.js';
5
+ import { d as ToolGuardrail } from './guardrail.d-Ds7JHxR1.js';
6
6
 
7
7
  /**
8
8
  * FEATURE_200 Phase F (v0.7.45) — MCP domain types extracted from types.ts.
@@ -1,5 +1,5 @@
1
- import { a as McpServerConfig, b as McpServersConfig, M as McpConnectMode } from './config.d-CJy1WENT.js';
2
1
  import { a as CapabilityProvider, C as CapabilityKind, b as CapabilityResult } from './capability.d-3C62G8Eq.js';
2
+ import { a as McpServerConfig, b as McpServersConfig, M as McpConnectMode } from './config.d-CJy1WENT.js';
3
3
 
4
4
  type McpCapabilityKind = 'tool' | 'resource' | 'prompt';
5
5
  type McpCapabilityRisk = 'read' | 'write' | 'network' | 'exec';
@@ -348,176 +348,6 @@ declare class McpCapabilityProvider implements CapabilityProvider {
348
348
  private requireRuntime;
349
349
  }
350
350
 
351
- interface McpTransportEvents {
352
- /** Called with a complete JSON-RPC message (raw JSON string). */
353
- onMessage(raw: string): void;
354
- onError(error: Error): void;
355
- onClose(reason: string): void;
356
- }
357
- interface McpTransport {
358
- open(events: McpTransportEvents): Promise<void>;
359
- /** Send a JSON string. The transport handles framing. */
360
- send(json: string): Promise<void>;
361
- setProtocolVersion?(version: string | undefined): void;
362
- close(): Promise<void>;
363
- readonly connected: boolean;
364
- /** Effective transport after auto-detection (diagnostics only). */
365
- readonly resolvedTransport?: string;
366
- }
367
- declare class McpExpiredSessionError extends Error {
368
- constructor();
369
- }
370
- /**
371
- * FEATURE_222 — the server demanded OAuth (401) or a stronger scope (403). It
372
- * carries the `WWW-Authenticate` header so the connect flow can discover the
373
- * authorization server (RFC 9728 pointer) or read the step-up scope.
374
- */
375
- declare class McpAuthRequiredError extends Error {
376
- readonly status: number;
377
- readonly wwwAuthenticate?: string | undefined;
378
- constructor(status: number, wwwAuthenticate?: string | undefined);
379
- }
380
- type StdioFraming = 'content-length' | 'ndjson';
381
- interface McpTransportOptions {
382
- stdioFraming?: StdioFraming;
383
- httpResolvedTransport?: 'streamable-http' | 'sse';
384
- }
385
- declare function createMcpTransport(config: McpServerConfig, options?: McpTransportOptions): McpTransport;
386
-
387
- /**
388
- * FEATURE_222 — MCP OAuth discovery (server→authorization-server resolution).
389
- *
390
- * The modern MCP auth flow does NOT require the user to hand-configure
391
- * authorization/token endpoints. Instead the client discovers them at runtime:
392
- *
393
- * 401 WWW-Authenticate (resource_metadata=...) [RFC 9728 pointer]
394
- * → GET /.well-known/oauth-protected-resource [RFC 9728 PRM]
395
- * → authorization_servers[0]
396
- * → GET /.well-known/oauth-authorization-server [RFC 8414]
397
- * (fallback /.well-known/openid-configuration) [OIDC]
398
- * → authorization_endpoint / token_endpoint / registration_endpoint
399
- *
400
- * This module is the pure-HTTP discovery layer (no PKCE, no browser, no token
401
- * storage — those compose on top). The path-aware fallback ordering mirrors
402
- * Claude Code's MCP client so KodaX resolves the same servers it does.
403
- */
404
- interface WwwAuthenticateChallenge {
405
- readonly scheme: string;
406
- readonly params: Record<string, string>;
407
- }
408
- /** The RFC 9728 `resource_metadata` URL a 401 challenge points at, if any. */
409
- declare function extractResourceMetadataUrl(header: string | undefined): string | undefined;
410
- /**
411
- * For a 403 `error="insufficient_scope"` challenge, the `scope` the server now
412
- * requires (space-separated). Undefined when the challenge is not a step-up.
413
- */
414
- declare function extractInsufficientScope(header: string | undefined): string | undefined;
415
- interface ProtectedResourceMetadata {
416
- readonly authorizationServers: string[];
417
- readonly resource?: string;
418
- readonly scopesSupported?: string[];
419
- }
420
- /**
421
- * Discover the protected-resource metadata for an MCP server URL. Prefers the
422
- * `resource_metadata` URL from the 401 challenge; otherwise probes the
423
- * path-specific then root `/.well-known/oauth-protected-resource`.
424
- */
425
- declare function discoverProtectedResourceMetadata(options: {
426
- serverUrl: string;
427
- resourceMetadataUrl?: string;
428
- fetchFn?: typeof fetch;
429
- }): Promise<ProtectedResourceMetadata | undefined>;
430
- interface AuthorizationServerMetadata {
431
- readonly issuer?: string;
432
- readonly authorizationEndpoint: string;
433
- readonly tokenEndpoint: string;
434
- readonly registrationEndpoint?: string;
435
- readonly scopesSupported?: string[];
436
- readonly codeChallengeMethodsSupported?: string[];
437
- }
438
- /** Discover an authorization server's endpoints. The first candidate returning
439
- * both an authorization + token endpoint wins. */
440
- declare function discoverAuthorizationServerMetadata(options: {
441
- authorizationServerUrl: string;
442
- fetchFn?: typeof fetch;
443
- }): Promise<AuthorizationServerMetadata | undefined>;
444
- /**
445
- * End-to-end endpoint discovery: PRM → first authorization server → AS metadata.
446
- * Returns the resolved endpoints plus the resource indicator (RFC 8707) and the
447
- * scopes the resource advertises. Undefined when discovery fails at any step.
448
- */
449
- interface DiscoveredOAuthEndpoints extends AuthorizationServerMetadata {
450
- /** RFC 8707 resource indicator (the MCP server's canonical URL). */
451
- readonly resource?: string;
452
- /** Scopes from the protected-resource document, when the AS omits them. */
453
- readonly resourceScopesSupported?: string[];
454
- }
455
- declare function discoverOAuthEndpoints(options: {
456
- serverUrl: string;
457
- resourceMetadataUrl?: string;
458
- fetchFn?: typeof fetch;
459
- }): Promise<DiscoveredOAuthEndpoints | undefined>;
460
-
461
- interface OAuthToken {
462
- readonly accessToken: string;
463
- readonly refreshToken?: string;
464
- readonly expiresAt?: number;
465
- readonly tokenType?: string;
466
- readonly scope?: string;
467
- }
468
-
469
- /** A dynamically-registered (or pre-configured) OAuth client. */
470
- interface OAuthClientInfo {
471
- readonly clientId: string;
472
- readonly clientSecret?: string;
473
- }
474
- /**
475
- * RFC 7591 Dynamic Client Registration. Registers a public client (PKCE, no
476
- * secret) for the loopback redirect and returns the issued client_id.
477
- */
478
- declare function registerOAuthClient(options: {
479
- registrationEndpoint: string;
480
- redirectUri: string;
481
- clientName: string;
482
- scope?: string;
483
- fetchFn?: typeof fetch;
484
- }): Promise<OAuthClientInfo>;
485
- /**
486
- * The host's consent gate for a login. Receives the authorization URL and must
487
- * return true to proceed (the user will open it in their browser). Returning
488
- * false aborts the login. KodaX never auto-opens the URL.
489
- */
490
- type OAuthLoginConsent = (authorizationUrl: string) => Promise<boolean>;
491
- interface PerformOAuthLoginOptions {
492
- serverId: string;
493
- /** The MCP server URL (resource) we are authenticating to. */
494
- serverUrl: string;
495
- /** resource_metadata URL from a 401 challenge, if one was seen. */
496
- resourceMetadataUrl?: string;
497
- /** A pre-configured client_id (skips dynamic registration). */
498
- configuredClientId?: string;
499
- /** Pre-configured scopes (override discovery). */
500
- configuredScopes?: readonly string[];
501
- /** For an insufficient_scope step-up: the elevated scope to request. */
502
- stepUpScope?: string;
503
- /** Host consent gate (anti-phishing) — receives the authorization URL. */
504
- consent: OAuthLoginConsent;
505
- /** Loopback callback port (defaults to {@link DEFAULT_OAUTH_REDIRECT_PORT}). */
506
- redirectPort?: number;
507
- fetchFn?: typeof fetch;
508
- }
509
- /**
510
- * Run the full interactive login and persist the resulting token. Returns the
511
- * token, or undefined when discovery fails, no client can be obtained, or the
512
- * user declines consent. Throws only on a hard protocol error (bad exchange).
513
- */
514
- declare function performOAuthLogin(options: PerformOAuthLoginOptions): Promise<OAuthToken | undefined>;
515
- /**
516
- * Return a still-valid cached token for a server, or undefined. (Discovery-based
517
- * refresh on expiry is driven by the connect flow, which knows the endpoints.)
518
- */
519
- declare function loadValidToken(serverId: string): Promise<OAuthToken | undefined>;
520
-
521
351
  /**
522
352
  * McpManager — v0.7.42 (extends FEATURE_186 MCP popout surface).
523
353
  *
@@ -697,5 +527,5 @@ declare class McpManager {
697
527
  */
698
528
  declare function createMcpManager(servers: McpServersConfig | undefined, options?: McpProviderOptions): McpManager;
699
529
 
700
- export { buildInitializeCapabilities as C, createMcpCapabilityId as E, createMcpManager as F, createMcpTransport as G, defaultMcpCacheDir as H, discoverAuthorizationServerMetadata as I, discoverOAuthEndpoints as J, discoverProtectedResourceMetadata as K, extractInsufficientScope as L, McpAuthRequiredError as M, extractResourceMetadataUrl as N, getMcpCachePaths as Q, loadValidToken as R, normalizeMcpCapabilityId as S, parseMcpCapabilityId as T, performOAuthLogin as U, registerOAuthClient as V, searchMcpCatalog as X, McpCapabilityProvider as c, McpExpiredSessionError as h, McpManager as j, McpServerRuntime as s };
701
- export type { AuthorizationServerMetadata as A, ProtectedResourceMetadata as B, DiscoveredOAuthEndpoints as D, OAuthClientInfo as O, PerformOAuthLoginOptions as P, WwwAuthenticateChallenge as W, McpCapabilityDescriptor as a, McpCapabilityKind as b, McpCapabilityRisk as d, McpCatalogItem as e, McpElicitRequest as f, McpElicitResult as g, McpIcon as i, McpProviderOptions as k, McpReverseCapabilities as l, McpRoot as m, McpSamplingRequest as n, McpSamplingResult as o, McpServerCatalog as p, McpServerCatalogSnapshot as q, McpServerLogs as r, McpServerRuntimeDiagnostics as t, McpServerStatus as u, McpServerToolList as v, McpToolTaskSupport as w, McpTransport as x, McpTransportEvents as y, OAuthLoginConsent as z };
530
+ export { normalizeMcpCapabilityId as A, parseMcpCapabilityId as B, searchMcpCatalog as C, McpCapabilityProvider as b, McpManager as h, McpServerRuntime as q, buildInitializeCapabilities as v, createMcpCapabilityId as w, createMcpManager as x, defaultMcpCacheDir as y, getMcpCachePaths as z };
531
+ export type { McpCapabilityDescriptor as M, McpCapabilityKind as a, McpCapabilityRisk as c, McpCatalogItem as d, McpElicitRequest as e, McpElicitResult as f, McpIcon as g, McpProviderOptions as i, McpReverseCapabilities as j, McpRoot as k, McpSamplingRequest as l, McpSamplingResult as m, McpServerCatalog as n, McpServerCatalogSnapshot as o, McpServerLogs as p, McpServerRuntimeDiagnostics as r, McpServerStatus as s, McpServerToolList as t, McpToolTaskSupport as u };
@@ -0,0 +1,174 @@
1
+ import { a as McpServerConfig } from './config.d-CJy1WENT.js';
2
+
3
+ interface McpTransportEvents {
4
+ /** Called with a complete JSON-RPC message (raw JSON string). */
5
+ onMessage(raw: string): void;
6
+ onError(error: Error): void;
7
+ onClose(reason: string): void;
8
+ }
9
+ interface McpTransport {
10
+ open(events: McpTransportEvents): Promise<void>;
11
+ /** Send a JSON string. The transport handles framing. */
12
+ send(json: string): Promise<void>;
13
+ setProtocolVersion?(version: string | undefined): void;
14
+ close(): Promise<void>;
15
+ readonly connected: boolean;
16
+ /** Effective transport after auto-detection (diagnostics only). */
17
+ readonly resolvedTransport?: string;
18
+ }
19
+ declare class McpExpiredSessionError extends Error {
20
+ constructor();
21
+ }
22
+ /**
23
+ * FEATURE_222 — the server demanded OAuth (401) or a stronger scope (403). It
24
+ * carries the `WWW-Authenticate` header so the connect flow can discover the
25
+ * authorization server (RFC 9728 pointer) or read the step-up scope.
26
+ */
27
+ declare class McpAuthRequiredError extends Error {
28
+ readonly status: number;
29
+ readonly wwwAuthenticate?: string | undefined;
30
+ constructor(status: number, wwwAuthenticate?: string | undefined);
31
+ }
32
+ type StdioFraming = 'content-length' | 'ndjson';
33
+ interface McpTransportOptions {
34
+ stdioFraming?: StdioFraming;
35
+ httpResolvedTransport?: 'streamable-http' | 'sse';
36
+ }
37
+ declare function createMcpTransport(config: McpServerConfig, options?: McpTransportOptions): McpTransport;
38
+
39
+ /**
40
+ * FEATURE_222 — MCP OAuth discovery (server→authorization-server resolution).
41
+ *
42
+ * The modern MCP auth flow does NOT require the user to hand-configure
43
+ * authorization/token endpoints. Instead the client discovers them at runtime:
44
+ *
45
+ * 401 WWW-Authenticate (resource_metadata=...) [RFC 9728 pointer]
46
+ * → GET /.well-known/oauth-protected-resource [RFC 9728 PRM]
47
+ * → authorization_servers[0]
48
+ * → GET /.well-known/oauth-authorization-server [RFC 8414]
49
+ * (fallback /.well-known/openid-configuration) [OIDC]
50
+ * → authorization_endpoint / token_endpoint / registration_endpoint
51
+ *
52
+ * This module is the pure-HTTP discovery layer (no PKCE, no browser, no token
53
+ * storage — those compose on top). The path-aware fallback ordering mirrors
54
+ * Claude Code's MCP client so KodaX resolves the same servers it does.
55
+ */
56
+ interface WwwAuthenticateChallenge {
57
+ readonly scheme: string;
58
+ readonly params: Record<string, string>;
59
+ }
60
+ /** The RFC 9728 `resource_metadata` URL a 401 challenge points at, if any. */
61
+ declare function extractResourceMetadataUrl(header: string | undefined): string | undefined;
62
+ /**
63
+ * For a 403 `error="insufficient_scope"` challenge, the `scope` the server now
64
+ * requires (space-separated). Undefined when the challenge is not a step-up.
65
+ */
66
+ declare function extractInsufficientScope(header: string | undefined): string | undefined;
67
+ interface ProtectedResourceMetadata {
68
+ readonly authorizationServers: string[];
69
+ readonly resource?: string;
70
+ readonly scopesSupported?: string[];
71
+ }
72
+ /**
73
+ * Discover the protected-resource metadata for an MCP server URL. Prefers the
74
+ * `resource_metadata` URL from the 401 challenge; otherwise probes the
75
+ * path-specific then root `/.well-known/oauth-protected-resource`.
76
+ */
77
+ declare function discoverProtectedResourceMetadata(options: {
78
+ serverUrl: string;
79
+ resourceMetadataUrl?: string;
80
+ fetchFn?: typeof fetch;
81
+ }): Promise<ProtectedResourceMetadata | undefined>;
82
+ interface AuthorizationServerMetadata {
83
+ readonly issuer?: string;
84
+ readonly authorizationEndpoint: string;
85
+ readonly tokenEndpoint: string;
86
+ readonly registrationEndpoint?: string;
87
+ readonly scopesSupported?: string[];
88
+ readonly codeChallengeMethodsSupported?: string[];
89
+ }
90
+ /** Discover an authorization server's endpoints. The first candidate returning
91
+ * both an authorization + token endpoint wins. */
92
+ declare function discoverAuthorizationServerMetadata(options: {
93
+ authorizationServerUrl: string;
94
+ fetchFn?: typeof fetch;
95
+ }): Promise<AuthorizationServerMetadata | undefined>;
96
+ /**
97
+ * End-to-end endpoint discovery: PRM → first authorization server → AS metadata.
98
+ * Returns the resolved endpoints plus the resource indicator (RFC 8707) and the
99
+ * scopes the resource advertises. Undefined when discovery fails at any step.
100
+ */
101
+ interface DiscoveredOAuthEndpoints extends AuthorizationServerMetadata {
102
+ /** RFC 8707 resource indicator (the MCP server's canonical URL). */
103
+ readonly resource?: string;
104
+ /** Scopes from the protected-resource document, when the AS omits them. */
105
+ readonly resourceScopesSupported?: string[];
106
+ }
107
+ declare function discoverOAuthEndpoints(options: {
108
+ serverUrl: string;
109
+ resourceMetadataUrl?: string;
110
+ fetchFn?: typeof fetch;
111
+ }): Promise<DiscoveredOAuthEndpoints | undefined>;
112
+
113
+ interface OAuthToken {
114
+ readonly accessToken: string;
115
+ readonly refreshToken?: string;
116
+ readonly expiresAt?: number;
117
+ readonly tokenType?: string;
118
+ readonly scope?: string;
119
+ }
120
+
121
+ /** A dynamically-registered (or pre-configured) OAuth client. */
122
+ interface OAuthClientInfo {
123
+ readonly clientId: string;
124
+ readonly clientSecret?: string;
125
+ }
126
+ /**
127
+ * RFC 7591 Dynamic Client Registration. Registers a public client (PKCE, no
128
+ * secret) for the loopback redirect and returns the issued client_id.
129
+ */
130
+ declare function registerOAuthClient(options: {
131
+ registrationEndpoint: string;
132
+ redirectUri: string;
133
+ clientName: string;
134
+ scope?: string;
135
+ fetchFn?: typeof fetch;
136
+ }): Promise<OAuthClientInfo>;
137
+ /**
138
+ * The host's consent gate for a login. Receives the authorization URL and must
139
+ * return true to proceed (the user will open it in their browser). Returning
140
+ * false aborts the login. KodaX never auto-opens the URL.
141
+ */
142
+ type OAuthLoginConsent = (authorizationUrl: string) => Promise<boolean>;
143
+ interface PerformOAuthLoginOptions {
144
+ serverId: string;
145
+ /** The MCP server URL (resource) we are authenticating to. */
146
+ serverUrl: string;
147
+ /** resource_metadata URL from a 401 challenge, if one was seen. */
148
+ resourceMetadataUrl?: string;
149
+ /** A pre-configured client_id (skips dynamic registration). */
150
+ configuredClientId?: string;
151
+ /** Pre-configured scopes (override discovery). */
152
+ configuredScopes?: readonly string[];
153
+ /** For an insufficient_scope step-up: the elevated scope to request. */
154
+ stepUpScope?: string;
155
+ /** Host consent gate (anti-phishing) — receives the authorization URL. */
156
+ consent: OAuthLoginConsent;
157
+ /** Loopback callback port (defaults to {@link DEFAULT_OAUTH_REDIRECT_PORT}). */
158
+ redirectPort?: number;
159
+ fetchFn?: typeof fetch;
160
+ }
161
+ /**
162
+ * Run the full interactive login and persist the resulting token. Returns the
163
+ * token, or undefined when discovery fails, no client can be obtained, or the
164
+ * user declines consent. Throws only on a hard protocol error (bad exchange).
165
+ */
166
+ declare function performOAuthLogin(options: PerformOAuthLoginOptions): Promise<OAuthToken | undefined>;
167
+ /**
168
+ * Return a still-valid cached token for a server, or undefined. (Discovery-based
169
+ * refresh on expiry is driven by the connect flow, which knows the endpoints.)
170
+ */
171
+ declare function loadValidToken(serverId: string): Promise<OAuthToken | undefined>;
172
+
173
+ export { McpAuthRequiredError as M, McpExpiredSessionError as a, createMcpTransport as f, discoverAuthorizationServerMetadata as g, discoverOAuthEndpoints as h, discoverProtectedResourceMetadata as i, extractInsufficientScope as j, extractResourceMetadataUrl as k, loadValidToken as l, performOAuthLogin as p, registerOAuthClient as r };
174
+ export type { AuthorizationServerMetadata as A, DiscoveredOAuthEndpoints as D, OAuthClientInfo as O, PerformOAuthLoginOptions as P, WwwAuthenticateChallenge as W, McpTransport as b, McpTransportEvents as c, OAuthLoginConsent as d, ProtectedResourceMetadata as e };