@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.
@@ -13432,9 +13432,23 @@ function conversationSortKey(data, createdAt) {
13432
13432
  if (pinnedAt) return PINNED_SORT_BASE + pinnedAt;
13433
13433
  return number(data.lastActivityAt) ?? createdAt;
13434
13434
  }
13435
+ var CONTEXT_FIELD_PREFIX = "context.";
13436
+ function contextField(key3) {
13437
+ return `${CONTEXT_FIELD_PREFIX}${key3}`;
13438
+ }
13439
+ function contextFields(context) {
13440
+ return plain(
13441
+ Object.fromEntries(Object.entries(context ?? {}).map(([k, value]) => [contextField(k), value]))
13442
+ );
13443
+ }
13444
+ function conversationContext(data) {
13445
+ const entries = Object.entries(data).filter(([field10]) => field10.startsWith(CONTEXT_FIELD_PREFIX)).map(([field10, value]) => [field10.slice(CONTEXT_FIELD_PREFIX.length), value]);
13446
+ return entries.length > 0 ? plain(Object.fromEntries(entries)) : void 0;
13447
+ }
13435
13448
  function toConversation(record2) {
13436
13449
  const pinnedAt = number(record2.data.pinnedAt);
13437
13450
  const projectId = text4(record2.data.projectId);
13451
+ const context = conversationContext(record2.data);
13438
13452
  return {
13439
13453
  uniqueId: record2.id,
13440
13454
  conversationId: record2.id,
@@ -13443,7 +13457,8 @@ function toConversation(record2) {
13443
13457
  createdAt: new Date(record2.createdAt),
13444
13458
  updatedAt: new Date(record2.updatedAt),
13445
13459
  isDeleted: record2.isDeleted,
13446
- pinnedAt: pinnedAt ? new Date(pinnedAt) : null
13460
+ pinnedAt: pinnedAt ? new Date(pinnedAt) : null,
13461
+ ...context ? { context } : {}
13447
13462
  };
13448
13463
  }
13449
13464
  function messageData(options) {
@@ -13602,6 +13617,7 @@ function bytes2(value) {
13602
13617
  function conversationRecord(conversation, messages) {
13603
13618
  const createdAt = ms(conversation.createdAt);
13604
13619
  const data = plain({
13620
+ ...contextFields(conversation.context),
13605
13621
  title: conversation.title,
13606
13622
  projectId: conversation.projectId || void 0,
13607
13623
  pinnedAt: conversation.pinnedAt ? ms(conversation.pinnedAt) : void 0,
@@ -15771,6 +15787,12 @@ function createVaultChatBackend(options) {
15771
15787
  async updateConversationPinned(conversationId, pinned) {
15772
15788
  return updateConversation(conversationId, { pinnedAt: pinned ? now() : null });
15773
15789
  },
15790
+ async updateConversationContext(conversationId, context) {
15791
+ const set = contextFields(context);
15792
+ if (Object.keys(set).length > 0) return updateConversation(conversationId, set);
15793
+ const record2 = await conversation(conversationId);
15794
+ return !!record2 && !record2.isDeleted;
15795
+ },
15774
15796
  async deleteConversation(conversationId) {
15775
15797
  const record2 = await conversation(conversationId);
15776
15798
  if (!record2 || record2.isDeleted) return false;
@@ -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;