@anuma/sdk 10.7.0 → 10.8.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.
@@ -3262,6 +3262,159 @@ interface WebSearchPreProcessorOptions {
3262
3262
  */
3263
3263
  declare function createWebSearchPreProcessor(options?: WebSearchPreProcessorOptions): PromptPreProcessor;
3264
3264
 
3265
+ type ChatRecordKind = "conversation" | "message" | "summary" | "project" | "memory_links" | "setting";
3266
+ type ChatJson = null | boolean | number | string | ChatJson[] | {
3267
+ [key: string]: ChatJson;
3268
+ };
3269
+ /** Whole-record JSON data is encrypted on the device, including all text, vectors and tool events. */
3270
+ interface ChatRecord {
3271
+ kind: ChatRecordKind;
3272
+ id: string;
3273
+ conversationId: string;
3274
+ sortKey: number;
3275
+ createdAt: number;
3276
+ updatedAt: number;
3277
+ isDeleted: boolean;
3278
+ data: {
3279
+ [key: string]: ChatJson;
3280
+ };
3281
+ }
3282
+ interface ChatSnapshot {
3283
+ record: ChatRecord;
3284
+ version: number;
3285
+ serverUpdatedAt: string;
3286
+ }
3287
+ interface ChatWrite {
3288
+ record: ChatRecord;
3289
+ expectedVersion: number;
3290
+ /** Sent and stored unencrypted so vault can run vector search. */
3291
+ embeddings?: number[][];
3292
+ embeddingModel?: string;
3293
+ }
3294
+ interface ChatRef {
3295
+ kind: ChatRecordKind;
3296
+ id: string;
3297
+ }
3298
+ type ChatAccountState = "none" | "migrating" | "active";
3299
+ interface ChatAccount {
3300
+ keyId: string;
3301
+ state: ChatAccountState;
3302
+ recordCount: number;
3303
+ storageBytes: number;
3304
+ vectorCount: number;
3305
+ /** The newest change; read it before loading history and poll `changes` from it. Absent before the first record. */
3306
+ changesCursor?: string;
3307
+ }
3308
+ interface ChatImport {
3309
+ record: ChatRecord;
3310
+ /** Sent and stored unencrypted so vault can run vector search. */
3311
+ embeddings?: number[][];
3312
+ embeddingModel?: string;
3313
+ }
3314
+ interface ChatRevision {
3315
+ kind: ChatRecordKind;
3316
+ id: string;
3317
+ updatedAt: number;
3318
+ isDeleted: boolean;
3319
+ }
3320
+ interface ChatChanges {
3321
+ items: ChatSnapshot[];
3322
+ nextCursor?: string;
3323
+ changesCursor: string;
3324
+ }
3325
+ interface ChatSearchOptions {
3326
+ limit?: number;
3327
+ kinds?: ("message" | "summary")[];
3328
+ conversationId?: string;
3329
+ excludeConversationId?: string;
3330
+ /** Ranks only vectors from this model; vectors stored without one always count. */
3331
+ embeddingModel?: string;
3332
+ signal?: AbortSignal;
3333
+ }
3334
+ interface ChatSearchHit extends ChatSnapshot {
3335
+ chunk: number;
3336
+ score: number;
3337
+ }
3338
+ interface ChatAttachment {
3339
+ id: string;
3340
+ sizeBytes: number;
3341
+ state: "pending" | "committed";
3342
+ ownerKind?: "message" | "summary";
3343
+ ownerId?: string;
3344
+ createdAt: string;
3345
+ committedAt?: string;
3346
+ }
3347
+ interface ChatPresignedUrl {
3348
+ url: string;
3349
+ method: string;
3350
+ headers: Record<string, string>;
3351
+ expiresAt: string;
3352
+ }
3353
+ interface ChatAttachments {
3354
+ create(sizeBytes: number, signal?: AbortSignal): Promise<{
3355
+ attachment: ChatAttachment;
3356
+ upload: ChatPresignedUrl;
3357
+ }>;
3358
+ commit(attachmentId: string, owner: {
3359
+ kind: "message" | "summary";
3360
+ id: string;
3361
+ }, signal?: AbortSignal): Promise<ChatAttachment>;
3362
+ get(attachmentId: string, signal?: AbortSignal): Promise<{
3363
+ attachment: ChatAttachment;
3364
+ download?: ChatPresignedUrl;
3365
+ } | null>;
3366
+ delete(attachmentId: string, signal?: AbortSignal): Promise<void>;
3367
+ }
3368
+ interface ChatListOptions {
3369
+ kind: ChatRecordKind;
3370
+ conversationId?: string;
3371
+ includeDeleted?: boolean;
3372
+ cursor?: string;
3373
+ limit?: number;
3374
+ signal?: AbortSignal;
3375
+ }
3376
+ interface ChatPage {
3377
+ items: ChatSnapshot[];
3378
+ nextCursor?: string;
3379
+ total?: number;
3380
+ }
3381
+ /** Explicit versions protect edits; ambiguous writes are never replayed automatically. */
3382
+ interface ChatStore {
3383
+ get(kind: ChatRecordKind, id: string, signal?: AbortSignal): Promise<ChatSnapshot | null>;
3384
+ list(options: ChatListOptions): Promise<ChatPage>;
3385
+ putMany(writes: readonly ChatWrite[], signal?: AbortSignal): Promise<ChatSnapshot[]>;
3386
+ getMany(refs: readonly ChatRef[], signal?: AbortSignal): Promise<ChatSnapshot[]>;
3387
+ account(signal?: AbortSignal): Promise<ChatAccount>;
3388
+ importRecords(records: readonly ChatImport[], signal?: AbortSignal): Promise<number>;
3389
+ verify(revisions: readonly ChatRevision[], signal?: AbortSignal): Promise<ChatRef[]>;
3390
+ activate(signal?: AbortSignal): Promise<boolean>;
3391
+ /** Without `kinds`, vault returns every kind except `setting`. */
3392
+ changes(cursor?: string, options?: {
3393
+ limit?: number;
3394
+ kinds?: readonly ChatRecordKind[];
3395
+ signal?: AbortSignal;
3396
+ }): Promise<ChatChanges>;
3397
+ search(embedding: readonly number[], options?: ChatSearchOptions): Promise<ChatSearchHit[]>;
3398
+ deleteAll(signal?: AbortSignal): Promise<number>;
3399
+ attachments: ChatAttachments;
3400
+ }
3401
+ interface RemoteChatStoreOptions {
3402
+ baseUrl: string;
3403
+ getToken: () => Promise<string | null>;
3404
+ keyId: string;
3405
+ encrypt: (plaintext: string) => Promise<string>;
3406
+ decrypt: (ciphertext: string) => Promise<string>;
3407
+ fetch?: typeof globalThis.fetch;
3408
+ timeoutMs?: number;
3409
+ signal?: AbortSignal;
3410
+ }
3411
+ declare class ChatStoreError extends Error {
3412
+ readonly status: number;
3413
+ readonly code?: string | undefined;
3414
+ readonly retryAfterMs?: number | undefined;
3415
+ constructor(message: string, status: number, code?: string | undefined, retryAfterMs?: number | undefined);
3416
+ }
3417
+
3265
3418
  declare class VaultMemory extends Model {
3266
3419
  static table: string;
3267
3420
  content: string;
@@ -8552,6 +8705,10 @@ interface StoredConversation {
8552
8705
  /** When the conversation was pinned to the top of the list; null/unset = not pinned.
8553
8706
  * `null` (not `undefined`) at runtime for unpinned rows — mirrors the model field. */
8554
8707
  pinnedAt?: Date | null;
8708
+ /** Per-conversation app state kept with the conversation in vault, keyed by the app; absent on local storage. */
8709
+ context?: {
8710
+ [key: string]: ChatJson;
8711
+ };
8555
8712
  }
8556
8713
  /**
8557
8714
  * Lazy variant of {@link StoredConversation}.
@@ -9251,159 +9408,6 @@ interface BaseUseChatStorageResult {
9251
9408
  }
9252
9409
  declare function generateConversationId(): string;
9253
9410
 
9254
- type ChatRecordKind = "conversation" | "message" | "summary" | "project" | "memory_links" | "setting";
9255
- type ChatJson = null | boolean | number | string | ChatJson[] | {
9256
- [key: string]: ChatJson;
9257
- };
9258
- /** Whole-record JSON data is encrypted on the device, including all text, vectors and tool events. */
9259
- interface ChatRecord {
9260
- kind: ChatRecordKind;
9261
- id: string;
9262
- conversationId: string;
9263
- sortKey: number;
9264
- createdAt: number;
9265
- updatedAt: number;
9266
- isDeleted: boolean;
9267
- data: {
9268
- [key: string]: ChatJson;
9269
- };
9270
- }
9271
- interface ChatSnapshot {
9272
- record: ChatRecord;
9273
- version: number;
9274
- serverUpdatedAt: string;
9275
- }
9276
- interface ChatWrite {
9277
- record: ChatRecord;
9278
- expectedVersion: number;
9279
- /** Sent and stored unencrypted so vault can run vector search. */
9280
- embeddings?: number[][];
9281
- embeddingModel?: string;
9282
- }
9283
- interface ChatRef {
9284
- kind: ChatRecordKind;
9285
- id: string;
9286
- }
9287
- type ChatAccountState = "none" | "migrating" | "active";
9288
- interface ChatAccount {
9289
- keyId: string;
9290
- state: ChatAccountState;
9291
- recordCount: number;
9292
- storageBytes: number;
9293
- vectorCount: number;
9294
- /** The newest change; read it before loading history and poll `changes` from it. Absent before the first record. */
9295
- changesCursor?: string;
9296
- }
9297
- interface ChatImport {
9298
- record: ChatRecord;
9299
- /** Sent and stored unencrypted so vault can run vector search. */
9300
- embeddings?: number[][];
9301
- embeddingModel?: string;
9302
- }
9303
- interface ChatRevision {
9304
- kind: ChatRecordKind;
9305
- id: string;
9306
- updatedAt: number;
9307
- isDeleted: boolean;
9308
- }
9309
- interface ChatChanges {
9310
- items: ChatSnapshot[];
9311
- nextCursor?: string;
9312
- changesCursor: string;
9313
- }
9314
- interface ChatSearchOptions {
9315
- limit?: number;
9316
- kinds?: ("message" | "summary")[];
9317
- conversationId?: string;
9318
- excludeConversationId?: string;
9319
- /** Ranks only vectors from this model; vectors stored without one always count. */
9320
- embeddingModel?: string;
9321
- signal?: AbortSignal;
9322
- }
9323
- interface ChatSearchHit extends ChatSnapshot {
9324
- chunk: number;
9325
- score: number;
9326
- }
9327
- interface ChatAttachment {
9328
- id: string;
9329
- sizeBytes: number;
9330
- state: "pending" | "committed";
9331
- ownerKind?: "message" | "summary";
9332
- ownerId?: string;
9333
- createdAt: string;
9334
- committedAt?: string;
9335
- }
9336
- interface ChatPresignedUrl {
9337
- url: string;
9338
- method: string;
9339
- headers: Record<string, string>;
9340
- expiresAt: string;
9341
- }
9342
- interface ChatAttachments {
9343
- create(sizeBytes: number, signal?: AbortSignal): Promise<{
9344
- attachment: ChatAttachment;
9345
- upload: ChatPresignedUrl;
9346
- }>;
9347
- commit(attachmentId: string, owner: {
9348
- kind: "message" | "summary";
9349
- id: string;
9350
- }, signal?: AbortSignal): Promise<ChatAttachment>;
9351
- get(attachmentId: string, signal?: AbortSignal): Promise<{
9352
- attachment: ChatAttachment;
9353
- download?: ChatPresignedUrl;
9354
- } | null>;
9355
- delete(attachmentId: string, signal?: AbortSignal): Promise<void>;
9356
- }
9357
- interface ChatListOptions {
9358
- kind: ChatRecordKind;
9359
- conversationId?: string;
9360
- includeDeleted?: boolean;
9361
- cursor?: string;
9362
- limit?: number;
9363
- signal?: AbortSignal;
9364
- }
9365
- interface ChatPage {
9366
- items: ChatSnapshot[];
9367
- nextCursor?: string;
9368
- total?: number;
9369
- }
9370
- /** Explicit versions protect edits; ambiguous writes are never replayed automatically. */
9371
- interface ChatStore {
9372
- get(kind: ChatRecordKind, id: string, signal?: AbortSignal): Promise<ChatSnapshot | null>;
9373
- list(options: ChatListOptions): Promise<ChatPage>;
9374
- putMany(writes: readonly ChatWrite[], signal?: AbortSignal): Promise<ChatSnapshot[]>;
9375
- getMany(refs: readonly ChatRef[], signal?: AbortSignal): Promise<ChatSnapshot[]>;
9376
- account(signal?: AbortSignal): Promise<ChatAccount>;
9377
- importRecords(records: readonly ChatImport[], signal?: AbortSignal): Promise<number>;
9378
- verify(revisions: readonly ChatRevision[], signal?: AbortSignal): Promise<ChatRef[]>;
9379
- activate(signal?: AbortSignal): Promise<boolean>;
9380
- /** Without `kinds`, vault returns every kind except `setting`. */
9381
- changes(cursor?: string, options?: {
9382
- limit?: number;
9383
- kinds?: readonly ChatRecordKind[];
9384
- signal?: AbortSignal;
9385
- }): Promise<ChatChanges>;
9386
- search(embedding: readonly number[], options?: ChatSearchOptions): Promise<ChatSearchHit[]>;
9387
- deleteAll(signal?: AbortSignal): Promise<number>;
9388
- attachments: ChatAttachments;
9389
- }
9390
- interface RemoteChatStoreOptions {
9391
- baseUrl: string;
9392
- getToken: () => Promise<string | null>;
9393
- keyId: string;
9394
- encrypt: (plaintext: string) => Promise<string>;
9395
- decrypt: (ciphertext: string) => Promise<string>;
9396
- fetch?: typeof globalThis.fetch;
9397
- timeoutMs?: number;
9398
- signal?: AbortSignal;
9399
- }
9400
- declare class ChatStoreError extends Error {
9401
- readonly status: number;
9402
- readonly code?: string | undefined;
9403
- readonly retryAfterMs?: number | undefined;
9404
- constructor(message: string, status: number, code?: string | undefined, retryAfterMs?: number | undefined);
9405
- }
9406
-
9407
9411
  interface ChatMigrationOptions {
9408
9412
  /** The device's local chat database. */
9409
9413
  database: Database;
@@ -9669,6 +9673,10 @@ interface VaultChatBackend extends ChatBackend {
9669
9673
  conversations: number;
9670
9674
  messages: number;
9671
9675
  }>;
9676
+ /** Sets keys of a conversation's app context, each saved on its own so devices editing different keys keep both; `null` clears a key. */
9677
+ updateConversationContext(conversationId: string, context: {
9678
+ [key: string]: ChatJson | null;
9679
+ }): Promise<boolean>;
9672
9680
  status(): {
9673
9681
  pending: number;
9674
9682
  stopped?: string;
@@ -11554,9 +11554,23 @@ function conversationSortKey(data, createdAt) {
11554
11554
  if (pinnedAt) return PINNED_SORT_BASE + pinnedAt;
11555
11555
  return number(data.lastActivityAt) ?? createdAt;
11556
11556
  }
11557
+ var CONTEXT_FIELD_PREFIX = "context.";
11558
+ function contextField(key3) {
11559
+ return `${CONTEXT_FIELD_PREFIX}${key3}`;
11560
+ }
11561
+ function contextFields(context) {
11562
+ return plain(
11563
+ Object.fromEntries(Object.entries(context ?? {}).map(([k, value]) => [contextField(k), value]))
11564
+ );
11565
+ }
11566
+ function conversationContext(data) {
11567
+ const entries = Object.entries(data).filter(([field10]) => field10.startsWith(CONTEXT_FIELD_PREFIX)).map(([field10, value]) => [field10.slice(CONTEXT_FIELD_PREFIX.length), value]);
11568
+ return entries.length > 0 ? plain(Object.fromEntries(entries)) : void 0;
11569
+ }
11557
11570
  function toConversation(record2) {
11558
11571
  const pinnedAt = number(record2.data.pinnedAt);
11559
11572
  const projectId = text4(record2.data.projectId);
11573
+ const context = conversationContext(record2.data);
11560
11574
  return {
11561
11575
  uniqueId: record2.id,
11562
11576
  conversationId: record2.id,
@@ -11565,7 +11579,8 @@ function toConversation(record2) {
11565
11579
  createdAt: new Date(record2.createdAt),
11566
11580
  updatedAt: new Date(record2.updatedAt),
11567
11581
  isDeleted: record2.isDeleted,
11568
- pinnedAt: pinnedAt ? new Date(pinnedAt) : null
11582
+ pinnedAt: pinnedAt ? new Date(pinnedAt) : null,
11583
+ ...context ? { context } : {}
11569
11584
  };
11570
11585
  }
11571
11586
  function messageData(options) {
@@ -11724,6 +11739,7 @@ function bytes2(value) {
11724
11739
  function conversationRecord(conversation, messages) {
11725
11740
  const createdAt = ms(conversation.createdAt);
11726
11741
  const data = plain({
11742
+ ...contextFields(conversation.context),
11727
11743
  title: conversation.title,
11728
11744
  projectId: conversation.projectId || void 0,
11729
11745
  pinnedAt: conversation.pinnedAt ? ms(conversation.pinnedAt) : void 0,
@@ -13893,6 +13909,12 @@ function createVaultChatBackend(options) {
13893
13909
  async updateConversationPinned(conversationId, pinned) {
13894
13910
  return updateConversation(conversationId, { pinnedAt: pinned ? now() : null });
13895
13911
  },
13912
+ async updateConversationContext(conversationId, context) {
13913
+ const set = contextFields(context);
13914
+ if (Object.keys(set).length > 0) return updateConversation(conversationId, set);
13915
+ const record2 = await conversation(conversationId);
13916
+ return !!record2 && !record2.isDeleted;
13917
+ },
13896
13918
  async deleteConversation(conversationId) {
13897
13919
  const record2 = await conversation(conversationId);
13898
13920
  if (!record2 || record2.isDeleted) return false;
@@ -2603,6 +2603,10 @@ interface StockPricePreProcessorOptions {
2603
2603
  */
2604
2604
  declare function createStockPricePreProcessor(options?: StockPricePreProcessorOptions): PromptPreProcessor;
2605
2605
 
2606
+ type ChatJson = null | boolean | number | string | ChatJson[] | {
2607
+ [key: string]: ChatJson;
2608
+ };
2609
+
2606
2610
  declare class VaultMemory extends Model {
2607
2611
  static table: string;
2608
2612
  content: string;
@@ -7564,6 +7568,10 @@ interface StoredConversation {
7564
7568
  /** When the conversation was pinned to the top of the list; null/unset = not pinned.
7565
7569
  * `null` (not `undefined`) at runtime for unpinned rows — mirrors the model field. */
7566
7570
  pinnedAt?: Date | null;
7571
+ /** Per-conversation app state kept with the conversation in vault, keyed by the app; absent on local storage. */
7572
+ context?: {
7573
+ [key: string]: ChatJson;
7574
+ };
7567
7575
  }
7568
7576
  /**
7569
7577
  * Lazy variant of {@link StoredConversation}.
@@ -2603,6 +2603,10 @@ interface StockPricePreProcessorOptions {
2603
2603
  */
2604
2604
  declare function createStockPricePreProcessor(options?: StockPricePreProcessorOptions): PromptPreProcessor;
2605
2605
 
2606
+ type ChatJson = null | boolean | number | string | ChatJson[] | {
2607
+ [key: string]: ChatJson;
2608
+ };
2609
+
2606
2610
  declare class VaultMemory extends Model {
2607
2611
  static table: string;
2608
2612
  content: string;
@@ -7564,6 +7568,10 @@ interface StoredConversation {
7564
7568
  /** When the conversation was pinned to the top of the list; null/unset = not pinned.
7565
7569
  * `null` (not `undefined`) at runtime for unpinned rows — mirrors the model field. */
7566
7570
  pinnedAt?: Date | null;
7571
+ /** Per-conversation app state kept with the conversation in vault, keyed by the app; absent on local storage. */
7572
+ context?: {
7573
+ [key: string]: ChatJson;
7574
+ };
7567
7575
  }
7568
7576
  /**
7569
7577
  * Lazy variant of {@link StoredConversation}.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "10.7.0",
3
+ "version": "10.8.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",