@kuntur/a2a-carbon-chat-adapter 0.1.6 → 0.1.8
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 +155 -16
- 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 +155 -16
- package/dist/index.js.map +1 -1
- package/dist/server.d.cts +40 -0
- package/dist/server.d.ts +40 -0
- package/dist/styles/index.css +76 -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
|
}
|
|
@@ -1726,6 +1784,13 @@ function A2AChat({
|
|
|
1726
1784
|
const instanceRef = react.useRef(null);
|
|
1727
1785
|
const translatorRef = react.useRef(null);
|
|
1728
1786
|
const abortControllerRef = react.useRef(null);
|
|
1787
|
+
const [isViewOpen, setIsViewOpen] = react.useState(true);
|
|
1788
|
+
const [showExternalLauncher, setShowExternalLauncher] = react.useState(false);
|
|
1789
|
+
const [sidebarClosing, setSidebarClosing] = react.useState(false);
|
|
1790
|
+
const layoutRef = react.useRef(layout);
|
|
1791
|
+
react.useEffect(() => {
|
|
1792
|
+
layoutRef.current = layout;
|
|
1793
|
+
}, [layout]);
|
|
1729
1794
|
react.useEffect(() => {
|
|
1730
1795
|
if (typeof window !== "undefined") {
|
|
1731
1796
|
import('@carbon/ai-chat').then((mod) => {
|
|
@@ -1742,6 +1807,40 @@ function A2AChat({
|
|
|
1742
1807
|
react.useEffect(() => {
|
|
1743
1808
|
onConnectionChange?.(connectionState);
|
|
1744
1809
|
}, [connectionState, onConnectionChange]);
|
|
1810
|
+
const SIDEBAR_ANIMATION_MS = 250;
|
|
1811
|
+
const onViewChange = react.useCallback(
|
|
1812
|
+
(event) => {
|
|
1813
|
+
const currentLayout = layoutRef.current;
|
|
1814
|
+
setIsViewOpen(event.newViewState.mainWindow);
|
|
1815
|
+
if (currentLayout === "sidebar") {
|
|
1816
|
+
if (event.newViewState.mainWindow) {
|
|
1817
|
+
setShowExternalLauncher(false);
|
|
1818
|
+
setSidebarClosing(false);
|
|
1819
|
+
onOpen?.();
|
|
1820
|
+
} else {
|
|
1821
|
+
setSidebarClosing(false);
|
|
1822
|
+
setShowExternalLauncher(true);
|
|
1823
|
+
onClose?.();
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
},
|
|
1827
|
+
[onOpen, onClose]
|
|
1828
|
+
);
|
|
1829
|
+
const onViewPreChange = react.useCallback(
|
|
1830
|
+
async (event) => {
|
|
1831
|
+
if (layoutRef.current === "sidebar" && !event.newViewState.mainWindow) {
|
|
1832
|
+
setSidebarClosing(true);
|
|
1833
|
+
await new Promise((resolve) => setTimeout(resolve, SIDEBAR_ANIMATION_MS));
|
|
1834
|
+
}
|
|
1835
|
+
},
|
|
1836
|
+
[]
|
|
1837
|
+
);
|
|
1838
|
+
const handleOpenSidebar = react.useCallback(() => {
|
|
1839
|
+
const instance = instanceRef.current;
|
|
1840
|
+
if (instance?.actions?.changeView) {
|
|
1841
|
+
instance.actions.changeView("MAIN_WINDOW");
|
|
1842
|
+
}
|
|
1843
|
+
}, []);
|
|
1745
1844
|
const handleSendMessage = react.useCallback(
|
|
1746
1845
|
async (message) => {
|
|
1747
1846
|
if (!agent) {
|
|
@@ -1894,6 +1993,21 @@ function A2AChat({
|
|
|
1894
1993
|
instanceRef.current = instance;
|
|
1895
1994
|
console.log("[A2AChat] Chat instance ready");
|
|
1896
1995
|
}, []);
|
|
1996
|
+
const elementClassName = react.useMemo(() => {
|
|
1997
|
+
const classes = ["a2a-chat__element"];
|
|
1998
|
+
if (layout === "sidebar") {
|
|
1999
|
+
classes.push("a2a-chat__element--sidebar");
|
|
2000
|
+
if (sidebarClosing) {
|
|
2001
|
+
classes.push("a2a-chat__element--sidebar-closing");
|
|
2002
|
+
}
|
|
2003
|
+
} else if (layout === "fullscreen") {
|
|
2004
|
+
classes.push("a2a-chat__element--fullscreen");
|
|
2005
|
+
}
|
|
2006
|
+
if (!isViewOpen) {
|
|
2007
|
+
classes.push("cds-aichat--hidden");
|
|
2008
|
+
}
|
|
2009
|
+
return classes.join(" ");
|
|
2010
|
+
}, [layout, isViewOpen, sidebarClosing]);
|
|
1897
2011
|
if (!agent) {
|
|
1898
2012
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `a2a-chat a2a-chat--error ${className}`, children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "No agent configured. Provide `agent`, `agentId`, or `agentUrl` prop." }) });
|
|
1899
2013
|
}
|
|
@@ -1947,7 +2061,7 @@ function A2AChat({
|
|
|
1947
2061
|
ChatCustomElement,
|
|
1948
2062
|
{
|
|
1949
2063
|
...{
|
|
1950
|
-
className:
|
|
2064
|
+
className: elementClassName,
|
|
1951
2065
|
debug: false,
|
|
1952
2066
|
aiEnabled: true,
|
|
1953
2067
|
openChatByDefault: true,
|
|
@@ -1964,6 +2078,8 @@ function A2AChat({
|
|
|
1964
2078
|
showFrame: layout === "float",
|
|
1965
2079
|
showCloseAndRestartButton: layout !== "fullscreen"
|
|
1966
2080
|
},
|
|
2081
|
+
onViewChange,
|
|
2082
|
+
onViewPreChange,
|
|
1967
2083
|
onAfterRender: handleAfterRender,
|
|
1968
2084
|
renderUserDefinedResponse: renderCustomResponse,
|
|
1969
2085
|
messaging: {
|
|
@@ -1978,6 +2094,29 @@ function A2AChat({
|
|
|
1978
2094
|
}
|
|
1979
2095
|
}
|
|
1980
2096
|
),
|
|
2097
|
+
layout === "sidebar" && showExternalLauncher && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2098
|
+
"button",
|
|
2099
|
+
{
|
|
2100
|
+
className: "a2a-chat__external-launcher",
|
|
2101
|
+
onClick: handleOpenSidebar,
|
|
2102
|
+
"aria-label": "Open chat",
|
|
2103
|
+
title: "Open chat",
|
|
2104
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2105
|
+
"svg",
|
|
2106
|
+
{
|
|
2107
|
+
width: "24",
|
|
2108
|
+
height: "24",
|
|
2109
|
+
viewBox: "0 0 32 32",
|
|
2110
|
+
fill: "currentColor",
|
|
2111
|
+
"aria-hidden": "true",
|
|
2112
|
+
children: [
|
|
2113
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M17.74 30L16 29l4-7h6a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h9v2H6a4 4 0 0 1-4-4V8a4 4 0 0 1 4-4h20a4 4 0 0 1 4 4v12a4 4 0 0 1-4 4h-4.84Z" }),
|
|
2114
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8 10h16v2H8zM8 16h10v2H8z" })
|
|
2115
|
+
]
|
|
2116
|
+
}
|
|
2117
|
+
)
|
|
2118
|
+
}
|
|
2119
|
+
),
|
|
1981
2120
|
formOverlay
|
|
1982
2121
|
] });
|
|
1983
2122
|
}
|