@discomedia/utils 1.0.39 → 1.0.40

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.
@@ -255,7 +255,7 @@ const safeJSON = (text) => {
255
255
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
256
256
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
257
257
 
258
- const VERSION = '6.1.0'; // x-release-please-version
258
+ const VERSION = '6.2.0'; // x-release-please-version
259
259
 
260
260
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
261
261
  const isRunningInBrowser = () => {
@@ -1656,6 +1656,15 @@ function getName(value) {
1656
1656
  .pop() || undefined);
1657
1657
  }
1658
1658
  const isAsyncIterable = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
1659
+ /**
1660
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
1661
+ * Otherwise returns the request as is.
1662
+ */
1663
+ const maybeMultipartFormRequestOptions = async (opts, fetch) => {
1664
+ if (!hasUploadableValue(opts.body))
1665
+ return opts;
1666
+ return { ...opts, body: await createForm(opts.body, fetch) };
1667
+ };
1659
1668
  const multipartFormRequestOptions = async (opts, fetch) => {
1660
1669
  return { ...opts, body: await createForm(opts.body, fetch) };
1661
1670
  };
@@ -1701,6 +1710,22 @@ const createForm = async (body, fetch) => {
1701
1710
  // We check for Blob not File because Bun.File doesn't inherit from File,
1702
1711
  // but they both inherit from Blob and have a `name` property at runtime.
1703
1712
  const isNamedBlob = (value) => value instanceof Blob && 'name' in value;
1713
+ const isUploadable = (value) => typeof value === 'object' &&
1714
+ value !== null &&
1715
+ (value instanceof Response || isAsyncIterable(value) || isNamedBlob(value));
1716
+ const hasUploadableValue = (value) => {
1717
+ if (isUploadable(value))
1718
+ return true;
1719
+ if (Array.isArray(value))
1720
+ return value.some(hasUploadableValue);
1721
+ if (value && typeof value === 'object') {
1722
+ for (const k in value) {
1723
+ if (hasUploadableValue(value[k]))
1724
+ return true;
1725
+ }
1726
+ }
1727
+ return false;
1728
+ };
1704
1729
  const addFormValue = async (form, key, value) => {
1705
1730
  if (value === undefined)
1706
1731
  return;
@@ -1755,7 +1780,7 @@ const isResponseLike = (value) => value != null &&
1755
1780
  typeof value.blob === 'function';
1756
1781
  /**
1757
1782
  * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
1758
- * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
1783
+ * @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts
1759
1784
  * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
1760
1785
  * @param {Object=} options additional properties
1761
1786
  * @param {string=} options.type the MIME type of the content
@@ -3606,7 +3631,7 @@ class Assistants extends APIResource {
3606
3631
  }
3607
3632
 
3608
3633
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3609
- class Sessions extends APIResource {
3634
+ let Sessions$1 = class Sessions extends APIResource {
3610
3635
  /**
3611
3636
  * Create an ephemeral API token for use in client-side applications with the
3612
3637
  * Realtime API. Can be configured with the same session parameters as the
@@ -3629,7 +3654,7 @@ class Sessions extends APIResource {
3629
3654
  headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),
3630
3655
  });
3631
3656
  }
3632
- }
3657
+ };
3633
3658
 
3634
3659
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3635
3660
  class TranscriptionSessions extends APIResource {
@@ -3664,13 +3689,144 @@ class TranscriptionSessions extends APIResource {
3664
3689
  let Realtime$1 = class Realtime extends APIResource {
3665
3690
  constructor() {
3666
3691
  super(...arguments);
3667
- this.sessions = new Sessions(this._client);
3692
+ this.sessions = new Sessions$1(this._client);
3668
3693
  this.transcriptionSessions = new TranscriptionSessions(this._client);
3669
3694
  }
3670
3695
  };
3671
- Realtime$1.Sessions = Sessions;
3696
+ Realtime$1.Sessions = Sessions$1;
3672
3697
  Realtime$1.TranscriptionSessions = TranscriptionSessions;
3673
3698
 
3699
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3700
+ class Sessions extends APIResource {
3701
+ /**
3702
+ * Create a ChatKit session
3703
+ *
3704
+ * @example
3705
+ * ```ts
3706
+ * const chatSession =
3707
+ * await client.beta.chatkit.sessions.create({
3708
+ * user: 'x',
3709
+ * workflow: { id: 'id' },
3710
+ * });
3711
+ * ```
3712
+ */
3713
+ create(body, options) {
3714
+ return this._client.post('/chatkit/sessions', {
3715
+ body,
3716
+ ...options,
3717
+ headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
3718
+ });
3719
+ }
3720
+ /**
3721
+ * Cancel a ChatKit session
3722
+ *
3723
+ * @example
3724
+ * ```ts
3725
+ * const chatSession =
3726
+ * await client.beta.chatkit.sessions.cancel('cksess_123');
3727
+ * ```
3728
+ */
3729
+ cancel(sessionID, options) {
3730
+ return this._client.post(path `/chatkit/sessions/${sessionID}/cancel`, {
3731
+ ...options,
3732
+ headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
3733
+ });
3734
+ }
3735
+ }
3736
+
3737
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3738
+ let Threads$1 = class Threads extends APIResource {
3739
+ /**
3740
+ * Retrieve a ChatKit thread
3741
+ *
3742
+ * @example
3743
+ * ```ts
3744
+ * const chatkitThread =
3745
+ * await client.beta.chatkit.threads.retrieve('cthr_123');
3746
+ * ```
3747
+ */
3748
+ retrieve(threadID, options) {
3749
+ return this._client.get(path `/chatkit/threads/${threadID}`, {
3750
+ ...options,
3751
+ headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
3752
+ });
3753
+ }
3754
+ /**
3755
+ * List ChatKit threads
3756
+ *
3757
+ * @example
3758
+ * ```ts
3759
+ * // Automatically fetches more pages as needed.
3760
+ * for await (const chatkitThread of client.beta.chatkit.threads.list()) {
3761
+ * // ...
3762
+ * }
3763
+ * ```
3764
+ */
3765
+ list(query = {}, options) {
3766
+ return this._client.getAPIList('/chatkit/threads', (ConversationCursorPage), {
3767
+ query,
3768
+ ...options,
3769
+ headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
3770
+ });
3771
+ }
3772
+ /**
3773
+ * Delete a ChatKit thread
3774
+ *
3775
+ * @example
3776
+ * ```ts
3777
+ * const thread = await client.beta.chatkit.threads.delete(
3778
+ * 'cthr_123',
3779
+ * );
3780
+ * ```
3781
+ */
3782
+ delete(threadID, options) {
3783
+ return this._client.delete(path `/chatkit/threads/${threadID}`, {
3784
+ ...options,
3785
+ headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
3786
+ });
3787
+ }
3788
+ /**
3789
+ * List ChatKit thread items
3790
+ *
3791
+ * @example
3792
+ * ```ts
3793
+ * // Automatically fetches more pages as needed.
3794
+ * for await (const thread of client.beta.chatkit.threads.listItems(
3795
+ * 'cthr_123',
3796
+ * )) {
3797
+ * // ...
3798
+ * }
3799
+ * ```
3800
+ */
3801
+ listItems(threadID, query = {}, options) {
3802
+ return this._client.getAPIList(path `/chatkit/threads/${threadID}/items`, (ConversationCursorPage), { query, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]) });
3803
+ }
3804
+ };
3805
+
3806
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3807
+ class ChatKit extends APIResource {
3808
+ constructor() {
3809
+ super(...arguments);
3810
+ this.sessions = new Sessions(this._client);
3811
+ this.threads = new Threads$1(this._client);
3812
+ }
3813
+ /**
3814
+ * Upload a ChatKit file
3815
+ *
3816
+ * @example
3817
+ * ```ts
3818
+ * const response = await client.beta.chatkit.uploadFile({
3819
+ * file: fs.createReadStream('path/to/file'),
3820
+ * });
3821
+ * ```
3822
+ */
3823
+ uploadFile(body, options) {
3824
+ return this._client.post('/chatkit/files', maybeMultipartFormRequestOptions({ body, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]) }, this._client));
3825
+ }
3826
+ }
3827
+ ChatKit.Sessions = Sessions;
3828
+ ChatKit.Threads = Threads$1;
3829
+
3674
3830
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3675
3831
  /**
3676
3832
  * @deprecated The Assistants API is deprecated in favor of the Responses API
@@ -4608,11 +4764,13 @@ class Beta extends APIResource {
4608
4764
  constructor() {
4609
4765
  super(...arguments);
4610
4766
  this.realtime = new Realtime$1(this._client);
4767
+ this.chatkit = new ChatKit(this._client);
4611
4768
  this.assistants = new Assistants(this._client);
4612
4769
  this.threads = new Threads(this._client);
4613
4770
  }
4614
4771
  }
4615
4772
  Beta.Realtime = Realtime$1;
4773
+ Beta.ChatKit = ChatKit;
4616
4774
  Beta.Assistants = Assistants;
4617
4775
  Beta.Threads = Threads;
4618
4776
 
@@ -6365,6 +6523,51 @@ class VectorStores extends APIResource {
6365
6523
  VectorStores.Files = Files;
6366
6524
  VectorStores.FileBatches = FileBatches;
6367
6525
 
6526
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
6527
+ class Videos extends APIResource {
6528
+ /**
6529
+ * Create a video
6530
+ */
6531
+ create(body, options) {
6532
+ return this._client.post('/videos', maybeMultipartFormRequestOptions({ body, ...options }, this._client));
6533
+ }
6534
+ /**
6535
+ * Retrieve a video
6536
+ */
6537
+ retrieve(videoID, options) {
6538
+ return this._client.get(path `/videos/${videoID}`, options);
6539
+ }
6540
+ /**
6541
+ * List videos
6542
+ */
6543
+ list(query = {}, options) {
6544
+ return this._client.getAPIList('/videos', (ConversationCursorPage), { query, ...options });
6545
+ }
6546
+ /**
6547
+ * Delete a video
6548
+ */
6549
+ delete(videoID, options) {
6550
+ return this._client.delete(path `/videos/${videoID}`, options);
6551
+ }
6552
+ /**
6553
+ * Download video content
6554
+ */
6555
+ downloadContent(videoID, query = {}, options) {
6556
+ return this._client.get(path `/videos/${videoID}/content`, {
6557
+ query,
6558
+ ...options,
6559
+ headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),
6560
+ __binaryResponse: true,
6561
+ });
6562
+ }
6563
+ /**
6564
+ * Create a video remix
6565
+ */
6566
+ remix(videoID, body, options) {
6567
+ return this._client.post(path `/videos/${videoID}/remix`, maybeMultipartFormRequestOptions({ body, ...options }, this._client));
6568
+ }
6569
+ }
6570
+
6368
6571
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
6369
6572
  var _Webhooks_instances, _Webhooks_validateSecret, _Webhooks_getRequiredHeader;
6370
6573
  class Webhooks extends APIResource {
@@ -6503,6 +6706,7 @@ class OpenAI {
6503
6706
  this.conversations = new Conversations(this);
6504
6707
  this.evals = new Evals(this);
6505
6708
  this.containers = new Containers(this);
6709
+ this.videos = new Videos(this);
6506
6710
  if (apiKey === undefined) {
6507
6711
  throw new OpenAIError('Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.');
6508
6712
  }
@@ -6973,6 +7177,7 @@ OpenAI.Realtime = Realtime;
6973
7177
  OpenAI.Conversations = Conversations;
6974
7178
  OpenAI.Evals = Evals;
6975
7179
  OpenAI.Containers = Containers;
7180
+ OpenAI.Videos = Videos;
6976
7181
 
6977
7182
  // llm-openai-config.ts
6978
7183
  const DEFAULT_MODEL = 'gpt-4.1-mini';
@@ -8893,6 +9098,46 @@ function getNYTimeZone(date) {
8893
9098
  const offset = getNYOffset(date || new Date());
8894
9099
  return offset === -4 ? '-04:00' : '-05:00';
8895
9100
  }
9101
+ /**
9102
+ * Returns the regular market open and close Date objects for a given trading day string in the
9103
+ * America/New_York timezone (NYSE/NASDAQ calendar).
9104
+ *
9105
+ * This helper is convenient when you have a calendar date like '2025-10-03' and want the precise
9106
+ * open and close Date values for that day. It internally:
9107
+ * - Determines the NY offset for the day using `getNYTimeZone()`.
9108
+ * - Anchors a noon-time Date on that day in NY time to avoid DST edge cases.
9109
+ * - Verifies the day is a market day via `isMarketDay()`.
9110
+ * - Fetches the open/close times via `getMarketOpenClose()`.
9111
+ *
9112
+ * Throws if the provided day is not a market day or if open/close times are unavailable.
9113
+ *
9114
+ * See also:
9115
+ * - `getNYTimeZone(date?: Date)`
9116
+ * - `isMarketDay(date: Date)`
9117
+ * - `getMarketOpenClose(options?: { date?: Date })`
9118
+ *
9119
+ * @param dateStr - Trading day string in 'YYYY-MM-DD' format (Eastern Time date)
9120
+ * @returns An object containing `{ open: Date; close: Date }`
9121
+ * @example
9122
+ * ```ts
9123
+ * const { open, close } = disco.time.getOpenCloseForTradingDay('2025-10-03');
9124
+ * ```
9125
+ */
9126
+ function getOpenCloseForTradingDay(dateStr) {
9127
+ // Build a UTC midnight anchor for the date, then derive the NY offset for that day.
9128
+ const utcAnchor = new Date(`${dateStr}T00:00:00Z`);
9129
+ const nyOffset = getNYTimeZone(utcAnchor); // '-04:00' | '-05:00'
9130
+ // Create a NY-local noon date to avoid DST midnight transitions.
9131
+ const nyNoon = new Date(`${dateStr}T12:00:00${nyOffset}`);
9132
+ if (!isMarketDay(nyNoon)) {
9133
+ throw new Error(`Not a market day in ET: ${dateStr}`);
9134
+ }
9135
+ const { open, close } = getMarketOpenClose({ date: nyNoon });
9136
+ if (!open || !close) {
9137
+ throw new Error(`No market times available for ${dateStr}`);
9138
+ }
9139
+ return { open, close };
9140
+ }
8896
9141
  /**
8897
9142
  * Converts any date to the market time zone (America/New_York, Eastern Time).
8898
9143
  * Returns a new Date object representing the same moment in time but adjusted to NY/Eastern timezone.
@@ -9086,6 +9331,7 @@ var time = /*#__PURE__*/Object.freeze({
9086
9331
  getMarketTimePeriod: getMarketTimePeriod,
9087
9332
  getNYTimeZone: getNYTimeZone,
9088
9333
  getNextMarketDay: getNextMarketDay,
9334
+ getOpenCloseForTradingDay: getOpenCloseForTradingDay,
9089
9335
  getPreviousMarketDay: getPreviousMarketDay,
9090
9336
  getStartAndEndDates: getStartAndEndDates,
9091
9337
  getTradingDate: getTradingDate,