@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.
- package/CHANGELOG.md +19 -0
- package/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/agent/approval-types.d.ts +49 -0
- package/dist/agent/context-registry/layers.d.ts +39 -0
- package/dist/agent/context-registry/registry-internal.d.ts +14 -0
- package/dist/agent/context-registry/registry.d.ts +104 -0
- package/dist/agent/context-registry/types.d.ts +110 -0
- package/dist/agent/guardrail-types.d.ts +58 -0
- package/dist/agent/history-types.d.ts +40 -0
- package/dist/agent/history.d.ts +111 -0
- package/dist/agent/loop-config.d.ts +67 -0
- package/dist/agent/loop-internals.d.ts +46 -0
- package/dist/agent/loop-step-state.d.ts +20 -0
- package/dist/agent/loop.d.ts +133 -0
- package/dist/agent/tool-key.d.ts +3 -0
- package/dist/agent/types.d.ts +138 -0
- package/dist/bus/agent-bus.d.ts +99 -0
- package/dist/bus/async-context.browser.d.ts +13 -0
- package/dist/bus/async-context.d.ts +11 -0
- package/dist/bus/async-context.types.d.ts +14 -0
- package/dist/bus/hook-bus.d.ts +43 -0
- package/dist/bus/hook-map.d.ts +592 -0
- package/dist/helpers/agent.d.ts +32 -0
- package/dist/helpers/batch.d.ts +74 -0
- package/dist/helpers/calibration-store.d.ts +27 -0
- package/dist/helpers/calibration-types.d.ts +64 -0
- package/dist/helpers/chain.d.ts +30 -0
- package/dist/helpers/client-pool.d.ts +15 -0
- package/dist/helpers/client-resolver.d.ts +62 -0
- package/dist/helpers/collection.d.ts +19 -0
- package/dist/helpers/consolidate.d.ts +66 -0
- package/dist/helpers/content.d.ts +25 -0
- package/dist/helpers/conversation-export.d.ts +14 -0
- package/dist/helpers/conversation-zip.d.ts +28 -0
- package/dist/helpers/count-tokens.d.ts +26 -0
- package/dist/helpers/define-tool.d.ts +66 -0
- package/dist/helpers/delegate.d.ts +6 -0
- package/dist/helpers/embed.d.ts +24 -0
- package/dist/helpers/engine.d.ts +121 -0
- package/dist/helpers/estimate-types.d.ts +67 -0
- package/dist/helpers/estimate.d.ts +45 -0
- package/dist/helpers/estimator.d.ts +48 -0
- package/dist/helpers/handoff-types.d.ts +18 -0
- package/dist/helpers/handoff.d.ts +14 -0
- package/dist/helpers/llm.d.ts +24 -0
- package/dist/helpers/mcp.d.ts +82 -0
- package/dist/helpers/media.d.ts +58 -0
- package/dist/helpers/models.d.ts +36 -0
- package/dist/helpers/moderate-types.d.ts +73 -0
- package/dist/helpers/moderate.d.ts +13 -0
- package/dist/helpers/moderation-guardrail.d.ts +29 -0
- package/dist/helpers/observer.d.ts +36 -0
- package/dist/helpers/one-shot.d.ts +86 -0
- package/dist/helpers/parallel.d.ts +16 -0
- package/dist/helpers/realtime.d.ts +25 -0
- package/dist/helpers/route.d.ts +29 -0
- package/dist/helpers/select-model.d.ts +41 -0
- package/dist/helpers/server.d.ts +32 -0
- package/dist/helpers/transcribe.d.ts +36 -0
- package/dist/index.browser.js +38047 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +37974 -0
- package/dist/llm/audio/voices.d.ts +7 -0
- package/dist/llm/client-config.d.ts +37 -0
- package/dist/llm/client-internal.d.ts +28 -0
- package/dist/llm/client.d.ts +68 -0
- package/dist/llm/providers/_shared/constants.d.ts +5 -0
- package/dist/llm/providers/_shared/response-utils.d.ts +8 -0
- package/dist/llm/providers/anthropic/batch.d.ts +19 -0
- package/dist/llm/providers/anthropic/constants.d.ts +13 -0
- package/dist/llm/providers/anthropic/files.d.ts +23 -0
- package/dist/llm/providers/anthropic/messages.d.ts +30 -0
- package/dist/llm/providers/google/batch.d.ts +20 -0
- package/dist/llm/providers/google/constants.d.ts +6 -0
- package/dist/llm/providers/google/embeddings.d.ts +15 -0
- package/dist/llm/providers/google/files.d.ts +22 -0
- package/dist/llm/providers/google/generate.d.ts +27 -0
- package/dist/llm/providers/google/interactions.d.ts +30 -0
- package/dist/llm/providers/google/media.d.ts +27 -0
- package/dist/llm/providers/google/realtime.d.ts +27 -0
- package/dist/llm/providers/openai/batch.d.ts +19 -0
- package/dist/llm/providers/openai/completions.d.ts +25 -0
- package/dist/llm/providers/openai/embeddings.d.ts +16 -0
- package/dist/llm/providers/openai/files.d.ts +23 -0
- package/dist/llm/providers/openai/media.d.ts +28 -0
- package/dist/llm/providers/openai/moderations.d.ts +19 -0
- package/dist/llm/providers/openai/realtime.d.ts +24 -0
- package/dist/llm/providers/openai/responses.d.ts +29 -0
- package/dist/llm/providers/openai/tiers.d.ts +13 -0
- package/dist/llm/providers/openai/transcription.d.ts +20 -0
- package/dist/llm/providers/openrouter/completions.d.ts +15 -0
- package/dist/llm/providers/openrouter/embeddings.d.ts +7 -0
- package/dist/llm/providers/openrouter/media.d.ts +25 -0
- package/dist/llm/providers/openrouter/responses.d.ts +17 -0
- package/dist/llm/providers/xai/batch.d.ts +19 -0
- package/dist/llm/providers/xai/completions.d.ts +24 -0
- package/dist/llm/providers/xai/files.d.ts +23 -0
- package/dist/llm/providers/xai/media.d.ts +27 -0
- package/dist/llm/providers/xai/responses.d.ts +20 -0
- package/dist/llm/realtime/session.d.ts +34 -0
- package/dist/llm/realtime/types.d.ts +66 -0
- package/dist/llm/server-state.d.ts +32 -0
- package/dist/llm/types/audio.d.ts +18 -0
- package/dist/llm/types/messages.d.ts +125 -0
- package/dist/llm/types/options.d.ts +51 -0
- package/dist/llm/types/provider.d.ts +39 -0
- package/dist/llm/types/request.d.ts +51 -0
- package/dist/llm/types/response.d.ts +36 -0
- package/dist/llm/types/schema-utils.d.ts +8 -0
- package/dist/llm/types/stream.d.ts +42 -0
- package/dist/llm/types/tiers.d.ts +11 -0
- package/dist/llm/types/tools.d.ts +20 -0
- package/dist/network/engine.d.ts +87 -0
- package/dist/network/errors.d.ts +14 -0
- package/dist/network/queue-state-config.d.ts +41 -0
- package/dist/network/queue-state.d.ts +45 -0
- package/dist/network/rate-limiter.d.ts +49 -0
- package/dist/network/realtime-connection.d.ts +40 -0
- package/dist/network/request-queue.d.ts +40 -0
- package/dist/network/semaphore.d.ts +12 -0
- package/dist/network/sse.d.ts +3 -0
- package/dist/network/types.d.ts +127 -0
- package/dist/plugins/batch/batcher.d.ts +45 -0
- package/dist/plugins/batch/strategy.d.ts +20 -0
- package/dist/plugins/batch/types.d.ts +54 -0
- package/dist/plugins/cache/cache.d.ts +50 -0
- package/dist/plugins/cache/file-store.d.ts +15 -0
- package/dist/plugins/cache/memory-store.d.ts +10 -0
- package/dist/plugins/cache/types.d.ts +28 -0
- package/dist/plugins/configuration/configuration.d.ts +71 -0
- package/dist/plugins/context-guard/facts.d.ts +14 -0
- package/dist/plugins/context-guard/guard.d.ts +27 -0
- package/dist/plugins/context-guard/strategies/layered.d.ts +24 -0
- package/dist/plugins/context-guard/strategies/truncate.d.ts +19 -0
- package/dist/plugins/context-guard/tools.d.ts +50 -0
- package/dist/plugins/context-guard/types.d.ts +110 -0
- package/dist/plugins/context-measurer/calibration/store.d.ts +19 -0
- package/dist/plugins/context-measurer/counter/count-api.d.ts +41 -0
- package/dist/plugins/context-measurer/counter/heuristic.d.ts +25 -0
- package/dist/plugins/context-measurer/counter/hybrid.d.ts +33 -0
- package/dist/plugins/context-measurer/counter/tiktoken.d.ts +13 -0
- package/dist/plugins/context-measurer/measurer.d.ts +49 -0
- package/dist/plugins/context-measurer/types.d.ts +40 -0
- package/dist/plugins/cost-collector/collector.d.ts +42 -0
- package/dist/plugins/cost-collector/cost-collector-internal.d.ts +58 -0
- package/dist/plugins/cost-collector/cost-collector-types.d.ts +42 -0
- package/dist/plugins/embeddings/types.d.ts +23 -0
- package/dist/plugins/files/attachment.d.ts +79 -0
- package/dist/plugins/files/provider-adapter.d.ts +37 -0
- package/dist/plugins/files/registry.d.ts +48 -0
- package/dist/plugins/files/strategy.d.ts +38 -0
- package/dist/plugins/internal-tools/backends/local.d.ts +12 -0
- package/dist/plugins/internal-tools/builtin/builtin.d.ts +21 -0
- package/dist/plugins/internal-tools/builtin/clarify.d.ts +12 -0
- package/dist/plugins/internal-tools/builtin/classify.d.ts +12 -0
- package/dist/plugins/internal-tools/builtin/score.d.ts +13 -0
- package/dist/plugins/internal-tools/builtin/structure.d.ts +11 -0
- package/dist/plugins/internal-tools/builtin/summarize.d.ts +19 -0
- package/dist/plugins/internal-tools/id.d.ts +12 -0
- package/dist/plugins/internal-tools/registry.d.ts +24 -0
- package/dist/plugins/internal-tools/runner/define.d.ts +7 -0
- package/dist/plugins/internal-tools/runner/json-enforcement.d.ts +3 -0
- package/dist/plugins/internal-tools/runner/runner.d.ts +47 -0
- package/dist/plugins/internal-tools/runner/template.d.ts +10 -0
- package/dist/plugins/internal-tools/runner/types.d.ts +57 -0
- package/dist/plugins/internal-tools/runner/variants.d.ts +34 -0
- package/dist/plugins/internal-tools/types.d.ts +80 -0
- package/dist/plugins/logger/console-sink.d.ts +26 -0
- package/dist/plugins/logger/logger.d.ts +38 -0
- package/dist/plugins/logger/types.d.ts +25 -0
- package/dist/plugins/mcp/base-transport.d.ts +58 -0
- package/dist/plugins/mcp/client.d.ts +92 -0
- package/dist/plugins/mcp/jsonrpc.d.ts +20 -0
- package/dist/plugins/mcp/oauth.d.ts +122 -0
- package/dist/plugins/mcp/sampling.d.ts +17 -0
- package/dist/plugins/mcp/tools.d.ts +20 -0
- package/dist/plugins/mcp/transport-http.d.ts +50 -0
- package/dist/plugins/mcp/transport-stdio.d.ts +23 -0
- package/dist/plugins/mcp/transport-ws.d.ts +32 -0
- package/dist/plugins/mcp/transport.d.ts +29 -0
- package/dist/plugins/mcp/types.d.ts +202 -0
- package/dist/plugins/mcp/url-guard.d.ts +70 -0
- package/dist/plugins/mcp/win-spawn.d.ts +20 -0
- package/dist/plugins/media/file-store.d.ts +24 -0
- package/dist/plugins/media/memory-store.d.ts +17 -0
- package/dist/plugins/media/output.d.ts +44 -0
- package/dist/plugins/media/source-image.d.ts +36 -0
- package/dist/plugins/media/types.d.ts +146 -0
- package/dist/plugins/model-catalog/catalog.d.ts +152 -0
- package/dist/plugins/permissions/glob.d.ts +6 -0
- package/dist/plugins/permissions/matchers.d.ts +7 -0
- package/dist/plugins/permissions/policy.d.ts +10 -0
- package/dist/plugins/permissions/types.d.ts +22 -0
- package/dist/plugins/persistence/file.d.ts +25 -0
- package/dist/plugins/persistence/memory.d.ts +23 -0
- package/dist/plugins/persistence/types.d.ts +21 -0
- package/dist/plugins/retrieval/chunker.d.ts +28 -0
- package/dist/plugins/retrieval/hosted-google.d.ts +60 -0
- package/dist/plugins/retrieval/hosted-openai.d.ts +45 -0
- package/dist/plugins/retrieval/hosted-xai.d.ts +57 -0
- package/dist/plugins/retrieval/index.d.ts +70 -0
- package/dist/plugins/retrieval/local.d.ts +50 -0
- package/dist/plugins/retrieval/types.d.ts +161 -0
- package/dist/plugins/retrieval/vector-store.d.ts +70 -0
- package/dist/plugins/scheduler/scheduler.d.ts +31 -0
- package/dist/plugins/telemetry/telemetry.d.ts +118 -0
- package/dist/plugins/tool-catalog/catalog.d.ts +31 -0
- package/dist/plugins/tool-catalog/errors.d.ts +22 -0
- package/dist/plugins/tool-catalog/types.d.ts +44 -0
- package/dist/runtime/runtime.d.ts +20 -0
- package/dist/server/auth.d.ts +25 -0
- package/dist/server/dispatch.d.ts +35 -0
- package/dist/server/loaders.d.ts +26 -0
- package/dist/server/oai-adapter.d.ts +30 -0
- package/dist/server/oai-types.d.ts +114 -0
- package/dist/server/response-store.d.ts +59 -0
- package/dist/server/router.d.ts +59 -0
- package/dist/server/server.d.ts +61 -0
- package/dist/types/request-context.d.ts +46 -0
- package/dist/util/async.d.ts +3 -0
- package/dist/util/base64.d.ts +8 -0
- package/dist/util/duration.d.ts +12 -0
- package/dist/util/http.d.ts +9 -0
- package/dist/util/image-mime.d.ts +8 -0
- package/dist/util/json-schema.d.ts +7 -0
- package/dist/util/wav.d.ts +20 -0
- package/package.json +95 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Hybrid voice resolution (A3): a small per-provider alias table maps a unified
|
|
2
|
+
* alias to that provider's voice id; any unrecognized string passes through
|
|
3
|
+
* unchanged, so raw provider voice ids always work. */
|
|
4
|
+
export declare const VOICE_ALIASES_LIST: readonly ["neutral", "warm", "bright", "deep"];
|
|
5
|
+
export type VoiceAlias = (typeof VOICE_ALIASES_LIST)[number];
|
|
6
|
+
/** Map an alias to the provider's voice id, else return the input unchanged. */
|
|
7
|
+
export declare function resolveVoice(provider: string, voice: string | undefined): string | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** LLMClient configuration types. */
|
|
2
|
+
import type { HookBus } from '../bus/hook-bus';
|
|
3
|
+
import type { EngineFetch, EngineFetchStream } from '../network/types';
|
|
4
|
+
import type { ModelCatalog } from '../plugins/model-catalog/catalog';
|
|
5
|
+
import type { RequestContext } from '../types/request-context';
|
|
6
|
+
import type { ApiType, ProviderAdapter, ProviderName } from './types/provider';
|
|
7
|
+
import type { NormalizedRequest } from './types/request';
|
|
8
|
+
/** Function that builds a ProviderAdapter for a (provider, apiKey, api, baseURL). */
|
|
9
|
+
export type AdapterFactory = (provider: ProviderName, apiKey: string, api: ApiType, baseURL?: string) => ProviderAdapter;
|
|
10
|
+
export interface LLMClientConfig {
|
|
11
|
+
provider: ProviderName;
|
|
12
|
+
model: string;
|
|
13
|
+
apiKey: string;
|
|
14
|
+
system?: string;
|
|
15
|
+
baseURL?: string;
|
|
16
|
+
/** Trace session id. createLLM passes `engine.sessionId`; a standalone client
|
|
17
|
+
* mints its own. Flows onto every RequestContext built by this client. */
|
|
18
|
+
sessionId?: string;
|
|
19
|
+
hooks?: HookBus;
|
|
20
|
+
fetch?: EngineFetch;
|
|
21
|
+
fetchStream?: EngineFetchStream;
|
|
22
|
+
/** Provider adapter factory. createLLM supplies a default;
|
|
23
|
+
* here you can also pass a pre-built adapter or a custom factory for tests. */
|
|
24
|
+
adapter?: ProviderAdapter | AdapterFactory;
|
|
25
|
+
queueName?: string;
|
|
26
|
+
configName?: string;
|
|
27
|
+
cacheName?: string;
|
|
28
|
+
cacheKeyFn?: (req: NormalizedRequest, ctx: RequestContext) => string;
|
|
29
|
+
api?: ApiType | 'auto';
|
|
30
|
+
mode?: 'foreground' | 'background';
|
|
31
|
+
batchable?: boolean;
|
|
32
|
+
priority?: number;
|
|
33
|
+
/** Model catalog — source of truth for server-state retention / model-binding.
|
|
34
|
+
* createLLM supplies `engine.catalog`. An empty catalog still yields correct
|
|
35
|
+
* provider-level defaults, so this is optional. */
|
|
36
|
+
catalog?: ModelCatalog;
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** LLMClient internals — request normalization, system extraction, context
|
|
2
|
+
* building, provider/adapter resolution, and structured-output parsing.
|
|
3
|
+
* Split out of client.ts to keep the class file focused on the public surface. */
|
|
4
|
+
import type { RequestContext } from '../types/request-context';
|
|
5
|
+
import type { LLMClient } from './client';
|
|
6
|
+
import type { LLMClientConfig } from './client-config';
|
|
7
|
+
import type { ContentPart, Message } from './types/messages';
|
|
8
|
+
import type { ExecuteOptions } from './types/options';
|
|
9
|
+
import type { ApiType, ProviderAdapter, ProviderName } from './types/provider';
|
|
10
|
+
export declare const PRIORITY_INTERACTIVE = 1;
|
|
11
|
+
export declare const PRIORITY_BACKGROUND = 2;
|
|
12
|
+
export declare function normalizeInput(input: string | ContentPart[] | Message[]): Message[];
|
|
13
|
+
/** Lift any role:'system' messages out of the input array.
|
|
14
|
+
* Anthropic and some other providers expect `system` as a top-level
|
|
15
|
+
* parameter, not as a message role. By extracting here in the client we
|
|
16
|
+
* give callers a single, provider-neutral way to set per-call system text:
|
|
17
|
+
* either pass `options.system`, or include role:'system' messages in the
|
|
18
|
+
* input (they get concatenated). Adapters never see role:'system'. */
|
|
19
|
+
export declare function extractSystem(messages: Message[]): {
|
|
20
|
+
system?: string;
|
|
21
|
+
messages: Message[];
|
|
22
|
+
};
|
|
23
|
+
/** Strip leading/trailing markdown fences and JSON.parse. Exported so AgentLoop
|
|
24
|
+
* + helper can share the same parsing rules. */
|
|
25
|
+
export declare function parseStructured<T>(text: string): T;
|
|
26
|
+
export declare function buildContext(client: LLMClient, options: ExecuteOptions): RequestContext;
|
|
27
|
+
export declare function resolveApi(provider: ProviderName, api?: ApiType | 'auto'): ApiType;
|
|
28
|
+
export declare function resolveAdapter(config: LLMClientConfig, api: ApiType): ProviderAdapter;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** LLMClient — Layer 2.
|
|
2
|
+
*
|
|
3
|
+
* Format adapter only. Does NOT own a queue, retry policy, or cache.
|
|
4
|
+
* Receives `fetch` (and optionally `fetchStream`) as injected functions.
|
|
5
|
+
* The semantic layer is fixed at construction:
|
|
6
|
+
* - `provider` + `model` + `apiKey` + `system` are immutable per instance.
|
|
7
|
+
*
|
|
8
|
+
* Public methods:
|
|
9
|
+
* - `complete(input, options?)` → CompletionResponse
|
|
10
|
+
* - `stream(input, options?)` → AsyncIterable<StreamEvent>
|
|
11
|
+
* - `destroy()` → emit lifecycle hook
|
|
12
|
+
*
|
|
13
|
+
* Input shapes (`string | ContentPart[] | Message[]`):
|
|
14
|
+
* - `string` → wrap as `[{role:'user', content: string}]`
|
|
15
|
+
* - `ContentPart[]` → wrap as `[{role:'user', content: parts}]`
|
|
16
|
+
* - `Message[]` → use as the full messages array (REPLACE)
|
|
17
|
+
*
|
|
18
|
+
* Hooks emitted: onClientCreate (in ctor), onMessageResolve, onBeforeSubmit,
|
|
19
|
+
* onCompletion, onClientDestroy. */
|
|
20
|
+
import type { HookBus } from '../bus/hook-bus';
|
|
21
|
+
import type { ContentPart, Message } from './types/messages';
|
|
22
|
+
import type { ExecuteOptions } from './types/options';
|
|
23
|
+
import type { ApiType, ProviderName } from './types/provider';
|
|
24
|
+
import type { CompletionResponse } from './types/response';
|
|
25
|
+
import type { StreamEvent } from './types/stream';
|
|
26
|
+
import type { LLMClientConfig } from './client-config';
|
|
27
|
+
export declare class LLMClient {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
/** Trace session id (from the engine, or self-minted for a standalone client). */
|
|
30
|
+
readonly sessionId: string;
|
|
31
|
+
readonly provider: ProviderName;
|
|
32
|
+
readonly model: string;
|
|
33
|
+
readonly system: string | undefined;
|
|
34
|
+
readonly hooks: HookBus;
|
|
35
|
+
readonly api: ApiType;
|
|
36
|
+
readonly mode: 'foreground' | 'background';
|
|
37
|
+
readonly batchable: boolean;
|
|
38
|
+
private readonly adapter;
|
|
39
|
+
private readonly fetchFn;
|
|
40
|
+
private readonly fetchStreamFn;
|
|
41
|
+
private readonly priority;
|
|
42
|
+
private readonly queueName;
|
|
43
|
+
private readonly configName;
|
|
44
|
+
private readonly cacheName;
|
|
45
|
+
private readonly cacheKeyFn?;
|
|
46
|
+
private readonly catalog;
|
|
47
|
+
constructor(config: LLMClientConfig);
|
|
48
|
+
destroy(): void;
|
|
49
|
+
/** Build an assistant history message from a response, stamped with provenance
|
|
50
|
+
* (id, createdAt, origin). On a stateful API (responses / interactions) the
|
|
51
|
+
* origin carries the server-state id so a later turn can continue server-side
|
|
52
|
+
* instead of resending the transcript. Push the result into your messages
|
|
53
|
+
* array between turns:
|
|
54
|
+
*
|
|
55
|
+
* const r1 = await llm.complete(messages);
|
|
56
|
+
* messages.push(llm.assistantMessage(r1));
|
|
57
|
+
* messages.push({ role: 'user', content: 'follow-up' });
|
|
58
|
+
* const r2 = await llm.complete(messages); // sends id + only the new turn
|
|
59
|
+
*/
|
|
60
|
+
assistantMessage(response: CompletionResponse): Message;
|
|
61
|
+
/** Submit a request. Returns the parsed CompletionResponse. */
|
|
62
|
+
complete(input: string | ContentPart[] | Message[], options?: ExecuteOptions): Promise<CompletionResponse>;
|
|
63
|
+
/** Run `complete` with a JSON Schema enforced via `structured`. Strips any
|
|
64
|
+
* leading/trailing markdown fences from the model reply, then JSON.parses
|
|
65
|
+
* to T. Throws if the parse fails — callers should catch + retry. */
|
|
66
|
+
structuredComplete<T = unknown>(input: string | ContentPart[] | Message[], schema: Record<string, unknown>, options?: ExecuteOptions): Promise<T>;
|
|
67
|
+
stream(input: string | ContentPart[] | Message[], options?: ExecuteOptions): AsyncIterable<StreamEvent>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Shared constants used across provider adapters. */
|
|
2
|
+
/** PCM16 mono audio sample rate emitted by Gemini Live and OpenAI Realtime. */
|
|
3
|
+
export declare const AUDIO_PCM16_SAMPLE_RATE_HZ = 24000;
|
|
4
|
+
/** Default max_tokens / max_completion_tokens when the caller omits the field. */
|
|
5
|
+
export declare const DEFAULT_MAX_TOKENS = 4096;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Shared response helpers used across provider adapters. */
|
|
2
|
+
import type { FinishReason } from '../../types/response';
|
|
3
|
+
/**
|
|
4
|
+
* Table-driven finish-reason mapper.
|
|
5
|
+
* Returns 'tool_use' when tool calls are present; otherwise looks up the
|
|
6
|
+
* provider's raw reason in reasonMap, falling back to 'stop'.
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractFinishReason(hasToolCalls: boolean, providerReason: string | undefined, reasonMap: Record<string, FinishReason>): FinishReason;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Anthropic batch adapter — POST /v1/messages/batches with inline requests.
|
|
2
|
+
* All HTTP flows through the injected EngineFetch (NetworkEngine queue). */
|
|
3
|
+
import type { EngineFetch } from '../../../network/types';
|
|
4
|
+
import type { BatchProviderAdapter, BatchRequest, BatchResult, BatchStatus } from '../../../plugins/batch/types';
|
|
5
|
+
export interface AnthropicBatchAdapterConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class AnthropicBatchAdapter implements BatchProviderAdapter {
|
|
10
|
+
readonly name = "anthropic";
|
|
11
|
+
private readonly apiKey;
|
|
12
|
+
private readonly baseURL;
|
|
13
|
+
constructor(config: AnthropicBatchAdapterConfig);
|
|
14
|
+
private authHeaders;
|
|
15
|
+
submit(requests: BatchRequest[], fetch: EngineFetch): Promise<string>;
|
|
16
|
+
getStatus(batchId: string, fetch: EngineFetch): Promise<BatchStatus>;
|
|
17
|
+
getResults(batchId: string, fetch: EngineFetch): Promise<BatchResult[]>;
|
|
18
|
+
cancel(batchId: string, fetch: EngineFetch): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Anthropic provider constants. */
|
|
2
|
+
/** The Anthropic API version header sent on every request. */
|
|
3
|
+
export declare const ANTHROPIC_API_VERSION = "2023-06-01";
|
|
4
|
+
/**
|
|
5
|
+
* Token budgets for Anthropic extended thinking by effort level.
|
|
6
|
+
* Used to set budget_tokens in the `thinking` request param.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ANTHROPIC_THINKING_BUDGETS: Record<string, number>;
|
|
9
|
+
/**
|
|
10
|
+
* Budget applied when no effort level is specified or when the level is
|
|
11
|
+
* unrecognised.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_ANTHROPIC_THINKING_BUDGET = 2048;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Anthropic file adapter — POST /v1/files (beta).
|
|
2
|
+
* All HTTP flows through the injected EngineFetch (NetworkEngine queue). */
|
|
3
|
+
import type { EngineFetch } from '../../../network/types';
|
|
4
|
+
import type { FileAttachment } from '../../../plugins/files/attachment';
|
|
5
|
+
import type { FileProviderAdapter, FileUploadResult, RemoteFileInfo } from '../../../plugins/files/provider-adapter';
|
|
6
|
+
export interface AnthropicFileAdapterConfig {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class AnthropicFileAdapter implements FileProviderAdapter {
|
|
11
|
+
readonly name = "anthropic";
|
|
12
|
+
readonly expiresAfter: null;
|
|
13
|
+
readonly maxFileSize = 500000000;
|
|
14
|
+
readonly supportedTypes: string[];
|
|
15
|
+
private readonly apiKey;
|
|
16
|
+
private readonly baseURL;
|
|
17
|
+
constructor(config: AnthropicFileAdapterConfig);
|
|
18
|
+
private authHeaders;
|
|
19
|
+
upload(file: FileAttachment, fetch: EngineFetch): Promise<FileUploadResult>;
|
|
20
|
+
delete(remoteId: string, fetch: EngineFetch): Promise<void>;
|
|
21
|
+
getInfo(remoteId: string, fetch: EngineFetch): Promise<RemoteFileInfo | null>;
|
|
22
|
+
list(fetch: EngineFetch): Promise<RemoteFileInfo[]>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Anthropic provider adapter (Messages API).
|
|
2
|
+
*
|
|
3
|
+
* Ported from llm-sdk verbatim. Only change: takes NormalizedRequest instead
|
|
4
|
+
* of CompletionRequest (same shape, renamed for v2 to reflect it's the
|
|
5
|
+
* internal normalized form LLMClient hands to the adapter). */
|
|
6
|
+
import type { SSEEvent } from '../../../network/types';
|
|
7
|
+
import type { ProviderAdapter, ProviderHttpRequest } from '../../types/provider';
|
|
8
|
+
import type { NormalizedRequest } from '../../types/request';
|
|
9
|
+
import { type CompletionResponse } from '../../types/response';
|
|
10
|
+
import type { StreamEvent } from '../../types/stream';
|
|
11
|
+
export interface AnthropicAdapterConfig {
|
|
12
|
+
apiKey: string;
|
|
13
|
+
baseURL?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class AnthropicAdapter implements ProviderAdapter {
|
|
16
|
+
readonly name: "anthropic";
|
|
17
|
+
protected readonly apiKey: string;
|
|
18
|
+
protected readonly _baseURL?: string;
|
|
19
|
+
constructor(config: AnthropicAdapterConfig);
|
|
20
|
+
authHeaders(): Record<string, string>;
|
|
21
|
+
baseURL(): string;
|
|
22
|
+
completionPath(): string;
|
|
23
|
+
buildRequest(req: NormalizedRequest): ProviderHttpRequest;
|
|
24
|
+
enableStreaming(providerReq: ProviderHttpRequest, _req: NormalizedRequest): void;
|
|
25
|
+
private buildMessage;
|
|
26
|
+
private buildContentPart;
|
|
27
|
+
parseResponse(raw: unknown, latencyMs: number): CompletionResponse;
|
|
28
|
+
parseStreamEvent(event: SSEEvent): StreamEvent[];
|
|
29
|
+
private parseUsage;
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Google batch adapter — inline batchGenerateContent.
|
|
2
|
+
* All HTTP flows through the injected EngineFetch (NetworkEngine queue). */
|
|
3
|
+
import type { EngineFetch } from '../../../network/types';
|
|
4
|
+
import type { BatchProviderAdapter, BatchRequest, BatchResult, BatchStatus } from '../../../plugins/batch/types';
|
|
5
|
+
export interface GoogleBatchAdapterConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
model?: string;
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class GoogleBatchAdapter implements BatchProviderAdapter {
|
|
11
|
+
readonly name = "google";
|
|
12
|
+
private readonly apiKey;
|
|
13
|
+
private readonly model;
|
|
14
|
+
private readonly baseURL;
|
|
15
|
+
constructor(config: GoogleBatchAdapterConfig);
|
|
16
|
+
submit(requests: BatchRequest[], fetch: EngineFetch): Promise<string>;
|
|
17
|
+
getStatus(batchId: string, fetch: EngineFetch): Promise<BatchStatus>;
|
|
18
|
+
getResults(batchId: string, fetch: EngineFetch): Promise<BatchResult[]>;
|
|
19
|
+
cancel(batchId: string, fetch: EngineFetch): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Google embeddings adapter — POST /v1beta/models/{model}:embedContent.
|
|
2
|
+
* One call per input text (batch via a simple loop). */
|
|
3
|
+
import type { EngineFetch } from '../../../network/types';
|
|
4
|
+
import type { EmbedRequest, EmbedResult, EmbeddingProviderAdapter } from '../../../plugins/embeddings/types';
|
|
5
|
+
export interface GoogleEmbeddingAdapterConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class GoogleEmbeddingAdapter implements EmbeddingProviderAdapter {
|
|
10
|
+
readonly name = "google";
|
|
11
|
+
private readonly apiKey;
|
|
12
|
+
private readonly baseURL;
|
|
13
|
+
constructor(config: GoogleEmbeddingAdapterConfig);
|
|
14
|
+
embed(req: EmbedRequest, fetch: EngineFetch): Promise<EmbedResult>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Google file adapter — resumable upload to Files API. 48h auto-delete.
|
|
2
|
+
* All HTTP flows through the injected EngineFetch (NetworkEngine queue). */
|
|
3
|
+
import type { EngineFetch } from '../../../network/types';
|
|
4
|
+
import type { FileAttachment } from '../../../plugins/files/attachment';
|
|
5
|
+
import type { FileProviderAdapter, FileUploadResult, RemoteFileInfo } from '../../../plugins/files/provider-adapter';
|
|
6
|
+
export interface GoogleFileAdapterConfig {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class GoogleFileAdapter implements FileProviderAdapter {
|
|
11
|
+
readonly name = "google";
|
|
12
|
+
readonly expiresAfter: number;
|
|
13
|
+
readonly maxFileSize = 2000000000;
|
|
14
|
+
readonly supportedTypes: null;
|
|
15
|
+
private readonly apiKey;
|
|
16
|
+
private readonly baseURL;
|
|
17
|
+
constructor(config: GoogleFileAdapterConfig);
|
|
18
|
+
upload(file: FileAttachment, fetch: EngineFetch): Promise<FileUploadResult>;
|
|
19
|
+
delete(remoteId: string, fetch: EngineFetch): Promise<void>;
|
|
20
|
+
getInfo(remoteId: string, fetch: EngineFetch): Promise<RemoteFileInfo | null>;
|
|
21
|
+
list(fetch: EngineFetch): Promise<RemoteFileInfo[]>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Google Gemini provider adapter (generateContent API). */
|
|
2
|
+
import type { SSEEvent } from '../../../network/types';
|
|
3
|
+
import type { ProviderAdapter, ProviderHttpRequest } from '../../types/provider';
|
|
4
|
+
import type { NormalizedRequest } from '../../types/request';
|
|
5
|
+
import { type CompletionResponse } from '../../types/response';
|
|
6
|
+
import type { StreamEvent } from '../../types/stream';
|
|
7
|
+
export interface GoogleAdapterConfig {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
baseURL?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class GoogleAdapter implements ProviderAdapter {
|
|
12
|
+
readonly name: "google";
|
|
13
|
+
private readonly apiKey;
|
|
14
|
+
private readonly _baseURL?;
|
|
15
|
+
constructor(config: GoogleAdapterConfig);
|
|
16
|
+
authHeaders(): Record<string, string>;
|
|
17
|
+
baseURL(): string;
|
|
18
|
+
completionPath(): string;
|
|
19
|
+
buildRequest(req: NormalizedRequest): ProviderHttpRequest;
|
|
20
|
+
enableStreaming(providerReq: ProviderHttpRequest, req: NormalizedRequest): void;
|
|
21
|
+
/** Map tool call IDs to function names (Google needs name in functionResponse) */
|
|
22
|
+
private toolCallNames;
|
|
23
|
+
private buildContent;
|
|
24
|
+
parseResponse(raw: unknown, latencyMs: number): CompletionResponse;
|
|
25
|
+
parseStreamEvent(event: SSEEvent): StreamEvent[];
|
|
26
|
+
private parseUsage;
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Google Interactions API adapter.
|
|
2
|
+
* Endpoint: POST /v1beta/interactions
|
|
3
|
+
* Modern API: input, system_instruction, outputs (plural), function_result,
|
|
4
|
+
* previous_interaction_id for stateful, 72h retention. */
|
|
5
|
+
import type { SSEEvent } from '../../../network/types';
|
|
6
|
+
import type { ProviderAdapter, ProviderHttpRequest } from '../../types/provider';
|
|
7
|
+
import type { NormalizedRequest } from '../../types/request';
|
|
8
|
+
import { type CompletionResponse } from '../../types/response';
|
|
9
|
+
import type { StreamEvent } from '../../types/stream';
|
|
10
|
+
export interface GoogleInteractionsAdapterConfig {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
baseURL?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class GoogleInteractionsAdapter implements ProviderAdapter {
|
|
15
|
+
readonly name: "google";
|
|
16
|
+
private readonly apiKey;
|
|
17
|
+
private readonly _baseURL?;
|
|
18
|
+
constructor(config: GoogleInteractionsAdapterConfig);
|
|
19
|
+
authHeaders(): Record<string, string>;
|
|
20
|
+
baseURL(): string;
|
|
21
|
+
completionPath(): string;
|
|
22
|
+
buildRequest(req: NormalizedRequest): ProviderHttpRequest;
|
|
23
|
+
private buildInputItems;
|
|
24
|
+
/** Track tool call IDs → names for function_result */
|
|
25
|
+
private toolCallNames;
|
|
26
|
+
enableStreaming(providerReq: ProviderHttpRequest): void;
|
|
27
|
+
parseResponse(raw: unknown, latencyMs: number): CompletionResponse;
|
|
28
|
+
parseStreamEvent(event: SSEEvent): StreamEvent[];
|
|
29
|
+
private parseUsage;
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Google media adapter — Imagen (:predict) + Veo (:predictLongRunning).
|
|
2
|
+
* All HTTP calls go through an injected EngineFetch (NetworkEngine queue). */
|
|
3
|
+
import type { EngineFetch } from '../../../network/types';
|
|
4
|
+
import type { AudioGenRequest, ImageEditRequest, ImageGenRequest, MediaCapabilities, MediaProviderAdapter, RawMediaResult, VideoGenRequest, VideoStatus } from '../../../plugins/media/types';
|
|
5
|
+
export interface GoogleMediaAdapterConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class GoogleMediaAdapter implements MediaProviderAdapter {
|
|
10
|
+
readonly name = "google";
|
|
11
|
+
private readonly apiKey;
|
|
12
|
+
private readonly baseURL;
|
|
13
|
+
constructor(config: GoogleMediaAdapterConfig);
|
|
14
|
+
capabilities(): MediaCapabilities;
|
|
15
|
+
generateImage(req: ImageGenRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
|
|
16
|
+
generateAudio(req: AudioGenRequest, fetch: EngineFetch): Promise<RawMediaResult>;
|
|
17
|
+
/** Image-to-image edit: gemini generateContent with the source image as an
|
|
18
|
+
* extra inline/file part next to the instruction. */
|
|
19
|
+
editImage(req: ImageEditRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
|
|
20
|
+
/** Shared inline-media path: POST :generateContent and collect inlineData
|
|
21
|
+
* parts + the reported token usage (token-priced media). */
|
|
22
|
+
private generateContentMedia;
|
|
23
|
+
submitVideo(req: VideoGenRequest, fetch: EngineFetch): Promise<string>;
|
|
24
|
+
getVideoStatus(operationId: string, fetch: EngineFetch): Promise<VideoStatus>;
|
|
25
|
+
downloadVideo(operationId: string, fetch: EngineFetch): Promise<RawMediaResult>;
|
|
26
|
+
cancelVideo(operationId: string, fetch: EngineFetch): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Google Gemini Live adapter (Bidi over WebSocket).
|
|
2
|
+
*
|
|
3
|
+
* Wire protocol (extracted from `@google/genai` live.ts):
|
|
4
|
+
* - URL: wss://generativelanguage.googleapis.com/ws/
|
|
5
|
+
* google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent?key=<key>
|
|
6
|
+
* - On open: send { setup: { model: 'models/<model>', generationConfig:
|
|
7
|
+
* { responseModalities } , systemInstruction? } }. Server replies
|
|
8
|
+
* { setupComplete: {} } → only then is the session ready for content.
|
|
9
|
+
* - Send a turn: { clientContent: { turns: [{role:'user',parts:[{text}]}],
|
|
10
|
+
* turnComplete } }.
|
|
11
|
+
* - Server: { serverContent: { modelTurn: { parts: [{text}|{inlineData:
|
|
12
|
+
* {mimeType,data(base64)}}] }, turnComplete? } }.
|
|
13
|
+
*
|
|
14
|
+
* Gemini Live models are audio-native: with responseModalities ['AUDIO'] the
|
|
15
|
+
* parts carry inlineData audio, not text. */
|
|
16
|
+
import type { EngineConnect } from '../../../network/types';
|
|
17
|
+
import type { RealtimeProviderAdapter, RealtimeSession, RealtimeSessionConfig } from '../../realtime/types';
|
|
18
|
+
export interface GoogleRealtimeAdapterConfig {
|
|
19
|
+
apiKey: string;
|
|
20
|
+
baseURL?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class GoogleRealtimeAdapter implements RealtimeProviderAdapter {
|
|
23
|
+
private readonly apiKey;
|
|
24
|
+
private readonly base;
|
|
25
|
+
constructor(config: GoogleRealtimeAdapterConfig);
|
|
26
|
+
connect(config: RealtimeSessionConfig, connect: EngineConnect): RealtimeSession;
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** OpenAI batch adapter — upload JSONL file, create batch, poll, download results.
|
|
2
|
+
* All HTTP flows through the injected EngineFetch (NetworkEngine queue). */
|
|
3
|
+
import type { EngineFetch } from '../../../network/types';
|
|
4
|
+
import type { BatchProviderAdapter, BatchRequest, BatchResult, BatchStatus } from '../../../plugins/batch/types';
|
|
5
|
+
export interface OpenAIBatchAdapterConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class OpenAIBatchAdapter implements BatchProviderAdapter {
|
|
10
|
+
readonly name = "openai";
|
|
11
|
+
private readonly apiKey;
|
|
12
|
+
private readonly baseURL;
|
|
13
|
+
constructor(config: OpenAIBatchAdapterConfig);
|
|
14
|
+
private bearer;
|
|
15
|
+
submit(requests: BatchRequest[], fetch: EngineFetch): Promise<string>;
|
|
16
|
+
getStatus(batchId: string, fetch: EngineFetch): Promise<BatchStatus>;
|
|
17
|
+
getResults(batchId: string, fetch: EngineFetch): Promise<BatchResult[]>;
|
|
18
|
+
cancel(batchId: string, fetch: EngineFetch): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** OpenAI provider adapter (Chat Completions API). */
|
|
2
|
+
import type { SSEEvent } from '../../../network/types';
|
|
3
|
+
import type { ProviderAdapter, ProviderHttpRequest } from '../../types/provider';
|
|
4
|
+
import type { NormalizedRequest } from '../../types/request';
|
|
5
|
+
import { type CompletionResponse } from '../../types/response';
|
|
6
|
+
import type { StreamEvent } from '../../types/stream';
|
|
7
|
+
export interface OpenAIAdapterConfig {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
baseURL?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class OpenAIAdapter implements ProviderAdapter {
|
|
12
|
+
readonly name: ProviderAdapter['name'];
|
|
13
|
+
protected readonly apiKey: string;
|
|
14
|
+
protected readonly _baseURL?: string;
|
|
15
|
+
constructor(config: OpenAIAdapterConfig);
|
|
16
|
+
authHeaders(): Record<string, string>;
|
|
17
|
+
baseURL(): string;
|
|
18
|
+
completionPath(): string;
|
|
19
|
+
buildRequest(req: NormalizedRequest): ProviderHttpRequest;
|
|
20
|
+
private buildMessage;
|
|
21
|
+
enableStreaming(providerReq: ProviderHttpRequest, _req: NormalizedRequest): void;
|
|
22
|
+
parseResponse(raw: unknown, latencyMs: number): CompletionResponse;
|
|
23
|
+
parseStreamEvent(event: SSEEvent): StreamEvent[];
|
|
24
|
+
private parseUsage;
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** OpenAI embeddings adapter — POST /v1/embeddings. Also the base for the
|
|
2
|
+
* OpenAI-compatible OpenRouter adapter. */
|
|
3
|
+
import type { EngineFetch } from '../../../network/types';
|
|
4
|
+
import type { EmbedRequest, EmbedResult, EmbeddingProviderAdapter } from '../../../plugins/embeddings/types';
|
|
5
|
+
export interface OpenAIEmbeddingAdapterConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class OpenAIEmbeddingAdapter implements EmbeddingProviderAdapter {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
protected readonly apiKey: string;
|
|
12
|
+
protected readonly _baseURL: string;
|
|
13
|
+
constructor(config: OpenAIEmbeddingAdapterConfig);
|
|
14
|
+
protected embeddingsPath(): string;
|
|
15
|
+
embed(req: EmbedRequest, fetch: EngineFetch): Promise<EmbedResult>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** OpenAI file adapter — POST /v1/files.
|
|
2
|
+
* All HTTP flows through the injected EngineFetch (NetworkEngine queue). */
|
|
3
|
+
import type { EngineFetch } from '../../../network/types';
|
|
4
|
+
import type { FileAttachment } from '../../../plugins/files/attachment';
|
|
5
|
+
import type { FileProviderAdapter, FileUploadResult, RemoteFileInfo } from '../../../plugins/files/provider-adapter';
|
|
6
|
+
export interface OpenAIFileAdapterConfig {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class OpenAIFileAdapter implements FileProviderAdapter {
|
|
11
|
+
readonly name = "openai";
|
|
12
|
+
readonly expiresAfter: null;
|
|
13
|
+
readonly maxFileSize = 50000000;
|
|
14
|
+
readonly supportedTypes: null;
|
|
15
|
+
private readonly apiKey;
|
|
16
|
+
private readonly baseURL;
|
|
17
|
+
constructor(config: OpenAIFileAdapterConfig);
|
|
18
|
+
private bearer;
|
|
19
|
+
upload(file: FileAttachment, fetch: EngineFetch): Promise<FileUploadResult>;
|
|
20
|
+
delete(remoteId: string, fetch: EngineFetch): Promise<void>;
|
|
21
|
+
getInfo(remoteId: string, fetch: EngineFetch): Promise<RemoteFileInfo | null>;
|
|
22
|
+
list(fetch: EngineFetch): Promise<RemoteFileInfo[]>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** OpenAI media adapter — image generation (/v1/images/generations) and TTS
|
|
2
|
+
* (/v1/audio/speech). All HTTP calls flow through an injected EngineFetch
|
|
3
|
+
* so they share the NetworkEngine queue, rate-limits, retry, and hooks. */
|
|
4
|
+
import type { EngineFetch } from '../../../network/types';
|
|
5
|
+
import type { AudioGenRequest, ImageEditRequest, ImageGenRequest, MediaCapabilities, MediaProviderAdapter, RawMediaResult, VideoGenRequest, VideoStatus } from '../../../plugins/media/types';
|
|
6
|
+
export interface OpenAIMediaAdapterConfig {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class OpenAIMediaAdapter implements MediaProviderAdapter {
|
|
11
|
+
readonly name = "openai";
|
|
12
|
+
private readonly apiKey;
|
|
13
|
+
private readonly baseURL;
|
|
14
|
+
constructor(config: OpenAIMediaAdapterConfig);
|
|
15
|
+
capabilities(): MediaCapabilities;
|
|
16
|
+
private authHeaders;
|
|
17
|
+
generateImage(req: ImageGenRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
|
|
18
|
+
/** Parse `/v1/images/{generations,edits}` response → RawMediaResult[], with
|
|
19
|
+
* the request-level usage attached to the first item (billed once). */
|
|
20
|
+
private parseImages;
|
|
21
|
+
/** Image-to-image edit via `/v1/images/edits` (JSON, base64 data-URL or
|
|
22
|
+
* file_id references). */
|
|
23
|
+
editImage(req: ImageEditRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
|
|
24
|
+
generateAudio(req: AudioGenRequest, fetch: EngineFetch): Promise<RawMediaResult>;
|
|
25
|
+
submitVideo(req: VideoGenRequest, fetch: EngineFetch): Promise<string>;
|
|
26
|
+
getVideoStatus(videoId: string, fetch: EngineFetch): Promise<VideoStatus>;
|
|
27
|
+
downloadVideo(videoId: string, fetch: EngineFetch): Promise<RawMediaResult>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** OpenAI moderations adapter -- POST /v1/moderations.
|
|
2
|
+
* Supports text and image+text content-part input as described in
|
|
3
|
+
* https://platform.openai.com/docs/api-reference/moderations/create
|
|
4
|
+
* All HTTP flows through the injected EngineFetch. */
|
|
5
|
+
import type { EngineFetch } from '../../../network/types';
|
|
6
|
+
import type { ModerationContentPart, ModerationResult } from '../../../helpers/moderate-types';
|
|
7
|
+
export interface OpenAIModerationAdapterConfig {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
baseURL?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const OPENAI_MODERATION_BASE_URL = "https://api.openai.com";
|
|
12
|
+
export declare const OPENAI_MODERATION_PATH = "/v1/moderations";
|
|
13
|
+
export declare const OPENAI_MODERATION_DEFAULT_MODEL = "omni-moderation-latest";
|
|
14
|
+
export declare class OpenAIModerationAdapter {
|
|
15
|
+
private readonly apiKey;
|
|
16
|
+
private readonly baseURL;
|
|
17
|
+
constructor(config: OpenAIModerationAdapterConfig);
|
|
18
|
+
moderate(input: string | string[] | ModerationContentPart | ModerationContentPart[], model: string, fetch: EngineFetch): Promise<ModerationResult[]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** OpenAI realtime adapter (GA `wss://api.openai.com/v1/realtime`).
|
|
2
|
+
*
|
|
3
|
+
* Wire protocol (extracted from the official `openai/realtime/websocket`):
|
|
4
|
+
* - Auth via WS subprotocols: ['realtime', 'openai-insecure-api-key.<key>'].
|
|
5
|
+
* - On open: session.update { session: { type:'realtime', output_modalities } }.
|
|
6
|
+
* - Send a turn: conversation.item.create (input_text / input_audio) then
|
|
7
|
+
* response.create.
|
|
8
|
+
* - Server events keyed by `.type`:
|
|
9
|
+
* response.output_text.delta → { text, delta }
|
|
10
|
+
* response.output_audio.delta → { audio, base64 delta }
|
|
11
|
+
* response.done → turn complete
|
|
12
|
+
* error → error */
|
|
13
|
+
import type { EngineConnect } from '../../../network/types';
|
|
14
|
+
import type { RealtimeProviderAdapter, RealtimeSession, RealtimeSessionConfig } from '../../realtime/types';
|
|
15
|
+
export interface OpenAIRealtimeAdapterConfig {
|
|
16
|
+
apiKey: string;
|
|
17
|
+
baseURL?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class OpenAIRealtimeAdapter implements RealtimeProviderAdapter {
|
|
20
|
+
private readonly apiKey;
|
|
21
|
+
private readonly baseURL;
|
|
22
|
+
constructor(config: OpenAIRealtimeAdapterConfig);
|
|
23
|
+
connect(config: RealtimeSessionConfig, connect: EngineConnect): RealtimeSession;
|
|
24
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** OpenAI Responses API adapter.
|
|
2
|
+
* Endpoint: POST /v1/responses
|
|
3
|
+
* Modern API: input (not messages), instructions (not system role),
|
|
4
|
+
* output items (not choices), function_call/function_call_output for tools. */
|
|
5
|
+
import type { SSEEvent } from '../../../network/types';
|
|
6
|
+
import type { ProviderAdapter, ProviderHttpRequest } from '../../types/provider';
|
|
7
|
+
import type { NormalizedRequest } from '../../types/request';
|
|
8
|
+
import { type CompletionResponse, type Usage } from '../../types/response';
|
|
9
|
+
import type { StreamEvent } from '../../types/stream';
|
|
10
|
+
export interface OpenAIResponsesAdapterConfig {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
baseURL?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class OpenAIResponsesAdapter implements ProviderAdapter {
|
|
15
|
+
readonly name: ProviderAdapter['name'];
|
|
16
|
+
protected readonly apiKey: string;
|
|
17
|
+
protected readonly _baseURL?: string;
|
|
18
|
+
constructor(config: OpenAIResponsesAdapterConfig);
|
|
19
|
+
authHeaders(): Record<string, string>;
|
|
20
|
+
baseURL(): string;
|
|
21
|
+
completionPath(): string;
|
|
22
|
+
buildRequest(req: NormalizedRequest): ProviderHttpRequest;
|
|
23
|
+
/** Convert a universal Message to Responses API input items */
|
|
24
|
+
private buildInputItems;
|
|
25
|
+
enableStreaming(providerReq: ProviderHttpRequest): void;
|
|
26
|
+
parseResponse(raw: unknown, latencyMs: number): CompletionResponse;
|
|
27
|
+
parseStreamEvent(event: SSEEvent): StreamEvent[];
|
|
28
|
+
protected parseUsage(u: Record<string, unknown> | undefined): Usage;
|
|
29
|
+
}
|