@versini/sassysaint-common 4.2.0 → 4.3.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.
package/dist/index.d.ts CHANGED
@@ -68,18 +68,20 @@ declare const POLICY_GRANTS: {
68
68
  PLAN_PLUS: string;
69
69
  PLAN_PREMIUM: string;
70
70
  REASONING: string;
71
+ WEBSEARCH: string;
71
72
  };
72
73
  /**
73
- * Header string for Callisto Chat Id. Used to identify the chat in the
74
- * server when there is a client abort.
74
+ * Header string for Callisto Chat Id. Used to identify the chat in the server
75
+ * when there is a client abort.
75
76
  */
76
77
  declare const CALLISTO_CHAT_ID_HEADER = "x-callisto-chat-id";
77
78
  /**
78
- * This function finds the provider associated with a given model name.
79
- * It checks the model name against a list of approximate models for each provider.
79
+ * This function finds the provider associated with a given model name. It
80
+ * checks the model name against a list of approximate models for each provider.
80
81
  *
81
82
  * @param modelName - The model name to check.
82
83
  * @returns The provider associated with the model name or null if not found.
84
+ *
83
85
  */
84
86
  declare const findProvider: (modelName: string) => null | typeof PROVIDER_ANTHROPIC | typeof PROVIDER_OPENAI | typeof PROVIDER_GOOGLE;
85
87
  /**
@@ -93,76 +95,110 @@ declare const SORT_BY_TOKEN_USAGE = "tokenUsage";
93
95
  declare const APPLICATION_NAME = "Callisto";
94
96
 
95
97
  /**
96
- * TypeScript interfaces for Server-Mediated Encryption
98
+ * TypeScript interfaces for Server-Mediated Encryption.
97
99
  */
98
100
  /**
99
- * RSA key pair stored in memory for the current session
101
+ * RSA key pair stored in memory for the current session.
100
102
  */
101
103
  interface ClientCryptoKeyPair {
102
104
  publicKey: CryptoKey;
103
105
  privateKey: CryptoKey;
104
106
  }
105
107
  /**
106
- * Serializable format for public key exchange with server
108
+ * Serializable format for public key exchange with server.
107
109
  */
108
110
  interface SerializablePublicKey {
109
- /** Public key in JSON Web Key format */
111
+ /**
112
+ * Public key in JSON Web Key format.
113
+ */
110
114
  jwk: JsonWebKey;
111
- /** Key type identifier */
115
+ /**
116
+ * Key type identifier.
117
+ */
112
118
  kty: "RSA";
113
- /** Algorithm identifier */
119
+ /**
120
+ * Algorithm identifier.
121
+ */
114
122
  alg: "RSA-OAEP-256";
115
123
  }
116
124
  /**
117
- * Response from server's key exchange mutation
125
+ * Response from server's key exchange mutation.
118
126
  */
119
127
  interface KeyExchangeResponse {
120
- /** Server's public key in JWK format */
128
+ /**
129
+ * Server's public key in JWK format.
130
+ */
121
131
  serverPublicKey: string;
122
- /** Server's key identifier for rotation tracking */
132
+ /**
133
+ * Server's key identifier for rotation tracking.
134
+ */
123
135
  keyId: string;
124
- /** List of supported encryption algorithms */
136
+ /**
137
+ * List of supported encryption algorithms.
138
+ */
125
139
  supportedAlgorithms: string[];
126
140
  }
127
141
  /**
128
- * Client crypto session state stored in memory
142
+ * Client crypto session state stored in memory.
129
143
  */
130
144
  interface CryptoSession {
131
- /** Client's RSA key pair */
145
+ /**
146
+ * Client's RSA key pair.
147
+ */
132
148
  clientKeyPair: ClientCryptoKeyPair;
133
- /** Server's public key for encryption */
149
+ /**
150
+ * Server's public key for encryption.
151
+ */
134
152
  serverPublicKey: CryptoKey;
135
- /** Unique device/session identifier */
153
+ /**
154
+ * Unique device/session identifier.
155
+ */
136
156
  deviceId: string;
137
- /** Server's key identifier */
157
+ /**
158
+ * Server's key identifier.
159
+ */
138
160
  serverKeyId: string;
139
- /** When this session was established */
161
+ /**
162
+ * When this session was established.
163
+ */
140
164
  establishedAt: Date;
141
165
  }
142
166
  /**
143
- * Encrypted message format for transport
167
+ * Encrypted message format for transport.
144
168
  */
145
169
  interface EncryptedMessage {
146
- /** Base64-encoded encrypted data */
170
+ /**
171
+ * Base64-encoded encrypted data.
172
+ */
147
173
  data: string;
148
- /** Algorithm used for encryption */
174
+ /**
175
+ * Algorithm used for encryption.
176
+ */
149
177
  algorithm: "RSA-OAEP";
150
- /** Key ID used for encryption */
178
+ /**
179
+ * Key ID used for encryption.
180
+ */
151
181
  keyId: string;
152
182
  }
153
183
  /**
154
- * Parameters for RSA key generation
184
+ * Parameters for RSA key generation.
155
185
  */
156
186
  interface RSAKeyGenParams {
157
- /** RSA modulus length in bits */
187
+ /**
188
+ * RSA modulus length in bits.
189
+ */
158
190
  modulusLength: 2048 | 4096;
159
- /** Public exponent */
191
+ /**
192
+ * Public exponent.
193
+ */
160
194
  publicExponent: Uint8Array;
161
- /** Hash algorithm for OAEP */
195
+ /**
196
+ * Hash algorithm for OAEP.
197
+ */
162
198
  hash: "SHA-256";
163
199
  }
164
200
  /**
165
- * Error types for crypto operations
201
+ * Error types for crypto operations.
166
202
  */
167
203
  declare class CryptoError extends Error {
168
204
  readonly code: "KEY_GENERATION_FAILED" | "ENCRYPTION_FAILED" | "DECRYPTION_FAILED" | "KEY_IMPORT_FAILED" | "INVALID_KEY_FORMAT";
@@ -170,85 +206,89 @@ declare class CryptoError extends Error {
170
206
  constructor(message: string, code: "KEY_GENERATION_FAILED" | "ENCRYPTION_FAILED" | "DECRYPTION_FAILED" | "KEY_IMPORT_FAILED" | "INVALID_KEY_FORMAT", originalError?: Error | undefined);
171
207
  }
172
208
  /**
173
- * Configuration options for crypto operations
209
+ * Configuration options for crypto operations.
174
210
  */
175
211
  interface CryptoConfig {
176
- /** RSA key size in bits */
212
+ /**
213
+ * RSA key size in bits.
214
+ */
177
215
  keySize: 2048 | 4096;
178
- /** Enable debug logging */
216
+ /**
217
+ * Enable debug logging.
218
+ */
179
219
  debug: boolean;
180
220
  }
181
221
  /**
182
- * Default crypto configuration
222
+ * Default crypto configuration.
183
223
  */
184
224
  declare const DEFAULT_CRYPTO_CONFIG: CryptoConfig;
185
225
 
186
226
  /**
187
- * Generate a new RSA key pair for the current session
227
+ * Generate a new RSA key pair for the current session.
188
228
  */
189
229
  declare function generateClientKeyPair(config?: Partial<CryptoConfig>): Promise<ClientCryptoKeyPair>;
190
230
  /**
191
- * Export public key to serializable format for server exchange
231
+ * Export public key to serializable format for server exchange.
192
232
  */
193
233
  declare function exportPublicKey(publicKey: CryptoKey): Promise<SerializablePublicKey>;
194
234
  /**
195
- * Import server's public key from JWK format
235
+ * Import server's public key from JWK format.
196
236
  */
197
237
  declare function importServerPublicKey(serverPublicKeyJWK: string): Promise<CryptoKey>;
198
238
  /**
199
- * Encrypt message for transmission to server
239
+ * Encrypt message for transmission to server.
200
240
  */
201
241
  declare function encryptForServer(message: string, serverPublicKey: CryptoKey, serverKeyId: string): Promise<EncryptedMessage>;
202
242
  /**
203
- * Decrypt message received from server
243
+ * Decrypt message received from server.
204
244
  */
205
245
  declare function decryptFromServer(encryptedMessage: EncryptedMessage, clientPrivateKey: CryptoKey): Promise<string>;
206
246
  /**
207
- * Create a complete crypto session with key exchange
247
+ * Create a complete crypto session with key exchange.
208
248
  */
209
249
  declare function establishCryptoSession(keyExchangeResponse: KeyExchangeResponse, clientKeyPair: ClientCryptoKeyPair, deviceId: string): Promise<CryptoSession>;
210
250
  /**
211
- * Validate that a crypto session is still valid
251
+ * Validate that a crypto session is still valid.
212
252
  */
213
253
  declare function isCryptoSessionValid(session: CryptoSession): boolean;
214
254
 
215
255
  /**
216
- * Utility functions for crypto operations
256
+ * Utility functions for crypto operations.
217
257
  */
218
258
  /**
219
- * Generate a unique device ID for this session
259
+ * Generate a unique device ID for this session.
220
260
  */
221
261
  declare function generateDeviceId(): string;
222
262
  /**
223
- * Check if the current environment supports Web Crypto API
263
+ * Check if the current environment supports Web Crypto API.
224
264
  */
225
265
  declare function isWebCryptoSupported(): boolean;
226
266
  /**
227
- * Validate that we're in a secure context (required for Web Crypto API)
267
+ * Validate that we're in a secure context (required for Web Crypto API).
228
268
  */
229
269
  declare function isSecureContext(): boolean;
230
270
  /**
231
- * Check if encryption is available in the current environment
271
+ * Check if encryption is available in the current environment.
232
272
  */
233
273
  declare function canUseEncryption(): boolean;
234
274
  /**
235
- * Convert ArrayBuffer to base64 string
275
+ * Convert ArrayBuffer to base64 string.
236
276
  */
237
277
  declare function arrayBufferToBase64(buffer: ArrayBuffer): string;
238
278
  /**
239
- * Convert base64 string to ArrayBuffer
279
+ * Convert base64 string to ArrayBuffer.
240
280
  */
241
281
  declare function base64ToArrayBuffer(base64: string): ArrayBuffer;
242
282
  /**
243
- * Safely stringify JSON with error handling
283
+ * Safely stringify JSON with error handling.
244
284
  */
245
285
  declare function safeStringify(obj: unknown): string;
246
286
  /**
247
- * Safely parse JSON with error handling
287
+ * Safely parse JSON with error handling.
248
288
  */
249
289
  declare function safeParse<T = unknown>(json: string): T | null;
250
290
  /**
251
- * Debug logger for crypto operations (only in development)
291
+ * Debug logger for crypto operations (only in development).
252
292
  *
253
293
  * ⚠️ SECURITY WARNING: Never log sensitive data such as:
254
294
  * - Private or public key objects
@@ -256,7 +296,9 @@ declare function safeParse<T = unknown>(json: string): T | null;
256
296
  * - Raw cryptographic material
257
297
  * - Device IDs or session identifiers
258
298
  *
259
- * Only log non-sensitive metadata like algorithms, key sizes, operation status, etc.
299
+ * Only log non-sensitive metadata like algorithms, key sizes, operation status,
300
+ * etc.
301
+ *
260
302
  */
261
303
  declare function debugLog(message: string, ...args: unknown[]): void;
262
304
 
package/dist/index.js CHANGED
@@ -1,22 +1,22 @@
1
- const w = "system", s = "user", c = "assistant", te = "hidden", re = "data", a = "OpenAI", i = "Anthropic", E = "Google", M = "Summary", g = "Memory", d = "Perplexity", ne = a, oe = [
1
+ const w = "system", s = "user", c = "assistant", re = "hidden", ne = "data", a = "OpenAI", i = "Anthropic", E = "Google", M = "Summary", g = "Memory", d = "Perplexity", oe = a, se = [
2
2
  a,
3
3
  i,
4
4
  E
5
- ], u = "gpt-5", _ = "gpt-4.1-nano", m = "o4-mini", l = "claude-3-5-haiku-20241022", A = "claude-sonnet-4-20250514", f = "gemini-2.5-flash", p = "gemini-2.5-pro", R = "sonar", P = "sonar-pro", se = [
6
- u,
5
+ ], A = "gpt-5", _ = "gpt-4.1-nano", m = "o4-mini", l = "claude-3-5-haiku-20241022", u = "claude-sonnet-4-20250514", R = "gemini-2.5-flash", p = "gemini-2.5-pro", f = "sonar", P = "sonar-pro", ce = [
6
+ A,
7
7
  _,
8
8
  m,
9
9
  l,
10
- A,
11
- f,
12
- p,
10
+ u,
13
11
  R,
12
+ p,
13
+ f,
14
14
  P
15
- ], ce = [
16
- u,
15
+ ], ae = [
17
16
  A,
17
+ u,
18
18
  p
19
- ], b = "claude-sonnet-4", h = "claude-3", T = "gpt-", N = "o3", v = "o4", K = "gemini", C = "sonar", U = {
19
+ ], b = "claude-sonnet-4", h = "claude-3", T = "gpt-", N = "o3", v = "o4", C = "gemini", K = "sonar", U = {
20
20
  [i]: [
21
21
  b,
22
22
  h
@@ -26,33 +26,34 @@ const w = "system", s = "user", c = "assistant", te = "hidden", re = "data", a =
26
26
  N,
27
27
  v
28
28
  ],
29
- [E]: [K],
30
- [d]: [C]
31
- }, ae = {
32
- [a]: [_, u],
33
- [i]: [l, A],
34
- [E]: [f, p],
35
- [d]: [R, P]
29
+ [E]: [C],
30
+ [d]: [K]
36
31
  }, ie = {
32
+ [a]: [_, A],
33
+ [i]: [l, u],
34
+ [E]: [R, p],
35
+ [d]: [f, P]
36
+ }, Ee = {
37
37
  [a]: [w, s, c],
38
38
  [i]: [s, c],
39
39
  [M]: [s, c],
40
40
  [g]: [s, c],
41
41
  [E]: [s, c],
42
42
  [d]: [s, c]
43
- }, k = "sassy:free", F = "sassy:plus", G = "sassy:advanced", V = "sassy:advanced:reasoning", Ee = {
43
+ }, k = "sassy:free", F = "sassy:plus", G = "sassy:advanced", V = "sassy:advanced:reasoning", Y = "sassy:advanced:websearch", ye = {
44
44
  PLAN_FREE: k,
45
45
  PLAN_PLUS: F,
46
46
  PLAN_PREMIUM: G,
47
- REASONING: V
48
- }, ye = "x-callisto-chat-id", de = (r) => {
47
+ REASONING: V,
48
+ WEBSEARCH: Y
49
+ }, de = "x-callisto-chat-id", Ae = (r) => {
49
50
  for (const [e, n] of Object.entries(
50
51
  U
51
52
  ))
52
53
  if (n.some((t) => r.startsWith(t)))
53
54
  return e;
54
55
  return null;
55
- }, ue = "timestamp", Ae = "tokenUsage", pe = "Callisto";
56
+ }, ue = "timestamp", pe = "tokenUsage", Oe = "Callisto";
56
57
  class o extends Error {
57
58
  constructor(e, n, t) {
58
59
  super(e), this.code = n, this.originalError = t, this.name = "CryptoError";
@@ -62,7 +63,7 @@ const S = {
62
63
  keySize: 4096,
63
64
  debug: !1
64
65
  };
65
- async function Y(r = {}) {
66
+ async function x(r = {}) {
66
67
  const e = { ...S, ...r };
67
68
  try {
68
69
  const n = {
@@ -99,7 +100,7 @@ async function Y(r = {}) {
99
100
  );
100
101
  }
101
102
  }
102
- async function x(r) {
103
+ async function H(r) {
103
104
  try {
104
105
  return {
105
106
  jwk: await crypto.subtle.exportKey("jwk", r),
@@ -160,7 +161,7 @@ async function X(r, e, n) {
160
161
  );
161
162
  }
162
163
  }
163
- async function H(r, e) {
164
+ async function $(r, e) {
164
165
  try {
165
166
  const n = Uint8Array.from(
166
167
  atob(r.data),
@@ -181,7 +182,7 @@ async function H(r, e) {
181
182
  );
182
183
  }
183
184
  }
184
- async function $(r, e, n) {
185
+ async function j(r, e, n) {
185
186
  try {
186
187
  const t = await I(
187
188
  r.serverPublicKey
@@ -201,10 +202,10 @@ async function $(r, e, n) {
201
202
  );
202
203
  }
203
204
  }
204
- function j(r) {
205
+ function B(r) {
205
206
  return !(!r || !r.clientKeyPair || !r.serverPublicKey);
206
207
  }
207
- function B() {
208
+ function z() {
208
209
  const r = Date.now().toString(36), e = new Uint8Array(8);
209
210
  if (typeof window < "u" && window.crypto?.getRandomValues)
210
211
  window.crypto.getRandomValues(e);
@@ -220,7 +221,7 @@ function L() {
220
221
  function D() {
221
222
  return typeof window < "u" && (window.isSecureContext || window.location.protocol === "https:");
222
223
  }
223
- function z() {
224
+ function W() {
224
225
  return L() && D();
225
226
  }
226
227
  function J(r) {
@@ -230,65 +231,65 @@ function J(r) {
230
231
  n += String.fromCharCode(e[t]);
231
232
  return btoa(n);
232
233
  }
233
- function W(r) {
234
+ function q(r) {
234
235
  const e = atob(r), n = new Uint8Array(e.length);
235
236
  for (let t = 0; t < e.length; t++)
236
237
  n[t] = e.charCodeAt(t);
237
238
  return n.buffer;
238
239
  }
239
- function q(r) {
240
+ function Q(r) {
240
241
  try {
241
242
  return JSON.stringify(r);
242
243
  } catch {
243
244
  return String(r);
244
245
  }
245
246
  }
246
- function Q(r) {
247
+ function Z(r) {
247
248
  try {
248
249
  return JSON.parse(r);
249
250
  } catch {
250
251
  return null;
251
252
  }
252
253
  }
253
- function Z(r, ...e) {
254
+ function ee(r, ...e) {
254
255
  typeof process < "u" && process.env && process.env.NODE_ENV === "development" && console.info(`🔐 [Crypto] ${r}`, ...e);
255
256
  }
256
- const Oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, CryptoError: o, DEFAULT_CRYPTO_CONFIG: S, arrayBufferToBase64: J, base64ToArrayBuffer: W, canUseEncryption: z, debugLog: Z, decryptFromServer: H, encryptForServer: X, establishCryptoSession: $, exportPublicKey: x, generateClientKeyPair: Y, generateDeviceId: B, importServerPublicKey: I, isCryptoSessionValid: j, isSecureContext: D, isWebCryptoSupported: L, safeParse: Q, safeStringify: q }, Symbol.toStringTag, { value: "Module" }));
257
+ const _e = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, CryptoError: o, DEFAULT_CRYPTO_CONFIG: S, arrayBufferToBase64: J, base64ToArrayBuffer: q, canUseEncryption: W, debugLog: ee, decryptFromServer: $, encryptForServer: X, establishCryptoSession: j, exportPublicKey: H, generateClientKeyPair: x, generateDeviceId: z, importServerPublicKey: I, isCryptoSessionValid: B, isSecureContext: D, isWebCryptoSupported: L, safeParse: Z, safeStringify: Q }, Symbol.toStringTag, { value: "Module" }));
257
258
  export {
258
- se as ALL_MODELS,
259
- oe as ALL_PROVIDERS,
260
- ce as ALL_REASONING_MODELS,
261
- pe as APPLICATION_NAME,
262
- ye as CALLISTO_CHAT_ID_HEADER,
263
- ne as DEFAULT_PROVIDER,
264
- ae as MODELS_PER_PROVIDER,
259
+ ce as ALL_MODELS,
260
+ se as ALL_PROVIDERS,
261
+ ae as ALL_REASONING_MODELS,
262
+ Oe as APPLICATION_NAME,
263
+ de as CALLISTO_CHAT_ID_HEADER,
264
+ oe as DEFAULT_PROVIDER,
265
+ ie as MODELS_PER_PROVIDER,
265
266
  l as MODEL_CLAUDE_HAIKU,
266
- A as MODEL_CLAUDE_SONNET,
267
- f as MODEL_GEMINI_FLASH,
267
+ u as MODEL_CLAUDE_SONNET,
268
+ R as MODEL_GEMINI_FLASH,
268
269
  p as MODEL_GEMINI_PRO,
269
- u as MODEL_GPT,
270
+ A as MODEL_GPT,
270
271
  _ as MODEL_GPT4_MINI,
271
272
  m as MODEL_O4_MINI,
272
- R as MODEL_SONAR,
273
+ f as MODEL_SONAR,
273
274
  P as MODEL_SONAR_PRO,
274
275
  k as PLAN_FREE,
275
276
  F as PLAN_PLUS,
276
277
  G as PLAN_PREMIUM,
277
- Ee as POLICY_GRANTS,
278
+ ye as POLICY_GRANTS,
278
279
  i as PROVIDER_ANTHROPIC,
279
280
  E as PROVIDER_GOOGLE,
280
281
  g as PROVIDER_MEMORY,
281
282
  a as PROVIDER_OPENAI,
282
283
  d as PROVIDER_PERPLEXITY,
283
- ie as PROVIDER_ROLE_MAP,
284
+ Ee as PROVIDER_ROLE_MAP,
284
285
  M as PROVIDER_SUMMARY,
285
286
  c as ROLE_ASSISTANT,
286
- te as ROLE_HIDDEN,
287
- re as ROLE_INTERNAL,
287
+ re as ROLE_HIDDEN,
288
+ ne as ROLE_INTERNAL,
288
289
  w as ROLE_SYSTEM,
289
290
  s as ROLE_USER,
290
291
  ue as SORT_BY_TIMESTAMP,
291
- Ae as SORT_BY_TOKEN_USAGE,
292
- Oe as crypto,
293
- de as findProvider
292
+ pe as SORT_BY_TOKEN_USAGE,
293
+ _e as crypto,
294
+ Ae as findProvider
294
295
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/sassysaint-common",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -19,9 +19,11 @@
19
19
  "build:types": "tsup",
20
20
  "build": "npm-run-all --serial clean build:check build:js build:types",
21
21
  "clean": "rimraf dist tmp",
22
+ "comments:fix": "comments src/**/*.ts* --merge-line-comments",
22
23
  "dev:js": "vite build --watch --mode development",
23
24
  "dev:types": "tsup --watch src",
24
25
  "dev": "npm-run-all --parallel dev:js dev:types",
26
+ "fix": "npm-run-all lint:fix comments:fix",
25
27
  "lint": "biome lint src",
26
28
  "lint:fix": "biome check src --write --no-errors-on-unmatched",
27
29
  "test": "vitest run",
@@ -30,5 +32,5 @@
30
32
  "test:watch": "vitest",
31
33
  "watch": "npm-run-all dev"
32
34
  },
33
- "gitHead": "e846a9619cd9510aa7a7d8bf0395b2f8a4b29d4c"
35
+ "gitHead": "639ee1b0e2f051da5a348b43c6ebeec211399986"
34
36
  }