opc-agent 4.0.10 → 4.0.12
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/channels/telegram.d.ts +50 -13
- package/dist/channels/telegram.js +309 -84
- package/dist/providers/index.js +65 -25
- package/package.json +1 -1
- package/src/channels/telegram.ts +377 -94
- package/src/providers/index.ts +65 -26
package/src/providers/index.ts
CHANGED
|
@@ -410,18 +410,7 @@ class ClaudeCLIProvider implements LLMProvider {
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
async *chatStream(messages: Message[], systemPrompt?: string): AsyncIterable<string> {
|
|
413
|
-
|
|
414
|
-
const parts: string[] = [];
|
|
415
|
-
if (systemPrompt) {
|
|
416
|
-
parts.push(`[System]: ${systemPrompt}`);
|
|
417
|
-
}
|
|
418
|
-
for (const m of messages) {
|
|
419
|
-
const role = m.role === 'user' ? 'Human' : 'Assistant';
|
|
420
|
-
parts.push(`${role}: ${m.content}`);
|
|
421
|
-
}
|
|
422
|
-
const prompt = parts.join('\n\n');
|
|
423
|
-
|
|
424
|
-
const args = ['-p', '--output-format', 'text'];
|
|
413
|
+
const args = ['-p', '--output-format', 'stream-json', '--include-partial-messages'];
|
|
425
414
|
if (this.model) {
|
|
426
415
|
args.push('--model', this.model);
|
|
427
416
|
}
|
|
@@ -438,7 +427,7 @@ class ClaudeCLIProvider implements LLMProvider {
|
|
|
438
427
|
}
|
|
439
428
|
|
|
440
429
|
const lastMsg = messages[messages.length - 1];
|
|
441
|
-
args.push(lastMsg?.content ??
|
|
430
|
+
args.push(lastMsg?.content ?? '');
|
|
442
431
|
|
|
443
432
|
const { spawn } = await import('child_process');
|
|
444
433
|
|
|
@@ -449,22 +438,72 @@ class ClaudeCLIProvider implements LLMProvider {
|
|
|
449
438
|
});
|
|
450
439
|
proc.stdin.end();
|
|
451
440
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
441
|
+
let buffer = '';
|
|
442
|
+
let lastContent = '';
|
|
443
|
+
|
|
444
|
+
for await (const chunk of proc.stdout) {
|
|
445
|
+
buffer += (chunk as Buffer).toString();
|
|
446
|
+
const lines = buffer.split('\n');
|
|
447
|
+
buffer = lines.pop() ?? '';
|
|
448
|
+
|
|
449
|
+
for (const line of lines) {
|
|
450
|
+
const trimmed = line.trim();
|
|
451
|
+
if (!trimmed) continue;
|
|
452
|
+
try {
|
|
453
|
+
const event = JSON.parse(trimmed);
|
|
454
|
+
// Handle partial message chunks (content_block_delta style)
|
|
455
|
+
if (event.type === 'content' && event.content) {
|
|
456
|
+
const newContent = event.content;
|
|
457
|
+
if (newContent.length > lastContent.length) {
|
|
458
|
+
yield newContent.slice(lastContent.length);
|
|
459
|
+
lastContent = newContent;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
// Handle assistant message with content array
|
|
463
|
+
if (event.type === 'assistant' && event.message?.content) {
|
|
464
|
+
for (const block of event.message.content) {
|
|
465
|
+
if (block.type === 'text' && block.text) {
|
|
466
|
+
const newText = block.text;
|
|
467
|
+
if (newText.length > lastContent.length) {
|
|
468
|
+
yield newText.slice(lastContent.length);
|
|
469
|
+
lastContent = newText;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
// Handle result message
|
|
475
|
+
if (event.type === 'result' && event.result) {
|
|
476
|
+
const resultText = typeof event.result === 'string' ? event.result : '';
|
|
477
|
+
if (resultText && resultText.length > lastContent.length) {
|
|
478
|
+
yield resultText.slice(lastContent.length);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
} catch {
|
|
482
|
+
// Not JSON, might be raw text
|
|
483
|
+
}
|
|
484
|
+
}
|
|
456
485
|
}
|
|
457
486
|
|
|
458
|
-
//
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
487
|
+
// Process remaining buffer
|
|
488
|
+
if (buffer.trim()) {
|
|
489
|
+
try {
|
|
490
|
+
const event = JSON.parse(buffer.trim());
|
|
491
|
+
if (event.type === 'result' && event.result) {
|
|
492
|
+
const resultText = typeof event.result === 'string' ? event.result : '';
|
|
493
|
+
if (resultText && resultText.length > lastContent.length) {
|
|
494
|
+
yield resultText.slice(lastContent.length);
|
|
495
|
+
}
|
|
464
496
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
497
|
+
} catch {
|
|
498
|
+
// If not JSON, yield as raw text if we haven't yielded anything
|
|
499
|
+
if (!lastContent && buffer.trim()) {
|
|
500
|
+
yield buffer.trim();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
await new Promise<void>((resolve) => {
|
|
506
|
+
proc.on('close', () => resolve());
|
|
468
507
|
});
|
|
469
508
|
} finally {
|
|
470
509
|
if (tmpFile) {
|