@liveblocks/core 2.25.0-aiprivatebeta10 → 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.cjs +161 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -15
- package/dist/index.d.ts +14 -15
- package/dist/index.js +71 -52
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -3818,6 +3818,9 @@ type InferFromSchema<T extends JSONSchema7> = JSONSchema7 extends T ? JsonObject
|
|
|
3818
3818
|
} ? {
|
|
3819
3819
|
-readonly [K in keyof T["properties"]]?: InferFromSchema<T["properties"][K]>;
|
|
3820
3820
|
} : T extends {
|
|
3821
|
+
type: "string" | "number" | "boolean";
|
|
3822
|
+
enum: readonly (infer U)[];
|
|
3823
|
+
} ? U : T extends {
|
|
3821
3824
|
type: "string";
|
|
3822
3825
|
} ? string : T extends {
|
|
3823
3826
|
type: "number";
|
|
@@ -3833,6 +3836,8 @@ type AiToolTypePack<A extends JsonObject = JsonObject, R extends ToolResultData
|
|
|
3833
3836
|
A: A;
|
|
3834
3837
|
R: R;
|
|
3835
3838
|
};
|
|
3839
|
+
type AskUserMessageInChatOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
|
|
3840
|
+
type SetToolResultOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
|
|
3836
3841
|
type AiToolInvocationProps<A extends JsonObject, R extends ToolResultData> = Resolve<DistributiveOmit<AiToolInvocationPart<A, R>, "type"> & {
|
|
3837
3842
|
respond: (result: R) => void;
|
|
3838
3843
|
/**
|
|
@@ -3947,15 +3952,11 @@ declare class KnowledgeStack {
|
|
|
3947
3952
|
updateKnowledge(layerKey: LayerKey, key: string, data: AiKnowledgeSource | null): void;
|
|
3948
3953
|
}
|
|
3949
3954
|
declare function createStore_forTools(): {
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
definition: AiOpaqueToolDefinition;
|
|
3954
|
-
}[];
|
|
3955
|
-
addToolDefinition: (chatId: string, name: string, definition: AiOpaqueToolDefinition) => void;
|
|
3956
|
-
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;
|
|
3957
3958
|
};
|
|
3958
|
-
declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?:
|
|
3959
|
+
declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>): {
|
|
3959
3960
|
getMessageById: (messageId: MessageId) => AiChatMessage | undefined;
|
|
3960
3961
|
getChatMessagesForBranchΣ: (chatId: string, branch?: MessageId) => DerivedSignal<UiChatMessage[]>;
|
|
3961
3962
|
createOptimistically: {
|
|
@@ -3975,7 +3976,7 @@ declare function createStore_forUserAiChats(): {
|
|
|
3975
3976
|
getChatById: (chatId: string) => AiChat | undefined;
|
|
3976
3977
|
upsert: (chat: AiChat) => void;
|
|
3977
3978
|
upsertMany: (chats: AiChat[]) => void;
|
|
3978
|
-
|
|
3979
|
+
markDeleted: (chatId: string) => void;
|
|
3979
3980
|
};
|
|
3980
3981
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
3981
3982
|
type Ai = {
|
|
@@ -4007,16 +4008,16 @@ type Ai = {
|
|
|
4007
4008
|
id: MessageId;
|
|
4008
4009
|
parentMessageId: MessageId | null;
|
|
4009
4010
|
content: AiUserContentPart[];
|
|
4010
|
-
}, targetMessageId: MessageId, options?:
|
|
4011
|
+
}, targetMessageId: MessageId, options?: AskUserMessageInChatOptions) => Promise<AskInChatResponse>;
|
|
4011
4012
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4012
4013
|
abort: (messageId: MessageId) => Promise<AbortAiResponse>;
|
|
4013
4014
|
/** @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?:
|
|
4015
|
+
setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>;
|
|
4015
4016
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4016
4017
|
signals: {
|
|
4017
4018
|
chatsΣ: DerivedSignal<AiChat[]>;
|
|
4018
4019
|
getChatMessagesForBranchΣ(chatId: string, branch?: MessageId): DerivedSignal<UiChatMessage[]>;
|
|
4019
|
-
|
|
4020
|
+
getToolΣ(name: string, chatId?: string): DerivedSignal<AiOpaqueToolDefinition | undefined>;
|
|
4020
4021
|
};
|
|
4021
4022
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4022
4023
|
getChatById: (chatId: string) => AiChat | undefined;
|
|
@@ -4027,9 +4028,7 @@ type Ai = {
|
|
|
4027
4028
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4028
4029
|
updateKnowledge: (layerKey: LayerKey, data: AiKnowledgeSource, key?: string) => void;
|
|
4029
4030
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4030
|
-
|
|
4031
|
-
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4032
|
-
unregisterChatTool: (chatId: string, toolName: string) => void;
|
|
4031
|
+
registerTool: (name: string, tool: AiOpaqueToolDefinition, chatId?: string) => () => void;
|
|
4033
4032
|
};
|
|
4034
4033
|
|
|
4035
4034
|
type CommentBodyParagraphElementArgs = {
|
package/dist/index.d.ts
CHANGED
|
@@ -3818,6 +3818,9 @@ type InferFromSchema<T extends JSONSchema7> = JSONSchema7 extends T ? JsonObject
|
|
|
3818
3818
|
} ? {
|
|
3819
3819
|
-readonly [K in keyof T["properties"]]?: InferFromSchema<T["properties"][K]>;
|
|
3820
3820
|
} : T extends {
|
|
3821
|
+
type: "string" | "number" | "boolean";
|
|
3822
|
+
enum: readonly (infer U)[];
|
|
3823
|
+
} ? U : T extends {
|
|
3821
3824
|
type: "string";
|
|
3822
3825
|
} ? string : T extends {
|
|
3823
3826
|
type: "number";
|
|
@@ -3833,6 +3836,8 @@ type AiToolTypePack<A extends JsonObject = JsonObject, R extends ToolResultData
|
|
|
3833
3836
|
A: A;
|
|
3834
3837
|
R: R;
|
|
3835
3838
|
};
|
|
3839
|
+
type AskUserMessageInChatOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
|
|
3840
|
+
type SetToolResultOptions = Omit<AiGenerationOptions, "tools" | "knowledge">;
|
|
3836
3841
|
type AiToolInvocationProps<A extends JsonObject, R extends ToolResultData> = Resolve<DistributiveOmit<AiToolInvocationPart<A, R>, "type"> & {
|
|
3837
3842
|
respond: (result: R) => void;
|
|
3838
3843
|
/**
|
|
@@ -3947,15 +3952,11 @@ declare class KnowledgeStack {
|
|
|
3947
3952
|
updateKnowledge(layerKey: LayerKey, key: string, data: AiKnowledgeSource | null): void;
|
|
3948
3953
|
}
|
|
3949
3954
|
declare function createStore_forTools(): {
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
definition: AiOpaqueToolDefinition;
|
|
3954
|
-
}[];
|
|
3955
|
-
addToolDefinition: (chatId: string, name: string, definition: AiOpaqueToolDefinition) => void;
|
|
3956
|
-
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;
|
|
3957
3958
|
};
|
|
3958
|
-
declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?:
|
|
3959
|
+
declare function createStore_forChatMessages(toolsStore: ReturnType<typeof createStore_forTools>, setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>): {
|
|
3959
3960
|
getMessageById: (messageId: MessageId) => AiChatMessage | undefined;
|
|
3960
3961
|
getChatMessagesForBranchΣ: (chatId: string, branch?: MessageId) => DerivedSignal<UiChatMessage[]>;
|
|
3961
3962
|
createOptimistically: {
|
|
@@ -3975,7 +3976,7 @@ declare function createStore_forUserAiChats(): {
|
|
|
3975
3976
|
getChatById: (chatId: string) => AiChat | undefined;
|
|
3976
3977
|
upsert: (chat: AiChat) => void;
|
|
3977
3978
|
upsertMany: (chats: AiChat[]) => void;
|
|
3978
|
-
|
|
3979
|
+
markDeleted: (chatId: string) => void;
|
|
3979
3980
|
};
|
|
3980
3981
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
3981
3982
|
type Ai = {
|
|
@@ -4007,16 +4008,16 @@ type Ai = {
|
|
|
4007
4008
|
id: MessageId;
|
|
4008
4009
|
parentMessageId: MessageId | null;
|
|
4009
4010
|
content: AiUserContentPart[];
|
|
4010
|
-
}, targetMessageId: MessageId, options?:
|
|
4011
|
+
}, targetMessageId: MessageId, options?: AskUserMessageInChatOptions) => Promise<AskInChatResponse>;
|
|
4011
4012
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4012
4013
|
abort: (messageId: MessageId) => Promise<AbortAiResponse>;
|
|
4013
4014
|
/** @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?:
|
|
4015
|
+
setToolResult: (chatId: string, messageId: MessageId, toolCallId: string, result: ToolResultData, options?: SetToolResultOptions) => Promise<SetToolResultResponse>;
|
|
4015
4016
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4016
4017
|
signals: {
|
|
4017
4018
|
chatsΣ: DerivedSignal<AiChat[]>;
|
|
4018
4019
|
getChatMessagesForBranchΣ(chatId: string, branch?: MessageId): DerivedSignal<UiChatMessage[]>;
|
|
4019
|
-
|
|
4020
|
+
getToolΣ(name: string, chatId?: string): DerivedSignal<AiOpaqueToolDefinition | undefined>;
|
|
4020
4021
|
};
|
|
4021
4022
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4022
4023
|
getChatById: (chatId: string) => AiChat | undefined;
|
|
@@ -4027,9 +4028,7 @@ type Ai = {
|
|
|
4027
4028
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4028
4029
|
updateKnowledge: (layerKey: LayerKey, data: AiKnowledgeSource, key?: string) => void;
|
|
4029
4030
|
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4030
|
-
|
|
4031
|
-
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
|
|
4032
|
-
unregisterChatTool: (chatId: string, toolName: string) => void;
|
|
4031
|
+
registerTool: (name: string, tool: AiOpaqueToolDefinition, chatId?: string) => () => void;
|
|
4033
4032
|
};
|
|
4034
4033
|
|
|
4035
4034
|
type CommentBodyParagraphElementArgs = {
|
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-
|
|
9
|
+
var PKG_VERSION = "2.25.0-aiprivatebeta11";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -3780,46 +3780,61 @@ var KnowledgeStack = class {
|
|
|
3780
3780
|
function now() {
|
|
3781
3781
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3782
3782
|
}
|
|
3783
|
+
var kWILDCARD = Symbol("*");
|
|
3783
3784
|
function createStore_forTools() {
|
|
3784
|
-
const toolsByChatId\u03A3 = new DefaultMap(
|
|
3785
|
-
|
|
3786
|
-
return new
|
|
3785
|
+
const toolsByChatId\u03A3 = new DefaultMap(
|
|
3786
|
+
(_chatId) => {
|
|
3787
|
+
return new DefaultMap((_name) => {
|
|
3788
|
+
return new Signal(void 0);
|
|
3789
|
+
});
|
|
3790
|
+
}
|
|
3791
|
+
);
|
|
3792
|
+
const globalOrScopedTool\u03A3 = new DefaultMap((nameAndChat) => {
|
|
3793
|
+
const [name, chatId] = tryParseJson(nameAndChat);
|
|
3794
|
+
return DerivedSignal.from(() => {
|
|
3795
|
+
return (
|
|
3796
|
+
// A tool that's registered and scoped to a specific chat ID...
|
|
3797
|
+
(chatId !== void 0 ? toolsByChatId\u03A3.get(chatId)?.get(name) : void 0)?.get() ?? // ...or a globally registered tool
|
|
3798
|
+
toolsByChatId\u03A3.getOrCreate(kWILDCARD).get(name)?.get()
|
|
3799
|
+
);
|
|
3787
3800
|
});
|
|
3788
3801
|
});
|
|
3789
|
-
function
|
|
3790
|
-
|
|
3802
|
+
function getTool\u03A3(name, chatId) {
|
|
3803
|
+
const key = JSON.stringify(chatId !== void 0 ? [name, chatId] : [name]);
|
|
3804
|
+
return globalOrScopedTool\u03A3.getOrCreate(key);
|
|
3791
3805
|
}
|
|
3792
|
-
function
|
|
3793
|
-
if (!
|
|
3806
|
+
function registerTool(name, tool, chatId) {
|
|
3807
|
+
if (!tool.execute && !tool.render) {
|
|
3794
3808
|
throw new Error(
|
|
3795
|
-
"A tool definition must have an execute() function, a render
|
|
3809
|
+
"A tool definition must have an execute() function, a render() function, or both."
|
|
3796
3810
|
);
|
|
3797
3811
|
}
|
|
3798
|
-
|
|
3812
|
+
const key = chatId ?? kWILDCARD;
|
|
3813
|
+
toolsByChatId\u03A3.getOrCreate(key).getOrCreate(name).set(tool);
|
|
3814
|
+
return () => unregisterTool(key, name);
|
|
3799
3815
|
}
|
|
3800
|
-
function
|
|
3816
|
+
function unregisterTool(chatId, name) {
|
|
3801
3817
|
const tools = toolsByChatId\u03A3.get(chatId);
|
|
3802
3818
|
if (tools === void 0) return;
|
|
3803
|
-
const tool = tools.get(
|
|
3819
|
+
const tool = tools.get(name);
|
|
3804
3820
|
if (tool === void 0) return;
|
|
3805
3821
|
tool.set(void 0);
|
|
3806
3822
|
}
|
|
3807
|
-
function
|
|
3808
|
-
const
|
|
3809
|
-
|
|
3810
|
-
return Array.from(
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
};
|
|
3816
|
-
})
|
|
3823
|
+
function getToolDescriptions(chatId) {
|
|
3824
|
+
const globalTools\u03A3 = toolsByChatId\u03A3.get(kWILDCARD);
|
|
3825
|
+
const scopedTools\u03A3 = toolsByChatId\u03A3.get(chatId);
|
|
3826
|
+
return Array.from([
|
|
3827
|
+
...globalTools\u03A3?.entries() ?? [],
|
|
3828
|
+
...scopedTools\u03A3?.entries() ?? []
|
|
3829
|
+
]).flatMap(([name, tool\u03A3]) => {
|
|
3830
|
+
const tool = tool\u03A3.get();
|
|
3831
|
+
return tool ? [{ name, description: tool.description, parameters: tool.parameters }] : [];
|
|
3832
|
+
});
|
|
3817
3833
|
}
|
|
3818
3834
|
return {
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
removeToolDefinition
|
|
3835
|
+
getToolDescriptions,
|
|
3836
|
+
getTool\u03A3,
|
|
3837
|
+
registerTool
|
|
3823
3838
|
};
|
|
3824
3839
|
}
|
|
3825
3840
|
function createStore_forChatMessages(toolsStore, setToolResult) {
|
|
@@ -3909,7 +3924,7 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
|
|
|
3909
3924
|
continue;
|
|
3910
3925
|
}
|
|
3911
3926
|
seenToolCallIds.add(toolCall.toolCallId);
|
|
3912
|
-
const toolDef = toolsStore.
|
|
3927
|
+
const toolDef = toolsStore.getTool\u03A3(toolCall.toolName, message.chatId).get();
|
|
3913
3928
|
const respondSync = (result) => {
|
|
3914
3929
|
setToolResult(
|
|
3915
3930
|
message.chatId,
|
|
@@ -4091,16 +4106,16 @@ function createStore_forChatMessages(toolsStore, setToolResult) {
|
|
|
4091
4106
|
};
|
|
4092
4107
|
}
|
|
4093
4108
|
function createStore_forUserAiChats() {
|
|
4094
|
-
const
|
|
4109
|
+
const allChatsInclDeleted\u03A3 = new MutableSignal(
|
|
4095
4110
|
SortedList.with((x, y) => y.createdAt < x.createdAt)
|
|
4096
4111
|
);
|
|
4097
|
-
const
|
|
4098
|
-
() => Array.from(
|
|
4112
|
+
const nonDeletedChats\u03A3 = DerivedSignal.from(
|
|
4113
|
+
() => Array.from(allChatsInclDeleted\u03A3.get()).filter((c) => !c.deletedAt)
|
|
4099
4114
|
);
|
|
4100
4115
|
function upsertMany(chats) {
|
|
4101
|
-
|
|
4116
|
+
allChatsInclDeleted\u03A3.mutate((list) => {
|
|
4102
4117
|
for (const chat of chats) {
|
|
4103
|
-
|
|
4118
|
+
list.removeBy((c) => c.id === chat.id, 1);
|
|
4104
4119
|
list.add(chat);
|
|
4105
4120
|
}
|
|
4106
4121
|
});
|
|
@@ -4108,19 +4123,26 @@ function createStore_forUserAiChats() {
|
|
|
4108
4123
|
function upsert(chat) {
|
|
4109
4124
|
upsertMany([chat]);
|
|
4110
4125
|
}
|
|
4111
|
-
function
|
|
4112
|
-
|
|
4126
|
+
function markDeleted(chatId) {
|
|
4127
|
+
allChatsInclDeleted\u03A3.mutate((list) => {
|
|
4128
|
+
const chat = list.find((c) => c.id === chatId);
|
|
4129
|
+
if (!chat) return false;
|
|
4130
|
+
upsert({ ...chat, deletedAt: now() });
|
|
4131
|
+
return void 0;
|
|
4132
|
+
});
|
|
4113
4133
|
}
|
|
4114
4134
|
function getChatById(chatId) {
|
|
4115
|
-
return Array.from(
|
|
4135
|
+
return Array.from(allChatsInclDeleted\u03A3.get()).find(
|
|
4136
|
+
(chat) => chat.id === chatId
|
|
4137
|
+
);
|
|
4116
4138
|
}
|
|
4117
4139
|
return {
|
|
4118
|
-
chats\u03A3,
|
|
4140
|
+
chats\u03A3: nonDeletedChats\u03A3,
|
|
4119
4141
|
getChatById,
|
|
4120
4142
|
// Mutations
|
|
4121
4143
|
upsert,
|
|
4122
4144
|
upsertMany,
|
|
4123
|
-
|
|
4145
|
+
markDeleted
|
|
4124
4146
|
};
|
|
4125
4147
|
}
|
|
4126
4148
|
function createAi(config) {
|
|
@@ -4220,7 +4242,7 @@ function createAi(config) {
|
|
|
4220
4242
|
context.messagesStore.remove(m.chatId, m.id);
|
|
4221
4243
|
}
|
|
4222
4244
|
for (const chatId of msg["-chats"] ?? []) {
|
|
4223
|
-
context.chatsStore.
|
|
4245
|
+
context.chatsStore.markDeleted(chatId);
|
|
4224
4246
|
context.messagesStore.removeByChatId(chatId);
|
|
4225
4247
|
}
|
|
4226
4248
|
for (const chatId of msg.clear ?? []) {
|
|
@@ -4246,7 +4268,7 @@ function createAi(config) {
|
|
|
4246
4268
|
context.chatsStore.upsert(msg.chat);
|
|
4247
4269
|
break;
|
|
4248
4270
|
case "delete-chat":
|
|
4249
|
-
context.chatsStore.
|
|
4271
|
+
context.chatsStore.markDeleted(msg.chatId);
|
|
4250
4272
|
context.messagesStore.removeByChatId(msg.chatId);
|
|
4251
4273
|
break;
|
|
4252
4274
|
case "get-message-tree":
|
|
@@ -4346,6 +4368,7 @@ function createAi(config) {
|
|
|
4346
4368
|
}
|
|
4347
4369
|
async function setToolResult(chatId, messageId, toolCallId, result, options) {
|
|
4348
4370
|
const knowledge = context.knowledge.get();
|
|
4371
|
+
const tools = context.toolsStore.getToolDescriptions(chatId);
|
|
4349
4372
|
const resp = await sendClientMsgWithResponse({
|
|
4350
4373
|
cmd: "set-tool-result",
|
|
4351
4374
|
chatId,
|
|
@@ -4356,12 +4379,10 @@ function createAi(config) {
|
|
|
4356
4379
|
copilotId: options?.copilotId,
|
|
4357
4380
|
stream: options?.stream,
|
|
4358
4381
|
timeout: options?.timeout,
|
|
4382
|
+
// Knowledge and tools aren't coming from the options, but retrieved
|
|
4383
|
+
// from the global context
|
|
4359
4384
|
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4360
|
-
tools:
|
|
4361
|
-
name: tool.name,
|
|
4362
|
-
description: tool.definition.description,
|
|
4363
|
-
parameters: tool.definition.parameters
|
|
4364
|
-
}))
|
|
4385
|
+
tools: tools.length > 0 ? tools : void 0
|
|
4365
4386
|
}
|
|
4366
4387
|
});
|
|
4367
4388
|
if (resp.ok) {
|
|
@@ -4387,6 +4408,7 @@ function createAi(config) {
|
|
|
4387
4408
|
clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
|
|
4388
4409
|
askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
|
|
4389
4410
|
const knowledge = context.knowledge.get();
|
|
4411
|
+
const tools = context.toolsStore.getToolDescriptions(chatId);
|
|
4390
4412
|
const resp = await sendClientMsgWithResponse({
|
|
4391
4413
|
cmd: "ask-in-chat",
|
|
4392
4414
|
chatId,
|
|
@@ -4396,12 +4418,10 @@ function createAi(config) {
|
|
|
4396
4418
|
copilotId: options?.copilotId,
|
|
4397
4419
|
stream: options?.stream,
|
|
4398
4420
|
timeout: options?.timeout,
|
|
4421
|
+
// Knowledge and tools aren't coming from the options, but retrieved
|
|
4422
|
+
// from the global context
|
|
4399
4423
|
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4400
|
-
tools:
|
|
4401
|
-
name: tool.name,
|
|
4402
|
-
description: tool.definition.description,
|
|
4403
|
-
parameters: tool.definition.parameters
|
|
4404
|
-
}))
|
|
4424
|
+
tools: tools.length > 0 ? tools : void 0
|
|
4405
4425
|
}
|
|
4406
4426
|
});
|
|
4407
4427
|
messagesStore.allowAutoExecuteToolCall(resp.targetMessage.id);
|
|
@@ -4413,14 +4433,13 @@ function createAi(config) {
|
|
|
4413
4433
|
signals: {
|
|
4414
4434
|
chats\u03A3: context.chatsStore.chats\u03A3,
|
|
4415
4435
|
getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
|
|
4416
|
-
|
|
4436
|
+
getTool\u03A3: context.toolsStore.getTool\u03A3
|
|
4417
4437
|
},
|
|
4418
4438
|
getChatById: context.chatsStore.getChatById,
|
|
4419
4439
|
registerKnowledgeLayer,
|
|
4420
4440
|
deregisterKnowledgeLayer,
|
|
4421
4441
|
updateKnowledge,
|
|
4422
|
-
|
|
4423
|
-
unregisterChatTool: context.toolsStore.removeToolDefinition
|
|
4442
|
+
registerTool: context.toolsStore.registerTool
|
|
4424
4443
|
},
|
|
4425
4444
|
kInternal,
|
|
4426
4445
|
{ enumerable: false }
|