@assemble-dev/providers 0.2.0 → 0.3.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { JsonValue } from '@assemble-dev/shared-types/json';
2
+ import { JsonValue, JsonObject } from '@assemble-dev/shared-types/json';
3
3
  import { TokenUsage } from '@assemble-dev/shared-types/runs';
4
4
  import { AppError } from '@assemble-dev/shared-utils/errors';
5
5
  import * as _assemble_dev_shared_types from '@assemble-dev/shared-types';
@@ -104,10 +104,14 @@ type ChatCompletionResult = {
104
104
  latencyMs: number;
105
105
  toolCalls?: ModelToolCall[];
106
106
  stopReason?: ChatStopReason;
107
+ thinkingText?: string;
107
108
  };
108
109
  type ChatStreamEvent = {
109
110
  type: "text_delta";
110
111
  text: string;
112
+ } | {
113
+ type: "thinking_delta";
114
+ text: string;
111
115
  } | {
112
116
  type: "tool_call_started";
113
117
  id: string;
@@ -227,6 +231,12 @@ type AnthropicToolChoice = {
227
231
  type: "tool";
228
232
  name: string;
229
233
  };
234
+ type AnthropicOutputConfig = {
235
+ format: {
236
+ type: "json_schema";
237
+ schema: JsonObject;
238
+ };
239
+ };
230
240
  type AnthropicRequestBody = {
231
241
  model: string;
232
242
  max_tokens: number;
@@ -239,6 +249,7 @@ type AnthropicRequestBody = {
239
249
  };
240
250
  tools?: AnthropicToolDefinition[];
241
251
  tool_choice?: AnthropicToolChoice;
252
+ output_config?: AnthropicOutputConfig;
242
253
  stream?: true;
243
254
  };
244
255
  type AnthropicRequestInput = {
@@ -247,6 +258,7 @@ type AnthropicRequestInput = {
247
258
  maxOutputTokens?: number;
248
259
  tools?: ModelToolDefinition[];
249
260
  toolChoice?: ModelToolChoice;
261
+ structuredOutputJsonSchema?: JsonObject;
250
262
  abortSignal?: AbortSignal;
251
263
  extraBody?: Record<string, JsonValue>;
252
264
  };
@@ -344,6 +356,16 @@ declare function isAbortError(error: Error): boolean;
344
356
  declare function buildProviderCanceledError(providerLabel: string): AppError;
345
357
  declare function executeAbortableProviderFetch(providerLabel: string, performFetch: () => Promise<Response>): Promise<Response>;
346
358
 
359
+ declare const openAiStructuredOutputSchemaName = "structured_output";
360
+ declare function convertZodSchemaToJsonSchema<T>(schema: z.ZodType<T>): JsonObject;
361
+ declare function buildAnthropicStructuredOutputJsonSchema<T>(schema: z.ZodType<T>): JsonObject;
362
+ declare function sanitizeJsonSchemaForAnthropicStructuredOutput(jsonSchema: JsonObject): JsonObject;
363
+ declare function buildOpenAiStructuredOutputJsonSchema<T>(schema: z.ZodType<T>): JsonObject;
364
+ declare function sanitizeJsonSchemaForOpenAiStructuredOutput(jsonSchema: JsonObject): JsonObject;
365
+
366
+ declare function buildGeminiResponseSchema<T>(schema: z.ZodType<T>): JsonObject;
367
+ declare function sanitizeJsonSchemaForGeminiResponseSchema(jsonSchema: JsonObject): JsonObject;
368
+
347
369
  declare const AnthropicUsageSchema: z.ZodObject<{
348
370
  input_tokens: z.ZodNumber;
349
371
  output_tokens: z.ZodNumber;
@@ -379,6 +401,7 @@ declare const AnthropicMessagesResponseSchema: z.ZodObject<{
379
401
  type AnthropicMessagesResponse = z.infer<typeof AnthropicMessagesResponseSchema>;
380
402
  declare function mapAnthropicResponseToChatCompletionResult(response: AnthropicMessagesResponse, latencyMs: number): ChatCompletionResult;
381
403
  declare function extractAnthropicToolCalls(response: AnthropicMessagesResponse): ModelToolCall[];
404
+ declare function extractAnthropicThinkingText(response: AnthropicMessagesResponse): string;
382
405
  declare function extractAnthropicTextContent(response: AnthropicMessagesResponse, allowEmptyText: boolean): string;
383
406
  declare function normalizeAnthropicStopReason(providerStopReason: string): ChatStopReason;
384
407
  declare function mapAnthropicUsageToTokenUsage(usage: AnthropicUsage): TokenUsage;
@@ -411,6 +434,12 @@ declare const AnthropicStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
411
434
  content_block: z.ZodDiscriminatedUnion<[z.ZodObject<{
412
435
  type: z.ZodLiteral<"text">;
413
436
  text: z.ZodOptional<z.ZodString>;
437
+ }, z.core.$strip>, z.ZodObject<{
438
+ type: z.ZodLiteral<"thinking">;
439
+ thinking: z.ZodOptional<z.ZodString>;
440
+ }, z.core.$strip>, z.ZodObject<{
441
+ type: z.ZodLiteral<"redacted_thinking">;
442
+ data: z.ZodOptional<z.ZodString>;
414
443
  }, z.core.$strip>, z.ZodObject<{
415
444
  type: z.ZodLiteral<"tool_use">;
416
445
  id: z.ZodString;
@@ -422,6 +451,12 @@ declare const AnthropicStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
422
451
  delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
423
452
  type: z.ZodLiteral<"text_delta">;
424
453
  text: z.ZodString;
454
+ }, z.core.$strip>, z.ZodObject<{
455
+ type: z.ZodLiteral<"thinking_delta">;
456
+ thinking: z.ZodString;
457
+ }, z.core.$strip>, z.ZodObject<{
458
+ type: z.ZodLiteral<"signature_delta">;
459
+ signature: z.ZodString;
425
460
  }, z.core.$strip>, z.ZodObject<{
426
461
  type: z.ZodLiteral<"input_json_delta">;
427
462
  partial_json: z.ZodString;
@@ -489,14 +524,22 @@ type OpenAiToolChoice = "auto" | "required" | "none" | {
489
524
  name: string;
490
525
  };
491
526
  };
527
+ type OpenAiResponseFormat = {
528
+ type: "json_object";
529
+ } | {
530
+ type: "json_schema";
531
+ json_schema: {
532
+ name: string;
533
+ strict: true;
534
+ schema: JsonObject;
535
+ };
536
+ };
492
537
  type OpenAiRequestBody = {
493
538
  model: string;
494
539
  messages: OpenAiRequestMessage[];
495
540
  temperature?: number;
496
541
  max_tokens?: number;
497
- response_format?: {
498
- type: "json_object";
499
- };
542
+ response_format?: OpenAiResponseFormat;
500
543
  tools?: OpenAiToolDefinition[];
501
544
  tool_choice?: OpenAiToolChoice;
502
545
  };
@@ -504,7 +547,8 @@ type OpenAiCallInput = {
504
547
  messages: ChatMessage[];
505
548
  temperature?: number;
506
549
  maxOutputTokens?: number;
507
- requireJsonObjectResponse: boolean;
550
+ structuredOutputJsonSchema?: JsonObject;
551
+ requireJsonObjectResponse?: boolean;
508
552
  tools?: ModelToolDefinition[];
509
553
  toolChoice?: ModelToolChoice;
510
554
  abortSignal?: AbortSignal;
@@ -524,6 +568,7 @@ type AnthropicBatchMessageRequest = {
524
568
  temperature?: number;
525
569
  promptCaching?: AnthropicBatchPromptCachingMode;
526
570
  requireJsonResponse?: boolean;
571
+ structuredOutputJsonSchema?: JsonObject;
527
572
  };
528
573
  type AnthropicBatchApiRequestMessage = {
529
574
  role: "user" | "assistant";
@@ -542,6 +587,7 @@ type AnthropicBatchApiRequestParams = {
542
587
  messages: AnthropicBatchApiRequestMessage[];
543
588
  system?: string | AnthropicBatchSystemContentBlock[];
544
589
  temperature?: number;
590
+ output_config?: AnthropicOutputConfig;
545
591
  };
546
592
  type AnthropicBatchApiRequest = {
547
593
  custom_id: string;
@@ -638,4 +684,111 @@ declare function createAnthropicBatchClient(options: AnthropicBatchClientOptions
638
684
  declare const anthropicBatchJsonOnlySystemInstruction = "Respond with a single JSON object that satisfies the caller's requested structure. Output only valid JSON with no surrounding text.";
639
685
  declare function parseAnthropicBatchStructuredContent<T>(content: string, schema: ValidationSchema<T>): T;
640
686
 
641
- export { type AnthropicAdapterOptions, type AnthropicBatchApiRequest, type AnthropicBatchApiRequestMessage, type AnthropicBatchApiRequestParams, type AnthropicBatchCanceledOutcome, type AnthropicBatchClient, type AnthropicBatchClientOptions, type AnthropicBatchErroredOutcome, type AnthropicBatchExpiredOutcome, type AnthropicBatchMessageRequest, type AnthropicBatchPromptCachingMode, type AnthropicBatchResult, type AnthropicBatchResultOutcome, type AnthropicBatchSubmittedRequestSummary, type AnthropicBatchSucceededOutcome, type AnthropicBatchSystemContentBlock, type AnthropicBatchTraceEventHandler, type AnthropicBatchWaitOptions, type AnthropicCacheControl, type AnthropicCacheTtl, type AnthropicMessageBatch, type AnthropicMessageBatchProcessingStatus, type AnthropicMessageBatchRequestCounts, type AnthropicMessagesResponse, AnthropicMessagesResponseSchema, type AnthropicPromptCachingMode, type AnthropicPromptCachingOptions, type AnthropicPromptCachingSettings, type AnthropicRequestBody, type AnthropicRequestContentBlock, type AnthropicRequestInput, type AnthropicRequestMessage, type AnthropicRequestSettings, type AnthropicStreamEvent, AnthropicStreamEventSchema, type AnthropicStreamRequestInput, type AnthropicStreamStartUsage, type AnthropicSystemContentBlock, type AnthropicThinkingOptions, type AnthropicToolChoice, type AnthropicToolDefinition, type AnthropicUsage, type ChatCompletionRequest, type ChatCompletionResult, type ChatMessage, type ChatMessageCacheControl, ChatMessageCacheControlSchema, type ChatMessageRole, ChatMessageRoleSchema, ChatMessageSchema, type ChatStopReason, ChatStopReasonSchema, type ChatStreamEvent, type GeminiAdapterOptions, type MessageContentBlock, MessageContentBlockSchema, type MockModelOptions, type ModelAdapter, type ModelPricingUsdPerMillionTokens, type ModelToolCall, ModelToolCallSchema, type ModelToolChoice, type ModelToolDefinition, type OpenAiAdapterOptions, type OpenAiCallInput, type OpenAiContentPart, type OpenAiRequestBody, type OpenAiRequestMessage, type OpenAiRequestToolCall, type OpenAiToolChoice, type OpenAiToolDefinition, type ProviderExtraBody, type ProviderRetryOptions, type ResolveProviderApiKeyInput, type StructuredOutputRequest, type StructuredOutputResult, anthropic, anthropicBatchJsonOnlySystemInstruction, anthropicBatchTraceWorkflowName, applyCacheControlToLastContentBlock, buildAnthropicCacheControl, buildAnthropicRequestBody, buildOpenAiRequestBody, buildProviderCanceledError, calculateProviderRetryDelayMs, createAnthropicBatchClient, defaultAnthropicBaseUrl, defaultAnthropicBatchPollIntervalMs, defaultAnthropicBatchTimeoutMs, defaultAnthropicMaxOutputTokens, defaultGeminiBaseUrl, defaultOpenAiBaseUrl, defaultProviderRetryInitialDelayMs, defaultProviderRetryMaxAttempts, defaultProviderRetryMaxDelayMs, estimateModelCallCostUsd, executeAbortableProviderFetch, executeProviderCallWithModelFallback, executeProviderCallWithRetry, extractAnthropicTextContent, extractAnthropicToolCalls, extractMessageText, gemini, isAbortError, isRetryableProviderAppError, joinSystemMessageText, mapAnthropicResponseToChatCompletionResult, mapAnthropicUsageToTokenUsage, mapChatMessageToAnthropicRequestMessage, mapChatMessageToOpenAiRequestMessage, mapModelToolChoiceToAnthropicToolChoice, mapModelToolChoiceToOpenAiToolChoice, mapModelToolDefinitionToOpenAiTool, mapModelToolDefinitionsToAnthropicTools, mergeProviderRequestExtraBody, mockModel, normalizeAnthropicStopReason, openai, parseAnthropicBatchStructuredContent, parseAnthropicStreamEvents, parseAnthropicToolInputJson, resolveAnthropicPromptCachingSettings, resolveProviderApiKey, streamAnthropicChatCompletion };
687
+ declare const defaultAzureOpenAiApiVersion = "2024-10-21";
688
+ type AzureOpenAiAdapterOptions = {
689
+ deployment: string;
690
+ resourceName?: string;
691
+ baseURL?: string;
692
+ apiVersion?: string;
693
+ apiKey?: string;
694
+ apiKeyName?: string;
695
+ fetchImplementation?: typeof fetch;
696
+ temperature?: number;
697
+ maxOutputTokens?: number;
698
+ retry?: ProviderRetryOptions;
699
+ extraBody?: Record<string, JsonValue>;
700
+ };
701
+ type AzureOpenAiChatRequestBody = Omit<OpenAiRequestBody, "model">;
702
+ declare function azureOpenai(options: AzureOpenAiAdapterOptions): ModelAdapter;
703
+ declare function buildAzureOpenAiChatCompletionsUrl(options: AzureOpenAiAdapterOptions): string;
704
+ declare function buildAzureOpenAiChatRequestBody(input: OpenAiCallInput): AzureOpenAiChatRequestBody;
705
+
706
+ declare const AzureOpenAiUsageSchema: z.ZodObject<{
707
+ prompt_tokens: z.ZodNumber;
708
+ completion_tokens: z.ZodNumber;
709
+ total_tokens: z.ZodNumber;
710
+ }, z.core.$strip>;
711
+ type AzureOpenAiUsage = z.infer<typeof AzureOpenAiUsageSchema>;
712
+ declare const AzureOpenAiChatCompletionResponseSchema: z.ZodObject<{
713
+ choices: z.ZodArray<z.ZodObject<{
714
+ message: z.ZodObject<{
715
+ content: z.ZodNullable<z.ZodString>;
716
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
717
+ id: z.ZodString;
718
+ function: z.ZodObject<{
719
+ name: z.ZodString;
720
+ arguments: z.ZodString;
721
+ }, z.core.$strip>;
722
+ }, z.core.$strip>>>;
723
+ }, z.core.$strip>;
724
+ finish_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
725
+ }, z.core.$strip>>;
726
+ usage: z.ZodObject<{
727
+ prompt_tokens: z.ZodNumber;
728
+ completion_tokens: z.ZodNumber;
729
+ total_tokens: z.ZodNumber;
730
+ }, z.core.$strip>;
731
+ }, z.core.$strip>;
732
+ type AzureOpenAiChatCompletionResponse = z.infer<typeof AzureOpenAiChatCompletionResponseSchema>;
733
+ declare function mapAzureOpenAiResponseToChatCompletionResult(response: AzureOpenAiChatCompletionResponse, latencyMs: number): ChatCompletionResult;
734
+ declare function parseAzureOpenAiToolArgumentsJson(argumentsJsonText: string): JsonValue;
735
+ declare function normalizeAzureOpenAiFinishReason(finishReason: string): ChatStopReason;
736
+ declare function mapAzureOpenAiUsageToTokenUsage(usage: AzureOpenAiUsage): TokenUsage;
737
+
738
+ type AzureOpenAiStreamRequestBody = Omit<OpenAiRequestBody, "model"> & {
739
+ stream: true;
740
+ stream_options: {
741
+ include_usage: boolean;
742
+ };
743
+ };
744
+ type AzureOpenAiStreamRequestInput = {
745
+ url: string;
746
+ headers: Record<string, string>;
747
+ body: AzureOpenAiStreamRequestBody;
748
+ fetchImplementation: typeof fetch;
749
+ retry?: ProviderRetryOptions;
750
+ abortSignal?: AbortSignal;
751
+ };
752
+ declare function streamAzureOpenAiChatCompletion(input: AzureOpenAiStreamRequestInput): AsyncGenerator<ChatStreamEvent, void, void>;
753
+ declare function parseAzureOpenAiStreamEvents(body: ReadableStream<Uint8Array>, startedAt: number, abortSignal: AbortSignal | undefined): AsyncGenerator<ChatStreamEvent, void, void>;
754
+
755
+ declare const awsSigV4Algorithm = "AWS4-HMAC-SHA256";
756
+ type AwsCredentials = {
757
+ accessKeyId: string;
758
+ secretAccessKey: string;
759
+ sessionToken?: string;
760
+ };
761
+ type AwsSigV4SigningInput = {
762
+ method: string;
763
+ url: URL;
764
+ headers: Record<string, string>;
765
+ bodyText: string;
766
+ region: string;
767
+ service: string;
768
+ credentials: AwsCredentials;
769
+ signingDate?: Date;
770
+ };
771
+ declare function signAwsRequestWithSigV4(input: AwsSigV4SigningInput): Promise<Record<string, string>>;
772
+
773
+ declare const bedrockAnthropicVersion = "bedrock-2023-05-31";
774
+ declare const defaultBedrockMaxOutputTokens = 1024;
775
+ type BedrockCredentials = AwsCredentials;
776
+ type BedrockAdapterOptions = {
777
+ region: string;
778
+ modelId: string;
779
+ credentials?: BedrockCredentials;
780
+ fetchImplementation?: typeof fetch;
781
+ temperature?: number;
782
+ maxOutputTokens?: number;
783
+ retry?: ProviderRetryOptions;
784
+ extraBody?: Record<string, JsonValue>;
785
+ };
786
+ type BedrockInvokeModelRequestBody = Omit<AnthropicRequestBody, "model" | "stream"> & {
787
+ anthropic_version: string;
788
+ };
789
+ declare function bedrock(options: BedrockAdapterOptions): ModelAdapter;
790
+ declare function buildBedrockInvokeModelUrl(region: string, modelId: string): string;
791
+ declare function resolveBedrockCredentials(options: BedrockAdapterOptions): BedrockCredentials;
792
+ declare function buildBedrockInvokeModelRequestBody(input: AnthropicRequestInput): BedrockInvokeModelRequestBody;
793
+
794
+ export { type AnthropicAdapterOptions, type AnthropicBatchApiRequest, type AnthropicBatchApiRequestMessage, type AnthropicBatchApiRequestParams, type AnthropicBatchCanceledOutcome, type AnthropicBatchClient, type AnthropicBatchClientOptions, type AnthropicBatchErroredOutcome, type AnthropicBatchExpiredOutcome, type AnthropicBatchMessageRequest, type AnthropicBatchPromptCachingMode, type AnthropicBatchResult, type AnthropicBatchResultOutcome, type AnthropicBatchSubmittedRequestSummary, type AnthropicBatchSucceededOutcome, type AnthropicBatchSystemContentBlock, type AnthropicBatchTraceEventHandler, type AnthropicBatchWaitOptions, type AnthropicCacheControl, type AnthropicCacheTtl, type AnthropicMessageBatch, type AnthropicMessageBatchProcessingStatus, type AnthropicMessageBatchRequestCounts, type AnthropicMessagesResponse, AnthropicMessagesResponseSchema, type AnthropicOutputConfig, type AnthropicPromptCachingMode, type AnthropicPromptCachingOptions, type AnthropicPromptCachingSettings, type AnthropicRequestBody, type AnthropicRequestContentBlock, type AnthropicRequestInput, type AnthropicRequestMessage, type AnthropicRequestSettings, type AnthropicStreamEvent, AnthropicStreamEventSchema, type AnthropicStreamRequestInput, type AnthropicStreamStartUsage, type AnthropicSystemContentBlock, type AnthropicThinkingOptions, type AnthropicToolChoice, type AnthropicToolDefinition, type AnthropicUsage, type AwsCredentials, type AwsSigV4SigningInput, type AzureOpenAiAdapterOptions, type AzureOpenAiChatCompletionResponse, AzureOpenAiChatCompletionResponseSchema, type AzureOpenAiChatRequestBody, type AzureOpenAiStreamRequestBody, type AzureOpenAiStreamRequestInput, type AzureOpenAiUsage, type BedrockAdapterOptions, type BedrockCredentials, type BedrockInvokeModelRequestBody, type ChatCompletionRequest, type ChatCompletionResult, type ChatMessage, type ChatMessageCacheControl, ChatMessageCacheControlSchema, type ChatMessageRole, ChatMessageRoleSchema, ChatMessageSchema, type ChatStopReason, ChatStopReasonSchema, type ChatStreamEvent, type GeminiAdapterOptions, type MessageContentBlock, MessageContentBlockSchema, type MockModelOptions, type ModelAdapter, type ModelPricingUsdPerMillionTokens, type ModelToolCall, ModelToolCallSchema, type ModelToolChoice, type ModelToolDefinition, type OpenAiAdapterOptions, type OpenAiCallInput, type OpenAiContentPart, type OpenAiRequestBody, type OpenAiRequestMessage, type OpenAiRequestToolCall, type OpenAiResponseFormat, type OpenAiToolChoice, type OpenAiToolDefinition, type ProviderExtraBody, type ProviderRetryOptions, type ResolveProviderApiKeyInput, type StructuredOutputRequest, type StructuredOutputResult, anthropic, anthropicBatchJsonOnlySystemInstruction, anthropicBatchTraceWorkflowName, applyCacheControlToLastContentBlock, awsSigV4Algorithm, azureOpenai, bedrock, bedrockAnthropicVersion, buildAnthropicCacheControl, buildAnthropicRequestBody, buildAnthropicStructuredOutputJsonSchema, buildAzureOpenAiChatCompletionsUrl, buildAzureOpenAiChatRequestBody, buildBedrockInvokeModelRequestBody, buildBedrockInvokeModelUrl, buildGeminiResponseSchema, buildOpenAiRequestBody, buildOpenAiStructuredOutputJsonSchema, buildProviderCanceledError, calculateProviderRetryDelayMs, convertZodSchemaToJsonSchema, createAnthropicBatchClient, defaultAnthropicBaseUrl, defaultAnthropicBatchPollIntervalMs, defaultAnthropicBatchTimeoutMs, defaultAnthropicMaxOutputTokens, defaultAzureOpenAiApiVersion, defaultBedrockMaxOutputTokens, defaultGeminiBaseUrl, defaultOpenAiBaseUrl, defaultProviderRetryInitialDelayMs, defaultProviderRetryMaxAttempts, defaultProviderRetryMaxDelayMs, estimateModelCallCostUsd, executeAbortableProviderFetch, executeProviderCallWithModelFallback, executeProviderCallWithRetry, extractAnthropicTextContent, extractAnthropicThinkingText, extractAnthropicToolCalls, extractMessageText, gemini, isAbortError, isRetryableProviderAppError, joinSystemMessageText, mapAnthropicResponseToChatCompletionResult, mapAnthropicUsageToTokenUsage, mapAzureOpenAiResponseToChatCompletionResult, mapAzureOpenAiUsageToTokenUsage, mapChatMessageToAnthropicRequestMessage, mapChatMessageToOpenAiRequestMessage, mapModelToolChoiceToAnthropicToolChoice, mapModelToolChoiceToOpenAiToolChoice, mapModelToolDefinitionToOpenAiTool, mapModelToolDefinitionsToAnthropicTools, mergeProviderRequestExtraBody, mockModel, normalizeAnthropicStopReason, normalizeAzureOpenAiFinishReason, openAiStructuredOutputSchemaName, openai, parseAnthropicBatchStructuredContent, parseAnthropicStreamEvents, parseAnthropicToolInputJson, parseAzureOpenAiStreamEvents, parseAzureOpenAiToolArgumentsJson, resolveAnthropicPromptCachingSettings, resolveBedrockCredentials, resolveProviderApiKey, sanitizeJsonSchemaForAnthropicStructuredOutput, sanitizeJsonSchemaForGeminiResponseSchema, sanitizeJsonSchemaForOpenAiStructuredOutput, signAwsRequestWithSigV4, streamAnthropicChatCompletion, streamAzureOpenAiChatCompletion };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { JsonValue } from '@assemble-dev/shared-types/json';
2
+ import { JsonValue, JsonObject } from '@assemble-dev/shared-types/json';
3
3
  import { TokenUsage } from '@assemble-dev/shared-types/runs';
4
4
  import { AppError } from '@assemble-dev/shared-utils/errors';
5
5
  import * as _assemble_dev_shared_types from '@assemble-dev/shared-types';
@@ -104,10 +104,14 @@ type ChatCompletionResult = {
104
104
  latencyMs: number;
105
105
  toolCalls?: ModelToolCall[];
106
106
  stopReason?: ChatStopReason;
107
+ thinkingText?: string;
107
108
  };
108
109
  type ChatStreamEvent = {
109
110
  type: "text_delta";
110
111
  text: string;
112
+ } | {
113
+ type: "thinking_delta";
114
+ text: string;
111
115
  } | {
112
116
  type: "tool_call_started";
113
117
  id: string;
@@ -227,6 +231,12 @@ type AnthropicToolChoice = {
227
231
  type: "tool";
228
232
  name: string;
229
233
  };
234
+ type AnthropicOutputConfig = {
235
+ format: {
236
+ type: "json_schema";
237
+ schema: JsonObject;
238
+ };
239
+ };
230
240
  type AnthropicRequestBody = {
231
241
  model: string;
232
242
  max_tokens: number;
@@ -239,6 +249,7 @@ type AnthropicRequestBody = {
239
249
  };
240
250
  tools?: AnthropicToolDefinition[];
241
251
  tool_choice?: AnthropicToolChoice;
252
+ output_config?: AnthropicOutputConfig;
242
253
  stream?: true;
243
254
  };
244
255
  type AnthropicRequestInput = {
@@ -247,6 +258,7 @@ type AnthropicRequestInput = {
247
258
  maxOutputTokens?: number;
248
259
  tools?: ModelToolDefinition[];
249
260
  toolChoice?: ModelToolChoice;
261
+ structuredOutputJsonSchema?: JsonObject;
250
262
  abortSignal?: AbortSignal;
251
263
  extraBody?: Record<string, JsonValue>;
252
264
  };
@@ -344,6 +356,16 @@ declare function isAbortError(error: Error): boolean;
344
356
  declare function buildProviderCanceledError(providerLabel: string): AppError;
345
357
  declare function executeAbortableProviderFetch(providerLabel: string, performFetch: () => Promise<Response>): Promise<Response>;
346
358
 
359
+ declare const openAiStructuredOutputSchemaName = "structured_output";
360
+ declare function convertZodSchemaToJsonSchema<T>(schema: z.ZodType<T>): JsonObject;
361
+ declare function buildAnthropicStructuredOutputJsonSchema<T>(schema: z.ZodType<T>): JsonObject;
362
+ declare function sanitizeJsonSchemaForAnthropicStructuredOutput(jsonSchema: JsonObject): JsonObject;
363
+ declare function buildOpenAiStructuredOutputJsonSchema<T>(schema: z.ZodType<T>): JsonObject;
364
+ declare function sanitizeJsonSchemaForOpenAiStructuredOutput(jsonSchema: JsonObject): JsonObject;
365
+
366
+ declare function buildGeminiResponseSchema<T>(schema: z.ZodType<T>): JsonObject;
367
+ declare function sanitizeJsonSchemaForGeminiResponseSchema(jsonSchema: JsonObject): JsonObject;
368
+
347
369
  declare const AnthropicUsageSchema: z.ZodObject<{
348
370
  input_tokens: z.ZodNumber;
349
371
  output_tokens: z.ZodNumber;
@@ -379,6 +401,7 @@ declare const AnthropicMessagesResponseSchema: z.ZodObject<{
379
401
  type AnthropicMessagesResponse = z.infer<typeof AnthropicMessagesResponseSchema>;
380
402
  declare function mapAnthropicResponseToChatCompletionResult(response: AnthropicMessagesResponse, latencyMs: number): ChatCompletionResult;
381
403
  declare function extractAnthropicToolCalls(response: AnthropicMessagesResponse): ModelToolCall[];
404
+ declare function extractAnthropicThinkingText(response: AnthropicMessagesResponse): string;
382
405
  declare function extractAnthropicTextContent(response: AnthropicMessagesResponse, allowEmptyText: boolean): string;
383
406
  declare function normalizeAnthropicStopReason(providerStopReason: string): ChatStopReason;
384
407
  declare function mapAnthropicUsageToTokenUsage(usage: AnthropicUsage): TokenUsage;
@@ -411,6 +434,12 @@ declare const AnthropicStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
411
434
  content_block: z.ZodDiscriminatedUnion<[z.ZodObject<{
412
435
  type: z.ZodLiteral<"text">;
413
436
  text: z.ZodOptional<z.ZodString>;
437
+ }, z.core.$strip>, z.ZodObject<{
438
+ type: z.ZodLiteral<"thinking">;
439
+ thinking: z.ZodOptional<z.ZodString>;
440
+ }, z.core.$strip>, z.ZodObject<{
441
+ type: z.ZodLiteral<"redacted_thinking">;
442
+ data: z.ZodOptional<z.ZodString>;
414
443
  }, z.core.$strip>, z.ZodObject<{
415
444
  type: z.ZodLiteral<"tool_use">;
416
445
  id: z.ZodString;
@@ -422,6 +451,12 @@ declare const AnthropicStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
422
451
  delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
423
452
  type: z.ZodLiteral<"text_delta">;
424
453
  text: z.ZodString;
454
+ }, z.core.$strip>, z.ZodObject<{
455
+ type: z.ZodLiteral<"thinking_delta">;
456
+ thinking: z.ZodString;
457
+ }, z.core.$strip>, z.ZodObject<{
458
+ type: z.ZodLiteral<"signature_delta">;
459
+ signature: z.ZodString;
425
460
  }, z.core.$strip>, z.ZodObject<{
426
461
  type: z.ZodLiteral<"input_json_delta">;
427
462
  partial_json: z.ZodString;
@@ -489,14 +524,22 @@ type OpenAiToolChoice = "auto" | "required" | "none" | {
489
524
  name: string;
490
525
  };
491
526
  };
527
+ type OpenAiResponseFormat = {
528
+ type: "json_object";
529
+ } | {
530
+ type: "json_schema";
531
+ json_schema: {
532
+ name: string;
533
+ strict: true;
534
+ schema: JsonObject;
535
+ };
536
+ };
492
537
  type OpenAiRequestBody = {
493
538
  model: string;
494
539
  messages: OpenAiRequestMessage[];
495
540
  temperature?: number;
496
541
  max_tokens?: number;
497
- response_format?: {
498
- type: "json_object";
499
- };
542
+ response_format?: OpenAiResponseFormat;
500
543
  tools?: OpenAiToolDefinition[];
501
544
  tool_choice?: OpenAiToolChoice;
502
545
  };
@@ -504,7 +547,8 @@ type OpenAiCallInput = {
504
547
  messages: ChatMessage[];
505
548
  temperature?: number;
506
549
  maxOutputTokens?: number;
507
- requireJsonObjectResponse: boolean;
550
+ structuredOutputJsonSchema?: JsonObject;
551
+ requireJsonObjectResponse?: boolean;
508
552
  tools?: ModelToolDefinition[];
509
553
  toolChoice?: ModelToolChoice;
510
554
  abortSignal?: AbortSignal;
@@ -524,6 +568,7 @@ type AnthropicBatchMessageRequest = {
524
568
  temperature?: number;
525
569
  promptCaching?: AnthropicBatchPromptCachingMode;
526
570
  requireJsonResponse?: boolean;
571
+ structuredOutputJsonSchema?: JsonObject;
527
572
  };
528
573
  type AnthropicBatchApiRequestMessage = {
529
574
  role: "user" | "assistant";
@@ -542,6 +587,7 @@ type AnthropicBatchApiRequestParams = {
542
587
  messages: AnthropicBatchApiRequestMessage[];
543
588
  system?: string | AnthropicBatchSystemContentBlock[];
544
589
  temperature?: number;
590
+ output_config?: AnthropicOutputConfig;
545
591
  };
546
592
  type AnthropicBatchApiRequest = {
547
593
  custom_id: string;
@@ -638,4 +684,111 @@ declare function createAnthropicBatchClient(options: AnthropicBatchClientOptions
638
684
  declare const anthropicBatchJsonOnlySystemInstruction = "Respond with a single JSON object that satisfies the caller's requested structure. Output only valid JSON with no surrounding text.";
639
685
  declare function parseAnthropicBatchStructuredContent<T>(content: string, schema: ValidationSchema<T>): T;
640
686
 
641
- export { type AnthropicAdapterOptions, type AnthropicBatchApiRequest, type AnthropicBatchApiRequestMessage, type AnthropicBatchApiRequestParams, type AnthropicBatchCanceledOutcome, type AnthropicBatchClient, type AnthropicBatchClientOptions, type AnthropicBatchErroredOutcome, type AnthropicBatchExpiredOutcome, type AnthropicBatchMessageRequest, type AnthropicBatchPromptCachingMode, type AnthropicBatchResult, type AnthropicBatchResultOutcome, type AnthropicBatchSubmittedRequestSummary, type AnthropicBatchSucceededOutcome, type AnthropicBatchSystemContentBlock, type AnthropicBatchTraceEventHandler, type AnthropicBatchWaitOptions, type AnthropicCacheControl, type AnthropicCacheTtl, type AnthropicMessageBatch, type AnthropicMessageBatchProcessingStatus, type AnthropicMessageBatchRequestCounts, type AnthropicMessagesResponse, AnthropicMessagesResponseSchema, type AnthropicPromptCachingMode, type AnthropicPromptCachingOptions, type AnthropicPromptCachingSettings, type AnthropicRequestBody, type AnthropicRequestContentBlock, type AnthropicRequestInput, type AnthropicRequestMessage, type AnthropicRequestSettings, type AnthropicStreamEvent, AnthropicStreamEventSchema, type AnthropicStreamRequestInput, type AnthropicStreamStartUsage, type AnthropicSystemContentBlock, type AnthropicThinkingOptions, type AnthropicToolChoice, type AnthropicToolDefinition, type AnthropicUsage, type ChatCompletionRequest, type ChatCompletionResult, type ChatMessage, type ChatMessageCacheControl, ChatMessageCacheControlSchema, type ChatMessageRole, ChatMessageRoleSchema, ChatMessageSchema, type ChatStopReason, ChatStopReasonSchema, type ChatStreamEvent, type GeminiAdapterOptions, type MessageContentBlock, MessageContentBlockSchema, type MockModelOptions, type ModelAdapter, type ModelPricingUsdPerMillionTokens, type ModelToolCall, ModelToolCallSchema, type ModelToolChoice, type ModelToolDefinition, type OpenAiAdapterOptions, type OpenAiCallInput, type OpenAiContentPart, type OpenAiRequestBody, type OpenAiRequestMessage, type OpenAiRequestToolCall, type OpenAiToolChoice, type OpenAiToolDefinition, type ProviderExtraBody, type ProviderRetryOptions, type ResolveProviderApiKeyInput, type StructuredOutputRequest, type StructuredOutputResult, anthropic, anthropicBatchJsonOnlySystemInstruction, anthropicBatchTraceWorkflowName, applyCacheControlToLastContentBlock, buildAnthropicCacheControl, buildAnthropicRequestBody, buildOpenAiRequestBody, buildProviderCanceledError, calculateProviderRetryDelayMs, createAnthropicBatchClient, defaultAnthropicBaseUrl, defaultAnthropicBatchPollIntervalMs, defaultAnthropicBatchTimeoutMs, defaultAnthropicMaxOutputTokens, defaultGeminiBaseUrl, defaultOpenAiBaseUrl, defaultProviderRetryInitialDelayMs, defaultProviderRetryMaxAttempts, defaultProviderRetryMaxDelayMs, estimateModelCallCostUsd, executeAbortableProviderFetch, executeProviderCallWithModelFallback, executeProviderCallWithRetry, extractAnthropicTextContent, extractAnthropicToolCalls, extractMessageText, gemini, isAbortError, isRetryableProviderAppError, joinSystemMessageText, mapAnthropicResponseToChatCompletionResult, mapAnthropicUsageToTokenUsage, mapChatMessageToAnthropicRequestMessage, mapChatMessageToOpenAiRequestMessage, mapModelToolChoiceToAnthropicToolChoice, mapModelToolChoiceToOpenAiToolChoice, mapModelToolDefinitionToOpenAiTool, mapModelToolDefinitionsToAnthropicTools, mergeProviderRequestExtraBody, mockModel, normalizeAnthropicStopReason, openai, parseAnthropicBatchStructuredContent, parseAnthropicStreamEvents, parseAnthropicToolInputJson, resolveAnthropicPromptCachingSettings, resolveProviderApiKey, streamAnthropicChatCompletion };
687
+ declare const defaultAzureOpenAiApiVersion = "2024-10-21";
688
+ type AzureOpenAiAdapterOptions = {
689
+ deployment: string;
690
+ resourceName?: string;
691
+ baseURL?: string;
692
+ apiVersion?: string;
693
+ apiKey?: string;
694
+ apiKeyName?: string;
695
+ fetchImplementation?: typeof fetch;
696
+ temperature?: number;
697
+ maxOutputTokens?: number;
698
+ retry?: ProviderRetryOptions;
699
+ extraBody?: Record<string, JsonValue>;
700
+ };
701
+ type AzureOpenAiChatRequestBody = Omit<OpenAiRequestBody, "model">;
702
+ declare function azureOpenai(options: AzureOpenAiAdapterOptions): ModelAdapter;
703
+ declare function buildAzureOpenAiChatCompletionsUrl(options: AzureOpenAiAdapterOptions): string;
704
+ declare function buildAzureOpenAiChatRequestBody(input: OpenAiCallInput): AzureOpenAiChatRequestBody;
705
+
706
+ declare const AzureOpenAiUsageSchema: z.ZodObject<{
707
+ prompt_tokens: z.ZodNumber;
708
+ completion_tokens: z.ZodNumber;
709
+ total_tokens: z.ZodNumber;
710
+ }, z.core.$strip>;
711
+ type AzureOpenAiUsage = z.infer<typeof AzureOpenAiUsageSchema>;
712
+ declare const AzureOpenAiChatCompletionResponseSchema: z.ZodObject<{
713
+ choices: z.ZodArray<z.ZodObject<{
714
+ message: z.ZodObject<{
715
+ content: z.ZodNullable<z.ZodString>;
716
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
717
+ id: z.ZodString;
718
+ function: z.ZodObject<{
719
+ name: z.ZodString;
720
+ arguments: z.ZodString;
721
+ }, z.core.$strip>;
722
+ }, z.core.$strip>>>;
723
+ }, z.core.$strip>;
724
+ finish_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
725
+ }, z.core.$strip>>;
726
+ usage: z.ZodObject<{
727
+ prompt_tokens: z.ZodNumber;
728
+ completion_tokens: z.ZodNumber;
729
+ total_tokens: z.ZodNumber;
730
+ }, z.core.$strip>;
731
+ }, z.core.$strip>;
732
+ type AzureOpenAiChatCompletionResponse = z.infer<typeof AzureOpenAiChatCompletionResponseSchema>;
733
+ declare function mapAzureOpenAiResponseToChatCompletionResult(response: AzureOpenAiChatCompletionResponse, latencyMs: number): ChatCompletionResult;
734
+ declare function parseAzureOpenAiToolArgumentsJson(argumentsJsonText: string): JsonValue;
735
+ declare function normalizeAzureOpenAiFinishReason(finishReason: string): ChatStopReason;
736
+ declare function mapAzureOpenAiUsageToTokenUsage(usage: AzureOpenAiUsage): TokenUsage;
737
+
738
+ type AzureOpenAiStreamRequestBody = Omit<OpenAiRequestBody, "model"> & {
739
+ stream: true;
740
+ stream_options: {
741
+ include_usage: boolean;
742
+ };
743
+ };
744
+ type AzureOpenAiStreamRequestInput = {
745
+ url: string;
746
+ headers: Record<string, string>;
747
+ body: AzureOpenAiStreamRequestBody;
748
+ fetchImplementation: typeof fetch;
749
+ retry?: ProviderRetryOptions;
750
+ abortSignal?: AbortSignal;
751
+ };
752
+ declare function streamAzureOpenAiChatCompletion(input: AzureOpenAiStreamRequestInput): AsyncGenerator<ChatStreamEvent, void, void>;
753
+ declare function parseAzureOpenAiStreamEvents(body: ReadableStream<Uint8Array>, startedAt: number, abortSignal: AbortSignal | undefined): AsyncGenerator<ChatStreamEvent, void, void>;
754
+
755
+ declare const awsSigV4Algorithm = "AWS4-HMAC-SHA256";
756
+ type AwsCredentials = {
757
+ accessKeyId: string;
758
+ secretAccessKey: string;
759
+ sessionToken?: string;
760
+ };
761
+ type AwsSigV4SigningInput = {
762
+ method: string;
763
+ url: URL;
764
+ headers: Record<string, string>;
765
+ bodyText: string;
766
+ region: string;
767
+ service: string;
768
+ credentials: AwsCredentials;
769
+ signingDate?: Date;
770
+ };
771
+ declare function signAwsRequestWithSigV4(input: AwsSigV4SigningInput): Promise<Record<string, string>>;
772
+
773
+ declare const bedrockAnthropicVersion = "bedrock-2023-05-31";
774
+ declare const defaultBedrockMaxOutputTokens = 1024;
775
+ type BedrockCredentials = AwsCredentials;
776
+ type BedrockAdapterOptions = {
777
+ region: string;
778
+ modelId: string;
779
+ credentials?: BedrockCredentials;
780
+ fetchImplementation?: typeof fetch;
781
+ temperature?: number;
782
+ maxOutputTokens?: number;
783
+ retry?: ProviderRetryOptions;
784
+ extraBody?: Record<string, JsonValue>;
785
+ };
786
+ type BedrockInvokeModelRequestBody = Omit<AnthropicRequestBody, "model" | "stream"> & {
787
+ anthropic_version: string;
788
+ };
789
+ declare function bedrock(options: BedrockAdapterOptions): ModelAdapter;
790
+ declare function buildBedrockInvokeModelUrl(region: string, modelId: string): string;
791
+ declare function resolveBedrockCredentials(options: BedrockAdapterOptions): BedrockCredentials;
792
+ declare function buildBedrockInvokeModelRequestBody(input: AnthropicRequestInput): BedrockInvokeModelRequestBody;
793
+
794
+ export { type AnthropicAdapterOptions, type AnthropicBatchApiRequest, type AnthropicBatchApiRequestMessage, type AnthropicBatchApiRequestParams, type AnthropicBatchCanceledOutcome, type AnthropicBatchClient, type AnthropicBatchClientOptions, type AnthropicBatchErroredOutcome, type AnthropicBatchExpiredOutcome, type AnthropicBatchMessageRequest, type AnthropicBatchPromptCachingMode, type AnthropicBatchResult, type AnthropicBatchResultOutcome, type AnthropicBatchSubmittedRequestSummary, type AnthropicBatchSucceededOutcome, type AnthropicBatchSystemContentBlock, type AnthropicBatchTraceEventHandler, type AnthropicBatchWaitOptions, type AnthropicCacheControl, type AnthropicCacheTtl, type AnthropicMessageBatch, type AnthropicMessageBatchProcessingStatus, type AnthropicMessageBatchRequestCounts, type AnthropicMessagesResponse, AnthropicMessagesResponseSchema, type AnthropicOutputConfig, type AnthropicPromptCachingMode, type AnthropicPromptCachingOptions, type AnthropicPromptCachingSettings, type AnthropicRequestBody, type AnthropicRequestContentBlock, type AnthropicRequestInput, type AnthropicRequestMessage, type AnthropicRequestSettings, type AnthropicStreamEvent, AnthropicStreamEventSchema, type AnthropicStreamRequestInput, type AnthropicStreamStartUsage, type AnthropicSystemContentBlock, type AnthropicThinkingOptions, type AnthropicToolChoice, type AnthropicToolDefinition, type AnthropicUsage, type AwsCredentials, type AwsSigV4SigningInput, type AzureOpenAiAdapterOptions, type AzureOpenAiChatCompletionResponse, AzureOpenAiChatCompletionResponseSchema, type AzureOpenAiChatRequestBody, type AzureOpenAiStreamRequestBody, type AzureOpenAiStreamRequestInput, type AzureOpenAiUsage, type BedrockAdapterOptions, type BedrockCredentials, type BedrockInvokeModelRequestBody, type ChatCompletionRequest, type ChatCompletionResult, type ChatMessage, type ChatMessageCacheControl, ChatMessageCacheControlSchema, type ChatMessageRole, ChatMessageRoleSchema, ChatMessageSchema, type ChatStopReason, ChatStopReasonSchema, type ChatStreamEvent, type GeminiAdapterOptions, type MessageContentBlock, MessageContentBlockSchema, type MockModelOptions, type ModelAdapter, type ModelPricingUsdPerMillionTokens, type ModelToolCall, ModelToolCallSchema, type ModelToolChoice, type ModelToolDefinition, type OpenAiAdapterOptions, type OpenAiCallInput, type OpenAiContentPart, type OpenAiRequestBody, type OpenAiRequestMessage, type OpenAiRequestToolCall, type OpenAiResponseFormat, type OpenAiToolChoice, type OpenAiToolDefinition, type ProviderExtraBody, type ProviderRetryOptions, type ResolveProviderApiKeyInput, type StructuredOutputRequest, type StructuredOutputResult, anthropic, anthropicBatchJsonOnlySystemInstruction, anthropicBatchTraceWorkflowName, applyCacheControlToLastContentBlock, awsSigV4Algorithm, azureOpenai, bedrock, bedrockAnthropicVersion, buildAnthropicCacheControl, buildAnthropicRequestBody, buildAnthropicStructuredOutputJsonSchema, buildAzureOpenAiChatCompletionsUrl, buildAzureOpenAiChatRequestBody, buildBedrockInvokeModelRequestBody, buildBedrockInvokeModelUrl, buildGeminiResponseSchema, buildOpenAiRequestBody, buildOpenAiStructuredOutputJsonSchema, buildProviderCanceledError, calculateProviderRetryDelayMs, convertZodSchemaToJsonSchema, createAnthropicBatchClient, defaultAnthropicBaseUrl, defaultAnthropicBatchPollIntervalMs, defaultAnthropicBatchTimeoutMs, defaultAnthropicMaxOutputTokens, defaultAzureOpenAiApiVersion, defaultBedrockMaxOutputTokens, defaultGeminiBaseUrl, defaultOpenAiBaseUrl, defaultProviderRetryInitialDelayMs, defaultProviderRetryMaxAttempts, defaultProviderRetryMaxDelayMs, estimateModelCallCostUsd, executeAbortableProviderFetch, executeProviderCallWithModelFallback, executeProviderCallWithRetry, extractAnthropicTextContent, extractAnthropicThinkingText, extractAnthropicToolCalls, extractMessageText, gemini, isAbortError, isRetryableProviderAppError, joinSystemMessageText, mapAnthropicResponseToChatCompletionResult, mapAnthropicUsageToTokenUsage, mapAzureOpenAiResponseToChatCompletionResult, mapAzureOpenAiUsageToTokenUsage, mapChatMessageToAnthropicRequestMessage, mapChatMessageToOpenAiRequestMessage, mapModelToolChoiceToAnthropicToolChoice, mapModelToolChoiceToOpenAiToolChoice, mapModelToolDefinitionToOpenAiTool, mapModelToolDefinitionsToAnthropicTools, mergeProviderRequestExtraBody, mockModel, normalizeAnthropicStopReason, normalizeAzureOpenAiFinishReason, openAiStructuredOutputSchemaName, openai, parseAnthropicBatchStructuredContent, parseAnthropicStreamEvents, parseAnthropicToolInputJson, parseAzureOpenAiStreamEvents, parseAzureOpenAiToolArgumentsJson, resolveAnthropicPromptCachingSettings, resolveBedrockCredentials, resolveProviderApiKey, sanitizeJsonSchemaForAnthropicStructuredOutput, sanitizeJsonSchemaForGeminiResponseSchema, sanitizeJsonSchemaForOpenAiStructuredOutput, signAwsRequestWithSigV4, streamAnthropicChatCompletion, streamAzureOpenAiChatCompletion };