@struct-ai/sdk 0.1.0
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/LICENSE +201 -0
- package/README.md +168 -0
- package/dist/commonjs/content-capture.d.ts +10 -0
- package/dist/commonjs/content-capture.js +23 -0
- package/dist/commonjs/context.d.ts +30 -0
- package/dist/commonjs/context.js +94 -0
- package/dist/commonjs/core.d.ts +120 -0
- package/dist/commonjs/core.js +408 -0
- package/dist/commonjs/events.d.ts +12 -0
- package/dist/commonjs/events.js +103 -0
- package/dist/commonjs/index.d.ts +6 -0
- package/dist/commonjs/index.js +10 -0
- package/dist/commonjs/integrations/anthropic-content.d.ts +24 -0
- package/dist/commonjs/integrations/anthropic-content.js +178 -0
- package/dist/commonjs/integrations/anthropic.d.ts +34 -0
- package/dist/commonjs/integrations/anthropic.js +377 -0
- package/dist/commonjs/integrations/index.d.ts +5 -0
- package/dist/commonjs/integrations/index.js +47 -0
- package/dist/commonjs/integrations/langchain-callback.d.ts +134 -0
- package/dist/commonjs/integrations/langchain-callback.js +723 -0
- package/dist/commonjs/integrations/langchain-content.d.ts +35 -0
- package/dist/commonjs/integrations/langchain-content.js +307 -0
- package/dist/commonjs/integrations/langchain.d.ts +11 -0
- package/dist/commonjs/integrations/langchain.js +100 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/semconv.d.ts +54 -0
- package/dist/commonjs/semconv.js +74 -0
- package/dist/commonjs/truncation.d.ts +10 -0
- package/dist/commonjs/truncation.js +103 -0
- package/dist/esm/content-capture.d.ts +10 -0
- package/dist/esm/content-capture.js +17 -0
- package/dist/esm/context.d.ts +30 -0
- package/dist/esm/context.js +80 -0
- package/dist/esm/core.d.ts +120 -0
- package/dist/esm/core.js +403 -0
- package/dist/esm/events.d.ts +12 -0
- package/dist/esm/events.js +99 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/integrations/anthropic-content.d.ts +24 -0
- package/dist/esm/integrations/anthropic-content.js +168 -0
- package/dist/esm/integrations/anthropic.d.ts +34 -0
- package/dist/esm/integrations/anthropic.js +370 -0
- package/dist/esm/integrations/index.d.ts +5 -0
- package/dist/esm/integrations/index.js +42 -0
- package/dist/esm/integrations/langchain-callback.d.ts +134 -0
- package/dist/esm/integrations/langchain-callback.js +719 -0
- package/dist/esm/integrations/langchain-content.d.ts +35 -0
- package/dist/esm/integrations/langchain-content.js +294 -0
- package/dist/esm/integrations/langchain.d.ts +11 -0
- package/dist/esm/integrations/langchain.js +95 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/semconv.d.ts +54 -0
- package/dist/esm/semconv.js +71 -0
- package/dist/esm/truncation.d.ts +10 -0
- package/dist/esm/truncation.js +96 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/content-capture.d.ts +10 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/context.d.ts +30 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/core.d.ts +120 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/events.d.ts +12 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/index.d.ts +6 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/anthropic-content.d.ts +24 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/anthropic.d.ts +34 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/index.d.ts +5 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain-callback.d.ts +134 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain-content.d.ts +35 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain.d.ts +11 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/package.json +3 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/semconv.d.ts +54 -0
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/truncation.d.ts +10 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/content-capture.d.ts +10 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/context.d.ts +30 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/core.d.ts +120 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/events.d.ts +12 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/index.d.ts +6 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/anthropic-content.d.ts +24 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/anthropic.d.ts +34 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/index.d.ts +5 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain-callback.d.ts +134 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain-content.d.ts +35 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain.d.ts +11 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/package.json +3 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/semconv.d.ts +54 -0
- package/dist/node_modules/@struct-ai/sdk/dist/esm/truncation.d.ts +10 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/commonjs/package.json +3 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/esm/package.json +3 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/package.json +100 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/package.json +103 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/package.json +118 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/package.json +916 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/package.json +188 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api/package.json +96 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api-logs/package.json +91 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/core/package.json +96 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-logs-otlp-proto/package.json +108 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-trace-otlp-proto/package.json +105 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/resources/package.json +100 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-logs/package.json +109 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-base/package.json +100 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-node/package.json +76 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/package.json +140 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/nock/package.json +89 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/tshy/package.json +81 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/typescript/package.json +120 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/vitest/package.json +239 -0
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/package.json +100 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/core.d.ts +244 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/error.d.ts +54 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/index.d.ts +188 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/package.json +103 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/pagination.d.ts +26 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/resource.d.ts +6 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/streaming.d.ts +41 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/uploads.d.ts +75 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/version.d.ts +2 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/experimental.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/index.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/package.json +118 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/agents.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/caches.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/chat_history.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/context.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/documents.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/embeddings.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/example_selectors.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/index.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/indexing.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/load.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/memory.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/messages.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/output_parsers.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/outputs.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/package.json +916 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/prompt_values.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/prompts.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/retrievers.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/runnables.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/singletons.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/stores.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/structured_query.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/tools.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/vectorstores.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/index.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/package.json +188 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/prebuilt.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/pregel.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/remote.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/web.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/zod.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api/package.json +96 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api-logs/package.json +91 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/core/package.json +96 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-logs-otlp-proto/package.json +108 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-trace-otlp-proto/package.json +105 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/resources/package.json +100 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-logs/package.json +109 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-base/package.json +100 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-node/package.json +76 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/assert.d.ts +1062 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/async_hooks.d.ts +605 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/buffer.buffer.d.ts +471 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/buffer.d.ts +1936 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/child_process.d.ts +1475 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/cluster.d.ts +577 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/console.d.ts +452 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/constants.d.ts +21 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/crypto.d.ts +4590 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/dgram.d.ts +597 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/diagnostics_channel.d.ts +578 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/dns.d.ts +871 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/domain.d.ts +170 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/events.d.ts +977 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/fs.d.ts +4375 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/globals.d.ts +172 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/globals.typedarray.d.ts +38 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/http.d.ts +2049 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/http2.d.ts +2631 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/https.d.ts +578 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/index.d.ts +93 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/inspector.generated.d.ts +3966 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/module.d.ts +539 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/net.d.ts +1031 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/os.d.ts +506 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/package.json +140 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/path.d.ts +200 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/perf_hooks.d.ts +961 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/process.d.ts +1961 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/punycode.d.ts +117 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/querystring.d.ts +152 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/readline.d.ts +589 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/repl.d.ts +430 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/sea.d.ts +153 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/stream.d.ts +1698 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/test.d.ts +1787 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/timers.d.ts +286 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/tls.d.ts +1259 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/trace_events.d.ts +197 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/tty.d.ts +208 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/url.d.ts +964 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/util.d.ts +2331 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/v8.d.ts +809 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/vm.d.ts +1001 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/wasi.d.ts +181 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/worker_threads.d.ts +715 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/zlib.d.ts +598 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/nock/package.json +89 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/tshy/package.json +81 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/typescript/package.json +120 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/config.d.ts +3 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/coverage.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/environments.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/globals.d.ts +22 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/import-meta.d.ts +5 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/importMeta.d.ts +4 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/jsdom.d.ts +6 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/mocker.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/node.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/optional-runtime-types.d.ts +6 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/optional-types.d.ts +7 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/package.json +239 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/reporters.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/runners.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/snapshot.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/suite.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/worker.d.ts +1 -0
- package/dist/node_modules/@struct-ai/sdk/package.json +100 -0
- package/package.json +100 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Part } from "./anthropic-content.js";
|
|
2
|
+
export declare const PROVIDER_MAP: Record<string, string>;
|
|
3
|
+
export declare const MODULE_PROVIDER_MAP: Record<string, string>;
|
|
4
|
+
/** Detect LLM provider from a LangChain model instance. */
|
|
5
|
+
export declare function detectProvider(model: unknown): string;
|
|
6
|
+
/** Probe `modelName`, `model`, `modelId` attrs in order. */
|
|
7
|
+
export declare function detectModel(model: unknown): string;
|
|
8
|
+
/**
|
|
9
|
+
* Extract the messages list from LangChain invoke()'s input argument.
|
|
10
|
+
* Handles: BaseMessage[], string, PromptValue (via toChatMessages/toMessages),
|
|
11
|
+
* dict with .messages key.
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractInputMessages(input: unknown): unknown[];
|
|
14
|
+
/**
|
|
15
|
+
* Extract thread_id from LangChain/LangGraph RunnableConfig.
|
|
16
|
+
* Signature: (input, config?, ...). Config has shape { configurable: { thread_id: "..." } }.
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractThreadId(args: readonly unknown[], options?: unknown): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Extract tool_call_id from LangChain ToolCall input.
|
|
21
|
+
* LangChain tool invocation input shape: { name, args, id, type: "tool_call" }.
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractToolCallId(args: readonly unknown[]): string | undefined;
|
|
24
|
+
/** Convert a LangChain message to (role, parts). Uses ._getType() first, falls back to class name. */
|
|
25
|
+
export declare function langchainMessageToRoleAndParts(msg: unknown): {
|
|
26
|
+
role: string;
|
|
27
|
+
parts: Part[];
|
|
28
|
+
};
|
|
29
|
+
export declare function langchainToInputMessages(messages: unknown[]): string;
|
|
30
|
+
export declare function langchainToOutputMessages(result: unknown): string;
|
|
31
|
+
/** Last user message parts for parent invoke_agent span propagation. */
|
|
32
|
+
export declare function lastUserMessageParts(messages: unknown[]): Part[] | undefined;
|
|
33
|
+
/** Merge a list of LangChain AIMessageChunks into one via .concat(). */
|
|
34
|
+
export declare function mergeChunks(chunks: unknown[]): unknown;
|
|
35
|
+
//# sourceMappingURL=langchain-content.d.ts.map
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { truncateAndSerialize } from "../truncation.js";
|
|
2
|
+
import { LANGCHAIN_FINISH_REASON_MAP } from "../semconv.js";
|
|
3
|
+
export const PROVIDER_MAP = {
|
|
4
|
+
ChatOpenAI: "openai",
|
|
5
|
+
AzureChatOpenAI: "azure.openai",
|
|
6
|
+
ChatAnthropic: "anthropic",
|
|
7
|
+
ChatGoogleGenerativeAI: "gcp.generative_ai",
|
|
8
|
+
ChatVertexAI: "gcp.vertex_ai",
|
|
9
|
+
ChatCohere: "cohere",
|
|
10
|
+
ChatMistralAI: "mistral",
|
|
11
|
+
ChatGroq: "groq",
|
|
12
|
+
ChatBedrock: "aws.bedrock",
|
|
13
|
+
ChatBedrockConverse: "aws.bedrock",
|
|
14
|
+
BedrockChat: "aws.bedrock",
|
|
15
|
+
ChatFireworks: "fireworks",
|
|
16
|
+
ChatTogether: "together",
|
|
17
|
+
ChatOllama: "ollama",
|
|
18
|
+
ChatDeepSeek: "deepseek",
|
|
19
|
+
};
|
|
20
|
+
export const MODULE_PROVIDER_MAP = {
|
|
21
|
+
openai: "openai",
|
|
22
|
+
anthropic: "anthropic",
|
|
23
|
+
google: "gcp.generative_ai",
|
|
24
|
+
cohere: "cohere",
|
|
25
|
+
mistral: "mistral",
|
|
26
|
+
groq: "groq",
|
|
27
|
+
bedrock: "aws.bedrock",
|
|
28
|
+
fireworks: "fireworks",
|
|
29
|
+
together: "together",
|
|
30
|
+
ollama: "ollama",
|
|
31
|
+
deepseek: "deepseek",
|
|
32
|
+
};
|
|
33
|
+
/** Detect LLM provider from a LangChain model instance. */
|
|
34
|
+
export function detectProvider(model) {
|
|
35
|
+
if (!model || typeof model !== "object")
|
|
36
|
+
return "langchain";
|
|
37
|
+
const m = model;
|
|
38
|
+
const className = m.constructor?.name ?? "";
|
|
39
|
+
if (className in PROVIDER_MAP)
|
|
40
|
+
return PROVIDER_MAP[className];
|
|
41
|
+
// LangChain's _llmType() returns the provider string directly (e.g. "openai", "anthropic").
|
|
42
|
+
if (typeof m._llmType === "function") {
|
|
43
|
+
try {
|
|
44
|
+
const t = m._llmType();
|
|
45
|
+
if (typeof t === "string" && t in MODULE_PROVIDER_MAP) {
|
|
46
|
+
return MODULE_PROVIDER_MAP[t];
|
|
47
|
+
}
|
|
48
|
+
if (typeof t === "string" && t)
|
|
49
|
+
return t;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
/* ignore */
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return "langchain";
|
|
56
|
+
}
|
|
57
|
+
/** Probe `modelName`, `model`, `modelId` attrs in order. */
|
|
58
|
+
export function detectModel(model) {
|
|
59
|
+
if (!model || typeof model !== "object")
|
|
60
|
+
return "unknown";
|
|
61
|
+
const m = model;
|
|
62
|
+
for (const attr of ["modelName", "model", "modelId"]) {
|
|
63
|
+
const val = m[attr];
|
|
64
|
+
if (typeof val === "string" && val.length > 0)
|
|
65
|
+
return val;
|
|
66
|
+
}
|
|
67
|
+
return "unknown";
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Extract the messages list from LangChain invoke()'s input argument.
|
|
71
|
+
* Handles: BaseMessage[], string, PromptValue (via toChatMessages/toMessages),
|
|
72
|
+
* dict with .messages key.
|
|
73
|
+
*/
|
|
74
|
+
export function extractInputMessages(input) {
|
|
75
|
+
if (input == null)
|
|
76
|
+
return [];
|
|
77
|
+
if (Array.isArray(input))
|
|
78
|
+
return input;
|
|
79
|
+
if (typeof input === "string") {
|
|
80
|
+
return [{ role: "user", content: input }];
|
|
81
|
+
}
|
|
82
|
+
if (typeof input === "object") {
|
|
83
|
+
const obj = input;
|
|
84
|
+
if (typeof obj.toChatMessages === "function") {
|
|
85
|
+
try {
|
|
86
|
+
return obj.toChatMessages() ?? [];
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
/* ignore */
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (typeof obj.toMessages === "function") {
|
|
93
|
+
try {
|
|
94
|
+
return obj.toMessages() ?? [];
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
/* ignore */
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (Array.isArray(obj.messages))
|
|
101
|
+
return obj.messages;
|
|
102
|
+
}
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Extract thread_id from LangChain/LangGraph RunnableConfig.
|
|
107
|
+
* Signature: (input, config?, ...). Config has shape { configurable: { thread_id: "..." } }.
|
|
108
|
+
*/
|
|
109
|
+
export function extractThreadId(args, options) {
|
|
110
|
+
const config = (args.length > 1 ? args[1] : undefined) ?? options ?? undefined;
|
|
111
|
+
if (!config || typeof config !== "object")
|
|
112
|
+
return undefined;
|
|
113
|
+
const configurable = config.configurable;
|
|
114
|
+
if (!configurable || typeof configurable !== "object")
|
|
115
|
+
return undefined;
|
|
116
|
+
const threadId = configurable.thread_id;
|
|
117
|
+
if (typeof threadId === "string" && threadId.length > 0)
|
|
118
|
+
return threadId;
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Extract tool_call_id from LangChain ToolCall input.
|
|
123
|
+
* LangChain tool invocation input shape: { name, args, id, type: "tool_call" }.
|
|
124
|
+
*/
|
|
125
|
+
export function extractToolCallId(args) {
|
|
126
|
+
const input = args.length > 0 ? args[0] : undefined;
|
|
127
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
128
|
+
return undefined;
|
|
129
|
+
const id = input.id;
|
|
130
|
+
if (typeof id === "string" && id.length > 0)
|
|
131
|
+
return id;
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
/** Convert a LangChain message to (role, parts). Uses ._getType() first, falls back to class name. */
|
|
135
|
+
export function langchainMessageToRoleAndParts(msg) {
|
|
136
|
+
if (msg && typeof msg === "object" && !Array.isArray(msg)) {
|
|
137
|
+
const m = msg;
|
|
138
|
+
// Plain dict form
|
|
139
|
+
if (typeof m.role === "string" && !("_getType" in m) && !("constructor" in m && m.constructor?.name?.endsWith("Message"))) {
|
|
140
|
+
const parts = [];
|
|
141
|
+
if (m.content)
|
|
142
|
+
parts.push({ type: "text", content: String(m.content) });
|
|
143
|
+
return { role: m.role, parts };
|
|
144
|
+
}
|
|
145
|
+
let type;
|
|
146
|
+
if (typeof m._getType === "function") {
|
|
147
|
+
try {
|
|
148
|
+
type = m._getType();
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
/* ignore */
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (!type) {
|
|
155
|
+
const cname = m.constructor?.name ?? "";
|
|
156
|
+
if (cname === "HumanMessage")
|
|
157
|
+
type = "human";
|
|
158
|
+
else if (cname === "SystemMessage")
|
|
159
|
+
type = "system";
|
|
160
|
+
else if (cname === "AIMessage" || cname === "AIMessageChunk")
|
|
161
|
+
type = "ai";
|
|
162
|
+
else if (cname === "ToolMessage")
|
|
163
|
+
type = "tool";
|
|
164
|
+
}
|
|
165
|
+
const parts = [];
|
|
166
|
+
const content = m.content;
|
|
167
|
+
if (type === "tool") {
|
|
168
|
+
const toolCallId = typeof m.tool_call_id === "string" ? m.tool_call_id : "";
|
|
169
|
+
parts.push({
|
|
170
|
+
type: "tool_call_response",
|
|
171
|
+
id: toolCallId,
|
|
172
|
+
response: typeof content === "string" ? content : String(content ?? ""),
|
|
173
|
+
});
|
|
174
|
+
return { role: "tool", parts };
|
|
175
|
+
}
|
|
176
|
+
// Text content (string) → text part
|
|
177
|
+
if (typeof content === "string" && content.length > 0) {
|
|
178
|
+
parts.push({ type: "text", content });
|
|
179
|
+
}
|
|
180
|
+
else if (Array.isArray(content)) {
|
|
181
|
+
for (const block of content) {
|
|
182
|
+
if (typeof block === "string") {
|
|
183
|
+
parts.push({ type: "text", content: block });
|
|
184
|
+
}
|
|
185
|
+
else if (block && typeof block === "object") {
|
|
186
|
+
const b = block;
|
|
187
|
+
const btype = b.type;
|
|
188
|
+
if (btype === "text") {
|
|
189
|
+
parts.push({ type: "text", content: String(b.text ?? "") });
|
|
190
|
+
}
|
|
191
|
+
else if (btype === "image_url") {
|
|
192
|
+
const url = b.image_url;
|
|
193
|
+
if (url && typeof url === "object") {
|
|
194
|
+
const u = url.url;
|
|
195
|
+
if (typeof u === "string") {
|
|
196
|
+
parts.push({ type: "uri", modality: "image", uri: u });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else if (typeof url === "string") {
|
|
200
|
+
parts.push({ type: "uri", modality: "image", uri: url });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// AI tool_calls → tool_call parts
|
|
207
|
+
if (type === "ai" || type === "assistant") {
|
|
208
|
+
const toolCalls = m.tool_calls;
|
|
209
|
+
if (Array.isArray(toolCalls)) {
|
|
210
|
+
for (const tc of toolCalls) {
|
|
211
|
+
const name = typeof tc.name === "string" ? tc.name : "";
|
|
212
|
+
const part = { type: "tool_call", name };
|
|
213
|
+
if (typeof tc.id === "string" && tc.id)
|
|
214
|
+
part.id = tc.id;
|
|
215
|
+
if (tc.args !== undefined)
|
|
216
|
+
part.arguments = tc.args;
|
|
217
|
+
parts.push(part);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { role: "assistant", parts };
|
|
221
|
+
}
|
|
222
|
+
if (type === "human" || type === "user")
|
|
223
|
+
return { role: "user", parts };
|
|
224
|
+
if (type === "system")
|
|
225
|
+
return { role: "system", parts };
|
|
226
|
+
if (type === "tool")
|
|
227
|
+
return { role: "tool", parts };
|
|
228
|
+
// Fallback: honor an explicit .role if present, else "user"
|
|
229
|
+
const role = typeof m.role === "string" ? m.role : type ?? "user";
|
|
230
|
+
return { role, parts };
|
|
231
|
+
}
|
|
232
|
+
return { role: "user", parts: [] };
|
|
233
|
+
}
|
|
234
|
+
export function langchainToInputMessages(messages) {
|
|
235
|
+
try {
|
|
236
|
+
const result = messages.map((msg) => {
|
|
237
|
+
const { role, parts } = langchainMessageToRoleAndParts(msg);
|
|
238
|
+
return { role, parts };
|
|
239
|
+
});
|
|
240
|
+
return truncateAndSerialize(result);
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return "[]";
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
export function langchainToOutputMessages(result) {
|
|
247
|
+
try {
|
|
248
|
+
const { parts } = langchainMessageToRoleAndParts(result);
|
|
249
|
+
const respMeta = (result && typeof result === "object"
|
|
250
|
+
? result
|
|
251
|
+
.response_metadata
|
|
252
|
+
: undefined) ?? {};
|
|
253
|
+
const finish = (typeof respMeta.finish_reason === "string" && respMeta.finish_reason) ||
|
|
254
|
+
(typeof respMeta.stop_reason === "string" && respMeta.stop_reason) ||
|
|
255
|
+
null;
|
|
256
|
+
const msg = { role: "assistant", parts };
|
|
257
|
+
if (finish) {
|
|
258
|
+
msg.finish_reason = LANGCHAIN_FINISH_REASON_MAP[finish] ?? finish;
|
|
259
|
+
}
|
|
260
|
+
return truncateAndSerialize([msg]);
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
return "[]";
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/** Last user message parts for parent invoke_agent span propagation. */
|
|
267
|
+
export function lastUserMessageParts(messages) {
|
|
268
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
269
|
+
const { role, parts } = langchainMessageToRoleAndParts(messages[i]);
|
|
270
|
+
if (role === "user")
|
|
271
|
+
return parts;
|
|
272
|
+
}
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
/** Merge a list of LangChain AIMessageChunks into one via .concat(). */
|
|
276
|
+
export function mergeChunks(chunks) {
|
|
277
|
+
if (chunks.length === 0)
|
|
278
|
+
return null;
|
|
279
|
+
let result = chunks[0];
|
|
280
|
+
for (let i = 1; i < chunks.length; i++) {
|
|
281
|
+
if (!result)
|
|
282
|
+
break;
|
|
283
|
+
try {
|
|
284
|
+
if (typeof result.concat === "function") {
|
|
285
|
+
result = result.concat(chunks[i]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=langchain-content.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StructSDK } from "../core.js";
|
|
2
|
+
import { StructCallbackHandler } from "./langchain-callback.js";
|
|
3
|
+
/**
|
|
4
|
+
* Export the handler so callers can register it explicitly
|
|
5
|
+
* (e.g. `runnable.invoke(x, { callbacks: [struct.langchainHandler] })`)
|
|
6
|
+
* when the global monkey-patch isn't an option.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getLangchainHandler(): StructCallbackHandler | undefined;
|
|
9
|
+
export declare function patch(sdk: StructSDK): Promise<void>;
|
|
10
|
+
export declare function unpatch(): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=langchain.d.ts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { StructCallbackHandler } from "./langchain-callback.js";
|
|
2
|
+
/**
|
|
3
|
+
* LangChain.js integration — registers a BaseCallbackHandler subclass with
|
|
4
|
+
* LangChain's CallbackManager so every chain/LLM/tool/retriever run produces
|
|
5
|
+
* an OTel span. This is the same integration pattern used by LangSmith,
|
|
6
|
+
* Arize OpenInference, Traceloop, and Langfuse.
|
|
7
|
+
*
|
|
8
|
+
* Why callbacks instead of monkey-patching: LangChain's callbacks carry
|
|
9
|
+
* parentRunId explicitly, so span parentage survives LangGraph's internal
|
|
10
|
+
* async microtask shuffling (which otherwise drops OTel's active context).
|
|
11
|
+
*/
|
|
12
|
+
const STRUCT_WRAPPED = Symbol.for("struct.wrapped");
|
|
13
|
+
const state = {};
|
|
14
|
+
/**
|
|
15
|
+
* Export the handler so callers can register it explicitly
|
|
16
|
+
* (e.g. `runnable.invoke(x, { callbacks: [struct.langchainHandler] })`)
|
|
17
|
+
* when the global monkey-patch isn't an option.
|
|
18
|
+
*/
|
|
19
|
+
export function getLangchainHandler() {
|
|
20
|
+
return state.handler;
|
|
21
|
+
}
|
|
22
|
+
export async function patch(sdk) {
|
|
23
|
+
const handler = new StructCallbackHandler(sdk, sdk.getTracer("struct-sdk-langchain"), sdk.emitEvents ? sdk.getLogger("struct-sdk-langchain") : undefined);
|
|
24
|
+
state.handler = handler;
|
|
25
|
+
// Monkey-patch CallbackManager.configure so every invoke/stream/batch call
|
|
26
|
+
// picks up our handler as an inheritable callback. This is exactly how
|
|
27
|
+
// OpenInference (@arizeai) and Traceloop hook into LangChain JS.
|
|
28
|
+
const mod = (await import("@langchain/core/callbacks/manager"));
|
|
29
|
+
const cm = mod.CallbackManager;
|
|
30
|
+
// Preserve original-function refs from any prior patch() — a second patch()
|
|
31
|
+
// call (e.g. autoInstrument then explicit patch) would otherwise wipe them,
|
|
32
|
+
// leaving unpatch() unable to restore.
|
|
33
|
+
const prev = state.cfg;
|
|
34
|
+
state.cfg = {
|
|
35
|
+
mod,
|
|
36
|
+
originalConfigure: prev?.originalConfigure,
|
|
37
|
+
originalConfigureSync: prev?.originalConfigureSync,
|
|
38
|
+
};
|
|
39
|
+
if (!cm.configure[STRUCT_WRAPPED]) {
|
|
40
|
+
const originalConfigure = cm.configure.bind(cm);
|
|
41
|
+
state.cfg.originalConfigure = originalConfigure;
|
|
42
|
+
const wrappedConfigure = function (...args) {
|
|
43
|
+
const active = state.handler;
|
|
44
|
+
if (active)
|
|
45
|
+
args[0] = injectHandler(args[0], active);
|
|
46
|
+
return originalConfigure.apply(cm, args);
|
|
47
|
+
};
|
|
48
|
+
wrappedConfigure[STRUCT_WRAPPED] = true;
|
|
49
|
+
cm.configure = wrappedConfigure;
|
|
50
|
+
}
|
|
51
|
+
if (cm._configureSync && !cm._configureSync[STRUCT_WRAPPED]) {
|
|
52
|
+
const originalSync = cm._configureSync.bind(cm);
|
|
53
|
+
state.cfg.originalConfigureSync = originalSync;
|
|
54
|
+
const wrappedSync = function (...args) {
|
|
55
|
+
const active = state.handler;
|
|
56
|
+
if (active)
|
|
57
|
+
args[0] = injectHandler(args[0], active);
|
|
58
|
+
return originalSync.apply(cm, args);
|
|
59
|
+
};
|
|
60
|
+
wrappedSync[STRUCT_WRAPPED] = true;
|
|
61
|
+
cm._configureSync = wrappedSync;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export async function unpatch() {
|
|
65
|
+
if (state.cfg?.mod) {
|
|
66
|
+
const cm = state.cfg.mod.CallbackManager;
|
|
67
|
+
if (cm.configure[STRUCT_WRAPPED] && state.cfg.originalConfigure) {
|
|
68
|
+
cm.configure = state.cfg.originalConfigure;
|
|
69
|
+
}
|
|
70
|
+
if (cm._configureSync?.[STRUCT_WRAPPED] &&
|
|
71
|
+
state.cfg.originalConfigureSync) {
|
|
72
|
+
cm._configureSync = state.cfg.originalConfigureSync;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
state.handler = undefined;
|
|
76
|
+
state.cfg = undefined;
|
|
77
|
+
}
|
|
78
|
+
function injectHandler(existing, handler) {
|
|
79
|
+
if (existing == null)
|
|
80
|
+
return [handler];
|
|
81
|
+
if (Array.isArray(existing)) {
|
|
82
|
+
if (existing.some((h) => h?.name === "struct")) {
|
|
83
|
+
return existing;
|
|
84
|
+
}
|
|
85
|
+
return [...existing, handler];
|
|
86
|
+
}
|
|
87
|
+
// BaseCallbackManager instance: addHandler on it.
|
|
88
|
+
const mgr = existing;
|
|
89
|
+
if (typeof mgr.addHandler === "function" &&
|
|
90
|
+
!mgr.handlers?.some((h) => h?.name === "struct")) {
|
|
91
|
+
mgr.addHandler(handler, true);
|
|
92
|
+
}
|
|
93
|
+
return existing;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=langchain.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare const GEN_AI: {
|
|
2
|
+
readonly OPERATION_NAME: "gen_ai.operation.name";
|
|
3
|
+
readonly PROVIDER_NAME: "gen_ai.provider.name";
|
|
4
|
+
readonly SYSTEM: "gen_ai.system";
|
|
5
|
+
readonly AGENT_NAME: "gen_ai.agent.name";
|
|
6
|
+
readonly AGENT_ID: "gen_ai.agent.id";
|
|
7
|
+
readonly AGENT_VERSION: "gen_ai.agent.version";
|
|
8
|
+
readonly CONVERSATION_ID: "gen_ai.conversation.id";
|
|
9
|
+
readonly REQUEST_MODEL: "gen_ai.request.model";
|
|
10
|
+
readonly REQUEST_MAX_TOKENS: "gen_ai.request.max_tokens";
|
|
11
|
+
readonly REQUEST_TEMPERATURE: "gen_ai.request.temperature";
|
|
12
|
+
readonly REQUEST_TOP_P: "gen_ai.request.top_p";
|
|
13
|
+
readonly REQUEST_TOP_K: "gen_ai.request.top_k";
|
|
14
|
+
readonly REQUEST_FREQUENCY_PENALTY: "gen_ai.request.frequency_penalty";
|
|
15
|
+
readonly REQUEST_PRESENCE_PENALTY: "gen_ai.request.presence_penalty";
|
|
16
|
+
readonly REQUEST_STOP_SEQUENCES: "gen_ai.request.stop_sequences";
|
|
17
|
+
readonly RESPONSE_MODEL: "gen_ai.response.model";
|
|
18
|
+
readonly RESPONSE_FINISH_REASONS: "gen_ai.response.finish_reasons";
|
|
19
|
+
readonly RESPONSE_ID: "gen_ai.response.id";
|
|
20
|
+
readonly USAGE_INPUT_TOKENS: "gen_ai.usage.input_tokens";
|
|
21
|
+
readonly USAGE_OUTPUT_TOKENS: "gen_ai.usage.output_tokens";
|
|
22
|
+
readonly USAGE_CACHE_READ_INPUT_TOKENS: "gen_ai.usage.cache_read.input_tokens";
|
|
23
|
+
readonly USAGE_CACHE_CREATION_INPUT_TOKENS: "gen_ai.usage.cache_creation.input_tokens";
|
|
24
|
+
readonly INPUT_MESSAGES: "gen_ai.input.messages";
|
|
25
|
+
readonly OUTPUT_MESSAGES: "gen_ai.output.messages";
|
|
26
|
+
readonly SYSTEM_INSTRUCTIONS: "gen_ai.system_instructions";
|
|
27
|
+
readonly TOOL_DEFINITIONS: "gen_ai.tool.definitions";
|
|
28
|
+
readonly TOOL_NAME: "gen_ai.tool.name";
|
|
29
|
+
readonly TOOL_CALL_ID: "gen_ai.tool.call.id";
|
|
30
|
+
readonly TOOL_CALL_ARGUMENTS: "gen_ai.tool.call.arguments";
|
|
31
|
+
readonly TOOL_CALL_RESULT: "gen_ai.tool.call.result";
|
|
32
|
+
readonly DATA_SOURCE_ID: "gen_ai.data_source.id";
|
|
33
|
+
readonly RETRIEVAL_QUERY_TEXT: "gen_ai.retrieval.query.text";
|
|
34
|
+
readonly RETRIEVAL_DOCUMENTS: "gen_ai.retrieval.documents";
|
|
35
|
+
readonly MESSAGE_INDEX: "gen_ai.message.index";
|
|
36
|
+
};
|
|
37
|
+
export declare const STRUCT: {
|
|
38
|
+
readonly METADATA_PREFIX: "struct.metadata.";
|
|
39
|
+
readonly AGENT_PARENT_SESSION_ID: "struct.agent.parent_session_id";
|
|
40
|
+
readonly INPUT_MESSAGE_COUNT: "struct.input.message_count";
|
|
41
|
+
};
|
|
42
|
+
export declare const EVENT_NAME = "event.name";
|
|
43
|
+
export declare const ERROR_TYPE = "error.type";
|
|
44
|
+
export declare const EVENT_NAMES: {
|
|
45
|
+
readonly USER_MESSAGE: "gen_ai.user.message";
|
|
46
|
+
readonly ASSISTANT_MESSAGE: "gen_ai.assistant.message";
|
|
47
|
+
readonly SYSTEM_MESSAGE: "gen_ai.system.message";
|
|
48
|
+
readonly TOOL_MESSAGE: "gen_ai.tool.message";
|
|
49
|
+
readonly CHOICE: "gen_ai.choice";
|
|
50
|
+
};
|
|
51
|
+
export declare const ROLE_TO_EVENT_NAME: Record<string, string>;
|
|
52
|
+
export declare const ANTHROPIC_FINISH_REASON_MAP: Record<string, string>;
|
|
53
|
+
export declare const LANGCHAIN_FINISH_REASON_MAP: Record<string, string>;
|
|
54
|
+
//# sourceMappingURL=semconv.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const GEN_AI = {
|
|
2
|
+
OPERATION_NAME: "gen_ai.operation.name",
|
|
3
|
+
PROVIDER_NAME: "gen_ai.provider.name",
|
|
4
|
+
SYSTEM: "gen_ai.system",
|
|
5
|
+
AGENT_NAME: "gen_ai.agent.name",
|
|
6
|
+
AGENT_ID: "gen_ai.agent.id",
|
|
7
|
+
AGENT_VERSION: "gen_ai.agent.version",
|
|
8
|
+
CONVERSATION_ID: "gen_ai.conversation.id",
|
|
9
|
+
REQUEST_MODEL: "gen_ai.request.model",
|
|
10
|
+
REQUEST_MAX_TOKENS: "gen_ai.request.max_tokens",
|
|
11
|
+
REQUEST_TEMPERATURE: "gen_ai.request.temperature",
|
|
12
|
+
REQUEST_TOP_P: "gen_ai.request.top_p",
|
|
13
|
+
REQUEST_TOP_K: "gen_ai.request.top_k",
|
|
14
|
+
REQUEST_FREQUENCY_PENALTY: "gen_ai.request.frequency_penalty",
|
|
15
|
+
REQUEST_PRESENCE_PENALTY: "gen_ai.request.presence_penalty",
|
|
16
|
+
REQUEST_STOP_SEQUENCES: "gen_ai.request.stop_sequences",
|
|
17
|
+
RESPONSE_MODEL: "gen_ai.response.model",
|
|
18
|
+
RESPONSE_FINISH_REASONS: "gen_ai.response.finish_reasons",
|
|
19
|
+
RESPONSE_ID: "gen_ai.response.id",
|
|
20
|
+
USAGE_INPUT_TOKENS: "gen_ai.usage.input_tokens",
|
|
21
|
+
USAGE_OUTPUT_TOKENS: "gen_ai.usage.output_tokens",
|
|
22
|
+
USAGE_CACHE_READ_INPUT_TOKENS: "gen_ai.usage.cache_read.input_tokens",
|
|
23
|
+
USAGE_CACHE_CREATION_INPUT_TOKENS: "gen_ai.usage.cache_creation.input_tokens",
|
|
24
|
+
INPUT_MESSAGES: "gen_ai.input.messages",
|
|
25
|
+
OUTPUT_MESSAGES: "gen_ai.output.messages",
|
|
26
|
+
SYSTEM_INSTRUCTIONS: "gen_ai.system_instructions",
|
|
27
|
+
TOOL_DEFINITIONS: "gen_ai.tool.definitions",
|
|
28
|
+
TOOL_NAME: "gen_ai.tool.name",
|
|
29
|
+
TOOL_CALL_ID: "gen_ai.tool.call.id",
|
|
30
|
+
TOOL_CALL_ARGUMENTS: "gen_ai.tool.call.arguments",
|
|
31
|
+
TOOL_CALL_RESULT: "gen_ai.tool.call.result",
|
|
32
|
+
DATA_SOURCE_ID: "gen_ai.data_source.id",
|
|
33
|
+
RETRIEVAL_QUERY_TEXT: "gen_ai.retrieval.query.text",
|
|
34
|
+
RETRIEVAL_DOCUMENTS: "gen_ai.retrieval.documents",
|
|
35
|
+
MESSAGE_INDEX: "gen_ai.message.index",
|
|
36
|
+
};
|
|
37
|
+
export const STRUCT = {
|
|
38
|
+
METADATA_PREFIX: "struct.metadata.",
|
|
39
|
+
AGENT_PARENT_SESSION_ID: "struct.agent.parent_session_id",
|
|
40
|
+
INPUT_MESSAGE_COUNT: "struct.input.message_count",
|
|
41
|
+
};
|
|
42
|
+
export const EVENT_NAME = "event.name";
|
|
43
|
+
export const ERROR_TYPE = "error.type";
|
|
44
|
+
export const EVENT_NAMES = {
|
|
45
|
+
USER_MESSAGE: "gen_ai.user.message",
|
|
46
|
+
ASSISTANT_MESSAGE: "gen_ai.assistant.message",
|
|
47
|
+
SYSTEM_MESSAGE: "gen_ai.system.message",
|
|
48
|
+
TOOL_MESSAGE: "gen_ai.tool.message",
|
|
49
|
+
CHOICE: "gen_ai.choice",
|
|
50
|
+
};
|
|
51
|
+
export const ROLE_TO_EVENT_NAME = {
|
|
52
|
+
user: EVENT_NAMES.USER_MESSAGE,
|
|
53
|
+
assistant: EVENT_NAMES.ASSISTANT_MESSAGE,
|
|
54
|
+
system: EVENT_NAMES.SYSTEM_MESSAGE,
|
|
55
|
+
tool: EVENT_NAMES.TOOL_MESSAGE,
|
|
56
|
+
};
|
|
57
|
+
export const ANTHROPIC_FINISH_REASON_MAP = {
|
|
58
|
+
end_turn: "stop",
|
|
59
|
+
stop_sequence: "stop",
|
|
60
|
+
max_tokens: "length",
|
|
61
|
+
tool_use: "tool_call",
|
|
62
|
+
};
|
|
63
|
+
export const LANGCHAIN_FINISH_REASON_MAP = {
|
|
64
|
+
end_turn: "stop",
|
|
65
|
+
stop_sequence: "stop",
|
|
66
|
+
max_tokens: "length",
|
|
67
|
+
tool_use: "tool_calls",
|
|
68
|
+
tool_calls: "tool_calls",
|
|
69
|
+
function_call: "tool_calls",
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=semconv.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const MAX_CONTENT_SIZE: number;
|
|
2
|
+
export declare const MAX_FIELD_SIZE = 16384;
|
|
3
|
+
export declare const TRUNCATION_MARKER = "\u2026 [truncated]";
|
|
4
|
+
export declare function truncateField<T>(value: T, maxLen?: number): T | string;
|
|
5
|
+
type Part = Record<string, unknown>;
|
|
6
|
+
export declare function truncateParts(parts: Part[]): Part[];
|
|
7
|
+
export declare function truncateAndSerialize(obj: unknown, maxSize?: number): string;
|
|
8
|
+
export declare function safeJsonStringify(obj: unknown): string;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=truncation.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export const MAX_CONTENT_SIZE = 128 * 1024;
|
|
2
|
+
export const MAX_FIELD_SIZE = 16384;
|
|
3
|
+
export const TRUNCATION_MARKER = "… [truncated]";
|
|
4
|
+
export function truncateField(value, maxLen = MAX_FIELD_SIZE) {
|
|
5
|
+
if (typeof value === "string" && value.length > maxLen) {
|
|
6
|
+
return value.slice(0, maxLen) + TRUNCATION_MARKER;
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
export function truncateParts(parts) {
|
|
11
|
+
const result = [];
|
|
12
|
+
for (const original of parts) {
|
|
13
|
+
const part = { ...original };
|
|
14
|
+
if (typeof part.content === "string") {
|
|
15
|
+
part.content = truncateField(part.content);
|
|
16
|
+
}
|
|
17
|
+
if ("arguments" in part) {
|
|
18
|
+
const arg = part.arguments;
|
|
19
|
+
if (typeof arg === "string") {
|
|
20
|
+
part.arguments = truncateField(arg);
|
|
21
|
+
}
|
|
22
|
+
else if (arg && typeof arg === "object") {
|
|
23
|
+
const serialized = safeJsonStringify(arg);
|
|
24
|
+
if (serialized.length > MAX_FIELD_SIZE) {
|
|
25
|
+
part.arguments = serialized.slice(0, MAX_FIELD_SIZE) + TRUNCATION_MARKER;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if ("response" in part) {
|
|
30
|
+
const resp = part.response;
|
|
31
|
+
if (typeof resp === "string") {
|
|
32
|
+
part.response = truncateField(resp);
|
|
33
|
+
}
|
|
34
|
+
else if (resp && typeof resp === "object") {
|
|
35
|
+
const serialized = safeJsonStringify(resp);
|
|
36
|
+
if (serialized.length > MAX_FIELD_SIZE) {
|
|
37
|
+
part.response = serialized.slice(0, MAX_FIELD_SIZE) + TRUNCATION_MARKER;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
result.push(part);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
export function truncateAndSerialize(obj, maxSize = MAX_CONTENT_SIZE) {
|
|
46
|
+
let result;
|
|
47
|
+
if (Array.isArray(obj)) {
|
|
48
|
+
const truncated = obj.map((item) => {
|
|
49
|
+
if (!item || typeof item !== "object")
|
|
50
|
+
return item;
|
|
51
|
+
const copy = { ...item };
|
|
52
|
+
if (Array.isArray(copy.parts)) {
|
|
53
|
+
copy.parts = truncateParts(copy.parts);
|
|
54
|
+
}
|
|
55
|
+
else if (typeof copy.content === "string") {
|
|
56
|
+
copy.content = truncateField(copy.content);
|
|
57
|
+
}
|
|
58
|
+
return copy;
|
|
59
|
+
});
|
|
60
|
+
result = safeJsonStringify(truncated);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
result = safeJsonStringify(obj);
|
|
64
|
+
}
|
|
65
|
+
if (result.length > maxSize) {
|
|
66
|
+
const cut = result.slice(0, maxSize - 50);
|
|
67
|
+
const lastBrace = cut.lastIndexOf("}");
|
|
68
|
+
if (lastBrace > 0) {
|
|
69
|
+
result = cut.slice(0, lastBrace + 1) + "]";
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
result = "[]";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
export function safeJsonStringify(obj) {
|
|
78
|
+
try {
|
|
79
|
+
return JSON.stringify(obj, defaultReplacer);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return JSON.stringify(String(obj));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function defaultReplacer(_key, value) {
|
|
86
|
+
if (typeof value === "bigint")
|
|
87
|
+
return value.toString();
|
|
88
|
+
if (value instanceof Error)
|
|
89
|
+
return `${value.name}: ${value.message}`;
|
|
90
|
+
if (value instanceof Map)
|
|
91
|
+
return Object.fromEntries(value.entries());
|
|
92
|
+
if (value instanceof Set)
|
|
93
|
+
return Array.from(value);
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=truncation.js.map
|