@liveblocks/core 2.25.0-aiprivatebeta9 → 3.1.0-alpha1

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.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { JSONSchema7 } from 'json-schema';
2
- import { ComponentType } from 'react';
3
2
 
4
3
  /**
5
4
  * Throws an error if multiple copies of a Liveblocks package are being loaded
@@ -1192,8 +1191,10 @@ type CommentBodyParagraph = {
1192
1191
  type: "paragraph";
1193
1192
  children: CommentBodyInlineElement[];
1194
1193
  };
1195
- type CommentBodyMention = {
1194
+ type CommentBodyMention = Relax<CommentBodyUserMention>;
1195
+ type CommentBodyUserMention = {
1196
1196
  type: "mention";
1197
+ kind: "user";
1197
1198
  id: string;
1198
1199
  };
1199
1200
  type CommentBodyLink = {
@@ -1290,13 +1291,6 @@ type NotificationChannelSettings = {
1290
1291
  type NotificationSettingsPlain = {
1291
1292
  [C in NotificationChannel]?: NotificationChannelSettings;
1292
1293
  };
1293
- /**
1294
- * @deprecated Renamed to `NotificationSettings`
1295
- *
1296
- * Notification settings.
1297
- * One channel for one set of settings.
1298
- */
1299
- type UserNotificationSettings = NotificationSettings;
1300
1294
  /**
1301
1295
  * Notification settings.
1302
1296
  * One channel for one set of settings.
@@ -1363,10 +1357,6 @@ type RoomSubscriptionSettings = {
1363
1357
  type UserRoomSubscriptionSettings = {
1364
1358
  roomId: string;
1365
1359
  } & RoomSubscriptionSettings;
1366
- /**
1367
- * @deprecated Renamed to `RoomSubscriptionSettings`
1368
- */
1369
- type RoomNotificationSettings = RoomSubscriptionSettings;
1370
1360
 
1371
1361
  type SubscriptionData<K extends keyof DAD = keyof DAD> = {
1372
1362
  kind: NotificationKind<K>;
@@ -1819,14 +1809,11 @@ type CommentsOrNotificationsErrorContext = {
1819
1809
  inboxNotificationId: string;
1820
1810
  } | {
1821
1811
  type: "MARK_ALL_INBOX_NOTIFICATIONS_AS_READ_ERROR" | "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR";
1822
- } | {
1823
- type: "UPDATE_NOTIFICATION_SETTINGS_ERROR";
1824
- roomId: string;
1825
1812
  } | {
1826
1813
  type: "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR";
1827
1814
  roomId: string;
1828
1815
  } | {
1829
- type: "UPDATE_USER_NOTIFICATION_SETTINGS_ERROR";
1816
+ type: "UPDATE_NOTIFICATION_SETTINGS_ERROR";
1830
1817
  };
1831
1818
  type LiveblocksErrorContext = Relax<RoomConnectionErrorContext | CommentsOrNotificationsErrorContext | AiConnectionErrorContext>;
1832
1819
  declare class LiveblocksError extends Error {
@@ -1834,8 +1821,6 @@ declare class LiveblocksError extends Error {
1834
1821
  constructor(message: string, context: LiveblocksErrorContext, cause?: Error);
1835
1822
  /** Convenience accessor for error.context.roomId (if available) */
1836
1823
  get roomId(): LiveblocksErrorContext["roomId"];
1837
- /** @deprecated Prefer using `context.code` instead, to enable type narrowing */
1838
- get code(): LiveblocksErrorContext["code"];
1839
1824
  /**
1840
1825
  * Creates a LiveblocksError from a generic error, by attaching Liveblocks
1841
1826
  * contextual information like room ID, thread ID, etc.
@@ -1843,6 +1828,12 @@ declare class LiveblocksError extends Error {
1843
1828
  static from(context: LiveblocksErrorContext, cause?: Error): LiveblocksError;
1844
1829
  }
1845
1830
 
1831
+ type MentionData = Relax<UserMentionData>;
1832
+ type UserMentionData = {
1833
+ kind: "user";
1834
+ id: string;
1835
+ };
1836
+
1846
1837
  type ResolveMentionSuggestionsArgs = {
1847
1838
  /**
1848
1839
  * The ID of the current room.
@@ -1904,7 +1895,7 @@ type InternalSyncStatus = SyncStatus | "has-local-changes";
1904
1895
  */
1905
1896
  type PrivateClientApi<U extends BaseUserMeta, M extends BaseMetadata> = {
1906
1897
  readonly currentUserId: Signal<string | undefined>;
1907
- readonly mentionSuggestionsCache: Map<string, string[]>;
1898
+ readonly mentionSuggestionsCache: Map<string, MentionData[]>;
1908
1899
  readonly resolveMentionSuggestions: ClientOptions<U>["resolveMentionSuggestions"];
1909
1900
  readonly usersStore: BatchStore<U["info"] | undefined, string>;
1910
1901
  readonly roomsInfoStore: BatchStore<DRI | undefined, string>;
@@ -2155,13 +2146,11 @@ type ClientOptions<U extends BaseUserMeta = DU> = {
2155
2146
  backgroundKeepAliveTimeout?: number;
2156
2147
  polyfills?: Polyfills;
2157
2148
  largeMessageStrategy?: LargeMessageStrategy;
2158
- /** @deprecated Use `largeMessageStrategy="experimental-fallback-to-http"` instead. */
2159
- unstable_fallbackToHTTP?: boolean;
2160
2149
  unstable_streamData?: boolean;
2161
2150
  /**
2162
- * A function that returns a list of user IDs matching a string.
2151
+ * A function that returns a list of mention suggestions matching a string.
2163
2152
  */
2164
- resolveMentionSuggestions?: (args: ResolveMentionSuggestionsArgs) => Awaitable<string[]>;
2153
+ resolveMentionSuggestions?: (args: ResolveMentionSuggestionsArgs) => Awaitable<string[] | MentionData[]>;
2165
2154
  /**
2166
2155
  * A function that returns user info from user IDs.
2167
2156
  * You should return a list of user objects of the same size, in the same order.
@@ -3013,11 +3002,6 @@ type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUs
3013
3002
  readonly self: Observable<User<P, U>>;
3014
3003
  readonly myPresence: Observable<P>;
3015
3004
  readonly others: Observable<OthersEvent<P, U>>;
3016
- /**
3017
- * @deprecated Renamed to `storageBatch`. The `storage` event source will
3018
- * soon be replaced by another/incompatible API.
3019
- */
3020
- readonly storage: Observable<StorageUpdate[]>;
3021
3005
  readonly storageBatch: Observable<StorageUpdate[]>;
3022
3006
  readonly history: Observable<HistoryEvent>;
3023
3007
  /**
@@ -3314,12 +3298,6 @@ type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUs
3314
3298
  * await room.getAttachmentUrl("at_xxx");
3315
3299
  */
3316
3300
  getAttachmentUrl(attachmentId: string): Promise<string>;
3317
- /**
3318
- * @deprecated Renamed to `getSubscriptionSettings`
3319
- *
3320
- * Gets the user's subscription settings for the current room.
3321
- */
3322
- getNotificationSettings(options?: GetSubscriptionSettingsOptions): Promise<RoomSubscriptionSettings>;
3323
3301
  /**
3324
3302
  * Gets the user's subscription settings for the current room.
3325
3303
  *
@@ -3327,12 +3305,6 @@ type Room<P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUs
3327
3305
  * const settings = await room.getSubscriptionSettings();
3328
3306
  */
3329
3307
  getSubscriptionSettings(options?: GetSubscriptionSettingsOptions): Promise<RoomSubscriptionSettings>;
3330
- /**
3331
- * @deprecated Renamed to `updateSubscriptionSettings`
3332
- *
3333
- * Updates the user's subscription settings for the current room.
3334
- */
3335
- updateNotificationSettings(settings: Partial<RoomSubscriptionSettings>): Promise<RoomSubscriptionSettings>;
3336
3308
  /**
3337
3309
  * Updates the user's subscription settings for the current room.
3338
3310
  *
@@ -3527,7 +3499,6 @@ type ISODateString = Brand<string, "ISODateString">;
3527
3499
  type ChatId = string;
3528
3500
  type MessageId = Brand<`ms_${string}`, "MessageId">;
3529
3501
  type CmdId = Brand<string, "CmdId">;
3530
- type ClientId = Brand<string, "ClientId">;
3531
3502
  type CopilotId = Brand<`co_${string}`, "CopilotId">;
3532
3503
  type ServerAiMsg = ServerCmdResponse | ServerEvent;
3533
3504
  type DefineCmd<CmdName extends string, TRequest, TResponse> = [
@@ -3620,13 +3591,6 @@ type AskInChatPair = DefineCmd<"ask-in-chat", {
3620
3591
  * message ID.
3621
3592
  */
3622
3593
  targetMessageId: MessageId;
3623
- /**
3624
- * A client ID unique to this command. Later delta and settle messages will
3625
- * reference this client ID, which is important to ensure that tool calls
3626
- * with side effects will only get executed once, and only by the client
3627
- * that originally made the request that produced the tool call.
3628
- */
3629
- clientId: ClientId;
3630
3594
  generationOptions: AiGenerationOptions;
3631
3595
  }, {
3632
3596
  sourceMessage?: AiChatMessage;
@@ -3637,13 +3601,33 @@ type AbortAiPair = DefineCmd<"abort-ai", {
3637
3601
  }, {
3638
3602
  ok: true;
3639
3603
  }>;
3640
- type ToolResultData = Json;
3604
+ type ToolResultResponse<R extends JsonObject = JsonObject> = Relax<({
3605
+ data: R;
3606
+ description?: string;
3607
+ } | {
3608
+ error: string;
3609
+ } | {
3610
+ cancel: true | /* reason */ string;
3611
+ })>;
3612
+ type NonEmptyString<T extends string> = T & {
3613
+ __nonEmpty: true;
3614
+ };
3615
+ type RenderableToolResultResponse<R extends JsonObject = JsonObject> = Relax<{
3616
+ type: "success";
3617
+ data: R;
3618
+ } | {
3619
+ type: "error";
3620
+ error: NonEmptyString<string>;
3621
+ } | {
3622
+ type: "cancelled";
3623
+ cancelled: true;
3624
+ reason?: string;
3625
+ }>;
3641
3626
  type SetToolResultPair = DefineCmd<"set-tool-result", {
3642
3627
  chatId: ChatId;
3643
3628
  messageId: MessageId;
3644
- toolCallId: string;
3645
- result: ToolResultData;
3646
- clientId: ClientId;
3629
+ invocationId: string;
3630
+ result: ToolResultResponse;
3647
3631
  generationOptions: AiGenerationOptions;
3648
3632
  }, {
3649
3633
  ok: true;
@@ -3651,7 +3635,7 @@ type SetToolResultPair = DefineCmd<"set-tool-result", {
3651
3635
  } | {
3652
3636
  ok: false;
3653
3637
  }>;
3654
- type ServerEvent = RebootedEvent | CmdFailedEvent | ErrorServerEvent | SyncServerEvent | DeltaServerEvent | SettleServerEvent;
3638
+ type ServerEvent = RebootedEvent | CmdFailedEvent | WarningServerEvent | ErrorServerEvent | SyncServerEvent | DeltaServerEvent | SettleServerEvent;
3655
3639
  type RebootedEvent = {
3656
3640
  event: "rebooted";
3657
3641
  };
@@ -3661,6 +3645,10 @@ type CmdFailedEvent = {
3661
3645
  failedCmdId: CmdId;
3662
3646
  error: string;
3663
3647
  };
3648
+ type WarningServerEvent = {
3649
+ event: "warning";
3650
+ message: string;
3651
+ };
3664
3652
  type ErrorServerEvent = {
3665
3653
  event: "error";
3666
3654
  error: string;
@@ -3680,8 +3668,6 @@ type SyncServerEvent = {
3680
3668
  type DeltaServerEvent = {
3681
3669
  event: "delta";
3682
3670
  id: MessageId;
3683
- /** The client ID that originally made the request that led to this event */
3684
- clientId: ClientId;
3685
3671
  delta: AiAssistantDeltaUpdate;
3686
3672
  };
3687
3673
  /**
@@ -3691,8 +3677,6 @@ type DeltaServerEvent = {
3691
3677
  */
3692
3678
  type SettleServerEvent = {
3693
3679
  event: "settle";
3694
- /** The client ID that originally made the request that led to this event */
3695
- clientId: ClientId;
3696
3680
  message: AiAwaitingToolAssistantMessage | AiCompletedAssistantMessage | AiFailedAssistantMessage;
3697
3681
  };
3698
3682
  type AiChat = {
@@ -3708,28 +3692,28 @@ type AiToolDescription = {
3708
3692
  description?: string;
3709
3693
  parameters: JSONSchema7;
3710
3694
  };
3711
- type AiToolInvocationPart<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = Relax<AiReceivingToolInvocationPart | AiExecutingToolInvocationPart<A> | AiExecutedToolInvocationPart<A, R>>;
3695
+ type AiToolInvocationPart<A extends JsonObject = JsonObject, R extends JsonObject = JsonObject> = Relax<AiReceivingToolInvocationPart | AiExecutingToolInvocationPart<A> | AiExecutedToolInvocationPart<A, R>>;
3712
3696
  type AiReceivingToolInvocationPart = {
3713
3697
  type: "tool-invocation";
3714
- status: "receiving";
3715
- toolCallId: string;
3716
- toolName: string;
3698
+ stage: "receiving";
3699
+ invocationId: string;
3700
+ name: string;
3717
3701
  partialArgs: Json;
3718
3702
  };
3719
3703
  type AiExecutingToolInvocationPart<A extends JsonObject = JsonObject> = {
3720
3704
  type: "tool-invocation";
3721
- status: "executing";
3722
- toolCallId: string;
3723
- toolName: string;
3705
+ stage: "executing";
3706
+ invocationId: string;
3707
+ name: string;
3724
3708
  args: A;
3725
3709
  };
3726
- type AiExecutedToolInvocationPart<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = {
3710
+ type AiExecutedToolInvocationPart<A extends JsonObject = JsonObject, R extends JsonObject = JsonObject> = {
3727
3711
  type: "tool-invocation";
3728
- status: "executed";
3729
- toolCallId: string;
3730
- toolName: string;
3712
+ stage: "executed";
3713
+ invocationId: string;
3714
+ name: string;
3731
3715
  args: A;
3732
- result: R;
3716
+ result: RenderableToolResultResponse<R>;
3733
3717
  };
3734
3718
  type AiTextPart = {
3735
3719
  type: "text";
@@ -3811,120 +3795,137 @@ type AiFailedAssistantMessage = {
3811
3795
  contentSoFar: AiAssistantContentPart[];
3812
3796
  errorReason: string;
3813
3797
  };
3814
- type AiChatMessage = AiUserMessage | AiAssistantMessage;
3798
+ type AiChatMessage = Relax<AiUserMessage | AiAssistantMessage>;
3815
3799
  type AiKnowledgeSource = {
3816
3800
  description: string;
3817
3801
  value: Json;
3818
3802
  };
3819
3803
 
3820
- type InferFromSchema<T extends JSONSchema7> = JSONSchema7 extends T ? JsonObject : T extends {
3821
- type: "object";
3822
- properties: Record<string, JSONSchema7>;
3823
- required: readonly string[];
3824
- } ? Resolve<{
3825
- -readonly [K in keyof T["properties"] as K extends string ? K extends Extract<K, T["required"][number]> ? K : never : never]: InferFromSchema<T["properties"][K]>;
3826
- } & {
3827
- -readonly [K in keyof T["properties"] as K extends string ? K extends Extract<K, T["required"][number]> ? never : K : never]?: InferFromSchema<T["properties"][K]>;
3828
- }> : T extends {
3804
+ type JSONObjectSchema7 = JSONSchema7 & {
3829
3805
  type: "object";
3830
- properties: Record<string, JSONSchema7>;
3806
+ };
3807
+ type NoFields = {};
3808
+ type Infer<T> = T extends JSONSchema7 ? InferFromSchema<T> : never;
3809
+ type InferAllOf<T extends readonly JSONSchema7[]> = T extends readonly [
3810
+ infer U,
3811
+ ...infer R
3812
+ ] ? R extends readonly JSONSchema7[] ? Infer<U> & InferAllOf<R> : Infer<U> : unknown;
3813
+ type InferRequireds<P, R extends readonly string[]> = {
3814
+ -readonly [K in keyof P as K extends string ? K extends Extract<K, R[number]> ? K : never : never]: Infer<P[K]>;
3815
+ };
3816
+ type InferOptionals<P, R extends readonly string[]> = {
3817
+ -readonly [K in keyof P as K extends string ? K extends Extract<K, R[number]> ? never : K : never]?: Infer<P[K]>;
3818
+ };
3819
+ type InferBaseObject<T extends JSONObjectSchema7> = T extends {
3820
+ properties?: infer P extends Record<string, JSONSchema7>;
3821
+ required?: infer R;
3822
+ } ? InferRequireds<P, R extends readonly string[] ? R : []> & InferOptionals<P, R extends readonly string[] ? R : []> : NoFields;
3823
+ type InferAdditionals<T extends JSONObjectSchema7> = T extends {
3824
+ additionalProperties: false;
3825
+ } ? NoFields : T extends {
3826
+ additionalProperties?: true;
3827
+ } ? JsonObject : T extends {
3828
+ additionalProperties: infer A;
3831
3829
  } ? {
3832
- -readonly [K in keyof T["properties"]]?: InferFromSchema<T["properties"][K]>;
3833
- } : T extends {
3830
+ [extra: string]: Infer<A> | undefined;
3831
+ } : JsonObject;
3832
+ type InferFromObjectSchema<T extends JSONObjectSchema7> = Resolve<InferBaseObject<T> & InferAdditionals<T>>;
3833
+ type InferFromArraySchema<T extends JSONSchema7> = T extends {
3834
+ items: infer U;
3835
+ } ? Infer<U>[] : Json[];
3836
+ type InferFromSchema<T extends JSONSchema7> = JSONSchema7 extends T ? JsonObject : T extends {
3837
+ type: "object";
3838
+ } ? InferFromObjectSchema<T> : T extends {
3839
+ type: "array";
3840
+ } ? InferFromArraySchema<T> : T extends {
3841
+ oneOf: readonly (infer U)[];
3842
+ } ? Infer<U> : T extends {
3843
+ anyOf: readonly (infer U)[];
3844
+ } ? Infer<U> : T extends {
3845
+ allOf: readonly JSONSchema7[];
3846
+ } ? InferAllOf<T["allOf"]> : T extends {
3847
+ not: JSONSchema7;
3848
+ } ? Json : T extends {
3849
+ enum: readonly (infer U)[];
3850
+ } ? U : T extends {
3851
+ const: infer C;
3852
+ } ? C : T extends {
3834
3853
  type: "string";
3835
3854
  } ? string : T extends {
3836
3855
  type: "number";
3856
+ } ? number : T extends {
3857
+ type: "integer";
3837
3858
  } ? number : T extends {
3838
3859
  type: "boolean";
3839
3860
  } ? boolean : T extends {
3840
3861
  type: "null";
3841
- } ? null : T extends {
3842
- type: "array";
3843
- items: JSONSchema7;
3844
- } ? InferFromSchema<T["items"]>[] : unknown;
3845
- type AiToolTypePack<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = {
3862
+ } ? null : Json;
3863
+
3864
+ type AiToolTypePack<A extends JsonObject = JsonObject, R extends JsonObject = JsonObject> = {
3846
3865
  A: A;
3847
3866
  R: R;
3848
3867
  };
3849
- type AiToolInvocationProps<A extends JsonObject, R extends ToolResultData> = Resolve<DistributiveOmit<AiToolInvocationPart<A, R>, "type"> & {
3850
- respond: (result: R) => void;
3868
+ type AskUserMessageInChatOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
3869
+ type SetToolResultOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
3870
+ type AiToolInvocationProps<A extends JsonObject, R extends JsonObject> = Resolve<DistributiveOmit<AiToolInvocationPart<A, R>, "type"> & {
3871
+ respond: (...args: OptionalTupleUnless<R, [result: ToolResultResponse<R>]>) => void;
3851
3872
  /**
3852
- * Exposes specific inferred types as a "type pack" which we can pass
3853
- * around statically to components to "bind" them to specific inferred
3854
- * A and R values. There is no runtime presence for these.
3873
+ * These are the inferred types for your tool call which you can pass down
3874
+ * to UI components, like so:
3875
+ *
3876
+ * <AiTool.Confirmation
3877
+ * types={types}
3878
+ * confirm={
3879
+ * // Now fully type-safe!
3880
+ * (args) => result
3881
+ * } />
3882
+ *
3883
+ * This will make your AiTool.Confirmation component aware of the types for
3884
+ * `args` and `result`.
3855
3885
  */
3856
- $types: AiToolTypePack<A, R>;
3886
+ types: AiToolTypePack<A, R>;
3857
3887
  [kInternal]: {
3858
3888
  execute: AiToolExecuteCallback<A, R> | undefined;
3859
3889
  };
3860
3890
  }>;
3861
- type AiOpaqueToolInvocationProps = AiToolInvocationProps<JsonObject, ToolResultData>;
3891
+ type AiOpaqueToolInvocationProps = AiToolInvocationProps<JsonObject, JsonObject>;
3862
3892
  type AiToolExecuteContext = {
3863
- toolName: string;
3864
- toolCallId: string;
3893
+ name: string;
3894
+ invocationId: string;
3865
3895
  };
3866
- type AiToolExecuteCallback<A extends JsonObject, R extends ToolResultData> = (args: A, context: AiToolExecuteContext) => Awaitable<R>;
3867
- type AiToolDefinition<S extends JSONSchema7, A extends JsonObject, R extends ToolResultData> = {
3896
+ type AiToolExecuteCallback<A extends JsonObject, R extends JsonObject> = (args: A, context: AiToolExecuteContext) => Record<string, never> extends R ? Awaitable<ToolResultResponse<R> | undefined | void> : Awaitable<ToolResultResponse<R>>;
3897
+ type AiToolDefinition<S extends JSONObjectSchema7, A extends JsonObject, R extends JsonObject> = {
3868
3898
  description?: string;
3869
3899
  parameters: S;
3870
3900
  execute?: AiToolExecuteCallback<A, R>;
3871
- render?: ComponentType<AiToolInvocationProps<A, R>>;
3901
+ render?: (props: AiToolInvocationProps<A, R>) => unknown;
3902
+ enabled?: boolean;
3872
3903
  };
3873
- type AiOpaqueToolDefinition = AiToolDefinition<JSONSchema7, JsonObject, ToolResultData>;
3904
+ type AiOpaqueToolDefinition = AiToolDefinition<JSONObjectSchema7, JsonObject, JsonObject>;
3874
3905
  /**
3875
3906
  * Helper function to help infer the types of `args`, `render`, and `result`.
3876
3907
  * This function has no runtime implementation and is only needed to make it
3877
3908
  * possible for TypeScript to infer types.
3878
3909
  */
3879
- declare function defineAiTool<R extends ToolResultData>(): <const S extends JSONSchema7>(def: AiToolDefinition<S, InferFromSchema<S> extends JsonObject ? InferFromSchema<S> : JsonObject, R>) => AiOpaqueToolDefinition;
3880
- type UiChatMessage = AiChatMessage & {
3881
- navigation: {
3882
- /**
3883
- * The message ID of the parent message, or null if there is no parent.
3884
- */
3885
- parent: MessageId | null;
3886
- /**
3887
- * The message ID of the left sibling message, or null if there is no left sibling.
3888
- */
3889
- prev: MessageId | null;
3890
- /**
3891
- * The message ID of the right sibling message, or null if there is no right sibling.
3892
- */
3893
- next: MessageId | null;
3894
- };
3895
- };
3896
- type UiUserMessage = AiUserMessage & {
3897
- navigation: {
3898
- /**
3899
- * The message ID of the parent message, or null if there is no parent.
3900
- */
3901
- parent: MessageId | null;
3902
- /**
3903
- * The message ID of the left sibling message, or null if there is no left sibling.
3904
- */
3905
- prev: MessageId | null;
3906
- /**
3907
- * The message ID of the right sibling message, or null if there is no right sibling.
3908
- */
3909
- next: MessageId | null;
3910
- };
3910
+ declare function defineAiTool<R extends JsonObject>(): <const S extends JSONObjectSchema7>(def: AiToolDefinition<S, InferFromSchema<S> extends JsonObject ? InferFromSchema<S> : JsonObject, R>) => AiOpaqueToolDefinition;
3911
+ type NavigationInfo = {
3912
+ /**
3913
+ * The message ID of the parent message, or null if there is no parent.
3914
+ */
3915
+ parent: MessageId | null;
3916
+ /**
3917
+ * The message ID of the left sibling message, or null if there is no left sibling.
3918
+ */
3919
+ prev: MessageId | null;
3920
+ /**
3921
+ * The message ID of the right sibling message, or null if there is no right sibling.
3922
+ */
3923
+ next: MessageId | null;
3911
3924
  };
3912
- type UiAssistantMessage = AiAssistantMessage & {
3913
- navigation: {
3914
- /**
3915
- * The message ID of the parent message, or null if there is no parent.
3916
- */
3917
- parent: MessageId | null;
3918
- /**
3919
- * The message ID of the left sibling message, or null if there is no left sibling.
3920
- */
3921
- prev: MessageId | null;
3922
- /**
3923
- * The message ID of the right sibling message, or null if there is no right sibling.
3924
- */
3925
- next: MessageId | null;
3926
- };
3925
+ type WithNavigation<T> = T & {
3926
+ navigation: NavigationInfo;
3927
3927
  };
3928
+ type UiChatMessage = WithNavigation<AiChatMessage>;
3928
3929
  type AiContext = {
3929
3930
  staticSessionInfoSig: Signal<StaticSessionInfo | null>;
3930
3931
  dynamicSessionInfoSig: Signal<DynamicSessionInfo | null>;
@@ -3948,15 +3949,11 @@ declare class KnowledgeStack {
3948
3949
  updateKnowledge(layerKey: LayerKey, key: string, data: AiKnowledgeSource | null): void;
3949
3950
  }
3950
3951
  declare function createStore_forTools(): {
3951
- getToolDefinitionΣ: (chatId: string, toolName: string) => Signal<AiOpaqueToolDefinition | undefined>;
3952
- getToolsForChat: (chatId: string) => {
3953
- name: string;
3954
- definition: AiOpaqueToolDefinition;
3955
- }[];
3956
- addToolDefinition: (chatId: string, name: string, definition: AiOpaqueToolDefinition) => void;
3957
- removeToolDefinition: (chatId: string, toolName: string) => void;
3952
+ getToolDescriptions: (chatId: string) => AiToolDescription[];
3953
+ getToolΣ: (name: string, chatId?: string) => DerivedSignal<AiOpaqueToolDefinition | undefined>;
3954
+ registerTool: (name: string, tool: AiOpaqueToolDefinition, chatId?: string) => () => void;
3958
3955
  };
3959
- declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?: AiGenerationOptions) => Promise<AskInChatResponse>): {
3956
+ declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResultFn: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultResponse, options?: SetToolResultOptions) => Promise<void>): {
3960
3957
  getMessageById: (messageId: MessageId) => AiChatMessage | undefined;
3961
3958
  getChatMessagesForBranchΣ: (chatId: string, branch?: MessageId) => DerivedSignal<UiChatMessage[]>;
3962
3959
  createOptimistically: {
@@ -3969,21 +3966,21 @@ declare function createStore_forChatMessages(toolsStore: ReturnType<typeof creat
3969
3966
  removeByChatId: (chatId: string) => void;
3970
3967
  addDelta: (messageId: MessageId, delta: AiAssistantDeltaUpdate) => void;
3971
3968
  failAllPending: () => void;
3969
+ markMine(messageId: MessageId): void;
3972
3970
  };
3973
3971
  declare function createStore_forUserAiChats(): {
3974
3972
  chatsΣ: DerivedSignal<AiChat[]>;
3975
3973
  getChatById: (chatId: string) => AiChat | undefined;
3976
3974
  upsert: (chat: AiChat) => void;
3977
3975
  upsertMany: (chats: AiChat[]) => void;
3978
- remove: (chatId: string) => void;
3976
+ markDeleted: (chatId: string) => void;
3979
3977
  };
3980
3978
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3981
3979
  type Ai = {
3982
3980
  [kInternal]: {
3983
3981
  context: AiContext;
3984
3982
  };
3985
- connect: () => void;
3986
- reconnect: () => void;
3983
+ connectInitially: () => void;
3987
3984
  disconnect: () => void;
3988
3985
  getStatus: () => Status;
3989
3986
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
@@ -4007,16 +4004,16 @@ type Ai = {
4007
4004
  id: MessageId;
4008
4005
  parentMessageId: MessageId | null;
4009
4006
  content: AiUserContentPart[];
4010
- }, targetMessageId: MessageId, options?: AiGenerationOptions) => Promise<AskInChatResponse>;
4007
+ }, targetMessageId: MessageId, options?: AskUserMessageInChatOptions) => Promise<AskInChatResponse>;
4011
4008
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4012
4009
  abort: (messageId: MessageId) => Promise<AbortAiResponse>;
4013
4010
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4014
- setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?: AiGenerationOptions) => Promise<AskInChatResponse>;
4011
+ setToolResult: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultResponse, options?: SetToolResultOptions) => Promise<void>;
4015
4012
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4016
4013
  signals: {
4017
4014
  chatsΣ: DerivedSignal<AiChat[]>;
4018
4015
  getChatMessagesForBranchΣ(chatId: string, branch?: MessageId): DerivedSignal<UiChatMessage[]>;
4019
- getToolDefinitionΣ(chatId: string, toolName: string): Signal<AiOpaqueToolDefinition | undefined>;
4016
+ getToolΣ(name: string, chatId?: string): DerivedSignal<AiOpaqueToolDefinition | undefined>;
4020
4017
  };
4021
4018
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4022
4019
  getChatById: (chatId: string) => AiChat | undefined;
@@ -4027,11 +4024,7 @@ type Ai = {
4027
4024
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4028
4025
  updateKnowledge: (layerKey: LayerKey, data: AiKnowledgeSource, key?: string) => void;
4029
4026
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4030
- debug_getAllKnowledge(): AiKnowledgeSource[];
4031
- /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4032
- registerChatTool: (chatId: string, name: string, definition: AiOpaqueToolDefinition) => void;
4033
- /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4034
- unregisterChatTool: (chatId: string, toolName: string) => void;
4027
+ registerTool: (name: string, tool: AiOpaqueToolDefinition, chatId?: string) => () => void;
4035
4028
  };
4036
4029
 
4037
4030
  type CommentBodyParagraphElementArgs = {
@@ -4112,9 +4105,12 @@ declare function isCommentBodyText(element: CommentBodyElement): element is Comm
4112
4105
  declare function isCommentBodyMention(element: CommentBodyElement): element is CommentBodyMention;
4113
4106
  declare function isCommentBodyLink(element: CommentBodyElement): element is CommentBodyLink;
4114
4107
  /**
4115
- * Get an array of each user's ID that has been mentioned in a `CommentBody`.
4108
+ * Get an array of all mentions in a `CommentBody`.
4109
+ *
4110
+ * Narrow results with an optional predicate, e.g.
4111
+ * `(mention) => mention.kind === "user"` to only get user mentions.
4116
4112
  */
4117
- declare function getMentionedIdsFromCommentBody(body: CommentBody): string[];
4113
+ declare function getMentionsFromCommentBody(body: CommentBody, predicate?: (mention: CommentBodyMention) => boolean): CommentBodyMention[];
4118
4114
  declare function resolveUsersInCommentBody<U extends BaseUserMeta>(body: CommentBody, resolveUsers?: (args: ResolveUsersArgs) => Awaitable<(U["info"] | undefined)[] | undefined>): Promise<Map<string, U["info"]>>;
4119
4115
  declare function htmlSafe(value: string): HtmlSafeString;
4120
4116
  declare class HtmlSafeString {
@@ -4817,9 +4813,4 @@ type EnsureJson<T> = T extends Json ? T : T extends Array<infer I> ? (EnsureJson
4817
4813
  [K in keyof T as EnsureJson<T[K]> extends never ? never : K]: EnsureJson<T[K]>;
4818
4814
  };
4819
4815
 
4820
- /** @deprecated Use HttpError instead. */
4821
- declare const CommentsApiError: typeof HttpError;
4822
- /** @deprecated Use HttpError instead. */
4823
- declare const NotificationsApiError: typeof HttpError;
4824
-
4825
- export { type AckOp, type ActivityData, type AiAssistantContentPart, type AiChat, type AiChatMessage, type AiKnowledgeSource, type AiOpaqueToolDefinition, type AiOpaqueToolInvocationProps, type AiReasoningPart, type AiTextPart, type AiToolDefinition, type AiToolExecuteCallback, type AiToolExecuteContext, type AiToolInvocationPart, type AiToolInvocationProps, type AiToolTypePack, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type Awaitable, 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, type ContextualPromptContext, type ContextualPromptResponse, type CopilotId, CrdtType, type CreateListOp, type CreateManagedPoolOptions, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type Cursor, type CustomAuthenticationResult, type DAD, type DE, type DM, type DP, type DRI, type DS, type DU, DefaultMap, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, Deque, 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 InferFromSchema, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type KDAD, type LargeMessageStrategy, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, LiveblocksError, type LiveblocksErrorContext, type LostConnectionEvent, type Lson, type LsonObject, type ManagedPool, type MessageId, MutableSignal, type NoInfr, type NodeMap, type NotificationChannel, type NotificationChannelSettings, type NotificationKind, type NotificationSettings, type NotificationSettingsPlain, NotificationsApiError, type Observable, type Op, OpCode, type OpaqueClient, type OpaqueRoom, type OptionalTupleUnless, type OthersEvent, type ParentToChildNodeMap, type PartialNotificationSettings, 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 RoomSubscriptionSettings, 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 SubscriptionData, type SubscriptionDataPlain, type SubscriptionDeleteInfo, type SubscriptionDeleteInfoPlain, type SubscriptionKey, type SyncSource, type SyncStatus, TextEditorType, type ThreadData, type ThreadDataPlain, type ThreadDataWithDeleteInfo, type ThreadDeleteInfo, type ToImmutable, type ToJson, type ToolResultData, type URLSafeString, type UiAssistantMessage, type UiChatMessage, type UiUserMessage, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type UploadAttachmentOptions, type User, type UserJoinServerMsg, type UserLeftServerMsg, type UserNotificationSettings, type UserRoomSubscriptionSettings, type UserSubscriptionData, type UserSubscriptionDataPlain, WebsocketCloseCodes, type YDocUpdateServerMsg, type YjsSyncStatus, ackOp, asPos, assert, assertNever, autoRetry, b64decode, batch, checkBounds, chunk, cloneLson, compactObject, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToInboxNotificationData, convertToSubscriptionData, convertToThreadData, convertToUserSubscriptionData, createClient, createCommentAttachmentId, createCommentId, createInboxNotificationId, createManagedPool, createNotificationSettings, createThreadId, defineAiTool, deprecate, deprecateIf, detectDupes, entries, errorIf, freeze, generateCommentUrl, getMentionedIdsFromCommentBody, getSubscriptionKey, html, htmlSafe, isChildCrdt, isCommentBodyLink, isCommentBodyMention, isCommentBodyText, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isNotificationChannelEnabled, isPlainObject, isRootCrdt, isStartsWithOperator, kInternal, keys, legacy_patchImmutableObject, lsonToJson, makeAbortController, makeEventSource, makePoller, makePosition, mapValues, memoizeOnSuccess, nanoid, nn, objectToQuery, patchLiveObjectKey, patchNotificationSettings, raise, resolveUsersInCommentBody, shallow, shallow2, stableStringify, stringifyCommentBody, throwUsageError, toAbsoluteUrl, toPlainLson, tryParseJson, url, urljoin, wait, withTimeout };
4816
+ export { type AckOp, type ActivityData, type AiAssistantContentPart, type AiAssistantMessage, type AiChat, type AiChatMessage, type AiKnowledgeSource, type AiOpaqueToolDefinition, type AiOpaqueToolInvocationProps, type AiReasoningPart, type AiTextPart, type AiToolDefinition, type AiToolExecuteCallback, type AiToolExecuteContext, type AiToolInvocationPart, type AiToolInvocationProps, type AiToolTypePack, type AiUserMessage, type AsyncError, type AsyncLoading, type AsyncResult, type AsyncSuccess, type Awaitable, 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, type CommentsEventServerMsg, type ContextualPromptContext, type ContextualPromptResponse, type CopilotId, CrdtType, type CreateListOp, type CreateManagedPoolOptions, type CreateMapOp, type CreateObjectOp, type CreateOp, type CreateRegisterOp, type Cursor, type CustomAuthenticationResult, type DAD, type DE, type DM, type DP, type DRI, type DS, type DU, DefaultMap, type Delegates, type DeleteCrdtOp, type DeleteObjectKeyOp, Deque, 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 InferFromSchema, type InitialDocumentStateServerMsg, type Json, type JsonArray, type JsonObject, type JsonScalar, type KDAD, type LargeMessageStrategy, LiveList, type LiveListUpdate, LiveMap, type LiveMapUpdate, type LiveNode, LiveObject, type LiveObjectUpdate, type LiveStructure, LiveblocksError, type LiveblocksErrorContext, type LostConnectionEvent, type Lson, type LsonObject, type ManagedPool, type MentionData, type MessageId, MutableSignal, type NoInfr, type NodeMap, type NotificationChannel, type NotificationChannelSettings, type NotificationKind, type NotificationSettings, type NotificationSettingsPlain, type Observable, type Op, OpCode, type OpaqueClient, type OpaqueRoom, type OptionalTupleUnless, type OthersEvent, type ParentToChildNodeMap, type PartialNotificationSettings, 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 RenderableToolResultResponse, type Resolve, type ResolveMentionSuggestionsArgs, type ResolveRoomsInfoArgs, type ResolveUsersArgs, type Room, type RoomEventMessage, type RoomStateServerMsg, type RoomSubscriptionSettings, 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 SubscriptionData, type SubscriptionDataPlain, type SubscriptionDeleteInfo, type SubscriptionDeleteInfoPlain, type SubscriptionKey, type SyncSource, type SyncStatus, TextEditorType, type ThreadData, type ThreadDataPlain, type ThreadDataWithDeleteInfo, type ThreadDeleteInfo, type ToImmutable, type ToJson, type ToolResultResponse, type URLSafeString, type UnsubscribeCallback, type UpdateObjectOp, type UpdatePresenceClientMsg, type UpdatePresenceServerMsg, type UpdateStorageClientMsg, type UpdateStorageServerMsg, type UpdateYDocClientMsg, type UploadAttachmentOptions, type User, type UserJoinServerMsg, type UserLeftServerMsg, type UserMentionData, type UserRoomSubscriptionSettings, type UserSubscriptionData, type UserSubscriptionDataPlain, WebsocketCloseCodes, type WithNavigation, type YDocUpdateServerMsg, type YjsSyncStatus, ackOp, asPos, assert, assertNever, autoRetry, b64decode, batch, checkBounds, chunk, cloneLson, compactObject, fancyConsole as console, convertToCommentData, convertToCommentUserReaction, convertToInboxNotificationData, convertToSubscriptionData, convertToThreadData, convertToUserSubscriptionData, createClient, createCommentAttachmentId, createCommentId, createInboxNotificationId, createManagedPool, createNotificationSettings, createThreadId, defineAiTool, deprecate, deprecateIf, detectDupes, entries, errorIf, freeze, generateCommentUrl, getMentionsFromCommentBody, getSubscriptionKey, html, htmlSafe, isChildCrdt, isCommentBodyLink, isCommentBodyMention, isCommentBodyText, isJsonArray, isJsonObject, isJsonScalar, isLiveNode, isNotificationChannelEnabled, isPlainObject, isRootCrdt, isStartsWithOperator, kInternal, keys, legacy_patchImmutableObject, lsonToJson, makeAbortController, makeEventSource, makePoller, makePosition, mapValues, memoizeOnSuccess, nanoid, nn, objectToQuery, patchLiveObjectKey, patchNotificationSettings, raise, resolveUsersInCommentBody, shallow, shallow2, stableStringify, stringifyCommentBody, throwUsageError, toAbsoluteUrl, toPlainLson, tryParseJson, url, urljoin, wait, withTimeout };