@kuntur/a2a-carbon-chat-adapter 0.1.6 → 0.1.7
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.cjs +73 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +73 -15
- package/dist/index.js.map +1 -1
- package/dist/server.d.cts +40 -0
- package/dist/server.d.ts +40 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -627,6 +627,8 @@ var A2AToCarbonTranslator = class {
|
|
|
627
627
|
responseId: this.generateResponseId(),
|
|
628
628
|
itemId: "1",
|
|
629
629
|
accumulatedText: "",
|
|
630
|
+
accumulatedThinking: "",
|
|
631
|
+
// Initialize empty for streaming thinking tokens
|
|
630
632
|
reasoningSteps: [],
|
|
631
633
|
chainOfThought: [],
|
|
632
634
|
pendingToolCalls: /* @__PURE__ */ new Map(),
|
|
@@ -688,6 +690,12 @@ var A2AToCarbonTranslator = class {
|
|
|
688
690
|
getAccumulatedText() {
|
|
689
691
|
return this.state.accumulatedText;
|
|
690
692
|
}
|
|
693
|
+
/**
|
|
694
|
+
* Get accumulated thinking content (for reasoning.content mode)
|
|
695
|
+
*/
|
|
696
|
+
getAccumulatedThinking() {
|
|
697
|
+
return this.state.accumulatedThinking;
|
|
698
|
+
}
|
|
691
699
|
/**
|
|
692
700
|
* Get current reasoning steps
|
|
693
701
|
*/
|
|
@@ -742,7 +750,7 @@ var A2AToCarbonTranslator = class {
|
|
|
742
750
|
}
|
|
743
751
|
};
|
|
744
752
|
if (includeReasoning) {
|
|
745
|
-
chunk.partial_response.message_options.reasoning = {
|
|
753
|
+
chunk.partial_response.message_options.reasoning = { content: "" };
|
|
746
754
|
}
|
|
747
755
|
return chunk;
|
|
748
756
|
}
|
|
@@ -860,17 +868,58 @@ var A2AToCarbonTranslator = class {
|
|
|
860
868
|
return null;
|
|
861
869
|
}
|
|
862
870
|
/**
|
|
863
|
-
* Translate thinking/reasoning content to Carbon
|
|
871
|
+
* Translate thinking/reasoning content to Carbon format
|
|
872
|
+
*
|
|
873
|
+
* ROUTING LOGIC:
|
|
874
|
+
* - content_type='thinking' (no title) → reasoning.content (streaming)
|
|
875
|
+
* - content_type='reasoning_step' WITH title → reasoning.steps[] (discrete)
|
|
864
876
|
*/
|
|
865
877
|
translateThinkingPart(text, metadata) {
|
|
866
|
-
const
|
|
878
|
+
const contentType = metadata?.content_type;
|
|
867
879
|
const stepTitle = metadata?.title;
|
|
880
|
+
if (contentType === "thinking" || !stepTitle) {
|
|
881
|
+
this.state.accumulatedThinking += text;
|
|
882
|
+
console.log("[Translator] Streaming thinking token:", {
|
|
883
|
+
tokenLength: text.length,
|
|
884
|
+
totalLength: this.state.accumulatedThinking.length
|
|
885
|
+
});
|
|
886
|
+
return {
|
|
887
|
+
partial_item: {
|
|
888
|
+
response_type: MessageResponseTypes.TEXT,
|
|
889
|
+
text: "",
|
|
890
|
+
streaming_metadata: {
|
|
891
|
+
id: this.state.itemId,
|
|
892
|
+
cancellable: true
|
|
893
|
+
}
|
|
894
|
+
},
|
|
895
|
+
partial_response: {
|
|
896
|
+
message_options: {
|
|
897
|
+
response_user_profile: this.agentProfile,
|
|
898
|
+
reasoning: {
|
|
899
|
+
content: this.state.accumulatedThinking,
|
|
900
|
+
// Stream to content
|
|
901
|
+
// Preserve any existing discrete steps
|
|
902
|
+
steps: this.state.reasoningSteps.length > 0 ? this.state.reasoningSteps : void 0
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
},
|
|
906
|
+
streaming_metadata: {
|
|
907
|
+
response_id: this.state.responseId
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
}
|
|
868
911
|
const newStep = {
|
|
869
|
-
title: stepTitle
|
|
912
|
+
title: stepTitle,
|
|
913
|
+
// No fallback - only real titles become discrete steps
|
|
870
914
|
content: text,
|
|
871
915
|
open_state: "default" /* DEFAULT */
|
|
872
916
|
};
|
|
873
917
|
this.state.reasoningSteps.push(newStep);
|
|
918
|
+
console.log("[Translator] Added discrete reasoning step:", {
|
|
919
|
+
title: stepTitle,
|
|
920
|
+
textLength: text.length,
|
|
921
|
+
totalSteps: this.state.reasoningSteps.length
|
|
922
|
+
});
|
|
874
923
|
return {
|
|
875
924
|
partial_item: {
|
|
876
925
|
response_type: MessageResponseTypes.TEXT,
|
|
@@ -884,9 +933,10 @@ var A2AToCarbonTranslator = class {
|
|
|
884
933
|
message_options: {
|
|
885
934
|
response_user_profile: this.agentProfile,
|
|
886
935
|
reasoning: {
|
|
936
|
+
// Include accumulated streaming content if any
|
|
937
|
+
content: this.state.accumulatedThinking || void 0,
|
|
887
938
|
steps: this.state.reasoningSteps,
|
|
888
939
|
open_state: "default" /* DEFAULT */
|
|
889
|
-
// Auto-expand during streaming
|
|
890
940
|
}
|
|
891
941
|
}
|
|
892
942
|
},
|
|
@@ -1065,6 +1115,14 @@ var A2AToCarbonTranslator = class {
|
|
|
1065
1115
|
* Optional but useful for accessibility and corrections.
|
|
1066
1116
|
*/
|
|
1067
1117
|
createCompleteItem(wasStopped = false) {
|
|
1118
|
+
const hasThinking = this.state.accumulatedThinking.length > 0;
|
|
1119
|
+
const hasSteps = this.state.reasoningSteps.length > 0;
|
|
1120
|
+
const reasoning = hasThinking || hasSteps ? {
|
|
1121
|
+
content: hasThinking ? this.state.accumulatedThinking : void 0,
|
|
1122
|
+
steps: hasSteps ? this.state.reasoningSteps : void 0,
|
|
1123
|
+
open_state: "close" /* CLOSE */
|
|
1124
|
+
// Collapse after completion
|
|
1125
|
+
} : void 0;
|
|
1068
1126
|
return {
|
|
1069
1127
|
complete_item: {
|
|
1070
1128
|
response_type: MessageResponseTypes.TEXT,
|
|
@@ -1077,11 +1135,7 @@ var A2AToCarbonTranslator = class {
|
|
|
1077
1135
|
partial_response: {
|
|
1078
1136
|
message_options: {
|
|
1079
1137
|
response_user_profile: this.agentProfile,
|
|
1080
|
-
reasoning
|
|
1081
|
-
steps: this.state.reasoningSteps,
|
|
1082
|
-
open_state: "close" /* CLOSE */
|
|
1083
|
-
// Collapse after completion
|
|
1084
|
-
} : void 0,
|
|
1138
|
+
reasoning,
|
|
1085
1139
|
chain_of_thought: this.state.chainOfThought.length > 0 ? this.state.chainOfThought : void 0
|
|
1086
1140
|
}
|
|
1087
1141
|
},
|
|
@@ -1097,6 +1151,14 @@ var A2AToCarbonTranslator = class {
|
|
|
1097
1151
|
* Without this, the UI will remain in a loading state.
|
|
1098
1152
|
*/
|
|
1099
1153
|
createFinalResponse() {
|
|
1154
|
+
const hasThinking = this.state.accumulatedThinking.length > 0;
|
|
1155
|
+
const hasSteps = this.state.reasoningSteps.length > 0;
|
|
1156
|
+
const reasoning = hasThinking || hasSteps ? {
|
|
1157
|
+
content: hasThinking ? this.state.accumulatedThinking : void 0,
|
|
1158
|
+
steps: hasSteps ? this.state.reasoningSteps : void 0,
|
|
1159
|
+
open_state: "close" /* CLOSE */
|
|
1160
|
+
// Collapse after completion
|
|
1161
|
+
} : void 0;
|
|
1100
1162
|
return {
|
|
1101
1163
|
final_response: {
|
|
1102
1164
|
id: this.state.responseId,
|
|
@@ -1113,11 +1175,7 @@ var A2AToCarbonTranslator = class {
|
|
|
1113
1175
|
},
|
|
1114
1176
|
message_options: {
|
|
1115
1177
|
response_user_profile: this.agentProfile,
|
|
1116
|
-
reasoning
|
|
1117
|
-
steps: this.state.reasoningSteps,
|
|
1118
|
-
open_state: "close" /* CLOSE */
|
|
1119
|
-
// Collapse after completion
|
|
1120
|
-
} : void 0,
|
|
1178
|
+
reasoning,
|
|
1121
1179
|
chain_of_thought: this.state.chainOfThought.length > 0 ? this.state.chainOfThought : void 0
|
|
1122
1180
|
}
|
|
1123
1181
|
}
|