mycto_agent 0.1.5 → 0.1.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/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +116 -170
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -170
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -696,6 +696,8 @@ type LLMStreamEvent = {
|
|
|
696
696
|
} | {
|
|
697
697
|
type: 'tool-result';
|
|
698
698
|
toolCallId: string;
|
|
699
|
+
toolName: string;
|
|
700
|
+
args: Record<string, unknown>;
|
|
699
701
|
result: unknown;
|
|
700
702
|
} | {
|
|
701
703
|
type: 'finish';
|
|
@@ -957,13 +959,13 @@ declare class OpenAgent {
|
|
|
957
959
|
*/
|
|
958
960
|
private executeTool;
|
|
959
961
|
/**
|
|
960
|
-
*
|
|
962
|
+
* 非流式对话(AI SDK 自动多步)
|
|
961
963
|
*/
|
|
962
964
|
chat(message: string, options?: {
|
|
963
965
|
sessionId?: string;
|
|
964
966
|
}): Promise<ChatResult>;
|
|
965
967
|
/**
|
|
966
|
-
*
|
|
968
|
+
* 流式对话(AI SDK 自动多步)
|
|
967
969
|
*/
|
|
968
970
|
stream(message: string, options?: {
|
|
969
971
|
sessionId?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -696,6 +696,8 @@ type LLMStreamEvent = {
|
|
|
696
696
|
} | {
|
|
697
697
|
type: 'tool-result';
|
|
698
698
|
toolCallId: string;
|
|
699
|
+
toolName: string;
|
|
700
|
+
args: Record<string, unknown>;
|
|
699
701
|
result: unknown;
|
|
700
702
|
} | {
|
|
701
703
|
type: 'finish';
|
|
@@ -957,13 +959,13 @@ declare class OpenAgent {
|
|
|
957
959
|
*/
|
|
958
960
|
private executeTool;
|
|
959
961
|
/**
|
|
960
|
-
*
|
|
962
|
+
* 非流式对话(AI SDK 自动多步)
|
|
961
963
|
*/
|
|
962
964
|
chat(message: string, options?: {
|
|
963
965
|
sessionId?: string;
|
|
964
966
|
}): Promise<ChatResult>;
|
|
965
967
|
/**
|
|
966
|
-
*
|
|
968
|
+
* 流式对话(AI SDK 自动多步)
|
|
967
969
|
*/
|
|
968
970
|
stream(message: string, options?: {
|
|
969
971
|
sessionId?: string;
|
package/dist/index.js
CHANGED
|
@@ -1313,6 +1313,8 @@ async function stream(input) {
|
|
|
1313
1313
|
yield {
|
|
1314
1314
|
type: "tool-result",
|
|
1315
1315
|
toolCallId: e.toolCallId,
|
|
1316
|
+
toolName: e.toolName,
|
|
1317
|
+
args: e.args ?? e.input ?? {},
|
|
1316
1318
|
result: e.result ?? e.output
|
|
1317
1319
|
};
|
|
1318
1320
|
break;
|
|
@@ -3483,7 +3485,7 @@ You can read, write, and edit files, search code, and execute commands.`
|
|
|
3483
3485
|
}
|
|
3484
3486
|
}
|
|
3485
3487
|
/**
|
|
3486
|
-
*
|
|
3488
|
+
* 非流式对话(AI SDK 自动多步)
|
|
3487
3489
|
*/
|
|
3488
3490
|
async chat(message, options) {
|
|
3489
3491
|
await this.ensureInitialized();
|
|
@@ -3496,90 +3498,61 @@ You can read, write, and edit files, search code, and execute commands.`
|
|
|
3496
3498
|
const msgId = `msg_${Date.now()}`;
|
|
3497
3499
|
const ctx = this.createToolContext(sessionId2, msgId);
|
|
3498
3500
|
const tools = getAIToolsForAgent(this.agent, ctx, this.mode);
|
|
3501
|
+
const messages = await getSessionMessages(sessionId2);
|
|
3502
|
+
const modelMessages = await toModelMessages(messages);
|
|
3503
|
+
const result = await stream({
|
|
3504
|
+
providerId: this.providerId,
|
|
3505
|
+
modelId: this.modelId,
|
|
3506
|
+
messages: modelMessages,
|
|
3507
|
+
system: buildSystemPrompt(this.agent),
|
|
3508
|
+
tools,
|
|
3509
|
+
temperature: this.temperature,
|
|
3510
|
+
maxOutputTokens: this.maxOutputTokens,
|
|
3511
|
+
maxSteps: this.maxSteps
|
|
3512
|
+
// AI SDK 自动处理多步
|
|
3513
|
+
});
|
|
3499
3514
|
let fullText = "";
|
|
3500
3515
|
const toolCalls = [];
|
|
3501
3516
|
let totalUsage = { input: 0, output: 0 };
|
|
3502
3517
|
let totalCost = 0;
|
|
3503
3518
|
let finishReason = "unknown";
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
// 每次只执行一步,由我们控制循环
|
|
3520
|
-
});
|
|
3521
|
-
let stepText = "";
|
|
3522
|
-
const stepToolCalls = [];
|
|
3523
|
-
for await (const event of result.fullStream) {
|
|
3524
|
-
switch (event.type) {
|
|
3525
|
-
case "text-delta":
|
|
3526
|
-
stepText += event.text;
|
|
3527
|
-
break;
|
|
3528
|
-
case "tool-call":
|
|
3529
|
-
stepToolCalls.push({
|
|
3530
|
-
id: event.toolCallId,
|
|
3531
|
-
name: event.toolName,
|
|
3532
|
-
args: event.args,
|
|
3533
|
-
status: "PENDING",
|
|
3534
|
-
providerMetadata: event.providerMetadata
|
|
3535
|
-
});
|
|
3536
|
-
break;
|
|
3537
|
-
case "finish":
|
|
3538
|
-
finishReason = event.finishReason;
|
|
3539
|
-
totalUsage.input += event.usage.tokens.input;
|
|
3540
|
-
totalUsage.output += event.usage.tokens.output;
|
|
3541
|
-
totalCost += event.usage.cost;
|
|
3542
|
-
break;
|
|
3543
|
-
}
|
|
3544
|
-
}
|
|
3545
|
-
if (stepText) {
|
|
3546
|
-
fullText += (fullText && stepText ? "\n" : "") + stepText;
|
|
3547
|
-
}
|
|
3548
|
-
if (stepToolCalls.length === 0) {
|
|
3549
|
-
if (stepText) {
|
|
3550
|
-
await batchSaveMessage({
|
|
3551
|
-
sessionId: sessionId2,
|
|
3552
|
-
role: "ASSISTANT",
|
|
3553
|
-
parts: [{ type: "TEXT", text: stepText }]
|
|
3519
|
+
const assistantParts = [];
|
|
3520
|
+
for await (const event of result.fullStream) {
|
|
3521
|
+
switch (event.type) {
|
|
3522
|
+
case "text-delta":
|
|
3523
|
+
fullText += event.text;
|
|
3524
|
+
break;
|
|
3525
|
+
case "tool-call":
|
|
3526
|
+
log6.debug(`Tool call: ${event.toolName}`, { args: event.args });
|
|
3527
|
+
break;
|
|
3528
|
+
case "tool-result":
|
|
3529
|
+
toolCalls.push({
|
|
3530
|
+
name: event.toolName,
|
|
3531
|
+
input: event.args,
|
|
3532
|
+
output: String(event.result),
|
|
3533
|
+
status: "COMPLETED"
|
|
3554
3534
|
});
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
output: result2.output,
|
|
3571
|
-
status: "COMPLETED"
|
|
3572
|
-
});
|
|
3573
|
-
assistantParts.push({
|
|
3574
|
-
type: "TOOL",
|
|
3575
|
-
toolName: call.name,
|
|
3576
|
-
toolCallId: call.id,
|
|
3577
|
-
toolInput: call.args,
|
|
3578
|
-
toolOutput: result2.output,
|
|
3579
|
-
toolStatus: "COMPLETED",
|
|
3580
|
-
toolMeta: call.providerMetadata
|
|
3581
|
-
});
|
|
3535
|
+
assistantParts.push({
|
|
3536
|
+
type: "TOOL",
|
|
3537
|
+
toolName: event.toolName,
|
|
3538
|
+
toolCallId: event.toolCallId,
|
|
3539
|
+
toolInput: event.args,
|
|
3540
|
+
toolOutput: String(event.result),
|
|
3541
|
+
toolStatus: "COMPLETED"
|
|
3542
|
+
});
|
|
3543
|
+
break;
|
|
3544
|
+
case "finish":
|
|
3545
|
+
finishReason = event.finishReason;
|
|
3546
|
+
totalUsage.input += event.usage.tokens.input;
|
|
3547
|
+
totalUsage.output += event.usage.tokens.output;
|
|
3548
|
+
totalCost += event.usage.cost;
|
|
3549
|
+
break;
|
|
3582
3550
|
}
|
|
3551
|
+
}
|
|
3552
|
+
if (fullText) {
|
|
3553
|
+
assistantParts.unshift({ type: "TEXT", text: fullText });
|
|
3554
|
+
}
|
|
3555
|
+
if (assistantParts.length > 0) {
|
|
3583
3556
|
await batchSaveMessage({
|
|
3584
3557
|
sessionId: sessionId2,
|
|
3585
3558
|
role: "ASSISTANT",
|
|
@@ -3596,7 +3569,7 @@ You can read, write, and edit files, search code, and execute commands.`
|
|
|
3596
3569
|
};
|
|
3597
3570
|
}
|
|
3598
3571
|
/**
|
|
3599
|
-
*
|
|
3572
|
+
* 流式对话(AI SDK 自动多步)
|
|
3600
3573
|
*/
|
|
3601
3574
|
async *stream(message, options) {
|
|
3602
3575
|
await this.ensureInitialized();
|
|
@@ -3609,105 +3582,78 @@ You can read, write, and edit files, search code, and execute commands.`
|
|
|
3609
3582
|
const msgId = `msg_${Date.now()}`;
|
|
3610
3583
|
const ctx = this.createToolContext(sessionId2, msgId);
|
|
3611
3584
|
const tools = getAIToolsForAgent(this.agent, ctx, this.mode);
|
|
3585
|
+
const messages = await getSessionMessages(sessionId2);
|
|
3586
|
+
const modelMessages = await toModelMessages(messages);
|
|
3612
3587
|
let fullText = "";
|
|
3613
3588
|
const toolCalls = [];
|
|
3614
3589
|
let totalUsage = { input: 0, output: 0 };
|
|
3615
3590
|
let totalCost = 0;
|
|
3616
3591
|
let finishReason = "unknown";
|
|
3617
|
-
|
|
3592
|
+
const assistantParts = [];
|
|
3618
3593
|
try {
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
yield {
|
|
3653
|
-
type: "tool-start",
|
|
3654
|
-
name: event.toolName,
|
|
3655
|
-
input: event.args
|
|
3656
|
-
};
|
|
3657
|
-
break;
|
|
3658
|
-
case "finish":
|
|
3659
|
-
finishReason = event.finishReason;
|
|
3660
|
-
totalUsage.input += event.usage.tokens.input;
|
|
3661
|
-
totalUsage.output += event.usage.tokens.output;
|
|
3662
|
-
totalCost += event.usage.cost;
|
|
3663
|
-
break;
|
|
3664
|
-
case "error":
|
|
3665
|
-
yield { type: "error", error: event.error };
|
|
3666
|
-
return;
|
|
3667
|
-
}
|
|
3668
|
-
}
|
|
3669
|
-
if (stepText) {
|
|
3670
|
-
fullText += (fullText && stepText ? "\n" : "") + stepText;
|
|
3671
|
-
}
|
|
3672
|
-
if (stepToolCalls.length === 0) {
|
|
3673
|
-
if (stepText) {
|
|
3674
|
-
await batchSaveMessage({
|
|
3675
|
-
sessionId: sessionId2,
|
|
3676
|
-
role: "ASSISTANT",
|
|
3677
|
-
parts: [{ type: "TEXT", text: stepText }]
|
|
3594
|
+
const result = await stream({
|
|
3595
|
+
providerId: this.providerId,
|
|
3596
|
+
modelId: this.modelId,
|
|
3597
|
+
messages: modelMessages,
|
|
3598
|
+
system: buildSystemPrompt(this.agent),
|
|
3599
|
+
tools,
|
|
3600
|
+
temperature: this.temperature,
|
|
3601
|
+
maxOutputTokens: this.maxOutputTokens,
|
|
3602
|
+
maxSteps: this.maxSteps
|
|
3603
|
+
// AI SDK 自动处理多步
|
|
3604
|
+
});
|
|
3605
|
+
for await (const event of result.fullStream) {
|
|
3606
|
+
switch (event.type) {
|
|
3607
|
+
case "text-delta":
|
|
3608
|
+
fullText += event.text;
|
|
3609
|
+
yield { type: "text", text: event.text };
|
|
3610
|
+
break;
|
|
3611
|
+
case "reasoning-delta":
|
|
3612
|
+
yield { type: "reasoning", text: event.text };
|
|
3613
|
+
break;
|
|
3614
|
+
case "tool-call":
|
|
3615
|
+
yield {
|
|
3616
|
+
type: "tool-start",
|
|
3617
|
+
name: event.toolName,
|
|
3618
|
+
input: event.args
|
|
3619
|
+
};
|
|
3620
|
+
break;
|
|
3621
|
+
case "tool-result":
|
|
3622
|
+
toolCalls.push({
|
|
3623
|
+
name: event.toolName,
|
|
3624
|
+
input: event.args,
|
|
3625
|
+
output: String(event.result),
|
|
3626
|
+
status: "COMPLETED"
|
|
3678
3627
|
});
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
type: "TOOL",
|
|
3703
|
-
toolName: call.name,
|
|
3704
|
-
toolCallId: call.id,
|
|
3705
|
-
toolInput: call.args,
|
|
3706
|
-
toolOutput: toolResult.output,
|
|
3707
|
-
toolStatus: "COMPLETED",
|
|
3708
|
-
toolMeta: call.providerMetadata
|
|
3709
|
-
});
|
|
3628
|
+
assistantParts.push({
|
|
3629
|
+
type: "TOOL",
|
|
3630
|
+
toolName: event.toolName,
|
|
3631
|
+
toolCallId: event.toolCallId,
|
|
3632
|
+
toolInput: event.args,
|
|
3633
|
+
toolOutput: String(event.result),
|
|
3634
|
+
toolStatus: "COMPLETED"
|
|
3635
|
+
});
|
|
3636
|
+
yield {
|
|
3637
|
+
type: "tool-end",
|
|
3638
|
+
name: event.toolName,
|
|
3639
|
+
output: String(event.result)
|
|
3640
|
+
};
|
|
3641
|
+
break;
|
|
3642
|
+
case "finish":
|
|
3643
|
+
finishReason = event.finishReason;
|
|
3644
|
+
totalUsage.input += event.usage.tokens.input;
|
|
3645
|
+
totalUsage.output += event.usage.tokens.output;
|
|
3646
|
+
totalCost += event.usage.cost;
|
|
3647
|
+
break;
|
|
3648
|
+
case "error":
|
|
3649
|
+
yield { type: "error", error: event.error };
|
|
3650
|
+
return;
|
|
3710
3651
|
}
|
|
3652
|
+
}
|
|
3653
|
+
if (fullText) {
|
|
3654
|
+
assistantParts.unshift({ type: "TEXT", text: fullText });
|
|
3655
|
+
}
|
|
3656
|
+
if (assistantParts.length > 0) {
|
|
3711
3657
|
await batchSaveMessage({
|
|
3712
3658
|
sessionId: sessionId2,
|
|
3713
3659
|
role: "ASSISTANT",
|