openai 4.78.1 → 4.79.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 (64) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +87 -0
  3. package/beta/realtime/index.d.ts +2 -0
  4. package/beta/realtime/index.d.ts.map +1 -0
  5. package/beta/realtime/index.js +6 -0
  6. package/beta/realtime/index.js.map +1 -0
  7. package/beta/realtime/index.mjs +2 -0
  8. package/beta/realtime/index.mjs.map +1 -0
  9. package/beta/realtime/internal-base.d.ts +47 -0
  10. package/beta/realtime/internal-base.d.ts.map +1 -0
  11. package/beta/realtime/internal-base.js +43 -0
  12. package/beta/realtime/internal-base.js.map +1 -0
  13. package/beta/realtime/internal-base.mjs +37 -0
  14. package/beta/realtime/internal-base.mjs.map +1 -0
  15. package/beta/realtime/websocket.d.ts +22 -0
  16. package/beta/realtime/websocket.d.ts.map +1 -0
  17. package/beta/realtime/websocket.js +91 -0
  18. package/beta/realtime/websocket.js.map +1 -0
  19. package/beta/realtime/websocket.mjs +64 -0
  20. package/beta/realtime/websocket.mjs.map +1 -0
  21. package/beta/realtime/ws.d.ts +19 -0
  22. package/beta/realtime/ws.d.ts.map +1 -0
  23. package/beta/realtime/ws.js +66 -0
  24. package/beta/realtime/ws.js.map +1 -0
  25. package/beta/realtime/ws.mjs +59 -0
  26. package/beta/realtime/ws.mjs.map +1 -0
  27. package/core.d.ts.map +1 -1
  28. package/core.js +28 -1
  29. package/core.js.map +1 -1
  30. package/core.mjs +28 -1
  31. package/core.mjs.map +1 -1
  32. package/index.d.mts +6 -6
  33. package/index.d.ts +6 -6
  34. package/index.d.ts.map +1 -1
  35. package/lib/EventEmitter.d.ts +45 -0
  36. package/lib/EventEmitter.d.ts.map +1 -0
  37. package/lib/EventEmitter.js +83 -0
  38. package/lib/EventEmitter.js.map +1 -0
  39. package/lib/EventEmitter.mjs +79 -0
  40. package/lib/EventEmitter.mjs.map +1 -0
  41. package/package.json +5 -1
  42. package/resources/beta/beta.d.ts +2 -2
  43. package/resources/beta/beta.d.ts.map +1 -1
  44. package/resources/beta/index.d.ts +1 -1
  45. package/resources/beta/index.d.ts.map +1 -1
  46. package/resources/beta/vector-stores/index.d.ts +1 -1
  47. package/resources/beta/vector-stores/index.d.ts.map +1 -1
  48. package/resources/beta/vector-stores/vector-stores.d.ts +3 -3
  49. package/resources/beta/vector-stores/vector-stores.d.ts.map +1 -1
  50. package/src/beta/realtime/index.ts +1 -0
  51. package/src/beta/realtime/internal-base.ts +83 -0
  52. package/src/beta/realtime/websocket.ts +97 -0
  53. package/src/beta/realtime/ws.ts +69 -0
  54. package/src/core.ts +35 -1
  55. package/src/index.ts +6 -6
  56. package/src/lib/EventEmitter.ts +98 -0
  57. package/src/resources/beta/beta.ts +2 -2
  58. package/src/resources/beta/index.ts +1 -1
  59. package/src/resources/beta/vector-stores/index.ts +1 -1
  60. package/src/resources/beta/vector-stores/vector-stores.ts +3 -3
  61. package/src/version.ts +1 -1
  62. package/version.d.ts +1 -1
  63. package/version.js +1 -1
  64. package/version.mjs +1 -1
package/src/index.ts CHANGED
@@ -137,7 +137,7 @@ export interface ClientOptions {
137
137
  * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
138
138
  * much longer than this timeout before the promise succeeds or fails.
139
139
  */
140
- timeout?: number;
140
+ timeout?: number | undefined;
141
141
 
142
142
  /**
143
143
  * An HTTP agent used to manage HTTP(S) connections.
@@ -145,7 +145,7 @@ export interface ClientOptions {
145
145
  * If not provided, an agent will be constructed by default in the Node.js environment,
146
146
  * otherwise no agent is used.
147
147
  */
148
- httpAgent?: Agent;
148
+ httpAgent?: Agent | undefined;
149
149
 
150
150
  /**
151
151
  * Specify a custom `fetch` function implementation.
@@ -161,7 +161,7 @@ export interface ClientOptions {
161
161
  *
162
162
  * @default 2
163
163
  */
164
- maxRetries?: number;
164
+ maxRetries?: number | undefined;
165
165
 
166
166
  /**
167
167
  * Default headers to include with every request to the API.
@@ -169,7 +169,7 @@ export interface ClientOptions {
169
169
  * These can be removed in individual requests by explicitly setting the
170
170
  * header to `undefined` or `null` in request options.
171
171
  */
172
- defaultHeaders?: Core.Headers;
172
+ defaultHeaders?: Core.Headers | undefined;
173
173
 
174
174
  /**
175
175
  * Default query parameters to include with every request to the API.
@@ -177,13 +177,13 @@ export interface ClientOptions {
177
177
  * These can be removed in individual requests by explicitly setting the
178
178
  * param to `undefined` in request options.
179
179
  */
180
- defaultQuery?: Core.DefaultQuery;
180
+ defaultQuery?: Core.DefaultQuery | undefined;
181
181
 
182
182
  /**
183
183
  * By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
184
184
  * Only set this option to `true` if you understand the risks and have appropriate mitigations in place.
185
185
  */
186
- dangerouslyAllowBrowser?: boolean;
186
+ dangerouslyAllowBrowser?: boolean | undefined;
187
187
  }
188
188
 
189
189
  /**
@@ -0,0 +1,98 @@
1
+ type EventListener<Events, EventType extends keyof Events> = Events[EventType];
2
+
3
+ type EventListeners<Events, EventType extends keyof Events> = Array<{
4
+ listener: EventListener<Events, EventType>;
5
+ once?: boolean;
6
+ }>;
7
+
8
+ export type EventParameters<Events, EventType extends keyof Events> = {
9
+ [Event in EventType]: EventListener<Events, EventType> extends (...args: infer P) => any ? P : never;
10
+ }[EventType];
11
+
12
+ export class EventEmitter<EventTypes extends Record<string, (...args: any) => any>> {
13
+ #listeners: {
14
+ [Event in keyof EventTypes]?: EventListeners<EventTypes, Event>;
15
+ } = {};
16
+
17
+ /**
18
+ * Adds the listener function to the end of the listeners array for the event.
19
+ * No checks are made to see if the listener has already been added. Multiple calls passing
20
+ * the same combination of event and listener will result in the listener being added, and
21
+ * called, multiple times.
22
+ * @returns this, so that calls can be chained
23
+ */
24
+ on<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {
25
+ const listeners: EventListeners<EventTypes, Event> =
26
+ this.#listeners[event] || (this.#listeners[event] = []);
27
+ listeners.push({ listener });
28
+ return this;
29
+ }
30
+
31
+ /**
32
+ * Removes the specified listener from the listener array for the event.
33
+ * off() will remove, at most, one instance of a listener from the listener array. If any single
34
+ * listener has been added multiple times to the listener array for the specified event, then
35
+ * off() must be called multiple times to remove each instance.
36
+ * @returns this, so that calls can be chained
37
+ */
38
+ off<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {
39
+ const listeners = this.#listeners[event];
40
+ if (!listeners) return this;
41
+ const index = listeners.findIndex((l) => l.listener === listener);
42
+ if (index >= 0) listeners.splice(index, 1);
43
+ return this;
44
+ }
45
+
46
+ /**
47
+ * Adds a one-time listener function for the event. The next time the event is triggered,
48
+ * this listener is removed and then invoked.
49
+ * @returns this, so that calls can be chained
50
+ */
51
+ once<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {
52
+ const listeners: EventListeners<EventTypes, Event> =
53
+ this.#listeners[event] || (this.#listeners[event] = []);
54
+ listeners.push({ listener, once: true });
55
+ return this;
56
+ }
57
+
58
+ /**
59
+ * This is similar to `.once()`, but returns a Promise that resolves the next time
60
+ * the event is triggered, instead of calling a listener callback.
61
+ * @returns a Promise that resolves the next time given event is triggered,
62
+ * or rejects if an error is emitted. (If you request the 'error' event,
63
+ * returns a promise that resolves with the error).
64
+ *
65
+ * Example:
66
+ *
67
+ * const message = await stream.emitted('message') // rejects if the stream errors
68
+ */
69
+ emitted<Event extends keyof EventTypes>(
70
+ event: Event,
71
+ ): Promise<
72
+ EventParameters<EventTypes, Event> extends [infer Param] ? Param
73
+ : EventParameters<EventTypes, Event> extends [] ? void
74
+ : EventParameters<EventTypes, Event>
75
+ > {
76
+ return new Promise((resolve, reject) => {
77
+ // TODO: handle errors
78
+ this.once(event, resolve as any);
79
+ });
80
+ }
81
+
82
+ protected _emit<Event extends keyof EventTypes>(
83
+ this: EventEmitter<EventTypes>,
84
+ event: Event,
85
+ ...args: EventParameters<EventTypes, Event>
86
+ ) {
87
+ const listeners: EventListeners<EventTypes, Event> | undefined = this.#listeners[event];
88
+ if (listeners) {
89
+ this.#listeners[event] = listeners.filter((l) => !l.once) as any;
90
+ listeners.forEach(({ listener }: any) => listener(...(args as any)));
91
+ }
92
+ }
93
+
94
+ protected _hasListener(event: keyof EventTypes): boolean {
95
+ const listeners = this.#listeners[event];
96
+ return listeners && listeners.length > 0;
97
+ }
98
+ }
@@ -48,7 +48,7 @@ import {
48
48
  OtherFileChunkingStrategyObject,
49
49
  StaticFileChunkingStrategy,
50
50
  StaticFileChunkingStrategyObject,
51
- StaticFileChunkingStrategyParam,
51
+ StaticFileChunkingStrategyObjectParam,
52
52
  VectorStore,
53
53
  VectorStoreCreateParams,
54
54
  VectorStoreDeleted,
@@ -85,7 +85,7 @@ export declare namespace Beta {
85
85
  type OtherFileChunkingStrategyObject as OtherFileChunkingStrategyObject,
86
86
  type StaticFileChunkingStrategy as StaticFileChunkingStrategy,
87
87
  type StaticFileChunkingStrategyObject as StaticFileChunkingStrategyObject,
88
- type StaticFileChunkingStrategyParam as StaticFileChunkingStrategyParam,
88
+ type StaticFileChunkingStrategyObjectParam as StaticFileChunkingStrategyObjectParam,
89
89
  type VectorStore as VectorStore,
90
90
  type VectorStoreDeleted as VectorStoreDeleted,
91
91
  VectorStoresPage as VectorStoresPage,
@@ -46,7 +46,7 @@ export {
46
46
  type OtherFileChunkingStrategyObject,
47
47
  type StaticFileChunkingStrategy,
48
48
  type StaticFileChunkingStrategyObject,
49
- type StaticFileChunkingStrategyParam,
49
+ type StaticFileChunkingStrategyObjectParam,
50
50
  type VectorStore,
51
51
  type VectorStoreDeleted,
52
52
  type VectorStoreCreateParams,
@@ -23,7 +23,7 @@ export {
23
23
  type OtherFileChunkingStrategyObject,
24
24
  type StaticFileChunkingStrategy,
25
25
  type StaticFileChunkingStrategyObject,
26
- type StaticFileChunkingStrategyParam,
26
+ type StaticFileChunkingStrategyObjectParam,
27
27
  type VectorStore,
28
28
  type VectorStoreDeleted,
29
29
  type VectorStoreCreateParams,
@@ -116,7 +116,7 @@ export type FileChunkingStrategy = StaticFileChunkingStrategyObject | OtherFileC
116
116
  * The chunking strategy used to chunk the file(s). If not set, will use the `auto`
117
117
  * strategy. Only applicable if `file_ids` is non-empty.
118
118
  */
119
- export type FileChunkingStrategyParam = AutoFileChunkingStrategyParam | StaticFileChunkingStrategyParam;
119
+ export type FileChunkingStrategyParam = AutoFileChunkingStrategyParam | StaticFileChunkingStrategyObjectParam;
120
120
 
121
121
  /**
122
122
  * This is returned when the chunking strategy is unknown. Typically, this is
@@ -154,7 +154,7 @@ export interface StaticFileChunkingStrategyObject {
154
154
  type: 'static';
155
155
  }
156
156
 
157
- export interface StaticFileChunkingStrategyParam {
157
+ export interface StaticFileChunkingStrategyObjectParam {
158
158
  static: StaticFileChunkingStrategy;
159
159
 
160
160
  /**
@@ -397,7 +397,7 @@ export declare namespace VectorStores {
397
397
  type OtherFileChunkingStrategyObject as OtherFileChunkingStrategyObject,
398
398
  type StaticFileChunkingStrategy as StaticFileChunkingStrategy,
399
399
  type StaticFileChunkingStrategyObject as StaticFileChunkingStrategyObject,
400
- type StaticFileChunkingStrategyParam as StaticFileChunkingStrategyParam,
400
+ type StaticFileChunkingStrategyObjectParam as StaticFileChunkingStrategyObjectParam,
401
401
  type VectorStore as VectorStore,
402
402
  type VectorStoreDeleted as VectorStoreDeleted,
403
403
  VectorStoresPage as VectorStoresPage,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '4.78.1'; // x-release-please-version
1
+ export const VERSION = '4.79.0'; // x-release-please-version
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "4.78.1";
1
+ export declare const VERSION = "4.79.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '4.78.1'; // x-release-please-version
4
+ exports.VERSION = '4.79.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '4.78.1'; // x-release-please-version
1
+ export const VERSION = '4.79.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map