@jaypie/llm 1.2.35 → 1.2.37

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.
@@ -0,0 +1,78 @@
1
+ import type { ConverseCommandInput, ConverseCommandOutput, DocumentFormat } from "@aws-sdk/client-bedrock-runtime";
2
+ import { JsonObject, NaturalSchema } from "@jaypie/types";
3
+ import { z } from "zod/v4";
4
+ import { Toolkit } from "../../tools/Toolkit.class.js";
5
+ import { LlmHistory, LlmOperateOptions, LlmUsageItem } from "../../types/LlmProvider.interface.js";
6
+ import { LlmStreamChunk } from "../../types/LlmStreamChunk.interface.js";
7
+ import { ClassifiedError, OperateRequest, ParsedResponse, ProviderToolDefinition, StandardToolCall, StandardToolResult } from "../types.js";
8
+ import { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
9
+ type BedrockContentBlock = {
10
+ text: string;
11
+ } | {
12
+ toolUse: {
13
+ toolUseId: string;
14
+ name: string;
15
+ input: JsonObject;
16
+ };
17
+ } | {
18
+ toolResult: {
19
+ toolUseId: string;
20
+ content: Array<{
21
+ text: string;
22
+ }>;
23
+ };
24
+ } | {
25
+ image: {
26
+ format: string;
27
+ source: {
28
+ bytes: Uint8Array;
29
+ };
30
+ };
31
+ } | {
32
+ document: {
33
+ format: DocumentFormat;
34
+ name: string;
35
+ source: {
36
+ bytes: Uint8Array;
37
+ };
38
+ };
39
+ };
40
+ type BedrockMessage = {
41
+ role: "user" | "assistant";
42
+ content: BedrockContentBlock[];
43
+ };
44
+ type BedrockRequest = Omit<ConverseCommandInput, "messages"> & {
45
+ messages: BedrockMessage[];
46
+ };
47
+ type AnnotatedBedrockResponse = ConverseCommandOutput & {
48
+ __jaypieStructuredOutput?: boolean;
49
+ };
50
+ export declare class BedrockAdapter extends BaseProviderAdapter {
51
+ readonly name: "bedrock";
52
+ readonly defaultModel: "amazon.nova-lite-v1:0";
53
+ private _modelsFallbackToStructuredOutputTool;
54
+ private _modelsWithoutTemperature;
55
+ private rememberModelRejectsOutputConfig;
56
+ private useFakeToolForStructuredOutput;
57
+ private rememberModelRejectsTemperature;
58
+ private supportsTemperature;
59
+ buildRequest(request: OperateRequest): BedrockRequest;
60
+ formatTools(toolkit: Toolkit): ProviderToolDefinition[];
61
+ formatOutputSchema(schema: JsonObject | NaturalSchema | z.ZodType): JsonObject;
62
+ executeRequest(client: unknown, request: unknown, signal?: AbortSignal): Promise<AnnotatedBedrockResponse>;
63
+ private toFallbackStructuredOutputRequest;
64
+ executeStreamRequest(client: unknown, request: unknown, signal?: AbortSignal): AsyncIterable<LlmStreamChunk>;
65
+ parseResponse(response: unknown, options?: LlmOperateOptions): ParsedResponse;
66
+ extractToolCalls(response: unknown): StandardToolCall[];
67
+ extractUsage(response: unknown, model: string): LlmUsageItem;
68
+ formatToolResult(toolCall: StandardToolCall, result: StandardToolResult): BedrockContentBlock;
69
+ appendToolResult(request: unknown, toolCall: StandardToolCall, result: StandardToolResult): BedrockRequest;
70
+ responseToHistoryItems(response: unknown): LlmHistory;
71
+ classifyError(error: unknown): ClassifiedError;
72
+ hasStructuredOutput(response: unknown): boolean;
73
+ extractStructuredOutput(response: unknown): JsonObject | undefined;
74
+ isComplete(response: unknown): boolean;
75
+ private extractContentFromMessage;
76
+ }
77
+ export declare const bedrockAdapter: BedrockAdapter;
78
+ export {};
@@ -8,7 +8,7 @@ import { OpenAiAdapter } from "./OpenAiAdapter.js";
8
8
  */
9
9
  export declare class XaiAdapter extends OpenAiAdapter {
10
10
  readonly name: "xai";
11
- readonly defaultModel: "grok-4.20-0309-reasoning";
11
+ readonly defaultModel: "grok-latest";
12
12
  classifyError(error: unknown): ClassifiedError;
13
13
  }
14
14
  export declare const xaiAdapter: XaiAdapter;
@@ -1,6 +1,7 @@
1
1
  export { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
2
2
  export type { ProviderAdapter } from "./ProviderAdapter.interface.js";
3
3
  export { AnthropicAdapter, anthropicAdapter } from "./AnthropicAdapter.js";
4
+ export { BedrockAdapter, bedrockAdapter } from "./BedrockAdapter.js";
4
5
  export { GeminiAdapter, geminiAdapter } from "./GeminiAdapter.js";
5
6
  export { OpenAiAdapter, openAiAdapter } from "./OpenAiAdapter.js";
6
7
  export { OpenRouterAdapter, openRouterAdapter } from "./OpenRouterAdapter.js";
@@ -1,4 +1,4 @@
1
- export { AnthropicAdapter, anthropicAdapter, BaseProviderAdapter, GeminiAdapter, geminiAdapter, OpenAiAdapter, openAiAdapter, OpenRouterAdapter, openRouterAdapter, XaiAdapter, xaiAdapter, } from "./adapters/index.js";
1
+ export { AnthropicAdapter, anthropicAdapter, BaseProviderAdapter, BedrockAdapter, bedrockAdapter, GeminiAdapter, geminiAdapter, OpenAiAdapter, openAiAdapter, OpenRouterAdapter, openRouterAdapter, XaiAdapter, xaiAdapter, } from "./adapters/index.js";
2
2
  export type { ProviderAdapter } from "./adapters/index.js";
3
3
  export { createOperateLoop, OperateLoop } from "./OperateLoop.js";
4
4
  export type { OperateLoopConfig } from "./OperateLoop.js";
@@ -0,0 +1,21 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ import { LlmHistory, LlmInputMessage, LlmMessageOptions, LlmOperateOptions, LlmOperateResponse, LlmProvider } from "../../types/LlmProvider.interface.js";
3
+ import { LlmStreamChunk } from "../../types/LlmStreamChunk.interface.js";
4
+ export declare class BedrockProvider implements LlmProvider {
5
+ private model;
6
+ private region?;
7
+ private _client?;
8
+ private _operateLoop?;
9
+ private _streamLoop?;
10
+ private log;
11
+ private conversationHistory;
12
+ constructor(model?: string, { region }?: {
13
+ region?: string;
14
+ });
15
+ private getClient;
16
+ private getOperateLoop;
17
+ private getStreamLoop;
18
+ send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
19
+ operate(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
20
+ stream(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
21
+ }
@@ -0,0 +1 @@
1
+ export { BedrockProvider } from "./BedrockProvider.class.js";
@@ -0,0 +1,6 @@
1
+ import type { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
2
+ export declare function loadSdk(): Promise<typeof import("@aws-sdk/client-bedrock-runtime")>;
3
+ export declare const getLogger: () => import("@jaypie/logger/dist/esm/JaypieLogger").default;
4
+ export declare function initializeClient({ region, }?: {
5
+ region?: string;
6
+ }): Promise<BedrockRuntimeClient>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/llm",
3
- "version": "1.2.35",
3
+ "version": "1.2.37",
4
4
  "description": "Large language model utilities",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,6 +29,7 @@
29
29
  "lint": "eslint .",
30
30
  "test": "vitest run .",
31
31
  "test:matrix": "tsx test/matrix.ts",
32
+ "test:matrix:bedrock": "APP_MODELS=\"us.anthropic.claude-opus-4-7,us.anthropic.claude-sonnet-4-6,us.anthropic.claude-haiku-4-5-20251001-v1:0,amazon.nova-pro-v1:0,us.amazon.nova-2-lite-v1:0,amazon.nova-micro-v1:0,deepseek.v3.2,google.gemma-3-27b-it,moonshotai.kimi-k2.5,openai.gpt-oss-120b-1:0\" tsx test/matrix.ts",
32
33
  "test:watch": "vitest",
33
34
  "typecheck": "tsc --noEmit"
34
35
  },
@@ -44,12 +45,14 @@
44
45
  },
45
46
  "devDependencies": {
46
47
  "@anthropic-ai/sdk": "^0.71.0",
48
+ "@aws-sdk/client-bedrock-runtime": "^3.1045.0",
47
49
  "@google/genai": "^1.30.0",
48
50
  "@jaypie/types": "*",
49
51
  "@openrouter/sdk": "^0.1.27"
50
52
  },
51
53
  "peerDependencies": {
52
54
  "@anthropic-ai/sdk": "^0.71.0",
55
+ "@aws-sdk/client-bedrock-runtime": "^3.1045.0",
53
56
  "@google/genai": "^1.30.0",
54
57
  "@jaypie/kit": "*",
55
58
  "@jaypie/logger": "*",
@@ -59,6 +62,9 @@
59
62
  "@anthropic-ai/sdk": {
60
63
  "optional": true
61
64
  },
65
+ "@aws-sdk/client-bedrock-runtime": {
66
+ "optional": true
67
+ },
62
68
  "@google/genai": {
63
69
  "optional": true
64
70
  },