@alvin0/ai-agent-sdk-provider-http 0.1.0 → 0.1.1
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/dist/index.d.ts +348 -45
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +902 -402
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { GenerateOptions, ModelAdapter, ModelError, ModelInfo, ModelInvocationContext, ModelModality, ModelReasoningInfo, NativeToolName, PreparedAdapterCall, ProviderInfo, ProviderRequestId, ResolvedModelInfo, ResolvedRetryPolicy, RetryPolicyConfig, StreamChunk, UsageCounters } from "@alvin0/ai-agent-sdk-core";
|
|
1
|
+
import { GenerateOptions, ModelAdapter, ModelError, ModelFailure, ModelInfo, ModelInvocationContext, ModelModality, ModelReasoningInfo, NativeToolName, PreparedAdapterCall, ProviderInfo, ProviderRequestId, ResolvedModelInfo, ResolvedRetryPolicy, RetryPolicyConfig, StreamChunk, UsageCounters } from "@alvin0/ai-agent-sdk-core";
|
|
2
2
|
import { CredentialInput, GenerateOptions as GenerateOptions$1, ModelInvocationContext as ModelInvocationContext$1, ResolvedModelInfo as ResolvedModelInfo$1, RetryPolicyConfig as RetryPolicyConfig$1, StreamChunk as StreamChunk$1, UsageCounters as UsageCounters$1 } from "@alvin0/ai-agent-sdk-core/provider";
|
|
3
|
+
import { EmbeddingModelInfo, EmbeddingNormalization, EmbeddingPurposeHandling, ResolvedEmbeddingModelInfo } from "@alvin0/ai-agent-sdk-core/embedding";
|
|
3
4
|
//#region src/stream/sse.d.ts
|
|
4
5
|
/**
|
|
5
6
|
* Decode an SSE byte stream into events.
|
|
@@ -63,12 +64,61 @@ type ProviderProtocolChunk = Exclude<StreamChunk, {
|
|
|
63
64
|
readonly usage: UsageCounters;
|
|
64
65
|
};
|
|
65
66
|
//#endregion
|
|
66
|
-
//#region src/
|
|
67
|
+
//#region src/transport/connection.d.ts
|
|
68
|
+
/** The transport-shared half of a connection snapshot. */
|
|
69
|
+
interface HttpTransportConnection {
|
|
70
|
+
/** Endpoint base; the pipeline's endpoint path is appended. */
|
|
71
|
+
readonly baseUrl: string;
|
|
72
|
+
/**
|
|
73
|
+
* Every header for the request, INCLUDING authorization.
|
|
74
|
+
*
|
|
75
|
+
* Resolved together with the endpoint so the credential travels with the URL it
|
|
76
|
+
* will be sent to. The transport adds attribution and `accept` on top.
|
|
77
|
+
*/
|
|
78
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
79
|
+
/** Auth-produced names that must be redacted regardless of spelling. */
|
|
80
|
+
readonly sensitiveHeaderNames?: readonly string[];
|
|
81
|
+
/** End-to-end request/stream timeout. */
|
|
82
|
+
readonly requestTimeoutMs?: number;
|
|
83
|
+
/** Maximum serialized outbound request bytes. */
|
|
84
|
+
readonly maxRequestBytes?: number;
|
|
85
|
+
/** Maximum cumulative successful response bytes. */
|
|
86
|
+
readonly maxResponseBytes?: number;
|
|
87
|
+
/** Maximum raw chunks accepted from a successful response. */
|
|
88
|
+
readonly maxResponseChunks?: number;
|
|
89
|
+
/** Maximum bytes read from a non-success response. */
|
|
90
|
+
readonly maxErrorBodyBytes?: number;
|
|
91
|
+
/** Maximum time granted to the optional request logger. */
|
|
92
|
+
readonly requestLoggerTimeoutMs?: number;
|
|
93
|
+
/** Permit cleartext HTTP explicitly, for trusted local development endpoints only. */
|
|
94
|
+
readonly allowInsecureHttp?: boolean;
|
|
95
|
+
/** Captured fetch implementation; omission uses the platform global. */
|
|
96
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
97
|
+
/** Retry policy this route owns. */
|
|
98
|
+
readonly retryPolicy: ResolvedRetryPolicy;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Merge the transport's own header layer beneath the snapshot's auth layer, once.
|
|
102
|
+
*
|
|
103
|
+
* Layer ownership is what makes this safe to call on a snapshot a subclass or a
|
|
104
|
+
* configuration produced: a transport header can never silently overwrite a
|
|
105
|
+
* credential, and the names the auth layer marked sensitive survive the merge so
|
|
106
|
+
* redaction still covers them.
|
|
107
|
+
*
|
|
108
|
+
* A snapshot that already carries every layer — which configured adapters return —
|
|
109
|
+
* passes an empty transport layer and is returned untouched, so capturing twice
|
|
110
|
+
* cannot re-apply attribution.
|
|
111
|
+
* @param connection - the snapshot captured for this operation.
|
|
112
|
+
* @param transportHeaders - the transport layer to merge underneath; may be empty.
|
|
113
|
+
* @returns the snapshot with merged headers and the union of sensitive names.
|
|
114
|
+
*/
|
|
115
|
+
declare function captureTransportConnection<T extends HttpTransportConnection>(connection: T, transportHeaders: Readonly<Record<string, string>>): T;
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/transport/http.d.ts
|
|
118
|
+
/** Replace credential-bearing header values, by provenance and by name shape. */
|
|
67
119
|
declare function redactHeaders(headers: Readonly<Record<string, string>>, sensitiveHeaderNames?: readonly string[]): Record<string, string>;
|
|
68
120
|
//#endregion
|
|
69
|
-
//#region src/
|
|
70
|
-
/** Default idle bound: five minutes without a single byte is a hung stream. */
|
|
71
|
-
declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300000;
|
|
121
|
+
//#region src/transport/limits.d.ts
|
|
72
122
|
/** Default end-to-end bound once provider request construction begins. */
|
|
73
123
|
declare const DEFAULT_REQUEST_TIMEOUT_MS: number;
|
|
74
124
|
/** Default serialized request ceiling. */
|
|
@@ -81,6 +131,40 @@ declare const DEFAULT_MAX_RESPONSE_CHUNKS = 100000;
|
|
|
81
131
|
declare const DEFAULT_MAX_ERROR_BODY_BYTES: number;
|
|
82
132
|
/** Default diagnostic observer deadline; logging must never gate dispatch indefinitely. */
|
|
83
133
|
declare const DEFAULT_REQUEST_LOGGER_TIMEOUT_MS = 5000;
|
|
134
|
+
/**
|
|
135
|
+
* Every transport bound for one request, defaulted and validated exactly once.
|
|
136
|
+
*
|
|
137
|
+
* Resolved from the connection snapshot, so a configuration change between two
|
|
138
|
+
* reads cannot move a bound mid-request.
|
|
139
|
+
*/
|
|
140
|
+
interface ResolvedTransportLimits {
|
|
141
|
+
/** End-to-end request/stream timeout. */
|
|
142
|
+
readonly requestTimeoutMs: number;
|
|
143
|
+
/** Maximum serialized outbound request bytes. */
|
|
144
|
+
readonly maxRequestBytes: number;
|
|
145
|
+
/** Maximum cumulative successful response bytes. */
|
|
146
|
+
readonly maxResponseBytes: number;
|
|
147
|
+
/** Maximum raw chunks accepted from a successful response. */
|
|
148
|
+
readonly maxResponseChunks: number;
|
|
149
|
+
/** Maximum bytes read from a non-success response. */
|
|
150
|
+
readonly maxErrorBodyBytes: number;
|
|
151
|
+
/** Maximum time granted to the optional request logger. */
|
|
152
|
+
readonly requestLoggerTimeoutMs: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Apply defaults and reject nonsense bounds before any I/O happens.
|
|
156
|
+
*
|
|
157
|
+
* Validation order is fixed and part of the contract: a configuration with two
|
|
158
|
+
* invalid bounds always reports the earlier field, so the error a caller sees does
|
|
159
|
+
* not depend on which limit the pipeline happens to consult first.
|
|
160
|
+
* @param connection - the captured snapshot this request is bound to.
|
|
161
|
+
* @returns fully resolved bounds; never partially defaulted.
|
|
162
|
+
*/
|
|
163
|
+
declare function resolveTransportLimits(connection: HttpTransportConnection): ResolvedTransportLimits;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/base/http-adapter.d.ts
|
|
166
|
+
/** Default idle bound: five minutes without a single byte is a hung stream. */
|
|
167
|
+
declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300000;
|
|
84
168
|
/** One model a provider's configuration advertises. */
|
|
85
169
|
interface ProviderCatalogModel {
|
|
86
170
|
/** Wire model id, passed to the provider verbatim. */
|
|
@@ -91,8 +175,16 @@ interface ProviderCatalogModel {
|
|
|
91
175
|
description?: string;
|
|
92
176
|
/** Combined request/response capacity, when known. */
|
|
93
177
|
contextWindow?: number;
|
|
178
|
+
/** Standard-price operating budget before a contextWindow override. */
|
|
179
|
+
defaultContextWindow?: number;
|
|
180
|
+
/** Known technical ceiling; overrides cannot exceed it. */
|
|
181
|
+
maxContextWindow?: number;
|
|
182
|
+
/** Input-token threshold for long-context pricing, when known. */
|
|
183
|
+
standardPriceInputTokens?: number;
|
|
94
184
|
/** Per-request output cap for this model. */
|
|
95
185
|
maxTokens?: number;
|
|
186
|
+
/** Default output budget, independently of the ceiling. Falls back to maxTokens. */
|
|
187
|
+
defaultMaxTokens?: number;
|
|
96
188
|
/** Accepted request modalities; omission is treated as text-only. */
|
|
97
189
|
inputModalities?: readonly ModelModality[];
|
|
98
190
|
/** Modalities this model route may return. */
|
|
@@ -103,49 +195,26 @@ interface ProviderCatalogModel {
|
|
|
103
195
|
reasoning?: ModelReasoningInfo;
|
|
104
196
|
}
|
|
105
197
|
/**
|
|
106
|
-
* Everything needed to issue ONE request, captured as a single snapshot.
|
|
198
|
+
* Everything needed to issue ONE generation request, captured as a single snapshot.
|
|
107
199
|
*
|
|
108
|
-
* The
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
200
|
+
* The transport half — endpoint, headers, bounds, retry policy — is
|
|
201
|
+
* {@link HttpTransportConnection} and is shared with every other pipeline in this
|
|
202
|
+
* package. What this interface adds is the part only generation has: the SSE
|
|
203
|
+
* decoding bounds and the advisory model catalog. The field set and the optionality
|
|
204
|
+
* of every field are unchanged from before the split, so existing provider
|
|
205
|
+
* configurations satisfy it exactly as they did.
|
|
206
|
+
*
|
|
207
|
+
* The catalog stays here deliberately. Embedding routes carry a catalog with
|
|
208
|
+
* different semantics, and folding the two into one shape is precisely the
|
|
209
|
+
* conflation this split avoids.
|
|
112
210
|
*/
|
|
113
|
-
interface HttpConnection {
|
|
114
|
-
/** Endpoint base; the provider's {@link HttpModelAdapter.endpointPath} is appended. */
|
|
115
|
-
readonly baseUrl: string;
|
|
116
|
-
/**
|
|
117
|
-
* Every header for the request, INCLUDING authorization.
|
|
118
|
-
*
|
|
119
|
-
* Resolved in `connect()` so the credential travels with the endpoint it will
|
|
120
|
-
* be sent to. The base pipeline adds attribution and `accept` on top.
|
|
121
|
-
*/
|
|
122
|
-
readonly headers: Readonly<Record<string, string>>;
|
|
123
|
-
/** Auth-produced names that must be redacted regardless of spelling. */
|
|
124
|
-
readonly sensitiveHeaderNames?: readonly string[];
|
|
211
|
+
interface HttpConnection extends HttpTransportConnection {
|
|
125
212
|
/** Maximum idle interval while a read is outstanding. */
|
|
126
213
|
readonly streamIdleTimeoutMs: number;
|
|
127
|
-
/** End-to-end request/stream timeout. */
|
|
128
|
-
readonly requestTimeoutMs?: number;
|
|
129
|
-
/** Maximum serialized outbound request bytes. */
|
|
130
|
-
readonly maxRequestBytes?: number;
|
|
131
|
-
/** Maximum cumulative successful response bytes. */
|
|
132
|
-
readonly maxResponseBytes?: number;
|
|
133
|
-
/** Maximum raw chunks accepted from a successful response. */
|
|
134
|
-
readonly maxResponseChunks?: number;
|
|
135
214
|
/** Maximum decoded SSE events accepted from one response. */
|
|
136
215
|
readonly maxSseEvents?: number;
|
|
137
216
|
/** Maximum characters accepted in one decoded SSE event. */
|
|
138
217
|
readonly maxSseEventChars?: number;
|
|
139
|
-
/** Maximum bytes read from a non-success response. */
|
|
140
|
-
readonly maxErrorBodyBytes?: number;
|
|
141
|
-
/** Maximum time granted to the optional request logger. */
|
|
142
|
-
readonly requestLoggerTimeoutMs?: number;
|
|
143
|
-
/** Permit cleartext HTTP explicitly, for trusted local development endpoints only. */
|
|
144
|
-
readonly allowInsecureHttp?: boolean;
|
|
145
|
-
/** Captured fetch implementation; omission uses the platform global. */
|
|
146
|
-
readonly fetch?: typeof globalThis.fetch;
|
|
147
|
-
/** Retry policy this route owns. */
|
|
148
|
-
readonly retryPolicy: ResolvedRetryPolicy;
|
|
149
218
|
/** Advisory catalog; requests are never restricted to it. */
|
|
150
219
|
readonly models: readonly ProviderCatalogModel[];
|
|
151
220
|
/** Output cap applied when neither the caller nor the model entry names one. */
|
|
@@ -253,15 +322,31 @@ declare abstract class HttpModelAdapter extends ModelAdapter {
|
|
|
253
322
|
/** Capture legacy subclass transport/auth layers once; configured adapters already return all five. */
|
|
254
323
|
private captureConnection;
|
|
255
324
|
/**
|
|
256
|
-
* The
|
|
325
|
+
* The generation pipeline: guard the modalities, then hand one request to the
|
|
326
|
+
* shared transport chain with SSE decoding as its only pipeline-specific part.
|
|
327
|
+
*
|
|
328
|
+
* Still a generator, and deliberately so: the modality guard, the body
|
|
329
|
+
* serialization and every transport step stay lazy until a consumer pulls, which
|
|
330
|
+
* is the behaviour every existing caller of `stream()` already relies on.
|
|
257
331
|
*/
|
|
258
332
|
private run;
|
|
333
|
+
/**
|
|
334
|
+
* The SSE half: media type, bounds, idle deadline, translation, usage honesty.
|
|
335
|
+
*
|
|
336
|
+
* Everything this sees has already cleared the transport's guards — 2xx, no
|
|
337
|
+
* redirect, attempt open, teardown owned — so what remains is only the format.
|
|
338
|
+
* Abort racing is not repeated here: {@link transportStream} already iterates
|
|
339
|
+
* this generator under the fused signal.
|
|
340
|
+
* @param session - the guarded response and its attempt-evidence hooks.
|
|
341
|
+
* @param request - the request this response answers.
|
|
342
|
+
* @param sse - event bounds resolved before any transport work began.
|
|
343
|
+
* @returns the provider's chunks, with incomplete usage held back.
|
|
344
|
+
*/
|
|
345
|
+
private decodeSse;
|
|
259
346
|
private prepareWireBody;
|
|
260
|
-
/** Turn a non-2xx response into a fully populated {@link ModelError}. */
|
|
261
|
-
private httpFailure;
|
|
262
347
|
}
|
|
263
348
|
//#endregion
|
|
264
|
-
//#region src/
|
|
349
|
+
//#region src/transport/errors.d.ts
|
|
265
350
|
/**
|
|
266
351
|
* Map an HTTP status plus whatever the provider said into a stable code.
|
|
267
352
|
*
|
|
@@ -310,6 +395,22 @@ interface ParsedErrorBody {
|
|
|
310
395
|
*/
|
|
311
396
|
declare function parseErrorBody(raw: string): ParsedErrorBody;
|
|
312
397
|
//#endregion
|
|
398
|
+
//#region src/base/context-policy.d.ts
|
|
399
|
+
/** Context facts only: never advertises models or guesses their capabilities. */
|
|
400
|
+
interface ModelContextPolicy {
|
|
401
|
+
readonly defaultContextWindow: number;
|
|
402
|
+
readonly maxContextWindow?: number;
|
|
403
|
+
readonly standardPriceInputTokens?: number;
|
|
404
|
+
}
|
|
405
|
+
interface ModelContextPolicyOptions {
|
|
406
|
+
readonly baseUrl?: string;
|
|
407
|
+
readonly models?: readonly ProviderCatalogModel[];
|
|
408
|
+
readonly defaultContextWindow?: number;
|
|
409
|
+
}
|
|
410
|
+
declare function applyModelContextPolicy(info: ResolvedModelInfo, policy: ModelContextPolicy | undefined, configured?: ProviderCatalogModel, providerOverride?: number): ResolvedModelInfo;
|
|
411
|
+
/** Capture configuration so later caller mutations cannot change model resolution. */
|
|
412
|
+
declare function createModelContextPolicy(policies: Readonly<Record<string, ModelContextPolicy>>, models: readonly ProviderCatalogModel[] | undefined, providerOverride?: number): (info: ResolvedModelInfo) => ResolvedModelInfo;
|
|
413
|
+
//#endregion
|
|
313
414
|
//#region src/common/config.d.ts
|
|
314
415
|
/** Runtime wire-protocol contract version supported by this package. */
|
|
315
416
|
declare const HTTP_PROTOCOL_API_VERSION: 1;
|
|
@@ -322,6 +423,7 @@ declare const HTTP_PROVIDER_ERROR_CODES: Readonly<{
|
|
|
322
423
|
readonly WIRE_BODY_INVALID: 'HTTP_WIRE_BODY_INVALID';
|
|
323
424
|
readonly WIRE_BODY_TOO_LARGE: 'HTTP_WIRE_BODY_TOO_LARGE';
|
|
324
425
|
readonly STREAM_MEDIA_TYPE_INVALID: 'HTTP_STREAM_MEDIA_TYPE_INVALID';
|
|
426
|
+
readonly JSON_MEDIA_TYPE_INVALID: 'HTTP_JSON_MEDIA_TYPE_INVALID';
|
|
325
427
|
readonly SSE_LIMIT_EXCEEDED: 'HTTP_SSE_LIMIT_EXCEEDED';
|
|
326
428
|
readonly REDIRECT_REJECTED: 'HTTP_REDIRECT_REJECTED';
|
|
327
429
|
}>;
|
|
@@ -637,5 +739,206 @@ declare function createRuntimeHttpProvider<Dialect extends object>(options: Runt
|
|
|
637
739
|
declare function observeCredentialOperation<T>(context: ModelInvocationContext | undefined, provider: string, operation: 'resolve' | 'refresh' | 'login', task: () => Promise<T>): Promise<T>;
|
|
638
740
|
declare function observeModelCatalogOperation<T>(context: ModelInvocationContext | undefined, provider: string, origin: string, task: () => Promise<T>): Promise<T>;
|
|
639
741
|
//#endregion
|
|
640
|
-
|
|
742
|
+
//#region src/transport/embedding-connection.d.ts
|
|
743
|
+
/**
|
|
744
|
+
* One embedding model an HTTP route declares.
|
|
745
|
+
*
|
|
746
|
+
* Every capability field is optional but one: {@link compatibilityIdentity}. A
|
|
747
|
+
* vector is only meaningful next to another vector from the same space, and no
|
|
748
|
+
* amount of matching dimension counts establishes that. Requiring the claim in
|
|
749
|
+
* the type means a self-hosted "OpenAI-compatible" endpoint is a tested profile
|
|
750
|
+
* someone declared, not an assumption drawn from the endpoint having an
|
|
751
|
+
* `/embeddings` path (Requirement 15.3).
|
|
752
|
+
*/
|
|
753
|
+
interface EmbeddingCatalogModel {
|
|
754
|
+
/** Wire model id, passed to the provider verbatim. */
|
|
755
|
+
readonly id: string;
|
|
756
|
+
/** Selector label; defaults to {@link id}. */
|
|
757
|
+
readonly name?: string;
|
|
758
|
+
/** Optional detail distinguishing similar variants. */
|
|
759
|
+
readonly description?: string;
|
|
760
|
+
/** Selectable vector widths this route accepts. */
|
|
761
|
+
readonly dimensions?: readonly number[];
|
|
762
|
+
/** Width used when the caller requests none. */
|
|
763
|
+
readonly defaultDimensions?: number;
|
|
764
|
+
/** Per-input token ceiling. Only a declared value may reject an input. */
|
|
765
|
+
readonly maxInputTokens?: number;
|
|
766
|
+
/** Items accepted in one physical batch. */
|
|
767
|
+
readonly maxBatchItems?: number;
|
|
768
|
+
/** Estimated tokens accepted in one physical batch. */
|
|
769
|
+
readonly maxBatchTokens?: number;
|
|
770
|
+
/** Payload bytes accepted in one physical batch. */
|
|
771
|
+
readonly maxBatchBytes?: number;
|
|
772
|
+
/**
|
|
773
|
+
* How this route expresses purpose on the wire.
|
|
774
|
+
*
|
|
775
|
+
* `'unsupported'` is the positive negative claim — the route states it has no
|
|
776
|
+
* mechanism, which is what OpenAI's embeddings API is — and it is distinct
|
|
777
|
+
* from omitting the field, which claims nothing. Either way the adapter sends
|
|
778
|
+
* the text verbatim and never invents an undocumented prefix.
|
|
779
|
+
*/
|
|
780
|
+
readonly purposeHandling?: EmbeddingPurposeHandling | 'unsupported';
|
|
781
|
+
/** Whether vectors arrive normalized. Never inferred from dimension count. */
|
|
782
|
+
readonly normalization?: EmbeddingNormalization;
|
|
783
|
+
/**
|
|
784
|
+
* The route's explicit declaration about the embedding space.
|
|
785
|
+
*
|
|
786
|
+
* Required, including for a self-hosted endpoint. Models sharing a declared
|
|
787
|
+
* space share this string; a new model generation gets a new one even when the
|
|
788
|
+
* vector width is unchanged.
|
|
789
|
+
*/
|
|
790
|
+
readonly compatibilityIdentity: string;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Everything needed to issue ONE embedding request, captured as a single snapshot.
|
|
794
|
+
*
|
|
795
|
+
* The transport half — endpoint, headers, bounds, cleartext opt-in, retry
|
|
796
|
+
* policy — is {@link HttpTransportConnection} and is shared with the generation
|
|
797
|
+
* pipeline verbatim. Both `OpenAI_Embedding_Adapter` and
|
|
798
|
+
* `Gemini_Embedding_Adapter` are configured through this one shape.
|
|
799
|
+
*/
|
|
800
|
+
interface EmbeddingHttpConnection extends HttpTransportConnection {
|
|
801
|
+
/** Advisory catalog; requests are never restricted to it. */
|
|
802
|
+
readonly models: readonly EmbeddingCatalogModel[];
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Translate one declared catalog entry into `Embedding_Catalog` metadata.
|
|
806
|
+
*
|
|
807
|
+
* `inputTypes` and `representation` come out `unknown` rather than filled in
|
|
808
|
+
* from the v1 scope: the scope is already readable from the types
|
|
809
|
+
* (`EmbeddingInputType` is `'text'`, `EmbeddingRepresentation` is
|
|
810
|
+
* `'dense-float32'`), and stating `supported` on the route's behalf would be
|
|
811
|
+
* the SDK asserting a claim the route never made.
|
|
812
|
+
* @param provider - route that owns the entry.
|
|
813
|
+
* @param model - the declared catalog entry.
|
|
814
|
+
* @returns advisory embedding metadata for this entry.
|
|
815
|
+
*/
|
|
816
|
+
declare function embeddingCatalogModelInfo(provider: string, model: EmbeddingCatalogModel): EmbeddingModelInfo;
|
|
817
|
+
/**
|
|
818
|
+
* Resolve exact embedding metadata for a model id from an advisory catalog.
|
|
819
|
+
*
|
|
820
|
+
* An id the catalog does not describe stays usable: the caller gets an
|
|
821
|
+
* identity-only descriptor with every capability `unknown` and the provider
|
|
822
|
+
* decides (Requirement 10.3). The catalog restricting the request would make
|
|
823
|
+
* membership authoritative, which it is not.
|
|
824
|
+
* @param provider - route being resolved.
|
|
825
|
+
* @param modelId - requested model id.
|
|
826
|
+
* @param models - the route's declared catalog.
|
|
827
|
+
* @returns exact metadata for the id, or the identity-only descriptor.
|
|
828
|
+
*/
|
|
829
|
+
declare function resolvedEmbeddingCatalogModelInfo(provider: string, modelId: string, models: readonly EmbeddingCatalogModel[]): ResolvedEmbeddingModelInfo;
|
|
830
|
+
//#endregion
|
|
831
|
+
//#region src/transport/session.d.ts
|
|
832
|
+
/** One serialized request body, measured before anything is sent. */
|
|
833
|
+
interface PreparedWireBody {
|
|
834
|
+
/** The value handed to the diagnostic observer; never re-serialized. */
|
|
835
|
+
readonly value: unknown;
|
|
836
|
+
/** Exact bytes sent on the wire. */
|
|
837
|
+
readonly encoded: string;
|
|
838
|
+
/** UTF-8 length of {@link encoded}. */
|
|
839
|
+
readonly bytes: number;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* How the transport obtains the body.
|
|
843
|
+
*
|
|
844
|
+
* A thunk exists because the pipeline that owns serialization also owns caching it
|
|
845
|
+
* across repeated `stream()` calls on one prepared call, and because building the
|
|
846
|
+
* body may itself do work that must observe the fused signal — which does not exist
|
|
847
|
+
* until the transport creates it.
|
|
848
|
+
*/
|
|
849
|
+
type WireBodySource = PreparedWireBody | ((signal: AbortSignal) => PreparedWireBody | Promise<PreparedWireBody>);
|
|
850
|
+
/**
|
|
851
|
+
* One exact wire request, observed immediately before dispatch.
|
|
852
|
+
*
|
|
853
|
+
* Structurally identical to the generation pipeline's record, and deliberately
|
|
854
|
+
* declared here so the transport does not depend on a pipeline for its own shape.
|
|
855
|
+
*/
|
|
856
|
+
interface WireRequestRecord {
|
|
857
|
+
readonly schemaVersion: 1;
|
|
858
|
+
readonly type: 'provider-request';
|
|
859
|
+
readonly id: string;
|
|
860
|
+
readonly timestamp: string;
|
|
861
|
+
readonly provider: string;
|
|
862
|
+
readonly model: string;
|
|
863
|
+
readonly method: 'POST';
|
|
864
|
+
readonly url: string;
|
|
865
|
+
/** Credentials and cookies already replaced by `[REDACTED]`. */
|
|
866
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
867
|
+
/** The exact serialized value. This may contain prompts and tool output. */
|
|
868
|
+
readonly body: unknown;
|
|
869
|
+
readonly bodyBytes: number;
|
|
870
|
+
}
|
|
871
|
+
/** Everything the shared chain needs to issue ONE request. */
|
|
872
|
+
interface HttpTransportRequestInput {
|
|
873
|
+
/** The snapshot this request is bound to; read once, never re-read mid-request. */
|
|
874
|
+
readonly connection: HttpTransportConnection;
|
|
875
|
+
/** Provider display name used in every message this chain raises. */
|
|
876
|
+
readonly displayName: string;
|
|
877
|
+
/** Route being served. */
|
|
878
|
+
readonly provider: string;
|
|
879
|
+
/** Wire model id. */
|
|
880
|
+
readonly model: string;
|
|
881
|
+
/** Path appended to {@link HttpTransportConnection.baseUrl}. */
|
|
882
|
+
readonly path: string;
|
|
883
|
+
/**
|
|
884
|
+
* Media type this pipeline requires back.
|
|
885
|
+
*
|
|
886
|
+
* The transport does not enforce it — the `accept` header travels on the
|
|
887
|
+
* connection snapshot and the check belongs to whoever decodes — but it is carried
|
|
888
|
+
* on the session so `decode` states its expectation in one place.
|
|
889
|
+
*/
|
|
890
|
+
readonly accept: string;
|
|
891
|
+
readonly body: WireBodySource;
|
|
892
|
+
/** The caller's cancellation, fused with the deadline and our teardown. */
|
|
893
|
+
readonly signal?: AbortSignal;
|
|
894
|
+
readonly context?: ModelInvocationContext;
|
|
895
|
+
/** Override status-to-code mapping for a provider with codes of its own. */
|
|
896
|
+
readonly errorCode?: (status: number, detail: string) => string;
|
|
897
|
+
/** Best-effort diagnostic observer; never a dispatch veto. */
|
|
898
|
+
readonly observeRequest?: (record: WireRequestRecord) => Promise<void> | void;
|
|
899
|
+
}
|
|
900
|
+
/** Outcome vocabulary a pipeline may report for the attempt ledger. */
|
|
901
|
+
type TransportAttemptStatus = 'success' | 'error' | 'aborted' | 'unknown';
|
|
902
|
+
/** A response that already cleared every transport guard, plus its ledger hooks. */
|
|
903
|
+
interface HttpTransportSession {
|
|
904
|
+
/** The response; its body is still unread and is owned by the transport. */
|
|
905
|
+
readonly response: Response;
|
|
906
|
+
readonly url: string;
|
|
907
|
+
readonly origin: string;
|
|
908
|
+
/** Fused signal: caller + request deadline + transport teardown. */
|
|
909
|
+
readonly signal: AbortSignal;
|
|
910
|
+
/** Provider correlation id, when the response carried one. */
|
|
911
|
+
readonly providerRequestId?: ProviderRequestId;
|
|
912
|
+
/** Media type the pipeline asked for; see {@link HttpTransportRequestInput.accept}. */
|
|
913
|
+
readonly accept: string;
|
|
914
|
+
readonly limits: ResolvedTransportLimits;
|
|
915
|
+
/**
|
|
916
|
+
* Record a usage report as attempt evidence.
|
|
917
|
+
*
|
|
918
|
+
* Evidence only: whether a report is complete enough to leave the SDK as
|
|
919
|
+
* `TokenUsage` is a pipeline decision, and this hook does not make it.
|
|
920
|
+
*/
|
|
921
|
+
readonly attemptId?: string;
|
|
922
|
+
reportUsage(usage: UsageCounters, final?: boolean): void;
|
|
923
|
+
/** Record the terminal outcome the decoded stream reported. */
|
|
924
|
+
reportOutcome(status: TransportAttemptStatus, failure?: ModelFailure): void;
|
|
925
|
+
}
|
|
926
|
+
//#endregion
|
|
927
|
+
//#region src/transport/json.d.ts
|
|
928
|
+
/** Media types this pipeline accepts back from a provider. */
|
|
929
|
+
declare const JSON_MEDIA_TYPES: readonly ["application/json"];
|
|
930
|
+
/**
|
|
931
|
+
* Send one request, read its JSON body under bound, and return `decode`'s value.
|
|
932
|
+
*
|
|
933
|
+
* The attempt closes as soon as the value is produced; nothing here stays open for
|
|
934
|
+
* a consumer, because the whole response is already in memory by then.
|
|
935
|
+
* @param input - request facts captured from one connection snapshot.
|
|
936
|
+
* @param decode - turns a parsed body into the pipeline's own value.
|
|
937
|
+
* @returns whatever `decode` returns.
|
|
938
|
+
*/
|
|
939
|
+
declare function transportJson<T>(input: HttpTransportRequestInput, decode: (session: HttpTransportSession, body: unknown) => T | Promise<T>): Promise<T>;
|
|
940
|
+
/** True when a `content-type` value names one of {@link JSON_MEDIA_TYPES}. */
|
|
941
|
+
declare function isJsonMediaType(contentType: string | null): boolean;
|
|
942
|
+
//#endregion
|
|
943
|
+
export { AnyWireProtocol, AuthScheme, CredentialSource, DEFAULT_MAX_ERROR_BODY_BYTES, DEFAULT_MAX_REQUEST_BYTES, DEFAULT_MAX_RESPONSE_BYTES, DEFAULT_MAX_RESPONSE_CHUNKS, DEFAULT_REQUEST_LOGGER_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, EmbeddingCatalogModel, EmbeddingHttpConnection, HTTP_PROTOCOL_API_VERSION, HTTP_PROVIDER_ERROR_CODES, type HttpAuthResolveOptions, type HttpConnection, HttpModelAdapter, HttpProviderOptions, type HttpTransportConnection, type HttpTransportRequestInput, type HttpTransportSession, JSON_MEDIA_TYPES, ModelContextPolicy, ModelContextPolicyOptions, ModelDiscoveryContext, type ParsedErrorBody, type PreparedWireBody, type ProtocolRequest, type ProtocolSseEvent, type ProtocolStreamChunk, type ProviderCatalogModel, type ProviderRequest, type ProviderRequestLogRecord, type ProviderRequestLogger, type ResolvedTransportLimits, type RuntimeAuthScheme, type RuntimeCredentialSource, type RuntimeHttpProviderOptions, type RuntimeModelDiscoveryContext, type RuntimeWireProtocol, SseEvent, type WireBodySource, WireProtocol, WireProtocolChunk, type WireProtocolDefinition, applyModelContextPolicy, captureTransportConnection, createHttpProvider, createModelContextPolicy, createRuntimeHttpProvider, defineWireProtocol, embeddingCatalogModelInfo, httpErrorCode, isJsonMediaType, observeCredentialOperation, observeModelCatalogOperation, parseErrorBody, parseSse, redactHeaders, requestIdFrom, resolveDialect, resolveTransportLimits, resolvedEmbeddingCatalogModelInfo, retryAfterMs, transportJson };
|
|
641
944
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/stream/sse.ts","../src/stream/types.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/stream/sse.ts","../src/stream/types.ts","../src/transport/connection.ts","../src/transport/http.ts","../src/transport/limits.ts","../src/base/http-adapter.ts","../src/transport/errors.ts","../src/base/context-policy.ts","../src/common/config.ts","../src/protocol/runtime-types.ts","../src/protocol/definition.ts","../src/protocol/protocol.ts","../src/configurable/http-provider.ts","../src/configurable/runtime-types.ts","../src/configurable/runtime-provider.ts","../src/observation/operations.ts","../src/transport/embedding-connection.ts","../src/transport/session.ts","../src/transport/json.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAmCiB;;;;;;;;EAQf;;EAEA;;;;;;;;;;;;;;iBAeqB,SACrB,QAAQ,eAAe,aACvB,yBACA,6BACC,eAAe;;;;KC7DN,wBACR,QAAQ;WAAwB;;WACrB;WAAwB,OAAO;;;;;UCiB7B;;WAEN;;;;;;;WAOA,SAAS,SAAS;;WAElB;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,eAAe,WAAW;;WAE1B,aAAa;;;;;;;;;;;;;;;;;iBAkBR,2BAA2B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