@liveblocks/core 2.25.0-aiprivatebeta7 → 2.25.0-aiprivatebeta9
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 +199 -134
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +215 -72
- package/dist/index.d.ts +215 -72
- package/dist/index.js +194 -129
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
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-aiprivatebeta9";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -188,6 +188,9 @@ var warnWithTitle = wrapWithTitle("warn");
|
|
|
188
188
|
var errorWithTitle = wrapWithTitle("error");
|
|
189
189
|
|
|
190
190
|
// src/lib/guards.ts
|
|
191
|
+
function isDefined(value) {
|
|
192
|
+
return value !== null && value !== void 0;
|
|
193
|
+
}
|
|
191
194
|
function isPlainObject(blob) {
|
|
192
195
|
return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
|
|
193
196
|
}
|
|
@@ -3685,11 +3688,6 @@ function parseAuthToken(rawTokenString) {
|
|
|
3685
3688
|
function appendDelta(content, delta) {
|
|
3686
3689
|
const lastPart = content[content.length - 1];
|
|
3687
3690
|
switch (delta.type) {
|
|
3688
|
-
case "reasoning":
|
|
3689
|
-
case "text":
|
|
3690
|
-
case "tool-call":
|
|
3691
|
-
content.push(delta);
|
|
3692
|
-
break;
|
|
3693
3691
|
case "text-delta":
|
|
3694
3692
|
if (_optionalChain([lastPart, 'optionalAccess', _55 => _55.type]) === "text") {
|
|
3695
3693
|
lastPart.text += delta.textDelta;
|
|
@@ -3700,15 +3698,16 @@ function appendDelta(content, delta) {
|
|
|
3700
3698
|
case "reasoning-delta":
|
|
3701
3699
|
if (_optionalChain([lastPart, 'optionalAccess', _56 => _56.type]) === "reasoning") {
|
|
3702
3700
|
lastPart.text += delta.textDelta;
|
|
3703
|
-
lastPart.signature ??= delta.signature;
|
|
3704
3701
|
} else {
|
|
3705
3702
|
content.push({
|
|
3706
3703
|
type: "reasoning",
|
|
3707
|
-
text: _nullishCoalesce(delta.textDelta, () => ( ""))
|
|
3708
|
-
signature: delta.signature
|
|
3704
|
+
text: _nullishCoalesce(delta.textDelta, () => ( ""))
|
|
3709
3705
|
});
|
|
3710
3706
|
}
|
|
3711
3707
|
break;
|
|
3708
|
+
case "tool-invocation":
|
|
3709
|
+
content.push(delta);
|
|
3710
|
+
break;
|
|
3712
3711
|
default:
|
|
3713
3712
|
return assertNever(delta, "Unhandled case");
|
|
3714
3713
|
}
|
|
@@ -3716,7 +3715,68 @@ function appendDelta(content, delta) {
|
|
|
3716
3715
|
|
|
3717
3716
|
// src/ai.ts
|
|
3718
3717
|
var DEFAULT_REQUEST_TIMEOUT = 4e3;
|
|
3719
|
-
|
|
3718
|
+
function defineAiTool() {
|
|
3719
|
+
return (def) => {
|
|
3720
|
+
return def;
|
|
3721
|
+
};
|
|
3722
|
+
}
|
|
3723
|
+
var KnowledgeStack = class {
|
|
3724
|
+
#_layers;
|
|
3725
|
+
#stack;
|
|
3726
|
+
// / \
|
|
3727
|
+
// knowledge key "layer" key
|
|
3728
|
+
// (random, or optionally (one entry per mounted component)
|
|
3729
|
+
// set by user)
|
|
3730
|
+
#_cache;
|
|
3731
|
+
constructor() {
|
|
3732
|
+
this.#_layers = /* @__PURE__ */ new Set();
|
|
3733
|
+
this.#stack = new DefaultMap(
|
|
3734
|
+
() => /* @__PURE__ */ new Map()
|
|
3735
|
+
);
|
|
3736
|
+
this.#_cache = void 0;
|
|
3737
|
+
}
|
|
3738
|
+
// Typically a useId()
|
|
3739
|
+
registerLayer(uniqueLayerId) {
|
|
3740
|
+
const layerKey = uniqueLayerId;
|
|
3741
|
+
if (this.#_layers.has(layerKey))
|
|
3742
|
+
raise(`Layer '${layerKey}' already exists, provide a unique layer id`);
|
|
3743
|
+
this.#_layers.add(layerKey);
|
|
3744
|
+
return layerKey;
|
|
3745
|
+
}
|
|
3746
|
+
deregisterLayer(layerKey) {
|
|
3747
|
+
this.#_layers.delete(layerKey);
|
|
3748
|
+
let deleted = false;
|
|
3749
|
+
for (const [key, knowledge] of this.#stack) {
|
|
3750
|
+
if (knowledge.delete(layerKey)) {
|
|
3751
|
+
deleted = true;
|
|
3752
|
+
}
|
|
3753
|
+
if (knowledge.size === 0)
|
|
3754
|
+
this.#stack.delete(key);
|
|
3755
|
+
}
|
|
3756
|
+
if (deleted) {
|
|
3757
|
+
this.invalidate();
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
get() {
|
|
3761
|
+
return this.#_cache ??= this.#recompute();
|
|
3762
|
+
}
|
|
3763
|
+
invalidate() {
|
|
3764
|
+
this.#_cache = void 0;
|
|
3765
|
+
}
|
|
3766
|
+
#recompute() {
|
|
3767
|
+
return Array.from(this.#stack.values()).flatMap(
|
|
3768
|
+
(layer) => (
|
|
3769
|
+
// Return only the last item (returns [] when empty)
|
|
3770
|
+
Array.from(layer.values()).slice(-1).filter(isDefined)
|
|
3771
|
+
)
|
|
3772
|
+
);
|
|
3773
|
+
}
|
|
3774
|
+
updateKnowledge(layerKey, key, data) {
|
|
3775
|
+
if (!this.#_layers.has(layerKey)) raise(`Unknown layer key: ${layerKey}`);
|
|
3776
|
+
this.#stack.getOrCreate(key).set(layerKey, data);
|
|
3777
|
+
this.invalidate();
|
|
3778
|
+
}
|
|
3779
|
+
};
|
|
3720
3780
|
function now() {
|
|
3721
3781
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3722
3782
|
}
|
|
@@ -3730,6 +3790,11 @@ function createStore_forTools() {
|
|
|
3730
3790
|
return toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(toolName);
|
|
3731
3791
|
}
|
|
3732
3792
|
function addToolDefinition(chatId, name, definition) {
|
|
3793
|
+
if (!definition.execute && !definition.render) {
|
|
3794
|
+
throw new Error(
|
|
3795
|
+
"A tool definition must have an execute() function, a render property, or both."
|
|
3796
|
+
);
|
|
3797
|
+
}
|
|
3733
3798
|
toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name).set(definition);
|
|
3734
3799
|
}
|
|
3735
3800
|
function removeToolDefinition(chatId, toolName) {
|
|
@@ -3751,13 +3816,14 @@ function createStore_forTools() {
|
|
|
3751
3816
|
}).filter((tool) => tool !== null);
|
|
3752
3817
|
}
|
|
3753
3818
|
return {
|
|
3754
|
-
|
|
3819
|
+
getToolDefinition\u03A3,
|
|
3755
3820
|
getToolsForChat,
|
|
3756
3821
|
addToolDefinition,
|
|
3757
3822
|
removeToolDefinition
|
|
3758
3823
|
};
|
|
3759
3824
|
}
|
|
3760
|
-
function createStore_forChatMessages() {
|
|
3825
|
+
function createStore_forChatMessages(toolsStore, setToolResult) {
|
|
3826
|
+
const seenToolCallIds = /* @__PURE__ */ new Set();
|
|
3761
3827
|
const messagePoolByChatId\u03A3 = new DefaultMap(
|
|
3762
3828
|
(_chatId) => new MutableSignal(
|
|
3763
3829
|
new TreePool(
|
|
@@ -3767,7 +3833,7 @@ function createStore_forChatMessages() {
|
|
|
3767
3833
|
)
|
|
3768
3834
|
)
|
|
3769
3835
|
);
|
|
3770
|
-
const
|
|
3836
|
+
const generatingMessages\u03A3 = new MutableSignal(
|
|
3771
3837
|
/* @__PURE__ */ new Map()
|
|
3772
3838
|
);
|
|
3773
3839
|
function createOptimistically(chatId, role, parentId, third) {
|
|
@@ -3791,7 +3857,7 @@ function createStore_forChatMessages() {
|
|
|
3791
3857
|
role,
|
|
3792
3858
|
parentId,
|
|
3793
3859
|
createdAt,
|
|
3794
|
-
status: "
|
|
3860
|
+
status: "generating",
|
|
3795
3861
|
contentSoFar: [],
|
|
3796
3862
|
_optimistic: true
|
|
3797
3863
|
});
|
|
@@ -3810,7 +3876,7 @@ function createStore_forChatMessages() {
|
|
|
3810
3876
|
if (!chatMsgs\u03A3) return;
|
|
3811
3877
|
const existing = chatMsgs\u03A3.get().get(messageId);
|
|
3812
3878
|
if (!existing || existing.deletedAt) return;
|
|
3813
|
-
if (existing.role === "assistant" &&
|
|
3879
|
+
if (existing.role === "assistant" && existing.status !== "completed") {
|
|
3814
3880
|
upsert({ ...existing, deletedAt: now(), contentSoFar: [] });
|
|
3815
3881
|
} else {
|
|
3816
3882
|
upsert({ ...existing, deletedAt: now(), content: [] });
|
|
@@ -3825,19 +3891,57 @@ function createStore_forChatMessages() {
|
|
|
3825
3891
|
batch(() => {
|
|
3826
3892
|
const chatMsgs\u03A3 = messagePoolByChatId\u03A3.getOrCreate(message.chatId);
|
|
3827
3893
|
chatMsgs\u03A3.mutate((pool) => pool.upsert(message));
|
|
3828
|
-
if (message.role === "assistant" && message.status === "
|
|
3829
|
-
|
|
3894
|
+
if (message.role === "assistant" && message.status === "generating") {
|
|
3895
|
+
generatingMessages\u03A3.mutate((lut) => {
|
|
3830
3896
|
lut.set(message.id, structuredClone(message));
|
|
3831
3897
|
});
|
|
3832
3898
|
} else {
|
|
3833
|
-
|
|
3899
|
+
generatingMessages\u03A3.mutate((lut) => {
|
|
3834
3900
|
lut.delete(message.id);
|
|
3835
3901
|
});
|
|
3836
3902
|
}
|
|
3903
|
+
if (message.role === "assistant" && message.status === "awaiting-tool") {
|
|
3904
|
+
for (const toolCall of message.contentSoFar.filter(
|
|
3905
|
+
(part) => part.type === "tool-invocation" && part.status === "executing"
|
|
3906
|
+
)) {
|
|
3907
|
+
if (seenToolCallIds.has(toolCall.toolCallId)) {
|
|
3908
|
+
continue;
|
|
3909
|
+
}
|
|
3910
|
+
seenToolCallIds.add(toolCall.toolCallId);
|
|
3911
|
+
const toolDef = toolsStore.getToolDefinition\u03A3(message.chatId, toolCall.toolName).get();
|
|
3912
|
+
const respondSync = (result) => {
|
|
3913
|
+
setToolResult(
|
|
3914
|
+
message.chatId,
|
|
3915
|
+
message.id,
|
|
3916
|
+
toolCall.toolCallId,
|
|
3917
|
+
result
|
|
3918
|
+
// TODO Pass in AiGenerationOptions here, or make the backend use the same options
|
|
3919
|
+
).catch((err) => {
|
|
3920
|
+
error2(
|
|
3921
|
+
`Error trying to respond to tool-call: ${String(err)} (in respond())`
|
|
3922
|
+
);
|
|
3923
|
+
});
|
|
3924
|
+
};
|
|
3925
|
+
const executeFn = _optionalChain([toolDef, 'optionalAccess', _57 => _57.execute]);
|
|
3926
|
+
if (executeFn) {
|
|
3927
|
+
(async () => {
|
|
3928
|
+
const result = await executeFn(toolCall.args, {
|
|
3929
|
+
toolName: toolCall.toolName,
|
|
3930
|
+
toolCallId: toolCall.toolCallId
|
|
3931
|
+
});
|
|
3932
|
+
respondSync(result);
|
|
3933
|
+
})().catch((err) => {
|
|
3934
|
+
error2(
|
|
3935
|
+
`Error trying to respond to tool-call: ${String(err)} (in execute())`
|
|
3936
|
+
);
|
|
3937
|
+
});
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
}
|
|
3837
3941
|
});
|
|
3838
3942
|
}
|
|
3839
3943
|
function addDelta(messageId, delta) {
|
|
3840
|
-
|
|
3944
|
+
generatingMessages\u03A3.mutate((lut) => {
|
|
3841
3945
|
const message = lut.get(messageId);
|
|
3842
3946
|
if (message === void 0) return false;
|
|
3843
3947
|
appendDelta(message.contentSoFar, delta);
|
|
@@ -3845,10 +3949,10 @@ function createStore_forChatMessages() {
|
|
|
3845
3949
|
return true;
|
|
3846
3950
|
});
|
|
3847
3951
|
}
|
|
3848
|
-
function*
|
|
3952
|
+
function* iterGeneratingMessages() {
|
|
3849
3953
|
for (const chatMsgs\u03A3 of messagePoolByChatId\u03A3.values()) {
|
|
3850
3954
|
for (const m of chatMsgs\u03A3.get()) {
|
|
3851
|
-
if (m.role === "assistant" && m.status === "
|
|
3955
|
+
if (m.role === "assistant" && m.status === "generating" && !m._optimistic) {
|
|
3852
3956
|
yield m;
|
|
3853
3957
|
}
|
|
3854
3958
|
}
|
|
@@ -3856,7 +3960,7 @@ function createStore_forChatMessages() {
|
|
|
3856
3960
|
}
|
|
3857
3961
|
function failAllPending() {
|
|
3858
3962
|
batch(() => {
|
|
3859
|
-
|
|
3963
|
+
generatingMessages\u03A3.mutate((lut) => {
|
|
3860
3964
|
let deleted = false;
|
|
3861
3965
|
for (const [k, v] of lut) {
|
|
3862
3966
|
if (!v._optimistic) {
|
|
@@ -3867,7 +3971,7 @@ function createStore_forChatMessages() {
|
|
|
3867
3971
|
return deleted;
|
|
3868
3972
|
});
|
|
3869
3973
|
upsertMany(
|
|
3870
|
-
Array.from(
|
|
3974
|
+
Array.from(iterGeneratingMessages()).map(
|
|
3871
3975
|
(message) => ({
|
|
3872
3976
|
...message,
|
|
3873
3977
|
status: "failed",
|
|
@@ -3902,11 +4006,20 @@ function createStore_forChatMessages() {
|
|
|
3902
4006
|
}
|
|
3903
4007
|
function selectSpine(leaf) {
|
|
3904
4008
|
const spine = [];
|
|
4009
|
+
let lastVisitedMessage = null;
|
|
3905
4010
|
for (const message2 of pool.walkUp(leaf.id)) {
|
|
3906
|
-
const prev = _nullishCoalesce(_optionalChain([first, 'call',
|
|
3907
|
-
const next = _nullishCoalesce(_optionalChain([first, 'call',
|
|
4011
|
+
const prev = _nullishCoalesce(_optionalChain([first, 'call', _58 => _58(pool.walkLeft(message2.id, isAlive)), 'optionalAccess', _59 => _59.id]), () => ( null));
|
|
4012
|
+
const next = _nullishCoalesce(_optionalChain([first, 'call', _60 => _60(pool.walkRight(message2.id, isAlive)), 'optionalAccess', _61 => _61.id]), () => ( null));
|
|
3908
4013
|
if (!message2.deletedAt || prev || next) {
|
|
3909
|
-
|
|
4014
|
+
const node = {
|
|
4015
|
+
...message2,
|
|
4016
|
+
navigation: { parent: null, prev, next }
|
|
4017
|
+
};
|
|
4018
|
+
if (lastVisitedMessage !== null) {
|
|
4019
|
+
lastVisitedMessage.navigation.parent = node.id;
|
|
4020
|
+
}
|
|
4021
|
+
lastVisitedMessage = node;
|
|
4022
|
+
spine.push(node);
|
|
3910
4023
|
}
|
|
3911
4024
|
}
|
|
3912
4025
|
return spine.reverse();
|
|
@@ -3932,18 +4045,6 @@ function createStore_forChatMessages() {
|
|
|
3932
4045
|
}
|
|
3933
4046
|
return fallback();
|
|
3934
4047
|
}
|
|
3935
|
-
function getLatestUserMessageAncestor(chatId, messageId) {
|
|
3936
|
-
const pool = messagePoolByChatId\u03A3.getOrCreate(chatId).get();
|
|
3937
|
-
const message = pool.get(messageId);
|
|
3938
|
-
if (!message) return null;
|
|
3939
|
-
if (message.role === "user") return message.id;
|
|
3940
|
-
for (const m of pool.walkUp(message.id)) {
|
|
3941
|
-
if (m.role === "user" && !m.deletedAt) {
|
|
3942
|
-
return m.id;
|
|
3943
|
-
}
|
|
3944
|
-
}
|
|
3945
|
-
return null;
|
|
3946
|
-
}
|
|
3947
4048
|
const immutableMessagesByBranch = new DefaultMap((chatId) => {
|
|
3948
4049
|
return new DefaultMap((branchId) => {
|
|
3949
4050
|
const messages\u03A3 = DerivedSignal.from(() => {
|
|
@@ -3951,16 +4052,16 @@ function createStore_forChatMessages() {
|
|
|
3951
4052
|
return selectBranch(pool, branchId);
|
|
3952
4053
|
}, shallow2);
|
|
3953
4054
|
return DerivedSignal.from(() => {
|
|
3954
|
-
const
|
|
4055
|
+
const generatingMessages = generatingMessages\u03A3.get();
|
|
3955
4056
|
return messages\u03A3.get().map((message) => {
|
|
3956
|
-
if (message.role !== "assistant" || message.status !== "
|
|
4057
|
+
if (message.role !== "assistant" || message.status !== "generating") {
|
|
3957
4058
|
return message;
|
|
3958
4059
|
}
|
|
3959
|
-
const
|
|
3960
|
-
if (
|
|
4060
|
+
const generatingMessage = generatingMessages.get(message.id);
|
|
4061
|
+
if (generatingMessage === void 0) return message;
|
|
3961
4062
|
return {
|
|
3962
4063
|
...message,
|
|
3963
|
-
contentSoFar:
|
|
4064
|
+
contentSoFar: generatingMessage.contentSoFar
|
|
3964
4065
|
};
|
|
3965
4066
|
});
|
|
3966
4067
|
}, shallow);
|
|
@@ -3969,21 +4070,10 @@ function createStore_forChatMessages() {
|
|
|
3969
4070
|
function getChatMessagesForBranch\u03A3(chatId, branch) {
|
|
3970
4071
|
return immutableMessagesByBranch.getOrCreate(chatId).getOrCreate(branch || null);
|
|
3971
4072
|
}
|
|
3972
|
-
const messagesByChatId\u03A3 = new DefaultMap((chatId) => {
|
|
3973
|
-
return DerivedSignal.from(() => {
|
|
3974
|
-
const pool = messagePoolByChatId\u03A3.getOrCreate(chatId).get();
|
|
3975
|
-
return Array.from(pool.sorted);
|
|
3976
|
-
});
|
|
3977
|
-
});
|
|
3978
|
-
function getMessagesForChat\u03A3(chatId) {
|
|
3979
|
-
return messagesByChatId\u03A3.getOrCreate(chatId);
|
|
3980
|
-
}
|
|
3981
4073
|
return {
|
|
3982
4074
|
// Readers
|
|
3983
4075
|
getMessageById,
|
|
3984
4076
|
getChatMessagesForBranch\u03A3,
|
|
3985
|
-
getMessagesForChat\u03A3,
|
|
3986
|
-
getLatestUserMessageAncestor,
|
|
3987
4077
|
// Mutations
|
|
3988
4078
|
createOptimistically,
|
|
3989
4079
|
upsert,
|
|
@@ -4015,8 +4105,12 @@ function createStore_forUserAiChats() {
|
|
|
4015
4105
|
function remove(chatId) {
|
|
4016
4106
|
mutable\u03A3.mutate((list) => list.removeBy((c) => c.id === chatId, 1));
|
|
4017
4107
|
}
|
|
4108
|
+
function getChatById(chatId) {
|
|
4109
|
+
return Array.from(mutable\u03A3.get()).find((chat) => chat.id === chatId);
|
|
4110
|
+
}
|
|
4018
4111
|
return {
|
|
4019
4112
|
chats\u03A3,
|
|
4113
|
+
getChatById,
|
|
4020
4114
|
// Mutations
|
|
4021
4115
|
upsert,
|
|
4022
4116
|
upsertMany,
|
|
@@ -4032,8 +4126,8 @@ function createAi(config) {
|
|
|
4032
4126
|
);
|
|
4033
4127
|
const clientId = nanoid(7);
|
|
4034
4128
|
const chatsStore = createStore_forUserAiChats();
|
|
4035
|
-
const messagesStore = createStore_forChatMessages();
|
|
4036
4129
|
const toolsStore = createStore_forTools();
|
|
4130
|
+
const messagesStore = createStore_forChatMessages(toolsStore, setToolResult);
|
|
4037
4131
|
const context = {
|
|
4038
4132
|
staticSessionInfoSig: new Signal(null),
|
|
4039
4133
|
dynamicSessionInfoSig: new Signal(null),
|
|
@@ -4041,7 +4135,7 @@ function createAi(config) {
|
|
|
4041
4135
|
chatsStore,
|
|
4042
4136
|
messagesStore,
|
|
4043
4137
|
toolsStore,
|
|
4044
|
-
|
|
4138
|
+
knowledge: new KnowledgeStack()
|
|
4045
4139
|
};
|
|
4046
4140
|
let lastTokenKey;
|
|
4047
4141
|
function onStatusDidChange(_newStatus) {
|
|
@@ -4099,7 +4193,7 @@ function createAi(config) {
|
|
|
4099
4193
|
if ("event" in msg) {
|
|
4100
4194
|
switch (msg.event) {
|
|
4101
4195
|
case "cmd-failed":
|
|
4102
|
-
_optionalChain([pendingCmd, 'optionalAccess',
|
|
4196
|
+
_optionalChain([pendingCmd, 'optionalAccess', _62 => _62.reject, 'call', _63 => _63(new Error(msg.error))]);
|
|
4103
4197
|
break;
|
|
4104
4198
|
case "delta": {
|
|
4105
4199
|
const { id, delta } = msg;
|
|
@@ -4168,11 +4262,16 @@ function createAi(config) {
|
|
|
4168
4262
|
break;
|
|
4169
4263
|
case "abort-ai":
|
|
4170
4264
|
break;
|
|
4265
|
+
case "set-tool-result":
|
|
4266
|
+
if (msg.ok) {
|
|
4267
|
+
context.messagesStore.upsert(msg.message);
|
|
4268
|
+
}
|
|
4269
|
+
break;
|
|
4171
4270
|
default:
|
|
4172
4271
|
return assertNever(msg, "Unhandled case");
|
|
4173
4272
|
}
|
|
4174
4273
|
}
|
|
4175
|
-
_optionalChain([pendingCmd, 'optionalAccess',
|
|
4274
|
+
_optionalChain([pendingCmd, 'optionalAccess', _64 => _64.resolve, 'call', _65 => _65(msg)]);
|
|
4176
4275
|
}
|
|
4177
4276
|
managedSocket.events.onMessage.subscribe(handleServerMessage);
|
|
4178
4277
|
managedSocket.events.statusDidChange.subscribe(onStatusDidChange);
|
|
@@ -4218,14 +4317,11 @@ function createAi(config) {
|
|
|
4218
4317
|
cursor: options.cursor
|
|
4219
4318
|
});
|
|
4220
4319
|
}
|
|
4221
|
-
function getOrCreateChat(id,
|
|
4320
|
+
function getOrCreateChat(id, options) {
|
|
4222
4321
|
return sendClientMsgWithResponse({
|
|
4223
4322
|
cmd: "get-or-create-chat",
|
|
4224
4323
|
id,
|
|
4225
|
-
options
|
|
4226
|
-
title,
|
|
4227
|
-
metadata: _optionalChain([options, 'optionalAccess', _65 => _65.metadata])
|
|
4228
|
-
}
|
|
4324
|
+
options
|
|
4229
4325
|
});
|
|
4230
4326
|
}
|
|
4231
4327
|
function getMessageTree(chatId) {
|
|
@@ -4234,56 +4330,44 @@ function createAi(config) {
|
|
|
4234
4330
|
chatId
|
|
4235
4331
|
});
|
|
4236
4332
|
}
|
|
4237
|
-
function
|
|
4238
|
-
|
|
4239
|
-
if (knowledge === void 0) {
|
|
4240
|
-
context.knowledgeByChatId.set(chatId, /* @__PURE__ */ new Set([data]));
|
|
4241
|
-
} else {
|
|
4242
|
-
knowledge.add(data);
|
|
4243
|
-
}
|
|
4244
|
-
return () => {
|
|
4245
|
-
const knowledge2 = context.knowledgeByChatId.get(chatId);
|
|
4246
|
-
if (knowledge2 !== void 0) {
|
|
4247
|
-
knowledge2.delete(data);
|
|
4248
|
-
if (knowledge2.size === 0) {
|
|
4249
|
-
context.knowledgeByChatId.delete(chatId);
|
|
4250
|
-
}
|
|
4251
|
-
}
|
|
4252
|
-
};
|
|
4333
|
+
function registerKnowledgeLayer(uniqueLayerId) {
|
|
4334
|
+
return context.knowledge.registerLayer(uniqueLayerId);
|
|
4253
4335
|
}
|
|
4254
|
-
function
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4336
|
+
function deregisterKnowledgeLayer(layerKey) {
|
|
4337
|
+
context.knowledge.deregisterLayer(layerKey);
|
|
4338
|
+
}
|
|
4339
|
+
function updateKnowledge(layerKey, data, key = nanoid()) {
|
|
4340
|
+
context.knowledge.updateKnowledge(layerKey, key, data);
|
|
4341
|
+
}
|
|
4342
|
+
function debug_getAllKnowledge() {
|
|
4343
|
+
return context.knowledge.get();
|
|
4344
|
+
}
|
|
4345
|
+
async function setToolResult(chatId, messageId, toolCallId, result, options) {
|
|
4346
|
+
const knowledge = context.knowledge.get();
|
|
4264
4347
|
return sendClientMsgWithResponse({
|
|
4265
|
-
cmd: "
|
|
4348
|
+
cmd: "set-tool-result",
|
|
4266
4349
|
chatId,
|
|
4267
|
-
|
|
4268
|
-
|
|
4350
|
+
messageId,
|
|
4351
|
+
toolCallId,
|
|
4269
4352
|
clientId,
|
|
4353
|
+
result,
|
|
4270
4354
|
generationOptions: {
|
|
4271
|
-
copilotId,
|
|
4272
|
-
stream,
|
|
4273
|
-
|
|
4355
|
+
copilotId: _optionalChain([options, 'optionalAccess', _66 => _66.copilotId]),
|
|
4356
|
+
stream: _optionalChain([options, 'optionalAccess', _67 => _67.stream]),
|
|
4357
|
+
timeout: _optionalChain([options, 'optionalAccess', _68 => _68.timeout]),
|
|
4358
|
+
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4274
4359
|
tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
|
|
4275
4360
|
name: tool.name,
|
|
4276
4361
|
description: tool.definition.description,
|
|
4277
4362
|
parameters: tool.definition.parameters
|
|
4278
|
-
}))
|
|
4279
|
-
timeout
|
|
4363
|
+
}))
|
|
4280
4364
|
}
|
|
4281
4365
|
});
|
|
4282
4366
|
}
|
|
4283
4367
|
return Object.defineProperty(
|
|
4284
4368
|
{
|
|
4285
4369
|
[kInternal]: {
|
|
4286
|
-
|
|
4370
|
+
context
|
|
4287
4371
|
},
|
|
4288
4372
|
connect: () => managedSocket.connect(),
|
|
4289
4373
|
reconnect: () => managedSocket.reconnect(),
|
|
@@ -4299,60 +4383,40 @@ function createAi(config) {
|
|
|
4299
4383
|
getMessageTree,
|
|
4300
4384
|
deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
|
|
4301
4385
|
clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
|
|
4302
|
-
|
|
4303
|
-
const
|
|
4304
|
-
if (parentUserMessageId === null) {
|
|
4305
|
-
throw new Error(
|
|
4306
|
-
`Unable to find user message ancestor for messageId: ${messageId}`
|
|
4307
|
-
);
|
|
4308
|
-
}
|
|
4309
|
-
return ask(chatId, parentUserMessageId, options);
|
|
4310
|
-
},
|
|
4311
|
-
addUserMessageAndAsk: async (chatId, parentMessageId, message, options) => {
|
|
4312
|
-
const content = [{ type: "text", text: message }];
|
|
4313
|
-
const newMessageId = context.messagesStore.createOptimistically(
|
|
4314
|
-
chatId,
|
|
4315
|
-
"user",
|
|
4316
|
-
parentMessageId,
|
|
4317
|
-
content
|
|
4318
|
-
);
|
|
4319
|
-
const targetMessageId = context.messagesStore.createOptimistically(
|
|
4320
|
-
chatId,
|
|
4321
|
-
"assistant",
|
|
4322
|
-
newMessageId
|
|
4323
|
-
);
|
|
4324
|
-
const copilotId = _optionalChain([options, 'optionalAccess', _69 => _69.copilotId]);
|
|
4325
|
-
const stream = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _70 => _70.stream]), () => ( false));
|
|
4326
|
-
const timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.timeout]), () => ( DEFAULT_AI_TIMEOUT));
|
|
4327
|
-
const knowledge = context.knowledgeByChatId.get(chatId);
|
|
4386
|
+
askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
|
|
4387
|
+
const knowledge = context.knowledge.get();
|
|
4328
4388
|
return sendClientMsgWithResponse({
|
|
4329
4389
|
cmd: "ask-in-chat",
|
|
4330
4390
|
chatId,
|
|
4331
|
-
sourceMessage:
|
|
4391
|
+
sourceMessage: userMessage,
|
|
4332
4392
|
targetMessageId,
|
|
4333
4393
|
clientId,
|
|
4334
4394
|
generationOptions: {
|
|
4335
|
-
copilotId,
|
|
4336
|
-
stream,
|
|
4337
|
-
|
|
4395
|
+
copilotId: _optionalChain([options, 'optionalAccess', _69 => _69.copilotId]),
|
|
4396
|
+
stream: _optionalChain([options, 'optionalAccess', _70 => _70.stream]),
|
|
4397
|
+
timeout: _optionalChain([options, 'optionalAccess', _71 => _71.timeout]),
|
|
4398
|
+
knowledge: knowledge.length > 0 ? knowledge : void 0,
|
|
4338
4399
|
tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
|
|
4339
4400
|
name: tool.name,
|
|
4340
4401
|
description: tool.definition.description,
|
|
4341
4402
|
parameters: tool.definition.parameters
|
|
4342
|
-
}))
|
|
4343
|
-
timeout
|
|
4403
|
+
}))
|
|
4344
4404
|
}
|
|
4345
4405
|
});
|
|
4346
4406
|
},
|
|
4347
4407
|
abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
|
|
4408
|
+
setToolResult,
|
|
4348
4409
|
getStatus: () => managedSocket.getStatus(),
|
|
4349
4410
|
signals: {
|
|
4350
4411
|
chats\u03A3: context.chatsStore.chats\u03A3,
|
|
4351
4412
|
getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
|
|
4352
|
-
getToolDefinition\u03A3: context.toolsStore.
|
|
4353
|
-
getMessagesForChat\u03A3: context.messagesStore.getMessagesForChat\u03A3
|
|
4413
|
+
getToolDefinition\u03A3: context.toolsStore.getToolDefinition\u03A3
|
|
4354
4414
|
},
|
|
4355
|
-
|
|
4415
|
+
getChatById: context.chatsStore.getChatById,
|
|
4416
|
+
registerKnowledgeLayer,
|
|
4417
|
+
deregisterKnowledgeLayer,
|
|
4418
|
+
updateKnowledge,
|
|
4419
|
+
debug_getAllKnowledge,
|
|
4356
4420
|
registerChatTool: context.toolsStore.addToolDefinition,
|
|
4357
4421
|
unregisterChatTool: context.toolsStore.removeToolDefinition
|
|
4358
4422
|
},
|
|
@@ -10570,5 +10634,6 @@ var NotificationsApiError = HttpError;
|
|
|
10570
10634
|
|
|
10571
10635
|
|
|
10572
10636
|
|
|
10573
|
-
|
|
10637
|
+
|
|
10638
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
|
|
10574
10639
|
//# sourceMappingURL=index.cjs.map
|