@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,74 @@
|
|
|
1
|
+
/** batch() / submitBatch() / batchJob() — explicit batch processing.
|
|
2
|
+
*
|
|
3
|
+
* A batch request is a deferred complete(): you describe each item the same way
|
|
4
|
+
* (prompt/system/maxTokens/…), the helper builds the per-provider body via that
|
|
5
|
+
* provider's adapter, submits one batch, and gives back a BatchJob handle.
|
|
6
|
+
*
|
|
7
|
+
* Two modes off the SAME handle:
|
|
8
|
+
* - AUTO : `await batch({...})` or `await job.wait()` — polls until done.
|
|
9
|
+
* - MANUAL : keep `job.id`, persist it, later `batchJob({id, provider})` →
|
|
10
|
+
* `job.status()` / `job.results()` (results() throws until complete).
|
|
11
|
+
*
|
|
12
|
+
* Reuses the existing per-provider BatchProviderAdapters; all HTTP flows through
|
|
13
|
+
* engine.fetch (queue/retry/hooks). */
|
|
14
|
+
import type { ContentPart, Message } from '../llm/types/messages';
|
|
15
|
+
import type { ProviderName } from '../llm/types/provider';
|
|
16
|
+
import type { CompletionResponse } from '../llm/types/response';
|
|
17
|
+
import type { BatchStatus } from '../plugins/batch/types';
|
|
18
|
+
import type { EngineHandle } from './engine';
|
|
19
|
+
export interface BatchRequestInput {
|
|
20
|
+
/** Correlation id. Defaults to `req-<index>` when omitted. */
|
|
21
|
+
customId?: string;
|
|
22
|
+
prompt: string | ContentPart[] | Message[];
|
|
23
|
+
system?: string;
|
|
24
|
+
maxTokens?: number;
|
|
25
|
+
temperature?: number;
|
|
26
|
+
structured?: {
|
|
27
|
+
schema: Record<string, unknown>;
|
|
28
|
+
name?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface BatchItemResult {
|
|
32
|
+
customId: string;
|
|
33
|
+
success: boolean;
|
|
34
|
+
/** Parsed reply text ('' when failed or empty). */
|
|
35
|
+
text: string;
|
|
36
|
+
/** Full normalized response (usage, finishReason, raw), or null on failure. */
|
|
37
|
+
response: CompletionResponse | null;
|
|
38
|
+
error: string | null;
|
|
39
|
+
}
|
|
40
|
+
export interface WaitOptions {
|
|
41
|
+
pollIntervalMs?: number;
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
onProgress?: (status: BatchStatus) => void;
|
|
44
|
+
}
|
|
45
|
+
export interface BatchJob {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly provider: ProviderName;
|
|
48
|
+
/** Current provider-side status (manual progress check). */
|
|
49
|
+
status(): Promise<BatchStatus>;
|
|
50
|
+
/** Fetch results. Throws if the batch is not yet in a terminal state. */
|
|
51
|
+
results(): Promise<BatchItemResult[]>;
|
|
52
|
+
/** Poll until terminal, then return results (auto mode). */
|
|
53
|
+
wait(opts?: WaitOptions): Promise<BatchItemResult[]>;
|
|
54
|
+
cancel(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
export interface SubmitBatchOptions {
|
|
57
|
+
model: string;
|
|
58
|
+
provider?: ProviderName;
|
|
59
|
+
apiKey?: string;
|
|
60
|
+
requests: BatchRequestInput[];
|
|
61
|
+
engine?: EngineHandle;
|
|
62
|
+
}
|
|
63
|
+
export interface BatchJobRef {
|
|
64
|
+
id: string;
|
|
65
|
+
provider: ProviderName;
|
|
66
|
+
apiKey?: string;
|
|
67
|
+
engine?: EngineHandle;
|
|
68
|
+
}
|
|
69
|
+
/** Submit a batch; returns a handle immediately (no blocking). */
|
|
70
|
+
export declare function submitBatch(opts: SubmitBatchOptions): Promise<BatchJob>;
|
|
71
|
+
/** Reconstruct a handle from a persisted id (resume — manual mode only). */
|
|
72
|
+
export declare function batchJob(ref: BatchJobRef): BatchJob;
|
|
73
|
+
/** One-shot auto mode: submit + wait + results. */
|
|
74
|
+
export declare function batch(opts: SubmitBatchOptions & WaitOptions): Promise<BatchItemResult[]>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** calibration-store.ts — per-key output-token running statistics.
|
|
2
|
+
*
|
|
3
|
+
* Maintains an EWMA mean and a fixed-bin histogram for p90 estimation.
|
|
4
|
+
* State is serialized via the Persistence interface (FilePersistence or
|
|
5
|
+
* MemoryPersistence) so it survives process restarts when configured. */
|
|
6
|
+
import type { Persistence } from '../plugins/persistence/types';
|
|
7
|
+
import { type InputBucketLabel, type CalibrationObservation, type OutputCalibrationConfig, type OutputCalibrationEntry } from './calibration-types';
|
|
8
|
+
/** Map an input-token count to its named bucket label. */
|
|
9
|
+
export declare function inputBucketLabel(inputTokens: number): InputBucketLabel;
|
|
10
|
+
/** Build the persistence key for a provider/model + bucket. */
|
|
11
|
+
export declare function calibrationKey(provider: string, model: string, bucket: InputBucketLabel): string;
|
|
12
|
+
export declare class OutputCalibrationStore {
|
|
13
|
+
private readonly persistence;
|
|
14
|
+
private readonly alpha;
|
|
15
|
+
constructor(persistence: Persistence, config?: OutputCalibrationConfig);
|
|
16
|
+
/** Record one observed completion, updating EWMA mean and histogram. */
|
|
17
|
+
record(obs: CalibrationObservation): Promise<void>;
|
|
18
|
+
/** Retrieve the calibration entry for a provider/model + input-token count.
|
|
19
|
+
* Returns null when no data exists for that key. */
|
|
20
|
+
get(provider: string, model: string, inputTokens: number): Promise<OutputCalibrationEntry | null>;
|
|
21
|
+
/** Compute the p90 output-token estimate from a stored entry. */
|
|
22
|
+
p90(entry: OutputCalibrationEntry): number;
|
|
23
|
+
/** List all stored keys (for testing/introspection). */
|
|
24
|
+
listKeys(): Promise<string[]>;
|
|
25
|
+
private newEntry;
|
|
26
|
+
private updateEntry;
|
|
27
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** calibration-types.ts — types and constants for the adaptive output-token
|
|
2
|
+
* calibration layer used by Estimator.
|
|
3
|
+
*
|
|
4
|
+
* All tuneable values live here as named constants (no magic numbers). */
|
|
5
|
+
/** Upper edges (exclusive) for input-token size buckets.
|
|
6
|
+
* E.g. edge 500 means the bucket covers [prev-edge, 500).
|
|
7
|
+
* The last bucket is open-ended: [32000, +inf). */
|
|
8
|
+
export declare const INPUT_SIZE_BUCKET_EDGES: readonly [500, 2000, 8000, 32000];
|
|
9
|
+
/** Human-readable labels, one per bucket (including the final open bucket). */
|
|
10
|
+
export declare const INPUT_SIZE_BUCKET_LABELS: readonly ["0-500", "500-2000", "2000-8000", "8000-32000", "32000+"];
|
|
11
|
+
export type InputBucketLabel = (typeof INPUT_SIZE_BUCKET_LABELS)[number];
|
|
12
|
+
/** Smoothing factor for the exponentially weighted moving average of output
|
|
13
|
+
* tokens. Higher = faster adaptation; lower = smoother, less noisy.
|
|
14
|
+
* Range: (0, 1). */
|
|
15
|
+
export declare const CALIBRATION_EWMA_ALPHA = 0.15;
|
|
16
|
+
/** Number of fixed bins in the output-token histogram used to estimate p90.
|
|
17
|
+
* More bins = higher resolution but more memory per key.
|
|
18
|
+
* Each bin represents a contiguous token-count range of P90_BIN_WIDTH. */
|
|
19
|
+
export declare const P90_HISTOGRAM_BIN_COUNT = 32;
|
|
20
|
+
/** Width of each histogram bin in output tokens. */
|
|
21
|
+
export declare const P90_HISTOGRAM_BIN_WIDTH = 256;
|
|
22
|
+
/** The quantile to track as the "high" calibrated bound. */
|
|
23
|
+
export declare const CALIBRATION_HIGH_QUANTILE = 0.9;
|
|
24
|
+
export declare const OUTPUT_CALIBRATION_KEY_PREFIX = "output-calibration:";
|
|
25
|
+
/** Compact per-key running state stored in persistence. */
|
|
26
|
+
export interface OutputCalibrationEntry {
|
|
27
|
+
/** Learning key: `provider/model#inputBucket` */
|
|
28
|
+
key: string;
|
|
29
|
+
/** EWMA-smoothed mean of observed output tokens. */
|
|
30
|
+
ewmaMean: number;
|
|
31
|
+
/** Fixed-count histogram of output token observations.
|
|
32
|
+
* Index i covers [i * P90_HISTOGRAM_BIN_WIDTH, (i+1) * P90_HISTOGRAM_BIN_WIDTH).
|
|
33
|
+
* The last bin is open-ended (captures all values >= (BIN_COUNT-1) * BIN_WIDTH). */
|
|
34
|
+
histogram: number[];
|
|
35
|
+
/** Total observations recorded. */
|
|
36
|
+
count: number;
|
|
37
|
+
/** Timestamp of the most recent update. */
|
|
38
|
+
lastUpdated: number;
|
|
39
|
+
}
|
|
40
|
+
export interface OutputCalibrationConfig {
|
|
41
|
+
/** EWMA smoothing alpha; defaults to CALIBRATION_EWMA_ALPHA. */
|
|
42
|
+
ewmaAlpha?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface CalibrationStoreConfig {
|
|
45
|
+
/** 'file' persists to disk via FilePersistence. 'memory' is in-process only. */
|
|
46
|
+
store: 'file' | 'memory';
|
|
47
|
+
/** Required when store='file'. Directory for the FilePersistence JSON files. */
|
|
48
|
+
path?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface EstimatorOptions {
|
|
51
|
+
/** When provided, enables adaptive calibration. Without this field the
|
|
52
|
+
* Estimator behaves identically to the static estimate() function. */
|
|
53
|
+
calibration?: CalibrationStoreConfig;
|
|
54
|
+
}
|
|
55
|
+
export interface CalibrationObservation {
|
|
56
|
+
/** Provider string, e.g. 'anthropic'. */
|
|
57
|
+
provider: string;
|
|
58
|
+
/** Model string, e.g. 'claude-haiku-4-5'. */
|
|
59
|
+
model: string;
|
|
60
|
+
/** Input-token count for this completion (used to map to bucket). */
|
|
61
|
+
inputTokens: number;
|
|
62
|
+
/** Actual output tokens observed. */
|
|
63
|
+
outputTokens: number;
|
|
64
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** chain — sequential pipeline where each step's output feeds the next.
|
|
2
|
+
*
|
|
3
|
+
* Each step is either:
|
|
4
|
+
* - an object describing a `complete()` call with a `prompt(input)`
|
|
5
|
+
* function that takes the previous output and returns the user prompt,
|
|
6
|
+
* - or a plain async function `(input: string) => string` (handy for
|
|
7
|
+
* delegating to an AgentLoop or running custom logic).
|
|
8
|
+
*
|
|
9
|
+
* Returns a callable. The optional `onStep` callback fires after every
|
|
10
|
+
* step with its index, optional name, and produced output — perfect for
|
|
11
|
+
* logging the Input → A → Output → B → Output → ... flow. */
|
|
12
|
+
import { type CompleteOptions } from './one-shot';
|
|
13
|
+
export interface ChainStepConfig extends Omit<CompleteOptions, 'prompt'> {
|
|
14
|
+
/** Optional label surfaced via `onStep` and useful for debugging. */
|
|
15
|
+
name?: string;
|
|
16
|
+
/** Receives the previous step's output (or the original input on step 1)
|
|
17
|
+
* and returns the user-visible prompt string for this LLM call. */
|
|
18
|
+
prompt: (input: string) => string;
|
|
19
|
+
}
|
|
20
|
+
export type ChainStepFn = (input: string) => Promise<string> | string;
|
|
21
|
+
export type ChainStep = ChainStepConfig | ChainStepFn;
|
|
22
|
+
export interface ChainOptions {
|
|
23
|
+
/** Fires after every step with its index, optional name, and output. */
|
|
24
|
+
onStep?: (info: {
|
|
25
|
+
index: number;
|
|
26
|
+
name?: string;
|
|
27
|
+
output: string;
|
|
28
|
+
}) => void;
|
|
29
|
+
}
|
|
30
|
+
export declare function chain(steps: ChainStep[], options?: ChainOptions): (input: string) => Promise<string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** ClientPool — keys LLMClients by provider (default) or (provider+model)
|
|
2
|
+
* when catalog marks a model as requiresDedicatedClient. Used by
|
|
3
|
+
* ClientResolver and (in the legacy SDK) by InternalToolRunner. */
|
|
4
|
+
import { LLMClient } from '../llm/client';
|
|
5
|
+
import type { LLMClientConfig } from '../llm/client-config';
|
|
6
|
+
import type { ModelCatalog } from '../plugins/model-catalog/catalog';
|
|
7
|
+
export declare class ClientPool {
|
|
8
|
+
private readonly catalog?;
|
|
9
|
+
private clients;
|
|
10
|
+
constructor(catalog?: ModelCatalog | undefined);
|
|
11
|
+
get(provider: string, model: string, config: LLMClientConfig): LLMClient;
|
|
12
|
+
destroy(): Promise<void>;
|
|
13
|
+
get size(): number;
|
|
14
|
+
private keyFor;
|
|
15
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** ClientResolver — turns a `"provider/model"` string into a pooled LLMClient.
|
|
2
|
+
*
|
|
3
|
+
* Lives on the orchestrator so every module registered with it can share one
|
|
4
|
+
* pool of clients (one per provider, keyed per-model only when the catalog
|
|
5
|
+
* marks `requiresDedicatedClient`). Wraps the same ClientPool used by
|
|
6
|
+
* internal-tool-runners — one keying policy across the SDK. */
|
|
7
|
+
import type { LLMClient } from '../llm/client';
|
|
8
|
+
import type { LLMClientConfig } from '../llm/client-config';
|
|
9
|
+
import type { HookBus } from '../bus/hook-bus';
|
|
10
|
+
import type { ProviderName } from '../llm/types/provider';
|
|
11
|
+
import type { ServiceTier } from '../llm/types/tiers';
|
|
12
|
+
import type { ModelCatalog } from '../plugins/model-catalog/catalog';
|
|
13
|
+
import type { EngineFetch, EngineFetchStream } from '../network/types';
|
|
14
|
+
export interface ClientResolverConfig {
|
|
15
|
+
/** provider → API key. Providers absent from this map can't be resolved. */
|
|
16
|
+
apiKeys: Partial<Record<ProviderName, string>>;
|
|
17
|
+
/** Hooks piped to every constructed LLMClient. */
|
|
18
|
+
hooks: HookBus;
|
|
19
|
+
/** Fetch function (typically engine.fetch). When absent, falls back to
|
|
20
|
+
* `globalThis.fetch.bind(globalThis)` — fine for simple direct-call use,
|
|
21
|
+
* bypasses the NetworkEngine queue + retry. Pass engine.fetch for
|
|
22
|
+
* production. */
|
|
23
|
+
fetch?: EngineFetch;
|
|
24
|
+
/** Streaming fetch (typically engine.fetchStream). Optional. */
|
|
25
|
+
fetchStream?: EngineFetchStream;
|
|
26
|
+
/** Catalog drives pool keying (requiresDedicatedClient) + capability hints. */
|
|
27
|
+
catalog?: ModelCatalog;
|
|
28
|
+
/** Extra LLMClient options applied to every resolved client. */
|
|
29
|
+
clientOptions?: Partial<Omit<LLMClientConfig, 'provider' | 'apiKey' | 'hooks' | 'catalog' | 'model' | 'fetch' | 'fetchStream'>>;
|
|
30
|
+
}
|
|
31
|
+
export interface ResolvedClient {
|
|
32
|
+
client: LLMClient;
|
|
33
|
+
provider: ProviderName;
|
|
34
|
+
model: string;
|
|
35
|
+
}
|
|
36
|
+
export declare class ClientResolver {
|
|
37
|
+
private readonly cfg;
|
|
38
|
+
private readonly pool;
|
|
39
|
+
constructor(cfg: ClientResolverConfig);
|
|
40
|
+
/** Turn `"anthropic/claude-haiku-4-5"` → resolved client. */
|
|
41
|
+
resolve(modelId: string): ResolvedClient;
|
|
42
|
+
availableProviders(): ProviderName[];
|
|
43
|
+
destroy(): Promise<void>;
|
|
44
|
+
get size(): number;
|
|
45
|
+
}
|
|
46
|
+
export declare function parseModelId(modelId: string): [ProviderName, string];
|
|
47
|
+
export declare function isNamespacedModelId(modelId: string): boolean;
|
|
48
|
+
/** Resolve a model + optional provider to a concrete { provider, model }.
|
|
49
|
+
* A namespaced id ("provider/model") yields its own provider; a bare model
|
|
50
|
+
* requires an explicit `provider`. `label` names the caller in the error. */
|
|
51
|
+
export declare function resolveModel(model: string, provider: ProviderName | undefined, label: string): {
|
|
52
|
+
provider: ProviderName;
|
|
53
|
+
model: string;
|
|
54
|
+
};
|
|
55
|
+
/** Split a trailing `:tier` off a model id, but only when the suffix is a known
|
|
56
|
+
* service tier. `"anthropic/claude-opus-4.8:priority"` → { modelId:
|
|
57
|
+
* "anthropic/claude-opus-4.8", serviceTier: "priority" }; `"…/qwen3-coder:free"`
|
|
58
|
+
* → unchanged (`:free` is an OpenRouter variant, not a tier). */
|
|
59
|
+
export declare function parseModelTier(modelId: string): {
|
|
60
|
+
modelId: string;
|
|
61
|
+
serviceTier?: ServiceTier;
|
|
62
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** createCollection — typed namespace over `engine.persistence`.
|
|
2
|
+
*
|
|
3
|
+
* Wraps the raw key/value persistence in a small typed handle keyed by
|
|
4
|
+
* short names within a single namespace. Lets app code talk in domain
|
|
5
|
+
* terms (subagents, prompts, conversations) without juggling key
|
|
6
|
+
* prefixes or the underlying file/db wiring. */
|
|
7
|
+
export interface Collection<T> {
|
|
8
|
+
set(key: string, value: T): Promise<void>;
|
|
9
|
+
get(key: string): Promise<T | null>;
|
|
10
|
+
has(key: string): Promise<boolean>;
|
|
11
|
+
delete(key: string): Promise<void>;
|
|
12
|
+
/** Short keys (without the namespace prefix). */
|
|
13
|
+
keys(): Promise<string[]>;
|
|
14
|
+
/** All values. */
|
|
15
|
+
list(): Promise<T[]>;
|
|
16
|
+
/** [shortKey, value] pairs. */
|
|
17
|
+
entries(): Promise<Array<[string, T]>>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createCollection<T>(name: string): Collection<T>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** consolidate — multi-agent debate that runs up to N rounds, stops early
|
|
2
|
+
* when the agents converge, and produces a final summary.
|
|
3
|
+
*
|
|
4
|
+
* Each round, every agent answers the task in parallel (seeing the prior
|
|
5
|
+
* round's answers). After each round a judge LLM evaluates whether the
|
|
6
|
+
* agents reached substantive agreement (structured JSON output). When
|
|
7
|
+
* it returns `agreed: true`, the loop exits early. Either way a closing
|
|
8
|
+
* summary call returns the consensus + per-agent unique points. */
|
|
9
|
+
import type { CompleteOptions, CompleteResult } from './one-shot';
|
|
10
|
+
export interface ConsolidateAgent {
|
|
11
|
+
/** Display name surfaced via `onRound` and inside summary prompts. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Namespaced model id, e.g. `anthropic/claude-haiku-4-5`. */
|
|
14
|
+
model: string;
|
|
15
|
+
/** Persona / role text. */
|
|
16
|
+
system: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ConsolidateAnswer {
|
|
19
|
+
agent: string;
|
|
20
|
+
text: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ConsolidateRoundInfo {
|
|
23
|
+
round: number;
|
|
24
|
+
answers: ConsolidateAnswer[];
|
|
25
|
+
agreed: boolean;
|
|
26
|
+
judgeReason: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ConsolidateJudge {
|
|
29
|
+
/** Namespaced model id for the judge. SHOULD be different from any
|
|
30
|
+
* participating agent's model — otherwise the judge is evaluating its
|
|
31
|
+
* own answer as one of the inputs, which biases the verdict. */
|
|
32
|
+
model: string;
|
|
33
|
+
/** Optional override for the judge system prompt. */
|
|
34
|
+
system?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Internal type for the completion function signature. */
|
|
37
|
+
export type CompleteFn = (opts: CompleteOptions) => Promise<CompleteResult>;
|
|
38
|
+
export interface ConsolidateOptions {
|
|
39
|
+
/** Two or more agents — heterogeneous models recommended. */
|
|
40
|
+
agents: ConsolidateAgent[];
|
|
41
|
+
/** The question / task they are debating. */
|
|
42
|
+
task: string;
|
|
43
|
+
/** External judge that decides round-by-round agreement and writes the
|
|
44
|
+
* closing summary. Must be a separate model from the debate participants
|
|
45
|
+
* to avoid self-evaluation bias. */
|
|
46
|
+
judge: ConsolidateJudge;
|
|
47
|
+
/** Maximum rounds before the loop ends regardless of agreement. */
|
|
48
|
+
rounds?: number;
|
|
49
|
+
/** Per-agent maxTokens for each round. */
|
|
50
|
+
maxTokens?: number;
|
|
51
|
+
/** Fires after every round with the answers + judge verdict. */
|
|
52
|
+
onRound?: (info: ConsolidateRoundInfo) => void;
|
|
53
|
+
/** Internal seam for tests — inject a fake complete() instead of the real one.
|
|
54
|
+
* Not part of the public API; omit in production code. */
|
|
55
|
+
_complete?: CompleteFn;
|
|
56
|
+
}
|
|
57
|
+
export interface ConsolidateResult {
|
|
58
|
+
/** Closing summary text (consensus + per-agent unique points). */
|
|
59
|
+
summary: string;
|
|
60
|
+
/** Every round's answers, in order. */
|
|
61
|
+
rounds: ConsolidateAnswer[][];
|
|
62
|
+
/** 1-based round index where the judge declared agreement, or null
|
|
63
|
+
* if the loop ran to `rounds`. */
|
|
64
|
+
agreedAt: number | null;
|
|
65
|
+
}
|
|
66
|
+
export declare function consolidate(opts: ConsolidateOptions): Promise<ConsolidateResult>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Content helpers — small builders for inline message parts.
|
|
2
|
+
*
|
|
3
|
+
* loadImageContent does the dirty work of fetching / reading / base64-
|
|
4
|
+
* encoding / mime-detecting an image and returns a ready-to-send
|
|
5
|
+
* `ContentPart` (type: 'image', source: { type: 'base64', mimeType, data }).
|
|
6
|
+
*
|
|
7
|
+
* Accepts:
|
|
8
|
+
* - string starting with 'http://' or 'https://' → fetch
|
|
9
|
+
* - any other string → read from disk
|
|
10
|
+
* - Uint8Array → use bytes directly
|
|
11
|
+
*
|
|
12
|
+
* Mime is auto-detected from URL extension OR file extension OR magic
|
|
13
|
+
* bytes (PNG / JPEG / GIF / WebP) when neither path applies. */
|
|
14
|
+
import type { ContentPart } from '../llm/types/messages';
|
|
15
|
+
export interface LoadImageOptions {
|
|
16
|
+
/** Optional override for the auto-detected mime type. */
|
|
17
|
+
mimeType?: string;
|
|
18
|
+
/** Optional User-Agent for URL fetches (some hosts e.g. Wikipedia 429 the default). */
|
|
19
|
+
userAgent?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function loadImageContent(source: string | Uint8Array, options?: LoadImageOptions): Promise<ContentPart>;
|
|
22
|
+
/** Load any inline content part (image / PDF document / audio / video), choosing
|
|
23
|
+
* the part type from the detected MIME. Use this for mixed attachments;
|
|
24
|
+
* `loadImageContent` forces an image part. */
|
|
25
|
+
export declare function loadContent(source: string | Uint8Array, options?: LoadImageOptions): Promise<ContentPart>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Conversation export — render a Message[] conversation as Markdown for
|
|
2
|
+
* archiving / sharing / debugging. Media parts become Markdown links: an inline
|
|
3
|
+
* image embeds its data-URL (self-contained, no archive needed); other media
|
|
4
|
+
* link to their URL or a short placeholder. */
|
|
5
|
+
import type { Message } from '../llm/types/messages';
|
|
6
|
+
export interface ConversationExportOptions {
|
|
7
|
+
/** Embed media as data-URL links (self-contained). When false, media is a
|
|
8
|
+
* short `[image]` placeholder. Default true. */
|
|
9
|
+
inlineMedia?: boolean;
|
|
10
|
+
/** Optional title at the top of the document. */
|
|
11
|
+
title?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Render a conversation as Markdown. */
|
|
14
|
+
export declare function conversationToMarkdown(messages: Message[], opts?: ConversationExportOptions): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Conversation export as a ZIP archive — Markdown with media pulled OUT into
|
|
2
|
+
* separate files (`media/media-001.png`) and referenced by relative link,
|
|
3
|
+
* instead of inlined as multi-megabyte data-URLs.
|
|
4
|
+
*
|
|
5
|
+
* The ZIP is written by hand in STORE mode (no compression) so the library
|
|
6
|
+
* keeps its zero-runtime-dependency promise — no `jszip`. Store mode is a
|
|
7
|
+
* trivial container (local headers + central directory + EOCD); media blobs
|
|
8
|
+
* (PNG/MP4/…) are already compressed, so store costs almost nothing. */
|
|
9
|
+
import type { Message } from '../llm/types/messages';
|
|
10
|
+
export interface ConversationZipOptions {
|
|
11
|
+
/** Document title (H1 at the top of the Markdown). */
|
|
12
|
+
title?: string;
|
|
13
|
+
/** Markdown file name inside the archive. Default 'conversation.md'. */
|
|
14
|
+
markdownName?: string;
|
|
15
|
+
/** Folder for extracted media. Default 'media'. */
|
|
16
|
+
mediaDir?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ConversationZipResult {
|
|
19
|
+
/** The .zip file bytes — wrap in a Blob to download. */
|
|
20
|
+
bytes: Uint8Array;
|
|
21
|
+
/** The Markdown document (also embedded in the zip), for preview/debug. */
|
|
22
|
+
markdown: string;
|
|
23
|
+
/** How many media files were extracted into the archive. */
|
|
24
|
+
mediaCount: number;
|
|
25
|
+
}
|
|
26
|
+
/** Build a downloadable ZIP of the conversation: one Markdown file plus every
|
|
27
|
+
* embedded media blob as its own file under `media/`. */
|
|
28
|
+
export declare function conversationToZip(messages: Message[], opts?: ConversationZipOptions): ConversationZipResult;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** countTokens() — thin convenience over the existing ContextMeasurer token
|
|
2
|
+
* counters. Does NOT implement counting itself: it builds a HybridTokenCounter
|
|
3
|
+
* from the engine catalog (which routes per model to tiktoken / provider
|
|
4
|
+
* count-API / heuristic) and calls it.
|
|
5
|
+
*
|
|
6
|
+
* const n = await countTokens({ model: 'openai/gpt-5.4-nano', input: 'hello' });
|
|
7
|
+
*
|
|
8
|
+
* `exact:true` (default) uses the precise path where available — tiktoken for
|
|
9
|
+
* OpenAI, the count-API for Anthropic/Google (needs apiKey) — and falls back to
|
|
10
|
+
* the calibrated heuristic otherwise. `exact:false` is always a sync estimate. */
|
|
11
|
+
import type { Message } from '../llm/types/messages';
|
|
12
|
+
import type { ProviderName } from '../llm/types/provider';
|
|
13
|
+
import { type EngineHandle } from './engine';
|
|
14
|
+
export interface CountTokensOptions {
|
|
15
|
+
/** Model string. Bare (`gpt-5.4-nano`, pair with `provider`) or namespaced. */
|
|
16
|
+
model: string;
|
|
17
|
+
provider?: ProviderName;
|
|
18
|
+
/** Text or messages to count. */
|
|
19
|
+
input: string | Message[];
|
|
20
|
+
/** Key for the exact count-API path (Anthropic/Google). Falls back to engine.apiKeys. */
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
/** Use the precise counter where available (default true). false = sync estimate. */
|
|
23
|
+
exact?: boolean;
|
|
24
|
+
engine?: EngineHandle;
|
|
25
|
+
}
|
|
26
|
+
export declare function countTokens(opts: CountTokensOptions): Promise<number>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** defineTool — concise builder for AgentTool.
|
|
2
|
+
*
|
|
3
|
+
* Reduces tool boilerplate. Instead of:
|
|
4
|
+
*
|
|
5
|
+
* {
|
|
6
|
+
* definition: {
|
|
7
|
+
* name: 'word_count',
|
|
8
|
+
* description: 'Count words',
|
|
9
|
+
* parameters: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
|
|
10
|
+
* },
|
|
11
|
+
* execute: async (args) => String((args as {text:string}).text.split(/\s+/).length),
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* write:
|
|
15
|
+
*
|
|
16
|
+
* defineTool({
|
|
17
|
+
* name: 'word_count',
|
|
18
|
+
* description: 'Count words',
|
|
19
|
+
* params: { text: 'string' },
|
|
20
|
+
* execute: (args) => String(args.text.split(/\s+/).length),
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* Type inference flows from `params` to the typed `args` parameter of
|
|
24
|
+
* `execute`. */
|
|
25
|
+
import type { AgentTool, ToolExecutionContext } from '../agent/types';
|
|
26
|
+
import type { ContentPart } from '../llm/types/messages';
|
|
27
|
+
/** Param spec — one of the JSON-schema scalars or an inline object. */
|
|
28
|
+
export type ParamSpec = 'string' | 'number' | 'integer' | 'boolean' | 'string[]' | 'number[]' | {
|
|
29
|
+
type: 'string' | 'number' | 'integer' | 'boolean';
|
|
30
|
+
enum?: readonly string[];
|
|
31
|
+
description?: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'object';
|
|
34
|
+
properties: Record<string, unknown>;
|
|
35
|
+
required?: string[];
|
|
36
|
+
description?: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'array';
|
|
39
|
+
items: unknown;
|
|
40
|
+
description?: string;
|
|
41
|
+
};
|
|
42
|
+
/** Translate a ParamSpec to its TypeScript type, used to infer `args`. */
|
|
43
|
+
type InferParam<S> = S extends 'string' ? string : S extends 'number' | 'integer' ? number : S extends 'boolean' ? boolean : S extends 'string[]' ? string[] : S extends 'number[]' ? number[] : S extends {
|
|
44
|
+
type: 'string';
|
|
45
|
+
enum: infer E;
|
|
46
|
+
} ? E extends readonly (infer U)[] ? U : string : S extends {
|
|
47
|
+
type: 'string';
|
|
48
|
+
} ? string : S extends {
|
|
49
|
+
type: 'number' | 'integer';
|
|
50
|
+
} ? number : S extends {
|
|
51
|
+
type: 'boolean';
|
|
52
|
+
} ? boolean : unknown;
|
|
53
|
+
type InferArgs<P extends Record<string, ParamSpec>> = {
|
|
54
|
+
[K in keyof P]: InferParam<P[K]>;
|
|
55
|
+
};
|
|
56
|
+
export interface DefineToolInput<P extends Record<string, ParamSpec>> {
|
|
57
|
+
name: string;
|
|
58
|
+
description: string;
|
|
59
|
+
/** Object spec — keys are arg names. All keys are treated as required by
|
|
60
|
+
* default; mark optional ones via `optional: ['x']`. */
|
|
61
|
+
params: P;
|
|
62
|
+
optional?: ReadonlyArray<keyof P & string>;
|
|
63
|
+
execute: (args: InferArgs<P>, context: ToolExecutionContext) => Promise<string | ContentPart[]> | string | ContentPart[];
|
|
64
|
+
}
|
|
65
|
+
export declare function defineTool<P extends Record<string, ParamSpec>>(input: DefineToolInput<P>): AgentTool;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** delegate — wrap an AgentLoop as a single AgentTool that another agent
|
|
2
|
+
* can call. The tool takes a `task: string` and returns the sub-agent's
|
|
3
|
+
* reply text. Useful for agent-as-tool composition / routing patterns. */
|
|
4
|
+
import type { AgentLoop } from '../agent/loop';
|
|
5
|
+
import type { AgentTool } from '../agent/types';
|
|
6
|
+
export declare function delegate(name: string, description: string, agent: AgentLoop): AgentTool;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** embed() — one-shot text→vector helper, mirroring complete().
|
|
2
|
+
*
|
|
3
|
+
* const { embeddings, dimensions } = await embed({
|
|
4
|
+
* model: 'openai/text-embedding-3-small',
|
|
5
|
+
* input: 'hello',
|
|
6
|
+
* });
|
|
7
|
+
* // embeddings[0] is the vector; dimensions is its length.
|
|
8
|
+
*
|
|
9
|
+
* Providers: openai, openrouter (OpenAI-compat), google. (anthropic/xai have no
|
|
10
|
+
* first-party embeddings endpoint.) HTTP flows through engine.fetch. */
|
|
11
|
+
import type { ProviderName } from '../llm/types/provider';
|
|
12
|
+
import type { EmbedResult, EmbeddingProviderAdapter } from '../plugins/embeddings/types';
|
|
13
|
+
import { type EngineHandle } from './engine';
|
|
14
|
+
export interface EmbedOptions {
|
|
15
|
+
/** Model string. Bare (pair with `provider`) or namespaced (`openai/text-embedding-3-small`). */
|
|
16
|
+
model: string;
|
|
17
|
+
provider?: ProviderName;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
input: string | string[];
|
|
20
|
+
/** Override the auto-built provider adapter. */
|
|
21
|
+
adapter?: EmbeddingProviderAdapter;
|
|
22
|
+
engine?: EngineHandle;
|
|
23
|
+
}
|
|
24
|
+
export declare function embed(opts: EmbedOptions): Promise<EmbedResult>;
|