js-bao-wss-client 3.5.0-alpha.1 → 3.5.0-alpha.2

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.
Files changed (44) hide show
  1. package/README.md +0 -3
  2. package/dist/JsBaoClient.d.ts +87 -44
  3. package/dist/JsBaoClient.js +189 -97
  4. package/dist/agents/sessionModelRuntime.d.ts +3 -2
  5. package/dist/agents/sessionModelRuntime.js +3 -2
  6. package/dist/agents/sessionModels.generated.d.ts +10 -1
  7. package/dist/agents/sessionModels.generated.js +17 -2
  8. package/dist/agents/sessionView.d.ts +257 -0
  9. package/dist/agents/sessionView.js +562 -0
  10. package/dist/agents/uiMessages.d.ts +19 -2
  11. package/dist/agents/uiMessages.js +5 -2
  12. package/dist/api/agentSessionsApi.d.ts +292 -7
  13. package/dist/api/agentSessionsApi.js +61 -3
  14. package/dist/api/documentsApi.d.ts +22 -0
  15. package/dist/api/documentsApi.js +93 -0
  16. package/dist/api/functionsApi.d.ts +49 -2
  17. package/dist/api/functionsApi.js +65 -1
  18. package/dist/api/meApi.d.ts +4 -1
  19. package/dist/browser.umd.js +15854 -14765
  20. package/dist/index.d.ts +2 -0
  21. package/dist/index.js +3 -0
  22. package/dist/internal/authController.d.ts +0 -25
  23. package/dist/internal/authController.js +5 -47
  24. package/dist/internal/documentManager.d.ts +62 -63
  25. package/dist/internal/documentManager.js +233 -160
  26. package/dist/internal/functionRunStatus.d.ts +67 -1
  27. package/dist/internal/functionRunStatus.js +70 -0
  28. package/dist/internal/httpClient.js +8 -0
  29. package/dist/internal/large-documents/epoch-marks.d.ts +41 -11
  30. package/dist/internal/large-documents/epoch-marks.js +35 -18
  31. package/dist/internal/offlineStore.d.ts +7 -3
  32. package/dist/internal/offlineStore.js +10 -7
  33. package/dist/internal/storage/indexedDbStorageProvider.d.ts +10 -1
  34. package/dist/internal/storage/indexedDbStorageProvider.js +63 -26
  35. package/dist/internal/storage/memoryStorageProvider.d.ts +2 -1
  36. package/dist/internal/storage/memoryStorageProvider.js +4 -5
  37. package/dist/internal/storage/mergePatch.d.ts +19 -0
  38. package/dist/internal/storage/mergePatch.js +26 -0
  39. package/dist/internal/storage/sqliteStorageProvider.d.ts +4 -0
  40. package/dist/internal/storage/sqliteStorageProvider.js +9 -4
  41. package/dist/internal/storage/types.d.ts +16 -4
  42. package/dist/internal/workflowSlice.d.ts +22 -0
  43. package/dist/internal/workflowSlice.js +13 -2
  44. package/package.json +2 -2
package/README.md CHANGED
@@ -1028,9 +1028,6 @@ await client.emailSignInRequest("user@example.com", {
1028
1028
  Both credentials expire together, 15 minutes after the request. Rate limits
1029
1029
  apply (5 requests per email per hour, 20 per IP per hour).
1030
1030
 
1031
- `magicLinkRequest` and `otpRequest` still work and are **deprecated**: both are
1032
- aliases of the same issuance path and send the same email.
1033
-
1034
1031
  ### Finish with the code
1035
1032
 
1036
1033
  ```typescript
@@ -62,7 +62,7 @@ export type { DocumentsAPI, DocumentContext, DocumentAliasesAPI, DocumentIngests
62
62
  export type { DatabasesAPI } from "./api/databasesApi";
63
63
  export type { CollectionsAPI } from "./api/collectionsApi";
64
64
  export type { AgentsAPI, AgentSessionsAPI } from "./api/agentSessionsApi";
65
- export type { AgentSessionMemberRole, AgentSessionMembers, AgentSessionInfo, AgentSessionListItem, ListAgentSessionsOptions, AgentSessionRenameResult, AgentSessionDeleteResult, AgentSessionMembersResult, } from "./api/agentSessionsApi";
65
+ export type { AgentSessionMemberRole, AgentSessionMembers, AgentSessionInfo, AgentSessionListItem, ListAgentSessionsOptions, AgentSessionRenameResult, AgentSessionDeleteResult, AgentSessionMembersResult, AgentSessionStatus, AgentTurnPause, AgentSessionTurnSummary, AgentSessionInspectedTurn, AgentSessionInspectedCall, AgentSessionObjectState, AgentSessionSendBody, AgentSessionSendResult, AgentCallAnswer, AgentCallAnswerResult, AgentSessionCancelResult, AgentSessionEvent, AgentSessionEventResult, } from "./api/agentSessionsApi";
66
66
  export type { MeAPI } from "./api/meApi";
67
67
  export type { SessionAPI } from "./api/sessionApi";
68
68
  export type { UsersAPI } from "./api/usersApi";
@@ -94,7 +94,7 @@ export type { DocumentDebugSnapshot, DocumentPermission, LocalDocumentEntry, Loc
94
94
  export type { LogLevel } from "./internal/logger";
95
95
  export type { RequestOptions } from "./internal/httpClient";
96
96
  export type { LocksAPI } from "./api/locksApi";
97
- export type { FunctionsAPI, FunctionInvokeOptions, FunctionInvokeResult, FunctionInvokeStatus, FunctionInvokeLimits, FunctionStartOptions, FunctionStartResult, FunctionRunRef, FunctionRun, FunctionRunError, FunctionRunErrorCode, FunctionRunSettled, FunctionRunSlice, FunctionRunStatus, FunctionRunStatusValue, FunctionRunTerminalStatus, FunctionWaitOptions, } from "./api/functionsApi";
97
+ export type { FunctionsAPI, FunctionInvokeOptions, FunctionInvokeResult, FunctionInvokeStatus, FunctionInvokeLimits, FunctionStartOptions, FunctionStartResult, FunctionRunRef, FunctionRun, FunctionRunError, FunctionRunErrorCode, FunctionRunSettled, FunctionRunSlice, FunctionRunStatus, FunctionRunStatusValue, FunctionRunTerminalStatus, FunctionWaitOptions, FunctionRunListOptions, FunctionRunPage, FunctionStepRun, FunctionRunSteps, } from "./api/functionsApi";
98
98
  export type { LockHandle, LockContention, AcquireResponse, AcquireOptions, BlockingAcquireOptions, ReleaseResult, RenewResult, LockStatus, LockListEntry, LockListResult, } from "./api/locksApi";
99
99
  export type { ResourceMetadataAPI } from "./api/resourceMetadataApi";
100
100
  export type { ResourceMetadataReadResult, ResourceMetadataWriteResult, ResourceMetadataBatchRequestItem, ResourceMetadataBatchParams, ResourceMetadataBatchCategoryResult, ResourceMetadataBatchResourceResult, ResourceMetadataBatchResult, ResourceMetadataListEntry, ResourceMetadataListResult, ResourceMetadataDeleteResult, ResourceMetadataResolveParams, ResourceMetadataResolveResult, } from "./api/resourceMetadataApi";
@@ -407,12 +407,26 @@ export interface ExecutePromptResult<R = unknown> {
407
407
  */
408
408
  upstreamStatus?: number;
409
409
  /**
410
- * `"PROMPT_UPSTREAM_TIMEOUT"` when the provider itself ran out of time,
411
- * which is the one failure of the model call that carries a code. Absent on
412
- * success and on every other provider failure, so `error` with no
410
+ * `"PROMPT_UPSTREAM_TIMEOUT"` when the provider itself ran out of time;
411
+ * `"PROMPT_UPSTREAM_REJECTED"` when the provider refused the request as
412
+ * invalid (`upstreamStatus` 400) — a setting the model does not support,
413
+ * such as a reasoning level, with the provider's message in `error`; fix
414
+ * the configuration rather than retrying;
415
+ * `"PROMPT_STRICT_OUTPUT_SCHEMA_MISSING"` when a strict-output config's
416
+ * prompt has no usable `outputSchema`, refused before the provider call; and
417
+ * `"PROMPT_OUTPUT_TRUNCATED"` when the completion came back empty because
418
+ * it spent the whole output token limit (`truncated` is `true` beside it).
419
+ * Absent on success and on every other provider failure, so `error` with no
413
420
  * `errorCode` still means "the call failed for some other reason".
414
421
  */
415
- errorCode?: "PROMPT_UPSTREAM_TIMEOUT";
422
+ errorCode?: "PROMPT_UPSTREAM_TIMEOUT" | "PROMPT_STRICT_OUTPUT_SCHEMA_MISSING" | "PROMPT_OUTPUT_TRUNCATED" | "PROMPT_UPSTREAM_REJECTED";
423
+ /**
424
+ * `true` when the provider stopped at the output token limit (the config's
425
+ * `maxTokens`) before the answer was finished; absent otherwise. A cut-off
426
+ * answer is still `success: true`, with the partial text in `output`. On
427
+ * Gemini, reasoning tokens count against the same limit. Raise `maxTokens`.
428
+ */
429
+ truncated?: true;
416
430
  metrics: {
417
431
  durationMs: number;
418
432
  inputTokens?: number;
@@ -1727,6 +1741,24 @@ export interface ListLocalDocumentsOptions {
1727
1741
  /** If true, only returns documents that have local data stored. */
1728
1742
  onlyWithLocalData?: boolean;
1729
1743
  }
1744
+ /** What {@link JsBaoClient.getLargeDocumentStorage} reports. */
1745
+ export interface LargeDocumentStorageInfo {
1746
+ /** Whether there is durable local storage to keep a large document in. */
1747
+ persistent: boolean;
1748
+ /** Bytes this origin may keep, or `null` when the platform will not say. */
1749
+ quotaBytes: number | null;
1750
+ /** Bytes the origin already holds, other documents included. */
1751
+ usedBytes?: number;
1752
+ /**
1753
+ * Whether the browser keeps that storage when it is short of space, as it
1754
+ * answered the client's request: `persisted` (already was), `granted`,
1755
+ * `declined` or `unsupported` (no API to ask). Absent until the `opfs`
1756
+ * engine has opened a large document, which is when it asks. On `declined`
1757
+ * and `unsupported` the local copy, unsynced writes included, is
1758
+ * best-effort.
1759
+ */
1760
+ persistence?: "persisted" | "granted" | "declined" | "unsupported";
1761
+ }
1730
1762
  /** Options for {@link JsBaoClient.evictAllLocal}. */
1731
1763
  export interface EvictAllLocalOptions {
1732
1764
  /** If true, only evicts documents that are fully synced with the server. */
@@ -2696,6 +2728,13 @@ export declare class JsBaoClient extends Observable<any> {
2696
2728
  * next user's.
2697
2729
  */
2698
2730
  private scopeReconcileGeneration;
2731
+ /**
2732
+ * Bumped whenever the signed-in user changes, logout included. A metadata
2733
+ * answer fetched under one generation is about that user's documents: once
2734
+ * the generation has moved on, it is dropped rather than merged into the
2735
+ * cache the next user reads (#4150).
2736
+ */
2737
+ private metadataSessionGeneration;
2699
2738
  /**
2700
2739
  * Reconcile the local metadata cache against the user's whole document
2701
2740
  * scope, evicting the documents the server no longer has (#2852).
@@ -3176,6 +3215,19 @@ export declare class JsBaoClient extends Observable<any> {
3176
3215
  * exactly as {@link format2ServerStateVectors} is.
3177
3216
  */
3178
3217
  private readonly format2HandshakeStateVectors;
3218
+ /**
3219
+ * Documents whose epoch move still owes the sync of its fresh overlay
3220
+ * (#4194, finding 4194-R3).
3221
+ *
3222
+ * A move carries the unacknowledged writes into the fresh overlay before its
3223
+ * update listener is attached, so the sync that follows is the only thing
3224
+ * that sends them. When a handshake is still in flight, `sendSyncStep1`
3225
+ * returns without starting one, and that handshake's `syncComplete` would
3226
+ * close the document's cycle with the carried writes never sent. The debt is
3227
+ * recorded here, settled by the next cycle that actually starts, and claimed
3228
+ * by the in-flight handshake's `syncComplete` when none has.
3229
+ */
3230
+ private readonly format2OwedMoveSyncs;
3179
3231
  /**
3180
3232
  * Documents whose adopted sequences are owed a claim that had no baseline
3181
3233
  * to build one against (finding 3431-R16).
@@ -4284,6 +4336,25 @@ export declare class JsBaoClient extends Observable<any> {
4284
4336
  * @group Documents
4285
4337
  */
4286
4338
  registerModel(model: TypedModelConstructor<any> | any): Promise<void>;
4339
+ /**
4340
+ * What this device can hold a large document in, and whether the browser
4341
+ * keeps it.
4342
+ *
4343
+ * The capability is the one a large document's load decides on —
4344
+ * `largeDocumentStorage.capability` when configured, what the platform
4345
+ * reports otherwise. With the `opfs` engine, the client asks the browser for
4346
+ * persistent storage when it first opens a large document, and
4347
+ * `persistence` carries the answer.
4348
+ *
4349
+ * ```ts
4350
+ * const { persistence } = await client.getLargeDocumentStorage();
4351
+ * if (persistence === "declined") showSyncReminder();
4352
+ * ```
4353
+ *
4354
+ * @throws If the client is destroyed or its js-bao runtime failed to start
4355
+ * @group Offline & Sync
4356
+ */
4357
+ getLargeDocumentStorage(): Promise<LargeDocumentStorageInfo>;
4287
4358
  /** Set the default document ID used by js-bao models when no explicit mapping exists.
4288
4359
  * @param documentId - The document to use as the default for all unmapped models
4289
4360
  * @group Documents */
@@ -4629,8 +4700,6 @@ export declare class JsBaoClient extends Observable<any> {
4629
4700
  * carrying both credentials.
4630
4701
  */
4631
4702
  emailSignInEnabled: boolean;
4632
- /** @deprecated Always equal to `emailSignInEnabled`. */
4633
- magicLinkEnabled: boolean;
4634
4703
  }>;
4635
4704
  /**
4636
4705
  * Request one sign-in email. It carries a 6-digit code and — when a redirect
@@ -4653,22 +4722,6 @@ export declare class JsBaoClient extends Observable<any> {
4653
4722
  }): Promise<{
4654
4723
  success: boolean;
4655
4724
  }>;
4656
- /**
4657
- * Request a magic link email for passwordless authentication.
4658
- *
4659
- * @deprecated Use {@link emailSignInRequest}. This is an alias of it — the
4660
- * server issues through the same path and sends the same email, which now
4661
- * also carries a 6-digit code.
4662
- * @param email - The email address to send the magic link to
4663
- * @param options - Optional configuration
4664
- * @param options.redirectUri - Override the default OAuth redirect URI for the magic link callback
4665
- * @group Authentication
4666
- */
4667
- magicLinkRequest(email: string, options?: {
4668
- redirectUri?: string;
4669
- }): Promise<{
4670
- success: boolean;
4671
- }>;
4672
4725
  /**
4673
4726
  * Verify a magic link token and authenticate the user.
4674
4727
  * @param token - The magic link token from the email URL
@@ -4689,18 +4742,6 @@ export declare class JsBaoClient extends Observable<any> {
4689
4742
  promptAddPasskey?: boolean;
4690
4743
  isNewUser?: boolean;
4691
4744
  }>;
4692
- /**
4693
- * Request a one-time password (OTP) code to be sent to the specified email.
4694
- * The code can be verified using `otpVerify()`.
4695
- *
4696
- * @deprecated Use {@link emailSignInRequest}. This is an alias of it that
4697
- * carries no redirect target, so the email it sends is code-only.
4698
- * @param email - The email address to send the OTP code to
4699
- * @group Authentication
4700
- */
4701
- otpRequest(email: string): Promise<{
4702
- success: boolean;
4703
- }>;
4704
4745
  /**
4705
4746
  * Verify a one-time password (OTP) code and authenticate the user.
4706
4747
  * On success, the client will be authenticated and connected.
@@ -4849,10 +4890,6 @@ export declare class JsBaoClient extends Observable<any> {
4849
4890
  * availability to report.
4850
4891
  */
4851
4892
  emailSignInEnabled: boolean;
4852
- /** @deprecated (#2884) Always equal to `emailSignInEnabled`. */
4853
- magicLinkEnabled: boolean;
4854
- /** @deprecated (#2884) Always equal to `emailSignInEnabled`. */
4855
- otpEnabled: boolean;
4856
4893
  hasApple: boolean;
4857
4894
  appleSignInEnabled: boolean;
4858
4895
  }>;
@@ -4935,14 +4972,20 @@ export declare class JsBaoClient extends Observable<any> {
4935
4972
  * epoch lock. An ordinary document on a hydrated session still pays nothing.
4936
4973
  */
4937
4974
  private _persistedNamingReader;
4938
- private _putMetadataToIdb;
4939
4975
  /**
4940
4976
  * Persist a DELTA of one document's metadata row (#3746) — the fields named
4941
- * and nothing else, merged into whatever is stored. What the document-open
4942
- * path writes with, so opening one document in one tab cannot regress a field
4943
- * another tab's rotation or a listing wrote.
4977
+ * and nothing else, merged into whatever is stored, a field named
4978
+ * `undefined` removed. Every metadata write the client makes goes through
4979
+ * here since #3779, so no write from one tab can regress a field another
4980
+ * tab's rotation or a listing wrote.
4981
+ *
4982
+ * A failure is NOT caught here: it rejects through to
4983
+ * `DocumentManager.safeMetadataMerge`, the one place that counts and
4984
+ * escalates metadata write failures.
4944
4985
  */
4945
4986
  private _mergeMetadataToIdb;
4987
+ /** The merge hook alone, for the client's own direct metadata writes. */
4988
+ private metadataMergeContext;
4946
4989
  private _deleteMetadataFromIdb;
4947
4990
  private _enforceRetentionPolicy;
4948
4991
  /** Get the current network status including connectivity and transport state.