@livekit/agents-plugin-openai 1.4.1 → 1.4.3
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/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/realtime/realtime_model.cjs +3 -0
- package/dist/realtime/realtime_model.cjs.map +1 -1
- package/dist/realtime/realtime_model.d.cts +1 -0
- package/dist/realtime/realtime_model.d.ts +1 -0
- package/dist/realtime/realtime_model.d.ts.map +1 -1
- package/dist/realtime/realtime_model.js +3 -0
- package/dist/realtime/realtime_model.js.map +1 -1
- package/dist/stt.cjs +20 -14
- package/dist/stt.cjs.map +1 -1
- package/dist/stt.d.cts +13 -0
- package/dist/stt.d.ts +13 -0
- package/dist/stt.d.ts.map +1 -1
- package/dist/stt.js +18 -13
- package/dist/stt.js.map +1 -1
- package/dist/stt.test.cjs +34 -0
- package/dist/stt.test.cjs.map +1 -1
- package/dist/stt.test.js +35 -1
- package/dist/stt.test.js.map +1 -1
- package/dist/ws/llm.cjs +11 -3
- package/dist/ws/llm.cjs.map +1 -1
- package/dist/ws/llm.d.cts +13 -0
- package/dist/ws/llm.d.ts +13 -0
- package/dist/ws/llm.d.ts.map +1 -1
- package/dist/ws/llm.js +9 -2
- package/dist/ws/llm.js.map +1 -1
- package/dist/ws/llm.test.cjs +48 -18
- package/dist/ws/llm.test.cjs.map +1 -1
- package/dist/ws/llm.test.js +49 -19
- package/dist/ws/llm.test.js.map +1 -1
- package/package.json +5 -5
- package/src/realtime/realtime_model.ts +4 -0
- package/src/stt.test.ts +44 -1
- package/src/stt.ts +32 -14
- package/src/ws/llm.test.ts +55 -19
- package/src/ws/llm.ts +22 -3
package/dist/ws/llm.test.js
CHANGED
|
@@ -1,25 +1,55 @@
|
|
|
1
1
|
import { initializeLogger } from "@livekit/agents";
|
|
2
2
|
import { llm, llmStrict } from "@livekit/agents-plugins-test";
|
|
3
|
-
import { describe } from "vitest";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { LLM } from "../responses/llm.js";
|
|
5
|
+
import { buildResponsesWsUrl } from "./llm.js";
|
|
5
6
|
initializeLogger({ level: "silent", pretty: false });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
const hasOpenAIApiKey = Boolean(process.env.OPENAI_API_KEY);
|
|
8
|
+
describe("buildResponsesWsUrl", () => {
|
|
9
|
+
it("points at the OpenAI Responses WS endpoint with model when no baseURL is set", () => {
|
|
10
|
+
const url = new URL(buildResponsesWsUrl(void 0, "gpt-4.1"));
|
|
11
|
+
expect(url.protocol).toBe("wss:");
|
|
12
|
+
expect(url.host).toBe("api.openai.com");
|
|
13
|
+
expect(url.pathname).toBe("/v1/responses");
|
|
14
|
+
expect(url.searchParams.get("model")).toBe("gpt-4.1");
|
|
15
|
+
});
|
|
16
|
+
it("rewrites https baseURL to wss and appends /responses with the model", () => {
|
|
17
|
+
const url = new URL(buildResponsesWsUrl("https://gateway.example.com/v1", "gpt-4o"));
|
|
18
|
+
expect(url.protocol).toBe("wss:");
|
|
19
|
+
expect(url.host).toBe("gateway.example.com");
|
|
20
|
+
expect(url.pathname).toBe("/v1/responses");
|
|
21
|
+
expect(url.searchParams.get("model")).toBe("gpt-4o");
|
|
22
|
+
});
|
|
23
|
+
it("strips a trailing slash on baseURL before appending /responses", () => {
|
|
24
|
+
const url = new URL(buildResponsesWsUrl("https://gateway.example.com/v1/", "gpt-4o-mini"));
|
|
25
|
+
expect(url.pathname).toBe("/v1/responses");
|
|
26
|
+
expect(url.searchParams.get("model")).toBe("gpt-4o-mini");
|
|
27
|
+
});
|
|
24
28
|
});
|
|
29
|
+
if (hasOpenAIApiKey) {
|
|
30
|
+
describe("OpenAI Responses WS wrapper", async () => {
|
|
31
|
+
await llm(
|
|
32
|
+
new LLM({
|
|
33
|
+
temperature: 0,
|
|
34
|
+
strictToolSchema: false,
|
|
35
|
+
useWebSocket: true
|
|
36
|
+
}),
|
|
37
|
+
true
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
describe("OpenAI Responses WS wrapper strict tool schema", async () => {
|
|
41
|
+
await llmStrict(
|
|
42
|
+
new LLM({
|
|
43
|
+
temperature: 0,
|
|
44
|
+
strictToolSchema: true,
|
|
45
|
+
useWebSocket: true
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
describe("OpenAI Responses WS wrapper", () => {
|
|
51
|
+
it.skip("requires OPENAI_API_KEY", () => {
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
25
55
|
//# sourceMappingURL=llm.test.js.map
|
package/dist/ws/llm.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ws/llm.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { initializeLogger } from '@livekit/agents';\nimport { llm, llmStrict } from '@livekit/agents-plugins-test';\nimport { describe } from 'vitest';\nimport { LLM } from '../responses/llm.js';\n\ninitializeLogger({ level: 'silent', pretty: false });\n\ndescribe('OpenAI Responses WS wrapper', async () => {\n
|
|
1
|
+
{"version":3,"sources":["../../src/ws/llm.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { initializeLogger } from '@livekit/agents';\nimport { llm, llmStrict } from '@livekit/agents-plugins-test';\nimport { describe, expect, it } from 'vitest';\nimport { LLM } from '../responses/llm.js';\nimport { buildResponsesWsUrl } from './llm.js';\n\ninitializeLogger({ level: 'silent', pretty: false });\n\nconst hasOpenAIApiKey = Boolean(process.env.OPENAI_API_KEY);\n\ndescribe('buildResponsesWsUrl', () => {\n it('points at the OpenAI Responses WS endpoint with model when no baseURL is set', () => {\n const url = new URL(buildResponsesWsUrl(undefined, 'gpt-4.1'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('api.openai.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4.1');\n });\n\n it('rewrites https baseURL to wss and appends /responses with the model', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('strips a trailing slash on baseURL before appending /responses', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/', 'gpt-4o-mini'));\n\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n});\n\nif (hasOpenAIApiKey) {\n describe('OpenAI Responses WS wrapper', async () => {\n await llm(\n new LLM({\n temperature: 0,\n strictToolSchema: false,\n useWebSocket: true,\n }),\n true,\n );\n });\n\n describe('OpenAI Responses WS wrapper strict tool schema', async () => {\n await llmStrict(\n new LLM({\n temperature: 0,\n strictToolSchema: true,\n useWebSocket: true,\n }),\n );\n });\n} else {\n describe('OpenAI Responses WS wrapper', () => {\n it.skip('requires OPENAI_API_KEY', () => {});\n });\n}\n"],"mappings":"AAGA,SAAS,wBAAwB;AACjC,SAAS,KAAK,iBAAiB;AAC/B,SAAS,UAAU,QAAQ,UAAU;AACrC,SAAS,WAAW;AACpB,SAAS,2BAA2B;AAEpC,iBAAiB,EAAE,OAAO,UAAU,QAAQ,MAAM,CAAC;AAEnD,MAAM,kBAAkB,QAAQ,QAAQ,IAAI,cAAc;AAE1D,SAAS,uBAAuB,MAAM;AACpC,KAAG,gFAAgF,MAAM;AACvF,UAAM,MAAM,IAAI,IAAI,oBAAoB,QAAW,SAAS,CAAC;AAE7D,WAAO,IAAI,QAAQ,EAAE,KAAK,MAAM;AAChC,WAAO,IAAI,IAAI,EAAE,KAAK,gBAAgB;AACtC,WAAO,IAAI,QAAQ,EAAE,KAAK,eAAe;AACzC,WAAO,IAAI,aAAa,IAAI,OAAO,CAAC,EAAE,KAAK,SAAS;AAAA,EACtD,CAAC;AAED,KAAG,uEAAuE,MAAM;AAC9E,UAAM,MAAM,IAAI,IAAI,oBAAoB,kCAAkC,QAAQ,CAAC;AAEnF,WAAO,IAAI,QAAQ,EAAE,KAAK,MAAM;AAChC,WAAO,IAAI,IAAI,EAAE,KAAK,qBAAqB;AAC3C,WAAO,IAAI,QAAQ,EAAE,KAAK,eAAe;AACzC,WAAO,IAAI,aAAa,IAAI,OAAO,CAAC,EAAE,KAAK,QAAQ;AAAA,EACrD,CAAC;AAED,KAAG,kEAAkE,MAAM;AACzE,UAAM,MAAM,IAAI,IAAI,oBAAoB,mCAAmC,aAAa,CAAC;AAEzF,WAAO,IAAI,QAAQ,EAAE,KAAK,eAAe;AACzC,WAAO,IAAI,aAAa,IAAI,OAAO,CAAC,EAAE,KAAK,aAAa;AAAA,EAC1D,CAAC;AACH,CAAC;AAED,IAAI,iBAAiB;AACnB,WAAS,+BAA+B,YAAY;AAClD,UAAM;AAAA,MACJ,IAAI,IAAI;AAAA,QACN,aAAa;AAAA,QACb,kBAAkB;AAAA,QAClB,cAAc;AAAA,MAChB,CAAC;AAAA,MACD;AAAA,IACF;AAAA,EACF,CAAC;AAED,WAAS,kDAAkD,YAAY;AACrE,UAAM;AAAA,MACJ,IAAI,IAAI;AAAA,QACN,aAAa;AAAA,QACb,kBAAkB;AAAA,QAClB,cAAc;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH,OAAO;AACL,WAAS,+BAA+B,MAAM;AAC5C,OAAG,KAAK,2BAA2B,MAAM;AAAA,IAAC,CAAC;AAAA,EAC7C,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livekit/agents-plugin-openai",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "OpenAI plugin for LiveKit Node Agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"require": "dist/index.cjs",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"@types/ws": "^8.5.10",
|
|
31
31
|
"tsup": "^8.3.5",
|
|
32
32
|
"typescript": "^5.0.0",
|
|
33
|
-
"@livekit/agents": "1.4.
|
|
34
|
-
"@livekit/agents-plugin-silero": "1.4.
|
|
35
|
-
"@livekit/agents-plugins-test": "1.4.
|
|
33
|
+
"@livekit/agents": "1.4.3",
|
|
34
|
+
"@livekit/agents-plugin-silero": "1.4.3",
|
|
35
|
+
"@livekit/agents-plugins-test": "1.4.3"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@livekit/mutex": "^1.1.1",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@livekit/rtc-node": "^0.13.27",
|
|
44
44
|
"zod": "^3.25.76 || ^4.1.8",
|
|
45
|
-
"@livekit/agents": "1.4.
|
|
45
|
+
"@livekit/agents": "1.4.3"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsup --onSuccess \"pnpm build:types\"",
|
package/src/stt.test.ts
CHANGED
|
@@ -5,7 +5,8 @@ import { VAD as BaseVAD, type VADStream } from '@livekit/agents';
|
|
|
5
5
|
import { VAD } from '@livekit/agents-plugin-silero';
|
|
6
6
|
import { stt } from '@livekit/agents-plugins-test';
|
|
7
7
|
import { describe, expect, it, vi } from 'vitest';
|
|
8
|
-
import {
|
|
8
|
+
import type { SpeechStream } from './stt.js';
|
|
9
|
+
import { STT, buildRealtimeSttUrl } from './stt.js';
|
|
9
10
|
|
|
10
11
|
const hasOpenAIApiKey = Boolean(process.env.OPENAI_API_KEY);
|
|
11
12
|
|
|
@@ -72,6 +73,48 @@ describe('OpenAI STT options', () => {
|
|
|
72
73
|
});
|
|
73
74
|
});
|
|
74
75
|
|
|
76
|
+
describe('buildRealtimeSttUrl', () => {
|
|
77
|
+
it('points at OpenAI realtime with intent and model when no baseURL is set', () => {
|
|
78
|
+
const url = new URL(buildRealtimeSttUrl(undefined, 'gpt-realtime-whisper'));
|
|
79
|
+
|
|
80
|
+
expect(url.protocol).toBe('wss:');
|
|
81
|
+
expect(url.host).toBe('api.openai.com');
|
|
82
|
+
expect(url.pathname).toBe('/v1/realtime');
|
|
83
|
+
expect(url.searchParams.get('intent')).toBe('transcription');
|
|
84
|
+
expect(url.searchParams.get('model')).toBe('gpt-realtime-whisper');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('upgrades https baseURL to wss and appends /realtime when path is /v1', () => {
|
|
88
|
+
const url = new URL(
|
|
89
|
+
buildRealtimeSttUrl('https://gateway.example.com/v1', 'gpt-4o-mini-transcribe'),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
expect(url.protocol).toBe('wss:');
|
|
93
|
+
expect(url.host).toBe('gateway.example.com');
|
|
94
|
+
expect(url.pathname).toBe('/v1/realtime');
|
|
95
|
+
expect(url.searchParams.get('model')).toBe('gpt-4o-mini-transcribe');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('preserves an existing /realtime path without duplicating it', () => {
|
|
99
|
+
const url = new URL(
|
|
100
|
+
buildRealtimeSttUrl('wss://gateway.example.com/v1/realtime', 'gpt-realtime-whisper'),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(url.pathname).toBe('/v1/realtime');
|
|
104
|
+
expect(url.searchParams.get('model')).toBe('gpt-realtime-whisper');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('appends /realtime to a non-/v1 path', () => {
|
|
108
|
+
const url = new URL(
|
|
109
|
+
buildRealtimeSttUrl('https://gateway.example.com/proxy/openai', 'gpt-realtime-whisper'),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(url.pathname).toBe('/proxy/openai/realtime');
|
|
113
|
+
expect(url.searchParams.get('intent')).toBe('transcription');
|
|
114
|
+
expect(url.searchParams.get('model')).toBe('gpt-realtime-whisper');
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
75
118
|
if (hasOpenAIApiKey) {
|
|
76
119
|
describe('OpenAI STT integration', async () => {
|
|
77
120
|
const vad = await VAD.load();
|
package/src/stt.ts
CHANGED
|
@@ -24,6 +24,37 @@ import type * as api_proto from './realtime/api_proto.js';
|
|
|
24
24
|
const REALTIME_SAMPLE_RATE = 24000;
|
|
25
25
|
const REALTIME_NUM_CHANNELS = 1;
|
|
26
26
|
const DEFAULT_REALTIME_MODEL = 'gpt-realtime-whisper';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Build the realtime transcription WebSocket URL.
|
|
30
|
+
*
|
|
31
|
+
* Includes the model on the upgrade URL so OpenAI-compatible gateways
|
|
32
|
+
* (which can only see the URL at the WebSocket upgrade, not the subsequent
|
|
33
|
+
* `session.update` frame) can route by model. Mirrors the existing
|
|
34
|
+
* convention in `realtime/realtime_model.ts` for the conversational
|
|
35
|
+
* Realtime API. OpenAI's native endpoint accepts and ignores the
|
|
36
|
+
* parameter, so this is a no-op for direct connections.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export function buildRealtimeSttUrl(baseURL: string | undefined, model: string): string {
|
|
41
|
+
const url = new URL(baseURL || 'https://api.openai.com/v1');
|
|
42
|
+
if (url.protocol === 'https:') {
|
|
43
|
+
url.protocol = 'wss:';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const path = url.pathname.replace(/\/$/, '');
|
|
47
|
+
if (!path || path === '/v1') {
|
|
48
|
+
url.pathname = `${path}/realtime`;
|
|
49
|
+
} else if (!path.endsWith('/realtime')) {
|
|
50
|
+
url.pathname = `${path}/realtime`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
url.searchParams.set('intent', 'transcription');
|
|
54
|
+
url.searchParams.set('model', model);
|
|
55
|
+
return url.toString();
|
|
56
|
+
}
|
|
57
|
+
|
|
27
58
|
const DEFAULT_REALTIME_TURN_DETECTION: api_proto.TurnDetectionType = {
|
|
28
59
|
type: 'server_vad',
|
|
29
60
|
threshold: 0.5,
|
|
@@ -530,20 +561,7 @@ export class SpeechStream extends stt.SpeechStream {
|
|
|
530
561
|
}
|
|
531
562
|
|
|
532
563
|
#realtimeUrl(): string {
|
|
533
|
-
|
|
534
|
-
if (url.protocol === 'https:') {
|
|
535
|
-
url.protocol = 'wss:';
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
const path = url.pathname.replace(/\/$/, '');
|
|
539
|
-
if (!path || path === '/v1') {
|
|
540
|
-
url.pathname = `${path}/realtime`;
|
|
541
|
-
} else if (!path.endsWith('/realtime')) {
|
|
542
|
-
url.pathname = `${path}/realtime`;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
url.searchParams.set('intent', 'transcription');
|
|
546
|
-
return url.toString();
|
|
564
|
+
return buildRealtimeSttUrl(this.#options.baseURL, this.#options.model);
|
|
547
565
|
}
|
|
548
566
|
|
|
549
567
|
#sessionUpdateEvent(): api_proto.SessionUpdateEvent {
|
package/src/ws/llm.test.ts
CHANGED
|
@@ -3,28 +3,64 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import { initializeLogger } from '@livekit/agents';
|
|
5
5
|
import { llm, llmStrict } from '@livekit/agents-plugins-test';
|
|
6
|
-
import { describe } from 'vitest';
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
7
|
import { LLM } from '../responses/llm.js';
|
|
8
|
+
import { buildResponsesWsUrl } from './llm.js';
|
|
8
9
|
|
|
9
10
|
initializeLogger({ level: 'silent', pretty: false });
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
const hasOpenAIApiKey = Boolean(process.env.OPENAI_API_KEY);
|
|
13
|
+
|
|
14
|
+
describe('buildResponsesWsUrl', () => {
|
|
15
|
+
it('points at the OpenAI Responses WS endpoint with model when no baseURL is set', () => {
|
|
16
|
+
const url = new URL(buildResponsesWsUrl(undefined, 'gpt-4.1'));
|
|
17
|
+
|
|
18
|
+
expect(url.protocol).toBe('wss:');
|
|
19
|
+
expect(url.host).toBe('api.openai.com');
|
|
20
|
+
expect(url.pathname).toBe('/v1/responses');
|
|
21
|
+
expect(url.searchParams.get('model')).toBe('gpt-4.1');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('rewrites https baseURL to wss and appends /responses with the model', () => {
|
|
25
|
+
const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1', 'gpt-4o'));
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
expect(url.protocol).toBe('wss:');
|
|
28
|
+
expect(url.host).toBe('gateway.example.com');
|
|
29
|
+
expect(url.pathname).toBe('/v1/responses');
|
|
30
|
+
expect(url.searchParams.get('model')).toBe('gpt-4o');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('strips a trailing slash on baseURL before appending /responses', () => {
|
|
34
|
+
const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/', 'gpt-4o-mini'));
|
|
35
|
+
|
|
36
|
+
expect(url.pathname).toBe('/v1/responses');
|
|
37
|
+
expect(url.searchParams.get('model')).toBe('gpt-4o-mini');
|
|
38
|
+
});
|
|
30
39
|
});
|
|
40
|
+
|
|
41
|
+
if (hasOpenAIApiKey) {
|
|
42
|
+
describe('OpenAI Responses WS wrapper', async () => {
|
|
43
|
+
await llm(
|
|
44
|
+
new LLM({
|
|
45
|
+
temperature: 0,
|
|
46
|
+
strictToolSchema: false,
|
|
47
|
+
useWebSocket: true,
|
|
48
|
+
}),
|
|
49
|
+
true,
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('OpenAI Responses WS wrapper strict tool schema', async () => {
|
|
54
|
+
await llmStrict(
|
|
55
|
+
new LLM({
|
|
56
|
+
temperature: 0,
|
|
57
|
+
strictToolSchema: true,
|
|
58
|
+
useWebSocket: true,
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
describe('OpenAI Responses WS wrapper', () => {
|
|
64
|
+
it.skip('requires OPENAI_API_KEY', () => {});
|
|
65
|
+
});
|
|
66
|
+
}
|
package/src/ws/llm.ts
CHANGED
|
@@ -31,6 +31,27 @@ const OPENAI_RESPONSES_WS_URL = 'wss://api.openai.com/v1/responses';
|
|
|
31
31
|
// OpenAI enforces a 60-minute maximum duration on Responses WebSocket connections.
|
|
32
32
|
const WS_MAX_SESSION_DURATION = 3_600_000;
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Build the Responses-API WebSocket URL.
|
|
36
|
+
*
|
|
37
|
+
* Includes the model on the upgrade URL so OpenAI-compatible gateways
|
|
38
|
+
* (which can only see the URL at the WebSocket upgrade, not the subsequent
|
|
39
|
+
* `response.create` frame) can route by model. Mirrors the existing
|
|
40
|
+
* convention in `realtime/realtime_model.ts` for the conversational
|
|
41
|
+
* Realtime API. OpenAI's native endpoint accepts and ignores the
|
|
42
|
+
* parameter, so this is a no-op for direct connections.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export function buildResponsesWsUrl(baseURL: string | undefined, model: string): string {
|
|
47
|
+
const base = baseURL
|
|
48
|
+
? `${baseURL.replace(/^https?/, 'wss').replace(/\/+$/, '')}/responses`
|
|
49
|
+
: OPENAI_RESPONSES_WS_URL;
|
|
50
|
+
const url = new URL(base);
|
|
51
|
+
url.searchParams.set('model', model);
|
|
52
|
+
return url.toString();
|
|
53
|
+
}
|
|
54
|
+
|
|
34
55
|
// ============================================================================
|
|
35
56
|
// Internal: ResponsesWebSocket
|
|
36
57
|
//
|
|
@@ -186,9 +207,7 @@ export class WSLLM extends llm.LLM {
|
|
|
186
207
|
this.#pool = new ConnectionPool<ResponsesWebSocket>({
|
|
187
208
|
maxSessionDuration: WS_MAX_SESSION_DURATION,
|
|
188
209
|
connectCb: async (timeoutMs: number) => {
|
|
189
|
-
const wsUrl = this.#opts.baseURL
|
|
190
|
-
? `${this.#opts.baseURL.replace(/^https?/, 'wss').replace(/\/+$/, '')}/responses`
|
|
191
|
-
: OPENAI_RESPONSES_WS_URL;
|
|
210
|
+
const wsUrl = buildResponsesWsUrl(this.#opts.baseURL, String(this.#opts.model));
|
|
192
211
|
const ws = await connectWs(wsUrl, this.#opts.apiKey!, timeoutMs);
|
|
193
212
|
return new ResponsesWebSocket(ws);
|
|
194
213
|
},
|