@theia/ai-openai 1.77.0-next.99 → 1.77.0
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/lib/browser/openai-frontend-application-contribution.d.ts +1 -1
- package/lib/browser/openai-frontend-application-contribution.d.ts.map +1 -1
- package/lib/browser/openai-frontend-application-contribution.js +55 -60
- package/lib/browser/openai-frontend-application-contribution.js.map +1 -1
- package/lib/browser/openai-frontend-application-contribution.spec.js +13 -15
- package/lib/browser/openai-frontend-application-contribution.spec.js.map +1 -1
- package/lib/browser/openai-frontend-module.js +13 -15
- package/lib/browser/openai-frontend-module.js.map +1 -1
- package/lib/common/index.d.ts +1 -1
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +1 -4
- package/lib/common/index.js.map +1 -1
- package/lib/common/openai-language-models-manager.js +3 -6
- package/lib/common/openai-language-models-manager.js.map +1 -1
- package/lib/common/openai-preferences.js +52 -55
- package/lib/common/openai-preferences.js.map +1 -1
- package/lib/node/openai-backend-module.d.ts.map +1 -1
- package/lib/node/openai-backend-module.js +31 -31
- package/lib/node/openai-backend-module.js.map +1 -1
- package/lib/node/openai-chat-completion-stream.d.ts +6 -9
- package/lib/node/openai-chat-completion-stream.d.ts.map +1 -1
- package/lib/node/openai-chat-completion-stream.js +34 -43
- package/lib/node/openai-chat-completion-stream.js.map +1 -1
- package/lib/node/openai-chat-completion-stream.spec.js +159 -76
- package/lib/node/openai-chat-completion-stream.spec.js.map +1 -1
- package/lib/node/openai-language-model.d.ts +4 -3
- package/lib/node/openai-language-model.d.ts.map +1 -1
- package/lib/node/openai-language-model.js +68 -76
- package/lib/node/openai-language-model.js.map +1 -1
- package/lib/node/openai-language-model.spec.js +137 -75
- package/lib/node/openai-language-model.spec.js.map +1 -1
- package/lib/node/openai-language-models-manager-impl.d.ts +3 -3
- package/lib/node/openai-language-models-manager-impl.d.ts.map +1 -1
- package/lib/node/openai-language-models-manager-impl.js +29 -36
- package/lib/node/openai-language-models-manager-impl.js.map +1 -1
- package/lib/node/openai-language-models-manager-impl.spec.js +34 -36
- package/lib/node/openai-language-models-manager-impl.spec.js.map +1 -1
- package/lib/node/openai-model-defaults.d.ts +1 -1
- package/lib/node/openai-model-defaults.d.ts.map +1 -1
- package/lib/node/openai-model-defaults.js +1 -4
- package/lib/node/openai-model-defaults.js.map +1 -1
- package/lib/node/openai-model-defaults.spec.js +52 -54
- package/lib/node/openai-model-defaults.spec.js.map +1 -1
- package/lib/node/openai-model-utils.d.ts +1 -1
- package/lib/node/openai-model-utils.d.ts.map +1 -1
- package/lib/node/openai-model-utils.js +14 -17
- package/lib/node/openai-model-utils.js.map +1 -1
- package/lib/node/openai-model-utils.spec.js +45 -47
- package/lib/node/openai-model-utils.spec.js.map +1 -1
- package/lib/node/openai-reasoning.js +1 -4
- package/lib/node/openai-reasoning.js.map +1 -1
- package/lib/node/openai-request-settings.js +9 -13
- package/lib/node/openai-request-settings.js.map +1 -1
- package/lib/node/openai-response-api-utils.d.ts +5 -3
- package/lib/node/openai-response-api-utils.d.ts.map +1 -1
- package/lib/node/openai-response-api-utils.js +84 -70
- package/lib/node/openai-response-api-utils.js.map +1 -1
- package/lib/node/openai-response-api-utils.spec.js +320 -166
- package/lib/node/openai-response-api-utils.spec.js.map +1 -1
- package/lib/node/openai-server-tools.js +4 -7
- package/lib/node/openai-server-tools.js.map +1 -1
- package/lib/node/openai-streaming-iterator.d.ts +2 -1
- package/lib/node/openai-streaming-iterator.d.ts.map +1 -1
- package/lib/node/openai-streaming-iterator.js +5 -8
- package/lib/node/openai-streaming-iterator.js.map +1 -1
- package/lib/node/openai-streaming-iterator.spec.js +37 -40
- package/lib/node/openai-streaming-iterator.spec.js.map +1 -1
- package/lib/node/openai-streaming-retry.d.ts +8 -0
- package/lib/node/openai-streaming-retry.d.ts.map +1 -0
- package/lib/node/openai-streaming-retry.js +108 -0
- package/lib/node/openai-streaming-retry.js.map +1 -0
- package/lib/node/openai-streaming-retry.spec.d.ts +2 -0
- package/lib/node/openai-streaming-retry.spec.d.ts.map +1 -0
- package/lib/node/openai-streaming-retry.spec.js +182 -0
- package/lib/node/openai-streaming-retry.spec.js.map +1 -0
- package/lib/node/streaming-response-iterator.js +5 -9
- package/lib/node/streaming-response-iterator.js.map +1 -1
- package/lib/node/streaming-response-iterator.spec.js +6 -8
- package/lib/node/streaming-response-iterator.spec.js.map +1 -1
- package/package.json +16 -7
- package/src/browser/openai-frontend-application-contribution.spec.ts +3 -3
- package/src/browser/openai-frontend-application-contribution.ts +2 -2
- package/src/browser/openai-frontend-module.ts +3 -3
- package/src/common/index.ts +1 -1
- package/src/node/openai-backend-module.ts +9 -7
- package/src/node/openai-chat-completion-stream.spec.ts +88 -3
- package/src/node/openai-chat-completion-stream.ts +20 -15
- package/src/node/openai-language-model.spec.ts +84 -7
- package/src/node/openai-language-model.ts +37 -32
- package/src/node/openai-language-models-manager-impl.spec.ts +3 -3
- package/src/node/openai-language-models-manager-impl.ts +4 -4
- package/src/node/openai-model-defaults.spec.ts +1 -1
- package/src/node/openai-model-defaults.ts +1 -1
- package/src/node/openai-model-utils.spec.ts +2 -2
- package/src/node/openai-model-utils.ts +2 -2
- package/src/node/openai-request-settings.ts +1 -1
- package/src/node/openai-response-api-utils.spec.ts +180 -27
- package/src/node/openai-response-api-utils.ts +45 -21
- package/src/node/openai-streaming-iterator.spec.ts +1 -1
- package/src/node/openai-streaming-iterator.ts +2 -1
- package/src/node/openai-streaming-retry.spec.ts +195 -0
- package/src/node/openai-streaming-retry.ts +110 -0
- package/src/node/streaming-response-iterator.spec.ts +1 -1
- package/lib/node/openai-request-api-context.d.ts +0 -4
- package/lib/node/openai-request-api-context.d.ts.map +0 -1
- package/lib/node/openai-request-api-context.js +0 -19
- package/lib/node/openai-request-api-context.js.map +0 -1
- package/src/node/openai-request-api-context.ts +0 -23
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import * as sinon from 'sinon';
|
|
19
|
+
import { CancellationError, CancellationToken, CancellationTokenSource } from '@theia/core';
|
|
20
|
+
import { Container, injectable } from '@theia/core/shared/inversify';
|
|
21
|
+
import { OpenAiStreamingRetry } from './openai-streaming-retry.js';
|
|
22
|
+
|
|
23
|
+
async function* events(...values: unknown[]): AsyncIterable<unknown> {
|
|
24
|
+
yield* values;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function collect(stream: AsyncIterable<unknown>): Promise<{ values: unknown[]; error?: unknown }> {
|
|
28
|
+
const values: unknown[] = [];
|
|
29
|
+
try {
|
|
30
|
+
for await (const value of stream) {
|
|
31
|
+
values.push(value);
|
|
32
|
+
}
|
|
33
|
+
return { values };
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return { values, error };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const busy = { type: 'response.failed', response: { error: { code: 'server_error', message: 'The server is too busy.' } } };
|
|
40
|
+
const lifecycle = { type: 'response.created' };
|
|
41
|
+
const output = { type: 'response.output_text.delta', delta: 'answer' };
|
|
42
|
+
|
|
43
|
+
describe('OpenAiStreamingRetry', () => {
|
|
44
|
+
let clock: sinon.SinonFakeTimers;
|
|
45
|
+
let retry: OpenAiStreamingRetry;
|
|
46
|
+
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
clock = sinon.useFakeTimers();
|
|
49
|
+
retry = new OpenAiStreamingRetry();
|
|
50
|
+
});
|
|
51
|
+
afterEach(() => sinon.restore());
|
|
52
|
+
|
|
53
|
+
it('retries a busy failure after lifecycle events without exposing the failure', async () => {
|
|
54
|
+
const open = sinon.stub();
|
|
55
|
+
open.onFirstCall().resolves(events(lifecycle, busy));
|
|
56
|
+
open.onSecondCall().resolves(events(lifecycle, output));
|
|
57
|
+
const result = collect(retry.retry(open, 3, event => event === lifecycle));
|
|
58
|
+
await clock.tickAsync(374);
|
|
59
|
+
expect(open.callCount).to.equal(1);
|
|
60
|
+
await clock.tickAsync(126);
|
|
61
|
+
expect(await result).to.deep.equal({ values: [lifecycle, lifecycle, output] });
|
|
62
|
+
expect(open.callCount).to.equal(2);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
for (const maxRetries of [0, 1, 3]) {
|
|
66
|
+
it(`stops after ${maxRetries} retries and preserves the provider error`, async () => {
|
|
67
|
+
const open = sinon.stub().callsFake(async () => events(busy));
|
|
68
|
+
const result = collect(retry.retry(open, maxRetries, () => true));
|
|
69
|
+
await clock.runAllAsync();
|
|
70
|
+
const { error, values } = await result;
|
|
71
|
+
expect(values).to.be.empty;
|
|
72
|
+
expect(error).to.be.instanceOf(Error).with.property('message', busy.response.error.message);
|
|
73
|
+
expect(error).to.have.property('code', 'server_error');
|
|
74
|
+
expect(open.callCount).to.equal(maxRetries + 1);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (const event of [output, { type: 'response.reasoning_summary_text.delta', delta: 'thinking' },
|
|
79
|
+
{ type: 'response.output_item.added', item: { type: 'function_call' } },
|
|
80
|
+
{ type: 'response.output_item.added', item: { type: 'web_search_call' } }]) {
|
|
81
|
+
it(`does not replay a response after ${JSON.stringify(event)}`, async () => {
|
|
82
|
+
const open = sinon.stub().callsFake(async () => events(lifecycle, event, busy));
|
|
83
|
+
const result = await collect(retry.retry(open, 3, value => value === lifecycle));
|
|
84
|
+
expect(result.values).to.deep.equal([lifecycle, event]);
|
|
85
|
+
expect(result.error).to.have.property('code', 'server_error');
|
|
86
|
+
expect(open.callCount).to.equal(1);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const error of [
|
|
91
|
+
{ code: 'rate_limit_exceeded', message: 'Slow down' },
|
|
92
|
+
{ type: 'overloaded_error', message: 'Overloaded' },
|
|
93
|
+
{ message: 'The server is too busy.' }
|
|
94
|
+
]) {
|
|
95
|
+
it(`retries an error stream event ${JSON.stringify(error)}`, async () => {
|
|
96
|
+
const open = sinon.stub();
|
|
97
|
+
open.onFirstCall().resolves(events({ ...error, type: 'error' }));
|
|
98
|
+
// SSE error events use `code`; SDK-thrown errors may instead carry an overloaded `type`.
|
|
99
|
+
if (error.type) {
|
|
100
|
+
open.onFirstCall().callsFake(async () => (async function* (): AsyncIterable<unknown> { throw Object.assign(new Error(error.message), error); })());
|
|
101
|
+
}
|
|
102
|
+
open.onSecondCall().resolves(events(output));
|
|
103
|
+
const result = collect(retry.retry(open, 1, () => true));
|
|
104
|
+
await clock.runAllAsync();
|
|
105
|
+
expect(await result).to.deep.equal({ values: [output] });
|
|
106
|
+
expect(open.callCount).to.equal(2);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (const code of ['insufficient_quota', 'billing_hard_limit_reached', 'invalid_api_key', 'invalid_request_error']) {
|
|
111
|
+
it(`does not retry ${code}`, async () => {
|
|
112
|
+
const open = sinon.stub().callsFake(async () => events({ type: 'error', code, message: 'Too busy' }));
|
|
113
|
+
const result = await collect(retry.retry(open, 3, () => true));
|
|
114
|
+
expect(result.error).to.have.property('code', code);
|
|
115
|
+
expect(open.callCount).to.equal(1);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
it('allows adopters to rebind the retry service with gateway-specific overload codes', async () => {
|
|
120
|
+
@injectable()
|
|
121
|
+
class GatewayStreamingRetry extends OpenAiStreamingRetry {
|
|
122
|
+
protected override isTransientStreamError(error: unknown): boolean {
|
|
123
|
+
return (error as { code?: string }).code === 'gateway_overloaded' || super.isTransientStreamError(error);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const container = new Container();
|
|
127
|
+
container.bind(OpenAiStreamingRetry).toSelf();
|
|
128
|
+
container.rebind(OpenAiStreamingRetry).to(GatewayStreamingRetry);
|
|
129
|
+
const open = sinon.stub();
|
|
130
|
+
open.onFirstCall().resolves(events({ type: 'error', code: 'gateway_overloaded', message: 'Try again' }));
|
|
131
|
+
open.onSecondCall().resolves(events(output));
|
|
132
|
+
const result = collect(container.get(OpenAiStreamingRetry).retry(open, 1, () => true));
|
|
133
|
+
await clock.runAllAsync();
|
|
134
|
+
expect(await result).to.deep.equal({ values: [output] });
|
|
135
|
+
expect(open.callCount).to.equal(2);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('does not add retries to an opening failure already handled by the SDK', async () => {
|
|
139
|
+
const error = Object.assign(new Error('Service unavailable'), { status: 503 });
|
|
140
|
+
const open = sinon.stub().rejects(error);
|
|
141
|
+
expect((await collect(retry.retry(open, 3, () => true))).error).to.equal(error);
|
|
142
|
+
expect(open.callCount).to.equal(1);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('reports a failed response with no error details instead of silently ending', async () => {
|
|
146
|
+
const open = sinon.stub().resolves(events({ type: 'response.failed', response: {} }));
|
|
147
|
+
const result = await collect(retry.retry(open, 3, () => true));
|
|
148
|
+
expect(result.error).to.be.instanceOf(Error).with.property('message', 'OpenAI response failed.');
|
|
149
|
+
expect(open.callCount).to.equal(1);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('cancels during backoff without sending again', async () => {
|
|
153
|
+
const source = new CancellationTokenSource();
|
|
154
|
+
const open = sinon.stub().callsFake(async () => events(busy));
|
|
155
|
+
const result = collect(retry.retry(open, 3, () => true, source.token));
|
|
156
|
+
await clock.tickAsync(0);
|
|
157
|
+
source.cancel();
|
|
158
|
+
expect((await result).error).to.be.instanceOf(CancellationError);
|
|
159
|
+
await clock.runAllAsync();
|
|
160
|
+
expect(open.callCount).to.equal(1);
|
|
161
|
+
expect((open.firstCall.args[0] as AbortSignal).aborted).to.equal(true);
|
|
162
|
+
source.dispose();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('reports cancellation when the upstream iterator finishes normally on abort', async () => {
|
|
166
|
+
const source = new CancellationTokenSource();
|
|
167
|
+
const open = sinon.stub().callsFake(async (signal: AbortSignal) => (async function* (): AsyncIterable<unknown> {
|
|
168
|
+
yield lifecycle;
|
|
169
|
+
await new Promise<void>(resolve => signal.addEventListener('abort', () => resolve(), { once: true }));
|
|
170
|
+
})());
|
|
171
|
+
const result = collect(retry.retry(open, 3, () => true, source.token));
|
|
172
|
+
await clock.tickAsync(0);
|
|
173
|
+
source.cancel();
|
|
174
|
+
expect((await result).error).to.be.instanceOf(CancellationError);
|
|
175
|
+
expect(open.callCount).to.equal(1);
|
|
176
|
+
source.dispose();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('does not open a cancelled request', async () => {
|
|
180
|
+
const open = sinon.stub();
|
|
181
|
+
const result = await collect(retry.retry(open, 3, () => true, CancellationToken.Cancelled));
|
|
182
|
+
expect(result.error).to.be.instanceOf(CancellationError);
|
|
183
|
+
expect(open.called).to.equal(false);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('aborts the upstream request when the consumer stops reading', async () => {
|
|
187
|
+
const open = sinon.stub().resolves(events(lifecycle, output));
|
|
188
|
+
for await (const event of retry.retry(open, 3, () => true)) {
|
|
189
|
+
expect(event).to.equal(lifecycle);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
expect((open.firstCall.args[0] as AbortSignal).aborted).to.equal(true);
|
|
193
|
+
expect(open.callCount).to.equal(1);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { CancellationError, CancellationToken, isObject } from '@theia/core';
|
|
18
|
+
import { timeout } from '@theia/core/lib/common/promise-util';
|
|
19
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
|
|
21
|
+
@injectable()
|
|
22
|
+
export class OpenAiStreamingRetry {
|
|
23
|
+
|
|
24
|
+
protected streamError(event: unknown): Error | undefined {
|
|
25
|
+
if (!isObject(event)) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const error = event.type === 'response.failed' && isObject(event.response) ? event.response.error
|
|
29
|
+
: event.type === 'error' ? event : undefined;
|
|
30
|
+
if (!isObject(error)) {
|
|
31
|
+
return event.type === 'response.failed' ? new Error('OpenAI response failed.') : undefined;
|
|
32
|
+
}
|
|
33
|
+
return Object.assign(new Error(typeof error.message === 'string' ? error.message : 'OpenAI response failed.'), {
|
|
34
|
+
code: error.code,
|
|
35
|
+
type: error.type === 'error' ? undefined : error.type,
|
|
36
|
+
param: error.param
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected isTransientStreamError(error: unknown): boolean {
|
|
41
|
+
if (!isObject(error)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (error.code === 'insufficient_quota' || error.code === 'billing_hard_limit_reached') {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (typeof error.status === 'number') {
|
|
48
|
+
return error.status === 408 || error.status === 409 || error.status === 429 || error.status >= 500;
|
|
49
|
+
}
|
|
50
|
+
const transientCodes = ['server_error', 'rate_limit_exceeded', 'overloaded_error', 'server_overloaded', 'engine_overloaded', 'model_overloaded'];
|
|
51
|
+
return transientCodes.includes(String(error.code)) || transientCodes.includes(String(error.type))
|
|
52
|
+
|| (!error.code && !error.type && typeof error.message === 'string' && /\b(overloaded|too busy)\b/i.test(error.message));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Retries stream failures only before output/tool activity. Opening failures are already retried by the SDK. */
|
|
56
|
+
async *retry<T>(
|
|
57
|
+
open: (signal: AbortSignal) => Promise<AsyncIterable<T>>,
|
|
58
|
+
maxRetries: number,
|
|
59
|
+
canRetryAfter: (event: T) => boolean,
|
|
60
|
+
cancellationToken: CancellationToken = CancellationToken.None
|
|
61
|
+
): AsyncIterable<T> {
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
const listener = cancellationToken.onCancellationRequested(() => controller.abort());
|
|
64
|
+
let retries = 0;
|
|
65
|
+
let safeToRetry = true;
|
|
66
|
+
try {
|
|
67
|
+
while (true) {
|
|
68
|
+
if (cancellationToken.isCancellationRequested) {
|
|
69
|
+
throw new CancellationError();
|
|
70
|
+
}
|
|
71
|
+
// Keep this outside the catch: don't multiply the SDK's HTTP/connection retry budget.
|
|
72
|
+
const stream = await open(controller.signal);
|
|
73
|
+
try {
|
|
74
|
+
for await (const event of stream) {
|
|
75
|
+
if (cancellationToken.isCancellationRequested) {
|
|
76
|
+
throw new CancellationError();
|
|
77
|
+
}
|
|
78
|
+
const error = this.streamError(event);
|
|
79
|
+
if (error) {
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
safeToRetry = safeToRetry && canRetryAfter(event);
|
|
83
|
+
yield event;
|
|
84
|
+
}
|
|
85
|
+
if (cancellationToken.isCancellationRequested) {
|
|
86
|
+
throw new CancellationError();
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (cancellationToken.isCancellationRequested) {
|
|
91
|
+
throw new CancellationError();
|
|
92
|
+
}
|
|
93
|
+
if (!safeToRetry || retries >= maxRetries || !this.isTransientStreamError(error)) {
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
const delay = Math.min(500 * 2 ** retries++, 8000) * (1 - 0.25 * Math.random());
|
|
97
|
+
await timeout(delay, cancellationToken);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (cancellationToken.isCancellationRequested) {
|
|
102
|
+
throw new CancellationError();
|
|
103
|
+
}
|
|
104
|
+
throw error;
|
|
105
|
+
} finally {
|
|
106
|
+
listener.dispose();
|
|
107
|
+
controller.abort();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { expect } from 'chai';
|
|
18
18
|
import { LanguageModelStreamResponsePart } from '@theia/ai-core';
|
|
19
|
-
import { AbstractStreamingResponseIterator } from './streaming-response-iterator';
|
|
19
|
+
import { AbstractStreamingResponseIterator } from './streaming-response-iterator.js';
|
|
20
20
|
|
|
21
21
|
class TestIterator extends AbstractStreamingResponseIterator {
|
|
22
22
|
push(part: LanguageModelStreamResponsePart): void {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai-request-api-context.d.ts","sourceRoot":"","sources":["../../src/node/openai-request-api-context.ts"],"names":[],"mappings":"AAgBA,UAAU,uBAAuB;IAC7B,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAEpC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2025 EclipseSource GmbH.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
// export class OpenAIRequestApiContext {
|
|
18
|
-
// }
|
|
19
|
-
//# sourceMappingURL=openai-request-api-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai-request-api-context.js","sourceRoot":"","sources":["../../src/node/openai-request-api-context.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAOhF,yCAAyC;AACzC,IAAI"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2025 EclipseSource GmbH.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
interface OpenAIRequestApiContext {
|
|
18
|
-
parent?: OpenAIRequestApiContext;
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// export class OpenAIRequestApiContext {
|
|
23
|
-
// }
|