@liveblocks/core 2.25.0-aiprivatebeta6 → 2.25.0-aiprivatebeta8

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.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-aiprivatebeta6";
9
+ var PKG_VERSION = "2.25.0-aiprivatebeta8";
10
10
  var PKG_FORMAT = "esm";
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 (lastPart?.type === "text") {
3695
3693
  lastPart.text += delta.textDelta;
@@ -3700,15 +3698,16 @@ function appendDelta(content, delta) {
3700
3698
  case "reasoning-delta":
3701
3699
  if (lastPart?.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: delta.textDelta ?? "",
3708
- signature: delta.signature
3704
+ text: 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,63 @@ function appendDelta(content, delta) {
3716
3715
 
3717
3716
  // src/ai.ts
3718
3717
  var DEFAULT_REQUEST_TIMEOUT = 4e3;
3719
- var DEFAULT_AI_TIMEOUT = 3e4;
3718
+ var KnowledgeStack = class {
3719
+ #_layers;
3720
+ #stack;
3721
+ // / \
3722
+ // knowledge key "layer" key
3723
+ // (random, or optionally (one entry per mounted component)
3724
+ // set by user)
3725
+ #_cache;
3726
+ constructor() {
3727
+ this.#_layers = /* @__PURE__ */ new Set();
3728
+ this.#stack = new DefaultMap(
3729
+ () => /* @__PURE__ */ new Map()
3730
+ );
3731
+ this.#_cache = void 0;
3732
+ }
3733
+ // Typically a useId()
3734
+ registerLayer(uniqueLayerId) {
3735
+ const layerKey = uniqueLayerId;
3736
+ if (this.#_layers.has(layerKey))
3737
+ raise(`Layer '${layerKey}' already exists, provide a unique layer id`);
3738
+ this.#_layers.add(layerKey);
3739
+ return layerKey;
3740
+ }
3741
+ deregisterLayer(layerKey) {
3742
+ this.#_layers.delete(layerKey);
3743
+ let deleted = false;
3744
+ for (const [key, knowledge] of this.#stack) {
3745
+ if (knowledge.delete(layerKey)) {
3746
+ deleted = true;
3747
+ }
3748
+ if (knowledge.size === 0)
3749
+ this.#stack.delete(key);
3750
+ }
3751
+ if (deleted) {
3752
+ this.invalidate();
3753
+ }
3754
+ }
3755
+ get() {
3756
+ return this.#_cache ??= this.#recompute();
3757
+ }
3758
+ invalidate() {
3759
+ this.#_cache = void 0;
3760
+ }
3761
+ #recompute() {
3762
+ return Array.from(this.#stack.values()).flatMap(
3763
+ (layer) => (
3764
+ // Return only the last item (returns [] when empty)
3765
+ Array.from(layer.values()).slice(-1).filter(isDefined)
3766
+ )
3767
+ );
3768
+ }
3769
+ updateKnowledge(layerKey, key, data) {
3770
+ if (!this.#_layers.has(layerKey)) raise(`Unknown layer key: ${layerKey}`);
3771
+ this.#stack.getOrCreate(key).set(layerKey, data);
3772
+ this.invalidate();
3773
+ }
3774
+ };
3720
3775
  function now() {
3721
3776
  return (/* @__PURE__ */ new Date()).toISOString();
3722
3777
  }
@@ -3730,6 +3785,11 @@ function createStore_forTools() {
3730
3785
  return toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(toolName);
3731
3786
  }
3732
3787
  function addToolDefinition(chatId, name, definition) {
3788
+ if (!definition.execute && !definition.render) {
3789
+ throw new Error(
3790
+ "A tool definition must have an execute() function, a render property, or both."
3791
+ );
3792
+ }
3733
3793
  toolsByChatId\u03A3.getOrCreate(chatId).getOrCreate(name).set(definition);
3734
3794
  }
3735
3795
  function removeToolDefinition(chatId, toolName) {
@@ -3751,13 +3811,14 @@ function createStore_forTools() {
3751
3811
  }).filter((tool) => tool !== null);
3752
3812
  }
3753
3813
  return {
3754
- getToolCallByName\u03A3: getToolDefinition\u03A3,
3814
+ getToolDefinition\u03A3,
3755
3815
  getToolsForChat,
3756
3816
  addToolDefinition,
3757
3817
  removeToolDefinition
3758
3818
  };
3759
3819
  }
3760
- function createStore_forChatMessages() {
3820
+ function createStore_forChatMessages(toolsStore, setToolResult) {
3821
+ const seenToolCallIds = /* @__PURE__ */ new Set();
3761
3822
  const messagePoolByChatId\u03A3 = new DefaultMap(
3762
3823
  (_chatId) => new MutableSignal(
3763
3824
  new TreePool(
@@ -3767,7 +3828,7 @@ function createStore_forChatMessages() {
3767
3828
  )
3768
3829
  )
3769
3830
  );
3770
- const pendingMessages\u03A3 = new MutableSignal(
3831
+ const generatingMessages\u03A3 = new MutableSignal(
3771
3832
  /* @__PURE__ */ new Map()
3772
3833
  );
3773
3834
  function createOptimistically(chatId, role, parentId, third) {
@@ -3791,7 +3852,7 @@ function createStore_forChatMessages() {
3791
3852
  role,
3792
3853
  parentId,
3793
3854
  createdAt,
3794
- status: "pending",
3855
+ status: "generating",
3795
3856
  contentSoFar: [],
3796
3857
  _optimistic: true
3797
3858
  });
@@ -3810,7 +3871,7 @@ function createStore_forChatMessages() {
3810
3871
  if (!chatMsgs\u03A3) return;
3811
3872
  const existing = chatMsgs\u03A3.get().get(messageId);
3812
3873
  if (!existing || existing.deletedAt) return;
3813
- if (existing.role === "assistant" && (existing.status === "pending" || existing.status === "failed")) {
3874
+ if (existing.role === "assistant" && existing.status !== "completed") {
3814
3875
  upsert({ ...existing, deletedAt: now(), contentSoFar: [] });
3815
3876
  } else {
3816
3877
  upsert({ ...existing, deletedAt: now(), content: [] });
@@ -3825,19 +3886,54 @@ function createStore_forChatMessages() {
3825
3886
  batch(() => {
3826
3887
  const chatMsgs\u03A3 = messagePoolByChatId\u03A3.getOrCreate(message.chatId);
3827
3888
  chatMsgs\u03A3.mutate((pool) => pool.upsert(message));
3828
- if (message.role === "assistant" && message.status === "pending") {
3829
- pendingMessages\u03A3.mutate((lut) => {
3889
+ if (message.role === "assistant" && message.status === "generating") {
3890
+ generatingMessages\u03A3.mutate((lut) => {
3830
3891
  lut.set(message.id, structuredClone(message));
3831
3892
  });
3832
3893
  } else {
3833
- pendingMessages\u03A3.mutate((lut) => {
3894
+ generatingMessages\u03A3.mutate((lut) => {
3834
3895
  lut.delete(message.id);
3835
3896
  });
3836
3897
  }
3898
+ if (message.role === "assistant" && message.status === "awaiting-tool") {
3899
+ for (const toolCall of message.contentSoFar.filter(
3900
+ (part) => part.type === "tool-invocation" && part.status === "executing"
3901
+ )) {
3902
+ if (seenToolCallIds.has(toolCall.toolCallId)) {
3903
+ continue;
3904
+ }
3905
+ seenToolCallIds.add(toolCall.toolCallId);
3906
+ const toolDef = toolsStore.getToolDefinition\u03A3(message.chatId, toolCall.toolName).get();
3907
+ const respondSync = (result) => {
3908
+ setToolResult(
3909
+ message.chatId,
3910
+ message.id,
3911
+ toolCall.toolCallId,
3912
+ result
3913
+ // TODO Pass in AiGenerationOptions here, or make the backend use the same options
3914
+ ).catch((err) => {
3915
+ error2(
3916
+ `Error trying to respond to tool-call: ${String(err)} (in respond())`
3917
+ );
3918
+ });
3919
+ };
3920
+ const executeFn = toolDef?.execute;
3921
+ if (executeFn) {
3922
+ (async () => {
3923
+ const result = await executeFn(toolCall.args);
3924
+ respondSync(result);
3925
+ })().catch((err) => {
3926
+ error2(
3927
+ `Error trying to respond to tool-call: ${String(err)} (in execute())`
3928
+ );
3929
+ });
3930
+ }
3931
+ }
3932
+ }
3837
3933
  });
3838
3934
  }
3839
3935
  function addDelta(messageId, delta) {
3840
- pendingMessages\u03A3.mutate((lut) => {
3936
+ generatingMessages\u03A3.mutate((lut) => {
3841
3937
  const message = lut.get(messageId);
3842
3938
  if (message === void 0) return false;
3843
3939
  appendDelta(message.contentSoFar, delta);
@@ -3845,10 +3941,10 @@ function createStore_forChatMessages() {
3845
3941
  return true;
3846
3942
  });
3847
3943
  }
3848
- function* iterPendingMessages() {
3944
+ function* iterGeneratingMessages() {
3849
3945
  for (const chatMsgs\u03A3 of messagePoolByChatId\u03A3.values()) {
3850
3946
  for (const m of chatMsgs\u03A3.get()) {
3851
- if (m.role === "assistant" && m.status === "pending" && !m._optimistic) {
3947
+ if (m.role === "assistant" && m.status === "generating" && !m._optimistic) {
3852
3948
  yield m;
3853
3949
  }
3854
3950
  }
@@ -3856,7 +3952,7 @@ function createStore_forChatMessages() {
3856
3952
  }
3857
3953
  function failAllPending() {
3858
3954
  batch(() => {
3859
- pendingMessages\u03A3.mutate((lut) => {
3955
+ generatingMessages\u03A3.mutate((lut) => {
3860
3956
  let deleted = false;
3861
3957
  for (const [k, v] of lut) {
3862
3958
  if (!v._optimistic) {
@@ -3867,7 +3963,7 @@ function createStore_forChatMessages() {
3867
3963
  return deleted;
3868
3964
  });
3869
3965
  upsertMany(
3870
- Array.from(iterPendingMessages()).map(
3966
+ Array.from(iterGeneratingMessages()).map(
3871
3967
  (message) => ({
3872
3968
  ...message,
3873
3969
  status: "failed",
@@ -3902,11 +3998,20 @@ function createStore_forChatMessages() {
3902
3998
  }
3903
3999
  function selectSpine(leaf) {
3904
4000
  const spine = [];
4001
+ let lastVisitedMessage = null;
3905
4002
  for (const message2 of pool.walkUp(leaf.id)) {
3906
4003
  const prev = first(pool.walkLeft(message2.id, isAlive))?.id ?? null;
3907
4004
  const next = first(pool.walkRight(message2.id, isAlive))?.id ?? null;
3908
4005
  if (!message2.deletedAt || prev || next) {
3909
- spine.push({ ...message2, prev, next });
4006
+ const node = {
4007
+ ...message2,
4008
+ navigation: { parent: null, prev, next }
4009
+ };
4010
+ if (lastVisitedMessage !== null) {
4011
+ lastVisitedMessage.navigation.parent = node.id;
4012
+ }
4013
+ lastVisitedMessage = node;
4014
+ spine.push(node);
3910
4015
  }
3911
4016
  }
3912
4017
  return spine.reverse();
@@ -3932,18 +4037,6 @@ function createStore_forChatMessages() {
3932
4037
  }
3933
4038
  return fallback();
3934
4039
  }
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
4040
  const immutableMessagesByBranch = new DefaultMap((chatId) => {
3948
4041
  return new DefaultMap((branchId) => {
3949
4042
  const messages\u03A3 = DerivedSignal.from(() => {
@@ -3951,16 +4044,16 @@ function createStore_forChatMessages() {
3951
4044
  return selectBranch(pool, branchId);
3952
4045
  }, shallow2);
3953
4046
  return DerivedSignal.from(() => {
3954
- const pendingMessages = pendingMessages\u03A3.get();
4047
+ const generatingMessages = generatingMessages\u03A3.get();
3955
4048
  return messages\u03A3.get().map((message) => {
3956
- if (message.role !== "assistant" || message.status !== "pending") {
4049
+ if (message.role !== "assistant" || message.status !== "generating") {
3957
4050
  return message;
3958
4051
  }
3959
- const pendingMessage = pendingMessages.get(message.id);
3960
- if (pendingMessage === void 0) return message;
4052
+ const generatingMessage = generatingMessages.get(message.id);
4053
+ if (generatingMessage === void 0) return message;
3961
4054
  return {
3962
4055
  ...message,
3963
- contentSoFar: pendingMessage.contentSoFar
4056
+ contentSoFar: generatingMessage.contentSoFar
3964
4057
  };
3965
4058
  });
3966
4059
  }, shallow);
@@ -3969,21 +4062,10 @@ function createStore_forChatMessages() {
3969
4062
  function getChatMessagesForBranch\u03A3(chatId, branch) {
3970
4063
  return immutableMessagesByBranch.getOrCreate(chatId).getOrCreate(branch || null);
3971
4064
  }
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
4065
  return {
3982
4066
  // Readers
3983
4067
  getMessageById,
3984
4068
  getChatMessagesForBranch\u03A3,
3985
- getMessagesForChat\u03A3,
3986
- getLatestUserMessageAncestor,
3987
4069
  // Mutations
3988
4070
  createOptimistically,
3989
4071
  upsert,
@@ -3999,7 +4081,7 @@ function createStore_forUserAiChats() {
3999
4081
  SortedList.with((x, y) => y.createdAt < x.createdAt)
4000
4082
  );
4001
4083
  const chats\u03A3 = DerivedSignal.from(
4002
- () => Array.from(mutable\u03A3.get()).filter((c) => !c.ephemeral && !c.deletedAt)
4084
+ () => Array.from(mutable\u03A3.get()).filter((c) => !c.deletedAt)
4003
4085
  );
4004
4086
  function upsertMany(chats) {
4005
4087
  mutable\u03A3.mutate((list) => {
@@ -4015,8 +4097,12 @@ function createStore_forUserAiChats() {
4015
4097
  function remove(chatId) {
4016
4098
  mutable\u03A3.mutate((list) => list.removeBy((c) => c.id === chatId, 1));
4017
4099
  }
4100
+ function getChatById(chatId) {
4101
+ return Array.from(mutable\u03A3.get()).find((chat) => chat.id === chatId);
4102
+ }
4018
4103
  return {
4019
4104
  chats\u03A3,
4105
+ getChatById,
4020
4106
  // Mutations
4021
4107
  upsert,
4022
4108
  upsertMany,
@@ -4032,8 +4118,8 @@ function createAi(config) {
4032
4118
  );
4033
4119
  const clientId = nanoid(7);
4034
4120
  const chatsStore = createStore_forUserAiChats();
4035
- const messagesStore = createStore_forChatMessages();
4036
4121
  const toolsStore = createStore_forTools();
4122
+ const messagesStore = createStore_forChatMessages(toolsStore, setToolResult);
4037
4123
  const context = {
4038
4124
  staticSessionInfoSig: new Signal(null),
4039
4125
  dynamicSessionInfoSig: new Signal(null),
@@ -4041,7 +4127,7 @@ function createAi(config) {
4041
4127
  chatsStore,
4042
4128
  messagesStore,
4043
4129
  toolsStore,
4044
- knowledgeByChatId: /* @__PURE__ */ new Map()
4130
+ knowledge: new KnowledgeStack()
4045
4131
  };
4046
4132
  let lastTokenKey;
4047
4133
  function onStatusDidChange(_newStatus) {
@@ -4143,7 +4229,7 @@ function createAi(config) {
4143
4229
  case "get-chats":
4144
4230
  context.chatsStore.upsertMany(msg.chats);
4145
4231
  break;
4146
- case "create-chat":
4232
+ case "get-or-create-chat":
4147
4233
  context.chatsStore.upsert(msg.chat);
4148
4234
  break;
4149
4235
  case "delete-chat":
@@ -4168,6 +4254,11 @@ function createAi(config) {
4168
4254
  break;
4169
4255
  case "abort-ai":
4170
4256
  break;
4257
+ case "set-tool-result":
4258
+ if (msg.ok) {
4259
+ context.messagesStore.upsert(msg.message);
4260
+ }
4261
+ break;
4171
4262
  default:
4172
4263
  return assertNever(msg, "Unhandled case");
4173
4264
  }
@@ -4218,13 +4309,11 @@ function createAi(config) {
4218
4309
  cursor: options.cursor
4219
4310
  });
4220
4311
  }
4221
- function createChat(id, title, options) {
4312
+ function getOrCreateChat(id, options) {
4222
4313
  return sendClientMsgWithResponse({
4223
- cmd: "create-chat",
4314
+ cmd: "get-or-create-chat",
4224
4315
  id,
4225
- title,
4226
- ephemeral: options?.ephemeral ?? false,
4227
- metadata: options?.metadata ?? {}
4316
+ options
4228
4317
  });
4229
4318
  }
4230
4319
  function getMessageTree(chatId) {
@@ -4233,62 +4322,50 @@ function createAi(config) {
4233
4322
  chatId
4234
4323
  });
4235
4324
  }
4236
- function registerKnowledgeSource(chatId, data) {
4237
- const knowledge = context.knowledgeByChatId.get(chatId);
4238
- if (knowledge === void 0) {
4239
- context.knowledgeByChatId.set(chatId, /* @__PURE__ */ new Set([data]));
4240
- } else {
4241
- knowledge.add(data);
4242
- }
4243
- return () => {
4244
- const knowledge2 = context.knowledgeByChatId.get(chatId);
4245
- if (knowledge2 !== void 0) {
4246
- knowledge2.delete(data);
4247
- if (knowledge2.size === 0) {
4248
- context.knowledgeByChatId.delete(chatId);
4249
- }
4250
- }
4251
- };
4325
+ function registerKnowledgeLayer(uniqueLayerId) {
4326
+ return context.knowledge.registerLayer(uniqueLayerId);
4252
4327
  }
4253
- function ask(chatId, messageId, options) {
4254
- const targetMessageId = context.messagesStore.createOptimistically(
4255
- chatId,
4256
- "assistant",
4257
- messageId
4258
- );
4259
- const copilotId = options?.copilotId;
4260
- const stream = options?.stream ?? false;
4261
- const timeout = options?.timeout ?? DEFAULT_AI_TIMEOUT;
4262
- const knowledge = context.knowledgeByChatId.get(chatId);
4328
+ function deregisterKnowledgeLayer(layerKey) {
4329
+ context.knowledge.deregisterLayer(layerKey);
4330
+ }
4331
+ function updateKnowledge(layerKey, data, key = nanoid()) {
4332
+ context.knowledge.updateKnowledge(layerKey, key, data);
4333
+ }
4334
+ function debug_getAllKnowledge() {
4335
+ return context.knowledge.get();
4336
+ }
4337
+ async function setToolResult(chatId, messageId, toolCallId, result, options) {
4338
+ const knowledge = context.knowledge.get();
4263
4339
  return sendClientMsgWithResponse({
4264
- cmd: "ask-in-chat",
4340
+ cmd: "set-tool-result",
4265
4341
  chatId,
4266
- sourceMessage: messageId,
4267
- targetMessageId,
4342
+ messageId,
4343
+ toolCallId,
4268
4344
  clientId,
4345
+ result,
4269
4346
  generationOptions: {
4270
- copilotId,
4271
- stream,
4272
- knowledge: knowledge ? Array.from(knowledge) : void 0,
4347
+ copilotId: options?.copilotId,
4348
+ stream: options?.stream,
4349
+ timeout: options?.timeout,
4350
+ knowledge: knowledge.length > 0 ? knowledge : void 0,
4273
4351
  tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
4274
4352
  name: tool.name,
4275
4353
  description: tool.definition.description,
4276
4354
  parameters: tool.definition.parameters
4277
- })),
4278
- timeout
4355
+ }))
4279
4356
  }
4280
4357
  });
4281
4358
  }
4282
4359
  return Object.defineProperty(
4283
4360
  {
4284
4361
  [kInternal]: {
4285
- debugContext: () => context
4362
+ context
4286
4363
  },
4287
4364
  connect: () => managedSocket.connect(),
4288
4365
  reconnect: () => managedSocket.reconnect(),
4289
4366
  disconnect: () => managedSocket.disconnect(),
4290
4367
  getChats,
4291
- createChat,
4368
+ getOrCreateChat,
4292
4369
  deleteChat: (chatId) => {
4293
4370
  return sendClientMsgWithResponse({
4294
4371
  cmd: "delete-chat",
@@ -4298,60 +4375,40 @@ function createAi(config) {
4298
4375
  getMessageTree,
4299
4376
  deleteMessage: (chatId, messageId) => sendClientMsgWithResponse({ cmd: "delete-message", chatId, messageId }),
4300
4377
  clearChat: (chatId) => sendClientMsgWithResponse({ cmd: "clear-chat", chatId }),
4301
- regenerateMessage: (chatId, messageId, options) => {
4302
- const parentUserMessageId = context.messagesStore.getLatestUserMessageAncestor(chatId, messageId);
4303
- if (parentUserMessageId === null) {
4304
- throw new Error(
4305
- `Unable to find user message ancestor for messageId: ${messageId}`
4306
- );
4307
- }
4308
- return ask(chatId, parentUserMessageId, options);
4309
- },
4310
- addUserMessageAndAsk: async (chatId, parentMessageId, message, options) => {
4311
- const content = [{ type: "text", text: message }];
4312
- const newMessageId = context.messagesStore.createOptimistically(
4313
- chatId,
4314
- "user",
4315
- parentMessageId,
4316
- content
4317
- );
4318
- const targetMessageId = context.messagesStore.createOptimistically(
4319
- chatId,
4320
- "assistant",
4321
- newMessageId
4322
- );
4323
- const copilotId = options?.copilotId;
4324
- const stream = options?.stream ?? false;
4325
- const timeout = options?.timeout ?? DEFAULT_AI_TIMEOUT;
4326
- const knowledge = context.knowledgeByChatId.get(chatId);
4378
+ askUserMessageInChat: async (chatId, userMessage, targetMessageId, options) => {
4379
+ const knowledge = context.knowledge.get();
4327
4380
  return sendClientMsgWithResponse({
4328
4381
  cmd: "ask-in-chat",
4329
4382
  chatId,
4330
- sourceMessage: { id: newMessageId, parentMessageId, content },
4383
+ sourceMessage: userMessage,
4331
4384
  targetMessageId,
4332
4385
  clientId,
4333
4386
  generationOptions: {
4334
- copilotId,
4335
- stream,
4336
- knowledge: knowledge ? Array.from(knowledge) : void 0,
4387
+ copilotId: options?.copilotId,
4388
+ stream: options?.stream,
4389
+ timeout: options?.timeout,
4390
+ knowledge: knowledge.length > 0 ? knowledge : void 0,
4337
4391
  tools: context.toolsStore.getToolsForChat(chatId).map((tool) => ({
4338
4392
  name: tool.name,
4339
4393
  description: tool.definition.description,
4340
4394
  parameters: tool.definition.parameters
4341
- })),
4342
- timeout
4395
+ }))
4343
4396
  }
4344
4397
  });
4345
4398
  },
4346
4399
  abort: (messageId) => sendClientMsgWithResponse({ cmd: "abort-ai", messageId }),
4400
+ setToolResult,
4347
4401
  getStatus: () => managedSocket.getStatus(),
4348
4402
  signals: {
4349
4403
  chats\u03A3: context.chatsStore.chats\u03A3,
4350
4404
  getChatMessagesForBranch\u03A3: context.messagesStore.getChatMessagesForBranch\u03A3,
4351
- getToolDefinition\u03A3: context.toolsStore.getToolCallByName\u03A3,
4352
- getMessagesForChat\u03A3: context.messagesStore.getMessagesForChat\u03A3
4405
+ getChatById: context.chatsStore.getChatById,
4406
+ getToolDefinition\u03A3: context.toolsStore.getToolDefinition\u03A3
4353
4407
  },
4354
- registerKnowledgeSource,
4408
+ registerKnowledgeLayer,
4409
+ deregisterKnowledgeLayer,
4410
+ updateKnowledge,
4411
+ debug_getAllKnowledge,
4355
4412
  registerChatTool: context.toolsStore.addToolDefinition,
4356
4413
  unregisterChatTool: context.toolsStore.removeToolDefinition
4357
4414
  },