@lit-protocol/vincent-scaffold-sdk
Version:
Shared build configuration and utilities for Vincent tools and policies
91 lines (75 loc) • 2.21 kB
JavaScript
const fs = require('fs');
const path = require('path');
/**
* Generate lit-action.ts content for tools
* @returns {string} The generated TypeScript content
*/
function generateToolLitAction() {
return `/**
* DO NOT EDIT THIS FILE. IT IS GENERATED ON BUILD.
*/
import { vincentToolHandler } from '@lit-protocol/vincent-tool-sdk';
import { z } from 'zod';
import { vincentTool } from '../lib/vincent-tool';
import { toolParamsSchema } from '../lib/schemas';
declare const toolParams: z.infer<typeof toolParamsSchema>;
declare const context: {
delegatorPkpEthAddress: string;
};
(async () => {
const func = vincentToolHandler({
vincentTool: vincentTool,
context: {
delegatorPkpEthAddress: context.delegatorPkpEthAddress,
},
toolParams,
});
await func();
})();`;
}
/**
* Generate lit-action.ts content for policies
* @returns {string} The generated TypeScript content
*/
function generatePolicyLitAction() {
return `/**
* DO NOT EDIT THIS FILE. IT IS GENERATED ON BUILD.
*/
import { vincentPolicyHandler } from '@lit-protocol/vincent-tool-sdk';
import { vincentPolicy } from '../lib/vincent-policy';
import { toolParamsSchema } from '../lib/schemas';
declare const context: {
toolIpfsCid: string;
delegatorPkpEthAddress: string;
};
declare const toolParams: typeof toolParamsSchema;
(async () => {
return await vincentPolicyHandler({
vincentPolicy: vincentPolicy,
context,
toolParams,
});
})();`;
}
/**
* Generate lit-action.ts file based on type
* @param {string} type - Either 'tool' or 'policy'
* @param {string} outputDir - Directory to write the file to
*/
function generateLitAction(type, outputDir = './src/generated') {
const content = type === 'tool'
? generateToolLitAction()
: generatePolicyLitAction();
const outputPath = path.join(outputDir, 'lit-action.ts');
// Ensure directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
fs.writeFileSync(outputPath, content, 'utf8');
console.log(`✅ Generated lit-action.ts for ${type} at ${outputPath}`);
}
module.exports = {
generateLitAction,
generateToolLitAction,
generatePolicyLitAction,
};