Skip to content

Commit 03580dd

Browse files
authored
fix: scope scout workspaces to chats (#95)
1 parent b0e64a9 commit 03580dd

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

packages/scout-agent/lib/compute/common.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Client } from "@blink-sdk/compute-protocol/client";
22
import type { Stream } from "@blink-sdk/multiplexer";
33
import Multiplexer from "@blink-sdk/multiplexer";
4+
import type * as blink from "blink";
45
import type { WebSocket } from "ws";
56

6-
export const WORKSPACE_INFO_KEY = "__compute_workspace_id";
7+
export const getWorkspaceInfoKey = (chatID: blink.ID) =>
8+
`__compute_workspace_id-${chatID}`;
79

810
export const newComputeClient = async (ws: WebSocket): Promise<Client> => {
911
return new Promise<Client>((resolve, reject) => {

packages/scout-agent/lib/compute/tools.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import { type Tool, tool } from "ai";
55
import * as blink from "blink";
66
import { z } from "zod";
77
import type { Message } from "../types";
8-
import { WORKSPACE_INFO_KEY } from "./common";
8+
import { getWorkspaceInfoKey } from "./common";
99

1010
export const createComputeTools = <T>({
1111
agent,
1212
githubAppContext,
1313
initializeWorkspace,
1414
createWorkspaceClient,
15+
chatID,
1516
}: {
1617
agent: blink.Agent<Message>;
1718
initializeWorkspace: (
@@ -23,9 +24,10 @@ export const createComputeTools = <T>({
2324
* If provided, the workspace_authenticate_git tool will be available.
2425
*/
2526
githubAppContext?: github.AppAuthOptions;
27+
chatID: blink.ID;
2628
}): Record<string, Tool> => {
2729
const newClient = async () => {
28-
const workspaceInfo = await agent.store.get(WORKSPACE_INFO_KEY);
30+
const workspaceInfo = await agent.store.get(getWorkspaceInfoKey(chatID));
2931
if (!workspaceInfo) {
3032
throw new Error(
3133
"Workspace not initialized. Call initialize_workspace first."
@@ -40,16 +42,17 @@ export const createComputeTools = <T>({
4042
description: "Initialize a workspace for the user.",
4143
inputSchema: z.object({}),
4244
execute: async (_args, _opts) => {
43-
const existingWorkspaceInfoRaw =
44-
await agent.store.get(WORKSPACE_INFO_KEY);
45+
const existingWorkspaceInfoRaw = await agent.store.get(
46+
getWorkspaceInfoKey(chatID)
47+
);
4548
const existingWorkspaceInfo = existingWorkspaceInfoRaw
4649
? JSON.parse(existingWorkspaceInfoRaw)
4750
: undefined;
4851
const { workspaceInfo, message } = await initializeWorkspace(
4952
existingWorkspaceInfo
5053
);
5154
await agent.store.set(
52-
WORKSPACE_INFO_KEY,
55+
getWorkspaceInfoKey(chatID),
5356
JSON.stringify(workspaceInfo)
5457
);
5558
return message;

packages/scout-agent/lib/core.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MockLanguageModelV2 } from "ai/test";
1010
import * as blink from "blink";
1111
import { Client } from "blink/client";
1212
import { WebSocketServer } from "ws";
13+
import { getWorkspaceInfoKey } from "./compute/common";
1314
import type { DaytonaClient, DaytonaSandbox } from "./compute/daytona/index";
1415
import { type Message, Scout } from "./index";
1516
import {
@@ -576,8 +577,9 @@ describe("daytona integration", () => {
576577
},
577578
});
578579

580+
const chatID = "test-chat-id" as blink.ID;
579581
const params = await scout.buildStreamTextParams({
580-
chatID: "test-chat-id" as blink.ID,
582+
chatID,
581583
messages: [],
582584
model: newMockModel({ textResponse: "test" }),
583585
});
@@ -610,7 +612,7 @@ describe("daytona integration", () => {
610612
});
611613

612614
// Verify workspace info was stored
613-
expect(apiServer.storage.__compute_workspace_id).toBe(
615+
expect(apiServer.storage[getWorkspaceInfoKey(chatID)]).toBe(
614616
JSON.stringify({ id: "new-daytona-workspace" })
615617
);
616618
});

packages/scout-agent/lib/core.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ export class Scout {
305305
githubAppContext,
306306
initializeWorkspace: initializeDockerWorkspace,
307307
createWorkspaceClient: getDockerWorkspaceClient,
308+
chatID,
308309
});
309310
break;
310311
}
@@ -313,6 +314,7 @@ export class Scout {
313314
computeTools = createComputeTools<DaytonaWorkspaceInfo>({
314315
agent: this.agent,
315316
githubAppContext,
317+
chatID,
316318
initializeWorkspace: (info) =>
317319
initializeDaytonaWorkspace(
318320
this.logger,

packages/scout-agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@blink-sdk/scout-agent",
33
"description": "A general-purpose AI agent with GitHub, Slack, web search, and compute capabilities built on Blink SDK.",
4-
"version": "0.0.7",
4+
"version": "0.0.8",
55
"type": "module",
66
"keywords": [
77
"blink",

0 commit comments

Comments
 (0)