@discomedia/utils 1.0.64 → 1.0.66

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/test.js CHANGED
@@ -2,7 +2,7 @@ import require$$0$3, { EventEmitter } from 'events';
2
2
  import require$$1 from 'https';
3
3
  import require$$2 from 'http';
4
4
  import require$$3$1 from 'net';
5
- import require$$4$1 from 'tls';
5
+ import require$$4 from 'tls';
6
6
  import require$$3 from 'crypto';
7
7
  import require$$0$2 from 'stream';
8
8
  import require$$7 from 'url';
@@ -1146,6 +1146,7 @@ function isOpenRouterModel(model) {
1146
1146
  const openRouterModels = [
1147
1147
  'openai/gpt-5',
1148
1148
  'openai/gpt-5-mini',
1149
+ 'openai/gpt-5.4-mini',
1149
1150
  'openai/gpt-5-nano',
1150
1151
  'openai/gpt-5.1',
1151
1152
  'openai/gpt-5.4',
@@ -1562,6 +1563,37 @@ class InvalidWebhookSignatureError extends Error {
1562
1563
  super(message);
1563
1564
  }
1564
1565
  }
1566
+ /**
1567
+ * Error thrown by the API server during OAuth token exchange.
1568
+ * Can have status codes 400, 401, or 403.
1569
+ * Other status codes from OAuth endpoints are raised as normal APIError types.
1570
+ */
1571
+ class OAuthError extends APIError {
1572
+ constructor(status, error, headers) {
1573
+ let finalMessage = 'OAuth2 authentication error';
1574
+ let error_code = undefined;
1575
+ if (error && typeof error === 'object') {
1576
+ const errorData = error;
1577
+ error_code = errorData['error'];
1578
+ const description = errorData['error_description'];
1579
+ if (description && typeof description === 'string') {
1580
+ finalMessage = description;
1581
+ }
1582
+ else if (error_code) {
1583
+ finalMessage = error_code;
1584
+ }
1585
+ }
1586
+ super(status, error, finalMessage, headers);
1587
+ this.error_code = error_code;
1588
+ }
1589
+ }
1590
+ class SubjectTokenProviderError extends OpenAIError {
1591
+ constructor(message, provider, cause) {
1592
+ super(message);
1593
+ this.provider = provider;
1594
+ this.cause = cause;
1595
+ }
1596
+ }
1565
1597
 
1566
1598
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
1567
1599
  // https://url.spec.whatwg.org/#url-scheme-string
@@ -1614,7 +1646,7 @@ const safeJSON = (text) => {
1614
1646
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
1615
1647
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
1616
1648
 
1617
- const VERSION = '6.31.0'; // x-release-please-version
1649
+ const VERSION = '6.34.0'; // x-release-please-version
1618
1650
 
1619
1651
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
1620
1652
  const isRunningInBrowser = () => {
@@ -2995,6 +3027,91 @@ class ConversationCursorPage extends AbstractPage {
2995
3027
  }
2996
3028
  }
2997
3029
 
3030
+ const SUBJECT_TOKEN_TYPES = {
3031
+ jwt: 'urn:ietf:params:oauth:token-type:jwt',
3032
+ id: 'urn:ietf:params:oauth:token-type:id_token',
3033
+ };
3034
+ const TOKEN_EXCHANGE_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:token-exchange';
3035
+ class WorkloadIdentityAuth {
3036
+ constructor(config, fetch) {
3037
+ this.cachedToken = null;
3038
+ this.refreshPromise = null;
3039
+ this.tokenExchangeUrl = 'https://auth.openai.com/oauth/token';
3040
+ this.config = config;
3041
+ this.fetch = fetch ?? getDefaultFetch();
3042
+ }
3043
+ async getToken() {
3044
+ if (!this.cachedToken || this.isTokenExpired(this.cachedToken)) {
3045
+ if (this.refreshPromise) {
3046
+ return await this.refreshPromise;
3047
+ }
3048
+ this.refreshPromise = this.refreshToken();
3049
+ try {
3050
+ const token = await this.refreshPromise;
3051
+ return token;
3052
+ }
3053
+ finally {
3054
+ this.refreshPromise = null;
3055
+ }
3056
+ }
3057
+ if (this.needsRefresh(this.cachedToken) && !this.refreshPromise) {
3058
+ this.refreshPromise = this.refreshToken().finally(() => {
3059
+ this.refreshPromise = null;
3060
+ });
3061
+ }
3062
+ return this.cachedToken.token;
3063
+ }
3064
+ async refreshToken() {
3065
+ const subjectToken = await this.config.provider.getToken();
3066
+ const response = await this.fetch(this.tokenExchangeUrl, {
3067
+ method: 'POST',
3068
+ headers: {
3069
+ 'Content-Type': 'application/json',
3070
+ },
3071
+ body: JSON.stringify({
3072
+ grant_type: TOKEN_EXCHANGE_GRANT_TYPE,
3073
+ client_id: this.config.clientId,
3074
+ subject_token: subjectToken,
3075
+ subject_token_type: SUBJECT_TOKEN_TYPES[this.config.provider.tokenType],
3076
+ identity_provider_id: this.config.identityProviderId,
3077
+ service_account_id: this.config.serviceAccountId,
3078
+ }),
3079
+ });
3080
+ if (!response.ok) {
3081
+ const errorText = await response.text();
3082
+ let body = undefined;
3083
+ try {
3084
+ body = JSON.parse(errorText);
3085
+ }
3086
+ catch { }
3087
+ if (response.status === 400 || response.status === 401 || response.status === 403) {
3088
+ throw new OAuthError(response.status, body, response.headers);
3089
+ }
3090
+ throw APIError.generate(response.status, body, `Token exchange failed with status ${response.status}`, response.headers);
3091
+ }
3092
+ const tokenResponse = (await response.json());
3093
+ const expiresIn = tokenResponse.expires_in || 3600;
3094
+ const expiresAt = Date.now() + expiresIn * 1000;
3095
+ this.cachedToken = {
3096
+ token: tokenResponse.access_token,
3097
+ expiresAt,
3098
+ };
3099
+ return tokenResponse.access_token;
3100
+ }
3101
+ isTokenExpired(cachedToken) {
3102
+ return Date.now() >= cachedToken.expiresAt;
3103
+ }
3104
+ needsRefresh(cachedToken) {
3105
+ const bufferSeconds = this.config.refreshBufferSeconds ?? 1200;
3106
+ const bufferMs = bufferSeconds * 1000;
3107
+ return Date.now() >= cachedToken.expiresAt - bufferMs;
3108
+ }
3109
+ invalidateToken() {
3110
+ this.cachedToken = null;
3111
+ this.refreshPromise = null;
3112
+ }
3113
+ }
3114
+
2998
3115
  const checkFileSupport = () => {
2999
3116
  if (typeof File === 'undefined') {
3000
3117
  const { process } = globalThis;
@@ -8300,6 +8417,7 @@ _Webhooks_instances = new WeakSet(), _Webhooks_validateSecret = function _Webhoo
8300
8417
 
8301
8418
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
8302
8419
  var _OpenAI_instances, _a$1, _OpenAI_encoder, _OpenAI_baseURLOverridden;
8420
+ const WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER = 'workload-identity-auth';
8303
8421
  /**
8304
8422
  * API Client for interfacing with the OpenAI API.
8305
8423
  */
@@ -8320,7 +8438,7 @@ class OpenAI {
8320
8438
  * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
8321
8439
  * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
8322
8440
  */
8323
- constructor({ baseURL = readEnv('OPENAI_BASE_URL'), apiKey = readEnv('OPENAI_API_KEY'), organization = readEnv('OPENAI_ORG_ID') ?? null, project = readEnv('OPENAI_PROJECT_ID') ?? null, webhookSecret = readEnv('OPENAI_WEBHOOK_SECRET') ?? null, ...opts } = {}) {
8441
+ constructor({ baseURL = readEnv('OPENAI_BASE_URL'), apiKey = readEnv('OPENAI_API_KEY'), organization = readEnv('OPENAI_ORG_ID') ?? null, project = readEnv('OPENAI_PROJECT_ID') ?? null, webhookSecret = readEnv('OPENAI_WEBHOOK_SECRET') ?? null, workloadIdentity, ...opts } = {}) {
8324
8442
  _OpenAI_instances.add(this);
8325
8443
  _OpenAI_encoder.set(this, void 0);
8326
8444
  /**
@@ -8375,14 +8493,21 @@ class OpenAI {
8375
8493
  this.containers = new Containers(this);
8376
8494
  this.skills = new Skills(this);
8377
8495
  this.videos = new Videos(this);
8378
- if (apiKey === undefined) {
8379
- throw new OpenAIError('Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.');
8496
+ if (workloadIdentity) {
8497
+ if (apiKey && apiKey !== WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER) {
8498
+ throw new OpenAIError('The `apiKey` and `workloadIdentity` arguments are mutually exclusive; only one can be passed at a time.');
8499
+ }
8500
+ apiKey = WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER;
8501
+ }
8502
+ else if (apiKey === undefined) {
8503
+ throw new OpenAIError('Missing credentials. Please pass an `apiKey`, `workloadIdentity`, or set the `OPENAI_API_KEY` environment variable.');
8380
8504
  }
8381
8505
  const options = {
8382
8506
  apiKey,
8383
8507
  organization,
8384
8508
  project,
8385
8509
  webhookSecret,
8510
+ workloadIdentity,
8386
8511
  ...opts,
8387
8512
  baseURL: baseURL || `https://api.openai.com/v1`,
8388
8513
  };
@@ -8404,6 +8529,9 @@ class OpenAI {
8404
8529
  this.fetch = options.fetch ?? getDefaultFetch();
8405
8530
  __classPrivateFieldSet(this, _OpenAI_encoder, FallbackEncoder);
8406
8531
  this._options = options;
8532
+ if (workloadIdentity) {
8533
+ this._workloadIdentityAuth = new WorkloadIdentityAuth(workloadIdentity, this.fetch);
8534
+ }
8407
8535
  this.apiKey = typeof apiKey === 'string' ? apiKey : 'Missing Key';
8408
8536
  this.organization = organization;
8409
8537
  this.project = project;
@@ -8423,6 +8551,7 @@ class OpenAI {
8423
8551
  fetch: this.fetch,
8424
8552
  fetchOptions: this.fetchOptions,
8425
8553
  apiKey: this.apiKey,
8554
+ workloadIdentity: this._options.workloadIdentity,
8426
8555
  organization: this.organization,
8427
8556
  project: this.project,
8428
8557
  webhookSecret: this.webhookSecret,
@@ -8549,7 +8678,7 @@ class OpenAI {
8549
8678
  throw new APIUserAbortError();
8550
8679
  }
8551
8680
  const controller = new AbortController();
8552
- const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
8681
+ const response = await this.fetchWithAuth(url, req, timeout, controller).catch(castToError);
8553
8682
  const headersTime = Date.now();
8554
8683
  if (response instanceof globalThis.Error) {
8555
8684
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
@@ -8579,6 +8708,9 @@ class OpenAI {
8579
8708
  durationMs: headersTime - startTime,
8580
8709
  message: response.message,
8581
8710
  }));
8711
+ if (response instanceof OAuthError || response instanceof SubjectTokenProviderError) {
8712
+ throw response;
8713
+ }
8582
8714
  if (isTimeout) {
8583
8715
  throw new APIConnectionTimeoutError();
8584
8716
  }
@@ -8590,6 +8722,20 @@ class OpenAI {
8590
8722
  .join('');
8591
8723
  const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${response.ok ? 'succeeded' : 'failed'} with status ${response.status} in ${headersTime - startTime}ms`;
8592
8724
  if (!response.ok) {
8725
+ if (response.status === 401 &&
8726
+ this._workloadIdentityAuth &&
8727
+ !options.__metadata?.['hasStreamingBody'] &&
8728
+ !options.__metadata?.['workloadIdentityTokenRefreshed']) {
8729
+ await CancelReadableStream(response.body);
8730
+ this._workloadIdentityAuth.invalidateToken();
8731
+ return this.makeRequest({
8732
+ ...options,
8733
+ __metadata: {
8734
+ ...options.__metadata,
8735
+ workloadIdentityTokenRefreshed: true,
8736
+ },
8737
+ }, retriesRemaining, retryOfRequestLogID ?? requestLogID);
8738
+ }
8593
8739
  const shouldRetry = await this.shouldRetry(response);
8594
8740
  if (retriesRemaining && shouldRetry) {
8595
8741
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
@@ -8640,6 +8786,18 @@ class OpenAI {
8640
8786
  const request = this.makeRequest(options, null, undefined);
8641
8787
  return new PagePromise(this, request, Page);
8642
8788
  }
8789
+ async fetchWithAuth(url, init, timeout, controller) {
8790
+ if (this._workloadIdentityAuth) {
8791
+ const headers = init.headers;
8792
+ const authHeader = headers.get('Authorization');
8793
+ if (!authHeader || authHeader === `Bearer ${WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER}`) {
8794
+ const token = await this._workloadIdentityAuth.getToken();
8795
+ headers.set('Authorization', `Bearer ${token}`);
8796
+ }
8797
+ }
8798
+ const response = await this.fetchWithTimeout(url, init, timeout, controller);
8799
+ return response;
8800
+ }
8643
8801
  async fetchWithTimeout(url, init, ms, controller) {
8644
8802
  const { signal, method, ...options } = init || {};
8645
8803
  const abort = this._makeAbort(controller);
@@ -8736,7 +8894,13 @@ class OpenAI {
8736
8894
  if ('timeout' in options)
8737
8895
  validatePositiveInteger('timeout', options.timeout);
8738
8896
  options.timeout = options.timeout ?? this.timeout;
8739
- const { bodyHeaders, body } = this.buildBody({ options });
8897
+ const { bodyHeaders, body, isStreamingBody } = this.buildBody({ options });
8898
+ if (isStreamingBody) {
8899
+ inputOptions.__metadata = {
8900
+ ...inputOptions.__metadata,
8901
+ hasStreamingBody: true,
8902
+ };
8903
+ }
8740
8904
  const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
8741
8905
  const req = {
8742
8906
  method,
@@ -8783,9 +8947,18 @@ class OpenAI {
8783
8947
  }
8784
8948
  buildBody({ options: { body, headers: rawHeaders } }) {
8785
8949
  if (!body) {
8786
- return { bodyHeaders: undefined, body: undefined };
8950
+ return { bodyHeaders: undefined, body: undefined, isStreamingBody: false };
8787
8951
  }
8788
8952
  const headers = buildHeaders([rawHeaders]);
8953
+ const isReadableStream = typeof globalThis.ReadableStream !== 'undefined' &&
8954
+ body instanceof globalThis.ReadableStream;
8955
+ const isRetryableBody = !isReadableStream &&
8956
+ (typeof body === 'string' ||
8957
+ body instanceof ArrayBuffer ||
8958
+ ArrayBuffer.isView(body) ||
8959
+ (typeof globalThis.Blob !== 'undefined' && body instanceof globalThis.Blob) ||
8960
+ body instanceof URLSearchParams ||
8961
+ body instanceof FormData);
8789
8962
  if (
8790
8963
  // Pass raw type verbatim
8791
8964
  ArrayBuffer.isView(body) ||
@@ -8801,23 +8974,28 @@ class OpenAI {
8801
8974
  // `URLSearchParams` -> `application/x-www-form-urlencoded`
8802
8975
  body instanceof URLSearchParams ||
8803
8976
  // Send chunked stream (each chunk has own `length`)
8804
- (globalThis.ReadableStream && body instanceof globalThis.ReadableStream)) {
8805
- return { bodyHeaders: undefined, body: body };
8977
+ isReadableStream) {
8978
+ return { bodyHeaders: undefined, body: body, isStreamingBody: !isRetryableBody };
8806
8979
  }
8807
8980
  else if (typeof body === 'object' &&
8808
8981
  (Symbol.asyncIterator in body ||
8809
8982
  (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))) {
8810
- return { bodyHeaders: undefined, body: ReadableStreamFrom(body) };
8983
+ return {
8984
+ bodyHeaders: undefined,
8985
+ body: ReadableStreamFrom(body),
8986
+ isStreamingBody: true,
8987
+ };
8811
8988
  }
8812
8989
  else if (typeof body === 'object' &&
8813
8990
  headers.values.get('content-type') === 'application/x-www-form-urlencoded') {
8814
8991
  return {
8815
8992
  bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
8816
8993
  body: this.stringifyQuery(body),
8994
+ isStreamingBody: false,
8817
8995
  };
8818
8996
  }
8819
8997
  else {
8820
- return __classPrivateFieldGet(this, _OpenAI_encoder, "f").call(this, { body, headers });
8998
+ return { ...__classPrivateFieldGet(this, _OpenAI_encoder, "f").call(this, { body, headers }), isStreamingBody: false };
8821
8999
  }
8822
9000
  }
8823
9001
  }
@@ -9824,7 +10002,7 @@ class Doc {
9824
10002
  }
9825
10003
  }
9826
10004
 
9827
- const version$1 = {
10005
+ const version = {
9828
10006
  major: 4,
9829
10007
  minor: 3,
9830
10008
  patch: 6,
@@ -9835,7 +10013,7 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
9835
10013
  inst ?? (inst = {});
9836
10014
  inst._zod.def = def; // set _def property
9837
10015
  inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
9838
- inst._zod.version = version$1;
10016
+ inst._zod.version = version;
9839
10017
  const checks = [...(inst._zod.def.checks ?? [])];
9840
10018
  // if inst is itself a checks.$ZodCheck, run it as a check
9841
10019
  if (inst._zod.traits.has("$ZodCheck")) {
@@ -14960,6 +15138,11 @@ const openAiModelCosts = {
14960
15138
  cacheHitCost: 0.025 / 1_000_000,
14961
15139
  outputCost: 2 / 1_000_000,
14962
15140
  },
15141
+ 'gpt-5.4-mini': {
15142
+ inputCost: 0.25 / 1_000_000,
15143
+ cacheHitCost: 0.025 / 1_000_000,
15144
+ outputCost: 2 / 1_000_000,
15145
+ },
14963
15146
  'gpt-5-nano': {
14964
15147
  inputCost: 0.05 / 1_000_000,
14965
15148
  cacheHitCost: 0.005 / 1_000_000,
@@ -15470,6 +15653,7 @@ const isSupportedModel = (model) => {
15470
15653
  'gpt-4.1-nano',
15471
15654
  'gpt-5',
15472
15655
  'gpt-5-mini',
15656
+ 'gpt-5.4-mini',
15473
15657
  'gpt-5-nano',
15474
15658
  'gpt-5.1',
15475
15659
  'gpt-5.4',
@@ -15498,6 +15682,7 @@ function supportsTemperature(model) {
15498
15682
  'o3',
15499
15683
  'gpt-5',
15500
15684
  'gpt-5-mini',
15685
+ 'gpt-5.4-mini',
15501
15686
  'gpt-5-nano',
15502
15687
  'gpt-5.1',
15503
15688
  'gpt-5.4',
@@ -15527,6 +15712,7 @@ function isGPT5Model(model) {
15527
15712
  const gpt5Models = [
15528
15713
  'gpt-5',
15529
15714
  'gpt-5-mini',
15715
+ 'gpt-5.4-mini',
15530
15716
  'gpt-5-nano',
15531
15717
  'gpt-5.1',
15532
15718
  'gpt-5.4',
@@ -15836,6 +16022,7 @@ const MULTIMODAL_VISION_MODELS = new Set([
15836
16022
  'gpt-4o',
15837
16023
  'gpt-5',
15838
16024
  'gpt-5-mini',
16025
+ 'gpt-5.4-mini',
15839
16026
  'gpt-5-nano',
15840
16027
  'gpt-5.1',
15841
16028
  'gpt-5.4',
@@ -16757,6 +16944,9 @@ function requirePermessageDeflate () {
16757
16944
  * acknowledge disabling of client context takeover
16758
16945
  * @param {Number} [options.concurrencyLimit=10] The number of concurrent
16759
16946
  * calls to zlib
16947
+ * @param {Boolean} [options.isServer=false] Create the instance in either
16948
+ * server or client mode
16949
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
16760
16950
  * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
16761
16951
  * use of a custom server window size
16762
16952
  * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
@@ -16767,16 +16957,13 @@ function requirePermessageDeflate () {
16767
16957
  * deflate
16768
16958
  * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
16769
16959
  * inflate
16770
- * @param {Boolean} [isServer=false] Create the instance in either server or
16771
- * client mode
16772
- * @param {Number} [maxPayload=0] The maximum allowed message length
16773
16960
  */
16774
- constructor(options, isServer, maxPayload) {
16775
- this._maxPayload = maxPayload | 0;
16961
+ constructor(options) {
16776
16962
  this._options = options || {};
16777
16963
  this._threshold =
16778
16964
  this._options.threshold !== undefined ? this._options.threshold : 1024;
16779
- this._isServer = !!isServer;
16965
+ this._maxPayload = this._options.maxPayload | 0;
16966
+ this._isServer = !!this._options.isServer;
16780
16967
  this._deflate = null;
16781
16968
  this._inflate = null;
16782
16969
 
@@ -19258,7 +19445,7 @@ function requireWebsocket () {
19258
19445
  const https = require$$1;
19259
19446
  const http = require$$2;
19260
19447
  const net = require$$3$1;
19261
- const tls = require$$4$1;
19448
+ const tls = require$$4;
19262
19449
  const { randomBytes, createHash } = require$$3;
19263
19450
  const { Duplex, Readable } = require$$0$2;
19264
19451
  const { URL } = require$$7;
@@ -19945,7 +20132,7 @@ function requireWebsocket () {
19945
20132
  } else {
19946
20133
  try {
19947
20134
  parsedUrl = new URL(address);
19948
- } catch (e) {
20135
+ } catch {
19949
20136
  throw new SyntaxError(`Invalid URL: ${address}`);
19950
20137
  }
19951
20138
  }
@@ -20007,11 +20194,11 @@ function requireWebsocket () {
20007
20194
  opts.timeout = opts.handshakeTimeout;
20008
20195
 
20009
20196
  if (opts.perMessageDeflate) {
20010
- perMessageDeflate = new PerMessageDeflate(
20011
- opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
20012
- false,
20013
- opts.maxPayload
20014
- );
20197
+ perMessageDeflate = new PerMessageDeflate({
20198
+ ...opts.perMessageDeflate,
20199
+ isServer: false,
20200
+ maxPayload: opts.maxPayload
20201
+ });
20015
20202
  opts.headers['Sec-WebSocket-Extensions'] = format({
20016
20203
  [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
20017
20204
  });
@@ -20818,13 +21005,14 @@ function requireStream () {
20818
21005
 
20819
21006
  requireStream();
20820
21007
 
21008
+ requireExtension();
21009
+
21010
+ requirePermessageDeflate();
21011
+
20821
21012
  requireReceiver();
20822
21013
 
20823
21014
  requireSender();
20824
21015
 
20825
- var websocketExports = requireWebsocket();
20826
- var WebSocket = /*@__PURE__*/getDefaultExportFromCjs(websocketExports);
20827
-
20828
21016
  var subprotocol;
20829
21017
  var hasRequiredSubprotocol;
20830
21018
 
@@ -20895,6 +21083,11 @@ function requireSubprotocol () {
20895
21083
  return subprotocol;
20896
21084
  }
20897
21085
 
21086
+ requireSubprotocol();
21087
+
21088
+ var websocketExports = requireWebsocket();
21089
+ var WebSocket = /*@__PURE__*/getDefaultExportFromCjs(websocketExports);
21090
+
20898
21091
  /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex$", "caughtErrors": "none" }] */
20899
21092
 
20900
21093
  var websocketServer;
@@ -21195,11 +21388,11 @@ function requireWebsocketServer () {
21195
21388
  this.options.perMessageDeflate &&
21196
21389
  secWebSocketExtensions !== undefined
21197
21390
  ) {
21198
- const perMessageDeflate = new PerMessageDeflate(
21199
- this.options.perMessageDeflate,
21200
- true,
21201
- this.options.maxPayload
21202
- );
21391
+ const perMessageDeflate = new PerMessageDeflate({
21392
+ ...this.options.perMessageDeflate,
21393
+ isServer: true,
21394
+ maxPayload: this.options.maxPayload
21395
+ });
21203
21396
 
21204
21397
  try {
21205
21398
  const offers = extension.parse(secWebSocketExtensions);
@@ -21463,10 +21656,6 @@ var config = {};
21463
21656
 
21464
21657
  var main = {exports: {}};
21465
21658
 
21466
- var version = "17.3.1";
21467
- var require$$4 = {
21468
- version: version};
21469
-
21470
21659
  var hasRequiredMain;
21471
21660
 
21472
21661
  function requireMain () {
@@ -21476,25 +21665,17 @@ function requireMain () {
21476
21665
  const path = require$$1$1;
21477
21666
  const os = require$$2$1;
21478
21667
  const crypto = require$$3;
21479
- const packageJson = require$$4;
21480
-
21481
- const version = packageJson.version;
21482
21668
 
21483
21669
  // Array of tips to display randomly
21484
21670
  const TIPS = [
21485
- '🔐 encrypt with Dotenvx: https://dotenvx.com',
21486
- '🔐 prevent committing .env to code: https://dotenvx.com/precommit',
21487
- '🔐 prevent building .env in docker: https://dotenvx.com/prebuild',
21488
- '🤖 agentic secret storage: https://dotenvx.com/as2',
21489
- '⚡️ secrets for agents: https://dotenvx.com/as2',
21490
- '🛡️ auth for agents: https://vestauth.com',
21491
- '🛠️ run anywhere with `dotenvx run -- yourcommand`',
21492
- '⚙️ specify custom .env file path with { path: \'/custom/path/.env\' }',
21493
- '⚙️ enable debug logging with { debug: true }',
21494
- '⚙️ override existing env vars with { override: true }',
21495
- '⚙️ suppress all logs with { quiet: true }',
21496
- '⚙️ write to custom object with { processEnv: myObject }',
21497
- '⚙️ load multiple .env files with { path: [\'.env.local\', \'.env\'] }'
21671
+ ' encrypted .env [www.dotenvx.com]',
21672
+ ' secrets for agents [www.dotenvx.com]',
21673
+ ' auth for agents [www.vestauth.com]',
21674
+ ' custom filepath { path: \'/custom/path/.env\' }',
21675
+ ' enable debugging { debug: true }',
21676
+ ' override existing { override: true }',
21677
+ ' suppress logs { quiet: true }',
21678
+ ' multiple files { path: [\'.env.local\', \'.env\'] }'
21498
21679
  ];
21499
21680
 
21500
21681
  // Get a random tip from the tips array
@@ -21602,15 +21783,15 @@ function requireMain () {
21602
21783
  }
21603
21784
 
21604
21785
  function _warn (message) {
21605
- console.error(`[dotenv@${version}][WARN] ${message}`);
21786
+ console.error(`⚠ ${message}`);
21606
21787
  }
21607
21788
 
21608
21789
  function _debug (message) {
21609
- console.log(`[dotenv@${version}][DEBUG] ${message}`);
21790
+ console.log(`┆ ${message}`);
21610
21791
  }
21611
21792
 
21612
21793
  function _log (message) {
21613
- console.log(`[dotenv@${version}] ${message}`);
21794
+ console.log(`◇ ${message}`);
21614
21795
  }
21615
21796
 
21616
21797
  function _dotenvKey (options) {
@@ -21704,7 +21885,7 @@ function requireMain () {
21704
21885
  const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || (options && options.quiet));
21705
21886
 
21706
21887
  if (debug || !quiet) {
21707
- _log('Loading env from encrypted .env.vault');
21888
+ _log('loading env from encrypted .env.vault');
21708
21889
  }
21709
21890
 
21710
21891
  const parsed = DotenvModule._parseVault(options);
@@ -21733,7 +21914,7 @@ function requireMain () {
21733
21914
  encoding = options.encoding;
21734
21915
  } else {
21735
21916
  if (debug) {
21736
- _debug('No encoding is specified. UTF-8 is used by default');
21917
+ _debug('no encoding is specified (UTF-8 is used by default)');
21737
21918
  }
21738
21919
  }
21739
21920
 
@@ -21761,7 +21942,7 @@ function requireMain () {
21761
21942
  DotenvModule.populate(parsedAll, parsed, options);
21762
21943
  } catch (e) {
21763
21944
  if (debug) {
21764
- _debug(`Failed to load ${path} ${e.message}`);
21945
+ _debug(`failed to load ${path} ${e.message}`);
21765
21946
  }
21766
21947
  lastError = e;
21767
21948
  }
@@ -21782,13 +21963,13 @@ function requireMain () {
21782
21963
  shortPaths.push(relative);
21783
21964
  } catch (e) {
21784
21965
  if (debug) {
21785
- _debug(`Failed to load ${filePath} ${e.message}`);
21966
+ _debug(`failed to load ${filePath} ${e.message}`);
21786
21967
  }
21787
21968
  lastError = e;
21788
21969
  }
21789
21970
  }
21790
21971
 
21791
- _log(`injecting env (${keysCount}) from ${shortPaths.join(',')} ${dim(`-- tip: ${_getRandomTip()}`)}`);
21972
+ _log(`injected env (${keysCount}) from ${shortPaths.join(',')} ${dim(`// tip: ${_getRandomTip()}`)}`);
21792
21973
  }
21793
21974
 
21794
21975
  if (lastError) {
@@ -21809,7 +21990,7 @@ function requireMain () {
21809
21990
 
21810
21991
  // dotenvKey exists but .env.vault file does not exist
21811
21992
  if (!vaultPath) {
21812
- _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
21993
+ _warn(`you set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}`);
21813
21994
 
21814
21995
  return DotenvModule.configDotenv(options)
21815
21996
  }
@@ -22339,7 +22520,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
22339
22520
  pageCount++;
22340
22521
  const requestParams = {
22341
22522
  ...params,
22342
- adjustment: DEFAULT_ADJUSTMENT,
22523
+ adjustment: params.adjustment ?? DEFAULT_ADJUSTMENT,
22343
22524
  feed: DEFAULT_FEED,
22344
22525
  ...(pageToken && { page_token: pageToken }),
22345
22526
  };
@@ -24994,6 +25175,48 @@ const disco = {
24994
25175
 
24995
25176
  // Test file for context functionality
24996
25177
  process.env['DEBUG'] === 'true' || false;
25178
+ async function testLLM() {
25179
+ //const models: LLMModel[] = ['gpt-5', 'gpt-5-mini', 'gpt-5.4-mini', 'gpt-5-nano'];
25180
+ const models = ['gpt-5.4-mini'];
25181
+ for (const model of models) {
25182
+ console.log(`\nTesting model: ${model}`);
25183
+ // 1. Basic call
25184
+ try {
25185
+ const basic = await disco.llm.call('What is the capital of France?', { model });
25186
+ if (!basic || !basic.response) {
25187
+ throw new Error('No response from LLM');
25188
+ }
25189
+ console.log(`Response: ${basic.response}`);
25190
+ }
25191
+ catch (e) {
25192
+ console.error(` Basic call error:`, e);
25193
+ }
25194
+ // 2. JSON call
25195
+ try {
25196
+ const jsonPrompt = 'Return a JSON object with keys country and capital for France.';
25197
+ const json = await disco.llm.call(jsonPrompt, { model, responseFormat: 'json' });
25198
+ if (!json || !json.response) {
25199
+ throw new Error('No response from LLM');
25200
+ }
25201
+ console.log(`Response: ${JSON.stringify(json.response)}`);
25202
+ }
25203
+ catch (e) {
25204
+ console.error(` JSON call error:`, e);
25205
+ }
25206
+ // 3. Web search
25207
+ try {
25208
+ const searchPrompt = 'What is the latest news about artificial intelligence? Respond with 3 sentences max.';
25209
+ const tool = await disco.llm.call(searchPrompt, { model, useWebSearch: true });
25210
+ if (!tool || !tool.response) {
25211
+ throw new Error('No response from LLM');
25212
+ }
25213
+ console.log(`Response: ${tool.response}`);
25214
+ }
25215
+ catch (e) {
25216
+ console.error(` Web search error:`, e);
25217
+ }
25218
+ }
25219
+ }
24997
25220
  async function testLLMStructuredOutputWithZod() {
24998
25221
  if (!process.env.OPENAI_API_KEY) {
24999
25222
  console.log('Skipping OpenAI structured output Zod test: OPENAI_API_KEY not set');
@@ -25008,7 +25231,7 @@ async function testLLMStructuredOutputWithZod() {
25008
25231
  try {
25009
25232
  const prompt = 'Return details for France using the exact schema.';
25010
25233
  const result = await disco.llm.call(prompt, {
25011
- model: 'gpt-5-mini',
25234
+ model: 'gpt-5.4-mini',
25012
25235
  schema: structuredSchema,
25013
25236
  schemaName: 'capital_response',
25014
25237
  schemaDescription: 'Country and capital metadata',
@@ -25039,7 +25262,6 @@ async function testLLMStructuredOutputWithZod() {
25039
25262
  // testGetPortfolioDailyHistory();
25040
25263
  // testWebSocketConnectAndDisconnect();
25041
25264
  // testGetAssetsShortableFilter();
25042
- // testLLM();
25043
25265
  // testImageModelDefaults();
25044
25266
  // testGetTradingDaysBack();
25045
25267
  // testMOOAndMOCOrders();
@@ -25049,5 +25271,6 @@ async function testLLMStructuredOutputWithZod() {
25049
25271
  // testMarketDataSubscription('SPY');
25050
25272
  // testMarketDataSubscription('FAKEPACA');
25051
25273
  // testGetTradingDate();
25274
+ testLLM();
25052
25275
  testLLMStructuredOutputWithZod();
25053
25276
  //# sourceMappingURL=test.js.map