opencara 0.108.2 → 0.109.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/bin.js +1 -1
- package/dist/claude-acp.js +115 -26
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1312,7 +1312,7 @@ function resolveLocalAcpAdapter(command, args) {
|
|
|
1312
1312
|
}
|
|
1313
1313
|
|
|
1314
1314
|
// src/commands/run.ts
|
|
1315
|
-
var PKG_VERSION = "0.
|
|
1315
|
+
var PKG_VERSION = "0.109.0";
|
|
1316
1316
|
var LOG_FLUSH_MS = 800;
|
|
1317
1317
|
var MAX_CHUNK_SIZE = 4 * 1024;
|
|
1318
1318
|
async function run(opts = {}) {
|
package/dist/claude-acp.js
CHANGED
|
@@ -182,27 +182,43 @@ async function runClaudeTurn(sessionId, state, promptText, permissionMode) {
|
|
|
182
182
|
});
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
|
|
185
|
+
function translateClaudeEvent(sessionId, raw) {
|
|
186
|
+
const out = [];
|
|
187
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
188
|
+
return { notifications: out };
|
|
189
|
+
}
|
|
187
190
|
const msg = raw;
|
|
188
191
|
const type = typeof msg["type"] === "string" ? msg["type"] : "";
|
|
189
192
|
if (type === "assistant") {
|
|
190
|
-
|
|
193
|
+
const message = msg["message"];
|
|
194
|
+
if (message && typeof message === "object" && !Array.isArray(message)) {
|
|
195
|
+
const content = message.content;
|
|
196
|
+
if (Array.isArray(content)) {
|
|
197
|
+
for (const block of content) {
|
|
198
|
+
const translated = translateAssistantBlock(sessionId, block);
|
|
199
|
+
if (translated) out.push(...translated);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return { notifications: out };
|
|
191
204
|
}
|
|
192
205
|
if (type === "stream_event") {
|
|
193
206
|
const event = msg["event"];
|
|
194
|
-
if (event?.type !== "content_block_delta") return;
|
|
195
|
-
if (event.delta?.type !== "text_delta") return;
|
|
207
|
+
if (event?.type !== "content_block_delta") return { notifications: out };
|
|
208
|
+
if (event.delta?.type !== "text_delta") return { notifications: out };
|
|
196
209
|
const text = typeof event.delta.text === "string" ? event.delta.text : "";
|
|
197
|
-
if (text.length === 0) return;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
210
|
+
if (text.length === 0) return { notifications: out };
|
|
211
|
+
out.push({
|
|
212
|
+
method: "session/update",
|
|
213
|
+
params: {
|
|
214
|
+
sessionId,
|
|
215
|
+
update: {
|
|
216
|
+
sessionUpdate: "agent_message_chunk",
|
|
217
|
+
content: { type: "text", text }
|
|
218
|
+
}
|
|
203
219
|
}
|
|
204
220
|
});
|
|
205
|
-
return;
|
|
221
|
+
return { notifications: out };
|
|
206
222
|
}
|
|
207
223
|
if (type === "result") {
|
|
208
224
|
const subtype = typeof msg["subtype"] === "string" ? msg["subtype"] : "";
|
|
@@ -210,30 +226,102 @@ function handleClaudeEvent(sessionId, raw, done) {
|
|
|
210
226
|
if (isError) {
|
|
211
227
|
const resultText = typeof msg["result"] === "string" ? msg["result"] : "";
|
|
212
228
|
if (resultText.length > 0) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
229
|
+
out.push({
|
|
230
|
+
method: "session/update",
|
|
231
|
+
params: {
|
|
232
|
+
sessionId,
|
|
233
|
+
update: {
|
|
234
|
+
sessionUpdate: "agent_message_chunk",
|
|
235
|
+
content: { type: "text", text: `
|
|
218
236
|
|
|
219
237
|
[claude error: ${resultText}]` }
|
|
238
|
+
}
|
|
220
239
|
}
|
|
221
240
|
});
|
|
222
241
|
}
|
|
223
|
-
|
|
224
|
-
return;
|
|
242
|
+
return { notifications: out, stopReason: "refusal" };
|
|
225
243
|
}
|
|
226
244
|
if (subtype === "error_max_turns") {
|
|
227
|
-
|
|
228
|
-
return;
|
|
245
|
+
return { notifications: out, stopReason: "max_turn_requests" };
|
|
229
246
|
}
|
|
230
247
|
if (subtype === "error_max_tokens") {
|
|
231
|
-
|
|
232
|
-
return;
|
|
248
|
+
return { notifications: out, stopReason: "max_tokens" };
|
|
233
249
|
}
|
|
234
|
-
|
|
235
|
-
|
|
250
|
+
return { notifications: out, stopReason: "end_turn" };
|
|
251
|
+
}
|
|
252
|
+
return { notifications: out };
|
|
253
|
+
}
|
|
254
|
+
function translateAssistantBlock(sessionId, block) {
|
|
255
|
+
if (!block || typeof block !== "object" || Array.isArray(block)) return null;
|
|
256
|
+
const b = block;
|
|
257
|
+
if (b["type"] !== "tool_use") return null;
|
|
258
|
+
if (b["name"] !== "AskUserQuestion") return null;
|
|
259
|
+
const input = b["input"];
|
|
260
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return null;
|
|
261
|
+
const questions = input.questions;
|
|
262
|
+
if (!Array.isArray(questions)) return null;
|
|
263
|
+
const chunks = [];
|
|
264
|
+
for (const q of questions) {
|
|
265
|
+
const rendered = renderAskUserQuestionItem(q);
|
|
266
|
+
if (rendered) chunks.push(rendered);
|
|
236
267
|
}
|
|
268
|
+
if (chunks.length === 0) return null;
|
|
269
|
+
const text = `
|
|
270
|
+
|
|
271
|
+
${chunks.join("\n\n")}
|
|
272
|
+
`;
|
|
273
|
+
return [
|
|
274
|
+
{
|
|
275
|
+
method: "session/update",
|
|
276
|
+
params: {
|
|
277
|
+
sessionId,
|
|
278
|
+
update: {
|
|
279
|
+
sessionUpdate: "agent_message_chunk",
|
|
280
|
+
content: { type: "text", text }
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
];
|
|
285
|
+
}
|
|
286
|
+
function renderAskUserQuestionItem(raw) {
|
|
287
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
288
|
+
const q = raw;
|
|
289
|
+
const question = typeof q["question"] === "string" ? q["question"].trim() : "";
|
|
290
|
+
if (!question) return null;
|
|
291
|
+
const header = typeof q["header"] === "string" ? q["header"].trim() : "";
|
|
292
|
+
const multiSelect = q["multiSelect"] === true;
|
|
293
|
+
const rawOptions = Array.isArray(q["options"]) ? q["options"] : [];
|
|
294
|
+
const options = [];
|
|
295
|
+
for (const opt of rawOptions) {
|
|
296
|
+
if (!opt || typeof opt !== "object" || Array.isArray(opt)) continue;
|
|
297
|
+
const o = opt;
|
|
298
|
+
const label = typeof o["label"] === "string" ? o["label"].trim() : "";
|
|
299
|
+
if (!label) continue;
|
|
300
|
+
const value = header ? `${header}: ${label}` : label;
|
|
301
|
+
options.push({ label, value });
|
|
302
|
+
}
|
|
303
|
+
if (options.length === 0) return null;
|
|
304
|
+
const promptParts = [`**${question}**`];
|
|
305
|
+
if (multiSelect) {
|
|
306
|
+
promptParts.push(
|
|
307
|
+
"_(Multiple answers expected \u2014 click one, then type any others.)_"
|
|
308
|
+
);
|
|
309
|
+
} else {
|
|
310
|
+
promptParts.push(
|
|
311
|
+
"_(Pick an option, or type your own answer below.)_"
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
const payload = {
|
|
315
|
+
type: "options",
|
|
316
|
+
text: promptParts.join(" "),
|
|
317
|
+
options
|
|
318
|
+
};
|
|
319
|
+
return "```json\n" + JSON.stringify(payload, null, 2) + "\n```";
|
|
320
|
+
}
|
|
321
|
+
function handleClaudeEvent(sessionId, raw, done) {
|
|
322
|
+
const { notifications, stopReason } = translateClaudeEvent(sessionId, raw);
|
|
323
|
+
for (const n of notifications) notify(n.method, n.params);
|
|
324
|
+
if (stopReason) done(stopReason);
|
|
237
325
|
}
|
|
238
326
|
function handleInitialize(_params) {
|
|
239
327
|
return {
|
|
@@ -376,5 +464,6 @@ export {
|
|
|
376
464
|
handleInitialize,
|
|
377
465
|
handleLoadSession,
|
|
378
466
|
handleNewSession,
|
|
379
|
-
sessions
|
|
467
|
+
sessions,
|
|
468
|
+
translateClaudeEvent
|
|
380
469
|
};
|