@polka-codes/core 0.1.6 → 0.1.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/index.js +8855 -5
- package/package.json +4 -1
- package/dist/Agent/AgentBase.d.ts +0 -49
- package/dist/Agent/AgentBase.js +0 -158
- package/dist/Agent/AgentBase.js.map +0 -1
- package/dist/Agent/CoderAgent/index.d.ts +0 -17
- package/dist/Agent/CoderAgent/index.js +0 -32
- package/dist/Agent/CoderAgent/index.js.map +0 -1
- package/dist/Agent/CoderAgent/prompts.d.ts +0 -20
- package/dist/Agent/CoderAgent/prompts.js +0 -165
- package/dist/Agent/CoderAgent/prompts.js.map +0 -1
- package/dist/Agent/index.d.ts +0 -2
- package/dist/Agent/index.js +0 -3
- package/dist/Agent/index.js.map +0 -1
- package/dist/Agent/parseAssistantMessage.d.ts +0 -45
- package/dist/Agent/parseAssistantMessage.js +0 -103
- package/dist/Agent/parseAssistantMessage.js.map +0 -1
- package/dist/Agent/prompts.d.ts +0 -7
- package/dist/Agent/prompts.js +0 -93
- package/dist/Agent/prompts.js.map +0 -1
- package/dist/AiService/AiServiceBase.d.ts +0 -29
- package/dist/AiService/AiServiceBase.js +0 -3
- package/dist/AiService/AiServiceBase.js.map +0 -1
- package/dist/AiService/AnthropicService.d.ts +0 -11
- package/dist/AiService/AnthropicService.js +0 -185
- package/dist/AiService/AnthropicService.js.map +0 -1
- package/dist/AiService/DeepSeekService.d.ts +0 -11
- package/dist/AiService/DeepSeekService.js +0 -64
- package/dist/AiService/DeepSeekService.js.map +0 -1
- package/dist/AiService/ModelInfo.d.ts +0 -79
- package/dist/AiService/ModelInfo.js +0 -67
- package/dist/AiService/ModelInfo.js.map +0 -1
- package/dist/AiService/OllamaService.d.ts +0 -11
- package/dist/AiService/OllamaService.js +0 -47
- package/dist/AiService/OllamaService.js.map +0 -1
- package/dist/AiService/index.d.ts +0 -12
- package/dist/AiService/index.js +0 -20
- package/dist/AiService/index.js.map +0 -1
- package/dist/AiService/utils.d.ts +0 -4
- package/dist/AiService/utils.js +0 -187
- package/dist/AiService/utils.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -5
- package/dist/logger.js +0 -25
- package/dist/logger.js.map +0 -1
- package/dist/tools/index.d.ts +0 -3
- package/dist/tools/index.js +0 -4
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/tools.d.ts +0 -200
- package/dist/tools/tools.js +0 -329
- package/dist/tools/tools.js.map +0 -1
- package/dist/tools/types.d.ts +0 -49
- package/dist/tools/types.js +0 -9
- package/dist/tools/types.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polka-codes/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"files": ["dist"],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "bun build src/index.ts --outdir dist"
|
|
15
|
+
},
|
|
13
16
|
"dependencies": {
|
|
14
17
|
"@anthropic-ai/sdk": "^0.33.1",
|
|
15
18
|
"openai": "^4.77.4",
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type Anthropic from "@anthropic-ai/sdk";
|
|
2
|
-
import type { AiServiceBase, MessageParam } from "../AiService/index.js";
|
|
3
|
-
import type { Logger } from "../logger.js";
|
|
4
|
-
import { type ToolHandler, type ToolInfo } from "../tools/index.js";
|
|
5
|
-
export type TaskEvent = {
|
|
6
|
-
kind: string;
|
|
7
|
-
info: TaskInfo;
|
|
8
|
-
newText?: string;
|
|
9
|
-
tool?: string;
|
|
10
|
-
userContent?: UserContent;
|
|
11
|
-
};
|
|
12
|
-
type UserContent = Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam | Anthropic.ToolUseBlockParam | Anthropic.ToolResultBlockParam>;
|
|
13
|
-
export type TaskEventCallback = (event: TaskEvent) => void | Promise<void>;
|
|
14
|
-
export type TaskInfo = {
|
|
15
|
-
options: {
|
|
16
|
-
maxIterations: number;
|
|
17
|
-
};
|
|
18
|
-
messages: MessageParam[];
|
|
19
|
-
inputTokens: number;
|
|
20
|
-
outputTokens: number;
|
|
21
|
-
cacheWriteTokens: number;
|
|
22
|
-
cacheReadTokens: number;
|
|
23
|
-
totalCost: number | undefined;
|
|
24
|
-
};
|
|
25
|
-
export type AgentBaseConfig = {
|
|
26
|
-
systemPrompt: string;
|
|
27
|
-
tools: ToolInfo[];
|
|
28
|
-
toolNamePrefix: string;
|
|
29
|
-
toolHandler: ToolHandler;
|
|
30
|
-
customInstructions?: string[];
|
|
31
|
-
};
|
|
32
|
-
export declare abstract class AgentBase {
|
|
33
|
-
#private;
|
|
34
|
-
protected readonly ai: AiServiceBase;
|
|
35
|
-
protected readonly config: Readonly<AgentBaseConfig>;
|
|
36
|
-
protected readonly logger: Logger;
|
|
37
|
-
constructor(ai: AiServiceBase, config: AgentBaseConfig, logger: Logger);
|
|
38
|
-
startTask({ task, context, maxIterations, callback, }: {
|
|
39
|
-
task: string;
|
|
40
|
-
context?: string;
|
|
41
|
-
maxIterations: number;
|
|
42
|
-
callback: TaskEventCallback;
|
|
43
|
-
}): Promise<TaskInfo>;
|
|
44
|
-
get model(): {
|
|
45
|
-
id: string;
|
|
46
|
-
info: import("../AiService/index.js").ModelInfo;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export {};
|
package/dist/Agent/AgentBase.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { ToolResponseType } from "../tools/index.js";
|
|
2
|
-
import { parseAssistantMessage } from "./parseAssistantMessage.js";
|
|
3
|
-
import { responsePrompts } from "./prompts.js";
|
|
4
|
-
export class AgentBase {
|
|
5
|
-
ai;
|
|
6
|
-
config;
|
|
7
|
-
logger;
|
|
8
|
-
constructor(ai, config, logger) {
|
|
9
|
-
this.ai = ai;
|
|
10
|
-
this.config = config;
|
|
11
|
-
this.logger = logger;
|
|
12
|
-
}
|
|
13
|
-
async startTask({ task, context, maxIterations = 50, callback = () => { }, }) {
|
|
14
|
-
const taskInfo = {
|
|
15
|
-
options: {
|
|
16
|
-
maxIterations,
|
|
17
|
-
},
|
|
18
|
-
messages: [],
|
|
19
|
-
inputTokens: 0,
|
|
20
|
-
outputTokens: 0,
|
|
21
|
-
cacheWriteTokens: 0,
|
|
22
|
-
cacheReadTokens: 0,
|
|
23
|
-
totalCost: 0,
|
|
24
|
-
};
|
|
25
|
-
let text = `<task>${task}</task>`;
|
|
26
|
-
if (context) {
|
|
27
|
-
text += `\n<context>${context}</context>`;
|
|
28
|
-
}
|
|
29
|
-
let nextRequest = [
|
|
30
|
-
{
|
|
31
|
-
type: "text",
|
|
32
|
-
text,
|
|
33
|
-
},
|
|
34
|
-
];
|
|
35
|
-
let iterations = 0;
|
|
36
|
-
while (nextRequest) {
|
|
37
|
-
if (iterations >= taskInfo.options.maxIterations) {
|
|
38
|
-
callback({ kind: "max_iterations_reached", info: taskInfo });
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
const response = await this.#request(taskInfo, nextRequest, callback);
|
|
42
|
-
nextRequest = await this.#handleResponse(taskInfo, response, callback);
|
|
43
|
-
++iterations;
|
|
44
|
-
}
|
|
45
|
-
callback({ kind: "end_task", info: taskInfo });
|
|
46
|
-
return taskInfo;
|
|
47
|
-
}
|
|
48
|
-
async #request(info, userContent, callback) {
|
|
49
|
-
await callback({ kind: "start_request", info, userContent });
|
|
50
|
-
info.messages.push({
|
|
51
|
-
role: "user",
|
|
52
|
-
content: userContent,
|
|
53
|
-
});
|
|
54
|
-
this.logger.trace(info.messages, "Sending messages to AI");
|
|
55
|
-
// TODO: use a truncated messages if needed to avoid exceeding the token limit
|
|
56
|
-
const stream = this.ai.send(this.config.systemPrompt, info.messages);
|
|
57
|
-
let currentAssistantMessage = "";
|
|
58
|
-
for await (const chunk of stream) {
|
|
59
|
-
switch (chunk.type) {
|
|
60
|
-
case "usage":
|
|
61
|
-
info.inputTokens = chunk.inputTokens;
|
|
62
|
-
info.outputTokens = chunk.outputTokens;
|
|
63
|
-
info.cacheWriteTokens = chunk.cacheWriteTokens ?? 0;
|
|
64
|
-
info.cacheReadTokens = chunk.cacheReadTokens ?? 0;
|
|
65
|
-
info.totalCost = chunk.totalCost;
|
|
66
|
-
await callback({ kind: "usage", info });
|
|
67
|
-
break;
|
|
68
|
-
case "text":
|
|
69
|
-
currentAssistantMessage += chunk.text;
|
|
70
|
-
await callback({ kind: "text", info, newText: chunk.text });
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// TODO: error handling
|
|
75
|
-
if (!currentAssistantMessage) {
|
|
76
|
-
throw new Error("No assistant message received");
|
|
77
|
-
}
|
|
78
|
-
info.messages.push({
|
|
79
|
-
role: "assistant",
|
|
80
|
-
content: currentAssistantMessage,
|
|
81
|
-
});
|
|
82
|
-
const ret = parseAssistantMessage(currentAssistantMessage, this.config.tools, this.config.toolNamePrefix);
|
|
83
|
-
await callback({ kind: "end_request", info });
|
|
84
|
-
return ret;
|
|
85
|
-
}
|
|
86
|
-
async #handleResponse(info, response, callback) {
|
|
87
|
-
const toolReponses = [];
|
|
88
|
-
for (const content of response) {
|
|
89
|
-
switch (content.type) {
|
|
90
|
-
case "text":
|
|
91
|
-
// no need to handle text content
|
|
92
|
-
break;
|
|
93
|
-
case "tool_use": {
|
|
94
|
-
await callback({ kind: "tool_use", info, tool: content.name });
|
|
95
|
-
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
96
|
-
switch (toolResp.type) {
|
|
97
|
-
case ToolResponseType.Reply:
|
|
98
|
-
// reply to the tool use
|
|
99
|
-
await callback({ kind: "tool_reply", info, tool: content.name });
|
|
100
|
-
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
101
|
-
break;
|
|
102
|
-
case ToolResponseType.Exit:
|
|
103
|
-
// task completed
|
|
104
|
-
return undefined;
|
|
105
|
-
case ToolResponseType.Invalid:
|
|
106
|
-
// tell AI about the invalid arguments
|
|
107
|
-
await callback({ kind: "tool_invalid", info, tool: content.name });
|
|
108
|
-
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
109
|
-
break;
|
|
110
|
-
case ToolResponseType.Error:
|
|
111
|
-
// tell AI about the error
|
|
112
|
-
await callback({ kind: "tool_error", info, tool: content.name });
|
|
113
|
-
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
114
|
-
break;
|
|
115
|
-
case ToolResponseType.Interrupted:
|
|
116
|
-
// the execution is killed
|
|
117
|
-
await callback({ kind: "tool_interrupted", info, tool: content.name });
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (toolReponses.length === 0) {
|
|
125
|
-
// TODO: in interactive mode, we just wait for user to provide the next input
|
|
126
|
-
// we need to convert the loop to a state machine
|
|
127
|
-
return [
|
|
128
|
-
{
|
|
129
|
-
type: "text",
|
|
130
|
-
text: responsePrompts.requireUseTool,
|
|
131
|
-
},
|
|
132
|
-
];
|
|
133
|
-
}
|
|
134
|
-
const finalResp = toolReponses.map(({ tool, response }) => responsePrompts.toolResults(tool, response)).join("\n");
|
|
135
|
-
return [
|
|
136
|
-
{
|
|
137
|
-
type: "text",
|
|
138
|
-
text: finalResp,
|
|
139
|
-
},
|
|
140
|
-
];
|
|
141
|
-
}
|
|
142
|
-
async #invokeTool(name, args) {
|
|
143
|
-
try {
|
|
144
|
-
return await this.config.toolHandler(name, args);
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
return {
|
|
148
|
-
type: ToolResponseType.Error,
|
|
149
|
-
message: responsePrompts.errorInvokeTool(name, error),
|
|
150
|
-
canRetry: false,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
get model() {
|
|
155
|
-
return this.ai.model;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
//# sourceMappingURL=AgentBase.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgentBase.js","sourceRoot":"","sources":["../../src/Agent/AgentBase.ts"],"names":[],"mappings":"AAGA,OAAO,EAAsD,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC/F,OAAO,EAAgC,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC7F,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAoC3C,MAAM,OAAgB,SAAS;IACV,EAAE,CAAe;IACjB,MAAM,CAA2B;IACjC,MAAM,CAAQ;IAEjC,YAAY,EAAiB,EAAE,MAAuB,EAAE,MAAc;QACpE,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,EACd,IAAI,EACJ,OAAO,EACP,aAAa,GAAG,EAAE,EAClB,QAAQ,GAAG,GAAG,EAAE,GAAE,CAAC,GACoE;QACvF,MAAM,QAAQ,GAAa;YACzB,OAAO,EAAE;gBACP,aAAa;aACd;YACD,QAAQ,EAAE,EAAE;YACZ,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,CAAC;YAClB,SAAS,EAAE,CAAC;SACb,CAAA;QAED,IAAI,IAAI,GAAG,SAAS,IAAI,SAAS,CAAA;QAEjC,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,IAAI,cAAc,OAAO,YAAY,CAAA;QAC3C,CAAC;QAED,IAAI,WAAW,GAA4B;YACzC;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI;aACL;SACF,CAAA;QAED,IAAI,UAAU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EAAE,KAAK;aAChB,CAAA;QACH,CAAC;IACH,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,CAAA;IACtB,CAAC;CACF"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AiServiceBase } from "../../AiService/index.js";
|
|
2
|
-
import { type ToolHandler, type ToolInfo } from "../../tools/index.js";
|
|
3
|
-
import { AgentBase } from "../AgentBase.js";
|
|
4
|
-
export type CoderAgentOptions = {
|
|
5
|
-
ai: AiServiceBase;
|
|
6
|
-
os: string;
|
|
7
|
-
toolHandler: ToolHandler;
|
|
8
|
-
tools?: ToolInfo[];
|
|
9
|
-
customInstructions?: string[];
|
|
10
|
-
commands?: Record<string, string | {
|
|
11
|
-
command: string;
|
|
12
|
-
description: string;
|
|
13
|
-
}>;
|
|
14
|
-
};
|
|
15
|
-
export declare class CoderAgent extends AgentBase {
|
|
16
|
-
constructor(options: CoderAgentOptions);
|
|
17
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { createServiceLogger } from "../../logger.js";
|
|
2
|
-
import { allTools } from "../../tools/index.js";
|
|
3
|
-
import { AgentBase } from "../AgentBase.js";
|
|
4
|
-
import { fullSystemPrompt } from "./prompts.js";
|
|
5
|
-
const defaultTools = [
|
|
6
|
-
allTools.executeCommand,
|
|
7
|
-
allTools.readFile,
|
|
8
|
-
allTools.writeToFile,
|
|
9
|
-
allTools.replaceInFile,
|
|
10
|
-
allTools.searchFiles,
|
|
11
|
-
allTools.listFiles,
|
|
12
|
-
allTools.listCodeDefinitionNames,
|
|
13
|
-
// allTools.askFollowupQuestion,
|
|
14
|
-
allTools.attemptCompletion,
|
|
15
|
-
];
|
|
16
|
-
export class CoderAgent extends AgentBase {
|
|
17
|
-
constructor(options) {
|
|
18
|
-
const tools = options.tools || defaultTools;
|
|
19
|
-
const toolNamePrefix = "tool_";
|
|
20
|
-
const systemPrompt = fullSystemPrompt({
|
|
21
|
-
os: options.os,
|
|
22
|
-
}, tools, toolNamePrefix, options.customInstructions ?? [], options.commands ?? {});
|
|
23
|
-
super(options.ai, {
|
|
24
|
-
systemPrompt,
|
|
25
|
-
tools,
|
|
26
|
-
toolNamePrefix,
|
|
27
|
-
toolHandler: options.toolHandler,
|
|
28
|
-
customInstructions: options.customInstructions,
|
|
29
|
-
}, createServiceLogger("CoderAgent"));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Agent/CoderAgent/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAmC,QAAQ,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAW5C,MAAM,YAAY,GAAG;IACnB,QAAQ,CAAC,cAAc;IACvB,QAAQ,CAAC,QAAQ;IACjB,QAAQ,CAAC,WAAW;IACpB,QAAQ,CAAC,aAAa;IACtB,QAAQ,CAAC,WAAW;IACpB,QAAQ,CAAC,SAAS;IAClB,QAAQ,CAAC,uBAAuB;IAChC,gCAAgC;IAChC,QAAQ,CAAC,iBAAiB;CAC3B,CAAA;AAED,MAAM,OAAO,UAAW,SAAQ,SAAS;IACvC,YAAY,OAA0B;QACpC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAAA;QAC3C,MAAM,cAAc,GAAG,OAAO,CAAA;QAC9B,MAAM,YAAY,GAAG,gBAAgB,CACnC;YACE,EAAE,EAAE,OAAO,CAAC,EAAE;SACf,EACD,KAAK,EACL,cAAc,EACd,OAAO,CAAC,kBAAkB,IAAI,EAAE,EAChC,OAAO,CAAC,QAAQ,IAAI,EAAE,CACvB,CAAA;QAED,KAAK,CACH,OAAO,CAAC,EAAE,EACV;YACE,YAAY;YACZ,KAAK;YACL,cAAc;YACd,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;SAC/C,EACD,mBAAmB,CAAC,YAAY,CAAC,CAClC,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ToolInfo } from "../../tools/index.js";
|
|
2
|
-
export declare const basePrompt = "You are a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.";
|
|
3
|
-
export declare const editingFilesPrompt: (toolNamePrefix: string) => string;
|
|
4
|
-
export declare const capabilities: (toolNamePrefix: string) => string;
|
|
5
|
-
export declare const rules: (toolNamePrefix: string) => string;
|
|
6
|
-
export declare const objectives: (toolNamePrefix: string) => string;
|
|
7
|
-
export declare const systemInformation: (info: {
|
|
8
|
-
os: string;
|
|
9
|
-
}) => string;
|
|
10
|
-
export declare const customInstructions: (customInstructions: string[]) => string;
|
|
11
|
-
export declare const customCommands: (commands: Record<string, string | {
|
|
12
|
-
command: string;
|
|
13
|
-
description: string;
|
|
14
|
-
}>) => string;
|
|
15
|
-
export declare const fullSystemPrompt: (info: {
|
|
16
|
-
os: string;
|
|
17
|
-
}, tools: ToolInfo[], toolNamePrefix: string, instructions: string[], commands: Record<string, string | {
|
|
18
|
-
command: string;
|
|
19
|
-
description: string;
|
|
20
|
-
}>) => string;
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// source: https://github.com/cline/cline/blob/f6c19c29a64ca84e9360df7ab2c07d128dcebe64/src/core/prompts/system.ts#L1
|
|
2
|
-
import { toolUsePrompt } from "../prompts.js";
|
|
3
|
-
// TODO: restructure the prompts to avoid duplications
|
|
4
|
-
export const basePrompt = "You are a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.";
|
|
5
|
-
export const editingFilesPrompt = (toolNamePrefix) => `
|
|
6
|
-
====
|
|
7
|
-
|
|
8
|
-
EDITING FILES
|
|
9
|
-
|
|
10
|
-
You have access to two tools for working with files: **${toolNamePrefix}write_to_file** and **${toolNamePrefix}replace_in_file**. Understanding their roles and selecting the right one for the job will help ensure efficient and accurate modifications.
|
|
11
|
-
|
|
12
|
-
# ${toolNamePrefix}write_to_file
|
|
13
|
-
|
|
14
|
-
## Purpose
|
|
15
|
-
|
|
16
|
-
- Create a new file, or overwrite the entire contents of an existing file.
|
|
17
|
-
|
|
18
|
-
## When to Use
|
|
19
|
-
|
|
20
|
-
- Initial file creation, such as when scaffolding a new project.
|
|
21
|
-
- Overwriting large boilerplate files where you want to replace the entire content at once.
|
|
22
|
-
- When the complexity or number of changes would make ${toolNamePrefix}replace_in_file unwieldy or error-prone.
|
|
23
|
-
- When you need to completely restructure a file's content or change its fundamental organization.
|
|
24
|
-
|
|
25
|
-
## Important Considerations
|
|
26
|
-
|
|
27
|
-
- Using ${toolNamePrefix}write_to_file requires providing the file’s complete final content.
|
|
28
|
-
- If you only need to make small changes to an existing file, consider using ${toolNamePrefix}replace_in_file instead to avoid unnecessarily rewriting the entire file.
|
|
29
|
-
- While ${toolNamePrefix}write_to_file should not be your default choice, don't hesitate to use it when the situation truly calls for it.
|
|
30
|
-
|
|
31
|
-
# ${toolNamePrefix}replace_in_file
|
|
32
|
-
|
|
33
|
-
## Purpose
|
|
34
|
-
|
|
35
|
-
- Make targeted edits to specific parts of an existing file without overwriting the entire file.
|
|
36
|
-
|
|
37
|
-
## When to Use
|
|
38
|
-
|
|
39
|
-
- Small, localized changes like updating a few lines, function implementations, changing variable names, modifying a section of text, etc.
|
|
40
|
-
- Targeted improvements where only specific portions of the file’s content needs to be altered.
|
|
41
|
-
- Especially useful for long files where much of the file will remain unchanged.
|
|
42
|
-
|
|
43
|
-
## Advantages
|
|
44
|
-
|
|
45
|
-
- More efficient for minor edits, since you don’t need to supply the entire file content.
|
|
46
|
-
- Reduces the chance of errors that can occur when overwriting large files.
|
|
47
|
-
|
|
48
|
-
# Choosing the Appropriate Tool
|
|
49
|
-
|
|
50
|
-
- **Default to ${toolNamePrefix}replace_in_file** for most changes. It's the safer, more precise option that minimizes potential issues.
|
|
51
|
-
- **Use ${toolNamePrefix}write_to_file** when:
|
|
52
|
-
- Creating new files
|
|
53
|
-
- The changes are so extensive that using ${toolNamePrefix}replace_in_file would be more complex or risky
|
|
54
|
-
- You need to completely reorganize or restructure a file
|
|
55
|
-
- The file is relatively small and the changes affect most of its content
|
|
56
|
-
- You're generating boilerplate or template files
|
|
57
|
-
|
|
58
|
-
# Workflow Tips
|
|
59
|
-
|
|
60
|
-
1. Before editing, assess the scope of your changes and decide which tool to use.
|
|
61
|
-
2. For targeted edits, apply ${toolNamePrefix}replace_in_file with carefully crafted SEARCH/REPLACE blocks. If you need multiple changes, you can stack multiple SEARCH/REPLACE blocks within a single ${toolNamePrefix}replace_in_file call.
|
|
62
|
-
3. For major overhauls or initial file creation, rely on ${toolNamePrefix}write_to_file.
|
|
63
|
-
4. Once the file has been edited with either ${toolNamePrefix}write_to_file or ${toolNamePrefix}replace_in_file, the system will provide you with the final state of the modified file. Use this updated content as the reference point for any subsequent SEARCH/REPLACE operations, since it reflects any auto-formatting or user-applied changes.
|
|
64
|
-
|
|
65
|
-
By thoughtfully selecting between ${toolNamePrefix}write_to_file and ${toolNamePrefix}replace_in_file, you can make your file editing process smoother, safer, and more efficient.`;
|
|
66
|
-
export const capabilities = (toolNamePrefix) => `
|
|
67
|
-
====
|
|
68
|
-
|
|
69
|
-
CAPABILITIES
|
|
70
|
-
|
|
71
|
-
- You have access to a range of tools to aid you in your work. These tools help you effectively accomplish a wide range of tasks, such as writing code, making edits or improvements to existing files, understanding the current state of a project, performing system operations, and much more.
|
|
72
|
-
- When the user initially gives you a task, a recursive list of all filepaths in the current working directory will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further.
|
|
73
|
-
- You can use ${toolNamePrefix}search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
|
|
74
|
-
- You can use the ${toolNamePrefix}list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task.
|
|
75
|
-
- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use ${toolNamePrefix}list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then ${toolNamePrefix}read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the ${toolNamePrefix}replace_in_file tool to implement changes. If you refactored code that could affect other parts of the codebase, you could use ${toolNamePrefix}search_files to ensure you update other files as needed.
|
|
76
|
-
- You can use the ${toolNamePrefix}execute_command tool to run commands on the user's computer whenever you feel it can help accomplish the user's task. When you need to execute a CLI command, you must provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, since they are more flexible and easier to run. Interactive and long-running commands are allowed, since the commands are run in the user's VSCode terminal. The user may keep commands running in the background and you will be kept updated on their status along the way. Each command you execute is run in a new terminal instance.`;
|
|
77
|
-
export const rules = (toolNamePrefix) => `
|
|
78
|
-
====
|
|
79
|
-
|
|
80
|
-
RULES
|
|
81
|
-
|
|
82
|
-
- You may use \`cd\` to enter any child directory within the current working directory. For example, \`cd myChildDir\`. But you may never move to a parent directory or any directory outside your current path. For example, do not use \`cd ..\`, \`cd /\`, or any absolute path.
|
|
83
|
-
- Always work with relative path names, and never use absolute paths.
|
|
84
|
-
- When generating code file, add a comment on top of the file indicating this file is generated by "polka.codes".
|
|
85
|
-
- When generate text file such as README.md, add a footer indicating this file is generated by "polka.codes".
|
|
86
|
-
- Before using the ${toolNamePrefix}execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory, and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command). For example, if you needed to run \`npm install\` in a project that's not in the current working directory, you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`. However, you can only cd into child directory, but never parent directory or root directory or home directory.
|
|
87
|
-
- When using the ${toolNamePrefix}search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the ${toolNamePrefix}search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use ${toolNamePrefix}read_file to examine the full context of interesting matches before using ${toolNamePrefix}replace_in_file to make informed changes.
|
|
88
|
-
- When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when creating files, as the ${toolNamePrefix}write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser.
|
|
89
|
-
- Be sure to consider the type of project (e.g. Python, JavaScript, web application) when determining the appropriate structure and files to include. Also consider what files may be most relevant to accomplishing the task, for example looking at a project's manifest file would help you understand the project's dependencies, which you could incorporate into any code you write.
|
|
90
|
-
- When making changes to code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.
|
|
91
|
-
- When you want to modify a file, use the ${toolNamePrefix}replace_in_file or ${toolNamePrefix}write_to_file tool directly with the desired changes. You do not need to display the changes before using the tool.
|
|
92
|
-
- Do not ask for more information than necessary. Use the tools provided to accomplish the user's request efficiently and effectively. When you've completed your task, you must use the ${toolNamePrefix}attempt_completion tool to present the result to the user.
|
|
93
|
-
- The user may provide a file's contents directly in their message, in which case you shouldn't use the ${toolNamePrefix}read_file tool to get the file contents again since you already have it.
|
|
94
|
-
- Your goal is to try to accomplish the user's task, NOT engage in a back and forth conversation.
|
|
95
|
-
- NEVER end ${toolNamePrefix}attempt_completion result with a question or request to engage in further conversation! Formulate the end of your result in a way that is final and does not require further input from the user.
|
|
96
|
-
- You are STRICTLY FORBIDDEN from starting your messages with "Great", "Certainly", "Okay", "Sure". You should NOT be conversational in your responses, but rather direct and to the point. For example you should NOT say "Great, I've updated the CSS" but instead something like "I've updated the CSS". It is important you be clear and technical in your messages.
|
|
97
|
-
- When presented with images, utilize your vision capabilities to thoroughly examine them and extract meaningful information. Incorporate these insights into your thought process as you accomplish the user's task.
|
|
98
|
-
- When using the ${toolNamePrefix}replace_in_file tool, you must include complete lines in your SEARCH blocks, not partial lines. The system requires exact line matches and cannot match partial lines. For example, if you want to match a line containing "const x = 5;", your SEARCH block must include the entire line, not just "x = 5" or other fragments.
|
|
99
|
-
- When using the ${toolNamePrefix}replace_in_file tool, if you use multiple SEARCH/REPLACE blocks, list them in the order they appear in the file. For example if you need to make changes to both line 10 and line 50, first include the SEARCH/REPLACE block for line 10, followed by the SEARCH/REPLACE block for line 50.
|
|
100
|
-
- It is critical you wait for the user's response after each tool use, in order to confirm the success of the tool use. For example, if asked to make a todo app, you would create a file, wait for the user's response it was created successfully, then create another file if needed, wait for the user's response it was created successfully, etc.`;
|
|
101
|
-
export const objectives = (toolNamePrefix) => `
|
|
102
|
-
====
|
|
103
|
-
|
|
104
|
-
OBJECTIVE
|
|
105
|
-
|
|
106
|
-
You accomplish a given task iteratively, breaking it down into clear steps and working through them methodically.
|
|
107
|
-
|
|
108
|
-
1. Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order.
|
|
109
|
-
2. Work through these goals sequentially, utilizing available tools one at a time as necessary. Each goal should correspond to a distinct step in your problem-solving process. You will be informed on the work completed and what's remaining as you go.
|
|
110
|
-
3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within <thinking></thinking> tags. First, analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Then, think about which of the provided tools is the most relevant tool to accomplish the user's task. Next, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use.
|
|
111
|
-
4. Once you've completed the user's task, you must use the ${toolNamePrefix}attempt_completion tool to present the result of the task to the user.
|
|
112
|
-
5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.`;
|
|
113
|
-
export const systemInformation = (info) => `
|
|
114
|
-
====
|
|
115
|
-
|
|
116
|
-
SYSTEM INFORMATION
|
|
117
|
-
|
|
118
|
-
Operating System: ${info.os}`;
|
|
119
|
-
export const customInstructions = (customInstructions) => {
|
|
120
|
-
const joined = customInstructions.join("\n");
|
|
121
|
-
if (joined.trim() === "") {
|
|
122
|
-
return "";
|
|
123
|
-
}
|
|
124
|
-
return `
|
|
125
|
-
====
|
|
126
|
-
|
|
127
|
-
USER'S CUSTOM INSTRUCTIONS
|
|
128
|
-
|
|
129
|
-
The following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.
|
|
130
|
-
|
|
131
|
-
${joined}`;
|
|
132
|
-
};
|
|
133
|
-
export const customCommands = (commands) => {
|
|
134
|
-
const joined = Object.entries(commands)
|
|
135
|
-
.map(([name, command]) => {
|
|
136
|
-
if (typeof command === "string") {
|
|
137
|
-
return `- ${name}\n - Command: \`${command}\``;
|
|
138
|
-
}
|
|
139
|
-
return `- ${name}\n - Command: \`${command.command}\`\n - Description: ${command.description}`;
|
|
140
|
-
})
|
|
141
|
-
.join("\n");
|
|
142
|
-
if (joined.trim() === "") {
|
|
143
|
-
return "";
|
|
144
|
-
}
|
|
145
|
-
return `
|
|
146
|
-
====
|
|
147
|
-
|
|
148
|
-
USER'S CUSTOM COMMANDS
|
|
149
|
-
|
|
150
|
-
The following additional commands are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.
|
|
151
|
-
|
|
152
|
-
${joined}`;
|
|
153
|
-
};
|
|
154
|
-
export const fullSystemPrompt = (info, tools, toolNamePrefix, instructions, commands) => `
|
|
155
|
-
${basePrompt}
|
|
156
|
-
${toolUsePrompt(tools, toolNamePrefix)}
|
|
157
|
-
${editingFilesPrompt(toolNamePrefix)}
|
|
158
|
-
${capabilities(toolNamePrefix)}
|
|
159
|
-
${rules(toolNamePrefix)}
|
|
160
|
-
${objectives(toolNamePrefix)}
|
|
161
|
-
${systemInformation(info)}
|
|
162
|
-
${customInstructions(instructions)}
|
|
163
|
-
${customCommands(commands)}
|
|
164
|
-
`;
|
|
165
|
-
//# sourceMappingURL=prompts.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/Agent/CoderAgent/prompts.ts"],"names":[],"mappings":"AAAA,qHAAqH;AAGrH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,sDAAsD;AAEtD,MAAM,CAAC,MAAM,UAAU,GACrB,qJAAqJ,CAAA;AAEvJ,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,cAAsB,EAAE,EAAE,CAAC;;;;;yDAKL,cAAc,yBAAyB,cAAc;;IAE1G,cAAc;;;;;;;;;;wDAUsC,cAAc;;;;;UAK5D,cAAc;+EACuD,cAAc;UACnF,cAAc;;IAEpB,cAAc;;;;;;;;;;;;;;;;;;;iBAmBD,cAAc;UACrB,cAAc;;8CAEsB,cAAc;;;;;;;;+BAQ7B,cAAc,4JAA4J,cAAc;2DAC5J,cAAc;+CAC1B,cAAc,oBAAoB,cAAc;;oCAE3D,cAAc,qBAAqB,cAAc,8FAA8F,CAAA;AAEnL,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,cAAsB,EAAE,EAAE,CAAC;;;;;;;gBAOxC,cAAc;oBACV,cAAc;+KAC6I,cAAc,mIAAmI,cAAc,wIAAwI,cAAc,kIAAkI,cAAc;oBAChmB,cAAc,inBAAinB,CAAA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IACb,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACzB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,OAAO;;;;;;;EAOP,MAAM,EAAE,CAAA;AACV,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,IAAoB,EACpB,KAAiB,EACjB,cAAsB,EACtB,YAAsB,EACtB,QAA2E,EAC3E,EAAE,CAAC;EACH,UAAU;EACV,aAAa,CAAC,KAAK,EAAE,cAAc,CAAC;EACpC,kBAAkB,CAAC,cAAc,CAAC;EAClC,YAAY,CAAC,cAAc,CAAC;EAC5B,KAAK,CAAC,cAAc,CAAC;EACrB,UAAU,CAAC,cAAc,CAAC;EAC1B,iBAAiB,CAAC,IAAI,CAAC;EACvB,kBAAkB,CAAC,YAAY,CAAC;EAChC,cAAc,CAAC,QAAQ,CAAC;CACzB,CAAA"}
|
package/dist/Agent/index.d.ts
DELETED
package/dist/Agent/index.js
DELETED
package/dist/Agent/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Agent/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ToolInfo } from "../tools/index.js";
|
|
2
|
-
export interface TextContent {
|
|
3
|
-
type: "text";
|
|
4
|
-
content: string;
|
|
5
|
-
}
|
|
6
|
-
export interface ToolUse {
|
|
7
|
-
type: "tool_use";
|
|
8
|
-
name: string;
|
|
9
|
-
params: Record<string, string>;
|
|
10
|
-
}
|
|
11
|
-
export type AssistantMessageContent = TextContent | ToolUse;
|
|
12
|
-
/**
|
|
13
|
-
* Parse an assistant's message into an array of text content and tool use content.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* const tools = [
|
|
17
|
-
* {
|
|
18
|
-
* name: "search",
|
|
19
|
-
* parameters: [
|
|
20
|
-
* {name: "query", type: "string"}
|
|
21
|
-
* ]
|
|
22
|
-
* }
|
|
23
|
-
* ]
|
|
24
|
-
*
|
|
25
|
-
* // Text only
|
|
26
|
-
* parseAssistantMessage("Hello world", tools, "tool_")
|
|
27
|
-
* // Returns: [{type: "text", content: "Hello world"}]
|
|
28
|
-
*
|
|
29
|
-
* // Tool use with parameters
|
|
30
|
-
* parseAssistantMessage(
|
|
31
|
-
* `Let me search that for you
|
|
32
|
-
* <tool_search>
|
|
33
|
-
* <tool_parameter_query>cats</tool_parameter_query>
|
|
34
|
-
* </tool_search>
|
|
35
|
-
* Here are the results`,
|
|
36
|
-
* tools,
|
|
37
|
-
* "tool_"
|
|
38
|
-
* )
|
|
39
|
-
* // Returns: [
|
|
40
|
-
* // {type: "text", content: "Let me search that for you"},
|
|
41
|
-
* // {type: "tool_use", name: "search", params: {query: "cats"}},
|
|
42
|
-
* // {type: "text", content: "Here are the results"}
|
|
43
|
-
* // ]
|
|
44
|
-
*/
|
|
45
|
-
export declare function parseAssistantMessage(assistantMessage: string, tools: ToolInfo[], toolNamePrefix: string): AssistantMessageContent[];
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse an assistant's message into an array of text content and tool use content.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* const tools = [
|
|
6
|
-
* {
|
|
7
|
-
* name: "search",
|
|
8
|
-
* parameters: [
|
|
9
|
-
* {name: "query", type: "string"}
|
|
10
|
-
* ]
|
|
11
|
-
* }
|
|
12
|
-
* ]
|
|
13
|
-
*
|
|
14
|
-
* // Text only
|
|
15
|
-
* parseAssistantMessage("Hello world", tools, "tool_")
|
|
16
|
-
* // Returns: [{type: "text", content: "Hello world"}]
|
|
17
|
-
*
|
|
18
|
-
* // Tool use with parameters
|
|
19
|
-
* parseAssistantMessage(
|
|
20
|
-
* `Let me search that for you
|
|
21
|
-
* <tool_search>
|
|
22
|
-
* <tool_parameter_query>cats</tool_parameter_query>
|
|
23
|
-
* </tool_search>
|
|
24
|
-
* Here are the results`,
|
|
25
|
-
* tools,
|
|
26
|
-
* "tool_"
|
|
27
|
-
* )
|
|
28
|
-
* // Returns: [
|
|
29
|
-
* // {type: "text", content: "Let me search that for you"},
|
|
30
|
-
* // {type: "tool_use", name: "search", params: {query: "cats"}},
|
|
31
|
-
* // {type: "text", content: "Here are the results"}
|
|
32
|
-
* // ]
|
|
33
|
-
*/
|
|
34
|
-
export function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
35
|
-
const parameterPrefix = `${toolNamePrefix}parameter_`;
|
|
36
|
-
const results = [];
|
|
37
|
-
// Generate list of possible tool tags
|
|
38
|
-
const toolTags = tools.map((tool) => `${toolNamePrefix}${tool.name}`);
|
|
39
|
-
const toolPattern = toolTags.join('|');
|
|
40
|
-
// Find the outermost tool tag by matching first opening and last closing tags
|
|
41
|
-
const tagRegex = new RegExp(`<(${toolPattern})>(.*)<\\/\\1>`, 's');
|
|
42
|
-
const match = assistantMessage.match(tagRegex);
|
|
43
|
-
if (match) {
|
|
44
|
-
// Split message into parts
|
|
45
|
-
const beforeTag = assistantMessage.slice(0, match.index).trim();
|
|
46
|
-
const fullTagContent = match[0];
|
|
47
|
-
// Add text before tag if exists
|
|
48
|
-
if (beforeTag) {
|
|
49
|
-
results.push({
|
|
50
|
-
type: 'text',
|
|
51
|
-
content: beforeTag,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
// Find which tool was used
|
|
55
|
-
const tagName = match[1];
|
|
56
|
-
const toolName = tagName.replace(toolNamePrefix, '');
|
|
57
|
-
const tool = tools.find((t) => t.name === toolName);
|
|
58
|
-
if (tool) {
|
|
59
|
-
// Parse parameters using new XML-like syntax
|
|
60
|
-
const params = {};
|
|
61
|
-
// Extract parameters while preserving nested content
|
|
62
|
-
for (const param of tool.parameters) {
|
|
63
|
-
const paramName = `${parameterPrefix}${param.name}`;
|
|
64
|
-
const escapedParamName = paramName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
65
|
-
// Match parameter content non-greedily while preserving nested content
|
|
66
|
-
const paramPattern = `<${escapedParamName}>([\\s\\S]*?)<\\/${escapedParamName}>`;
|
|
67
|
-
const paramMatch = fullTagContent.match(new RegExp(paramPattern, 's'));
|
|
68
|
-
if (paramMatch) {
|
|
69
|
-
params[param.name] = paramMatch[1].trim();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
results.push({
|
|
73
|
-
type: 'tool_use',
|
|
74
|
-
name: toolName,
|
|
75
|
-
params,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
// Unknown tool - treat as text
|
|
80
|
-
results.push({
|
|
81
|
-
type: 'text',
|
|
82
|
-
content: fullTagContent,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
// Add text after the full tag if exists
|
|
86
|
-
const afterTag = assistantMessage.slice((match.index ?? 0) + fullTagContent.length).trim();
|
|
87
|
-
if (afterTag) {
|
|
88
|
-
results.push({
|
|
89
|
-
type: 'text',
|
|
90
|
-
content: afterTag,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
// No tool tags found, treat entire message as text
|
|
96
|
-
results.push({
|
|
97
|
-
type: 'text',
|
|
98
|
-
content: assistantMessage,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return results;
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=parseAssistantMessage.js.map
|