@mastra/ai-sdk 1.11.2 → 1.11.3-alpha.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/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +209 -55
- package/dist/_types/@internal_ai-v6/dist/index.d.ts +161 -47
- package/dist/_types/@internal_ai-v7/dist/index.d.ts +1049 -274
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +837 -841
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +836 -839
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/ui.cjs +1 -2
- package/dist/ui.js +1 -2
- package/package.json +17 -17
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { MASTRA_RESOURCE_ID_KEY } from "@mastra/core/request-context";
|
|
|
9
9
|
import { MessageList, TripWire, aiV5ModelMessageToV2PromptMessage } from "@mastra/core/agent";
|
|
10
10
|
import { RequestContext } from "@mastra/core/di";
|
|
11
11
|
import { MessageHistory, SemanticRecall, WorkingMemory } from "@mastra/core/processors";
|
|
12
|
-
|
|
12
|
+
// ../../packages/_vendored/ai_v5/dist/dist-DRvrQv6K.js
|
|
13
13
|
var marker$1$4 = "vercel.ai.error";
|
|
14
14
|
var symbol$1$4 = Symbol.for(marker$1$4);
|
|
15
15
|
var _a$1$4;
|
|
@@ -1219,8 +1219,7 @@ function asSchema$2(schema) {
|
|
|
1219
1219
|
}) : isSchema$2(schema) ? schema : typeof schema === "function" ? schema() : zodSchema$2(schema);
|
|
1220
1220
|
}
|
|
1221
1221
|
var { btoa: btoa$3, atob: atob$6 } = globalThis;
|
|
1222
|
-
|
|
1223
|
-
//#region ../../packages/_vendored/ai_v5/dist/index.js
|
|
1222
|
+
// ../../packages/_vendored/ai_v5/dist/index.js
|
|
1224
1223
|
/** only globals that common to node and browsers are allowed */
|
|
1225
1224
|
var _globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
1226
1225
|
var VERSION$1$3 = "1.9.0";
|
|
@@ -1411,7 +1410,7 @@ function logProxy$1(funcName, namespace, args) {
|
|
|
1411
1410
|
* of the levels are defined to match the original values from the initial LogLevel to avoid
|
|
1412
1411
|
* compatibility/migration issues for any implementation that assume the numeric ordering.
|
|
1413
1412
|
*/
|
|
1414
|
-
var DiagLogLevel
|
|
1413
|
+
var DiagLogLevel;
|
|
1415
1414
|
(function(DiagLogLevel) {
|
|
1416
1415
|
/** Diagnostic Logging level setting to disable all logging (except and forced logs) */
|
|
1417
1416
|
DiagLogLevel[DiagLogLevel["NONE"] = 0] = "NONE";
|
|
@@ -1430,10 +1429,10 @@ var DiagLogLevel$1;
|
|
|
1430
1429
|
DiagLogLevel[DiagLogLevel["VERBOSE"] = 80] = "VERBOSE";
|
|
1431
1430
|
/** Used to set the logging level to include all logging */
|
|
1432
1431
|
DiagLogLevel[DiagLogLevel["ALL"] = 9999] = "ALL";
|
|
1433
|
-
})(DiagLogLevel
|
|
1432
|
+
})(DiagLogLevel || (DiagLogLevel = {}));
|
|
1434
1433
|
function createLogLevelDiagLogger$1(maxLevel, logger) {
|
|
1435
|
-
if (maxLevel < DiagLogLevel
|
|
1436
|
-
else if (maxLevel > DiagLogLevel
|
|
1434
|
+
if (maxLevel < DiagLogLevel.NONE) maxLevel = DiagLogLevel.NONE;
|
|
1435
|
+
else if (maxLevel > DiagLogLevel.ALL) maxLevel = DiagLogLevel.ALL;
|
|
1437
1436
|
logger = logger || {};
|
|
1438
1437
|
function _filterFunc(funcName, theLevel) {
|
|
1439
1438
|
var theFunc = logger[funcName];
|
|
@@ -1441,11 +1440,11 @@ function createLogLevelDiagLogger$1(maxLevel, logger) {
|
|
|
1441
1440
|
return function() {};
|
|
1442
1441
|
}
|
|
1443
1442
|
return {
|
|
1444
|
-
error: _filterFunc("error", DiagLogLevel
|
|
1445
|
-
warn: _filterFunc("warn", DiagLogLevel
|
|
1446
|
-
info: _filterFunc("info", DiagLogLevel
|
|
1447
|
-
debug: _filterFunc("debug", DiagLogLevel
|
|
1448
|
-
verbose: _filterFunc("verbose", DiagLogLevel
|
|
1443
|
+
error: _filterFunc("error", DiagLogLevel.ERROR),
|
|
1444
|
+
warn: _filterFunc("warn", DiagLogLevel.WARN),
|
|
1445
|
+
info: _filterFunc("info", DiagLogLevel.INFO),
|
|
1446
|
+
debug: _filterFunc("debug", DiagLogLevel.DEBUG),
|
|
1447
|
+
verbose: _filterFunc("verbose", DiagLogLevel.VERBOSE)
|
|
1449
1448
|
};
|
|
1450
1449
|
}
|
|
1451
1450
|
var __read$2 = function(o, n) {
|
|
@@ -1497,7 +1496,7 @@ var DiagAPI$1 = function() {
|
|
|
1497
1496
|
var self = this;
|
|
1498
1497
|
var setLogger = function(logger, optionsOrLogLevel) {
|
|
1499
1498
|
var _a, _b, _c;
|
|
1500
|
-
if (optionsOrLogLevel === void 0) optionsOrLogLevel = { logLevel: DiagLogLevel
|
|
1499
|
+
if (optionsOrLogLevel === void 0) optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
|
|
1501
1500
|
if (logger === self) {
|
|
1502
1501
|
var err = /* @__PURE__ */ new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
1503
1502
|
self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
@@ -1505,7 +1504,7 @@ var DiagAPI$1 = function() {
|
|
|
1505
1504
|
}
|
|
1506
1505
|
if (typeof optionsOrLogLevel === "number") optionsOrLogLevel = { logLevel: optionsOrLogLevel };
|
|
1507
1506
|
var oldLogger = getGlobal$1("diag");
|
|
1508
|
-
var newLogger = createLogLevelDiagLogger$1((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel
|
|
1507
|
+
var newLogger = createLogLevelDiagLogger$1((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger);
|
|
1509
1508
|
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
1510
1509
|
var stack = (_c = (/* @__PURE__ */ new Error()).stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
|
|
1511
1510
|
oldLogger.warn("Current logger will be overwritten from " + stack);
|
|
@@ -1700,17 +1699,17 @@ var ContextAPI$1 = function() {
|
|
|
1700
1699
|
};
|
|
1701
1700
|
return ContextAPI;
|
|
1702
1701
|
}();
|
|
1703
|
-
var TraceFlags
|
|
1702
|
+
var TraceFlags;
|
|
1704
1703
|
(function(TraceFlags) {
|
|
1705
1704
|
/** Represents no flag set. */
|
|
1706
1705
|
TraceFlags[TraceFlags["NONE"] = 0] = "NONE";
|
|
1707
1706
|
/** Bit to represent whether trace is sampled in trace flags. */
|
|
1708
1707
|
TraceFlags[TraceFlags["SAMPLED"] = 1] = "SAMPLED";
|
|
1709
|
-
})(TraceFlags
|
|
1708
|
+
})(TraceFlags || (TraceFlags = {}));
|
|
1710
1709
|
var INVALID_SPAN_CONTEXT$1 = {
|
|
1711
1710
|
traceId: "00000000000000000000000000000000",
|
|
1712
1711
|
spanId: "0000000000000000",
|
|
1713
|
-
traceFlags: TraceFlags
|
|
1712
|
+
traceFlags: TraceFlags.NONE
|
|
1714
1713
|
};
|
|
1715
1714
|
/**
|
|
1716
1715
|
* The NonRecordingSpan is the default {@link Span} that is used when no Span
|
|
@@ -1942,7 +1941,7 @@ var ProxyTracerProvider$1 = function() {
|
|
|
1942
1941
|
/**
|
|
1943
1942
|
* An enumeration of status codes.
|
|
1944
1943
|
*/
|
|
1945
|
-
var SpanStatusCode
|
|
1944
|
+
var SpanStatusCode;
|
|
1946
1945
|
(function(SpanStatusCode) {
|
|
1947
1946
|
/**
|
|
1948
1947
|
* The default status.
|
|
@@ -1957,7 +1956,7 @@ var SpanStatusCode$1;
|
|
|
1957
1956
|
* The operation contains an error.
|
|
1958
1957
|
*/
|
|
1959
1958
|
SpanStatusCode[SpanStatusCode["ERROR"] = 2] = "ERROR";
|
|
1960
|
-
})(SpanStatusCode
|
|
1959
|
+
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
1961
1960
|
var API_NAME$3 = "trace";
|
|
1962
1961
|
(function() {
|
|
1963
1962
|
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
@@ -2008,40 +2007,40 @@ var API_NAME$3 = "trace";
|
|
|
2008
2007
|
})().getInstance();
|
|
2009
2008
|
var __defProp$1 = Object.defineProperty;
|
|
2010
2009
|
var __export$1 = (target, all) => {
|
|
2011
|
-
for (var
|
|
2012
|
-
get: all[
|
|
2010
|
+
for (var name17 in all) __defProp$1(target, name17, {
|
|
2011
|
+
get: all[name17],
|
|
2013
2012
|
enumerable: true
|
|
2014
2013
|
});
|
|
2015
2014
|
};
|
|
2016
|
-
var
|
|
2017
|
-
var
|
|
2018
|
-
var
|
|
2019
|
-
var
|
|
2015
|
+
var name7$2 = "AI_NoObjectGeneratedError";
|
|
2016
|
+
var marker7$2 = `vercel.ai.error.${name7$2}`;
|
|
2017
|
+
var symbol7$2 = Symbol.for(marker7$2);
|
|
2018
|
+
var _a7$2;
|
|
2020
2019
|
var NoObjectGeneratedError$1 = class extends AISDKError$2 {
|
|
2021
2020
|
constructor({ message = "No object generated.", cause, text: text2, response, usage, finishReason }) {
|
|
2022
2021
|
super({
|
|
2023
|
-
name:
|
|
2022
|
+
name: name7$2,
|
|
2024
2023
|
message,
|
|
2025
2024
|
cause
|
|
2026
2025
|
});
|
|
2027
|
-
this[
|
|
2026
|
+
this[_a7$2] = true;
|
|
2028
2027
|
this.text = text2;
|
|
2029
2028
|
this.response = response;
|
|
2030
2029
|
this.usage = usage;
|
|
2031
2030
|
this.finishReason = finishReason;
|
|
2032
2031
|
}
|
|
2033
2032
|
static isInstance(error) {
|
|
2034
|
-
return AISDKError$2.hasMarker(error,
|
|
2033
|
+
return AISDKError$2.hasMarker(error, marker7$2);
|
|
2035
2034
|
}
|
|
2036
2035
|
};
|
|
2037
|
-
|
|
2036
|
+
_a7$2 = symbol7$2;
|
|
2038
2037
|
var dataContentSchema$1 = z.union([
|
|
2039
2038
|
z.string(),
|
|
2040
2039
|
z.instanceof(Uint8Array),
|
|
2041
2040
|
z.instanceof(ArrayBuffer),
|
|
2042
2041
|
z.custom((value) => {
|
|
2043
|
-
var
|
|
2044
|
-
return (_b = (
|
|
2042
|
+
var _a17, _b;
|
|
2043
|
+
return (_b = (_a17 = globalThis.Buffer) == null ? void 0 : _a17.isBuffer(value)) != null ? _b : false;
|
|
2045
2044
|
}, { message: "Must be a Buffer" })
|
|
2046
2045
|
]);
|
|
2047
2046
|
var jsonValueSchema$2 = z.lazy(() => z.union([
|
|
@@ -2544,7 +2543,7 @@ function getToolName(part) {
|
|
|
2544
2543
|
return part.type.split("-").slice(1).join("-");
|
|
2545
2544
|
}
|
|
2546
2545
|
function createStreamingUIMessageState$2({ lastMessage, messageId }) {
|
|
2547
|
-
var
|
|
2546
|
+
var _a17;
|
|
2548
2547
|
const message = (lastMessage == null ? void 0 : lastMessage.role) === "assistant" ? lastMessage : {
|
|
2549
2548
|
id: messageId,
|
|
2550
2549
|
metadata: void 0,
|
|
@@ -2560,7 +2559,7 @@ function createStreamingUIMessageState$2({ lastMessage, messageId }) {
|
|
|
2560
2559
|
if (isToolUIPart$2(part)) staticToolIndex++;
|
|
2561
2560
|
if (part.state !== "input-streaming") continue;
|
|
2562
2561
|
partialToolCalls[part.toolCallId] = {
|
|
2563
|
-
text: (
|
|
2562
|
+
text: (_a17 = part.rawInput) != null ? _a17 : "",
|
|
2564
2563
|
index,
|
|
2565
2564
|
toolName: isDynamicToolUIPart$2(part) ? part.toolName : getToolName(part),
|
|
2566
2565
|
dynamic: isDynamicToolUIPart$2(part)
|
|
@@ -2576,7 +2575,7 @@ function createStreamingUIMessageState$2({ lastMessage, messageId }) {
|
|
|
2576
2575
|
function processUIMessageStream$2({ stream, messageMetadataSchema, dataPartSchemas, runUpdateMessageJob, onError, onToolCall, onData, resetStateOnMessageIdChange = false }) {
|
|
2577
2576
|
return stream.pipeThrough(new TransformStream({ async transform(chunk, controller) {
|
|
2578
2577
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
2579
|
-
var
|
|
2578
|
+
var _a17, _b, _c, _d;
|
|
2580
2579
|
function getCurrentStepParts() {
|
|
2581
2580
|
const parts = state.message.parts;
|
|
2582
2581
|
let currentStepStartIndex = parts.length - 1;
|
|
@@ -2617,7 +2616,7 @@ function processUIMessageStream$2({ stream, messageMetadataSchema, dataPartSchem
|
|
|
2617
2616
|
return toolInvocation;
|
|
2618
2617
|
}
|
|
2619
2618
|
function updateToolPart(options, existingPart) {
|
|
2620
|
-
var
|
|
2619
|
+
var _a18;
|
|
2621
2620
|
const part = existingPart != null ? existingPart : getCurrentStepParts().find((part2) => isToolUIPart$2(part2) && part2.toolCallId === options.toolCallId);
|
|
2622
2621
|
const anyOptions = options;
|
|
2623
2622
|
const anyPart = part;
|
|
@@ -2628,7 +2627,7 @@ function processUIMessageStream$2({ stream, messageMetadataSchema, dataPartSchem
|
|
|
2628
2627
|
anyPart.errorText = anyOptions.errorText;
|
|
2629
2628
|
anyPart.rawInput = anyOptions.rawInput;
|
|
2630
2629
|
anyPart.preliminary = anyOptions.preliminary;
|
|
2631
|
-
anyPart.providerExecuted = (
|
|
2630
|
+
anyPart.providerExecuted = (_a18 = anyOptions.providerExecuted) != null ? _a18 : part.providerExecuted;
|
|
2632
2631
|
if (anyOptions.providerMetadata != null && part.state === "input-available") part.callProviderMetadata = anyOptions.providerMetadata;
|
|
2633
2632
|
} else state.message.parts.push({
|
|
2634
2633
|
type: `tool-${options.toolName}`,
|
|
@@ -2644,7 +2643,7 @@ function processUIMessageStream$2({ stream, messageMetadataSchema, dataPartSchem
|
|
|
2644
2643
|
});
|
|
2645
2644
|
}
|
|
2646
2645
|
function updateDynamicToolPart(options, existingPart) {
|
|
2647
|
-
var
|
|
2646
|
+
var _a18;
|
|
2648
2647
|
const part = existingPart != null ? existingPart : getCurrentStepParts().find((part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId);
|
|
2649
2648
|
const anyOptions = options;
|
|
2650
2649
|
const anyPart = part;
|
|
@@ -2656,7 +2655,7 @@ function processUIMessageStream$2({ stream, messageMetadataSchema, dataPartSchem
|
|
|
2656
2655
|
anyPart.errorText = anyOptions.errorText;
|
|
2657
2656
|
anyPart.rawInput = anyOptions.rawInput;
|
|
2658
2657
|
anyPart.preliminary = anyOptions.preliminary;
|
|
2659
|
-
anyPart.providerExecuted = (
|
|
2658
|
+
anyPart.providerExecuted = (_a18 = anyOptions.providerExecuted) != null ? _a18 : part.providerExecuted;
|
|
2660
2659
|
if (anyOptions.providerMetadata != null && part.state === "input-available") part.callProviderMetadata = anyOptions.providerMetadata;
|
|
2661
2660
|
} else state.message.parts.push({
|
|
2662
2661
|
type: "dynamic-tool",
|
|
@@ -2697,7 +2696,7 @@ function processUIMessageStream$2({ stream, messageMetadataSchema, dataPartSchem
|
|
|
2697
2696
|
case "text-delta": {
|
|
2698
2697
|
const textPart = state.activeTextParts[chunk.id];
|
|
2699
2698
|
textPart.text += chunk.delta;
|
|
2700
|
-
textPart.providerMetadata = (
|
|
2699
|
+
textPart.providerMetadata = (_a17 = chunk.providerMetadata) != null ? _a17 : textPart.providerMetadata;
|
|
2701
2700
|
write();
|
|
2702
2701
|
break;
|
|
2703
2702
|
}
|
|
@@ -2999,11 +2998,11 @@ function handleUIMessageStreamFinish$2({ messageId, originalMessages = [], onFin
|
|
|
2999
2998
|
};
|
|
3000
2999
|
let finishCalled = false;
|
|
3001
3000
|
const callOnFinish = async () => {
|
|
3002
|
-
var
|
|
3001
|
+
var _a17;
|
|
3003
3002
|
if (finishCalled || !onFinish) return;
|
|
3004
3003
|
finishCalled = true;
|
|
3005
3004
|
const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
|
|
3006
|
-
const declaredOutcome = (
|
|
3005
|
+
const declaredOutcome = (_a17 = getOutcome == null ? void 0 : getOutcome()) != null ? _a17 : { status: "unknown" };
|
|
3007
3006
|
const outcome = hasProcessingFailure ? {
|
|
3008
3007
|
status: "failed",
|
|
3009
3008
|
error: processingError
|
|
@@ -3119,7 +3118,7 @@ var wrapLanguageModel$1 = ({ model, middleware: middlewareArg, modelId, provider
|
|
|
3119
3118
|
}, model);
|
|
3120
3119
|
};
|
|
3121
3120
|
var doWrap$1 = ({ model, middleware: { transformParams, wrapGenerate, wrapStream, overrideProvider, overrideModelId, overrideSupportedUrls }, modelId, providerId }) => {
|
|
3122
|
-
var
|
|
3121
|
+
var _a17, _b, _c;
|
|
3123
3122
|
async function doTransform({ params, type }) {
|
|
3124
3123
|
return transformParams ? await transformParams({
|
|
3125
3124
|
params,
|
|
@@ -3129,7 +3128,7 @@ var doWrap$1 = ({ model, middleware: { transformParams, wrapGenerate, wrapStream
|
|
|
3129
3128
|
}
|
|
3130
3129
|
return {
|
|
3131
3130
|
specificationVersion: "v2",
|
|
3132
|
-
provider: (
|
|
3131
|
+
provider: (_a17 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a17 : model.provider,
|
|
3133
3132
|
modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
|
|
3134
3133
|
supportedUrls: (_c = overrideSupportedUrls == null ? void 0 : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
|
|
3135
3134
|
async doGenerate(params) {
|
|
@@ -3245,8 +3244,7 @@ function createUIMessageStream$2({ execute, onError = () => "An error occurred."
|
|
|
3245
3244
|
getOutcome: () => outcome
|
|
3246
3245
|
});
|
|
3247
3246
|
}
|
|
3248
|
-
|
|
3249
|
-
//#region ../../packages/_vendored/ai_v6/dist/dist-B3lfSiDN.js
|
|
3247
|
+
// ../../packages/_vendored/ai_v6/dist/dist-Dl1sIpsh.js
|
|
3250
3248
|
var marker$1$2 = "vercel.ai.error";
|
|
3251
3249
|
var symbol$1$2 = Symbol.for(marker$1$2);
|
|
3252
3250
|
var _a$1;
|
|
@@ -4477,9 +4475,8 @@ async function resolve(value) {
|
|
|
4477
4475
|
return value;
|
|
4478
4476
|
}
|
|
4479
4477
|
new TextDecoder();
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
const VERSION$1 = "1.9.1";
|
|
4478
|
+
// ../../packages/_vendored/ai_v6/dist/index.js
|
|
4479
|
+
const VERSION$1 = "1.10.0";
|
|
4483
4480
|
const re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
|
|
4484
4481
|
/**
|
|
4485
4482
|
* Create a function to test an API version to see if it is compatible with the provided ownVersion.
|
|
@@ -4559,15 +4556,23 @@ const isCompatible = _makeCompatibilityCheck(VERSION$1);
|
|
|
4559
4556
|
const major = VERSION$1.split(".")[0];
|
|
4560
4557
|
const GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for(`opentelemetry.js.api.${major}`);
|
|
4561
4558
|
const _global = typeof globalThis === "object" ? globalThis : typeof self === "object" ? self : typeof window === "object" ? window : typeof global === "object" ? global : {};
|
|
4559
|
+
function _makeGlobalApi() {
|
|
4560
|
+
return Object.defineProperty({}, "version", {
|
|
4561
|
+
value: VERSION$1,
|
|
4562
|
+
enumerable: true,
|
|
4563
|
+
writable: false,
|
|
4564
|
+
configurable: false
|
|
4565
|
+
});
|
|
4566
|
+
}
|
|
4562
4567
|
function registerGlobal(type, instance, diag, allowOverride = false) {
|
|
4563
|
-
var
|
|
4564
|
-
const api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (
|
|
4568
|
+
var _global$GLOBAL_OPENTE;
|
|
4569
|
+
const api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_global$GLOBAL_OPENTE = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _global$GLOBAL_OPENTE !== void 0 ? _global$GLOBAL_OPENTE : _makeGlobalApi();
|
|
4565
4570
|
if (!allowOverride && api[type]) {
|
|
4566
4571
|
const err = /* @__PURE__ */ new Error(`@opentelemetry/api: Attempted duplicate registration of API: ${type}`);
|
|
4567
4572
|
diag.error(err.stack || err.message);
|
|
4568
4573
|
return false;
|
|
4569
4574
|
}
|
|
4570
|
-
if (api.version !== "1.
|
|
4575
|
+
if (api.version !== "1.10.0") {
|
|
4571
4576
|
const err = /* @__PURE__ */ new Error(`@opentelemetry/api: Registration of version v${api.version} for ${type} does not match previously registered API v${VERSION$1}`);
|
|
4572
4577
|
diag.error(err.stack || err.message);
|
|
4573
4578
|
return false;
|
|
@@ -4576,11 +4581,15 @@ function registerGlobal(type, instance, diag, allowOverride = false) {
|
|
|
4576
4581
|
diag.debug(`@opentelemetry/api: Registered a global for ${type} v${VERSION$1}.`);
|
|
4577
4582
|
return true;
|
|
4578
4583
|
}
|
|
4584
|
+
let _compatibleGlobalApi;
|
|
4579
4585
|
function getGlobal(type) {
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
if (
|
|
4583
|
-
|
|
4586
|
+
const api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
|
|
4587
|
+
if (api == null) return;
|
|
4588
|
+
if (api !== _compatibleGlobalApi) {
|
|
4589
|
+
if (!api.version || !isCompatible(api.version)) return;
|
|
4590
|
+
_compatibleGlobalApi = api;
|
|
4591
|
+
}
|
|
4592
|
+
return api[type];
|
|
4584
4593
|
}
|
|
4585
4594
|
function unregisterGlobal(type, diag) {
|
|
4586
4595
|
diag.debug(`@opentelemetry/api: Unregistering a global for ${type} v${VERSION$1}.`);
|
|
@@ -4621,34 +4630,9 @@ function logProxy(funcName, namespace, args) {
|
|
|
4621
4630
|
if (!logger) return;
|
|
4622
4631
|
return logger[funcName](namespace, ...args);
|
|
4623
4632
|
}
|
|
4624
|
-
/**
|
|
4625
|
-
* Defines the available internal logging levels for the diagnostic logger, the numeric values
|
|
4626
|
-
* of the levels are defined to match the original values from the initial LogLevel to avoid
|
|
4627
|
-
* compatibility/migration issues for any implementation that assume the numeric ordering.
|
|
4628
|
-
*/
|
|
4629
|
-
var DiagLogLevel;
|
|
4630
|
-
(function(DiagLogLevel) {
|
|
4631
|
-
/** Diagnostic Logging level setting to disable all logging (except and forced logs) */
|
|
4632
|
-
DiagLogLevel[DiagLogLevel["NONE"] = 0] = "NONE";
|
|
4633
|
-
/** Identifies an error scenario */
|
|
4634
|
-
DiagLogLevel[DiagLogLevel["ERROR"] = 30] = "ERROR";
|
|
4635
|
-
/** Identifies a warning scenario */
|
|
4636
|
-
DiagLogLevel[DiagLogLevel["WARN"] = 50] = "WARN";
|
|
4637
|
-
/** General informational log message */
|
|
4638
|
-
DiagLogLevel[DiagLogLevel["INFO"] = 60] = "INFO";
|
|
4639
|
-
/** General debug log message */
|
|
4640
|
-
DiagLogLevel[DiagLogLevel["DEBUG"] = 70] = "DEBUG";
|
|
4641
|
-
/**
|
|
4642
|
-
* Detailed trace level logging should only be used for development, should only be set
|
|
4643
|
-
* in a development environment.
|
|
4644
|
-
*/
|
|
4645
|
-
DiagLogLevel[DiagLogLevel["VERBOSE"] = 80] = "VERBOSE";
|
|
4646
|
-
/** Used to set the logging level to include all logging */
|
|
4647
|
-
DiagLogLevel[DiagLogLevel["ALL"] = 9999] = "ALL";
|
|
4648
|
-
})(DiagLogLevel || (DiagLogLevel = {}));
|
|
4649
4633
|
function createLogLevelDiagLogger(maxLevel, logger) {
|
|
4650
|
-
if (maxLevel <
|
|
4651
|
-
else if (maxLevel >
|
|
4634
|
+
if (maxLevel < 0) maxLevel = 0;
|
|
4635
|
+
else if (maxLevel > 9999) maxLevel = 9999;
|
|
4652
4636
|
logger = logger || {};
|
|
4653
4637
|
function _filterFunc(funcName, theLevel) {
|
|
4654
4638
|
const theFunc = logger[funcName];
|
|
@@ -4656,11 +4640,11 @@ function createLogLevelDiagLogger(maxLevel, logger) {
|
|
|
4656
4640
|
return function() {};
|
|
4657
4641
|
}
|
|
4658
4642
|
return {
|
|
4659
|
-
error: _filterFunc("error",
|
|
4660
|
-
warn: _filterFunc("warn",
|
|
4661
|
-
info: _filterFunc("info",
|
|
4662
|
-
debug: _filterFunc("debug",
|
|
4663
|
-
verbose: _filterFunc("verbose",
|
|
4643
|
+
error: _filterFunc("error", 30),
|
|
4644
|
+
warn: _filterFunc("warn", 50),
|
|
4645
|
+
info: _filterFunc("info", 60),
|
|
4646
|
+
debug: _filterFunc("debug", 70),
|
|
4647
|
+
verbose: _filterFunc("verbose", 80)
|
|
4664
4648
|
};
|
|
4665
4649
|
}
|
|
4666
4650
|
const API_NAME$2 = "diag";
|
|
@@ -4689,18 +4673,20 @@ var DiagAPI = class DiagAPI {
|
|
|
4689
4673
|
};
|
|
4690
4674
|
}
|
|
4691
4675
|
const self = this;
|
|
4692
|
-
const setLogger = (logger, optionsOrLogLevel = { logLevel:
|
|
4693
|
-
var
|
|
4676
|
+
const setLogger = (logger, optionsOrLogLevel = { logLevel: 60 }) => {
|
|
4677
|
+
var _optionsOrLogLevel$lo;
|
|
4694
4678
|
if (logger === self) {
|
|
4679
|
+
var _err$stack;
|
|
4695
4680
|
const err = /* @__PURE__ */ new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
4696
|
-
self.error((
|
|
4681
|
+
self.error((_err$stack = err.stack) !== null && _err$stack !== void 0 ? _err$stack : err.message);
|
|
4697
4682
|
return false;
|
|
4698
4683
|
}
|
|
4699
4684
|
if (typeof optionsOrLogLevel === "number") optionsOrLogLevel = { logLevel: optionsOrLogLevel };
|
|
4700
4685
|
const oldLogger = getGlobal("diag");
|
|
4701
|
-
const newLogger = createLogLevelDiagLogger((
|
|
4686
|
+
const newLogger = createLogLevelDiagLogger((_optionsOrLogLevel$lo = optionsOrLogLevel.logLevel) !== null && _optionsOrLogLevel$lo !== void 0 ? _optionsOrLogLevel$lo : 60, logger);
|
|
4702
4687
|
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
4703
|
-
|
|
4688
|
+
var _Error$stack;
|
|
4689
|
+
const stack = (_Error$stack = (/* @__PURE__ */ new Error()).stack) !== null && _Error$stack !== void 0 ? _Error$stack : "<failed to generate stacktrace>";
|
|
4704
4690
|
oldLogger.warn(`Current logger will be overwritten from ${stack}`);
|
|
4705
4691
|
newLogger.warn(`Current logger will overwrite one already registered from ${stack}`);
|
|
4706
4692
|
}
|
|
@@ -4755,98 +4741,13 @@ const ROOT_CONTEXT = new class BaseContext {
|
|
|
4755
4741
|
};
|
|
4756
4742
|
}
|
|
4757
4743
|
}();
|
|
4758
|
-
var NoopContextManager = class {
|
|
4759
|
-
active() {
|
|
4760
|
-
return ROOT_CONTEXT;
|
|
4761
|
-
}
|
|
4762
|
-
with(_context, fn, thisArg, ...args) {
|
|
4763
|
-
return fn.call(thisArg, ...args);
|
|
4764
|
-
}
|
|
4765
|
-
bind(_context, target) {
|
|
4766
|
-
return target;
|
|
4767
|
-
}
|
|
4768
|
-
enable() {
|
|
4769
|
-
return this;
|
|
4770
|
-
}
|
|
4771
|
-
disable() {
|
|
4772
|
-
return this;
|
|
4773
|
-
}
|
|
4774
|
-
};
|
|
4775
|
-
const API_NAME$1 = "context";
|
|
4776
|
-
const NOOP_CONTEXT_MANAGER = new NoopContextManager();
|
|
4777
|
-
/**
|
|
4778
|
-
* Singleton object which represents the entry point to the OpenTelemetry Context API
|
|
4779
|
-
*
|
|
4780
|
-
* @since 1.0.0
|
|
4781
|
-
*/
|
|
4782
|
-
var ContextAPI = class ContextAPI {
|
|
4783
|
-
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
4784
|
-
constructor() {}
|
|
4785
|
-
/** Get the singleton instance of the Context API */
|
|
4786
|
-
static getInstance() {
|
|
4787
|
-
if (!this._instance) this._instance = new ContextAPI();
|
|
4788
|
-
return this._instance;
|
|
4789
|
-
}
|
|
4790
|
-
/**
|
|
4791
|
-
* Set the current context manager.
|
|
4792
|
-
*
|
|
4793
|
-
* @returns true if the context manager was successfully registered, else false
|
|
4794
|
-
*/
|
|
4795
|
-
setGlobalContextManager(contextManager) {
|
|
4796
|
-
return registerGlobal(API_NAME$1, contextManager, DiagAPI.instance());
|
|
4797
|
-
}
|
|
4798
|
-
/**
|
|
4799
|
-
* Get the currently active context
|
|
4800
|
-
*/
|
|
4801
|
-
active() {
|
|
4802
|
-
return this._getContextManager().active();
|
|
4803
|
-
}
|
|
4804
|
-
/**
|
|
4805
|
-
* Execute a function with an active context
|
|
4806
|
-
*
|
|
4807
|
-
* @param context context to be active during function execution
|
|
4808
|
-
* @param fn function to execute in a context
|
|
4809
|
-
* @param thisArg optional receiver to be used for calling fn
|
|
4810
|
-
* @param args optional arguments forwarded to fn
|
|
4811
|
-
*/
|
|
4812
|
-
with(context, fn, thisArg, ...args) {
|
|
4813
|
-
return this._getContextManager().with(context, fn, thisArg, ...args);
|
|
4814
|
-
}
|
|
4815
|
-
/**
|
|
4816
|
-
* Bind a context to a target function or event emitter
|
|
4817
|
-
*
|
|
4818
|
-
* @param context context to bind to the event emitter or function. Defaults to the currently active context
|
|
4819
|
-
* @param target function or event emitter to bind
|
|
4820
|
-
*/
|
|
4821
|
-
bind(context, target) {
|
|
4822
|
-
return this._getContextManager().bind(context, target);
|
|
4823
|
-
}
|
|
4824
|
-
_getContextManager() {
|
|
4825
|
-
return getGlobal(API_NAME$1) || NOOP_CONTEXT_MANAGER;
|
|
4826
|
-
}
|
|
4827
|
-
/** Disable and remove the global context manager */
|
|
4828
|
-
disable() {
|
|
4829
|
-
this._getContextManager().disable();
|
|
4830
|
-
unregisterGlobal(API_NAME$1, DiagAPI.instance());
|
|
4831
|
-
}
|
|
4832
|
-
};
|
|
4833
|
-
/**
|
|
4834
|
-
* @since 1.0.0
|
|
4835
|
-
*/
|
|
4836
|
-
var TraceFlags;
|
|
4837
|
-
(function(TraceFlags) {
|
|
4838
|
-
/** Represents no flag set. */
|
|
4839
|
-
TraceFlags[TraceFlags["NONE"] = 0] = "NONE";
|
|
4840
|
-
/** Bit to represent whether trace is sampled in trace flags. */
|
|
4841
|
-
TraceFlags[TraceFlags["SAMPLED"] = 1] = "SAMPLED";
|
|
4842
|
-
})(TraceFlags || (TraceFlags = {}));
|
|
4843
4744
|
/**
|
|
4844
4745
|
* @since 1.0.0
|
|
4845
4746
|
*/
|
|
4846
4747
|
const INVALID_SPAN_CONTEXT = {
|
|
4847
4748
|
traceId: "00000000000000000000000000000000",
|
|
4848
4749
|
spanId: "0000000000000000",
|
|
4849
|
-
traceFlags:
|
|
4750
|
+
traceFlags: 0
|
|
4850
4751
|
};
|
|
4851
4752
|
/**
|
|
4852
4753
|
* The NonRecordingSpan is the default {@link Span} that is used when no Span
|
|
@@ -4887,60 +4788,6 @@ var NonRecordingSpan = class {
|
|
|
4887
4788
|
}
|
|
4888
4789
|
recordException(_exception, _time) {}
|
|
4889
4790
|
};
|
|
4890
|
-
/**
|
|
4891
|
-
* span key
|
|
4892
|
-
*/
|
|
4893
|
-
const SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
|
|
4894
|
-
/**
|
|
4895
|
-
* Return the span if one exists
|
|
4896
|
-
*
|
|
4897
|
-
* @param context context to get span from
|
|
4898
|
-
*/
|
|
4899
|
-
function getSpan(context) {
|
|
4900
|
-
return context.getValue(SPAN_KEY) || void 0;
|
|
4901
|
-
}
|
|
4902
|
-
/**
|
|
4903
|
-
* Gets the span from the current context, if one exists.
|
|
4904
|
-
*/
|
|
4905
|
-
function getActiveSpan() {
|
|
4906
|
-
return getSpan(ContextAPI.getInstance().active());
|
|
4907
|
-
}
|
|
4908
|
-
/**
|
|
4909
|
-
* Set the span on a context
|
|
4910
|
-
*
|
|
4911
|
-
* @param context context to use as parent
|
|
4912
|
-
* @param span span to set active
|
|
4913
|
-
*/
|
|
4914
|
-
function setSpan(context, span) {
|
|
4915
|
-
return context.setValue(SPAN_KEY, span);
|
|
4916
|
-
}
|
|
4917
|
-
/**
|
|
4918
|
-
* Remove current span stored in the context
|
|
4919
|
-
*
|
|
4920
|
-
* @param context context to delete span from
|
|
4921
|
-
*/
|
|
4922
|
-
function deleteSpan(context) {
|
|
4923
|
-
return context.deleteValue(SPAN_KEY);
|
|
4924
|
-
}
|
|
4925
|
-
/**
|
|
4926
|
-
* Wrap span context in a NoopSpan and set as span in a new
|
|
4927
|
-
* context
|
|
4928
|
-
*
|
|
4929
|
-
* @param context context to set active span on
|
|
4930
|
-
* @param spanContext span context to be wrapped
|
|
4931
|
-
*/
|
|
4932
|
-
function setSpanContext(context, spanContext) {
|
|
4933
|
-
return setSpan(context, new NonRecordingSpan(spanContext));
|
|
4934
|
-
}
|
|
4935
|
-
/**
|
|
4936
|
-
* Get the span context of the span if it exists.
|
|
4937
|
-
*
|
|
4938
|
-
* @param context context to get values from
|
|
4939
|
-
*/
|
|
4940
|
-
function getSpanContext(context) {
|
|
4941
|
-
var _a;
|
|
4942
|
-
return (_a = getSpan(context)) === null || _a === void 0 ? void 0 : _a.spanContext();
|
|
4943
|
-
}
|
|
4944
4791
|
const isHex = new Uint8Array([
|
|
4945
4792
|
0,
|
|
4946
4793
|
0,
|
|
@@ -5082,58 +4929,226 @@ function isSpanContextValid(spanContext) {
|
|
|
5082
4929
|
function wrapSpanContext(spanContext) {
|
|
5083
4930
|
return new NonRecordingSpan(spanContext);
|
|
5084
4931
|
}
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
*/
|
|
5089
|
-
var NoopTracer = class {
|
|
5090
|
-
startSpan(name, options, context = contextApi.active()) {
|
|
5091
|
-
if (Boolean(options === null || options === void 0 ? void 0 : options.root)) return new NonRecordingSpan();
|
|
5092
|
-
const parentFromContext = context && getSpanContext(context);
|
|
5093
|
-
if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) return new NonRecordingSpan(parentFromContext);
|
|
5094
|
-
else return new NonRecordingSpan();
|
|
4932
|
+
var NoopContextManager = class {
|
|
4933
|
+
active() {
|
|
4934
|
+
return ROOT_CONTEXT;
|
|
5095
4935
|
}
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
const span = this.startSpan(name, opts, parentContext);
|
|
5112
|
-
const contextWithSpanSet = setSpan(parentContext, span);
|
|
5113
|
-
return contextApi.with(contextWithSpanSet, fn, void 0, span);
|
|
4936
|
+
with(_context, fn, thisArg, ...args) {
|
|
4937
|
+
return fn.call(thisArg, ...args);
|
|
4938
|
+
}
|
|
4939
|
+
bind(_context, target) {
|
|
4940
|
+
return target;
|
|
4941
|
+
}
|
|
4942
|
+
enable() {
|
|
4943
|
+
return this;
|
|
4944
|
+
}
|
|
4945
|
+
disable() {
|
|
4946
|
+
return this;
|
|
4947
|
+
}
|
|
4948
|
+
/** @experimental This API is experimental and may change in minor releases without prior notice. */
|
|
4949
|
+
attach(_context) {
|
|
4950
|
+
return { dispose() {} };
|
|
5114
4951
|
}
|
|
5115
4952
|
};
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
}
|
|
5119
|
-
const NOOP_TRACER = new NoopTracer();
|
|
4953
|
+
const API_NAME$1 = "context";
|
|
4954
|
+
const NOOP_CONTEXT_MANAGER = new NoopContextManager();
|
|
4955
|
+
const NOOP_TOKEN = Object.freeze({ dispose: () => {} });
|
|
5120
4956
|
/**
|
|
5121
|
-
*
|
|
4957
|
+
* Singleton object which represents the entry point to the OpenTelemetry Context API
|
|
5122
4958
|
*
|
|
5123
4959
|
* @since 1.0.0
|
|
5124
4960
|
*/
|
|
5125
|
-
var
|
|
5126
|
-
constructor
|
|
5127
|
-
|
|
5128
|
-
this.
|
|
5129
|
-
this.version = version;
|
|
5130
|
-
this.options = options;
|
|
5131
|
-
}
|
|
5132
|
-
startSpan(name, options, context) {
|
|
5133
|
-
return this._getTracer().startSpan(name, options, context);
|
|
4961
|
+
var ContextAPI = class ContextAPI {
|
|
4962
|
+
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
4963
|
+
constructor() {
|
|
4964
|
+
this._attachUnsupportedWarned = false;
|
|
5134
4965
|
}
|
|
5135
|
-
|
|
5136
|
-
|
|
4966
|
+
/** Get the singleton instance of the Context API */
|
|
4967
|
+
static getInstance() {
|
|
4968
|
+
if (!this._instance) this._instance = new ContextAPI();
|
|
4969
|
+
return this._instance;
|
|
4970
|
+
}
|
|
4971
|
+
/**
|
|
4972
|
+
* Set the current context manager.
|
|
4973
|
+
*
|
|
4974
|
+
* @returns true if the context manager was successfully registered, else false
|
|
4975
|
+
*/
|
|
4976
|
+
setGlobalContextManager(contextManager) {
|
|
4977
|
+
return registerGlobal(API_NAME$1, contextManager, DiagAPI.instance());
|
|
4978
|
+
}
|
|
4979
|
+
/**
|
|
4980
|
+
* Get the currently active context
|
|
4981
|
+
*/
|
|
4982
|
+
active() {
|
|
4983
|
+
return this._getContextManager().active();
|
|
4984
|
+
}
|
|
4985
|
+
/**
|
|
4986
|
+
* Execute a function with an active context
|
|
4987
|
+
*
|
|
4988
|
+
* @param context context to be active during function execution
|
|
4989
|
+
* @param fn function to execute in a context
|
|
4990
|
+
* @param thisArg optional receiver to be used for calling fn
|
|
4991
|
+
* @param args optional arguments forwarded to fn
|
|
4992
|
+
*/
|
|
4993
|
+
with(context, fn, thisArg, ...args) {
|
|
4994
|
+
return this._getContextManager().with(context, fn, thisArg, ...args);
|
|
4995
|
+
}
|
|
4996
|
+
/**
|
|
4997
|
+
* Bind a context to a target function or event emitter
|
|
4998
|
+
*
|
|
4999
|
+
* @param context context to bind to the event emitter or function. Defaults to the currently active context
|
|
5000
|
+
* @param target function or event emitter to bind
|
|
5001
|
+
*/
|
|
5002
|
+
bind(context, target) {
|
|
5003
|
+
return this._getContextManager().bind(context, target);
|
|
5004
|
+
}
|
|
5005
|
+
/**
|
|
5006
|
+
* Imperatively sets `context` as active, returning a {@link ContextManagementToken} whose
|
|
5007
|
+
* {@link ContextManagementToken.dispose} restores the previous context.
|
|
5008
|
+
*
|
|
5009
|
+
* This is a delicate, low-level API - prefer {@link with}/{@link bind}, which
|
|
5010
|
+
* restore context automatically. Use `attach` only to bridge callback
|
|
5011
|
+
* boundaries that `with` cannot wrap. Call `token.dispose()` when the
|
|
5012
|
+
* operation is done.
|
|
5013
|
+
*
|
|
5014
|
+
* **Caveat for async functions:** If called inside an async function before
|
|
5015
|
+
* the first `await`, the context change may leak into the caller's context
|
|
5016
|
+
* and remain active there. Prefer {@link with} for async code.
|
|
5017
|
+
*
|
|
5018
|
+
* Support is best-effort and varies by the active ContextManager (see
|
|
5019
|
+
* {@link ContextManager.attach}); if it does not implement `attach`, this logs
|
|
5020
|
+
* a warning and returns a no-op token.
|
|
5021
|
+
*
|
|
5022
|
+
* @param context The Context to attach
|
|
5023
|
+
* @returns A {@link ContextManagementToken} whose dispose() restores the previous Context
|
|
5024
|
+
* @since 1.10.0
|
|
5025
|
+
* @experimental This API is experimental and may change in minor releases without prior notice.
|
|
5026
|
+
*/
|
|
5027
|
+
attach(context) {
|
|
5028
|
+
const contextManager = this._getContextManager();
|
|
5029
|
+
if (contextManager.attach) return contextManager.attach(context);
|
|
5030
|
+
if (!this._attachUnsupportedWarned) {
|
|
5031
|
+
this._attachUnsupportedWarned = true;
|
|
5032
|
+
DiagAPI.instance().warn("The current ContextManager does not implement attach(). The context will not be attached. Use a ContextManager that supports attach() (e.g. AsyncLocalStorageContextManager) or use with()/bind() instead.");
|
|
5033
|
+
}
|
|
5034
|
+
return NOOP_TOKEN;
|
|
5035
|
+
}
|
|
5036
|
+
_getContextManager() {
|
|
5037
|
+
return getGlobal(API_NAME$1) || NOOP_CONTEXT_MANAGER;
|
|
5038
|
+
}
|
|
5039
|
+
/** Disable and remove the global context manager */
|
|
5040
|
+
disable() {
|
|
5041
|
+
this._getContextManager().disable();
|
|
5042
|
+
unregisterGlobal(API_NAME$1, DiagAPI.instance());
|
|
5043
|
+
}
|
|
5044
|
+
};
|
|
5045
|
+
/**
|
|
5046
|
+
* span key
|
|
5047
|
+
*/
|
|
5048
|
+
const SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
|
|
5049
|
+
/**
|
|
5050
|
+
* Return the span if one exists
|
|
5051
|
+
*
|
|
5052
|
+
* @param context context to get span from
|
|
5053
|
+
*/
|
|
5054
|
+
function getSpan(context) {
|
|
5055
|
+
return context.getValue(SPAN_KEY) || void 0;
|
|
5056
|
+
}
|
|
5057
|
+
/**
|
|
5058
|
+
* Gets the span from the current context, if one exists.
|
|
5059
|
+
*/
|
|
5060
|
+
function getActiveSpan() {
|
|
5061
|
+
return getSpan(ContextAPI.getInstance().active());
|
|
5062
|
+
}
|
|
5063
|
+
/**
|
|
5064
|
+
* Set the span on a context
|
|
5065
|
+
*
|
|
5066
|
+
* @param context context to use as parent
|
|
5067
|
+
* @param span span to set active
|
|
5068
|
+
*/
|
|
5069
|
+
function setSpan(context, span) {
|
|
5070
|
+
return context.setValue(SPAN_KEY, span);
|
|
5071
|
+
}
|
|
5072
|
+
/**
|
|
5073
|
+
* Remove current span stored in the context
|
|
5074
|
+
*
|
|
5075
|
+
* @param context context to delete span from
|
|
5076
|
+
*/
|
|
5077
|
+
function deleteSpan(context) {
|
|
5078
|
+
return context.deleteValue(SPAN_KEY);
|
|
5079
|
+
}
|
|
5080
|
+
/**
|
|
5081
|
+
* Wrap span context in a NoopSpan and set as span in a new
|
|
5082
|
+
* context
|
|
5083
|
+
*
|
|
5084
|
+
* @param context context to set active span on
|
|
5085
|
+
* @param spanContext span context to be wrapped
|
|
5086
|
+
*/
|
|
5087
|
+
function setSpanContext(context, spanContext) {
|
|
5088
|
+
return setSpan(context, new NonRecordingSpan(spanContext));
|
|
5089
|
+
}
|
|
5090
|
+
/**
|
|
5091
|
+
* Get the span context of the span if it exists.
|
|
5092
|
+
*
|
|
5093
|
+
* @param context context to get values from
|
|
5094
|
+
*/
|
|
5095
|
+
function getSpanContext(context) {
|
|
5096
|
+
var _getSpan;
|
|
5097
|
+
return (_getSpan = getSpan(context)) === null || _getSpan === void 0 ? void 0 : _getSpan.spanContext();
|
|
5098
|
+
}
|
|
5099
|
+
const contextApi = ContextAPI.getInstance();
|
|
5100
|
+
/**
|
|
5101
|
+
* No-op implementations of {@link Tracer}.
|
|
5102
|
+
*/
|
|
5103
|
+
var NoopTracer = class {
|
|
5104
|
+
startSpan(name, options, context = contextApi.active()) {
|
|
5105
|
+
if (Boolean(options === null || options === void 0 ? void 0 : options.root)) return new NonRecordingSpan();
|
|
5106
|
+
const parentFromContext = context && getSpanContext(context);
|
|
5107
|
+
if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) return new NonRecordingSpan(parentFromContext);
|
|
5108
|
+
else return new NonRecordingSpan();
|
|
5109
|
+
}
|
|
5110
|
+
startActiveSpan(name, arg2, arg3, arg4) {
|
|
5111
|
+
var _ctx;
|
|
5112
|
+
let opts;
|
|
5113
|
+
let ctx;
|
|
5114
|
+
let fn;
|
|
5115
|
+
if (arguments.length < 2) return;
|
|
5116
|
+
else if (arguments.length === 2) fn = arg2;
|
|
5117
|
+
else if (arguments.length === 3) {
|
|
5118
|
+
opts = arg2;
|
|
5119
|
+
fn = arg3;
|
|
5120
|
+
} else {
|
|
5121
|
+
opts = arg2;
|
|
5122
|
+
ctx = arg3;
|
|
5123
|
+
fn = arg4;
|
|
5124
|
+
}
|
|
5125
|
+
const parentContext = (_ctx = ctx) !== null && _ctx !== void 0 ? _ctx : contextApi.active();
|
|
5126
|
+
const span = this.startSpan(name, opts, parentContext);
|
|
5127
|
+
const contextWithSpanSet = setSpan(parentContext, span);
|
|
5128
|
+
return contextApi.with(contextWithSpanSet, fn, void 0, span);
|
|
5129
|
+
}
|
|
5130
|
+
};
|
|
5131
|
+
function isSpanContext(spanContext) {
|
|
5132
|
+
return spanContext !== null && typeof spanContext === "object" && "spanId" in spanContext && typeof spanContext["spanId"] === "string" && "traceId" in spanContext && typeof spanContext["traceId"] === "string" && "traceFlags" in spanContext && typeof spanContext["traceFlags"] === "number";
|
|
5133
|
+
}
|
|
5134
|
+
const NOOP_TRACER = new NoopTracer();
|
|
5135
|
+
/**
|
|
5136
|
+
* Proxy tracer provided by the proxy tracer provider
|
|
5137
|
+
*
|
|
5138
|
+
* @since 1.0.0
|
|
5139
|
+
*/
|
|
5140
|
+
var ProxyTracer = class {
|
|
5141
|
+
constructor(provider, name, version, options) {
|
|
5142
|
+
this._provider = provider;
|
|
5143
|
+
this.name = name;
|
|
5144
|
+
this.version = version;
|
|
5145
|
+
this.options = options;
|
|
5146
|
+
}
|
|
5147
|
+
startSpan(name, options, context) {
|
|
5148
|
+
return this._getTracer().startSpan(name, options, context);
|
|
5149
|
+
}
|
|
5150
|
+
startActiveSpan(_name, _options, _context, _fn) {
|
|
5151
|
+
const tracer = this._getTracer();
|
|
5137
5152
|
return Reflect.apply(tracer.startActiveSpan, tracer, arguments);
|
|
5138
5153
|
}
|
|
5139
5154
|
/**
|
|
@@ -5176,12 +5191,12 @@ var ProxyTracerProvider = class {
|
|
|
5176
5191
|
* Get a {@link ProxyTracer}
|
|
5177
5192
|
*/
|
|
5178
5193
|
getTracer(name, version, options) {
|
|
5179
|
-
var
|
|
5180
|
-
return (
|
|
5194
|
+
var _this$getDelegateTrac;
|
|
5195
|
+
return (_this$getDelegateTrac = this.getDelegateTracer(name, version, options)) !== null && _this$getDelegateTrac !== void 0 ? _this$getDelegateTrac : new ProxyTracer(this, name, version, options);
|
|
5181
5196
|
}
|
|
5182
5197
|
getDelegate() {
|
|
5183
|
-
var
|
|
5184
|
-
return (
|
|
5198
|
+
var _this$_delegate;
|
|
5199
|
+
return (_this$_delegate = this._delegate) !== null && _this$_delegate !== void 0 ? _this$_delegate : NOOP_TRACER_PROVIDER;
|
|
5185
5200
|
}
|
|
5186
5201
|
/**
|
|
5187
5202
|
* Set the delegate tracer provider
|
|
@@ -5190,31 +5205,10 @@ var ProxyTracerProvider = class {
|
|
|
5190
5205
|
this._delegate = delegate;
|
|
5191
5206
|
}
|
|
5192
5207
|
getDelegateTracer(name, version, options) {
|
|
5193
|
-
var
|
|
5194
|
-
return (
|
|
5208
|
+
var _this$_delegate2;
|
|
5209
|
+
return (_this$_delegate2 = this._delegate) === null || _this$_delegate2 === void 0 ? void 0 : _this$_delegate2.getTracer(name, version, options);
|
|
5195
5210
|
}
|
|
5196
5211
|
};
|
|
5197
|
-
/**
|
|
5198
|
-
* An enumeration of status codes.
|
|
5199
|
-
*
|
|
5200
|
-
* @since 1.0.0
|
|
5201
|
-
*/
|
|
5202
|
-
var SpanStatusCode;
|
|
5203
|
-
(function(SpanStatusCode) {
|
|
5204
|
-
/**
|
|
5205
|
-
* The default status.
|
|
5206
|
-
*/
|
|
5207
|
-
SpanStatusCode[SpanStatusCode["UNSET"] = 0] = "UNSET";
|
|
5208
|
-
/**
|
|
5209
|
-
* The operation has been validated by an Application developer or
|
|
5210
|
-
* Operator to have completed successfully.
|
|
5211
|
-
*/
|
|
5212
|
-
SpanStatusCode[SpanStatusCode["OK"] = 1] = "OK";
|
|
5213
|
-
/**
|
|
5214
|
-
* The operation contains an error.
|
|
5215
|
-
*/
|
|
5216
|
-
SpanStatusCode[SpanStatusCode["ERROR"] = 2] = "ERROR";
|
|
5217
|
-
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
5218
5212
|
ContextAPI.getInstance();
|
|
5219
5213
|
const API_NAME = "trace";
|
|
5220
5214
|
(class TraceAPI {
|
|
@@ -6223,6 +6217,7 @@ function processUIMessageStream$1({ stream, messageMetadataSchema, dataPartSchem
|
|
|
6223
6217
|
const anyPart = part;
|
|
6224
6218
|
if (part != null) {
|
|
6225
6219
|
part.state = options.state;
|
|
6220
|
+
anyPart.type = `tool-${options.toolName}`;
|
|
6226
6221
|
anyPart.input = anyOptions.input;
|
|
6227
6222
|
anyPart.output = anyOptions.output;
|
|
6228
6223
|
anyPart.errorText = anyOptions.errorText;
|
|
@@ -6926,8 +6921,7 @@ var doWrap = ({ model, middleware: { transformParams, wrapGenerate, wrapStream,
|
|
|
6926
6921
|
}
|
|
6927
6922
|
};
|
|
6928
6923
|
};
|
|
6929
|
-
|
|
6930
|
-
//#region ../../packages/_vendored/ai_v7/dist/dist-BLdjeX1i.js
|
|
6924
|
+
// ../../packages/_vendored/ai_v7/dist/dist-5fMURLh0.js
|
|
6931
6925
|
/**
|
|
6932
6926
|
* Symbol used for identifying AI SDK Error instances.
|
|
6933
6927
|
* Enables checking if an error is an instance of AISDKError across package versions.
|
|
@@ -8203,8 +8197,7 @@ async function safeParseJSON({ text, schema }) {
|
|
|
8203
8197
|
}
|
|
8204
8198
|
}
|
|
8205
8199
|
new TextDecoder();
|
|
8206
|
-
|
|
8207
|
-
//#region ../../packages/_vendored/ai_v7/dist/index.js
|
|
8200
|
+
// ../../packages/_vendored/ai_v7/dist/index.js
|
|
8208
8201
|
const name$5 = "AI_UIMessageStreamError";
|
|
8209
8202
|
const marker$5 = `vercel.ai.error.${name$5}`;
|
|
8210
8203
|
const symbol$5 = Symbol.for(marker$5);
|
|
@@ -8266,309 +8259,6 @@ function mergeObjects(base, overrides) {
|
|
|
8266
8259
|
}
|
|
8267
8260
|
return result;
|
|
8268
8261
|
}
|
|
8269
|
-
const z$1 = {
|
|
8270
|
-
array,
|
|
8271
|
-
boolean,
|
|
8272
|
-
custom,
|
|
8273
|
-
discriminatedUnion,
|
|
8274
|
-
enum: enum$1,
|
|
8275
|
-
instanceof: instanceof$1,
|
|
8276
|
-
lazy,
|
|
8277
|
-
literal,
|
|
8278
|
-
looseObject,
|
|
8279
|
-
never,
|
|
8280
|
-
null: null$1,
|
|
8281
|
-
number,
|
|
8282
|
-
object,
|
|
8283
|
-
record,
|
|
8284
|
-
string,
|
|
8285
|
-
union,
|
|
8286
|
-
unknown
|
|
8287
|
-
};
|
|
8288
|
-
const jsonValueSchema = z$1.lazy(() => z$1.union([
|
|
8289
|
-
z$1.null(),
|
|
8290
|
-
z$1.string(),
|
|
8291
|
-
z$1.number(),
|
|
8292
|
-
z$1.boolean(),
|
|
8293
|
-
z$1.record(z$1.string(), jsonValueSchema.optional()),
|
|
8294
|
-
z$1.array(jsonValueSchema)
|
|
8295
|
-
]));
|
|
8296
|
-
const providerMetadataSchema = z$1.record(z$1.string(), z$1.record(z$1.string(), jsonValueSchema.optional()));
|
|
8297
|
-
const fileInlineDataSchema = z$1.union([
|
|
8298
|
-
z$1.string(),
|
|
8299
|
-
z$1.instanceof(Uint8Array),
|
|
8300
|
-
z$1.instanceof(ArrayBuffer),
|
|
8301
|
-
z$1.custom(isBuffer, { message: "Must be a Buffer" })
|
|
8302
|
-
]);
|
|
8303
|
-
const providerReferenceSchema$1 = z$1.record(z$1.string(), z$1.string());
|
|
8304
|
-
/**
|
|
8305
|
-
* @internal
|
|
8306
|
-
*/
|
|
8307
|
-
const textPartSchema = z$1.object({
|
|
8308
|
-
type: z$1.literal("text"),
|
|
8309
|
-
text: z$1.string(),
|
|
8310
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8311
|
-
});
|
|
8312
|
-
/**
|
|
8313
|
-
* @internal
|
|
8314
|
-
* @deprecated Use `filePartSchema` with `mediaType: 'image'` instead:
|
|
8315
|
-
* `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
|
|
8316
|
-
*/
|
|
8317
|
-
const imagePartSchema = z$1.object({
|
|
8318
|
-
type: z$1.literal("image"),
|
|
8319
|
-
image: z$1.union([
|
|
8320
|
-
fileInlineDataSchema,
|
|
8321
|
-
z$1.instanceof(URL),
|
|
8322
|
-
providerReferenceSchema$1
|
|
8323
|
-
]),
|
|
8324
|
-
mediaType: z$1.string().optional(),
|
|
8325
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8326
|
-
});
|
|
8327
|
-
const taggedFileDataSchema = z$1.discriminatedUnion("type", [
|
|
8328
|
-
z$1.object({
|
|
8329
|
-
type: z$1.literal("data"),
|
|
8330
|
-
data: fileInlineDataSchema
|
|
8331
|
-
}),
|
|
8332
|
-
z$1.object({
|
|
8333
|
-
type: z$1.literal("url"),
|
|
8334
|
-
url: z$1.instanceof(URL)
|
|
8335
|
-
}),
|
|
8336
|
-
z$1.object({
|
|
8337
|
-
type: z$1.literal("reference"),
|
|
8338
|
-
reference: providerReferenceSchema$1
|
|
8339
|
-
}),
|
|
8340
|
-
z$1.object({
|
|
8341
|
-
type: z$1.literal("text"),
|
|
8342
|
-
text: z$1.string()
|
|
8343
|
-
})
|
|
8344
|
-
]);
|
|
8345
|
-
const taggedReasoningFileDataSchema = z$1.discriminatedUnion("type", [z$1.object({
|
|
8346
|
-
type: z$1.literal("data"),
|
|
8347
|
-
data: fileInlineDataSchema
|
|
8348
|
-
}), z$1.object({
|
|
8349
|
-
type: z$1.literal("url"),
|
|
8350
|
-
url: z$1.instanceof(URL)
|
|
8351
|
-
})]);
|
|
8352
|
-
/**
|
|
8353
|
-
* @internal
|
|
8354
|
-
*/
|
|
8355
|
-
const filePartSchema = z$1.object({
|
|
8356
|
-
type: z$1.literal("file"),
|
|
8357
|
-
data: z$1.union([
|
|
8358
|
-
taggedFileDataSchema,
|
|
8359
|
-
fileInlineDataSchema,
|
|
8360
|
-
z$1.instanceof(URL),
|
|
8361
|
-
providerReferenceSchema$1
|
|
8362
|
-
]),
|
|
8363
|
-
filename: z$1.string().optional(),
|
|
8364
|
-
mediaType: z$1.string(),
|
|
8365
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8366
|
-
});
|
|
8367
|
-
/**
|
|
8368
|
-
* @internal
|
|
8369
|
-
*/
|
|
8370
|
-
const reasoningPartSchema = z$1.object({
|
|
8371
|
-
type: z$1.literal("reasoning"),
|
|
8372
|
-
text: z$1.string(),
|
|
8373
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8374
|
-
});
|
|
8375
|
-
/**
|
|
8376
|
-
* @internal
|
|
8377
|
-
*/
|
|
8378
|
-
const customPartSchema = z$1.object({
|
|
8379
|
-
type: z$1.literal("custom"),
|
|
8380
|
-
kind: z$1.string().transform((value) => value),
|
|
8381
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8382
|
-
});
|
|
8383
|
-
/**
|
|
8384
|
-
* @internal
|
|
8385
|
-
*/
|
|
8386
|
-
const reasoningFilePartSchema = z$1.object({
|
|
8387
|
-
type: z$1.literal("reasoning-file"),
|
|
8388
|
-
data: z$1.union([
|
|
8389
|
-
taggedReasoningFileDataSchema,
|
|
8390
|
-
fileInlineDataSchema,
|
|
8391
|
-
z$1.instanceof(URL)
|
|
8392
|
-
]),
|
|
8393
|
-
mediaType: z$1.string(),
|
|
8394
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8395
|
-
});
|
|
8396
|
-
/**
|
|
8397
|
-
* @internal
|
|
8398
|
-
*/
|
|
8399
|
-
const toolCallPartSchema = z$1.object({
|
|
8400
|
-
type: z$1.literal("tool-call"),
|
|
8401
|
-
toolCallId: z$1.string(),
|
|
8402
|
-
toolName: z$1.string(),
|
|
8403
|
-
input: z$1.unknown(),
|
|
8404
|
-
providerOptions: providerMetadataSchema.optional(),
|
|
8405
|
-
providerExecuted: z$1.boolean().optional()
|
|
8406
|
-
});
|
|
8407
|
-
/**
|
|
8408
|
-
* @internal
|
|
8409
|
-
*/
|
|
8410
|
-
const outputSchema = z$1.discriminatedUnion("type", [
|
|
8411
|
-
z$1.object({
|
|
8412
|
-
type: z$1.literal("text"),
|
|
8413
|
-
value: z$1.string(),
|
|
8414
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8415
|
-
}),
|
|
8416
|
-
z$1.object({
|
|
8417
|
-
type: z$1.literal("json"),
|
|
8418
|
-
value: jsonValueSchema,
|
|
8419
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8420
|
-
}),
|
|
8421
|
-
z$1.object({
|
|
8422
|
-
type: z$1.literal("execution-denied"),
|
|
8423
|
-
reason: z$1.string().optional(),
|
|
8424
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8425
|
-
}),
|
|
8426
|
-
z$1.object({
|
|
8427
|
-
type: z$1.literal("error-text"),
|
|
8428
|
-
value: z$1.string(),
|
|
8429
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8430
|
-
}),
|
|
8431
|
-
z$1.object({
|
|
8432
|
-
type: z$1.literal("error-json"),
|
|
8433
|
-
value: jsonValueSchema,
|
|
8434
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8435
|
-
}),
|
|
8436
|
-
z$1.object({
|
|
8437
|
-
type: z$1.literal("content"),
|
|
8438
|
-
value: z$1.array(z$1.union([
|
|
8439
|
-
z$1.object({
|
|
8440
|
-
type: z$1.literal("text"),
|
|
8441
|
-
text: z$1.string(),
|
|
8442
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8443
|
-
}),
|
|
8444
|
-
z$1.object({
|
|
8445
|
-
type: z$1.literal("file"),
|
|
8446
|
-
data: taggedFileDataSchema,
|
|
8447
|
-
mediaType: z$1.string(),
|
|
8448
|
-
filename: z$1.string().optional(),
|
|
8449
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8450
|
-
}),
|
|
8451
|
-
z$1.object({
|
|
8452
|
-
type: z$1.literal("file-data"),
|
|
8453
|
-
data: z$1.string(),
|
|
8454
|
-
mediaType: z$1.string(),
|
|
8455
|
-
filename: z$1.string().optional(),
|
|
8456
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8457
|
-
}),
|
|
8458
|
-
z$1.object({
|
|
8459
|
-
type: z$1.literal("file-url"),
|
|
8460
|
-
url: z$1.string(),
|
|
8461
|
-
mediaType: z$1.string().optional(),
|
|
8462
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8463
|
-
}),
|
|
8464
|
-
z$1.object({
|
|
8465
|
-
type: z$1.literal("file-id"),
|
|
8466
|
-
fileId: z$1.union([z$1.string(), z$1.record(z$1.string(), z$1.string())]),
|
|
8467
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8468
|
-
}),
|
|
8469
|
-
z$1.object({
|
|
8470
|
-
type: z$1.literal("file-reference"),
|
|
8471
|
-
providerReference: z$1.record(z$1.string(), z$1.string()),
|
|
8472
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8473
|
-
}),
|
|
8474
|
-
z$1.object({
|
|
8475
|
-
type: z$1.literal("image-data"),
|
|
8476
|
-
data: z$1.string(),
|
|
8477
|
-
mediaType: z$1.string(),
|
|
8478
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8479
|
-
}),
|
|
8480
|
-
z$1.object({
|
|
8481
|
-
type: z$1.literal("image-url"),
|
|
8482
|
-
url: z$1.string(),
|
|
8483
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8484
|
-
}),
|
|
8485
|
-
z$1.object({
|
|
8486
|
-
type: z$1.literal("image-file-id"),
|
|
8487
|
-
fileId: z$1.union([z$1.string(), z$1.record(z$1.string(), z$1.string())]),
|
|
8488
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8489
|
-
}),
|
|
8490
|
-
z$1.object({
|
|
8491
|
-
type: z$1.literal("image-file-reference"),
|
|
8492
|
-
providerReference: z$1.record(z$1.string(), z$1.string()),
|
|
8493
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8494
|
-
}),
|
|
8495
|
-
z$1.object({
|
|
8496
|
-
type: z$1.literal("custom"),
|
|
8497
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8498
|
-
})
|
|
8499
|
-
]))
|
|
8500
|
-
})
|
|
8501
|
-
]);
|
|
8502
|
-
/**
|
|
8503
|
-
* @internal
|
|
8504
|
-
*/
|
|
8505
|
-
const toolResultPartSchema = z$1.object({
|
|
8506
|
-
type: z$1.literal("tool-result"),
|
|
8507
|
-
toolCallId: z$1.string(),
|
|
8508
|
-
toolName: z$1.string(),
|
|
8509
|
-
output: outputSchema,
|
|
8510
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8511
|
-
});
|
|
8512
|
-
/**
|
|
8513
|
-
* @internal
|
|
8514
|
-
*/
|
|
8515
|
-
const toolApprovalRequestSchema = z$1.object({
|
|
8516
|
-
type: z$1.literal("tool-approval-request"),
|
|
8517
|
-
approvalId: z$1.string(),
|
|
8518
|
-
toolCallId: z$1.string(),
|
|
8519
|
-
reason: z$1.string().optional(),
|
|
8520
|
-
isAutomatic: z$1.boolean().optional(),
|
|
8521
|
-
signature: z$1.string().optional(),
|
|
8522
|
-
inputSchemaInput: z$1.unknown().optional()
|
|
8523
|
-
});
|
|
8524
|
-
/**
|
|
8525
|
-
* @internal
|
|
8526
|
-
*/
|
|
8527
|
-
const toolApprovalResponseSchema = z$1.object({
|
|
8528
|
-
type: z$1.literal("tool-approval-response"),
|
|
8529
|
-
approvalId: z$1.string(),
|
|
8530
|
-
approved: z$1.boolean(),
|
|
8531
|
-
reason: z$1.string().optional()
|
|
8532
|
-
});
|
|
8533
|
-
const systemModelMessageSchema = z$1.object({
|
|
8534
|
-
role: z$1.literal("system"),
|
|
8535
|
-
content: z$1.string(),
|
|
8536
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8537
|
-
});
|
|
8538
|
-
const userModelMessageSchema = z$1.object({
|
|
8539
|
-
role: z$1.literal("user"),
|
|
8540
|
-
content: z$1.union([z$1.string(), z$1.array(z$1.union([
|
|
8541
|
-
textPartSchema,
|
|
8542
|
-
imagePartSchema,
|
|
8543
|
-
filePartSchema
|
|
8544
|
-
]))]),
|
|
8545
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8546
|
-
});
|
|
8547
|
-
const assistantModelMessageSchema = z$1.object({
|
|
8548
|
-
role: z$1.literal("assistant"),
|
|
8549
|
-
content: z$1.union([z$1.string(), z$1.array(z$1.union([
|
|
8550
|
-
textPartSchema,
|
|
8551
|
-
customPartSchema,
|
|
8552
|
-
filePartSchema,
|
|
8553
|
-
reasoningPartSchema,
|
|
8554
|
-
reasoningFilePartSchema,
|
|
8555
|
-
toolCallPartSchema,
|
|
8556
|
-
toolResultPartSchema,
|
|
8557
|
-
toolApprovalRequestSchema
|
|
8558
|
-
]))]),
|
|
8559
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8560
|
-
});
|
|
8561
|
-
const toolModelMessageSchema = z$1.object({
|
|
8562
|
-
role: z$1.literal("tool"),
|
|
8563
|
-
content: z$1.array(z$1.union([toolResultPartSchema, toolApprovalResponseSchema])),
|
|
8564
|
-
providerOptions: providerMetadataSchema.optional()
|
|
8565
|
-
});
|
|
8566
|
-
z$1.union([
|
|
8567
|
-
systemModelMessageSchema,
|
|
8568
|
-
userModelMessageSchema,
|
|
8569
|
-
assistantModelMessageSchema,
|
|
8570
|
-
toolModelMessageSchema
|
|
8571
|
-
]);
|
|
8572
8262
|
function fixJson(input) {
|
|
8573
8263
|
const stack = ["ROOT"];
|
|
8574
8264
|
let lastValidIndex = -1;
|
|
@@ -8840,6 +8530,10 @@ async function parsePartialJson(jsonText) {
|
|
|
8840
8530
|
state: "failed-parse"
|
|
8841
8531
|
};
|
|
8842
8532
|
}
|
|
8533
|
+
createIdGenerator({
|
|
8534
|
+
prefix: "steer",
|
|
8535
|
+
size: 24
|
|
8536
|
+
});
|
|
8843
8537
|
new TextEncoder();
|
|
8844
8538
|
new TextEncoder();
|
|
8845
8539
|
createIdGenerator({
|
|
@@ -8954,32 +8648,60 @@ function createUIMessageStreamResponse({ status, statusText, headers, stream, ke
|
|
|
8954
8648
|
headers: prepareHeaders(headers, UI_MESSAGE_STREAM_HEADERS)
|
|
8955
8649
|
});
|
|
8956
8650
|
}
|
|
8957
|
-
z$1
|
|
8958
|
-
|
|
8959
|
-
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
8964
|
-
|
|
8965
|
-
|
|
8966
|
-
|
|
8967
|
-
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
|
|
8971
|
-
|
|
8972
|
-
|
|
8973
|
-
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
8978
|
-
z$1.
|
|
8979
|
-
|
|
8980
|
-
|
|
8981
|
-
|
|
8982
|
-
|
|
8651
|
+
const z$1 = {
|
|
8652
|
+
array,
|
|
8653
|
+
boolean,
|
|
8654
|
+
custom,
|
|
8655
|
+
discriminatedUnion,
|
|
8656
|
+
enum: enum$1,
|
|
8657
|
+
instanceof: instanceof$1,
|
|
8658
|
+
lazy,
|
|
8659
|
+
literal,
|
|
8660
|
+
looseObject,
|
|
8661
|
+
never,
|
|
8662
|
+
null: null$1,
|
|
8663
|
+
number,
|
|
8664
|
+
object,
|
|
8665
|
+
record,
|
|
8666
|
+
string,
|
|
8667
|
+
union,
|
|
8668
|
+
unknown
|
|
8669
|
+
};
|
|
8670
|
+
const jsonValueSchema = z$1.lazy(() => z$1.union([
|
|
8671
|
+
z$1.null(),
|
|
8672
|
+
z$1.string(),
|
|
8673
|
+
z$1.number(),
|
|
8674
|
+
z$1.boolean(),
|
|
8675
|
+
z$1.record(z$1.string(), jsonValueSchema.optional()),
|
|
8676
|
+
z$1.array(jsonValueSchema)
|
|
8677
|
+
]));
|
|
8678
|
+
const providerMetadataSchema = z$1.record(z$1.string(), z$1.record(z$1.string(), jsonValueSchema.optional()));
|
|
8679
|
+
z$1.object({
|
|
8680
|
+
source: z$1.discriminatedUnion("sourceType", [z$1.object({
|
|
8681
|
+
type: z$1.literal("source"),
|
|
8682
|
+
sourceType: z$1.literal("url"),
|
|
8683
|
+
id: z$1.string(),
|
|
8684
|
+
url: z$1.string(),
|
|
8685
|
+
title: z$1.string().optional(),
|
|
8686
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
8687
|
+
}), z$1.object({
|
|
8688
|
+
type: z$1.literal("source"),
|
|
8689
|
+
sourceType: z$1.literal("document"),
|
|
8690
|
+
id: z$1.string(),
|
|
8691
|
+
mediaType: z$1.string(),
|
|
8692
|
+
title: z$1.string(),
|
|
8693
|
+
filename: z$1.string().optional(),
|
|
8694
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
8695
|
+
})]),
|
|
8696
|
+
startIndex: z$1.number().int().nonnegative().optional(),
|
|
8697
|
+
endIndex: z$1.number().int().nonnegative().optional(),
|
|
8698
|
+
citedText: z$1.string().optional()
|
|
8699
|
+
});
|
|
8700
|
+
z$1.record(z$1.string(), jsonValueSchema.optional());
|
|
8701
|
+
function isDataUIMessageChunk(chunk) {
|
|
8702
|
+
return chunk.type.startsWith("data-");
|
|
8703
|
+
}
|
|
8704
|
+
/**
|
|
8983
8705
|
* Creates a string-keyed map without an object prototype.
|
|
8984
8706
|
*
|
|
8985
8707
|
* Use this for lookup tables keyed by IDs or names that may come from outside
|
|
@@ -9103,6 +8825,7 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
|
|
|
9103
8825
|
const anyPart = part;
|
|
9104
8826
|
if (part != null) {
|
|
9105
8827
|
part.state = options.state;
|
|
8828
|
+
anyPart.type = `tool-${options.toolName}`;
|
|
9106
8829
|
anyPart.input = anyOptions.input;
|
|
9107
8830
|
anyPart.output = anyOptions.output;
|
|
9108
8831
|
anyPart.errorText = anyOptions.errorText;
|
|
@@ -9702,152 +9425,427 @@ createIdGenerator({
|
|
|
9702
9425
|
size: 24
|
|
9703
9426
|
});
|
|
9704
9427
|
/**
|
|
9705
|
-
* Creates a UI message stream that can be used to send messages to the client.
|
|
9706
|
-
*
|
|
9707
|
-
* @param options.execute - A function that is called with a writer to write UI message chunks to the stream.
|
|
9708
|
-
* @param options.onError - A function that extracts an error message from an error. Defaults to `() => 'An error occurred.'` so server-side error details are not leaked to the client; supply your own to surface richer messages.
|
|
9709
|
-
* @param options.originalMessages - The original messages. If provided, persistence mode is assumed
|
|
9710
|
-
* and a message ID is provided for the response message.
|
|
9711
|
-
* @param options.onStepEnd - A callback that is called when each step ends. Useful for persisting intermediate messages.
|
|
9712
|
-
* @param options.onStepFinish - Deprecated alias for `onStepEnd`.
|
|
9713
|
-
* @param options.onEnd - A callback that is called when the stream ends.
|
|
9714
|
-
* @param options.onFinish - Deprecated alias for `onEnd`.
|
|
9715
|
-
* @param options.generateId - A function that generates a unique ID. Defaults to the built-in ID generator.
|
|
9716
|
-
*
|
|
9717
|
-
* @returns A `ReadableStream` of UI message chunks.
|
|
9428
|
+
* Creates a UI message stream that can be used to send messages to the client.
|
|
9429
|
+
*
|
|
9430
|
+
* @param options.execute - A function that is called with a writer to write UI message chunks to the stream.
|
|
9431
|
+
* @param options.onError - A function that extracts an error message from an error. Defaults to `() => 'An error occurred.'` so server-side error details are not leaked to the client; supply your own to surface richer messages.
|
|
9432
|
+
* @param options.originalMessages - The original messages. If provided, persistence mode is assumed
|
|
9433
|
+
* and a message ID is provided for the response message.
|
|
9434
|
+
* @param options.onStepEnd - A callback that is called when each step ends. Useful for persisting intermediate messages.
|
|
9435
|
+
* @param options.onStepFinish - Deprecated alias for `onStepEnd`.
|
|
9436
|
+
* @param options.onEnd - A callback that is called when the stream ends.
|
|
9437
|
+
* @param options.onFinish - Deprecated alias for `onEnd`.
|
|
9438
|
+
* @param options.generateId - A function that generates a unique ID. Defaults to the built-in ID generator.
|
|
9439
|
+
*
|
|
9440
|
+
* @returns A `ReadableStream` of UI message chunks.
|
|
9441
|
+
*/
|
|
9442
|
+
function createUIMessageStream({ execute, onError = () => "An error occurred.", originalMessages, onStepEnd, onStepFinish, onEnd, onFinish, generateId: generateId$2 = generateId }) {
|
|
9443
|
+
let controller;
|
|
9444
|
+
const ongoingStreamPromises = [];
|
|
9445
|
+
const activeReaders = /* @__PURE__ */ new Set();
|
|
9446
|
+
let isCancelled = false;
|
|
9447
|
+
let cancelReason;
|
|
9448
|
+
let outcome = { status: "unknown" };
|
|
9449
|
+
const stream = new ReadableStream({
|
|
9450
|
+
start(controllerArg) {
|
|
9451
|
+
controller = controllerArg;
|
|
9452
|
+
},
|
|
9453
|
+
async cancel(reason) {
|
|
9454
|
+
isCancelled = true;
|
|
9455
|
+
cancelReason = reason;
|
|
9456
|
+
await Promise.all(Array.from(activeReaders, (reader) => reader.cancel(reason)));
|
|
9457
|
+
}
|
|
9458
|
+
});
|
|
9459
|
+
function safeEnqueue(data) {
|
|
9460
|
+
try {
|
|
9461
|
+
controller.enqueue(data);
|
|
9462
|
+
} catch {}
|
|
9463
|
+
}
|
|
9464
|
+
function setOutcome(newOutcome) {
|
|
9465
|
+
if (outcome.status === "unknown" && newOutcome.status !== "unknown") outcome = newOutcome;
|
|
9466
|
+
}
|
|
9467
|
+
function failOutcome(error) {
|
|
9468
|
+
outcome = {
|
|
9469
|
+
status: "failed",
|
|
9470
|
+
error
|
|
9471
|
+
};
|
|
9472
|
+
}
|
|
9473
|
+
function safeError(error) {
|
|
9474
|
+
try {
|
|
9475
|
+
controller.error(error);
|
|
9476
|
+
} catch {}
|
|
9477
|
+
}
|
|
9478
|
+
function handleError(error) {
|
|
9479
|
+
failOutcome(error);
|
|
9480
|
+
let errorText;
|
|
9481
|
+
try {
|
|
9482
|
+
errorText = onError(error);
|
|
9483
|
+
} catch (onErrorError) {
|
|
9484
|
+
failOutcome(onErrorError);
|
|
9485
|
+
safeError(onErrorError);
|
|
9486
|
+
return;
|
|
9487
|
+
}
|
|
9488
|
+
safeEnqueue({
|
|
9489
|
+
type: "error",
|
|
9490
|
+
errorText
|
|
9491
|
+
});
|
|
9492
|
+
}
|
|
9493
|
+
try {
|
|
9494
|
+
const result = execute({ writer: {
|
|
9495
|
+
write(part) {
|
|
9496
|
+
safeEnqueue(part);
|
|
9497
|
+
},
|
|
9498
|
+
merge(streamArg) {
|
|
9499
|
+
if (isCancelled) {
|
|
9500
|
+
streamArg.cancel(cancelReason).catch(() => {});
|
|
9501
|
+
return;
|
|
9502
|
+
}
|
|
9503
|
+
ongoingStreamPromises.push((async () => {
|
|
9504
|
+
const reader = streamArg.getReader();
|
|
9505
|
+
activeReaders.add(reader);
|
|
9506
|
+
try {
|
|
9507
|
+
while (true) {
|
|
9508
|
+
const { done, value } = await reader.read();
|
|
9509
|
+
if (done) break;
|
|
9510
|
+
safeEnqueue(value);
|
|
9511
|
+
}
|
|
9512
|
+
} finally {
|
|
9513
|
+
activeReaders.delete(reader);
|
|
9514
|
+
reader.releaseLock();
|
|
9515
|
+
}
|
|
9516
|
+
})().catch((error) => {
|
|
9517
|
+
handleError(error);
|
|
9518
|
+
}));
|
|
9519
|
+
},
|
|
9520
|
+
setOutcome,
|
|
9521
|
+
onError
|
|
9522
|
+
} });
|
|
9523
|
+
if (result) ongoingStreamPromises.push(result.catch((error) => {
|
|
9524
|
+
handleError(error);
|
|
9525
|
+
}));
|
|
9526
|
+
} catch (error) {
|
|
9527
|
+
handleError(error);
|
|
9528
|
+
}
|
|
9529
|
+
(async () => {
|
|
9530
|
+
while (ongoingStreamPromises.length > 0) await ongoingStreamPromises.shift();
|
|
9531
|
+
})().finally(() => {
|
|
9532
|
+
try {
|
|
9533
|
+
controller.close();
|
|
9534
|
+
} catch {}
|
|
9535
|
+
});
|
|
9536
|
+
return handleUIMessageStreamFinish({
|
|
9537
|
+
stream,
|
|
9538
|
+
messageId: generateId$2(),
|
|
9539
|
+
originalMessages,
|
|
9540
|
+
onStepEnd: onStepEnd ?? onStepFinish,
|
|
9541
|
+
onEnd: onEnd ?? onFinish,
|
|
9542
|
+
onError,
|
|
9543
|
+
getOutcome: () => outcome
|
|
9544
|
+
});
|
|
9545
|
+
}
|
|
9546
|
+
z$1.record(z$1.string(), jsonValueSchema.optional());
|
|
9547
|
+
z$1.record(z$1.string(), z$1.string());
|
|
9548
|
+
createIdGenerator({
|
|
9549
|
+
prefix: "call",
|
|
9550
|
+
size: 24
|
|
9551
|
+
});
|
|
9552
|
+
createIdGenerator({
|
|
9553
|
+
prefix: "call",
|
|
9554
|
+
size: 24
|
|
9555
|
+
});
|
|
9556
|
+
new TextEncoder();
|
|
9557
|
+
createIdGenerator({
|
|
9558
|
+
prefix: "call",
|
|
9559
|
+
size: 24
|
|
9560
|
+
});
|
|
9561
|
+
createIdGenerator({
|
|
9562
|
+
prefix: "aiobj",
|
|
9563
|
+
size: 24
|
|
9564
|
+
});
|
|
9565
|
+
const { atob: atob$1 } = globalThis;
|
|
9566
|
+
createIdGenerator({
|
|
9567
|
+
prefix: "aiobj",
|
|
9568
|
+
size: 24
|
|
9569
|
+
});
|
|
9570
|
+
createIdGenerator({
|
|
9571
|
+
prefix: "call",
|
|
9572
|
+
size: 24
|
|
9573
|
+
});
|
|
9574
|
+
const fileInlineDataSchema = z$1.union([
|
|
9575
|
+
z$1.string(),
|
|
9576
|
+
z$1.instanceof(Uint8Array),
|
|
9577
|
+
z$1.instanceof(ArrayBuffer),
|
|
9578
|
+
z$1.custom(isBuffer, { message: "Must be a Buffer" })
|
|
9579
|
+
]);
|
|
9580
|
+
const providerReferenceSchema = z$1.record(z$1.string(), z$1.string());
|
|
9581
|
+
/**
|
|
9582
|
+
* @internal
|
|
9583
|
+
*/
|
|
9584
|
+
const textPartSchema = z$1.object({
|
|
9585
|
+
type: z$1.literal("text"),
|
|
9586
|
+
text: z$1.string(),
|
|
9587
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9588
|
+
});
|
|
9589
|
+
/**
|
|
9590
|
+
* @internal
|
|
9591
|
+
* @deprecated Use `filePartSchema` with `mediaType: 'image'` instead:
|
|
9592
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
|
|
9593
|
+
*/
|
|
9594
|
+
const imagePartSchema = z$1.object({
|
|
9595
|
+
type: z$1.literal("image"),
|
|
9596
|
+
image: z$1.union([
|
|
9597
|
+
fileInlineDataSchema,
|
|
9598
|
+
z$1.instanceof(URL),
|
|
9599
|
+
providerReferenceSchema
|
|
9600
|
+
]),
|
|
9601
|
+
mediaType: z$1.string().optional(),
|
|
9602
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9603
|
+
});
|
|
9604
|
+
const taggedFileDataSchema = z$1.discriminatedUnion("type", [
|
|
9605
|
+
z$1.object({
|
|
9606
|
+
type: z$1.literal("data"),
|
|
9607
|
+
data: fileInlineDataSchema
|
|
9608
|
+
}),
|
|
9609
|
+
z$1.object({
|
|
9610
|
+
type: z$1.literal("url"),
|
|
9611
|
+
url: z$1.instanceof(URL)
|
|
9612
|
+
}),
|
|
9613
|
+
z$1.object({
|
|
9614
|
+
type: z$1.literal("reference"),
|
|
9615
|
+
reference: providerReferenceSchema
|
|
9616
|
+
}),
|
|
9617
|
+
z$1.object({
|
|
9618
|
+
type: z$1.literal("text"),
|
|
9619
|
+
text: z$1.string()
|
|
9620
|
+
})
|
|
9621
|
+
]);
|
|
9622
|
+
const taggedReasoningFileDataSchema = z$1.discriminatedUnion("type", [z$1.object({
|
|
9623
|
+
type: z$1.literal("data"),
|
|
9624
|
+
data: fileInlineDataSchema
|
|
9625
|
+
}), z$1.object({
|
|
9626
|
+
type: z$1.literal("url"),
|
|
9627
|
+
url: z$1.instanceof(URL)
|
|
9628
|
+
})]);
|
|
9629
|
+
/**
|
|
9630
|
+
* @internal
|
|
9631
|
+
*/
|
|
9632
|
+
const filePartSchema = z$1.object({
|
|
9633
|
+
type: z$1.literal("file"),
|
|
9634
|
+
data: z$1.union([
|
|
9635
|
+
taggedFileDataSchema,
|
|
9636
|
+
fileInlineDataSchema,
|
|
9637
|
+
z$1.instanceof(URL),
|
|
9638
|
+
providerReferenceSchema
|
|
9639
|
+
]),
|
|
9640
|
+
filename: z$1.string().optional(),
|
|
9641
|
+
mediaType: z$1.string(),
|
|
9642
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9643
|
+
});
|
|
9644
|
+
/**
|
|
9645
|
+
* @internal
|
|
9646
|
+
*/
|
|
9647
|
+
const reasoningPartSchema = z$1.object({
|
|
9648
|
+
type: z$1.literal("reasoning"),
|
|
9649
|
+
text: z$1.string(),
|
|
9650
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9651
|
+
});
|
|
9652
|
+
/**
|
|
9653
|
+
* @internal
|
|
9654
|
+
*/
|
|
9655
|
+
const customPartSchema = z$1.object({
|
|
9656
|
+
type: z$1.literal("custom"),
|
|
9657
|
+
kind: z$1.string().transform((value) => value),
|
|
9658
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9659
|
+
});
|
|
9660
|
+
/**
|
|
9661
|
+
* @internal
|
|
9662
|
+
*/
|
|
9663
|
+
const reasoningFilePartSchema = z$1.object({
|
|
9664
|
+
type: z$1.literal("reasoning-file"),
|
|
9665
|
+
data: z$1.union([
|
|
9666
|
+
taggedReasoningFileDataSchema,
|
|
9667
|
+
fileInlineDataSchema,
|
|
9668
|
+
z$1.instanceof(URL)
|
|
9669
|
+
]),
|
|
9670
|
+
mediaType: z$1.string(),
|
|
9671
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9672
|
+
});
|
|
9673
|
+
/**
|
|
9674
|
+
* @internal
|
|
9675
|
+
*/
|
|
9676
|
+
const toolCallPartSchema = z$1.object({
|
|
9677
|
+
type: z$1.literal("tool-call"),
|
|
9678
|
+
toolCallId: z$1.string(),
|
|
9679
|
+
toolName: z$1.string(),
|
|
9680
|
+
input: z$1.unknown(),
|
|
9681
|
+
providerOptions: providerMetadataSchema.optional(),
|
|
9682
|
+
providerExecuted: z$1.boolean().optional()
|
|
9683
|
+
});
|
|
9684
|
+
/**
|
|
9685
|
+
* @internal
|
|
9686
|
+
*/
|
|
9687
|
+
const outputSchema = z$1.discriminatedUnion("type", [
|
|
9688
|
+
z$1.object({
|
|
9689
|
+
type: z$1.literal("text"),
|
|
9690
|
+
value: z$1.string(),
|
|
9691
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9692
|
+
}),
|
|
9693
|
+
z$1.object({
|
|
9694
|
+
type: z$1.literal("json"),
|
|
9695
|
+
value: jsonValueSchema,
|
|
9696
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9697
|
+
}),
|
|
9698
|
+
z$1.object({
|
|
9699
|
+
type: z$1.literal("execution-denied"),
|
|
9700
|
+
reason: z$1.string().optional(),
|
|
9701
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9702
|
+
}),
|
|
9703
|
+
z$1.object({
|
|
9704
|
+
type: z$1.literal("error-text"),
|
|
9705
|
+
value: z$1.string(),
|
|
9706
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9707
|
+
}),
|
|
9708
|
+
z$1.object({
|
|
9709
|
+
type: z$1.literal("error-json"),
|
|
9710
|
+
value: jsonValueSchema,
|
|
9711
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9712
|
+
}),
|
|
9713
|
+
z$1.object({
|
|
9714
|
+
type: z$1.literal("content"),
|
|
9715
|
+
value: z$1.array(z$1.union([
|
|
9716
|
+
z$1.object({
|
|
9717
|
+
type: z$1.literal("text"),
|
|
9718
|
+
text: z$1.string(),
|
|
9719
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9720
|
+
}),
|
|
9721
|
+
z$1.object({
|
|
9722
|
+
type: z$1.literal("file"),
|
|
9723
|
+
data: taggedFileDataSchema,
|
|
9724
|
+
mediaType: z$1.string(),
|
|
9725
|
+
filename: z$1.string().optional(),
|
|
9726
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9727
|
+
}),
|
|
9728
|
+
z$1.object({
|
|
9729
|
+
type: z$1.literal("file-data"),
|
|
9730
|
+
data: z$1.string(),
|
|
9731
|
+
mediaType: z$1.string(),
|
|
9732
|
+
filename: z$1.string().optional(),
|
|
9733
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9734
|
+
}),
|
|
9735
|
+
z$1.object({
|
|
9736
|
+
type: z$1.literal("file-url"),
|
|
9737
|
+
url: z$1.string(),
|
|
9738
|
+
mediaType: z$1.string().optional(),
|
|
9739
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9740
|
+
}),
|
|
9741
|
+
z$1.object({
|
|
9742
|
+
type: z$1.literal("file-id"),
|
|
9743
|
+
fileId: z$1.union([z$1.string(), z$1.record(z$1.string(), z$1.string())]),
|
|
9744
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9745
|
+
}),
|
|
9746
|
+
z$1.object({
|
|
9747
|
+
type: z$1.literal("file-reference"),
|
|
9748
|
+
providerReference: z$1.record(z$1.string(), z$1.string()),
|
|
9749
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9750
|
+
}),
|
|
9751
|
+
z$1.object({
|
|
9752
|
+
type: z$1.literal("image-data"),
|
|
9753
|
+
data: z$1.string(),
|
|
9754
|
+
mediaType: z$1.string(),
|
|
9755
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9756
|
+
}),
|
|
9757
|
+
z$1.object({
|
|
9758
|
+
type: z$1.literal("image-url"),
|
|
9759
|
+
url: z$1.string(),
|
|
9760
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9761
|
+
}),
|
|
9762
|
+
z$1.object({
|
|
9763
|
+
type: z$1.literal("image-file-id"),
|
|
9764
|
+
fileId: z$1.union([z$1.string(), z$1.record(z$1.string(), z$1.string())]),
|
|
9765
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9766
|
+
}),
|
|
9767
|
+
z$1.object({
|
|
9768
|
+
type: z$1.literal("image-file-reference"),
|
|
9769
|
+
providerReference: z$1.record(z$1.string(), z$1.string()),
|
|
9770
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9771
|
+
}),
|
|
9772
|
+
z$1.object({
|
|
9773
|
+
type: z$1.literal("custom"),
|
|
9774
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9775
|
+
})
|
|
9776
|
+
]))
|
|
9777
|
+
})
|
|
9778
|
+
]);
|
|
9779
|
+
/**
|
|
9780
|
+
* @internal
|
|
9781
|
+
*/
|
|
9782
|
+
const toolResultPartSchema = z$1.object({
|
|
9783
|
+
type: z$1.literal("tool-result"),
|
|
9784
|
+
toolCallId: z$1.string(),
|
|
9785
|
+
toolName: z$1.string(),
|
|
9786
|
+
output: outputSchema,
|
|
9787
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9788
|
+
});
|
|
9789
|
+
/**
|
|
9790
|
+
* @internal
|
|
9718
9791
|
*/
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
start(controllerArg) {
|
|
9728
|
-
controller = controllerArg;
|
|
9729
|
-
},
|
|
9730
|
-
async cancel(reason) {
|
|
9731
|
-
isCancelled = true;
|
|
9732
|
-
cancelReason = reason;
|
|
9733
|
-
await Promise.all(Array.from(activeReaders, (reader) => reader.cancel(reason)));
|
|
9734
|
-
}
|
|
9735
|
-
});
|
|
9736
|
-
function safeEnqueue(data) {
|
|
9737
|
-
try {
|
|
9738
|
-
controller.enqueue(data);
|
|
9739
|
-
} catch {}
|
|
9740
|
-
}
|
|
9741
|
-
function setOutcome(newOutcome) {
|
|
9742
|
-
if (outcome.status === "unknown" && newOutcome.status !== "unknown") outcome = newOutcome;
|
|
9743
|
-
}
|
|
9744
|
-
function failOutcome(error) {
|
|
9745
|
-
outcome = {
|
|
9746
|
-
status: "failed",
|
|
9747
|
-
error
|
|
9748
|
-
};
|
|
9749
|
-
}
|
|
9750
|
-
function safeError(error) {
|
|
9751
|
-
try {
|
|
9752
|
-
controller.error(error);
|
|
9753
|
-
} catch {}
|
|
9754
|
-
}
|
|
9755
|
-
function handleError(error) {
|
|
9756
|
-
failOutcome(error);
|
|
9757
|
-
let errorText;
|
|
9758
|
-
try {
|
|
9759
|
-
errorText = onError(error);
|
|
9760
|
-
} catch (onErrorError) {
|
|
9761
|
-
failOutcome(onErrorError);
|
|
9762
|
-
safeError(onErrorError);
|
|
9763
|
-
return;
|
|
9764
|
-
}
|
|
9765
|
-
safeEnqueue({
|
|
9766
|
-
type: "error",
|
|
9767
|
-
errorText
|
|
9768
|
-
});
|
|
9769
|
-
}
|
|
9770
|
-
try {
|
|
9771
|
-
const result = execute({ writer: {
|
|
9772
|
-
write(part) {
|
|
9773
|
-
safeEnqueue(part);
|
|
9774
|
-
},
|
|
9775
|
-
merge(streamArg) {
|
|
9776
|
-
if (isCancelled) {
|
|
9777
|
-
streamArg.cancel(cancelReason).catch(() => {});
|
|
9778
|
-
return;
|
|
9779
|
-
}
|
|
9780
|
-
ongoingStreamPromises.push((async () => {
|
|
9781
|
-
const reader = streamArg.getReader();
|
|
9782
|
-
activeReaders.add(reader);
|
|
9783
|
-
try {
|
|
9784
|
-
while (true) {
|
|
9785
|
-
const { done, value } = await reader.read();
|
|
9786
|
-
if (done) break;
|
|
9787
|
-
safeEnqueue(value);
|
|
9788
|
-
}
|
|
9789
|
-
} finally {
|
|
9790
|
-
activeReaders.delete(reader);
|
|
9791
|
-
reader.releaseLock();
|
|
9792
|
-
}
|
|
9793
|
-
})().catch((error) => {
|
|
9794
|
-
handleError(error);
|
|
9795
|
-
}));
|
|
9796
|
-
},
|
|
9797
|
-
setOutcome,
|
|
9798
|
-
onError
|
|
9799
|
-
} });
|
|
9800
|
-
if (result) ongoingStreamPromises.push(result.catch((error) => {
|
|
9801
|
-
handleError(error);
|
|
9802
|
-
}));
|
|
9803
|
-
} catch (error) {
|
|
9804
|
-
handleError(error);
|
|
9805
|
-
}
|
|
9806
|
-
(async () => {
|
|
9807
|
-
while (ongoingStreamPromises.length > 0) await ongoingStreamPromises.shift();
|
|
9808
|
-
})().finally(() => {
|
|
9809
|
-
try {
|
|
9810
|
-
controller.close();
|
|
9811
|
-
} catch {}
|
|
9812
|
-
});
|
|
9813
|
-
return handleUIMessageStreamFinish({
|
|
9814
|
-
stream,
|
|
9815
|
-
messageId: generateId$2(),
|
|
9816
|
-
originalMessages,
|
|
9817
|
-
onStepEnd: onStepEnd ?? onStepFinish,
|
|
9818
|
-
onEnd: onEnd ?? onFinish,
|
|
9819
|
-
onError,
|
|
9820
|
-
getOutcome: () => outcome
|
|
9821
|
-
});
|
|
9822
|
-
}
|
|
9823
|
-
z$1.record(z$1.string(), jsonValueSchema.optional());
|
|
9824
|
-
z$1.record(z$1.string(), z$1.string());
|
|
9825
|
-
createIdGenerator({
|
|
9826
|
-
prefix: "call",
|
|
9827
|
-
size: 24
|
|
9792
|
+
const toolApprovalRequestSchema = z$1.object({
|
|
9793
|
+
type: z$1.literal("tool-approval-request"),
|
|
9794
|
+
approvalId: z$1.string(),
|
|
9795
|
+
toolCallId: z$1.string(),
|
|
9796
|
+
reason: z$1.string().optional(),
|
|
9797
|
+
isAutomatic: z$1.boolean().optional(),
|
|
9798
|
+
signature: z$1.string().optional(),
|
|
9799
|
+
inputSchemaInput: z$1.unknown().optional()
|
|
9828
9800
|
});
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
9801
|
+
/**
|
|
9802
|
+
* @internal
|
|
9803
|
+
*/
|
|
9804
|
+
const toolApprovalResponseSchema = z$1.object({
|
|
9805
|
+
type: z$1.literal("tool-approval-response"),
|
|
9806
|
+
approvalId: z$1.string(),
|
|
9807
|
+
approved: z$1.boolean(),
|
|
9808
|
+
reason: z$1.string().optional()
|
|
9832
9809
|
});
|
|
9833
|
-
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
9810
|
+
const systemModelMessageSchema = z$1.object({
|
|
9811
|
+
role: z$1.literal("system"),
|
|
9812
|
+
content: z$1.string(),
|
|
9813
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9837
9814
|
});
|
|
9838
|
-
|
|
9839
|
-
|
|
9840
|
-
|
|
9815
|
+
const userModelMessageSchema = z$1.object({
|
|
9816
|
+
role: z$1.literal("user"),
|
|
9817
|
+
content: z$1.union([z$1.string(), z$1.array(z$1.union([
|
|
9818
|
+
textPartSchema,
|
|
9819
|
+
imagePartSchema,
|
|
9820
|
+
filePartSchema
|
|
9821
|
+
]))]),
|
|
9822
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9841
9823
|
});
|
|
9842
|
-
const
|
|
9843
|
-
|
|
9844
|
-
|
|
9845
|
-
|
|
9824
|
+
const assistantModelMessageSchema = z$1.object({
|
|
9825
|
+
role: z$1.literal("assistant"),
|
|
9826
|
+
content: z$1.union([z$1.string(), z$1.array(z$1.union([
|
|
9827
|
+
textPartSchema,
|
|
9828
|
+
customPartSchema,
|
|
9829
|
+
filePartSchema,
|
|
9830
|
+
reasoningPartSchema,
|
|
9831
|
+
reasoningFilePartSchema,
|
|
9832
|
+
toolCallPartSchema,
|
|
9833
|
+
toolResultPartSchema,
|
|
9834
|
+
toolApprovalRequestSchema
|
|
9835
|
+
]))]),
|
|
9836
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9846
9837
|
});
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9838
|
+
const toolModelMessageSchema = z$1.object({
|
|
9839
|
+
role: z$1.literal("tool"),
|
|
9840
|
+
content: z$1.array(z$1.union([toolResultPartSchema, toolApprovalResponseSchema])),
|
|
9841
|
+
providerOptions: providerMetadataSchema.optional()
|
|
9850
9842
|
});
|
|
9843
|
+
z$1.union([
|
|
9844
|
+
systemModelMessageSchema,
|
|
9845
|
+
userModelMessageSchema,
|
|
9846
|
+
assistantModelMessageSchema,
|
|
9847
|
+
toolModelMessageSchema
|
|
9848
|
+
]);
|
|
9851
9849
|
z$1.object({
|
|
9852
9850
|
token: z$1.string().refine((value) => value.trim().length > 0),
|
|
9853
9851
|
url: z$1.string().refine((value) => {
|
|
@@ -9878,8 +9876,7 @@ createIdGenerator({
|
|
|
9878
9876
|
prefix: "call",
|
|
9879
9877
|
size: 24
|
|
9880
9878
|
});
|
|
9881
|
-
|
|
9882
|
-
//#region src/smooth-stream.ts
|
|
9879
|
+
// src/smooth-stream.ts
|
|
9883
9880
|
/**
|
|
9884
9881
|
* Creates an experimental stream transform that emits text and reasoning in
|
|
9885
9882
|
* consistent, delayed chunks.
|
|
@@ -9893,8 +9890,7 @@ function applyMastraStreamTransforms(stream, transforms) {
|
|
|
9893
9890
|
if (!transforms) return stream;
|
|
9894
9891
|
return (Array.isArray(transforms) ? transforms : [transforms]).reduce((current, transform) => current.pipeThrough(transform()), stream);
|
|
9895
9892
|
}
|
|
9896
|
-
|
|
9897
|
-
//#region src/utils.ts
|
|
9893
|
+
// src/utils.ts
|
|
9898
9894
|
const isDataChunkType = (chunk) => {
|
|
9899
9895
|
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("data-");
|
|
9900
9896
|
};
|
|
@@ -10049,23 +10045,24 @@ function convertMastraChunkToAISDKBase({ chunk, mode = "stream", normalizeWarnin
|
|
|
10049
10045
|
id: chunk.payload.id,
|
|
10050
10046
|
providerMetadata: chunk.payload.providerMetadata
|
|
10051
10047
|
};
|
|
10052
|
-
case "source":
|
|
10053
|
-
|
|
10054
|
-
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10048
|
+
case "source":
|
|
10049
|
+
if (chunk.payload.sourceType === "url") return {
|
|
10050
|
+
type: "source",
|
|
10051
|
+
sourceType: "url",
|
|
10052
|
+
id: chunk.payload.id,
|
|
10053
|
+
url: chunk.payload.url,
|
|
10054
|
+
title: chunk.payload.title,
|
|
10055
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
10056
|
+
};
|
|
10057
|
+
return {
|
|
10058
|
+
type: "source",
|
|
10059
|
+
sourceType: "document",
|
|
10060
|
+
id: chunk.payload.id,
|
|
10061
|
+
mediaType: chunk.payload.mimeType,
|
|
10062
|
+
title: chunk.payload.title,
|
|
10063
|
+
filename: chunk.payload.filename,
|
|
10064
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
10065
|
+
};
|
|
10069
10066
|
case "file":
|
|
10070
10067
|
if (mode === "generate") return {
|
|
10071
10068
|
type: "file",
|
|
@@ -10099,6 +10096,8 @@ function convertMastraChunkToAISDKBase({ chunk, mode = "stream", normalizeWarnin
|
|
|
10099
10096
|
runId: chunk.runId,
|
|
10100
10097
|
toolCallId: chunk.payload.toolCallId,
|
|
10101
10098
|
toolName: chunk.payload.toolName,
|
|
10099
|
+
...chunk.payload.delegatedToolCallId ? { delegatedToolCallId: chunk.payload.delegatedToolCallId } : {},
|
|
10100
|
+
...chunk.payload.delegatedToolName ? { delegatedToolName: chunk.payload.delegatedToolName } : {},
|
|
10102
10101
|
args: hasTransformedToolPayload(displayApprovalTransform) ? displayApprovalTransform.transformed : chunk.payload.args,
|
|
10103
10102
|
resumeSchema: chunk.payload.resumeSchema
|
|
10104
10103
|
}
|
|
@@ -10111,6 +10110,8 @@ function convertMastraChunkToAISDKBase({ chunk, mode = "stream", normalizeWarnin
|
|
|
10111
10110
|
runId: chunk.runId,
|
|
10112
10111
|
toolCallId: chunk.payload.toolCallId,
|
|
10113
10112
|
toolName: chunk.payload.toolName,
|
|
10113
|
+
...chunk.payload.delegatedToolCallId ? { delegatedToolCallId: chunk.payload.delegatedToolCallId } : {},
|
|
10114
|
+
...chunk.payload.delegatedToolName ? { delegatedToolName: chunk.payload.delegatedToolName } : {},
|
|
10114
10115
|
suspendPayload: hasTransformedToolPayload(displaySuspendTransform) ? displaySuspendTransform.transformed : chunk.payload.suspendPayload,
|
|
10115
10116
|
resumeSchema: chunk.payload.resumeSchema
|
|
10116
10117
|
}
|
|
@@ -10124,6 +10125,8 @@ function convertMastraChunkToAISDKBase({ chunk, mode = "stream", normalizeWarnin
|
|
|
10124
10125
|
runId: chunk.runId,
|
|
10125
10126
|
toolCallId: chunk.payload.toolCallId,
|
|
10126
10127
|
toolName: chunk.payload.toolName,
|
|
10128
|
+
...chunk.payload.delegatedToolCallId ? { delegatedToolCallId: chunk.payload.delegatedToolCallId } : {},
|
|
10129
|
+
...chunk.payload.delegatedToolName ? { delegatedToolName: chunk.payload.delegatedToolName } : {},
|
|
10127
10130
|
args: hasTransformedToolPayload(displayApprovalTransform) ? displayApprovalTransform.transformed : chunk.payload.args,
|
|
10128
10131
|
resumeSchema: chunk.payload.resumeSchema,
|
|
10129
10132
|
resumed: true
|
|
@@ -10137,6 +10140,8 @@ function convertMastraChunkToAISDKBase({ chunk, mode = "stream", normalizeWarnin
|
|
|
10137
10140
|
runId: chunk.runId,
|
|
10138
10141
|
toolCallId: chunk.payload.toolCallId,
|
|
10139
10142
|
toolName: chunk.payload.toolName,
|
|
10143
|
+
...chunk.payload.delegatedToolCallId ? { delegatedToolCallId: chunk.payload.delegatedToolCallId } : {},
|
|
10144
|
+
...chunk.payload.delegatedToolName ? { delegatedToolName: chunk.payload.delegatedToolName } : {},
|
|
10140
10145
|
suspendPayload: hasTransformedToolPayload(displaySuspendTransform) ? displaySuspendTransform.transformed : chunk.payload.suspendPayload,
|
|
10141
10146
|
resumeSchema: chunk.payload.resumeSchema,
|
|
10142
10147
|
resumed: true
|
|
@@ -10204,7 +10209,8 @@ function convertMastraChunkToAISDKBase({ chunk, mode = "stream", normalizeWarnin
|
|
|
10204
10209
|
providerExecuted: chunk.payload.providerExecuted,
|
|
10205
10210
|
toolName: chunk.payload.toolName,
|
|
10206
10211
|
output: hasTransformedToolPayload(displayOutputTransform) ? displayOutputTransform.transformed : chunk.payload.result,
|
|
10207
|
-
...chunk.payload.providerMetadata != null ? { providerMetadata: chunk.payload.providerMetadata } : {}
|
|
10212
|
+
...chunk.payload.providerMetadata != null ? { providerMetadata: chunk.payload.providerMetadata } : {},
|
|
10213
|
+
..."preliminary" in chunk.payload && chunk.payload.preliminary === true ? { preliminary: true } : {}
|
|
10208
10214
|
};
|
|
10209
10215
|
case "tool-error": return {
|
|
10210
10216
|
type: "tool-error",
|
|
@@ -10324,6 +10330,8 @@ function convertMastraChunkToAISDKv6({ chunk, mode = "stream" }) {
|
|
|
10324
10330
|
runId: chunk.runId,
|
|
10325
10331
|
toolCallId: chunk.payload.toolCallId,
|
|
10326
10332
|
toolName: chunk.payload.toolName,
|
|
10333
|
+
...chunk.payload.delegatedToolCallId ? { delegatedToolCallId: chunk.payload.delegatedToolCallId } : {},
|
|
10334
|
+
...chunk.payload.delegatedToolName ? { delegatedToolName: chunk.payload.delegatedToolName } : {},
|
|
10327
10335
|
args: hasTransformedToolPayload(displayTransform) ? displayTransform.transformed : chunk.payload.args,
|
|
10328
10336
|
resumeSchema: chunk.payload.resumeSchema
|
|
10329
10337
|
}
|
|
@@ -10488,7 +10496,8 @@ function convertFullStreamChunkToUIMessageStream({ part, messageMetadataValue, s
|
|
|
10488
10496
|
output: part.output,
|
|
10489
10497
|
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
|
10490
10498
|
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
10491
|
-
...part.dynamic != null ? { dynamic: part.dynamic } : {}
|
|
10499
|
+
...part.dynamic != null ? { dynamic: part.dynamic } : {},
|
|
10500
|
+
...part.preliminary != null ? { preliminary: part.preliminary } : {}
|
|
10492
10501
|
};
|
|
10493
10502
|
case "tool-output-denied": return {
|
|
10494
10503
|
type: "tool-output-denied",
|
|
@@ -10566,8 +10575,7 @@ function convertFullStreamChunkToUIMessageStream({ part, messageMetadataValue, s
|
|
|
10566
10575
|
return;
|
|
10567
10576
|
}
|
|
10568
10577
|
}
|
|
10569
|
-
|
|
10570
|
-
//#region src/transformers.ts
|
|
10578
|
+
// src/transformers.ts
|
|
10571
10579
|
const PRIMITIVE_CACHE_SYMBOL = Symbol("primitive-cache");
|
|
10572
10580
|
const COMPLETED_STEPS_SYMBOL = Symbol("completed-steps-cache");
|
|
10573
10581
|
function cloneWorkflowStep(step, includeOutput) {
|
|
@@ -11628,8 +11636,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
11628
11636
|
return null;
|
|
11629
11637
|
}
|
|
11630
11638
|
}
|
|
11631
|
-
|
|
11632
|
-
//#region src/convert-streams.ts
|
|
11639
|
+
// src/convert-streams.ts
|
|
11633
11640
|
function toAISdkV5Stream(stream, options = {
|
|
11634
11641
|
from: "agent",
|
|
11635
11642
|
sendStart: true,
|
|
@@ -11704,8 +11711,7 @@ function toAISdkStream(stream, options = {
|
|
|
11704
11711
|
includeSubAgentMetadata: options.includeSubAgentMetadata
|
|
11705
11712
|
}));
|
|
11706
11713
|
}
|
|
11707
|
-
|
|
11708
|
-
//#region src/sse-heartbeat.ts
|
|
11714
|
+
// src/sse-heartbeat.ts
|
|
11709
11715
|
const SSE_HEARTBEAT_BYTES = new TextEncoder().encode(": heartbeat\n\n");
|
|
11710
11716
|
const LF_BYTE = 10;
|
|
11711
11717
|
const MAX_TIMEOUT_MS = 2147483647;
|
|
@@ -11828,8 +11834,7 @@ function withSseHeartbeat(response, heartbeatMs) {
|
|
|
11828
11834
|
headers: response.headers
|
|
11829
11835
|
});
|
|
11830
11836
|
}
|
|
11831
|
-
|
|
11832
|
-
//#region src/chat-route.ts
|
|
11837
|
+
// src/chat-route.ts
|
|
11833
11838
|
/**
|
|
11834
11839
|
* Collects every approval response across all assistant messages in a v6
|
|
11835
11840
|
* request. Responses are deduplicated by their composite run/tool-call target,
|
|
@@ -12234,8 +12239,7 @@ function chatRoute({ path = "/chat/:agentId", agent, defaultOptions, experimenta
|
|
|
12234
12239
|
}
|
|
12235
12240
|
});
|
|
12236
12241
|
}
|
|
12237
|
-
|
|
12238
|
-
//#region src/workflow-route.ts
|
|
12242
|
+
// src/workflow-route.ts
|
|
12239
12243
|
async function handleWorkflowStream({ mastra, workflowId, params, version = "v5", includeTextStreamParts = true, sendReasoning = false, sendSources = false }) {
|
|
12240
12244
|
const { runId, resourceId: resourceIdFromParams, inputData, initialState, resumeData, requestContext, ...rest } = params;
|
|
12241
12245
|
const resourceId = requestContext?.get(MASTRA_RESOURCE_ID_KEY) ?? resourceIdFromParams;
|
|
@@ -12387,8 +12391,7 @@ function workflowRoute({ path = "/api/workflows/:workflowId/stream", workflow, v
|
|
|
12387
12391
|
}
|
|
12388
12392
|
});
|
|
12389
12393
|
}
|
|
12390
|
-
|
|
12391
|
-
//#region src/network-route.ts
|
|
12394
|
+
// src/network-route.ts
|
|
12392
12395
|
async function handleNetworkStream({ mastra, agentId, agentVersion, params, defaultOptions, version = "v5" }) {
|
|
12393
12396
|
const { messages, ...rest } = params;
|
|
12394
12397
|
const agentObj = agentVersion ? await mastra.getAgentById(agentId, agentVersion) : mastra.getAgentById(agentId);
|
|
@@ -12584,8 +12587,7 @@ function networkRoute({ path = "/network/:agentId", agent, defaultOptions, versi
|
|
|
12584
12587
|
}
|
|
12585
12588
|
});
|
|
12586
12589
|
}
|
|
12587
|
-
|
|
12588
|
-
//#region src/convert-snapshot.ts
|
|
12590
|
+
// src/convert-snapshot.ts
|
|
12589
12591
|
/**
|
|
12590
12592
|
* Converts a `WorkflowState` (as returned by `getWorkflowRunById` or the
|
|
12591
12593
|
* workflow runs API) into a `ReadableStream` of AI SDK UIMessage data parts —
|
|
@@ -12657,8 +12659,7 @@ function mergeForEachStepResult(results) {
|
|
|
12657
12659
|
output: stepResults.map((result) => result.output)
|
|
12658
12660
|
};
|
|
12659
12661
|
}
|
|
12660
|
-
|
|
12661
|
-
//#region src/middleware.ts
|
|
12662
|
+
// src/middleware.ts
|
|
12662
12663
|
function withMastra(model, options = {}) {
|
|
12663
12664
|
const { memory, inputProcessors = [], outputProcessors = [] } = options;
|
|
12664
12665
|
const allInputProcessors = [...inputProcessors];
|
|
@@ -12761,9 +12762,8 @@ var StreamOutputAccumulator = class {
|
|
|
12761
12762
|
state.result = chunk.payload.result;
|
|
12762
12763
|
if (state.args === void 0) this.finalizeToolArgs(state);
|
|
12763
12764
|
state.providerMetadata = chunk.payload.providerMetadata || state.providerMetadata;
|
|
12764
|
-
|
|
12765
|
+
break;
|
|
12765
12766
|
}
|
|
12766
|
-
default: return;
|
|
12767
12767
|
}
|
|
12768
12768
|
}
|
|
12769
12769
|
buildResponseMessage(memory) {
|
|
@@ -12813,9 +12813,7 @@ var StreamOutputAccumulator = class {
|
|
|
12813
12813
|
if (state.args !== void 0 || !state.argDeltas?.length) return;
|
|
12814
12814
|
try {
|
|
12815
12815
|
state.args = JSON.parse(state.argDeltas.join(""));
|
|
12816
|
-
} catch {
|
|
12817
|
-
return;
|
|
12818
|
-
}
|
|
12816
|
+
} catch {}
|
|
12819
12817
|
}
|
|
12820
12818
|
appendTextDelta(text) {
|
|
12821
12819
|
const last = this.partOrder[this.partOrder.length - 1];
|
|
@@ -13253,23 +13251,24 @@ function convertMastraChunkToAISDKStreamPart(chunk) {
|
|
|
13253
13251
|
providerExecuted: chunk.payload.providerExecuted,
|
|
13254
13252
|
providerMetadata: chunk.payload.providerMetadata
|
|
13255
13253
|
};
|
|
13256
|
-
case "source":
|
|
13257
|
-
|
|
13258
|
-
|
|
13259
|
-
|
|
13260
|
-
|
|
13261
|
-
|
|
13262
|
-
|
|
13263
|
-
|
|
13264
|
-
|
|
13265
|
-
|
|
13266
|
-
|
|
13267
|
-
|
|
13268
|
-
|
|
13269
|
-
|
|
13270
|
-
|
|
13271
|
-
|
|
13272
|
-
|
|
13254
|
+
case "source":
|
|
13255
|
+
if (chunk.payload.sourceType === "url") return {
|
|
13256
|
+
type: "source",
|
|
13257
|
+
sourceType: "url",
|
|
13258
|
+
id: chunk.payload.id,
|
|
13259
|
+
url: chunk.payload.url,
|
|
13260
|
+
title: chunk.payload.title,
|
|
13261
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
13262
|
+
};
|
|
13263
|
+
return {
|
|
13264
|
+
type: "source",
|
|
13265
|
+
sourceType: "document",
|
|
13266
|
+
id: chunk.payload.id,
|
|
13267
|
+
mediaType: chunk.payload.mimeType,
|
|
13268
|
+
title: chunk.payload.title,
|
|
13269
|
+
filename: chunk.payload.filename,
|
|
13270
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
13271
|
+
};
|
|
13273
13272
|
case "file": return {
|
|
13274
13273
|
type: "file",
|
|
13275
13274
|
data: chunk.payload.data || chunk.payload.base64,
|
|
@@ -13303,8 +13302,7 @@ function convertMastraChunkToAISDKStreamPart(chunk) {
|
|
|
13303
13302
|
default: return null;
|
|
13304
13303
|
}
|
|
13305
13304
|
}
|
|
13306
|
-
|
|
13307
|
-
//#region src/to-ai-sdk-format.ts
|
|
13305
|
+
// src/to-ai-sdk-format.ts
|
|
13308
13306
|
/**
|
|
13309
13307
|
* @deprecated Use `toAISdkStream` instead. This function has been renamed for clarity.
|
|
13310
13308
|
*
|
|
@@ -13322,7 +13320,6 @@ function convertMastraChunkToAISDKStreamPart(chunk) {
|
|
|
13322
13320
|
function toAISdkFormat() {
|
|
13323
13321
|
throw new Error("toAISdkFormat() has been deprecated. Please use toAISdkStream() instead.\n\nMigration:\n import { toAISdkFormat } from \"@mastra/ai-sdk\";\n // Change to:\n import { toAISdkStream } from \"@mastra/ai-sdk\";\n\nThe function signature remains the same.");
|
|
13324
13322
|
}
|
|
13325
|
-
//#endregion
|
|
13326
13323
|
export { assertValidHeartbeatMs, chatRoute, handleChatStream, handleNetworkStream, handleWorkflowStream, networkRoute, smoothStream, toAISdkFormat, toAISdkStream, toAISdkV5Stream, withMastra, withSseHeartbeat, workflowRoute, workflowSnapshotToStream };
|
|
13327
13324
|
|
|
13328
13325
|
//# sourceMappingURL=index.js.map
|