@kernl-sdk/openai 0.1.0 → 0.3.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.
Files changed (36) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/CHANGELOG.md +26 -1
  3. package/LICENSE +201 -0
  4. package/dist/__tests__/realtime.integration.test.js +1 -1
  5. package/dist/__tests__/realtime.test.js +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/realtime/connection.d.ts +45 -0
  10. package/dist/realtime/connection.d.ts.map +1 -0
  11. package/dist/{realtime.js → realtime/connection.js} +21 -80
  12. package/dist/realtime/convert/__tests__/event.test.d.ts.map +1 -0
  13. package/dist/{convert → realtime/convert}/event.d.ts +2 -2
  14. package/dist/realtime/convert/event.d.ts.map +1 -0
  15. package/dist/{convert → realtime/convert}/event.js +4 -7
  16. package/dist/{realtime.d.ts → realtime/model.d.ts} +8 -2
  17. package/dist/realtime/model.d.ts.map +1 -0
  18. package/dist/realtime/model.js +111 -0
  19. package/dist/{convert/types.d.ts → realtime/protocol.d.ts} +1 -1
  20. package/dist/realtime/protocol.d.ts.map +1 -0
  21. package/package.json +13 -13
  22. package/src/__tests__/realtime.integration.test.ts +1 -1
  23. package/src/__tests__/realtime.test.ts +2 -2
  24. package/src/index.ts +1 -1
  25. package/src/{realtime.ts → realtime/connection.ts} +32 -120
  26. package/src/{convert → realtime/convert}/event.ts +11 -14
  27. package/src/realtime/model.ts +164 -0
  28. package/dist/convert/__tests__/event.test.d.ts.map +0 -1
  29. package/dist/convert/event.d.ts.map +0 -1
  30. package/dist/convert/types.d.ts.map +0 -1
  31. package/dist/realtime.d.ts.map +0 -1
  32. /package/dist/{convert → realtime/convert}/__tests__/event.test.d.ts +0 -0
  33. /package/dist/{convert → realtime/convert}/__tests__/event.test.js +0 -0
  34. /package/dist/{convert/types.js → realtime/protocol.js} +0 -0
  35. /package/src/{convert → realtime/convert}/__tests__/event.test.ts +0 -0
  36. /package/src/{convert/types.ts → realtime/protocol.ts} +0 -0
@@ -1,5 +1,4 @@
1
-
2
- 
3
- > @kernl-sdk/openai@0.1.0 build /Users/andjones/Documents/projects/kernl/packages/providers/openai
4
- > tsc && tsc-alias --resolve-full-paths
5
-
1
+
2
+ > @kernl-sdk/openai@0.3.0 build /home/runner/work/kernl/kernl/packages/providers/openai
3
+ > tsc && tsc-alias --resolve-full-paths
4
+
package/CHANGELOG.md CHANGED
@@ -1,6 +1,31 @@
1
1
  # @kernl-sdk/openai
2
2
 
3
- ## 0.1.0
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f593374: Add realtime voice agents with multi-provider support.
8
+ - `RealtimeAgent` and `RealtimeSession` for voice-enabled AI agents
9
+ - OpenAI GPT-4o realtime with WebSocket streaming
10
+ - xAI Grok realtime with OpenAI-compatible protocol
11
+ - React hooks: `useRealtime`, `useBrowserAudio`, `LiveWaveform`
12
+ - Ephemeral credential pattern for secure browser connections
13
+ - Tool execution with client-side context support
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [f593374]
18
+ - @kernl-sdk/protocol@0.4.0
19
+
20
+ ## 0.2.1
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [25e46e7]
25
+ - @kernl-sdk/shared@0.3.1
26
+ - @kernl-sdk/protocol@0.3.1
27
+
28
+ ## 0.2.0
4
29
 
5
30
  ### Minor Changes
6
31
 
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Andrew Jones
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect, beforeAll } from "vitest";
2
- import { OpenAIRealtimeModel } from "../realtime.js";
2
+ import { OpenAIRealtimeModel } from "../realtime/model.js";
3
3
  const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
4
4
  describe.skipIf(!OPENAI_API_KEY)("OpenAI Realtime Integration", () => {
5
5
  let model;
@@ -24,7 +24,7 @@ vi.mock("ws", () => {
24
24
  };
25
25
  });
26
26
  // Import after mock
27
- import { OpenAIRealtimeModel } from "../realtime.js";
27
+ import { OpenAIRealtimeModel } from "../realtime/model.js";
28
28
  describe("OpenAIRealtimeModel", () => {
29
29
  beforeEach(() => {
30
30
  vi.clearAllMocks();
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OpenAIRealtimeModel, type OpenAIRealtimeOptions } from "./realtime.js";
1
+ import { OpenAIRealtimeModel, type OpenAIRealtimeOptions } from "./realtime/model.js";
2
2
  /**
3
3
  * OpenAI provider interface.
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,KAAK,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,mBAAmB,CAAC;CACjF;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,EAAE,cAIpB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEnF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,mBAAmB,CAAC;CACjF;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,EAAE,cAIpB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { OpenAIRealtimeModel } from "./realtime.js";
1
+ import { OpenAIRealtimeModel } from "./realtime/model.js";
2
2
  /**
3
3
  * OpenAI provider.
4
4
  *
@@ -0,0 +1,45 @@
1
+ import { Emitter } from "@kernl-sdk/shared";
2
+ import { type RealtimeConnection, type RealtimeConnectionEvents, type RealtimeClientEvent, type TransportStatus, type WebSocketLike } from "@kernl-sdk/protocol";
3
+ /**
4
+ * OpenAI realtime connection implementation.
5
+ */
6
+ export declare class OpenAIRealtimeConnection extends Emitter<RealtimeConnectionEvents> implements RealtimeConnection {
7
+ private ws;
8
+ private _status;
9
+ private _muted;
10
+ private _sessionId;
11
+ private currid;
12
+ private curridx;
13
+ private faudtime;
14
+ private audlenms;
15
+ private responding;
16
+ constructor(socket: WebSocketLike);
17
+ get status(): TransportStatus;
18
+ get muted(): boolean;
19
+ get sessionId(): string | null;
20
+ /**
21
+ * Send a client event to the OpenAI realtime API.
22
+ */
23
+ send(event: RealtimeClientEvent): void;
24
+ /**
25
+ * Close the WebSocket connection.
26
+ */
27
+ close(): void;
28
+ /**
29
+ * Mute audio input.
30
+ */
31
+ mute(): void;
32
+ /**
33
+ * Unmute audio input.
34
+ */
35
+ unmute(): void;
36
+ /**
37
+ * Interrupt the current response.
38
+ */
39
+ interrupt(): void;
40
+ /**
41
+ * Reset audio tracking state.
42
+ */
43
+ private reset;
44
+ }
45
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/realtime/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAC;AAK7B;;GAEG;AACH,qBAAa,wBACX,SAAQ,OAAO,CAAC,wBAAwB,CACxC,YAAW,kBAAkB;IAE7B,OAAO,CAAC,EAAE,CAAgB;IAC1B,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAuB;IAGzC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,UAAU,CAAkB;gBAExB,MAAM,EAAE,aAAa;IA+DjC,IAAI,MAAM,IAAI,eAAe,CAE5B;IAED,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI;IAOtC;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,SAAS,IAAI,IAAI;IA4BjB;;OAEG;IACH,OAAO,CAAC,KAAK;CAMd"}
@@ -1,75 +1,10 @@
1
- import { EventEmitter } from "node:events";
2
- import WebSocket from "ws";
1
+ import { Emitter } from "@kernl-sdk/shared";
2
+ import { WS_OPEN, } from "@kernl-sdk/protocol";
3
3
  import { CLIENT_EVENT, SERVER_EVENT } from "./convert/event.js";
4
- const OPENAI_REALTIME_URL = "wss://api.openai.com/v1/realtime";
5
- /**
6
- * OpenAI realtime model implementation.
7
- */
8
- export class OpenAIRealtimeModel {
9
- spec = "1.0";
10
- provider = "openai";
11
- modelId;
12
- apiKey;
13
- baseUrl;
14
- constructor(modelId, options) {
15
- this.modelId = modelId;
16
- this.apiKey = options?.apiKey ?? process.env.OPENAI_API_KEY ?? "";
17
- this.baseUrl = options?.baseUrl ?? OPENAI_REALTIME_URL;
18
- if (!this.apiKey) {
19
- throw new Error("OpenAI API key is required");
20
- }
21
- }
22
- /**
23
- * Establish a WebSocket connection to the OpenAI realtime API.
24
- */
25
- async connect(options) {
26
- const url = `${this.baseUrl}?model=${this.modelId}`;
27
- const ws = new WebSocket(url, {
28
- headers: {
29
- Authorization: `Bearer ${this.apiKey}`,
30
- "OpenAI-Beta": "realtime=v1",
31
- },
32
- });
33
- const connection = new OpenAIRealtimeConnection(ws);
34
- await new Promise((resolve, reject) => {
35
- if (options?.abort?.aborted) {
36
- return reject(new Error("Connection aborted"));
37
- }
38
- const cleanup = () => {
39
- ws.off("open", onOpen);
40
- ws.off("error", onError);
41
- options?.abort?.removeEventListener("abort", onAbort);
42
- };
43
- const onOpen = () => {
44
- cleanup();
45
- resolve();
46
- };
47
- const onError = (err) => {
48
- cleanup();
49
- reject(err);
50
- };
51
- const onAbort = () => {
52
- cleanup();
53
- ws.close();
54
- reject(new Error("Connection aborted"));
55
- };
56
- ws.on("open", onOpen);
57
- ws.on("error", onError);
58
- options?.abort?.addEventListener("abort", onAbort);
59
- });
60
- if (options?.sessionConfig) {
61
- connection.send({
62
- kind: "session.update",
63
- config: options.sessionConfig,
64
- });
65
- }
66
- return connection;
67
- }
68
- }
69
4
  /**
70
5
  * OpenAI realtime connection implementation.
71
6
  */
72
- class OpenAIRealtimeConnection extends EventEmitter {
7
+ export class OpenAIRealtimeConnection extends Emitter {
73
8
  ws;
74
9
  _status = "connecting";
75
10
  _muted = false;
@@ -83,9 +18,13 @@ class OpenAIRealtimeConnection extends EventEmitter {
83
18
  constructor(socket) {
84
19
  super();
85
20
  this.ws = socket;
86
- socket.on("message", (data) => {
21
+ socket.addEventListener("message", (event) => {
87
22
  try {
88
- const raw = JSON.parse(data.toString());
23
+ // Browser sends MessageEvent with data property
24
+ const data = event && typeof event === "object" && "data" in event
25
+ ? event.data
26
+ : String(event);
27
+ const raw = JSON.parse(data);
89
28
  // track audio state for interruption handling
90
29
  if (raw.type === "response.output_audio.delta") {
91
30
  this.currid = raw.item_id;
@@ -109,28 +48,29 @@ class OpenAIRealtimeConnection extends EventEmitter {
109
48
  else if (raw.type === "input_audio_buffer.speech_started") {
110
49
  this.interrupt();
111
50
  }
112
- const event = SERVER_EVENT.decode(raw);
113
- if (event) {
114
- if (event.kind === "session.created") {
115
- this._sessionId = event.session.id;
51
+ const event_ = SERVER_EVENT.decode(raw);
52
+ if (event_) {
53
+ if (event_.kind === "session.created") {
54
+ this._sessionId = event_.session.id;
116
55
  }
117
- this.emit("event", event);
56
+ this.emit("event", event_);
118
57
  }
119
58
  }
120
59
  catch (err) {
121
60
  this.emit("error", err instanceof Error ? err : new Error(String(err)));
122
61
  }
123
62
  });
124
- socket.on("open", () => {
63
+ socket.addEventListener("open", () => {
125
64
  this._status = "connected";
126
65
  this.emit("status", this._status);
127
66
  });
128
- socket.on("close", () => {
67
+ socket.addEventListener("close", () => {
129
68
  this._status = "closed";
130
69
  this.reset();
131
70
  this.emit("status", this._status);
132
71
  });
133
- socket.on("error", (err) => {
72
+ socket.addEventListener("error", (event) => {
73
+ const err = event instanceof Error ? event : new Error("WebSocket error");
134
74
  this.emit("error", err);
135
75
  });
136
76
  }
@@ -148,7 +88,7 @@ class OpenAIRealtimeConnection extends EventEmitter {
148
88
  */
149
89
  send(event) {
150
90
  const encoded = CLIENT_EVENT.encode(event);
151
- if (encoded && this.ws.readyState === WebSocket.OPEN) {
91
+ if (encoded && this.ws.readyState === WS_OPEN) {
152
92
  this.ws.send(JSON.stringify(encoded));
153
93
  }
154
94
  }
@@ -184,7 +124,7 @@ class OpenAIRealtimeConnection extends EventEmitter {
184
124
  if (this.currid && this.faudtime !== undefined) {
185
125
  const elapsed = Date.now() - this.faudtime;
186
126
  const endms = Math.max(0, Math.floor(Math.min(elapsed, this.audlenms)));
187
- if (this.ws.readyState === WebSocket.OPEN) {
127
+ if (this.ws.readyState === WS_OPEN) {
188
128
  this.ws.send(JSON.stringify({
189
129
  type: "conversation.item.truncate",
190
130
  item_id: this.currid,
@@ -193,6 +133,7 @@ class OpenAIRealtimeConnection extends EventEmitter {
193
133
  }));
194
134
  }
195
135
  }
136
+ this.emit("interrupted");
196
137
  this.reset();
197
138
  }
198
139
  /**
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.test.d.ts","sourceRoot":"","sources":["../../../../src/realtime/convert/__tests__/event.test.ts"],"names":[],"mappings":""}
@@ -1,6 +1,6 @@
1
1
  import type { Codec } from "@kernl-sdk/shared/lib";
2
- import type { RealtimeClientEvent, RealtimeServerEvent, RealtimeSessionConfig, TurnDetectionConfig, LanguageModelItem } from "@kernl-sdk/protocol";
3
- import type { OpenAIClientEvent, OpenAIServerEvent, OpenAISessionConfig, OpenAITurnDetection, OpenAIItem } from "./types.js";
2
+ import { type RealtimeClientEvent, type RealtimeServerEvent, type RealtimeSessionConfig, type TurnDetectionConfig, type LanguageModelItem } from "@kernl-sdk/protocol";
3
+ import type { OpenAIClientEvent, OpenAIServerEvent, OpenAISessionConfig, OpenAITurnDetection, OpenAIItem } from "../protocol.js";
4
4
  /**
5
5
  * Codec for turn detection config.
6
6
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/realtime/convert/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EAEX,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,mBAAmB,EAAE,mBAAmB,CA4B1E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,qBAAqB,EAAE,mBAAmB,CAmC1E,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,iBAAiB,EAAE,UAAU,CA6FrD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAC9B,mBAAmB,EACnB,iBAAiB,GAAG,IAAI,CA+EzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAC9B,mBAAmB,GAAG,IAAI,EAC1B,iBAAiB,CAmMlB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { randomID } from "@kernl-sdk/shared/lib";
2
+ import { RealtimeError, } from "@kernl-sdk/protocol";
2
3
  /**
3
4
  * Codec for turn detection config.
4
5
  */
@@ -39,14 +40,9 @@ export const SESSION_CONFIG = {
39
40
  */
40
41
  encode(config) {
41
42
  return {
43
+ type: "realtime",
42
44
  instructions: config.instructions,
43
- modalities: config.modalities,
44
45
  voice: config.voice?.voiceId,
45
- input_audio_format: config.audio?.inputFormat?.mimeType,
46
- output_audio_format: config.audio?.outputFormat?.mimeType,
47
- turn_detection: config.turnDetection
48
- ? TURN_DETECTION.encode(config.turnDetection)
49
- : undefined,
50
46
  tools: config.tools
51
47
  ?.filter((t) => t.kind === "function")
52
48
  .map((t) => ({
@@ -55,6 +51,7 @@ export const SESSION_CONFIG = {
55
51
  description: t.description,
56
52
  parameters: t.parameters,
57
53
  })),
54
+ tool_choice: config.tools?.length ? "auto" : undefined,
58
55
  };
59
56
  },
60
57
  /**
@@ -259,7 +256,7 @@ export const SERVER_EVENT = {
259
256
  case "error":
260
257
  return {
261
258
  kind: "session.error",
262
- error: { code: event.error.code, message: event.error.message },
259
+ error: new RealtimeError(event.error.code, event.error.message),
263
260
  };
264
261
  case "input_audio_buffer.committed":
265
262
  return { kind: "audio.input.committed", itemId: event.item_id };
@@ -1,4 +1,4 @@
1
- import type { RealtimeModel, RealtimeConnection, RealtimeConnectOptions } from "@kernl-sdk/protocol";
1
+ import type { RealtimeModel, RealtimeConnection, RealtimeConnectOptions, ClientCredential } from "@kernl-sdk/protocol";
2
2
  /**
3
3
  * Options for creating an OpenAI realtime model.
4
4
  */
@@ -22,9 +22,15 @@ export declare class OpenAIRealtimeModel implements RealtimeModel {
22
22
  private apiKey;
23
23
  private baseUrl;
24
24
  constructor(modelId: string, options?: OpenAIRealtimeOptions);
25
+ /**
26
+ * Create ephemeral credential for client-side connections.
27
+ *
28
+ * Must be called server-side where API key is available.
29
+ */
30
+ authenticate(): Promise<ClientCredential>;
25
31
  /**
26
32
  * Establish a WebSocket connection to the OpenAI realtime API.
27
33
  */
28
34
  connect(options?: RealtimeConnectOptions): Promise<RealtimeConnection>;
29
35
  }
30
- //# sourceMappingURL=realtime.d.ts.map
36
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/realtime/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,qBAAqB,CAAC;AAQ7B;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,mBAAoB,YAAW,aAAa;IACvD,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAC/B,QAAQ,CAAC,QAAQ,YAAY;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAS5D;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAgC/C;;OAEG;IACG,OAAO,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA2E7E"}
@@ -0,0 +1,111 @@
1
+ import { OpenAIRealtimeConnection } from "./connection.js";
2
+ const OPENAI_REALTIME_URL = "wss://api.openai.com/v1/realtime";
3
+ const OPENAI_CLIENT_SECRETS_URL = "https://api.openai.com/v1/realtime/client_secrets";
4
+ /**
5
+ * OpenAI realtime model implementation.
6
+ */
7
+ export class OpenAIRealtimeModel {
8
+ spec = "1.0";
9
+ provider = "openai";
10
+ modelId;
11
+ apiKey;
12
+ baseUrl;
13
+ constructor(modelId, options) {
14
+ this.modelId = modelId;
15
+ this.apiKey =
16
+ options?.apiKey ??
17
+ (typeof process !== "undefined" ? process.env?.OPENAI_API_KEY : null) ??
18
+ null;
19
+ this.baseUrl = options?.baseUrl ?? OPENAI_REALTIME_URL;
20
+ }
21
+ /**
22
+ * Create ephemeral credential for client-side connections.
23
+ *
24
+ * Must be called server-side where API key is available.
25
+ */
26
+ async authenticate() {
27
+ if (!this.apiKey) {
28
+ throw new Error("API key required for authenticate(). " +
29
+ "Call this server-side where OPENAI_API_KEY is available.");
30
+ }
31
+ const res = await fetch(OPENAI_CLIENT_SECRETS_URL, {
32
+ method: "POST",
33
+ headers: {
34
+ Authorization: `Bearer ${this.apiKey}`,
35
+ "Content-Type": "application/json",
36
+ },
37
+ body: JSON.stringify({
38
+ session: { type: "realtime", model: this.modelId },
39
+ }),
40
+ });
41
+ if (!res.ok) {
42
+ const text = await res.text();
43
+ throw new Error(`Failed to create credential: ${res.status} ${text}`);
44
+ }
45
+ const data = (await res.json());
46
+ return {
47
+ kind: "token",
48
+ token: data.value,
49
+ expiresAt: new Date(Date.now() + 60_000), // ~60s TTL
50
+ };
51
+ }
52
+ /**
53
+ * Establish a WebSocket connection to the OpenAI realtime API.
54
+ */
55
+ async connect(options) {
56
+ const credential = options?.credential;
57
+ if (credential && credential.kind !== "token") {
58
+ throw new Error(`OpenAI requires token credentials, got "${credential.kind}".`);
59
+ }
60
+ const authToken = credential?.token ?? this.apiKey;
61
+ if (!authToken) {
62
+ throw new Error("No API key or credential provided. " +
63
+ "Either set OPENAI_API_KEY or pass a credential from authenticate().");
64
+ }
65
+ // Use injectable WebSocket or globalThis.WebSocket
66
+ const WS = options?.websocket ?? globalThis.WebSocket;
67
+ if (!WS) {
68
+ throw new Error("No WebSocket available. In Node.js <22, use WebSocketTransport with the 'ws' package:\n" +
69
+ " import WebSocket from 'ws';\n" +
70
+ " import { WebSocketTransport } from 'kernl';\n" +
71
+ " new RealtimeSession(agent, { transport: new WebSocketTransport({ websocket: WebSocket }), ... })");
72
+ }
73
+ const url = `${this.baseUrl}?model=${this.modelId}`;
74
+ // Use subprotocol auth (works in browsers and Node)
75
+ // Note: Don't include openai-beta.realtime-v1 when using ephemeral tokens -
76
+ // the version is encoded in the token itself
77
+ const protocols = ["realtime", `openai-insecure-api-key.${authToken}`];
78
+ const ws = new WS(url, protocols);
79
+ const connection = new OpenAIRealtimeConnection(ws);
80
+ await new Promise((resolve, reject) => {
81
+ if (options?.abort?.aborted) {
82
+ return reject(new Error("Connection aborted"));
83
+ }
84
+ const onOpen = () => {
85
+ cleanup();
86
+ resolve();
87
+ };
88
+ const onError = (event) => {
89
+ cleanup();
90
+ const err = event instanceof Error
91
+ ? event
92
+ : new Error("WebSocket connection failed");
93
+ reject(err);
94
+ };
95
+ const onAbort = () => {
96
+ cleanup();
97
+ ws.close();
98
+ reject(new Error("Connection aborted"));
99
+ };
100
+ const cleanup = () => {
101
+ ws.removeEventListener("open", onOpen);
102
+ ws.removeEventListener("error", onError);
103
+ options?.abort?.removeEventListener("abort", onAbort);
104
+ };
105
+ ws.addEventListener("open", onOpen);
106
+ ws.addEventListener("error", onError);
107
+ options?.abort?.addEventListener("abort", onAbort);
108
+ });
109
+ return connection;
110
+ }
111
+ }
@@ -256,4 +256,4 @@ export type OpenAIContentPart = {
256
256
  audio: string;
257
257
  transcript?: string;
258
258
  };
259
- //# sourceMappingURL=types.d.ts.map
259
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/realtime/protocol.ts"],"names":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;CAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kernl-sdk/openai",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "OpenAI provider for kernl",
5
5
  "keywords": [
6
6
  "kernl",
@@ -30,18 +30,10 @@
30
30
  "import": "./dist/index.js"
31
31
  }
32
32
  },
33
- "scripts": {
34
- "build": "tsc && tsc-alias --resolve-full-paths",
35
- "dev": "tsc --watch",
36
- "check-types": "tsc --noEmit",
37
- "test": "vitest",
38
- "test:watch": "vitest --watch",
39
- "test:run": "vitest run"
40
- },
41
33
  "dependencies": {
42
- "@kernl-sdk/protocol": "workspace:*",
43
- "@kernl-sdk/shared": "workspace:*",
44
- "ws": "^8.18.0"
34
+ "ws": "^8.18.0",
35
+ "@kernl-sdk/protocol": "0.4.0",
36
+ "@kernl-sdk/shared": "0.3.1"
45
37
  },
46
38
  "devDependencies": {
47
39
  "@types/json-schema": "^7.0.15",
@@ -50,5 +42,13 @@
50
42
  "tsc-alias": "^1.8.10",
51
43
  "typescript": "5.9.2",
52
44
  "vitest": "^4.0.8"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc && tsc-alias --resolve-full-paths",
48
+ "dev": "tsc --watch",
49
+ "check-types": "tsc --noEmit",
50
+ "test": "vitest",
51
+ "test:watch": "vitest --watch",
52
+ "test:run": "vitest run"
53
53
  }
54
- }
54
+ }
@@ -4,7 +4,7 @@ import type {
4
4
  RealtimeServerEvent,
5
5
  RealtimeConnection,
6
6
  } from "@kernl-sdk/protocol";
7
- import { OpenAIRealtimeModel } from "../realtime";
7
+ import { OpenAIRealtimeModel } from "../realtime/model";
8
8
 
9
9
  const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
10
10
 
@@ -5,7 +5,7 @@ import type {
5
5
  RealtimeServerEvent,
6
6
  TransportStatus,
7
7
  } from "@kernl-sdk/protocol";
8
- import type { OpenAIServerEvent } from "../convert/types";
8
+ import type { OpenAIServerEvent } from "../realtime/protocol";
9
9
 
10
10
  // Track mock WebSocket instances
11
11
  const wsInstances: TestWebSocket[] = [];
@@ -42,7 +42,7 @@ vi.mock("ws", () => {
42
42
  });
43
43
 
44
44
  // Import after mock
45
- import { OpenAIRealtimeModel } from "../realtime";
45
+ import { OpenAIRealtimeModel } from "../realtime/model";
46
46
 
47
47
  describe("OpenAIRealtimeModel", () => {
48
48
  beforeEach(() => {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OpenAIRealtimeModel, type OpenAIRealtimeOptions } from "./realtime";
1
+ import { OpenAIRealtimeModel, type OpenAIRealtimeOptions } from "./realtime/model";
2
2
 
3
3
  /**
4
4
  * OpenAI provider interface.
@@ -1,119 +1,24 @@
1
- import { EventEmitter } from "node:events";
2
- import WebSocket from "ws";
3
-
4
- import type {
5
- RealtimeModel,
6
- RealtimeConnection,
7
- RealtimeConnectOptions,
8
- RealtimeClientEvent,
9
- TransportStatus,
1
+ import { Emitter } from "@kernl-sdk/shared";
2
+ import {
3
+ WS_OPEN,
4
+ type RealtimeConnection,
5
+ type RealtimeConnectionEvents,
6
+ type RealtimeClientEvent,
7
+ type TransportStatus,
8
+ type WebSocketLike,
10
9
  } from "@kernl-sdk/protocol";
11
10
 
12
11
  import { CLIENT_EVENT, SERVER_EVENT } from "./convert/event";
13
- import type { OpenAIServerEvent } from "./convert/types";
14
-
15
- const OPENAI_REALTIME_URL = "wss://api.openai.com/v1/realtime";
16
-
17
- /**
18
- * Options for creating an OpenAI realtime model.
19
- */
20
- export interface OpenAIRealtimeOptions {
21
- /**
22
- * OpenAI API key. Defaults to OPENAI_API_KEY env var.
23
- */
24
- apiKey?: string;
25
-
26
- /**
27
- * Base URL for the realtime API.
28
- */
29
- baseUrl?: string;
30
- }
31
-
32
- /**
33
- * OpenAI realtime model implementation.
34
- */
35
- export class OpenAIRealtimeModel implements RealtimeModel {
36
- readonly spec = "1.0" as const;
37
- readonly provider = "openai";
38
- readonly modelId: string;
39
-
40
- private apiKey: string;
41
- private baseUrl: string;
42
-
43
- constructor(modelId: string, options?: OpenAIRealtimeOptions) {
44
- this.modelId = modelId;
45
- this.apiKey = options?.apiKey ?? process.env.OPENAI_API_KEY ?? "";
46
- this.baseUrl = options?.baseUrl ?? OPENAI_REALTIME_URL;
47
-
48
- if (!this.apiKey) {
49
- throw new Error("OpenAI API key is required");
50
- }
51
- }
52
-
53
- /**
54
- * Establish a WebSocket connection to the OpenAI realtime API.
55
- */
56
- async connect(options?: RealtimeConnectOptions): Promise<RealtimeConnection> {
57
- const url = `${this.baseUrl}?model=${this.modelId}`;
58
-
59
- const ws = new WebSocket(url, {
60
- headers: {
61
- Authorization: `Bearer ${this.apiKey}`,
62
- "OpenAI-Beta": "realtime=v1",
63
- },
64
- });
65
-
66
- const connection = new OpenAIRealtimeConnection(ws);
67
-
68
- await new Promise<void>((resolve, reject) => {
69
- if (options?.abort?.aborted) {
70
- return reject(new Error("Connection aborted"));
71
- }
72
-
73
- const cleanup = () => {
74
- ws.off("open", onOpen);
75
- ws.off("error", onError);
76
- options?.abort?.removeEventListener("abort", onAbort);
77
- };
78
-
79
- const onOpen = () => {
80
- cleanup();
81
- resolve();
82
- };
83
- const onError = (err: Error) => {
84
- cleanup();
85
- reject(err);
86
- };
87
- const onAbort = () => {
88
- cleanup();
89
- ws.close();
90
- reject(new Error("Connection aborted"));
91
- };
92
-
93
- ws.on("open", onOpen);
94
- ws.on("error", onError);
95
- options?.abort?.addEventListener("abort", onAbort);
96
- });
97
-
98
- if (options?.sessionConfig) {
99
- connection.send({
100
- kind: "session.update",
101
- config: options.sessionConfig,
102
- });
103
- }
104
-
105
- return connection;
106
- }
107
- }
12
+ import type { OpenAIServerEvent } from "./protocol";
108
13
 
109
14
  /**
110
15
  * OpenAI realtime connection implementation.
111
16
  */
112
- class OpenAIRealtimeConnection
113
- extends EventEmitter
17
+ export class OpenAIRealtimeConnection
18
+ extends Emitter<RealtimeConnectionEvents>
114
19
  implements RealtimeConnection
115
20
  {
116
- private ws: WebSocket;
21
+ private ws: WebSocketLike;
117
22
  private _status: TransportStatus = "connecting";
118
23
  private _muted = false;
119
24
  private _sessionId: string | null = null;
@@ -125,13 +30,18 @@ class OpenAIRealtimeConnection
125
30
  private audlenms: number = 0;
126
31
  private responding: boolean = false;
127
32
 
128
- constructor(socket: WebSocket) {
33
+ constructor(socket: WebSocketLike) {
129
34
  super();
130
35
  this.ws = socket;
131
36
 
132
- socket.on("message", (data) => {
37
+ socket.addEventListener("message", (event: unknown) => {
133
38
  try {
134
- const raw = JSON.parse(data.toString()) as OpenAIServerEvent;
39
+ // Browser sends MessageEvent with data property
40
+ const data =
41
+ event && typeof event === "object" && "data" in event
42
+ ? (event as { data: string }).data
43
+ : String(event);
44
+ const raw = JSON.parse(data) as OpenAIServerEvent;
135
45
 
136
46
  // track audio state for interruption handling
137
47
  if (raw.type === "response.output_audio.delta") {
@@ -154,30 +64,31 @@ class OpenAIRealtimeConnection
154
64
  this.interrupt();
155
65
  }
156
66
 
157
- const event = SERVER_EVENT.decode(raw);
158
- if (event) {
159
- if (event.kind === "session.created") {
160
- this._sessionId = event.session.id;
67
+ const event_ = SERVER_EVENT.decode(raw);
68
+ if (event_) {
69
+ if (event_.kind === "session.created") {
70
+ this._sessionId = event_.session.id;
161
71
  }
162
- this.emit("event", event);
72
+ this.emit("event", event_);
163
73
  }
164
74
  } catch (err) {
165
75
  this.emit("error", err instanceof Error ? err : new Error(String(err)));
166
76
  }
167
77
  });
168
78
 
169
- socket.on("open", () => {
79
+ socket.addEventListener("open", () => {
170
80
  this._status = "connected";
171
81
  this.emit("status", this._status);
172
82
  });
173
83
 
174
- socket.on("close", () => {
84
+ socket.addEventListener("close", () => {
175
85
  this._status = "closed";
176
86
  this.reset();
177
87
  this.emit("status", this._status);
178
88
  });
179
89
 
180
- socket.on("error", (err) => {
90
+ socket.addEventListener("error", (event: unknown) => {
91
+ const err = event instanceof Error ? event : new Error("WebSocket error");
181
92
  this.emit("error", err);
182
93
  });
183
94
  }
@@ -199,7 +110,7 @@ class OpenAIRealtimeConnection
199
110
  */
200
111
  send(event: RealtimeClientEvent): void {
201
112
  const encoded = CLIENT_EVENT.encode(event);
202
- if (encoded && this.ws.readyState === WebSocket.OPEN) {
113
+ if (encoded && this.ws.readyState === WS_OPEN) {
203
114
  this.ws.send(JSON.stringify(encoded));
204
115
  }
205
116
  }
@@ -241,7 +152,7 @@ class OpenAIRealtimeConnection
241
152
  const elapsed = Date.now() - this.faudtime;
242
153
  const endms = Math.max(0, Math.floor(Math.min(elapsed, this.audlenms)));
243
154
 
244
- if (this.ws.readyState === WebSocket.OPEN) {
155
+ if (this.ws.readyState === WS_OPEN) {
245
156
  this.ws.send(
246
157
  JSON.stringify({
247
158
  type: "conversation.item.truncate",
@@ -253,6 +164,7 @@ class OpenAIRealtimeConnection
253
164
  }
254
165
  }
255
166
 
167
+ this.emit("interrupted");
256
168
  this.reset();
257
169
  }
258
170
 
@@ -1,11 +1,12 @@
1
1
  import type { Codec } from "@kernl-sdk/shared/lib";
2
2
  import { randomID } from "@kernl-sdk/shared/lib";
3
- import type {
4
- RealtimeClientEvent,
5
- RealtimeServerEvent,
6
- RealtimeSessionConfig,
7
- TurnDetectionConfig,
8
- LanguageModelItem,
3
+ import {
4
+ RealtimeError,
5
+ type RealtimeClientEvent,
6
+ type RealtimeServerEvent,
7
+ type RealtimeSessionConfig,
8
+ type TurnDetectionConfig,
9
+ type LanguageModelItem,
9
10
  } from "@kernl-sdk/protocol";
10
11
 
11
12
  import type {
@@ -15,7 +16,7 @@ import type {
15
16
  OpenAITurnDetection,
16
17
  OpenAIItem,
17
18
  OpenAIContentPart,
18
- } from "./types";
19
+ } from "../protocol";
19
20
 
20
21
  /**
21
22
  * Codec for turn detection config.
@@ -60,14 +61,9 @@ export const SESSION_CONFIG: Codec<RealtimeSessionConfig, OpenAISessionConfig> =
60
61
  */
61
62
  encode(config) {
62
63
  return {
64
+ type: "realtime",
63
65
  instructions: config.instructions,
64
- modalities: config.modalities,
65
66
  voice: config.voice?.voiceId,
66
- input_audio_format: config.audio?.inputFormat?.mimeType,
67
- output_audio_format: config.audio?.outputFormat?.mimeType,
68
- turn_detection: config.turnDetection
69
- ? TURN_DETECTION.encode(config.turnDetection)
70
- : undefined,
71
67
  tools: config.tools
72
68
  ?.filter((t) => t.kind === "function")
73
69
  .map((t) => ({
@@ -76,6 +72,7 @@ export const SESSION_CONFIG: Codec<RealtimeSessionConfig, OpenAISessionConfig> =
76
72
  description: t.description,
77
73
  parameters: t.parameters,
78
74
  })),
75
+ tool_choice: config.tools?.length ? "auto" : undefined,
79
76
  };
80
77
  },
81
78
 
@@ -318,7 +315,7 @@ export const SERVER_EVENT: Codec<
318
315
  case "error":
319
316
  return {
320
317
  kind: "session.error",
321
- error: { code: event.error.code, message: event.error.message },
318
+ error: new RealtimeError(event.error.code, event.error.message),
322
319
  };
323
320
 
324
321
  case "input_audio_buffer.committed":
@@ -0,0 +1,164 @@
1
+ import type {
2
+ RealtimeModel,
3
+ RealtimeConnection,
4
+ RealtimeConnectOptions,
5
+ ClientCredential,
6
+ } from "@kernl-sdk/protocol";
7
+
8
+ import { OpenAIRealtimeConnection } from "./connection";
9
+
10
+ const OPENAI_REALTIME_URL = "wss://api.openai.com/v1/realtime";
11
+ const OPENAI_CLIENT_SECRETS_URL =
12
+ "https://api.openai.com/v1/realtime/client_secrets";
13
+
14
+ /**
15
+ * Options for creating an OpenAI realtime model.
16
+ */
17
+ export interface OpenAIRealtimeOptions {
18
+ /**
19
+ * OpenAI API key. Defaults to OPENAI_API_KEY env var.
20
+ */
21
+ apiKey?: string;
22
+
23
+ /**
24
+ * Base URL for the realtime API.
25
+ */
26
+ baseUrl?: string;
27
+ }
28
+
29
+ /**
30
+ * OpenAI realtime model implementation.
31
+ */
32
+ export class OpenAIRealtimeModel implements RealtimeModel {
33
+ readonly spec = "1.0" as const;
34
+ readonly provider = "openai";
35
+ readonly modelId: string;
36
+
37
+ private apiKey: string | null;
38
+ private baseUrl: string;
39
+
40
+ constructor(modelId: string, options?: OpenAIRealtimeOptions) {
41
+ this.modelId = modelId;
42
+ this.apiKey =
43
+ options?.apiKey ??
44
+ (typeof process !== "undefined" ? process.env?.OPENAI_API_KEY : null) ??
45
+ null;
46
+ this.baseUrl = options?.baseUrl ?? OPENAI_REALTIME_URL;
47
+ }
48
+
49
+ /**
50
+ * Create ephemeral credential for client-side connections.
51
+ *
52
+ * Must be called server-side where API key is available.
53
+ */
54
+ async authenticate(): Promise<ClientCredential> {
55
+ if (!this.apiKey) {
56
+ throw new Error(
57
+ "API key required for authenticate(). " +
58
+ "Call this server-side where OPENAI_API_KEY is available.",
59
+ );
60
+ }
61
+
62
+ const res = await fetch(OPENAI_CLIENT_SECRETS_URL, {
63
+ method: "POST",
64
+ headers: {
65
+ Authorization: `Bearer ${this.apiKey}`,
66
+ "Content-Type": "application/json",
67
+ },
68
+ body: JSON.stringify({
69
+ session: { type: "realtime", model: this.modelId },
70
+ }),
71
+ });
72
+
73
+ if (!res.ok) {
74
+ const text = await res.text();
75
+ throw new Error(`Failed to create credential: ${res.status} ${text}`);
76
+ }
77
+
78
+ const data = (await res.json()) as { value: string };
79
+ return {
80
+ kind: "token",
81
+ token: data.value,
82
+ expiresAt: new Date(Date.now() + 60_000), // ~60s TTL
83
+ };
84
+ }
85
+
86
+ /**
87
+ * Establish a WebSocket connection to the OpenAI realtime API.
88
+ */
89
+ async connect(options?: RealtimeConnectOptions): Promise<RealtimeConnection> {
90
+ const credential = options?.credential;
91
+
92
+ if (credential && credential.kind !== "token") {
93
+ throw new Error(
94
+ `OpenAI requires token credentials, got "${credential.kind}".`,
95
+ );
96
+ }
97
+
98
+ const authToken = credential?.token ?? this.apiKey;
99
+
100
+ if (!authToken) {
101
+ throw new Error(
102
+ "No API key or credential provided. " +
103
+ "Either set OPENAI_API_KEY or pass a credential from authenticate().",
104
+ );
105
+ }
106
+
107
+ // Use injectable WebSocket or globalThis.WebSocket
108
+ const WS = options?.websocket ?? globalThis.WebSocket;
109
+ if (!WS) {
110
+ throw new Error(
111
+ "No WebSocket available. In Node.js <22, use WebSocketTransport with the 'ws' package:\n" +
112
+ " import WebSocket from 'ws';\n" +
113
+ " import { WebSocketTransport } from 'kernl';\n" +
114
+ " new RealtimeSession(agent, { transport: new WebSocketTransport({ websocket: WebSocket }), ... })",
115
+ );
116
+ }
117
+
118
+ const url = `${this.baseUrl}?model=${this.modelId}`;
119
+
120
+ // Use subprotocol auth (works in browsers and Node)
121
+ // Note: Don't include openai-beta.realtime-v1 when using ephemeral tokens -
122
+ // the version is encoded in the token itself
123
+ const protocols = ["realtime", `openai-insecure-api-key.${authToken}`];
124
+ const ws = new WS(url, protocols);
125
+
126
+ const connection = new OpenAIRealtimeConnection(ws);
127
+
128
+ await new Promise<void>((resolve, reject) => {
129
+ if (options?.abort?.aborted) {
130
+ return reject(new Error("Connection aborted"));
131
+ }
132
+
133
+ const onOpen = () => {
134
+ cleanup();
135
+ resolve();
136
+ };
137
+ const onError = (event: unknown) => {
138
+ cleanup();
139
+ const err =
140
+ event instanceof Error
141
+ ? event
142
+ : new Error("WebSocket connection failed");
143
+ reject(err);
144
+ };
145
+ const onAbort = () => {
146
+ cleanup();
147
+ ws.close();
148
+ reject(new Error("Connection aborted"));
149
+ };
150
+
151
+ const cleanup = () => {
152
+ ws.removeEventListener("open", onOpen);
153
+ ws.removeEventListener("error", onError);
154
+ options?.abort?.removeEventListener("abort", onAbort);
155
+ };
156
+
157
+ ws.addEventListener("open", onOpen);
158
+ ws.addEventListener("error", onError);
159
+ options?.abort?.addEventListener("abort", onAbort);
160
+ });
161
+
162
+ return connection;
163
+ }
164
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"event.test.d.ts","sourceRoot":"","sources":["../../../src/convert/__tests__/event.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/convert/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,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/B,QAAQ,CAAC,QAAQ,YAAY;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAU5D;;OAEG;IACG,OAAO,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAmD7E"}
File without changes
File without changes