@usabledev/usable-chat 1.156.0 → 1.158.0

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 (2) hide show
  1. package/cli.js +102 -47
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -111749,11 +111749,11 @@ var require_dist_cjs20 = __commonJS({
111749
111749
  var createScope = /* @__PURE__ */ __name((shortDate, region, service) => `${shortDate}/${region}/${service}/${KEY_TYPE_IDENTIFIER}`, "createScope");
111750
111750
  var getSigningKey = /* @__PURE__ */ __name(async (sha256Constructor, credentials, shortDate, region, service) => {
111751
111751
  const credsHash = await hmac2(sha256Constructor, credentials.secretAccessKey, credentials.accessKeyId);
111752
- const cacheKey = `${shortDate}:${region}:${service}:${(0, import_util_hex_encoding.toHex)(credsHash)}:${credentials.sessionToken}`;
111753
- if (cacheKey in signingKeyCache) {
111754
- return signingKeyCache[cacheKey];
111752
+ const cacheKey2 = `${shortDate}:${region}:${service}:${(0, import_util_hex_encoding.toHex)(credsHash)}:${credentials.sessionToken}`;
111753
+ if (cacheKey2 in signingKeyCache) {
111754
+ return signingKeyCache[cacheKey2];
111755
111755
  }
111756
- cacheQueue.push(cacheKey);
111756
+ cacheQueue.push(cacheKey2);
111757
111757
  while (cacheQueue.length > MAX_CACHE_SIZE) {
111758
111758
  delete signingKeyCache[cacheQueue.shift()];
111759
111759
  }
@@ -111761,12 +111761,12 @@ var require_dist_cjs20 = __commonJS({
111761
111761
  for (const signable of [shortDate, region, service, KEY_TYPE_IDENTIFIER]) {
111762
111762
  key = await hmac2(sha256Constructor, key, signable);
111763
111763
  }
111764
- return signingKeyCache[cacheKey] = key;
111764
+ return signingKeyCache[cacheKey2] = key;
111765
111765
  }, "getSigningKey");
111766
111766
  var clearCredentialCache = /* @__PURE__ */ __name(() => {
111767
111767
  cacheQueue.length = 0;
111768
- Object.keys(signingKeyCache).forEach((cacheKey) => {
111769
- delete signingKeyCache[cacheKey];
111768
+ Object.keys(signingKeyCache).forEach((cacheKey2) => {
111769
+ delete signingKeyCache[cacheKey2];
111770
111770
  });
111771
111771
  }, "clearCredentialCache");
111772
111772
  var hmac2 = /* @__PURE__ */ __name((ctor, secret, data2) => {
@@ -114521,8 +114521,8 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
114521
114521
  this.sessionCache.set(authority, existingConnectionPool);
114522
114522
  }
114523
114523
  release(requestContext, session) {
114524
- const cacheKey = this.getUrlString(requestContext);
114525
- this.sessionCache.get(cacheKey)?.offerLast(session);
114524
+ const cacheKey2 = this.getUrlString(requestContext);
114525
+ this.sessionCache.get(cacheKey2)?.offerLast(session);
114526
114526
  }
114527
114527
  destroy() {
114528
114528
  for (const [key, connectionPool] of this.sessionCache) {
@@ -119455,11 +119455,11 @@ var require_dist_cjs34 = __commonJS({
119455
119455
  var createScope = (shortDate, region, service) => `${shortDate}/${region}/${service}/${KEY_TYPE_IDENTIFIER}`;
119456
119456
  var getSigningKey = async (sha256Constructor, credentials, shortDate, region, service) => {
119457
119457
  const credsHash = await hmac2(sha256Constructor, credentials.secretAccessKey, credentials.accessKeyId);
119458
- const cacheKey = `${shortDate}:${region}:${service}:${utilHexEncoding.toHex(credsHash)}:${credentials.sessionToken}`;
119459
- if (cacheKey in signingKeyCache) {
119460
- return signingKeyCache[cacheKey];
119458
+ const cacheKey2 = `${shortDate}:${region}:${service}:${utilHexEncoding.toHex(credsHash)}:${credentials.sessionToken}`;
119459
+ if (cacheKey2 in signingKeyCache) {
119460
+ return signingKeyCache[cacheKey2];
119461
119461
  }
119462
- cacheQueue.push(cacheKey);
119462
+ cacheQueue.push(cacheKey2);
119463
119463
  while (cacheQueue.length > MAX_CACHE_SIZE) {
119464
119464
  delete signingKeyCache[cacheQueue.shift()];
119465
119465
  }
@@ -119467,12 +119467,12 @@ var require_dist_cjs34 = __commonJS({
119467
119467
  for (const signable of [shortDate, region, service, KEY_TYPE_IDENTIFIER]) {
119468
119468
  key = await hmac2(sha256Constructor, key, signable);
119469
119469
  }
119470
- return signingKeyCache[cacheKey] = key;
119470
+ return signingKeyCache[cacheKey2] = key;
119471
119471
  };
119472
119472
  var clearCredentialCache = () => {
119473
119473
  cacheQueue.length = 0;
119474
- Object.keys(signingKeyCache).forEach((cacheKey) => {
119475
- delete signingKeyCache[cacheKey];
119474
+ Object.keys(signingKeyCache).forEach((cacheKey2) => {
119475
+ delete signingKeyCache[cacheKey2];
119476
119476
  });
119477
119477
  };
119478
119478
  var hmac2 = (ctor, secret, data2) => {
@@ -135170,7 +135170,7 @@ var require_dist_cjs66 = __commonJS({
135170
135170
  }
135171
135171
  function fromCognitoIdentityPool({ accountId, cache: cache8 = localStorage2(), client, clientConfig, customRoleArn, identityPoolId, logins, userIdentifier = !logins || Object.keys(logins).length === 0 ? "ANONYMOUS" : void 0, logger: logger6, parentClientConfig }) {
135172
135172
  logger6?.debug("@aws-sdk/credential-provider-cognito-identity - fromCognitoIdentity");
135173
- const cacheKey = userIdentifier ? `aws:cognito-identity-credentials:${identityPoolId}:${userIdentifier}` : void 0;
135173
+ const cacheKey2 = userIdentifier ? `aws:cognito-identity-credentials:${identityPoolId}:${userIdentifier}` : void 0;
135174
135174
  let provider = async (awsIdentityProperties) => {
135175
135175
  const { GetIdCommand, CognitoIdentityClient } = await Promise.resolve().then(function() {
135176
135176
  return require_loadCognitoIdentity_BPNvueUJ();
@@ -135181,7 +135181,7 @@ var require_dist_cjs66 = __commonJS({
135181
135181
  profile: fromConfigs("profile"),
135182
135182
  userAgentAppId: fromConfigs("userAgentAppId")
135183
135183
  }));
135184
- let identityId = cacheKey && await cache8.getItem(cacheKey);
135184
+ let identityId = cacheKey2 && await cache8.getItem(cacheKey2);
135185
135185
  if (!identityId) {
135186
135186
  const { IdentityId = throwOnMissingId(logger6) } = await _client2.send(new GetIdCommand({
135187
135187
  AccountId: accountId,
@@ -135189,8 +135189,8 @@ var require_dist_cjs66 = __commonJS({
135189
135189
  Logins: logins ? await resolveLogins(logins) : void 0
135190
135190
  }));
135191
135191
  identityId = IdentityId;
135192
- if (cacheKey) {
135193
- Promise.resolve(cache8.setItem(cacheKey, identityId)).catch(() => {
135192
+ if (cacheKey2) {
135193
+ Promise.resolve(cache8.setItem(cacheKey2, identityId)).catch(() => {
135194
135194
  });
135195
135195
  }
135196
135196
  }
@@ -135203,8 +135203,8 @@ var require_dist_cjs66 = __commonJS({
135203
135203
  return provider(awsIdentityProperties);
135204
135204
  };
135205
135205
  return (awsIdentityProperties) => provider(awsIdentityProperties).catch(async (err) => {
135206
- if (cacheKey) {
135207
- Promise.resolve(cache8.removeItem(cacheKey)).catch(() => {
135206
+ if (cacheKey2) {
135207
+ Promise.resolve(cache8.removeItem(cacheKey2)).catch(() => {
135208
135208
  });
135209
135209
  }
135210
135210
  throw err;
@@ -139066,8 +139066,8 @@ var require_dist_cjs79 = __commonJS({
139066
139066
  }
139067
139067
  release(requestContext, session) {
139068
139068
  var _a27;
139069
- const cacheKey = this.getUrlString(requestContext);
139070
- (_a27 = this.sessionCache.get(cacheKey)) == null ? void 0 : _a27.offerLast(session);
139069
+ const cacheKey2 = this.getUrlString(requestContext);
139070
+ (_a27 = this.sessionCache.get(cacheKey2)) == null ? void 0 : _a27.offerLast(session);
139071
139071
  }
139072
139072
  destroy() {
139073
139073
  for (const [key, connectionPool] of this.sessionCache) {
@@ -155402,8 +155402,8 @@ var require_core = __commonJS({
155402
155402
  return this;
155403
155403
  }
155404
155404
  case "object": {
155405
- const cacheKey = schemaKeyRef;
155406
- this._cache.delete(cacheKey);
155405
+ const cacheKey2 = schemaKeyRef;
155406
+ this._cache.delete(cacheKey2);
155407
155407
  let id = schemaKeyRef[this.opts.schemaId];
155408
155408
  if (id) {
155409
155409
  id = (0, resolve_1.normalizeId)(id);
@@ -175710,16 +175710,16 @@ var require_jwtaccess = __commonJS({
175710
175710
  * @returns A string that returns the cached key.
175711
175711
  */
175712
175712
  getCachedKey(url2, scopes) {
175713
- let cacheKey = url2;
175713
+ let cacheKey2 = url2;
175714
175714
  if (scopes && Array.isArray(scopes) && scopes.length) {
175715
- cacheKey = url2 ? `${url2}_${scopes.join("_")}` : `${scopes.join("_")}`;
175715
+ cacheKey2 = url2 ? `${url2}_${scopes.join("_")}` : `${scopes.join("_")}`;
175716
175716
  } else if (typeof scopes === "string") {
175717
- cacheKey = url2 ? `${url2}_${scopes}` : scopes;
175717
+ cacheKey2 = url2 ? `${url2}_${scopes}` : scopes;
175718
175718
  }
175719
- if (!cacheKey) {
175719
+ if (!cacheKey2) {
175720
175720
  throw Error("Scopes or url must be provided");
175721
175721
  }
175722
- return cacheKey;
175722
+ return cacheKey2;
175723
175723
  }
175724
175724
  /**
175725
175725
  * Get a non-expired access token, after refreshing if necessary.
@@ -181861,7 +181861,7 @@ var require_websocket = __commonJS({
181861
181861
  var http3 = __require("http");
181862
181862
  var net2 = __require("net");
181863
181863
  var tls2 = __require("tls");
181864
- var { randomBytes: randomBytes5, createHash: createHash5 } = __require("crypto");
181864
+ var { randomBytes: randomBytes5, createHash: createHash6 } = __require("crypto");
181865
181865
  var { Duplex, Readable: Readable3 } = __require("stream");
181866
181866
  var { URL: URL2 } = __require("url");
181867
181867
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -182521,7 +182521,7 @@ var require_websocket = __commonJS({
182521
182521
  abortHandshake(websocket, socket, "Invalid Upgrade header");
182522
182522
  return;
182523
182523
  }
182524
- const digest = createHash5("sha1").update(key + GUID).digest("base64");
182524
+ const digest = createHash6("sha1").update(key + GUID).digest("base64");
182525
182525
  if (res.headers["sec-websocket-accept"] !== digest) {
182526
182526
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
182527
182527
  return;
@@ -182888,7 +182888,7 @@ var require_websocket_server = __commonJS({
182888
182888
  var EventEmitter4 = __require("events");
182889
182889
  var http3 = __require("http");
182890
182890
  var { Duplex } = __require("stream");
182891
- var { createHash: createHash5 } = __require("crypto");
182891
+ var { createHash: createHash6 } = __require("crypto");
182892
182892
  var extension2 = require_extension();
182893
182893
  var PerMessageDeflate2 = require_permessage_deflate();
182894
182894
  var subprotocol2 = require_subprotocol();
@@ -183189,7 +183189,7 @@ var require_websocket_server = __commonJS({
183189
183189
  );
183190
183190
  }
183191
183191
  if (this._state > RUNNING) return abortHandshake(socket, 503);
183192
- const digest = createHash5("sha1").update(key + GUID).digest("base64");
183192
+ const digest = createHash6("sha1").update(key + GUID).digest("base64");
183193
183193
  const headers = [
183194
183194
  "HTTP/1.1 101 Switching Protocols",
183195
183195
  "Upgrade: websocket",
@@ -203720,11 +203720,50 @@ var init_usable_api = __esm({
203720
203720
  // src/lib/system-prompt-source.ts
203721
203721
  var system_prompt_source_exports = {};
203722
203722
  __export(system_prompt_source_exports, {
203723
+ SYSTEM_PROMPT_SOURCE_CACHE_TTL_MS: () => SYSTEM_PROMPT_SOURCE_CACHE_TTL_MS,
203723
203724
  SystemPromptSourceError: () => SystemPromptSourceError,
203725
+ clearSystemPromptSourceCache: () => clearSystemPromptSourceCache,
203724
203726
  requireResolvedSystemPrompt: () => requireResolvedSystemPrompt,
203725
203727
  resolveSystemPromptSource: () => resolveSystemPromptSource,
203726
203728
  validateSystemPromptSourceAvailable: () => validateSystemPromptSourceAvailable
203727
203729
  });
203730
+ import { createHash as createHash5 } from "crypto";
203731
+ function tokenFingerprint(accessToken) {
203732
+ return createHash5("sha256").update(accessToken).digest("hex");
203733
+ }
203734
+ function cacheKey(fragmentId, accessToken, maxChars) {
203735
+ return `${fragmentId}:${maxChars}:${tokenFingerprint(accessToken)}`;
203736
+ }
203737
+ function getCachedPrompt(cacheKeyValue) {
203738
+ const cached2 = promptSourceCache.get(cacheKeyValue);
203739
+ if (!cached2) return null;
203740
+ if (cached2.expiresAt <= Date.now()) {
203741
+ promptSourceCache.delete(cacheKeyValue);
203742
+ return null;
203743
+ }
203744
+ return { ...cached2.result };
203745
+ }
203746
+ function setCachedPrompt(cacheKeyValue, result) {
203747
+ if (promptSourceCache.size >= MAX_CACHE_ENTRIES) {
203748
+ const firstKey = promptSourceCache.keys().next().value;
203749
+ if (firstKey) promptSourceCache.delete(firstKey);
203750
+ }
203751
+ promptSourceCache.set(cacheKeyValue, {
203752
+ expiresAt: Date.now() + SYSTEM_PROMPT_SOURCE_CACHE_TTL_MS,
203753
+ result: { ...result }
203754
+ });
203755
+ }
203756
+ function clearSystemPromptSourceCache(fragmentId) {
203757
+ if (!fragmentId) {
203758
+ promptSourceCache.clear();
203759
+ return;
203760
+ }
203761
+ for (const key of promptSourceCache.keys()) {
203762
+ if (key.startsWith(`${fragmentId}:`)) {
203763
+ promptSourceCache.delete(key);
203764
+ }
203765
+ }
203766
+ }
203728
203767
  function extractFragmentContent(fragment2) {
203729
203768
  if (typeof fragment2.content === "string") return fragment2.content;
203730
203769
  if (typeof fragment2.contentWithoutFrontmatter === "string") {
@@ -203841,7 +203880,18 @@ async function resolveSystemPromptSource(options2) {
203841
203880
  };
203842
203881
  }
203843
203882
  try {
203844
- const fragment2 = await getMemoryFragment(source.fragmentId, options2.getToken);
203883
+ const initialToken = await options2.getToken();
203884
+ const initialCacheKey = cacheKey(source.fragmentId, initialToken, maxChars);
203885
+ const cached2 = getCachedPrompt(initialCacheKey);
203886
+ if (cached2) return cached2;
203887
+ let tokenForFetchedFragment = initialToken;
203888
+ const trackingGetToken = async (forceRefresh) => {
203889
+ if (!forceRefresh) return initialToken;
203890
+ const refreshedToken = await options2.getToken(true);
203891
+ tokenForFetchedFragment = refreshedToken;
203892
+ return refreshedToken;
203893
+ };
203894
+ const fragment2 = await getMemoryFragment(source.fragmentId, trackingGetToken);
203845
203895
  const prompt = extractFragmentContent(fragment2).trim();
203846
203896
  if (!prompt) {
203847
203897
  const fallback = fallbackResult(options2.inlinePrompt, maxChars);
@@ -203855,7 +203905,7 @@ async function resolveSystemPromptSource(options2) {
203855
203905
  };
203856
203906
  }
203857
203907
  const truncated = prompt.length > maxChars;
203858
- return {
203908
+ const result = {
203859
203909
  ok: true,
203860
203910
  prompt: truncated ? prompt.slice(0, maxChars) : prompt,
203861
203911
  sourceType: "fragment",
@@ -203863,6 +203913,8 @@ async function resolveSystemPromptSource(options2) {
203863
203913
  title: fragment2.title,
203864
203914
  truncated
203865
203915
  };
203916
+ setCachedPrompt(cacheKey(source.fragmentId, tokenForFetchedFragment, maxChars), result);
203917
+ return result;
203866
203918
  } catch (error41) {
203867
203919
  const fallback = fallbackResult(options2.inlinePrompt, maxChars);
203868
203920
  if (getPromptUnavailableBehavior(source) === "fallback" && fallback) return fallback;
@@ -203885,7 +203937,7 @@ async function requireResolvedSystemPrompt(options2) {
203885
203937
  ownerId: options2.ownerId
203886
203938
  });
203887
203939
  }
203888
- var SystemPromptSourceError, DEFAULT_MAX_CHARS;
203940
+ var SystemPromptSourceError, DEFAULT_MAX_CHARS, SYSTEM_PROMPT_SOURCE_CACHE_TTL_MS, MAX_CACHE_ENTRIES, promptSourceCache;
203889
203941
  var init_system_prompt_source2 = __esm({
203890
203942
  "src/lib/system-prompt-source.ts"() {
203891
203943
  "use strict";
@@ -203902,6 +203954,9 @@ var init_system_prompt_source2 = __esm({
203902
203954
  }
203903
203955
  };
203904
203956
  DEFAULT_MAX_CHARS = 5e4;
203957
+ SYSTEM_PROMPT_SOURCE_CACHE_TTL_MS = 5 * 60 * 1e3;
203958
+ MAX_CACHE_ENTRIES = 250;
203959
+ promptSourceCache = /* @__PURE__ */ new Map();
203905
203960
  }
203906
203961
  });
203907
203962
 
@@ -215436,8 +215491,8 @@ __export(fragment_types_cache_exports, {
215436
215491
  getFragmentTypesForWorkspace: () => getFragmentTypesForWorkspace
215437
215492
  });
215438
215493
  async function getFragmentTypesForWorkspace(workspaceId, accessToken, usableApiUrl) {
215439
- const cacheKey = workspaceId;
215440
- const cached2 = cache7.get(cacheKey);
215494
+ const cacheKey2 = workspaceId;
215495
+ const cached2 = cache7.get(cacheKey2);
215441
215496
  if (cached2 && Date.now() - cached2.cachedAt < CACHE_TTL_MS) {
215442
215497
  return cached2.fragmentTypes;
215443
215498
  }
@@ -215462,7 +215517,7 @@ async function getFragmentTypesForWorkspace(workspaceId, accessToken, usableApiU
215462
215517
  description: ft7.description,
215463
215518
  cachedAt: Date.now()
215464
215519
  }));
215465
- cache7.set(cacheKey, {
215520
+ cache7.set(cacheKey2, {
215466
215521
  fragmentTypes: formattedTypes,
215467
215522
  cachedAt: Date.now()
215468
215523
  });
@@ -215514,8 +215569,8 @@ function clearSkillCache() {
215514
215569
  function getCacheKey(userId, workspaceIds) {
215515
215570
  return `user:${userId}:workspaces:${[...workspaceIds].sort().join(",")}`;
215516
215571
  }
215517
- function getCachedSkills(cacheKey) {
215518
- const cached2 = perUserWorkspaceSkillCache.get(cacheKey);
215572
+ function getCachedSkills(cacheKey2) {
215573
+ const cached2 = perUserWorkspaceSkillCache.get(cacheKey2);
215519
215574
  if (!cached2) {
215520
215575
  return {};
215521
215576
  }
@@ -215698,8 +215753,8 @@ async function discoverWorkspaceSkillsForUser(params) {
215698
215753
  }
215699
215754
  };
215700
215755
  }
215701
- const cacheKey = getCacheKey(userId, dedupedWorkspaceIds);
215702
- const cached2 = getCachedSkills(cacheKey);
215756
+ const cacheKey2 = getCacheKey(userId, dedupedWorkspaceIds);
215757
+ const cached2 = getCachedSkills(cacheKey2);
215703
215758
  if (cached2.fresh) {
215704
215759
  return {
215705
215760
  skills: cached2.fresh.skills,
@@ -215719,7 +215774,7 @@ async function discoverWorkspaceSkillsForUser(params) {
215719
215774
  workspaceIds: dedupedWorkspaceIds
215720
215775
  });
215721
215776
  const fetchedAt = (/* @__PURE__ */ new Date()).toISOString();
215722
- perUserWorkspaceSkillCache.set(cacheKey, {
215777
+ perUserWorkspaceSkillCache.set(cacheKey2, {
215723
215778
  skills,
215724
215779
  fetchedAt,
215725
215780
  expiresAt: Date.now() + CACHE_TTL_MS2
@@ -309293,7 +309348,7 @@ init_tui_select();
309293
309348
  init_model_registry();
309294
309349
 
309295
309350
  // package.json
309296
- var version2 = "1.156.0";
309351
+ var version2 = "1.158.0";
309297
309352
 
309298
309353
  // src/adapters/cli/model-catalog.ts
309299
309354
  init_codex_auth();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usabledev/usable-chat",
3
- "version": "1.156.0",
3
+ "version": "1.158.0",
4
4
  "description": "usable-chat — terminal harness for usable-chat (headless + TUI)",
5
5
  "type": "module",
6
6
  "bin": {