Skip to content

Commit 818ffe0

Browse files
committed
fixup! fix(server-utils): Read pi-durable 1.2.0 tool results from output
1 parent 61274c5 commit 818ffe0

4 files changed

Lines changed: 15 additions & 31 deletions

File tree

‎dev-packages/e2e-tests/test-applications/cloudflare-pi-durable/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"test:assert": "playwright test"
1313
},
1414
"dependencies": {
15-
"@earendil-works/pi-ai": "1.0.0",
16-
"@earendil-works/pi-durable": "1.0.0",
15+
"@earendil-works/pi-ai": "1.2.0",
16+
"@earendil-works/pi-durable": "1.2.0",
1717
"@sentry/cloudflare": "file:../../packed/sentry-cloudflare-packed.tgz",
1818
"agents": "0.26.0"
1919
},

‎dev-packages/e2e-tests/test-applications/cloudflare-pi-durable/src/assistant.ts‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ import * as Sentry from '@sentry/cloudflare';
66
import { Agent } from 'agents';
77
import { PiHarness } from 'agents/harness/pi';
88

9-
type TextBlock = { type: 'text'; text: string };
10-
11-
// pi-durable 1.2.0 renamed the tool result field `content` to `output`. The app runs on 1.0.0 and on the
12-
// latest version, so its tool results set both.
13-
function textResult(text: string): { output: TextBlock[]; content: TextBlock[] } {
14-
const blocks: TextBlock[] = [{ type: 'text', text }];
15-
return { output: blocks, content: blocks };
16-
}
17-
189
/**
1910
* pi-durable hosted by the Agents SDK `PiHarness`: pi keeps its state in this object's SQLite
2011
* database, and the harness reopens pi when the object restarts. Nothing wires Sentry into
@@ -55,9 +46,9 @@ export class Assistant extends Agent<Env> {
5546
parameters: Type.Object({ city: Type.String() }),
5647
// The manual span should nest under the SDK's `execute_tool` span.
5748
execute: async args =>
58-
Sentry.startSpan({ name: 'resolve-weather', attributes: { 'weather.city': args.city } }, () =>
59-
textResult(`It is 21 degrees and sunny in ${args.city}.`),
60-
),
49+
Sentry.startSpan({ name: 'resolve-weather', attributes: { 'weather.city': args.city } }, () => ({
50+
output: [{ type: 'text', text: `It is 21 degrees and sunny in ${args.city}.` }],
51+
})),
6152
}),
6253
defineTool({
6354
name: 'fail_now',
@@ -76,7 +67,7 @@ export class Assistant extends Agent<Env> {
7667
execute: async args => {
7768
const marker = `crashed:${args.job}`;
7869
if (await this.ctx.storage.get(marker)) {
79-
return textResult(`Step of job ${args.job} completed.`);
70+
return { output: [{ type: 'text', text: `Step of job ${args.job} completed.` }] };
8071
}
8172
await this.ctx.storage.put(marker, true);
8273
await this.ctx.storage.sync();

‎dev-packages/e2e-tests/test-applications/node-pi-durable/package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"test:assert": "OPENROUTER_API_KEY=$E2E_OPENROUTER_API_KEY playwright test"
1212
},
1313
"dependencies": {
14-
"@earendil-works/chord": "1.0.0",
15-
"@earendil-works/pi-ai": "1.0.0",
16-
"@earendil-works/pi-durable": "1.0.0",
14+
"@earendil-works/chord": "1.2.0",
15+
"@earendil-works/pi-ai": "1.2.0",
16+
"@earendil-works/pi-durable": "1.2.0",
1717
"@sentry/node": "file:../../packed/sentry-node-packed.tgz"
1818
},
1919
"devDependencies": {

‎dev-packages/e2e-tests/test-applications/node-pi-durable/src/server.mjs‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ if (!process.env.OPENROUTER_API_KEY) {
2424
throw new Error('OPENROUTER_API_KEY is not set (E2E_OPENROUTER_API_KEY in the e2e-tests .env)');
2525
}
2626

27-
// pi-durable 1.2.0 renamed the tool result field `content` to `output`. The app runs on 1.0.0 and on the
28-
// latest version, so its tool results set both.
29-
const textResult = text => {
30-
const blocks = [{ type: 'text', text }];
31-
return { output: blocks, content: blocks };
32-
};
33-
3427
const dataDir = fileURLToPath(new URL('../.data/', import.meta.url));
3528
mkdirSync(dataDir, { recursive: true });
3629

@@ -44,9 +37,9 @@ const tools = [
4437
parameters: Type.Object({ city: Type.String() }),
4538
// The manual span should nest under the SDK's `execute_tool` span.
4639
execute: async args =>
47-
Sentry.startSpan({ name: 'resolve-weather', attributes: { 'weather.city': args.city } }, () =>
48-
textResult(`It is 21 degrees and sunny in ${args.city}.`),
49-
),
40+
Sentry.startSpan({ name: 'resolve-weather', attributes: { 'weather.city': args.city } }, () => ({
41+
output: [{ type: 'text', text: `It is 21 degrees and sunny in ${args.city}.` }],
42+
})),
5043
}),
5144
defineTool({
5245
name: 'fail_now',
@@ -67,7 +60,7 @@ const tools = [
6760
try {
6861
writeFileSync(`${dataDir}crashed-${args.job}`, 'crashed once', { flag: 'wx' });
6962
} catch {
70-
return textResult(`Step of job ${args.job} completed.`);
63+
return { output: [{ type: 'text', text: `Step of job ${args.job} completed.` }] };
7164
}
7265
process.exit(CRASH_EXIT_CODE);
7366
},
@@ -87,14 +80,14 @@ const tools = [
8780
const request = { type: 'input', content: args.task, requestId: `delegate:${api.taskId}` };
8881
const settled = await (await child.submit(request, toolContext)).wait(toolContext);
8982
if (settled.status !== 'done') {
90-
return { isError: true, ...textResult(`Subagent ended: ${settled.reason}`) };
83+
return { isError: true, output: [{ type: 'text', text: `Subagent ended: ${settled.reason}` }] };
9184
}
9285
const answer = await api.commit(tx => tx.entry(AssistantEntry, settled.answer), toolContext);
9386
const text = (answer?.model?.[0]?.content ?? [])
9487
.filter(part => part.type === 'text')
9588
.map(part => part.text)
9689
.join('');
97-
return textResult(text);
90+
return { output: [{ type: 'text', text }] };
9891
},
9992
}),
10093
];

0 commit comments

Comments
 (0)