acpreact 1.0.5 → 1.0.6
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/core.js +28 -27
- package/package.json +1 -1
package/core.js
CHANGED
|
@@ -23,10 +23,6 @@ class ACPProtocol extends EventEmitter {
|
|
|
23
23
|
return ++this.messageId;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
createJsonRpcRequest(method, params) {
|
|
27
|
-
return { jsonrpc: "2.0", id: this.generateRequestId(), method, params };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
26
|
createJsonRpcResponse(id, result) {
|
|
31
27
|
return { jsonrpc: "2.0", id, result };
|
|
32
28
|
}
|
|
@@ -51,6 +47,21 @@ class ACPProtocol extends EventEmitter {
|
|
|
51
47
|
}));
|
|
52
48
|
}
|
|
53
49
|
|
|
50
|
+
getToolsPrompt() {
|
|
51
|
+
const tools = this.getToolsList();
|
|
52
|
+
if (tools.length === 0) return '';
|
|
53
|
+
|
|
54
|
+
let prompt = '\n\nYou have access to the following tools. You MUST use these tools to respond:\n\n';
|
|
55
|
+
for (const tool of tools) {
|
|
56
|
+
prompt += `## Tool: ${tool.name}\n${tool.description}\n`;
|
|
57
|
+
prompt += `Parameters: ${JSON.stringify(tool.inputSchema, null, 2)}\n`;
|
|
58
|
+
prompt += `To call this tool, output a JSON-RPC request like:\n`;
|
|
59
|
+
prompt += `{"jsonrpc":"2.0","id":<unique_id>,"method":"tools/${tool.name}","params":{<parameters>}}\n\n`;
|
|
60
|
+
}
|
|
61
|
+
prompt += 'IMPORTANT: Always respond by calling a tool with a JSON-RPC request. Do not just output text.\n';
|
|
62
|
+
return prompt;
|
|
63
|
+
}
|
|
64
|
+
|
|
54
65
|
validateToolCall(toolName) {
|
|
55
66
|
if (!this.toolWhitelist.has(toolName)) {
|
|
56
67
|
const availableTools = Array.from(this.toolWhitelist);
|
|
@@ -195,17 +206,16 @@ class ACPProtocol extends EventEmitter {
|
|
|
195
206
|
}
|
|
196
207
|
|
|
197
208
|
createInitializeResponse(id) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
209
|
+
return {
|
|
210
|
+
jsonrpc: "2.0",
|
|
211
|
+
id,
|
|
212
|
+
result: {
|
|
213
|
+
protocolVersion: 1,
|
|
214
|
+
capabilities: { tools: this.getToolsList() },
|
|
215
|
+
serverInfo: { name: 'acpreact', version: '1.0.0' },
|
|
216
|
+
instruction: this.instruction,
|
|
217
|
+
}
|
|
202
218
|
};
|
|
203
|
-
|
|
204
|
-
if (this.instruction) {
|
|
205
|
-
result.instruction = this.instruction;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return { jsonrpc: "2.0", id, result };
|
|
209
219
|
}
|
|
210
220
|
|
|
211
221
|
createSession() {
|
|
@@ -220,24 +230,15 @@ class ACPProtocol extends EventEmitter {
|
|
|
220
230
|
});
|
|
221
231
|
}
|
|
222
232
|
|
|
223
|
-
getToolsDescription() {
|
|
224
|
-
const tools = this.getToolsList();
|
|
225
|
-
if (tools.length === 0) return '';
|
|
226
|
-
|
|
227
|
-
return '\n\nAvailable tools:\n' + tools.map(t =>
|
|
228
|
-
`- ${t.name}: ${t.description}\n Parameters: ${JSON.stringify(t.inputSchema)}`
|
|
229
|
-
).join('\n');
|
|
230
|
-
}
|
|
231
|
-
|
|
232
233
|
async sendPrompt(content) {
|
|
233
234
|
if (!this.sessionId) {
|
|
234
235
|
throw new Error('No session. Call start() first.');
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
const reqId = this.generateRequestId();
|
|
238
|
-
const
|
|
239
|
-
? `${this.instruction}${this.
|
|
240
|
-
: content
|
|
239
|
+
const fullPrompt = this.instruction
|
|
240
|
+
? `${this.instruction}${this.getToolsPrompt()}\n\n---\n\n${content}`
|
|
241
|
+
: `${this.getToolsPrompt()}\n\n---\n\n${content}`;
|
|
241
242
|
|
|
242
243
|
return new Promise((resolve) => {
|
|
243
244
|
this.pendingRequests.set(reqId, resolve);
|
|
@@ -247,7 +248,7 @@ class ACPProtocol extends EventEmitter {
|
|
|
247
248
|
method: "session/prompt",
|
|
248
249
|
params: {
|
|
249
250
|
sessionId: this.sessionId,
|
|
250
|
-
prompt: [{ type: "text", text:
|
|
251
|
+
prompt: [{ type: "text", text: fullPrompt }],
|
|
251
252
|
},
|
|
252
253
|
});
|
|
253
254
|
|