@openai/agents-openai 0.6.0 → 0.7.1

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.
@@ -0,0 +1,95 @@
1
+ function isRecord(value) {
2
+ return typeof value === 'object' && value !== null;
3
+ }
4
+ function isUnsafeToReplayError(error) {
5
+ return isRecord(error) && error.unsafeToReplay === true;
6
+ }
7
+ function getHeaderValue(error, key) {
8
+ if (!isRecord(error)) {
9
+ return undefined;
10
+ }
11
+ const headerSources = [error.headers, error.responseHeaders];
12
+ for (const source of headerSources) {
13
+ if (!source) {
14
+ continue;
15
+ }
16
+ if (typeof Headers !== 'undefined' && source instanceof Headers) {
17
+ return source.get(key) ?? undefined;
18
+ }
19
+ if (isRecord(source)) {
20
+ const normalizedKey = key.toLowerCase();
21
+ for (const [headerName, headerValue] of Object.entries(source)) {
22
+ if (headerName.toLowerCase() === normalizedKey &&
23
+ typeof headerValue === 'string') {
24
+ return headerValue;
25
+ }
26
+ }
27
+ }
28
+ }
29
+ return undefined;
30
+ }
31
+ function getStatusCode(error) {
32
+ if (!isRecord(error)) {
33
+ return undefined;
34
+ }
35
+ if (typeof error.statusCode === 'number') {
36
+ return error.statusCode;
37
+ }
38
+ if (typeof error.status === 'number') {
39
+ return error.status;
40
+ }
41
+ return undefined;
42
+ }
43
+ function isStatefulReplayRequest(request) {
44
+ return Boolean(request.conversationId || request.previousResponseId);
45
+ }
46
+ export function getOpenAIRetryAdvice(args) {
47
+ const { error, request } = args;
48
+ if (isUnsafeToReplayError(error)) {
49
+ return {
50
+ suggested: false,
51
+ replaySafety: 'unsafe',
52
+ reason: error instanceof Error ? error.message : undefined,
53
+ };
54
+ }
55
+ const errorMessage = error instanceof Error ? error.message.toLowerCase() : undefined;
56
+ const shouldRetryHeader = getHeaderValue(error, 'x-should-retry')
57
+ ?.toLowerCase()
58
+ .trim();
59
+ if (errorMessage?.includes('the request may have been accepted, so the sdk will not automatically retry this websocket request.')) {
60
+ return {
61
+ suggested: false,
62
+ replaySafety: 'unsafe',
63
+ reason: error instanceof Error ? error.message : undefined,
64
+ };
65
+ }
66
+ if (shouldRetryHeader === 'true') {
67
+ return {
68
+ suggested: true,
69
+ replaySafety: 'safe',
70
+ reason: error instanceof Error ? error.message : undefined,
71
+ };
72
+ }
73
+ if (shouldRetryHeader === 'false') {
74
+ return {
75
+ suggested: false,
76
+ reason: error instanceof Error ? error.message : undefined,
77
+ };
78
+ }
79
+ const statusCode = getStatusCode(error);
80
+ if (!isStatefulReplayRequest(request) &&
81
+ // Mirror the OpenAI SDK fallback retry statuses when x-should-retry is absent.
82
+ // This is specific to the OpenAI provider contract and should not automatically
83
+ // be mirrored in the AI SDK adapter, which depends on provider-specific guidance.
84
+ (statusCode === 408 ||
85
+ statusCode === 409 ||
86
+ statusCode === 429 ||
87
+ (typeof statusCode === 'number' && statusCode >= 500))) {
88
+ return {
89
+ suggested: true,
90
+ reason: error instanceof Error ? error.message : undefined,
91
+ };
92
+ }
93
+ return undefined;
94
+ }
95
+ //# sourceMappingURL=retryAdvice.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryAdvice.mjs","sourceRoot":"","sources":["../src/retryAdvice.ts"],"names":[],"mappings":"AAKA,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,cAAc,KAAK,IAAI,CAAC;AAC1D,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,GAAW;IACjD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,aAAa,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IAC7D,KAAK,MAAM,MA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O,CAAC;QACjC,+EAA+E;QAC/E,gFAAgF;QAChF,kFAAkF;QAClF,CAAC,UAAU,KAAK,GAAG;YACjB,UAAU,KAAK,GAAG;YAClB,UAAU,KAAK,GAAG;YAClB,CAAC,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,IAAI,GAAG,CAAC,CAAC,EACxD,CAAC;QACD,OAAO;YACL,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;SAC3D,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@openai/agents-openai",
3
3
  "repository": "https://github.com/openai/openai-agents-js",
4
4
  "homepage": "https://openai.github.io/openai-agents-js/",
5
- "version": "0.6.0",
5
+ "version": "0.7.1",
6
6
  "description": "The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.",
7
7
  "author": "OpenAI <support@openai.com>",
8
8
  "main": "dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "debug": "^4.4.0",
19
19
  "openai": "^6.26.0",
20
- "@openai/agents-core": "0.6.0"
20
+ "@openai/agents-core": "0.7.1"
21
21
  },
22
22
  "keywords": [
23
23
  "openai",