@combycode/llm-sdk 1.0.0-rc.0

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 (228) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +21 -0
  3. package/README.md +103 -0
  4. package/dist/agent/approval-types.d.ts +49 -0
  5. package/dist/agent/context-registry/layers.d.ts +39 -0
  6. package/dist/agent/context-registry/registry-internal.d.ts +14 -0
  7. package/dist/agent/context-registry/registry.d.ts +104 -0
  8. package/dist/agent/context-registry/types.d.ts +110 -0
  9. package/dist/agent/guardrail-types.d.ts +58 -0
  10. package/dist/agent/history-types.d.ts +40 -0
  11. package/dist/agent/history.d.ts +111 -0
  12. package/dist/agent/loop-config.d.ts +67 -0
  13. package/dist/agent/loop-internals.d.ts +46 -0
  14. package/dist/agent/loop-step-state.d.ts +20 -0
  15. package/dist/agent/loop.d.ts +133 -0
  16. package/dist/agent/tool-key.d.ts +3 -0
  17. package/dist/agent/types.d.ts +138 -0
  18. package/dist/bus/agent-bus.d.ts +99 -0
  19. package/dist/bus/async-context.browser.d.ts +13 -0
  20. package/dist/bus/async-context.d.ts +11 -0
  21. package/dist/bus/async-context.types.d.ts +14 -0
  22. package/dist/bus/hook-bus.d.ts +43 -0
  23. package/dist/bus/hook-map.d.ts +592 -0
  24. package/dist/helpers/agent.d.ts +32 -0
  25. package/dist/helpers/batch.d.ts +74 -0
  26. package/dist/helpers/calibration-store.d.ts +27 -0
  27. package/dist/helpers/calibration-types.d.ts +64 -0
  28. package/dist/helpers/chain.d.ts +30 -0
  29. package/dist/helpers/client-pool.d.ts +15 -0
  30. package/dist/helpers/client-resolver.d.ts +62 -0
  31. package/dist/helpers/collection.d.ts +19 -0
  32. package/dist/helpers/consolidate.d.ts +66 -0
  33. package/dist/helpers/content.d.ts +25 -0
  34. package/dist/helpers/conversation-export.d.ts +14 -0
  35. package/dist/helpers/conversation-zip.d.ts +28 -0
  36. package/dist/helpers/count-tokens.d.ts +26 -0
  37. package/dist/helpers/define-tool.d.ts +66 -0
  38. package/dist/helpers/delegate.d.ts +6 -0
  39. package/dist/helpers/embed.d.ts +24 -0
  40. package/dist/helpers/engine.d.ts +121 -0
  41. package/dist/helpers/estimate-types.d.ts +67 -0
  42. package/dist/helpers/estimate.d.ts +45 -0
  43. package/dist/helpers/estimator.d.ts +48 -0
  44. package/dist/helpers/handoff-types.d.ts +18 -0
  45. package/dist/helpers/handoff.d.ts +14 -0
  46. package/dist/helpers/llm.d.ts +24 -0
  47. package/dist/helpers/mcp.d.ts +82 -0
  48. package/dist/helpers/media.d.ts +58 -0
  49. package/dist/helpers/models.d.ts +36 -0
  50. package/dist/helpers/moderate-types.d.ts +73 -0
  51. package/dist/helpers/moderate.d.ts +13 -0
  52. package/dist/helpers/moderation-guardrail.d.ts +29 -0
  53. package/dist/helpers/observer.d.ts +36 -0
  54. package/dist/helpers/one-shot.d.ts +86 -0
  55. package/dist/helpers/parallel.d.ts +16 -0
  56. package/dist/helpers/realtime.d.ts +25 -0
  57. package/dist/helpers/route.d.ts +29 -0
  58. package/dist/helpers/select-model.d.ts +41 -0
  59. package/dist/helpers/server.d.ts +32 -0
  60. package/dist/helpers/transcribe.d.ts +36 -0
  61. package/dist/index.browser.js +38047 -0
  62. package/dist/index.d.ts +275 -0
  63. package/dist/index.js +37974 -0
  64. package/dist/llm/audio/voices.d.ts +7 -0
  65. package/dist/llm/client-config.d.ts +37 -0
  66. package/dist/llm/client-internal.d.ts +28 -0
  67. package/dist/llm/client.d.ts +68 -0
  68. package/dist/llm/providers/_shared/constants.d.ts +5 -0
  69. package/dist/llm/providers/_shared/response-utils.d.ts +8 -0
  70. package/dist/llm/providers/anthropic/batch.d.ts +19 -0
  71. package/dist/llm/providers/anthropic/constants.d.ts +13 -0
  72. package/dist/llm/providers/anthropic/files.d.ts +23 -0
  73. package/dist/llm/providers/anthropic/messages.d.ts +30 -0
  74. package/dist/llm/providers/google/batch.d.ts +20 -0
  75. package/dist/llm/providers/google/constants.d.ts +6 -0
  76. package/dist/llm/providers/google/embeddings.d.ts +15 -0
  77. package/dist/llm/providers/google/files.d.ts +22 -0
  78. package/dist/llm/providers/google/generate.d.ts +27 -0
  79. package/dist/llm/providers/google/interactions.d.ts +30 -0
  80. package/dist/llm/providers/google/media.d.ts +27 -0
  81. package/dist/llm/providers/google/realtime.d.ts +27 -0
  82. package/dist/llm/providers/openai/batch.d.ts +19 -0
  83. package/dist/llm/providers/openai/completions.d.ts +25 -0
  84. package/dist/llm/providers/openai/embeddings.d.ts +16 -0
  85. package/dist/llm/providers/openai/files.d.ts +23 -0
  86. package/dist/llm/providers/openai/media.d.ts +28 -0
  87. package/dist/llm/providers/openai/moderations.d.ts +19 -0
  88. package/dist/llm/providers/openai/realtime.d.ts +24 -0
  89. package/dist/llm/providers/openai/responses.d.ts +29 -0
  90. package/dist/llm/providers/openai/tiers.d.ts +13 -0
  91. package/dist/llm/providers/openai/transcription.d.ts +20 -0
  92. package/dist/llm/providers/openrouter/completions.d.ts +15 -0
  93. package/dist/llm/providers/openrouter/embeddings.d.ts +7 -0
  94. package/dist/llm/providers/openrouter/media.d.ts +25 -0
  95. package/dist/llm/providers/openrouter/responses.d.ts +17 -0
  96. package/dist/llm/providers/xai/batch.d.ts +19 -0
  97. package/dist/llm/providers/xai/completions.d.ts +24 -0
  98. package/dist/llm/providers/xai/files.d.ts +23 -0
  99. package/dist/llm/providers/xai/media.d.ts +27 -0
  100. package/dist/llm/providers/xai/responses.d.ts +20 -0
  101. package/dist/llm/realtime/session.d.ts +34 -0
  102. package/dist/llm/realtime/types.d.ts +66 -0
  103. package/dist/llm/server-state.d.ts +32 -0
  104. package/dist/llm/types/audio.d.ts +18 -0
  105. package/dist/llm/types/messages.d.ts +125 -0
  106. package/dist/llm/types/options.d.ts +51 -0
  107. package/dist/llm/types/provider.d.ts +39 -0
  108. package/dist/llm/types/request.d.ts +51 -0
  109. package/dist/llm/types/response.d.ts +36 -0
  110. package/dist/llm/types/schema-utils.d.ts +8 -0
  111. package/dist/llm/types/stream.d.ts +42 -0
  112. package/dist/llm/types/tiers.d.ts +11 -0
  113. package/dist/llm/types/tools.d.ts +20 -0
  114. package/dist/network/engine.d.ts +87 -0
  115. package/dist/network/errors.d.ts +14 -0
  116. package/dist/network/queue-state-config.d.ts +41 -0
  117. package/dist/network/queue-state.d.ts +45 -0
  118. package/dist/network/rate-limiter.d.ts +49 -0
  119. package/dist/network/realtime-connection.d.ts +40 -0
  120. package/dist/network/request-queue.d.ts +40 -0
  121. package/dist/network/semaphore.d.ts +12 -0
  122. package/dist/network/sse.d.ts +3 -0
  123. package/dist/network/types.d.ts +127 -0
  124. package/dist/plugins/batch/batcher.d.ts +45 -0
  125. package/dist/plugins/batch/strategy.d.ts +20 -0
  126. package/dist/plugins/batch/types.d.ts +54 -0
  127. package/dist/plugins/cache/cache.d.ts +50 -0
  128. package/dist/plugins/cache/file-store.d.ts +15 -0
  129. package/dist/plugins/cache/memory-store.d.ts +10 -0
  130. package/dist/plugins/cache/types.d.ts +28 -0
  131. package/dist/plugins/configuration/configuration.d.ts +71 -0
  132. package/dist/plugins/context-guard/facts.d.ts +14 -0
  133. package/dist/plugins/context-guard/guard.d.ts +27 -0
  134. package/dist/plugins/context-guard/strategies/layered.d.ts +24 -0
  135. package/dist/plugins/context-guard/strategies/truncate.d.ts +19 -0
  136. package/dist/plugins/context-guard/tools.d.ts +50 -0
  137. package/dist/plugins/context-guard/types.d.ts +110 -0
  138. package/dist/plugins/context-measurer/calibration/store.d.ts +19 -0
  139. package/dist/plugins/context-measurer/counter/count-api.d.ts +41 -0
  140. package/dist/plugins/context-measurer/counter/heuristic.d.ts +25 -0
  141. package/dist/plugins/context-measurer/counter/hybrid.d.ts +33 -0
  142. package/dist/plugins/context-measurer/counter/tiktoken.d.ts +13 -0
  143. package/dist/plugins/context-measurer/measurer.d.ts +49 -0
  144. package/dist/plugins/context-measurer/types.d.ts +40 -0
  145. package/dist/plugins/cost-collector/collector.d.ts +42 -0
  146. package/dist/plugins/cost-collector/cost-collector-internal.d.ts +58 -0
  147. package/dist/plugins/cost-collector/cost-collector-types.d.ts +42 -0
  148. package/dist/plugins/embeddings/types.d.ts +23 -0
  149. package/dist/plugins/files/attachment.d.ts +79 -0
  150. package/dist/plugins/files/provider-adapter.d.ts +37 -0
  151. package/dist/plugins/files/registry.d.ts +48 -0
  152. package/dist/plugins/files/strategy.d.ts +38 -0
  153. package/dist/plugins/internal-tools/backends/local.d.ts +12 -0
  154. package/dist/plugins/internal-tools/builtin/builtin.d.ts +21 -0
  155. package/dist/plugins/internal-tools/builtin/clarify.d.ts +12 -0
  156. package/dist/plugins/internal-tools/builtin/classify.d.ts +12 -0
  157. package/dist/plugins/internal-tools/builtin/score.d.ts +13 -0
  158. package/dist/plugins/internal-tools/builtin/structure.d.ts +11 -0
  159. package/dist/plugins/internal-tools/builtin/summarize.d.ts +19 -0
  160. package/dist/plugins/internal-tools/id.d.ts +12 -0
  161. package/dist/plugins/internal-tools/registry.d.ts +24 -0
  162. package/dist/plugins/internal-tools/runner/define.d.ts +7 -0
  163. package/dist/plugins/internal-tools/runner/json-enforcement.d.ts +3 -0
  164. package/dist/plugins/internal-tools/runner/runner.d.ts +47 -0
  165. package/dist/plugins/internal-tools/runner/template.d.ts +10 -0
  166. package/dist/plugins/internal-tools/runner/types.d.ts +57 -0
  167. package/dist/plugins/internal-tools/runner/variants.d.ts +34 -0
  168. package/dist/plugins/internal-tools/types.d.ts +80 -0
  169. package/dist/plugins/logger/console-sink.d.ts +26 -0
  170. package/dist/plugins/logger/logger.d.ts +38 -0
  171. package/dist/plugins/logger/types.d.ts +25 -0
  172. package/dist/plugins/mcp/base-transport.d.ts +58 -0
  173. package/dist/plugins/mcp/client.d.ts +92 -0
  174. package/dist/plugins/mcp/jsonrpc.d.ts +20 -0
  175. package/dist/plugins/mcp/oauth.d.ts +122 -0
  176. package/dist/plugins/mcp/sampling.d.ts +17 -0
  177. package/dist/plugins/mcp/tools.d.ts +20 -0
  178. package/dist/plugins/mcp/transport-http.d.ts +50 -0
  179. package/dist/plugins/mcp/transport-stdio.d.ts +23 -0
  180. package/dist/plugins/mcp/transport-ws.d.ts +32 -0
  181. package/dist/plugins/mcp/transport.d.ts +29 -0
  182. package/dist/plugins/mcp/types.d.ts +202 -0
  183. package/dist/plugins/mcp/url-guard.d.ts +70 -0
  184. package/dist/plugins/mcp/win-spawn.d.ts +20 -0
  185. package/dist/plugins/media/file-store.d.ts +24 -0
  186. package/dist/plugins/media/memory-store.d.ts +17 -0
  187. package/dist/plugins/media/output.d.ts +44 -0
  188. package/dist/plugins/media/source-image.d.ts +36 -0
  189. package/dist/plugins/media/types.d.ts +146 -0
  190. package/dist/plugins/model-catalog/catalog.d.ts +152 -0
  191. package/dist/plugins/permissions/glob.d.ts +6 -0
  192. package/dist/plugins/permissions/matchers.d.ts +7 -0
  193. package/dist/plugins/permissions/policy.d.ts +10 -0
  194. package/dist/plugins/permissions/types.d.ts +22 -0
  195. package/dist/plugins/persistence/file.d.ts +25 -0
  196. package/dist/plugins/persistence/memory.d.ts +23 -0
  197. package/dist/plugins/persistence/types.d.ts +21 -0
  198. package/dist/plugins/retrieval/chunker.d.ts +28 -0
  199. package/dist/plugins/retrieval/hosted-google.d.ts +60 -0
  200. package/dist/plugins/retrieval/hosted-openai.d.ts +45 -0
  201. package/dist/plugins/retrieval/hosted-xai.d.ts +57 -0
  202. package/dist/plugins/retrieval/index.d.ts +70 -0
  203. package/dist/plugins/retrieval/local.d.ts +50 -0
  204. package/dist/plugins/retrieval/types.d.ts +161 -0
  205. package/dist/plugins/retrieval/vector-store.d.ts +70 -0
  206. package/dist/plugins/scheduler/scheduler.d.ts +31 -0
  207. package/dist/plugins/telemetry/telemetry.d.ts +118 -0
  208. package/dist/plugins/tool-catalog/catalog.d.ts +31 -0
  209. package/dist/plugins/tool-catalog/errors.d.ts +22 -0
  210. package/dist/plugins/tool-catalog/types.d.ts +44 -0
  211. package/dist/runtime/runtime.d.ts +20 -0
  212. package/dist/server/auth.d.ts +25 -0
  213. package/dist/server/dispatch.d.ts +35 -0
  214. package/dist/server/loaders.d.ts +26 -0
  215. package/dist/server/oai-adapter.d.ts +30 -0
  216. package/dist/server/oai-types.d.ts +114 -0
  217. package/dist/server/response-store.d.ts +59 -0
  218. package/dist/server/router.d.ts +59 -0
  219. package/dist/server/server.d.ts +61 -0
  220. package/dist/types/request-context.d.ts +46 -0
  221. package/dist/util/async.d.ts +3 -0
  222. package/dist/util/base64.d.ts +8 -0
  223. package/dist/util/duration.d.ts +12 -0
  224. package/dist/util/http.d.ts +9 -0
  225. package/dist/util/image-mime.d.ts +8 -0
  226. package/dist/util/json-schema.d.ts +7 -0
  227. package/dist/util/wav.d.ts +20 -0
  228. package/package.json +95 -0
@@ -0,0 +1,50 @@
1
+ /** Streamable-HTTP MCP transport — each call is a POST through the engine's
2
+ * `fetch` (so it rides the central queue + network telemetry, never side-fetch).
3
+ * Cross-env (works in the browser when the server allows CORS). Handles a
4
+ * single request/response per call: the response body is either one JSON-RPC
5
+ * message (`application/json`) or an SSE batch (`text/event-stream`). The
6
+ * long-lived server->client GET stream reconnects with backoff + Last-Event-ID
7
+ * for resumption. */
8
+ import type { EngineFetch, EngineFetchStream } from '../../network/types';
9
+ import type { McpTransport } from './transport';
10
+ import type { McpHttpConfig } from './types';
11
+ import { BaseJsonRpcTransport } from './base-transport';
12
+ export interface HttpTransportDeps {
13
+ fetch: EngineFetch;
14
+ /** Streaming fetch for the server->client GET SSE channel. */
15
+ fetchStream: EngineFetchStream;
16
+ queueName?: string;
17
+ timeoutMs?: number;
18
+ /** Authorization headers (Bearer) to attach to every request. */
19
+ getAuthHeaders?: () => Promise<Record<string, string>>;
20
+ /** Called on a 401; return true to retry the request once (after re-auth). */
21
+ onUnauthorized?: () => Promise<boolean>;
22
+ }
23
+ export declare class HttpTransport extends BaseJsonRpcTransport implements McpTransport {
24
+ private readonly config;
25
+ private readonly deps;
26
+ private nextHttpId;
27
+ private sessionId;
28
+ private protocolVersion;
29
+ private eventAbort;
30
+ private lastEventId;
31
+ constructor(config: McpHttpConfig, deps: HttpTransportDeps);
32
+ start(): Promise<void>;
33
+ setProtocolVersion(version: string): void;
34
+ /** Open the server->client GET SSE stream (best-effort: a 405 means the server
35
+ * is request/response only). Reconnects with backoff + Last-Event-ID until
36
+ * close(). Runs in the background. */
37
+ listen(): void;
38
+ private eventLoop;
39
+ /** Run one GET SSE session. Returns whether the stream opened (vs 405/error). */
40
+ private runEventStream;
41
+ request(method: string, params?: unknown): Promise<unknown>;
42
+ notify(method: string, params?: unknown): Promise<void>;
43
+ close(): Promise<void>;
44
+ /** Send a JSON-RPC response back via POST (used by handleRequest from base). */
45
+ protected sendMessage(obj: unknown): Promise<void>;
46
+ private headers;
47
+ /** Base headers + any OAuth bearer + per-call extras. */
48
+ private authedHeaders;
49
+ private post;
50
+ }
@@ -0,0 +1,23 @@
1
+ /** Stdio MCP transport — spawns the server as a child process and exchanges
2
+ * newline-delimited JSON-RPC over stdin/stdout. Node/Bun only (browser callers
3
+ * get a friendly error via the lazy `node:child_process` loader). */
4
+ import type { McpTransport } from './transport';
5
+ import type { McpStdioConfig } from './types';
6
+ import { BaseJsonRpcTransport } from './base-transport';
7
+ export declare class StdioTransport extends BaseJsonRpcTransport implements McpTransport {
8
+ private readonly config;
9
+ private proc;
10
+ private buffer;
11
+ private readonly timeoutMs;
12
+ constructor(config: McpStdioConfig, opts?: {
13
+ timeoutMs?: number;
14
+ });
15
+ start(): Promise<void>;
16
+ setProtocolVersion(): void;
17
+ request(method: string, params?: unknown): Promise<unknown>;
18
+ notify(method: string, params?: unknown): Promise<void>;
19
+ close(): Promise<void>;
20
+ protected sendMessage(obj: unknown): void;
21
+ private onData;
22
+ private parseAndRoute;
23
+ }
@@ -0,0 +1,32 @@
1
+ /** WebSocket MCP transport — JSON-RPC messages as text frames over a duplex
2
+ * socket (naturally bidirectional). Uses the engine's `connect` so it shares
3
+ * the engine's WebSocket factory + hooks. Cross-env (browser + Node/Bun). */
4
+ import type { EngineConnect } from '../../network/types';
5
+ import type { McpTransport } from './transport';
6
+ import { BaseJsonRpcTransport } from './base-transport';
7
+ export interface McpWsConfig {
8
+ /** ws:// or wss:// MCP endpoint. */
9
+ url: string;
10
+ protocols?: string | string[];
11
+ headers?: Record<string, string>;
12
+ name?: string;
13
+ }
14
+ export interface WsTransportDeps {
15
+ connect: EngineConnect;
16
+ timeoutMs?: number;
17
+ }
18
+ export declare class WsTransport extends BaseJsonRpcTransport implements McpTransport {
19
+ private readonly config;
20
+ private readonly deps;
21
+ private conn;
22
+ private readonly timeoutMs;
23
+ constructor(config: McpWsConfig, deps: WsTransportDeps);
24
+ setProtocolVersion(): void;
25
+ listen(): void;
26
+ start(): Promise<void>;
27
+ request(method: string, params?: unknown): Promise<unknown>;
28
+ notify(method: string, params?: unknown): Promise<void>;
29
+ close(): Promise<void>;
30
+ protected sendMessage(obj: unknown): void;
31
+ private onFrame;
32
+ }
@@ -0,0 +1,29 @@
1
+ /** A transport carries JSON-RPC messages to/from an MCP server over a wire
2
+ * (stdio or Streamable HTTP). It is BIDIRECTIONAL: besides our requests, it
3
+ * routes incoming server->client requests (sampling/elicitation/roots/ping)
4
+ * and notifications (logging, *_changed, progress) to the registered handlers.
5
+ * The McpClient speaks methods; the transport speaks the wire + correlation. */
6
+ /** Handlers for messages the server initiates toward us. */
7
+ export interface IncomingMcpHandlers {
8
+ /** Server->client request — return the result, or throw McpError. */
9
+ onRequest?: (method: string, params: unknown) => Promise<unknown>;
10
+ /** Server->client notification (no reply). */
11
+ onNotification?: (method: string, params: unknown) => void;
12
+ }
13
+ export interface McpTransport {
14
+ /** Open the connection (spawn the process / no-op for HTTP). */
15
+ start(): Promise<void>;
16
+ /** Send a request and resolve its `result`; throws McpError on a JSON-RPC error. */
17
+ request(method: string, params?: unknown): Promise<unknown>;
18
+ /** Fire-and-forget notification (no response). */
19
+ notify(method: string, params?: unknown): Promise<void>;
20
+ /** Register handlers for server-initiated messages. */
21
+ setHandlers(handlers: IncomingMcpHandlers): void;
22
+ /** Record the negotiated protocol version (HTTP sets a header; stdio ignores). */
23
+ setProtocolVersion?(version: string): void;
24
+ /** Open the server->client channel (HTTP GET SSE stream). Stdio is already
25
+ * duplex, so this is a no-op there. Call after the initialize handshake. */
26
+ listen?(): Promise<void> | void;
27
+ /** Close the connection (kill the process / DELETE the HTTP session). */
28
+ close(): Promise<void>;
29
+ }
@@ -0,0 +1,202 @@
1
+ /** MCP (Model Context Protocol) wire types + client config for protocol
2
+ * v2025-11-25. See docs/design/mcp.md. Hand-rolled (no `@modelcontextprotocol/sdk`)
3
+ * to stay zero-dep and browser-capable. */
4
+ /** Protocol version we advertise in `initialize`. */
5
+ export declare const MCP_PROTOCOL_VERSION = "2025-11-25";
6
+ export interface JsonRpcError {
7
+ code: number;
8
+ message: string;
9
+ data?: unknown;
10
+ }
11
+ export interface JsonRpcResponse {
12
+ jsonrpc: '2.0';
13
+ id: number | string | null;
14
+ result?: unknown;
15
+ error?: JsonRpcError;
16
+ }
17
+ export interface McpToolDef {
18
+ name: string;
19
+ description?: string;
20
+ title?: string;
21
+ /** JSON Schema (object at root) for the tool's arguments. */
22
+ inputSchema: Record<string, unknown>;
23
+ /** JSON Schema for the tool's `structuredContent` output (optional). */
24
+ outputSchema?: Record<string, unknown>;
25
+ }
26
+ /** A content block in a `tools/call` result. Open union — unknown types ignored. */
27
+ export type McpContentBlock = {
28
+ type: 'text';
29
+ text: string;
30
+ } | {
31
+ type: 'image';
32
+ data: string;
33
+ mimeType: string;
34
+ } | {
35
+ type: 'audio';
36
+ data: string;
37
+ mimeType: string;
38
+ } | {
39
+ type: 'resource';
40
+ resource: {
41
+ uri: string;
42
+ mimeType?: string;
43
+ text?: string;
44
+ blob?: string;
45
+ };
46
+ } | {
47
+ type: 'resource_link';
48
+ uri: string;
49
+ mimeType?: string;
50
+ title?: string;
51
+ } | {
52
+ type: string;
53
+ [k: string]: unknown;
54
+ };
55
+ export interface McpCallResult {
56
+ content: McpContentBlock[];
57
+ isError?: boolean;
58
+ structuredContent?: Record<string, unknown>;
59
+ }
60
+ export interface McpResource {
61
+ uri: string;
62
+ name?: string;
63
+ title?: string;
64
+ description?: string;
65
+ mimeType?: string;
66
+ }
67
+ export interface McpResourceTemplate {
68
+ uriTemplate: string;
69
+ name?: string;
70
+ title?: string;
71
+ description?: string;
72
+ mimeType?: string;
73
+ }
74
+ export interface McpResourceContent {
75
+ uri: string;
76
+ mimeType?: string;
77
+ text?: string;
78
+ blob?: string;
79
+ }
80
+ export interface McpPromptArg {
81
+ name: string;
82
+ description?: string;
83
+ required?: boolean;
84
+ }
85
+ export interface McpPrompt {
86
+ name: string;
87
+ title?: string;
88
+ description?: string;
89
+ arguments?: McpPromptArg[];
90
+ }
91
+ export interface McpPromptMessage {
92
+ role: 'user' | 'assistant';
93
+ content: McpContentBlock;
94
+ }
95
+ export interface McpGetPromptResult {
96
+ description?: string;
97
+ messages: McpPromptMessage[];
98
+ }
99
+ export type McpLogLevel = 'debug' | 'info' | 'notice' | 'warning' | 'error' | 'critical' | 'alert' | 'emergency';
100
+ /** Reference for argument autocompletion (`completion/complete`). */
101
+ export type McpCompletionRef = {
102
+ type: 'ref/prompt';
103
+ name: string;
104
+ } | {
105
+ type: 'ref/resource';
106
+ uri: string;
107
+ };
108
+ export interface McpCompletionResult {
109
+ values: string[];
110
+ total?: number;
111
+ hasMore?: boolean;
112
+ }
113
+ export interface McpSamplingMessage {
114
+ role: 'user' | 'assistant';
115
+ content: McpContentBlock;
116
+ }
117
+ /** Params of a server-initiated `sampling/createMessage` (the server asks us to
118
+ * run an LLM completion on its behalf). */
119
+ export interface McpCreateMessageParams {
120
+ messages: McpSamplingMessage[];
121
+ systemPrompt?: string;
122
+ maxTokens: number;
123
+ temperature?: number;
124
+ stopSequences?: string[];
125
+ modelPreferences?: {
126
+ hints?: Array<{
127
+ name?: string;
128
+ }>;
129
+ costPriority?: number;
130
+ speedPriority?: number;
131
+ intelligencePriority?: number;
132
+ };
133
+ includeContext?: 'none' | 'thisServer' | 'allServers';
134
+ metadata?: Record<string, unknown>;
135
+ }
136
+ export interface McpCreateMessageResult {
137
+ role: 'assistant';
138
+ content: McpContentBlock;
139
+ model: string;
140
+ stopReason?: string;
141
+ }
142
+ /** Params of a server-initiated `elicitation/create` (ask the user for input). */
143
+ export interface McpElicitRequestParams {
144
+ message: string;
145
+ requestedSchema: Record<string, unknown>;
146
+ }
147
+ export interface McpElicitResult {
148
+ action: 'accept' | 'decline' | 'cancel';
149
+ content?: Record<string, unknown>;
150
+ }
151
+ /** A filesystem root we expose to the server (`roots/list`). */
152
+ export interface McpRoot {
153
+ uri: string;
154
+ name?: string;
155
+ }
156
+ export type McpTaskStatus = 'working' | 'input_required' | 'completed' | 'failed' | 'cancelled';
157
+ export interface McpTask {
158
+ taskId: string;
159
+ status: McpTaskStatus;
160
+ /** ms to keep results after completion; null = unlimited. */
161
+ ttl: number | null;
162
+ createdAt: string;
163
+ lastUpdatedAt: string;
164
+ /** Suggested poll interval (ms). */
165
+ pollInterval?: number;
166
+ statusMessage?: string;
167
+ }
168
+ /** Request augmentation: include on a `tools/call` to run it as a task. */
169
+ export interface McpTaskMetadata {
170
+ ttl?: number;
171
+ }
172
+ export interface McpServerInfo {
173
+ name: string;
174
+ version: string;
175
+ title?: string;
176
+ }
177
+ export interface McpInitializeResult {
178
+ protocolVersion: string;
179
+ capabilities: Record<string, unknown>;
180
+ serverInfo: McpServerInfo;
181
+ instructions?: string;
182
+ }
183
+ export interface McpHttpConfig {
184
+ /** Streamable-HTTP MCP endpoint URL. Cross-env (browser needs server CORS). */
185
+ url: string;
186
+ /** Extra headers (e.g. `Authorization: Bearer …`). */
187
+ headers?: Record<string, string>;
188
+ /** Short label for tool namespacing + telemetry. Default: the URL host. */
189
+ name?: string;
190
+ }
191
+ export interface McpStdioConfig {
192
+ /** Command to spawn (stdio transport — Node/Bun only). */
193
+ command: string;
194
+ args?: string[];
195
+ env?: Record<string, string>;
196
+ cwd?: string;
197
+ /** Short label for tool namespacing. Default: the command basename. */
198
+ name?: string;
199
+ }
200
+ export type McpServerConfig = McpHttpConfig | McpStdioConfig;
201
+ /** Discriminate the two config variants by the presence of `url`. */
202
+ export declare function isHttpConfig(c: McpServerConfig): c is McpHttpConfig;
@@ -0,0 +1,70 @@
1
+ /** SSRF guard for OAuth/MCP discovered endpoints.
2
+ *
3
+ * All URLs derived from server-controlled discovery metadata (authorization_endpoint,
4
+ * token_endpoint, registration_endpoint, the issuer URL itself) MUST pass
5
+ * `assertSafeAuthUrl` before any fetch is made through the engine.
6
+ *
7
+ * Secure by default:
8
+ * - Only `https:` is allowed (opt-in `allowInsecureHttp` for explicit local-dev only).
9
+ * - Loopback / link-local / private / reserved hosts are blocked by default
10
+ * (opt-in `allowLoopback` for explicit local-dev only).
11
+ * - The discovered endpoint must be same-origin as the issuer unless the caller
12
+ * supplies an explicit `allowedHosts` allowlist.
13
+ *
14
+ * Cross-env: pure URL / IP-literal parsing only — no DNS, no node: imports. */
15
+ /** Options that relax the SSRF guard. All fields default to the most restrictive
16
+ * posture. Escape hatches are intentionally verbose to signal risk at the call site. */
17
+ export interface SsrfGuardOptions {
18
+ /**
19
+ * When set, a discovered endpoint is accepted if its hostname matches ANY entry
20
+ * in this list (case-insensitive, exact match on the registered domain / host).
21
+ * Without this, same-origin with the issuer is enforced.
22
+ *
23
+ * Use this for real IdPs hosted on a separate domain from the MCP server
24
+ * (e.g. issuer = `https://api.example.com`, auth server = `https://auth.example.com`).
25
+ */
26
+ allowedHosts?: readonly string[];
27
+ /**
28
+ * Set to `true` ONLY for explicit local development to allow `http:` scheme.
29
+ * NEVER set in production. Defaults to `false`.
30
+ */
31
+ allowInsecureHttp?: boolean;
32
+ /**
33
+ * Set to `true` ONLY for explicit local development to allow loopback addresses
34
+ * (localhost, 127.x, ::1) and private/reserved ranges.
35
+ * NEVER set in production. Defaults to `false`.
36
+ */
37
+ allowLoopback?: boolean;
38
+ }
39
+ /** Thrown when a server-controlled URL fails the SSRF safety check. */
40
+ export declare class McpSsrfError extends Error {
41
+ /** The offending URL (as a string). */
42
+ readonly url: string;
43
+ /** Human-readable reason the URL was blocked. */
44
+ readonly reason: string;
45
+ constructor(url: string, reason: string);
46
+ }
47
+ /** Canonical IPv4 parser: accepts 1-, 2-, 3-, and 4-part forms with each part
48
+ * in decimal, octal (0-prefix), or hex (0x-prefix). Converts to 4 octets.
49
+ *
50
+ * RFC 3986 / POSIX inet_aton support these short forms:
51
+ * 1-part: entire address as a 32-bit integer (e.g. 2130706433 = 127.0.0.1)
52
+ * 2-part: first octet + 24-bit remainder (e.g. 127.1 = 127.0.0.1)
53
+ * 3-part: first two octets + 16-bit remainder
54
+ * 4-part: standard dotted-decimal / hex / octal
55
+ *
56
+ * Returns null if the host is not a parseable IPv4 literal (e.g. a hostname). */
57
+ export declare function parseCanonicalIpv4(host: string): [number, number, number, number] | null;
58
+ /**
59
+ * Assert that `url` is safe to use as a server-controlled OAuth endpoint.
60
+ *
61
+ * Throws `McpSsrfError` if any check fails:
62
+ * 1. Scheme must be `https:` (unless `opts.allowInsecureHttp` is explicitly `true`).
63
+ * 2. Host must not be loopback / private / reserved (unless `opts.allowLoopback` is explicitly `true`).
64
+ * 3. Host must be same-origin as `issuerUrl` OR match one of `opts.allowedHosts`.
65
+ *
66
+ * @param url The discovered/auth endpoint URL to validate.
67
+ * @param issuerUrl The MCP server's base URL (the trusted origin anchor).
68
+ * @param opts Security options — all default to the most restrictive posture.
69
+ */
70
+ export declare function assertSafeAuthUrl(url: string, issuerUrl: string, opts?: SsrfGuardOptions): void;
@@ -0,0 +1,20 @@
1
+ /** Windows command resolution + escaping for spawning stdio MCP servers.
2
+ *
3
+ * Bare commands like `npx`/`uvx` are `.cmd` shims on Windows; spawning them
4
+ * directly throws ENOENT, and a blanket `shell:true` is a quoting/injection
5
+ * risk. This replicates the essential `cross-spawn` behavior (zero-dep):
6
+ * resolve the real file via PATH+PATHEXT, and route `.cmd`/`.bat` through
7
+ * `cmd.exe /d /s /c "<escaped command line>"` with verbatim args. No-op off
8
+ * Windows. The pure functions take an `exists` probe so they're testable. */
9
+ export interface SpawnPlan {
10
+ file: string;
11
+ args: string[];
12
+ /** -> spawn options.windowsVerbatimArguments. */
13
+ verbatim: boolean;
14
+ }
15
+ /** Quote one argument per Windows `CommandLineToArgvW` rules. */
16
+ export declare function quoteWinArg(arg: string): string;
17
+ /** Caret-escape cmd.exe metacharacters. */
18
+ export declare function escapeCmdMeta(s: string): string;
19
+ /** Plan how to spawn `command args` on Windows. */
20
+ export declare function windowsSpawnPlan(command: string, args: string[], env: Record<string, string | undefined>, exists: (p: string) => boolean): SpawnPlan;
@@ -0,0 +1,24 @@
1
+ /** FileMediaStore — stores media binary files + JSON metadata on disk. */
2
+ import type { MediaMeta, MediaStore, MediaType } from './types';
3
+ export interface FileMediaStoreConfig {
4
+ /** Directory under which media files + meta JSON go. */
5
+ dir: string;
6
+ }
7
+ export declare class FileMediaStore implements MediaStore {
8
+ private ready;
9
+ private readonly dir;
10
+ constructor(config: FileMediaStoreConfig);
11
+ save(id: string, data: Uint8Array, meta: MediaMeta): Promise<void>;
12
+ load(id: string): Promise<{
13
+ data: Uint8Array;
14
+ meta: MediaMeta;
15
+ } | null>;
16
+ getMeta(id: string): Promise<MediaMeta | null>;
17
+ delete(id: string): Promise<void>;
18
+ list(filter?: {
19
+ type?: MediaType;
20
+ provider?: string;
21
+ }): Promise<string[]>;
22
+ has(id: string): Promise<boolean>;
23
+ private ensureDir;
24
+ }
@@ -0,0 +1,17 @@
1
+ /** In-memory MediaStore. Test default; data is lost on process exit. */
2
+ import type { MediaMeta, MediaStore, MediaType } from './types';
3
+ export declare class MemoryMediaStore implements MediaStore {
4
+ private entries;
5
+ save(id: string, data: Uint8Array, meta: MediaMeta): Promise<void>;
6
+ load(id: string): Promise<{
7
+ data: Uint8Array;
8
+ meta: MediaMeta;
9
+ } | null>;
10
+ getMeta(id: string): Promise<MediaMeta | null>;
11
+ delete(id: string): Promise<void>;
12
+ list(filter?: {
13
+ type?: MediaType;
14
+ provider?: string;
15
+ }): Promise<string[]>;
16
+ has(id: string): Promise<boolean>;
17
+ }
@@ -0,0 +1,44 @@
1
+ /** MediaOutput — separate-endpoint media generation (images, audio, video).
2
+ *
3
+ * All HTTP calls flow through an injected EngineFetch (NetworkEngine queue).
4
+ * Persists raw bytes to MediaStore, emits onMediaGenerated (which carries
5
+ * cost-relevant metadata for CostCollector to price). Inline media (e.g.
6
+ * Google generateContent images, OpenAI image_generation tool) is handled
7
+ * by core LLM adapters + an onCompletion subscriber, NOT this class. */
8
+ import type { HookBus } from '../../bus/hook-bus';
9
+ import type { EngineFetch } from '../../network/types';
10
+ import type { ModelCatalog } from '../model-catalog/catalog';
11
+ import { type AudioGenRequest, type ImageEditRequest, type ImageGenRequest, type MediaOutputConfig, type MediaProviderAdapter, type MediaResult, type MediaStore, type VideoGenRequest } from './types';
12
+ export interface MediaOutputInit {
13
+ hooks: HookBus;
14
+ mediaStore: MediaStore;
15
+ /** Network fetch — all adapter HTTP goes through this so calls flow through
16
+ * the NetworkEngine queue (rate-limit, retry, hooks). Typically engine.fetch. */
17
+ fetch: EngineFetch;
18
+ providers?: Map<string, MediaProviderAdapter>;
19
+ catalog?: ModelCatalog;
20
+ config?: MediaOutputConfig;
21
+ /** Trace session id (engine.sessionId); each op mints its own requestId. */
22
+ sessionId?: string;
23
+ }
24
+ export declare class MediaOutput {
25
+ private hooks;
26
+ private mediaStore;
27
+ private fetch;
28
+ private providers;
29
+ private catalog;
30
+ private pollIntervalMs;
31
+ private maxPollWaitMs;
32
+ private sessionId?;
33
+ constructor(init: MediaOutputInit);
34
+ /** Mint a trace + a fetch that stamps it onto every request this op makes. */
35
+ private tracedOp;
36
+ registerProvider(name: string, adapter: MediaProviderAdapter): void;
37
+ generateImage(req: ImageGenRequest): Promise<MediaResult[]>;
38
+ editImage(req: ImageEditRequest): Promise<MediaResult[]>;
39
+ generateAudio(req: AudioGenRequest): Promise<MediaResult>;
40
+ generateVideo(req: VideoGenRequest): Promise<MediaResult>;
41
+ private getAdapter;
42
+ private saveResults;
43
+ private pollVideoCompletion;
44
+ }
@@ -0,0 +1,36 @@
1
+ /** Source/reference image handling for media edit + image-to-video.
2
+ *
3
+ * Normalizes a DataSource (base64 / buffer / url / file-id) into a neutral
4
+ * shape, then each provider adapter maps it to its own wire field:
5
+ * - OpenAI: `{ image_url }` (data-URL) or `{ file_id }`
6
+ * - xAI: `{ url }` (data-URL) or `{ file_id }`
7
+ * - Google: `inline_data {mime_type,data}` or `file_data {file_uri}` */
8
+ import type { DataSource } from '../../llm/types/messages';
9
+ export interface NormalizedImageRef {
10
+ /** Raw base64 (no `data:` prefix), when inline. */
11
+ base64?: string;
12
+ mimeType?: string;
13
+ /** A remote URL, when the source is a URL. */
14
+ url?: string;
15
+ /** A provider Files-API id, when the source is an uploaded file. */
16
+ fileId?: string;
17
+ }
18
+ /** Collapse any DataSource into base64 / url / fileId. The declared mime is
19
+ * cross-checked against the actual bytes (and corrected on mismatch) so a
20
+ * mislabeled source image — e.g. JPEG bytes tagged "image/png" — doesn't get
21
+ * rejected by strict validators downstream (Google Veo, OpenAI edits). */
22
+ export declare function normalizeImageSource(src: DataSource): NormalizedImageRef;
23
+ /** Build a `data:<mime>;base64,…` URL (or pass a plain URL through). */
24
+ export declare function toDataUrl(ref: NormalizedImageRef): string;
25
+ /** OpenAI image-ref object (`/v1/images/edits` images[], video input_reference). */
26
+ export declare function openaiImageRef(ref: NormalizedImageRef): Record<string, string>;
27
+ /** xAI image-ref object (`/v1/images/edits` image, video image). */
28
+ export declare function xaiImageRef(ref: NormalizedImageRef): Record<string, string>;
29
+ /** Google generateContent image part (inline base64 or Files-API file_uri). */
30
+ export declare function googleImagePart(ref: NormalizedImageRef): Record<string, unknown>;
31
+ /** Google Veo instance image (`:predictLongRunning` instances[].image).
32
+ * The predict API uses the Image proto — `bytesBase64Encoded` + `mimeType` —
33
+ * NOT the `inlineData` shape of generateContent (Veo rejects inlineData with a
34
+ * 400). The Gemini Developer API accepts only inline bytes here (no gcsUri /
35
+ * file URI), so the URL fallback exists for Vertex-style callers only. */
36
+ export declare function googleVeoImage(ref: NormalizedImageRef): Record<string, unknown>;