@liveblocks/core 2.25.0-aiprivatebeta1 → 2.25.0-aiprivatebeta11

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
- import { JSONSchema4 } from 'json-schema';
2
- import { ComponentType } from 'react';
1
+ import { JSONSchema7 } from 'json-schema';
3
2
 
4
3
  /**
5
4
  * Throws an error if multiple copies of a Liveblocks package are being loaded
@@ -3527,7 +3526,6 @@ type ISODateString = Brand<string, "ISODateString">;
3527
3526
  type ChatId = string;
3528
3527
  type MessageId = Brand<`ms_${string}`, "MessageId">;
3529
3528
  type CmdId = Brand<string, "CmdId">;
3530
- type ClientId = Brand<string, "ClientId">;
3531
3529
  type CopilotId = Brand<`co_${string}`, "CopilotId">;
3532
3530
  type ServerAiMsg = ServerCmdResponse | ServerEvent;
3533
3531
  type DefineCmd<CmdName extends string, TRequest, TResponse> = [
@@ -3540,17 +3538,17 @@ type DefineCmd<CmdName extends string, TRequest, TResponse> = [
3540
3538
  cmdId: CmdId;
3541
3539
  } & TResponse>
3542
3540
  ];
3543
- type CommandPair = GetChatsPair | CreateChatPair | DeleteChatPair | GetMessageTreePair | AddUserMessagePair | DeleteMessagePair | ClearChatPair | AskAIPair | AbortAiPair;
3541
+ type CommandPair = GetChatsPair | GetOrCreateChatPair | DeleteChatPair | GetMessageTreePair | DeleteMessagePair | ClearChatPair | AskInChatPair | AbortAiPair | SetToolResultPair;
3544
3542
  type ServerCmdResponse<T extends CommandPair = CommandPair> = T[1];
3545
3543
  type GetChatsResponse = ServerCmdResponse<GetChatsPair>;
3546
- type CreateChatResponse = ServerCmdResponse<CreateChatPair>;
3544
+ type GetOrCreateChatResponse = ServerCmdResponse<GetOrCreateChatPair>;
3547
3545
  type DeleteChatResponse = ServerCmdResponse<DeleteChatPair>;
3548
3546
  type GetMessageTreeResponse = ServerCmdResponse<GetMessageTreePair>;
3549
- type AddUserMessageResponse = ServerCmdResponse<AddUserMessagePair>;
3550
3547
  type DeleteMessageResponse = ServerCmdResponse<DeleteMessagePair>;
3551
3548
  type ClearChatResponse = ServerCmdResponse<ClearChatPair>;
3552
- type AskAiResponse = ServerCmdResponse<AskAIPair>;
3549
+ type AskInChatResponse = ServerCmdResponse<AskInChatPair>;
3553
3550
  type AbortAiResponse = ServerCmdResponse<AbortAiPair>;
3551
+ type SetToolResultResponse = ServerCmdResponse<SetToolResultPair>;
3554
3552
  type GetChatsPair = DefineCmd<"get-chats", {
3555
3553
  cursor?: Cursor;
3556
3554
  pageSize?: number;
@@ -3558,12 +3556,15 @@ type GetChatsPair = DefineCmd<"get-chats", {
3558
3556
  chats: AiChat[];
3559
3557
  nextCursor: Cursor | null;
3560
3558
  }>;
3561
- type CreateChatPair = DefineCmd<"create-chat", // XXXX Rename to "upsert-chat"?
3562
- {
3559
+ type CreateChatOptions = {
3560
+ /** A human-friendly title for the chat. If not set, it will get auto-generated after the first response. */
3561
+ title?: string;
3562
+ /** Arbitrary metadata to record for this chat. This can be later used to filter the list of chats by metadata. */
3563
+ metadata?: Record<string, string | string[]>;
3564
+ };
3565
+ type GetOrCreateChatPair = DefineCmd<"get-or-create-chat", {
3563
3566
  id: ChatId;
3564
- name?: string;
3565
- ephemeral: boolean;
3566
- metadata: Record<string, string | string[]>;
3567
+ options?: CreateChatOptions;
3567
3568
  }, {
3568
3569
  chat: AiChat;
3569
3570
  }>;
@@ -3578,14 +3579,6 @@ type GetMessageTreePair = DefineCmd<"get-message-tree", {
3578
3579
  chat: AiChat;
3579
3580
  messages: AiChatMessage[];
3580
3581
  }>;
3581
- type AddUserMessagePair = DefineCmd<"add-user-message", {
3582
- id: MessageId;
3583
- chatId: ChatId;
3584
- parentMessageId: MessageId | null;
3585
- content: AiUserContentPart[];
3586
- }, {
3587
- message: AiUserMessage;
3588
- }>;
3589
3582
  type DeleteMessagePair = DefineCmd<"delete-message", {
3590
3583
  chatId: ChatId;
3591
3584
  messageId: MessageId;
@@ -3598,10 +3591,27 @@ type ClearChatPair = DefineCmd<"clear-chat", {
3598
3591
  }, {
3599
3592
  chatId: ChatId;
3600
3593
  }>;
3601
- type AskAIPair = DefineCmd<"ask-ai", {
3594
+ type AiGenerationOptions = {
3595
+ /**
3596
+ * The Copilot ID to use for this request. If not provided, a built-in
3597
+ * default Copilot will be used instead of one that you configured via the
3598
+ * dashboard.
3599
+ */
3600
+ copilotId?: CopilotId;
3601
+ stream?: boolean;
3602
+ tools?: AiToolDescription[];
3603
+ knowledge?: AiKnowledgeSource[];
3604
+ timeout?: number;
3605
+ };
3606
+ type AskInChatPair = DefineCmd<"ask-in-chat", {
3602
3607
  chatId: ChatId;
3603
3608
  /** The chat message to use as the source to create the assistant response. */
3604
- sourceMessageId: MessageId;
3609
+ sourceMessage: // An existing message ID to reply to
3610
+ MessageId | {
3611
+ id: MessageId;
3612
+ parentMessageId: MessageId | null;
3613
+ content: AiUserContentPart[];
3614
+ };
3605
3615
  /**
3606
3616
  * The new (!) message ID to output the assistant response into. This ID
3607
3617
  * should be a non-existing message ID, optimistically assigned by the
@@ -3609,32 +3619,29 @@ type AskAIPair = DefineCmd<"ask-ai", {
3609
3619
  * message ID.
3610
3620
  */
3611
3621
  targetMessageId: MessageId;
3612
- /**
3613
- * The Copilot ID to use for this request. If not provided, a built-in
3614
- * default Copilot will be used instead of one that you configured via the
3615
- * dashboard.
3616
- */
3617
- copilotId?: CopilotId;
3618
- /**
3619
- * A client ID unique to this command. Later delta and settle messages will
3620
- * reference this client ID, which is important to ensure that tool calls
3621
- * with side effects will only get executed once, and only by the client
3622
- * that originally made the request that produced the tool call.
3623
- */
3624
- clientId: ClientId;
3625
- stream: boolean;
3626
- tools?: AiToolDefinition[];
3627
- toolChoice?: ToolChoice;
3628
- context?: AiChatContext[];
3629
- timeout: number;
3622
+ generationOptions: AiGenerationOptions;
3630
3623
  }, {
3631
- message: AiChatMessage;
3624
+ sourceMessage?: AiChatMessage;
3625
+ targetMessage: AiChatMessage;
3632
3626
  }>;
3633
3627
  type AbortAiPair = DefineCmd<"abort-ai", {
3634
3628
  messageId: MessageId;
3635
3629
  }, {
3636
3630
  ok: true;
3637
3631
  }>;
3632
+ type ToolResultData = Json;
3633
+ type SetToolResultPair = DefineCmd<"set-tool-result", {
3634
+ chatId: ChatId;
3635
+ messageId: MessageId;
3636
+ toolCallId: string;
3637
+ result: ToolResultData;
3638
+ generationOptions: AiGenerationOptions;
3639
+ }, {
3640
+ ok: true;
3641
+ message: AiChatMessage;
3642
+ } | {
3643
+ ok: false;
3644
+ }>;
3638
3645
  type ServerEvent = RebootedEvent | CmdFailedEvent | ErrorServerEvent | SyncServerEvent | DeltaServerEvent | SettleServerEvent;
3639
3646
  type RebootedEvent = {
3640
3647
  event: "rebooted";
@@ -3664,8 +3671,6 @@ type SyncServerEvent = {
3664
3671
  type DeltaServerEvent = {
3665
3672
  event: "delta";
3666
3673
  id: MessageId;
3667
- /** The client ID that originally made the request that led to this event */
3668
- clientId: ClientId;
3669
3674
  delta: AiAssistantDeltaUpdate;
3670
3675
  };
3671
3676
  /**
@@ -3675,29 +3680,43 @@ type DeltaServerEvent = {
3675
3680
  */
3676
3681
  type SettleServerEvent = {
3677
3682
  event: "settle";
3678
- /** The client ID that originally made the request that led to this event */
3679
- clientId: ClientId;
3680
- message: AiCompletedAssistantMessage | AiFailedAssistantMessage;
3683
+ message: AiAwaitingToolAssistantMessage | AiCompletedAssistantMessage | AiFailedAssistantMessage;
3681
3684
  };
3682
3685
  type AiChat = {
3683
3686
  id: ChatId;
3684
- name: string;
3685
- ephemeral: boolean;
3687
+ title: string;
3686
3688
  metadata: Record<string, string | string[]>;
3687
3689
  createdAt: ISODateString;
3688
3690
  lastMessageAt?: ISODateString;
3689
3691
  deletedAt?: ISODateString;
3690
3692
  };
3691
- type AiToolDefinition = {
3693
+ type AiToolDescription = {
3692
3694
  name: string;
3693
3695
  description?: string;
3694
- parameters: JsonObject;
3696
+ parameters: JSONSchema7;
3695
3697
  };
3696
- type AiToolCallPart = {
3697
- type: "tool-call";
3698
+ type AiToolInvocationPart<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = Relax<AiReceivingToolInvocationPart | AiExecutingToolInvocationPart<A> | AiExecutedToolInvocationPart<A, R>>;
3699
+ type AiReceivingToolInvocationPart = {
3700
+ type: "tool-invocation";
3701
+ status: "receiving";
3698
3702
  toolCallId: string;
3699
3703
  toolName: string;
3700
- args: unknown;
3704
+ partialArgs: Json;
3705
+ };
3706
+ type AiExecutingToolInvocationPart<A extends JsonObject = JsonObject> = {
3707
+ type: "tool-invocation";
3708
+ status: "executing";
3709
+ toolCallId: string;
3710
+ toolName: string;
3711
+ args: A;
3712
+ };
3713
+ type AiExecutedToolInvocationPart<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = {
3714
+ type: "tool-invocation";
3715
+ status: "executed";
3716
+ toolCallId: string;
3717
+ toolName: string;
3718
+ args: A;
3719
+ result: R;
3701
3720
  };
3702
3721
  type AiTextPart = {
3703
3722
  type: "text";
@@ -3717,7 +3736,6 @@ type AiReasoningDelta = Relax<{
3717
3736
  type AiReasoningPart = {
3718
3737
  type: "reasoning";
3719
3738
  text: string;
3720
- signature?: string;
3721
3739
  };
3722
3740
  type AiUploadedImagePart = {
3723
3741
  type: "image";
@@ -3727,12 +3745,8 @@ type AiUploadedImagePart = {
3727
3745
  mimeType: string;
3728
3746
  };
3729
3747
  type AiUserContentPart = AiTextPart | AiUploadedImagePart;
3730
- type AiAssistantContentPart = AiReasoningPart | AiTextPart | AiToolCallPart;
3731
- type AiAssistantDeltaUpdate = AiAssistantContentPart | AiTextDelta | AiReasoningDelta;
3732
- type ToolChoice = "auto" | "required" | "none" | {
3733
- type: "tool";
3734
- toolName: string;
3735
- };
3748
+ type AiAssistantContentPart = AiReasoningPart | AiTextPart | AiToolInvocationPart;
3749
+ type AiAssistantDeltaUpdate = AiTextDelta | AiReasoningDelta | AiExecutingToolInvocationPart;
3736
3750
  type AiUserMessage = {
3737
3751
  id: MessageId;
3738
3752
  chatId: ChatId;
@@ -3742,63 +3756,178 @@ type AiUserMessage = {
3742
3756
  createdAt: ISODateString;
3743
3757
  deletedAt?: ISODateString;
3744
3758
  };
3745
- type AiAssistantMessage = Relax<AiCompletedAssistantMessage | AiPendingAssistantMessage | AiFailedAssistantMessage>;
3746
- type AiCompletedAssistantMessage = {
3759
+ type AiAssistantMessage = Relax<AiGeneratingAssistantMessage | AiAwaitingToolAssistantMessage | AiCompletedAssistantMessage | AiFailedAssistantMessage>;
3760
+ type AiGeneratingAssistantMessage = {
3747
3761
  id: MessageId;
3748
3762
  chatId: ChatId;
3749
3763
  parentId: MessageId | null;
3750
3764
  role: "assistant";
3751
- content: AiAssistantContentPart[];
3752
3765
  createdAt: ISODateString;
3753
3766
  deletedAt?: ISODateString;
3754
- status: "completed";
3767
+ status: "generating";
3768
+ contentSoFar: AiAssistantContentPart[];
3755
3769
  };
3756
- type AiFailedAssistantMessage = {
3770
+ type AiAwaitingToolAssistantMessage = {
3757
3771
  id: MessageId;
3758
3772
  chatId: ChatId;
3759
3773
  parentId: MessageId | null;
3760
3774
  role: "assistant";
3761
3775
  createdAt: ISODateString;
3762
3776
  deletedAt?: ISODateString;
3763
- status: "failed";
3777
+ status: "awaiting-tool";
3764
3778
  contentSoFar: AiAssistantContentPart[];
3765
- errorReason: string;
3766
3779
  };
3767
- type AiPendingAssistantMessage = {
3780
+ type AiCompletedAssistantMessage = {
3781
+ id: MessageId;
3782
+ chatId: ChatId;
3783
+ parentId: MessageId | null;
3784
+ role: "assistant";
3785
+ content: AiAssistantContentPart[];
3786
+ createdAt: ISODateString;
3787
+ deletedAt?: ISODateString;
3788
+ status: "completed";
3789
+ };
3790
+ type AiFailedAssistantMessage = {
3768
3791
  id: MessageId;
3769
3792
  chatId: ChatId;
3770
3793
  parentId: MessageId | null;
3771
3794
  role: "assistant";
3772
3795
  createdAt: ISODateString;
3773
3796
  deletedAt?: ISODateString;
3774
- status: "pending";
3797
+ status: "failed";
3775
3798
  contentSoFar: AiAssistantContentPart[];
3799
+ errorReason: string;
3776
3800
  };
3777
3801
  type AiChatMessage = AiUserMessage | AiAssistantMessage;
3778
- type AiChatContext = {
3779
- value: string;
3802
+ type AiKnowledgeSource = {
3780
3803
  description: string;
3804
+ value: Json;
3781
3805
  };
3782
3806
 
3783
- type ClientToolDefinition = {
3807
+ type InferFromSchema<T extends JSONSchema7> = JSONSchema7 extends T ? JsonObject : T extends {
3808
+ type: "object";
3809
+ properties: Record<string, JSONSchema7>;
3810
+ required: readonly string[];
3811
+ } ? Resolve<{
3812
+ -readonly [K in keyof T["properties"] as K extends string ? K extends Extract<K, T["required"][number]> ? K : never : never]: InferFromSchema<T["properties"][K]>;
3813
+ } & {
3814
+ -readonly [K in keyof T["properties"] as K extends string ? K extends Extract<K, T["required"][number]> ? never : K : never]?: InferFromSchema<T["properties"][K]>;
3815
+ }> : T extends {
3816
+ type: "object";
3817
+ properties: Record<string, JSONSchema7>;
3818
+ } ? {
3819
+ -readonly [K in keyof T["properties"]]?: InferFromSchema<T["properties"][K]>;
3820
+ } : T extends {
3821
+ type: "string" | "number" | "boolean";
3822
+ enum: readonly (infer U)[];
3823
+ } ? U : T extends {
3824
+ type: "string";
3825
+ } ? string : T extends {
3826
+ type: "number";
3827
+ } ? number : T extends {
3828
+ type: "boolean";
3829
+ } ? boolean : T extends {
3830
+ type: "null";
3831
+ } ? null : T extends {
3832
+ type: "array";
3833
+ items: JSONSchema7;
3834
+ } ? InferFromSchema<T["items"]>[] : unknown;
3835
+ type AiToolTypePack<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = {
3836
+ A: A;
3837
+ R: R;
3838
+ };
3839
+ type AskUserMessageInChatOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
3840
+ type SetToolResultOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
3841
+ type AiToolInvocationProps<A extends JsonObject, R extends ToolResultData> = Resolve<DistributiveOmit<AiToolInvocationPart<A, R>, "type"> & {
3842
+ respond: (result: R) => void;
3843
+ /**
3844
+ * These are the inferred types for your tool call which you can pass down
3845
+ * to UI components, like so:
3846
+ *
3847
+ * <AiTool.Confirmation
3848
+ * types={types}
3849
+ * confirm={
3850
+ * // Now fully type-safe!
3851
+ * (args) => result
3852
+ * } />
3853
+ *
3854
+ * This will make your AiTool.Confirmation component aware of the types for
3855
+ * `args` and `result`.
3856
+ */
3857
+ types: AiToolTypePack<A, R>;
3858
+ [kInternal]: {
3859
+ execute: AiToolExecuteCallback<A, R> | undefined;
3860
+ };
3861
+ }>;
3862
+ type AiOpaqueToolInvocationProps = AiToolInvocationProps<JsonObject, ToolResultData>;
3863
+ type AiToolExecuteContext = {
3864
+ toolName: string;
3865
+ toolCallId: string;
3866
+ };
3867
+ type AiToolExecuteCallback<A extends JsonObject, R extends ToolResultData> = (args: A, context: AiToolExecuteContext) => Awaitable<R>;
3868
+ type AiToolDefinition<S extends JSONObjectSchema7, A extends JsonObject, R extends ToolResultData> = {
3784
3869
  description?: string;
3785
- parameters: JSONSchema4;
3786
- render: ComponentType<{
3787
- args: any;
3788
- }>;
3789
- execute?: never;
3870
+ parameters: S;
3871
+ execute?: AiToolExecuteCallback<A, R>;
3872
+ render?: (props: AiToolInvocationProps<A, R>) => unknown;
3790
3873
  };
3874
+ type AiOpaqueToolDefinition = AiToolDefinition<JSONObjectSchema7, JsonObject, ToolResultData>;
3875
+ type JSONObjectSchema7 = JSONSchema7 & {
3876
+ type: "object";
3877
+ };
3878
+ /**
3879
+ * Helper function to help infer the types of `args`, `render`, and `result`.
3880
+ * This function has no runtime implementation and is only needed to make it
3881
+ * possible for TypeScript to infer types.
3882
+ */
3883
+ declare function defineAiTool<R extends ToolResultData>(): <const S extends JSONObjectSchema7>(def: AiToolDefinition<S, InferFromSchema<S> extends JsonObject ? InferFromSchema<S> : JsonObject, R>) => AiOpaqueToolDefinition;
3791
3884
  type UiChatMessage = AiChatMessage & {
3792
- prev: MessageId | null;
3793
- next: MessageId | null;
3885
+ navigation: {
3886
+ /**
3887
+ * The message ID of the parent message, or null if there is no parent.
3888
+ */
3889
+ parent: MessageId | null;
3890
+ /**
3891
+ * The message ID of the left sibling message, or null if there is no left sibling.
3892
+ */
3893
+ prev: MessageId | null;
3894
+ /**
3895
+ * The message ID of the right sibling message, or null if there is no right sibling.
3896
+ */
3897
+ next: MessageId | null;
3898
+ };
3794
3899
  };
3795
3900
  type UiUserMessage = AiUserMessage & {
3796
- prev: MessageId | null;
3797
- next: MessageId | null;
3901
+ navigation: {
3902
+ /**
3903
+ * The message ID of the parent message, or null if there is no parent.
3904
+ */
3905
+ parent: MessageId | null;
3906
+ /**
3907
+ * The message ID of the left sibling message, or null if there is no left sibling.
3908
+ */
3909
+ prev: MessageId | null;
3910
+ /**
3911
+ * The message ID of the right sibling message, or null if there is no right sibling.
3912
+ */
3913
+ next: MessageId | null;
3914
+ };
3798
3915
  };
3799
3916
  type UiAssistantMessage = AiAssistantMessage & {
3800
- prev: MessageId | null;
3801
- next: MessageId | null;
3917
+ navigation: {
3918
+ /**
3919
+ * The message ID of the parent message, or null if there is no parent.
3920
+ */
3921
+ parent: MessageId | null;
3922
+ /**
3923
+ * The message ID of the left sibling message, or null if there is no left sibling.
3924
+ */
3925
+ prev: MessageId | null;
3926
+ /**
3927
+ * The message ID of the right sibling message, or null if there is no right sibling.
3928
+ */
3929
+ next: MessageId | null;
3930
+ };
3802
3931
  };
3803
3932
  type AiContext = {
3804
3933
  staticSessionInfoSig: Signal<StaticSessionInfo | null>;
@@ -3810,31 +3939,26 @@ type AiContext = {
3810
3939
  chatsStore: ReturnType<typeof createStore_forUserAiChats>;
3811
3940
  toolsStore: ReturnType<typeof createStore_forTools>;
3812
3941
  messagesStore: ReturnType<typeof createStore_forChatMessages>;
3813
- contextByChatId: Map<string, Set<AiChatContext>>;
3814
- };
3815
- type CreateChatOptions = {
3816
- ephemeral?: boolean;
3817
- metadata?: AiChat["metadata"];
3818
- };
3819
- type AskAiOptions = {
3820
- copilotId?: CopilotId;
3821
- stream?: boolean;
3822
- timeout?: number;
3942
+ knowledge: KnowledgeStack;
3823
3943
  };
3944
+ type LayerKey = Brand<string, "LayerKey">;
3945
+ declare class KnowledgeStack {
3946
+ #private;
3947
+ constructor();
3948
+ registerLayer(uniqueLayerId: string): LayerKey;
3949
+ deregisterLayer(layerKey: LayerKey): void;
3950
+ get(): AiKnowledgeSource[];
3951
+ invalidate(): void;
3952
+ updateKnowledge(layerKey: LayerKey, key: string, data: AiKnowledgeSource | null): void;
3953
+ }
3824
3954
  declare function createStore_forTools(): {
3825
- getToolCallByNameΣ: (chatId: string, toolName: string) => Signal<ClientToolDefinition | undefined>;
3826
- getToolsForChat: (chatId: string) => {
3827
- name: string;
3828
- definition: ClientToolDefinition;
3829
- }[];
3830
- addToolDefinition: (chatId: string, name: string, definition: ClientToolDefinition) => void;
3831
- removeToolDefinition: (chatId: string, toolName: string) => void;
3955
+ getToolDescriptions: (chatId: string) => AiToolDescription[];
3956
+ getToolΣ: (name: string, chatId?: string) => DerivedSignal<AiOpaqueToolDefinition | undefined>;
3957
+ registerTool: (name: string, tool: AiOpaqueToolDefinition, chatId?: string) => () => void;
3832
3958
  };
3833
- declare function createStore_forChatMessages(): {
3959
+ declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>): {
3834
3960
  getMessageById: (messageId: MessageId) => AiChatMessage | undefined;
3835
3961
  getChatMessagesForBranchΣ: (chatId: string, branch?: MessageId) => DerivedSignal<UiChatMessage[]>;
3836
- getMessagesForChatΣ: (chatId: string) => DerivedSignal<AiChatMessage[]>;
3837
- getLatestUserMessageAncestor: (chatId: string, messageId: MessageId) => MessageId | null;
3838
3962
  createOptimistically: {
3839
3963
  (chatId: string, role: "user", parentId: MessageId | null, content: AiUserContentPart[]): MessageId;
3840
3964
  (chatId: string, role: "assistant", parentId: MessageId | null): MessageId;
@@ -3845,45 +3969,66 @@ declare function createStore_forChatMessages(): {
3845
3969
  removeByChatId: (chatId: string) => void;
3846
3970
  addDelta: (messageId: MessageId, delta: AiAssistantDeltaUpdate) => void;
3847
3971
  failAllPending: () => void;
3972
+ allowAutoExecuteToolCall(messageId: MessageId): void;
3848
3973
  };
3849
3974
  declare function createStore_forUserAiChats(): {
3850
3975
  chatsΣ: DerivedSignal<AiChat[]>;
3976
+ getChatById: (chatId: string) => AiChat | undefined;
3851
3977
  upsert: (chat: AiChat) => void;
3852
3978
  upsertMany: (chats: AiChat[]) => void;
3853
- remove: (chatId: string) => void;
3979
+ markDeleted: (chatId: string) => void;
3854
3980
  };
3981
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3855
3982
  type Ai = {
3856
3983
  [kInternal]: {
3857
- debugContext: () => AiContext;
3984
+ context: AiContext;
3858
3985
  };
3859
3986
  connect: () => void;
3860
3987
  reconnect: () => void;
3861
3988
  disconnect: () => void;
3862
3989
  getStatus: () => Status;
3990
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3863
3991
  getChats: (options?: {
3864
3992
  cursor?: Cursor;
3865
3993
  }) => Promise<GetChatsResponse>;
3866
- createChat: (chatId: string, // A unique identifier
3867
- name?: string, // A human-friendly "title"
3868
- options?: CreateChatOptions) => Promise<CreateChatResponse>;
3994
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3995
+ getOrCreateChat: (
3996
+ /** A unique identifier for the chat. */
3997
+ chatId: string, options?: CreateChatOptions) => Promise<GetOrCreateChatResponse>;
3998
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3869
3999
  deleteChat: (chatId: string) => Promise<DeleteChatResponse>;
4000
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3870
4001
  getMessageTree: (chatId: string) => Promise<GetMessageTreeResponse>;
4002
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3871
4003
  deleteMessage: (chatId: string, messageId: MessageId) => Promise<DeleteMessageResponse>;
4004
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3872
4005
  clearChat: (chatId: string) => Promise<ClearChatResponse>;
3873
- addUserMessage: (chatId: string, parentMessageId: MessageId | null, message: string) => Promise<AddUserMessageResponse>;
3874
- ask: (chatId: string, messageId: MessageId, options?: AskAiOptions) => Promise<AskAiResponse>;
3875
- regenerateMessage: (chatId: string, messageId: MessageId, options?: AskAiOptions) => Promise<AskAiResponse>;
3876
- addUserMessageAndAsk: (chatId: string, parentMessageId: MessageId | null, message: string, options?: AskAiOptions) => Promise<AskAiResponse>;
4006
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4007
+ askUserMessageInChat: (chatId: string, userMessage: MessageId | {
4008
+ id: MessageId;
4009
+ parentMessageId: MessageId | null;
4010
+ content: AiUserContentPart[];
4011
+ }, targetMessageId: MessageId, options?: AskUserMessageInChatOptions) => Promise<AskInChatResponse>;
4012
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3877
4013
  abort: (messageId: MessageId) => Promise<AbortAiResponse>;
4014
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4015
+ setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>;
4016
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3878
4017
  signals: {
3879
4018
  chatsΣ: DerivedSignal<AiChat[]>;
3880
4019
  getChatMessagesForBranchΣ(chatId: string, branch?: MessageId): DerivedSignal<UiChatMessage[]>;
3881
- getMessagesForChatΣ(chatId: string): DerivedSignal<AiChatMessage[]>;
3882
- getToolDefinitionΣ(chatId: string, toolName: string): Signal<ClientToolDefinition | undefined>;
4020
+ getToolΣ(name: string, chatId?: string): DerivedSignal<AiOpaqueToolDefinition | undefined>;
3883
4021
  };
3884
- registerChatContext: (chatId: string, data: AiChatContext) => () => void;
3885
- registerChatTool: (chatId: string, name: string, definition: ClientToolDefinition) => void;
3886
- unregisterChatTool: (chatId: string, toolName: string) => void;
4022
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4023
+ getChatById: (chatId: string) => AiChat | undefined;
4024
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4025
+ registerKnowledgeLayer: (uniqueLayerId: string) => LayerKey;
4026
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4027
+ deregisterKnowledgeLayer: (layerKey: LayerKey) => void;
4028
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4029
+ updateKnowledge: (layerKey: LayerKey, data: AiKnowledgeSource, key?: string) => void;
4030
+ /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
4031
+ registerTool: (name: string, tool: AiOpaqueToolDefinition, chatId?: string) => () => void;
3887
4032
  };
3888
4033
 
3889
4034
  type CommentBodyParagraphElementArgs = {
@@ -4674,4 +4819,4 @@ declare const CommentsApiError: typeof HttpError;
4674
4819
  /** @deprecated Use HttpError instead. */
4675
4820
  declare const NotificationsApiError: typeof HttpError;
4676
4821
 
4677
- export { type AckOp, type ActivityData, type AiAssistantContentPart, type AiChat, type AiChatContext, 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 ClientToolDefinition, 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 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 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, 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 };
4822
+ 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 };