@ai-sdk/harness 1.0.94 → 1.0.96
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/CHANGELOG.md +17 -0
- package/dist/agent/index.js +30 -6
- package/dist/agent/index.js.map +1 -1
- package/dist/utils/index.d.ts +11 -1
- package/dist/utils/index.js +25 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -3
- package/src/agent/internal/run-prompt.ts +15 -0
- package/src/agent/internal/turn-telemetry.ts +34 -8
- package/src/utils/bridge-asset.ts +9 -0
- package/src/utils/bridge-token.ts +18 -0
- package/src/utils/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/harness",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.96",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@ai-sdk/provider": "4.0.9",
|
|
48
48
|
"@ai-sdk/provider-utils": "5.0.34",
|
|
49
|
-
"ai": "7.0.
|
|
49
|
+
"ai": "7.0.87"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"ws": "^8.21.0",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@ai-sdk/otel": "1.0.
|
|
61
|
+
"@ai-sdk/otel": "1.0.87",
|
|
62
62
|
"@opentelemetry/sdk-trace-base": "2.7.1",
|
|
63
63
|
"@types/node": "22.19.19",
|
|
64
64
|
"@types/ws": "^8.5.13",
|
|
@@ -138,12 +138,27 @@ export function runPrompt<
|
|
|
138
138
|
const onPendingToolResult = input.onPendingToolResult ?? (() => {});
|
|
139
139
|
const onToolResultSettled = input.onToolResultSettled ?? (() => {});
|
|
140
140
|
const activeTools = input.activeTools ?? input.tools;
|
|
141
|
+
const activeToolNames = Object.keys(input.tools).filter(
|
|
142
|
+
toolName =>
|
|
143
|
+
Object.prototype.hasOwnProperty.call(activeTools, toolName) ||
|
|
144
|
+
(Object.prototype.hasOwnProperty.call(
|
|
145
|
+
input.harness.builtinTools,
|
|
146
|
+
toolName,
|
|
147
|
+
) &&
|
|
148
|
+
isHarnessV1BuiltinToolIncluded({
|
|
149
|
+
toolName,
|
|
150
|
+
toolFiltering: input.builtinToolFiltering,
|
|
151
|
+
})),
|
|
152
|
+
);
|
|
141
153
|
|
|
142
154
|
const telemetry = createTurnTelemetry({
|
|
143
155
|
telemetry: input.telemetry,
|
|
144
156
|
harnessId: input.harness.harnessId,
|
|
145
157
|
modelId: input.model,
|
|
146
158
|
instructions: input.instructions,
|
|
159
|
+
tools: input.tools,
|
|
160
|
+
activeToolNames,
|
|
161
|
+
toolSpecs: input.toolSpecs,
|
|
147
162
|
promptText: input.prompt != null ? promptToText(input.prompt) : '',
|
|
148
163
|
runtimeContext: input.runtimeContext,
|
|
149
164
|
});
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
generateId,
|
|
3
|
+
type ModelMessage,
|
|
4
|
+
type ToolSet,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
2
6
|
import { createTelemetryDispatcher } from 'ai/internal';
|
|
3
7
|
import type { LanguageModelUsage, TelemetryOptions } from 'ai';
|
|
8
|
+
import type { HarnessV1ToolSpec } from '../../v1';
|
|
4
9
|
|
|
5
10
|
/*
|
|
6
11
|
* Drives AI SDK's pluggable `Telemetry` lifecycle from a harness turn.
|
|
@@ -13,8 +18,9 @@ import type { LanguageModelUsage, TelemetryOptions } from 'ai';
|
|
|
13
18
|
* step boundary, tool-calls = tool executions, `finish` = operation end. The
|
|
14
19
|
* model-call-only event fields the harness has no value for (sampling params,
|
|
15
20
|
* standardized prompt) are left `undefined` / cast; the fields the integrations
|
|
16
|
-
* actually read (`callId`, `operationId`, `provider`, `modelId`,
|
|
17
|
-
* `toolCall`, `usage`, `finishReason`)
|
|
21
|
+
* actually read (`callId`, `operationId`, `provider`, `modelId`,
|
|
22
|
+
* `instructions`, `messages`, `tools`, `toolCall`, `usage`, `finishReason`)
|
|
23
|
+
* carry real values.
|
|
18
24
|
*
|
|
19
25
|
* Telemetry is opt-in: the framework only drives it when `settings.telemetry`
|
|
20
26
|
* is set (the dispatcher then also honours globally-registered integrations).
|
|
@@ -160,6 +166,9 @@ export function createTurnTelemetry(opts: {
|
|
|
160
166
|
harnessId: string;
|
|
161
167
|
modelId: string | undefined;
|
|
162
168
|
instructions: string | undefined;
|
|
169
|
+
tools: ToolSet;
|
|
170
|
+
activeToolNames: string[];
|
|
171
|
+
toolSpecs: HarnessV1ToolSpec[];
|
|
163
172
|
promptText: string;
|
|
164
173
|
runtimeContext: unknown;
|
|
165
174
|
}): TurnTelemetry {
|
|
@@ -177,6 +186,19 @@ export function createTurnTelemetry(opts: {
|
|
|
177
186
|
const inputMessages: ModelMessage[] = [
|
|
178
187
|
{ role: 'user', content: opts.promptText },
|
|
179
188
|
];
|
|
189
|
+
const languageModelTools =
|
|
190
|
+
opts.toolSpecs.length === 0
|
|
191
|
+
? undefined
|
|
192
|
+
: opts.toolSpecs.map(tool => ({
|
|
193
|
+
type: 'function' as const,
|
|
194
|
+
name: tool.name,
|
|
195
|
+
...(tool.description != null
|
|
196
|
+
? { description: tool.description }
|
|
197
|
+
: {}),
|
|
198
|
+
...(tool.inputSchema != null
|
|
199
|
+
? { inputSchema: tool.inputSchema }
|
|
200
|
+
: {}),
|
|
201
|
+
}));
|
|
180
202
|
|
|
181
203
|
let started = false;
|
|
182
204
|
let stepOpen = false;
|
|
@@ -211,9 +233,9 @@ export function createTurnTelemetry(opts: {
|
|
|
211
233
|
operationId: 'ai.harness',
|
|
212
234
|
provider,
|
|
213
235
|
modelId,
|
|
214
|
-
tools:
|
|
236
|
+
tools: opts.tools,
|
|
215
237
|
toolChoice: undefined,
|
|
216
|
-
activeTools:
|
|
238
|
+
activeTools: opts.activeToolNames,
|
|
217
239
|
maxRetries: 0,
|
|
218
240
|
timeout: undefined,
|
|
219
241
|
headers: undefined,
|
|
@@ -243,13 +265,14 @@ export function createTurnTelemetry(opts: {
|
|
|
243
265
|
provider,
|
|
244
266
|
modelId,
|
|
245
267
|
stepNumber,
|
|
246
|
-
tools:
|
|
268
|
+
tools: opts.tools,
|
|
247
269
|
toolChoice: undefined,
|
|
248
|
-
activeTools:
|
|
270
|
+
activeTools: opts.activeToolNames,
|
|
249
271
|
steps: new Array(stepNumber),
|
|
250
272
|
providerOptions: undefined,
|
|
251
273
|
output: undefined,
|
|
252
274
|
runtimeContext,
|
|
275
|
+
instructions: opts.instructions,
|
|
253
276
|
messages: inputMessages,
|
|
254
277
|
}),
|
|
255
278
|
);
|
|
@@ -260,8 +283,9 @@ export function createTurnTelemetry(opts: {
|
|
|
260
283
|
callId,
|
|
261
284
|
provider,
|
|
262
285
|
modelId,
|
|
286
|
+
instructions: opts.instructions,
|
|
263
287
|
messages: inputMessages,
|
|
264
|
-
tools:
|
|
288
|
+
tools: languageModelTools,
|
|
265
289
|
}),
|
|
266
290
|
);
|
|
267
291
|
};
|
|
@@ -279,6 +303,8 @@ export function createTurnTelemetry(opts: {
|
|
|
279
303
|
await dispatcher.onLanguageModelCallEnd?.(
|
|
280
304
|
cast<'onLanguageModelCallEnd'>({
|
|
281
305
|
callId,
|
|
306
|
+
provider,
|
|
307
|
+
modelId,
|
|
282
308
|
finishReason,
|
|
283
309
|
responseId: callId,
|
|
284
310
|
usage,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
|
|
3
|
+
export function createReadBridgeAsset({
|
|
4
|
+
resolveAssetUrl,
|
|
5
|
+
}: {
|
|
6
|
+
resolveAssetUrl: (name: string) => URL;
|
|
7
|
+
}): (name: string) => Promise<string> {
|
|
8
|
+
return async name => readFile(resolveAssetUrl(name), 'utf8');
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import type { HarnessV1PortEndpoint } from '../v1';
|
|
3
|
+
|
|
4
|
+
export function createBridgeToken(): string {
|
|
5
|
+
return randomBytes(32).toString('hex');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function withBridgeToken({
|
|
9
|
+
endpoint,
|
|
10
|
+
token,
|
|
11
|
+
}: {
|
|
12
|
+
endpoint: HarnessV1PortEndpoint;
|
|
13
|
+
token: string;
|
|
14
|
+
}): HarnessV1PortEndpoint {
|
|
15
|
+
const bridgeUrl = new URL(endpoint.url);
|
|
16
|
+
bridgeUrl.searchParams.set('agent_bridge_token', token);
|
|
17
|
+
return { ...endpoint, url: bridgeUrl.toString() };
|
|
18
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -40,6 +40,8 @@ export {
|
|
|
40
40
|
type WaitForBridgeReadyOptions,
|
|
41
41
|
type WaitForBridgeReadyResult,
|
|
42
42
|
} from './bridge-ready';
|
|
43
|
+
export { createBridgeToken, withBridgeToken } from './bridge-token';
|
|
44
|
+
export { createReadBridgeAsset } from './bridge-asset';
|
|
43
45
|
export {
|
|
44
46
|
createBridgeErrorHandler,
|
|
45
47
|
createBridgeStartupError,
|