@ai-sdk/provider-utils 5.0.41 → 5.0.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/provider-utils",
3
- "version": "5.0.41",
3
+ "version": "5.0.42",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -32,7 +32,7 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@ai-sdk/provider": "4.0.15",
35
+ "@ai-sdk/provider": "4.0.16",
36
36
  "@standard-schema/spec": "^1.1.0",
37
37
  "@workflow/serde": "4.1.0",
38
38
  "eventsource-parser": "^3.0.8",
@@ -1,6 +1,7 @@
1
1
  export function isAbortError(error: unknown): error is Error {
2
2
  return (
3
- (error instanceof Error || error instanceof DOMException) &&
3
+ (error instanceof Error ||
4
+ (typeof DOMException === 'function' && error instanceof DOMException)) &&
4
5
  (error.name === 'AbortError' ||
5
6
  error.name === 'ResponseAborted' || // Next.js
6
7
  error.name === 'TimeoutError')
@@ -102,47 +102,37 @@ export function createSafeLookup(lookup: Lookup): SafeLookup {
102
102
  }
103
103
 
104
104
  let safeNodeFetchPromise: Promise<FetchFunction> | undefined;
105
- const initialGlobalFetch = globalThis.fetch;
106
- const initialGlobalFetchIsNodeDefault = isNodeDefaultFetch(initialGlobalFetch);
107
105
 
108
106
  export function isNodeRuntime(): boolean {
109
107
  const runtimeProcess = globalThis.process as
110
108
  | {
111
109
  release?: { name?: string };
112
- versions?: { bun?: string };
110
+ title?: string;
111
+ versions?: { bun?: string; deno?: string };
113
112
  }
114
113
  | undefined;
115
114
 
115
+ // Node-compatible process objects do not imply support for Node DNS/socket
116
+ // hooks. Workers identifies itself as workerd, including without navigator.
116
117
  return (
117
118
  runtimeProcess?.release?.name === 'node' &&
118
- runtimeProcess.versions?.bun == null
119
+ runtimeProcess.versions?.bun == null &&
120
+ runtimeProcess.versions?.deno == null &&
121
+ runtimeProcess.title !== 'workerd' &&
122
+ (globalThis as { EdgeRuntime?: unknown }).EdgeRuntime == null
119
123
  );
120
124
  }
121
125
 
122
126
  export async function getDefaultDownloadFetch(): Promise<FetchFunction> {
123
- if (
124
- !isNodeRuntime() ||
125
- !initialGlobalFetchIsNodeDefault ||
126
- globalThis.fetch !== initialGlobalFetch
127
- ) {
127
+ if (!isNodeRuntime()) {
128
128
  return globalThis.fetch;
129
129
  }
130
130
 
131
+ // Global fetch wrappers cannot be relied on to preserve the dispatcher
132
+ // that pins connections to validated DNS results.
131
133
  return (safeNodeFetchPromise ??= Promise.resolve().then(createSafeNodeFetch));
132
134
  }
133
135
 
134
- function isNodeDefaultFetch(fetch: unknown): boolean {
135
- if (typeof fetch !== 'function') {
136
- return false;
137
- }
138
-
139
- const source = Function.prototype.toString.call(fetch);
140
- return (
141
- source.includes('internal/deps/undici') ||
142
- source.includes('lazy loading of undici')
143
- );
144
- }
145
-
146
136
  function createSafeNodeFetch(): FetchFunction {
147
137
  // Load Node-only modules indirectly so browser bundlers do not pull undici
148
138
  // and Node built-ins into the browser-facing provider-utils entry point.
@@ -6,6 +6,14 @@ export type ToolCallerDefinition =
6
6
  | {
7
7
  type: 'local';
8
8
  bind: (tools: ToolSet) => Tool;
9
+ /**
10
+ * Creates a provider-agnostic user message that describes the tools
11
+ * available through this caller. When present, the unbound caller tool
12
+ * remains model-visible so its definition stays stable, while the
13
+ * returned message is added to the conversation when its content has
14
+ * not already been announced.
15
+ */
16
+ prepareModelMessage?: (tools: ToolSet) => string | undefined;
9
17
  }
10
18
  | {
11
19
  type: 'provider';