@discomedia/utils 1.0.34 → 1.0.36

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.
@@ -269,7 +269,7 @@ const safeJSON = (text) => {
269
269
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
270
270
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
271
271
 
272
- const VERSION = '5.16.0'; // x-release-please-version
272
+ const VERSION = '5.23.1'; // x-release-please-version
273
273
 
274
274
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
275
275
  const isRunningInBrowser = () => {
@@ -3672,15 +3672,18 @@ class TranscriptionSessions extends APIResource {
3672
3672
  }
3673
3673
 
3674
3674
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3675
- class Realtime extends APIResource {
3675
+ /**
3676
+ * @deprecated Realtime has now launched and is generally available. The old beta API is now deprecated.
3677
+ */
3678
+ let Realtime$1 = class Realtime extends APIResource {
3676
3679
  constructor() {
3677
3680
  super(...arguments);
3678
3681
  this.sessions = new Sessions(this._client);
3679
3682
  this.transcriptionSessions = new TranscriptionSessions(this._client);
3680
3683
  }
3681
- }
3682
- Realtime.Sessions = Sessions;
3683
- Realtime.TranscriptionSessions = TranscriptionSessions;
3684
+ };
3685
+ Realtime$1.Sessions = Sessions;
3686
+ Realtime$1.TranscriptionSessions = TranscriptionSessions;
3684
3687
 
3685
3688
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3686
3689
  /**
@@ -4618,12 +4621,12 @@ Threads.Messages = Messages;
4618
4621
  class Beta extends APIResource {
4619
4622
  constructor() {
4620
4623
  super(...arguments);
4621
- this.realtime = new Realtime(this._client);
4624
+ this.realtime = new Realtime$1(this._client);
4622
4625
  this.assistants = new Assistants(this._client);
4623
4626
  this.threads = new Threads(this._client);
4624
4627
  }
4625
4628
  }
4626
- Beta.Realtime = Realtime;
4629
+ Beta.Realtime = Realtime$1;
4627
4630
  Beta.Assistants = Assistants;
4628
4631
  Beta.Threads = Threads;
4629
4632
 
@@ -4773,23 +4776,23 @@ class Conversations extends APIResource {
4773
4776
  /**
4774
4777
  * Create a conversation.
4775
4778
  */
4776
- create(body, options) {
4779
+ create(body = {}, options) {
4777
4780
  return this._client.post('/conversations', { body, ...options });
4778
4781
  }
4779
4782
  /**
4780
- * Get a conversation with the given ID.
4783
+ * Get a conversation
4781
4784
  */
4782
4785
  retrieve(conversationID, options) {
4783
4786
  return this._client.get(path `/conversations/${conversationID}`, options);
4784
4787
  }
4785
4788
  /**
4786
- * Update a conversation's metadata with the given ID.
4789
+ * Update a conversation
4787
4790
  */
4788
4791
  update(conversationID, body, options) {
4789
4792
  return this._client.post(path `/conversations/${conversationID}`, { body, ...options });
4790
4793
  }
4791
4794
  /**
4792
- * Delete a conversation with the given ID.
4795
+ * Delete a conversation. Items in the conversation will not be deleted.
4793
4796
  */
4794
4797
  delete(conversationID, options) {
4795
4798
  return this._client.delete(path `/conversations/${conversationID}`, options);
@@ -5384,6 +5387,25 @@ class Moderations extends APIResource {
5384
5387
  }
5385
5388
  }
5386
5389
 
5390
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5391
+ class ClientSecrets extends APIResource {
5392
+ /**
5393
+ * Create a Realtime client secret with an associated session configuration.
5394
+ */
5395
+ create(body, options) {
5396
+ return this._client.post('/realtime/client_secrets', { body, ...options });
5397
+ }
5398
+ }
5399
+
5400
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5401
+ class Realtime extends APIResource {
5402
+ constructor() {
5403
+ super(...arguments);
5404
+ this.clientSecrets = new ClientSecrets(this._client);
5405
+ }
5406
+ }
5407
+ Realtime.ClientSecrets = ClientSecrets;
5408
+
5387
5409
  function maybeParseResponse(response, params) {
5388
5410
  if (!params || !hasAutoParseableInput(params)) {
5389
5411
  return {
@@ -5634,8 +5656,16 @@ class ResponseStream extends EventStream {
5634
5656
  if (!output) {
5635
5657
  throw new OpenAIError(`missing output at index ${event.output_index}`);
5636
5658
  }
5637
- if (output.type === 'message') {
5638
- output.content.push(event.part);
5659
+ const type = output.type;
5660
+ const part = event.part;
5661
+ if (type === 'message' && part.type !== 'reasoning_text') {
5662
+ output.content.push(part);
5663
+ }
5664
+ else if (type === 'reasoning' && part.type === 'reasoning_text') {
5665
+ if (!output.content) {
5666
+ output.content = [];
5667
+ }
5668
+ output.content.push(part);
5639
5669
  }
5640
5670
  break;
5641
5671
  }
@@ -5666,6 +5696,23 @@ class ResponseStream extends EventStream {
5666
5696
  }
5667
5697
  break;
5668
5698
  }
5699
+ case 'response.reasoning_text.delta': {
5700
+ const output = snapshot.output[event.output_index];
5701
+ if (!output) {
5702
+ throw new OpenAIError(`missing output at index ${event.output_index}`);
5703
+ }
5704
+ if (output.type === 'reasoning') {
5705
+ const content = output.content?.[event.content_index];
5706
+ if (!content) {
5707
+ throw new OpenAIError(`missing content at index ${event.content_index}`);
5708
+ }
5709
+ if (content.type !== 'reasoning_text') {
5710
+ throw new OpenAIError(`expected content to be 'reasoning_text', got ${content.type}`);
5711
+ }
5712
+ content.text += event.delta;
5713
+ }
5714
+ break;
5715
+ }
5669
5716
  case 'response.completed': {
5670
5717
  __classPrivateFieldSet(this, _ResponseStream_currentResponseSnapshot, event.response);
5671
5718
  break;
@@ -6390,11 +6437,12 @@ class OpenAI {
6390
6437
  this.batches = new Batches(this);
6391
6438
  this.uploads = new Uploads(this);
6392
6439
  this.responses = new Responses(this);
6440
+ this.realtime = new Realtime(this);
6393
6441
  this.conversations = new Conversations(this);
6394
6442
  this.evals = new Evals(this);
6395
6443
  this.containers = new Containers(this);
6396
6444
  if (apiKey === undefined) {
6397
- 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' }).");
6445
+ throw new OpenAIError('Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.');
6398
6446
  }
6399
6447
  const options = {
6400
6448
  apiKey,
@@ -6422,7 +6470,7 @@ class OpenAI {
6422
6470
  this.fetch = options.fetch ?? getDefaultFetch();
6423
6471
  __classPrivateFieldSet(this, _OpenAI_encoder, FallbackEncoder);
6424
6472
  this._options = options;
6425
- this.apiKey = apiKey;
6473
+ this.apiKey = typeof apiKey === 'string' ? apiKey : 'Missing Key';
6426
6474
  this.organization = organization;
6427
6475
  this.project = project;
6428
6476
  this.webhookSecret = webhookSecret;
@@ -6469,6 +6517,27 @@ class OpenAI {
6469
6517
  makeStatusError(status, error, message, headers) {
6470
6518
  return APIError.generate(status, error, message, headers);
6471
6519
  }
6520
+ async _callApiKey() {
6521
+ const apiKey = this._options.apiKey;
6522
+ if (typeof apiKey !== 'function')
6523
+ return false;
6524
+ let token;
6525
+ try {
6526
+ token = await apiKey();
6527
+ }
6528
+ catch (err) {
6529
+ if (err instanceof OpenAIError)
6530
+ throw err;
6531
+ throw new OpenAIError(`Failed to get token from 'apiKey' function: ${err.message}`,
6532
+ // @ts-ignore
6533
+ { cause: err });
6534
+ }
6535
+ if (typeof token !== 'string' || !token) {
6536
+ throw new OpenAIError(`Expected 'apiKey' function argument to return a string but it returned ${token}`);
6537
+ }
6538
+ this.apiKey = token;
6539
+ return true;
6540
+ }
6472
6541
  buildURL(path, query, defaultBaseURL) {
6473
6542
  const baseURL = (!__classPrivateFieldGet(this, _OpenAI_instances, "m", _OpenAI_baseURLOverridden).call(this) && defaultBaseURL) || this.baseURL;
6474
6543
  const url = isAbsoluteURL(path) ?
@@ -6486,7 +6555,9 @@ class OpenAI {
6486
6555
  /**
6487
6556
  * Used as a callback for mutating the given `FinalRequestOptions` object.
6488
6557
  */
6489
- async prepareOptions(options) { }
6558
+ async prepareOptions(options) {
6559
+ await this._callApiKey();
6560
+ }
6490
6561
  /**
6491
6562
  * Used as a callback for mutating the given `RequestInit` object.
6492
6563
  *
@@ -6545,7 +6616,7 @@ class OpenAI {
6545
6616
  const controller = new AbortController();
6546
6617
  const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
6547
6618
  const headersTime = Date.now();
6548
- if (response instanceof Error) {
6619
+ if (response instanceof globalThis.Error) {
6549
6620
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
6550
6621
  if (options.signal?.aborted) {
6551
6622
  throw new APIUserAbortError();
@@ -6836,6 +6907,7 @@ OpenAI.Beta = Beta;
6836
6907
  OpenAI.Batches = Batches;
6837
6908
  OpenAI.Uploads = Uploads;
6838
6909
  OpenAI.Responses = Responses;
6910
+ OpenAI.Realtime = Realtime;
6839
6911
  OpenAI.Conversations = Conversations;
6840
6912
  OpenAI.Evals = Evals;
6841
6913
  OpenAI.Containers = Containers;
@@ -13016,7 +13088,7 @@ var config = {};
13016
13088
 
13017
13089
  var main = {exports: {}};
13018
13090
 
13019
- var version = "17.2.1";
13091
+ var version = "17.2.2";
13020
13092
  var require$$4 = {
13021
13093
  version: version};
13022
13094