@polka-codes/core 0.0.3 → 0.1.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/Agent/AgentBase.d.ts +49 -0
- package/dist/Agent/AgentBase.js +158 -0
- package/dist/Agent/AgentBase.js.map +1 -0
- package/dist/Agent/CoderAgent/__snapshots__/prompts.test.js.snap +432 -0
- package/dist/Agent/CoderAgent/index.d.ts +17 -0
- package/dist/Agent/CoderAgent/index.js +32 -0
- package/dist/Agent/CoderAgent/index.js.map +1 -0
- package/dist/Agent/CoderAgent/prompts.d.ts +20 -0
- package/dist/Agent/CoderAgent/prompts.js +163 -0
- package/dist/Agent/CoderAgent/prompts.js.map +1 -0
- package/dist/Agent/CoderAgent/prompts.test.d.ts +1 -0
- package/dist/Agent/CoderAgent/prompts.test.js +20 -0
- package/dist/Agent/CoderAgent/prompts.test.js.map +1 -0
- package/dist/Agent/index.d.ts +2 -0
- package/dist/Agent/index.js +3 -0
- package/dist/Agent/index.js.map +1 -0
- package/dist/Agent/parseAssistantMessage.d.ts +45 -0
- package/dist/Agent/parseAssistantMessage.js +103 -0
- package/dist/Agent/parseAssistantMessage.js.map +1 -0
- package/dist/Agent/parseAssistantMessage.test.d.ts +1 -0
- package/dist/Agent/parseAssistantMessage.test.js +172 -0
- package/dist/Agent/parseAssistantMessage.test.js.map +1 -0
- package/dist/Agent/prompts.d.ts +7 -0
- package/dist/Agent/prompts.js +93 -0
- package/dist/Agent/prompts.js.map +1 -0
- package/dist/AiService/AiServiceBase.d.ts +29 -0
- package/dist/AiService/AiServiceBase.js +3 -0
- package/dist/AiService/AiServiceBase.js.map +1 -0
- package/dist/AiService/AnthropicService.d.ts +11 -0
- package/dist/AiService/AnthropicService.js +185 -0
- package/dist/AiService/AnthropicService.js.map +1 -0
- package/dist/AiService/DeepSeekService.d.ts +11 -0
- package/dist/AiService/DeepSeekService.js +64 -0
- package/dist/AiService/DeepSeekService.js.map +1 -0
- package/dist/AiService/ModelInfo.d.ts +79 -0
- package/dist/AiService/ModelInfo.js +67 -0
- package/dist/AiService/ModelInfo.js.map +1 -0
- package/dist/AiService/OllamaService.d.ts +11 -0
- package/dist/AiService/OllamaService.js +47 -0
- package/dist/AiService/OllamaService.js.map +1 -0
- package/dist/AiService/index.d.ts +12 -0
- package/dist/AiService/index.js +20 -0
- package/dist/AiService/index.js.map +1 -0
- package/dist/AiService/utils.d.ts +4 -0
- package/dist/AiService/utils.js +187 -0
- package/dist/AiService/utils.js.map +1 -0
- package/dist/AiService/utils.test.d.ts +1 -0
- package/dist/AiService/utils.test.js +275 -0
- package/dist/AiService/utils.test.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +5 -0
- package/dist/logger.js +25 -0
- package/dist/logger.js.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/tools.d.ts +200 -0
- package/dist/tools/tools.js +329 -0
- package/dist/tools/tools.js.map +1 -0
- package/dist/tools/types.d.ts +49 -0
- package/dist/tools/types.js +9 -0
- package/dist/tools/types.js.map +1 -0
- package/package.json +9 -6
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AiServiceBase, AiServiceOptions, MessageParam } from './AiServiceBase';
|
|
2
|
+
import { AnthropicService } from './AnthropicService';
|
|
3
|
+
import { DeepSeekService } from './DeepSeekService';
|
|
4
|
+
import type { ModelInfo } from './ModelInfo';
|
|
5
|
+
import { OllamaService } from './OllamaService';
|
|
6
|
+
export declare enum AiServiceProvider {
|
|
7
|
+
Anthropic = "anthropic",
|
|
8
|
+
Ollama = "ollama",
|
|
9
|
+
DeepSeek = "deepseek"
|
|
10
|
+
}
|
|
11
|
+
export declare const createService: (provider: AiServiceProvider, options: AiServiceOptions) => AnthropicService | DeepSeekService | OllamaService;
|
|
12
|
+
export type { MessageParam, AiServiceOptions, AiServiceBase, ModelInfo };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AnthropicService } from './AnthropicService';
|
|
2
|
+
import { DeepSeekService } from './DeepSeekService';
|
|
3
|
+
import { OllamaService } from './OllamaService';
|
|
4
|
+
export var AiServiceProvider;
|
|
5
|
+
(function (AiServiceProvider) {
|
|
6
|
+
AiServiceProvider["Anthropic"] = "anthropic";
|
|
7
|
+
AiServiceProvider["Ollama"] = "ollama";
|
|
8
|
+
AiServiceProvider["DeepSeek"] = "deepseek";
|
|
9
|
+
})(AiServiceProvider || (AiServiceProvider = {}));
|
|
10
|
+
export const createService = (provider, options) => {
|
|
11
|
+
switch (provider) {
|
|
12
|
+
case AiServiceProvider.Anthropic:
|
|
13
|
+
return new AnthropicService(options);
|
|
14
|
+
case AiServiceProvider.Ollama:
|
|
15
|
+
return new OllamaService(options);
|
|
16
|
+
case AiServiceProvider.DeepSeek:
|
|
17
|
+
return new DeepSeekService(options);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/AiService/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,MAAM,CAAN,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,4CAAuB,CAAA;IACvB,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;AACvB,CAAC,EAJW,iBAAiB,KAAjB,iBAAiB,QAI5B;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAA2B,EAAE,OAAyB,EAAE,EAAE;IACtF,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,iBAAiB,CAAC,SAAS;YAC9B,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAA;QACtC,KAAK,iBAAiB,CAAC,MAAM;YAC3B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;QACnC,KAAK,iBAAiB,CAAC,QAAQ;YAC7B,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Anthropic } from '@anthropic-ai/sdk';
|
|
2
|
+
import type OpenAI from 'openai';
|
|
3
|
+
export declare function convertToOpenAiMessages(anthropicMessages: Anthropic.Messages.MessageParam[]): OpenAI.Chat.ChatCompletionMessageParam[];
|
|
4
|
+
export declare function convertToAnthropicMessage(completion: OpenAI.Chat.Completions.ChatCompletion): Anthropic.Messages.Message;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// source: https://github.com/cline/cline/blob/f6c19c29a64ca84e9360df7ab2c07d128dcebe64/src/api/transform/openai-format.ts
|
|
2
|
+
import { createServiceLogger } from '../logger';
|
|
3
|
+
const logger = createServiceLogger('utils');
|
|
4
|
+
export function convertToOpenAiMessages(anthropicMessages) {
|
|
5
|
+
const openAiMessages = [];
|
|
6
|
+
for (const anthropicMessage of anthropicMessages) {
|
|
7
|
+
if (typeof anthropicMessage.content === 'string') {
|
|
8
|
+
openAiMessages.push({
|
|
9
|
+
role: anthropicMessage.role,
|
|
10
|
+
content: anthropicMessage.content,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
// image_url.url is base64 encoded image data
|
|
15
|
+
// ensure it contains the content-type of the image: data:image/png;base64,
|
|
16
|
+
/*
|
|
17
|
+
{ role: "user", content: "" | { type: "text", text: string } | { type: "image_url", image_url: { url: string } } },
|
|
18
|
+
// content required unless tool_calls is present
|
|
19
|
+
{ role: "assistant", content?: "" | null, tool_calls?: [{ id: "", function: { name: "", arguments: "" }, type: "function" }] },
|
|
20
|
+
{ role: "tool", tool_call_id: "", content: ""}
|
|
21
|
+
*/
|
|
22
|
+
if (anthropicMessage.role === 'user') {
|
|
23
|
+
const { nonToolMessages, toolMessages } = anthropicMessage.content.reduce((acc, part) => {
|
|
24
|
+
if (part.type === 'tool_result') {
|
|
25
|
+
acc.toolMessages.push(part);
|
|
26
|
+
}
|
|
27
|
+
else if (part.type === 'text' || part.type === 'image') {
|
|
28
|
+
acc.nonToolMessages.push(part);
|
|
29
|
+
} // user cannot send tool_use messages
|
|
30
|
+
return acc;
|
|
31
|
+
}, { nonToolMessages: [], toolMessages: [] });
|
|
32
|
+
// Process tool result messages FIRST since they must follow the tool use messages
|
|
33
|
+
const toolResultImages = [];
|
|
34
|
+
for (const toolMessage of toolMessages) {
|
|
35
|
+
// The Anthropic SDK allows tool results to be a string or an array of text and image blocks, enabling rich and structured content. In contrast, the OpenAI SDK only supports tool results as a single string, so we map the Anthropic tool result parts into one concatenated string to maintain compatibility.
|
|
36
|
+
let content;
|
|
37
|
+
if (typeof toolMessage.content === 'string') {
|
|
38
|
+
content = toolMessage.content;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
content =
|
|
42
|
+
toolMessage.content
|
|
43
|
+
?.map((part) => {
|
|
44
|
+
if (part.type === 'image') {
|
|
45
|
+
toolResultImages.push(part);
|
|
46
|
+
return '(see following user message for image)';
|
|
47
|
+
}
|
|
48
|
+
return part.text;
|
|
49
|
+
})
|
|
50
|
+
.join('\n') ?? '';
|
|
51
|
+
}
|
|
52
|
+
openAiMessages.push({
|
|
53
|
+
role: 'tool',
|
|
54
|
+
tool_call_id: toolMessage.tool_use_id,
|
|
55
|
+
content: content,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// If tool results contain images, send as a separate user message
|
|
59
|
+
// I ran into an issue where if I gave feedback for one of many tool uses, the request would fail.
|
|
60
|
+
// "Messages following `tool_use` blocks must begin with a matching number of `tool_result` blocks."
|
|
61
|
+
// Therefore we need to send these images after the tool result messages
|
|
62
|
+
// NOTE: it's actually okay to have multiple user messages in a row, the model will treat them as a continuation of the same input (this way works better than combining them into one message, since the tool result specifically mentions (see following user message for image)
|
|
63
|
+
// UPDATE v2.0: we don't use tools anymore, but if we did it's important to note that the openrouter prompt caching mechanism requires one user message at a time, so we would need to add these images to the user content array instead.
|
|
64
|
+
// if (toolResultImages.length > 0) {
|
|
65
|
+
// openAiMessages.push({
|
|
66
|
+
// role: "user",
|
|
67
|
+
// content: toolResultImages.map((part) => ({
|
|
68
|
+
// type: "image_url",
|
|
69
|
+
// image_url: { url: `data:${part.source.media_type};base64,${part.source.data}` },
|
|
70
|
+
// })),
|
|
71
|
+
// })
|
|
72
|
+
// }
|
|
73
|
+
// Process non-tool messages
|
|
74
|
+
if (nonToolMessages.length > 0) {
|
|
75
|
+
openAiMessages.push({
|
|
76
|
+
role: 'user',
|
|
77
|
+
content: nonToolMessages.map((part) => {
|
|
78
|
+
if (part.type === 'image') {
|
|
79
|
+
return {
|
|
80
|
+
type: 'image_url',
|
|
81
|
+
image_url: {
|
|
82
|
+
url: `data:${part.source.media_type};base64,${part.source.data}`,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return { type: 'text', text: part.text };
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (anthropicMessage.role === 'assistant') {
|
|
92
|
+
const { nonToolMessages, toolMessages } = anthropicMessage.content.reduce((acc, part) => {
|
|
93
|
+
if (part.type === 'tool_use') {
|
|
94
|
+
acc.toolMessages.push(part);
|
|
95
|
+
}
|
|
96
|
+
else if (part.type === 'text' || part.type === 'image') {
|
|
97
|
+
acc.nonToolMessages.push(part);
|
|
98
|
+
} // assistant cannot send tool_result messages
|
|
99
|
+
return acc;
|
|
100
|
+
}, { nonToolMessages: [], toolMessages: [] });
|
|
101
|
+
// Process non-tool messages
|
|
102
|
+
let content;
|
|
103
|
+
if (nonToolMessages.length > 0) {
|
|
104
|
+
content = nonToolMessages
|
|
105
|
+
.map((part) => {
|
|
106
|
+
if (part.type === 'image') {
|
|
107
|
+
return ''; // impossible as the assistant cannot send images
|
|
108
|
+
}
|
|
109
|
+
return part.text;
|
|
110
|
+
})
|
|
111
|
+
.join('\n');
|
|
112
|
+
}
|
|
113
|
+
// Process tool use messages
|
|
114
|
+
const tool_calls = toolMessages.map((toolMessage) => ({
|
|
115
|
+
id: toolMessage.id,
|
|
116
|
+
type: 'function',
|
|
117
|
+
function: {
|
|
118
|
+
name: toolMessage.name,
|
|
119
|
+
// json string
|
|
120
|
+
arguments: JSON.stringify(toolMessage.input),
|
|
121
|
+
},
|
|
122
|
+
}));
|
|
123
|
+
openAiMessages.push({
|
|
124
|
+
role: 'assistant',
|
|
125
|
+
content,
|
|
126
|
+
// Cannot be an empty array. API expects an array with minimum length 1, and will respond with an error if it's empty
|
|
127
|
+
tool_calls: tool_calls.length > 0 ? tool_calls : undefined,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return openAiMessages;
|
|
133
|
+
}
|
|
134
|
+
// Convert OpenAI response to Anthropic format
|
|
135
|
+
export function convertToAnthropicMessage(completion) {
|
|
136
|
+
const openAiMessage = completion.choices[0].message;
|
|
137
|
+
const anthropicMessage = {
|
|
138
|
+
id: completion.id,
|
|
139
|
+
type: 'message',
|
|
140
|
+
role: openAiMessage.role, // always "assistant"
|
|
141
|
+
content: [
|
|
142
|
+
{
|
|
143
|
+
type: 'text',
|
|
144
|
+
text: openAiMessage.content || '',
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
model: completion.model,
|
|
148
|
+
stop_reason: (() => {
|
|
149
|
+
switch (completion.choices[0].finish_reason) {
|
|
150
|
+
case 'stop':
|
|
151
|
+
return 'end_turn';
|
|
152
|
+
case 'length':
|
|
153
|
+
return 'max_tokens';
|
|
154
|
+
case 'tool_calls':
|
|
155
|
+
return 'tool_use';
|
|
156
|
+
default:
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
})(),
|
|
160
|
+
stop_sequence: null, // which custom stop_sequence was generated, if any (not applicable if you don't use stop_sequence)
|
|
161
|
+
usage: {
|
|
162
|
+
input_tokens: completion.usage?.prompt_tokens || 0,
|
|
163
|
+
output_tokens: completion.usage?.completion_tokens || 0,
|
|
164
|
+
cache_creation_input_tokens: null,
|
|
165
|
+
cache_read_input_tokens: null,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
if (openAiMessage.tool_calls && openAiMessage.tool_calls.length > 0) {
|
|
169
|
+
anthropicMessage.content.push(...openAiMessage.tool_calls.map((toolCall) => {
|
|
170
|
+
let parsedInput = {};
|
|
171
|
+
try {
|
|
172
|
+
parsedInput = JSON.parse(toolCall.function.arguments || '{}');
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
logger.warn('Failed to parse tool arguments:', error);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
type: 'tool_use',
|
|
179
|
+
id: toolCall.id,
|
|
180
|
+
name: toolCall.function.name,
|
|
181
|
+
input: parsedInput,
|
|
182
|
+
};
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
return anthropicMessage;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/AiService/utils.ts"],"names":[],"mappings":"AAAA,0HAA0H;AAK1H,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAE/C,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAA;AAE3C,MAAM,UAAU,uBAAuB,CAAC,iBAAoD;IAC1F,MAAM,cAAc,GAA6C,EAAE,CAAA;IAEnE,KAAK,MAAM,gBAAgB,IAAI,iBAAiB,EAAE,CAAC;QACjD,IAAI,OAAO,gBAAgB,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACjD,cAAc,CAAC,IAAI,C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KACF,CAAA;IAED,IAAI,aAAa,CAAC,UAAU,IAAI,aAAa,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpE,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAC3B,GAAG,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAA0B,EAAE;YACnE,IAAI,WAAW,GAAG,EAAE,CAAA;YACpB,IAAI,CAAC;gBACH,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,IAAI,IAAI,CAAC,CAAA;YAC/D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,IAAI,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAA;YACvD,CAAC;YACD,OAAO;gBACL,IAAI,EAAE,UAAU;gBAChB,EAAE,EAAE,QAAQ,CAAC,EAAE;gBACf,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI;gBAC5B,KAAK,EAAE,WAAW;aACnB,CAAA;QACH,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IACD,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { convertToAnthropicMessage, convertToOpenAiMessages } from './utils';
|
|
3
|
+
describe('convertToOpenAiMessages', () => {
|
|
4
|
+
it('should convert simple text messages', () => {
|
|
5
|
+
const anthropicMessages = [
|
|
6
|
+
{ role: 'user', content: 'Hello' },
|
|
7
|
+
{ role: 'assistant', content: 'Hi there!' },
|
|
8
|
+
];
|
|
9
|
+
const result = convertToOpenAiMessages(anthropicMessages);
|
|
10
|
+
expect(result).toEqual([
|
|
11
|
+
{ role: 'user', content: 'Hello' },
|
|
12
|
+
{ role: 'assistant', content: 'Hi there!' },
|
|
13
|
+
]);
|
|
14
|
+
});
|
|
15
|
+
it('should handle user messages with images', () => {
|
|
16
|
+
const anthropicMessages = [
|
|
17
|
+
{
|
|
18
|
+
role: 'user',
|
|
19
|
+
content: [
|
|
20
|
+
{ type: 'text', text: 'Check this image:' },
|
|
21
|
+
{
|
|
22
|
+
type: 'image',
|
|
23
|
+
source: {
|
|
24
|
+
type: 'base64',
|
|
25
|
+
media_type: 'image/jpeg',
|
|
26
|
+
data: 'base64data',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
const result = convertToOpenAiMessages(anthropicMessages);
|
|
33
|
+
expect(result).toEqual([
|
|
34
|
+
{
|
|
35
|
+
role: 'user',
|
|
36
|
+
content: [
|
|
37
|
+
{ type: 'text', text: 'Check this image:' },
|
|
38
|
+
{
|
|
39
|
+
type: 'image_url',
|
|
40
|
+
image_url: {
|
|
41
|
+
url: 'data:image/jpeg;base64,base64data',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
it('should handle assistant messages with tool calls', () => {
|
|
49
|
+
const anthropicMessages = [
|
|
50
|
+
{
|
|
51
|
+
role: 'assistant',
|
|
52
|
+
content: [
|
|
53
|
+
{ type: 'text', text: 'Let me help you with that.' },
|
|
54
|
+
{
|
|
55
|
+
type: 'tool_use',
|
|
56
|
+
id: 'tool123',
|
|
57
|
+
name: 'search',
|
|
58
|
+
input: { query: 'test' },
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
const result = convertToOpenAiMessages(anthropicMessages);
|
|
64
|
+
expect(result).toEqual([
|
|
65
|
+
{
|
|
66
|
+
role: 'assistant',
|
|
67
|
+
content: 'Let me help you with that.',
|
|
68
|
+
tool_calls: [
|
|
69
|
+
{
|
|
70
|
+
id: 'tool123',
|
|
71
|
+
type: 'function',
|
|
72
|
+
function: {
|
|
73
|
+
name: 'search',
|
|
74
|
+
arguments: '{"query":"test"}',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
it('should handle tool results', () => {
|
|
82
|
+
const anthropicMessages = [
|
|
83
|
+
{
|
|
84
|
+
role: 'user',
|
|
85
|
+
content: [
|
|
86
|
+
{
|
|
87
|
+
type: 'tool_result',
|
|
88
|
+
tool_use_id: 'tool123',
|
|
89
|
+
content: 'Search results found',
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
const result = convertToOpenAiMessages(anthropicMessages);
|
|
95
|
+
expect(result).toEqual([
|
|
96
|
+
{
|
|
97
|
+
role: 'tool',
|
|
98
|
+
tool_call_id: 'tool123',
|
|
99
|
+
content: 'Search results found',
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('convertToAnthropicMessage', () => {
|
|
105
|
+
it('should convert simple text completion', () => {
|
|
106
|
+
const openAiCompletion = {
|
|
107
|
+
id: 'cmpl-123',
|
|
108
|
+
choices: [
|
|
109
|
+
{
|
|
110
|
+
message: {
|
|
111
|
+
role: 'assistant',
|
|
112
|
+
content: 'Hello there!',
|
|
113
|
+
refusal: null,
|
|
114
|
+
},
|
|
115
|
+
finish_reason: 'stop',
|
|
116
|
+
index: 0,
|
|
117
|
+
logprobs: null,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
created: 1234567890,
|
|
121
|
+
model: 'gpt-4',
|
|
122
|
+
object: 'chat.completion',
|
|
123
|
+
usage: {
|
|
124
|
+
prompt_tokens: 10,
|
|
125
|
+
completion_tokens: 20,
|
|
126
|
+
total_tokens: 30,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
const result = convertToAnthropicMessage(openAiCompletion);
|
|
130
|
+
expect(result).toEqual({
|
|
131
|
+
id: 'cmpl-123',
|
|
132
|
+
type: 'message',
|
|
133
|
+
role: 'assistant',
|
|
134
|
+
content: [
|
|
135
|
+
{
|
|
136
|
+
type: 'text',
|
|
137
|
+
text: 'Hello there!',
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
model: 'gpt-4',
|
|
141
|
+
stop_reason: 'end_turn',
|
|
142
|
+
stop_sequence: null,
|
|
143
|
+
usage: {
|
|
144
|
+
input_tokens: 10,
|
|
145
|
+
output_tokens: 20,
|
|
146
|
+
cache_creation_input_tokens: null,
|
|
147
|
+
cache_read_input_tokens: null,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
it('should handle tool calls in completion', () => {
|
|
152
|
+
const openAiCompletion = {
|
|
153
|
+
id: 'cmpl-123',
|
|
154
|
+
choices: [
|
|
155
|
+
{
|
|
156
|
+
message: {
|
|
157
|
+
role: 'assistant',
|
|
158
|
+
content: 'Let me search that for you.',
|
|
159
|
+
refusal: null,
|
|
160
|
+
tool_calls: [
|
|
161
|
+
{
|
|
162
|
+
id: 'call_123',
|
|
163
|
+
type: 'function',
|
|
164
|
+
function: {
|
|
165
|
+
name: 'search',
|
|
166
|
+
arguments: '{"query":"test"}',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
finish_reason: 'tool_calls',
|
|
172
|
+
index: 0,
|
|
173
|
+
logprobs: null,
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
created: 1234567890,
|
|
177
|
+
model: 'gpt-4',
|
|
178
|
+
object: 'chat.completion',
|
|
179
|
+
usage: {
|
|
180
|
+
prompt_tokens: 10,
|
|
181
|
+
completion_tokens: 20,
|
|
182
|
+
total_tokens: 30,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
const result = convertToAnthropicMessage(openAiCompletion);
|
|
186
|
+
expect(result).toEqual({
|
|
187
|
+
id: 'cmpl-123',
|
|
188
|
+
type: 'message',
|
|
189
|
+
role: 'assistant',
|
|
190
|
+
content: [
|
|
191
|
+
{
|
|
192
|
+
type: 'text',
|
|
193
|
+
text: 'Let me search that for you.',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
type: 'tool_use',
|
|
197
|
+
id: 'call_123',
|
|
198
|
+
name: 'search',
|
|
199
|
+
input: { query: 'test' },
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
model: 'gpt-4',
|
|
203
|
+
stop_reason: 'tool_use',
|
|
204
|
+
stop_sequence: null,
|
|
205
|
+
usage: {
|
|
206
|
+
input_tokens: 10,
|
|
207
|
+
output_tokens: 20,
|
|
208
|
+
cache_creation_input_tokens: null,
|
|
209
|
+
cache_read_input_tokens: null,
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
it('should handle invalid tool call arguments', () => {
|
|
214
|
+
const openAiCompletion = {
|
|
215
|
+
id: 'cmpl-123',
|
|
216
|
+
choices: [
|
|
217
|
+
{
|
|
218
|
+
message: {
|
|
219
|
+
role: 'assistant',
|
|
220
|
+
content: 'Testing invalid arguments',
|
|
221
|
+
refusal: null,
|
|
222
|
+
tool_calls: [
|
|
223
|
+
{
|
|
224
|
+
id: 'call_123',
|
|
225
|
+
type: 'function',
|
|
226
|
+
function: {
|
|
227
|
+
name: 'test',
|
|
228
|
+
arguments: 'invalid json',
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
finish_reason: 'tool_calls',
|
|
234
|
+
index: 0,
|
|
235
|
+
logprobs: null,
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
created: 1234567890,
|
|
239
|
+
model: 'gpt-4',
|
|
240
|
+
object: 'chat.completion',
|
|
241
|
+
};
|
|
242
|
+
const result = convertToAnthropicMessage(openAiCompletion);
|
|
243
|
+
expect(result.content).toHaveLength(2);
|
|
244
|
+
expect(result.content[1]).toEqual({
|
|
245
|
+
type: 'tool_use',
|
|
246
|
+
id: 'call_123',
|
|
247
|
+
name: 'test',
|
|
248
|
+
input: {},
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
it('should handle different finish reasons', () => {
|
|
252
|
+
const createCompletion = (finish_reason) => ({
|
|
253
|
+
id: 'cmpl-123',
|
|
254
|
+
choices: [
|
|
255
|
+
{
|
|
256
|
+
message: {
|
|
257
|
+
role: 'assistant',
|
|
258
|
+
content: 'Test',
|
|
259
|
+
refusal: null,
|
|
260
|
+
},
|
|
261
|
+
finish_reason: finish_reason,
|
|
262
|
+
index: 0,
|
|
263
|
+
logprobs: null,
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
created: 1234567890,
|
|
267
|
+
model: 'gpt-4',
|
|
268
|
+
object: 'chat.completion',
|
|
269
|
+
});
|
|
270
|
+
expect(convertToAnthropicMessage(createCompletion('stop')).stop_reason).toBe('end_turn');
|
|
271
|
+
expect(convertToAnthropicMessage(createCompletion('length')).stop_reason).toBe('max_tokens');
|
|
272
|
+
expect(convertToAnthropicMessage(createCompletion('tool_calls')).stop_reason).toBe('tool_use');
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
//# sourceMappingURL=utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../src/AiService/utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AAI/C,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAE5E,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,iBAAiB,GAAsC;YAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE;YAClC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE;SAC5C,CAAA;QAED,MAAM,M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AAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAChG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import pino from 'pino';
|
|
2
|
+
export declare const getLogger: () => pino.Logger<never>;
|
|
3
|
+
export declare const setLogger: (newLogger: pino.Logger) => void;
|
|
4
|
+
export declare const createServiceLogger: (service: string) => pino.Logger<never>;
|
|
5
|
+
export type Logger = pino.Logger;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import pino from 'pino';
|
|
2
|
+
let logger = undefined;
|
|
3
|
+
export const getLogger = () => {
|
|
4
|
+
if (!logger) {
|
|
5
|
+
logger = pino({
|
|
6
|
+
level: process.env.LOG_LEVEL || 'info',
|
|
7
|
+
redact: ['apiKey'],
|
|
8
|
+
transport: {
|
|
9
|
+
target: 'pino-pretty',
|
|
10
|
+
options: {
|
|
11
|
+
colorize: true,
|
|
12
|
+
translateTime: 'SYS:standard',
|
|
13
|
+
ignore: 'pid,hostname',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return logger;
|
|
19
|
+
};
|
|
20
|
+
export const setLogger = (newLogger) => {
|
|
21
|
+
logger = newLogger;
|
|
22
|
+
};
|
|
23
|
+
// Create namespaced loggers for different services
|
|
24
|
+
export const createServiceLogger = (service) => getLogger().child({ service });
|
|
25
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,IAAI,MAAM,GAA4B,SAAS,CAAA;AAE/C,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,IAAI,CAAC;YACZ,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM;YACtC,MAAM,EAAE,CAAC,QAAQ,CAAC;YAClB,SAAS,EAAE;gBACT,MAAM,EAAE,aAAa;gBACrB,OAAO,EAAE;oBACP,QAAQ,EAAE,IAAI;oBACd,aAAa,EAAE,cAAc;oBAC7B,MAAM,EAAE,cAAc;iBACvB;aACF;SACF,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAAsB,EAAE,EAAE;IAClD,MAAM,GAAG,SAAS,CAAA;AACpB,CAAC,CAAA;AAED,mDAAmD;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AAEvB,OAAO,KAAK,QAAQ,MAAM,SAAS,CAAA"}
|