feat(coding): add Pi Data Service product tools

This commit is contained in:
2026-08-26 19:58:38 +08:00
parent 44bcdf52fc
commit 1d63233cd0
12 changed files with 790 additions and 26 deletions

View File

@@ -14,6 +14,12 @@ const MUTATION_TOOLS = new Set([
'write',
'game_asset_browser',
'game_asset_review',
'data_service_configure',
'data_service_put_document',
'data_service_delete_document',
'data_service_remove_collection',
'data_service_reset',
'data_service_remove_project',
]);
const WORKER_ROLE = process.env.MAKELORE_PI_WORKER_ROLE || 'parent';
const leases = new Map();
@@ -283,6 +289,127 @@ export default function makeloreRuntime(pi) {
'Read the safe selected-skill and command catalog for this managed worker.',
{ type: 'object', additionalProperties: false, properties: {} },
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_configure',
'Data Service configure',
'Configure collections for the active Makelore project Data Service instance.',
{
type: 'object', additionalProperties: false, required: ['collections'],
properties: {
collections: {
type: 'array', minItems: 0, maxItems: 20,
items: { type: 'string', minLength: 1, maxLength: 48, pattern: '^[a-z][a-z0-9_-]{0,47}$' },
},
},
},
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_inspect',
'Data Service inspect',
'Inspect the active Makelore project Data Service instance.',
{ type: 'object', additionalProperties: false, properties: {} },
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_list_projects',
'Data Service projects',
'List Data Service instances available to the signed-in account.',
{ type: 'object', additionalProperties: false, properties: {} },
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_get_document',
'Data Service get document',
'Read one document from a collection in the active Makelore project.',
{
type: 'object', additionalProperties: false, required: ['collection', 'document_id'],
properties: {
collection: { type: 'string', minLength: 1, maxLength: 48, pattern: '^[a-z][a-z0-9_-]{0,47}$' },
document_id: { type: 'string', minLength: 1, maxLength: 128, pattern: '^[A-Za-z0-9._~-]{1,128}$' },
},
},
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_list_documents',
'Data Service list documents',
'List documents from a collection in the active Makelore project.',
{
type: 'object', additionalProperties: false, required: ['collection'],
properties: {
collection: { type: 'string', minLength: 1, maxLength: 48, pattern: '^[a-z][a-z0-9_-]{0,47}$' },
limit: { type: 'integer', minimum: 1, maximum: 100 },
cursor: { type: 'string', minLength: 1, maxLength: 1024 },
},
},
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_put_document',
'Data Service put document',
'Create or update one document in a collection in the active Makelore project.',
{
type: 'object', additionalProperties: false,
required: ['collection', 'document_id', 'data'],
properties: {
collection: { type: 'string', minLength: 1, maxLength: 48, pattern: '^[a-z][a-z0-9_-]{0,47}$' },
document_id: { type: 'string', minLength: 1, maxLength: 128, pattern: '^[A-Za-z0-9._~-]{1,128}$' },
data: { type: 'object' },
if_revision: { type: 'integer', minimum: 1 },
},
},
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_delete_document',
'Data Service delete document',
'Delete one document from the active Makelore project after explicit confirmation.',
{
type: 'object', additionalProperties: false,
required: ['collection', 'document_id', 'confirmed'],
properties: {
collection: { type: 'string', minLength: 1, maxLength: 48, pattern: '^[a-z][a-z0-9_-]{0,47}$' },
document_id: { type: 'string', minLength: 1, maxLength: 128, pattern: '^[A-Za-z0-9._~-]{1,128}$' },
if_revision: { type: 'integer', minimum: 1 },
confirmed: { type: 'boolean', const: true },
},
},
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_remove_collection',
'Data Service remove collection',
'Remove a collection from the active Makelore project after explicit confirmation.',
{
type: 'object', additionalProperties: false, required: ['collection', 'confirmed'],
properties: {
collection: { type: 'string', minLength: 1, maxLength: 48, pattern: '^[a-z][a-z0-9_-]{0,47}$' },
confirmed: { type: 'boolean', const: true },
},
},
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_reset',
'Data Service reset',
'Reset all collections in the active Makelore project after explicit confirmation.',
{
type: 'object', additionalProperties: false, required: ['confirmed'],
properties: { confirmed: { type: 'boolean', const: true } },
},
);
if (WORKER_ROLE === 'parent') registerProductTool(
pi,
'data_service_remove_project',
'Data Service remove project',
'Remove the active Makelore project Data Service instance after explicit confirmation.',
{
type: 'object', additionalProperties: false, required: ['confirmed'],
properties: { confirmed: { type: 'boolean', const: true } },
},
);
pi.on('tool_call', async (event, ctx) => {
if (!MUTATION_TOOLS.has(event.toolName)) return;