@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.
@@ -11129,7 +11129,13 @@ Executing tool: ${toolInfo}
11129
11129
  if (onError) onError(errorObj);
11130
11130
  await fireRunError({ error: errorMsg, stage: "model", errorObject: errorObj });
11131
11131
  const statusCode = err instanceof Error && "statusCode" in err ? err.statusCode : void 0;
11132
- return { data: null, error: errorMsg, statusCode };
11132
+ const connectionLost = !(err instanceof ProviderStreamError) && !(err instanceof SseError);
11133
+ return {
11134
+ data: null,
11135
+ error: errorMsg,
11136
+ statusCode,
11137
+ ...connectionLost ? { connectionLost: true } : {}
11138
+ };
11133
11139
  } finally {
11134
11140
  cleanupSignalLink();
11135
11141
  }
@@ -11809,9 +11815,23 @@ function conversationSortKey(data, createdAt) {
11809
11815
  if (pinnedAt) return PINNED_SORT_BASE + pinnedAt;
11810
11816
  return number(data.lastActivityAt) ?? createdAt;
11811
11817
  }
11818
+ var CONTEXT_FIELD_PREFIX = "context.";
11819
+ function contextField(key3) {
11820
+ return `${CONTEXT_FIELD_PREFIX}${key3}`;
11821
+ }
11822
+ function contextFields(context) {
11823
+ return plain(
11824
+ Object.fromEntries(Object.entries(context ?? {}).map(([k, value]) => [contextField(k), value]))
11825
+ );
11826
+ }
11827
+ function conversationContext(data) {
11828
+ const entries = Object.entries(data).filter(([field10]) => field10.startsWith(CONTEXT_FIELD_PREFIX)).map(([field10, value]) => [field10.slice(CONTEXT_FIELD_PREFIX.length), value]);
11829
+ return entries.length > 0 ? plain(Object.fromEntries(entries)) : void 0;
11830
+ }
11812
11831
  function toConversation(record2) {
11813
11832
  const pinnedAt = number(record2.data.pinnedAt);
11814
11833
  const projectId = text4(record2.data.projectId);
11834
+ const context = conversationContext(record2.data);
11815
11835
  return {
11816
11836
  uniqueId: record2.id,
11817
11837
  conversationId: record2.id,
@@ -11820,7 +11840,8 @@ function toConversation(record2) {
11820
11840
  createdAt: new Date(record2.createdAt),
11821
11841
  updatedAt: new Date(record2.updatedAt),
11822
11842
  isDeleted: record2.isDeleted,
11823
- pinnedAt: pinnedAt ? new Date(pinnedAt) : null
11843
+ pinnedAt: pinnedAt ? new Date(pinnedAt) : null,
11844
+ ...context ? { context } : {}
11824
11845
  };
11825
11846
  }
11826
11847
  function messageData(options) {
@@ -11979,6 +12000,7 @@ function bytes2(value) {
11979
12000
  function conversationRecord(conversation, messages) {
11980
12001
  const createdAt = ms(conversation.createdAt);
11981
12002
  const data = plain({
12003
+ ...contextFields(conversation.context),
11982
12004
  title: conversation.title,
11983
12005
  projectId: conversation.projectId || void 0,
11984
12006
  pinnedAt: conversation.pinnedAt ? ms(conversation.pinnedAt) : void 0,
@@ -14876,6 +14898,12 @@ function createVaultChatBackend(options) {
14876
14898
  async updateConversationPinned(conversationId, pinned) {
14877
14899
  return updateConversation(conversationId, { pinnedAt: pinned ? now() : null });
14878
14900
  },
14901
+ async updateConversationContext(conversationId, context) {
14902
+ const set = contextFields(context);
14903
+ if (Object.keys(set).length > 0) return updateConversation(conversationId, set);
14904
+ const record2 = await conversation(conversationId);
14905
+ return !!record2 && !record2.isDeleted;
14906
+ },
14879
14907
  async deleteConversation(conversationId) {
14880
14908
  const record2 = await conversation(conversationId);
14881
14909
  if (!record2 || record2.isDeleted) return false;
@@ -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;