@qilin-agent/llm 0.0.0-stage → 3.1.4
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/LICENSE +21 -0
- package/README.i18n.yaml +64 -0
- package/README.md +177 -2
- package/README.zh.md +178 -0
- package/lib/index.js +2388 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +626 -0
- package/lib/typert.remote-client.d.ts +26 -0
- package/lib/typert.remote-client.js +109 -0
- package/lib/types/adapter-failure.d.ts +14 -0
- package/lib/types/adapter-failure.js +108 -0
- package/lib/types/api-key.d.ts +28 -0
- package/lib/types/api-key.js +34 -0
- package/lib/types/assembler.d.ts +75 -0
- package/lib/types/assembler.js +191 -0
- package/lib/types/assistant-stream.d.ts +166 -0
- package/lib/types/assistant-stream.js +458 -0
- package/lib/types/attribution.d.ts +47 -0
- package/lib/types/attribution.js +46 -0
- package/lib/types/brand.d.ts +56 -0
- package/lib/types/brand.js +53 -0
- package/lib/types/call-config.d.ts +53 -0
- package/lib/types/call-config.js +46 -0
- package/lib/types/content.d.ts +149 -0
- package/lib/types/content.js +355 -0
- package/lib/types/error.d.ts +81 -0
- package/lib/types/error.js +153 -0
- package/lib/types/index.d.ts +416 -0
- package/lib/types/index.js +948 -0
- package/lib/types/message.d.ts +246 -0
- package/lib/types/message.js +101 -0
- package/lib/types/retry-policy.d.ts +66 -0
- package/lib/types/retry-policy.js +127 -0
- package/lib/types/types.d.ts +532 -0
- package/lib/types/types.js +7 -0
- package/package.json +74 -3
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM service: adapter registry with a waterfall-interceptable streaming call
|
|
3
|
+
* API. Exports the `LlmRuntime` default, the abstract `LlmAdapter` for
|
|
4
|
+
* provider backends, and `BlockAssembler` for chunk assembly.
|
|
5
|
+
*
|
|
6
|
+
* @module @qilin-agent/llm
|
|
7
|
+
*/
|
|
8
|
+
import { Context } from '@qilin-agent/kylin';
|
|
9
|
+
import { TypertRemoteService } from '@qilin-agent/typert-protocol';
|
|
10
|
+
import type { GenerateOptions, LlmConfigurableProvider, LlmDiscoveredModel, LlmFailure, LlmImageRequestPricing, LlmModelContext, LlmModelDiscoveryRequest, LlmModelInfo, LlmResolvedModelInfo, LlmProviderInfo, ModelModality, StreamChunk, SystemPromptUpdate, ToolUpdate } from './types.ts';
|
|
11
|
+
import type { ResolvedRetryPolicy } from './retry-policy.ts';
|
|
12
|
+
import type { ProviderRequestId } from './brand.ts';
|
|
13
|
+
import type { LlmCallConfig, LlmCallConfigAdapterDefaults } from './call-config.ts';
|
|
14
|
+
import { HarnessError } from './error.ts';
|
|
15
|
+
import type { FileAttachmentRef } from '@qilin-agent/attachment';
|
|
16
|
+
export * from './attribution.ts';
|
|
17
|
+
export * from './brand.ts';
|
|
18
|
+
export * from './error.ts';
|
|
19
|
+
export * from './api-key.ts';
|
|
20
|
+
export * from './types.ts';
|
|
21
|
+
export * from './content.ts';
|
|
22
|
+
export * from './assistant-stream.ts';
|
|
23
|
+
export * from './message.ts';
|
|
24
|
+
export * from './retry-policy.ts';
|
|
25
|
+
export { BlockAssembler } from './assembler.ts';
|
|
26
|
+
export { callConfigEquals, isAgentLoopRequest, markAgentLoopRequest } from './call-config.ts';
|
|
27
|
+
export type { LlmCallConfig, LlmCallConfigAdapterDefaults } from './call-config.ts';
|
|
28
|
+
declare module '@qilin-agent/kylin' {
|
|
29
|
+
interface Context {
|
|
30
|
+
llm: LlmRuntime;
|
|
31
|
+
}
|
|
32
|
+
interface Events {
|
|
33
|
+
/**
|
|
34
|
+
* Waterfall around every streaming model call (retry, replay, routing).
|
|
35
|
+
* Bound to the {@link LlmRuntime}; call `next()` to reach the resolved
|
|
36
|
+
* adapter's stream, or yield your own chunks to short-circuit.
|
|
37
|
+
* @param options - the full request. A LOOP-built request carries the
|
|
38
|
+
* process-local {@link markAgentLoopRequest} identity and arrives deep-frozen
|
|
39
|
+
* (mutation throws): its content is a pure function of the session log (the
|
|
40
|
+
* reconstructability Agent Note), so listeners read it, never rewrite it.
|
|
41
|
+
* Hand-built calls do not carry that marker; callers own their request
|
|
42
|
+
* inputs and must keep them unchanged until the stream settles.
|
|
43
|
+
* @mode waterfall
|
|
44
|
+
*/
|
|
45
|
+
'llm/stream'(this: LlmRuntime, options: GenerateOptions, next: () => AsyncIterable<StreamChunk>): AsyncIterable<StreamChunk>;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Structured provider facts and cause accepted by {@link LlmError}. */
|
|
49
|
+
export interface LlmErrorOptions extends ErrorOptions {
|
|
50
|
+
/** Valid HTTP status observed at the provider boundary. */
|
|
51
|
+
status?: number;
|
|
52
|
+
/** Positive finite provider-requested delay in milliseconds. */
|
|
53
|
+
providerRetryAfterMs?: number;
|
|
54
|
+
/** Non-empty opaque provider request id. */
|
|
55
|
+
requestId?: ProviderRequestId;
|
|
56
|
+
/** Positive count of additional oldest retained image occurrences to offload; only with `IMAGE_OFFLOAD_REQUIRED`. */
|
|
57
|
+
offloadImages?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Typed error for LLM-related failures. Extends {@link HarnessError}, so the
|
|
61
|
+
* `code` string (e.g. `AUTH`, `RATE_LIMIT`, `NO_ADAPTER`) is shared taxonomy.
|
|
62
|
+
*/
|
|
63
|
+
export declare class LlmError extends HarnessError {
|
|
64
|
+
/** Serializable facts retained beside this live Error. */
|
|
65
|
+
readonly failure: LlmFailure;
|
|
66
|
+
/**
|
|
67
|
+
* @param message - non-empty human-readable failure summary.
|
|
68
|
+
* @param code - non-empty stable provider-neutral machine code.
|
|
69
|
+
* @param options - optional cause and validated serializable provider facts.
|
|
70
|
+
*/
|
|
71
|
+
constructor(message: string, code: string, options?: LlmErrorOptions);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Accept one supplied credential, or refuse it as unusable.
|
|
75
|
+
*
|
|
76
|
+
* A stored key arrives from the credentials seam, a `.env` line, or a shell
|
|
77
|
+
* export, all of which pick up surrounding whitespace, so trimming is silent.
|
|
78
|
+
* Anything else fails here rather than inside `fetch`, whose ByteString
|
|
79
|
+
* refusal names a UTF-16 code point instead of the setting to change. The key
|
|
80
|
+
* never enters the message: `ref` names where to fix it, and echoing any part
|
|
81
|
+
* of a secret into a log or a UI is the failure this diagnosis avoids.
|
|
82
|
+
*
|
|
83
|
+
* Lives beside {@link LlmError} rather than in `./api-key.ts` so the predicate
|
|
84
|
+
* module stays dependency-free; both adapters share this one diagnosis instead
|
|
85
|
+
* of keeping near-identical local copies.
|
|
86
|
+
* @param raw - the credential exactly as supplied.
|
|
87
|
+
* @param pkg - the refusing package name, prefixed to the diagnostic.
|
|
88
|
+
* @param ref - the credential reference the value resolved through.
|
|
89
|
+
* @returns the trimmed, usable key.
|
|
90
|
+
*/
|
|
91
|
+
export declare function assertUsableApiKey(raw: string, pkg: string, ref: string): string;
|
|
92
|
+
/** One model call whose config and adapter registration were resolved together. */
|
|
93
|
+
export interface PreparedLlmCall {
|
|
94
|
+
/** Detached, deep-frozen config with any adapter-owned default materialized. */
|
|
95
|
+
readonly config: LlmCallConfig;
|
|
96
|
+
/** Immutable retry policy captured with the adapter registration. */
|
|
97
|
+
readonly retryPolicy: ResolvedRetryPolicy;
|
|
98
|
+
/** Detached context metadata resolved with the registration-bound call. */
|
|
99
|
+
readonly context?: LlmModelContext;
|
|
100
|
+
/** Exact model modalities captured with the adapter dispatch generation. */
|
|
101
|
+
readonly inputModalities?: readonly ModelModality[];
|
|
102
|
+
/** Exact model system prompt update mode captured with the adapter dispatch generation. */
|
|
103
|
+
readonly systemPromptUpdate?: SystemPromptUpdate;
|
|
104
|
+
/** Exact model tool update mode captured with the adapter dispatch generation. */
|
|
105
|
+
readonly toolUpdate?: ToolUpdate;
|
|
106
|
+
/** Config fields materialized by the captured adapter rather than proposed by the caller. */
|
|
107
|
+
readonly adapterDefaults: LlmCallConfigAdapterDefaults;
|
|
108
|
+
/**
|
|
109
|
+
* Dispatch this call once through the registration captured during
|
|
110
|
+
* preparation. The request's call-config fields must match {@link config};
|
|
111
|
+
* reuse or mismatch fails with `INVALID_PREPARED_CALL`.
|
|
112
|
+
* @param options - fully assembled request carrying the prepared config.
|
|
113
|
+
* @returns the chunk stream, including the `llm/stream` waterfall.
|
|
114
|
+
*/
|
|
115
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
116
|
+
}
|
|
117
|
+
/** One adapter-owned model-resolution generation bound to its eventual stream call. */
|
|
118
|
+
export interface PreparedAdapterCall {
|
|
119
|
+
/** Exact model metadata from the same adapter generation as {@link stream}. */
|
|
120
|
+
readonly model: LlmResolvedModelInfo;
|
|
121
|
+
/** Dispatch through that generation without re-reading dynamic connection facts. */
|
|
122
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Provider-wire adapter for the harness message and stream vocabulary. Register implementations
|
|
126
|
+
* with `ctx.llm.registerAdapter(providers, adapter)`. Every provider HTTP request must include
|
|
127
|
+
* `attributionHeaders()`; prove the headers are added in the wire request or library header hook. The direct-fetch
|
|
128
|
+
* DeepSeek and library-backed pi-ai adapters meet this contract through different internals.
|
|
129
|
+
*/
|
|
130
|
+
export declare abstract class LlmAdapter {
|
|
131
|
+
/**
|
|
132
|
+
* Describe one provider route owned by this adapter.
|
|
133
|
+
* @param provider - a route passed to `registerAdapter()` for this instance.
|
|
134
|
+
* @returns detached display metadata whose id must equal `provider`.
|
|
135
|
+
*/
|
|
136
|
+
providerInfo(provider: string): LlmProviderInfo;
|
|
137
|
+
/**
|
|
138
|
+
* Return the provider-owned retry policy captured with this route.
|
|
139
|
+
* @param _provider - a route passed to `registerAdapter()` for this instance.
|
|
140
|
+
* @returns a resolved policy, or `undefined` to use the normal defaults.
|
|
141
|
+
*/
|
|
142
|
+
providerRetryPolicy(_provider: string): ResolvedRetryPolicy | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Resolve provider-side request-image pricing for one exact model route.
|
|
145
|
+
* The default declares none, so consumers fall back to their own neutral
|
|
146
|
+
* estimate. Implementations must answer synchronously without I/O; the
|
|
147
|
+
* token meter resolves this per measurement.
|
|
148
|
+
* @param _provider - a route passed to `registerAdapter()` for this instance.
|
|
149
|
+
* @param _model - exact model id passed to {@link GenerateOptions.model}.
|
|
150
|
+
* @returns route-owned image pricing, or `undefined` when the route declares none.
|
|
151
|
+
*/
|
|
152
|
+
imageRequestPricing(_provider: string, _model: string): LlmImageRequestPricing | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* List models this adapter can currently advertise for one owned provider.
|
|
155
|
+
* Core routing accepts unlisted model ids; catalog-driven entry points such
|
|
156
|
+
* as the GUI may require membership. Adapters used there must advertise
|
|
157
|
+
* their available models; the base empty catalog offers no GUI selection.
|
|
158
|
+
* @param _provider - one provider route owned by this adapter.
|
|
159
|
+
* @returns discoverable models in adapter-preferred order.
|
|
160
|
+
*/
|
|
161
|
+
listModels(_provider: string): Promise<readonly LlmModelInfo[]>;
|
|
162
|
+
/**
|
|
163
|
+
* Resolve all metadata available for one exact model. This query is
|
|
164
|
+
* independent of the advisory catalog and does not validate request routing.
|
|
165
|
+
* @param provider - one provider route owned by this adapter.
|
|
166
|
+
* @param model - exact model id passed to {@link GenerateOptions.model}.
|
|
167
|
+
* @param _signal - cancellation for this exact-model lookup; asynchronous
|
|
168
|
+
* implementations must settle promptly after it aborts.
|
|
169
|
+
* @returns provider/model identity plus any context, call-default, and reasoning metadata.
|
|
170
|
+
*/
|
|
171
|
+
resolveModel(provider: string, model: string, _signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
|
|
172
|
+
/**
|
|
173
|
+
* Bind exact model metadata and the eventual request dispatch to one adapter generation.
|
|
174
|
+
* Dynamic adapters override this so settings changes between preparation and
|
|
175
|
+
* dispatch cannot combine one generation's capabilities with another's endpoint.
|
|
176
|
+
* @param provider - registered provider route.
|
|
177
|
+
* @param model - exact model id.
|
|
178
|
+
* @param signal - cancellation for model resolution.
|
|
179
|
+
* @returns model metadata and a one-generation stream entry point.
|
|
180
|
+
*/
|
|
181
|
+
prepareCall(provider: string, model: string, signal?: AbortSignal): Promise<PreparedAdapterCall>;
|
|
182
|
+
/**
|
|
183
|
+
* Stream one model call as raw chunks. The only required method.
|
|
184
|
+
* @param options - the fully-assembled request; implementations must honor `options.signal`.
|
|
185
|
+
* @returns the chunk stream, obeying the adapter contract documented on `StreamChunk`.
|
|
186
|
+
*/
|
|
187
|
+
abstract stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* What {@link LlmRuntime.registerAdapter} returns: the disposer, plus an
|
|
191
|
+
* atomic route replacement for the same adapter instance.
|
|
192
|
+
*/
|
|
193
|
+
export interface AdapterRegistrationHandle {
|
|
194
|
+
/** Release every route this registration currently holds. */
|
|
195
|
+
(): void;
|
|
196
|
+
/**
|
|
197
|
+
* Replace this registration's routes with `providers`, keeping the same
|
|
198
|
+
* adapter instance. The candidate set is validated in full first — a
|
|
199
|
+
* conflict with another adapter, an invalid name, or bad provider metadata
|
|
200
|
+
* throws and leaves the current routes untouched — and the swap itself is
|
|
201
|
+
* one synchronous section, so no request can observe a gap. An empty array
|
|
202
|
+
* is legal here (a settings section that emptied holds zero routes while
|
|
203
|
+
* staying registered), unlike an empty initial registration.
|
|
204
|
+
*
|
|
205
|
+
* Throws `LlmError` with code `REGISTRATION_DISPOSED` once the registration
|
|
206
|
+
* has been released: its routes are gone and its disposer has already run,
|
|
207
|
+
* so anything registered afterwards would have no owner left to release it.
|
|
208
|
+
* @param providers - the complete next route set for this registration.
|
|
209
|
+
*/
|
|
210
|
+
replace(providers: string[]): void;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* A live configurable-provider registration, disposable and atomically
|
|
214
|
+
* replaceable — the directory counterpart of {@link AdapterRegistrationHandle}.
|
|
215
|
+
*/
|
|
216
|
+
export interface DirectoryRegistrationHandle {
|
|
217
|
+
/** Withdraw every entry this registration currently holds. */
|
|
218
|
+
(): void;
|
|
219
|
+
/**
|
|
220
|
+
* Replace this registration's entries with `entries`. The candidate set is
|
|
221
|
+
* validated in full first — an entry another registration already declares,
|
|
222
|
+
* a duplicate within the set, or invalid metadata throws and leaves the
|
|
223
|
+
* current entries untouched — and the swap is one synchronous section, so no
|
|
224
|
+
* reader observes a gap. An empty array is legal here, unlike an empty
|
|
225
|
+
* initial registration.
|
|
226
|
+
*
|
|
227
|
+
* Throws `LlmError` with code `REGISTRATION_DISPOSED` once the registration
|
|
228
|
+
* has been disposed.
|
|
229
|
+
*/
|
|
230
|
+
replace(entries: readonly LlmConfigurableProvider[]): void;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The abstract `llm` service: an adapter registry plus a streaming model-call
|
|
234
|
+
* API, interceptable via the `llm/stream` waterfall.
|
|
235
|
+
*/
|
|
236
|
+
export declare class LlmRuntime extends TypertRemoteService {
|
|
237
|
+
private adapters;
|
|
238
|
+
private directory;
|
|
239
|
+
private discoveries;
|
|
240
|
+
constructor(ctx: Context);
|
|
241
|
+
/** Notify topology observers without letting one broken listener veto the commit. */
|
|
242
|
+
private emitAdaptersUpdated;
|
|
243
|
+
/** Contained-listener diagnostic shared by the sync and async failure paths. */
|
|
244
|
+
private warnAdaptersListenerFailure;
|
|
245
|
+
/**
|
|
246
|
+
* Register an adapter for the given provider routes. Throws `LlmError` with code
|
|
247
|
+
* `DUPLICATE_ADAPTER` if any provider already has an adapter (all-or-nothing).
|
|
248
|
+
* Disposed with the fiber.
|
|
249
|
+
* @param providers - every provider route this adapter should serve.
|
|
250
|
+
* @param adapter - the adapter that streams calls for those providers.
|
|
251
|
+
* @returns the disposer, carrying {@link AdapterRegistrationHandle.replace}.
|
|
252
|
+
*/
|
|
253
|
+
registerAdapter(providers: string[], adapter: LlmAdapter): AdapterRegistrationHandle;
|
|
254
|
+
/**
|
|
255
|
+
* Validate one candidate route set for `adapter`, treating routes this
|
|
256
|
+
* registration already holds as available. Nothing is mutated: a rejected
|
|
257
|
+
* candidate leaves the registry exactly as it was.
|
|
258
|
+
*/
|
|
259
|
+
private prepareRoutes;
|
|
260
|
+
/**
|
|
261
|
+
* Swap this registration's routes for the prepared ones in one synchronous
|
|
262
|
+
* section, so no observer can see the registry between the release and the
|
|
263
|
+
* re-registration. The route set's one mutation point is also where
|
|
264
|
+
* `llm/adapters-updated` is published, so a `replace` announces itself
|
|
265
|
+
* exactly like a first registration.
|
|
266
|
+
*/
|
|
267
|
+
private commitRoutes;
|
|
268
|
+
/**
|
|
269
|
+
* Describe provider routes with a registered adapter.
|
|
270
|
+
* @returns detached provider metadata in registration order.
|
|
271
|
+
*/
|
|
272
|
+
listProviders(): LlmProviderInfo[];
|
|
273
|
+
/**
|
|
274
|
+
* Declare provider routes an adapter plugin can activate through
|
|
275
|
+
* configuration. Registration is all-or-nothing: an empty list, invalid
|
|
276
|
+
* entry, or a provider already declared by any registration throws
|
|
277
|
+
* `LlmError` without registering the rest. Disposed with the fiber.
|
|
278
|
+
* @param entries - every configurable provider this plugin owns.
|
|
279
|
+
* @returns a handle that withdraws all of them, and can atomically replace them.
|
|
280
|
+
*/
|
|
281
|
+
registerConfigurableProviders(entries: readonly LlmConfigurableProvider[]): DirectoryRegistrationHandle;
|
|
282
|
+
/**
|
|
283
|
+
* List every declared configurable provider, registered or dormant.
|
|
284
|
+
* @returns detached directory entries in declaration order.
|
|
285
|
+
*/
|
|
286
|
+
listConfigurableProviders(): LlmConfigurableProvider[];
|
|
287
|
+
/**
|
|
288
|
+
* Offer to interrogate provider endpoints on behalf of the settings
|
|
289
|
+
* namespace this plugin owns. The namespace is the key because that is what
|
|
290
|
+
* a configuration surface already holds from the configurable-provider
|
|
291
|
+
* directory, and because a provider being *added* has no route to name yet.
|
|
292
|
+
* Disposed with the fiber.
|
|
293
|
+
* @param settingsNs - the namespace whose profiles this discovery serves.
|
|
294
|
+
* @param discover - interrogates one endpoint and must honor the supplied signal.
|
|
295
|
+
* @returns the disposer that withdraws the offer.
|
|
296
|
+
*/
|
|
297
|
+
registerModelDiscovery(settingsNs: string, discover: (request: LlmModelDiscoveryRequest, signal?: AbortSignal) => Promise<readonly LlmDiscoveredModel[]>): () => void;
|
|
298
|
+
/**
|
|
299
|
+
* Interrogate one provider endpoint for the models it advertises. The
|
|
300
|
+
* request describes a draft, not a stored route, so nothing here reads or
|
|
301
|
+
* writes settings or credentials — the caller owns both, and the reply is
|
|
302
|
+
* candidate metadata a surface may offer for adoption.
|
|
303
|
+
* @param settingsNs - namespace whose registered discovery serves this draft.
|
|
304
|
+
* @param request - the endpoint, protocol, and one-shot credential to use.
|
|
305
|
+
* @param signal - caller cancellation.
|
|
306
|
+
* @returns the advertised models, deduplicated in endpoint order.
|
|
307
|
+
*/
|
|
308
|
+
discoverModels(settingsNs: string, request: LlmModelDiscoveryRequest, signal?: AbortSignal): Promise<LlmDiscoveredModel[]>;
|
|
309
|
+
/**
|
|
310
|
+
* Remote adapter for one draft provider interrogation.
|
|
311
|
+
* @param settingsNs - namespace whose registered discovery serves this draft.
|
|
312
|
+
* @param request - endpoint, protocol, and one-shot credential to use.
|
|
313
|
+
* @param signal - caller cancellation supplied by the Remote carrier.
|
|
314
|
+
* @returns advertised models in endpoint order.
|
|
315
|
+
* @throws RemoteError with `llm/model-discovery-rejected` when discovery refuses or fails.
|
|
316
|
+
*/
|
|
317
|
+
remoteDiscoverModels(settingsNs: string, request: LlmModelDiscoveryRequest, signal: AbortSignal): Promise<LlmDiscoveredModel[]>;
|
|
318
|
+
/**
|
|
319
|
+
* Resolve the retry policy captured when one provider route was registered.
|
|
320
|
+
* @param provider - registered provider route to inspect.
|
|
321
|
+
* @returns the provider-owned policy, with normal defaults already resolved.
|
|
322
|
+
*/
|
|
323
|
+
providerRetryPolicy(provider: string): ResolvedRetryPolicy;
|
|
324
|
+
/**
|
|
325
|
+
* Resolve provider-side request-image pricing for one exact route, or
|
|
326
|
+
* `undefined` when the provider is unregistered or declares none. Unknown
|
|
327
|
+
* providers degrade to `undefined` rather than throwing because callers
|
|
328
|
+
* price durable history whose route may no longer be mounted.
|
|
329
|
+
* @param provider - provider route named by a request header.
|
|
330
|
+
* @param model - exact model id named by the same header.
|
|
331
|
+
* @returns the owning adapter's image pricing for the route, when declared.
|
|
332
|
+
*/
|
|
333
|
+
imageRequestPricing(provider: string, model: string): LlmImageRequestPricing | undefined;
|
|
334
|
+
/**
|
|
335
|
+
* Resolve the exact text one durable file occurrence contributes to every
|
|
336
|
+
* provider request in the current execution environment.
|
|
337
|
+
* @param ref - durable verbatim file reference from model history.
|
|
338
|
+
* @returns the same deterministic handle text used at adapter dispatch.
|
|
339
|
+
*/
|
|
340
|
+
fileRequestText(ref: FileAttachmentRef): string;
|
|
341
|
+
/** Detach typed adapter-owned modality metadata. */
|
|
342
|
+
private detachedModalities;
|
|
343
|
+
/**
|
|
344
|
+
* Discover models advertised by one registered provider. Catalog membership
|
|
345
|
+
* does not constrain core routing. Catalog-driven entry points may restrict
|
|
346
|
+
* selection and submission to the advertised models.
|
|
347
|
+
* @param provider - registered provider route to inspect.
|
|
348
|
+
* @returns detached model metadata in adapter-preferred order.
|
|
349
|
+
*/
|
|
350
|
+
listModels(provider: string): Promise<LlmModelInfo[]>;
|
|
351
|
+
/**
|
|
352
|
+
* Resolve and validate all metadata from the adapter that owns one exact
|
|
353
|
+
* route. The result is detached from adapter-owned objects; catalog
|
|
354
|
+
* membership remains advisory and does not control request routing.
|
|
355
|
+
* @param provider - registered provider route to inspect.
|
|
356
|
+
* @param model - exact model id passed to the adapter.
|
|
357
|
+
* @param signal - optional cancellation for adapter-owned asynchronous lookup.
|
|
358
|
+
* @returns exact model identity plus available context and reasoning metadata.
|
|
359
|
+
*/
|
|
360
|
+
resolveModelInfo(provider: string, model: string, signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
|
|
361
|
+
private resolveModelInfoFor;
|
|
362
|
+
/** Validate and detach one adapter-returned exact model result. */
|
|
363
|
+
private normalizeModelInfo;
|
|
364
|
+
/**
|
|
365
|
+
* Validate a conversation call config against its exact model capability and
|
|
366
|
+
* materialize adapter-configured defaults. Unsupported explicit efforts
|
|
367
|
+
* reject before provider I/O; no clamping or aliasing is performed. This
|
|
368
|
+
* standalone query does not bind a later dispatch; use {@link prepareCall}
|
|
369
|
+
* when logging and streaming must share one adapter registration.
|
|
370
|
+
* @param config - provider/model route and optional request controls.
|
|
371
|
+
* @param signal - optional cancellation for adapter-owned capability lookup.
|
|
372
|
+
* @returns a detached config only when a default must be materialized.
|
|
373
|
+
*/
|
|
374
|
+
resolveCallConfig(config: LlmCallConfig, signal?: AbortSignal): Promise<LlmCallConfig>;
|
|
375
|
+
private resolveCallFor;
|
|
376
|
+
/** Validate request controls against one already-bound exact model result. */
|
|
377
|
+
private resolveCallWithInfo;
|
|
378
|
+
/**
|
|
379
|
+
* Resolve one call under its current adapter registration. The returned
|
|
380
|
+
* one-shot handle keeps that registration across header logging and dispatch,
|
|
381
|
+
* so HMR cannot combine one adapter's capability result with another adapter.
|
|
382
|
+
* @param config - provider/model route and optional request controls.
|
|
383
|
+
* @param signal - optional cancellation for adapter-owned capability lookup.
|
|
384
|
+
* @returns a prepared config and its registration-bound stream entry point.
|
|
385
|
+
*/
|
|
386
|
+
prepareCall(config: LlmCallConfig, signal?: AbortSignal): Promise<PreparedLlmCall>;
|
|
387
|
+
private registration;
|
|
388
|
+
/** Remove replay state whose historical route is owned by another adapter. */
|
|
389
|
+
private forAdapter;
|
|
390
|
+
/**
|
|
391
|
+
* Resolve the current execution-world read path of one durable file
|
|
392
|
+
* reference through the mounted attachment and filesystem providers.
|
|
393
|
+
*/
|
|
394
|
+
private fileReadPath;
|
|
395
|
+
/**
|
|
396
|
+
* Final adapter boundary. Adapter selection, dispatch, iterator construction,
|
|
397
|
+
* and iteration failures become one terminal failure chunk. Middleware and
|
|
398
|
+
* downstream consumer failures remain thrown plugin or consumer errors.
|
|
399
|
+
*/
|
|
400
|
+
private adapterStream;
|
|
401
|
+
/**
|
|
402
|
+
* Stream one model call as raw chunks (token-level deltas). Replay state is
|
|
403
|
+
* retained only when the same adapter instance owns its historical provider
|
|
404
|
+
* and the target provider. Final adapter selection remains fixed through
|
|
405
|
+
* asynchronous exact-model resolution and dispatch. Adapter selection,
|
|
406
|
+
* dispatch, and iteration failures become terminal `error` or `aborted`
|
|
407
|
+
* finish chunks; middleware, nested-call, cleanup, and consumer failures
|
|
408
|
+
* remain thrown.
|
|
409
|
+
* @param options - the full request; `options.provider` selects the adapter.
|
|
410
|
+
* @returns the chunk stream, possibly wrapped by `llm/stream` listeners.
|
|
411
|
+
*/
|
|
412
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
413
|
+
private streamWithRegistration;
|
|
414
|
+
}
|
|
415
|
+
export default LlmRuntime;
|
|
416
|
+
//# sourceMappingURL=index.d.ts.map
|