@liveblocks/core 2.25.0-aiprivatebeta16 → 2.25.0-aiprivatebeta17

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.cts CHANGED
@@ -3602,15 +3602,33 @@ type AbortAiPair = DefineCmd<"abort-ai", {
3602
3602
  }, {
3603
3603
  ok: true;
3604
3604
  }>;
3605
- type ToolResultData = JsonObject;
3606
- type ToolResultResponse<R extends ToolResultData = ToolResultData> = {
3605
+ type ToolResultResponse<R extends JsonObject = JsonObject> = Relax<({
3607
3606
  data: R;
3607
+ description?: string;
3608
+ } | {
3609
+ error: string;
3610
+ } | {
3611
+ cancel: true | /* reason */ string;
3612
+ })>;
3613
+ type NonEmptyString<T extends string> = T & {
3614
+ __nonEmpty: true;
3608
3615
  };
3616
+ type RenderableToolResultResponse<R extends JsonObject = JsonObject> = Relax<{
3617
+ type: "success";
3618
+ data: R;
3619
+ } | {
3620
+ type: "error";
3621
+ error: NonEmptyString<string>;
3622
+ } | {
3623
+ type: "cancelled";
3624
+ cancelled: true;
3625
+ reason?: string;
3626
+ }>;
3609
3627
  type SetToolResultPair = DefineCmd<"set-tool-result", {
3610
3628
  chatId: ChatId;
3611
3629
  messageId: MessageId;
3612
3630
  invocationId: string;
3613
- result: JsonObject;
3631
+ result: ToolResultResponse;
3614
3632
  generationOptions: AiGenerationOptions;
3615
3633
  }, {
3616
3634
  ok: true;
@@ -3675,7 +3693,7 @@ type AiToolDescription = {
3675
3693
  description?: string;
3676
3694
  parameters: JSONSchema7;
3677
3695
  };
3678
- type AiToolInvocationPart<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = Relax<AiReceivingToolInvocationPart | AiExecutingToolInvocationPart<A> | AiExecutedToolInvocationPart<A, R>>;
3696
+ type AiToolInvocationPart<A extends JsonObject = JsonObject, R extends JsonObject = JsonObject> = Relax<AiReceivingToolInvocationPart | AiExecutingToolInvocationPart<A> | AiExecutedToolInvocationPart<A, R>>;
3679
3697
  type AiReceivingToolInvocationPart = {
3680
3698
  type: "tool-invocation";
3681
3699
  stage: "receiving";
@@ -3690,13 +3708,13 @@ type AiExecutingToolInvocationPart<A extends JsonObject = JsonObject> = {
3690
3708
  name: string;
3691
3709
  args: A;
3692
3710
  };
3693
- type AiExecutedToolInvocationPart<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = {
3711
+ type AiExecutedToolInvocationPart<A extends JsonObject = JsonObject, R extends JsonObject = JsonObject> = {
3694
3712
  type: "tool-invocation";
3695
3713
  stage: "executed";
3696
3714
  invocationId: string;
3697
3715
  name: string;
3698
3716
  args: A;
3699
- result: R;
3717
+ result: RenderableToolResultResponse<R>;
3700
3718
  };
3701
3719
  type AiTextPart = {
3702
3720
  type: "text";
@@ -3844,14 +3862,14 @@ type InferFromSchema<T extends JSONSchema7> = JSONSchema7 extends T ? JsonObject
3844
3862
  type: "null";
3845
3863
  } ? null : Json;
3846
3864
 
3847
- type AiToolTypePack<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = {
3865
+ type AiToolTypePack<A extends JsonObject = JsonObject, R extends JsonObject = JsonObject> = {
3848
3866
  A: A;
3849
3867
  R: R;
3850
3868
  };
3851
3869
  type AskUserMessageInChatOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
3852
3870
  type SetToolResultOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
3853
- type AiToolInvocationProps<A extends JsonObject, R extends ToolResultData> = Resolve<DistributiveOmit<AiToolInvocationPart<A, R>, "type"> & {
3854
- respond: (result: ToolResultResponse<R>) => void;
3871
+ type AiToolInvocationProps<A extends JsonObject, R extends JsonObject> = Resolve<DistributiveOmit<AiToolInvocationPart<A, R>, "type"> & {
3872
+ respond: (...args: OptionalTupleUnless<R, [result: ToolResultResponse<R>]>) => void;
3855
3873
  /**
3856
3874
  * These are the inferred types for your tool call which you can pass down
3857
3875
  * to UI components, like so:
@@ -3871,25 +3889,25 @@ type AiToolInvocationProps<A extends JsonObject, R extends ToolResultData> = Res
3871
3889
  execute: AiToolExecuteCallback<A, R> | undefined;
3872
3890
  };
3873
3891
  }>;
3874
- type AiOpaqueToolInvocationProps = AiToolInvocationProps<JsonObject, ToolResultData>;
3892
+ type AiOpaqueToolInvocationProps = AiToolInvocationProps<JsonObject, JsonObject>;
3875
3893
  type AiToolExecuteContext = {
3876
3894
  name: string;
3877
3895
  invocationId: string;
3878
3896
  };
3879
- type AiToolExecuteCallback<A extends JsonObject, R extends ToolResultData> = (args: A, context: AiToolExecuteContext) => Awaitable<ToolResultResponse<R>>;
3880
- type AiToolDefinition<S extends JSONObjectSchema7, A extends JsonObject, R extends ToolResultData> = {
3897
+ 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>>;
3898
+ type AiToolDefinition<S extends JSONObjectSchema7, A extends JsonObject, R extends JsonObject> = {
3881
3899
  description?: string;
3882
3900
  parameters: S;
3883
3901
  execute?: AiToolExecuteCallback<A, R>;
3884
3902
  render?: (props: AiToolInvocationProps<A, R>) => unknown;
3885
3903
  };
3886
- type AiOpaqueToolDefinition = AiToolDefinition<JSONObjectSchema7, JsonObject, ToolResultData>;
3904
+ type AiOpaqueToolDefinition = AiToolDefinition<JSONObjectSchema7, JsonObject, JsonObject>;
3887
3905
  /**
3888
3906
  * Helper function to help infer the types of `args`, `render`, and `result`.
3889
3907
  * This function has no runtime implementation and is only needed to make it
3890
3908
  * possible for TypeScript to infer types.
3891
3909
  */
3892
- declare function defineAiTool<R extends ToolResultData>(): <const S extends JSONObjectSchema7>(def: AiToolDefinition<S, InferFromSchema<S> extends JsonObject ? InferFromSchema<S> : JsonObject, R>) => AiOpaqueToolDefinition;
3910
+ declare function defineAiTool<R extends JsonObject>(): <const S extends JSONObjectSchema7>(def: AiToolDefinition<S, InferFromSchema<S> extends JsonObject ? InferFromSchema<S> : JsonObject, R>) => AiOpaqueToolDefinition;
3893
3911
  type NavigationInfo = {
3894
3912
  /**
3895
3913
  * The message ID of the parent message, or null if there is no parent.
@@ -3935,7 +3953,7 @@ declare function createStore_forTools(): {
3935
3953
  getToolΣ: (name: string, chatId?: string) => DerivedSignal<AiOpaqueToolDefinition | undefined>;
3936
3954
  registerTool: (name: string, tool: AiOpaqueToolDefinition, chatId?: string) => () => void;
3937
3955
  };
3938
- declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>): {
3956
+ declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultResponse, options?: SetToolResultOptions) => Promise<SetToolResultResponse>): {
3939
3957
  getMessageById: (messageId: MessageId) => AiChatMessage | undefined;
3940
3958
  getChatMessagesForBranchΣ: (chatId: string, branch?: MessageId) => DerivedSignal<UiChatMessage[]>;
3941
3959
  createOptimistically: {
@@ -3991,7 +4009,7 @@ type Ai = {
3991
4009
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3992
4010
  abort: (messageId: MessageId) => Promise<AbortAiResponse>;
3993
4011
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3994
- setToolResult: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>;
4012
+ setToolResult: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultResponse, options?: SetToolResultOptions) => Promise<SetToolResultResponse>;
3995
4013
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3996
4014
  signals: {
3997
4015
  chatsΣ: DerivedSignal<AiChat[]>;
@@ -4796,4 +4814,4 @@ type EnsureJson<T> = T extends Json ? T : T extends Array<infer I> ? (EnsureJson
4796
4814
  [K in keyof T as EnsureJson<T[K]> extends never ? never : K]: EnsureJson<T[K]>;
4797
4815
  };
4798
4816
 
4799
- 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 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 ToolResultData, 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 };
4817
+ 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 };
package/dist/index.d.ts CHANGED
@@ -3602,15 +3602,33 @@ type AbortAiPair = DefineCmd<"abort-ai", {
3602
3602
  }, {
3603
3603
  ok: true;
3604
3604
  }>;
3605
- type ToolResultData = JsonObject;
3606
- type ToolResultResponse<R extends ToolResultData = ToolResultData> = {
3605
+ type ToolResultResponse<R extends JsonObject = JsonObject> = Relax<({
3607
3606
  data: R;
3607
+ description?: string;
3608
+ } | {
3609
+ error: string;
3610
+ } | {
3611
+ cancel: true | /* reason */ string;
3612
+ })>;
3613
+ type NonEmptyString<T extends string> = T & {
3614
+ __nonEmpty: true;
3608
3615
  };
3616
+ type RenderableToolResultResponse<R extends JsonObject = JsonObject> = Relax<{
3617
+ type: "success";
3618
+ data: R;
3619
+ } | {
3620
+ type: "error";
3621
+ error: NonEmptyString<string>;
3622
+ } | {
3623
+ type: "cancelled";
3624
+ cancelled: true;
3625
+ reason?: string;
3626
+ }>;
3609
3627
  type SetToolResultPair = DefineCmd<"set-tool-result", {
3610
3628
  chatId: ChatId;
3611
3629
  messageId: MessageId;
3612
3630
  invocationId: string;
3613
- result: JsonObject;
3631
+ result: ToolResultResponse;
3614
3632
  generationOptions: AiGenerationOptions;
3615
3633
  }, {
3616
3634
  ok: true;
@@ -3675,7 +3693,7 @@ type AiToolDescription = {
3675
3693
  description?: string;
3676
3694
  parameters: JSONSchema7;
3677
3695
  };
3678
- type AiToolInvocationPart<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = Relax<AiReceivingToolInvocationPart | AiExecutingToolInvocationPart<A> | AiExecutedToolInvocationPart<A, R>>;
3696
+ type AiToolInvocationPart<A extends JsonObject = JsonObject, R extends JsonObject = JsonObject> = Relax<AiReceivingToolInvocationPart | AiExecutingToolInvocationPart<A> | AiExecutedToolInvocationPart<A, R>>;
3679
3697
  type AiReceivingToolInvocationPart = {
3680
3698
  type: "tool-invocation";
3681
3699
  stage: "receiving";
@@ -3690,13 +3708,13 @@ type AiExecutingToolInvocationPart<A extends JsonObject = JsonObject> = {
3690
3708
  name: string;
3691
3709
  args: A;
3692
3710
  };
3693
- type AiExecutedToolInvocationPart<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = {
3711
+ type AiExecutedToolInvocationPart<A extends JsonObject = JsonObject, R extends JsonObject = JsonObject> = {
3694
3712
  type: "tool-invocation";
3695
3713
  stage: "executed";
3696
3714
  invocationId: string;
3697
3715
  name: string;
3698
3716
  args: A;
3699
- result: R;
3717
+ result: RenderableToolResultResponse<R>;
3700
3718
  };
3701
3719
  type AiTextPart = {
3702
3720
  type: "text";
@@ -3844,14 +3862,14 @@ type InferFromSchema<T extends JSONSchema7> = JSONSchema7 extends T ? JsonObject
3844
3862
  type: "null";
3845
3863
  } ? null : Json;
3846
3864
 
3847
- type AiToolTypePack<A extends JsonObject = JsonObject, R extends ToolResultData = ToolResultData> = {
3865
+ type AiToolTypePack<A extends JsonObject = JsonObject, R extends JsonObject = JsonObject> = {
3848
3866
  A: A;
3849
3867
  R: R;
3850
3868
  };
3851
3869
  type AskUserMessageInChatOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
3852
3870
  type SetToolResultOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
3853
- type AiToolInvocationProps<A extends JsonObject, R extends ToolResultData> = Resolve<DistributiveOmit<AiToolInvocationPart<A, R>, "type"> & {
3854
- respond: (result: ToolResultResponse<R>) => void;
3871
+ type AiToolInvocationProps<A extends JsonObject, R extends JsonObject> = Resolve<DistributiveOmit<AiToolInvocationPart<A, R>, "type"> & {
3872
+ respond: (...args: OptionalTupleUnless<R, [result: ToolResultResponse<R>]>) => void;
3855
3873
  /**
3856
3874
  * These are the inferred types for your tool call which you can pass down
3857
3875
  * to UI components, like so:
@@ -3871,25 +3889,25 @@ type AiToolInvocationProps<A extends JsonObject, R extends ToolResultData> = Res
3871
3889
  execute: AiToolExecuteCallback<A, R> | undefined;
3872
3890
  };
3873
3891
  }>;
3874
- type AiOpaqueToolInvocationProps = AiToolInvocationProps<JsonObject, ToolResultData>;
3892
+ type AiOpaqueToolInvocationProps = AiToolInvocationProps<JsonObject, JsonObject>;
3875
3893
  type AiToolExecuteContext = {
3876
3894
  name: string;
3877
3895
  invocationId: string;
3878
3896
  };
3879
- type AiToolExecuteCallback<A extends JsonObject, R extends ToolResultData> = (args: A, context: AiToolExecuteContext) => Awaitable<ToolResultResponse<R>>;
3880
- type AiToolDefinition<S extends JSONObjectSchema7, A extends JsonObject, R extends ToolResultData> = {
3897
+ 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>>;
3898
+ type AiToolDefinition<S extends JSONObjectSchema7, A extends JsonObject, R extends JsonObject> = {
3881
3899
  description?: string;
3882
3900
  parameters: S;
3883
3901
  execute?: AiToolExecuteCallback<A, R>;
3884
3902
  render?: (props: AiToolInvocationProps<A, R>) => unknown;
3885
3903
  };
3886
- type AiOpaqueToolDefinition = AiToolDefinition<JSONObjectSchema7, JsonObject, ToolResultData>;
3904
+ type AiOpaqueToolDefinition = AiToolDefinition<JSONObjectSchema7, JsonObject, JsonObject>;
3887
3905
  /**
3888
3906
  * Helper function to help infer the types of `args`, `render`, and `result`.
3889
3907
  * This function has no runtime implementation and is only needed to make it
3890
3908
  * possible for TypeScript to infer types.
3891
3909
  */
3892
- declare function defineAiTool<R extends ToolResultData>(): <const S extends JSONObjectSchema7>(def: AiToolDefinition<S, InferFromSchema<S> extends JsonObject ? InferFromSchema<S> : JsonObject, R>) => AiOpaqueToolDefinition;
3910
+ declare function defineAiTool<R extends JsonObject>(): <const S extends JSONObjectSchema7>(def: AiToolDefinition<S, InferFromSchema<S> extends JsonObject ? InferFromSchema<S> : JsonObject, R>) => AiOpaqueToolDefinition;
3893
3911
  type NavigationInfo = {
3894
3912
  /**
3895
3913
  * The message ID of the parent message, or null if there is no parent.
@@ -3935,7 +3953,7 @@ declare function createStore_forTools(): {
3935
3953
  getToolΣ: (name: string, chatId?: string) => DerivedSignal<AiOpaqueToolDefinition | undefined>;
3936
3954
  registerTool: (name: string, tool: AiOpaqueToolDefinition, chatId?: string) => () => void;
3937
3955
  };
3938
- declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>): {
3956
+ declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultResponse, options?: SetToolResultOptions) => Promise<SetToolResultResponse>): {
3939
3957
  getMessageById: (messageId: MessageId) => AiChatMessage | undefined;
3940
3958
  getChatMessagesForBranchΣ: (chatId: string, branch?: MessageId) => DerivedSignal<UiChatMessage[]>;
3941
3959
  createOptimistically: {
@@ -3991,7 +4009,7 @@ type Ai = {
3991
4009
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3992
4010
  abort: (messageId: MessageId) => Promise<AbortAiResponse>;
3993
4011
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3994
- setToolResult: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>;
4012
+ setToolResult: (chatId: string, messageId: MessageId, invocationId: string, result: ToolResultResponse, options?: SetToolResultOptions) => Promise<SetToolResultResponse>;
3995
4013
  /** @private This API will change, and is not considered stable. DO NOT RELY on it. */
3996
4014
  signals: {
3997
4015
  chatsΣ: DerivedSignal<AiChat[]>;
@@ -4796,4 +4814,4 @@ type EnsureJson<T> = T extends Json ? T : T extends Array<infer I> ? (EnsureJson
4796
4814
  [K in keyof T as EnsureJson<T[K]> extends never ? never : K]: EnsureJson<T[K]>;
4797
4815
  };
4798
4816
 
4799
- 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 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 ToolResultData, 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 };
4817
+ 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 };
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.25.0-aiprivatebeta16";
9
+ var PKG_VERSION = "2.25.0-aiprivatebeta17";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -3925,12 +3925,13 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
3925
3925
  }
3926
3926
  seenToolCallIds.add(toolCall.invocationId);
3927
3927
  const toolDef = toolsStore.getTool\u03A3(toolCall.name, message.chatId).get();
3928
- const respondSync = (result) => {
3928
+ const respondSync = (...args) => {
3929
+ const [result] = args;
3929
3930
  setToolResult(
3930
3931
  message.chatId,
3931
3932
  message.id,
3932
3933
  toolCall.invocationId,
3933
- result.data
3934
+ result ?? { data: {} }
3934
3935
  // TODO Pass in AiGenerationOptions here, or make the backend use the same options
3935
3936
  ).catch((err) => {
3936
3937
  error2(
@@ -3945,7 +3946,7 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
3945
3946
  name: toolCall.name,
3946
3947
  invocationId: toolCall.invocationId
3947
3948
  });
3948
- respondSync(result);
3949
+ respondSync(result ?? void 0);
3949
3950
  })().catch((err) => {
3950
3951
  error2(
3951
3952
  `Error trying to respond to tool-call: ${String(err)} (in execute())`
@@ -4459,7 +4460,7 @@ function makeCreateSocketDelegateForAi(baseUrl, WebSocketPolyfill) {
4459
4460
  }
4460
4461
  const url2 = new URL(baseUrl);
4461
4462
  url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
4462
- url2.pathname = "/ai/v3";
4463
+ url2.pathname = "/ai/v4";
4463
4464
  if (authValue.type === "secret") {
4464
4465
  url2.searchParams.set("tok", authValue.token.raw);
4465
4466
  } else if (authValue.type === "public") {