@anuma/sdk 10.6.2 → 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.
@@ -2587,6 +2587,8 @@ type RunToolLoopResult = {
2587
2587
  detached?: true;
2588
2588
  /** Non-null only when `resumable` was true AND an inference id was captured before detach. */
2589
2589
  resume?: StreamResumeHandle | null;
2590
+ /** True when the connection failed rather than the generation: the portal may still be generating. */
2591
+ connectionLost?: true;
2590
2592
  /**
2591
2593
  * Terminal state of the final model response, when the failure is one the
2592
2594
  * loop diagnosed FROM that response — today, the truncated-to-nothing
@@ -3065,6 +3067,159 @@ declare function createWebSearchPreProcessor(options?: WebSearchPreProcessorOpti
3065
3067
  */
3066
3068
  declare const xhrTransport: StreamingTransport;
3067
3069
 
3070
+ type ChatRecordKind = "conversation" | "message" | "summary" | "project" | "memory_links" | "setting";
3071
+ type ChatJson = null | boolean | number | string | ChatJson[] | {
3072
+ [key: string]: ChatJson;
3073
+ };
3074
+ /** Whole-record JSON data is encrypted on the device, including all text, vectors and tool events. */
3075
+ interface ChatRecord {
3076
+ kind: ChatRecordKind;
3077
+ id: string;
3078
+ conversationId: string;
3079
+ sortKey: number;
3080
+ createdAt: number;
3081
+ updatedAt: number;
3082
+ isDeleted: boolean;
3083
+ data: {
3084
+ [key: string]: ChatJson;
3085
+ };
3086
+ }
3087
+ interface ChatSnapshot {
3088
+ record: ChatRecord;
3089
+ version: number;
3090
+ serverUpdatedAt: string;
3091
+ }
3092
+ interface ChatWrite {
3093
+ record: ChatRecord;
3094
+ expectedVersion: number;
3095
+ /** Sent and stored unencrypted so vault can run vector search. */
3096
+ embeddings?: number[][];
3097
+ embeddingModel?: string;
3098
+ }
3099
+ interface ChatRef {
3100
+ kind: ChatRecordKind;
3101
+ id: string;
3102
+ }
3103
+ type ChatAccountState = "none" | "migrating" | "active";
3104
+ interface ChatAccount {
3105
+ keyId: string;
3106
+ state: ChatAccountState;
3107
+ recordCount: number;
3108
+ storageBytes: number;
3109
+ vectorCount: number;
3110
+ /** The newest change; read it before loading history and poll `changes` from it. Absent before the first record. */
3111
+ changesCursor?: string;
3112
+ }
3113
+ interface ChatImport {
3114
+ record: ChatRecord;
3115
+ /** Sent and stored unencrypted so vault can run vector search. */
3116
+ embeddings?: number[][];
3117
+ embeddingModel?: string;
3118
+ }
3119
+ interface ChatRevision {
3120
+ kind: ChatRecordKind;
3121
+ id: string;
3122
+ updatedAt: number;
3123
+ isDeleted: boolean;
3124
+ }
3125
+ interface ChatChanges {
3126
+ items: ChatSnapshot[];
3127
+ nextCursor?: string;
3128
+ changesCursor: string;
3129
+ }
3130
+ interface ChatSearchOptions {
3131
+ limit?: number;
3132
+ kinds?: ("message" | "summary")[];
3133
+ conversationId?: string;
3134
+ excludeConversationId?: string;
3135
+ /** Ranks only vectors from this model; vectors stored without one always count. */
3136
+ embeddingModel?: string;
3137
+ signal?: AbortSignal;
3138
+ }
3139
+ interface ChatSearchHit extends ChatSnapshot {
3140
+ chunk: number;
3141
+ score: number;
3142
+ }
3143
+ interface ChatAttachment {
3144
+ id: string;
3145
+ sizeBytes: number;
3146
+ state: "pending" | "committed";
3147
+ ownerKind?: "message" | "summary";
3148
+ ownerId?: string;
3149
+ createdAt: string;
3150
+ committedAt?: string;
3151
+ }
3152
+ interface ChatPresignedUrl {
3153
+ url: string;
3154
+ method: string;
3155
+ headers: Record<string, string>;
3156
+ expiresAt: string;
3157
+ }
3158
+ interface ChatAttachments {
3159
+ create(sizeBytes: number, signal?: AbortSignal): Promise<{
3160
+ attachment: ChatAttachment;
3161
+ upload: ChatPresignedUrl;
3162
+ }>;
3163
+ commit(attachmentId: string, owner: {
3164
+ kind: "message" | "summary";
3165
+ id: string;
3166
+ }, signal?: AbortSignal): Promise<ChatAttachment>;
3167
+ get(attachmentId: string, signal?: AbortSignal): Promise<{
3168
+ attachment: ChatAttachment;
3169
+ download?: ChatPresignedUrl;
3170
+ } | null>;
3171
+ delete(attachmentId: string, signal?: AbortSignal): Promise<void>;
3172
+ }
3173
+ interface ChatListOptions {
3174
+ kind: ChatRecordKind;
3175
+ conversationId?: string;
3176
+ includeDeleted?: boolean;
3177
+ cursor?: string;
3178
+ limit?: number;
3179
+ signal?: AbortSignal;
3180
+ }
3181
+ interface ChatPage {
3182
+ items: ChatSnapshot[];
3183
+ nextCursor?: string;
3184
+ total?: number;
3185
+ }
3186
+ /** Explicit versions protect edits; ambiguous writes are never replayed automatically. */
3187
+ interface ChatStore {
3188
+ get(kind: ChatRecordKind, id: string, signal?: AbortSignal): Promise<ChatSnapshot | null>;
3189
+ list(options: ChatListOptions): Promise<ChatPage>;
3190
+ putMany(writes: readonly ChatWrite[], signal?: AbortSignal): Promise<ChatSnapshot[]>;
3191
+ getMany(refs: readonly ChatRef[], signal?: AbortSignal): Promise<ChatSnapshot[]>;
3192
+ account(signal?: AbortSignal): Promise<ChatAccount>;
3193
+ importRecords(records: readonly ChatImport[], signal?: AbortSignal): Promise<number>;
3194
+ verify(revisions: readonly ChatRevision[], signal?: AbortSignal): Promise<ChatRef[]>;
3195
+ activate(signal?: AbortSignal): Promise<boolean>;
3196
+ /** Without `kinds`, vault returns every kind except `setting`. */
3197
+ changes(cursor?: string, options?: {
3198
+ limit?: number;
3199
+ kinds?: readonly ChatRecordKind[];
3200
+ signal?: AbortSignal;
3201
+ }): Promise<ChatChanges>;
3202
+ search(embedding: readonly number[], options?: ChatSearchOptions): Promise<ChatSearchHit[]>;
3203
+ deleteAll(signal?: AbortSignal): Promise<number>;
3204
+ attachments: ChatAttachments;
3205
+ }
3206
+ interface RemoteChatStoreOptions {
3207
+ baseUrl: string;
3208
+ getToken: () => Promise<string | null>;
3209
+ keyId: string;
3210
+ encrypt: (plaintext: string) => Promise<string>;
3211
+ decrypt: (ciphertext: string) => Promise<string>;
3212
+ fetch?: typeof globalThis.fetch;
3213
+ timeoutMs?: number;
3214
+ signal?: AbortSignal;
3215
+ }
3216
+ declare class ChatStoreError extends Error {
3217
+ readonly status: number;
3218
+ readonly code?: string | undefined;
3219
+ readonly retryAfterMs?: number | undefined;
3220
+ constructor(message: string, status: number, code?: string | undefined, retryAfterMs?: number | undefined);
3221
+ }
3222
+
3068
3223
  declare class VaultMemory extends Model {
3069
3224
  static table: string;
3070
3225
  content: string;
@@ -7535,6 +7690,10 @@ interface StoredConversation {
7535
7690
  /** When the conversation was pinned to the top of the list; null/unset = not pinned.
7536
7691
  * `null` (not `undefined`) at runtime for unpinned rows — mirrors the model field. */
7537
7692
  pinnedAt?: Date | null;
7693
+ /** Per-conversation app state kept with the conversation in vault, keyed by the app; absent on local storage. */
7694
+ context?: {
7695
+ [key: string]: ChatJson;
7696
+ };
7538
7697
  }
7539
7698
  /**
7540
7699
  * Lazy variant of {@link StoredConversation}.
@@ -8273,159 +8432,6 @@ interface BaseUseChatStorageResult {
8273
8432
  }
8274
8433
  declare function generateConversationId(): string;
8275
8434
 
8276
- type ChatRecordKind = "conversation" | "message" | "summary" | "project" | "memory_links" | "setting";
8277
- type ChatJson = null | boolean | number | string | ChatJson[] | {
8278
- [key: string]: ChatJson;
8279
- };
8280
- /** Whole-record JSON data is encrypted on the device, including all text, vectors and tool events. */
8281
- interface ChatRecord {
8282
- kind: ChatRecordKind;
8283
- id: string;
8284
- conversationId: string;
8285
- sortKey: number;
8286
- createdAt: number;
8287
- updatedAt: number;
8288
- isDeleted: boolean;
8289
- data: {
8290
- [key: string]: ChatJson;
8291
- };
8292
- }
8293
- interface ChatSnapshot {
8294
- record: ChatRecord;
8295
- version: number;
8296
- serverUpdatedAt: string;
8297
- }
8298
- interface ChatWrite {
8299
- record: ChatRecord;
8300
- expectedVersion: number;
8301
- /** Sent and stored unencrypted so vault can run vector search. */
8302
- embeddings?: number[][];
8303
- embeddingModel?: string;
8304
- }
8305
- interface ChatRef {
8306
- kind: ChatRecordKind;
8307
- id: string;
8308
- }
8309
- type ChatAccountState = "none" | "migrating" | "active";
8310
- interface ChatAccount {
8311
- keyId: string;
8312
- state: ChatAccountState;
8313
- recordCount: number;
8314
- storageBytes: number;
8315
- vectorCount: number;
8316
- /** The newest change; read it before loading history and poll `changes` from it. Absent before the first record. */
8317
- changesCursor?: string;
8318
- }
8319
- interface ChatImport {
8320
- record: ChatRecord;
8321
- /** Sent and stored unencrypted so vault can run vector search. */
8322
- embeddings?: number[][];
8323
- embeddingModel?: string;
8324
- }
8325
- interface ChatRevision {
8326
- kind: ChatRecordKind;
8327
- id: string;
8328
- updatedAt: number;
8329
- isDeleted: boolean;
8330
- }
8331
- interface ChatChanges {
8332
- items: ChatSnapshot[];
8333
- nextCursor?: string;
8334
- changesCursor: string;
8335
- }
8336
- interface ChatSearchOptions {
8337
- limit?: number;
8338
- kinds?: ("message" | "summary")[];
8339
- conversationId?: string;
8340
- excludeConversationId?: string;
8341
- /** Ranks only vectors from this model; vectors stored without one always count. */
8342
- embeddingModel?: string;
8343
- signal?: AbortSignal;
8344
- }
8345
- interface ChatSearchHit extends ChatSnapshot {
8346
- chunk: number;
8347
- score: number;
8348
- }
8349
- interface ChatAttachment {
8350
- id: string;
8351
- sizeBytes: number;
8352
- state: "pending" | "committed";
8353
- ownerKind?: "message" | "summary";
8354
- ownerId?: string;
8355
- createdAt: string;
8356
- committedAt?: string;
8357
- }
8358
- interface ChatPresignedUrl {
8359
- url: string;
8360
- method: string;
8361
- headers: Record<string, string>;
8362
- expiresAt: string;
8363
- }
8364
- interface ChatAttachments {
8365
- create(sizeBytes: number, signal?: AbortSignal): Promise<{
8366
- attachment: ChatAttachment;
8367
- upload: ChatPresignedUrl;
8368
- }>;
8369
- commit(attachmentId: string, owner: {
8370
- kind: "message" | "summary";
8371
- id: string;
8372
- }, signal?: AbortSignal): Promise<ChatAttachment>;
8373
- get(attachmentId: string, signal?: AbortSignal): Promise<{
8374
- attachment: ChatAttachment;
8375
- download?: ChatPresignedUrl;
8376
- } | null>;
8377
- delete(attachmentId: string, signal?: AbortSignal): Promise<void>;
8378
- }
8379
- interface ChatListOptions {
8380
- kind: ChatRecordKind;
8381
- conversationId?: string;
8382
- includeDeleted?: boolean;
8383
- cursor?: string;
8384
- limit?: number;
8385
- signal?: AbortSignal;
8386
- }
8387
- interface ChatPage {
8388
- items: ChatSnapshot[];
8389
- nextCursor?: string;
8390
- total?: number;
8391
- }
8392
- /** Explicit versions protect edits; ambiguous writes are never replayed automatically. */
8393
- interface ChatStore {
8394
- get(kind: ChatRecordKind, id: string, signal?: AbortSignal): Promise<ChatSnapshot | null>;
8395
- list(options: ChatListOptions): Promise<ChatPage>;
8396
- putMany(writes: readonly ChatWrite[], signal?: AbortSignal): Promise<ChatSnapshot[]>;
8397
- getMany(refs: readonly ChatRef[], signal?: AbortSignal): Promise<ChatSnapshot[]>;
8398
- account(signal?: AbortSignal): Promise<ChatAccount>;
8399
- importRecords(records: readonly ChatImport[], signal?: AbortSignal): Promise<number>;
8400
- verify(revisions: readonly ChatRevision[], signal?: AbortSignal): Promise<ChatRef[]>;
8401
- activate(signal?: AbortSignal): Promise<boolean>;
8402
- /** Without `kinds`, vault returns every kind except `setting`. */
8403
- changes(cursor?: string, options?: {
8404
- limit?: number;
8405
- kinds?: readonly ChatRecordKind[];
8406
- signal?: AbortSignal;
8407
- }): Promise<ChatChanges>;
8408
- search(embedding: readonly number[], options?: ChatSearchOptions): Promise<ChatSearchHit[]>;
8409
- deleteAll(signal?: AbortSignal): Promise<number>;
8410
- attachments: ChatAttachments;
8411
- }
8412
- interface RemoteChatStoreOptions {
8413
- baseUrl: string;
8414
- getToken: () => Promise<string | null>;
8415
- keyId: string;
8416
- encrypt: (plaintext: string) => Promise<string>;
8417
- decrypt: (ciphertext: string) => Promise<string>;
8418
- fetch?: typeof globalThis.fetch;
8419
- timeoutMs?: number;
8420
- signal?: AbortSignal;
8421
- }
8422
- declare class ChatStoreError extends Error {
8423
- readonly status: number;
8424
- readonly code?: string | undefined;
8425
- readonly retryAfterMs?: number | undefined;
8426
- constructor(message: string, status: number, code?: string | undefined, retryAfterMs?: number | undefined);
8427
- }
8428
-
8429
8435
  interface ChatMigrationOptions {
8430
8436
  /** The device's local chat database. */
8431
8437
  database: Database;
@@ -8691,6 +8697,10 @@ interface VaultChatBackend extends ChatBackend {
8691
8697
  conversations: number;
8692
8698
  messages: number;
8693
8699
  }>;
8700
+ /** Sets keys of a conversation's app context, each saved on its own so devices editing different keys keep both; `null` clears a key. */
8701
+ updateConversationContext(conversationId: string, context: {
8702
+ [key: string]: ChatJson | null;
8703
+ }): Promise<boolean>;
8694
8704
  status(): {
8695
8705
  pending: number;
8696
8706
  stopped?: string;
@@ -9461,7 +9461,13 @@ Executing tool: ${toolInfo}
9461
9461
  if (onError) onError(errorObj);
9462
9462
  await fireRunError({ error: errorMsg, stage: "model", errorObject: errorObj });
9463
9463
  const statusCode = err instanceof Error && "statusCode" in err ? err.statusCode : void 0;
9464
- return { data: null, error: errorMsg, statusCode };
9464
+ const connectionLost = !(err instanceof ProviderStreamError) && !(err instanceof SseError);
9465
+ return {
9466
+ data: null,
9467
+ error: errorMsg,
9468
+ statusCode,
9469
+ ...connectionLost ? { connectionLost: true } : {}
9470
+ };
9465
9471
  } finally {
9466
9472
  cleanupSignalLink();
9467
9473
  }
@@ -10140,9 +10146,23 @@ function conversationSortKey(data, createdAt) {
10140
10146
  if (pinnedAt) return PINNED_SORT_BASE + pinnedAt;
10141
10147
  return number(data.lastActivityAt) ?? createdAt;
10142
10148
  }
10149
+ var CONTEXT_FIELD_PREFIX = "context.";
10150
+ function contextField(key3) {
10151
+ return `${CONTEXT_FIELD_PREFIX}${key3}`;
10152
+ }
10153
+ function contextFields(context) {
10154
+ return plain(
10155
+ Object.fromEntries(Object.entries(context ?? {}).map(([k, value]) => [contextField(k), value]))
10156
+ );
10157
+ }
10158
+ function conversationContext(data) {
10159
+ const entries = Object.entries(data).filter(([field10]) => field10.startsWith(CONTEXT_FIELD_PREFIX)).map(([field10, value]) => [field10.slice(CONTEXT_FIELD_PREFIX.length), value]);
10160
+ return entries.length > 0 ? plain(Object.fromEntries(entries)) : void 0;
10161
+ }
10143
10162
  function toConversation(record2) {
10144
10163
  const pinnedAt = number(record2.data.pinnedAt);
10145
10164
  const projectId = text4(record2.data.projectId);
10165
+ const context = conversationContext(record2.data);
10146
10166
  return {
10147
10167
  uniqueId: record2.id,
10148
10168
  conversationId: record2.id,
@@ -10151,7 +10171,8 @@ function toConversation(record2) {
10151
10171
  createdAt: new Date(record2.createdAt),
10152
10172
  updatedAt: new Date(record2.updatedAt),
10153
10173
  isDeleted: record2.isDeleted,
10154
- pinnedAt: pinnedAt ? new Date(pinnedAt) : null
10174
+ pinnedAt: pinnedAt ? new Date(pinnedAt) : null,
10175
+ ...context ? { context } : {}
10155
10176
  };
10156
10177
  }
10157
10178
  function messageData(options) {
@@ -10310,6 +10331,7 @@ function bytes2(value) {
10310
10331
  function conversationRecord(conversation, messages) {
10311
10332
  const createdAt = ms(conversation.createdAt);
10312
10333
  const data = plain({
10334
+ ...contextFields(conversation.context),
10313
10335
  title: conversation.title,
10314
10336
  projectId: conversation.projectId || void 0,
10315
10337
  pinnedAt: conversation.pinnedAt ? ms(conversation.pinnedAt) : void 0,
@@ -13203,6 +13225,12 @@ function createVaultChatBackend(options) {
13203
13225
  async updateConversationPinned(conversationId, pinned) {
13204
13226
  return updateConversation(conversationId, { pinnedAt: pinned ? now() : null });
13205
13227
  },
13228
+ async updateConversationContext(conversationId, context) {
13229
+ const set = contextFields(context);
13230
+ if (Object.keys(set).length > 0) return updateConversation(conversationId, set);
13231
+ const record2 = await conversation(conversationId);
13232
+ return !!record2 && !record2.isDeleted;
13233
+ },
13206
13234
  async deleteConversation(conversationId) {
13207
13235
  const record2 = await conversation(conversationId);
13208
13236
  if (!record2 || record2.isDeleted) return false;