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