@discomedia/utils 1.0.39 → 1.0.41

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