@kuntur/a2a-carbon-chat-adapter 0.1.5 → 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.d.cts CHANGED
@@ -1203,6 +1203,7 @@ interface TranslatorState {
1203
1203
  responseId: string;
1204
1204
  itemId: string;
1205
1205
  accumulatedText: string;
1206
+ accumulatedThinking: string;
1206
1207
  reasoningSteps: ReasoningStep[];
1207
1208
  chainOfThought: ChainOfThoughtStep[];
1208
1209
  pendingToolCalls: Map<string, number>;
@@ -1260,6 +1261,10 @@ declare class A2AToCarbonTranslator {
1260
1261
  * Get accumulated text
1261
1262
  */
1262
1263
  getAccumulatedText(): string;
1264
+ /**
1265
+ * Get accumulated thinking content (for reasoning.content mode)
1266
+ */
1267
+ getAccumulatedThinking(): string;
1263
1268
  /**
1264
1269
  * Get current reasoning steps
1265
1270
  */
@@ -1300,7 +1305,11 @@ declare class A2AToCarbonTranslator {
1300
1305
  */
1301
1306
  translatePart(part: A2APartWithMetadata, artifactMetadata?: Record<string, unknown>): CarbonStreamChunk | null;
1302
1307
  /**
1303
- * Translate thinking/reasoning content to Carbon reasoning step
1308
+ * Translate thinking/reasoning content to Carbon format
1309
+ *
1310
+ * ROUTING LOGIC:
1311
+ * - content_type='thinking' (no title) → reasoning.content (streaming)
1312
+ * - content_type='reasoning_step' WITH title → reasoning.steps[] (discrete)
1304
1313
  */
1305
1314
  private translateThinkingPart;
1306
1315
  /**
package/dist/index.d.ts CHANGED
@@ -1203,6 +1203,7 @@ interface TranslatorState {
1203
1203
  responseId: string;
1204
1204
  itemId: string;
1205
1205
  accumulatedText: string;
1206
+ accumulatedThinking: string;
1206
1207
  reasoningSteps: ReasoningStep[];
1207
1208
  chainOfThought: ChainOfThoughtStep[];
1208
1209
  pendingToolCalls: Map<string, number>;
@@ -1260,6 +1261,10 @@ declare class A2AToCarbonTranslator {
1260
1261
  * Get accumulated text
1261
1262
  */
1262
1263
  getAccumulatedText(): string;
1264
+ /**
1265
+ * Get accumulated thinking content (for reasoning.content mode)
1266
+ */
1267
+ getAccumulatedThinking(): string;
1263
1268
  /**
1264
1269
  * Get current reasoning steps
1265
1270
  */
@@ -1300,7 +1305,11 @@ declare class A2AToCarbonTranslator {
1300
1305
  */
1301
1306
  translatePart(part: A2APartWithMetadata, artifactMetadata?: Record<string, unknown>): CarbonStreamChunk | null;
1302
1307
  /**
1303
- * Translate thinking/reasoning content to Carbon reasoning step
1308
+ * Translate thinking/reasoning content to Carbon format
1309
+ *
1310
+ * ROUTING LOGIC:
1311
+ * - content_type='thinking' (no title) → reasoning.content (streaming)
1312
+ * - content_type='reasoning_step' WITH title → reasoning.steps[] (discrete)
1304
1313
  */
1305
1314
  private translateThinkingPart;
1306
1315
  /**
package/dist/index.js CHANGED
@@ -625,6 +625,8 @@ var A2AToCarbonTranslator = class {
625
625
  responseId: this.generateResponseId(),
626
626
  itemId: "1",
627
627
  accumulatedText: "",
628
+ accumulatedThinking: "",
629
+ // Initialize empty for streaming thinking tokens
628
630
  reasoningSteps: [],
629
631
  chainOfThought: [],
630
632
  pendingToolCalls: /* @__PURE__ */ new Map(),
@@ -686,6 +688,12 @@ var A2AToCarbonTranslator = class {
686
688
  getAccumulatedText() {
687
689
  return this.state.accumulatedText;
688
690
  }
691
+ /**
692
+ * Get accumulated thinking content (for reasoning.content mode)
693
+ */
694
+ getAccumulatedThinking() {
695
+ return this.state.accumulatedThinking;
696
+ }
689
697
  /**
690
698
  * Get current reasoning steps
691
699
  */
@@ -740,7 +748,7 @@ var A2AToCarbonTranslator = class {
740
748
  }
741
749
  };
742
750
  if (includeReasoning) {
743
- chunk.partial_response.message_options.reasoning = { steps: [] };
751
+ chunk.partial_response.message_options.reasoning = { content: "" };
744
752
  }
745
753
  return chunk;
746
754
  }
@@ -858,17 +866,58 @@ var A2AToCarbonTranslator = class {
858
866
  return null;
859
867
  }
860
868
  /**
861
- * Translate thinking/reasoning content to Carbon reasoning step
869
+ * Translate thinking/reasoning content to Carbon format
870
+ *
871
+ * ROUTING LOGIC:
872
+ * - content_type='thinking' (no title) → reasoning.content (streaming)
873
+ * - content_type='reasoning_step' WITH title → reasoning.steps[] (discrete)
862
874
  */
863
875
  translateThinkingPart(text, metadata) {
864
- const stepNumber = metadata?.step;
876
+ const contentType = metadata?.content_type;
865
877
  const stepTitle = metadata?.title;
878
+ if (contentType === "thinking" || !stepTitle) {
879
+ this.state.accumulatedThinking += text;
880
+ console.log("[Translator] Streaming thinking token:", {
881
+ tokenLength: text.length,
882
+ totalLength: this.state.accumulatedThinking.length
883
+ });
884
+ return {
885
+ partial_item: {
886
+ response_type: MessageResponseTypes.TEXT,
887
+ text: "",
888
+ streaming_metadata: {
889
+ id: this.state.itemId,
890
+ cancellable: true
891
+ }
892
+ },
893
+ partial_response: {
894
+ message_options: {
895
+ response_user_profile: this.agentProfile,
896
+ reasoning: {
897
+ content: this.state.accumulatedThinking,
898
+ // Stream to content
899
+ // Preserve any existing discrete steps
900
+ steps: this.state.reasoningSteps.length > 0 ? this.state.reasoningSteps : void 0
901
+ }
902
+ }
903
+ },
904
+ streaming_metadata: {
905
+ response_id: this.state.responseId
906
+ }
907
+ };
908
+ }
866
909
  const newStep = {
867
- title: stepTitle || `Thinking Step ${(stepNumber ?? this.state.reasoningSteps.length) + 1}`,
910
+ title: stepTitle,
911
+ // No fallback - only real titles become discrete steps
868
912
  content: text,
869
913
  open_state: "default" /* DEFAULT */
870
914
  };
871
915
  this.state.reasoningSteps.push(newStep);
916
+ console.log("[Translator] Added discrete reasoning step:", {
917
+ title: stepTitle,
918
+ textLength: text.length,
919
+ totalSteps: this.state.reasoningSteps.length
920
+ });
872
921
  return {
873
922
  partial_item: {
874
923
  response_type: MessageResponseTypes.TEXT,
@@ -882,9 +931,10 @@ var A2AToCarbonTranslator = class {
882
931
  message_options: {
883
932
  response_user_profile: this.agentProfile,
884
933
  reasoning: {
934
+ // Include accumulated streaming content if any
935
+ content: this.state.accumulatedThinking || void 0,
885
936
  steps: this.state.reasoningSteps,
886
937
  open_state: "default" /* DEFAULT */
887
- // Auto-expand during streaming
888
938
  }
889
939
  }
890
940
  },
@@ -1063,6 +1113,14 @@ var A2AToCarbonTranslator = class {
1063
1113
  * Optional but useful for accessibility and corrections.
1064
1114
  */
1065
1115
  createCompleteItem(wasStopped = false) {
1116
+ const hasThinking = this.state.accumulatedThinking.length > 0;
1117
+ const hasSteps = this.state.reasoningSteps.length > 0;
1118
+ const reasoning = hasThinking || hasSteps ? {
1119
+ content: hasThinking ? this.state.accumulatedThinking : void 0,
1120
+ steps: hasSteps ? this.state.reasoningSteps : void 0,
1121
+ open_state: "close" /* CLOSE */
1122
+ // Collapse after completion
1123
+ } : void 0;
1066
1124
  return {
1067
1125
  complete_item: {
1068
1126
  response_type: MessageResponseTypes.TEXT,
@@ -1075,11 +1133,7 @@ var A2AToCarbonTranslator = class {
1075
1133
  partial_response: {
1076
1134
  message_options: {
1077
1135
  response_user_profile: this.agentProfile,
1078
- reasoning: this.state.reasoningSteps.length > 0 ? {
1079
- steps: this.state.reasoningSteps,
1080
- open_state: "close" /* CLOSE */
1081
- // Collapse after completion
1082
- } : void 0,
1136
+ reasoning,
1083
1137
  chain_of_thought: this.state.chainOfThought.length > 0 ? this.state.chainOfThought : void 0
1084
1138
  }
1085
1139
  },
@@ -1095,6 +1149,14 @@ var A2AToCarbonTranslator = class {
1095
1149
  * Without this, the UI will remain in a loading state.
1096
1150
  */
1097
1151
  createFinalResponse() {
1152
+ const hasThinking = this.state.accumulatedThinking.length > 0;
1153
+ const hasSteps = this.state.reasoningSteps.length > 0;
1154
+ const reasoning = hasThinking || hasSteps ? {
1155
+ content: hasThinking ? this.state.accumulatedThinking : void 0,
1156
+ steps: hasSteps ? this.state.reasoningSteps : void 0,
1157
+ open_state: "close" /* CLOSE */
1158
+ // Collapse after completion
1159
+ } : void 0;
1098
1160
  return {
1099
1161
  final_response: {
1100
1162
  id: this.state.responseId,
@@ -1111,11 +1173,7 @@ var A2AToCarbonTranslator = class {
1111
1173
  },
1112
1174
  message_options: {
1113
1175
  response_user_profile: this.agentProfile,
1114
- reasoning: this.state.reasoningSteps.length > 0 ? {
1115
- steps: this.state.reasoningSteps,
1116
- open_state: "close" /* CLOSE */
1117
- // Collapse after completion
1118
- } : void 0,
1176
+ reasoning,
1119
1177
  chain_of_thought: this.state.chainOfThought.length > 0 ? this.state.chainOfThought : void 0
1120
1178
  }
1121
1179
  }