Skip to content

Commit 2df55d5

Browse files
committed
Fix #216 Publicly accessible PDF file URL is not yet supported in the input_file content data
1 parent 9e718c0 commit 2df55d5

File tree

9 files changed

+68
-19
lines changed

9 files changed

+68
-19
lines changed

examples/basic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"start:previous-response-id": "tsx previous-response-id.ts",
1818
"start:prompt": "tsx prompt-id.ts",
1919
"start:remote-image": "tsx remote-image.ts",
20+
"start:remote-pdf": "tsx remote-pdf.ts",
2021
"start:stream-items": "tsx stream-items.ts",
2122
"start:stream-text": "tsx stream-text.ts",
2223
"start:json-schema-output-type": "tsx json-schema-output-type.ts",

examples/basic/remote-pdf.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Agent, run } from '@openai/agents';
2+
3+
const URL = 'https://www.berkshirehathaway.com/letters/2024ltr.pdf';
4+
5+
async function main() {
6+
const agent = new Agent({
7+
name: 'Assistant',
8+
instructions: 'You are a helpful assistant.',
9+
});
10+
11+
const result = await run(agent, [
12+
{
13+
role: 'user',
14+
content: [{ type: 'input_file', file: URL }],
15+
},
16+
{
17+
role: 'user',
18+
content: 'Can you summarize the letter?',
19+
},
20+
]);
21+
22+
console.log(result.finalOutput);
23+
}
24+
25+
if (require.main === module) {
26+
main().catch(console.error);
27+
}

examples/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@openai/agents-extensions": "workspace:*",
99
"@ai-sdk/openai": "^1.0.0",
1010
"server-only": "^0.0.1",
11-
"openai": "^5.0.1",
11+
"openai": "^5.10.1",
1212
"zod": "3.25.40 - 3.25.67"
1313
},
1414
"scripts": {

packages/agents-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"dependencies": {
9191
"@openai/zod": "npm:[email protected] - 3.25.67",
9292
"debug": "^4.4.0",
93-
"openai": "^5.0.1"
93+
"openai": "^5.10.1"
9494
},
9595
"peerDependencies": {
9696
"zod": "3.25.40 - 3.25.67"

packages/agents-core/src/types/protocol.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,17 @@ export const InputFile = SharedBase.extend({
9191
*/
9292
file: z
9393
.string()
94+
.describe(
95+
'Either base64 encoded file data or a publicly accessible file URL',
96+
)
9497
.or(
9598
z.object({
96-
id: z.string(),
99+
id: z.string().describe('OpenAI file ID'),
100+
}),
101+
)
102+
.or(
103+
z.object({
104+
url: z.string().describe('Publicly accessible PDF file URL'),
97105
}),
98106
)
99107
.describe('Contents of the file or an object with a file ID.'),

packages/agents-openai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dependencies": {
2121
"@openai/agents-core": "workspace:*",
2222
"debug": "^4.4.0",
23-
"openai": "^5.0.1",
23+
"openai": "^5.10.1",
2424
"@openai/zod": "npm:[email protected] - 3.25.67"
2525
},
2626
"scripts": {

packages/agents-openai/src/openaiResponsesModel.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,19 @@ function getInputMessageContent(
265265
type: 'input_file',
266266
};
267267
if (typeof entry.file === 'string') {
268-
fileEntry.file_data = entry.file;
269-
} else {
268+
if (entry.file.startsWith('data:')) {
269+
fileEntry.file_data = entry.file;
270+
} else if (entry.file.startsWith('https://')) {
271+
fileEntry.file_url = entry.file;
272+
} else {
273+
throw new UserError(
274+
`Unsupported string data for file input. If you're trying to pass an uploaded file's ID, use an object with the ID property instead.`,
275+
);
276+
}
277+
} else if ('id' in entry.file) {
270278
fileEntry.file_id = entry.file.id;
279+
} else if ('url' in entry.file) {
280+
fileEntry.file_url = entry.file.url;
271281
}
272282
return {
273283
...fileEntry,
@@ -525,7 +535,10 @@ function getInputItems(
525535
type: 'code_interpreter_call',
526536
id: item.id!,
527537
code: item.providerData?.code ?? '',
528-
results: item.providerData?.results ?? [],
538+
// This property used to be results, so keeping both for backward compatibility
539+
// That said, this property cannot be passed from a user, so it's just API's internal data.
540+
outputs:
541+
item.providerData?.outputs ?? item.providerData?.results ?? [],
529542
status: CodeInterpreterStatus.parse(item.status ?? 'failed'),
530543
container_id: item.providerData?.containerId,
531544
};

packages/agents/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@openai/agents-core": "workspace:*",
4343
"@openai/agents-openai": "workspace:*",
4444
"@openai/agents-realtime": "workspace:*",
45-
"openai": "^5.0.1",
45+
"openai": "^5.10.1",
4646
"debug": "^4.4.0"
4747
},
4848
"keywords": [

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)