@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.
@@ -267,7 +267,7 @@ const safeJSON = (text) => {
267
267
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
268
268
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
269
269
 
270
- const VERSION = '5.16.0'; // x-release-please-version
270
+ const VERSION = '5.22.0'; // x-release-please-version
271
271
 
272
272
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
273
273
  const isRunningInBrowser = () => {
@@ -3670,15 +3670,18 @@ class TranscriptionSessions extends APIResource {
3670
3670
  }
3671
3671
 
3672
3672
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3673
- class Realtime extends APIResource {
3673
+ /**
3674
+ * @deprecated Realtime has now launched and is generally available. The old beta API is now deprecated.
3675
+ */
3676
+ let Realtime$1 = class Realtime extends APIResource {
3674
3677
  constructor() {
3675
3678
  super(...arguments);
3676
3679
  this.sessions = new Sessions(this._client);
3677
3680
  this.transcriptionSessions = new TranscriptionSessions(this._client);
3678
3681
  }
3679
- }
3680
- Realtime.Sessions = Sessions;
3681
- Realtime.TranscriptionSessions = TranscriptionSessions;
3682
+ };
3683
+ Realtime$1.Sessions = Sessions;
3684
+ Realtime$1.TranscriptionSessions = TranscriptionSessions;
3682
3685
 
3683
3686
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3684
3687
  /**
@@ -4616,12 +4619,12 @@ Threads.Messages = Messages;
4616
4619
  class Beta extends APIResource {
4617
4620
  constructor() {
4618
4621
  super(...arguments);
4619
- this.realtime = new Realtime(this._client);
4622
+ this.realtime = new Realtime$1(this._client);
4620
4623
  this.assistants = new Assistants(this._client);
4621
4624
  this.threads = new Threads(this._client);
4622
4625
  }
4623
4626
  }
4624
- Beta.Realtime = Realtime;
4627
+ Beta.Realtime = Realtime$1;
4625
4628
  Beta.Assistants = Assistants;
4626
4629
  Beta.Threads = Threads;
4627
4630
 
@@ -5382,6 +5385,25 @@ class Moderations extends APIResource {
5382
5385
  }
5383
5386
  }
5384
5387
 
5388
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5389
+ class ClientSecrets extends APIResource {
5390
+ /**
5391
+ * Create a Realtime client secret with an associated session configuration.
5392
+ */
5393
+ create(body, options) {
5394
+ return this._client.post('/realtime/client_secrets', { body, ...options });
5395
+ }
5396
+ }
5397
+
5398
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5399
+ class Realtime extends APIResource {
5400
+ constructor() {
5401
+ super(...arguments);
5402
+ this.clientSecrets = new ClientSecrets(this._client);
5403
+ }
5404
+ }
5405
+ Realtime.ClientSecrets = ClientSecrets;
5406
+
5385
5407
  function maybeParseResponse(response, params) {
5386
5408
  if (!params || !hasAutoParseableInput(params)) {
5387
5409
  return {
@@ -5632,8 +5654,16 @@ class ResponseStream extends EventStream {
5632
5654
  if (!output) {
5633
5655
  throw new OpenAIError(`missing output at index ${event.output_index}`);
5634
5656
  }
5635
- if (output.type === 'message') {
5636
- output.content.push(event.part);
5657
+ const type = output.type;
5658
+ const part = event.part;
5659
+ if (type === 'message' && part.type !== 'reasoning_text') {
5660
+ output.content.push(part);
5661
+ }
5662
+ else if (type === 'reasoning' && part.type === 'reasoning_text') {
5663
+ if (!output.content) {
5664
+ output.content = [];
5665
+ }
5666
+ output.content.push(part);
5637
5667
  }
5638
5668
  break;
5639
5669
  }
@@ -5664,6 +5694,23 @@ class ResponseStream extends EventStream {
5664
5694
  }
5665
5695
  break;
5666
5696
  }
5697
+ case 'response.reasoning_text.delta': {
5698
+ const output = snapshot.output[event.output_index];
5699
+ if (!output) {
5700
+ throw new OpenAIError(`missing output at index ${event.output_index}`);
5701
+ }
5702
+ if (output.type === 'reasoning') {
5703
+ const content = output.content?.[event.content_index];
5704
+ if (!content) {
5705
+ throw new OpenAIError(`missing content at index ${event.content_index}`);
5706
+ }
5707
+ if (content.type !== 'reasoning_text') {
5708
+ throw new OpenAIError(`expected content to be 'reasoning_text', got ${content.type}`);
5709
+ }
5710
+ content.text += event.delta;
5711
+ }
5712
+ break;
5713
+ }
5667
5714
  case 'response.completed': {
5668
5715
  __classPrivateFieldSet(this, _ResponseStream_currentResponseSnapshot, event.response);
5669
5716
  break;
@@ -6388,11 +6435,12 @@ class OpenAI {
6388
6435
  this.batches = new Batches(this);
6389
6436
  this.uploads = new Uploads(this);
6390
6437
  this.responses = new Responses(this);
6438
+ this.realtime = new Realtime(this);
6391
6439
  this.conversations = new Conversations(this);
6392
6440
  this.evals = new Evals(this);
6393
6441
  this.containers = new Containers(this);
6394
6442
  if (apiKey === undefined) {
6395
- 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' }).");
6443
+ throw new OpenAIError('Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.');
6396
6444
  }
6397
6445
  const options = {
6398
6446
  apiKey,
@@ -6420,7 +6468,7 @@ class OpenAI {
6420
6468
  this.fetch = options.fetch ?? getDefaultFetch();
6421
6469
  __classPrivateFieldSet(this, _OpenAI_encoder, FallbackEncoder);
6422
6470
  this._options = options;
6423
- this.apiKey = apiKey;
6471
+ this.apiKey = typeof apiKey === 'string' ? apiKey : 'Missing Key';
6424
6472
  this.organization = organization;
6425
6473
  this.project = project;
6426
6474
  this.webhookSecret = webhookSecret;
@@ -6467,6 +6515,27 @@ class OpenAI {
6467
6515
  makeStatusError(status, error, message, headers) {
6468
6516
  return APIError.generate(status, error, message, headers);
6469
6517
  }
6518
+ async _callApiKey() {
6519
+ const apiKey = this._options.apiKey;
6520
+ if (typeof apiKey !== 'function')
6521
+ return false;
6522
+ let token;
6523
+ try {
6524
+ token = await apiKey();
6525
+ }
6526
+ catch (err) {
6527
+ if (err instanceof OpenAIError)
6528
+ throw err;
6529
+ throw new OpenAIError(`Failed to get token from 'apiKey' function: ${err.message}`,
6530
+ // @ts-ignore
6531
+ { cause: err });
6532
+ }
6533
+ if (typeof token !== 'string' || !token) {
6534
+ throw new OpenAIError(`Expected 'apiKey' function argument to return a string but it returned ${token}`);
6535
+ }
6536
+ this.apiKey = token;
6537
+ return true;
6538
+ }
6470
6539
  buildURL(path, query, defaultBaseURL) {
6471
6540
  const baseURL = (!__classPrivateFieldGet(this, _OpenAI_instances, "m", _OpenAI_baseURLOverridden).call(this) && defaultBaseURL) || this.baseURL;
6472
6541
  const url = isAbsoluteURL(path) ?
@@ -6484,7 +6553,9 @@ class OpenAI {
6484
6553
  /**
6485
6554
  * Used as a callback for mutating the given `FinalRequestOptions` object.
6486
6555
  */
6487
- async prepareOptions(options) { }
6556
+ async prepareOptions(options) {
6557
+ await this._callApiKey();
6558
+ }
6488
6559
  /**
6489
6560
  * Used as a callback for mutating the given `RequestInit` object.
6490
6561
  *
@@ -6543,7 +6614,7 @@ class OpenAI {
6543
6614
  const controller = new AbortController();
6544
6615
  const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
6545
6616
  const headersTime = Date.now();
6546
- if (response instanceof Error) {
6617
+ if (response instanceof globalThis.Error) {
6547
6618
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
6548
6619
  if (options.signal?.aborted) {
6549
6620
  throw new APIUserAbortError();
@@ -6834,6 +6905,7 @@ OpenAI.Beta = Beta;
6834
6905
  OpenAI.Batches = Batches;
6835
6906
  OpenAI.Uploads = Uploads;
6836
6907
  OpenAI.Responses = Responses;
6908
+ OpenAI.Realtime = Realtime;
6837
6909
  OpenAI.Conversations = Conversations;
6838
6910
  OpenAI.Evals = Evals;
6839
6911
  OpenAI.Containers = Containers;
@@ -13014,7 +13086,7 @@ var config = {};
13014
13086
 
13015
13087
  var main = {exports: {}};
13016
13088
 
13017
- var version = "17.2.1";
13089
+ var version = "17.2.2";
13018
13090
  var require$$4 = {
13019
13091
  version: version};
13020
13092