@langchain/core 1.1.1 → 1.1.3
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/CHANGELOG.md +16 -0
- package/dist/agents.d.cts +0 -2
- package/dist/agents.d.ts +0 -2
- package/dist/callbacks/base.d.cts +22 -60
- package/dist/callbacks/base.d.ts +22 -60
- package/dist/callbacks/dispatch/index.d.cts +1 -3
- package/dist/callbacks/dispatch/index.d.ts +1 -3
- package/dist/callbacks/dispatch/web.d.cts +1 -3
- package/dist/callbacks/dispatch/web.d.ts +1 -3
- package/dist/callbacks/manager.d.cts +2 -12
- package/dist/callbacks/manager.d.ts +2 -12
- package/dist/chat_history.cjs +1 -1
- package/dist/chat_history.d.cts +0 -1
- package/dist/chat_history.d.ts +0 -1
- package/dist/chat_history.js +1 -1
- package/dist/document_loaders/langsmith.d.cts +0 -3
- package/dist/document_loaders/langsmith.d.ts +0 -3
- package/dist/documents/document.d.cts +3 -12
- package/dist/documents/document.d.ts +3 -12
- package/dist/example_selectors/length_based.d.cts +1 -1
- package/dist/example_selectors/length_based.d.ts +1 -1
- package/dist/indexing/base.d.cts +0 -1
- package/dist/indexing/base.d.ts +0 -1
- package/dist/indexing/record_manager.d.cts +0 -1
- package/dist/indexing/record_manager.d.ts +0 -1
- package/dist/language_models/base.d.cts +8 -38
- package/dist/language_models/base.d.ts +8 -38
- package/dist/language_models/chat_models.cjs +1 -1
- package/dist/language_models/chat_models.d.cts +6 -33
- package/dist/language_models/chat_models.d.ts +6 -33
- package/dist/language_models/chat_models.js +1 -1
- package/dist/language_models/llms.d.cts +0 -6
- package/dist/language_models/llms.d.ts +0 -6
- package/dist/load/import_type.d.cts +0 -1
- package/dist/load/import_type.d.ts +0 -1
- package/dist/load/map_keys.cjs +4 -5
- package/dist/load/map_keys.cjs.map +1 -1
- package/dist/load/map_keys.d.cts +0 -1
- package/dist/load/map_keys.d.ts +0 -1
- package/dist/load/map_keys.js +3 -3
- package/dist/load/map_keys.js.map +1 -1
- package/dist/load/serializable.d.cts +0 -1
- package/dist/load/serializable.d.ts +0 -1
- package/dist/memory.d.cts +0 -3
- package/dist/memory.d.ts +0 -3
- package/dist/messages/ai.cjs +6 -48
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js +6 -48
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +3 -2
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +1 -13
- package/dist/messages/base.d.ts +1 -13
- package/dist/messages/base.js +3 -2
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/content/data.d.cts +2 -7
- package/dist/messages/content/data.d.ts +2 -7
- package/dist/messages/content/index.d.cts +1 -4
- package/dist/messages/content/index.d.ts +1 -4
- package/dist/messages/content/multimodal.d.cts +0 -1
- package/dist/messages/content/multimodal.d.ts +0 -1
- package/dist/messages/content/tools.d.cts +0 -1
- package/dist/messages/content/tools.d.ts +0 -1
- package/dist/messages/index.cjs +4 -2
- package/dist/messages/index.d.cts +2 -2
- package/dist/messages/index.d.ts +2 -2
- package/dist/messages/index.js +5 -4
- package/dist/messages/tool.d.cts +2 -9
- package/dist/messages/tool.d.ts +2 -9
- package/dist/messages/transformers.cjs +2 -2
- package/dist/messages/transformers.d.cts +0 -3
- package/dist/messages/transformers.d.ts +0 -3
- package/dist/messages/transformers.js +2 -2
- package/dist/messages/utils.cjs +77 -4
- package/dist/messages/utils.cjs.map +1 -1
- package/dist/messages/utils.d.cts +35 -7
- package/dist/messages/utils.d.ts +35 -7
- package/dist/messages/utils.js +77 -5
- package/dist/messages/utils.js.map +1 -1
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs +169 -0
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js +168 -0
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js.map +1 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs +122 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js +121 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js.map +1 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs +18 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js +17 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js.map +1 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.cjs +27 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js +26 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js.map +1 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs +141 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js +141 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js.map +1 -0
- package/dist/output_parsers/json.cjs.map +1 -1
- package/dist/output_parsers/json.d.cts +1 -5
- package/dist/output_parsers/json.d.ts +1 -5
- package/dist/output_parsers/json.js.map +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +2 -6
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +2 -6
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +10 -34
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +10 -34
- package/dist/output_parsers/transform.d.cts +0 -1
- package/dist/output_parsers/transform.d.ts +0 -1
- package/dist/outputs.d.cts +0 -6
- package/dist/outputs.d.ts +0 -6
- package/dist/prompts/base.d.cts +2 -10
- package/dist/prompts/base.d.ts +2 -10
- package/dist/prompts/chat.cjs +2 -2
- package/dist/prompts/chat.d.cts +13 -51
- package/dist/prompts/chat.d.ts +13 -51
- package/dist/prompts/chat.js +2 -2
- package/dist/prompts/few_shot.d.cts +1 -5
- package/dist/prompts/few_shot.d.ts +1 -5
- package/dist/prompts/image.d.cts +2 -10
- package/dist/prompts/image.d.ts +2 -10
- package/dist/prompts/prompt.d.cts +4 -15
- package/dist/prompts/prompt.d.ts +4 -16
- package/dist/prompts/serde.d.cts +0 -1
- package/dist/prompts/serde.d.ts +0 -1
- package/dist/prompts/string.d.cts +1 -5
- package/dist/prompts/string.d.ts +1 -5
- package/dist/prompts/structured.d.cts +3 -16
- package/dist/prompts/structured.d.ts +3 -16
- package/dist/retrievers/document_compressors/index.d.cts +0 -1
- package/dist/retrievers/document_compressors/index.d.ts +0 -1
- package/dist/retrievers/index.d.cts +2 -6
- package/dist/retrievers/index.d.ts +2 -6
- package/dist/runnables/base.cjs +7 -7
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +12 -64
- package/dist/runnables/base.d.ts +12 -64
- package/dist/runnables/base.js +1 -1
- package/dist/runnables/branch.d.cts +0 -2
- package/dist/runnables/branch.d.ts +0 -2
- package/dist/runnables/config.d.cts +0 -1
- package/dist/runnables/config.d.ts +0 -1
- package/dist/runnables/graph.d.cts +1 -5
- package/dist/runnables/graph.d.ts +1 -5
- package/dist/runnables/graph_mermaid.cjs +2 -1
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js +3 -1
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/history.cjs +1 -1
- package/dist/runnables/history.d.cts +4 -12
- package/dist/runnables/history.d.ts +4 -12
- package/dist/runnables/history.js +1 -1
- package/dist/runnables/passthrough.d.cts +0 -2
- package/dist/runnables/passthrough.d.ts +0 -2
- package/dist/runnables/router.d.cts +0 -1
- package/dist/runnables/router.d.ts +0 -1
- package/dist/runnables/types.d.cts +2 -9
- package/dist/runnables/types.d.ts +2 -9
- package/dist/runnables/utils.cjs +5 -0
- package/dist/runnables/utils.cjs.map +1 -1
- package/dist/runnables/utils.js +5 -1
- package/dist/runnables/utils.js.map +1 -1
- package/dist/singletons/async_local_storage/context.d.cts +0 -2
- package/dist/singletons/async_local_storage/context.d.ts +0 -2
- package/dist/singletons/async_local_storage/globals.d.cts +0 -1
- package/dist/singletons/async_local_storage/globals.d.ts +0 -1
- package/dist/singletons/callbacks.cjs.map +1 -1
- package/dist/singletons/callbacks.js.map +1 -1
- package/dist/stores.d.cts +0 -1
- package/dist/stores.d.ts +0 -1
- package/dist/structured_query/utils.d.cts +1 -4
- package/dist/structured_query/utils.d.ts +1 -4
- package/dist/tools/index.d.cts +1 -6
- package/dist/tools/index.d.ts +1 -6
- package/dist/tools/types.d.cts +3 -13
- package/dist/tools/types.d.ts +3 -13
- package/dist/tracers/base.d.cts +1 -20
- package/dist/tracers/base.d.ts +1 -20
- package/dist/tracers/console.cjs +3 -3
- package/dist/tracers/console.cjs.map +1 -1
- package/dist/tracers/console.d.cts +0 -2
- package/dist/tracers/console.d.ts +0 -2
- package/dist/tracers/console.js +3 -3
- package/dist/tracers/console.js.map +1 -1
- package/dist/tracers/event_stream.d.cts +0 -4
- package/dist/tracers/event_stream.d.ts +0 -4
- package/dist/tracers/log_stream.d.cts +0 -6
- package/dist/tracers/log_stream.d.ts +0 -6
- package/dist/types/_internal.d.cts +0 -3
- package/dist/types/_internal.d.ts +0 -3
- package/dist/types/type-utils.d.cts +0 -2
- package/dist/types/type-utils.d.ts +0 -2
- package/dist/utils/async_caller.cjs +2 -7
- package/dist/utils/async_caller.cjs.map +1 -1
- package/dist/utils/async_caller.d.cts +0 -3
- package/dist/utils/async_caller.d.ts +0 -3
- package/dist/utils/async_caller.js +1 -6
- package/dist/utils/async_caller.js.map +1 -1
- package/dist/utils/env.d.cts +0 -4
- package/dist/utils/env.d.ts +0 -4
- package/dist/utils/event_source_parse.d.cts +1 -4
- package/dist/utils/event_source_parse.d.ts +1 -4
- package/dist/utils/function_calling.d.cts +1 -3
- package/dist/utils/function_calling.d.ts +1 -3
- package/dist/utils/json.cjs +182 -22
- package/dist/utils/json.cjs.map +1 -1
- package/dist/utils/json.d.cts +1 -3
- package/dist/utils/json.d.ts +1 -3
- package/dist/utils/json.js +182 -22
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/stream.d.cts +1 -13
- package/dist/utils/stream.d.ts +1 -13
- package/dist/utils/testing/chat_models.d.cts +3 -11
- package/dist/utils/testing/chat_models.d.ts +3 -11
- package/dist/utils/testing/message_history.cjs +1 -1
- package/dist/utils/testing/message_history.js +1 -1
- package/dist/utils/testing/retrievers.d.cts +1 -3
- package/dist/utils/testing/retrievers.d.ts +1 -3
- package/dist/utils/testing/vectorstores.d.cts +0 -1
- package/dist/utils/testing/vectorstores.d.ts +0 -1
- package/dist/utils/types/index.cjs +4 -0
- package/dist/utils/types/index.d.cts +2 -4
- package/dist/utils/types/index.d.ts +2 -4
- package/dist/utils/types/index.js +4 -2
- package/dist/utils/types/zod.cjs +24 -0
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.d.cts +4 -4
- package/dist/utils/types/zod.d.ts +4 -4
- package/dist/utils/types/zod.js +23 -1
- package/dist/utils/types/zod.js.map +1 -1
- package/dist/vectorstores.d.cts +5 -17
- package/dist/vectorstores.d.ts +5 -17
- package/package.json +6 -6
package/dist/tracers/base.d.cts
CHANGED
|
@@ -11,14 +11,11 @@ import { RunTree } from "langsmith/run_trees";
|
|
|
11
11
|
|
|
12
12
|
//#region src/tracers/base.d.ts
|
|
13
13
|
type RunType = string;
|
|
14
|
-
// TODO: Remove this type and just use the base LangSmith Run type.
|
|
15
14
|
interface Run extends BaseRun {
|
|
16
|
-
// some optional fields are always present here
|
|
17
15
|
id: string;
|
|
18
16
|
start_time: number;
|
|
19
17
|
end_time?: number;
|
|
20
18
|
execution_order: number;
|
|
21
|
-
// some additional fields that don't exist in sdk runs
|
|
22
19
|
child_runs: this[];
|
|
23
20
|
child_execution_order: number;
|
|
24
21
|
events: Array<{
|
|
@@ -58,12 +55,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
58
55
|
parent_run_id?: string | undefined;
|
|
59
56
|
tags?: string[] | undefined;
|
|
60
57
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
61
|
-
// some optional fields are always present here
|
|
62
58
|
id: string;
|
|
63
59
|
start_time: number;
|
|
64
60
|
end_time?: number | undefined;
|
|
65
61
|
execution_order: number;
|
|
66
|
-
// some additional fields that don't exist in sdk runs
|
|
67
62
|
child_runs: Run[];
|
|
68
63
|
child_execution_order: number;
|
|
69
64
|
events: {
|
|
@@ -95,12 +90,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
95
90
|
parent_run_id?: string | undefined;
|
|
96
91
|
tags?: string[] | undefined;
|
|
97
92
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
98
|
-
// some optional fields are always present here
|
|
99
93
|
id: string;
|
|
100
94
|
start_time: number;
|
|
101
95
|
end_time?: number | undefined;
|
|
102
96
|
execution_order: number;
|
|
103
|
-
// some additional fields that don't exist in sdk runs
|
|
104
97
|
child_runs: Run[];
|
|
105
98
|
child_execution_order: number;
|
|
106
99
|
events: {
|
|
@@ -131,12 +124,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
131
124
|
parent_run_id?: string | undefined;
|
|
132
125
|
tags?: string[] | undefined;
|
|
133
126
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
134
|
-
// some optional fields are always present here
|
|
135
127
|
id: string;
|
|
136
128
|
start_time: number;
|
|
137
129
|
end_time?: number | undefined;
|
|
138
130
|
execution_order: number;
|
|
139
|
-
// some additional fields that don't exist in sdk runs
|
|
140
131
|
child_runs: Run[];
|
|
141
132
|
child_execution_order: number;
|
|
142
133
|
events: {
|
|
@@ -169,12 +160,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
169
160
|
parent_run_id?: string | undefined;
|
|
170
161
|
tags?: string[] | undefined;
|
|
171
162
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
172
|
-
// some optional fields are always present here
|
|
173
163
|
id: string;
|
|
174
164
|
start_time: number;
|
|
175
165
|
end_time?: number | undefined;
|
|
176
166
|
execution_order: number;
|
|
177
|
-
// some additional fields that don't exist in sdk runs
|
|
178
167
|
child_runs: Run[];
|
|
179
168
|
child_execution_order: number;
|
|
180
169
|
events: {
|
|
@@ -211,12 +200,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
211
200
|
parent_run_id?: string | undefined;
|
|
212
201
|
tags?: string[] | undefined;
|
|
213
202
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
214
|
-
// some optional fields are always present here
|
|
215
203
|
id: string;
|
|
216
204
|
start_time: number;
|
|
217
205
|
end_time?: number | undefined;
|
|
218
206
|
execution_order: number;
|
|
219
|
-
// some additional fields that don't exist in sdk runs
|
|
220
207
|
child_runs: Run[];
|
|
221
208
|
child_execution_order: number;
|
|
222
209
|
events: {
|
|
@@ -230,7 +217,6 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
230
217
|
_serialized_start_time?: string | undefined;
|
|
231
218
|
};
|
|
232
219
|
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
233
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
234
220
|
handleToolEnd(output: any, runId: string): Promise<Run>;
|
|
235
221
|
handleToolError(error: unknown, runId: string): Promise<Run>;
|
|
236
222
|
handleAgentAction(action: AgentAction, runId: string): Promise<void>;
|
|
@@ -252,12 +238,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
252
238
|
parent_run_id?: string | undefined;
|
|
253
239
|
tags?: string[] | undefined;
|
|
254
240
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
255
|
-
// some optional fields are always present here
|
|
256
241
|
id: string;
|
|
257
242
|
start_time: number;
|
|
258
243
|
end_time?: number | undefined;
|
|
259
244
|
execution_order: number;
|
|
260
|
-
// some additional fields that don't exist in sdk runs
|
|
261
245
|
child_runs: Run[];
|
|
262
246
|
child_execution_order: number;
|
|
263
247
|
events: {
|
|
@@ -275,7 +259,6 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
275
259
|
handleRetrieverError(error: unknown, runId: string): Promise<Run>;
|
|
276
260
|
handleText(text: string, runId: string): Promise<void>;
|
|
277
261
|
handleLLMNewToken(token: string, idx: NewTokenIndices, runId: string, _parentRunId?: string, _tags?: string[], fields?: HandleLLMNewTokenCallbackFields): Promise<Run>;
|
|
278
|
-
// custom event handlers
|
|
279
262
|
onRunCreate?(run: Run): void | Promise<void>;
|
|
280
263
|
onRunUpdate?(run: Run): void | Promise<void>;
|
|
281
264
|
onLLMStart?(run: Run): void | Promise<void>;
|
|
@@ -293,9 +276,7 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
293
276
|
onRetrieverEnd?(run: Run): void | Promise<void>;
|
|
294
277
|
onRetrieverError?(run: Run): void | Promise<void>;
|
|
295
278
|
onText?(run: Run): void | Promise<void>;
|
|
296
|
-
onLLMNewToken?(run: Run, token: string,
|
|
297
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
298
|
-
kwargs?: {
|
|
279
|
+
onLLMNewToken?(run: Run, token: string, kwargs?: {
|
|
299
280
|
chunk: any;
|
|
300
281
|
}): void | Promise<void>;
|
|
301
282
|
}
|
package/dist/tracers/base.d.ts
CHANGED
|
@@ -11,14 +11,11 @@ import { BaseRun, KVMap } from "langsmith/schemas";
|
|
|
11
11
|
|
|
12
12
|
//#region src/tracers/base.d.ts
|
|
13
13
|
type RunType = string;
|
|
14
|
-
// TODO: Remove this type and just use the base LangSmith Run type.
|
|
15
14
|
interface Run extends BaseRun {
|
|
16
|
-
// some optional fields are always present here
|
|
17
15
|
id: string;
|
|
18
16
|
start_time: number;
|
|
19
17
|
end_time?: number;
|
|
20
18
|
execution_order: number;
|
|
21
|
-
// some additional fields that don't exist in sdk runs
|
|
22
19
|
child_runs: this[];
|
|
23
20
|
child_execution_order: number;
|
|
24
21
|
events: Array<{
|
|
@@ -58,12 +55,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
58
55
|
parent_run_id?: string | undefined;
|
|
59
56
|
tags?: string[] | undefined;
|
|
60
57
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
61
|
-
// some optional fields are always present here
|
|
62
58
|
id: string;
|
|
63
59
|
start_time: number;
|
|
64
60
|
end_time?: number | undefined;
|
|
65
61
|
execution_order: number;
|
|
66
|
-
// some additional fields that don't exist in sdk runs
|
|
67
62
|
child_runs: Run[];
|
|
68
63
|
child_execution_order: number;
|
|
69
64
|
events: {
|
|
@@ -95,12 +90,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
95
90
|
parent_run_id?: string | undefined;
|
|
96
91
|
tags?: string[] | undefined;
|
|
97
92
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
98
|
-
// some optional fields are always present here
|
|
99
93
|
id: string;
|
|
100
94
|
start_time: number;
|
|
101
95
|
end_time?: number | undefined;
|
|
102
96
|
execution_order: number;
|
|
103
|
-
// some additional fields that don't exist in sdk runs
|
|
104
97
|
child_runs: Run[];
|
|
105
98
|
child_execution_order: number;
|
|
106
99
|
events: {
|
|
@@ -131,12 +124,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
131
124
|
parent_run_id?: string | undefined;
|
|
132
125
|
tags?: string[] | undefined;
|
|
133
126
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
134
|
-
// some optional fields are always present here
|
|
135
127
|
id: string;
|
|
136
128
|
start_time: number;
|
|
137
129
|
end_time?: number | undefined;
|
|
138
130
|
execution_order: number;
|
|
139
|
-
// some additional fields that don't exist in sdk runs
|
|
140
131
|
child_runs: Run[];
|
|
141
132
|
child_execution_order: number;
|
|
142
133
|
events: {
|
|
@@ -169,12 +160,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
169
160
|
parent_run_id?: string | undefined;
|
|
170
161
|
tags?: string[] | undefined;
|
|
171
162
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
172
|
-
// some optional fields are always present here
|
|
173
163
|
id: string;
|
|
174
164
|
start_time: number;
|
|
175
165
|
end_time?: number | undefined;
|
|
176
166
|
execution_order: number;
|
|
177
|
-
// some additional fields that don't exist in sdk runs
|
|
178
167
|
child_runs: Run[];
|
|
179
168
|
child_execution_order: number;
|
|
180
169
|
events: {
|
|
@@ -211,12 +200,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
211
200
|
parent_run_id?: string | undefined;
|
|
212
201
|
tags?: string[] | undefined;
|
|
213
202
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
214
|
-
// some optional fields are always present here
|
|
215
203
|
id: string;
|
|
216
204
|
start_time: number;
|
|
217
205
|
end_time?: number | undefined;
|
|
218
206
|
execution_order: number;
|
|
219
|
-
// some additional fields that don't exist in sdk runs
|
|
220
207
|
child_runs: Run[];
|
|
221
208
|
child_execution_order: number;
|
|
222
209
|
events: {
|
|
@@ -230,7 +217,6 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
230
217
|
_serialized_start_time?: string | undefined;
|
|
231
218
|
};
|
|
232
219
|
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
233
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
234
220
|
handleToolEnd(output: any, runId: string): Promise<Run>;
|
|
235
221
|
handleToolError(error: unknown, runId: string): Promise<Run>;
|
|
236
222
|
handleAgentAction(action: AgentAction, runId: string): Promise<void>;
|
|
@@ -252,12 +238,10 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
252
238
|
parent_run_id?: string | undefined;
|
|
253
239
|
tags?: string[] | undefined;
|
|
254
240
|
attachments?: langsmith_schemas0.Attachments | undefined;
|
|
255
|
-
// some optional fields are always present here
|
|
256
241
|
id: string;
|
|
257
242
|
start_time: number;
|
|
258
243
|
end_time?: number | undefined;
|
|
259
244
|
execution_order: number;
|
|
260
|
-
// some additional fields that don't exist in sdk runs
|
|
261
245
|
child_runs: Run[];
|
|
262
246
|
child_execution_order: number;
|
|
263
247
|
events: {
|
|
@@ -275,7 +259,6 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
275
259
|
handleRetrieverError(error: unknown, runId: string): Promise<Run>;
|
|
276
260
|
handleText(text: string, runId: string): Promise<void>;
|
|
277
261
|
handleLLMNewToken(token: string, idx: NewTokenIndices, runId: string, _parentRunId?: string, _tags?: string[], fields?: HandleLLMNewTokenCallbackFields): Promise<Run>;
|
|
278
|
-
// custom event handlers
|
|
279
262
|
onRunCreate?(run: Run): void | Promise<void>;
|
|
280
263
|
onRunUpdate?(run: Run): void | Promise<void>;
|
|
281
264
|
onLLMStart?(run: Run): void | Promise<void>;
|
|
@@ -293,9 +276,7 @@ declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
293
276
|
onRetrieverEnd?(run: Run): void | Promise<void>;
|
|
294
277
|
onRetrieverError?(run: Run): void | Promise<void>;
|
|
295
278
|
onText?(run: Run): void | Promise<void>;
|
|
296
|
-
onLLMNewToken?(run: Run, token: string,
|
|
297
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
298
|
-
kwargs?: {
|
|
279
|
+
onLLMNewToken?(run: Run, token: string, kwargs?: {
|
|
299
280
|
chunk: any;
|
|
300
281
|
}): void | Promise<void>;
|
|
301
282
|
}
|
package/dist/tracers/console.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_tracers_base = require('./base.cjs');
|
|
3
|
-
const
|
|
3
|
+
const require_index = require('../node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/tracers/console.ts
|
|
6
6
|
var console_exports = {};
|
|
@@ -26,7 +26,7 @@ function elapsed(run) {
|
|
|
26
26
|
if (elapsed$1 < 1e3) return `${elapsed$1}ms`;
|
|
27
27
|
return `${(elapsed$1 / 1e3).toFixed(2)}s`;
|
|
28
28
|
}
|
|
29
|
-
const { color } =
|
|
29
|
+
const { color } = require_index.default;
|
|
30
30
|
/**
|
|
31
31
|
* A tracer that logs all events to the console. It extends from the
|
|
32
32
|
* `BaseTracer` class and overrides its methods to provide custom logging
|
|
@@ -80,7 +80,7 @@ var ConsoleCallbackHandler = class extends require_tracers_base.BaseTracer {
|
|
|
80
80
|
const parents = this.getParents(run).reverse();
|
|
81
81
|
const string = [...parents, run].map((parent, i, arr) => {
|
|
82
82
|
const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;
|
|
83
|
-
return i === arr.length - 1 ? wrap(
|
|
83
|
+
return i === arr.length - 1 ? wrap(require_index.default.bold, name) : name;
|
|
84
84
|
}).join(" > ");
|
|
85
85
|
return wrap(color.grey, string);
|
|
86
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.cjs","names":["style: CSPair","text: string","obj: unknown","fallback: string","value: unknown","run: Run","elapsed","styles","BaseTracer","_run: Run","parents: Run[]"],"sources":["../../src/tracers/console.ts"],"sourcesContent":["import type { CSPair } from \"ansi-styles\";\nimport styles from \"ansi-styles\";\nimport { BaseTracer, type AgentRun, type Run } from \"./base.js\";\n\nfunction wrap(style: CSPair, text: string) {\n return `${style.open}${text}${style.close}`;\n}\n\nfunction tryJsonStringify(obj: unknown, fallback: string) {\n try {\n return JSON.stringify(obj, null, 2);\n } catch {\n return fallback;\n }\n}\n\nfunction formatKVMapItem(value: unknown) {\n if (typeof value === \"string\") {\n return value.trim();\n }\n\n if (value === null || value === undefined) {\n return value;\n }\n\n return tryJsonStringify(value, value.toString());\n}\n\nfunction elapsed(run: Run): string {\n if (!run.end_time) return \"\";\n const elapsed = run.end_time - run.start_time;\n if (elapsed < 1000) {\n return `${elapsed}ms`;\n }\n return `${(elapsed / 1000).toFixed(2)}s`;\n}\n\nconst { color } = styles;\n\n/**\n * A tracer that logs all events to the console. It extends from the\n * `BaseTracer` class and overrides its methods to provide custom logging\n * functionality.\n * @example\n * ```typescript\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * tags: [\"example\", \"callbacks\", \"constructor\"],\n * callbacks: [new ConsoleCallbackHandler()],\n * });\n *\n * ```\n */\nexport class ConsoleCallbackHandler extends BaseTracer {\n name = \"console_callback_handler\" as const;\n\n /**\n * Method used to persist the run. In this case, it simply returns a\n * resolved promise as there's no persistence logic.\n * @param _run The run to persist.\n * @returns A resolved promise.\n */\n protected persistRun(_run: Run) {\n return Promise.resolve();\n }\n\n // utility methods\n\n /**\n * Method used to get all the parent runs of a given run.\n * @param run The run whose parents are to be retrieved.\n * @returns An array of parent runs.\n */\n getParents(run: Run) {\n const parents: Run[] = [];\n let currentRun = run;\n while (currentRun.parent_run_id) {\n const parent = this.runMap.get(currentRun.parent_run_id);\n if (parent) {\n parents.push(parent);\n currentRun = parent;\n } else {\n break;\n }\n }\n return parents;\n }\n\n /**\n * Method used to get a string representation of the run's lineage, which\n * is used in logging.\n * @param run The run whose lineage is to be retrieved.\n * @returns A string representation of the run's lineage.\n */\n getBreadcrumbs(run: Run) {\n const parents = this.getParents(run).reverse();\n const string = [...parents, run]\n .map((parent, i, arr) => {\n const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;\n return i === arr.length - 1 ? wrap(styles.bold, name) : name;\n })\n .join(\" > \");\n return wrap(color.grey, string);\n }\n\n // logging methods\n\n /**\n * Method used to log the start of a chain run.\n * @param run The chain run that has started.\n * @returns void\n */\n onChainStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[chain/start]\"\n )} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a chain run.\n * @param run The chain run that has ended.\n * @returns void\n */\n onChainEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[chain/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Chain run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a chain run.\n * @param run The chain run that has errored.\n * @returns void\n */\n onChainError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[chain/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Chain run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of an LLM run.\n * @param run The LLM run that has started.\n * @returns void\n */\n onLLMStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n const inputs =\n \"prompts\" in run.inputs\n ? { prompts: (run.inputs.prompts as string[]).map((p) => p.trim()) }\n : run.inputs;\n console.log(\n `${wrap(\n color.green,\n \"[llm/start]\"\n )} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(\n inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of an LLM run.\n * @param run The LLM run that has ended.\n * @returns void\n */\n onLLMEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[llm/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting LLM run with output: ${tryJsonStringify(\n run.outputs,\n \"[response]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of an LLM run.\n * @param run The LLM run that has errored.\n * @returns void\n */\n onLLMError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[llm/error]\")} [${crumbs}] [${elapsed(\n run\n )}] LLM run errored with error: ${tryJsonStringify(run.error, \"[error]\")}`\n );\n }\n\n /**\n * Method used to log the start of a tool run.\n * @param run The tool run that has started.\n * @returns void\n */\n onToolStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[tool/start]\"\n )} [${crumbs}] Entering Tool run with input: \"${formatKVMapItem(\n run.inputs.input\n )}\"`\n );\n }\n\n /**\n * Method used to log the end of a tool run.\n * @param run The tool run that has ended.\n * @returns void\n */\n onToolEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n\n console.log(\n `${wrap(color.cyan, \"[tool/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Tool run with output: \"${formatKVMapItem(\n run.outputs?.output\n )}\"`\n );\n }\n\n /**\n * Method used to log any errors of a tool run.\n * @param run The tool run that has errored.\n * @returns void\n */\n onToolError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[tool/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Tool run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of a retriever run.\n * @param run The retriever run that has started.\n * @returns void\n */\n onRetrieverStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[retriever/start]\"\n )} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a retriever run.\n * @param run The retriever run that has ended.\n * @returns void\n */\n onRetrieverEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[retriever/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Retriever run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a retriever run.\n * @param run The retriever run that has errored.\n * @returns void\n */\n onRetrieverError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[retriever/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Retriever run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the action selected by the agent.\n * @param run The run in which the agent action occurred.\n * @returns void\n */\n onAgentAction(run: Run) {\n const agentRun = run as AgentRun;\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.blue,\n \"[agent/action]\"\n )} [${crumbs}] Agent selected action: ${tryJsonStringify(\n agentRun.actions[agentRun.actions.length - 1],\n \"[action]\"\n )}`\n );\n }\n}\n"],"mappings":";;;;;;;AAIA,SAAS,KAAKA,OAAeC,MAAc;AACzC,QAAO,GAAG,MAAM,OAAO,OAAO,MAAM,OAAO;AAC5C;AAED,SAAS,iBAAiBC,KAAcC,UAAkB;AACxD,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,MAAM,EAAE;CACpC,QAAO;AACN,SAAO;CACR;AACF;AAED,SAAS,gBAAgBC,OAAgB;AACvC,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,MAAM;AAGrB,KAAI,UAAU,QAAQ,UAAU,OAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,MAAM,UAAU,CAAC;AACjD;AAED,SAAS,QAAQC,KAAkB;AACjC,KAAI,CAAC,IAAI,SAAU,QAAO;CAC1B,MAAMC,YAAU,IAAI,WAAW,IAAI;AACnC,KAAIA,YAAU,IACZ,QAAO,GAAGA,UAAQ,EAAE,CAAC;AAEvB,QAAO,IAAIA,YAAU,KAAM,QAAQ,EAAE,CAAC,CAAC,CAAC;AACzC;AAED,MAAM,EAAE,OAAO,GA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IACD,CAAC,iCAAiC,EAAE,gBACnC,IAAI,SAAS,OACd,CAAC,CAAC,CAAC,CACL;CACF;;;;;;CAOD,YAAYA,KAAU;EACpB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KAAK,MAAM,KAAK,eAAe,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,QACjD,IACD,CAAC,+BAA+B,EAAE,iBACjC,IAAI,OACJ,UACD,EAAE,CACJ;CACF;;;;;;CAOD,iBAAiBA,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KACD,MAAM,OACN,oBACD,CAAC,EAAE,EAAE,OAAO,qCAAqC,EAAE,iBAClD,IAAI,QACJ,WACD,EAAE,CACJ;CACF;;;;;;CAOD,eAAeA,KAAU;EACvB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KAAK,MAAM,MAAM,kBAAkB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,QACrD,IACD,CAAC,qCAAqC,EAAE,iBACvC,IAAI,SACJ,YACD,EAAE,CACJ;CACF;;;;;;CAOD,iBAAiBA,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KAAK,MAAM,KAAK,oBAAoB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,QACtD,IACD,CAAC,oCAAoC,EAAE,iBACtC,IAAI,OACJ,UACD,EAAE,CACJ;CACF;;;;;;CAOD,cAAcA,KAAU;EACtB,MAAM,WAAW;EACjB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KACD,MAAM,MACN,iBACD,CAAC,EAAE,EAAE,OAAO,yBAAyB,EAAE,iBACtC,SAAS,QAAQ,SAAS,QAAQ,SAAS,IAC3C,WACD,EAAE,CACJ;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"console.cjs","names":["style: CSPair","text: string","obj: unknown","fallback: string","value: unknown","run: Run","elapsed","styles","BaseTracer","_run: Run","parents: Run[]"],"sources":["../../src/tracers/console.ts"],"sourcesContent":["import type { CSPair } from \"ansi-styles\";\nimport styles from \"ansi-styles\";\nimport { BaseTracer, type AgentRun, type Run } from \"./base.js\";\n\nfunction wrap(style: CSPair, text: string) {\n return `${style.open}${text}${style.close}`;\n}\n\nfunction tryJsonStringify(obj: unknown, fallback: string) {\n try {\n return JSON.stringify(obj, null, 2);\n } catch {\n return fallback;\n }\n}\n\nfunction formatKVMapItem(value: unknown) {\n if (typeof value === \"string\") {\n return value.trim();\n }\n\n if (value === null || value === undefined) {\n return value;\n }\n\n return tryJsonStringify(value, value.toString());\n}\n\nfunction elapsed(run: Run): string {\n if (!run.end_time) return \"\";\n const elapsed = run.end_time - run.start_time;\n if (elapsed < 1000) {\n return `${elapsed}ms`;\n }\n return `${(elapsed / 1000).toFixed(2)}s`;\n}\n\nconst { color } = styles;\n\n/**\n * A tracer that logs all events to the console. It extends from the\n * `BaseTracer` class and overrides its methods to provide custom logging\n * functionality.\n * @example\n * ```typescript\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * tags: [\"example\", \"callbacks\", \"constructor\"],\n * callbacks: [new ConsoleCallbackHandler()],\n * });\n *\n * ```\n */\nexport class ConsoleCallbackHandler extends BaseTracer {\n name = \"console_callback_handler\" as const;\n\n /**\n * Method used to persist the run. In this case, it simply returns a\n * resolved promise as there's no persistence logic.\n * @param _run The run to persist.\n * @returns A resolved promise.\n */\n protected persistRun(_run: Run) {\n return Promise.resolve();\n }\n\n // utility methods\n\n /**\n * Method used to get all the parent runs of a given run.\n * @param run The run whose parents are to be retrieved.\n * @returns An array of parent runs.\n */\n getParents(run: Run) {\n const parents: Run[] = [];\n let currentRun = run;\n while (currentRun.parent_run_id) {\n const parent = this.runMap.get(currentRun.parent_run_id);\n if (parent) {\n parents.push(parent);\n currentRun = parent;\n } else {\n break;\n }\n }\n return parents;\n }\n\n /**\n * Method used to get a string representation of the run's lineage, which\n * is used in logging.\n * @param run The run whose lineage is to be retrieved.\n * @returns A string representation of the run's lineage.\n */\n getBreadcrumbs(run: Run) {\n const parents = this.getParents(run).reverse();\n const string = [...parents, run]\n .map((parent, i, arr) => {\n const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;\n return i === arr.length - 1 ? wrap(styles.bold, name) : name;\n })\n .join(\" > \");\n return wrap(color.grey, string);\n }\n\n // logging methods\n\n /**\n * Method used to log the start of a chain run.\n * @param run The chain run that has started.\n * @returns void\n */\n onChainStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[chain/start]\"\n )} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a chain run.\n * @param run The chain run that has ended.\n * @returns void\n */\n onChainEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[chain/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Chain run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a chain run.\n * @param run The chain run that has errored.\n * @returns void\n */\n onChainError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[chain/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Chain run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of an LLM run.\n * @param run The LLM run that has started.\n * @returns void\n */\n onLLMStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n const inputs =\n \"prompts\" in run.inputs\n ? { prompts: (run.inputs.prompts as string[]).map((p) => p.trim()) }\n : run.inputs;\n console.log(\n `${wrap(\n color.green,\n \"[llm/start]\"\n )} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(\n inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of an LLM run.\n * @param run The LLM run that has ended.\n * @returns void\n */\n onLLMEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[llm/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting LLM run with output: ${tryJsonStringify(\n run.outputs,\n \"[response]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of an LLM run.\n * @param run The LLM run that has errored.\n * @returns void\n */\n onLLMError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[llm/error]\")} [${crumbs}] [${elapsed(\n run\n )}] LLM run errored with error: ${tryJsonStringify(run.error, \"[error]\")}`\n );\n }\n\n /**\n * Method used to log the start of a tool run.\n * @param run The tool run that has started.\n * @returns void\n */\n onToolStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[tool/start]\"\n )} [${crumbs}] Entering Tool run with input: \"${formatKVMapItem(\n run.inputs.input\n )}\"`\n );\n }\n\n /**\n * Method used to log the end of a tool run.\n * @param run The tool run that has ended.\n * @returns void\n */\n onToolEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n\n console.log(\n `${wrap(color.cyan, \"[tool/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Tool run with output: \"${formatKVMapItem(\n run.outputs?.output\n )}\"`\n );\n }\n\n /**\n * Method used to log any errors of a tool run.\n * @param run The tool run that has errored.\n * @returns void\n */\n onToolError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[tool/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Tool run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of a retriever run.\n * @param run The retriever run that has started.\n * @returns void\n */\n onRetrieverStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[retriever/start]\"\n )} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a retriever run.\n * @param run The retriever run that has ended.\n * @returns void\n */\n onRetrieverEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[retriever/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Retriever run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a retriever run.\n * @param run The retriever run that has errored.\n * @returns void\n */\n onRetrieverError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[retriever/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Retriever run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the action selected by the agent.\n * @param run The run in which the agent action occurred.\n * @returns void\n */\n onAgentAction(run: Run) {\n const agentRun = run as AgentRun;\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.blue,\n \"[agent/action]\"\n )} [${crumbs}] Agent selected action: ${tryJsonStringify(\n agentRun.actions[agentRun.actions.length - 1],\n \"[action]\"\n )}`\n );\n }\n}\n"],"mappings":";;;;;;;AAIA,SAAS,KAAKA,OAAeC,MAAc;AACzC,QAAO,GAAG,MAAM,OAAO,OAAO,MAAM,OAAO;AAC5C;AAED,SAAS,iBAAiBC,KAAcC,UAAkB;AACxD,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,MAAM,EAAE;CACpC,QAAO;AACN,SAAO;CACR;AACF;AAED,SAAS,gBAAgBC,OAAgB;AACvC,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,MAAM;AAGrB,KAAI,UAAU,QAAQ,UAAU,OAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,MAAM,UAAU,CAAC;AACjD;AAED,SAAS,QAAQC,KAAkB;AACjC,KAAI,CAAC,IAAI,SA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ACD,MAAM,MACN,iBACD,CAAC,EAAE,EAAE,OAAO,yBAAyB,EAAE,iBACtC,SAAS,QAAQ,SAAS,QAAQ,SAAS,IAC3C,WACD,EAAE,CACJ;CACF;AACF"}
|
|
@@ -26,7 +26,6 @@ declare class ConsoleCallbackHandler extends BaseTracer {
|
|
|
26
26
|
* @returns A resolved promise.
|
|
27
27
|
*/
|
|
28
28
|
protected persistRun(_run: Run): Promise<void>;
|
|
29
|
-
// utility methods
|
|
30
29
|
/**
|
|
31
30
|
* Method used to get all the parent runs of a given run.
|
|
32
31
|
* @param run The run whose parents are to be retrieved.
|
|
@@ -40,7 +39,6 @@ declare class ConsoleCallbackHandler extends BaseTracer {
|
|
|
40
39
|
* @returns A string representation of the run's lineage.
|
|
41
40
|
*/
|
|
42
41
|
getBreadcrumbs(run: Run): string;
|
|
43
|
-
// logging methods
|
|
44
42
|
/**
|
|
45
43
|
* Method used to log the start of a chain run.
|
|
46
44
|
* @param run The chain run that has started.
|
|
@@ -26,7 +26,6 @@ declare class ConsoleCallbackHandler extends BaseTracer {
|
|
|
26
26
|
* @returns A resolved promise.
|
|
27
27
|
*/
|
|
28
28
|
protected persistRun(_run: Run): Promise<void>;
|
|
29
|
-
// utility methods
|
|
30
29
|
/**
|
|
31
30
|
* Method used to get all the parent runs of a given run.
|
|
32
31
|
* @param run The run whose parents are to be retrieved.
|
|
@@ -40,7 +39,6 @@ declare class ConsoleCallbackHandler extends BaseTracer {
|
|
|
40
39
|
* @returns A string representation of the run's lineage.
|
|
41
40
|
*/
|
|
42
41
|
getBreadcrumbs(run: Run): string;
|
|
43
|
-
// logging methods
|
|
44
42
|
/**
|
|
45
43
|
* Method used to log the start of a chain run.
|
|
46
44
|
* @param run The chain run that has started.
|
package/dist/tracers/console.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __export } from "../_virtual/rolldown_runtime.js";
|
|
2
2
|
import { BaseTracer } from "./base.js";
|
|
3
|
-
import
|
|
3
|
+
import ansi_styles_default from "../node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js";
|
|
4
4
|
|
|
5
5
|
//#region src/tracers/console.ts
|
|
6
6
|
var console_exports = {};
|
|
@@ -26,7 +26,7 @@ function elapsed(run) {
|
|
|
26
26
|
if (elapsed$1 < 1e3) return `${elapsed$1}ms`;
|
|
27
27
|
return `${(elapsed$1 / 1e3).toFixed(2)}s`;
|
|
28
28
|
}
|
|
29
|
-
const { color } =
|
|
29
|
+
const { color } = ansi_styles_default;
|
|
30
30
|
/**
|
|
31
31
|
* A tracer that logs all events to the console. It extends from the
|
|
32
32
|
* `BaseTracer` class and overrides its methods to provide custom logging
|
|
@@ -80,7 +80,7 @@ var ConsoleCallbackHandler = class extends BaseTracer {
|
|
|
80
80
|
const parents = this.getParents(run).reverse();
|
|
81
81
|
const string = [...parents, run].map((parent, i, arr) => {
|
|
82
82
|
const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;
|
|
83
|
-
return i === arr.length - 1 ? wrap(
|
|
83
|
+
return i === arr.length - 1 ? wrap(ansi_styles_default.bold, name) : name;
|
|
84
84
|
}).join(" > ");
|
|
85
85
|
return wrap(color.grey, string);
|
|
86
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.js","names":["style: CSPair","text: string","obj: unknown","fallback: string","value: unknown","run: Run","elapsed","_run: Run","parents: Run[]"],"sources":["../../src/tracers/console.ts"],"sourcesContent":["import type { CSPair } from \"ansi-styles\";\nimport styles from \"ansi-styles\";\nimport { BaseTracer, type AgentRun, type Run } from \"./base.js\";\n\nfunction wrap(style: CSPair, text: string) {\n return `${style.open}${text}${style.close}`;\n}\n\nfunction tryJsonStringify(obj: unknown, fallback: string) {\n try {\n return JSON.stringify(obj, null, 2);\n } catch {\n return fallback;\n }\n}\n\nfunction formatKVMapItem(value: unknown) {\n if (typeof value === \"string\") {\n return value.trim();\n }\n\n if (value === null || value === undefined) {\n return value;\n }\n\n return tryJsonStringify(value, value.toString());\n}\n\nfunction elapsed(run: Run): string {\n if (!run.end_time) return \"\";\n const elapsed = run.end_time - run.start_time;\n if (elapsed < 1000) {\n return `${elapsed}ms`;\n }\n return `${(elapsed / 1000).toFixed(2)}s`;\n}\n\nconst { color } = styles;\n\n/**\n * A tracer that logs all events to the console. It extends from the\n * `BaseTracer` class and overrides its methods to provide custom logging\n * functionality.\n * @example\n * ```typescript\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * tags: [\"example\", \"callbacks\", \"constructor\"],\n * callbacks: [new ConsoleCallbackHandler()],\n * });\n *\n * ```\n */\nexport class ConsoleCallbackHandler extends BaseTracer {\n name = \"console_callback_handler\" as const;\n\n /**\n * Method used to persist the run. In this case, it simply returns a\n * resolved promise as there's no persistence logic.\n * @param _run The run to persist.\n * @returns A resolved promise.\n */\n protected persistRun(_run: Run) {\n return Promise.resolve();\n }\n\n // utility methods\n\n /**\n * Method used to get all the parent runs of a given run.\n * @param run The run whose parents are to be retrieved.\n * @returns An array of parent runs.\n */\n getParents(run: Run) {\n const parents: Run[] = [];\n let currentRun = run;\n while (currentRun.parent_run_id) {\n const parent = this.runMap.get(currentRun.parent_run_id);\n if (parent) {\n parents.push(parent);\n currentRun = parent;\n } else {\n break;\n }\n }\n return parents;\n }\n\n /**\n * Method used to get a string representation of the run's lineage, which\n * is used in logging.\n * @param run The run whose lineage is to be retrieved.\n * @returns A string representation of the run's lineage.\n */\n getBreadcrumbs(run: Run) {\n const parents = this.getParents(run).reverse();\n const string = [...parents, run]\n .map((parent, i, arr) => {\n const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;\n return i === arr.length - 1 ? wrap(styles.bold, name) : name;\n })\n .join(\" > \");\n return wrap(color.grey, string);\n }\n\n // logging methods\n\n /**\n * Method used to log the start of a chain run.\n * @param run The chain run that has started.\n * @returns void\n */\n onChainStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[chain/start]\"\n )} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a chain run.\n * @param run The chain run that has ended.\n * @returns void\n */\n onChainEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[chain/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Chain run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a chain run.\n * @param run The chain run that has errored.\n * @returns void\n */\n onChainError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[chain/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Chain run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of an LLM run.\n * @param run The LLM run that has started.\n * @returns void\n */\n onLLMStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n const inputs =\n \"prompts\" in run.inputs\n ? { prompts: (run.inputs.prompts as string[]).map((p) => p.trim()) }\n : run.inputs;\n console.log(\n `${wrap(\n color.green,\n \"[llm/start]\"\n )} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(\n inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of an LLM run.\n * @param run The LLM run that has ended.\n * @returns void\n */\n onLLMEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[llm/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting LLM run with output: ${tryJsonStringify(\n run.outputs,\n \"[response]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of an LLM run.\n * @param run The LLM run that has errored.\n * @returns void\n */\n onLLMError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[llm/error]\")} [${crumbs}] [${elapsed(\n run\n )}] LLM run errored with error: ${tryJsonStringify(run.error, \"[error]\")}`\n );\n }\n\n /**\n * Method used to log the start of a tool run.\n * @param run The tool run that has started.\n * @returns void\n */\n onToolStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[tool/start]\"\n )} [${crumbs}] Entering Tool run with input: \"${formatKVMapItem(\n run.inputs.input\n )}\"`\n );\n }\n\n /**\n * Method used to log the end of a tool run.\n * @param run The tool run that has ended.\n * @returns void\n */\n onToolEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n\n console.log(\n `${wrap(color.cyan, \"[tool/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Tool run with output: \"${formatKVMapItem(\n run.outputs?.output\n )}\"`\n );\n }\n\n /**\n * Method used to log any errors of a tool run.\n * @param run The tool run that has errored.\n * @returns void\n */\n onToolError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[tool/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Tool run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of a retriever run.\n * @param run The retriever run that has started.\n * @returns void\n */\n onRetrieverStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[retriever/start]\"\n )} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a retriever run.\n * @param run The retriever run that has ended.\n * @returns void\n */\n onRetrieverEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[retriever/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Retriever run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a retriever run.\n * @param run The retriever run that has errored.\n * @returns void\n */\n onRetrieverError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[retriever/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Retriever run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the action selected by the agent.\n * @param run The run in which the agent action occurred.\n * @returns void\n */\n onAgentAction(run: Run) {\n const agentRun = run as AgentRun;\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.blue,\n \"[agent/action]\"\n )} [${crumbs}] Agent selected action: ${tryJsonStringify(\n agentRun.actions[agentRun.actions.length - 1],\n \"[action]\"\n )}`\n );\n }\n}\n"],"mappings":";;;;;;;AAIA,SAAS,KAAKA,OAAeC,MAAc;AACzC,QAAO,GAAG,MAAM,OAAO,OAAO,MAAM,OAAO;AAC5C;AAED,SAAS,iBAAiBC,KAAcC,UAAkB;AACxD,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,MAAM,EAAE;CACpC,QAAO;AACN,SAAO;CACR;AACF;AAED,SAAS,gBAAgBC,OAAgB;AACvC,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,MAAM;AAGrB,KAAI,UAAU,QAAQ,UAAU,OAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,MAAM,UAAU,CAAC;AACjD;AAED,SAAS,QAAQC,KAAkB;AACjC,KAAI,CAAC,IAAI,SAAU,QAAO;CAC1B,MAAMC,YAAU,IAAI,WAAW,IAAI;AACnC,KAAIA,YAAU,IACZ,QAAO,GAAGA,UAAQ,EAAE,CAAC;AAEvB,QAAO,IAAIA,YAAU,KAAM,QAAQ,EAAE,CAAC,CAAC,CAAC;AACzC;AAED,MAAM,EAAE,OAAO,GAAG;;;;;;;;;;;;;;;;AAiBlB,IAAa,yBAAb,cAA4C,WAAW;CACrD,OAAO;;;;;;;CAQP,AAAU,WAAWC,MAAW;AAC9B,SAAO,QAAQ,SAAS;CACzB;;;;;;CASD,WAAWF,KAAU;EACnB,MAAMG,UAAiB,CAAE;EACzB,IAAI,aAAa;AACjB,SAAO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E,QACjD,IACD,CAAC,+BAA+B,EAAE,iBACjC,IAAI,OACJ,UACD,EAAE,CACJ;CACF;;;;;;CAOD,iBAAiBA,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KACD,MAAM,OACN,oBACD,CAAC,EAAE,EAAE,OAAO,qCAAqC,EAAE,iBAClD,IAAI,QACJ,WACD,EAAE,CACJ;CACF;;;;;;CAOD,eAAeA,KAAU;EACvB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KAAK,MAAM,MAAM,kBAAkB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,QACrD,IACD,CAAC,qCAAqC,EAAE,iBACvC,IAAI,SACJ,YACD,EAAE,CACJ;CACF;;;;;;CAOD,iBAAiBA,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KAAK,MAAM,KAAK,oBAAoB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,QACtD,IACD,CAAC,oCAAoC,EAAE,iBACtC,IAAI,OACJ,UACD,EAAE,CACJ;CACF;;;;;;CAOD,cAAcA,KAAU;EACtB,MAAM,WAAW;EACjB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KACD,MAAM,MACN,iBACD,CAAC,EAAE,EAAE,OAAO,yBAAyB,EAAE,iBACtC,SAAS,QAAQ,SAAS,QAAQ,SAAS,IAC3C,WACD,EAAE,CACJ;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"console.js","names":["style: CSPair","text: string","obj: unknown","fallback: string","value: unknown","run: Run","elapsed","styles","_run: Run","parents: Run[]"],"sources":["../../src/tracers/console.ts"],"sourcesContent":["import type { CSPair } from \"ansi-styles\";\nimport styles from \"ansi-styles\";\nimport { BaseTracer, type AgentRun, type Run } from \"./base.js\";\n\nfunction wrap(style: CSPair, text: string) {\n return `${style.open}${text}${style.close}`;\n}\n\nfunction tryJsonStringify(obj: unknown, fallback: string) {\n try {\n return JSON.stringify(obj, null, 2);\n } catch {\n return fallback;\n }\n}\n\nfunction formatKVMapItem(value: unknown) {\n if (typeof value === \"string\") {\n return value.trim();\n }\n\n if (value === null || value === undefined) {\n return value;\n }\n\n return tryJsonStringify(value, value.toString());\n}\n\nfunction elapsed(run: Run): string {\n if (!run.end_time) return \"\";\n const elapsed = run.end_time - run.start_time;\n if (elapsed < 1000) {\n return `${elapsed}ms`;\n }\n return `${(elapsed / 1000).toFixed(2)}s`;\n}\n\nconst { color } = styles;\n\n/**\n * A tracer that logs all events to the console. It extends from the\n * `BaseTracer` class and overrides its methods to provide custom logging\n * functionality.\n * @example\n * ```typescript\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * tags: [\"example\", \"callbacks\", \"constructor\"],\n * callbacks: [new ConsoleCallbackHandler()],\n * });\n *\n * ```\n */\nexport class ConsoleCallbackHandler extends BaseTracer {\n name = \"console_callback_handler\" as const;\n\n /**\n * Method used to persist the run. In this case, it simply returns a\n * resolved promise as there's no persistence logic.\n * @param _run The run to persist.\n * @returns A resolved promise.\n */\n protected persistRun(_run: Run) {\n return Promise.resolve();\n }\n\n // utility methods\n\n /**\n * Method used to get all the parent runs of a given run.\n * @param run The run whose parents are to be retrieved.\n * @returns An array of parent runs.\n */\n getParents(run: Run) {\n const parents: Run[] = [];\n let currentRun = run;\n while (currentRun.parent_run_id) {\n const parent = this.runMap.get(currentRun.parent_run_id);\n if (parent) {\n parents.push(parent);\n currentRun = parent;\n } else {\n break;\n }\n }\n return parents;\n }\n\n /**\n * Method used to get a string representation of the run's lineage, which\n * is used in logging.\n * @param run The run whose lineage is to be retrieved.\n * @returns A string representation of the run's lineage.\n */\n getBreadcrumbs(run: Run) {\n const parents = this.getParents(run).reverse();\n const string = [...parents, run]\n .map((parent, i, arr) => {\n const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;\n return i === arr.length - 1 ? wrap(styles.bold, name) : name;\n })\n .join(\" > \");\n return wrap(color.grey, string);\n }\n\n // logging methods\n\n /**\n * Method used to log the start of a chain run.\n * @param run The chain run that has started.\n * @returns void\n */\n onChainStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[chain/start]\"\n )} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a chain run.\n * @param run The chain run that has ended.\n * @returns void\n */\n onChainEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[chain/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Chain run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a chain run.\n * @param run The chain run that has errored.\n * @returns void\n */\n onChainError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[chain/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Chain run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of an LLM run.\n * @param run The LLM run that has started.\n * @returns void\n */\n onLLMStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n const inputs =\n \"prompts\" in run.inputs\n ? { prompts: (run.inputs.prompts as string[]).map((p) => p.trim()) }\n : run.inputs;\n console.log(\n `${wrap(\n color.green,\n \"[llm/start]\"\n )} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(\n inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of an LLM run.\n * @param run The LLM run that has ended.\n * @returns void\n */\n onLLMEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[llm/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting LLM run with output: ${tryJsonStringify(\n run.outputs,\n \"[response]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of an LLM run.\n * @param run The LLM run that has errored.\n * @returns void\n */\n onLLMError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[llm/error]\")} [${crumbs}] [${elapsed(\n run\n )}] LLM run errored with error: ${tryJsonStringify(run.error, \"[error]\")}`\n );\n }\n\n /**\n * Method used to log the start of a tool run.\n * @param run The tool run that has started.\n * @returns void\n */\n onToolStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[tool/start]\"\n )} [${crumbs}] Entering Tool run with input: \"${formatKVMapItem(\n run.inputs.input\n )}\"`\n );\n }\n\n /**\n * Method used to log the end of a tool run.\n * @param run The tool run that has ended.\n * @returns void\n */\n onToolEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n\n console.log(\n `${wrap(color.cyan, \"[tool/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Tool run with output: \"${formatKVMapItem(\n run.outputs?.output\n )}\"`\n );\n }\n\n /**\n * Method used to log any errors of a tool run.\n * @param run The tool run that has errored.\n * @returns void\n */\n onToolError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[tool/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Tool run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of a retriever run.\n * @param run The retriever run that has started.\n * @returns void\n */\n onRetrieverStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[retriever/start]\"\n )} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a retriever run.\n * @param run The retriever run that has ended.\n * @returns void\n */\n onRetrieverEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[retriever/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Retriever run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a retriever run.\n * @param run The retriever run that has errored.\n * @returns void\n */\n onRetrieverError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[retriever/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Retriever run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the action selected by the agent.\n * @param run The run in which the agent action occurred.\n * @returns void\n */\n onAgentAction(run: Run) {\n const agentRun = run as AgentRun;\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.blue,\n \"[agent/action]\"\n )} [${crumbs}] Agent selected action: ${tryJsonStringify(\n agentRun.actions[agentRun.actions.length - 1],\n \"[action]\"\n )}`\n );\n }\n}\n"],"mappings":";;;;;;;AAIA,SAAS,KAAKA,OAAeC,MAAc;AACzC,QAAO,GAAG,MAAM,OAAO,OAAO,MAAM,OAAO;AAC5C;AAED,SAAS,iBAAiBC,KAAcC,UAAkB;AACxD,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,MAAM,EAAE;CACpC,QAAO;AACN,SAAO;CACR;AACF;AAED,SAAS,gBAAgBC,OAAgB;AACvC,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,MAAM;AAGrB,KAAI,UAAU,QAAQ,UAAU,OAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,MAAM,UAAU,CAAC;AACjD;AAED,SAAS,QAAQC,KAAkB;AACjC,KAAI,CAAC,IAAI,SAAU,QAAO;CAC1B,MAAMC,YAAU,IAAI,WAAW,IAAI;AACnC,KAAIA,YAAU,IACZ,QAAO,GAAGA,UAAQ,EAAE,CAAC;AAEvB,QAAO,IAAIA,YAAU,KAAM,QAAQ,EAAE,CAAC,CAAC,CAAC;AACzC;AAED,MAAM,EAAE,OAAO,GAAGC;;;;;;;;;;;;;;;;AAiBlB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IAAI,SAAS,OACd,CAAC,CAAC,CAAC,CACL;CACF;;;;;;CAOD,YAAYA,KAAU;EACpB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KAAK,MAAM,KAAK,eAAe,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,QACjD,IACD,CAAC,+BAA+B,EAAE,iBACjC,IAAI,OACJ,UACD,EAAE,CACJ;CACF;;;;;;CAOD,iBAAiBA,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KACD,MAAM,OACN,oBACD,CAAC,EAAE,EAAE,OAAO,qCAAqC,EAAE,iBAClD,IAAI,QACJ,WACD,EAAE,CACJ;CACF;;;;;;CAOD,eAAeA,KAAU;EACvB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KAAK,MAAM,MAAM,kBAAkB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,QACrD,IACD,CAAC,qCAAqC,EAAE,iBACvC,IAAI,SACJ,YACD,EAAE,CACJ;CACF;;;;;;CAOD,iBAAiBA,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KAAK,MAAM,KAAK,oBAAoB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,QACtD,IACD,CAAC,oCAAoC,EAAE,iBACtC,IAAI,OACJ,UACD,EAAE,CACJ;CACF;;;;;;CAOD,cAAcA,KAAU;EACtB,MAAM,WAAW;EACjB,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,QAAQ,IACN,GAAG,KACD,MAAM,MACN,iBACD,CAAC,EAAE,EAAE,OAAO,yBAAyB,EAAE,iBACtC,SAAS,QAAQ,SAAS,QAAQ,SAAS,IAC3C,WACD,EAAE,CACJ;CACF;AACF"}
|
|
@@ -14,7 +14,6 @@ type StreamEventData = {
|
|
|
14
14
|
* won't be known until the *END* of the runnable when it has finished streaming
|
|
15
15
|
* its inputs.
|
|
16
16
|
*/
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
17
|
input?: any;
|
|
19
18
|
/**
|
|
20
19
|
* The output of the runnable that generated the event.
|
|
@@ -23,14 +22,12 @@ type StreamEventData = {
|
|
|
23
22
|
* though there might be some exceptions for special cased runnables (e.g., like
|
|
24
23
|
* chat models), which may return more information.
|
|
25
24
|
*/
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
25
|
output?: any;
|
|
28
26
|
/**
|
|
29
27
|
* A streaming chunk from the output that generated the event.
|
|
30
28
|
* chunks support addition in general, and adding them up should result
|
|
31
29
|
* in the output of the runnable that generated the event.
|
|
32
30
|
*/
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
31
|
chunk?: any;
|
|
35
32
|
};
|
|
36
33
|
/**
|
|
@@ -74,7 +71,6 @@ type StreamEvent = {
|
|
|
74
71
|
*/
|
|
75
72
|
tags?: string[];
|
|
76
73
|
/** Metadata associated with the runnable that generated this event. */
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
74
|
metadata: Record<string, any>;
|
|
79
75
|
/**
|
|
80
76
|
* Event data.
|
|
@@ -15,7 +15,6 @@ type StreamEventData = {
|
|
|
15
15
|
* won't be known until the *END* of the runnable when it has finished streaming
|
|
16
16
|
* its inputs.
|
|
17
17
|
*/
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
18
|
input?: any;
|
|
20
19
|
/**
|
|
21
20
|
* The output of the runnable that generated the event.
|
|
@@ -24,14 +23,12 @@ type StreamEventData = {
|
|
|
24
23
|
* though there might be some exceptions for special cased runnables (e.g., like
|
|
25
24
|
* chat models), which may return more information.
|
|
26
25
|
*/
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
26
|
output?: any;
|
|
29
27
|
/**
|
|
30
28
|
* A streaming chunk from the output that generated the event.
|
|
31
29
|
* chunks support addition in general, and adding them up should result
|
|
32
30
|
* in the output of the runnable that generated the event.
|
|
33
31
|
*/
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
32
|
chunk?: any;
|
|
36
33
|
};
|
|
37
34
|
/**
|
|
@@ -75,7 +72,6 @@ type StreamEvent = {
|
|
|
75
72
|
*/
|
|
76
73
|
tags?: string[];
|
|
77
74
|
/** Metadata associated with the runnable that generated this event. */
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
75
|
metadata: Record<string, any>;
|
|
80
76
|
/**
|
|
81
77
|
* Event data.
|
|
@@ -20,20 +20,16 @@ type LogEntry = {
|
|
|
20
20
|
/** List of tags for the run. */
|
|
21
21
|
tags: string[];
|
|
22
22
|
/** Key-value pairs of metadata for the run. */
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
23
|
metadata: Record<string, any>;
|
|
25
24
|
/** ISO-8601 timestamp of when the run started. */
|
|
26
25
|
start_time: string;
|
|
27
26
|
/** List of general output chunks streamed by this run. */
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
27
|
streamed_output: any[];
|
|
30
28
|
/** List of LLM tokens streamed by this run, if applicable. */
|
|
31
29
|
streamed_output_str: string[];
|
|
32
30
|
/** Inputs to this run. Not available currently via streamLog. */
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
31
|
inputs?: any;
|
|
35
32
|
/** Final output of this run. Only available after the run has finished successfully. */
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
33
|
final_output?: any;
|
|
38
34
|
/** ISO-8601 timestamp of when the run ended. Only available after the run has finished. */
|
|
39
35
|
end_time?: string;
|
|
@@ -42,10 +38,8 @@ type RunState = {
|
|
|
42
38
|
/** ID of the sub-run. */
|
|
43
39
|
id: string;
|
|
44
40
|
/** List of output chunks streamed by Runnable.stream() */
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
41
|
streamed_output: any[];
|
|
47
42
|
/** Final output of the run, usually the result of aggregating streamed_output. Only available after the run has finished successfully. */
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
43
|
final_output?: any;
|
|
50
44
|
/**
|
|
51
45
|
* List of sub-runs contained in this run, if any, in the order they were started.
|
|
@@ -20,20 +20,16 @@ type LogEntry = {
|
|
|
20
20
|
/** List of tags for the run. */
|
|
21
21
|
tags: string[];
|
|
22
22
|
/** Key-value pairs of metadata for the run. */
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
23
|
metadata: Record<string, any>;
|
|
25
24
|
/** ISO-8601 timestamp of when the run started. */
|
|
26
25
|
start_time: string;
|
|
27
26
|
/** List of general output chunks streamed by this run. */
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
27
|
streamed_output: any[];
|
|
30
28
|
/** List of LLM tokens streamed by this run, if applicable. */
|
|
31
29
|
streamed_output_str: string[];
|
|
32
30
|
/** Inputs to this run. Not available currently via streamLog. */
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
31
|
inputs?: any;
|
|
35
32
|
/** Final output of this run. Only available after the run has finished successfully. */
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
33
|
final_output?: any;
|
|
38
34
|
/** ISO-8601 timestamp of when the run ended. Only available after the run has finished. */
|
|
39
35
|
end_time?: string;
|
|
@@ -42,10 +38,8 @@ type RunState = {
|
|
|
42
38
|
/** ID of the sub-run. */
|
|
43
39
|
id: string;
|
|
44
40
|
/** List of output chunks streamed by Runnable.stream() */
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
41
|
streamed_output: any[];
|
|
47
42
|
/** Final output of the run, usually the result of aggregating streamed_output. Only available after the run has finished successfully. */
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
43
|
final_output?: any;
|
|
50
44
|
/**
|
|
51
45
|
* List of sub-runs contained in this run, if any, in the order they were started.
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
//#region src/types/_internal.d.ts
|
|
2
|
-
// Make this a type to override ReadableStream's async iterator type in case
|
|
3
|
-
// the popular web-streams-polyfill is imported - the supplied types
|
|
4
|
-
// in that case don't quite match.
|
|
5
2
|
type IterableReadableStreamInterface<T> = ReadableStream<T> & AsyncIterable<T>;
|
|
6
3
|
//#endregion
|
|
7
4
|
export { IterableReadableStreamInterface };
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
//#region src/types/_internal.d.ts
|
|
2
|
-
// Make this a type to override ReadableStream's async iterator type in case
|
|
3
|
-
// the popular web-streams-polyfill is imported - the supplied types
|
|
4
|
-
// in that case don't quite match.
|
|
5
2
|
type IterableReadableStreamInterface<T> = ReadableStream<T> & AsyncIterable<T>;
|
|
6
3
|
//#endregion
|
|
7
4
|
export { IterableReadableStreamInterface };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
//#region src/types/type-utils.d.ts
|
|
2
|
-
// Utility for marking only some keys of an interface as optional
|
|
3
|
-
// Compare to Partial<T> which marks all keys as optional
|
|
4
2
|
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
5
3
|
//#endregion
|
|
6
4
|
export { Optional };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
//#region src/types/type-utils.d.ts
|
|
2
|
-
// Utility for marking only some keys of an interface as optional
|
|
3
|
-
// Compare to Partial<T> which marks all keys as optional
|
|
4
2
|
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
5
3
|
//#endregion
|
|
6
4
|
export { Optional };
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_index = require('../node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs');
|
|
2
3
|
const require_signal = require('./signal.cjs');
|
|
3
4
|
const p_queue = require_rolldown_runtime.__toESM(require("p-queue"));
|
|
4
5
|
|
|
5
6
|
//#region src/utils/async_caller.ts
|
|
6
7
|
var async_caller_exports = {};
|
|
7
8
|
require_rolldown_runtime.__export(async_caller_exports, { AsyncCaller: () => AsyncCaller });
|
|
8
|
-
let pRetryModule = null;
|
|
9
|
-
async function getPRetry() {
|
|
10
|
-
if (!pRetryModule) pRetryModule = await import("p-retry");
|
|
11
|
-
return pRetryModule.default;
|
|
12
|
-
}
|
|
13
9
|
const STATUS_NO_RETRY = [
|
|
14
10
|
400,
|
|
15
11
|
401,
|
|
@@ -58,8 +54,7 @@ var AsyncCaller = class {
|
|
|
58
54
|
this.queue = new PQueue({ concurrency: this.maxConcurrency });
|
|
59
55
|
}
|
|
60
56
|
async call(callable, ...args) {
|
|
61
|
-
|
|
62
|
-
return this.queue.add(() => pRetry(() => callable(...args).catch((error) => {
|
|
57
|
+
return this.queue.add(() => require_index.pRetry(() => callable(...args).catch((error) => {
|
|
63
58
|
if (error instanceof Error) throw error;
|
|
64
59
|
else throw new Error(error);
|
|
65
60
|
}), {
|