feat(coding): add Pi Data Service product tools
This commit is contained in:
@@ -15,9 +15,24 @@ import { PiProductTools } from '../../electron/coding-runtime/pi/product-tools';
|
||||
type ExtensionHandler = (...arguments_: unknown[]) => Promise<unknown> | unknown;
|
||||
type ExtensionTool = {
|
||||
name: string;
|
||||
parameters?: Record<string, unknown>;
|
||||
execute?: (...arguments_: unknown[]) => Promise<unknown>;
|
||||
};
|
||||
|
||||
async function post(
|
||||
registration: Awaited<ReturnType<PiManagedExtensionHost['registerWorker']>>,
|
||||
body: Record<string, unknown>,
|
||||
): Promise<Response> {
|
||||
return await fetch(registration.env.MAKELORE_PI_BRIDGE_URL as string, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
authorization: `Bearer ${registration.env.MAKELORE_PI_WORKER_TOKEN}`,
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
}
|
||||
|
||||
const roots: string[] = [];
|
||||
const hosts: PiManagedExtensionHost[] = [];
|
||||
|
||||
@@ -209,7 +224,26 @@ describe('Makelore Pi extension bundle', () => {
|
||||
expect([...tools.keys()]).toEqual([
|
||||
'ask_user', 'subagent', 'agent_browser', 'game_asset_browser',
|
||||
'game_asset_review', 'task_state', 'changed_file', 'runtime_context',
|
||||
'data_service_configure', 'data_service_inspect', 'data_service_list_projects',
|
||||
'data_service_get_document', 'data_service_list_documents', 'data_service_put_document',
|
||||
'data_service_delete_document', 'data_service_remove_collection', 'data_service_reset',
|
||||
'data_service_remove_project',
|
||||
]);
|
||||
const dataServiceTools = [
|
||||
'data_service_configure', 'data_service_inspect', 'data_service_list_projects',
|
||||
'data_service_get_document', 'data_service_list_documents', 'data_service_put_document',
|
||||
'data_service_delete_document', 'data_service_remove_collection', 'data_service_reset',
|
||||
'data_service_remove_project',
|
||||
];
|
||||
for (const name of dataServiceTools) {
|
||||
const tool = tools.get(name);
|
||||
expect(tool?.parameters).toMatchObject({
|
||||
type: 'object', additionalProperties: false,
|
||||
});
|
||||
expect(Object.keys(tool?.parameters?.properties ?? {})).not.toEqual(
|
||||
expect.arrayContaining(['owner', 'project', 'path', 'token', 'endpoint', 'url', 'handle']),
|
||||
);
|
||||
}
|
||||
|
||||
const updates: unknown[] = [];
|
||||
const subagentResult = await tools.get('subagent')?.execute?.(
|
||||
@@ -317,6 +351,12 @@ describe('Makelore Pi extension bundle', () => {
|
||||
on: (event, handler) => handlers.set(event, handler),
|
||||
});
|
||||
expect(tools).toEqual([]);
|
||||
const forgedParentTool = await post(child, {
|
||||
action: 'product.invoke', conversationId: 'conversation-child', workerGeneration: 1,
|
||||
runId: 'run-parent', resourceId: 'forged-data-tool',
|
||||
toolName: 'data_service_inspect', input: {},
|
||||
});
|
||||
expect(forgedParentTool.status).toBe(403);
|
||||
await writeFile(path.join(root, 'child.txt'), 'after\n', 'utf8');
|
||||
await handlers.get('tool_call')?.({
|
||||
toolName: 'write', toolCallId: 'child-write', input: { path: 'child.txt' },
|
||||
|
||||
Reference in New Issue
Block a user