@papercraneai/sandbox-agent 0.1.10 → 0.1.11

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.
Files changed (2) hide show
  1. package/dist/index.js +19 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -373,6 +373,8 @@ const app = express();
373
373
  app.use(express.json());
374
374
  const PORT = cliArgs.agentPort;
375
375
  let PROJECT_DIR = getProjectDir(); // Will be updated after template setup
376
+ // Per-request UI context for GetContext tool (keyed by requestId, cleaned up after each turn)
377
+ const sessionContext = {};
376
378
  // Registration state
377
379
  let environmentId = null;
378
380
  let connectionToken = null;
@@ -390,10 +392,17 @@ const showPreviewTool = tool("ShowPreview", "Shows the preview iframe for a spec
390
392
  });
391
393
  // Factory to create a fresh MCP server per chat session
392
394
  // (each Protocol instance can only be connected to one transport at a time)
393
- function createClientToolsServer() {
395
+ // contextKey links to the per-request entry in sessionContext for GetContext
396
+ function createClientToolsServer(contextKey) {
397
+ const getContextTool = tool("GetContext", "Returns the current UI context — which dashboard the user is viewing in the preview panel. Use this when the user's request is ambiguous about which dashboard they're referring to.", {}, async () => ({
398
+ content: [{
399
+ type: "text",
400
+ text: JSON.stringify(sessionContext[contextKey] || { selectedDashboard: null })
401
+ }]
402
+ }));
394
403
  return createSdkMcpServer({
395
404
  name: "client-tools",
396
- tools: [showPreviewTool]
405
+ tools: [showPreviewTool, getContextTool]
397
406
  });
398
407
  }
399
408
  // Recursively build file tree
@@ -1125,7 +1134,7 @@ const buildHooks = (res, verbose, requestId, requestStartTime) => {
1125
1134
  app.post("/chat", async (req, res) => {
1126
1135
  const requestStartTime = Date.now();
1127
1136
  const requestId = Math.random().toString(36).substring(7);
1128
- const { message, sessionId, systemPrompt, verbose = false, subdir,
1137
+ const { message, sessionId, systemPrompt, verbose = false, subdir, selectedDashboard,
1129
1138
  // Configurable agent options
1130
1139
  maxTurns = 40, allowedTools, disallowedTools, model, maxBudgetUsd } = req.body;
1131
1140
  const ctx = { requestId, sessionId };
@@ -1187,9 +1196,12 @@ app.post("/chat", async (req, res) => {
1187
1196
  "WebSearch",
1188
1197
  "AgentOutput",
1189
1198
  "KillShell",
1190
- "mcp__client-tools__ShowPreview"
1199
+ "mcp__client-tools__ShowPreview",
1200
+ "mcp__client-tools__GetContext"
1191
1201
  ];
1192
- const clientTools = createClientToolsServer();
1202
+ // Store UI context for GetContext tool
1203
+ sessionContext[requestId] = { selectedDashboard: selectedDashboard || null };
1204
+ const clientTools = createClientToolsServer(requestId);
1193
1205
  const options = {
1194
1206
  maxTurns,
1195
1207
  cwd,
@@ -1278,7 +1290,8 @@ app.post("/chat", async (req, res) => {
1278
1290
  }
1279
1291
  }
1280
1292
  finally {
1281
- // Close the per-session MCP server to free resources
1293
+ // Clean up per-request context and close MCP server
1294
+ delete sessionContext[requestId];
1282
1295
  await clientTools.instance?.close().catch(() => { });
1283
1296
  }
1284
1297
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@papercraneai/sandbox-agent",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Claude Agent SDK server for sandbox environments",
5
5
  "license": "MIT",
6
6
  "type": "module",