@discomedia/utils 1.0.58 → 1.0.60

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.
Files changed (45) hide show
  1. package/README.md +0 -2
  2. package/dist/index-frontend.cjs +132 -9
  3. package/dist/index-frontend.cjs.map +1 -1
  4. package/dist/index-frontend.mjs +132 -9
  5. package/dist/index-frontend.mjs.map +1 -1
  6. package/dist/index.cjs +136 -1394
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.mjs +136 -1394
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/package.json +3 -3
  11. package/dist/test.js +136 -241
  12. package/dist/test.js.map +1 -1
  13. package/dist/types/index.d.ts +0 -82
  14. package/dist/types/index.d.ts.map +1 -1
  15. package/dist/types/misc-utils.d.ts +0 -6
  16. package/dist/types/misc-utils.d.ts.map +1 -1
  17. package/dist/types/types/index.d.ts +0 -2
  18. package/dist/types/types/index.d.ts.map +1 -1
  19. package/dist/types-frontend/index.d.ts +0 -82
  20. package/dist/types-frontend/index.d.ts.map +1 -1
  21. package/dist/types-frontend/misc-utils.d.ts +0 -6
  22. package/dist/types-frontend/misc-utils.d.ts.map +1 -1
  23. package/dist/types-frontend/types/index.d.ts +0 -2
  24. package/dist/types-frontend/types/index.d.ts.map +1 -1
  25. package/package.json +3 -3
  26. package/dist/types/polygon-indices.d.ts +0 -85
  27. package/dist/types/polygon-indices.d.ts.map +0 -1
  28. package/dist/types/polygon.d.ts +0 -126
  29. package/dist/types/polygon.d.ts.map +0 -1
  30. package/dist/types/technical-analysis.d.ts +0 -90
  31. package/dist/types/technical-analysis.d.ts.map +0 -1
  32. package/dist/types/types/polygon-indices-types.d.ts +0 -190
  33. package/dist/types/types/polygon-indices-types.d.ts.map +0 -1
  34. package/dist/types/types/polygon-types.d.ts +0 -204
  35. package/dist/types/types/polygon-types.d.ts.map +0 -1
  36. package/dist/types-frontend/polygon-indices.d.ts +0 -85
  37. package/dist/types-frontend/polygon-indices.d.ts.map +0 -1
  38. package/dist/types-frontend/polygon.d.ts +0 -126
  39. package/dist/types-frontend/polygon.d.ts.map +0 -1
  40. package/dist/types-frontend/technical-analysis.d.ts +0 -90
  41. package/dist/types-frontend/technical-analysis.d.ts.map +0 -1
  42. package/dist/types-frontend/types/polygon-indices-types.d.ts +0 -190
  43. package/dist/types-frontend/types/polygon-indices-types.d.ts.map +0 -1
  44. package/dist/types-frontend/types/polygon-types.d.ts +0 -204
  45. package/dist/types-frontend/types/polygon-types.d.ts.map +0 -1
package/dist/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.58",
6
+ "version": "1.0.60",
7
7
  "author": "Disco Media",
8
8
  "description": "Utility functions used in Disco Media apps",
9
9
  "always-build-npm": true,
@@ -32,8 +32,8 @@
32
32
  "test": "npm run build && node dist/test.js"
33
33
  },
34
34
  "dependencies": {
35
- "dotenv": "^17.2.3",
36
- "openai": "^6.17.0",
35
+ "dotenv": "^17.3.1",
36
+ "openai": "^6.22.0",
37
37
  "p-limit": "^7.3.0",
38
38
  "tslib": "^2.8.1",
39
39
  "ws": "^8.19.0"
package/dist/test.js CHANGED
@@ -381,231 +381,6 @@ function getTradingDate(time) {
381
381
  return `${nyDate.getUTCFullYear()}-${String(nyDate.getUTCMonth() + 1).padStart(2, '0')}-${String(nyDate.getUTCDate()).padStart(2, '0')}`;
382
382
  }
383
383
 
384
- /*
385
- How it works:
386
- `this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
387
- */
388
-
389
- class Node {
390
- value;
391
- next;
392
-
393
- constructor(value) {
394
- this.value = value;
395
- }
396
- }
397
-
398
- class Queue {
399
- #head;
400
- #tail;
401
- #size;
402
-
403
- constructor() {
404
- this.clear();
405
- }
406
-
407
- enqueue(value) {
408
- const node = new Node(value);
409
-
410
- if (this.#head) {
411
- this.#tail.next = node;
412
- this.#tail = node;
413
- } else {
414
- this.#head = node;
415
- this.#tail = node;
416
- }
417
-
418
- this.#size++;
419
- }
420
-
421
- dequeue() {
422
- const current = this.#head;
423
- if (!current) {
424
- return;
425
- }
426
-
427
- this.#head = this.#head.next;
428
- this.#size--;
429
- return current.value;
430
- }
431
-
432
- peek() {
433
- if (!this.#head) {
434
- return;
435
- }
436
-
437
- return this.#head.value;
438
-
439
- // TODO: Node.js 18.
440
- // return this.#head?.value;
441
- }
442
-
443
- clear() {
444
- this.#head = undefined;
445
- this.#tail = undefined;
446
- this.#size = 0;
447
- }
448
-
449
- get size() {
450
- return this.#size;
451
- }
452
-
453
- * [Symbol.iterator]() {
454
- let current = this.#head;
455
-
456
- while (current) {
457
- yield current.value;
458
- current = current.next;
459
- }
460
- }
461
-
462
- * drain() {
463
- while (this.#head) {
464
- yield this.dequeue();
465
- }
466
- }
467
- }
468
-
469
- function pLimit(concurrency) {
470
- let rejectOnClear = false;
471
-
472
- if (typeof concurrency === 'object') {
473
- ({concurrency, rejectOnClear = false} = concurrency);
474
- }
475
-
476
- validateConcurrency(concurrency);
477
-
478
- if (typeof rejectOnClear !== 'boolean') {
479
- throw new TypeError('Expected `rejectOnClear` to be a boolean');
480
- }
481
-
482
- const queue = new Queue();
483
- let activeCount = 0;
484
-
485
- const resumeNext = () => {
486
- // Process the next queued function if we're under the concurrency limit
487
- if (activeCount < concurrency && queue.size > 0) {
488
- activeCount++;
489
- queue.dequeue().run();
490
- }
491
- };
492
-
493
- const next = () => {
494
- activeCount--;
495
- resumeNext();
496
- };
497
-
498
- const run = async (function_, resolve, arguments_) => {
499
- // Execute the function and capture the result promise
500
- const result = (async () => function_(...arguments_))();
501
-
502
- // Resolve immediately with the promise (don't wait for completion)
503
- resolve(result);
504
-
505
- // Wait for the function to complete (success or failure)
506
- // We catch errors here to prevent unhandled rejections,
507
- // but the original promise rejection is preserved for the caller
508
- try {
509
- await result;
510
- } catch {}
511
-
512
- // Decrement active count and process next queued function
513
- next();
514
- };
515
-
516
- const enqueue = (function_, resolve, reject, arguments_) => {
517
- const queueItem = {reject};
518
-
519
- // Queue the internal resolve function instead of the run function
520
- // to preserve the asynchronous execution context.
521
- new Promise(internalResolve => { // eslint-disable-line promise/param-names
522
- queueItem.run = internalResolve;
523
- queue.enqueue(queueItem);
524
- }).then(run.bind(undefined, function_, resolve, arguments_)); // eslint-disable-line promise/prefer-await-to-then
525
-
526
- // Start processing immediately if we haven't reached the concurrency limit
527
- if (activeCount < concurrency) {
528
- resumeNext();
529
- }
530
- };
531
-
532
- const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
533
- enqueue(function_, resolve, reject, arguments_);
534
- });
535
-
536
- Object.defineProperties(generator, {
537
- activeCount: {
538
- get: () => activeCount,
539
- },
540
- pendingCount: {
541
- get: () => queue.size,
542
- },
543
- clearQueue: {
544
- value() {
545
- if (!rejectOnClear) {
546
- queue.clear();
547
- return;
548
- }
549
-
550
- const abortError = AbortSignal.abort().reason;
551
-
552
- while (queue.size > 0) {
553
- queue.dequeue().reject(abortError);
554
- }
555
- },
556
- },
557
- concurrency: {
558
- get: () => concurrency,
559
-
560
- set(newConcurrency) {
561
- validateConcurrency(newConcurrency);
562
- concurrency = newConcurrency;
563
-
564
- queueMicrotask(() => {
565
- // eslint-disable-next-line no-unmodified-loop-condition
566
- while (activeCount < concurrency && queue.size > 0) {
567
- resumeNext();
568
- }
569
- });
570
- },
571
- },
572
- map: {
573
- async value(iterable, function_) {
574
- const promises = Array.from(iterable, (value, index) => this(function_, value, index));
575
- return Promise.all(promises);
576
- },
577
- },
578
- });
579
-
580
- return generator;
581
- }
582
-
583
- function validateConcurrency(concurrency) {
584
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
585
- throw new TypeError('Expected `concurrency` to be a number from 1 and up');
586
- }
587
- }
588
-
589
- /**********************************************************************************
590
- * Polygon.io calls
591
- **********************************************************************************/
592
- // Constants from environment variables
593
- process.env.POLYGON_API_KEY;
594
- // Define concurrency limits per API
595
- const POLYGON_CONCURRENCY_LIMIT = 100;
596
- pLimit(POLYGON_CONCURRENCY_LIMIT);
597
-
598
- /**
599
- * Polygon Indices API Implementation
600
- *
601
- * This module provides functions to interact with the Polygon.io Indices API.
602
- */
603
- // Constants from environment variables
604
- const { ALPACA_INDICES_API_KEY } = process.env;
605
- // Define concurrency limits for API
606
- const POLYGON_INDICES_CONCURRENCY_LIMIT = 5;
607
- pLimit(POLYGON_INDICES_CONCURRENCY_LIMIT);
608
-
609
384
  function __classPrivateFieldSet(receiver, state, value, kind, f) {
610
385
  if (typeof state === "function" ? receiver !== state || true : !state.has(receiver))
611
386
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
@@ -837,7 +612,7 @@ const safeJSON = (text) => {
837
612
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
838
613
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
839
614
 
840
- const VERSION = '6.17.0'; // x-release-please-version
615
+ const VERSION = '6.22.0'; // x-release-please-version
841
616
 
842
617
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
843
618
  const isRunningInBrowser = () => {
@@ -1970,6 +1745,11 @@ async function defaultParseResponse(client, props) {
1970
1745
  const mediaType = contentType?.split(';')[0]?.trim();
1971
1746
  const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
1972
1747
  if (isJSON) {
1748
+ const contentLength = response.headers.get('content-length');
1749
+ if (contentLength === '0') {
1750
+ // if there is no content we can't do anything
1751
+ return undefined;
1752
+ }
1973
1753
  const json = await response.json();
1974
1754
  return addRequestID(json, response);
1975
1755
  }
@@ -5326,7 +5106,7 @@ class Completions extends APIResource {
5326
5106
  }
5327
5107
 
5328
5108
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5329
- class Content extends APIResource {
5109
+ let Content$2 = class Content extends APIResource {
5330
5110
  /**
5331
5111
  * Retrieve Container File Content
5332
5112
  */
@@ -5338,13 +5118,13 @@ class Content extends APIResource {
5338
5118
  __binaryResponse: true,
5339
5119
  });
5340
5120
  }
5341
- }
5121
+ };
5342
5122
 
5343
5123
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5344
5124
  let Files$2 = class Files extends APIResource {
5345
5125
  constructor() {
5346
5126
  super(...arguments);
5347
- this.content = new Content(this._client);
5127
+ this.content = new Content$2(this._client);
5348
5128
  }
5349
5129
  /**
5350
5130
  * Create a Container File
@@ -5353,7 +5133,7 @@ let Files$2 = class Files extends APIResource {
5353
5133
  * a JSON request with a file ID.
5354
5134
  */
5355
5135
  create(containerID, body, options) {
5356
- return this._client.post(path `/containers/${containerID}/files`, multipartFormRequestOptions({ body, ...options }, this._client));
5136
+ return this._client.post(path `/containers/${containerID}/files`, maybeMultipartFormRequestOptions({ body, ...options }, this._client));
5357
5137
  }
5358
5138
  /**
5359
5139
  * Retrieve Container File
@@ -5382,7 +5162,7 @@ let Files$2 = class Files extends APIResource {
5382
5162
  });
5383
5163
  }
5384
5164
  };
5385
- Files$2.Content = Content;
5165
+ Files$2.Content = Content$2;
5386
5166
 
5387
5167
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5388
5168
  class Containers extends APIResource {
@@ -6670,6 +6450,114 @@ class Responses extends APIResource {
6670
6450
  Responses.InputItems = InputItems;
6671
6451
  Responses.InputTokens = InputTokens;
6672
6452
 
6453
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
6454
+ let Content$1 = class Content extends APIResource {
6455
+ /**
6456
+ * Get Skill Content
6457
+ */
6458
+ retrieve(skillID, options) {
6459
+ return this._client.get(path `/skills/${skillID}/content`, {
6460
+ ...options,
6461
+ headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),
6462
+ __binaryResponse: true,
6463
+ });
6464
+ }
6465
+ };
6466
+
6467
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
6468
+ class Content extends APIResource {
6469
+ /**
6470
+ * Get Skill Version Content
6471
+ */
6472
+ retrieve(version, params, options) {
6473
+ const { skill_id } = params;
6474
+ return this._client.get(path `/skills/${skill_id}/versions/${version}/content`, {
6475
+ ...options,
6476
+ headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),
6477
+ __binaryResponse: true,
6478
+ });
6479
+ }
6480
+ }
6481
+
6482
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
6483
+ class Versions extends APIResource {
6484
+ constructor() {
6485
+ super(...arguments);
6486
+ this.content = new Content(this._client);
6487
+ }
6488
+ /**
6489
+ * Create Skill Version
6490
+ */
6491
+ create(skillID, body = {}, options) {
6492
+ return this._client.post(path `/skills/${skillID}/versions`, maybeMultipartFormRequestOptions({ body, ...options }, this._client));
6493
+ }
6494
+ /**
6495
+ * Get Skill Version
6496
+ */
6497
+ retrieve(version, params, options) {
6498
+ const { skill_id } = params;
6499
+ return this._client.get(path `/skills/${skill_id}/versions/${version}`, options);
6500
+ }
6501
+ /**
6502
+ * List Skill Versions
6503
+ */
6504
+ list(skillID, query = {}, options) {
6505
+ return this._client.getAPIList(path `/skills/${skillID}/versions`, (CursorPage), {
6506
+ query,
6507
+ ...options,
6508
+ });
6509
+ }
6510
+ /**
6511
+ * Delete Skill Version
6512
+ */
6513
+ delete(version, params, options) {
6514
+ const { skill_id } = params;
6515
+ return this._client.delete(path `/skills/${skill_id}/versions/${version}`, options);
6516
+ }
6517
+ }
6518
+ Versions.Content = Content;
6519
+
6520
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
6521
+ class Skills extends APIResource {
6522
+ constructor() {
6523
+ super(...arguments);
6524
+ this.content = new Content$1(this._client);
6525
+ this.versions = new Versions(this._client);
6526
+ }
6527
+ /**
6528
+ * Create Skill
6529
+ */
6530
+ create(body = {}, options) {
6531
+ return this._client.post('/skills', maybeMultipartFormRequestOptions({ body, ...options }, this._client));
6532
+ }
6533
+ /**
6534
+ * Get Skill
6535
+ */
6536
+ retrieve(skillID, options) {
6537
+ return this._client.get(path `/skills/${skillID}`, options);
6538
+ }
6539
+ /**
6540
+ * Update Skill Default Version
6541
+ */
6542
+ update(skillID, body, options) {
6543
+ return this._client.post(path `/skills/${skillID}`, { body, ...options });
6544
+ }
6545
+ /**
6546
+ * List Skills
6547
+ */
6548
+ list(query = {}, options) {
6549
+ return this._client.getAPIList('/skills', (CursorPage), { query, ...options });
6550
+ }
6551
+ /**
6552
+ * Delete Skill
6553
+ */
6554
+ delete(skillID, options) {
6555
+ return this._client.delete(path `/skills/${skillID}`, options);
6556
+ }
6557
+ }
6558
+ Skills.Content = Content$1;
6559
+ Skills.Versions = Versions;
6560
+
6673
6561
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
6674
6562
  class Parts extends APIResource {
6675
6563
  /**
@@ -7279,6 +7167,7 @@ class OpenAI {
7279
7167
  this.conversations = new Conversations(this);
7280
7168
  this.evals = new Evals(this);
7281
7169
  this.containers = new Containers(this);
7170
+ this.skills = new Skills(this);
7282
7171
  this.videos = new Videos(this);
7283
7172
  if (apiKey === undefined) {
7284
7173
  throw new OpenAIError('Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.');
@@ -7536,7 +7425,9 @@ class OpenAI {
7536
7425
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
7537
7426
  }
7538
7427
  getAPIList(path, Page, opts) {
7539
- return this.requestAPIList(Page, { method: 'get', path, ...opts });
7428
+ return this.requestAPIList(Page, opts && 'then' in opts ?
7429
+ opts.then((opts) => ({ method: 'get', path, ...opts }))
7430
+ : { method: 'get', path, ...opts });
7540
7431
  }
7541
7432
  requestAPIList(Page, options) {
7542
7433
  const request = this.makeRequest(options, null, undefined);
@@ -7544,9 +7435,10 @@ class OpenAI {
7544
7435
  }
7545
7436
  async fetchWithTimeout(url, init, ms, controller) {
7546
7437
  const { signal, method, ...options } = init || {};
7438
+ const abort = this._makeAbort(controller);
7547
7439
  if (signal)
7548
- signal.addEventListener('abort', () => controller.abort());
7549
- const timeout = setTimeout(() => controller.abort(), ms);
7440
+ signal.addEventListener('abort', abort, { once: true });
7441
+ const timeout = setTimeout(abort, ms);
7550
7442
  const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
7551
7443
  (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
7552
7444
  const fetchOptions = {
@@ -7677,6 +7569,11 @@ class OpenAI {
7677
7569
  this.validateHeaders(headers);
7678
7570
  return headers.values;
7679
7571
  }
7572
+ _makeAbort(controller) {
7573
+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
7574
+ // would capture all request options, and cause a memory leak.
7575
+ return () => controller.abort();
7576
+ }
7680
7577
  buildBody({ options: { body, headers: rawHeaders } }) {
7681
7578
  if (!body) {
7682
7579
  return { bodyHeaders: undefined, body: undefined };
@@ -7750,6 +7647,7 @@ OpenAI.Realtime = Realtime;
7750
7647
  OpenAI.Conversations = Conversations;
7751
7648
  OpenAI.Evals = Evals;
7752
7649
  OpenAI.Containers = Containers;
7650
+ OpenAI.Skills = Skills;
7753
7651
  OpenAI.Videos = Videos;
7754
7652
 
7755
7653
  function getDefaultExportFromCjs (x) {
@@ -12736,7 +12634,7 @@ var config = {};
12736
12634
 
12737
12635
  var main = {exports: {}};
12738
12636
 
12739
- var version = "17.2.3";
12637
+ var version = "17.3.1";
12740
12638
  var require$$4 = {
12741
12639
  version: version};
12742
12640
 
@@ -12758,12 +12656,9 @@ function requireMain () {
12758
12656
  '🔐 encrypt with Dotenvx: https://dotenvx.com',
12759
12657
  '🔐 prevent committing .env to code: https://dotenvx.com/precommit',
12760
12658
  '🔐 prevent building .env in docker: https://dotenvx.com/prebuild',
12761
- '📡 add observability to secrets: https://dotenvx.com/ops',
12762
- '👥 sync secrets across teammates & machines: https://dotenvx.com/ops',
12763
- '🗂️ backup and recover secrets: https://dotenvx.com/ops',
12764
- '✅ audit secrets and track compliance: https://dotenvx.com/ops',
12765
- '🔄 add secrets lifecycle management: https://dotenvx.com/ops',
12766
- '🔑 add access controls to secrets: https://dotenvx.com/ops',
12659
+ '🤖 agentic secret storage: https://dotenvx.com/as2',
12660
+ '⚡️ secrets for agents: https://dotenvx.com/as2',
12661
+ '🛡️ auth for agents: https://vestauth.com',
12767
12662
  '🛠️ run anywhere with `dotenvx run -- yourcommand`',
12768
12663
  '⚙️ specify custom .env file path with { path: \'/custom/path/.env\' }',
12769
12664
  '⚙️ enable debug logging with { debug: true }',