@struct-ai/sdk 0.2.0 → 0.3.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/README.md +46 -3
- package/dist/commonjs/core.d.ts +2 -0
- package/dist/commonjs/core.js +53 -7
- package/dist/esm/core.d.ts +2 -0
- package/dist/esm/core.js +54 -8
- package/package.json +21 -21
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/content-capture.d.ts +0 -10
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/context.d.ts +0 -30
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/core.d.ts +0 -120
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/events.d.ts +0 -12
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/index.d.ts +0 -6
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/anthropic-content.d.ts +0 -24
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/anthropic.d.ts +0 -34
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/index.d.ts +0 -5
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain-callback.d.ts +0 -134
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain-content.d.ts +0 -35
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain.d.ts +0 -11
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/package.json +0 -3
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/semconv.d.ts +0 -54
- package/dist/node_modules/@struct-ai/sdk/dist/commonjs/truncation.d.ts +0 -10
- package/dist/node_modules/@struct-ai/sdk/dist/esm/content-capture.d.ts +0 -10
- package/dist/node_modules/@struct-ai/sdk/dist/esm/context.d.ts +0 -30
- package/dist/node_modules/@struct-ai/sdk/dist/esm/core.d.ts +0 -120
- package/dist/node_modules/@struct-ai/sdk/dist/esm/events.d.ts +0 -12
- package/dist/node_modules/@struct-ai/sdk/dist/esm/index.d.ts +0 -6
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/anthropic-content.d.ts +0 -24
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/anthropic.d.ts +0 -34
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/index.d.ts +0 -5
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain-callback.d.ts +0 -134
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain-content.d.ts +0 -35
- package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain.d.ts +0 -11
- package/dist/node_modules/@struct-ai/sdk/dist/esm/package.json +0 -3
- package/dist/node_modules/@struct-ai/sdk/dist/esm/semconv.d.ts +0 -54
- package/dist/node_modules/@struct-ai/sdk/dist/esm/truncation.d.ts +0 -10
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/commonjs/package.json +0 -3
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/esm/package.json +0 -3
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/package.json +0 -103
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/package.json +0 -103
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/package.json +0 -118
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/package.json +0 -916
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/package.json +0 -188
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/openai/package.json +0 -105
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api/package.json +0 -96
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api-logs/package.json +0 -91
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/core/package.json +0 -96
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-logs-otlp-proto/package.json +0 -108
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-trace-otlp-proto/package.json +0 -105
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/resources/package.json +0 -100
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-logs/package.json +0 -109
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-base/package.json +0 -100
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-node/package.json +0 -76
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/package.json +0 -140
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/nock/package.json +0 -89
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/tshy/package.json +0 -81
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/tsx/package.json +0 -68
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/typescript/package.json +0 -120
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/vitest/package.json +0 -239
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/zod/package.json +0 -135
- package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/package.json +0 -103
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/core.d.ts +0 -244
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/error.d.ts +0 -54
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/index.d.ts +0 -188
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/package.json +0 -103
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/pagination.d.ts +0 -26
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/resource.d.ts +0 -6
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/streaming.d.ts +0 -41
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/uploads.d.ts +0 -75
- package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/version.d.ts +0 -2
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/experimental.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/index.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/package.json +0 -118
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/agents.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/caches.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/chat_history.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/context.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/documents.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/embeddings.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/example_selectors.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/index.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/indexing.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/load.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/memory.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/messages.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/output_parsers.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/outputs.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/package.json +0 -916
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/prompt_values.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/prompts.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/retrievers.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/runnables.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/singletons.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/stores.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/structured_query.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/tools.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/vectorstores.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/index.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/package.json +0 -188
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/prebuilt.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/pregel.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/remote.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/web.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/zod.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/openai/index.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/openai/package.json +0 -105
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api/package.json +0 -96
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api-logs/package.json +0 -91
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/core/package.json +0 -96
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-logs-otlp-proto/package.json +0 -108
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-trace-otlp-proto/package.json +0 -105
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/resources/package.json +0 -100
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-logs/package.json +0 -109
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-base/package.json +0 -100
- package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-node/package.json +0 -76
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/assert.d.ts +0 -1062
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/async_hooks.d.ts +0 -605
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/buffer.buffer.d.ts +0 -471
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/buffer.d.ts +0 -1936
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/child_process.d.ts +0 -1475
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/cluster.d.ts +0 -577
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/console.d.ts +0 -452
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/constants.d.ts +0 -21
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/crypto.d.ts +0 -4590
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/dgram.d.ts +0 -597
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/diagnostics_channel.d.ts +0 -578
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/dns.d.ts +0 -871
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/domain.d.ts +0 -170
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/events.d.ts +0 -977
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/fs.d.ts +0 -4375
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/globals.d.ts +0 -172
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/globals.typedarray.d.ts +0 -38
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/http.d.ts +0 -2049
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/http2.d.ts +0 -2631
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/https.d.ts +0 -578
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/index.d.ts +0 -93
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/inspector.generated.d.ts +0 -3966
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/module.d.ts +0 -539
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/net.d.ts +0 -1031
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/os.d.ts +0 -506
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/package.json +0 -140
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/path.d.ts +0 -200
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/perf_hooks.d.ts +0 -961
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/process.d.ts +0 -1961
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/punycode.d.ts +0 -117
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/querystring.d.ts +0 -152
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/readline.d.ts +0 -589
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/repl.d.ts +0 -430
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/sea.d.ts +0 -153
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/stream.d.ts +0 -1698
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/test.d.ts +0 -1787
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/timers.d.ts +0 -286
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/tls.d.ts +0 -1259
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/trace_events.d.ts +0 -197
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/tty.d.ts +0 -208
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/url.d.ts +0 -964
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/util.d.ts +0 -2331
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/v8.d.ts +0 -809
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/vm.d.ts +0 -1001
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/wasi.d.ts +0 -181
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/worker_threads.d.ts +0 -715
- package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/zlib.d.ts +0 -598
- package/dist/node_modules/@struct-ai/sdk/node_modules/nock/package.json +0 -89
- package/dist/node_modules/@struct-ai/sdk/node_modules/tshy/package.json +0 -81
- package/dist/node_modules/@struct-ai/sdk/node_modules/tsx/package.json +0 -68
- package/dist/node_modules/@struct-ai/sdk/node_modules/typescript/package.json +0 -120
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/config.d.ts +0 -3
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/coverage.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/environments.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/globals.d.ts +0 -22
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/import-meta.d.ts +0 -5
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/importMeta.d.ts +0 -4
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/jsdom.d.ts +0 -6
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/mocker.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/node.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/optional-runtime-types.d.ts +0 -6
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/optional-types.d.ts +0 -7
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/package.json +0 -239
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/reporters.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/runners.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/snapshot.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/suite.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/worker.d.ts +0 -1
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/index.d.ts +0 -4
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/locales/package.json +0 -7
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/mini/package.json +0 -7
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/package.json +0 -135
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v3/package.json +0 -7
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/classic/package.json +0 -7
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/core/package.json +0 -7
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/locales/package.json +0 -7
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/mini/package.json +0 -7
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/package.json +0 -7
- package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4-mini/package.json +0 -7
- package/dist/node_modules/@struct-ai/sdk/package.json +0 -103
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ await struct.agent({ name: "checkout" }, async () => {
|
|
|
60
60
|
| `@langchain/core` `BaseChatModel` | `.invoke`, `.stream` | `chat {model}` | Skipped when a provider-direct instrumentor is active (e.g. ChatAnthropic + Anthropic patch → single span) |
|
|
61
61
|
| `@langchain/core` `StructuredTool` | `.invoke` | `execute_tool {name}` | Extracts `tool_call_id` from LangChain ToolCall input or pending queue |
|
|
62
62
|
| `@langchain/core` `BaseRetriever` | `.invoke` | `retrieval {name}` | |
|
|
63
|
-
| `@langchain/langgraph` `Pregel` | `.invoke`, `.stream` | `invoke_agent {name}` | Covers `createReactAgent
|
|
63
|
+
| `@langchain/langgraph` `Pregel` | `.invoke`, `.stream` | `invoke_agent {name}` | Covers `createReactAgent` and custom graphs. Reads conversation id from any of: `configurable.thread_id` (LangGraph canonical), or `metadata.{thread_id, session_id, conversation_id}` (LangSmith conventions). For multi-turn HTTP-style threading, wrap your entry point in [`struct.agent({ sessionId: convId }, ...)`](#recommended-pattern-wrap-langchain-entry-points-in-structagent) — the struct-native replacement for LangSmith's `tracing_context(parent=run_tree)`. |
|
|
64
64
|
|
|
65
65
|
## Framework integration
|
|
66
66
|
|
|
@@ -97,6 +97,39 @@ import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
|
97
97
|
// BaseRetriever.invoke gets retrieval spans.
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
##### Recommended pattern: wrap LangChain entry points in `struct.agent`
|
|
101
|
+
|
|
102
|
+
For multi-turn HTTP-style usage (every request continues the same
|
|
103
|
+
conversation), wrap your request handler in
|
|
104
|
+
`struct.agent({ sessionId: conversationId }, async () => { ... })`.
|
|
105
|
+
This is the struct-native replacement for `with ls.tracing_context(parent=run_tree):`
|
|
106
|
+
and gives you two things you can't get from `configurable.thread_id` alone:
|
|
107
|
+
|
|
108
|
+
1. **Threading without per-call config plumbing.** Every nested
|
|
109
|
+
LangChain call inherits the conversation id via the SDK's ambient
|
|
110
|
+
AsyncLocalStorage — you don't have to ensure each `compiledGraph.invoke`
|
|
111
|
+
gets `thread_id` on its config.
|
|
112
|
+
2. **One trace per request.** `struct.agent` creates a parent OTel span
|
|
113
|
+
so all the LangChain work for the request nests under one trace
|
|
114
|
+
(clean tree, "Subagents" / "Spawned by" UI links work). Without it,
|
|
115
|
+
each `.invoke()` becomes its own root trace, and the UI's session
|
|
116
|
+
list shows a non-deterministic agent name (`omni_agent`,
|
|
117
|
+
`LangGraph`, the first sub-agent it sees…).
|
|
118
|
+
|
|
119
|
+
Migrating from LangSmith:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
// Before — LangSmith convention, fragments under struct-sdk
|
|
123
|
+
await ls.traceable(async () => {
|
|
124
|
+
await orchestrator.invoke(inputs, config);
|
|
125
|
+
}, { parent: runTree })();
|
|
126
|
+
|
|
127
|
+
// After — struct-native, threads correctly, no langsmith dep
|
|
128
|
+
await struct.agent({ sessionId: conversationId }, async () => {
|
|
129
|
+
await orchestrator.invoke(inputs, config);
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
100
133
|
### LLM SDKs used directly — manual agent + tool scopes required
|
|
101
134
|
|
|
102
135
|
When you call an LLM SDK directly (no agent framework wrapping it), only
|
|
@@ -201,8 +234,18 @@ await struct.agent(
|
|
|
201
234
|
);
|
|
202
235
|
```
|
|
203
236
|
|
|
204
|
-
|
|
205
|
-
|
|
237
|
+
Sub-agents (e.g. a `createReactAgent` graph invoked from inside another
|
|
238
|
+
agent's tool body) record their parent via the
|
|
239
|
+
`struct.agent.parent_session_id` attribute on the inner `invoke_agent`
|
|
240
|
+
span. This powers the UI's "Spawned by" backlink, which works for any
|
|
241
|
+
nested invocation.
|
|
242
|
+
|
|
243
|
+
The parent's "Subagents" forward list — the inverse direction — requires
|
|
244
|
+
that the nested invoke inherits the parent's trace via LangChain's
|
|
245
|
+
callback chain. This works automatically when the outer tool is built
|
|
246
|
+
with the `tool()` factory from `@langchain/core/tools`; it does **not**
|
|
247
|
+
work with `new DynamicTool({...})`, which skips the callback wrap. See
|
|
248
|
+
the troubleshooting section below for the workaround.
|
|
206
249
|
|
|
207
250
|
## Semantic conventions
|
|
208
251
|
|
package/dist/commonjs/core.d.ts
CHANGED
package/dist/commonjs/core.js
CHANGED
|
@@ -37,6 +37,43 @@ const defaultInternalLogger = {
|
|
|
37
37
|
* so consumers cannot reach it via the package's public API surface.
|
|
38
38
|
*/
|
|
39
39
|
exports.firstFailureLogged = new Set();
|
|
40
|
+
/**
|
|
41
|
+
* OTel SDK 2.x providers accept processors only at construction time —
|
|
42
|
+
* `addSpanProcessor` / `addLogRecordProcessor` no longer exist on the
|
|
43
|
+
* providers. These fan-outs are registered at construction and delegate to a
|
|
44
|
+
* mutable list, preserving the SDK's test-only `addSpanProcessor` /
|
|
45
|
+
* `addLogRecordProcessor` hooks.
|
|
46
|
+
*/
|
|
47
|
+
class FanoutSpanProcessor {
|
|
48
|
+
delegates = [];
|
|
49
|
+
onStart(...args) {
|
|
50
|
+
for (const p of this.delegates)
|
|
51
|
+
p.onStart(...args);
|
|
52
|
+
}
|
|
53
|
+
onEnd(...args) {
|
|
54
|
+
for (const p of this.delegates)
|
|
55
|
+
p.onEnd(...args);
|
|
56
|
+
}
|
|
57
|
+
forceFlush() {
|
|
58
|
+
return Promise.all(this.delegates.map((p) => p.forceFlush())).then(() => undefined);
|
|
59
|
+
}
|
|
60
|
+
shutdown() {
|
|
61
|
+
return Promise.all(this.delegates.map((p) => p.shutdown())).then(() => undefined);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class FanoutLogRecordProcessor {
|
|
65
|
+
delegates = [];
|
|
66
|
+
onEmit(...args) {
|
|
67
|
+
for (const p of this.delegates)
|
|
68
|
+
p.onEmit(...args);
|
|
69
|
+
}
|
|
70
|
+
forceFlush() {
|
|
71
|
+
return Promise.all(this.delegates.map((p) => p.forceFlush())).then(() => undefined);
|
|
72
|
+
}
|
|
73
|
+
shutdown() {
|
|
74
|
+
return Promise.all(this.delegates.map((p) => p.shutdown())).then(() => undefined);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
40
77
|
/**
|
|
41
78
|
* Run `fn`; swallow any exception. The first failure per `site` logs at WARN
|
|
42
79
|
* (with the error attached); subsequent failures at the same site log at
|
|
@@ -64,6 +101,8 @@ class StructSDK {
|
|
|
64
101
|
_initialized = false;
|
|
65
102
|
_tracerProvider;
|
|
66
103
|
_loggerProvider;
|
|
104
|
+
_spanFanout;
|
|
105
|
+
_logFanout;
|
|
67
106
|
_ingestKey = "";
|
|
68
107
|
_endpoint = exports.DEFAULT_ENDPOINT;
|
|
69
108
|
_contentCapture = content_capture_js_1.ContentCaptureMode.EventOnly;
|
|
@@ -137,26 +176,31 @@ class StructSDK {
|
|
|
137
176
|
maxExportBatchSize: 100,
|
|
138
177
|
scheduledDelayMillis: 1000,
|
|
139
178
|
});
|
|
140
|
-
const resource =
|
|
179
|
+
const resource = (0, resources_1.resourceFromAttributes)({
|
|
141
180
|
"service.name": serviceName,
|
|
142
181
|
"service.version": serviceVersion,
|
|
143
182
|
"deployment.environment": environment,
|
|
144
183
|
});
|
|
184
|
+
this._spanFanout = new FanoutSpanProcessor();
|
|
145
185
|
this._tracerProvider = new sdk_trace_node_1.NodeTracerProvider({
|
|
146
186
|
resource,
|
|
147
|
-
spanProcessors: [spanProcessor],
|
|
187
|
+
spanProcessors: [spanProcessor, this._spanFanout],
|
|
148
188
|
});
|
|
149
189
|
const logExporter = new exporter_logs_otlp_proto_1.OTLPLogExporter({
|
|
150
190
|
url: `${this._endpoint}/v1/logs`,
|
|
151
191
|
headers,
|
|
152
192
|
});
|
|
153
|
-
const logProcessor = new sdk_logs_1.BatchLogRecordProcessor(
|
|
193
|
+
const logProcessor = new sdk_logs_1.BatchLogRecordProcessor({
|
|
194
|
+
exporter: logExporter,
|
|
154
195
|
maxQueueSize: 10000,
|
|
155
196
|
maxExportBatchSize: 100,
|
|
156
197
|
scheduledDelayMillis: 1000,
|
|
157
198
|
});
|
|
158
|
-
this.
|
|
159
|
-
this._loggerProvider.
|
|
199
|
+
this._logFanout = new FanoutLogRecordProcessor();
|
|
200
|
+
this._loggerProvider = new sdk_logs_1.LoggerProvider({
|
|
201
|
+
resource,
|
|
202
|
+
processors: [logProcessor, this._logFanout],
|
|
203
|
+
});
|
|
160
204
|
this._initialized = true;
|
|
161
205
|
this._shutdownHook = () => {
|
|
162
206
|
void this.shutdown();
|
|
@@ -176,6 +220,8 @@ class StructSDK {
|
|
|
176
220
|
this._initialized = false;
|
|
177
221
|
this._tracerProvider = undefined;
|
|
178
222
|
this._loggerProvider = undefined;
|
|
223
|
+
this._spanFanout = undefined;
|
|
224
|
+
this._logFanout = undefined;
|
|
179
225
|
this._shutdownHook = undefined;
|
|
180
226
|
this._readyPromise = Promise.resolve();
|
|
181
227
|
return;
|
|
@@ -199,11 +245,11 @@ class StructSDK {
|
|
|
199
245
|
}
|
|
200
246
|
/** Test-only: attach a custom span processor to the internal provider. */
|
|
201
247
|
addSpanProcessor(processor) {
|
|
202
|
-
this.
|
|
248
|
+
this._spanFanout?.delegates.push(processor);
|
|
203
249
|
}
|
|
204
250
|
/** Test-only: attach a custom log record processor. */
|
|
205
251
|
addLogRecordProcessor(processor) {
|
|
206
|
-
this.
|
|
252
|
+
this._logFanout?.delegates.push(processor);
|
|
207
253
|
}
|
|
208
254
|
/**
|
|
209
255
|
* Shut down the SDK and flush pending telemetry.
|
package/dist/esm/core.d.ts
CHANGED
package/dist/esm/core.js
CHANGED
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { context as otelContext, SpanKind, SpanStatusCode, trace, } from "@opentelemetry/api";
|
|
3
3
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
|
|
4
4
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
5
|
-
import {
|
|
5
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
6
6
|
import { BatchLogRecordProcessor, LoggerProvider, } from "@opentelemetry/sdk-logs";
|
|
7
7
|
import { BatchSpanProcessor, NodeTracerProvider, } from "@opentelemetry/sdk-trace-node";
|
|
8
8
|
import { ContentCaptureMode, captureContentFor, emitEventsFor, emitSpanContentFor, } from "./content-capture.js";
|
|
@@ -33,6 +33,43 @@ const defaultInternalLogger = {
|
|
|
33
33
|
* so consumers cannot reach it via the package's public API surface.
|
|
34
34
|
*/
|
|
35
35
|
export const firstFailureLogged = new Set();
|
|
36
|
+
/**
|
|
37
|
+
* OTel SDK 2.x providers accept processors only at construction time —
|
|
38
|
+
* `addSpanProcessor` / `addLogRecordProcessor` no longer exist on the
|
|
39
|
+
* providers. These fan-outs are registered at construction and delegate to a
|
|
40
|
+
* mutable list, preserving the SDK's test-only `addSpanProcessor` /
|
|
41
|
+
* `addLogRecordProcessor` hooks.
|
|
42
|
+
*/
|
|
43
|
+
class FanoutSpanProcessor {
|
|
44
|
+
delegates = [];
|
|
45
|
+
onStart(...args) {
|
|
46
|
+
for (const p of this.delegates)
|
|
47
|
+
p.onStart(...args);
|
|
48
|
+
}
|
|
49
|
+
onEnd(...args) {
|
|
50
|
+
for (const p of this.delegates)
|
|
51
|
+
p.onEnd(...args);
|
|
52
|
+
}
|
|
53
|
+
forceFlush() {
|
|
54
|
+
return Promise.all(this.delegates.map((p) => p.forceFlush())).then(() => undefined);
|
|
55
|
+
}
|
|
56
|
+
shutdown() {
|
|
57
|
+
return Promise.all(this.delegates.map((p) => p.shutdown())).then(() => undefined);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class FanoutLogRecordProcessor {
|
|
61
|
+
delegates = [];
|
|
62
|
+
onEmit(...args) {
|
|
63
|
+
for (const p of this.delegates)
|
|
64
|
+
p.onEmit(...args);
|
|
65
|
+
}
|
|
66
|
+
forceFlush() {
|
|
67
|
+
return Promise.all(this.delegates.map((p) => p.forceFlush())).then(() => undefined);
|
|
68
|
+
}
|
|
69
|
+
shutdown() {
|
|
70
|
+
return Promise.all(this.delegates.map((p) => p.shutdown())).then(() => undefined);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
36
73
|
/**
|
|
37
74
|
* Run `fn`; swallow any exception. The first failure per `site` logs at WARN
|
|
38
75
|
* (with the error attached); subsequent failures at the same site log at
|
|
@@ -60,6 +97,8 @@ export class StructSDK {
|
|
|
60
97
|
_initialized = false;
|
|
61
98
|
_tracerProvider;
|
|
62
99
|
_loggerProvider;
|
|
100
|
+
_spanFanout;
|
|
101
|
+
_logFanout;
|
|
63
102
|
_ingestKey = "";
|
|
64
103
|
_endpoint = DEFAULT_ENDPOINT;
|
|
65
104
|
_contentCapture = ContentCaptureMode.EventOnly;
|
|
@@ -133,26 +172,31 @@ export class StructSDK {
|
|
|
133
172
|
maxExportBatchSize: 100,
|
|
134
173
|
scheduledDelayMillis: 1000,
|
|
135
174
|
});
|
|
136
|
-
const resource =
|
|
175
|
+
const resource = resourceFromAttributes({
|
|
137
176
|
"service.name": serviceName,
|
|
138
177
|
"service.version": serviceVersion,
|
|
139
178
|
"deployment.environment": environment,
|
|
140
179
|
});
|
|
180
|
+
this._spanFanout = new FanoutSpanProcessor();
|
|
141
181
|
this._tracerProvider = new NodeTracerProvider({
|
|
142
182
|
resource,
|
|
143
|
-
spanProcessors: [spanProcessor],
|
|
183
|
+
spanProcessors: [spanProcessor, this._spanFanout],
|
|
144
184
|
});
|
|
145
185
|
const logExporter = new OTLPLogExporter({
|
|
146
186
|
url: `${this._endpoint}/v1/logs`,
|
|
147
187
|
headers,
|
|
148
188
|
});
|
|
149
|
-
const logProcessor = new BatchLogRecordProcessor(
|
|
189
|
+
const logProcessor = new BatchLogRecordProcessor({
|
|
190
|
+
exporter: logExporter,
|
|
150
191
|
maxQueueSize: 10000,
|
|
151
192
|
maxExportBatchSize: 100,
|
|
152
193
|
scheduledDelayMillis: 1000,
|
|
153
194
|
});
|
|
154
|
-
this.
|
|
155
|
-
this._loggerProvider
|
|
195
|
+
this._logFanout = new FanoutLogRecordProcessor();
|
|
196
|
+
this._loggerProvider = new LoggerProvider({
|
|
197
|
+
resource,
|
|
198
|
+
processors: [logProcessor, this._logFanout],
|
|
199
|
+
});
|
|
156
200
|
this._initialized = true;
|
|
157
201
|
this._shutdownHook = () => {
|
|
158
202
|
void this.shutdown();
|
|
@@ -172,6 +216,8 @@ export class StructSDK {
|
|
|
172
216
|
this._initialized = false;
|
|
173
217
|
this._tracerProvider = undefined;
|
|
174
218
|
this._loggerProvider = undefined;
|
|
219
|
+
this._spanFanout = undefined;
|
|
220
|
+
this._logFanout = undefined;
|
|
175
221
|
this._shutdownHook = undefined;
|
|
176
222
|
this._readyPromise = Promise.resolve();
|
|
177
223
|
return;
|
|
@@ -195,11 +241,11 @@ export class StructSDK {
|
|
|
195
241
|
}
|
|
196
242
|
/** Test-only: attach a custom span processor to the internal provider. */
|
|
197
243
|
addSpanProcessor(processor) {
|
|
198
|
-
this.
|
|
244
|
+
this._spanFanout?.delegates.push(processor);
|
|
199
245
|
}
|
|
200
246
|
/** Test-only: attach a custom log record processor. */
|
|
201
247
|
addLogRecordProcessor(processor) {
|
|
202
|
-
this.
|
|
248
|
+
this._logFanout?.delegates.push(processor);
|
|
203
249
|
}
|
|
204
250
|
/**
|
|
205
251
|
* Shut down the SDK and flush pending telemetry.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@struct-ai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Struct agent observability SDK — auto-instruments AI agent frameworks with OpenTelemetry",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/commonjs/index.js",
|
|
@@ -24,6 +24,15 @@
|
|
|
24
24
|
"README.md",
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tshy",
|
|
29
|
+
"dev": "tshy --watch",
|
|
30
|
+
"clean": "rm -rf dist .tshy .tshy-build",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"lint": "echo 'TODO: eslint not configured for @struct-ai/sdk yet — see investigation'",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest"
|
|
35
|
+
},
|
|
27
36
|
"keywords": [
|
|
28
37
|
"struct",
|
|
29
38
|
"observability",
|
|
@@ -42,18 +51,18 @@
|
|
|
42
51
|
"access": "public"
|
|
43
52
|
},
|
|
44
53
|
"engines": {
|
|
45
|
-
"node": "
|
|
54
|
+
"node": "^18.19.0 || >=20.6.0"
|
|
46
55
|
},
|
|
47
56
|
"dependencies": {
|
|
48
57
|
"@opentelemetry/api": "^1.9.0",
|
|
49
|
-
"@opentelemetry/api-logs": "^0.
|
|
50
|
-
"@opentelemetry/core": "^
|
|
51
|
-
"@opentelemetry/exporter-logs-otlp-proto": "^0.
|
|
52
|
-
"@opentelemetry/exporter-trace-otlp-proto": "^0.
|
|
53
|
-
"@opentelemetry/resources": "^
|
|
54
|
-
"@opentelemetry/sdk-logs": "^0.
|
|
55
|
-
"@opentelemetry/sdk-trace-base": "^
|
|
56
|
-
"@opentelemetry/sdk-trace-node": "^
|
|
58
|
+
"@opentelemetry/api-logs": "^0.220.0",
|
|
59
|
+
"@opentelemetry/core": "^2.9.0",
|
|
60
|
+
"@opentelemetry/exporter-logs-otlp-proto": "^0.220.0",
|
|
61
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.220.0",
|
|
62
|
+
"@opentelemetry/resources": "^2.9.0",
|
|
63
|
+
"@opentelemetry/sdk-logs": "^0.220.0",
|
|
64
|
+
"@opentelemetry/sdk-trace-base": "^2.9.0",
|
|
65
|
+
"@opentelemetry/sdk-trace-node": "^2.9.0"
|
|
57
66
|
},
|
|
58
67
|
"peerDependencies": {
|
|
59
68
|
"@anthropic-ai/sdk": ">=0.30.0",
|
|
@@ -90,14 +99,5 @@
|
|
|
90
99
|
".": "./src/index.ts"
|
|
91
100
|
}
|
|
92
101
|
},
|
|
93
|
-
"module": "./dist/esm/index.js"
|
|
94
|
-
|
|
95
|
-
"build": "tshy",
|
|
96
|
-
"dev": "tshy --watch",
|
|
97
|
-
"clean": "rm -rf dist .tshy .tshy-build",
|
|
98
|
-
"typecheck": "tsc --noEmit",
|
|
99
|
-
"lint": "echo 'TODO: eslint not configured for @struct-ai/sdk yet — see investigation'",
|
|
100
|
-
"test": "vitest run",
|
|
101
|
-
"test:watch": "vitest"
|
|
102
|
-
}
|
|
103
|
-
}
|
|
102
|
+
"module": "./dist/esm/index.js"
|
|
103
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare enum ContentCaptureMode {
|
|
2
|
-
None = "none",
|
|
3
|
-
EventOnly = "event_only",
|
|
4
|
-
SpanOnly = "span_only",
|
|
5
|
-
SpanAndEvent = "span_and_event"
|
|
6
|
-
}
|
|
7
|
-
export declare function emitEventsFor(mode: ContentCaptureMode): boolean;
|
|
8
|
-
export declare function emitSpanContentFor(mode: ContentCaptureMode): boolean;
|
|
9
|
-
export declare function captureContentFor(mode: ContentCaptureMode): boolean;
|
|
10
|
-
//# sourceMappingURL=content-capture.d.ts.map
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Span } from "@opentelemetry/api";
|
|
2
|
-
export interface StructContext {
|
|
3
|
-
sessionId?: string;
|
|
4
|
-
conversationId?: string;
|
|
5
|
-
agentSpan?: Span;
|
|
6
|
-
pendingToolCalls?: Record<string, string[]>;
|
|
7
|
-
}
|
|
8
|
-
export declare function getStore(): StructContext | undefined;
|
|
9
|
-
export declare function getSessionId(): string | undefined;
|
|
10
|
-
export declare function getConversationId(): string | undefined;
|
|
11
|
-
export declare function getAgentSpan(): Span | undefined;
|
|
12
|
-
export declare function getPendingToolCalls(): Record<string, string[]> | undefined;
|
|
13
|
-
export declare function runWithContext<T>(patch: Partial<StructContext>, fn: () => T): T;
|
|
14
|
-
export declare function ensurePendingToolCallsSlot(): Record<string, string[]>;
|
|
15
|
-
/**
|
|
16
|
-
* Pop the first pending tool_use id matching `name`, or undefined.
|
|
17
|
-
* FIFO semantics match Python struct-sdk-python.
|
|
18
|
-
*/
|
|
19
|
-
export declare function popPendingToolCallId(name: string): string | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Push (name, id) pairs into the active pending-tool-calls slot.
|
|
22
|
-
* Initializes a transient dict if no active agent scope.
|
|
23
|
-
*/
|
|
24
|
-
export declare function pushPendingToolCalls(pairs: readonly [string, string][]): void;
|
|
25
|
-
/** Snapshot the store for wrapping async iterators. */
|
|
26
|
-
export declare function snapshotStore(): StructContext | undefined;
|
|
27
|
-
export declare function runWithStore<T>(store: StructContext | undefined, fn: () => T): T;
|
|
28
|
-
/** Test-only: run `fn` inside a completely fresh context (no parent store). */
|
|
29
|
-
export declare function runInFreshContext<T>(fn: () => T): T;
|
|
30
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { type Tracer } from "@opentelemetry/api";
|
|
2
|
-
import { type Logger } from "@opentelemetry/api-logs";
|
|
3
|
-
import { type LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
4
|
-
import type { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
5
|
-
import { ContentCaptureMode } from "./content-capture.js";
|
|
6
|
-
export declare const DEFAULT_ENDPOINT = "https://ingest.struct.ai";
|
|
7
|
-
export interface InitOptions {
|
|
8
|
-
ingestKey: string;
|
|
9
|
-
serviceName?: string;
|
|
10
|
-
serviceVersion?: string;
|
|
11
|
-
environment?: string;
|
|
12
|
-
endpoint?: string;
|
|
13
|
-
captureContent?: boolean;
|
|
14
|
-
contentCapture?: ContentCaptureMode;
|
|
15
|
-
/**
|
|
16
|
-
* Maximum time `shutdown()` is allowed to spend flushing telemetry providers
|
|
17
|
-
* before returning. If the ingest endpoint is dead or slow, shutdown returns
|
|
18
|
-
* within this budget rather than hanging the host process exit. Defaults to
|
|
19
|
-
* 5000ms. Can be overridden per call via `shutdown(timeoutMs)`.
|
|
20
|
-
*/
|
|
21
|
-
shutdownTimeoutMs?: number;
|
|
22
|
-
}
|
|
23
|
-
export interface AgentScopeOptions {
|
|
24
|
-
name: string;
|
|
25
|
-
sessionId?: string;
|
|
26
|
-
/**
|
|
27
|
-
* Stable identifier for the agent DEFINITION — `gen_ai.agent.id` per the OTel
|
|
28
|
-
* GenAI spec. Not the same as sessionId (which identifies a single
|
|
29
|
-
* invocation / conversation). Omit if you don't have a stable ID.
|
|
30
|
-
*/
|
|
31
|
-
agentId?: string;
|
|
32
|
-
version?: string;
|
|
33
|
-
metadata?: Record<string, string>;
|
|
34
|
-
}
|
|
35
|
-
export interface ToolScopeOptions {
|
|
36
|
-
name: string;
|
|
37
|
-
toolCallId?: string;
|
|
38
|
-
}
|
|
39
|
-
export interface InternalLogger {
|
|
40
|
-
info(msg: string, ...args: unknown[]): void;
|
|
41
|
-
warn(msg: string, ...args: unknown[]): void;
|
|
42
|
-
debug(msg: string, ...args: unknown[]): void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Sites that have already logged a first-failure WARN; subsequent failures at
|
|
46
|
-
* the same site log at DEBUG. Mirrors `_first_failure_logged` in the Python
|
|
47
|
-
* SDK.
|
|
48
|
-
*
|
|
49
|
-
* Exported for tests that need to clear the set between runs so log-level
|
|
50
|
-
* assertions are deterministic. Internal — not re-exported from `index.ts`,
|
|
51
|
-
* so consumers cannot reach it via the package's public API surface.
|
|
52
|
-
*/
|
|
53
|
-
export declare const firstFailureLogged: Set<string>;
|
|
54
|
-
/**
|
|
55
|
-
* Run `fn`; swallow any exception. The first failure per `site` logs at WARN
|
|
56
|
-
* (with the error attached); subsequent failures at the same site log at
|
|
57
|
-
* DEBUG. The caller's logger is passed explicitly so this helper stays a free
|
|
58
|
-
* module-level function — usable from instrumentation modules that don't
|
|
59
|
-
* carry an SDK reference of their own.
|
|
60
|
-
*
|
|
61
|
-
* Mirrors `_safe(fn, *, site)` in the Python SDK.
|
|
62
|
-
*/
|
|
63
|
-
export declare function safe(fn: () => void, site: string, logger: InternalLogger): void;
|
|
64
|
-
export declare class StructSDK {
|
|
65
|
-
private _initialized;
|
|
66
|
-
private _tracerProvider;
|
|
67
|
-
private _loggerProvider;
|
|
68
|
-
private _ingestKey;
|
|
69
|
-
private _endpoint;
|
|
70
|
-
private _contentCapture;
|
|
71
|
-
private _shutdownHook;
|
|
72
|
-
private _shutdownTimeoutMs;
|
|
73
|
-
private _internalLogger;
|
|
74
|
-
private _readyPromise;
|
|
75
|
-
/** Resolves once auto-instrumentation has attempted to patch every detected library. */
|
|
76
|
-
get ready(): Promise<void>;
|
|
77
|
-
get initialized(): boolean;
|
|
78
|
-
get endpoint(): string;
|
|
79
|
-
get ingestKey(): string;
|
|
80
|
-
get contentCapture(): ContentCaptureMode;
|
|
81
|
-
get captureContent(): boolean;
|
|
82
|
-
get emitEvents(): boolean;
|
|
83
|
-
get emitSpanContent(): boolean;
|
|
84
|
-
init(options: InitOptions): void;
|
|
85
|
-
getTracer(name?: string): Tracer;
|
|
86
|
-
getLogger(name?: string): Logger;
|
|
87
|
-
getInternalLogger(): InternalLogger;
|
|
88
|
-
/** Test-only: attach a custom span processor to the internal provider. */
|
|
89
|
-
addSpanProcessor(processor: SpanProcessor): void;
|
|
90
|
-
/** Test-only: attach a custom log record processor. */
|
|
91
|
-
addLogRecordProcessor(processor: LogRecordProcessor): void;
|
|
92
|
-
/**
|
|
93
|
-
* Shut down the SDK and flush pending telemetry.
|
|
94
|
-
*
|
|
95
|
-
* Returns within `timeoutMs` (default: SDK init's `shutdownTimeoutMs`,
|
|
96
|
-
* fallback 5000ms). If the ingest endpoint is unreachable, in-flight
|
|
97
|
-
* telemetry may be dropped — the trade-off vs. blocking process exit.
|
|
98
|
-
*
|
|
99
|
-
* In serverless / edge runtimes (Lambda, Vercel, etc.), the runtime does
|
|
100
|
-
* NOT await our `beforeExit` hook. Call `await struct.shutdown()`
|
|
101
|
-
* explicitly before your function returns or before container freeze.
|
|
102
|
-
*
|
|
103
|
-
* Safe to call multiple times. Safe to call on an SDK that failed to init
|
|
104
|
-
* or was never initialized.
|
|
105
|
-
*
|
|
106
|
-
* @param timeoutMs - Override the configured shutdown timeout for this call.
|
|
107
|
-
*/
|
|
108
|
-
shutdown(timeoutMs?: number): Promise<void>;
|
|
109
|
-
/**
|
|
110
|
-
* Run `fn` inside an `invoke_agent` span scope.
|
|
111
|
-
* Matches Python's _AgentContext behavior.
|
|
112
|
-
*/
|
|
113
|
-
agent<T>(options: AgentScopeOptions, fn: () => Promise<T> | T): Promise<T>;
|
|
114
|
-
/**
|
|
115
|
-
* Run `fn` inside an `execute_tool` span scope.
|
|
116
|
-
* Matches Python's _ToolContext behavior.
|
|
117
|
-
*/
|
|
118
|
-
tool<T>(options: ToolScopeOptions, fn: () => Promise<T> | T): Promise<T>;
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=core.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { type Tracer } from "@opentelemetry/api";
|
|
2
|
-
import type { Logger } from "@opentelemetry/api-logs";
|
|
3
|
-
import { type StructSDK } from "../core.js";
|
|
4
|
-
interface PatchContext {
|
|
5
|
-
tracer: Tracer;
|
|
6
|
-
sdk: StructSDK;
|
|
7
|
-
logger: Logger | undefined;
|
|
8
|
-
}
|
|
9
|
-
interface CreateParams {
|
|
10
|
-
model?: string;
|
|
11
|
-
max_tokens?: number;
|
|
12
|
-
temperature?: number;
|
|
13
|
-
top_p?: number;
|
|
14
|
-
top_k?: number;
|
|
15
|
-
stop_sequences?: string[];
|
|
16
|
-
messages?: unknown[];
|
|
17
|
-
system?: unknown;
|
|
18
|
-
tools?: unknown[];
|
|
19
|
-
stream?: boolean;
|
|
20
|
-
}
|
|
21
|
-
export declare function patch(sdk: StructSDK): Promise<void>;
|
|
22
|
-
export declare function unpatch(): Promise<void>;
|
|
23
|
-
type CreateMethod = (this: unknown, params: CreateParams, opts?: unknown) => unknown;
|
|
24
|
-
type StreamMethod = (this: unknown, params: CreateParams, opts?: unknown) => unknown;
|
|
25
|
-
/** @internal */
|
|
26
|
-
export type _PatchContextForTest = PatchContext;
|
|
27
|
-
/** @internal */
|
|
28
|
-
export declare function _wrapCreateForTest(original: CreateMethod): CreateMethod;
|
|
29
|
-
/** @internal */
|
|
30
|
-
export declare function _wrapStreamForTest(original: StreamMethod): StreamMethod;
|
|
31
|
-
/** @internal */
|
|
32
|
-
export declare function _setActivePatchCtxForTest(ctx: PatchContext | undefined): void;
|
|
33
|
-
export {};
|
|
34
|
-
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { StructSDK } from "../core.js";
|
|
2
|
-
export declare const patchedIntegrations: Set<string>;
|
|
3
|
-
export declare function resetPatchedIntegrations(): void;
|
|
4
|
-
export declare function autoInstrument(sdk: StructSDK): Promise<void>;
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|