@cloudbase/agent-adapter-langgraph 1.0.1-alpha.10 → 1.0.1-alpha.12
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +48 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{langchain-NZNM23PL.mjs → langchain-6EY35CAB.mjs} +39 -38
- package/dist/{langchain-NZNM23PL.mjs.map → langchain-6EY35CAB.mjs.map} +1 -1
- package/package.json +9 -7
|
@@ -1798,6 +1798,7 @@ import {
|
|
|
1798
1798
|
AIMessageChunk,
|
|
1799
1799
|
BaseMessage
|
|
1800
1800
|
} from "@langchain/core/messages";
|
|
1801
|
+
import { noopLogger } from "@cloudbase/agent-shared";
|
|
1801
1802
|
init_src();
|
|
1802
1803
|
var CallbackHandler = class extends BaseCallbackHandler {
|
|
1803
1804
|
constructor(params) {
|
|
@@ -1816,17 +1817,17 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
1816
1817
|
__publicField(this, "externalParentSpanContext");
|
|
1817
1818
|
// Adapter name for ROOT span prefix
|
|
1818
1819
|
__publicField(this, "adapterName");
|
|
1820
|
+
// Logger for debug output (defaults to noopLogger for silent operation)
|
|
1821
|
+
__publicField(this, "logger");
|
|
1819
1822
|
this.sessionId = params?.sessionId;
|
|
1820
1823
|
this.userId = params?.userId;
|
|
1821
1824
|
this.tags = params?.tags ?? [];
|
|
1822
1825
|
this.traceMetadata = params?.traceMetadata;
|
|
1823
1826
|
this.version = params?.version;
|
|
1824
1827
|
this.adapterName = params?.adapterName;
|
|
1828
|
+
this.logger = params?.logger ?? noopLogger;
|
|
1825
1829
|
this.promptToParentRunMap = /* @__PURE__ */ new Map();
|
|
1826
1830
|
}
|
|
1827
|
-
get logger() {
|
|
1828
|
-
return console;
|
|
1829
|
-
}
|
|
1830
1831
|
/**
|
|
1831
1832
|
* Set external parent SpanContext from AG-UI.Server span.
|
|
1832
1833
|
* This allows the CallbackHandler to link LangChain/LangGraph spans
|
|
@@ -1840,13 +1841,13 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
1840
1841
|
}
|
|
1841
1842
|
async handleLLMNewToken(token, _idx, runId, _parentRunId, _tags, _fields) {
|
|
1842
1843
|
if (runId && !(runId in this.completionStartTimes)) {
|
|
1843
|
-
this.logger.debug(`LLM first streaming token: ${runId}`);
|
|
1844
|
+
this.logger.debug?.(`LLM first streaming token: ${runId}`);
|
|
1844
1845
|
this.completionStartTimes[runId] = /* @__PURE__ */ new Date();
|
|
1845
1846
|
}
|
|
1846
1847
|
}
|
|
1847
1848
|
async handleChainStart(chain, inputs, runId, parentRunId, tags, metadata, runType, name) {
|
|
1848
1849
|
try {
|
|
1849
|
-
this.logger.debug(`Chain start with Id: ${runId}`);
|
|
1850
|
+
this.logger.debug?.(`Chain start with Id: ${runId}`);
|
|
1850
1851
|
const runName = name ?? chain.id.at(-1)?.toString() ?? "Langchain Run";
|
|
1851
1852
|
this.registerPromptInfo(parentRunId, metadata);
|
|
1852
1853
|
let finalInput = inputs;
|
|
@@ -1883,12 +1884,12 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
1883
1884
|
});
|
|
1884
1885
|
}
|
|
1885
1886
|
} catch (e) {
|
|
1886
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
1887
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
1887
1888
|
}
|
|
1888
1889
|
}
|
|
1889
1890
|
async handleAgentAction(action, runId, parentRunId) {
|
|
1890
1891
|
try {
|
|
1891
|
-
this.logger.debug(`Agent action ${action.tool} with ID: ${runId}`);
|
|
1892
|
+
this.logger.debug?.(`Agent action ${action.tool} with ID: ${runId}`);
|
|
1892
1893
|
this.startAndRegisterObservation({
|
|
1893
1894
|
runId,
|
|
1894
1895
|
parentRunId,
|
|
@@ -1899,23 +1900,23 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
1899
1900
|
asType: "tool"
|
|
1900
1901
|
});
|
|
1901
1902
|
} catch (e) {
|
|
1902
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
1903
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
1903
1904
|
}
|
|
1904
1905
|
}
|
|
1905
1906
|
async handleAgentEnd(action, runId, _parentRunId) {
|
|
1906
1907
|
try {
|
|
1907
|
-
this.logger.debug(`Agent finish with ID: ${runId}`);
|
|
1908
|
+
this.logger.debug?.(`Agent finish with ID: ${runId}`);
|
|
1908
1909
|
this.handleObservationEnd({
|
|
1909
1910
|
runId,
|
|
1910
1911
|
attributes: { output: action }
|
|
1911
1912
|
});
|
|
1912
1913
|
} catch (e) {
|
|
1913
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
1914
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
1914
1915
|
}
|
|
1915
1916
|
}
|
|
1916
1917
|
async handleChainError(err, runId, _parentRunId) {
|
|
1917
1918
|
try {
|
|
1918
|
-
this.logger.debug(`Chain error: ${err} with ID: ${runId}`);
|
|
1919
|
+
this.logger.debug?.(`Chain error: ${err} with ID: ${runId}`);
|
|
1919
1920
|
this.handleObservationEnd({
|
|
1920
1921
|
runId,
|
|
1921
1922
|
attributes: {
|
|
@@ -1924,11 +1925,11 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
1924
1925
|
}
|
|
1925
1926
|
});
|
|
1926
1927
|
} catch (e) {
|
|
1927
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
1928
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
1928
1929
|
}
|
|
1929
1930
|
}
|
|
1930
1931
|
async handleGenerationStart(llm, messages, runId, parentRunId, extraParams, tags, metadata, name) {
|
|
1931
|
-
this.logger.debug(
|
|
1932
|
+
this.logger.debug?.(
|
|
1932
1933
|
`Generation start with ID: ${runId} and parentRunId ${parentRunId}`
|
|
1933
1934
|
);
|
|
1934
1935
|
const runName = name ?? llm.id.at(-1)?.toString() ?? "Langchain Generation";
|
|
@@ -1974,7 +1975,7 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
1974
1975
|
}
|
|
1975
1976
|
async handleChatModelStart(llm, messages, runId, parentRunId, extraParams, tags, metadata, name) {
|
|
1976
1977
|
try {
|
|
1977
|
-
this.logger.debug(`Chat model start with ID: ${runId}`);
|
|
1978
|
+
this.logger.debug?.(`Chat model start with ID: ${runId}`);
|
|
1978
1979
|
const prompts = messages.flatMap(
|
|
1979
1980
|
(message) => message.map((m) => this.extractChatMessageContent(m))
|
|
1980
1981
|
);
|
|
@@ -1989,12 +1990,12 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
1989
1990
|
name
|
|
1990
1991
|
);
|
|
1991
1992
|
} catch (e) {
|
|
1992
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
1993
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
1993
1994
|
}
|
|
1994
1995
|
}
|
|
1995
1996
|
async handleChainEnd(outputs, runId, _parentRunId) {
|
|
1996
1997
|
try {
|
|
1997
|
-
this.logger.debug(`Chain end with ID: ${runId}`);
|
|
1998
|
+
this.logger.debug?.(`Chain end with ID: ${runId}`);
|
|
1998
1999
|
let finalOutput = outputs;
|
|
1999
2000
|
if (typeof outputs === "object" && "output" in outputs && typeof outputs["output"] === "string") {
|
|
2000
2001
|
finalOutput = outputs["output"];
|
|
@@ -2013,12 +2014,12 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2013
2014
|
});
|
|
2014
2015
|
this.deregisterPromptInfo(runId);
|
|
2015
2016
|
} catch (e) {
|
|
2016
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2017
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2017
2018
|
}
|
|
2018
2019
|
}
|
|
2019
2020
|
async handleLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata, name) {
|
|
2020
2021
|
try {
|
|
2021
|
-
this.logger.debug(`LLM start with ID: ${runId}`);
|
|
2022
|
+
this.logger.debug?.(`LLM start with ID: ${runId}`);
|
|
2022
2023
|
this.handleGenerationStart(
|
|
2023
2024
|
llm,
|
|
2024
2025
|
prompts,
|
|
@@ -2030,12 +2031,12 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2030
2031
|
name
|
|
2031
2032
|
);
|
|
2032
2033
|
} catch (e) {
|
|
2033
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2034
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2034
2035
|
}
|
|
2035
2036
|
}
|
|
2036
2037
|
async handleToolStart(tool, input, runId, parentRunId, tags, metadata, name) {
|
|
2037
2038
|
try {
|
|
2038
|
-
this.logger.debug(`Tool start with ID: ${runId}`);
|
|
2039
|
+
this.logger.debug?.(`Tool start with ID: ${runId}`);
|
|
2039
2040
|
this.startAndRegisterObservation({
|
|
2040
2041
|
runId,
|
|
2041
2042
|
parentRunId,
|
|
@@ -2048,12 +2049,12 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2048
2049
|
asType: "tool"
|
|
2049
2050
|
});
|
|
2050
2051
|
} catch (e) {
|
|
2051
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2052
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2052
2053
|
}
|
|
2053
2054
|
}
|
|
2054
2055
|
async handleRetrieverStart(retriever, query, runId, parentRunId, tags, metadata, name) {
|
|
2055
2056
|
try {
|
|
2056
|
-
this.logger.debug(`Retriever start with ID: ${runId}`);
|
|
2057
|
+
this.logger.debug?.(`Retriever start with ID: ${runId}`);
|
|
2057
2058
|
this.startAndRegisterObservation({
|
|
2058
2059
|
runId,
|
|
2059
2060
|
parentRunId,
|
|
@@ -2066,12 +2067,12 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2066
2067
|
asType: "span"
|
|
2067
2068
|
});
|
|
2068
2069
|
} catch (e) {
|
|
2069
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2070
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2070
2071
|
}
|
|
2071
2072
|
}
|
|
2072
2073
|
async handleRetrieverEnd(documents, runId, _parentRunId) {
|
|
2073
2074
|
try {
|
|
2074
|
-
this.logger.debug(`Retriever end with ID: ${runId}`);
|
|
2075
|
+
this.logger.debug?.(`Retriever end with ID: ${runId}`);
|
|
2075
2076
|
this.handleObservationEnd({
|
|
2076
2077
|
runId,
|
|
2077
2078
|
attributes: {
|
|
@@ -2079,12 +2080,12 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2079
2080
|
}
|
|
2080
2081
|
});
|
|
2081
2082
|
} catch (e) {
|
|
2082
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2083
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2083
2084
|
}
|
|
2084
2085
|
}
|
|
2085
2086
|
async handleRetrieverError(err, runId, _parentRunId) {
|
|
2086
2087
|
try {
|
|
2087
|
-
this.logger.debug(`Retriever error: ${err} with ID: ${runId}`);
|
|
2088
|
+
this.logger.debug?.(`Retriever error: ${err} with ID: ${runId}`);
|
|
2088
2089
|
this.handleObservationEnd({
|
|
2089
2090
|
runId,
|
|
2090
2091
|
attributes: {
|
|
@@ -2093,23 +2094,23 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2093
2094
|
}
|
|
2094
2095
|
});
|
|
2095
2096
|
} catch (e) {
|
|
2096
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2097
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2097
2098
|
}
|
|
2098
2099
|
}
|
|
2099
2100
|
async handleToolEnd(output, runId, _parentRunId) {
|
|
2100
2101
|
try {
|
|
2101
|
-
this.logger.debug(`Tool end with ID: ${runId}`);
|
|
2102
|
+
this.logger.debug?.(`Tool end with ID: ${runId}`);
|
|
2102
2103
|
this.handleObservationEnd({
|
|
2103
2104
|
runId,
|
|
2104
2105
|
attributes: { output }
|
|
2105
2106
|
});
|
|
2106
2107
|
} catch (e) {
|
|
2107
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2108
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2108
2109
|
}
|
|
2109
2110
|
}
|
|
2110
2111
|
async handleToolError(err, runId, _parentRunId) {
|
|
2111
2112
|
try {
|
|
2112
|
-
this.logger.debug(`Tool error ${err} with ID: ${runId}`);
|
|
2113
|
+
this.logger.debug?.(`Tool error ${err} with ID: ${runId}`);
|
|
2113
2114
|
this.handleObservationEnd({
|
|
2114
2115
|
runId,
|
|
2115
2116
|
attributes: {
|
|
@@ -2118,12 +2119,12 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2118
2119
|
}
|
|
2119
2120
|
});
|
|
2120
2121
|
} catch (e) {
|
|
2121
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2122
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2122
2123
|
}
|
|
2123
2124
|
}
|
|
2124
2125
|
async handleLLMEnd(output, runId, _parentRunId) {
|
|
2125
2126
|
try {
|
|
2126
|
-
this.logger.debug(`LLM end with ID: ${runId}`);
|
|
2127
|
+
this.logger.debug?.(`LLM end with ID: ${runId}`);
|
|
2127
2128
|
const lastResponse = output.generations[output.generations.length - 1][output.generations[output.generations.length - 1].length - 1];
|
|
2128
2129
|
const llmUsage = this.extractUsageMetadata(lastResponse) ?? output.llmOutput?.["tokenUsage"];
|
|
2129
2130
|
const modelName = this.extractModelNameFromMetadata(lastResponse);
|
|
@@ -2168,12 +2169,12 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2168
2169
|
delete this.completionStartTimes[runId];
|
|
2169
2170
|
}
|
|
2170
2171
|
} catch (e) {
|
|
2171
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2172
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2172
2173
|
}
|
|
2173
2174
|
}
|
|
2174
2175
|
async handleLLMError(err, runId, _parentRunId) {
|
|
2175
2176
|
try {
|
|
2176
|
-
this.logger.debug(`LLM error ${err} with ID: ${runId}`);
|
|
2177
|
+
this.logger.debug?.(`LLM error ${err} with ID: ${runId}`);
|
|
2177
2178
|
this.handleObservationEnd({
|
|
2178
2179
|
runId,
|
|
2179
2180
|
attributes: {
|
|
@@ -2182,7 +2183,7 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2182
2183
|
}
|
|
2183
2184
|
});
|
|
2184
2185
|
} catch (e) {
|
|
2185
|
-
this.logger.debug(e instanceof Error ? e.message : String(e));
|
|
2186
|
+
this.logger.debug?.(e instanceof Error ? e.message : String(e));
|
|
2186
2187
|
}
|
|
2187
2188
|
}
|
|
2188
2189
|
registerPromptInfo(parentRunId, metadata) {
|
|
@@ -2227,7 +2228,7 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2227
2228
|
const { runId, attributes = {} } = params;
|
|
2228
2229
|
const observation = this.runMap.get(runId);
|
|
2229
2230
|
if (!observation) {
|
|
2230
|
-
this.logger.warn("Observation not found in runMap. Skipping operation.");
|
|
2231
|
+
this.logger.warn?.("Observation not found in runMap. Skipping operation.");
|
|
2231
2232
|
return;
|
|
2232
2233
|
}
|
|
2233
2234
|
observation.update(attributes).end();
|
|
@@ -2261,7 +2262,7 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2261
2262
|
const usageMetadata = "message" in generation && (AIMessage.isInstance(generation["message"]) || AIMessageChunk.isInstance(generation["message"])) ? generation["message"].usage_metadata : void 0;
|
|
2262
2263
|
return usageMetadata;
|
|
2263
2264
|
} catch (err) {
|
|
2264
|
-
this.logger.debug(`Error extracting usage metadata: ${err}`);
|
|
2265
|
+
this.logger.debug?.(`Error extracting usage metadata: ${err}`);
|
|
2265
2266
|
return;
|
|
2266
2267
|
}
|
|
2267
2268
|
}
|
|
@@ -2319,4 +2320,4 @@ var CallbackHandler = class extends BaseCallbackHandler {
|
|
|
2319
2320
|
export {
|
|
2320
2321
|
CallbackHandler
|
|
2321
2322
|
};
|
|
2322
|
-
//# sourceMappingURL=langchain-
|
|
2323
|
+
//# sourceMappingURL=langchain-6EY35CAB.mjs.map
|