@providerprotocol/ai 0.0.20 → 0.0.22
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/anthropic/index.d.ts +184 -14
- package/dist/anthropic/index.js +306 -107
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-P5IRTEM5.js → chunk-7WYBJPJJ.js} +2 -2
- package/dist/chunk-I2VHCGQE.js +49 -0
- package/dist/chunk-I2VHCGQE.js.map +1 -0
- package/dist/{chunk-UMKWXGO3.js → chunk-M4BMM5IB.js} +86 -2
- package/dist/chunk-M4BMM5IB.js.map +1 -0
- package/dist/{chunk-SKY2JLA7.js → chunk-MKDLXV4O.js} +1 -1
- package/dist/chunk-MKDLXV4O.js.map +1 -0
- package/dist/{chunk-Z7RBRCRN.js → chunk-NWS5IKNR.js} +37 -11
- package/dist/chunk-NWS5IKNR.js.map +1 -0
- package/dist/{chunk-U3FZWV4U.js → chunk-RFWLEFAB.js} +100 -43
- package/dist/chunk-RFWLEFAB.js.map +1 -0
- package/dist/{chunk-U4JJC2YX.js → chunk-RS7C25LS.js} +36 -11
- package/dist/chunk-RS7C25LS.js.map +1 -0
- package/dist/google/index.d.ts +35 -24
- package/dist/google/index.js +273 -99
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +3 -3
- package/dist/http/index.js +4 -4
- package/dist/index.d.ts +103 -38
- package/dist/index.js +346 -153
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +14 -16
- package/dist/ollama/index.js +68 -16
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +25 -133
- package/dist/openai/index.js +208 -122
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +28 -53
- package/dist/openrouter/index.js +179 -72
- package/dist/openrouter/index.js.map +1 -1
- package/dist/provider-DWEAzeM5.d.ts +1329 -0
- package/dist/proxy/index.d.ts +2 -3
- package/dist/proxy/index.js +174 -17
- package/dist/proxy/index.js.map +1 -1
- package/dist/{retry-DR7YRJDz.d.ts → retry-DmPmqZL6.d.ts} +12 -3
- package/dist/{stream-DRHy6q1a.d.ts → stream-DbkLOIbJ.d.ts} +15 -5
- package/dist/xai/index.d.ts +16 -88
- package/dist/xai/index.js +167 -86
- package/dist/xai/index.js.map +1 -1
- package/package.json +4 -1
- package/dist/chunk-MSR5P65T.js +0 -39
- package/dist/chunk-MSR5P65T.js.map +0 -1
- package/dist/chunk-SKY2JLA7.js.map +0 -1
- package/dist/chunk-U3FZWV4U.js.map +0 -1
- package/dist/chunk-U4JJC2YX.js.map +0 -1
- package/dist/chunk-UMKWXGO3.js.map +0 -1
- package/dist/chunk-Z7RBRCRN.js.map +0 -1
- package/dist/content-DEl3z_W2.d.ts +0 -276
- package/dist/image-Dhq-Yuq4.d.ts +0 -456
- package/dist/provider-BBMBZuGn.d.ts +0 -570
- /package/dist/{chunk-P5IRTEM5.js.map → chunk-7WYBJPJJ.js.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { M as Message, T as Turn, a as MessageType, b as MessageJSON, c as Tool, d as ToolUseStrategy, J as JSONSchema, S as StreamResult, A as AssistantMessage, e as TokenUsage, f as StreamEvent } from './stream-
|
|
2
|
-
export { l as AfterCallResult, B as BeforeCallResult, E as EventDelta, g as JSONSchemaProperty, h as JSONSchemaPropertyType, r as MessageMetadata, s as MessageOptions, w as StreamEventType, i as ToolCall, m as ToolExecution, k as ToolMetadata, j as ToolResult, n as ToolResultMessage, U as UserMessage, v as aggregateUsage, F as contentBlockStart, G as contentBlockStop, x as createStreamResult, t as createTurn, u as emptyUsage, p as isAssistantMessage, q as isToolResultMessage, o as isUserMessage, C as messageStart, D as messageStop, y as textDelta, z as toolCallDelta } from './stream-
|
|
3
|
-
import { U as UserContent, A as AssistantContent, C as ContentBlock } from './
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
export { g as EmbeddingProvider, i as EmbeddingRequest, j as EmbeddingResponse, k as EmbeddingVector, e as ErrorCode, h as ImageProvider, K as KeyStrategy, M as Modality, f as ModelReference, R as RetryStrategy, U as UPPError } from './provider-BBMBZuGn.js';
|
|
7
|
-
import { I as ImageOptions, a as ImageInstance } from './image-Dhq-Yuq4.js';
|
|
8
|
-
export { B as BoundImageModel, G as GeneratedImage, b as Image, i as ImageCapabilities, d as ImageEditInput, k as ImageEditRequest, n as ImageHandler, c as ImageInput, o as ImageModelInput, m as ImageProviderStreamResult, j as ImageRequest, l as ImageResponse, f as ImageResult, g as ImageStreamEvent, h as ImageStreamResult, e as ImageUsage } from './image-Dhq-Yuq4.js';
|
|
9
|
-
export { D as DynamicKey, E as ExponentialBackoff, L as LinearBackoff, N as NoRetry, a as RetryAfterStrategy, R as RoundRobinKeys, T as TokenBucket, W as WeightedKeys } from './retry-DR7YRJDz.js';
|
|
1
|
+
import { M as Message, T as Turn, a as MessageType, b as MessageJSON, c as Tool, d as ToolUseStrategy, J as JSONSchema, S as StreamResult, A as AssistantMessage, e as TokenUsage, f as StreamEvent } from './stream-DbkLOIbJ.js';
|
|
2
|
+
export { l as AfterCallResult, B as BeforeCallResult, E as EventDelta, g as JSONSchemaProperty, h as JSONSchemaPropertyType, r as MessageMetadata, s as MessageOptions, w as StreamEventType, i as ToolCall, m as ToolExecution, k as ToolMetadata, j as ToolResult, n as ToolResultMessage, U as UserMessage, v as aggregateUsage, F as contentBlockStart, G as contentBlockStop, x as createStreamResult, t as createTurn, u as emptyUsage, p as isAssistantMessage, q as isToolResultMessage, o as isUserMessage, C as messageStart, D as messageStop, y as textDelta, z as toolCallDelta } from './stream-DbkLOIbJ.js';
|
|
3
|
+
import { U as UserContent, A as AssistantContent, P as ProviderIdentity, a as ProviderConfig, C as ContentBlock, L as LLMProvider, E as EmbeddingInput, b as EmbeddingUsage, B as BoundEmbeddingModel, I as ImageOptions, c as ImageInstance, d as LLMHandler$1, e as EmbeddingHandler, f as ImageHandler, g as Provider, M as ModelReference } from './provider-DWEAzeM5.js';
|
|
4
|
+
export { m as AudioBlock, n as BinaryBlock, _ as BoundImageModel, v as EmbeddingProvider, x as EmbeddingRequest, y as EmbeddingResponse, z as EmbeddingVector, j as ErrorCode, H as GeneratedImage, h as Image, l as ImageBlock, S as ImageCapabilities, F as ImageEditInput, X as ImageEditRequest, G as ImageGenerateOptions, $ as ImageHandler, D as ImageInput, a0 as ImageModelInput, w as ImageProvider, Z as ImageProviderStreamResult, W as ImageRequest, Y as ImageResponse, N as ImageResult, o as ImageSource, O as ImageStreamEvent, Q as ImageStreamResult, J as ImageUsage, K as KeyStrategy, k as Modality, R as RetryStrategy, T as TextBlock, i as UPPError, V as VideoBlock, r as isAudioBlock, u as isBinaryBlock, q as isImageBlock, p as isTextBlock, s as isVideoBlock, t as text } from './provider-DWEAzeM5.js';
|
|
5
|
+
export { D as DynamicKey, E as ExponentialBackoff, L as LinearBackoff, N as NoRetry, a as RetryAfterStrategy, R as RoundRobinKeys, T as TokenBucket, W as WeightedKeys } from './retry-DmPmqZL6.js';
|
|
10
6
|
|
|
11
7
|
/**
|
|
12
8
|
* @fileoverview Thread class for managing conversation history.
|
|
@@ -228,16 +224,26 @@ declare class Thread {
|
|
|
228
224
|
* Structural type for model input that accepts any ModelReference.
|
|
229
225
|
* Uses structural typing to avoid generic variance issues with Provider generics.
|
|
230
226
|
* The nested types use `unknown` to accept any provider parameter types.
|
|
227
|
+
*
|
|
228
|
+
* @remarks
|
|
229
|
+
* This type mirrors {@link ModelReference} while keeping provider options
|
|
230
|
+
* structurally compatible across providers.
|
|
231
|
+
*
|
|
232
|
+
* @see ModelReference
|
|
231
233
|
*/
|
|
232
234
|
type ModelInput = {
|
|
233
235
|
readonly modelId: string;
|
|
234
|
-
readonly provider:
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
readonly provider: ProviderIdentity;
|
|
237
|
+
/**
|
|
238
|
+
* Optional provider-specific configuration that gets merged into request config.
|
|
239
|
+
* Set when creating a model reference with provider-specific options.
|
|
240
|
+
*/
|
|
241
|
+
readonly providerConfig?: Partial<ProviderConfig>;
|
|
242
|
+
/**
|
|
243
|
+
* The original options passed when creating this model reference.
|
|
244
|
+
* Used by providers with multiple LLM handlers to resolve the correct handler.
|
|
245
|
+
*/
|
|
246
|
+
readonly options?: unknown;
|
|
241
247
|
};
|
|
242
248
|
/**
|
|
243
249
|
* LLM capabilities declare what a provider's API supports.
|
|
@@ -273,7 +279,7 @@ interface LLMCapabilities {
|
|
|
273
279
|
videoInput: boolean;
|
|
274
280
|
/** Provider API supports audio input in messages */
|
|
275
281
|
audioInput: boolean;
|
|
276
|
-
/** Provider API supports image generation output (via
|
|
282
|
+
/** Provider API supports image generation output (via image() or built-in tools) */
|
|
277
283
|
imageOutput?: boolean;
|
|
278
284
|
}
|
|
279
285
|
/**
|
|
@@ -554,16 +560,18 @@ declare function llm<TParams = unknown>(options: LLMOptions<TParams>): LLMInstan
|
|
|
554
560
|
/**
|
|
555
561
|
* Structural type for embedding model input.
|
|
556
562
|
* Uses structural typing to avoid generic variance issues with Provider generics.
|
|
563
|
+
*
|
|
564
|
+
* @remarks
|
|
565
|
+
* This type mirrors {@link ModelReference} while keeping provider options
|
|
566
|
+
* structurally compatible across providers.
|
|
567
|
+
*
|
|
568
|
+
* @see ModelReference
|
|
557
569
|
*/
|
|
558
570
|
interface EmbeddingModelInput {
|
|
559
571
|
readonly modelId: string;
|
|
560
|
-
readonly provider:
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
readonly modalities: {
|
|
564
|
-
embedding?: unknown;
|
|
565
|
-
};
|
|
566
|
-
};
|
|
572
|
+
readonly provider: ProviderIdentity;
|
|
573
|
+
/** Optional provider configuration merged into requests */
|
|
574
|
+
readonly providerConfig?: Partial<ProviderConfig>;
|
|
567
575
|
}
|
|
568
576
|
/**
|
|
569
577
|
* Options for creating an embedding instance with the embedding() function.
|
|
@@ -778,12 +786,36 @@ declare function embedding<TParams = unknown>(options: EmbeddingOptions<TParams>
|
|
|
778
786
|
*/
|
|
779
787
|
declare function image<TParams = unknown>(options: ImageOptions<TParams>): ImageInstance<TParams>;
|
|
780
788
|
|
|
789
|
+
/**
|
|
790
|
+
* @fileoverview Internal handler registry and resolver utilities.
|
|
791
|
+
*
|
|
792
|
+
* @module core/provider-handlers
|
|
793
|
+
*/
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Resolver for dynamically selecting LLM handlers based on model options.
|
|
797
|
+
*
|
|
798
|
+
* Used by providers that support multiple API modes (e.g., OpenAI with responses/completions).
|
|
799
|
+
* The resolver eliminates shared mutable state by storing the mode on the ModelReference
|
|
800
|
+
* and resolving the correct handler at request time.
|
|
801
|
+
*
|
|
802
|
+
* @typeParam TOptions - Provider-specific options type
|
|
803
|
+
*/
|
|
804
|
+
interface LLMHandlerResolver<TOptions = unknown> {
|
|
805
|
+
/** Map of mode identifiers to their corresponding LLM handlers */
|
|
806
|
+
handlers: Record<string, LLMHandler$1>;
|
|
807
|
+
/** The default mode when options don't specify one */
|
|
808
|
+
defaultMode: string;
|
|
809
|
+
/** Function to extract the mode from provider options */
|
|
810
|
+
getMode: (options: TOptions | undefined) => string;
|
|
811
|
+
}
|
|
812
|
+
|
|
781
813
|
/**
|
|
782
814
|
* @fileoverview Base provider interface and factory for the Universal Provider Protocol.
|
|
783
815
|
*
|
|
784
816
|
* This module provides the foundation for creating AI providers that conform to the
|
|
785
817
|
* UPP specification. Providers are callable functions that create model references
|
|
786
|
-
* and
|
|
818
|
+
* and register internal handlers for LLM, embedding, and image modalities.
|
|
787
819
|
*
|
|
788
820
|
* @module core/provider
|
|
789
821
|
*/
|
|
@@ -791,43 +823,63 @@ declare function image<TParams = unknown>(options: ImageOptions<TParams>): Image
|
|
|
791
823
|
/**
|
|
792
824
|
* Configuration options for creating a new provider.
|
|
793
825
|
*
|
|
826
|
+
* @typeParam TOptions - Provider-specific options type
|
|
827
|
+
*
|
|
794
828
|
* @example
|
|
795
829
|
* ```typescript
|
|
830
|
+
* // Simple provider with single handler
|
|
796
831
|
* const options: CreateProviderOptions = {
|
|
797
832
|
* name: 'my-provider',
|
|
798
833
|
* version: '1.0.0',
|
|
799
|
-
*
|
|
834
|
+
* handlers: {
|
|
800
835
|
* llm: createLLMHandler(),
|
|
801
836
|
* embedding: createEmbeddingHandler(),
|
|
802
837
|
* },
|
|
803
838
|
* };
|
|
839
|
+
*
|
|
840
|
+
* // Provider with multiple LLM handlers (API modes)
|
|
841
|
+
* const options: CreateProviderOptions<OpenAIOptions> = {
|
|
842
|
+
* name: 'openai',
|
|
843
|
+
* version: '1.0.0',
|
|
844
|
+
* handlers: {
|
|
845
|
+
* llm: {
|
|
846
|
+
* handlers: { responses: handler1, completions: handler2 },
|
|
847
|
+
* defaultMode: 'responses',
|
|
848
|
+
* getMode: (opts) => opts?.api ?? 'responses',
|
|
849
|
+
* },
|
|
850
|
+
* },
|
|
851
|
+
* };
|
|
804
852
|
* ```
|
|
805
853
|
*/
|
|
806
|
-
interface CreateProviderOptions {
|
|
854
|
+
interface CreateProviderOptions<TOptions = unknown> {
|
|
807
855
|
/** Unique identifier for the provider */
|
|
808
856
|
name: string;
|
|
809
857
|
/** Semantic version string for the provider implementation */
|
|
810
858
|
version: string;
|
|
811
859
|
/** Handlers for supported modalities (LLM, embedding, image generation) */
|
|
812
|
-
|
|
813
|
-
/** Handler for language model completions */
|
|
814
|
-
llm?: LLMHandler$1
|
|
860
|
+
handlers: {
|
|
861
|
+
/** Handler for language model completions, or resolver for multi-handler providers */
|
|
862
|
+
llm?: LLMHandler$1 | LLMHandlerResolver<TOptions>;
|
|
815
863
|
/** Handler for text embeddings */
|
|
816
864
|
embedding?: EmbeddingHandler;
|
|
817
865
|
/** Handler for image generation */
|
|
818
866
|
image?: ImageHandler;
|
|
819
867
|
};
|
|
868
|
+
/**
|
|
869
|
+
* Custom function to create model references from options.
|
|
870
|
+
* Use this to map provider options to providerConfig (e.g., betas to headers).
|
|
871
|
+
*/
|
|
872
|
+
createModelReference?: (modelId: string, options: TOptions | undefined, provider: Provider<TOptions>) => ModelReference<TOptions>;
|
|
820
873
|
}
|
|
821
874
|
/**
|
|
822
|
-
* Creates a provider factory function with
|
|
875
|
+
* Creates a provider factory function with registered modality handlers.
|
|
823
876
|
*
|
|
824
877
|
* The returned provider is a callable function that creates model references
|
|
825
|
-
* when invoked with a model ID. It
|
|
826
|
-
* `modalities` properties for introspection.
|
|
878
|
+
* when invoked with a model ID. It exposes `name` and `version` metadata.
|
|
827
879
|
*
|
|
828
880
|
* @typeParam TOptions - Provider-specific options type (defaults to unknown)
|
|
829
881
|
* @param options - Provider configuration including name, version, and handlers
|
|
830
|
-
* @returns A callable Provider with
|
|
882
|
+
* @returns A callable Provider with handlers registered internally
|
|
831
883
|
*
|
|
832
884
|
* @example
|
|
833
885
|
* ```typescript
|
|
@@ -835,7 +887,7 @@ interface CreateProviderOptions {
|
|
|
835
887
|
* const anthropic = createProvider({
|
|
836
888
|
* name: 'anthropic',
|
|
837
889
|
* version: '1.0.0',
|
|
838
|
-
*
|
|
890
|
+
* handlers: { llm: createLLMHandler() },
|
|
839
891
|
* });
|
|
840
892
|
*
|
|
841
893
|
* // Use the provider to create a model reference
|
|
@@ -846,11 +898,24 @@ interface CreateProviderOptions {
|
|
|
846
898
|
* const myProvider = createProvider<MyOptions>({
|
|
847
899
|
* name: 'my-provider',
|
|
848
900
|
* version: '1.0.0',
|
|
849
|
-
*
|
|
901
|
+
* handlers: { llm: handler },
|
|
902
|
+
* });
|
|
903
|
+
*
|
|
904
|
+
* // Provider with multiple LLM handlers (API modes)
|
|
905
|
+
* const openai = createProvider<OpenAIOptions>({
|
|
906
|
+
* name: 'openai',
|
|
907
|
+
* version: '1.0.0',
|
|
908
|
+
* handlers: {
|
|
909
|
+
* llm: {
|
|
910
|
+
* handlers: { responses: responsesHandler, completions: completionsHandler },
|
|
911
|
+
* defaultMode: 'responses',
|
|
912
|
+
* getMode: (opts) => opts?.api ?? 'responses',
|
|
913
|
+
* },
|
|
914
|
+
* },
|
|
850
915
|
* });
|
|
851
916
|
* ```
|
|
852
917
|
*/
|
|
853
|
-
declare function createProvider<TOptions = unknown>(options: CreateProviderOptions): Provider<TOptions>;
|
|
918
|
+
declare function createProvider<TOptions = unknown>(options: CreateProviderOptions<TOptions>): Provider<TOptions>;
|
|
854
919
|
|
|
855
920
|
/**
|
|
856
921
|
* @fileoverview Unified Provider Protocol (UPP) - A unified interface for AI model inference
|
|
@@ -910,4 +975,4 @@ declare const ai: {
|
|
|
910
975
|
image: typeof image;
|
|
911
976
|
};
|
|
912
977
|
|
|
913
|
-
export { AssistantContent, AssistantMessage, BoundEmbeddingModel, type BoundLLMModel, ContentBlock, type EmbedOptions, type Embedding, EmbeddingHandler, EmbeddingInput, type EmbeddingInstance, type EmbeddingModelInput, type EmbeddingOptions, type EmbeddingProgress, type EmbeddingResult, type EmbeddingStream, EmbeddingUsage, ImageInstance, ImageOptions, type InferenceInput, JSONSchema, type LLMCapabilities, type LLMHandler, type LLMInstance, type LLMOptions, LLMProvider, type LLMRequest, type LLMResponse, type LLMStreamResult, Message, MessageJSON, MessageType, Provider, ProviderConfig, StreamEvent, StreamResult, Thread, type ThreadJSON, TokenUsage, Tool, ToolUseStrategy, Turn, UserContent, ai, createProvider, embedding, image, llm };
|
|
978
|
+
export { AssistantContent, AssistantMessage, BoundEmbeddingModel, type BoundLLMModel, ContentBlock, type EmbedOptions, type Embedding, EmbeddingHandler, EmbeddingInput, type EmbeddingInstance, type EmbeddingModelInput, type EmbeddingOptions, type EmbeddingProgress, type EmbeddingResult, type EmbeddingStream, EmbeddingUsage, ImageInstance, ImageOptions, type InferenceInput, JSONSchema, type LLMCapabilities, type LLMHandler, type LLMInstance, type LLMOptions, LLMProvider, type LLMRequest, type LLMResponse, type LLMStreamResult, Message, MessageJSON, MessageType, ModelReference, Provider, ProviderConfig, ProviderIdentity, StreamEvent, StreamResult, Thread, type ThreadJSON, TokenUsage, Tool, ToolUseStrategy, Turn, UserContent, ai, createProvider, embedding, image, llm };
|