Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
## vNEXT (not yet published)

## v3.4.1

### `@liveblocks/core`

- Fix a bug where copilot id wasn't passed when setting tool call result if a
tool call was defined with `execute` callback.

### `@liveblocks/react`

- Update `useSendAiMessage` to use the the last used copilot id in a chat when
no copilot id is passed to the hook or the method returned by the hook.

## v3.4.0

### `@liveblocks/react`
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG_PUBLIC.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Tool calls will now stream in while under construction. This means that tools
will render sooner and more often re-render, while `partialArgs` are streaming
in.

> New behavior (>=3.4):
> New behavior (v3.4 and higher):
>
> - 1st render: `{ stage: "receiving", partialArgs: {} }`
> - 2nd render: `{ stage: "receiving", partialArgs: { cities: [] } }`
Expand All @@ -39,7 +39,7 @@ in.
> - Then `{ stage: "executing", args: { cities: "Paris" } }` (same as before)
> - And `{ stage: "executed", args, result }` (same as before)
>
> Before (<3.4):
> Before (v3.3 and lower):
>
> - Stage "receiving" would never happen
> - 1st render would be with
Expand Down
98 changes: 49 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/liveblocks-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liveblocks/client",
"version": "3.4.0",
"version": "3.4.1",
"description": "A client that lets you interact with Liveblocks servers. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
"license": "Apache-2.0",
"type": "module",
Expand Down Expand Up @@ -34,7 +34,7 @@
"test:watch": "NODE_OPTIONS=\"--no-deprecation\" vitest"
},
"dependencies": {
"@liveblocks/core": "3.4.0"
"@liveblocks/core": "3.4.1"
},
"devDependencies": {
"@liveblocks/eslint-config": "*",
Expand Down
2 changes: 1 addition & 1 deletion packages/liveblocks-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liveblocks/core",
"version": "3.4.0",
"version": "3.4.1",
"description": "Private internals for Liveblocks. DO NOT import directly from this package!",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
31 changes: 23 additions & 8 deletions packages/liveblocks-core/src/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type {
ClearChatResponse,
ClientAiMsg,
CmdId,
CopilotId,
CreateChatOptions,
DeleteChatResponse,
DeleteMessageResponse,
Expand Down Expand Up @@ -438,18 +439,19 @@ function createStore_forChatMessages(
function createOptimistically(
chatId: string,
role: "assistant",
parentId: MessageId | null
parentId: MessageId | null,
copilotId?: CopilotId
): MessageId;
function createOptimistically(
chatId: string,
role: "user" | "assistant",
parentId: MessageId | null,
third?: AiUserContentPart[]
third?: AiUserContentPart[] | CopilotId
) {
const id = `ms_${nanoid()}` as MessageId;
const createdAt = now();
if (role === "user") {
const content = third!; // eslint-disable-line
const content = third as AiUserContentPart[];
upsert({
id,
chatId,
Expand All @@ -460,6 +462,7 @@ function createStore_forChatMessages(
_optimistic: true,
} satisfies AiUserMessage);
} else {
const copilotId = third as CopilotId | undefined;
upsert({
id,
chatId,
Expand All @@ -468,6 +471,7 @@ function createStore_forChatMessages(
createdAt,
status: "generating",
contentSoFar: [],
copilotId,
_optimistic: true,
} satisfies AiGeneratingAssistantMessage);
}
Expand Down Expand Up @@ -554,8 +558,8 @@ function createStore_forChatMessages(
message.chatId,
message.id,
toolInvocation.invocationId,
result ?? { data: {} }
// TODO Pass in AiGenerationOptions here, or make the backend use the same options
result ?? { data: {} },
{ copilotId: message.copilotId } // TODO: Should we pass the other generation options (tools, knowledge) as well?
);
})().catch((err) => {
console.error(
Expand Down Expand Up @@ -754,10 +758,20 @@ function createStore_forChatMessages(
.getOrCreate(branch || null);
}

function getLastUsedCopilotId(chatId: string): CopilotId | undefined {
const pool = messagePoolByChatIdΣ.getOrCreate(chatId).get();
// Find the most recent non-deleted assistant message
const latest = pool.sorted.findRight(
(m) => m.role === "assistant" && !m.deletedAt
);
return latest?.copilotId;
}

return {
// Readers
getMessageById,
getChatMessagesForBranchΣ,
getLastUsedCopilotId,

// Mutations
createOptimistically,
Expand Down Expand Up @@ -887,6 +901,8 @@ export type Ai = {
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
queryChats: (query: AiChatsQuery) => AiChat[];
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
getLastUsedCopilotId: (chatId: string) => CopilotId | undefined;
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
registerKnowledgeLayer: (uniqueLayerId: string) => LayerKey;
/** @private This API will change, and is not considered stable. DO NOT RELY on it. */
deregisterKnowledgeLayer: (layerKey: LayerKey) => void;
Expand Down Expand Up @@ -982,9 +998,7 @@ export function createAi(config: AiConfig): Ai {
// NoOp for now, but we should maybe fetch messages or something?
}

function onDidDisconnect() {
console.warn("onDidDisconnect");
}
function onDidDisconnect() {}

function handleServerMessage(event: IWebSocketMessageEvent) {
if (typeof event.data !== "string")
Expand Down Expand Up @@ -1335,6 +1349,7 @@ export function createAi(config: AiConfig): Ai {

getChatById: context.chatsStore.getChatById,
queryChats: context.chatsStore.findMany,
getLastUsedCopilotId: context.messagesStore.getLastUsedCopilotId,
registerKnowledgeLayer,
deregisterKnowledgeLayer,
updateKnowledge,
Expand Down
Loading
Loading