@jaypie/llm 1.2.6 → 1.2.8

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.
@@ -1,19 +1,28 @@
1
1
  export declare const PROVIDER: {
2
- readonly OPENROUTER: {
2
+ readonly ANTHROPIC: {
3
+ readonly MAX_TOKENS: {
4
+ readonly DEFAULT: 4096;
5
+ };
3
6
  readonly MODEL: {
4
- readonly DEFAULT: "z-ai/glm-4.7";
5
- readonly SMALL: "z-ai/glm-4.7";
6
- readonly LARGE: "z-ai/glm-4.7";
7
- readonly TINY: "z-ai/glm-4.7";
7
+ readonly DEFAULT: "claude-sonnet-4-5";
8
+ readonly LARGE: "claude-opus-4-5";
9
+ readonly SMALL: "claude-sonnet-4-5";
10
+ readonly TINY: "claude-haiku-4-5";
11
+ };
12
+ readonly MODEL_MATCH_WORDS: readonly ["anthropic", "claude", "haiku", "opus", "sonnet"];
13
+ readonly NAME: "anthropic";
14
+ readonly PROMPT: {
15
+ readonly AI: "\n\nAssistant:";
16
+ readonly HUMAN: "\n\nHuman:";
8
17
  };
9
- readonly MODEL_MATCH_WORDS: readonly ["openrouter"];
10
- readonly NAME: "openrouter";
11
18
  readonly ROLE: {
12
19
  readonly ASSISTANT: "assistant";
13
20
  readonly SYSTEM: "system";
14
- readonly TOOL: "tool";
15
21
  readonly USER: "user";
16
22
  };
23
+ readonly TOOLS: {
24
+ readonly SCHEMA_VERSION: "v2";
25
+ };
17
26
  };
18
27
  readonly GEMINI: {
19
28
  readonly MODEL: {
@@ -29,65 +38,56 @@ export declare const PROVIDER: {
29
38
  readonly USER: "user";
30
39
  };
31
40
  };
32
- readonly ANTHROPIC: {
41
+ readonly OPENAI: {
33
42
  readonly MODEL: {
34
- readonly DEFAULT: "claude-sonnet-4-5";
35
- readonly LARGE: "claude-opus-4-5";
36
- readonly SMALL: "claude-sonnet-4-5";
37
- readonly TINY: "claude-haiku-4-5";
43
+ readonly DEFAULT: "gpt-5.2";
44
+ readonly LARGE: "gpt-5.2-pro";
45
+ readonly SMALL: "gpt-5-mini";
46
+ readonly TINY: "gpt-5-nano";
38
47
  };
39
- readonly MODEL_MATCH_WORDS: readonly ["anthropic", "claude", "haiku", "opus", "sonnet"];
40
- readonly NAME: "anthropic";
41
- readonly PROMPT: {
42
- readonly AI: "\n\nAssistant:";
43
- readonly HUMAN: "\n\nHuman:";
48
+ readonly MODEL_MATCH_WORDS: readonly ["openai", "gpt", RegExp];
49
+ readonly NAME: "openai";
50
+ };
51
+ readonly OPENROUTER: {
52
+ readonly MODEL: {
53
+ readonly DEFAULT: "z-ai/glm-4.7";
54
+ readonly LARGE: "z-ai/glm-4.7";
55
+ readonly SMALL: "z-ai/glm-4.7";
56
+ readonly TINY: "z-ai/glm-4.7";
44
57
  };
58
+ readonly MODEL_MATCH_WORDS: readonly ["openrouter"];
59
+ readonly NAME: "openrouter";
45
60
  readonly ROLE: {
46
61
  readonly ASSISTANT: "assistant";
47
62
  readonly SYSTEM: "system";
63
+ readonly TOOL: "tool";
48
64
  readonly USER: "user";
49
65
  };
50
- readonly MAX_TOKENS: {
51
- readonly DEFAULT: 4096;
52
- };
53
- readonly TOOLS: {
54
- readonly SCHEMA_VERSION: "v2";
55
- };
56
- };
57
- readonly OPENAI: {
58
- readonly MODEL: {
59
- readonly DEFAULT: "gpt-5.1";
60
- readonly LARGE: "gpt-5.1";
61
- readonly SMALL: "gpt-5.1-mini";
62
- readonly TINY: "gpt-5.1-nano";
63
- };
64
- readonly MODEL_MATCH_WORDS: readonly ["openai", "gpt", RegExp];
65
- readonly NAME: "openai";
66
66
  };
67
67
  };
68
68
  export type LlmProviderName = typeof PROVIDER.ANTHROPIC.NAME | typeof PROVIDER.GEMINI.NAME | typeof PROVIDER.OPENAI.NAME | typeof PROVIDER.OPENROUTER.NAME;
69
69
  export declare const DEFAULT: {
70
70
  readonly MODEL: {
71
- readonly BASE: "gpt-5.1";
72
- readonly LARGE: "gpt-5.1";
73
- readonly SMALL: "gpt-5.1-mini";
74
- readonly TINY: "gpt-5.1-nano";
71
+ readonly BASE: "gpt-5.2";
72
+ readonly LARGE: "gpt-5.2-pro";
73
+ readonly SMALL: "gpt-5-mini";
74
+ readonly TINY: "gpt-5-nano";
75
75
  };
76
76
  readonly PROVIDER: {
77
77
  readonly MODEL: {
78
- readonly DEFAULT: "gpt-5.1";
79
- readonly LARGE: "gpt-5.1";
80
- readonly SMALL: "gpt-5.1-mini";
81
- readonly TINY: "gpt-5.1-nano";
78
+ readonly DEFAULT: "gpt-5.2";
79
+ readonly LARGE: "gpt-5.2-pro";
80
+ readonly SMALL: "gpt-5-mini";
81
+ readonly TINY: "gpt-5-nano";
82
82
  };
83
83
  readonly MODEL_MATCH_WORDS: readonly ["openai", "gpt", RegExp];
84
84
  readonly NAME: "openai";
85
85
  };
86
86
  };
87
87
  export declare const ALL: {
88
- readonly BASE: readonly ["claude-sonnet-4-5", "gemini-3-pro-preview", "gpt-5.1"];
89
- readonly COMBINED: readonly ["claude-sonnet-4-5", "claude-opus-4-5", "claude-sonnet-4-5", "claude-haiku-4-5", "gemini-3-pro-preview", "gemini-3-pro-preview", "gemini-3-flash-preview", "gemini-3-flash-preview", "gpt-5.1", "gpt-5.1", "gpt-5.1-mini", "gpt-5.1-nano"];
90
- readonly LARGE: readonly ["claude-opus-4-5", "gemini-3-pro-preview", "gpt-5.1"];
91
- readonly SMALL: readonly ["claude-sonnet-4-5", "gemini-3-flash-preview", "gpt-5.1-mini"];
92
- readonly TINY: readonly ["claude-haiku-4-5", "gemini-3-flash-preview", "gpt-5.1-nano"];
88
+ readonly BASE: readonly ["claude-sonnet-4-5", "gemini-3-pro-preview", "gpt-5.2"];
89
+ readonly COMBINED: readonly ["claude-sonnet-4-5", "claude-opus-4-5", "claude-sonnet-4-5", "claude-haiku-4-5", "gemini-3-pro-preview", "gemini-3-pro-preview", "gemini-3-flash-preview", "gemini-3-flash-preview", "gpt-5.2", "gpt-5.2-pro", "gpt-5-mini", "gpt-5-nano"];
90
+ readonly LARGE: readonly ["claude-opus-4-5", "gemini-3-pro-preview", "gpt-5.2-pro"];
91
+ readonly SMALL: readonly ["claude-sonnet-4-5", "gemini-3-flash-preview", "gpt-5-mini"];
92
+ readonly TINY: readonly ["claude-haiku-4-5", "gemini-3-flash-preview", "gpt-5-nano"];
93
93
  };
@@ -13,49 +13,43 @@ var path = require('path');
13
13
  var aws = require('@jaypie/aws');
14
14
  var openmeteo = require('openmeteo');
15
15
 
16
- const PROVIDER = {
17
- OPENROUTER: {
18
- // https://openrouter.ai/models
19
- // OpenRouter provides access to hundreds of models from various providers
20
- // The model format is: provider/model-name (e.g., "openai/gpt-4", "anthropic/claude-3-opus")
21
- MODEL: {
22
- // Default uses env var OPENROUTER_MODEL if set, otherwise a reasonable default
23
- DEFAULT: "z-ai/glm-4.7",
24
- SMALL: "z-ai/glm-4.7",
25
- LARGE: "z-ai/glm-4.7",
26
- TINY: "z-ai/glm-4.7",
27
- },
28
- MODEL_MATCH_WORDS: ["openrouter"],
29
- NAME: "openrouter",
30
- ROLE: {
31
- ASSISTANT: "assistant",
32
- SYSTEM: "system",
33
- TOOL: "tool",
34
- USER: "user",
35
- },
16
+ const FIRST_CLASS_PROVIDER = {
17
+ ANTHROPIC: {
18
+ DEFAULT: "claude-sonnet-4-5",
19
+ LARGE: "claude-opus-4-5",
20
+ SMALL: "claude-sonnet-4-5",
21
+ TINY: "claude-haiku-4-5",
36
22
  },
37
23
  GEMINI: {
38
- // https://ai.google.dev/gemini-api/docs/models
39
- MODEL: {
40
- DEFAULT: "gemini-3-pro-preview",
41
- LARGE: "gemini-3-pro-preview",
42
- SMALL: "gemini-3-flash-preview",
43
- TINY: "gemini-3-flash-preview",
44
- },
45
- MODEL_MATCH_WORDS: ["gemini", "google"],
46
- NAME: "gemini",
47
- ROLE: {
48
- MODEL: "model",
49
- USER: "user",
50
- },
24
+ DEFAULT: "gemini-3-pro-preview",
25
+ LARGE: "gemini-3-pro-preview",
26
+ SMALL: "gemini-3-flash-preview",
27
+ TINY: "gemini-3-flash-preview",
28
+ },
29
+ OPENAI: {
30
+ DEFAULT: "gpt-5.2",
31
+ LARGE: "gpt-5.2-pro",
32
+ SMALL: "gpt-5-mini",
33
+ TINY: "gpt-5-nano",
51
34
  },
35
+ OPENROUTER: {
36
+ DEFAULT: "z-ai/glm-4.7",
37
+ LARGE: "z-ai/glm-4.7",
38
+ SMALL: "z-ai/glm-4.7",
39
+ TINY: "z-ai/glm-4.7",
40
+ },
41
+ };
42
+ const PROVIDER = {
52
43
  ANTHROPIC: {
53
44
  // https://docs.anthropic.com/en/docs/about-claude/models/overview
45
+ MAX_TOKENS: {
46
+ DEFAULT: 4096,
47
+ },
54
48
  MODEL: {
55
- DEFAULT: "claude-sonnet-4-5",
56
- LARGE: "claude-opus-4-5",
57
- SMALL: "claude-sonnet-4-5",
58
- TINY: "claude-haiku-4-5",
49
+ DEFAULT: FIRST_CLASS_PROVIDER.ANTHROPIC.DEFAULT,
50
+ LARGE: FIRST_CLASS_PROVIDER.ANTHROPIC.LARGE,
51
+ SMALL: FIRST_CLASS_PROVIDER.ANTHROPIC.SMALL,
52
+ TINY: FIRST_CLASS_PROVIDER.ANTHROPIC.TINY,
59
53
  },
60
54
  MODEL_MATCH_WORDS: [
61
55
  "anthropic",
@@ -74,24 +68,56 @@ const PROVIDER = {
74
68
  SYSTEM: "system",
75
69
  USER: "user",
76
70
  },
77
- MAX_TOKENS: {
78
- DEFAULT: 4096,
79
- },
80
71
  TOOLS: {
81
72
  SCHEMA_VERSION: "v2",
82
73
  },
83
74
  },
75
+ GEMINI: {
76
+ // https://ai.google.dev/gemini-api/docs/models
77
+ MODEL: {
78
+ DEFAULT: FIRST_CLASS_PROVIDER.GEMINI.DEFAULT,
79
+ LARGE: FIRST_CLASS_PROVIDER.GEMINI.LARGE,
80
+ SMALL: FIRST_CLASS_PROVIDER.GEMINI.SMALL,
81
+ TINY: FIRST_CLASS_PROVIDER.GEMINI.TINY,
82
+ },
83
+ MODEL_MATCH_WORDS: ["gemini", "google"],
84
+ NAME: "gemini",
85
+ ROLE: {
86
+ MODEL: "model",
87
+ USER: "user",
88
+ },
89
+ },
84
90
  OPENAI: {
85
91
  // https://platform.openai.com/docs/models
86
92
  MODEL: {
87
- DEFAULT: "gpt-5.1",
88
- LARGE: "gpt-5.1",
89
- SMALL: "gpt-5.1-mini",
90
- TINY: "gpt-5.1-nano",
93
+ DEFAULT: FIRST_CLASS_PROVIDER.OPENAI.DEFAULT,
94
+ LARGE: FIRST_CLASS_PROVIDER.OPENAI.LARGE,
95
+ SMALL: FIRST_CLASS_PROVIDER.OPENAI.SMALL,
96
+ TINY: FIRST_CLASS_PROVIDER.OPENAI.TINY,
91
97
  },
92
98
  MODEL_MATCH_WORDS: ["openai", "gpt", /^o\d/],
93
99
  NAME: "openai",
94
100
  },
101
+ OPENROUTER: {
102
+ // https://openrouter.ai/models
103
+ // OpenRouter provides access to hundreds of models from various providers
104
+ // The model format is: provider/model-name (e.g., "openai/gpt-4", "anthropic/claude-3-opus")
105
+ MODEL: {
106
+ // Default uses env var OPENROUTER_MODEL if set, otherwise a reasonable default
107
+ DEFAULT: FIRST_CLASS_PROVIDER.OPENROUTER.DEFAULT,
108
+ LARGE: FIRST_CLASS_PROVIDER.OPENROUTER.LARGE,
109
+ SMALL: FIRST_CLASS_PROVIDER.OPENROUTER.SMALL,
110
+ TINY: FIRST_CLASS_PROVIDER.OPENROUTER.TINY,
111
+ },
112
+ MODEL_MATCH_WORDS: ["openrouter"],
113
+ NAME: "openrouter",
114
+ ROLE: {
115
+ ASSISTANT: "assistant",
116
+ SYSTEM: "system",
117
+ TOOL: "tool",
118
+ USER: "user",
119
+ },
120
+ },
95
121
  };
96
122
  // Last: Defaults
97
123
  const DEFAULT = {
@@ -885,19 +911,51 @@ class AnthropicAdapter extends BaseProviderAdapter {
885
911
  //
886
912
  buildRequest(request) {
887
913
  // Convert messages to Anthropic format
888
- // Filter out system messages - Anthropic only accepts system as a top-level field
889
- const messages = request.messages
890
- .filter((msg) => {
891
- const role = msg.role;
892
- return role !== "system";
893
- })
894
- .map((msg) => {
914
+ // Handle different message types: regular messages, function calls, and function outputs
915
+ const messages = [];
916
+ for (const msg of request.messages) {
895
917
  const typedMsg = msg;
896
- return {
897
- role: typedMsg.role,
898
- content: convertContentToAnthropic(typedMsg.content),
899
- };
900
- });
918
+ // Skip system messages - Anthropic only accepts system as a top-level field
919
+ if (typedMsg.role === "system") {
920
+ continue;
921
+ }
922
+ // Handle FunctionCall messages - convert to assistant message with tool_use
923
+ if (typedMsg.type === exports.LlmMessageType.FunctionCall) {
924
+ messages.push({
925
+ role: "assistant",
926
+ content: [
927
+ {
928
+ type: "tool_use",
929
+ id: typedMsg.call_id || "",
930
+ name: typedMsg.name || "",
931
+ input: JSON.parse(typedMsg.arguments || "{}"),
932
+ },
933
+ ],
934
+ });
935
+ continue;
936
+ }
937
+ // Handle FunctionCallOutput messages - convert to user message with tool_result
938
+ if (typedMsg.type === exports.LlmMessageType.FunctionCallOutput) {
939
+ messages.push({
940
+ role: "user",
941
+ content: [
942
+ {
943
+ type: "tool_result",
944
+ tool_use_id: typedMsg.call_id || "",
945
+ content: typedMsg.output || "",
946
+ },
947
+ ],
948
+ });
949
+ continue;
950
+ }
951
+ // Handle regular messages with role and content
952
+ if (typedMsg.role && typedMsg.content !== undefined) {
953
+ messages.push({
954
+ role: typedMsg.role,
955
+ content: convertContentToAnthropic(typedMsg.content),
956
+ });
957
+ }
958
+ }
901
959
  // Append instructions to last message if provided
902
960
  if (request.instructions && messages.length > 0) {
903
961
  const lastMsg = messages[messages.length - 1];
@@ -2885,6 +2943,31 @@ class OpenRouterAdapter extends BaseProviderAdapter {
2885
2943
  });
2886
2944
  }
2887
2945
  }
2946
+ else if (message.type === exports.LlmMessageType.FunctionCall) {
2947
+ // Handle FunctionCall messages from StreamLoop (issue #165)
2948
+ openRouterMessages.push({
2949
+ role: "assistant",
2950
+ content: null,
2951
+ toolCalls: [
2952
+ {
2953
+ id: message.call_id,
2954
+ type: "function",
2955
+ function: {
2956
+ name: message.name,
2957
+ arguments: message.arguments || "{}",
2958
+ },
2959
+ },
2960
+ ],
2961
+ });
2962
+ }
2963
+ else if (message.type === exports.LlmMessageType.FunctionCallOutput) {
2964
+ // Handle FunctionCallOutput messages from StreamLoop (issue #165)
2965
+ openRouterMessages.push({
2966
+ role: "tool",
2967
+ toolCallId: message.call_id,
2968
+ content: message.output || "",
2969
+ });
2970
+ }
2888
2971
  }
2889
2972
  return openRouterMessages;
2890
2973
  }