feat: add space functions to center, remove space remote template
This commit is contained in:
1 parent
e9956bd34f
commit
953976cfc1
9 files changed
+79
-21
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
export const spec = {
|
||||
name: 'read-file',
|
||||
description: 'Read the text content of a file in the space.',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
path: { type: 'string', description: 'File path relative to the space directory.' },
|
||||
},
|
||||
required: ['path'],
|
||||
},
|
||||
};
|
||||
|
||||
function resolveIn(base, relPath) {
|
||||
const resolved = path.resolve(base, relPath);
|
||||
if (resolved !== base && !resolved.startsWith(base + path.sep)) {
|
||||
throw new Error('Path escapes the space directory');
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
export default async function (args, ctx) {
|
||||
return { content: fs.readFileSync(resolveIn(ctx.dir, args.path), 'utf8') };
|
||||
}
|
||||
Reference in new issue
Block a user