@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,146 @@
|
|
|
1
|
+
/** Media subsystem types — storage, generation requests, results,
|
|
2
|
+
* and provider adapter contract. */
|
|
3
|
+
import type { DataSource } from '../../llm/types/messages';
|
|
4
|
+
import type { Usage } from '../../llm/types/response';
|
|
5
|
+
export type MediaType = 'image' | 'audio' | 'video';
|
|
6
|
+
export interface MediaMeta {
|
|
7
|
+
id: string;
|
|
8
|
+
type: MediaType;
|
|
9
|
+
mimeType: string;
|
|
10
|
+
size: number;
|
|
11
|
+
createdAt: number;
|
|
12
|
+
provider: string;
|
|
13
|
+
model?: string;
|
|
14
|
+
prompt?: string;
|
|
15
|
+
revisedPrompt?: string;
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
durationMs?: number;
|
|
19
|
+
sampleRate?: number;
|
|
20
|
+
params?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface MediaStore {
|
|
23
|
+
save(id: string, data: Uint8Array, meta: MediaMeta): Promise<void>;
|
|
24
|
+
load(id: string): Promise<{
|
|
25
|
+
data: Uint8Array;
|
|
26
|
+
meta: MediaMeta;
|
|
27
|
+
} | null>;
|
|
28
|
+
getMeta(id: string): Promise<MediaMeta | null>;
|
|
29
|
+
delete(id: string): Promise<void>;
|
|
30
|
+
list(filter?: {
|
|
31
|
+
type?: MediaType;
|
|
32
|
+
provider?: string;
|
|
33
|
+
}): Promise<string[]>;
|
|
34
|
+
has(id: string): Promise<boolean>;
|
|
35
|
+
}
|
|
36
|
+
export interface ImageGenRequest {
|
|
37
|
+
provider: string;
|
|
38
|
+
model?: string;
|
|
39
|
+
prompt: string;
|
|
40
|
+
params?: {
|
|
41
|
+
n?: number;
|
|
42
|
+
size?: string;
|
|
43
|
+
aspectRatio?: string;
|
|
44
|
+
/** Google `sampleImageSize` / Gemini `imageSize` (e.g. "1K", "2K"). */
|
|
45
|
+
imageSize?: string;
|
|
46
|
+
resolution?: string;
|
|
47
|
+
quality?: string;
|
|
48
|
+
/** OpenAI gpt-image `background` (transparent|opaque|auto). */
|
|
49
|
+
background?: string;
|
|
50
|
+
/** OpenAI gpt-image `output_format` (png|jpeg|webp). */
|
|
51
|
+
outputFormat?: string;
|
|
52
|
+
style?: string;
|
|
53
|
+
/** OpenRouter image-to-image strength (0–1; lower = closer to the input). */
|
|
54
|
+
strength?: number;
|
|
55
|
+
responseFormat?: 'b64_json' | 'url';
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface ImageEditRequest extends ImageGenRequest {
|
|
59
|
+
sourceImage: DataSource;
|
|
60
|
+
mask?: DataSource;
|
|
61
|
+
}
|
|
62
|
+
export interface AudioGenRequest {
|
|
63
|
+
provider: string;
|
|
64
|
+
model?: string;
|
|
65
|
+
input: string;
|
|
66
|
+
params?: {
|
|
67
|
+
voice?: string;
|
|
68
|
+
format?: string;
|
|
69
|
+
speed?: number;
|
|
70
|
+
instructions?: string;
|
|
71
|
+
sampleRate?: number;
|
|
72
|
+
language?: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export interface VideoGenRequest {
|
|
76
|
+
provider: string;
|
|
77
|
+
model?: string;
|
|
78
|
+
prompt: string;
|
|
79
|
+
sourceImage?: DataSource;
|
|
80
|
+
params?: {
|
|
81
|
+
duration?: number;
|
|
82
|
+
aspectRatio?: string;
|
|
83
|
+
resolution?: string;
|
|
84
|
+
/** OpenAI Sora literal pixel `size` (e.g. "720x1280"). */
|
|
85
|
+
size?: string;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export interface MediaResult {
|
|
89
|
+
id: string;
|
|
90
|
+
type: MediaType;
|
|
91
|
+
mimeType: string;
|
|
92
|
+
meta: MediaMeta;
|
|
93
|
+
}
|
|
94
|
+
export interface RawMediaResult {
|
|
95
|
+
data: Uint8Array;
|
|
96
|
+
mimeType: string;
|
|
97
|
+
width?: number;
|
|
98
|
+
height?: number;
|
|
99
|
+
durationMs?: number;
|
|
100
|
+
sampleRate?: number;
|
|
101
|
+
revisedPrompt?: string;
|
|
102
|
+
/** Token usage the provider reported (token-priced media: gpt-image,
|
|
103
|
+
* gemini-tts). Drives accurate cost via the catalog's per-token rates. */
|
|
104
|
+
usage?: Usage;
|
|
105
|
+
providerMeta?: Record<string, unknown>;
|
|
106
|
+
}
|
|
107
|
+
export interface VideoStatus {
|
|
108
|
+
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
109
|
+
progress?: number;
|
|
110
|
+
error?: string;
|
|
111
|
+
}
|
|
112
|
+
import type { EngineFetch } from '../../network/types';
|
|
113
|
+
export interface MediaCapabilities {
|
|
114
|
+
imageGeneration: boolean;
|
|
115
|
+
imageEditing: boolean;
|
|
116
|
+
audioGeneration: boolean;
|
|
117
|
+
videoGeneration: boolean;
|
|
118
|
+
audioStreaming: boolean;
|
|
119
|
+
}
|
|
120
|
+
/** All MediaProviderAdapter HTTP calls now go through the NetworkEngine
|
|
121
|
+
* queue (rate limits, retries, hooks, observability) instead of holding a
|
|
122
|
+
* private `fetchFn`. The adapter receives an EngineFetch per call from
|
|
123
|
+
* MediaOutput, which in turn was given engine.fetch by the caller.
|
|
124
|
+
*
|
|
125
|
+
* Adapter responsibilities:
|
|
126
|
+
* - Build the right URL / headers / body for a provider operation.
|
|
127
|
+
* - Choose the correct response shape via HttpRequest.responseType
|
|
128
|
+
* ('json' for image-gen / video-status, 'arraybuffer' for binary
|
|
129
|
+
* audio / video downloads).
|
|
130
|
+
* - Parse the response body returned by EngineFetch into RawMediaResult. */
|
|
131
|
+
export interface MediaProviderAdapter {
|
|
132
|
+
readonly name: string;
|
|
133
|
+
capabilities(): MediaCapabilities;
|
|
134
|
+
generateImage(req: ImageGenRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
|
|
135
|
+
editImage?(req: ImageEditRequest, fetch: EngineFetch): Promise<RawMediaResult[]>;
|
|
136
|
+
generateAudio(req: AudioGenRequest, fetch: EngineFetch): Promise<RawMediaResult>;
|
|
137
|
+
submitVideo?(req: VideoGenRequest, fetch: EngineFetch): Promise<string>;
|
|
138
|
+
getVideoStatus?(operationId: string, fetch: EngineFetch): Promise<VideoStatus>;
|
|
139
|
+
downloadVideo?(operationId: string, fetch: EngineFetch): Promise<RawMediaResult>;
|
|
140
|
+
cancelVideo?(operationId: string, fetch: EngineFetch): Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
export interface MediaOutputConfig {
|
|
143
|
+
pollIntervalMs?: number;
|
|
144
|
+
maxPollWaitMs?: number;
|
|
145
|
+
}
|
|
146
|
+
export declare const MEDIA_OUTPUT_DEFAULTS: Required<MediaOutputConfig>;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/** ModelCatalog — pricing, capabilities, and model info. Loaded from JSON. */
|
|
2
|
+
export type ApiType = 'responses' | 'completions' | 'interactions' | 'generate' | 'messages';
|
|
3
|
+
export interface ModelPricing {
|
|
4
|
+
inputPerMTok?: number;
|
|
5
|
+
outputPerMTok?: number;
|
|
6
|
+
cacheReadPerMTok?: number;
|
|
7
|
+
cacheWritePerMTok?: number;
|
|
8
|
+
/** Audio token rates (realtime / audio models), per 1M tokens. */
|
|
9
|
+
audioInputPerMTok?: number;
|
|
10
|
+
audioOutputPerMTok?: number;
|
|
11
|
+
perImage?: number;
|
|
12
|
+
perSecond?: number;
|
|
13
|
+
/** Speech-to-text transcription rate (USD per minute of audio). Used by
|
|
14
|
+
* whisper-class and gpt-4o-transcribe when the provider bills by duration,
|
|
15
|
+
* not by token. The cost engine multiplies by audio duration in minutes. */
|
|
16
|
+
perMinute?: number;
|
|
17
|
+
perMChars?: number;
|
|
18
|
+
/** Per-unit rates keyed by a quality/resolution tier (e.g. video
|
|
19
|
+
* `{"720p":0.1,"1080p":0.12}`, image `{"1k":0.002,"2k":0.02}`). When the
|
|
20
|
+
* selected resolution matches a key, it overrides the flat perImage/perSecond. */
|
|
21
|
+
perUnit?: Record<string, number>;
|
|
22
|
+
/** Per-service-tier rate overrides, keyed by the provider's OWN billed tier
|
|
23
|
+
* name (the value the provider returns: anthropic `standard|priority|batch`,
|
|
24
|
+
* openai `flex|scale|priority|batch`). The flat fields above are the implicit
|
|
25
|
+
* `standard` tier. Cost looks up `tiers[usage.pricingTier]`, falling back to
|
|
26
|
+
* the flat fields — so models without tiers behave exactly as before. */
|
|
27
|
+
tiers?: Record<string, TierRates>;
|
|
28
|
+
}
|
|
29
|
+
/** One service tier's rate overrides — same shape as the flat rates, no nesting. */
|
|
30
|
+
export type TierRates = Omit<ModelPricing, 'tiers'>;
|
|
31
|
+
export interface ModelCapabilities {
|
|
32
|
+
toolUse: boolean;
|
|
33
|
+
builtinTools?: string[];
|
|
34
|
+
streaming: boolean;
|
|
35
|
+
structuredOutput: boolean;
|
|
36
|
+
vision: boolean;
|
|
37
|
+
audio: boolean;
|
|
38
|
+
video: boolean;
|
|
39
|
+
imageGeneration: boolean;
|
|
40
|
+
audioGeneration: boolean;
|
|
41
|
+
videoGeneration: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** One generation parameter a media model accepts, with its allowed values.
|
|
44
|
+
* Either an enum (`values` + `default`) or a numeric range (`min`/`max`).
|
|
45
|
+
* Keys are normalized (e.g. `aspectRatio`, `size`, `voice`, `duration`); each
|
|
46
|
+
* provider adapter maps the normalized key to its own wire param name. */
|
|
47
|
+
export interface MediaParamSpec {
|
|
48
|
+
/** Enumerated allowed values for a string param. */
|
|
49
|
+
values?: string[];
|
|
50
|
+
/** Numeric bounds for an integer param (e.g. duration seconds, image count). */
|
|
51
|
+
min?: number;
|
|
52
|
+
max?: number;
|
|
53
|
+
/** Default value (blank/omitted means "let the provider decide"). */
|
|
54
|
+
default?: string | number;
|
|
55
|
+
/** Where the allowed values came from + when last verified. */
|
|
56
|
+
source?: string;
|
|
57
|
+
verifiedOn?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ModelReasoning {
|
|
60
|
+
supported: boolean;
|
|
61
|
+
automatic: boolean;
|
|
62
|
+
effortControl: boolean;
|
|
63
|
+
effortValues?: string[];
|
|
64
|
+
encryptedContent: boolean;
|
|
65
|
+
summaryAvailable: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface TokenizerInfo {
|
|
68
|
+
strategy: 'heuristic' | 'tiktoken' | 'count_api';
|
|
69
|
+
charsPerTokenDefault: number;
|
|
70
|
+
countApiAvailable: boolean;
|
|
71
|
+
tiktokenEncoding?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface ModelInfo {
|
|
74
|
+
provider: string;
|
|
75
|
+
/** Catalog key — our canonical (normalised) slug, e.g. `claude-opus-4.8`. */
|
|
76
|
+
model: string;
|
|
77
|
+
pricing: ModelPricing;
|
|
78
|
+
preferredApi: ApiType;
|
|
79
|
+
supportedApis: ApiType[];
|
|
80
|
+
contextWindow?: number;
|
|
81
|
+
maxOutput?: number;
|
|
82
|
+
capabilities: ModelCapabilities;
|
|
83
|
+
reasoning: ModelReasoning;
|
|
84
|
+
mediaOnly?: boolean;
|
|
85
|
+
tokenizer?: TokenizerInfo;
|
|
86
|
+
requiresDedicatedClient?: boolean;
|
|
87
|
+
supportsPreviousResponseId?: boolean;
|
|
88
|
+
/** Exact id to SEND to the provider API (may differ from the slug + carry
|
|
89
|
+
* dates). When set, the SDK sends this; otherwise it sends `model`. */
|
|
90
|
+
providerModelName?: string;
|
|
91
|
+
/** Other callable ids that resolve to this model (dated snapshots, the bare
|
|
92
|
+
* callable form). Indexed for lookup + accepted as model strings. */
|
|
93
|
+
aliases?: string[];
|
|
94
|
+
/** Model role/modality: chat | code | image | video | tts | stt | embedding | … */
|
|
95
|
+
type?: string;
|
|
96
|
+
/** Content kinds the model ACCEPTS as input: text | image | audio | video |
|
|
97
|
+
* pdf. Use to decide whether prior media can be replayed to this model. */
|
|
98
|
+
inputModalities?: string[];
|
|
99
|
+
/** Content kinds the model PRODUCES: text | image | audio | video. */
|
|
100
|
+
outputModalities?: string[];
|
|
101
|
+
/** For media models: the generation params this model accepts + allowed
|
|
102
|
+
* values, keyed by normalized param name. Drives UI + validation. */
|
|
103
|
+
mediaParams?: Record<string, MediaParamSpec>;
|
|
104
|
+
family?: string;
|
|
105
|
+
version?: string;
|
|
106
|
+
/** Lifecycle: stable | preview | legacy. */
|
|
107
|
+
status?: string;
|
|
108
|
+
/** Callable from this account/SDK now (probe-verified). false = don't call. */
|
|
109
|
+
active?: boolean;
|
|
110
|
+
/** End-of-life signalled by a source. */
|
|
111
|
+
deprecation?: {
|
|
112
|
+
date?: string;
|
|
113
|
+
shutdownDate?: string;
|
|
114
|
+
source: string;
|
|
115
|
+
};
|
|
116
|
+
/** Server-side state retention as a duration string ("30d", "72h"). null = none. */
|
|
117
|
+
stateRetentionDuration?: string | null;
|
|
118
|
+
/** Whether server-state continuation requires the SAME model (true) or works
|
|
119
|
+
* across models of the same provider (false). Safe default: true. */
|
|
120
|
+
stateModelBound?: boolean;
|
|
121
|
+
}
|
|
122
|
+
export declare class ModelCatalog {
|
|
123
|
+
private models;
|
|
124
|
+
/** `provider/alias` → `provider/canonical-slug`. Lets get()/resolveModelId
|
|
125
|
+
* accept any callable id (providerModelName, dated snapshot) AND the slug. */
|
|
126
|
+
private aliasIndex;
|
|
127
|
+
private key;
|
|
128
|
+
set(provider: string, model: string, info: Partial<Omit<ModelInfo, 'provider' | 'model'>> & {
|
|
129
|
+
pricing: ModelPricing;
|
|
130
|
+
}): void;
|
|
131
|
+
get(provider: string, model: string): ModelInfo | null;
|
|
132
|
+
/** The exact id to SEND to the provider for a given model string. Translates
|
|
133
|
+
* our slug → providerModelName; passes an already-callable id (alias) through
|
|
134
|
+
* verbatim (respects an explicit choice); unknown model → verbatim passthrough. */
|
|
135
|
+
resolveModelId(provider: string, model: string): string;
|
|
136
|
+
getPricing(provider: string, model: string): ModelPricing | null;
|
|
137
|
+
getPreferredApi(provider: string, model: string): ApiType | null;
|
|
138
|
+
supportsApi(provider: string, model: string, api: ApiType): boolean;
|
|
139
|
+
supportsTools(provider: string, model: string): boolean;
|
|
140
|
+
supportsPreviousResponseId(provider: string, model: string): boolean;
|
|
141
|
+
/** Server-state retention as a duration string ("30d", "72h"), or null if unsupported. */
|
|
142
|
+
getStateRetention(provider: string, model: string): string | null;
|
|
143
|
+
/** Whether server-state continuation requires the same model (true) or works
|
|
144
|
+
* across models of the same provider (false). Safe default: true. */
|
|
145
|
+
isStateModelBound(provider: string, model: string): boolean;
|
|
146
|
+
list(provider?: string): ModelInfo[];
|
|
147
|
+
load(data: Record<string, unknown>): void;
|
|
148
|
+
/** Load every provider's `catalog.json` shipped with the SDK. Synchronous —
|
|
149
|
+
* the JSON files are bundled via static import so no I/O at runtime. */
|
|
150
|
+
loadProviderDefaults(): void;
|
|
151
|
+
get size(): number;
|
|
152
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Minimal glob → regex compiler for permission target matching. */
|
|
2
|
+
export interface GlobOptions {
|
|
3
|
+
loose?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function globToRegex(pattern: string, options?: GlobOptions): RegExp;
|
|
6
|
+
export declare function compileGlobs(patterns: readonly string[], options?: GlobOptions): (s: string) => boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Built-in TargetMatcher factories. */
|
|
2
|
+
import type { TargetMatcher } from './types';
|
|
3
|
+
export declare function memoryCategory(...categories: string[]): TargetMatcher;
|
|
4
|
+
export declare function fsGlob(...patterns: string[]): TargetMatcher;
|
|
5
|
+
export declare function shellGlob(...patterns: string[]): TargetMatcher;
|
|
6
|
+
export declare function urlPattern(...patterns: string[]): TargetMatcher;
|
|
7
|
+
export declare function anyOfKind(...kinds: string[]): TargetMatcher;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** PermissionPolicy — walk rules in declaration order, first match wins.
|
|
2
|
+
* No matching rule → default-deny. */
|
|
3
|
+
import type { PermissionDecision, PermissionTarget, Rule } from './types';
|
|
4
|
+
export declare class PermissionPolicy {
|
|
5
|
+
private readonly rules;
|
|
6
|
+
constructor(rules: readonly Rule[]);
|
|
7
|
+
check(source: string, target: PermissionTarget, action: string): PermissionDecision;
|
|
8
|
+
withAdditional(extra: readonly Rule[]): PermissionPolicy;
|
|
9
|
+
get size(): number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Permissions — pure rule evaluator for `(source, target, action)` tuples. */
|
|
2
|
+
export interface PermissionTarget {
|
|
3
|
+
kind: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export type TargetMatcher = (target: PermissionTarget) => boolean;
|
|
7
|
+
export interface Rule {
|
|
8
|
+
source?: string | string[];
|
|
9
|
+
target?: TargetMatcher;
|
|
10
|
+
action?: string | string[];
|
|
11
|
+
/** 'allow' — proceed; 'deny' — block; 'ask' — suspend for human approval. */
|
|
12
|
+
effect: 'allow' | 'deny' | 'ask';
|
|
13
|
+
reason?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PermissionDecision {
|
|
16
|
+
/** True when effect is 'allow'. False for 'deny' and 'ask'. */
|
|
17
|
+
allow: boolean;
|
|
18
|
+
/** True when effect is 'ask' — caller must request human approval. */
|
|
19
|
+
ask?: boolean;
|
|
20
|
+
reason?: string;
|
|
21
|
+
matchedRule?: number;
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** FilePersistence — stores each key as a JSON file in a directory.
|
|
2
|
+
*
|
|
3
|
+
* Key encoding: chars outside `[A-Za-z0-9_.-]` are %-escaped (URL-style)
|
|
4
|
+
* so any key works on Windows/Unix filesystems.
|
|
5
|
+
*
|
|
6
|
+
* Concurrency: writes are not atomic. For a multi-process scenario,
|
|
7
|
+
* callers should layer their own locking on top. Single-process,
|
|
8
|
+
* single-thread use is safe. */
|
|
9
|
+
import type { Persistence } from './types';
|
|
10
|
+
export interface FilePersistenceConfig {
|
|
11
|
+
/** Directory in which JSON files are stored. Created on first write. */
|
|
12
|
+
dir: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class FilePersistence implements Persistence {
|
|
15
|
+
private readonly dir;
|
|
16
|
+
private readonly ready;
|
|
17
|
+
constructor(config: FilePersistenceConfig | string);
|
|
18
|
+
get<T>(key: string): Promise<T | null>;
|
|
19
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
20
|
+
delete(key: string): Promise<void>;
|
|
21
|
+
list(prefix?: string): Promise<string[]>;
|
|
22
|
+
has(key: string): Promise<boolean>;
|
|
23
|
+
private keyPath;
|
|
24
|
+
private ensureDir;
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** MemoryPersistence — in-process Map-backed Persistence implementation.
|
|
2
|
+
*
|
|
3
|
+
* Use cases:
|
|
4
|
+
* - Unit tests (no temp dirs).
|
|
5
|
+
* - Ephemeral runs where state should not outlive the process.
|
|
6
|
+
* - Default fallback in createEngine when no persistence is configured.
|
|
7
|
+
*
|
|
8
|
+
* Values are deep-copied via structuredClone on get/set to prevent callers
|
|
9
|
+
* from mutating stored objects through retained references. This matches
|
|
10
|
+
* FilePersistence semantics (JSON serialize/parse round-trip). */
|
|
11
|
+
import type { Persistence } from './types';
|
|
12
|
+
export declare class MemoryPersistence implements Persistence {
|
|
13
|
+
private store;
|
|
14
|
+
get<T>(key: string): Promise<T | null>;
|
|
15
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
16
|
+
delete(key: string): Promise<void>;
|
|
17
|
+
list(prefix?: string): Promise<string[]>;
|
|
18
|
+
has(key: string): Promise<boolean>;
|
|
19
|
+
/** Test affordance: number of stored entries. Not part of Persistence iface. */
|
|
20
|
+
get size(): number;
|
|
21
|
+
/** Test affordance: drop everything. Not part of Persistence iface. */
|
|
22
|
+
clear(): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Persistence interface — unified key-value storage.
|
|
2
|
+
*
|
|
3
|
+
* Implementations:
|
|
4
|
+
* - `MemoryPersistence` — in-process Map (tests, ephemeral state).
|
|
5
|
+
* - `FilePersistence` — JSON files per key on disk.
|
|
6
|
+
* - (future) DbPersistence, RedisPersistence, ...
|
|
7
|
+
*
|
|
8
|
+
* Used by: ConfigurationPlugin, Cache (FileCacheStore), Scheduler,
|
|
9
|
+
* ResponseStore, ConversationPersistence, Batcher (pending jobs). */
|
|
10
|
+
export interface Persistence {
|
|
11
|
+
/** Get a value by key. Returns null if not found. */
|
|
12
|
+
get<T>(key: string): Promise<T | null>;
|
|
13
|
+
/** Set a value. Overwrites if exists. */
|
|
14
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
15
|
+
/** Delete a key. No-op if not found. */
|
|
16
|
+
delete(key: string): Promise<void>;
|
|
17
|
+
/** List all keys, optionally filtered by prefix. */
|
|
18
|
+
list(prefix?: string): Promise<string[]>;
|
|
19
|
+
/** Check if a key exists. */
|
|
20
|
+
has(key: string): Promise<boolean>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Text chunker — splits text into overlapping windows of approximate token size.
|
|
2
|
+
*
|
|
3
|
+
* Uses a character-based approximation for token counting (no external dep,
|
|
4
|
+
* works in the browser). The `countTokensFn` injection point lets callers
|
|
5
|
+
* swap in a more accurate counter without changing the chunker contract.
|
|
6
|
+
*
|
|
7
|
+
* Named constants govern all defaults — no magic values. */
|
|
8
|
+
/** Default maximum chunk size in tokens (approximate). */
|
|
9
|
+
export declare const DEFAULT_CHUNK_MAX_TOKENS = 512;
|
|
10
|
+
/** Default overlap between consecutive chunks in tokens. */
|
|
11
|
+
export declare const DEFAULT_CHUNK_OVERLAP_TOKENS = 64;
|
|
12
|
+
export interface ChunkOptions {
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
overlapTokens?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface TextChunk {
|
|
17
|
+
/** The chunk content. */
|
|
18
|
+
text: string;
|
|
19
|
+
/** Byte offset of the chunk start in the source text. */
|
|
20
|
+
offset: number;
|
|
21
|
+
/** 0-based chunk index within the document. */
|
|
22
|
+
index: number;
|
|
23
|
+
}
|
|
24
|
+
/** Optional injected token counter (synchronous estimate only; no I/O path). */
|
|
25
|
+
export type EstimateTokensFn = (text: string) => number;
|
|
26
|
+
/** Split `text` into overlapping windows based on approximate token count.
|
|
27
|
+
* Splits on whitespace boundaries to avoid cutting words mid-token. */
|
|
28
|
+
export declare function chunkText(text: string, opts?: ChunkOptions, estimateTokens?: EstimateTokensFn): TextChunk[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Hosted Google (Gemini) File Search backend.
|
|
2
|
+
*
|
|
3
|
+
* Maps the unified RetrievalBackend interface to the Gemini File Search API:
|
|
4
|
+
* createCorpus -> POST {base}/v1beta/fileSearchStores
|
|
5
|
+
* addDocument -> POST {upload}/upload/v1beta/files (Files API)
|
|
6
|
+
* -> POST {base}/v1beta/{store}:importFile
|
|
7
|
+
* indexStatus -> GET {base}/v1beta/{store} (normalized from count fields)
|
|
8
|
+
* removeDocument -> DELETE {base}/v1beta/{fileName}
|
|
9
|
+
* deleteCorpus -> DELETE {base}/v1beta/{store}?force=true
|
|
10
|
+
* listCorpora -> GET {base}/v1beta/fileSearchStores
|
|
11
|
+
* asTool -> returns ProviderToolSpec { fileSearch: { fileSearchStoreNames, ... } }
|
|
12
|
+
* search -> not supported; use asTool
|
|
13
|
+
*
|
|
14
|
+
* Auth: x-goog-api-key REQUEST HEADER (NOT ?key= query param) to avoid telemetry key-leak.
|
|
15
|
+
* See SEC-C1 in the readiness audit for why ?key= was fixed in the google provider adapter.
|
|
16
|
+
*
|
|
17
|
+
* ALL HTTP flows through the injected EngineFetch (NetworkEngine queue).
|
|
18
|
+
* Never globalThis.fetch.
|
|
19
|
+
*
|
|
20
|
+
* Note: the asTool() emitter produces the Gemini-native generateContent tool shape:
|
|
21
|
+
* { fileSearch: { fileSearchStoreNames: [...], metadataFilter? } }
|
|
22
|
+
* This diverges from the OpenAI/xAI `file_search` + `vector_store_ids` family on purpose.
|
|
23
|
+
* Google's File Search API uses its own AIP-160 filter and camelCase field names.
|
|
24
|
+
*
|
|
25
|
+
* Provider behavior note: raw uploaded Files API files expire ~48h after upload.
|
|
26
|
+
* The fileSearchStore ITSELF persists until deleted. This asymmetry is provider-managed;
|
|
27
|
+
* callers should not depend on re-downloading the source file from Files API after 48h. */
|
|
28
|
+
import type { EngineFetch } from '../../network/types';
|
|
29
|
+
import type { AddDocumentOptions, AsToolOptions, CorpusRef, CreateCorpusOptions, DocumentRef, DocumentSource, IndexStatus, ProviderToolSpec, RetrievalBackend, RetrievalCapabilities, RetrievalHit, RetrievalSearchOptions } from './types';
|
|
30
|
+
export interface HostedGoogleRetrievalConfig {
|
|
31
|
+
apiKey: string;
|
|
32
|
+
fetch: EngineFetch;
|
|
33
|
+
baseURL?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare class HostedGoogleRetrievalBackend implements RetrievalBackend {
|
|
36
|
+
readonly capabilities: RetrievalCapabilities;
|
|
37
|
+
private readonly apiKey;
|
|
38
|
+
private readonly fetch;
|
|
39
|
+
private readonly baseURL;
|
|
40
|
+
constructor(config: HostedGoogleRetrievalConfig);
|
|
41
|
+
private authHeaders;
|
|
42
|
+
/** Auth headers for multipart/form-data file upload (no content-type override). */
|
|
43
|
+
private authHeadersNoContentType;
|
|
44
|
+
createCorpus(opts: CreateCorpusOptions): Promise<CorpusRef>;
|
|
45
|
+
addDocument(corpus: CorpusRef, source: DocumentSource, opts?: AddDocumentOptions): Promise<DocumentRef>;
|
|
46
|
+
/** Poll a long-running Operation until done: true.
|
|
47
|
+
* Returns the operation body when complete. */
|
|
48
|
+
pollOperation(operationName: string): Promise<Record<string, unknown>>;
|
|
49
|
+
indexStatus(corpus: CorpusRef): Promise<IndexStatus>;
|
|
50
|
+
removeDocument(corpus: CorpusRef, docId: string): Promise<void>;
|
|
51
|
+
deleteCorpus(corpus: CorpusRef): Promise<void>;
|
|
52
|
+
listCorpora(): Promise<CorpusRef[]>;
|
|
53
|
+
/** Returns a Gemini-native `fileSearch` ProviderToolSpec for splicing into a generateContent call.
|
|
54
|
+
* NOTE: this spec shape diverges from the OpenAI/xAI `file_search` + `vector_store_ids` family.
|
|
55
|
+
* Gemini uses camelCase `fileSearch` / `fileSearchStoreNames` with AIP-160 metadataFilter. */
|
|
56
|
+
asTool(corpora: CorpusRef[], opts?: AsToolOptions): ProviderToolSpec;
|
|
57
|
+
/** Direct search is not supported for server-side Gemini file search stores.
|
|
58
|
+
* Use `asTool()` and splice the spec into a generateContent call instead. */
|
|
59
|
+
search(_corpora: CorpusRef[], _query: string, _opts?: RetrievalSearchOptions): Promise<RetrievalHit[]>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Hosted OpenAI Vector Stores backend.
|
|
2
|
+
*
|
|
3
|
+
* Maps the unified RetrievalBackend interface to the OpenAI Vector Stores API:
|
|
4
|
+
* createCorpus -> POST /v1/vector_stores
|
|
5
|
+
* addDocument -> POST /v1/files then POST /v1/vector_stores/{id}/files
|
|
6
|
+
* indexStatus -> GET /v1/vector_stores/{id} (normalized)
|
|
7
|
+
* removeDocument-> DELETE /v1/vector_stores/{id}/files/{file_id}
|
|
8
|
+
* deleteCorpus -> DELETE /v1/vector_stores/{id}
|
|
9
|
+
* listCorpora -> GET /v1/vector_stores
|
|
10
|
+
* asTool -> returns ProviderToolSpec (splice into a Responses call)
|
|
11
|
+
* search -> not supported server-side; use asTool
|
|
12
|
+
*
|
|
13
|
+
* ALL HTTP flows through the injected EngineFetch (NetworkEngine queue).
|
|
14
|
+
* Never globalThis.fetch.
|
|
15
|
+
*
|
|
16
|
+
* Note: xAI will reuse the `asTool` emitter shape (same file_search spec) —
|
|
17
|
+
* the divergence point for xAI will be the base URL and any auth differences.
|
|
18
|
+
* // future: hostedXai — subclass or factory: pass baseURL, different auth header. */
|
|
19
|
+
import type { EngineFetch } from '../../network/types';
|
|
20
|
+
import type { AddDocumentOptions, AsToolOptions, CorpusRef, CreateCorpusOptions, DocumentRef, DocumentSource, IndexStatus, ProviderToolSpec, RetrievalBackend, RetrievalCapabilities, RetrievalHit, RetrievalSearchOptions } from './types';
|
|
21
|
+
export interface HostedOpenAIRetrievalConfig {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
fetch: EngineFetch;
|
|
24
|
+
baseURL?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare class HostedOpenAIRetrievalBackend implements RetrievalBackend {
|
|
27
|
+
readonly capabilities: RetrievalCapabilities;
|
|
28
|
+
private readonly apiKey;
|
|
29
|
+
private readonly fetch;
|
|
30
|
+
private readonly baseURL;
|
|
31
|
+
constructor(config: HostedOpenAIRetrievalConfig);
|
|
32
|
+
private bearer;
|
|
33
|
+
createCorpus(opts: CreateCorpusOptions): Promise<CorpusRef>;
|
|
34
|
+
addDocument(corpus: CorpusRef, source: DocumentSource, opts?: AddDocumentOptions): Promise<DocumentRef>;
|
|
35
|
+
indexStatus(corpus: CorpusRef): Promise<IndexStatus>;
|
|
36
|
+
removeDocument(corpus: CorpusRef, docId: string): Promise<void>;
|
|
37
|
+
deleteCorpus(corpus: CorpusRef): Promise<void>;
|
|
38
|
+
listCorpora(): Promise<CorpusRef[]>;
|
|
39
|
+
/** Returns a `file_search` ProviderToolSpec for splicing into a Responses call.
|
|
40
|
+
* // future: hostedXai will reuse this same tool spec shape. */
|
|
41
|
+
asTool(corpora: CorpusRef[], opts?: AsToolOptions): ProviderToolSpec;
|
|
42
|
+
/** Direct search is not supported for server-side vector stores.
|
|
43
|
+
* Use `asTool()` and splice the spec into a Responses API call instead. */
|
|
44
|
+
search(_corpora: CorpusRef[], _query: string, _opts?: RetrievalSearchOptions): Promise<RetrievalHit[]>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Hosted xAI (Grok Collections) retrieval backend.
|
|
2
|
+
*
|
|
3
|
+
* Two API planes, two keys, two Bearer auths:
|
|
4
|
+
* Management API base https://management-api.x.ai/v1 -- managementApiKey
|
|
5
|
+
* Standard API base https://api.x.ai/v1 -- apiKey
|
|
6
|
+
*
|
|
7
|
+
* Maps the unified RetrievalBackend interface:
|
|
8
|
+
* createCorpus -> POST {mgmt}/collections body { collection_name }
|
|
9
|
+
* addDocument -> POST {std}/files (multipart) then
|
|
10
|
+
* -> POST {mgmt}/collections/{id}/documents/{file_id}
|
|
11
|
+
* indexStatus -> GET {mgmt}/collections/{id} (normalised from documents_count)
|
|
12
|
+
* removeDocument -> DELETE {mgmt}/collections/{id}/documents/{fileId}
|
|
13
|
+
* deleteCorpus -> DELETE {mgmt}/collections/{id}
|
|
14
|
+
* listCorpora -> GET {mgmt}/collections
|
|
15
|
+
* search -> POST {std}/documents/search (hybrid/keyword/semantic)
|
|
16
|
+
* asTool -> ProviderToolSpec { type: 'file_search', vector_store_ids: [...] }
|
|
17
|
+
*
|
|
18
|
+
* asTool reuses the OpenAI file_search spec shape because xAI /responses is OpenAI-compatible
|
|
19
|
+
* for file_search; a native collections_search shape is NOT accepted (verified 422).
|
|
20
|
+
*
|
|
21
|
+
* ALL HTTP flows through the injected EngineFetch (NetworkEngine queue).
|
|
22
|
+
* Never globalThis.fetch. */
|
|
23
|
+
import type { EngineFetch } from '../../network/types';
|
|
24
|
+
import type { AddDocumentOptions, AsToolOptions, CorpusRef, CreateCorpusOptions, DocumentRef, DocumentSource, IndexStatus, ProviderToolSpec, RetrievalBackend, RetrievalCapabilities, RetrievalHit, RetrievalSearchOptions } from './types';
|
|
25
|
+
export interface HostedXaiRetrievalConfig {
|
|
26
|
+
/** Standard API key (api.x.ai) — used for file uploads and search. */
|
|
27
|
+
apiKey: string;
|
|
28
|
+
/** Management API key (management-api.x.ai) — used for collection management. */
|
|
29
|
+
managementApiKey: string;
|
|
30
|
+
fetch: EngineFetch;
|
|
31
|
+
/** Override for the standard API base URL. */
|
|
32
|
+
baseURL?: string;
|
|
33
|
+
/** Override for the management API base URL. */
|
|
34
|
+
managementBaseURL?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare class HostedXaiRetrievalBackend implements RetrievalBackend {
|
|
37
|
+
readonly capabilities: RetrievalCapabilities;
|
|
38
|
+
private readonly apiKey;
|
|
39
|
+
private readonly managementApiKey;
|
|
40
|
+
private readonly fetch;
|
|
41
|
+
private readonly baseURL;
|
|
42
|
+
private readonly managementBaseURL;
|
|
43
|
+
constructor(config: HostedXaiRetrievalConfig);
|
|
44
|
+
private stdBearer;
|
|
45
|
+
private mgmtBearer;
|
|
46
|
+
createCorpus(opts: CreateCorpusOptions): Promise<CorpusRef>;
|
|
47
|
+
addDocument(corpus: CorpusRef, source: DocumentSource, opts?: AddDocumentOptions): Promise<DocumentRef>;
|
|
48
|
+
indexStatus(corpus: CorpusRef): Promise<IndexStatus>;
|
|
49
|
+
removeDocument(corpus: CorpusRef, fileId: string): Promise<void>;
|
|
50
|
+
deleteCorpus(corpus: CorpusRef): Promise<void>;
|
|
51
|
+
listCorpora(): Promise<CorpusRef[]>;
|
|
52
|
+
search(corpora: CorpusRef[], query: string, opts?: RetrievalSearchOptions): Promise<RetrievalHit[]>;
|
|
53
|
+
/** Returns a `file_search` ProviderToolSpec for splicing into a Responses call.
|
|
54
|
+
* xAI Responses is OpenAI-compatible for file_search; native collections_search
|
|
55
|
+
* is NOT accepted (verified 422). */
|
|
56
|
+
asTool(corpora: CorpusRef[], opts?: AsToolOptions): ProviderToolSpec;
|
|
57
|
+
}
|