feat: expose image generation to page agents
This commit is contained in:
@@ -4,6 +4,8 @@ import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { once } from 'node:events';
|
||||
import http from 'node:http';
|
||||
import { syncPublicDocxDownloads } from './mindspace-public-finish-sync.mjs';
|
||||
|
||||
function copyDocxGenerateSkill(root) {
|
||||
@@ -85,6 +87,60 @@ function startSandbox(root, envOverrides = {}) {
|
||||
return { child, request };
|
||||
}
|
||||
|
||||
test('generate_image calls the authenticated Memind internal route and returns MindSpace asset data', async (t) => {
|
||||
const requests = [];
|
||||
const api = http.createServer((req, res) => {
|
||||
let body = '';
|
||||
req.setEncoding('utf8');
|
||||
req.on('data', (chunk) => { body += chunk; });
|
||||
req.on('end', () => {
|
||||
requests.push({ url: req.url, authorization: req.headers.authorization, body: JSON.parse(body) });
|
||||
res.setHeader('content-type', 'application/json');
|
||||
res.end(JSON.stringify({
|
||||
data: {
|
||||
ok: true,
|
||||
purpose: 'hero',
|
||||
asset: {
|
||||
id: 'asset-1',
|
||||
publicUrl: 'https://m.example/image.webp',
|
||||
workspaceRelativePath: 'public/images/2026-07-19/image.webp',
|
||||
},
|
||||
},
|
||||
}));
|
||||
});
|
||||
});
|
||||
api.listen(0, '127.0.0.1');
|
||||
await once(api, 'listening');
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'mindspace-sandbox-generate-image-'));
|
||||
const sandbox = startSandbox(root, {
|
||||
ALLOWED_TOOLS: 'generate_image',
|
||||
PRIVATE_DATA_USER_ID: 'user-1',
|
||||
MINDSPACE_AGENT_API_BASE_URL: `http://127.0.0.1:${api.address().port}/api`,
|
||||
MINDSPACE_INTERNAL_AGENT_SECRET: 'internal-secret',
|
||||
});
|
||||
t.after(() => sandbox.child.kill());
|
||||
t.after(() => api.close());
|
||||
|
||||
await sandbox.request('initialize');
|
||||
const called = await sandbox.request('tools/call', {
|
||||
name: 'generate_image',
|
||||
arguments: { purpose: 'hero', prompt: 'calm reading room', idempotency_key: 'imgreq-1' },
|
||||
});
|
||||
assert.equal(called.result.isError, false);
|
||||
const result = JSON.parse(called.result.content[0].text);
|
||||
assert.equal(result.asset.id, 'asset-1');
|
||||
assert.deepEqual(requests, [{
|
||||
url: '/api/agent/mindspace_image_generate',
|
||||
authorization: 'Bearer internal-secret',
|
||||
body: {
|
||||
user_id: 'user-1',
|
||||
purpose: 'hero',
|
||||
prompt: 'calm reading room',
|
||||
negative_prompt: '',
|
||||
},
|
||||
}]);
|
||||
});
|
||||
|
||||
test('sandbox MCP rejects browser storage in generated page code', async (t) => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'mindspace-sandbox-storage-ban-'));
|
||||
const server = startSandbox(root, { ALLOWED_TOOLS: 'write_file,edit_file' });
|
||||
|
||||
Reference in New Issue
Block a user