@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,408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StructSDK = exports.firstFailureLogged = exports.DEFAULT_ENDPOINT = void 0;
|
|
4
|
+
exports.safe = safe;
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const exporter_logs_otlp_proto_1 = require("@opentelemetry/exporter-logs-otlp-proto");
|
|
8
|
+
const exporter_trace_otlp_proto_1 = require("@opentelemetry/exporter-trace-otlp-proto");
|
|
9
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
10
|
+
const sdk_logs_1 = require("@opentelemetry/sdk-logs");
|
|
11
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
12
|
+
const content_capture_js_1 = require("./content-capture.js");
|
|
13
|
+
const context_js_1 = require("./context.js");
|
|
14
|
+
const index_js_1 = require("./integrations/index.js");
|
|
15
|
+
const semconv_js_1 = require("./semconv.js");
|
|
16
|
+
const truncation_js_1 = require("./truncation.js");
|
|
17
|
+
exports.DEFAULT_ENDPOINT = "https://ingest.struct.ai";
|
|
18
|
+
const LOG_ENABLED = process.env.STRUCT_SDK_LOG === "1";
|
|
19
|
+
const defaultInternalLogger = {
|
|
20
|
+
info: (msg, ...args) => {
|
|
21
|
+
if (LOG_ENABLED)
|
|
22
|
+
console.info(`[struct-sdk] ${msg}`, ...args);
|
|
23
|
+
},
|
|
24
|
+
warn: (msg, ...args) => console.warn(`[struct-sdk] ${msg}`, ...args),
|
|
25
|
+
debug: (msg, ...args) => {
|
|
26
|
+
if (LOG_ENABLED)
|
|
27
|
+
console.debug(`[struct-sdk] ${msg}`, ...args);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Sites that have already logged a first-failure WARN; subsequent failures at
|
|
32
|
+
* the same site log at DEBUG. Mirrors `_first_failure_logged` in the Python
|
|
33
|
+
* SDK.
|
|
34
|
+
*
|
|
35
|
+
* Exported for tests that need to clear the set between runs so log-level
|
|
36
|
+
* assertions are deterministic. Internal — not re-exported from `index.ts`,
|
|
37
|
+
* so consumers cannot reach it via the package's public API surface.
|
|
38
|
+
*/
|
|
39
|
+
exports.firstFailureLogged = new Set();
|
|
40
|
+
/**
|
|
41
|
+
* Run `fn`; swallow any exception. The first failure per `site` logs at WARN
|
|
42
|
+
* (with the error attached); subsequent failures at the same site log at
|
|
43
|
+
* DEBUG. The caller's logger is passed explicitly so this helper stays a free
|
|
44
|
+
* module-level function — usable from instrumentation modules that don't
|
|
45
|
+
* carry an SDK reference of their own.
|
|
46
|
+
*
|
|
47
|
+
* Mirrors `_safe(fn, *, site)` in the Python SDK.
|
|
48
|
+
*/
|
|
49
|
+
function safe(fn, site, logger) {
|
|
50
|
+
try {
|
|
51
|
+
fn();
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
if (exports.firstFailureLogged.has(site)) {
|
|
55
|
+
logger.debug(`Struct SDK suppressed exception at ${site}`, err);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
exports.firstFailureLogged.add(site);
|
|
59
|
+
logger.warn(`Struct SDK suppressed exception at ${site}`, err);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class StructSDK {
|
|
64
|
+
_initialized = false;
|
|
65
|
+
_tracerProvider;
|
|
66
|
+
_loggerProvider;
|
|
67
|
+
_ingestKey = "";
|
|
68
|
+
_endpoint = exports.DEFAULT_ENDPOINT;
|
|
69
|
+
_contentCapture = content_capture_js_1.ContentCaptureMode.EventOnly;
|
|
70
|
+
_shutdownHook;
|
|
71
|
+
// Always set so `shutdown()` can read it even when init() was never called
|
|
72
|
+
// or failed before reaching the assignment in init(). Mirrors the Python
|
|
73
|
+
// SDK's `_shutdown_timeout_seconds` default in `__init__`.
|
|
74
|
+
_shutdownTimeoutMs = 5000;
|
|
75
|
+
_internalLogger = defaultInternalLogger;
|
|
76
|
+
_readyPromise = Promise.resolve();
|
|
77
|
+
/** Resolves once auto-instrumentation has attempted to patch every detected library. */
|
|
78
|
+
get ready() {
|
|
79
|
+
return this._readyPromise;
|
|
80
|
+
}
|
|
81
|
+
get initialized() {
|
|
82
|
+
return this._initialized;
|
|
83
|
+
}
|
|
84
|
+
get endpoint() {
|
|
85
|
+
return this._endpoint;
|
|
86
|
+
}
|
|
87
|
+
get ingestKey() {
|
|
88
|
+
return this._ingestKey;
|
|
89
|
+
}
|
|
90
|
+
get contentCapture() {
|
|
91
|
+
return this._contentCapture;
|
|
92
|
+
}
|
|
93
|
+
get captureContent() {
|
|
94
|
+
return (0, content_capture_js_1.captureContentFor)(this._contentCapture);
|
|
95
|
+
}
|
|
96
|
+
get emitEvents() {
|
|
97
|
+
return (0, content_capture_js_1.emitEventsFor)(this._contentCapture);
|
|
98
|
+
}
|
|
99
|
+
get emitSpanContent() {
|
|
100
|
+
return (0, content_capture_js_1.emitSpanContentFor)(this._contentCapture);
|
|
101
|
+
}
|
|
102
|
+
init(options) {
|
|
103
|
+
if (this._initialized) {
|
|
104
|
+
this._internalLogger.warn("struct.init() called multiple times — ignoring");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const { ingestKey, serviceName = "default-agent", serviceVersion = "0.0.0", environment = "development", endpoint = exports.DEFAULT_ENDPOINT, captureContent = true, contentCapture, shutdownTimeoutMs = 5000, } = options;
|
|
108
|
+
this._ingestKey = ingestKey;
|
|
109
|
+
this._endpoint = endpoint.replace(/\/+$/, "");
|
|
110
|
+
// Stored before any code that could throw so shutdown() always sees
|
|
111
|
+
// the user-configured timeout, even on a partially-failed init.
|
|
112
|
+
this._shutdownTimeoutMs = shutdownTimeoutMs;
|
|
113
|
+
if (contentCapture !== undefined) {
|
|
114
|
+
this._contentCapture = contentCapture;
|
|
115
|
+
}
|
|
116
|
+
else if (!captureContent) {
|
|
117
|
+
this._contentCapture = content_capture_js_1.ContentCaptureMode.None;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this._contentCapture = content_capture_js_1.ContentCaptureMode.EventOnly;
|
|
121
|
+
}
|
|
122
|
+
// Everything from here through autoInstrument() can fail in the wild —
|
|
123
|
+
// exporter constructors validate URLs, the resource builder may reject
|
|
124
|
+
// attribute values, processors allocate buffers, etc. The SDK contract
|
|
125
|
+
// is that init() never raises; on failure we leave the SDK in a clean
|
|
126
|
+
// disabled state and let the user's app keep running. Decorator-style
|
|
127
|
+
// calls (`agent`, `tool`) already short-circuit when `_initialized`
|
|
128
|
+
// is false, so a disabled SDK is a no-op rather than a hazard.
|
|
129
|
+
try {
|
|
130
|
+
const headers = { "x-struct-ingest-key": ingestKey };
|
|
131
|
+
const spanExporter = new exporter_trace_otlp_proto_1.OTLPTraceExporter({
|
|
132
|
+
url: `${this._endpoint}/v1/traces`,
|
|
133
|
+
headers,
|
|
134
|
+
});
|
|
135
|
+
const spanProcessor = new sdk_trace_node_1.BatchSpanProcessor(spanExporter, {
|
|
136
|
+
maxQueueSize: 10000,
|
|
137
|
+
maxExportBatchSize: 100,
|
|
138
|
+
scheduledDelayMillis: 1000,
|
|
139
|
+
});
|
|
140
|
+
const resource = new resources_1.Resource({
|
|
141
|
+
"service.name": serviceName,
|
|
142
|
+
"service.version": serviceVersion,
|
|
143
|
+
"deployment.environment": environment,
|
|
144
|
+
});
|
|
145
|
+
this._tracerProvider = new sdk_trace_node_1.NodeTracerProvider({
|
|
146
|
+
resource,
|
|
147
|
+
spanProcessors: [spanProcessor],
|
|
148
|
+
});
|
|
149
|
+
const logExporter = new exporter_logs_otlp_proto_1.OTLPLogExporter({
|
|
150
|
+
url: `${this._endpoint}/v1/logs`,
|
|
151
|
+
headers,
|
|
152
|
+
});
|
|
153
|
+
const logProcessor = new sdk_logs_1.BatchLogRecordProcessor(logExporter, {
|
|
154
|
+
maxQueueSize: 10000,
|
|
155
|
+
maxExportBatchSize: 100,
|
|
156
|
+
scheduledDelayMillis: 1000,
|
|
157
|
+
});
|
|
158
|
+
this._loggerProvider = new sdk_logs_1.LoggerProvider({ resource });
|
|
159
|
+
this._loggerProvider.addLogRecordProcessor(logProcessor);
|
|
160
|
+
this._initialized = true;
|
|
161
|
+
this._shutdownHook = () => {
|
|
162
|
+
void this.shutdown();
|
|
163
|
+
};
|
|
164
|
+
process.on("beforeExit", this._shutdownHook);
|
|
165
|
+
this._readyPromise = (0, index_js_1.autoInstrument)(this);
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
this._internalLogger.warn(`Struct SDK init failed; SDK disabled: service=${serviceName} endpoint=${this._endpoint}`, err);
|
|
169
|
+
// Tear down anything we may have already wired up. If process.on
|
|
170
|
+
// succeeded but a later step failed, the beforeExit listener is still
|
|
171
|
+
// live — unregister it so the disabled SDK doesn't run shutdown logic
|
|
172
|
+
// against half-built providers at process exit.
|
|
173
|
+
if (this._shutdownHook) {
|
|
174
|
+
process.off("beforeExit", this._shutdownHook);
|
|
175
|
+
}
|
|
176
|
+
this._initialized = false;
|
|
177
|
+
this._tracerProvider = undefined;
|
|
178
|
+
this._loggerProvider = undefined;
|
|
179
|
+
this._shutdownHook = undefined;
|
|
180
|
+
this._readyPromise = Promise.resolve();
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this._internalLogger.info(`Struct SDK initialized: service=${serviceName} endpoint=${this._endpoint} content_capture=${this._contentCapture}`);
|
|
184
|
+
}
|
|
185
|
+
getTracer(name = "struct-sdk") {
|
|
186
|
+
if (!this._tracerProvider) {
|
|
187
|
+
throw new Error("Call struct.init() before using the SDK");
|
|
188
|
+
}
|
|
189
|
+
return this._tracerProvider.getTracer(name);
|
|
190
|
+
}
|
|
191
|
+
getLogger(name = "struct-sdk") {
|
|
192
|
+
if (!this._loggerProvider) {
|
|
193
|
+
throw new Error("Call struct.init() before using the SDK");
|
|
194
|
+
}
|
|
195
|
+
return this._loggerProvider.getLogger(name);
|
|
196
|
+
}
|
|
197
|
+
getInternalLogger() {
|
|
198
|
+
return this._internalLogger;
|
|
199
|
+
}
|
|
200
|
+
/** Test-only: attach a custom span processor to the internal provider. */
|
|
201
|
+
addSpanProcessor(processor) {
|
|
202
|
+
this._tracerProvider?.addSpanProcessor(processor);
|
|
203
|
+
}
|
|
204
|
+
/** Test-only: attach a custom log record processor. */
|
|
205
|
+
addLogRecordProcessor(processor) {
|
|
206
|
+
this._loggerProvider?.addLogRecordProcessor(processor);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Shut down the SDK and flush pending telemetry.
|
|
210
|
+
*
|
|
211
|
+
* Returns within `timeoutMs` (default: SDK init's `shutdownTimeoutMs`,
|
|
212
|
+
* fallback 5000ms). If the ingest endpoint is unreachable, in-flight
|
|
213
|
+
* telemetry may be dropped — the trade-off vs. blocking process exit.
|
|
214
|
+
*
|
|
215
|
+
* In serverless / edge runtimes (Lambda, Vercel, etc.), the runtime does
|
|
216
|
+
* NOT await our `beforeExit` hook. Call `await struct.shutdown()`
|
|
217
|
+
* explicitly before your function returns or before container freeze.
|
|
218
|
+
*
|
|
219
|
+
* Safe to call multiple times. Safe to call on an SDK that failed to init
|
|
220
|
+
* or was never initialized.
|
|
221
|
+
*
|
|
222
|
+
* @param timeoutMs - Override the configured shutdown timeout for this call.
|
|
223
|
+
*/
|
|
224
|
+
async shutdown(timeoutMs) {
|
|
225
|
+
const timeout = timeoutMs ?? this._shutdownTimeoutMs;
|
|
226
|
+
if (this._shutdownHook) {
|
|
227
|
+
process.off("beforeExit", this._shutdownHook);
|
|
228
|
+
this._shutdownHook = undefined;
|
|
229
|
+
}
|
|
230
|
+
// Order matches the previous behavior (logger first, tracer second) so
|
|
231
|
+
// any consumer that depended on relative ordering keeps working.
|
|
232
|
+
const flushAll = async () => {
|
|
233
|
+
await this._loggerProvider?.shutdown().catch(() => undefined);
|
|
234
|
+
await this._tracerProvider?.shutdown().catch(() => undefined);
|
|
235
|
+
};
|
|
236
|
+
let timedOut = false;
|
|
237
|
+
const timer = new Promise((resolve) => {
|
|
238
|
+
const handle = setTimeout(() => {
|
|
239
|
+
timedOut = true;
|
|
240
|
+
resolve("timeout");
|
|
241
|
+
}, timeout);
|
|
242
|
+
// Don't keep the event loop alive for this timer — once flushAll
|
|
243
|
+
// resolves, the process is free to exit even though the timer hasn't
|
|
244
|
+
// fired. `unref` is missing on some non-Node timer shims, hence `?.`.
|
|
245
|
+
handle.unref?.();
|
|
246
|
+
});
|
|
247
|
+
const result = await Promise.race([flushAll(), timer]);
|
|
248
|
+
if (timedOut || result === "timeout") {
|
|
249
|
+
// DEBUG-only: atexit context is noisy enough; a WARN here would
|
|
250
|
+
// clutter user stderr for a fault we already handled.
|
|
251
|
+
this._internalLogger.debug(`Struct SDK shutdown timed out after ${timeout}ms (ingest may be unreachable)`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Run `fn` inside an `invoke_agent` span scope.
|
|
256
|
+
* Matches Python's _AgentContext behavior.
|
|
257
|
+
*/
|
|
258
|
+
async agent(options, fn) {
|
|
259
|
+
if (!this._initialized) {
|
|
260
|
+
return await fn();
|
|
261
|
+
}
|
|
262
|
+
const agentName = options.name;
|
|
263
|
+
const sessionId = options.sessionId ?? (0, node_crypto_1.randomUUID)();
|
|
264
|
+
const parentSessionId = (0, context_js_1.getSessionId)();
|
|
265
|
+
const tracer = this.getTracer("struct-sdk");
|
|
266
|
+
// Parent the new agent span on the nearest enclosing agent span (if
|
|
267
|
+
// any) so nested `struct.agent()` / `struct.tool()` calls build a
|
|
268
|
+
// single trace tree. Falls back to OTel's active context (which may
|
|
269
|
+
// include the caller's own OTel span), or a fresh trace when there's
|
|
270
|
+
// nothing to hang off. We do NOT rely on the global OTel context
|
|
271
|
+
// manager being installed — the SDK manages its own parent chain via
|
|
272
|
+
// StructContext ALS to stay neutral in multi-tenant OTel setups.
|
|
273
|
+
const parentSpan = (0, context_js_1.getAgentSpan)();
|
|
274
|
+
const parentCtx = parentSpan
|
|
275
|
+
? api_1.trace.setSpan(api_1.context.active(), parentSpan)
|
|
276
|
+
: api_1.context.active();
|
|
277
|
+
// Span creation itself can fail (custom tracer, broken context). If it
|
|
278
|
+
// does, fall through to running `fn` directly so the user's call
|
|
279
|
+
// always runs uninstrumented rather than blowing up on telemetry.
|
|
280
|
+
let span;
|
|
281
|
+
safe(() => {
|
|
282
|
+
span = tracer.startSpan(`invoke_agent ${agentName}`, { kind: api_1.SpanKind.INTERNAL }, parentCtx);
|
|
283
|
+
}, "agent.start_span", this._internalLogger);
|
|
284
|
+
if (span === undefined) {
|
|
285
|
+
return await fn();
|
|
286
|
+
}
|
|
287
|
+
const startedSpan = span;
|
|
288
|
+
safe(() => {
|
|
289
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.OPERATION_NAME, "invoke_agent");
|
|
290
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.PROVIDER_NAME, "struct");
|
|
291
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.AGENT_NAME, agentName);
|
|
292
|
+
// gen_ai.agent.id is the stable identifier of the agent
|
|
293
|
+
// DEFINITION. Only set it when the caller provides one — we do
|
|
294
|
+
// not auto-derive it from sessionId (that would conflate agent
|
|
295
|
+
// identity with invocation).
|
|
296
|
+
if (options.agentId) {
|
|
297
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.AGENT_ID, options.agentId);
|
|
298
|
+
}
|
|
299
|
+
if (options.version) {
|
|
300
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.AGENT_VERSION, options.version);
|
|
301
|
+
}
|
|
302
|
+
// gen_ai.conversation.id is the spec-blessed name for
|
|
303
|
+
// session/thread id.
|
|
304
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.CONVERSATION_ID, sessionId);
|
|
305
|
+
if (parentSessionId && parentSessionId !== sessionId) {
|
|
306
|
+
startedSpan.setAttribute(semconv_js_1.STRUCT.AGENT_PARENT_SESSION_ID, parentSessionId);
|
|
307
|
+
}
|
|
308
|
+
if (options.metadata) {
|
|
309
|
+
for (const [key, value] of Object.entries(options.metadata)) {
|
|
310
|
+
startedSpan.setAttribute(`${semconv_js_1.STRUCT.METADATA_PREFIX}${key}`, value);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}, "agent.set_attrs", this._internalLogger);
|
|
314
|
+
return await (0, context_js_1.runWithContext)({
|
|
315
|
+
sessionId,
|
|
316
|
+
conversationId: sessionId,
|
|
317
|
+
agentSpan: startedSpan,
|
|
318
|
+
pendingToolCalls: {},
|
|
319
|
+
}, async () => {
|
|
320
|
+
const activeCtx = api_1.trace.setSpan(api_1.context.active(), startedSpan);
|
|
321
|
+
try {
|
|
322
|
+
const result = await api_1.context.with(activeCtx, fn);
|
|
323
|
+
safe(() => startedSpan.setStatus({ code: api_1.SpanStatusCode.OK }), "agent.set_ok_status", this._internalLogger);
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
safe(() => recordError(startedSpan, err), "agent.record_error", this._internalLogger);
|
|
328
|
+
throw err;
|
|
329
|
+
}
|
|
330
|
+
finally {
|
|
331
|
+
safe(() => startedSpan.end(), "agent.span_end", this._internalLogger);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Run `fn` inside an `execute_tool` span scope.
|
|
337
|
+
* Matches Python's _ToolContext behavior.
|
|
338
|
+
*/
|
|
339
|
+
async tool(options, fn) {
|
|
340
|
+
if (!this._initialized) {
|
|
341
|
+
return await fn();
|
|
342
|
+
}
|
|
343
|
+
const toolName = options.name;
|
|
344
|
+
let toolCallId = options.toolCallId;
|
|
345
|
+
if (!toolCallId) {
|
|
346
|
+
toolCallId = (0, context_js_1.popPendingToolCallId)(toolName);
|
|
347
|
+
}
|
|
348
|
+
const tracer = this.getTracer("struct-sdk");
|
|
349
|
+
// Parent on the enclosing agent span (StructContext ALS) so tool spans
|
|
350
|
+
// live under their agent in the same trace. See the comment in
|
|
351
|
+
// `agent()` — we manage our own parent chain rather than depend on the
|
|
352
|
+
// global OTel context manager being registered.
|
|
353
|
+
const parentSpan = (0, context_js_1.getAgentSpan)();
|
|
354
|
+
const parentCtx = parentSpan
|
|
355
|
+
? api_1.trace.setSpan(api_1.context.active(), parentSpan)
|
|
356
|
+
: api_1.context.active();
|
|
357
|
+
// Span creation itself can fail. Fall through to running `fn` so the
|
|
358
|
+
// user's tool call always runs uninstrumented rather than failing
|
|
359
|
+
// because of telemetry.
|
|
360
|
+
let span;
|
|
361
|
+
safe(() => {
|
|
362
|
+
span = tracer.startSpan(`execute_tool ${toolName}`, { kind: api_1.SpanKind.INTERNAL }, parentCtx);
|
|
363
|
+
}, "tool.start_span", this._internalLogger);
|
|
364
|
+
if (span === undefined) {
|
|
365
|
+
return await fn();
|
|
366
|
+
}
|
|
367
|
+
const startedSpan = span;
|
|
368
|
+
safe(() => {
|
|
369
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.OPERATION_NAME, "execute_tool");
|
|
370
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.PROVIDER_NAME, "struct");
|
|
371
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.TOOL_NAME, toolName);
|
|
372
|
+
if (toolCallId) {
|
|
373
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.TOOL_CALL_ID, toolCallId);
|
|
374
|
+
}
|
|
375
|
+
const sessionId = (0, context_js_1.getSessionId)();
|
|
376
|
+
if (sessionId) {
|
|
377
|
+
startedSpan.setAttribute(semconv_js_1.GEN_AI.CONVERSATION_ID, sessionId);
|
|
378
|
+
}
|
|
379
|
+
}, "tool.set_attrs", this._internalLogger);
|
|
380
|
+
const activeCtx = api_1.trace.setSpan(api_1.context.active(), startedSpan);
|
|
381
|
+
try {
|
|
382
|
+
const result = await api_1.context.with(activeCtx, fn);
|
|
383
|
+
if (this.captureContent && result !== undefined && result !== null) {
|
|
384
|
+
safe(() => startedSpan.setAttribute(semconv_js_1.GEN_AI.TOOL_CALL_RESULT, (0, truncation_js_1.safeJsonStringify)(result).slice(0, 8192)), "tool.set_result_attr", this._internalLogger);
|
|
385
|
+
}
|
|
386
|
+
safe(() => startedSpan.setStatus({ code: api_1.SpanStatusCode.OK }), "tool.set_ok_status", this._internalLogger);
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
catch (err) {
|
|
390
|
+
safe(() => recordError(startedSpan, err), "tool.record_error", this._internalLogger);
|
|
391
|
+
throw err;
|
|
392
|
+
}
|
|
393
|
+
finally {
|
|
394
|
+
safe(() => startedSpan.end(), "tool.span_end", this._internalLogger);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
exports.StructSDK = StructSDK;
|
|
399
|
+
function recordError(span, err) {
|
|
400
|
+
const errorType = err instanceof Error ? err.constructor.name : typeof err;
|
|
401
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
402
|
+
span.setAttribute(semconv_js_1.ERROR_TYPE, errorType);
|
|
403
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message });
|
|
404
|
+
if (err instanceof Error) {
|
|
405
|
+
span.recordException(err);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Logger } from "@opentelemetry/api-logs";
|
|
2
|
+
/**
|
|
3
|
+
* Emit per-message log events for an Anthropic messages.create() call.
|
|
4
|
+
* Port of _emit_message_events from anthropic.py.
|
|
5
|
+
*/
|
|
6
|
+
export declare function emitAnthropicMessageEvents(logger: Logger, messages: unknown, system: unknown): void;
|
|
7
|
+
/**
|
|
8
|
+
* Emit a gen_ai.choice LogRecord for an Anthropic response.
|
|
9
|
+
* Port of _emit_choice_event from anthropic.py.
|
|
10
|
+
*/
|
|
11
|
+
export declare function emitAnthropicChoiceEvent(logger: Logger, contentBlocks: unknown, stopReason: string | null | undefined): void;
|
|
12
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emitAnthropicMessageEvents = emitAnthropicMessageEvents;
|
|
4
|
+
exports.emitAnthropicChoiceEvent = emitAnthropicChoiceEvent;
|
|
5
|
+
const api_1 = require("@opentelemetry/api");
|
|
6
|
+
const api_logs_1 = require("@opentelemetry/api-logs");
|
|
7
|
+
const context_js_1 = require("./context.js");
|
|
8
|
+
const semconv_js_1 = require("./semconv.js");
|
|
9
|
+
const truncation_js_1 = require("./truncation.js");
|
|
10
|
+
const anthropic_content_js_1 = require("./integrations/anthropic-content.js");
|
|
11
|
+
/**
|
|
12
|
+
* Emit a LogRecord with the active span context linked.
|
|
13
|
+
*
|
|
14
|
+
* Follows the OTel logs data model convention:
|
|
15
|
+
* - `body` (log record body) = event tag string (human-readable signal)
|
|
16
|
+
* - `attributes.body` (log record attribute) = JSON-serialised payload
|
|
17
|
+
*/
|
|
18
|
+
function emitLogRecord({ logger, eventName, payload, extraAttrs = {}, }) {
|
|
19
|
+
const sessionId = (0, context_js_1.getSessionId)();
|
|
20
|
+
const attributes = {
|
|
21
|
+
[semconv_js_1.EVENT_NAME]: eventName,
|
|
22
|
+
body: payload,
|
|
23
|
+
...extraAttrs,
|
|
24
|
+
};
|
|
25
|
+
if (sessionId)
|
|
26
|
+
attributes[semconv_js_1.GEN_AI.CONVERSATION_ID] = sessionId;
|
|
27
|
+
logger.emit({
|
|
28
|
+
body: eventName,
|
|
29
|
+
severityNumber: api_logs_1.SeverityNumber.INFO,
|
|
30
|
+
attributes,
|
|
31
|
+
context: api_1.context.active(),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Emit per-message log events for an Anthropic messages.create() call.
|
|
36
|
+
* Port of _emit_message_events from anthropic.py.
|
|
37
|
+
*/
|
|
38
|
+
function emitAnthropicMessageEvents(logger, messages, system) {
|
|
39
|
+
if (!Array.isArray(messages))
|
|
40
|
+
return;
|
|
41
|
+
let msgIndex = 0;
|
|
42
|
+
if (system) {
|
|
43
|
+
const parts = typeof system === "string"
|
|
44
|
+
? [{ type: "text", content: system }]
|
|
45
|
+
: Array.isArray(system)
|
|
46
|
+
? (0, anthropic_content_js_1.contentToParts)(system)
|
|
47
|
+
: [{ type: "text", content: String(system) }];
|
|
48
|
+
emitLogRecord({
|
|
49
|
+
logger,
|
|
50
|
+
eventName: semconv_js_1.EVENT_NAMES.SYSTEM_MESSAGE,
|
|
51
|
+
payload: (0, truncation_js_1.safeJsonStringify)({
|
|
52
|
+
role: "system",
|
|
53
|
+
parts: (0, truncation_js_1.truncateParts)(parts),
|
|
54
|
+
}),
|
|
55
|
+
extraAttrs: {
|
|
56
|
+
[semconv_js_1.GEN_AI.SYSTEM]: "anthropic",
|
|
57
|
+
[semconv_js_1.GEN_AI.MESSAGE_INDEX]: msgIndex,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
msgIndex++;
|
|
61
|
+
}
|
|
62
|
+
for (const msg of messages) {
|
|
63
|
+
if (!msg || typeof msg !== "object")
|
|
64
|
+
continue;
|
|
65
|
+
const m = msg;
|
|
66
|
+
const role = typeof m.role === "string" ? m.role : "user";
|
|
67
|
+
const parts = (0, anthropic_content_js_1.contentToParts)(m.content);
|
|
68
|
+
const eventName = semconv_js_1.ROLE_TO_EVENT_NAME[role] ?? `gen_ai.${role}.message`;
|
|
69
|
+
emitLogRecord({
|
|
70
|
+
logger,
|
|
71
|
+
eventName,
|
|
72
|
+
payload: (0, truncation_js_1.safeJsonStringify)({ role, parts: (0, truncation_js_1.truncateParts)(parts) }),
|
|
73
|
+
extraAttrs: {
|
|
74
|
+
[semconv_js_1.GEN_AI.SYSTEM]: "anthropic",
|
|
75
|
+
[semconv_js_1.GEN_AI.MESSAGE_INDEX]: msgIndex,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
msgIndex++;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Emit a gen_ai.choice LogRecord for an Anthropic response.
|
|
83
|
+
* Port of _emit_choice_event from anthropic.py.
|
|
84
|
+
*/
|
|
85
|
+
function emitAnthropicChoiceEvent(logger, contentBlocks, stopReason) {
|
|
86
|
+
const parts = (0, anthropic_content_js_1.contentToParts)(contentBlocks);
|
|
87
|
+
const mappedReason = (stopReason && (semconv_js_1.ANTHROPIC_FINISH_REASON_MAP[stopReason] ?? stopReason)) ||
|
|
88
|
+
"stop";
|
|
89
|
+
const payload = (0, truncation_js_1.safeJsonStringify)({
|
|
90
|
+
index: 0,
|
|
91
|
+
finish_reason: mappedReason,
|
|
92
|
+
message: { role: "assistant", parts: (0, truncation_js_1.truncateParts)(parts) },
|
|
93
|
+
});
|
|
94
|
+
emitLogRecord({
|
|
95
|
+
logger,
|
|
96
|
+
eventName: semconv_js_1.EVENT_NAMES.CHOICE,
|
|
97
|
+
payload,
|
|
98
|
+
extraAttrs: {
|
|
99
|
+
[semconv_js_1.GEN_AI.SYSTEM]: "anthropic",
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { StructSDK } from "./core.js";
|
|
2
|
+
export { ContentCaptureMode } from "./content-capture.js";
|
|
3
|
+
export type { AgentScopeOptions, InitOptions, InternalLogger, ToolScopeOptions, } from "./core.js";
|
|
4
|
+
export { StructSDK } from "./core.js";
|
|
5
|
+
export declare const struct: StructSDK;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.struct = exports.StructSDK = exports.ContentCaptureMode = void 0;
|
|
4
|
+
const core_js_1 = require("./core.js");
|
|
5
|
+
var content_capture_js_1 = require("./content-capture.js");
|
|
6
|
+
Object.defineProperty(exports, "ContentCaptureMode", { enumerable: true, get: function () { return content_capture_js_1.ContentCaptureMode; } });
|
|
7
|
+
var core_js_2 = require("./core.js");
|
|
8
|
+
Object.defineProperty(exports, "StructSDK", { enumerable: true, get: function () { return core_js_2.StructSDK; } });
|
|
9
|
+
exports.struct = new core_js_1.StructSDK();
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { truncateField } from "../truncation.js";
|
|
2
|
+
/** Part in the GenAI spec format. */
|
|
3
|
+
export type Part = Record<string, unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* Walk Anthropic response content blocks, return (name, id) pairs for tool_use blocks.
|
|
6
|
+
* Port of _iter_tool_uses from anthropic.py.
|
|
7
|
+
*/
|
|
8
|
+
export declare function iterToolUses(blocks: unknown): Array<[string, string]>;
|
|
9
|
+
/**
|
|
10
|
+
* Convert arbitrary content (string | block[] | unknown) → GenAI parts.
|
|
11
|
+
* Port of _content_to_parts from anthropic.py.
|
|
12
|
+
*/
|
|
13
|
+
export declare function contentToParts(content: unknown): Part[];
|
|
14
|
+
/** Convert Anthropic message list → GenAI input-messages JSON string. */
|
|
15
|
+
export declare function toInputMessages(messages: unknown): string;
|
|
16
|
+
/** Convert response content blocks → GenAI output-messages JSON string. */
|
|
17
|
+
export declare function toOutputMessages(contentBlocks: unknown, stopReason: string | null | undefined): string;
|
|
18
|
+
/** Convert system prompt (string | block[]) → GenAI system_instructions JSON string. */
|
|
19
|
+
export declare function toSystemInstructions(system: unknown): string;
|
|
20
|
+
export declare function safeJsonForTool(obj: unknown): string;
|
|
21
|
+
/** Extract the last user message's parts for parent-span propagation. */
|
|
22
|
+
export declare function lastUserMessageParts(messages: unknown): Part[] | undefined;
|
|
23
|
+
export { truncateField };
|
|
24
|
+
//# sourceMappingURL=anthropic-content.d.ts.map
|