@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.
- package/dist/index-frontend.cjs +90 -18
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +90 -18
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +107 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +107 -18
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +4 -4
- package/dist/test.js +107 -18
- package/dist/test.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/market-time.d.ts +14 -0
- package/dist/types/market-time.d.ts.map +1 -1
- package/dist/types-frontend/index.d.ts +1 -0
- package/dist/types-frontend/index.d.ts.map +1 -1
- package/dist/types-frontend/market-time.d.ts +14 -0
- package/dist/types-frontend/market-time.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.36",
|
|
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.
|
|
36
|
-
"openai": "^5.
|
|
35
|
+
"dotenv": "^17.2.2",
|
|
36
|
+
"openai": "^5.23.1",
|
|
37
37
|
"p-limit": "^7.1.1",
|
|
38
38
|
"tslib": "^2.8.1",
|
|
39
39
|
"ws": "^8.18.3"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
47
47
|
"@types/ws": "^8.18.1",
|
|
48
48
|
"lightweight-charts": "^5.0.8",
|
|
49
|
-
"rollup": "^4.
|
|
49
|
+
"rollup": "^4.52.2",
|
|
50
50
|
"typescript": "^5.9.2"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/dist/test.js
CHANGED
|
@@ -772,6 +772,22 @@ function getNYTimeZone(date) {
|
|
|
772
772
|
const offset = getNYOffset(date || new Date());
|
|
773
773
|
return offset === -4 ? '-04:00' : '-05:00';
|
|
774
774
|
}
|
|
775
|
+
/**
|
|
776
|
+
* Converts any date to the market time zone (America/New_York, Eastern Time).
|
|
777
|
+
* Returns a new Date object representing the same moment in time but adjusted to NY/Eastern timezone.
|
|
778
|
+
* Automatically handles daylight saving time transitions (EST/EDT).
|
|
779
|
+
*
|
|
780
|
+
* @param date - Date object to convert to market time zone
|
|
781
|
+
* @returns Date object in NY/Eastern time zone
|
|
782
|
+
* @example
|
|
783
|
+
* ```typescript
|
|
784
|
+
* const utcDate = new Date('2024-01-15T15:30:00Z'); // 3:30 PM UTC
|
|
785
|
+
* const nyDate = convertDateToMarketTimeZone(utcDate); // 10:30 AM EST (winter) or 11:30 AM EDT (summer)
|
|
786
|
+
* ```
|
|
787
|
+
*/
|
|
788
|
+
function convertDateToMarketTimeZone(date) {
|
|
789
|
+
return toNYTime(date);
|
|
790
|
+
}
|
|
775
791
|
/**
|
|
776
792
|
* Returns the current market status for a given date.
|
|
777
793
|
* @param options - { date?: Date }
|
|
@@ -2393,7 +2409,7 @@ const safeJSON = (text) => {
|
|
|
2393
2409
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2394
2410
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
2395
2411
|
|
|
2396
|
-
const VERSION = '5.
|
|
2412
|
+
const VERSION = '5.23.1'; // x-release-please-version
|
|
2397
2413
|
|
|
2398
2414
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2399
2415
|
const isRunningInBrowser = () => {
|
|
@@ -5796,15 +5812,18 @@ class TranscriptionSessions extends APIResource {
|
|
|
5796
5812
|
}
|
|
5797
5813
|
|
|
5798
5814
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5799
|
-
|
|
5815
|
+
/**
|
|
5816
|
+
* @deprecated Realtime has now launched and is generally available. The old beta API is now deprecated.
|
|
5817
|
+
*/
|
|
5818
|
+
let Realtime$1 = class Realtime extends APIResource {
|
|
5800
5819
|
constructor() {
|
|
5801
5820
|
super(...arguments);
|
|
5802
5821
|
this.sessions = new Sessions(this._client);
|
|
5803
5822
|
this.transcriptionSessions = new TranscriptionSessions(this._client);
|
|
5804
5823
|
}
|
|
5805
|
-
}
|
|
5806
|
-
Realtime.Sessions = Sessions;
|
|
5807
|
-
Realtime.TranscriptionSessions = TranscriptionSessions;
|
|
5824
|
+
};
|
|
5825
|
+
Realtime$1.Sessions = Sessions;
|
|
5826
|
+
Realtime$1.TranscriptionSessions = TranscriptionSessions;
|
|
5808
5827
|
|
|
5809
5828
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5810
5829
|
/**
|
|
@@ -6742,12 +6761,12 @@ Threads.Messages = Messages;
|
|
|
6742
6761
|
class Beta extends APIResource {
|
|
6743
6762
|
constructor() {
|
|
6744
6763
|
super(...arguments);
|
|
6745
|
-
this.realtime = new Realtime(this._client);
|
|
6764
|
+
this.realtime = new Realtime$1(this._client);
|
|
6746
6765
|
this.assistants = new Assistants(this._client);
|
|
6747
6766
|
this.threads = new Threads(this._client);
|
|
6748
6767
|
}
|
|
6749
6768
|
}
|
|
6750
|
-
Beta.Realtime = Realtime;
|
|
6769
|
+
Beta.Realtime = Realtime$1;
|
|
6751
6770
|
Beta.Assistants = Assistants;
|
|
6752
6771
|
Beta.Threads = Threads;
|
|
6753
6772
|
|
|
@@ -6897,23 +6916,23 @@ class Conversations extends APIResource {
|
|
|
6897
6916
|
/**
|
|
6898
6917
|
* Create a conversation.
|
|
6899
6918
|
*/
|
|
6900
|
-
create(body, options) {
|
|
6919
|
+
create(body = {}, options) {
|
|
6901
6920
|
return this._client.post('/conversations', { body, ...options });
|
|
6902
6921
|
}
|
|
6903
6922
|
/**
|
|
6904
|
-
* Get a conversation
|
|
6923
|
+
* Get a conversation
|
|
6905
6924
|
*/
|
|
6906
6925
|
retrieve(conversationID, options) {
|
|
6907
6926
|
return this._client.get(path `/conversations/${conversationID}`, options);
|
|
6908
6927
|
}
|
|
6909
6928
|
/**
|
|
6910
|
-
* Update a conversation
|
|
6929
|
+
* Update a conversation
|
|
6911
6930
|
*/
|
|
6912
6931
|
update(conversationID, body, options) {
|
|
6913
6932
|
return this._client.post(path `/conversations/${conversationID}`, { body, ...options });
|
|
6914
6933
|
}
|
|
6915
6934
|
/**
|
|
6916
|
-
* Delete a conversation
|
|
6935
|
+
* Delete a conversation. Items in the conversation will not be deleted.
|
|
6917
6936
|
*/
|
|
6918
6937
|
delete(conversationID, options) {
|
|
6919
6938
|
return this._client.delete(path `/conversations/${conversationID}`, options);
|
|
@@ -7508,6 +7527,25 @@ class Moderations extends APIResource {
|
|
|
7508
7527
|
}
|
|
7509
7528
|
}
|
|
7510
7529
|
|
|
7530
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
7531
|
+
class ClientSecrets extends APIResource {
|
|
7532
|
+
/**
|
|
7533
|
+
* Create a Realtime client secret with an associated session configuration.
|
|
7534
|
+
*/
|
|
7535
|
+
create(body, options) {
|
|
7536
|
+
return this._client.post('/realtime/client_secrets', { body, ...options });
|
|
7537
|
+
}
|
|
7538
|
+
}
|
|
7539
|
+
|
|
7540
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
7541
|
+
class Realtime extends APIResource {
|
|
7542
|
+
constructor() {
|
|
7543
|
+
super(...arguments);
|
|
7544
|
+
this.clientSecrets = new ClientSecrets(this._client);
|
|
7545
|
+
}
|
|
7546
|
+
}
|
|
7547
|
+
Realtime.ClientSecrets = ClientSecrets;
|
|
7548
|
+
|
|
7511
7549
|
function maybeParseResponse(response, params) {
|
|
7512
7550
|
if (!params || !hasAutoParseableInput(params)) {
|
|
7513
7551
|
return {
|
|
@@ -7758,8 +7796,16 @@ class ResponseStream extends EventStream {
|
|
|
7758
7796
|
if (!output) {
|
|
7759
7797
|
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
7760
7798
|
}
|
|
7761
|
-
|
|
7762
|
-
|
|
7799
|
+
const type = output.type;
|
|
7800
|
+
const part = event.part;
|
|
7801
|
+
if (type === 'message' && part.type !== 'reasoning_text') {
|
|
7802
|
+
output.content.push(part);
|
|
7803
|
+
}
|
|
7804
|
+
else if (type === 'reasoning' && part.type === 'reasoning_text') {
|
|
7805
|
+
if (!output.content) {
|
|
7806
|
+
output.content = [];
|
|
7807
|
+
}
|
|
7808
|
+
output.content.push(part);
|
|
7763
7809
|
}
|
|
7764
7810
|
break;
|
|
7765
7811
|
}
|
|
@@ -7790,6 +7836,23 @@ class ResponseStream extends EventStream {
|
|
|
7790
7836
|
}
|
|
7791
7837
|
break;
|
|
7792
7838
|
}
|
|
7839
|
+
case 'response.reasoning_text.delta': {
|
|
7840
|
+
const output = snapshot.output[event.output_index];
|
|
7841
|
+
if (!output) {
|
|
7842
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
7843
|
+
}
|
|
7844
|
+
if (output.type === 'reasoning') {
|
|
7845
|
+
const content = output.content?.[event.content_index];
|
|
7846
|
+
if (!content) {
|
|
7847
|
+
throw new OpenAIError(`missing content at index ${event.content_index}`);
|
|
7848
|
+
}
|
|
7849
|
+
if (content.type !== 'reasoning_text') {
|
|
7850
|
+
throw new OpenAIError(`expected content to be 'reasoning_text', got ${content.type}`);
|
|
7851
|
+
}
|
|
7852
|
+
content.text += event.delta;
|
|
7853
|
+
}
|
|
7854
|
+
break;
|
|
7855
|
+
}
|
|
7793
7856
|
case 'response.completed': {
|
|
7794
7857
|
__classPrivateFieldSet(this, _ResponseStream_currentResponseSnapshot, event.response);
|
|
7795
7858
|
break;
|
|
@@ -8514,11 +8577,12 @@ class OpenAI {
|
|
|
8514
8577
|
this.batches = new Batches(this);
|
|
8515
8578
|
this.uploads = new Uploads(this);
|
|
8516
8579
|
this.responses = new Responses(this);
|
|
8580
|
+
this.realtime = new Realtime(this);
|
|
8517
8581
|
this.conversations = new Conversations(this);
|
|
8518
8582
|
this.evals = new Evals(this);
|
|
8519
8583
|
this.containers = new Containers(this);
|
|
8520
8584
|
if (apiKey === undefined) {
|
|
8521
|
-
throw new OpenAIError(
|
|
8585
|
+
throw new OpenAIError('Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.');
|
|
8522
8586
|
}
|
|
8523
8587
|
const options = {
|
|
8524
8588
|
apiKey,
|
|
@@ -8546,7 +8610,7 @@ class OpenAI {
|
|
|
8546
8610
|
this.fetch = options.fetch ?? getDefaultFetch();
|
|
8547
8611
|
__classPrivateFieldSet(this, _OpenAI_encoder, FallbackEncoder);
|
|
8548
8612
|
this._options = options;
|
|
8549
|
-
this.apiKey = apiKey;
|
|
8613
|
+
this.apiKey = typeof apiKey === 'string' ? apiKey : 'Missing Key';
|
|
8550
8614
|
this.organization = organization;
|
|
8551
8615
|
this.project = project;
|
|
8552
8616
|
this.webhookSecret = webhookSecret;
|
|
@@ -8593,6 +8657,27 @@ class OpenAI {
|
|
|
8593
8657
|
makeStatusError(status, error, message, headers) {
|
|
8594
8658
|
return APIError.generate(status, error, message, headers);
|
|
8595
8659
|
}
|
|
8660
|
+
async _callApiKey() {
|
|
8661
|
+
const apiKey = this._options.apiKey;
|
|
8662
|
+
if (typeof apiKey !== 'function')
|
|
8663
|
+
return false;
|
|
8664
|
+
let token;
|
|
8665
|
+
try {
|
|
8666
|
+
token = await apiKey();
|
|
8667
|
+
}
|
|
8668
|
+
catch (err) {
|
|
8669
|
+
if (err instanceof OpenAIError)
|
|
8670
|
+
throw err;
|
|
8671
|
+
throw new OpenAIError(`Failed to get token from 'apiKey' function: ${err.message}`,
|
|
8672
|
+
// @ts-ignore
|
|
8673
|
+
{ cause: err });
|
|
8674
|
+
}
|
|
8675
|
+
if (typeof token !== 'string' || !token) {
|
|
8676
|
+
throw new OpenAIError(`Expected 'apiKey' function argument to return a string but it returned ${token}`);
|
|
8677
|
+
}
|
|
8678
|
+
this.apiKey = token;
|
|
8679
|
+
return true;
|
|
8680
|
+
}
|
|
8596
8681
|
buildURL(path, query, defaultBaseURL) {
|
|
8597
8682
|
const baseURL = (!__classPrivateFieldGet(this, _OpenAI_instances, "m", _OpenAI_baseURLOverridden).call(this) && defaultBaseURL) || this.baseURL;
|
|
8598
8683
|
const url = isAbsoluteURL(path) ?
|
|
@@ -8610,7 +8695,9 @@ class OpenAI {
|
|
|
8610
8695
|
/**
|
|
8611
8696
|
* Used as a callback for mutating the given `FinalRequestOptions` object.
|
|
8612
8697
|
*/
|
|
8613
|
-
async prepareOptions(options) {
|
|
8698
|
+
async prepareOptions(options) {
|
|
8699
|
+
await this._callApiKey();
|
|
8700
|
+
}
|
|
8614
8701
|
/**
|
|
8615
8702
|
* Used as a callback for mutating the given `RequestInit` object.
|
|
8616
8703
|
*
|
|
@@ -8669,7 +8756,7 @@ class OpenAI {
|
|
|
8669
8756
|
const controller = new AbortController();
|
|
8670
8757
|
const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
|
|
8671
8758
|
const headersTime = Date.now();
|
|
8672
|
-
if (response instanceof Error) {
|
|
8759
|
+
if (response instanceof globalThis.Error) {
|
|
8673
8760
|
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
8674
8761
|
if (options.signal?.aborted) {
|
|
8675
8762
|
throw new APIUserAbortError();
|
|
@@ -8960,6 +9047,7 @@ OpenAI.Beta = Beta;
|
|
|
8960
9047
|
OpenAI.Batches = Batches;
|
|
8961
9048
|
OpenAI.Uploads = Uploads;
|
|
8962
9049
|
OpenAI.Responses = Responses;
|
|
9050
|
+
OpenAI.Realtime = Realtime;
|
|
8963
9051
|
OpenAI.Conversations = Conversations;
|
|
8964
9052
|
OpenAI.Evals = Evals;
|
|
8965
9053
|
OpenAI.Containers = Containers;
|
|
@@ -15771,7 +15859,7 @@ var config = {};
|
|
|
15771
15859
|
|
|
15772
15860
|
var main = {exports: {}};
|
|
15773
15861
|
|
|
15774
|
-
var version = "17.2.
|
|
15862
|
+
var version = "17.2.2";
|
|
15775
15863
|
var require$$4 = {
|
|
15776
15864
|
version: version};
|
|
15777
15865
|
|
|
@@ -18912,6 +19000,7 @@ const disco = {
|
|
|
18912
19000
|
calculateFibonacciLevels: calculateFibonacciLevels,
|
|
18913
19001
|
},
|
|
18914
19002
|
time: {
|
|
19003
|
+
convertDateToMarketTimeZone: convertDateToMarketTimeZone,
|
|
18915
19004
|
getStartAndEndDates: getStartAndEndDates,
|
|
18916
19005
|
getMarketOpenClose: getMarketOpenClose,
|
|
18917
19006
|
getLastFullTradingDate: getLastFullTradingDate,
|