@providerprotocol/ai 0.0.31 → 0.0.32

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 CHANGED
@@ -1,8 +1,8 @@
1
- import { L as LLMOptions, a as LLMInstance, I as ImageOptions, b as ImageInstance, c as LLMHandler, E as EmbeddingHandler, d as ImageHandler, P as Provider, M as ModelReference, D as DocumentSource, e as DocumentBlock, A as AudioBlock, V as VideoBlock } from './llm-DgDEy9il.js';
2
- export { S as AfterCallResult, o as AssistantContent, Z as AssistantMessage, Q as BeforeCallResult, B as BinaryBlock, aw as BoundEmbeddingModel, aV as BoundImageModel, aG as BoundLLMModel, C as ContentBlock, p as ContentBlockType, r as DocumentSourceType, aB as EmbeddingInput, au as EmbeddingProvider, ax as EmbeddingRequest, ay as EmbeddingResponse, aA as EmbeddingUsage, az as EmbeddingVector, g as ErrorCode, af as EventDelta, aL as GeneratedImage, f as Image, l as ImageBlock, aQ as ImageCapabilities, aJ as ImageEditInput, aS as ImageEditRequest, aK as ImageGenerateOptions, aI as ImageInput, aW as ImageModelInput, av as ImageProvider, aU as ImageProviderStreamResult, aR as ImageRequest, aT as ImageResponse, aN as ImageResult, m as ImageSource, q as ImageSourceType, aO as ImageStreamEvent, aP as ImageStreamResult, aM as ImageUsage, aH as InferenceInput, J as JSONSchema, j as JSONSchemaProperty, k as JSONSchemaPropertyType, ar as KeyStrategy, aC as LLMCapabilities, at as LLMProvider, aD as LLMRequest, aE as LLMResponse, aF as LLMStreamResult, X as Message, ad as MessageJSON, a4 as MessageMetadata, a5 as MessageOptions, $ as MessageRole, a3 as MessageType, i as Modality, h as ModalityType, aq as ProviderConfig, ap as ProviderIdentity, R as ReasoningBlock, as as RetryStrategy, ae as StreamEvent, ah as StreamEventType, ag as StreamResult, T as TextBlock, ab as Thread, ac as ThreadJSON, a7 as TokenUsage, G as Tool, H as ToolCall, W as ToolExecution, N as ToolMetadata, K as ToolResult, _ as ToolResultMessage, O as ToolUseStrategy, a6 as Turn, U as UPPError, n as UserContent, Y as UserMessage, aa as aggregateUsage, an as contentBlockStart, ao as contentBlockStop, ai as createStreamResult, a8 as createTurn, a9 as emptyUsage, a1 as isAssistantMessage, y as isAudioBlock, F as isBinaryBlock, x as isDocumentBlock, w as isImageBlock, v as isReasoningBlock, u as isTextBlock, a2 as isToolResultMessage, a0 as isUserMessage, z as isVideoBlock, al as messageStart, am as messageStop, s as reasoning, t as text, aj as textDelta, ak as toolCallDelta } from './llm-DgDEy9il.js';
3
- import { E as EmbeddingOptions, a as EmbeddingInstance } from './embedding-k7g-BcSY.js';
4
- export { b as EmbedOptions, c as Embedding, h as EmbeddingInputType, g as EmbeddingModelInput, e as EmbeddingProgress, d as EmbeddingResult, f as EmbeddingStream } from './embedding-k7g-BcSY.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-CyAwm_KZ.js';
1
+ import { L as LLMOptions, a as LLMInstance, I as ImageOptions, b as ImageInstance, c as LLMHandler, E as EmbeddingHandler, d as ImageHandler, P as Provider, M as ModelReference, D as DocumentSource, e as DocumentBlock, A as AudioBlock, V as VideoBlock, f as Middleware, g as EventDelta, S as StreamEvent } from './llm-BQJZj3cD.js';
2
+ export { Y as AfterCallResult, b2 as AnyRequest, b3 as AnyResponse, q as AssistantContent, a0 as AssistantMessage, X as BeforeCallResult, B as BinaryBlock, aA as BoundEmbeddingModel, aZ as BoundImageModel, aK as BoundLLMModel, C as ContentBlock, r as ContentBlockType, t as DocumentSourceType, aF as EmbeddingInput, ay as EmbeddingProvider, aB as EmbeddingRequest, aC as EmbeddingResponse, aE as EmbeddingUsage, aD as EmbeddingVector, i as ErrorCode, aP as GeneratedImage, h as Image, n as ImageBlock, aU as ImageCapabilities, aN as ImageEditInput, aW as ImageEditRequest, aO as ImageGenerateOptions, aM as ImageInput, a_ as ImageModelInput, az as ImageProvider, aY as ImageProviderStreamResult, aV as ImageRequest, aX as ImageResponse, aR as ImageResult, o as ImageSource, s as ImageSourceType, aS as ImageStreamEvent, aT as ImageStreamResult, aQ as ImageUsage, aL as InferenceInput, J as JSONSchema, l as JSONSchemaProperty, m as JSONSchemaPropertyType, av as KeyStrategy, aG as LLMCapabilities, ax as LLMProvider, aH as LLMRequest, aI as LLMResponse, aJ as LLMStreamResult, _ as Message, ag as MessageJSON, a7 as MessageMetadata, a8 as MessageOptions, a2 as MessageRole, a6 as MessageType, a$ as MiddlewareContext, b1 as MiddlewareModality, k as Modality, j as ModalityType, au as ProviderConfig, at as ProviderIdentity, R as ReasoningBlock, aw as RetryStrategy, b0 as StreamContext, ai as StreamEventType, ah as StreamResult, T as TextBlock, ae as Thread, af as ThreadJSON, aa as TokenUsage, K as Tool, N as ToolCall, Z as ToolExecution, Q as ToolMetadata, O as ToolResult, a1 as ToolResultMessage, W as ToolUseStrategy, a9 as Turn, U as UPPError, p as UserContent, $ as UserMessage, ad as aggregateUsage, ap as contentBlockStart, aq as contentBlockStop, aj as createStreamResult, ab as createTurn, ac as emptyUsage, a4 as isAssistantMessage, F as isAudioBlock, H as isBinaryBlock, z as isDocumentBlock, y as isImageBlock, x as isReasoningBlock, w as isTextBlock, a5 as isToolResultMessage, a3 as isUserMessage, G as isVideoBlock, an as messageStart, ao as messageStop, am as objectDelta, v as reasoning, u as text, ak as textDelta, al as toolCallDelta, as as toolExecutionEnd, ar as toolExecutionStart } from './llm-BQJZj3cD.js';
3
+ import { E as EmbeddingOptions, a as EmbeddingInstance } from './embedding-D2BYIehX.js';
4
+ export { b as EmbedOptions, c as Embedding, h as EmbeddingInputType, g as EmbeddingModelInput, e as EmbeddingProgress, d as EmbeddingResult, f as EmbeddingStream } from './embedding-D2BYIehX.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-8Ch-WWgX.js';
6
6
 
7
7
  /**
8
8
  * @fileoverview LLM instance factory and streaming logic for the Universal Provider Protocol.
@@ -680,6 +680,118 @@ declare class Video {
680
680
  static fromBlock(block: VideoBlock): Video;
681
681
  }
682
682
 
683
+ /**
684
+ * @fileoverview Parsed object middleware for incremental JSON parsing.
685
+ *
686
+ * This middleware parses partial JSON from ObjectDelta and ToolCallDelta
687
+ * stream events, providing incremental structured data during streaming.
688
+ *
689
+ * @module middleware/parsed-object
690
+ */
691
+
692
+ /**
693
+ * Event delta with parsed JSON data.
694
+ * Extended by parsedObjectMiddleware when parsing is enabled.
695
+ */
696
+ interface ParsedEventDelta extends EventDelta {
697
+ /** Incrementally parsed JSON value */
698
+ parsed?: unknown;
699
+ }
700
+ /**
701
+ * Stream event with parsed JSON data.
702
+ * Returned by parsedObjectMiddleware for ObjectDelta and ToolCallDelta events.
703
+ */
704
+ interface ParsedStreamEvent extends Omit<StreamEvent, 'delta'> {
705
+ delta: ParsedEventDelta;
706
+ }
707
+ /**
708
+ * Options for parsed object middleware.
709
+ */
710
+ interface ParsedObjectOptions {
711
+ /**
712
+ * Parse ObjectDelta events (structured output responses).
713
+ * @default true
714
+ */
715
+ parseObjects?: boolean;
716
+ /**
717
+ * Parse ToolCallDelta events (tool call arguments).
718
+ * @default true
719
+ */
720
+ parseToolCalls?: boolean;
721
+ }
722
+ declare function parsedObjectMiddleware(options?: ParsedObjectOptions): Middleware;
723
+
724
+ /**
725
+ * @fileoverview Logging middleware for request/response visibility.
726
+ *
727
+ * Provides configurable logging for LLM, embedding, and image operations,
728
+ * including timing, error tracking, and optional event logging.
729
+ *
730
+ * @module middleware/logging
731
+ */
732
+
733
+ /**
734
+ * Log levels for filtering output.
735
+ */
736
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
737
+ /**
738
+ * Options for logging middleware.
739
+ */
740
+ interface LoggingOptions {
741
+ /**
742
+ * Minimum log level to output.
743
+ * @default 'info'
744
+ */
745
+ level?: LogLevel;
746
+ /**
747
+ * Log individual stream events.
748
+ * @default false
749
+ */
750
+ logStreamEvents?: boolean;
751
+ /**
752
+ * Log tool calls and results.
753
+ * @default true
754
+ */
755
+ logToolCalls?: boolean;
756
+ /**
757
+ * Custom logger function. If not provided, uses console.log.
758
+ * @param level - The log level
759
+ * @param message - The log message
760
+ * @param data - Optional additional data
761
+ */
762
+ logger?(level: LogLevel, message: string, data?: Record<string, unknown>): void;
763
+ /**
764
+ * Prefix for all log messages.
765
+ * @default '[PP]'
766
+ */
767
+ prefix?: string;
768
+ }
769
+ /**
770
+ * Creates a logging middleware for visibility into request lifecycle.
771
+ *
772
+ * This middleware logs the start, end, and errors of requests,
773
+ * with optional logging of stream events and tool calls.
774
+ *
775
+ * @param options - Configuration options
776
+ * @returns A middleware that logs request lifecycle events
777
+ *
778
+ * @example
779
+ * ```typescript
780
+ * import { llm, loggingMiddleware } from '@providerprotocol/ai';
781
+ * import { anthropic } from '@providerprotocol/ai/anthropic';
782
+ *
783
+ * const model = llm({
784
+ * model: anthropic('claude-sonnet-4-20250514'),
785
+ * middleware: [loggingMiddleware({ level: 'debug' })],
786
+ * });
787
+ *
788
+ * // Logs: [PP] [anthropic] Starting llm request (streaming)
789
+ * // Logs: [PP] [anthropic] Completed in 1234ms
790
+ * const result = await model.generate('Hello');
791
+ * ```
792
+ */
793
+ declare function loggingMiddleware(options?: LoggingOptions): Middleware;
794
+
683
795
  /**
684
796
  * @fileoverview Unified Provider Protocol (UPP) - A unified interface for AI model inference
685
797
  *
@@ -738,4 +850,4 @@ declare const ai: {
738
850
  image: typeof image;
739
851
  };
740
852
 
741
- export { Audio, AudioBlock, Document, DocumentBlock, DocumentSource, EmbeddingHandler, EmbeddingInstance, EmbeddingOptions, ImageHandler, ImageInstance, ImageOptions, LLMHandler, LLMInstance, LLMOptions, ModelReference, Provider, Video, VideoBlock, ai, createProvider, embedding, image, llm };
853
+ export { Audio, AudioBlock, Document, DocumentBlock, DocumentSource, EmbeddingHandler, EmbeddingInstance, EmbeddingOptions, EventDelta, ImageHandler, ImageInstance, ImageOptions, LLMHandler, LLMInstance, LLMOptions, type LogLevel, type LoggingOptions, Middleware, ModelReference, type ParsedEventDelta, type ParsedObjectOptions, type ParsedStreamEvent, Provider, StreamEvent, Video, VideoBlock, ai, createProvider, embedding, image, llm, loggingMiddleware, parsedObjectMiddleware };