@polka-codes/core 0.7.3 → 0.7.5
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.
|
@@ -82,6 +82,7 @@ declare interface AiServiceOptions {
|
|
|
82
82
|
baseUrl?: string;
|
|
83
83
|
usageMeter: UsageMeter;
|
|
84
84
|
enableCache?: boolean;
|
|
85
|
+
parameters: Record<string, any>;
|
|
85
86
|
}
|
|
86
87
|
export { AiServiceOptions }
|
|
87
88
|
export { AiServiceOptions as AiServiceOptions_alias_1 }
|
|
@@ -182,6 +183,7 @@ declare const anthropicModels: {
|
|
|
182
183
|
readonly outputPrice: 15;
|
|
183
184
|
readonly cacheWritesPrice: 3.75;
|
|
184
185
|
readonly cacheReadsPrice: 0.3;
|
|
186
|
+
readonly reasoning: true;
|
|
185
187
|
};
|
|
186
188
|
readonly 'claude-3-5-sonnet-20241022': {
|
|
187
189
|
readonly maxTokens: 8192;
|
|
@@ -1541,6 +1543,7 @@ declare interface ModelInfo {
|
|
|
1541
1543
|
outputPrice?: number;
|
|
1542
1544
|
cacheWritesPrice?: number;
|
|
1543
1545
|
cacheReadsPrice?: number;
|
|
1546
|
+
reasoning?: boolean;
|
|
1544
1547
|
}
|
|
1545
1548
|
export { ModelInfo }
|
|
1546
1549
|
export { ModelInfo as ModelInfo_alias_1 }
|
|
@@ -1558,6 +1561,7 @@ declare const modelInfos: {
|
|
|
1558
1561
|
readonly outputPrice: 15;
|
|
1559
1562
|
readonly cacheWritesPrice: 3.75;
|
|
1560
1563
|
readonly cacheReadsPrice: 0.3;
|
|
1564
|
+
readonly reasoning: true;
|
|
1561
1565
|
};
|
|
1562
1566
|
readonly 'claude-3-5-sonnet-20241022': {
|
|
1563
1567
|
readonly maxTokens: 8192;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export { AiServiceProvider } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { defaultModels } from './_tsup-dts-rollup.js';
|
|
3
|
+
export { createService } from './_tsup-dts-rollup.js';
|
|
4
|
+
export { UsageMeter } from './_tsup-dts-rollup.js';
|
|
5
|
+
export { MessageParam } from './_tsup-dts-rollup.js';
|
|
6
|
+
export { AiServiceOptions } from './_tsup-dts-rollup.js';
|
|
7
|
+
export { AiServiceBase } from './_tsup-dts-rollup.js';
|
|
8
|
+
export { ModelInfo } from './_tsup-dts-rollup.js';
|
|
9
|
+
export { ApiUsage } from './_tsup-dts-rollup.js';
|
|
10
|
+
export { allAgents } from './_tsup-dts-rollup.js';
|
|
11
|
+
export { AgentNameType } from './_tsup-dts-rollup.js';
|
|
12
|
+
export { TaskEventKind } from './_tsup-dts-rollup.js';
|
|
13
|
+
export { TaskEventBase } from './_tsup-dts-rollup.js';
|
|
14
|
+
export { TaskEventStartTask } from './_tsup-dts-rollup.js';
|
|
15
|
+
export { TaskEventStartRequest } from './_tsup-dts-rollup.js';
|
|
16
|
+
export { TaskEventEndRequest } from './_tsup-dts-rollup.js';
|
|
17
|
+
export { TaskEventUsage } from './_tsup-dts-rollup.js';
|
|
18
|
+
export { TaskEventText } from './_tsup-dts-rollup.js';
|
|
19
|
+
export { TaskEventTool } from './_tsup-dts-rollup.js';
|
|
20
|
+
export { TaskEventToolHandOverDelegate } from './_tsup-dts-rollup.js';
|
|
21
|
+
export { TaskEventUsageExceeded } from './_tsup-dts-rollup.js';
|
|
22
|
+
export { TaskEventEndTask } from './_tsup-dts-rollup.js';
|
|
23
|
+
export { TaskEvent } from './_tsup-dts-rollup.js';
|
|
24
|
+
export { TaskEventCallback } from './_tsup-dts-rollup.js';
|
|
25
|
+
export { SharedAgentOptions } from './_tsup-dts-rollup.js';
|
|
26
|
+
export { AgentBaseConfig } from './_tsup-dts-rollup.js';
|
|
27
|
+
export { AgentInfo } from './_tsup-dts-rollup.js';
|
|
28
|
+
export { ExitReason } from './_tsup-dts-rollup.js';
|
|
29
|
+
export { AgentBase } from './_tsup-dts-rollup.js';
|
|
30
|
+
export { CoderAgentOptions } from './_tsup-dts-rollup.js';
|
|
31
|
+
export { CoderAgent } from './_tsup-dts-rollup.js';
|
|
32
|
+
export { coderAgentInfo } from './_tsup-dts-rollup.js';
|
|
33
|
+
export { ArchitectAgentOptions } from './_tsup-dts-rollup.js';
|
|
34
|
+
export { ArchitectAgent } from './_tsup-dts-rollup.js';
|
|
35
|
+
export { architectAgentInfo } from './_tsup-dts-rollup.js';
|
|
36
|
+
export { AnalyzerAgentOptions } from './_tsup-dts-rollup.js';
|
|
37
|
+
export { AnalyzerAgent } from './_tsup-dts-rollup.js';
|
|
38
|
+
export { analyzerAgentInfo } from './_tsup-dts-rollup.js';
|
|
39
|
+
export { CodeFixerAgentOptions } from './_tsup-dts-rollup.js';
|
|
40
|
+
export { CodeFixerAgent } from './_tsup-dts-rollup.js';
|
|
41
|
+
export { codeFixerAgentInfo } from './_tsup-dts-rollup.js';
|
|
42
|
+
export { MultiAgentConfig } from './_tsup-dts-rollup.js';
|
|
43
|
+
export { MultiAgent } from './_tsup-dts-rollup.js';
|
|
44
|
+
export { allTools } from './_tsup-dts-rollup.js';
|
|
45
|
+
export { FilesystemProvider } from './_tsup-dts-rollup.js';
|
|
46
|
+
export { CommandProvider } from './_tsup-dts-rollup.js';
|
|
47
|
+
export { InteractionProvider } from './_tsup-dts-rollup.js';
|
|
48
|
+
export { ToolProvider } from './_tsup-dts-rollup.js';
|
|
49
|
+
export { MockProvider } from './_tsup-dts-rollup.js';
|
|
50
|
+
export { askFollowupQuestion } from './_tsup-dts-rollup.js';
|
|
51
|
+
export { attemptCompletion } from './_tsup-dts-rollup.js';
|
|
52
|
+
export { delegate } from './_tsup-dts-rollup.js';
|
|
53
|
+
export { executeCommand } from './_tsup-dts-rollup.js';
|
|
54
|
+
export { listCodeDefinitionNames } from './_tsup-dts-rollup.js';
|
|
55
|
+
export { listFiles } from './_tsup-dts-rollup.js';
|
|
56
|
+
export { readFile } from './_tsup-dts-rollup.js';
|
|
57
|
+
export { replaceInFile } from './_tsup-dts-rollup.js';
|
|
58
|
+
export { searchFiles } from './_tsup-dts-rollup.js';
|
|
59
|
+
export { writeToFile } from './_tsup-dts-rollup.js';
|
|
60
|
+
export { handOver } from './_tsup-dts-rollup.js';
|
|
61
|
+
export { removeFile } from './_tsup-dts-rollup.js';
|
|
62
|
+
export { renameFile } from './_tsup-dts-rollup.js';
|
|
63
|
+
export { AnthropicModelId } from './_tsup-dts-rollup.js';
|
|
64
|
+
export { anthropicDefaultModelId } from './_tsup-dts-rollup.js';
|
|
65
|
+
export { anthropicModels } from './_tsup-dts-rollup.js';
|
|
66
|
+
export { openAiModelInfoSaneDefaults } from './_tsup-dts-rollup.js';
|
|
67
|
+
export { DeepSeekModelId } from './_tsup-dts-rollup.js';
|
|
68
|
+
export { deepSeekDefaultModelId } from './_tsup-dts-rollup.js';
|
|
69
|
+
export { deepSeekModels } from './_tsup-dts-rollup.js';
|
|
70
|
+
export { modelInfos } from './_tsup-dts-rollup.js';
|
|
71
|
+
export { executeTool } from './_tsup-dts-rollup.js';
|
|
72
|
+
export { executeAgentTool } from './_tsup-dts-rollup.js';
|
|
73
|
+
export { makeTool } from './_tsup-dts-rollup.js';
|
|
74
|
+
export { makeAgentTool } from './_tsup-dts-rollup.js';
|
|
75
|
+
export { generateGitCommitMessage } from './_tsup-dts-rollup.js';
|
|
76
|
+
export { generateGithubPullRequestDetails } from './_tsup-dts-rollup.js';
|
|
77
|
+
export { generateProjectConfig } from './_tsup-dts-rollup.js';
|
|
78
|
+
export { createNewProject } from './_tsup-dts-rollup.js';
|
|
79
|
+
export { AiToolDefinition } from './_tsup-dts-rollup.js';
|
|
80
|
+
export { GetInput } from './_tsup-dts-rollup.js';
|
|
81
|
+
export { GetOutput } from './_tsup-dts-rollup.js';
|
|
82
|
+
export { ToolParameter } from './_tsup-dts-rollup.js';
|
|
83
|
+
export { ToolExample } from './_tsup-dts-rollup.js';
|
|
84
|
+
export { PermissionLevel } from './_tsup-dts-rollup.js';
|
|
85
|
+
export { ToolInfo } from './_tsup-dts-rollup.js';
|
|
86
|
+
export { FullToolInfo } from './_tsup-dts-rollup.js';
|
|
87
|
+
export { ToolResponseType } from './_tsup-dts-rollup.js';
|
|
88
|
+
export { ToolResponseReply } from './_tsup-dts-rollup.js';
|
|
89
|
+
export { ToolResponseExit } from './_tsup-dts-rollup.js';
|
|
90
|
+
export { ToolResponseInvalid } from './_tsup-dts-rollup.js';
|
|
91
|
+
export { ToolResponseError } from './_tsup-dts-rollup.js';
|
|
92
|
+
export { ToolResponseInterrupted } from './_tsup-dts-rollup.js';
|
|
93
|
+
export { ToolResponseHandOver } from './_tsup-dts-rollup.js';
|
|
94
|
+
export { ToolResponseDelegate } from './_tsup-dts-rollup.js';
|
|
95
|
+
export { ToolResponse } from './_tsup-dts-rollup.js';
|
|
96
|
+
export { ToolHandler } from './_tsup-dts-rollup.js';
|
|
97
|
+
export { getAvailableTools_alias_1 as getAvailableTools } from './_tsup-dts-rollup.js';
|
|
@@ -1,88 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
2
|
var __export = (target, all) => {
|
|
9
3
|
for (var name in all)
|
|
10
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
5
|
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
AgentBase: () => AgentBase,
|
|
34
|
-
AiServiceProvider: () => AiServiceProvider,
|
|
35
|
-
AnalyzerAgent: () => AnalyzerAgent,
|
|
36
|
-
ArchitectAgent: () => ArchitectAgent,
|
|
37
|
-
CodeFixerAgent: () => CodeFixerAgent,
|
|
38
|
-
CoderAgent: () => CoderAgent,
|
|
39
|
-
MockProvider: () => MockProvider,
|
|
40
|
-
MultiAgent: () => MultiAgent,
|
|
41
|
-
PermissionLevel: () => PermissionLevel,
|
|
42
|
-
TaskEventKind: () => TaskEventKind,
|
|
43
|
-
ToolResponseType: () => ToolResponseType,
|
|
44
|
-
UsageMeter: () => UsageMeter,
|
|
45
|
-
allAgents: () => allAgents,
|
|
46
|
-
allTools: () => allTools_exports,
|
|
47
|
-
analyzerAgentInfo: () => analyzerAgentInfo,
|
|
48
|
-
anthropicDefaultModelId: () => anthropicDefaultModelId,
|
|
49
|
-
anthropicModels: () => anthropicModels,
|
|
50
|
-
architectAgentInfo: () => architectAgentInfo,
|
|
51
|
-
askFollowupQuestion: () => askFollowupQuestion_default,
|
|
52
|
-
attemptCompletion: () => attemptCompletion_default,
|
|
53
|
-
codeFixerAgentInfo: () => codeFixerAgentInfo,
|
|
54
|
-
coderAgentInfo: () => coderAgentInfo,
|
|
55
|
-
createNewProject: () => createNewProject,
|
|
56
|
-
createService: () => createService,
|
|
57
|
-
deepSeekDefaultModelId: () => deepSeekDefaultModelId,
|
|
58
|
-
deepSeekModels: () => deepSeekModels,
|
|
59
|
-
defaultModels: () => defaultModels,
|
|
60
|
-
delegate: () => delegate_default,
|
|
61
|
-
executeAgentTool: () => executeAgentTool,
|
|
62
|
-
executeCommand: () => executeCommand_default,
|
|
63
|
-
executeTool: () => executeTool,
|
|
64
|
-
generateGitCommitMessage: () => generateGitCommitMessage,
|
|
65
|
-
generateGithubPullRequestDetails: () => generateGithubPullRequestDetails,
|
|
66
|
-
generateProjectConfig: () => generateProjectConfig,
|
|
67
|
-
getAvailableTools: () => getAvailableTools,
|
|
68
|
-
handOver: () => handOver_default,
|
|
69
|
-
listCodeDefinitionNames: () => listCodeDefinitionNames_default,
|
|
70
|
-
listFiles: () => listFiles_default,
|
|
71
|
-
makeAgentTool: () => makeAgentTool,
|
|
72
|
-
makeTool: () => makeTool,
|
|
73
|
-
modelInfos: () => modelInfos,
|
|
74
|
-
openAiModelInfoSaneDefaults: () => openAiModelInfoSaneDefaults,
|
|
75
|
-
readFile: () => readFile_default,
|
|
76
|
-
removeFile: () => removeFile_default,
|
|
77
|
-
renameFile: () => renameFile_default,
|
|
78
|
-
replaceInFile: () => replaceInFile_default,
|
|
79
|
-
searchFiles: () => searchFiles_default,
|
|
80
|
-
writeToFile: () => writeToFile_default
|
|
81
|
-
});
|
|
82
|
-
module.exports = __toCommonJS(index_exports);
|
|
83
6
|
|
|
84
7
|
// src/AiService/AnthropicService.ts
|
|
85
|
-
|
|
8
|
+
import { Anthropic } from "@anthropic-ai/sdk";
|
|
86
9
|
|
|
87
10
|
// src/AiService/AiServiceBase.ts
|
|
88
11
|
var AiServiceBase = class {
|
|
@@ -151,7 +74,8 @@ var anthropicModels = {
|
|
|
151
74
|
inputPrice: 3,
|
|
152
75
|
outputPrice: 15,
|
|
153
76
|
cacheWritesPrice: 3.75,
|
|
154
|
-
cacheReadsPrice: 0.3
|
|
77
|
+
cacheReadsPrice: 0.3,
|
|
78
|
+
reasoning: true
|
|
155
79
|
},
|
|
156
80
|
"claude-3-5-sonnet-20241022": {
|
|
157
81
|
maxTokens: 8192,
|
|
@@ -245,7 +169,7 @@ var AnthropicService = class extends AiServiceBase {
|
|
|
245
169
|
constructor(options) {
|
|
246
170
|
super(options.usageMeter);
|
|
247
171
|
this.#options = options;
|
|
248
|
-
this.#client = new
|
|
172
|
+
this.#client = new Anthropic({
|
|
249
173
|
apiKey: options.apiKey,
|
|
250
174
|
baseURL: options.baseUrl || void 0
|
|
251
175
|
});
|
|
@@ -260,6 +184,14 @@ var AnthropicService = class extends AiServiceBase {
|
|
|
260
184
|
let stream;
|
|
261
185
|
const modelId = this.model.id;
|
|
262
186
|
const cacheControl = this.#options.enableCache ? { type: "ephemeral" } : void 0;
|
|
187
|
+
let temperature = 0;
|
|
188
|
+
let thinkingBudgetTokens = 0;
|
|
189
|
+
if (this.model.info.reasoning) {
|
|
190
|
+
thinkingBudgetTokens = this.#options.parameters.thinkingBudgetTokens ?? 0;
|
|
191
|
+
}
|
|
192
|
+
if (thinkingBudgetTokens > 0) {
|
|
193
|
+
temperature = void 0;
|
|
194
|
+
}
|
|
263
195
|
switch (modelId) {
|
|
264
196
|
// 'latest' alias does not support cache_control
|
|
265
197
|
case "claude-3-7-sonnet-20250219":
|
|
@@ -278,7 +210,8 @@ var AnthropicService = class extends AiServiceBase {
|
|
|
278
210
|
stream = await this.#client.messages.create({
|
|
279
211
|
model: modelId,
|
|
280
212
|
max_tokens: this.model.info.maxTokens || 8192,
|
|
281
|
-
|
|
213
|
+
thinking: thinkingBudgetTokens ? { type: "enabled", budget_tokens: thinkingBudgetTokens } : void 0,
|
|
214
|
+
temperature,
|
|
282
215
|
system: [
|
|
283
216
|
{
|
|
284
217
|
text: systemPrompt,
|
|
@@ -318,8 +251,6 @@ var AnthropicService = class extends AiServiceBase {
|
|
|
318
251
|
temperature: 0,
|
|
319
252
|
system: [{ text: systemPrompt, type: "text" }],
|
|
320
253
|
messages,
|
|
321
|
-
// tools,
|
|
322
|
-
// tool_choice: { type: "auto" },
|
|
323
254
|
stream: true
|
|
324
255
|
});
|
|
325
256
|
break;
|
|
@@ -362,6 +293,18 @@ var AnthropicService = class extends AiServiceBase {
|
|
|
362
293
|
text: chunk.content_block.text
|
|
363
294
|
};
|
|
364
295
|
break;
|
|
296
|
+
case "thinking":
|
|
297
|
+
yield {
|
|
298
|
+
type: "reasoning",
|
|
299
|
+
text: chunk.content_block.thinking
|
|
300
|
+
};
|
|
301
|
+
break;
|
|
302
|
+
case "redacted_thinking":
|
|
303
|
+
yield {
|
|
304
|
+
type: "reasoning",
|
|
305
|
+
text: "[Redacted by providered]"
|
|
306
|
+
};
|
|
307
|
+
break;
|
|
365
308
|
}
|
|
366
309
|
break;
|
|
367
310
|
case "content_block_delta":
|
|
@@ -372,6 +315,12 @@ var AnthropicService = class extends AiServiceBase {
|
|
|
372
315
|
text: chunk.delta.text
|
|
373
316
|
};
|
|
374
317
|
break;
|
|
318
|
+
case "thinking_delta":
|
|
319
|
+
yield {
|
|
320
|
+
type: "reasoning",
|
|
321
|
+
text: chunk.delta.thinking
|
|
322
|
+
};
|
|
323
|
+
break;
|
|
375
324
|
}
|
|
376
325
|
break;
|
|
377
326
|
case "content_block_stop":
|
|
@@ -382,7 +331,7 @@ var AnthropicService = class extends AiServiceBase {
|
|
|
382
331
|
};
|
|
383
332
|
|
|
384
333
|
// src/AiService/DeepSeekService.ts
|
|
385
|
-
|
|
334
|
+
import OpenAI from "openai";
|
|
386
335
|
|
|
387
336
|
// src/AiService/utils.ts
|
|
388
337
|
function convertToOpenAiMessages(anthropicMessages) {
|
|
@@ -431,10 +380,18 @@ function convertToOpenAiMessages(anthropicMessages) {
|
|
|
431
380
|
role: "user",
|
|
432
381
|
content: nonToolMessages.map((part) => {
|
|
433
382
|
if (part.type === "image") {
|
|
383
|
+
if (part.source.type === "base64") {
|
|
384
|
+
return {
|
|
385
|
+
type: "image_url",
|
|
386
|
+
image_url: {
|
|
387
|
+
url: `data:${part.source.media_type};base64,${part.source.data}`
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
}
|
|
434
391
|
return {
|
|
435
392
|
type: "image_url",
|
|
436
393
|
image_url: {
|
|
437
|
-
url:
|
|
394
|
+
url: part.source.url
|
|
438
395
|
}
|
|
439
396
|
};
|
|
440
397
|
}
|
|
@@ -490,7 +447,7 @@ var DeepSeekService = class extends AiServiceBase {
|
|
|
490
447
|
model;
|
|
491
448
|
constructor(options) {
|
|
492
449
|
super(options.usageMeter);
|
|
493
|
-
this.#client = new
|
|
450
|
+
this.#client = new OpenAI({
|
|
494
451
|
baseURL: "https://api.deepseek.com/v1",
|
|
495
452
|
apiKey: options.apiKey
|
|
496
453
|
});
|
|
@@ -547,13 +504,13 @@ var DeepSeekService = class extends AiServiceBase {
|
|
|
547
504
|
};
|
|
548
505
|
|
|
549
506
|
// src/AiService/OllamaService.ts
|
|
550
|
-
|
|
507
|
+
import OpenAI2 from "openai";
|
|
551
508
|
var OllamaService = class extends AiServiceBase {
|
|
552
509
|
#client;
|
|
553
510
|
model;
|
|
554
511
|
constructor(options) {
|
|
555
512
|
super(options.usageMeter);
|
|
556
|
-
this.#client = new
|
|
513
|
+
this.#client = new OpenAI2({
|
|
557
514
|
baseURL: `${options.baseUrl || "http://localhost:11434"}/v1`,
|
|
558
515
|
apiKey: "ollama"
|
|
559
516
|
});
|
|
@@ -587,7 +544,7 @@ var OllamaService = class extends AiServiceBase {
|
|
|
587
544
|
};
|
|
588
545
|
|
|
589
546
|
// src/AiService/OpenRouterService.ts
|
|
590
|
-
|
|
547
|
+
import OpenAI3 from "openai";
|
|
591
548
|
var OpenRouterService = class extends AiServiceBase {
|
|
592
549
|
#client;
|
|
593
550
|
#apiKey;
|
|
@@ -603,7 +560,7 @@ var OpenRouterService = class extends AiServiceBase {
|
|
|
603
560
|
throw new Error("OpenRouter requires an API key");
|
|
604
561
|
}
|
|
605
562
|
this.#apiKey = options.apiKey;
|
|
606
|
-
this.#client = new
|
|
563
|
+
this.#client = new OpenAI3({
|
|
607
564
|
baseURL: "https://openrouter.ai/api/v1",
|
|
608
565
|
apiKey: options.apiKey,
|
|
609
566
|
defaultHeaders: {
|
|
@@ -695,6 +652,20 @@ var OpenRouterService = class extends AiServiceBase {
|
|
|
695
652
|
maxTokens = 8192;
|
|
696
653
|
break;
|
|
697
654
|
}
|
|
655
|
+
let reasoning = {};
|
|
656
|
+
switch (this.model.id) {
|
|
657
|
+
case "anthropic/claude-3.7-sonnet":
|
|
658
|
+
case "anthropic/claude-3.7-sonnet:beta":
|
|
659
|
+
case "anthropic/claude-3.7-sonnet:thinking":
|
|
660
|
+
case "anthropic/claude-3-7-sonnet":
|
|
661
|
+
case "anthropic/claude-3-7-sonnet:beta": {
|
|
662
|
+
const budget_tokens = this.#options.parameters.thinkingBudgetTokens || 0;
|
|
663
|
+
if (budget_tokens > 0) {
|
|
664
|
+
reasoning = { max_tokens: budget_tokens };
|
|
665
|
+
}
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
698
669
|
let shouldApplyMiddleOutTransform = !this.model.info.supportsPromptCache;
|
|
699
670
|
if (this.model.id === "deepseek/deepseek-chat") {
|
|
700
671
|
shouldApplyMiddleOutTransform = true;
|
|
@@ -706,7 +677,8 @@ var OpenRouterService = class extends AiServiceBase {
|
|
|
706
677
|
temperature: 0,
|
|
707
678
|
stream: true,
|
|
708
679
|
transforms: shouldApplyMiddleOutTransform ? ["middle-out"] : void 0,
|
|
709
|
-
include_reasoning: true
|
|
680
|
+
include_reasoning: true,
|
|
681
|
+
...reasoning
|
|
710
682
|
});
|
|
711
683
|
let genId;
|
|
712
684
|
for await (const chunk of stream) {
|
|
@@ -771,7 +743,7 @@ var OpenRouterService = class extends AiServiceBase {
|
|
|
771
743
|
};
|
|
772
744
|
|
|
773
745
|
// src/AiService/UsageMeter.ts
|
|
774
|
-
|
|
746
|
+
import { merge } from "lodash";
|
|
775
747
|
var UsageMeter = class {
|
|
776
748
|
#usage = {
|
|
777
749
|
inputTokens: 0,
|
|
@@ -787,7 +759,7 @@ var UsageMeter = class {
|
|
|
787
759
|
constructor(options = {}) {
|
|
788
760
|
this.maxCost = options.maxCost || 1e3;
|
|
789
761
|
this.maxMessageCount = options.maxMessageCount || 1e3;
|
|
790
|
-
this.#prices =
|
|
762
|
+
this.#prices = merge({}, modelInfos, options.prices ?? {});
|
|
791
763
|
}
|
|
792
764
|
/**
|
|
793
765
|
* Add usage metrics to the current totals
|
|
@@ -2279,19 +2251,23 @@ ${agents}`;
|
|
|
2279
2251
|
for (let i = 0; i < retryCount; i++) {
|
|
2280
2252
|
currentAssistantMessage = "";
|
|
2281
2253
|
const stream = this.ai.send(this.config.systemPrompt, this.messages);
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2254
|
+
try {
|
|
2255
|
+
for await (const chunk of stream) {
|
|
2256
|
+
switch (chunk.type) {
|
|
2257
|
+
case "usage":
|
|
2258
|
+
await this.#callback({ kind: "Usage" /* Usage */, agent: this });
|
|
2259
|
+
break;
|
|
2260
|
+
case "text":
|
|
2261
|
+
currentAssistantMessage += chunk.text;
|
|
2262
|
+
await this.#callback({ kind: "Text" /* Text */, agent: this, newText: chunk.text });
|
|
2263
|
+
break;
|
|
2264
|
+
case "reasoning":
|
|
2265
|
+
await this.#callback({ kind: "Reasoning" /* Reasoning */, agent: this, newText: chunk.text });
|
|
2266
|
+
break;
|
|
2267
|
+
}
|
|
2294
2268
|
}
|
|
2269
|
+
} catch (error) {
|
|
2270
|
+
console.error("Error in stream:", error);
|
|
2295
2271
|
}
|
|
2296
2272
|
if (currentAssistantMessage) {
|
|
2297
2273
|
break;
|
|
@@ -3404,8 +3380,7 @@ var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
|
|
|
3404
3380
|
var generateGithubPullRequestDetails = makeTool(generateGithubPullRequestDetails_default);
|
|
3405
3381
|
var generateProjectConfig = makeAgentTool(generateProjectConfig_default);
|
|
3406
3382
|
var createNewProject = makeAgentTool(createNewProject_default);
|
|
3407
|
-
|
|
3408
|
-
0 && (module.exports = {
|
|
3383
|
+
export {
|
|
3409
3384
|
AgentBase,
|
|
3410
3385
|
AiServiceProvider,
|
|
3411
3386
|
AnalyzerAgent,
|
|
@@ -3419,13 +3394,13 @@ var createNewProject = makeAgentTool(createNewProject_default);
|
|
|
3419
3394
|
ToolResponseType,
|
|
3420
3395
|
UsageMeter,
|
|
3421
3396
|
allAgents,
|
|
3422
|
-
allTools,
|
|
3397
|
+
allTools_exports as allTools,
|
|
3423
3398
|
analyzerAgentInfo,
|
|
3424
3399
|
anthropicDefaultModelId,
|
|
3425
3400
|
anthropicModels,
|
|
3426
3401
|
architectAgentInfo,
|
|
3427
|
-
askFollowupQuestion,
|
|
3428
|
-
attemptCompletion,
|
|
3402
|
+
askFollowupQuestion_default as askFollowupQuestion,
|
|
3403
|
+
attemptCompletion_default as attemptCompletion,
|
|
3429
3404
|
codeFixerAgentInfo,
|
|
3430
3405
|
coderAgentInfo,
|
|
3431
3406
|
createNewProject,
|
|
@@ -3433,25 +3408,25 @@ var createNewProject = makeAgentTool(createNewProject_default);
|
|
|
3433
3408
|
deepSeekDefaultModelId,
|
|
3434
3409
|
deepSeekModels,
|
|
3435
3410
|
defaultModels,
|
|
3436
|
-
delegate,
|
|
3411
|
+
delegate_default as delegate,
|
|
3437
3412
|
executeAgentTool,
|
|
3438
|
-
executeCommand,
|
|
3413
|
+
executeCommand_default as executeCommand,
|
|
3439
3414
|
executeTool,
|
|
3440
3415
|
generateGitCommitMessage,
|
|
3441
3416
|
generateGithubPullRequestDetails,
|
|
3442
3417
|
generateProjectConfig,
|
|
3443
3418
|
getAvailableTools,
|
|
3444
|
-
handOver,
|
|
3445
|
-
listCodeDefinitionNames,
|
|
3446
|
-
listFiles,
|
|
3419
|
+
handOver_default as handOver,
|
|
3420
|
+
listCodeDefinitionNames_default as listCodeDefinitionNames,
|
|
3421
|
+
listFiles_default as listFiles,
|
|
3447
3422
|
makeAgentTool,
|
|
3448
3423
|
makeTool,
|
|
3449
3424
|
modelInfos,
|
|
3450
3425
|
openAiModelInfoSaneDefaults,
|
|
3451
|
-
readFile,
|
|
3452
|
-
removeFile,
|
|
3453
|
-
renameFile,
|
|
3454
|
-
replaceInFile,
|
|
3455
|
-
searchFiles,
|
|
3456
|
-
writeToFile
|
|
3457
|
-
}
|
|
3426
|
+
readFile_default as readFile,
|
|
3427
|
+
removeFile_default as removeFile,
|
|
3428
|
+
renameFile_default as renameFile,
|
|
3429
|
+
replaceInFile_default as replaceInFile,
|
|
3430
|
+
searchFiles_default as searchFiles,
|
|
3431
|
+
writeToFile_default as writeToFile
|
|
3432
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polka-codes/core",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"author": "github@polka.codes",
|
|
6
6
|
"type": "module",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": ["dist"],
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "tsup src/index.ts --experimental-dts"
|
|
15
|
+
"build": "tsup src/index.ts --experimental-dts --format esm --clean"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@anthropic-ai/sdk": "
|
|
18
|
+
"@anthropic-ai/sdk": "0.39.0",
|
|
19
19
|
"lodash": "^4.17.21",
|
|
20
20
|
"openai": "^4.80.0"
|
|
21
21
|
}
|
package/dist/index.d.cts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
export { AiServiceProvider } from './_tsup-dts-rollup.cjs';
|
|
2
|
-
export { defaultModels } from './_tsup-dts-rollup.cjs';
|
|
3
|
-
export { createService } from './_tsup-dts-rollup.cjs';
|
|
4
|
-
export { UsageMeter } from './_tsup-dts-rollup.cjs';
|
|
5
|
-
export { MessageParam } from './_tsup-dts-rollup.cjs';
|
|
6
|
-
export { AiServiceOptions } from './_tsup-dts-rollup.cjs';
|
|
7
|
-
export { AiServiceBase } from './_tsup-dts-rollup.cjs';
|
|
8
|
-
export { ModelInfo } from './_tsup-dts-rollup.cjs';
|
|
9
|
-
export { ApiUsage } from './_tsup-dts-rollup.cjs';
|
|
10
|
-
export { allAgents } from './_tsup-dts-rollup.cjs';
|
|
11
|
-
export { AgentNameType } from './_tsup-dts-rollup.cjs';
|
|
12
|
-
export { TaskEventKind } from './_tsup-dts-rollup.cjs';
|
|
13
|
-
export { TaskEventBase } from './_tsup-dts-rollup.cjs';
|
|
14
|
-
export { TaskEventStartTask } from './_tsup-dts-rollup.cjs';
|
|
15
|
-
export { TaskEventStartRequest } from './_tsup-dts-rollup.cjs';
|
|
16
|
-
export { TaskEventEndRequest } from './_tsup-dts-rollup.cjs';
|
|
17
|
-
export { TaskEventUsage } from './_tsup-dts-rollup.cjs';
|
|
18
|
-
export { TaskEventText } from './_tsup-dts-rollup.cjs';
|
|
19
|
-
export { TaskEventTool } from './_tsup-dts-rollup.cjs';
|
|
20
|
-
export { TaskEventToolHandOverDelegate } from './_tsup-dts-rollup.cjs';
|
|
21
|
-
export { TaskEventUsageExceeded } from './_tsup-dts-rollup.cjs';
|
|
22
|
-
export { TaskEventEndTask } from './_tsup-dts-rollup.cjs';
|
|
23
|
-
export { TaskEvent } from './_tsup-dts-rollup.cjs';
|
|
24
|
-
export { TaskEventCallback } from './_tsup-dts-rollup.cjs';
|
|
25
|
-
export { SharedAgentOptions } from './_tsup-dts-rollup.cjs';
|
|
26
|
-
export { AgentBaseConfig } from './_tsup-dts-rollup.cjs';
|
|
27
|
-
export { AgentInfo } from './_tsup-dts-rollup.cjs';
|
|
28
|
-
export { ExitReason } from './_tsup-dts-rollup.cjs';
|
|
29
|
-
export { AgentBase } from './_tsup-dts-rollup.cjs';
|
|
30
|
-
export { CoderAgentOptions } from './_tsup-dts-rollup.cjs';
|
|
31
|
-
export { CoderAgent } from './_tsup-dts-rollup.cjs';
|
|
32
|
-
export { coderAgentInfo } from './_tsup-dts-rollup.cjs';
|
|
33
|
-
export { ArchitectAgentOptions } from './_tsup-dts-rollup.cjs';
|
|
34
|
-
export { ArchitectAgent } from './_tsup-dts-rollup.cjs';
|
|
35
|
-
export { architectAgentInfo } from './_tsup-dts-rollup.cjs';
|
|
36
|
-
export { AnalyzerAgentOptions } from './_tsup-dts-rollup.cjs';
|
|
37
|
-
export { AnalyzerAgent } from './_tsup-dts-rollup.cjs';
|
|
38
|
-
export { analyzerAgentInfo } from './_tsup-dts-rollup.cjs';
|
|
39
|
-
export { CodeFixerAgentOptions } from './_tsup-dts-rollup.cjs';
|
|
40
|
-
export { CodeFixerAgent } from './_tsup-dts-rollup.cjs';
|
|
41
|
-
export { codeFixerAgentInfo } from './_tsup-dts-rollup.cjs';
|
|
42
|
-
export { MultiAgentConfig } from './_tsup-dts-rollup.cjs';
|
|
43
|
-
export { MultiAgent } from './_tsup-dts-rollup.cjs';
|
|
44
|
-
export { allTools } from './_tsup-dts-rollup.cjs';
|
|
45
|
-
export { FilesystemProvider } from './_tsup-dts-rollup.cjs';
|
|
46
|
-
export { CommandProvider } from './_tsup-dts-rollup.cjs';
|
|
47
|
-
export { InteractionProvider } from './_tsup-dts-rollup.cjs';
|
|
48
|
-
export { ToolProvider } from './_tsup-dts-rollup.cjs';
|
|
49
|
-
export { MockProvider } from './_tsup-dts-rollup.cjs';
|
|
50
|
-
export { askFollowupQuestion } from './_tsup-dts-rollup.cjs';
|
|
51
|
-
export { attemptCompletion } from './_tsup-dts-rollup.cjs';
|
|
52
|
-
export { delegate } from './_tsup-dts-rollup.cjs';
|
|
53
|
-
export { executeCommand } from './_tsup-dts-rollup.cjs';
|
|
54
|
-
export { listCodeDefinitionNames } from './_tsup-dts-rollup.cjs';
|
|
55
|
-
export { listFiles } from './_tsup-dts-rollup.cjs';
|
|
56
|
-
export { readFile } from './_tsup-dts-rollup.cjs';
|
|
57
|
-
export { replaceInFile } from './_tsup-dts-rollup.cjs';
|
|
58
|
-
export { searchFiles } from './_tsup-dts-rollup.cjs';
|
|
59
|
-
export { writeToFile } from './_tsup-dts-rollup.cjs';
|
|
60
|
-
export { handOver } from './_tsup-dts-rollup.cjs';
|
|
61
|
-
export { removeFile } from './_tsup-dts-rollup.cjs';
|
|
62
|
-
export { renameFile } from './_tsup-dts-rollup.cjs';
|
|
63
|
-
export { AnthropicModelId } from './_tsup-dts-rollup.cjs';
|
|
64
|
-
export { anthropicDefaultModelId } from './_tsup-dts-rollup.cjs';
|
|
65
|
-
export { anthropicModels } from './_tsup-dts-rollup.cjs';
|
|
66
|
-
export { openAiModelInfoSaneDefaults } from './_tsup-dts-rollup.cjs';
|
|
67
|
-
export { DeepSeekModelId } from './_tsup-dts-rollup.cjs';
|
|
68
|
-
export { deepSeekDefaultModelId } from './_tsup-dts-rollup.cjs';
|
|
69
|
-
export { deepSeekModels } from './_tsup-dts-rollup.cjs';
|
|
70
|
-
export { modelInfos } from './_tsup-dts-rollup.cjs';
|
|
71
|
-
export { executeTool } from './_tsup-dts-rollup.cjs';
|
|
72
|
-
export { executeAgentTool } from './_tsup-dts-rollup.cjs';
|
|
73
|
-
export { makeTool } from './_tsup-dts-rollup.cjs';
|
|
74
|
-
export { makeAgentTool } from './_tsup-dts-rollup.cjs';
|
|
75
|
-
export { generateGitCommitMessage } from './_tsup-dts-rollup.cjs';
|
|
76
|
-
export { generateGithubPullRequestDetails } from './_tsup-dts-rollup.cjs';
|
|
77
|
-
export { generateProjectConfig } from './_tsup-dts-rollup.cjs';
|
|
78
|
-
export { createNewProject } from './_tsup-dts-rollup.cjs';
|
|
79
|
-
export { AiToolDefinition } from './_tsup-dts-rollup.cjs';
|
|
80
|
-
export { GetInput } from './_tsup-dts-rollup.cjs';
|
|
81
|
-
export { GetOutput } from './_tsup-dts-rollup.cjs';
|
|
82
|
-
export { ToolParameter } from './_tsup-dts-rollup.cjs';
|
|
83
|
-
export { ToolExample } from './_tsup-dts-rollup.cjs';
|
|
84
|
-
export { PermissionLevel } from './_tsup-dts-rollup.cjs';
|
|
85
|
-
export { ToolInfo } from './_tsup-dts-rollup.cjs';
|
|
86
|
-
export { FullToolInfo } from './_tsup-dts-rollup.cjs';
|
|
87
|
-
export { ToolResponseType } from './_tsup-dts-rollup.cjs';
|
|
88
|
-
export { ToolResponseReply } from './_tsup-dts-rollup.cjs';
|
|
89
|
-
export { ToolResponseExit } from './_tsup-dts-rollup.cjs';
|
|
90
|
-
export { ToolResponseInvalid } from './_tsup-dts-rollup.cjs';
|
|
91
|
-
export { ToolResponseError } from './_tsup-dts-rollup.cjs';
|
|
92
|
-
export { ToolResponseInterrupted } from './_tsup-dts-rollup.cjs';
|
|
93
|
-
export { ToolResponseHandOver } from './_tsup-dts-rollup.cjs';
|
|
94
|
-
export { ToolResponseDelegate } from './_tsup-dts-rollup.cjs';
|
|
95
|
-
export { ToolResponse } from './_tsup-dts-rollup.cjs';
|
|
96
|
-
export { ToolHandler } from './_tsup-dts-rollup.cjs';
|
|
97
|
-
export { getAvailableTools_alias_1 as getAvailableTools } from './_tsup-dts-rollup.cjs';
|