js-bao-wss-client 3.5.0-alpha.0 → 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 (47) hide show
  1. package/README.md +0 -3
  2. package/dist/JsBaoClient.d.ts +95 -45
  3. package/dist/JsBaoClient.js +191 -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 +437 -0
  13. package/dist/api/agentSessionsApi.js +149 -0
  14. package/dist/api/blobBucketsApi.d.ts +4 -13
  15. package/dist/api/databasesApi.d.ts +9 -134
  16. package/dist/api/databasesApi.js +1 -84
  17. package/dist/api/documentsApi.d.ts +22 -0
  18. package/dist/api/documentsApi.js +93 -0
  19. package/dist/api/functionsApi.d.ts +49 -2
  20. package/dist/api/functionsApi.js +65 -1
  21. package/dist/api/meApi.d.ts +4 -1
  22. package/dist/browser.umd.js +15857 -14759
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +3 -0
  25. package/dist/internal/authController.d.ts +0 -25
  26. package/dist/internal/authController.js +5 -47
  27. package/dist/internal/documentManager.d.ts +62 -63
  28. package/dist/internal/documentManager.js +233 -160
  29. package/dist/internal/functionRunStatus.d.ts +67 -1
  30. package/dist/internal/functionRunStatus.js +70 -0
  31. package/dist/internal/httpClient.js +8 -0
  32. package/dist/internal/large-documents/epoch-marks.d.ts +41 -11
  33. package/dist/internal/large-documents/epoch-marks.js +35 -18
  34. package/dist/internal/offlineStore.d.ts +7 -3
  35. package/dist/internal/offlineStore.js +10 -7
  36. package/dist/internal/storage/indexedDbStorageProvider.d.ts +10 -1
  37. package/dist/internal/storage/indexedDbStorageProvider.js +63 -26
  38. package/dist/internal/storage/memoryStorageProvider.d.ts +2 -1
  39. package/dist/internal/storage/memoryStorageProvider.js +4 -5
  40. package/dist/internal/storage/mergePatch.d.ts +19 -0
  41. package/dist/internal/storage/mergePatch.js +26 -0
  42. package/dist/internal/storage/sqliteStorageProvider.d.ts +4 -0
  43. package/dist/internal/storage/sqliteStorageProvider.js +9 -4
  44. package/dist/internal/storage/types.d.ts +16 -4
  45. package/dist/internal/workflowSlice.d.ts +22 -0
  46. package/dist/internal/workflowSlice.js +13 -2
  47. 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
@@ -33,6 +33,7 @@ import { GroupTypeConfigsAPI } from "./api/groupTypeConfigsApi";
33
33
  import { CollectionTypeConfigsAPI } from "./api/collectionTypeConfigsApi";
34
34
  import { DatabaseTypeConfigsAPI } from "./api/databaseTypeConfigsApi";
35
35
  import { CollectionsAPI } from "./api/collectionsApi";
36
+ import { AgentsAPI } from "./api/agentSessionsApi";
36
37
  import { InvitationsAPI } from "./api/invitationsApi";
37
38
  import { NotificationsAPI } from "./api/notificationsApi";
38
39
  export { JsBaoError, isJsBaoError, LockTimeoutError, JsBaoApiError, isJsBaoApiError, JsBaoNetworkError, isJsBaoNetworkError, } from "./errors";
@@ -43,7 +44,7 @@ export type { DocumentInfo, DocumentPermissionEntry, DocumentAccessResult, Docum
43
44
  export type { UserProfile, SharedDocument, SharedDocumentListResult, SharedDocumentsOptions, OwnedDocumentsOptions, } from "./api/meApi";
44
45
  export type { SessionInfo } from "./api/sessionApi";
45
46
  export type { BasicUserInfo, BatchUserProfile } from "./api/usersApi";
46
- export type { DatabaseInfo, DatabasePermissionEntry, DatabaseGroupPermissionEntry, GrantDatabaseGroupPermissionParams, DatabaseOwnershipTransferResult, DatabaseOperationInfo, AddManagerParams, CsvImportOptions, CsvImportProgress, CsvImportResult, CelContextResult, ExecuteOperationOptions, DatabaseChangeEvent, DatabaseChangePayload, DatabaseSubscribeOptions, ListDatabasesOptions, DatabaseListPage, OperationType, OperationFilter, QueryDefinition, MutationOperation, MutationDefinition, CountDefinition, AggregateOperation, AggregateDefinition, PipelineStep, PipelineDefinition, ApplyToQuerySource, ApplyToQueryAction, ApplyToQueryDefinition, OperationDefinition, CreateOperationParams, UpdateOperationParams, } from "./api/databasesApi";
47
+ export type { DatabaseInfo, DatabasePermissionEntry, DatabaseGroupPermissionEntry, GrantDatabaseGroupPermissionParams, DatabaseOwnershipTransferResult, DatabaseOperationInfo, AddManagerParams, CsvImportOptions, CsvImportProgress, CsvImportResult, ExecuteOperationOptions, DatabaseChangeEvent, DatabaseChangePayload, DatabaseSubscribeOptions, ListDatabasesOptions, DatabaseListPage, OperationType, OperationFilter, QueryDefinition, MutationOperation, MutationDefinition, CountDefinition, AggregateOperation, AggregateDefinition, PipelineStep, PipelineDefinition, ApplyToQuerySource, ApplyToQueryAction, ApplyToQueryDefinition, OperationDefinition, CreateOperationParams, UpdateOperationParams, } from "./api/databasesApi";
47
48
  export type { GroupInfo, GroupMemberInfo, GroupMembershipInfo, GroupDocumentInfo, GroupDatabaseInfo, ListUserMembershipsOptions, DirectGroupAdd, DeferredGroupAdd, GroupAddMemberResult, } from "./api/groupsApi";
48
49
  export type { CollectionInfo, CollectionDocumentInfo, CollectionGroupPermissionInfo, CollectionMemberInfo, CollectionAccessInfo, DocumentCollectionInfo, AddCollectionMemberParams, DirectCollectionAdd, DeferredCollectionAdd, CollectionAddMemberResult, PendingCollectionInvitationEntry, } from "./api/collectionsApi";
49
50
  export type { RuleSetInfo, RuleSetSchema, RuleSetTestResult, RuleSetDebugResult, TraceEntry, TriggerDefInfo, ModelRulesInfo, PathDeclaration, RuleLoads, RuleExpression, CategoryRules, } from "./api/ruleSetsApi";
@@ -60,13 +61,15 @@ export type { DocumentBlobContext, BlobUploadSourceOptions, BlobUploadResult, Bl
60
61
  export type { DocumentsAPI, DocumentContext, DocumentAliasesAPI, DocumentIngestsAPI, DocumentSnapshotsAPI, } from "./api/documentsApi";
61
62
  export type { DatabasesAPI } from "./api/databasesApi";
62
63
  export type { CollectionsAPI } from "./api/collectionsApi";
64
+ export type { AgentsAPI, AgentSessionsAPI } 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";
63
66
  export type { MeAPI } from "./api/meApi";
64
67
  export type { SessionAPI } from "./api/sessionApi";
65
68
  export type { UsersAPI } from "./api/usersApi";
66
69
  export type { GroupsAPI } from "./api/groupsApi";
67
70
  export type { RuleSetsAPI } from "./api/ruleSetsApi";
68
71
  export type { NotificationsAPI, NotificationInfo, NotificationListOptions, NotificationListResult, NotificationSendResult, SendNotificationParams, PushDeviceInfo, RegisterPushDeviceParams, } from "./api/notificationsApi";
69
- export type { BlobBucketsAPI, BlobBucketInfo, BlobBucketTtlTier, BlobBucketPreset, BlobBucketAccessPolicy, CreateBlobBucketParams, UpdateBlobBucketParams, BlobInfo, BlobUploadParams, BucketBlobUploadResult, BucketBlobListResult, BlobListOptions, BlobSignedUrlResult, BatchBlobDeleteResult, } from "./api/blobBucketsApi";
72
+ export type { BlobBucketsAPI, BlobBucketInfo, BlobBucketTtlTier, BlobBucketPreset, CreateBlobBucketParams, UpdateBlobBucketParams, BlobInfo, BlobUploadParams, BucketBlobUploadResult, BucketBlobListResult, BlobListOptions, BlobSignedUrlResult, BatchBlobDeleteResult, } from "./api/blobBucketsApi";
70
73
  export type { GroupTypeConfigsAPI } from "./api/groupTypeConfigsApi";
71
74
  export type { CollectionTypeConfigsAPI } from "./api/collectionTypeConfigsApi";
72
75
  export type { DatabaseTypeConfigsAPI } from "./api/databaseTypeConfigsApi";
@@ -91,7 +94,7 @@ export type { DocumentDebugSnapshot, DocumentPermission, LocalDocumentEntry, Loc
91
94
  export type { LogLevel } from "./internal/logger";
92
95
  export type { RequestOptions } from "./internal/httpClient";
93
96
  export type { LocksAPI } from "./api/locksApi";
94
- 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";
95
98
  export type { LockHandle, LockContention, AcquireResponse, AcquireOptions, BlockingAcquireOptions, ReleaseResult, RenewResult, LockStatus, LockListEntry, LockListResult, } from "./api/locksApi";
96
99
  export type { ResourceMetadataAPI } from "./api/resourceMetadataApi";
97
100
  export type { ResourceMetadataReadResult, ResourceMetadataWriteResult, ResourceMetadataBatchRequestItem, ResourceMetadataBatchParams, ResourceMetadataBatchCategoryResult, ResourceMetadataBatchResourceResult, ResourceMetadataBatchResult, ResourceMetadataListEntry, ResourceMetadataListResult, ResourceMetadataDeleteResult, ResourceMetadataResolveParams, ResourceMetadataResolveResult, } from "./api/resourceMetadataApi";
@@ -404,12 +407,26 @@ export interface ExecutePromptResult<R = unknown> {
404
407
  */
405
408
  upstreamStatus?: number;
406
409
  /**
407
- * `"PROMPT_UPSTREAM_TIMEOUT"` when the provider itself ran out of time,
408
- * which is the one failure of the model call that carries a code. Absent on
409
- * 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
410
420
  * `errorCode` still means "the call failed for some other reason".
411
421
  */
412
- 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;
413
430
  metrics: {
414
431
  durationMs: number;
415
432
  inputTokens?: number;
@@ -1724,6 +1741,24 @@ export interface ListLocalDocumentsOptions {
1724
1741
  /** If true, only returns documents that have local data stored. */
1725
1742
  onlyWithLocalData?: boolean;
1726
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
+ }
1727
1762
  /** Options for {@link JsBaoClient.evictAllLocal}. */
1728
1763
  export interface EvictAllLocalOptions {
1729
1764
  /** If true, only evicts documents that are fully synced with the server. */
@@ -2517,6 +2552,10 @@ export declare class JsBaoClient extends Observable<any> {
2517
2552
  /** Sub-API for managing document collections.
2518
2553
  * @group Sub-APIs */
2519
2554
  collections: CollectionsAPI;
2555
+ /** Sub-API for agents: `agents.sessions` lists, reads, renames and deletes
2556
+ * agent sessions and manages their members.
2557
+ * @group Sub-APIs */
2558
+ agents: AgentsAPI;
2520
2559
  /** Sub-API for managing rule sets.
2521
2560
  * @group Sub-APIs */
2522
2561
  ruleSets: RuleSetsAPI;
@@ -2689,6 +2728,13 @@ export declare class JsBaoClient extends Observable<any> {
2689
2728
  * next user's.
2690
2729
  */
2691
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;
2692
2738
  /**
2693
2739
  * Reconcile the local metadata cache against the user's whole document
2694
2740
  * scope, evicting the documents the server no longer has (#2852).
@@ -3169,6 +3215,19 @@ export declare class JsBaoClient extends Observable<any> {
3169
3215
  * exactly as {@link format2ServerStateVectors} is.
3170
3216
  */
3171
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;
3172
3231
  /**
3173
3232
  * Documents whose adopted sequences are owed a claim that had no baseline
3174
3233
  * to build one against (finding 3431-R16).
@@ -4277,6 +4336,25 @@ export declare class JsBaoClient extends Observable<any> {
4277
4336
  * @group Documents
4278
4337
  */
4279
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>;
4280
4358
  /** Set the default document ID used by js-bao models when no explicit mapping exists.
4281
4359
  * @param documentId - The document to use as the default for all unmapped models
4282
4360
  * @group Documents */
@@ -4622,8 +4700,6 @@ export declare class JsBaoClient extends Observable<any> {
4622
4700
  * carrying both credentials.
4623
4701
  */
4624
4702
  emailSignInEnabled: boolean;
4625
- /** @deprecated Always equal to `emailSignInEnabled`. */
4626
- magicLinkEnabled: boolean;
4627
4703
  }>;
4628
4704
  /**
4629
4705
  * Request one sign-in email. It carries a 6-digit code and — when a redirect
@@ -4646,22 +4722,6 @@ export declare class JsBaoClient extends Observable<any> {
4646
4722
  }): Promise<{
4647
4723
  success: boolean;
4648
4724
  }>;
4649
- /**
4650
- * Request a magic link email for passwordless authentication.
4651
- *
4652
- * @deprecated Use {@link emailSignInRequest}. This is an alias of it — the
4653
- * server issues through the same path and sends the same email, which now
4654
- * also carries a 6-digit code.
4655
- * @param email - The email address to send the magic link to
4656
- * @param options - Optional configuration
4657
- * @param options.redirectUri - Override the default OAuth redirect URI for the magic link callback
4658
- * @group Authentication
4659
- */
4660
- magicLinkRequest(email: string, options?: {
4661
- redirectUri?: string;
4662
- }): Promise<{
4663
- success: boolean;
4664
- }>;
4665
4725
  /**
4666
4726
  * Verify a magic link token and authenticate the user.
4667
4727
  * @param token - The magic link token from the email URL
@@ -4682,18 +4742,6 @@ export declare class JsBaoClient extends Observable<any> {
4682
4742
  promptAddPasskey?: boolean;
4683
4743
  isNewUser?: boolean;
4684
4744
  }>;
4685
- /**
4686
- * Request a one-time password (OTP) code to be sent to the specified email.
4687
- * The code can be verified using `otpVerify()`.
4688
- *
4689
- * @deprecated Use {@link emailSignInRequest}. This is an alias of it that
4690
- * carries no redirect target, so the email it sends is code-only.
4691
- * @param email - The email address to send the OTP code to
4692
- * @group Authentication
4693
- */
4694
- otpRequest(email: string): Promise<{
4695
- success: boolean;
4696
- }>;
4697
4745
  /**
4698
4746
  * Verify a one-time password (OTP) code and authenticate the user.
4699
4747
  * On success, the client will be authenticated and connected.
@@ -4842,10 +4890,6 @@ export declare class JsBaoClient extends Observable<any> {
4842
4890
  * availability to report.
4843
4891
  */
4844
4892
  emailSignInEnabled: boolean;
4845
- /** @deprecated (#2884) Always equal to `emailSignInEnabled`. */
4846
- magicLinkEnabled: boolean;
4847
- /** @deprecated (#2884) Always equal to `emailSignInEnabled`. */
4848
- otpEnabled: boolean;
4849
4893
  hasApple: boolean;
4850
4894
  appleSignInEnabled: boolean;
4851
4895
  }>;
@@ -4928,14 +4972,20 @@ export declare class JsBaoClient extends Observable<any> {
4928
4972
  * epoch lock. An ordinary document on a hydrated session still pays nothing.
4929
4973
  */
4930
4974
  private _persistedNamingReader;
4931
- private _putMetadataToIdb;
4932
4975
  /**
4933
4976
  * Persist a DELTA of one document's metadata row (#3746) — the fields named
4934
- * and nothing else, merged into whatever is stored. What the document-open
4935
- * path writes with, so opening one document in one tab cannot regress a field
4936
- * 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.
4937
4985
  */
4938
4986
  private _mergeMetadataToIdb;
4987
+ /** The merge hook alone, for the client's own direct metadata writes. */
4988
+ private metadataMergeContext;
4939
4989
  private _deleteMetadataFromIdb;
4940
4990
  private _enforceRetentionPolicy;
4941
4991
  /** Get the current network status including connectivity and transport state.