@superdurable/dex-agents 0.0.0-stage → 0.2.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 +105 -0
- package/README.md +1981 -2
- package/dist/src/agent-built-in-tools.d.ts +81 -0
- package/dist/src/agent-built-in-tools.js +246 -0
- package/dist/src/agent-built-in-tools.js.map +1 -0
- package/dist/src/agent-context-compaction.d.ts +108 -0
- package/dist/src/agent-context-compaction.js +39 -0
- package/dist/src/agent-context-compaction.js.map +1 -0
- package/dist/src/agent-event-writer.d.ts +26 -0
- package/dist/src/agent-event-writer.js +110 -0
- package/dist/src/agent-event-writer.js.map +1 -0
- package/dist/src/agent-framework-runner.d.ts +808 -0
- package/dist/src/agent-framework-runner.js +82 -0
- package/dist/src/agent-framework-runner.js.map +1 -0
- package/dist/src/agent-plans.d.ts +48 -0
- package/dist/src/agent-plans.js +86 -0
- package/dist/src/agent-plans.js.map +1 -0
- package/dist/src/agent-session-cancellation-steps.d.ts +28 -0
- package/dist/src/agent-session-cancellation-steps.js +154 -0
- package/dist/src/agent-session-cancellation-steps.js.map +1 -0
- package/dist/src/agent-session-codecs.d.ts +105 -0
- package/dist/src/agent-session-codecs.js +689 -0
- package/dist/src/agent-session-codecs.js.map +1 -0
- package/dist/src/agent-session-flow.d.ts +416 -0
- package/dist/src/agent-session-flow.js +623 -0
- package/dist/src/agent-session-flow.js.map +1 -0
- package/dist/src/agent-session-persistence.d.ts +133 -0
- package/dist/src/agent-session-persistence.js +74 -0
- package/dist/src/agent-session-persistence.js.map +1 -0
- package/dist/src/agent-session-settings.d.ts +58 -0
- package/dist/src/agent-session-settings.js +81 -0
- package/dist/src/agent-session-settings.js.map +1 -0
- package/dist/src/agent-session-step-options.d.ts +27 -0
- package/dist/src/agent-session-step-options.js +39 -0
- package/dist/src/agent-session-step-options.js.map +1 -0
- package/dist/src/agent-session-step-types.d.ts +20 -0
- package/dist/src/agent-session-step-types.js +28 -0
- package/dist/src/agent-session-step-types.js.map +1 -0
- package/dist/src/agent-session-steps.d.ts +179 -0
- package/dist/src/agent-session-steps.js +1272 -0
- package/dist/src/agent-session-steps.js.map +1 -0
- package/dist/src/agent-session-tracer.d.ts +61 -0
- package/dist/src/agent-session-tracer.js +608 -0
- package/dist/src/agent-session-tracer.js.map +1 -0
- package/dist/src/agent-session-transitions.d.ts +224 -0
- package/dist/src/agent-session-transitions.js +850 -0
- package/dist/src/agent-session-transitions.js.map +1 -0
- package/dist/src/agent-session-values.d.ts +998 -0
- package/dist/src/agent-session-values.js +162 -0
- package/dist/src/agent-session-values.js.map +1 -0
- package/dist/src/agent-session-wait-steps.d.ts +53 -0
- package/dist/src/agent-session-wait-steps.js +389 -0
- package/dist/src/agent-session-wait-steps.js.map +1 -0
- package/dist/src/agent-tracing-options.d.ts +107 -0
- package/dist/src/agent-tracing-options.js +20 -0
- package/dist/src/agent-tracing-options.js.map +1 -0
- package/dist/src/ai-sdk/ai-sdk-model-client.d.ts +40 -0
- package/dist/src/ai-sdk/ai-sdk-model-client.js +235 -0
- package/dist/src/ai-sdk/ai-sdk-model-client.js.map +1 -0
- package/dist/src/ai-sdk/index.d.ts +1 -0
- package/dist/src/ai-sdk/index.js +9 -0
- package/dist/src/ai-sdk/index.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +17 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/index.d.ts +3 -0
- package/dist/src/mcp/index.js +10 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/mcp-resource-and-prompt-tools.d.ts +29 -0
- package/dist/src/mcp/mcp-resource-and-prompt-tools.js +185 -0
- package/dist/src/mcp/mcp-resource-and-prompt-tools.js.map +1 -0
- package/dist/src/mcp/mcp-server-config.d.ts +86 -0
- package/dist/src/mcp/mcp-server-config.js +38 -0
- package/dist/src/mcp/mcp-server-config.js.map +1 -0
- package/dist/src/mcp/mcp-tool-source.d.ts +470 -0
- package/dist/src/mcp/mcp-tool-source.js +1204 -0
- package/dist/src/mcp/mcp-tool-source.js.map +1 -0
- package/dist/src/stepwise/agent-definition.d.ts +158 -0
- package/dist/src/stepwise/agent-definition.js +9 -0
- package/dist/src/stepwise/agent-definition.js.map +1 -0
- package/dist/src/stepwise/function-tool.d.ts +130 -0
- package/dist/src/stepwise/function-tool.js +75 -0
- package/dist/src/stepwise/function-tool.js.map +1 -0
- package/dist/src/stepwise/index.d.ts +7 -0
- package/dist/src/stepwise/index.js +12 -0
- package/dist/src/stepwise/index.js.map +1 -0
- package/dist/src/stepwise/json-schema-validation.d.ts +9 -0
- package/dist/src/stepwise/json-schema-validation.js +141 -0
- package/dist/src/stepwise/json-schema-validation.js.map +1 -0
- package/dist/src/stepwise/model-client.d.ts +194 -0
- package/dist/src/stepwise/model-client.js +9 -0
- package/dist/src/stepwise/model-client.js.map +1 -0
- package/dist/src/stepwise/scripted-model-client.d.ts +99 -0
- package/dist/src/stepwise/scripted-model-client.js +156 -0
- package/dist/src/stepwise/scripted-model-client.js.map +1 -0
- package/dist/src/stepwise/stepwise-agent-runner.d.ts +189 -0
- package/dist/src/stepwise/stepwise-agent-runner.js +804 -0
- package/dist/src/stepwise/stepwise-agent-runner.js.map +1 -0
- package/dist/src/stepwise/stepwise-agent-session-flow.d.ts +35 -0
- package/dist/src/stepwise/stepwise-agent-session-flow.js +56 -0
- package/dist/src/stepwise/stepwise-agent-session-flow.js.map +1 -0
- package/dist/src/stepwise/stepwise-input-items.d.ts +12 -0
- package/dist/src/stepwise/stepwise-input-items.js +172 -0
- package/dist/src/stepwise/stepwise-input-items.js.map +1 -0
- package/dist/src/stepwise/tool-source.d.ts +103 -0
- package/dist/src/stepwise/tool-source.js +9 -0
- package/dist/src/stepwise/tool-source.js.map +1 -0
- package/dist/src/testing/agent-session-test-client.d.ts +205 -0
- package/dist/src/testing/agent-session-test-client.js +290 -0
- package/dist/src/testing/agent-session-test-client.js.map +1 -0
- package/dist/src/testing/agent-test-environment.d.ts +52 -0
- package/dist/src/testing/agent-test-environment.js +86 -0
- package/dist/src/testing/agent-test-environment.js.map +1 -0
- package/dist/src/testing/agent-worker-process.d.ts +91 -0
- package/dist/src/testing/agent-worker-process.js +150 -0
- package/dist/src/testing/agent-worker-process.js.map +1 -0
- package/dist/src/testing/child-process-group.d.ts +33 -0
- package/dist/src/testing/child-process-group.js +164 -0
- package/dist/src/testing/child-process-group.js.map +1 -0
- package/dist/src/testing/coordination.d.ts +99 -0
- package/dist/src/testing/coordination.js +155 -0
- package/dist/src/testing/coordination.js.map +1 -0
- package/dist/src/testing/index.d.ts +8 -0
- package/dist/src/testing/index.js +16 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/polling.d.ts +31 -0
- package/dist/src/testing/polling.js +51 -0
- package/dist/src/testing/polling.js.map +1 -0
- package/dist/src/testing/private-dex-engine.d.ts +101 -0
- package/dist/src/testing/private-dex-engine.js +223 -0
- package/dist/src/testing/private-dex-engine.js.map +1 -0
- package/dist/src/testing/scripted-model-client.d.ts +1 -0
- package/dist/src/testing/scripted-model-client.js +10 -0
- package/dist/src/testing/scripted-model-client.js.map +1 -0
- package/dist/src/testing/step-history.d.ts +40 -0
- package/dist/src/testing/step-history.js +59 -0
- package/dist/src/testing/step-history.js.map +1 -0
- package/dist/src/ui-stream/agent-event-json.d.ts +30 -0
- package/dist/src/ui-stream/agent-event-json.js +64 -0
- package/dist/src/ui-stream/agent-event-json.js.map +1 -0
- package/dist/src/ui-stream/agent-event-sse.d.ts +154 -0
- package/dist/src/ui-stream/agent-event-sse.js +159 -0
- package/dist/src/ui-stream/agent-event-sse.js.map +1 -0
- package/dist/src/ui-stream/agent-event-stream-positions.d.ts +42 -0
- package/dist/src/ui-stream/agent-event-stream-positions.js +153 -0
- package/dist/src/ui-stream/agent-event-stream-positions.js.map +1 -0
- package/dist/src/ui-stream/agent-session-record-reader.d.ts +72 -0
- package/dist/src/ui-stream/agent-session-record-reader.js +241 -0
- package/dist/src/ui-stream/agent-session-record-reader.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-message-stream-responses.d.ts +219 -0
- package/dist/src/ui-stream/agent-ui-message-stream-responses.js +440 -0
- package/dist/src/ui-stream/agent-ui-message-stream-responses.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-message-stream.d.ts +138 -0
- package/dist/src/ui-stream/agent-ui-message-stream.js +681 -0
- package/dist/src/ui-stream/agent-ui-message-stream.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-message-types.d.ts +238 -0
- package/dist/src/ui-stream/agent-ui-message-types.js +57 -0
- package/dist/src/ui-stream/agent-ui-message-types.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-messages.d.ts +66 -0
- package/dist/src/ui-stream/agent-ui-messages.js +220 -0
- package/dist/src/ui-stream/agent-ui-messages.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-stream-cursor.d.ts +64 -0
- package/dist/src/ui-stream/agent-ui-stream-cursor.js +186 -0
- package/dist/src/ui-stream/agent-ui-stream-cursor.js.map +1 -0
- package/dist/src/ui-stream/index.d.ts +14 -0
- package/dist/src/ui-stream/index.js +22 -0
- package/dist/src/ui-stream/index.js.map +1 -0
- package/dist/src/ui-stream/server-sent-event-responses.d.ts +6 -0
- package/dist/src/ui-stream/server-sent-event-responses.js +34 -0
- package/dist/src/ui-stream/server-sent-event-responses.js.map +1 -0
- package/package.json +86 -4
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenTelemetry GenAI semantic conventions version that the session's spans follow.
|
|
3
|
+
*
|
|
4
|
+
* The GenAI conventions are still marked Development, so attribute names can change between versions.
|
|
5
|
+
* The session pins one version and sets its schema URL on the tracer. Pick an older version when a
|
|
6
|
+
* tracing backend still reads the older names.
|
|
7
|
+
*
|
|
8
|
+
* - `"1.42.0-dev"`: the conventions in `open-telemetry/semantic-conventions-genai` at commit
|
|
9
|
+
* `dc3571562603552dc555c667dfa327a638d94ab2` (2026-11-01), whose schema URL names `1.42.0-dev`. That repository has no release tag
|
|
10
|
+
* yet. The default. Chat spans carry `gen_ai.provider.name` and the cache and reasoning token counts, and
|
|
11
|
+
* content capture is available.
|
|
12
|
+
* - `"1.36.0"`: OpenTelemetry semantic conventions 1.36.0, the last release before `gen_ai.system`
|
|
13
|
+
* became `gen_ai.provider.name`. Chat spans carry `gen_ai.system` and only the input and output token
|
|
14
|
+
* counts. Content capture is not available, because 1.36.0 recorded content as events.
|
|
15
|
+
*/
|
|
16
|
+
export type GenAISemanticConventionsVersion = "1.42.0-dev" | "1.36.0";
|
|
17
|
+
/**
|
|
18
|
+
* OpenTelemetry schema URL of each {@link GenAISemanticConventionsVersion}, set on the session's tracer.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const schemaUrl = genAISemanticConventionsSchemaUrls["1.42.0-dev"];
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const genAISemanticConventionsSchemaUrls: Readonly<Record<GenAISemanticConventionsVersion, string>>;
|
|
26
|
+
/**
|
|
27
|
+
* The part of an OpenTelemetry `TracerProvider` the session uses.
|
|
28
|
+
*
|
|
29
|
+
* Any `TracerProvider` from `@opentelemetry/api`, such as an SDK `BasicTracerProvider` or
|
|
30
|
+
* `NodeTracerProvider`, satisfies it. The core declares it structurally so that applications without
|
|
31
|
+
* `@opentelemetry/api` still type-check.
|
|
32
|
+
*/
|
|
33
|
+
export interface OpenTelemetryTracerProvider {
|
|
34
|
+
/**
|
|
35
|
+
* Returns a tracer, as `TracerProvider.getTracer` does.
|
|
36
|
+
* @param name - Instrumentation scope name.
|
|
37
|
+
* @param version - Instrumentation scope version.
|
|
38
|
+
* @param options - Tracer options; the session passes the schema URL.
|
|
39
|
+
* @returns An OpenTelemetry `Tracer`.
|
|
40
|
+
*/
|
|
41
|
+
getTracer(name: string, version?: string, options?: {
|
|
42
|
+
readonly schemaUrl?: string;
|
|
43
|
+
}): unknown;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* OpenTelemetry GenAI span options of one agent session Flow, passed as
|
|
47
|
+
* {@link AgentSessionOptions.tracing}.
|
|
48
|
+
*
|
|
49
|
+
* Tracing is on by default and uses the global tracer provider, so an application that registers the
|
|
50
|
+
* OpenTelemetry SDK gets spans without further setup. `@opentelemetry/api` is an optional peer
|
|
51
|
+
* dependency: when it is not installed, or no SDK is registered, the session emits nothing and stores
|
|
52
|
+
* nothing extra.
|
|
53
|
+
*
|
|
54
|
+
* The session emits one trace per activation: a burst of Steps that starts when the session consumes
|
|
55
|
+
* a user message or an interrupt answer, and ends when the session waits again. The activation's root
|
|
56
|
+
* span is `invoke_agent {agent name}`. Each `RunModel` attempt adds a `chat` span, named
|
|
57
|
+
* `chat {model}` when the runner returns `modelCallMetadata`, and each tool Step attempt adds an
|
|
58
|
+
* `execute_tool {tool name}` span. Every span carries the Flow ID as `gen_ai.conversation.id` and
|
|
59
|
+
* `session.id`. Tracing never fails a Step: an error from OpenTelemetry, such as a throwing span
|
|
60
|
+
* processor, is logged with `console.warn` and the span is skipped. The package README lists every
|
|
61
|
+
* span and attribute.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { BasicTracerProvider, SimpleSpanProcessor, ConsoleSpanExporter } from "@opentelemetry/sdk-trace-base";
|
|
66
|
+
*
|
|
67
|
+
* const tracerProvider = new BasicTracerProvider({
|
|
68
|
+
* spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())],
|
|
69
|
+
* });
|
|
70
|
+
* const flow = createAgentSessionFlow(runner, "TriageAgent", {
|
|
71
|
+
* tracing: { tracerProvider, agentName: "Triage", shouldCaptureMessageContent: true },
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export interface AgentTracingOptions {
|
|
76
|
+
/** Whether the session emits spans. Defaults to `true`. `false` never loads `@opentelemetry/api`. */
|
|
77
|
+
readonly isEnabled?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Tracer provider to emit with. Defaults to the global provider, read at the first Step that emits a
|
|
80
|
+
* span.
|
|
81
|
+
*/
|
|
82
|
+
readonly tracerProvider?: OpenTelemetryTracerProvider;
|
|
83
|
+
/** `gen_ai.agent.name` and the `invoke_agent` span name. Defaults to the Flow type. */
|
|
84
|
+
readonly agentName?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Whether spans carry message text, tool arguments, and tool results. Defaults to `false`: spans then
|
|
87
|
+
* carry only Dex references, such as `AgentMessages` instance keys and tool call IDs, because the
|
|
88
|
+
* content is already durable in Dex. Content can be sensitive and large; enable it only where the
|
|
89
|
+
* tracing backend may store it.
|
|
90
|
+
*/
|
|
91
|
+
readonly shouldCaptureMessageContent?: boolean;
|
|
92
|
+
/** GenAI semantic conventions version. Defaults to `"1.42.0-dev"`. */
|
|
93
|
+
readonly semanticConventionsVersion?: GenAISemanticConventionsVersion;
|
|
94
|
+
}
|
|
95
|
+
/** Tracing options applied by an agent session Flow, with every default filled in. */
|
|
96
|
+
export interface ResolvedAgentTracingOptions {
|
|
97
|
+
/** Whether the session emits spans. */
|
|
98
|
+
readonly isEnabled: boolean;
|
|
99
|
+
/** Tracer provider, or `undefined` for the global provider. */
|
|
100
|
+
readonly tracerProvider: OpenTelemetryTracerProvider | undefined;
|
|
101
|
+
/** `gen_ai.agent.name`: the configured name or the Flow type. */
|
|
102
|
+
readonly agentName: string;
|
|
103
|
+
/** Whether spans carry message content. */
|
|
104
|
+
readonly shouldCaptureMessageContent: boolean;
|
|
105
|
+
/** GenAI semantic conventions version. */
|
|
106
|
+
readonly semanticConventionsVersion: GenAISemanticConventionsVersion;
|
|
107
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
/**
|
|
9
|
+
* OpenTelemetry schema URL of each {@link GenAISemanticConventionsVersion}, set on the session's tracer.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const schemaUrl = genAISemanticConventionsSchemaUrls["1.42.0-dev"];
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const genAISemanticConventionsSchemaUrls = Object.freeze({
|
|
17
|
+
"1.42.0-dev": "https://opentelemetry.io/schemas/gen-ai-dev/1.42.0-dev",
|
|
18
|
+
"1.36.0": "https://opentelemetry.io/schemas/1.36.0",
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=agent-tracing-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-tracing-options.js","sourceRoot":"","sources":["../../src/agent-tracing-options.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAmB1D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAC7C,MAAM,CAAC,MAAM,CAAC;IACZ,YAAY,EAAE,wDAAwD;IACtE,QAAQ,EAAE,yCAAyC;CACpD,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type LanguageModel } from "ai";
|
|
2
|
+
import type { ModelClient } from "../stepwise/model-client.js";
|
|
3
|
+
/** API name recorded on every output item of this client. */
|
|
4
|
+
export declare const aiSdkModelClientApi = "ai-sdk";
|
|
5
|
+
/** Options of {@link createAiSdkModelClient}. */
|
|
6
|
+
export interface AiSdkModelClientOptions {
|
|
7
|
+
/** HTTP headers sent with every model request. Defaults to none. */
|
|
8
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates a Stepwise {@link ModelClient} for any AI SDK language model.
|
|
12
|
+
*
|
|
13
|
+
* Each `callModel` makes exactly one model call: one `streamText` call with `stopWhen: stepCountIs(1)`,
|
|
14
|
+
* `maxRetries: 0`, and the agent's tools as definitions without `execute`. The AI SDK therefore runs no
|
|
15
|
+
* tool loop, no tool, and no retry; a retry is a `RunModel` attempt. Text and reasoning deltas stream to
|
|
16
|
+
* `AgentEvents` as they arrive.
|
|
17
|
+
*
|
|
18
|
+
* The client stores each response as the AI SDK assistant `ModelMessage`, as JSON text, with every
|
|
19
|
+
* text, reasoning, tool call, and file part and its `providerOptions`, which hold provider signatures and
|
|
20
|
+
* encrypted reasoning, exactly as the AI SDK returned them. It replays that message unchanged to a model
|
|
21
|
+
* of the same provider, and only its text and tool calls to any other model, so a session can change
|
|
22
|
+
* model between turns. Tool results reach the model as text. For a model ID string, the string itself
|
|
23
|
+
* names the provider, so a model switch between two strings replays text only.
|
|
24
|
+
*
|
|
25
|
+
* It requires the optional peer dependency `ai`, version 7.0.159 or a later 7.x release, and uses only
|
|
26
|
+
* its public API; install it next to the provider package.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { anthropic } from "@ai-sdk/anthropic";
|
|
31
|
+
* import { createAiSdkModelClient } from "@superdurable/dex-agents/ai-sdk";
|
|
32
|
+
*
|
|
33
|
+
* const model = createAiSdkModelClient(anthropic("claude-sonnet-4-5"));
|
|
34
|
+
* const flow = createStepwiseAgentSessionFlow({ name: "support", instructions, model, tools }, "SupportAgent");
|
|
35
|
+
* ```
|
|
36
|
+
* @param model - Any AI SDK `LanguageModel`: a provider model or a model ID string.
|
|
37
|
+
* @param options - Request headers.
|
|
38
|
+
* @returns The model client.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createAiSdkModelClient(model: LanguageModel, options?: AiSdkModelClientOptions): ModelClient;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
import { jsonSchema, stepCountIs, streamText, } from "ai";
|
|
9
|
+
import { emptyAgentUsage } from "../agent-session-values.js";
|
|
10
|
+
/** API name recorded on every output item of this client. */
|
|
11
|
+
export const aiSdkModelClientApi = "ai-sdk";
|
|
12
|
+
const reasoningEfforts = [
|
|
13
|
+
"provider-default",
|
|
14
|
+
"none",
|
|
15
|
+
"minimal",
|
|
16
|
+
"low",
|
|
17
|
+
"medium",
|
|
18
|
+
"high",
|
|
19
|
+
"xhigh",
|
|
20
|
+
"max",
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Creates a Stepwise {@link ModelClient} for any AI SDK language model.
|
|
24
|
+
*
|
|
25
|
+
* Each `callModel` makes exactly one model call: one `streamText` call with `stopWhen: stepCountIs(1)`,
|
|
26
|
+
* `maxRetries: 0`, and the agent's tools as definitions without `execute`. The AI SDK therefore runs no
|
|
27
|
+
* tool loop, no tool, and no retry; a retry is a `RunModel` attempt. Text and reasoning deltas stream to
|
|
28
|
+
* `AgentEvents` as they arrive.
|
|
29
|
+
*
|
|
30
|
+
* The client stores each response as the AI SDK assistant `ModelMessage`, as JSON text, with every
|
|
31
|
+
* text, reasoning, tool call, and file part and its `providerOptions`, which hold provider signatures and
|
|
32
|
+
* encrypted reasoning, exactly as the AI SDK returned them. It replays that message unchanged to a model
|
|
33
|
+
* of the same provider, and only its text and tool calls to any other model, so a session can change
|
|
34
|
+
* model between turns. Tool results reach the model as text. For a model ID string, the string itself
|
|
35
|
+
* names the provider, so a model switch between two strings replays text only.
|
|
36
|
+
*
|
|
37
|
+
* It requires the optional peer dependency `ai`, version 7.0.159 or a later 7.x release, and uses only
|
|
38
|
+
* its public API; install it next to the provider package.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { anthropic } from "@ai-sdk/anthropic";
|
|
43
|
+
* import { createAiSdkModelClient } from "@superdurable/dex-agents/ai-sdk";
|
|
44
|
+
*
|
|
45
|
+
* const model = createAiSdkModelClient(anthropic("claude-sonnet-4-5"));
|
|
46
|
+
* const flow = createStepwiseAgentSessionFlow({ name: "support", instructions, model, tools }, "SupportAgent");
|
|
47
|
+
* ```
|
|
48
|
+
* @param model - Any AI SDK `LanguageModel`: a provider model or a model ID string.
|
|
49
|
+
* @param options - Request headers.
|
|
50
|
+
* @returns The model client.
|
|
51
|
+
*/
|
|
52
|
+
export function createAiSdkModelClient(model, options = {}) {
|
|
53
|
+
return new AiSdkModelClient(model, options);
|
|
54
|
+
}
|
|
55
|
+
class AiSdkModelClient {
|
|
56
|
+
model;
|
|
57
|
+
options;
|
|
58
|
+
provider;
|
|
59
|
+
constructor(model, options) {
|
|
60
|
+
this.model = model;
|
|
61
|
+
this.options = options;
|
|
62
|
+
this.provider = typeof model === "string" ? model : model.provider;
|
|
63
|
+
}
|
|
64
|
+
async callModel(request, output) {
|
|
65
|
+
const settings = request.settings;
|
|
66
|
+
const tools = {};
|
|
67
|
+
for (const definition of request.tools) {
|
|
68
|
+
const tool = { description: definition.description, inputSchema: jsonSchema(definition.parameters) };
|
|
69
|
+
tools[definition.name] = tool;
|
|
70
|
+
}
|
|
71
|
+
let streamError;
|
|
72
|
+
const result = streamText({
|
|
73
|
+
model: this.model,
|
|
74
|
+
...(request.instructions.trim() === "" ? {} : { system: request.instructions }),
|
|
75
|
+
messages: request.inputItems.reduce((messages, item) => this.appendInputItem(messages, item), []),
|
|
76
|
+
...(request.tools.length === 0 ? {} : { tools, toolChoice: toAiSdkToolChoice(request.toolChoice) }),
|
|
77
|
+
...(settings.temperature === undefined ? {} : { temperature: settings.temperature }),
|
|
78
|
+
...(settings.maxOutputTokens === undefined ? {} : { maxOutputTokens: settings.maxOutputTokens }),
|
|
79
|
+
...(settings.reasoningEffort === undefined ? {} : { reasoning: toReasoningEffort(settings.reasoningEffort) }),
|
|
80
|
+
...(settings.providerOptions === undefined
|
|
81
|
+
? {}
|
|
82
|
+
: { providerOptions: settings.providerOptions }),
|
|
83
|
+
...(this.options.headers === undefined ? {} : { headers: { ...this.options.headers } }),
|
|
84
|
+
maxRetries: 0,
|
|
85
|
+
stopWhen: stepCountIs(1),
|
|
86
|
+
abortSignal: request.cancellationSignal,
|
|
87
|
+
onError: ({ error }) => {
|
|
88
|
+
streamError ??= { error };
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
for await (const part of result.fullStream) {
|
|
92
|
+
switch (part.type) {
|
|
93
|
+
case "text-delta":
|
|
94
|
+
output.writeTextDelta(part.text);
|
|
95
|
+
break;
|
|
96
|
+
case "reasoning-delta":
|
|
97
|
+
output.writeReasoningDelta(part.text);
|
|
98
|
+
break;
|
|
99
|
+
case "error":
|
|
100
|
+
streamError ??= { error: part.error };
|
|
101
|
+
break;
|
|
102
|
+
case "abort":
|
|
103
|
+
request.cancellationSignal.throwIfAborted();
|
|
104
|
+
throw new Error(`the AI SDK aborted the model call: ${part.reason ?? "no reason given"}`);
|
|
105
|
+
default:
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (streamError !== undefined) {
|
|
110
|
+
throw streamError.error;
|
|
111
|
+
}
|
|
112
|
+
const [step] = await result.steps;
|
|
113
|
+
if (step === undefined) {
|
|
114
|
+
throw new Error("the AI SDK model call returned no step");
|
|
115
|
+
}
|
|
116
|
+
const toolCalls = step.content.flatMap((part) => part.type === "tool-call" && part.providerExecuted !== true
|
|
117
|
+
? [{ toolCallId: part.toolCallId, toolName: part.toolName, arguments: serializeToolInput(part) }]
|
|
118
|
+
: []);
|
|
119
|
+
const assistantMessage = (await result.responseMessages).find((message) => message.role === "assistant");
|
|
120
|
+
const outputItems = assistantMessage === undefined
|
|
121
|
+
? []
|
|
122
|
+
: [
|
|
123
|
+
{
|
|
124
|
+
type: "model_output",
|
|
125
|
+
provider: this.provider,
|
|
126
|
+
api: aiSdkModelClientApi,
|
|
127
|
+
item: JSON.stringify(assistantMessage),
|
|
128
|
+
text: step.text === "" ? null : step.text,
|
|
129
|
+
toolCalls,
|
|
130
|
+
},
|
|
131
|
+
];
|
|
132
|
+
return {
|
|
133
|
+
outputItems,
|
|
134
|
+
text: step.text,
|
|
135
|
+
toolCalls,
|
|
136
|
+
usage: toAgentUsage(step.usage),
|
|
137
|
+
responseModel: step.response.modelId,
|
|
138
|
+
finishReason: step.finishReason,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
estimateInputTokens(request) {
|
|
142
|
+
const characters = request.instructions.length + JSON.stringify(request.inputItems).length + JSON.stringify(request.tools).length;
|
|
143
|
+
return Math.ceil(characters / 4);
|
|
144
|
+
}
|
|
145
|
+
appendInputItem(messages, item) {
|
|
146
|
+
switch (item.type) {
|
|
147
|
+
case "user_text":
|
|
148
|
+
messages.push({ role: "user", content: [{ type: "text", text: item.text }] });
|
|
149
|
+
return messages;
|
|
150
|
+
case "model_output": {
|
|
151
|
+
const message = this.replayModelOutput(item);
|
|
152
|
+
if (typeof message.content === "string" ? message.content !== "" : message.content.length > 0) {
|
|
153
|
+
messages.push(message);
|
|
154
|
+
}
|
|
155
|
+
return messages;
|
|
156
|
+
}
|
|
157
|
+
case "tool_result": {
|
|
158
|
+
const part = {
|
|
159
|
+
type: "tool-result",
|
|
160
|
+
toolCallId: item.toolCallId,
|
|
161
|
+
toolName: item.toolName,
|
|
162
|
+
output: { type: "text", value: item.output },
|
|
163
|
+
};
|
|
164
|
+
const lastMessage = messages.at(-1);
|
|
165
|
+
if (lastMessage?.role === "tool") {
|
|
166
|
+
lastMessage.content.push(part);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
messages.push({ role: "tool", content: [part] });
|
|
170
|
+
}
|
|
171
|
+
return messages;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** Replays the stored message unchanged to the same provider; other providers get text and tool calls. */
|
|
176
|
+
replayModelOutput(item) {
|
|
177
|
+
if (item.api === aiSdkModelClientApi && item.provider === this.provider) {
|
|
178
|
+
const message = JSON.parse(item.item);
|
|
179
|
+
if (message?.role !== "assistant") {
|
|
180
|
+
throw new TypeError("a stored AI SDK model output is not an assistant message");
|
|
181
|
+
}
|
|
182
|
+
return message;
|
|
183
|
+
}
|
|
184
|
+
const content = [];
|
|
185
|
+
if (item.text !== null && item.text !== "") {
|
|
186
|
+
content.push({ type: "text", text: item.text });
|
|
187
|
+
}
|
|
188
|
+
for (const toolCall of item.toolCalls) {
|
|
189
|
+
content.push({
|
|
190
|
+
type: "tool-call",
|
|
191
|
+
toolCallId: toolCall.toolCallId,
|
|
192
|
+
toolName: toolCall.toolName,
|
|
193
|
+
input: parseToolInput(toolCall.arguments),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return { role: "assistant", content };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** The model's arguments as JSON text; an invalid call keeps its raw text, so the tool Step reports it. */
|
|
200
|
+
function serializeToolInput(part) {
|
|
201
|
+
if (part.invalid === true && typeof part.input === "string") {
|
|
202
|
+
return part.input;
|
|
203
|
+
}
|
|
204
|
+
return JSON.stringify(part.input ?? {});
|
|
205
|
+
}
|
|
206
|
+
function toAiSdkToolChoice(toolChoice) {
|
|
207
|
+
return typeof toolChoice === "string" ? toolChoice : { type: "tool", toolName: toolChoice.toolName };
|
|
208
|
+
}
|
|
209
|
+
function toReasoningEffort(reasoningEffort) {
|
|
210
|
+
if (!reasoningEfforts.includes(reasoningEffort)) {
|
|
211
|
+
throw new TypeError(`the AI SDK supports reasoning efforts ${reasoningEfforts.join(", ")}, not ${reasoningEffort}`);
|
|
212
|
+
}
|
|
213
|
+
return reasoningEffort;
|
|
214
|
+
}
|
|
215
|
+
/** Tool call input as JSON; text that is not a JSON object is replayed as an empty object, as the AI SDK does. */
|
|
216
|
+
function parseToolInput(argumentsText) {
|
|
217
|
+
try {
|
|
218
|
+
const parsed = JSON.parse(argumentsText);
|
|
219
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return {};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function toAgentUsage(usage) {
|
|
226
|
+
return {
|
|
227
|
+
...emptyAgentUsage(),
|
|
228
|
+
modelCalls: 1,
|
|
229
|
+
inputTokens: usage.inputTokens ?? 0,
|
|
230
|
+
outputTokens: usage.outputTokens ?? 0,
|
|
231
|
+
cachedInputTokens: usage.inputTokenDetails.cacheReadTokens ?? 0,
|
|
232
|
+
reasoningTokens: usage.outputTokenDetails.reasoningTokens ?? 0,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=ai-sdk-model-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk-model-client.js","sourceRoot":"","sources":["../../../src/ai-sdk/ai-sdk-model-client.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,GASX,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,eAAe,EAAmB,MAAM,4BAA4B,CAAC;AAY9E,6DAA6D;AAC7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,QAAQ,CAAC;AAM5C,MAAM,gBAAgB,GAA+B;IACnD,kBAAkB;IAClB,MAAM;IACN,SAAS;IACT,KAAK;IACL,QAAQ;IACR,MAAM;IACN,OAAO;IACP,KAAK;CACN,CAAC;AAQF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAoB,EAAE,UAAmC,EAAE;IAChG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E,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC;AACvG,CAAC;AAED,SAAS,iBAAiB,CAAC,eAAuB;IAChD,IAAI,CAAE,gBAAsC,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,SAAS,CAAC,yCAAyC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,eAAe,EAAE,CAAC,CAAC;IACtH,CAAC;IACD,OAAO,eAAkC,CAAC;AAC5C,CAAC;AAED,kHAAkH;AAClH,SAAS,cAAc,CAAC,aAAqB;IAC3C,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAClD,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,KAAyB;IAC7C,OAAO;QACL,GAAG,eAAe,EAAE;QACpB,UAAU,EAAE,CAAC;QACb,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,CAAC;QACnC,YAAY,EAAE,KAAK,CAAC,YAAY,IAAI,CAAC;QACrC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,CAAC,eAAe,IAAI,CAAC;QAC/D,eAAe,EAAE,KAAK,CAAC,kBAAkB,CAAC,eAAe,IAAI,CAAC;KAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { aiSdkModelClientApi, createAiSdkModelClient, type AiSdkModelClientOptions } from "./ai-sdk-model-client.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
export { aiSdkModelClientApi, createAiSdkModelClient } from "./ai-sdk-model-client.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ai-sdk/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAgC,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { builtInToolDefinitions, writeTodosCalledMoreThanOnce, type BuiltInTool, type BuiltInToolDefinition, } from "./agent-built-in-tools.js";
|
|
2
|
+
export { buildPlanExecutionMessage, buildPlanNote, noPlanNote, planStatusAfterWrite, planningTurnInstruction, planningTurnToolRejection, } from "./agent-plans.js";
|
|
3
|
+
export { type CompactionPolicy, type ContextSummaryRequest, type ContextSummaryResult, type ResolvedCompactionPolicy, } from "./agent-context-compaction.js";
|
|
4
|
+
export { ToolExecutionError, resolveToolPolicy, toolEffectFromMcpToolAnnotations, type AgentEventWriter, type AgentFrameworkRunner, type AgentTurnContext, type AgentTurnOutcome, type DeferredToolCall, type DeferredToolExecution, type DeferredToolOutcome, type McpToolAnnotations, type ModelCallMetadata, type ResolvedToolPolicy, type ToolExecutionResult, type ToolInputRequested, type ToolPolicy, type ToolTaskPending, type ToolTaskCancellation, type ToolTaskPoll, type ToolTaskPollOutcome, type ToolTaskStarted, type TurnCompleted, type ToolCallsRequested, } from "./agent-framework-runner.js";
|
|
5
|
+
export { createAgentSessionFlow, type AgentSessionFlow, type AgentSessionOptions, type ResolvedAgentSessionOptions, } from "./agent-session-flow.js";
|
|
6
|
+
export { defaultAgentEventsCapacityBytes, messageSequenceKey, planExecutionKey, type AgentSessionPersistence, } from "./agent-session-persistence.js";
|
|
7
|
+
export { addAgentUsage, approvalDeadlinePassed, blankToolTaskId, buildTurnFailureNote, defaultQuestionDeclinedToolResult, defaultRejectionToolResult, describeToolCallOutcome, emptyAgentUsage, invalidToolTaskPollInterval, toolCallNotRunErrorPrefix, toolTaskAbandonedError, isFinalToolCallStatus, missingToolTaskPoller, outcomeUnknownToolResult, questionDeadlinePassed, toolCallCancelledBySteeringResult, toolCallCancelledByTurnCancellationResult, turnCancelledNoteHeader, turnFailureNoteFooter, turnFailureNoteHeader, turnSteeredNoteHeader, type AgentEvent, type AgentEventType, type AgentInterrupt, type AgentInterruptKind, type AgentInterruptResolution, type AgentMessage, type AgentMessageChunk, type AgentMessageChunkRange, type AgentMessageIndex, type AgentMessageRole, type AgentMessagesPage, type AgentPlan, type AgentPlanTask, type AgentSessionStartInput, type AgentSessionStatus, type AgentSnapshot, type AgentState, type AgentToolCall, type AgentToolCallRecord, type AgentToolCallRecordStatus, type AgentToolCallStatus, type AgentToolCallWaitingStatus, type AgentUsage, type AgentUserMessage, type AnswerQuestionRequest, type CancelTurnRequest, type DeleteQueuedMessageRequest, type ExecutePlanRequest, type CompactContextInput, type ContextSummary, type FrameworkMessage, type InteractionMode, type ListAgentMessagesInput, type PendingUserMessage, type PlanExecutionRequest, type PlanStatus, type PlanTaskStatus, type QuestionAnswer, type QuestionResolution, type ResolveInterruptInput, type SessionSettings, type TurnReplySequence, type TurnSessionSettings, type SteerUserMessageRequest, type ToolCallCancellation, type ToolCallCancellationReason, type ToolCallCompleted, type ToolEffect, type TurnCancellationRequest, type TurnControlKind, type TurnControlRequest, type UpdateSessionSettingsRequest, } from "./agent-session-values.js";
|
|
8
|
+
export { MAX_SESSION_SETTINGS_BYTES, SESSION_SETTINGS_SIZE_TOLERANCE_BYTES, sessionSettingsSize, validateSessionSettings, } from "./agent-session-settings.js";
|
|
9
|
+
export { invalidStartSessionSettingsReason } from "./agent-session-steps.js";
|
|
10
|
+
export { genAISemanticConventionsSchemaUrls, type AgentTracingOptions, type GenAISemanticConventionsVersion, type OpenTelemetryTracerProvider, type ResolvedAgentTracingOptions, } from "./agent-tracing-options.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
export { builtInToolDefinitions, writeTodosCalledMoreThanOnce, } from "./agent-built-in-tools.js";
|
|
9
|
+
export { buildPlanExecutionMessage, buildPlanNote, noPlanNote, planStatusAfterWrite, planningTurnInstruction, planningTurnToolRejection, } from "./agent-plans.js";
|
|
10
|
+
export { ToolExecutionError, resolveToolPolicy, toolEffectFromMcpToolAnnotations, } from "./agent-framework-runner.js";
|
|
11
|
+
export { createAgentSessionFlow, } from "./agent-session-flow.js";
|
|
12
|
+
export { defaultAgentEventsCapacityBytes, messageSequenceKey, planExecutionKey, } from "./agent-session-persistence.js";
|
|
13
|
+
export { addAgentUsage, approvalDeadlinePassed, blankToolTaskId, buildTurnFailureNote, defaultQuestionDeclinedToolResult, defaultRejectionToolResult, describeToolCallOutcome, emptyAgentUsage, invalidToolTaskPollInterval, toolCallNotRunErrorPrefix, toolTaskAbandonedError, isFinalToolCallStatus, missingToolTaskPoller, outcomeUnknownToolResult, questionDeadlinePassed, toolCallCancelledBySteeringResult, toolCallCancelledByTurnCancellationResult, turnCancelledNoteHeader, turnFailureNoteFooter, turnFailureNoteHeader, turnSteeredNoteHeader, } from "./agent-session-values.js";
|
|
14
|
+
export { MAX_SESSION_SETTINGS_BYTES, SESSION_SETTINGS_SIZE_TOLERANCE_BYTES, sessionSettingsSize, validateSessionSettings, } from "./agent-session-settings.js";
|
|
15
|
+
export { invalidStartSessionSettingsReason } from "./agent-session-steps.js";
|
|
16
|
+
export { genAISemanticConventionsSchemaUrls, } from "./agent-tracing-options.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EACL,sBAAsB,EACtB,4BAA4B,GAG7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAO1B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,gCAAgC,GAqBjC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,GAIvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,+BAA+B,EAC/B,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,eAAe,EACf,oBAAoB,EACpB,iCAAiC,EACjC,0BAA0B,EAC1B,uBAAuB,EACvB,eAAe,EACf,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,iCAAiC,EACjC,yCAAyC,EACzC,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,GAqDtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,0BAA0B,EAC1B,qCAAqC,EACrC,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EACL,kCAAkC,GAKnC,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type McpServerConfig, type McpStdioServerConfig, type McpStreamableHttpServerConfig, } from "./mcp-server-config.js";
|
|
2
|
+
export { mcpGetPromptToolName, mcpListResourcesAndPromptsToolName, mcpReadResourceToolName, } from "./mcp-resource-and-prompt-tools.js";
|
|
3
|
+
export { McpToolCallInterruptedError, McpToolListingError, McpToolSource, defaultMcpConnectionAttempts, defaultMcpConnectionTimeoutMs, defaultMcpListingFailureBackoffMs, defaultMcpListingTtlMs, defaultMcpRequestTimeoutMs, defaultMcpSourceName, defaultMcpTaskTtlMs, defaultMcpTaskWaitTimeoutMs, mcpIdempotencyKeyMetaKey, mcpTaskStatusEventType, mcpToolProgressEventType, type DeferredToolHandler, type McpTool, type McpToolCallOptions, type McpToolSourceOptions, } from "./mcp-tool-source.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
export { mcpGetPromptToolName, mcpListResourcesAndPromptsToolName, mcpReadResourceToolName, } from "./mcp-resource-and-prompt-tools.js";
|
|
9
|
+
export { McpToolCallInterruptedError, McpToolListingError, McpToolSource, defaultMcpConnectionAttempts, defaultMcpConnectionTimeoutMs, defaultMcpListingFailureBackoffMs, defaultMcpListingTtlMs, defaultMcpRequestTimeoutMs, defaultMcpSourceName, defaultMcpTaskTtlMs, defaultMcpTaskWaitTimeoutMs, mcpIdempotencyKeyMetaKey, mcpTaskStatusEventType, mcpToolProgressEventType, } from "./mcp-tool-source.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAO1D,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EAClC,uBAAuB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,aAAa,EACb,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EACjC,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,GAKzB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
/** Name of the read tool that lists a server's resources, resource templates, and prompts. */
|
|
3
|
+
export declare const mcpListResourcesAndPromptsToolName = "mcp_list_resources_and_prompts";
|
|
4
|
+
/** Name of the read tool that reads one resource of a server. */
|
|
5
|
+
export declare const mcpReadResourceToolName = "mcp_read_resource";
|
|
6
|
+
/** Name of the read tool that gets one prompt of a server. */
|
|
7
|
+
export declare const mcpGetPromptToolName = "mcp_get_prompt";
|
|
8
|
+
export declare const resourceAndPromptToolNames: ReadonlySet<string>;
|
|
9
|
+
/** A read tool's definition, before it becomes an `McpTool`. */
|
|
10
|
+
export interface ResourceAndPromptToolDefinition {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly description: string;
|
|
13
|
+
readonly inputSchema: Readonly<Record<string, unknown>>;
|
|
14
|
+
}
|
|
15
|
+
/** Returns the three read tools; the `server` argument names one of `serverNames`. */
|
|
16
|
+
export declare function buildResourceAndPromptToolDefinitions(serverNames: readonly string[]): ResourceAndPromptToolDefinition[];
|
|
17
|
+
/** Returns the `server` argument, or throws the {@link ToolExecutionError} the model sees. */
|
|
18
|
+
export declare function readServerName(toolArguments: Readonly<Record<string, unknown>>): string;
|
|
19
|
+
/** Sends one read tool's requests on an open connection and returns the output JSON text. */
|
|
20
|
+
export declare function runResourceAndPromptTool(client: Client, toolName: string, toolArguments: Readonly<Record<string, unknown>>, requestOptions: {
|
|
21
|
+
readonly timeout: number;
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
}): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Serializes with sorted keys and spaced separators, as the Python core's `json.dumps(sort_keys=True)`.
|
|
26
|
+
* Keys sort by code point while the text is written, never through an object, because JavaScript objects
|
|
27
|
+
* put integer-like keys first.
|
|
28
|
+
*/
|
|
29
|
+
export declare function serializeToolOutputJson(value: unknown): string;
|