@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,36 @@
|
|
|
1
|
+
/** createObserver — agent-scoped reactive subscription.
|
|
2
|
+
*
|
|
3
|
+
* createObserver(agent, 'onRunComplete', reactor);
|
|
4
|
+
*
|
|
5
|
+
* The reactor is either a plain async function `(ctx) => void` or an
|
|
6
|
+
* AgentOptions object describing an observer agent. When it's an agent
|
|
7
|
+
* config, the helper internally builds an AgentLoop with the supplied
|
|
8
|
+
* tools; on every fired event it converts the ctx to a prompt and runs
|
|
9
|
+
* `observer.complete(prompt)` — the observer's tools execute the side
|
|
10
|
+
* effects, the reply text is discarded.
|
|
11
|
+
*
|
|
12
|
+
* Hooks are pulled from `coreRegistry.get().hooks`. Events fire fire-
|
|
13
|
+
* and-forget; an in-flight reaction never blocks the next event. */
|
|
14
|
+
import type { AgentLoop } from '../agent/loop';
|
|
15
|
+
import type { RunCompleteContext, RunErrorContext, RunStartContext, StepCompleteContext, StepStartContext, ToolCallCompleteContext, ToolCallErrorContext, ToolCallStartContext } from '../bus/hook-map';
|
|
16
|
+
import { type CreateAgentOptions } from './agent';
|
|
17
|
+
/** Agent-scoped event names — hook-map entries that carry `agentId`. */
|
|
18
|
+
export type AgentEventName = 'onRunStart' | 'onRunComplete' | 'onRunError' | 'onStepStart' | 'onStepComplete' | 'onToolCallStart' | 'onToolCallComplete' | 'onToolCallError';
|
|
19
|
+
interface AgentEventCtxMap {
|
|
20
|
+
onRunStart: RunStartContext;
|
|
21
|
+
onRunComplete: RunCompleteContext;
|
|
22
|
+
onRunError: RunErrorContext;
|
|
23
|
+
onStepStart: StepStartContext;
|
|
24
|
+
onStepComplete: StepCompleteContext;
|
|
25
|
+
onToolCallStart: ToolCallStartContext;
|
|
26
|
+
onToolCallComplete: ToolCallCompleteContext;
|
|
27
|
+
onToolCallError: ToolCallErrorContext;
|
|
28
|
+
}
|
|
29
|
+
export type ObserverReactor<E extends AgentEventName> = ((ctx: AgentEventCtxMap[E]) => void | Promise<void>) | ObserverAgentReactor<E>;
|
|
30
|
+
export interface ObserverAgentReactor<E extends AgentEventName> extends CreateAgentOptions {
|
|
31
|
+
/** Convert the event ctx into the prompt text fed to the observer agent.
|
|
32
|
+
* Defaults to a JSON dump of ctx. */
|
|
33
|
+
prompt?: (ctx: AgentEventCtxMap[E]) => string | Promise<string>;
|
|
34
|
+
}
|
|
35
|
+
export declare function createObserver<E extends AgentEventName>(agent: AgentLoop, event: E, reactor: ObserverReactor<E>): () => void;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** One-shot complete() — single-call helper that hides the ceremony.
|
|
2
|
+
*
|
|
3
|
+
* const reply = await complete({
|
|
4
|
+
* provider: 'anthropic',
|
|
5
|
+
* model: 'claude-haiku-4-5',
|
|
6
|
+
* apiKey,
|
|
7
|
+
* system: 'Reply in one sentence.',
|
|
8
|
+
* prompt: 'What is TypeScript?',
|
|
9
|
+
* maxTokens: 60,
|
|
10
|
+
* });
|
|
11
|
+
* // reply: { text, usage, finishReason, raw }
|
|
12
|
+
*
|
|
13
|
+
* When `tools` is supplied, the helper internally builds an AgentLoop and
|
|
14
|
+
* runs the multi-step tool loop. Without tools, it goes through plain
|
|
15
|
+
* LLMClient.complete. Either way the helper destroys its created client
|
|
16
|
+
* before returning so callers don't leak. */
|
|
17
|
+
import type { AgentTool } from '../agent/types';
|
|
18
|
+
import type { LLMClientConfig } from '../llm/client-config';
|
|
19
|
+
import type { AudioOptions } from '../llm/types/audio';
|
|
20
|
+
import type { ContentPart, Message } from '../llm/types/messages';
|
|
21
|
+
import type { CompletionResponse } from '../llm/types/response';
|
|
22
|
+
import type { ProviderName } from '../llm/types/provider';
|
|
23
|
+
import type { ServiceTier } from '../llm/types/tiers';
|
|
24
|
+
import type { BuiltinTool } from '../llm/types/tools';
|
|
25
|
+
import type { EngineHandle } from './engine';
|
|
26
|
+
import type { EstimateBound } from './estimate-types';
|
|
27
|
+
export interface CompleteOptions {
|
|
28
|
+
/** Model string. Bare (e.g. `claude-haiku-4-5` — pair with `provider`) or
|
|
29
|
+
* namespaced (e.g. `anthropic/claude-haiku-4-5`). */
|
|
30
|
+
model: string;
|
|
31
|
+
/** Required when `model` is bare. */
|
|
32
|
+
provider?: ProviderName;
|
|
33
|
+
/** Optional — falls back to `engine.apiKeys[provider]`. */
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
/** Per-call system prompt. */
|
|
36
|
+
system?: string;
|
|
37
|
+
/** Either a string (becomes user message) OR an explicit messages array. */
|
|
38
|
+
prompt: string | ContentPart[] | Message[];
|
|
39
|
+
/** Inline media / file parts to append to the user message. Each entry may be:
|
|
40
|
+
* - a string path or `http(s)://` URL → auto-loaded as an image part
|
|
41
|
+
* - a `Uint8Array` → auto-loaded as an image part
|
|
42
|
+
* - a `ContentPart` → used as-is
|
|
43
|
+
* Sugar over `prompt: [...{role:'user', content:[...attachments, {type:'text', text}]}]`. */
|
|
44
|
+
attachments?: Array<string | Uint8Array | ContentPart>;
|
|
45
|
+
/** Tools — if any are passed, the helper runs an AgentLoop. Executable tools
|
|
46
|
+
* (from `defineTool`) AND bare builtin tools (`{type:'web_search'}` /
|
|
47
|
+
* `{type:'code_interpreter'}` …) are both accepted; builtins run server-side
|
|
48
|
+
* so they need no client executor. */
|
|
49
|
+
tools?: Array<AgentTool | BuiltinTool>;
|
|
50
|
+
/** Generation control. */
|
|
51
|
+
maxTokens?: number;
|
|
52
|
+
temperature?: number;
|
|
53
|
+
structured?: {
|
|
54
|
+
schema: Record<string, unknown>;
|
|
55
|
+
name?: string;
|
|
56
|
+
};
|
|
57
|
+
/** Output audio controls (voice/format) for audio-capable models. */
|
|
58
|
+
audio?: AudioOptions;
|
|
59
|
+
/** Which output modalities to return. Default ['text']; add 'audio' for a spoken
|
|
60
|
+
* reply (surfaced as a media part on `response.media`). */
|
|
61
|
+
outputModalities?: Array<'text' | 'audio'>;
|
|
62
|
+
/** Service tier for this call. Also settable as a `model:tier` suffix (e.g.
|
|
63
|
+
* `anthropic/claude-opus-4.8:priority`); an explicit value here wins. */
|
|
64
|
+
serviceTier?: ServiceTier;
|
|
65
|
+
/** Optional engine to use. Falls back to coreRegistry default. */
|
|
66
|
+
engine?: EngineHandle;
|
|
67
|
+
/** Provider-specific request options (e.g. `{ openrouter: { models: [...] } }`). */
|
|
68
|
+
providerOptions?: Record<string, unknown>;
|
|
69
|
+
/** Extra LLMClient options. */
|
|
70
|
+
client?: Partial<Omit<LLMClientConfig, 'provider' | 'model' | 'apiKey'>>;
|
|
71
|
+
/** When set, `estimate()` runs BEFORE the request is sent. If the cost for
|
|
72
|
+
* `budgetBound` exceeds this limit, throws `BudgetExceededError` and never
|
|
73
|
+
* calls the provider. OFF by default (no behavior change when absent). */
|
|
74
|
+
maxCostUsd?: number;
|
|
75
|
+
/** Which estimate bound to compare against `maxCostUsd`.
|
|
76
|
+
* Default: `'expected'`. Use `'high'` for conservative worst-case gating. */
|
|
77
|
+
budgetBound?: EstimateBound;
|
|
78
|
+
}
|
|
79
|
+
export interface CompleteResult<T = unknown> {
|
|
80
|
+
text: string;
|
|
81
|
+
/** Auto-parsed JSON result. Present iff `opts.structured.schema` was set;
|
|
82
|
+
* otherwise `undefined`. The generic on `complete<T>(...)` types this. */
|
|
83
|
+
parsed?: T;
|
|
84
|
+
response: CompletionResponse;
|
|
85
|
+
}
|
|
86
|
+
export declare function complete<T = unknown>(opts: CompleteOptions): Promise<CompleteResult<T>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** parallel — fan-out a single input across N steps and collect their
|
|
2
|
+
* outputs in order. Companion to `chain` (sequential).
|
|
3
|
+
*
|
|
4
|
+
* Each step is either a `complete()` config with `prompt(input)` or a
|
|
5
|
+
* plain async function. Optional `onStep` fires per-completion (in
|
|
6
|
+
* whichever order they finish). */
|
|
7
|
+
import type { ChainStep } from './chain';
|
|
8
|
+
export interface ParallelOptions {
|
|
9
|
+
/** Fires once per step as it completes (NOT necessarily in step order). */
|
|
10
|
+
onStep?: (info: {
|
|
11
|
+
index: number;
|
|
12
|
+
name?: string;
|
|
13
|
+
output: string;
|
|
14
|
+
}) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function parallel(steps: ChainStep[], options?: ParallelOptions): (input: string) => Promise<string[]>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** createRealtime — open a unified realtime/live session using the current
|
|
2
|
+
* EngineHandle (engine.connect transport + engine.apiKeys). Resolves a default
|
|
3
|
+
* per-provider RealtimeProviderAdapter (openai/google). Mirrors createLLM. */
|
|
4
|
+
import type { AudioOptions } from '../llm/types/audio';
|
|
5
|
+
import type { RealtimeModality, RealtimeSession } from '../llm/realtime/types';
|
|
6
|
+
import type { ProviderName } from '../llm/types/provider';
|
|
7
|
+
import type { EngineHandle } from './engine';
|
|
8
|
+
export interface CreateRealtimeOptions {
|
|
9
|
+
/** Model string. Bare (`gpt-realtime` — pair with `provider`) or namespaced
|
|
10
|
+
* (`openai/gpt-realtime`). */
|
|
11
|
+
model: string;
|
|
12
|
+
/** Required when `model` is bare. Ignored when namespaced. */
|
|
13
|
+
provider?: ProviderName;
|
|
14
|
+
/** Falls back to `engine.apiKeys[provider]` when omitted. */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
modalities?: RealtimeModality[];
|
|
17
|
+
/** Output audio controls (voice/format). `audio.voice` accepts a provider voice
|
|
18
|
+
* id or a unified alias. Takes precedence over the legacy `voice` field. */
|
|
19
|
+
audio?: AudioOptions;
|
|
20
|
+
/** @deprecated use `audio.voice`. */
|
|
21
|
+
voice?: string;
|
|
22
|
+
instructions?: string;
|
|
23
|
+
engine?: EngineHandle;
|
|
24
|
+
}
|
|
25
|
+
export declare function createRealtime(opts: CreateRealtimeOptions): RealtimeSession;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** route() — provider routing with fallback.
|
|
2
|
+
*
|
|
3
|
+
* V2 (client-side): try each model in order; on a *retryable* failure
|
|
4
|
+
* (classified ErrorKind) fall over to the next; on a non-retryable failure
|
|
5
|
+
* (auth, invalid_request, content_filter, …) fail fast — another model won't
|
|
6
|
+
* fix a fundamentally bad request. Works across providers.
|
|
7
|
+
*
|
|
8
|
+
* V1 (openrouter passthrough): when every model is openrouter, send ONE request
|
|
9
|
+
* with a `models` array and let OpenRouter route server-side (one round-trip;
|
|
10
|
+
* `response.model` reports who served). */
|
|
11
|
+
import type { ErrorKind } from '../network/errors';
|
|
12
|
+
import { type CompleteOptions, type CompleteResult } from './one-shot';
|
|
13
|
+
export interface RouteOptions extends Omit<CompleteOptions, 'model' | 'provider'> {
|
|
14
|
+
/** Ordered candidate models — "provider/model" (namespaced) preferred. */
|
|
15
|
+
models: string[];
|
|
16
|
+
/** Override which ErrorKinds trigger fallback. */
|
|
17
|
+
fallbackOn?: ErrorKind[];
|
|
18
|
+
}
|
|
19
|
+
export interface RouteAttempt {
|
|
20
|
+
model: string;
|
|
21
|
+
error?: string;
|
|
22
|
+
kind?: ErrorKind;
|
|
23
|
+
}
|
|
24
|
+
export interface RouteResult<T = unknown> extends CompleteResult<T> {
|
|
25
|
+
/** The candidate model whose request produced this result. */
|
|
26
|
+
servedBy: string;
|
|
27
|
+
attempts: RouteAttempt[];
|
|
28
|
+
}
|
|
29
|
+
export declare function route<T = unknown>(opts: RouteOptions): Promise<RouteResult<T>>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** select() — pick a model by capabilities/features via a tiny tag DSL, returning
|
|
2
|
+
* a `provider/slug` string you can feed straight to complete({ model }).
|
|
3
|
+
*
|
|
4
|
+
* Query: a `;`-separated string OR an array of clauses. Clause grammar:
|
|
5
|
+
* key:value exact e.g. type:chat, search:yes, status:stable
|
|
6
|
+
* key → key:yes e.g. search, vision, reasoning
|
|
7
|
+
* key > N key ≥ N e.g. context > 200k (inclusive)
|
|
8
|
+
* key < N key ≤ N e.g. price < 1 (inclusive)
|
|
9
|
+
* N parses k/M suffixes (200k → 200000). Custom tags expand first.
|
|
10
|
+
*
|
|
11
|
+
* Availability-aware: only considers providers with a configured API key.
|
|
12
|
+
* Ranks cheapest-first (tiebreak: newest version); select() returns the single
|
|
13
|
+
* best, selectModels() the ranked list. Thresholds + custom tags are overridable. */
|
|
14
|
+
import type { ModelInfo } from '../plugins/model-catalog/catalog';
|
|
15
|
+
import type { ProviderName } from '../llm/types/provider';
|
|
16
|
+
import { type EngineHandle } from './engine';
|
|
17
|
+
export interface SelectPrefs {
|
|
18
|
+
/** Named cutoffs (overridable). */
|
|
19
|
+
thresholds?: Partial<typeof DEFAULT_THRESHOLDS>;
|
|
20
|
+
/** Custom tag → DSL expansion, e.g. `{ cheap: 'price < 1', coding: 'type:code; tools' }`. */
|
|
21
|
+
tags?: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
export interface SelectOptions {
|
|
24
|
+
engine?: EngineHandle;
|
|
25
|
+
/** Restrict to one provider. */
|
|
26
|
+
provider?: ProviderName;
|
|
27
|
+
/** Price tier to evaluate `price` against (default: standard/flat). */
|
|
28
|
+
tier?: string;
|
|
29
|
+
prefs?: SelectPrefs;
|
|
30
|
+
}
|
|
31
|
+
declare const DEFAULT_THRESHOLDS: {
|
|
32
|
+
'price.low': number;
|
|
33
|
+
'price.mid': number;
|
|
34
|
+
'context.small': number;
|
|
35
|
+
'context.large': number;
|
|
36
|
+
};
|
|
37
|
+
/** All matching models, ranked cheapest-first (tiebreak: newest version). */
|
|
38
|
+
export declare function selectModels(query: string | string[], opts?: SelectOptions): ModelInfo[];
|
|
39
|
+
/** The single best match as a `provider/slug` string (feedable to complete), or null. */
|
|
40
|
+
export declare function select(query: string | string[], opts?: SelectOptions): string | null;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** createServer — convenience helper that builds an OaiServer with engine
|
|
2
|
+
* wiring (shared HookBus + ResponseStore-backed Persistence).
|
|
3
|
+
*
|
|
4
|
+
* When `agents` is supplied, the helper auto-builds an `agentLoader` that
|
|
5
|
+
* constructs an AgentLoop per request and a `conversationLoader` backed
|
|
6
|
+
* by `createCollection<HistorySnapshot>('server-conversations')` so chat
|
|
7
|
+
* history survives across requests + restarts. The raw `agentLoader` /
|
|
8
|
+
* `conversationLoader` slots remain available for advanced cases. */
|
|
9
|
+
import type { AgentTool } from '../agent/types';
|
|
10
|
+
import type { AgentLoop } from '../agent/loop';
|
|
11
|
+
import { OaiServer, type OaiServerConfig } from '../server/server';
|
|
12
|
+
import { type CreateAgentOptions } from './agent';
|
|
13
|
+
import type { EngineHandle } from './engine';
|
|
14
|
+
export interface ServerAgentSpec extends CreateAgentOptions {
|
|
15
|
+
/** Pre-built AgentLoop. When set, the same instance is reused for every
|
|
16
|
+
* request — best for single-tenant stateful agents. */
|
|
17
|
+
agent?: AgentLoop;
|
|
18
|
+
/** Internal tools (executable on the server, hidden from the client). */
|
|
19
|
+
internalTools?: AgentTool[];
|
|
20
|
+
/** When false, client-supplied tools in the OAI request are dropped. Default true. */
|
|
21
|
+
allowExternalTools?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface CreateServerOptions extends Omit<OaiServerConfig, 'hooks' | 'responseStorePersistence'> {
|
|
24
|
+
/** High-level agent registration. Each entry becomes a server model with
|
|
25
|
+
* a per-request AgentLoop built from the spec, plus per-(userId,
|
|
26
|
+
* conversationId) history backed by `engine.persistence`. */
|
|
27
|
+
agents?: Record<string, ServerAgentSpec>;
|
|
28
|
+
engine?: EngineHandle;
|
|
29
|
+
hooks?: OaiServerConfig['hooks'];
|
|
30
|
+
responseStorePersistence?: OaiServerConfig['responseStorePersistence'];
|
|
31
|
+
}
|
|
32
|
+
export declare function createServer(opts?: CreateServerOptions): OaiServer;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** transcribe() — speech-to-text, unified across providers.
|
|
2
|
+
*
|
|
3
|
+
* Two provider shapes:
|
|
4
|
+
* - openai: a dedicated /v1/audio/transcriptions multipart endpoint
|
|
5
|
+
* (gpt-4o-transcribe / whisper). Routed to OpenAITranscriptionAdapter.
|
|
6
|
+
* - generateContent providers (google, …): transcription is just a normal
|
|
7
|
+
* completion with the audio attached, so reuse complete(). */
|
|
8
|
+
import type { AudioInput } from '../llm/types/audio';
|
|
9
|
+
import type { ProviderName } from '../llm/types/provider';
|
|
10
|
+
import type { EngineHandle } from './engine';
|
|
11
|
+
export interface TranscribeOptions {
|
|
12
|
+
model: string;
|
|
13
|
+
provider?: ProviderName;
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/** Audio source: a file path, raw bytes, or an AudioInput (with explicit
|
|
16
|
+
* mimeType for raw/stream audio). */
|
|
17
|
+
audio: string | Uint8Array | AudioInput;
|
|
18
|
+
/** Optional language hint (BCP-47, e.g. "en"). */
|
|
19
|
+
language?: string;
|
|
20
|
+
/** Prompt used for generateContent-style providers (ignored by openai). */
|
|
21
|
+
prompt?: string;
|
|
22
|
+
/** Caller-supplied audio duration in seconds. Used to price OpenAI
|
|
23
|
+
* transcription calls (the API does not return duration). When omitted,
|
|
24
|
+
* the helper tries to parse duration from a WAV header; other formats
|
|
25
|
+
* emit an honest zero with a note. */
|
|
26
|
+
audioDurationSeconds?: number;
|
|
27
|
+
engine?: EngineHandle;
|
|
28
|
+
}
|
|
29
|
+
export interface TranscribeResult {
|
|
30
|
+
text: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function transcribe(opts: TranscribeOptions): Promise<TranscribeResult>;
|
|
33
|
+
/** WAV PCM duration from raw bytes — pure arithmetic, cross-env.
|
|
34
|
+
* Reads sample-rate (bytes 24-27) and data-chunk size from the RIFF header.
|
|
35
|
+
* Returns undefined for non-WAV or malformed data. */
|
|
36
|
+
export declare function deriveWavDuration(bytes: Uint8Array, mimeType: string): number | undefined;
|