@discomedia/utils 1.0.34 → 1.0.35

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.mjs CHANGED
@@ -2393,7 +2393,7 @@ const safeJSON = (text) => {
2393
2393
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2394
2394
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2395
2395
 
2396
- const VERSION = '5.16.0'; // x-release-please-version
2396
+ const VERSION = '5.22.0'; // x-release-please-version
2397
2397
 
2398
2398
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2399
2399
  const isRunningInBrowser = () => {
@@ -5796,15 +5796,18 @@ class TranscriptionSessions extends APIResource {
5796
5796
  }
5797
5797
 
5798
5798
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5799
- class Realtime extends APIResource {
5799
+ /**
5800
+ * @deprecated Realtime has now launched and is generally available. The old beta API is now deprecated.
5801
+ */
5802
+ let Realtime$1 = class Realtime extends APIResource {
5800
5803
  constructor() {
5801
5804
  super(...arguments);
5802
5805
  this.sessions = new Sessions(this._client);
5803
5806
  this.transcriptionSessions = new TranscriptionSessions(this._client);
5804
5807
  }
5805
- }
5806
- Realtime.Sessions = Sessions;
5807
- Realtime.TranscriptionSessions = TranscriptionSessions;
5808
+ };
5809
+ Realtime$1.Sessions = Sessions;
5810
+ Realtime$1.TranscriptionSessions = TranscriptionSessions;
5808
5811
 
5809
5812
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5810
5813
  /**
@@ -6742,12 +6745,12 @@ Threads.Messages = Messages;
6742
6745
  class Beta extends APIResource {
6743
6746
  constructor() {
6744
6747
  super(...arguments);
6745
- this.realtime = new Realtime(this._client);
6748
+ this.realtime = new Realtime$1(this._client);
6746
6749
  this.assistants = new Assistants(this._client);
6747
6750
  this.threads = new Threads(this._client);
6748
6751
  }
6749
6752
  }
6750
- Beta.Realtime = Realtime;
6753
+ Beta.Realtime = Realtime$1;
6751
6754
  Beta.Assistants = Assistants;
6752
6755
  Beta.Threads = Threads;
6753
6756
 
@@ -7508,6 +7511,25 @@ class Moderations extends APIResource {
7508
7511
  }
7509
7512
  }
7510
7513
 
7514
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
7515
+ class ClientSecrets extends APIResource {
7516
+ /**
7517
+ * Create a Realtime client secret with an associated session configuration.
7518
+ */
7519
+ create(body, options) {
7520
+ return this._client.post('/realtime/client_secrets', { body, ...options });
7521
+ }
7522
+ }
7523
+
7524
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
7525
+ class Realtime extends APIResource {
7526
+ constructor() {
7527
+ super(...arguments);
7528
+ this.clientSecrets = new ClientSecrets(this._client);
7529
+ }
7530
+ }
7531
+ Realtime.ClientSecrets = ClientSecrets;
7532
+
7511
7533
  function maybeParseResponse(response, params) {
7512
7534
  if (!params || !hasAutoParseableInput(params)) {
7513
7535
  return {
@@ -7758,8 +7780,16 @@ class ResponseStream extends EventStream {
7758
7780
  if (!output) {
7759
7781
  throw new OpenAIError(`missing output at index ${event.output_index}`);
7760
7782
  }
7761
- if (output.type === 'message') {
7762
- output.content.push(event.part);
7783
+ const type = output.type;
7784
+ const part = event.part;
7785
+ if (type === 'message' && part.type !== 'reasoning_text') {
7786
+ output.content.push(part);
7787
+ }
7788
+ else if (type === 'reasoning' && part.type === 'reasoning_text') {
7789
+ if (!output.content) {
7790
+ output.content = [];
7791
+ }
7792
+ output.content.push(part);
7763
7793
  }
7764
7794
  break;
7765
7795
  }
@@ -7790,6 +7820,23 @@ class ResponseStream extends EventStream {
7790
7820
  }
7791
7821
  break;
7792
7822
  }
7823
+ case 'response.reasoning_text.delta': {
7824
+ const output = snapshot.output[event.output_index];
7825
+ if (!output) {
7826
+ throw new OpenAIError(`missing output at index ${event.output_index}`);
7827
+ }
7828
+ if (output.type === 'reasoning') {
7829
+ const content = output.content?.[event.content_index];
7830
+ if (!content) {
7831
+ throw new OpenAIError(`missing content at index ${event.content_index}`);
7832
+ }
7833
+ if (content.type !== 'reasoning_text') {
7834
+ throw new OpenAIError(`expected content to be 'reasoning_text', got ${content.type}`);
7835
+ }
7836
+ content.text += event.delta;
7837
+ }
7838
+ break;
7839
+ }
7793
7840
  case 'response.completed': {
7794
7841
  __classPrivateFieldSet(this, _ResponseStream_currentResponseSnapshot, event.response);
7795
7842
  break;
@@ -8514,11 +8561,12 @@ class OpenAI {
8514
8561
  this.batches = new Batches(this);
8515
8562
  this.uploads = new Uploads(this);
8516
8563
  this.responses = new Responses(this);
8564
+ this.realtime = new Realtime(this);
8517
8565
  this.conversations = new Conversations(this);
8518
8566
  this.evals = new Evals(this);
8519
8567
  this.containers = new Containers(this);
8520
8568
  if (apiKey === undefined) {
8521
- throw new OpenAIError("The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }).");
8569
+ throw new OpenAIError('Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.');
8522
8570
  }
8523
8571
  const options = {
8524
8572
  apiKey,
@@ -8546,7 +8594,7 @@ class OpenAI {
8546
8594
  this.fetch = options.fetch ?? getDefaultFetch();
8547
8595
  __classPrivateFieldSet(this, _OpenAI_encoder, FallbackEncoder);
8548
8596
  this._options = options;
8549
- this.apiKey = apiKey;
8597
+ this.apiKey = typeof apiKey === 'string' ? apiKey : 'Missing Key';
8550
8598
  this.organization = organization;
8551
8599
  this.project = project;
8552
8600
  this.webhookSecret = webhookSecret;
@@ -8593,6 +8641,27 @@ class OpenAI {
8593
8641
  makeStatusError(status, error, message, headers) {
8594
8642
  return APIError.generate(status, error, message, headers);
8595
8643
  }
8644
+ async _callApiKey() {
8645
+ const apiKey = this._options.apiKey;
8646
+ if (typeof apiKey !== 'function')
8647
+ return false;
8648
+ let token;
8649
+ try {
8650
+ token = await apiKey();
8651
+ }
8652
+ catch (err) {
8653
+ if (err instanceof OpenAIError)
8654
+ throw err;
8655
+ throw new OpenAIError(`Failed to get token from 'apiKey' function: ${err.message}`,
8656
+ // @ts-ignore
8657
+ { cause: err });
8658
+ }
8659
+ if (typeof token !== 'string' || !token) {
8660
+ throw new OpenAIError(`Expected 'apiKey' function argument to return a string but it returned ${token}`);
8661
+ }
8662
+ this.apiKey = token;
8663
+ return true;
8664
+ }
8596
8665
  buildURL(path, query, defaultBaseURL) {
8597
8666
  const baseURL = (!__classPrivateFieldGet(this, _OpenAI_instances, "m", _OpenAI_baseURLOverridden).call(this) && defaultBaseURL) || this.baseURL;
8598
8667
  const url = isAbsoluteURL(path) ?
@@ -8610,7 +8679,9 @@ class OpenAI {
8610
8679
  /**
8611
8680
  * Used as a callback for mutating the given `FinalRequestOptions` object.
8612
8681
  */
8613
- async prepareOptions(options) { }
8682
+ async prepareOptions(options) {
8683
+ await this._callApiKey();
8684
+ }
8614
8685
  /**
8615
8686
  * Used as a callback for mutating the given `RequestInit` object.
8616
8687
  *
@@ -8669,7 +8740,7 @@ class OpenAI {
8669
8740
  const controller = new AbortController();
8670
8741
  const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
8671
8742
  const headersTime = Date.now();
8672
- if (response instanceof Error) {
8743
+ if (response instanceof globalThis.Error) {
8673
8744
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
8674
8745
  if (options.signal?.aborted) {
8675
8746
  throw new APIUserAbortError();
@@ -8960,6 +9031,7 @@ OpenAI.Beta = Beta;
8960
9031
  OpenAI.Batches = Batches;
8961
9032
  OpenAI.Uploads = Uploads;
8962
9033
  OpenAI.Responses = Responses;
9034
+ OpenAI.Realtime = Realtime;
8963
9035
  OpenAI.Conversations = Conversations;
8964
9036
  OpenAI.Evals = Evals;
8965
9037
  OpenAI.Containers = Containers;
@@ -15771,7 +15843,7 @@ var config = {};
15771
15843
 
15772
15844
  var main = {exports: {}};
15773
15845
 
15774
- var version = "17.2.1";
15846
+ var version = "17.2.2";
15775
15847
  var require$$4 = {
15776
15848
  version: version};
15777
15849