@liveblocks/core 2.16.0-toolbars5 → 2.16.1-ai

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.
package/dist/index.d.mts CHANGED
@@ -5,18 +5,72 @@
5
5
  declare function detectDupes(pkgName: string, pkgVersion: string | false, // false if not built yet
6
6
  pkgFormat: string | false): void;
7
7
 
8
- type CustomAuthenticationResult = {
8
+ /**
9
+ * This helper type is effectively a no-op, but will force TypeScript to
10
+ * "evaluate" any named helper types in its definition. This can sometimes make
11
+ * API signatures clearer in IDEs.
12
+ *
13
+ * For example, in:
14
+ *
15
+ * type Payload<T> = { data: T };
16
+ *
17
+ * let r1: Payload<string>;
18
+ * let r2: Resolve<Payload<string>>;
19
+ *
20
+ * The inferred type of `r1` is going to be `Payload<string>` which shows up in
21
+ * editor hints, and it may be unclear what's inside if you don't know the
22
+ * definition of `Payload`.
23
+ *
24
+ * The inferred type of `r2` is going to be `{ data: string }`, which may be
25
+ * more helpful.
26
+ *
27
+ * This trick comes from:
28
+ * https://effectivetypescript.com/2022/02/25/gentips-4-display/
29
+ */
30
+ type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
31
+ [K in keyof T]: T[K];
32
+ };
33
+
34
+ /**
35
+ * Relaxes a discriminated union type definition, by explicitly adding
36
+ * properties defined in any other member as 'never'.
37
+ *
38
+ * This makes accessing the members much more relaxed in TypeScript.
39
+ *
40
+ * For example:
41
+ * type MyUnion = Relax<
42
+ * | { foo: string }
43
+ * | { foo: number; bar: string; }
44
+ * | { qux: boolean }
45
+ * >;
46
+ *
47
+ * // With Relax, accessing is much easier:
48
+ * union.foo; // string | number | undefined
49
+ * union.bar; // string | undefined
50
+ * union.qux; // boolean
51
+ * union.whatever; // Error: Property 'whatever' does not exist on type 'MyUnion'
52
+ *
53
+ * // Without Relax, these would all be type errors:
54
+ * union.foo; // Error: Property 'foo' does not exist on type 'MyUnion'
55
+ * union.bar; // Error: Property 'bar' does not exist on type 'MyUnion'
56
+ * union.qux; // Error: Property 'qux' does not exist on type 'MyUnion'
57
+ */
58
+ type Relax<T> = DistributiveRelax<T, T extends any ? keyof T : never>;
59
+ type DistributiveRelax<T, Ks extends string | number | symbol> = T extends any ? Resolve<{
60
+ [K in keyof T]: T[K];
61
+ } & {
62
+ [K in Exclude<Ks, keyof T>]?: never;
63
+ }> : never;
64
+
65
+ type CustomAuthenticationResult = Relax<{
9
66
  token: string;
10
- error?: never;
11
67
  } | {
12
- token?: never;
13
68
  error: "forbidden";
14
69
  reason: string;
15
70
  } | {
16
- token?: never;
17
71
  error: string;
18
72
  reason: string;
19
- };
73
+ }>;
20
74
 
21
75
  /**
22
76
  * Represents an indefinitely deep arbitrary JSON data structure. There are
@@ -919,22 +973,18 @@ type CommentData = {
919
973
  editedAt?: Date;
920
974
  reactions: CommentReaction[];
921
975
  attachments: CommentAttachment[];
922
- } & ({
976
+ } & Relax<{
923
977
  body: CommentBody;
924
- deletedAt?: never;
925
978
  } | {
926
- body?: never;
927
979
  deletedAt: Date;
928
- });
980
+ }>;
929
981
  type CommentDataPlain = Omit<DateToString<CommentData>, "reactions" | "body"> & {
930
982
  reactions: DateToString<CommentReaction>[];
931
- } & ({
983
+ } & Relax<{
932
984
  body: CommentBody;
933
- deletedAt?: never;
934
985
  } | {
935
- body?: never;
936
986
  deletedAt: string;
937
- });
987
+ }>;
938
988
  type CommentBodyBlockElement = CommentBodyParagraph;
939
989
  type CommentBodyInlineElement = CommentBodyText | CommentBodyMention | CommentBodyLink;
940
990
  type CommentBodyElement = CommentBodyBlockElement | CommentBodyInlineElement;
@@ -1131,11 +1181,13 @@ type FetchYDocClientMsg = {
1131
1181
  readonly type: ClientMsgCode.FETCH_YDOC;
1132
1182
  readonly vector: string;
1133
1183
  readonly guid?: string;
1184
+ readonly v2?: boolean;
1134
1185
  };
1135
1186
  type UpdateYDocClientMsg = {
1136
1187
  readonly type: ClientMsgCode.UPDATE_YDOC;
1137
1188
  readonly update: string;
1138
1189
  readonly guid?: string;
1190
+ readonly v2?: boolean;
1139
1191
  };
1140
1192
 
1141
1193
  type IdTuple<T> = [id: string, value: T];
@@ -1338,6 +1390,7 @@ type YDocUpdateServerMsg = {
1338
1390
  readonly isSync: boolean;
1339
1391
  readonly stateVector: string | null;
1340
1392
  readonly guid?: string;
1393
+ readonly v2?: boolean;
1341
1394
  };
1342
1395
  /**
1343
1396
  * Sent by the WebSocket server and broadcasted to all clients to announce that
@@ -1469,32 +1522,6 @@ declare namespace DevToolsTreeNode {
1469
1522
  export type { DevToolsTreeNode_CustomEventTreeNode as CustomEventTreeNode, DevToolsTreeNode_JsonTreeNode as JsonTreeNode, DevToolsTreeNode_LiveTreeNode as LiveTreeNode, DevToolsTreeNode_LsonTreeNode as LsonTreeNode, DevToolsTreeNode_TreeNode as TreeNode, DevToolsTreeNode_UserTreeNode as UserTreeNode };
1470
1523
  }
1471
1524
 
1472
- /**
1473
- * This helper type is effectively a no-op, but will force TypeScript to
1474
- * "evaluate" any named helper types in its definition. This can sometimes make
1475
- * API signatures clearer in IDEs.
1476
- *
1477
- * For example, in:
1478
- *
1479
- * type Payload<T> = { data: T };
1480
- *
1481
- * let r1: Payload<string>;
1482
- * let r2: Resolve<Payload<string>>;
1483
- *
1484
- * The inferred type of `r1` is going to be `Payload<string>` which shows up in
1485
- * editor hints, and it may be unclear what's inside if you don't know the
1486
- * definition of `Payload`.
1487
- *
1488
- * The inferred type of `r2` is going to be `{ data: string }`, which may be
1489
- * more helpful.
1490
- *
1491
- * This trick comes from:
1492
- * https://effectivetypescript.com/2022/02/25/gentips-4-display/
1493
- */
1494
- type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
1495
- [K in keyof T]: T[K];
1496
- };
1497
-
1498
1525
  /**
1499
1526
  * Represents a user connected in a room. Treated as immutable.
1500
1527
  */
@@ -1527,7 +1554,7 @@ type User<P extends JsonObject = DP, U extends BaseUserMeta = DU> = {
1527
1554
  readonly canComment: boolean;
1528
1555
  };
1529
1556
 
1530
- type InternalOthersEvent<P extends JsonObject, U extends BaseUserMeta> = {
1557
+ type InternalOthersEvent<P extends JsonObject, U extends BaseUserMeta> = Relax<{
1531
1558
  type: "leave";
1532
1559
  user: User<P, U>;
1533
1560
  } | {
@@ -1539,8 +1566,7 @@ type InternalOthersEvent<P extends JsonObject, U extends BaseUserMeta> = {
1539
1566
  updates: Partial<P>;
1540
1567
  } | {
1541
1568
  type: "reset";
1542
- user?: never;
1543
- };
1569
+ }>;
1544
1570
  type OthersEvent<P extends JsonObject = DP, U extends BaseUserMeta = DU> = Resolve<InternalOthersEvent<P, U> & {
1545
1571
  others: readonly User<P, U>[];
1546
1572
  }>;
@@ -1909,11 +1935,11 @@ type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUs
1909
1935
  *
1910
1936
  * @param {string} data the doc update to send to the server, base64 encoded uint8array
1911
1937
  */
1912
- updateYDoc(data: string, guid?: string): void;
1938
+ updateYDoc(data: string, guid?: string, isV2?: boolean): void;
1913
1939
  /**
1914
1940
  * Sends a request for the current document from liveblocks server
1915
1941
  */
1916
- fetchYDoc(stateVector: string, guid?: string): void;
1942
+ fetchYDoc(stateVector: string, guid?: string, isV2?: boolean): void;
1917
1943
  /**
1918
1944
  * Broadcasts an event to other users in the room. Event broadcasted to the room can be listened with {@link Room.subscribe}("event").
1919
1945
  * @param {any} event the event to broadcast. Should be serializable to JSON
@@ -2310,6 +2336,12 @@ type PrivateRoomApi = {
2310
2336
  }>;
2311
2337
  getTextVersion(versionId: string): Promise<Response>;
2312
2338
  createTextVersion(): Promise<void>;
2339
+ executeContextualPrompt(options: {
2340
+ prompt: string;
2341
+ selectionText: string;
2342
+ context: string;
2343
+ signal: AbortSignal;
2344
+ }): Promise<string>;
2313
2345
  simulate: {
2314
2346
  explicitClose(event: IWebSocketCloseEvent): void;
2315
2347
  rawSend(data: string): void;
@@ -2523,6 +2555,13 @@ interface RoomHttpApi<M extends BaseMetadata> {
2523
2555
  nonce: string | undefined;
2524
2556
  messages: ClientMsg<P, E>[];
2525
2557
  }): Promise<Response>;
2558
+ executeContextualPrompt({ roomId, selectionText, context, }: {
2559
+ roomId: string;
2560
+ prompt: string;
2561
+ selectionText: string;
2562
+ context: string;
2563
+ signal: AbortSignal;
2564
+ }): Promise<string>;
2526
2565
  }
2527
2566
  interface NotificationHttpApi<M extends BaseMetadata> {
2528
2567
  getInboxNotifications(options?: {
@@ -2977,13 +3016,11 @@ type ClientOptions<U extends BaseUserMeta = DU> = {
2977
3016
  * the server yet.
2978
3017
  */
2979
3018
  preventUnsavedChanges?: boolean;
2980
- } & ({
3019
+ } & Relax<{
2981
3020
  publicApiKey: string;
2982
- authEndpoint?: never;
2983
3021
  } | {
2984
- publicApiKey?: never;
2985
3022
  authEndpoint: AuthEndpoint;
2986
- });
3023
+ }>;
2987
3024
  /**
2988
3025
  * Create a client that will be responsible to communicate with liveblocks servers.
2989
3026
  *
@@ -3751,4 +3788,4 @@ declare const CommentsApiError: typeof HttpError;
3751
3788
  /** @deprecated Use HttpError instead. */
3752
3789
  declare const NotificationsApiError: typeof HttpError;
3753
3790
 
3754
- export { type AckOp, type ActivityData, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type BaseActivitiesData, type BaseAuthResult, type BaseMetadata, type BaseRoomInfo, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type Client, type ClientMsg, ClientMsgCode, type ClientOptions, type CommentAttachment, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentLocalAttachment, type CommentMixedAttachment, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, CommentsApiError, type CommentsEventServerMsg, CrdtType, type CreateListOp, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type CustomAuthenticationResult, type DAD, type DE, type DM, type DP, type DRI, type DS, type DU, DefaultMap, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, DerivedSignal, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, type DistributiveOmit, type EnsureJson, type EnterOptions, type EventSource, type FetchStorageClientMsg, type FetchYDocClientMsg, type GetThreadsOptions, type History, type HistoryVersion, HttpError, type ISignal, type IUserInfo, type IWebSocket, type IWebSocketCloseEvent, type IWebSocketEvent, type IWebSocketInstance, type IWebSocketMessageEvent, type IYjsProvider, type IdTuple, type Immutable, type InboxNotificationCustomData, type InboxNotificationCustomDataPlain, type InboxNotificationData, type InboxNotificationDataPlain, type InboxNotificationDeleteInfo, type InboxNotificationTextMentionData, type InboxNotificationTextMentionDataPlain, type InboxNotificationThreadData, type InboxNotificationThreadDataPlain, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type KDAD, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, LiveblocksError, type LostConnectionEvent, type Lson, type LsonObject, MutableSignal, type NoInfr, type NodeMap, NotificationsApiError, type Observable, type Op, OpCode, type OpaqueClient, type OpaqueRoom, type OptionalPromise, type OptionalTupleUnless, type OthersEvent, type ParentToChildNodeMap, type PartialUnless, type Patchable, Permission, type PlainLson, type PlainLsonFields, type PlainLsonList, type PlainLsonMap, type PlainLsonObject, type Poller, type PrivateClientApi, type PrivateRoomApi, Promise_withResolvers, type QueryMetadata, type QueryParams, type RejectedStorageOpServerMsg, type Resolve, type ResolveMentionSuggestionsArgs, type ResolveRoomsInfoArgs, type ResolveUsersArgs, type Room, type RoomEventMessage, type RoomNotificationSettings, type RoomStateServerMsg, type SerializedChild, type SerializedCrdt, type SerializedList, type SerializedMap, type SerializedObject, type SerializedRegister, type SerializedRootObject, type ServerMsg, ServerMsgCode, type SetParentKeyOp, Signal, type SignalType, SortedList, type Status, type StorageStatus, type StorageUpdate, type StringifyCommentBodyElements, type StringifyCommentBodyOptions, type SyncSource, type SyncStatus, TextEditorType, type ThreadData, type ThreadDataPlain, type ThreadDataWithDeleteInfo, type ThreadDeleteInfo, type ToImmutable, type ToJson, type URLSafeString, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type UploadAttachmentOptions, type User, type UserJoinServerMsg, type UserLeftServerMsg, WebsocketCloseCodes, type YDocUpdateServerMsg, type YjsSyncStatus, ackOp, asPos, assert, assertNever, autoRetry, b64decode, batch, chunk, cloneLson, compactObject, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToInboxNotificationData, convertToThreadData, createClient, createCommentAttachmentId, createCommentId, createInboxNotificationId, createThreadId, deprecate, deprecateIf, detectDupes, errorIf, freeze, generateCommentUrl, getMentionedIdsFromCommentBody, html, htmlSafe, isChildCrdt, isCommentBodyLink, isCommentBodyMention, isCommentBodyText, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, isStartsWithOperator, kInternal, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, mapValues, memoizeOnSuccess, nanoid, nn, objectToQuery, patchLiveObjectKey, raise, resolveUsersInCommentBody, shallow, stringify, stringifyCommentBody, throwUsageError, toAbsoluteUrl, toPlainLson, tryParseJson, unstringify, url, urljoin, wait, withTimeout };
3791
+ export { type AckOp, type ActivityData, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type BaseActivitiesData, type BaseAuthResult, type BaseMetadata, type BaseRoomInfo, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type Client, type ClientMsg, ClientMsgCode, type ClientOptions, type CommentAttachment, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentLocalAttachment, type CommentMixedAttachment, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, CommentsApiError, type CommentsEventServerMsg, CrdtType, type CreateListOp, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type CustomAuthenticationResult, type DAD, type DE, type DM, type DP, type DRI, type DS, type DU, DefaultMap, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, DerivedSignal, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, type DistributiveOmit, type EnsureJson, type EnterOptions, type EventSource, type FetchStorageClientMsg, type FetchYDocClientMsg, type GetThreadsOptions, type History, type HistoryVersion, HttpError, type ISignal, type IUserInfo, type IWebSocket, type IWebSocketCloseEvent, type IWebSocketEvent, type IWebSocketInstance, type IWebSocketMessageEvent, type IYjsProvider, type IdTuple, type Immutable, type InboxNotificationCustomData, type InboxNotificationCustomDataPlain, type InboxNotificationData, type InboxNotificationDataPlain, type InboxNotificationDeleteInfo, type InboxNotificationTextMentionData, type InboxNotificationTextMentionDataPlain, type InboxNotificationThreadData, type InboxNotificationThreadDataPlain, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type KDAD, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, LiveblocksError, type LostConnectionEvent, type Lson, type LsonObject, MutableSignal, type NoInfr, type NodeMap, NotificationsApiError, type Observable, type Op, OpCode, type OpaqueClient, type OpaqueRoom, type OptionalPromise, type OptionalTupleUnless, type OthersEvent, type ParentToChildNodeMap, type PartialUnless, type Patchable, Permission, type PlainLson, type PlainLsonFields, type PlainLsonList, type PlainLsonMap, type PlainLsonObject, type Poller, type PrivateClientApi, type PrivateRoomApi, Promise_withResolvers, type QueryMetadata, type QueryParams, type RejectedStorageOpServerMsg, type Relax, type Resolve, type ResolveMentionSuggestionsArgs, type ResolveRoomsInfoArgs, type ResolveUsersArgs, type Room, type RoomEventMessage, type RoomNotificationSettings, type RoomStateServerMsg, type SerializedChild, type SerializedCrdt, type SerializedList, type SerializedMap, type SerializedObject, type SerializedRegister, type SerializedRootObject, type ServerMsg, ServerMsgCode, type SetParentKeyOp, Signal, type SignalType, SortedList, type Status, type StorageStatus, type StorageUpdate, type StringifyCommentBodyElements, type StringifyCommentBodyOptions, type SyncSource, type SyncStatus, TextEditorType, type ThreadData, type ThreadDataPlain, type ThreadDataWithDeleteInfo, type ThreadDeleteInfo, type ToImmutable, type ToJson, type URLSafeString, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type UploadAttachmentOptions, type User, type UserJoinServerMsg, type UserLeftServerMsg, WebsocketCloseCodes, type YDocUpdateServerMsg, type YjsSyncStatus, ackOp, asPos, assert, assertNever, autoRetry, b64decode, batch, chunk, cloneLson, compactObject, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToInboxNotificationData, convertToThreadData, createClient, createCommentAttachmentId, createCommentId, createInboxNotificationId, createThreadId, deprecate, deprecateIf, detectDupes, errorIf, freeze, generateCommentUrl, getMentionedIdsFromCommentBody, html, htmlSafe, isChildCrdt, isCommentBodyLink, isCommentBodyMention, isCommentBodyText, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, isStartsWithOperator, kInternal, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, mapValues, memoizeOnSuccess, nanoid, nn, objectToQuery, patchLiveObjectKey, raise, resolveUsersInCommentBody, shallow, stringify, stringifyCommentBody, throwUsageError, toAbsoluteUrl, toPlainLson, tryParseJson, unstringify, url, urljoin, wait, withTimeout };
package/dist/index.d.ts CHANGED
@@ -5,18 +5,72 @@
5
5
  declare function detectDupes(pkgName: string, pkgVersion: string | false, // false if not built yet
6
6
  pkgFormat: string | false): void;
7
7
 
8
- type CustomAuthenticationResult = {
8
+ /**
9
+ * This helper type is effectively a no-op, but will force TypeScript to
10
+ * "evaluate" any named helper types in its definition. This can sometimes make
11
+ * API signatures clearer in IDEs.
12
+ *
13
+ * For example, in:
14
+ *
15
+ * type Payload<T> = { data: T };
16
+ *
17
+ * let r1: Payload<string>;
18
+ * let r2: Resolve<Payload<string>>;
19
+ *
20
+ * The inferred type of `r1` is going to be `Payload<string>` which shows up in
21
+ * editor hints, and it may be unclear what's inside if you don't know the
22
+ * definition of `Payload`.
23
+ *
24
+ * The inferred type of `r2` is going to be `{ data: string }`, which may be
25
+ * more helpful.
26
+ *
27
+ * This trick comes from:
28
+ * https://effectivetypescript.com/2022/02/25/gentips-4-display/
29
+ */
30
+ type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
31
+ [K in keyof T]: T[K];
32
+ };
33
+
34
+ /**
35
+ * Relaxes a discriminated union type definition, by explicitly adding
36
+ * properties defined in any other member as 'never'.
37
+ *
38
+ * This makes accessing the members much more relaxed in TypeScript.
39
+ *
40
+ * For example:
41
+ * type MyUnion = Relax<
42
+ * | { foo: string }
43
+ * | { foo: number; bar: string; }
44
+ * | { qux: boolean }
45
+ * >;
46
+ *
47
+ * // With Relax, accessing is much easier:
48
+ * union.foo; // string | number | undefined
49
+ * union.bar; // string | undefined
50
+ * union.qux; // boolean
51
+ * union.whatever; // Error: Property 'whatever' does not exist on type 'MyUnion'
52
+ *
53
+ * // Without Relax, these would all be type errors:
54
+ * union.foo; // Error: Property 'foo' does not exist on type 'MyUnion'
55
+ * union.bar; // Error: Property 'bar' does not exist on type 'MyUnion'
56
+ * union.qux; // Error: Property 'qux' does not exist on type 'MyUnion'
57
+ */
58
+ type Relax<T> = DistributiveRelax<T, T extends any ? keyof T : never>;
59
+ type DistributiveRelax<T, Ks extends string | number | symbol> = T extends any ? Resolve<{
60
+ [K in keyof T]: T[K];
61
+ } & {
62
+ [K in Exclude<Ks, keyof T>]?: never;
63
+ }> : never;
64
+
65
+ type CustomAuthenticationResult = Relax<{
9
66
  token: string;
10
- error?: never;
11
67
  } | {
12
- token?: never;
13
68
  error: "forbidden";
14
69
  reason: string;
15
70
  } | {
16
- token?: never;
17
71
  error: string;
18
72
  reason: string;
19
- };
73
+ }>;
20
74
 
21
75
  /**
22
76
  * Represents an indefinitely deep arbitrary JSON data structure. There are
@@ -919,22 +973,18 @@ type CommentData = {
919
973
  editedAt?: Date;
920
974
  reactions: CommentReaction[];
921
975
  attachments: CommentAttachment[];
922
- } & ({
976
+ } & Relax<{
923
977
  body: CommentBody;
924
- deletedAt?: never;
925
978
  } | {
926
- body?: never;
927
979
  deletedAt: Date;
928
- });
980
+ }>;
929
981
  type CommentDataPlain = Omit<DateToString<CommentData>, "reactions" | "body"> & {
930
982
  reactions: DateToString<CommentReaction>[];
931
- } & ({
983
+ } & Relax<{
932
984
  body: CommentBody;
933
- deletedAt?: never;
934
985
  } | {
935
- body?: never;
936
986
  deletedAt: string;
937
- });
987
+ }>;
938
988
  type CommentBodyBlockElement = CommentBodyParagraph;
939
989
  type CommentBodyInlineElement = CommentBodyText | CommentBodyMention | CommentBodyLink;
940
990
  type CommentBodyElement = CommentBodyBlockElement | CommentBodyInlineElement;
@@ -1131,11 +1181,13 @@ type FetchYDocClientMsg = {
1131
1181
  readonly type: ClientMsgCode.FETCH_YDOC;
1132
1182
  readonly vector: string;
1133
1183
  readonly guid?: string;
1184
+ readonly v2?: boolean;
1134
1185
  };
1135
1186
  type UpdateYDocClientMsg = {
1136
1187
  readonly type: ClientMsgCode.UPDATE_YDOC;
1137
1188
  readonly update: string;
1138
1189
  readonly guid?: string;
1190
+ readonly v2?: boolean;
1139
1191
  };
1140
1192
 
1141
1193
  type IdTuple<T> = [id: string, value: T];
@@ -1338,6 +1390,7 @@ type YDocUpdateServerMsg = {
1338
1390
  readonly isSync: boolean;
1339
1391
  readonly stateVector: string | null;
1340
1392
  readonly guid?: string;
1393
+ readonly v2?: boolean;
1341
1394
  };
1342
1395
  /**
1343
1396
  * Sent by the WebSocket server and broadcasted to all clients to announce that
@@ -1469,32 +1522,6 @@ declare namespace DevToolsTreeNode {
1469
1522
  export type { DevToolsTreeNode_CustomEventTreeNode as CustomEventTreeNode, DevToolsTreeNode_JsonTreeNode as JsonTreeNode, DevToolsTreeNode_LiveTreeNode as LiveTreeNode, DevToolsTreeNode_LsonTreeNode as LsonTreeNode, DevToolsTreeNode_TreeNode as TreeNode, DevToolsTreeNode_UserTreeNode as UserTreeNode };
1470
1523
  }
1471
1524
 
1472
- /**
1473
- * This helper type is effectively a no-op, but will force TypeScript to
1474
- * "evaluate" any named helper types in its definition. This can sometimes make
1475
- * API signatures clearer in IDEs.
1476
- *
1477
- * For example, in:
1478
- *
1479
- * type Payload<T> = { data: T };
1480
- *
1481
- * let r1: Payload<string>;
1482
- * let r2: Resolve<Payload<string>>;
1483
- *
1484
- * The inferred type of `r1` is going to be `Payload<string>` which shows up in
1485
- * editor hints, and it may be unclear what's inside if you don't know the
1486
- * definition of `Payload`.
1487
- *
1488
- * The inferred type of `r2` is going to be `{ data: string }`, which may be
1489
- * more helpful.
1490
- *
1491
- * This trick comes from:
1492
- * https://effectivetypescript.com/2022/02/25/gentips-4-display/
1493
- */
1494
- type Resolve<T> = T extends (...args: unknown[]) => unknown ? T : {
1495
- [K in keyof T]: T[K];
1496
- };
1497
-
1498
1525
  /**
1499
1526
  * Represents a user connected in a room. Treated as immutable.
1500
1527
  */
@@ -1527,7 +1554,7 @@ type User<P extends JsonObject = DP, U extends BaseUserMeta = DU> = {
1527
1554
  readonly canComment: boolean;
1528
1555
  };
1529
1556
 
1530
- type InternalOthersEvent<P extends JsonObject, U extends BaseUserMeta> = {
1557
+ type InternalOthersEvent<P extends JsonObject, U extends BaseUserMeta> = Relax<{
1531
1558
  type: "leave";
1532
1559
  user: User<P, U>;
1533
1560
  } | {
@@ -1539,8 +1566,7 @@ type InternalOthersEvent<P extends JsonObject, U extends BaseUserMeta> = {
1539
1566
  updates: Partial<P>;
1540
1567
  } | {
1541
1568
  type: "reset";
1542
- user?: never;
1543
- };
1569
+ }>;
1544
1570
  type OthersEvent<P extends JsonObject = DP, U extends BaseUserMeta = DU> = Resolve<InternalOthersEvent<P, U> & {
1545
1571
  others: readonly User<P, U>[];
1546
1572
  }>;
@@ -1909,11 +1935,11 @@ type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUs
1909
1935
  *
1910
1936
  * @param {string} data the doc update to send to the server, base64 encoded uint8array
1911
1937
  */
1912
- updateYDoc(data: string, guid?: string): void;
1938
+ updateYDoc(data: string, guid?: string, isV2?: boolean): void;
1913
1939
  /**
1914
1940
  * Sends a request for the current document from liveblocks server
1915
1941
  */
1916
- fetchYDoc(stateVector: string, guid?: string): void;
1942
+ fetchYDoc(stateVector: string, guid?: string, isV2?: boolean): void;
1917
1943
  /**
1918
1944
  * Broadcasts an event to other users in the room. Event broadcasted to the room can be listened with {@link Room.subscribe}("event").
1919
1945
  * @param {any} event the event to broadcast. Should be serializable to JSON
@@ -2310,6 +2336,12 @@ type PrivateRoomApi = {
2310
2336
  }>;
2311
2337
  getTextVersion(versionId: string): Promise<Response>;
2312
2338
  createTextVersion(): Promise<void>;
2339
+ executeContextualPrompt(options: {
2340
+ prompt: string;
2341
+ selectionText: string;
2342
+ context: string;
2343
+ signal: AbortSignal;
2344
+ }): Promise<string>;
2313
2345
  simulate: {
2314
2346
  explicitClose(event: IWebSocketCloseEvent): void;
2315
2347
  rawSend(data: string): void;
@@ -2523,6 +2555,13 @@ interface RoomHttpApi<M extends BaseMetadata> {
2523
2555
  nonce: string | undefined;
2524
2556
  messages: ClientMsg<P, E>[];
2525
2557
  }): Promise<Response>;
2558
+ executeContextualPrompt({ roomId, selectionText, context, }: {
2559
+ roomId: string;
2560
+ prompt: string;
2561
+ selectionText: string;
2562
+ context: string;
2563
+ signal: AbortSignal;
2564
+ }): Promise<string>;
2526
2565
  }
2527
2566
  interface NotificationHttpApi<M extends BaseMetadata> {
2528
2567
  getInboxNotifications(options?: {
@@ -2977,13 +3016,11 @@ type ClientOptions<U extends BaseUserMeta = DU> = {
2977
3016
  * the server yet.
2978
3017
  */
2979
3018
  preventUnsavedChanges?: boolean;
2980
- } & ({
3019
+ } & Relax<{
2981
3020
  publicApiKey: string;
2982
- authEndpoint?: never;
2983
3021
  } | {
2984
- publicApiKey?: never;
2985
3022
  authEndpoint: AuthEndpoint;
2986
- });
3023
+ }>;
2987
3024
  /**
2988
3025
  * Create a client that will be responsible to communicate with liveblocks servers.
2989
3026
  *
@@ -3751,4 +3788,4 @@ declare const CommentsApiError: typeof HttpError;
3751
3788
  /** @deprecated Use HttpError instead. */
3752
3789
  declare const NotificationsApiError: typeof HttpError;
3753
3790
 
3754
- export { type AckOp, type ActivityData, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type BaseActivitiesData, type BaseAuthResult, type BaseMetadata, type BaseRoomInfo, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type Client, type ClientMsg, ClientMsgCode, type ClientOptions, type CommentAttachment, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentLocalAttachment, type CommentMixedAttachment, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, CommentsApiError, type CommentsEventServerMsg, CrdtType, type CreateListOp, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type CustomAuthenticationResult, type DAD, type DE, type DM, type DP, type DRI, type DS, type DU, DefaultMap, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, DerivedSignal, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, type DistributiveOmit, type EnsureJson, type EnterOptions, type EventSource, type FetchStorageClientMsg, type FetchYDocClientMsg, type GetThreadsOptions, type History, type HistoryVersion, HttpError, type ISignal, type IUserInfo, type IWebSocket, type IWebSocketCloseEvent, type IWebSocketEvent, type IWebSocketInstance, type IWebSocketMessageEvent, type IYjsProvider, type IdTuple, type Immutable, type InboxNotificationCustomData, type InboxNotificationCustomDataPlain, type InboxNotificationData, type InboxNotificationDataPlain, type InboxNotificationDeleteInfo, type InboxNotificationTextMentionData, type InboxNotificationTextMentionDataPlain, type InboxNotificationThreadData, type InboxNotificationThreadDataPlain, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type KDAD, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, LiveblocksError, type LostConnectionEvent, type Lson, type LsonObject, MutableSignal, type NoInfr, type NodeMap, NotificationsApiError, type Observable, type Op, OpCode, type OpaqueClient, type OpaqueRoom, type OptionalPromise, type OptionalTupleUnless, type OthersEvent, type ParentToChildNodeMap, type PartialUnless, type Patchable, Permission, type PlainLson, type PlainLsonFields, type PlainLsonList, type PlainLsonMap, type PlainLsonObject, type Poller, type PrivateClientApi, type PrivateRoomApi, Promise_withResolvers, type QueryMetadata, type QueryParams, type RejectedStorageOpServerMsg, type Resolve, type ResolveMentionSuggestionsArgs, type ResolveRoomsInfoArgs, type ResolveUsersArgs, type Room, type RoomEventMessage, type RoomNotificationSettings, type RoomStateServerMsg, type SerializedChild, type SerializedCrdt, type SerializedList, type SerializedMap, type SerializedObject, type SerializedRegister, type SerializedRootObject, type ServerMsg, ServerMsgCode, type SetParentKeyOp, Signal, type SignalType, SortedList, type Status, type StorageStatus, type StorageUpdate, type StringifyCommentBodyElements, type StringifyCommentBodyOptions, type SyncSource, type SyncStatus, TextEditorType, type ThreadData, type ThreadDataPlain, type ThreadDataWithDeleteInfo, type ThreadDeleteInfo, type ToImmutable, type ToJson, type URLSafeString, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type UploadAttachmentOptions, type User, type UserJoinServerMsg, type UserLeftServerMsg, WebsocketCloseCodes, type YDocUpdateServerMsg, type YjsSyncStatus, ackOp, asPos, assert, assertNever, autoRetry, b64decode, batch, chunk, cloneLson, compactObject, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToInboxNotificationData, convertToThreadData, createClient, createCommentAttachmentId, createCommentId, createInboxNotificationId, createThreadId, deprecate, deprecateIf, detectDupes, errorIf, freeze, generateCommentUrl, getMentionedIdsFromCommentBody, html, htmlSafe, isChildCrdt, isCommentBodyLink, isCommentBodyMention, isCommentBodyText, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, isStartsWithOperator, kInternal, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, mapValues, memoizeOnSuccess, nanoid, nn, objectToQuery, patchLiveObjectKey, raise, resolveUsersInCommentBody, shallow, stringify, stringifyCommentBody, throwUsageError, toAbsoluteUrl, toPlainLson, tryParseJson, unstringify, url, urljoin, wait, withTimeout };
3791
+ export { type AckOp, type ActivityData, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type BaseActivitiesData, type BaseAuthResult, type BaseMetadata, type BaseRoomInfo, type BaseUserMeta, type Brand, type BroadcastEventClientMsg, type BroadcastOptions, type BroadcastedEventServerMsg, type Client, type ClientMsg, ClientMsgCode, type ClientOptions, type CommentAttachment, type CommentBody, type CommentBodyBlockElement, type CommentBodyElement, type CommentBodyInlineElement, type CommentBodyLink, type CommentBodyLinkElementArgs, type CommentBodyMention, type CommentBodyMentionElementArgs, type CommentBodyParagraph, type CommentBodyParagraphElementArgs, type CommentBodyText, type CommentBodyTextElementArgs, type CommentData, type CommentDataPlain, type CommentLocalAttachment, type CommentMixedAttachment, type CommentReaction, type CommentUserReaction, type CommentUserReactionPlain, CommentsApiError, type CommentsEventServerMsg, CrdtType, type CreateListOp, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type CustomAuthenticationResult, type DAD, type DE, type DM, type DP, type DRI, type DS, type DU, DefaultMap, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, DerivedSignal, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, type DistributiveOmit, type EnsureJson, type EnterOptions, type EventSource, type FetchStorageClientMsg, type FetchYDocClientMsg, type GetThreadsOptions, type History, type HistoryVersion, HttpError, type ISignal, type IUserInfo, type IWebSocket, type IWebSocketCloseEvent, type IWebSocketEvent, type IWebSocketInstance, type IWebSocketMessageEvent, type IYjsProvider, type IdTuple, type Immutable, type InboxNotificationCustomData, type InboxNotificationCustomDataPlain, type InboxNotificationData, type InboxNotificationDataPlain, type InboxNotificationDeleteInfo, type InboxNotificationTextMentionData, type InboxNotificationTextMentionDataPlain, type InboxNotificationThreadData, type InboxNotificationThreadDataPlain, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type KDAD, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, LiveblocksError, type LostConnectionEvent, type Lson, type LsonObject, MutableSignal, type NoInfr, type NodeMap, NotificationsApiError, type Observable, type Op, OpCode, type OpaqueClient, type OpaqueRoom, type OptionalPromise, type OptionalTupleUnless, type OthersEvent, type ParentToChildNodeMap, type PartialUnless, type Patchable, Permission, type PlainLson, type PlainLsonFields, type PlainLsonList, type PlainLsonMap, type PlainLsonObject, type Poller, type PrivateClientApi, type PrivateRoomApi, Promise_withResolvers, type QueryMetadata, type QueryParams, type RejectedStorageOpServerMsg, type Relax, type Resolve, type ResolveMentionSuggestionsArgs, type ResolveRoomsInfoArgs, type ResolveUsersArgs, type Room, type RoomEventMessage, type RoomNotificationSettings, type RoomStateServerMsg, type SerializedChild, type SerializedCrdt, type SerializedList, type SerializedMap, type SerializedObject, type SerializedRegister, type SerializedRootObject, type ServerMsg, ServerMsgCode, type SetParentKeyOp, Signal, type SignalType, SortedList, type Status, type StorageStatus, type StorageUpdate, type StringifyCommentBodyElements, type StringifyCommentBodyOptions, type SyncSource, type SyncStatus, TextEditorType, type ThreadData, type ThreadDataPlain, type ThreadDataWithDeleteInfo, type ThreadDeleteInfo, type ToImmutable, type ToJson, type URLSafeString, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type UploadAttachmentOptions, type User, type UserJoinServerMsg, type UserLeftServerMsg, WebsocketCloseCodes, type YDocUpdateServerMsg, type YjsSyncStatus, ackOp, asPos, assert, assertNever, autoRetry, b64decode, batch, chunk, cloneLson, compactObject, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToInboxNotificationData, convertToThreadData, createClient, createCommentAttachmentId, createCommentId, createInboxNotificationId, createThreadId, deprecate, deprecateIf, detectDupes, errorIf, freeze, generateCommentUrl, getMentionedIdsFromCommentBody, html, htmlSafe, isChildCrdt, isCommentBodyLink, isCommentBodyMention, isCommentBodyText, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isPlainObject, isRootCrdt, isStartsWithOperator, kInternal, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, mapValues, memoizeOnSuccess, nanoid, nn, objectToQuery, patchLiveObjectKey, raise, resolveUsersInCommentBody, shallow, stringify, stringifyCommentBody, throwUsageError, toAbsoluteUrl, toPlainLson, tryParseJson, unstringify, url, urljoin, wait, withTimeout };
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "2.16.0-toolbars5";
9
+ var PKG_VERSION = "2.16.1-ai";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -1536,6 +1536,25 @@ function createApiClient({
1536
1536
  }
1537
1537
  );
1538
1538
  }
1539
+ async function executeContextualPrompt(options) {
1540
+ const result = await httpClient.post(
1541
+ url`/v2/c/rooms/${options.roomId}/ai/contextual-prompt`,
1542
+ await authManager.getAuthValue({
1543
+ requestedScope: "room:read",
1544
+ roomId: options.roomId
1545
+ }),
1546
+ {
1547
+ prompt: options.prompt,
1548
+ selectionText: options.selectionText,
1549
+ context: options.context
1550
+ },
1551
+ { signal: options.signal }
1552
+ );
1553
+ if (!result || result.content.length === 0) {
1554
+ throw new Error("No content returned from server");
1555
+ }
1556
+ return result.content[0].text;
1557
+ }
1539
1558
  async function listTextVersions(options) {
1540
1559
  const result = await httpClient.get(
1541
1560
  url`/v2/c/rooms/${options.roomId}/versions`,
@@ -1776,7 +1795,9 @@ function createApiClient({
1776
1795
  deleteInboxNotification,
1777
1796
  // User threads
1778
1797
  getUserThreads_experimental,
1779
- getUserThreadsSince_experimental
1798
+ getUserThreadsSince_experimental,
1799
+ // ai
1800
+ executeContextualPrompt
1780
1801
  };
1781
1802
  }
1782
1803
  function getBearerTokenFromAuthValue(authValue) {
@@ -6504,6 +6525,12 @@ function createRoom(options, config) {
6504
6525
  async function createTextVersion() {
6505
6526
  return httpClient.createTextVersion({ roomId });
6506
6527
  }
6528
+ async function executeContextualPrompt(options2) {
6529
+ return httpClient.executeContextualPrompt({
6530
+ roomId,
6531
+ ...options2
6532
+ });
6533
+ }
6507
6534
  function sendMessages(messages) {
6508
6535
  const serializedPayload = JSON.stringify(messages);
6509
6536
  const nonce = _optionalChain([context, 'access', _139 => _139.dynamicSessionInfoSig, 'access', _140 => _140.get, 'call', _141 => _141(), 'optionalAccess', _142 => _142.nonce]);
@@ -7071,11 +7098,12 @@ ${Array.from(traces).join("\n\n")}`
7071
7098
  }
7072
7099
  return messages;
7073
7100
  }
7074
- function updateYDoc(update, guid) {
7101
+ function updateYDoc(update, guid, isV2) {
7075
7102
  const clientMsg = {
7076
7103
  type: 301 /* UPDATE_YDOC */,
7077
7104
  update,
7078
- guid
7105
+ guid,
7106
+ v2: isV2
7079
7107
  };
7080
7108
  context.buffer.messages.push(clientMsg);
7081
7109
  eventHub.ydoc.notify(clientMsg);
@@ -7156,14 +7184,15 @@ ${Array.from(traces).join("\n\n")}`
7156
7184
  root: nn(context.root)
7157
7185
  };
7158
7186
  }
7159
- function fetchYDoc(vector, guid) {
7187
+ function fetchYDoc(vector, guid, isV2) {
7160
7188
  if (!context.buffer.messages.find((m) => {
7161
- return m.type === 300 /* FETCH_YDOC */ && m.vector === vector && m.guid === guid;
7189
+ return m.type === 300 /* FETCH_YDOC */ && m.vector === vector && m.guid === guid && m.v2 === isV2;
7162
7190
  })) {
7163
7191
  context.buffer.messages.push({
7164
7192
  type: 300 /* FETCH_YDOC */,
7165
7193
  vector,
7166
- guid
7194
+ guid,
7195
+ v2: isV2
7167
7196
  });
7168
7197
  }
7169
7198
  flushNowOrSoon();
@@ -7487,6 +7516,8 @@ ${Array.from(traces).join("\n\n")}`
7487
7516
  getTextVersion,
7488
7517
  // create a version
7489
7518
  createTextVersion,
7519
+ // execute contextual prompt
7520
+ executeContextualPrompt,
7490
7521
  // Support for the Liveblocks browser extension
7491
7522
  getSelf_forDevTools: () => selfAsTreeNode.get(),
7492
7523
  getOthers_forDevTools: () => others_forDevTools.get(),