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
4 changes: 3 additions & 1 deletion packages/scout-agent/lib/compute/common.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Client } from "@blink-sdk/compute-protocol/client";
import type { Stream } from "@blink-sdk/multiplexer";
import Multiplexer from "@blink-sdk/multiplexer";
import type * as blink from "blink";
import type { WebSocket } from "ws";

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

export const newComputeClient = async (ws: WebSocket): Promise<Client> => {
return new Promise<Client>((resolve, reject) => {
Expand Down
13 changes: 8 additions & 5 deletions packages/scout-agent/lib/compute/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { type Tool, tool } from "ai";
import * as blink from "blink";
import { z } from "zod";
import type { Message } from "../types";
import { WORKSPACE_INFO_KEY } from "./common";
import { getWorkspaceInfoKey } from "./common";

export const createComputeTools = <T>({
agent,
githubAppContext,
initializeWorkspace,
createWorkspaceClient,
chatID,
}: {
agent: blink.Agent<Message>;
initializeWorkspace: (
Expand All @@ -23,9 +24,10 @@ export const createComputeTools = <T>({
* If provided, the workspace_authenticate_git tool will be available.
*/
githubAppContext?: github.AppAuthOptions;
chatID: blink.ID;
}): Record<string, Tool> => {
const newClient = async () => {
const workspaceInfo = await agent.store.get(WORKSPACE_INFO_KEY);
const workspaceInfo = await agent.store.get(getWorkspaceInfoKey(chatID));
if (!workspaceInfo) {
throw new Error(
"Workspace not initialized. Call initialize_workspace first."
Expand All @@ -40,16 +42,17 @@ export const createComputeTools = <T>({
description: "Initialize a workspace for the user.",
inputSchema: z.object({}),
execute: async (_args, _opts) => {
const existingWorkspaceInfoRaw =
await agent.store.get(WORKSPACE_INFO_KEY);
const existingWorkspaceInfoRaw = await agent.store.get(
getWorkspaceInfoKey(chatID)
);
const existingWorkspaceInfo = existingWorkspaceInfoRaw
? JSON.parse(existingWorkspaceInfoRaw)
: undefined;
const { workspaceInfo, message } = await initializeWorkspace(
existingWorkspaceInfo
);
await agent.store.set(
WORKSPACE_INFO_KEY,
getWorkspaceInfoKey(chatID),
JSON.stringify(workspaceInfo)
);
return message;
Expand Down
6 changes: 4 additions & 2 deletions packages/scout-agent/lib/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MockLanguageModelV2 } from "ai/test";
import * as blink from "blink";
import { Client } from "blink/client";
import { WebSocketServer } from "ws";
import { getWorkspaceInfoKey } from "./compute/common";
import type { DaytonaClient, DaytonaSandbox } from "./compute/daytona/index";
import { type Message, Scout } from "./index";
import {
Expand Down Expand Up @@ -576,8 +577,9 @@ describe("daytona integration", () => {
},
});

const chatID = "test-chat-id" as blink.ID;
const params = await scout.buildStreamTextParams({
chatID: "test-chat-id" as blink.ID,
chatID,
messages: [],
model: newMockModel({ textResponse: "test" }),
});
Expand Down Expand Up @@ -610,7 +612,7 @@ describe("daytona integration", () => {
});

// Verify workspace info was stored
expect(apiServer.storage.__compute_workspace_id).toBe(
expect(apiServer.storage[getWorkspaceInfoKey(chatID)]).toBe(
JSON.stringify({ id: "new-daytona-workspace" })
);
});
Expand Down
2 changes: 2 additions & 0 deletions packages/scout-agent/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export class Scout {
githubAppContext,
initializeWorkspace: initializeDockerWorkspace,
createWorkspaceClient: getDockerWorkspaceClient,
chatID,
});
break;
}
Expand All @@ -313,6 +314,7 @@ export class Scout {
computeTools = createComputeTools<DaytonaWorkspaceInfo>({
agent: this.agent,
githubAppContext,
chatID,
initializeWorkspace: (info) =>
initializeDaytonaWorkspace(
this.logger,
Expand Down
2 changes: 1 addition & 1 deletion packages/scout-agent/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@blink-sdk/scout-agent",
"description": "A general-purpose AI agent with GitHub, Slack, web search, and compute capabilities built on Blink SDK.",
"version": "0.0.7",
"version": "0.0.8",
"type": "module",
"keywords": [
"blink",
Expand Down