@fangyb/ahchat-bridge 0.1.38 → 0.1.39
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/cli.cjs +42 -3
- package/dist/index.js +42 -3
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -117376,6 +117376,29 @@ function extractTodosFromInput(input) {
|
|
|
117376
117376
|
function isObjectRecord(value) {
|
|
117377
117377
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
117378
117378
|
}
|
|
117379
|
+
function readString(value) {
|
|
117380
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
117381
|
+
}
|
|
117382
|
+
function findToolNameByUseId(contentBlocks, toolUseId) {
|
|
117383
|
+
if (!toolUseId) return null;
|
|
117384
|
+
for (let i = contentBlocks.length - 1; i >= 0; i--) {
|
|
117385
|
+
const block = contentBlocks[i];
|
|
117386
|
+
if (block.type === "tool_use" && block.toolUseId === toolUseId) {
|
|
117387
|
+
return block.toolName;
|
|
117388
|
+
}
|
|
117389
|
+
}
|
|
117390
|
+
return null;
|
|
117391
|
+
}
|
|
117392
|
+
function findToolUseBlockById(contentBlocks, toolUseId) {
|
|
117393
|
+
if (!toolUseId) return null;
|
|
117394
|
+
for (let i = contentBlocks.length - 1; i >= 0; i--) {
|
|
117395
|
+
const block = contentBlocks[i];
|
|
117396
|
+
if (block.type === "tool_use" && block.toolUseId === toolUseId) {
|
|
117397
|
+
return block;
|
|
117398
|
+
}
|
|
117399
|
+
}
|
|
117400
|
+
return null;
|
|
117401
|
+
}
|
|
117379
117402
|
function readTrimmedString(input, key) {
|
|
117380
117403
|
const value = input[key];
|
|
117381
117404
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
@@ -117648,9 +117671,11 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117648
117671
|
} else if (block.type === "tool_use") {
|
|
117649
117672
|
proc.currentBlockType = "tool_use";
|
|
117650
117673
|
proc.currentToolName = block.name ?? "unknown";
|
|
117674
|
+
proc.currentToolUseId = readString(block.id);
|
|
117651
117675
|
proc.activeToolUseStartedAt = Date.now();
|
|
117652
117676
|
proc.accumulatedToolInput = "";
|
|
117653
117677
|
const toolName = block.name ?? "unknown";
|
|
117678
|
+
const toolUseId = proc.currentToolUseId;
|
|
117654
117679
|
proc.suppressCurrentToolUse = proc.officialMediaGenerationSatisfied === true && isOfficialMediaGenerationToolName(toolName);
|
|
117655
117680
|
const isMcpTool = parseMcpRuntimeToolName(toolName) != null;
|
|
117656
117681
|
proc.currentMcpInvocationId = isMcpTool ? createMcpToolInvocationId() : null;
|
|
@@ -117660,12 +117685,14 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117660
117685
|
type: "agent:tool_use",
|
|
117661
117686
|
payload: {
|
|
117662
117687
|
...wireBase(base),
|
|
117688
|
+
...toolUseId ? { toolUseId } : {},
|
|
117663
117689
|
toolName,
|
|
117664
117690
|
input: {}
|
|
117665
117691
|
}
|
|
117666
117692
|
});
|
|
117667
117693
|
proc.contentBlocks.push({
|
|
117668
117694
|
type: "tool_use",
|
|
117695
|
+
...toolUseId ? { toolUseId } : {},
|
|
117669
117696
|
toolName,
|
|
117670
117697
|
input: {},
|
|
117671
117698
|
status: "running"
|
|
@@ -117696,6 +117723,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117696
117723
|
type: "agent:tool_input_update",
|
|
117697
117724
|
payload: {
|
|
117698
117725
|
...wireBase(base),
|
|
117726
|
+
...proc.currentToolUseId ? { toolUseId: proc.currentToolUseId } : {},
|
|
117699
117727
|
toolName: proc.currentToolName,
|
|
117700
117728
|
input: liveInput
|
|
117701
117729
|
}
|
|
@@ -117755,7 +117783,9 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117755
117783
|
}
|
|
117756
117784
|
}
|
|
117757
117785
|
if (!proc.suppressCurrentToolUse) {
|
|
117758
|
-
const lastToolUse = [...proc.contentBlocks].reverse().find(
|
|
117786
|
+
const lastToolUse = [...proc.contentBlocks].reverse().find(
|
|
117787
|
+
(bl) => bl.type === "tool_use" && (proc.currentToolUseId ? bl.toolUseId === proc.currentToolUseId : true)
|
|
117788
|
+
);
|
|
117759
117789
|
if (lastToolUse && lastToolUse.type === "tool_use") {
|
|
117760
117790
|
lastToolUse.input = parsedInput;
|
|
117761
117791
|
}
|
|
@@ -117764,6 +117794,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117764
117794
|
type: "agent:tool_input_update",
|
|
117765
117795
|
payload: {
|
|
117766
117796
|
...wireBase(base),
|
|
117797
|
+
...proc.currentToolUseId ? { toolUseId: proc.currentToolUseId } : {},
|
|
117767
117798
|
toolName: proc.currentToolName,
|
|
117768
117799
|
input: parsedInput
|
|
117769
117800
|
}
|
|
@@ -117858,6 +117889,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117858
117889
|
}
|
|
117859
117890
|
proc.suppressCurrentToolUse = false;
|
|
117860
117891
|
proc.currentBlockType = null;
|
|
117892
|
+
proc.currentToolUseId = null;
|
|
117861
117893
|
break;
|
|
117862
117894
|
}
|
|
117863
117895
|
default:
|
|
@@ -117900,7 +117932,8 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117900
117932
|
for (const block of content) {
|
|
117901
117933
|
const b = block;
|
|
117902
117934
|
if (b.type === "tool_result") {
|
|
117903
|
-
const
|
|
117935
|
+
const toolUseId = readString(b.tool_use_id);
|
|
117936
|
+
const toolName = findToolNameByUseId(proc.contentBlocks, toolUseId) ?? proc.currentToolName ?? "unknown";
|
|
117904
117937
|
const isError = toolName === "ExitPlanMode" ? false : !!b.is_error;
|
|
117905
117938
|
const output = typeof b.content === "string" ? b.content : JSON.stringify(b.content);
|
|
117906
117939
|
const duplicateOfficialMediaDeny = isError && isOfficialMediaGenerationToolName(toolName) && isOfficialMediaGenerationDuplicateDenyMessage(output);
|
|
@@ -117915,6 +117948,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117915
117948
|
proc.currentMcpInvocationStartedAt = null;
|
|
117916
117949
|
proc.activeToolUseStartedAt = void 0;
|
|
117917
117950
|
proc.currentToolName = null;
|
|
117951
|
+
proc.currentToolUseId = null;
|
|
117918
117952
|
continue;
|
|
117919
117953
|
}
|
|
117920
117954
|
if (isSuccessfulOfficialMediaOutput(toolName, output)) {
|
|
@@ -117923,6 +117957,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117923
117957
|
if (isAskUserQuestionToolName(toolName)) {
|
|
117924
117958
|
proc.activeToolUseStartedAt = void 0;
|
|
117925
117959
|
proc.currentToolName = null;
|
|
117960
|
+
proc.currentToolUseId = null;
|
|
117926
117961
|
continue;
|
|
117927
117962
|
}
|
|
117928
117963
|
if (proc.currentMcpInvocationId && parseMcpRuntimeToolName(toolName)) {
|
|
@@ -117954,6 +117989,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117954
117989
|
type: "agent:tool_result",
|
|
117955
117990
|
payload: {
|
|
117956
117991
|
...wireBase(base),
|
|
117992
|
+
...toolUseId ? { toolUseId } : {},
|
|
117957
117993
|
toolName,
|
|
117958
117994
|
output,
|
|
117959
117995
|
isError
|
|
@@ -117961,11 +117997,12 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117961
117997
|
});
|
|
117962
117998
|
proc.contentBlocks.push({
|
|
117963
117999
|
type: "tool_result",
|
|
118000
|
+
...toolUseId ? { toolUseId } : {},
|
|
117964
118001
|
toolName,
|
|
117965
118002
|
output,
|
|
117966
118003
|
isError
|
|
117967
118004
|
});
|
|
117968
|
-
const lastToolUse = [...proc.contentBlocks].reverse().find((bl) => bl.type === "tool_use");
|
|
118005
|
+
const lastToolUse = findToolUseBlockById(proc.contentBlocks, toolUseId) ?? [...proc.contentBlocks].reverse().find((bl) => bl.type === "tool_use");
|
|
117969
118006
|
if (lastToolUse && lastToolUse.type === "tool_use") {
|
|
117970
118007
|
lastToolUse.status = isError ? "error" : "done";
|
|
117971
118008
|
if (lastToolUse.toolName === "ExitPlanMode") {
|
|
@@ -117974,6 +118011,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
117974
118011
|
}
|
|
117975
118012
|
}
|
|
117976
118013
|
proc.activeToolUseStartedAt = void 0;
|
|
118014
|
+
proc.currentToolUseId = null;
|
|
117977
118015
|
}
|
|
117978
118016
|
}
|
|
117979
118017
|
}
|
|
@@ -118355,6 +118393,7 @@ function resetAccumulators(proc) {
|
|
|
118355
118393
|
proc.contentBlocks = [];
|
|
118356
118394
|
proc.currentBlockType = null;
|
|
118357
118395
|
proc.currentToolName = null;
|
|
118396
|
+
proc.currentToolUseId = null;
|
|
118358
118397
|
proc.currentMcpInvocationId = null;
|
|
118359
118398
|
proc.currentMcpInvocationStartedAt = null;
|
|
118360
118399
|
proc.activeToolUseStartedAt = void 0;
|
package/dist/index.js
CHANGED
|
@@ -28601,6 +28601,29 @@ function extractTodosFromInput(input) {
|
|
|
28601
28601
|
function isObjectRecord(value) {
|
|
28602
28602
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
28603
28603
|
}
|
|
28604
|
+
function readString(value) {
|
|
28605
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
28606
|
+
}
|
|
28607
|
+
function findToolNameByUseId(contentBlocks, toolUseId) {
|
|
28608
|
+
if (!toolUseId) return null;
|
|
28609
|
+
for (let i = contentBlocks.length - 1; i >= 0; i--) {
|
|
28610
|
+
const block = contentBlocks[i];
|
|
28611
|
+
if (block.type === "tool_use" && block.toolUseId === toolUseId) {
|
|
28612
|
+
return block.toolName;
|
|
28613
|
+
}
|
|
28614
|
+
}
|
|
28615
|
+
return null;
|
|
28616
|
+
}
|
|
28617
|
+
function findToolUseBlockById(contentBlocks, toolUseId) {
|
|
28618
|
+
if (!toolUseId) return null;
|
|
28619
|
+
for (let i = contentBlocks.length - 1; i >= 0; i--) {
|
|
28620
|
+
const block = contentBlocks[i];
|
|
28621
|
+
if (block.type === "tool_use" && block.toolUseId === toolUseId) {
|
|
28622
|
+
return block;
|
|
28623
|
+
}
|
|
28624
|
+
}
|
|
28625
|
+
return null;
|
|
28626
|
+
}
|
|
28604
28627
|
function readTrimmedString(input, key) {
|
|
28605
28628
|
const value = input[key];
|
|
28606
28629
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
@@ -28873,9 +28896,11 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
28873
28896
|
} else if (block.type === "tool_use") {
|
|
28874
28897
|
proc.currentBlockType = "tool_use";
|
|
28875
28898
|
proc.currentToolName = block.name ?? "unknown";
|
|
28899
|
+
proc.currentToolUseId = readString(block.id);
|
|
28876
28900
|
proc.activeToolUseStartedAt = Date.now();
|
|
28877
28901
|
proc.accumulatedToolInput = "";
|
|
28878
28902
|
const toolName = block.name ?? "unknown";
|
|
28903
|
+
const toolUseId = proc.currentToolUseId;
|
|
28879
28904
|
proc.suppressCurrentToolUse = proc.officialMediaGenerationSatisfied === true && isOfficialMediaGenerationToolName(toolName);
|
|
28880
28905
|
const isMcpTool = parseMcpRuntimeToolName(toolName) != null;
|
|
28881
28906
|
proc.currentMcpInvocationId = isMcpTool ? createMcpToolInvocationId() : null;
|
|
@@ -28885,12 +28910,14 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
28885
28910
|
type: "agent:tool_use",
|
|
28886
28911
|
payload: {
|
|
28887
28912
|
...wireBase(base),
|
|
28913
|
+
...toolUseId ? { toolUseId } : {},
|
|
28888
28914
|
toolName,
|
|
28889
28915
|
input: {}
|
|
28890
28916
|
}
|
|
28891
28917
|
});
|
|
28892
28918
|
proc.contentBlocks.push({
|
|
28893
28919
|
type: "tool_use",
|
|
28920
|
+
...toolUseId ? { toolUseId } : {},
|
|
28894
28921
|
toolName,
|
|
28895
28922
|
input: {},
|
|
28896
28923
|
status: "running"
|
|
@@ -28921,6 +28948,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
28921
28948
|
type: "agent:tool_input_update",
|
|
28922
28949
|
payload: {
|
|
28923
28950
|
...wireBase(base),
|
|
28951
|
+
...proc.currentToolUseId ? { toolUseId: proc.currentToolUseId } : {},
|
|
28924
28952
|
toolName: proc.currentToolName,
|
|
28925
28953
|
input: liveInput
|
|
28926
28954
|
}
|
|
@@ -28980,7 +29008,9 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
28980
29008
|
}
|
|
28981
29009
|
}
|
|
28982
29010
|
if (!proc.suppressCurrentToolUse) {
|
|
28983
|
-
const lastToolUse = [...proc.contentBlocks].reverse().find(
|
|
29011
|
+
const lastToolUse = [...proc.contentBlocks].reverse().find(
|
|
29012
|
+
(bl) => bl.type === "tool_use" && (proc.currentToolUseId ? bl.toolUseId === proc.currentToolUseId : true)
|
|
29013
|
+
);
|
|
28984
29014
|
if (lastToolUse && lastToolUse.type === "tool_use") {
|
|
28985
29015
|
lastToolUse.input = parsedInput;
|
|
28986
29016
|
}
|
|
@@ -28989,6 +29019,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
28989
29019
|
type: "agent:tool_input_update",
|
|
28990
29020
|
payload: {
|
|
28991
29021
|
...wireBase(base),
|
|
29022
|
+
...proc.currentToolUseId ? { toolUseId: proc.currentToolUseId } : {},
|
|
28992
29023
|
toolName: proc.currentToolName,
|
|
28993
29024
|
input: parsedInput
|
|
28994
29025
|
}
|
|
@@ -29083,6 +29114,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
29083
29114
|
}
|
|
29084
29115
|
proc.suppressCurrentToolUse = false;
|
|
29085
29116
|
proc.currentBlockType = null;
|
|
29117
|
+
proc.currentToolUseId = null;
|
|
29086
29118
|
break;
|
|
29087
29119
|
}
|
|
29088
29120
|
default:
|
|
@@ -29125,7 +29157,8 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
29125
29157
|
for (const block of content) {
|
|
29126
29158
|
const b = block;
|
|
29127
29159
|
if (b.type === "tool_result") {
|
|
29128
|
-
const
|
|
29160
|
+
const toolUseId = readString(b.tool_use_id);
|
|
29161
|
+
const toolName = findToolNameByUseId(proc.contentBlocks, toolUseId) ?? proc.currentToolName ?? "unknown";
|
|
29129
29162
|
const isError = toolName === "ExitPlanMode" ? false : !!b.is_error;
|
|
29130
29163
|
const output = typeof b.content === "string" ? b.content : JSON.stringify(b.content);
|
|
29131
29164
|
const duplicateOfficialMediaDeny = isError && isOfficialMediaGenerationToolName(toolName) && isOfficialMediaGenerationDuplicateDenyMessage(output);
|
|
@@ -29140,6 +29173,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
29140
29173
|
proc.currentMcpInvocationStartedAt = null;
|
|
29141
29174
|
proc.activeToolUseStartedAt = void 0;
|
|
29142
29175
|
proc.currentToolName = null;
|
|
29176
|
+
proc.currentToolUseId = null;
|
|
29143
29177
|
continue;
|
|
29144
29178
|
}
|
|
29145
29179
|
if (isSuccessfulOfficialMediaOutput(toolName, output)) {
|
|
@@ -29148,6 +29182,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
29148
29182
|
if (isAskUserQuestionToolName(toolName)) {
|
|
29149
29183
|
proc.activeToolUseStartedAt = void 0;
|
|
29150
29184
|
proc.currentToolName = null;
|
|
29185
|
+
proc.currentToolUseId = null;
|
|
29151
29186
|
continue;
|
|
29152
29187
|
}
|
|
29153
29188
|
if (proc.currentMcpInvocationId && parseMcpRuntimeToolName(toolName)) {
|
|
@@ -29179,6 +29214,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
29179
29214
|
type: "agent:tool_result",
|
|
29180
29215
|
payload: {
|
|
29181
29216
|
...wireBase(base),
|
|
29217
|
+
...toolUseId ? { toolUseId } : {},
|
|
29182
29218
|
toolName,
|
|
29183
29219
|
output,
|
|
29184
29220
|
isError
|
|
@@ -29186,11 +29222,12 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
29186
29222
|
});
|
|
29187
29223
|
proc.contentBlocks.push({
|
|
29188
29224
|
type: "tool_result",
|
|
29225
|
+
...toolUseId ? { toolUseId } : {},
|
|
29189
29226
|
toolName,
|
|
29190
29227
|
output,
|
|
29191
29228
|
isError
|
|
29192
29229
|
});
|
|
29193
|
-
const lastToolUse = [...proc.contentBlocks].reverse().find((bl) => bl.type === "tool_use");
|
|
29230
|
+
const lastToolUse = findToolUseBlockById(proc.contentBlocks, toolUseId) ?? [...proc.contentBlocks].reverse().find((bl) => bl.type === "tool_use");
|
|
29194
29231
|
if (lastToolUse && lastToolUse.type === "tool_use") {
|
|
29195
29232
|
lastToolUse.status = isError ? "error" : "done";
|
|
29196
29233
|
if (lastToolUse.toolName === "ExitPlanMode") {
|
|
@@ -29199,6 +29236,7 @@ function mapSDKMessage(proc, message, rawEmit, sessionStore, onCompleted, onPost
|
|
|
29199
29236
|
}
|
|
29200
29237
|
}
|
|
29201
29238
|
proc.activeToolUseStartedAt = void 0;
|
|
29239
|
+
proc.currentToolUseId = null;
|
|
29202
29240
|
}
|
|
29203
29241
|
}
|
|
29204
29242
|
}
|
|
@@ -29580,6 +29618,7 @@ function resetAccumulators(proc) {
|
|
|
29580
29618
|
proc.contentBlocks = [];
|
|
29581
29619
|
proc.currentBlockType = null;
|
|
29582
29620
|
proc.currentToolName = null;
|
|
29621
|
+
proc.currentToolUseId = null;
|
|
29583
29622
|
proc.currentMcpInvocationId = null;
|
|
29584
29623
|
proc.currentMcpInvocationStartedAt = null;
|
|
29585
29624
|
proc.activeToolUseStartedAt = void 0;
|