@agirails/sdk 2.3.0 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -8
- package/dist/ACTPClient.d.ts +35 -1
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +156 -26
- package/dist/ACTPClient.js.map +1 -1
- package/dist/adapters/AdapterRouter.d.ts.map +1 -1
- package/dist/adapters/AdapterRouter.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts +10 -1
- package/dist/adapters/BasicAdapter.d.ts.map +1 -1
- package/dist/adapters/BasicAdapter.js +36 -1
- package/dist/adapters/BasicAdapter.js.map +1 -1
- package/dist/cli/commands/init.d.ts +2 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +345 -25
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/publish.d.ts.map +1 -1
- package/dist/cli/commands/publish.js.map +1 -1
- package/dist/cli/commands/register.d.ts +16 -0
- package/dist/cli/commands/register.d.ts.map +1 -0
- package/dist/cli/commands/register.js +211 -0
- package/dist/cli/commands/register.js.map +1 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/utils/config.d.ts +20 -0
- package/dist/cli/utils/config.d.ts.map +1 -1
- package/dist/cli/utils/config.js.map +1 -1
- package/dist/config/networks.d.ts +20 -4
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +59 -27
- package/dist/config/networks.js.map +1 -1
- package/dist/config/publishPipeline.d.ts +14 -0
- package/dist/config/publishPipeline.d.ts.map +1 -1
- package/dist/config/publishPipeline.js +2 -1
- package/dist/config/publishPipeline.js.map +1 -1
- package/dist/erc8004/ERC8004Bridge.d.ts.map +1 -1
- package/dist/erc8004/ERC8004Bridge.js +6 -5
- package/dist/erc8004/ERC8004Bridge.js.map +1 -1
- package/dist/erc8004/ReputationReporter.d.ts.map +1 -1
- package/dist/erc8004/ReputationReporter.js +9 -12
- package/dist/erc8004/ReputationReporter.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/level1/Agent.js +4 -4
- package/dist/level1/Agent.js.map +1 -1
- package/dist/protocol/ACTPKernel.d.ts +7 -1
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +13 -10
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/protocol/EventMonitor.d.ts +14 -0
- package/dist/protocol/EventMonitor.d.ts.map +1 -1
- package/dist/protocol/EventMonitor.js +14 -0
- package/dist/protocol/EventMonitor.js.map +1 -1
- package/dist/runtime/BlockchainRuntime.d.ts +5 -0
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +1 -1
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/storage/ArchiveBundleBuilder.d.ts.map +1 -1
- package/dist/storage/ArchiveBundleBuilder.js.map +1 -1
- package/dist/storage/ArweaveClient.d.ts.map +1 -1
- package/dist/storage/ArweaveClient.js +2 -0
- package/dist/storage/ArweaveClient.js.map +1 -1
- package/dist/storage/FilebaseClient.d.ts.map +1 -1
- package/dist/storage/FilebaseClient.js +2 -0
- package/dist/storage/FilebaseClient.js.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.d.ts.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.js +3 -2
- package/dist/utils/ErrorRecoveryGuide.js.map +1 -1
- package/dist/utils/IPFSClient.d.ts +3 -2
- package/dist/utils/IPFSClient.d.ts.map +1 -1
- package/dist/utils/IPFSClient.js +7 -5
- package/dist/utils/IPFSClient.js.map +1 -1
- package/dist/utils/computeTypeHash.js +1 -3
- package/dist/utils/computeTypeHash.js.map +1 -1
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +0 -1
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/validation.d.ts +2 -2
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +2 -2
- package/dist/utils/validation.js.map +1 -1
- package/dist/wallet/AutoWalletProvider.d.ts +77 -0
- package/dist/wallet/AutoWalletProvider.d.ts.map +1 -0
- package/dist/wallet/AutoWalletProvider.js +197 -0
- package/dist/wallet/AutoWalletProvider.js.map +1 -0
- package/dist/wallet/EOAWalletProvider.d.ts +21 -0
- package/dist/wallet/EOAWalletProvider.d.ts.map +1 -0
- package/dist/wallet/EOAWalletProvider.js +57 -0
- package/dist/wallet/EOAWalletProvider.js.map +1 -0
- package/dist/wallet/IWalletProvider.d.ts +115 -0
- package/dist/wallet/IWalletProvider.d.ts.map +1 -0
- package/dist/wallet/IWalletProvider.js +12 -0
- package/dist/wallet/IWalletProvider.js.map +1 -0
- package/dist/wallet/aa/BundlerClient.d.ts +70 -0
- package/dist/wallet/aa/BundlerClient.d.ts.map +1 -0
- package/dist/wallet/aa/BundlerClient.js +184 -0
- package/dist/wallet/aa/BundlerClient.js.map +1 -0
- package/dist/wallet/aa/DualNonceManager.d.ts +56 -0
- package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -0
- package/dist/wallet/aa/DualNonceManager.js +142 -0
- package/dist/wallet/aa/DualNonceManager.js.map +1 -0
- package/dist/wallet/aa/PaymasterClient.d.ts +52 -0
- package/dist/wallet/aa/PaymasterClient.d.ts.map +1 -0
- package/dist/wallet/aa/PaymasterClient.js +116 -0
- package/dist/wallet/aa/PaymasterClient.js.map +1 -0
- package/dist/wallet/aa/TransactionBatcher.d.ts +87 -0
- package/dist/wallet/aa/TransactionBatcher.d.ts.map +1 -0
- package/dist/wallet/aa/TransactionBatcher.js +148 -0
- package/dist/wallet/aa/TransactionBatcher.js.map +1 -0
- package/dist/wallet/aa/UserOpBuilder.d.ts +71 -0
- package/dist/wallet/aa/UserOpBuilder.d.ts.map +1 -0
- package/dist/wallet/aa/UserOpBuilder.js +196 -0
- package/dist/wallet/aa/UserOpBuilder.js.map +1 -0
- package/dist/wallet/aa/constants.d.ts +54 -0
- package/dist/wallet/aa/constants.d.ts.map +1 -0
- package/dist/wallet/aa/constants.js +18 -0
- package/dist/wallet/aa/constants.js.map +1 -0
- package/package.json +4 -2
- package/src/ACTPClient.ts +217 -31
- package/src/adapters/AdapterRouter.ts +0 -1
- package/src/adapters/BasicAdapter.ts +41 -1
- package/src/cli/commands/init.ts +394 -25
- package/src/cli/commands/publish.ts +1 -2
- package/src/cli/commands/register.ts +233 -0
- package/src/cli/index.ts +4 -0
- package/src/cli/utils/config.ts +30 -0
- package/src/config/networks.ts +82 -27
- package/src/config/publishPipeline.ts +2 -2
- package/src/erc8004/ERC8004Bridge.ts +6 -5
- package/src/erc8004/ReputationReporter.ts +14 -18
- package/src/index.ts +12 -0
- package/src/level1/Agent.ts +5 -5
- package/src/protocol/ACTPKernel.ts +20 -10
- package/src/protocol/EventMonitor.ts +14 -0
- package/src/runtime/BlockchainRuntime.ts +7 -1
- package/src/storage/ArchiveBundleBuilder.ts +0 -2
- package/src/storage/ArweaveClient.ts +2 -1
- package/src/storage/FilebaseClient.ts +3 -3
- package/src/utils/ErrorRecoveryGuide.ts +4 -2
- package/src/utils/IPFSClient.ts +9 -7
- package/src/utils/computeTypeHash.ts +1 -3
- package/src/utils/retry.ts +0 -1
- package/src/utils/validation.ts +2 -2
- package/src/wallet/AutoWalletProvider.ts +294 -0
- package/src/wallet/EOAWalletProvider.ts +69 -0
- package/src/wallet/IWalletProvider.ts +133 -0
- package/src/wallet/aa/BundlerClient.ts +274 -0
- package/src/wallet/aa/DualNonceManager.ts +173 -0
- package/src/wallet/aa/PaymasterClient.ts +174 -0
- package/src/wallet/aa/TransactionBatcher.ts +240 -0
- package/src/wallet/aa/UserOpBuilder.ts +246 -0
- package/src/wallet/aa/constants.ts +60 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/BasicAdapter.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,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAkCzD;;;;OAIG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C;;;;;;;;;;OAUG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB1D;;;;;OAKG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGxE"}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.BasicAdapter = void 0;
|
|
18
18
|
const BaseAdapter_1 = require("./BaseAdapter");
|
|
19
|
+
const ethers_1 = require("ethers");
|
|
19
20
|
/**
|
|
20
21
|
* BasicAdapter - High-level API for simple payment flows.
|
|
21
22
|
*
|
|
@@ -53,11 +54,15 @@ class BasicAdapter extends BaseAdapter_1.BaseAdapter {
|
|
|
53
54
|
* @param runtime - ACTP runtime implementation (MockRuntime or BlockchainRuntime)
|
|
54
55
|
* @param requesterAddress - The requester's Ethereum address
|
|
55
56
|
* @param easHelper - Optional EAS helper for attestation verification (SECURITY FIX C-4)
|
|
57
|
+
* @param walletProvider - Optional wallet provider for AA batched payments
|
|
58
|
+
* @param contractAddresses - Optional contract addresses for batched payment encoding
|
|
56
59
|
*/
|
|
57
|
-
constructor(runtime, requesterAddress, easHelper) {
|
|
60
|
+
constructor(runtime, requesterAddress, easHelper, walletProvider, contractAddresses) {
|
|
58
61
|
super(requesterAddress);
|
|
59
62
|
this.runtime = runtime;
|
|
60
63
|
this.easHelper = easHelper;
|
|
64
|
+
this.walletProvider = walletProvider;
|
|
65
|
+
this.contractAddresses = contractAddresses;
|
|
61
66
|
/**
|
|
62
67
|
* Adapter metadata for router selection.
|
|
63
68
|
*/
|
|
@@ -126,6 +131,36 @@ class BasicAdapter extends BaseAdapter_1.BaseAdapter {
|
|
|
126
131
|
`This limit exists because contracts have not been formally audited. ` +
|
|
127
132
|
`For larger amounts, please contact support@agirails.io.`);
|
|
128
133
|
}
|
|
134
|
+
// ====================================================================
|
|
135
|
+
// AIP-12: Batched payment via AA wallet (1 UserOp = 3 on-chain calls)
|
|
136
|
+
// ====================================================================
|
|
137
|
+
if (this.walletProvider?.payACTPBatched && this.contractAddresses) {
|
|
138
|
+
const serviceHash = ethers_1.ethers.ZeroHash;
|
|
139
|
+
const result = await this.walletProvider.payACTPBatched({
|
|
140
|
+
provider,
|
|
141
|
+
requester,
|
|
142
|
+
amount: amount.toString(),
|
|
143
|
+
deadline,
|
|
144
|
+
disputeWindow,
|
|
145
|
+
serviceHash,
|
|
146
|
+
agentId: agentId || '0',
|
|
147
|
+
contracts: this.contractAddresses,
|
|
148
|
+
});
|
|
149
|
+
if (!result.success) {
|
|
150
|
+
throw new Error(`Batched payment UserOp failed: ${result.hash}`);
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
txId: result.txId,
|
|
154
|
+
provider,
|
|
155
|
+
requester,
|
|
156
|
+
amount: this.formatAmount(amount),
|
|
157
|
+
deadline: new Date(deadline * 1000).toISOString(),
|
|
158
|
+
state: 'COMMITTED',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
// ====================================================================
|
|
162
|
+
// Legacy flow: sequential on-chain calls (EOA / mock)
|
|
163
|
+
// ====================================================================
|
|
129
164
|
// Create transaction
|
|
130
165
|
const txId = await this.runtime.createTransaction({
|
|
131
166
|
provider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicAdapter.js","sourceRoot":"","sources":["../../src/adapters/BasicAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,+CAA6D;
|
|
1
|
+
{"version":3,"file":"BasicAdapter.js","sourceRoot":"","sources":["../../src/adapters/BasicAd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,CAAC,OAAO,CAAC,IAAY,EAAE,KAAc;QACxC,IAAI,aAAa,GAAG,KAAK,CAAC;QAE1B,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,oDAAoD;YACpD,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACnD,IAAI,CAAC,EAAE,EAAE,CAAC;gBACR,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,YAAY,CAAC,CAAC;YACnD,CAAC;YACD,iDAAiD;YACjD,aAAa,GAAG,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;QAClE,CAAC;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;IACvE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,QAAgB,EAAE,cAAuB;QACrD,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC7D,CAAC;CACF;AAxXD,oCAwXC"}
|
|
@@ -12,12 +12,13 @@ export declare function createInitCommand(): Command;
|
|
|
12
12
|
interface InitOptions {
|
|
13
13
|
mode: string;
|
|
14
14
|
address?: string;
|
|
15
|
+
wallet?: string;
|
|
15
16
|
force?: boolean;
|
|
16
17
|
scaffold?: boolean;
|
|
17
18
|
intent?: string;
|
|
18
19
|
service?: string;
|
|
19
20
|
price?: string;
|
|
20
21
|
}
|
|
21
|
-
declare function runInit(options: InitOptions, output: Output): Promise<void>;
|
|
22
|
+
declare function runInit(options: InitOptions, output: Output, cmd?: Command): Promise<void>;
|
|
22
23
|
export { runInit };
|
|
23
24
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,OAAO,EAAE,MAAM,EAAY,MAAM,iBAAiB,CAAC;AAOnD,wBAAgB,iBAAiB,IAAI,OAAO,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,OAAO,EAAE,MAAM,EAAY,MAAM,iBAAiB,CAAC;AAOnD,wBAAgB,iBAAiB,IAAI,OAAO,CA8B3C;AAQD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,iBAAe,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAoNzF;AAyfD,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -48,6 +48,7 @@ function createInitCommand() {
|
|
|
48
48
|
.description('Initialize ACTP in the current directory')
|
|
49
49
|
.option('-m, --mode <mode>', 'Operating mode: mock, testnet, mainnet', 'mock')
|
|
50
50
|
.option('-a, --address <address>', 'Your Ethereum address')
|
|
51
|
+
.option('-w, --wallet <type>', 'Wallet type: auto (gas-free Smart Wallet) or eoa (traditional)', 'auto')
|
|
51
52
|
.option('-f, --force', 'Overwrite existing configuration')
|
|
52
53
|
.option('--scaffold', 'Generate a starter agent.ts file')
|
|
53
54
|
.option('--intent <intent>', 'Agent intent: earn, pay, or both (default: earn)')
|
|
@@ -55,10 +56,10 @@ function createInitCommand() {
|
|
|
55
56
|
.option('--price <usdc>', 'Base price in USDC (default: 1)')
|
|
56
57
|
.option('--json', 'Output as JSON')
|
|
57
58
|
.option('-q, --quiet', 'Minimal output')
|
|
58
|
-
.action(async (options) => {
|
|
59
|
+
.action(async (options, command) => {
|
|
59
60
|
const output = new output_1.Output(options.json ? 'json' : options.quiet ? 'quiet' : 'human');
|
|
60
61
|
try {
|
|
61
|
-
await runInit(options, output);
|
|
62
|
+
await runInit(options, output, command);
|
|
62
63
|
}
|
|
63
64
|
catch (error) {
|
|
64
65
|
output.errorResult({
|
|
@@ -71,21 +72,86 @@ function createInitCommand() {
|
|
|
71
72
|
return cmd;
|
|
72
73
|
}
|
|
73
74
|
exports.createInitCommand = createInitCommand;
|
|
74
|
-
async function runInit(options, output) {
|
|
75
|
+
async function runInit(options, output, cmd) {
|
|
75
76
|
const projectRoot = process.cwd();
|
|
76
77
|
// Check if already initialized
|
|
77
78
|
if ((0, config_1.isInitialized)(projectRoot) && !options.force) {
|
|
78
79
|
throw new Error('ACTP already initialized in this directory.\n' +
|
|
79
80
|
'Use --force to reinitialize.');
|
|
80
81
|
}
|
|
82
|
+
// ── AGIRAILS.md pre-fill ──────────────────────────────────────────────
|
|
83
|
+
const agirailsMdPath = path.join(projectRoot, 'AGIRAILS.md');
|
|
84
|
+
let mdConfig = null;
|
|
85
|
+
if (fs.existsSync(agirailsMdPath)) {
|
|
86
|
+
try {
|
|
87
|
+
const { parseAgirailsMd } = await Promise.resolve().then(() => __importStar(require('../../config/agirailsmd')));
|
|
88
|
+
const parsed = parseAgirailsMd(fs.readFileSync(agirailsMdPath, 'utf-8'));
|
|
89
|
+
mdConfig = parsed.frontmatter;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
output.warning('Found AGIRAILS.md but could not parse it — ignoring');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Helper: true when the user explicitly passed a flag on the CLI
|
|
96
|
+
const isExplicit = (flag) => cmd?.getOptionValueSource(flag) === 'cli';
|
|
97
|
+
// Apply AGIRAILS.md values where the user didn't set an explicit flag
|
|
98
|
+
if (mdConfig) {
|
|
99
|
+
// network → mode mapping
|
|
100
|
+
if (!isExplicit('mode') && mdConfig.network) {
|
|
101
|
+
const net = String(mdConfig.network);
|
|
102
|
+
if (net === 'base-sepolia' || net === 'testnet')
|
|
103
|
+
options.mode = 'testnet';
|
|
104
|
+
else if (net === 'base-mainnet' || net === 'mainnet')
|
|
105
|
+
options.mode = 'mainnet';
|
|
106
|
+
else if (net === 'mock')
|
|
107
|
+
options.mode = 'mock';
|
|
108
|
+
}
|
|
109
|
+
// intent
|
|
110
|
+
if (!isExplicit('intent') && mdConfig.intent) {
|
|
111
|
+
options.intent = String(mdConfig.intent);
|
|
112
|
+
}
|
|
113
|
+
// capabilities → service (first capability)
|
|
114
|
+
if (!isExplicit('service') && Array.isArray(mdConfig.capabilities) && mdConfig.capabilities.length > 0) {
|
|
115
|
+
options.service = String(mdConfig.capabilities[0]);
|
|
116
|
+
}
|
|
117
|
+
// price
|
|
118
|
+
if (!isExplicit('price') && mdConfig.price != null) {
|
|
119
|
+
options.price = String(mdConfig.price);
|
|
120
|
+
}
|
|
121
|
+
// Log what we pre-filled
|
|
122
|
+
const lines = [];
|
|
123
|
+
if (mdConfig.network)
|
|
124
|
+
lines.push(` Mode: ${options.mode}`);
|
|
125
|
+
if (mdConfig.name)
|
|
126
|
+
lines.push(` Agent: ${String(mdConfig.name)}`);
|
|
127
|
+
if (mdConfig.intent)
|
|
128
|
+
lines.push(` Intent: ${options.intent || mdConfig.intent}`);
|
|
129
|
+
if (Array.isArray(mdConfig.capabilities))
|
|
130
|
+
lines.push(` Capabilities: ${mdConfig.capabilities.join(', ')}`);
|
|
131
|
+
if (mdConfig.price != null)
|
|
132
|
+
lines.push(` Price: $${mdConfig.price} USDC`);
|
|
133
|
+
output.info('Found AGIRAILS.md \u2014 using config from file');
|
|
134
|
+
for (const line of lines) {
|
|
135
|
+
output.print(line);
|
|
136
|
+
}
|
|
137
|
+
output.blank();
|
|
138
|
+
}
|
|
139
|
+
// ── End AGIRAILS.md pre-fill ──────────────────────────────────────────
|
|
81
140
|
// Validate mode
|
|
82
141
|
const validModes = ['mock', 'testnet', 'mainnet'];
|
|
83
142
|
if (!validModes.includes(options.mode)) {
|
|
84
143
|
throw new Error(`Invalid mode: "${options.mode}". Valid modes: ${validModes.join(', ')}`);
|
|
85
144
|
}
|
|
86
145
|
const mode = options.mode;
|
|
146
|
+
// Determine wallet type
|
|
147
|
+
const walletType = (mode === 'mock') ? 'mock' : (options.wallet || 'auto');
|
|
148
|
+
if (walletType !== 'mock' && walletType !== 'auto' && walletType !== 'eoa') {
|
|
149
|
+
throw new Error(`Invalid wallet type: "${walletType}". Valid types: auto, eoa`);
|
|
150
|
+
}
|
|
87
151
|
// Get or generate address
|
|
88
152
|
let address = options.address;
|
|
153
|
+
let smartWalletAddress;
|
|
154
|
+
let didRegister = false;
|
|
89
155
|
if (!address) {
|
|
90
156
|
if (mode === 'mock') {
|
|
91
157
|
// Generate a random address for mock mode
|
|
@@ -96,7 +162,22 @@ async function runInit(options, output) {
|
|
|
96
162
|
// Generate a real wallet with encrypted keystore
|
|
97
163
|
const actpDir = (0, config_1.getActpDir)(projectRoot);
|
|
98
164
|
fs.mkdirSync(actpDir, { recursive: true });
|
|
99
|
-
|
|
165
|
+
const eoaAddress = await generateWallet(actpDir, output);
|
|
166
|
+
if (walletType === 'auto') {
|
|
167
|
+
// Compute Smart Wallet address from signer
|
|
168
|
+
smartWalletAddress = await computeSmartWalletInit(eoaAddress, mode, output);
|
|
169
|
+
// Y/N: Register for gas-free transactions?
|
|
170
|
+
const shouldRegister = await promptRegister(output);
|
|
171
|
+
if (shouldRegister) {
|
|
172
|
+
didRegister = await runInlineRegistration(projectRoot, mode, output);
|
|
173
|
+
}
|
|
174
|
+
// address = Smart Wallet if registered, EOA if not
|
|
175
|
+
// This ensures CLI commands (balance, tx list) show the correct address
|
|
176
|
+
address = didRegister ? smartWalletAddress : eoaAddress;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
address = eoaAddress;
|
|
180
|
+
}
|
|
100
181
|
}
|
|
101
182
|
}
|
|
102
183
|
// Validate address format
|
|
@@ -109,6 +190,17 @@ async function runInit(options, output) {
|
|
|
109
190
|
mode,
|
|
110
191
|
address: address.toLowerCase(),
|
|
111
192
|
version: '1.0',
|
|
193
|
+
...(walletType !== 'mock' && { wallet: walletType }),
|
|
194
|
+
...(smartWalletAddress && { smartWallet: smartWalletAddress.toLowerCase() }),
|
|
195
|
+
...(didRegister && { registered: true }),
|
|
196
|
+
// AGIRAILS.md-derived values (stored for downstream use)
|
|
197
|
+
...(mdConfig && mdConfig.name ? { agentName: String(mdConfig.name) } : {}),
|
|
198
|
+
...(mdConfig && mdConfig.intent ? { intent: String(mdConfig.intent) } : {}),
|
|
199
|
+
...(mdConfig && Array.isArray(mdConfig.capabilities) ? { capabilities: mdConfig.capabilities.map(String) } : {}),
|
|
200
|
+
...(mdConfig && mdConfig.price != null ? { price: Number(mdConfig.price) } : {}),
|
|
201
|
+
...(mdConfig && mdConfig.concurrency != null ? { concurrency: Number(mdConfig.concurrency) } : {}),
|
|
202
|
+
...(mdConfig && mdConfig.payment_mode ? { paymentMode: String(mdConfig.payment_mode) } : {}),
|
|
203
|
+
...(mdConfig && mdConfig.budget != null ? { budget: Number(mdConfig.budget) } : {}),
|
|
112
204
|
};
|
|
113
205
|
// Save configuration
|
|
114
206
|
(0, config_1.saveConfig)(config, projectRoot);
|
|
@@ -141,17 +233,32 @@ async function runInit(options, output) {
|
|
|
141
233
|
directory: (0, config_1.getActpDir)(projectRoot),
|
|
142
234
|
mode,
|
|
143
235
|
address,
|
|
236
|
+
...(walletType !== 'mock' && { wallet: walletType }),
|
|
144
237
|
}, { quietKey: 'address' });
|
|
145
238
|
// Generate scaffold if requested
|
|
146
239
|
if (options.scaffold) {
|
|
147
|
-
await runScaffold(options, mode, output);
|
|
240
|
+
await runScaffold(options, mode, output, mdConfig);
|
|
148
241
|
}
|
|
149
242
|
else {
|
|
150
243
|
output.blank();
|
|
151
244
|
output.print('Next steps:');
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
245
|
+
if (walletType === 'auto' && didRegister) {
|
|
246
|
+
// Already registered — ready to go
|
|
247
|
+
output.print(' 1. Create a payment: actp pay <provider> <amount>');
|
|
248
|
+
output.print(' 2. Check your balance: actp balance');
|
|
249
|
+
output.print(' 3. List transactions: actp tx list');
|
|
250
|
+
}
|
|
251
|
+
else if (walletType === 'auto') {
|
|
252
|
+
// Skipped registration — remind them
|
|
253
|
+
output.print(' 1. Register for gas-free: actp register');
|
|
254
|
+
output.print(' 2. Create a payment: actp pay <provider> <amount>');
|
|
255
|
+
output.print(' 3. Check your balance: actp balance');
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
output.print(' 1. Create a payment: actp pay <provider> <amount>');
|
|
259
|
+
output.print(' 2. Check your balance: actp balance');
|
|
260
|
+
output.print(' 3. List transactions: actp tx list');
|
|
261
|
+
}
|
|
155
262
|
output.print('');
|
|
156
263
|
output.print('Tip: Use --scaffold to generate a starter agent.ts');
|
|
157
264
|
}
|
|
@@ -187,6 +294,230 @@ async function generateWallet(actpDir, output) {
|
|
|
187
294
|
output.info(' npx ts-node agent.ts');
|
|
188
295
|
return wallet.address;
|
|
189
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Compute the Smart Wallet address for an EOA signer.
|
|
299
|
+
* Uses CREATE2 counterfactual derivation — no deployment needed.
|
|
300
|
+
*/
|
|
301
|
+
async function computeSmartWalletInit(eoaAddress, mode, output) {
|
|
302
|
+
const { ethers } = await Promise.resolve().then(() => __importStar(require('ethers')));
|
|
303
|
+
const { getNetwork } = await Promise.resolve().then(() => __importStar(require('../../config/networks')));
|
|
304
|
+
const { computeSmartWalletAddress } = await Promise.resolve().then(() => __importStar(require('../../wallet/aa/UserOpBuilder')));
|
|
305
|
+
const network = mode === 'testnet' ? 'base-sepolia' : 'base-mainnet';
|
|
306
|
+
const networkConfig = getNetwork(network);
|
|
307
|
+
const rpcUrl = networkConfig.rpcUrl;
|
|
308
|
+
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
|
309
|
+
output.info('Computing Smart Wallet address...');
|
|
310
|
+
const smartWalletAddress = await computeSmartWalletAddress(eoaAddress, provider);
|
|
311
|
+
output.success(`Smart Wallet: ${smartWalletAddress}`);
|
|
312
|
+
output.info('Gas-free transactions enabled (requires registration)');
|
|
313
|
+
output.info('Register with: actp register');
|
|
314
|
+
return smartWalletAddress;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Ask user if they want to register for gas-free transactions.
|
|
318
|
+
* Non-TTY (piped/agent) defaults to yes.
|
|
319
|
+
*/
|
|
320
|
+
async function promptRegister(output) {
|
|
321
|
+
output.blank();
|
|
322
|
+
output.print('Register for gas-free transactions? (recommended)');
|
|
323
|
+
output.print(' Your agent gets a Smart Wallet with sponsored gas — no ETH needed.');
|
|
324
|
+
output.print(' Requires on-chain registration on AgentRegistry.');
|
|
325
|
+
output.blank();
|
|
326
|
+
if (!process.stdin.isTTY) {
|
|
327
|
+
output.info('Non-interactive mode: auto-registering');
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
const rl = readline.createInterface({
|
|
331
|
+
input: process.stdin,
|
|
332
|
+
output: process.stdout,
|
|
333
|
+
});
|
|
334
|
+
return new Promise((resolve) => {
|
|
335
|
+
rl.question(' Register now? [Y/n] ', (answer) => {
|
|
336
|
+
rl.close();
|
|
337
|
+
const trimmed = answer.trim().toLowerCase();
|
|
338
|
+
resolve(trimmed === '' || trimmed === 'y' || trimmed === 'yes');
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Run inline registration during init.
|
|
344
|
+
* Reuses the same logic as `actp register` — parses AGIRAILS.md,
|
|
345
|
+
* builds gasless UserOp (testnet: register + mint 1000 USDC).
|
|
346
|
+
*
|
|
347
|
+
* Returns true if registration succeeded, false on failure (non-fatal).
|
|
348
|
+
*/
|
|
349
|
+
async function runInlineRegistration(projectRoot, mode, output) {
|
|
350
|
+
try {
|
|
351
|
+
const { resolvePrivateKey } = await Promise.resolve().then(() => __importStar(require('../../wallet/keystore')));
|
|
352
|
+
const privateKey = await resolvePrivateKey(projectRoot);
|
|
353
|
+
if (!privateKey) {
|
|
354
|
+
output.warning('Could not load wallet key. Run "actp register" later.');
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
const { parseAgirailsMd } = await Promise.resolve().then(() => __importStar(require('../../config/agirailsmd')));
|
|
358
|
+
const { extractRegistrationParams } = await Promise.resolve().then(() => __importStar(require('../../config/publishPipeline')));
|
|
359
|
+
const { ethers } = await Promise.resolve().then(() => __importStar(require('ethers')));
|
|
360
|
+
const { getNetwork } = await Promise.resolve().then(() => __importStar(require('../../config/networks')));
|
|
361
|
+
const { AutoWalletProvider } = await Promise.resolve().then(() => __importStar(require('../../wallet/AutoWalletProvider')));
|
|
362
|
+
const { buildRegisterAgentBatch, buildTestnetInitBatch, buildTestnetMintBatch } = await Promise.resolve().then(() => __importStar(require('../../wallet/aa/TransactionBatcher')));
|
|
363
|
+
const { sdkLogger } = await Promise.resolve().then(() => __importStar(require('../../utils/Logger')));
|
|
364
|
+
// Parse AGIRAILS.md if present
|
|
365
|
+
const agirailsMdPath = path.join(projectRoot, 'AGIRAILS.md');
|
|
366
|
+
let endpoint = '';
|
|
367
|
+
let serviceDescriptors;
|
|
368
|
+
if (fs.existsSync(agirailsMdPath)) {
|
|
369
|
+
const content = fs.readFileSync(agirailsMdPath, 'utf-8');
|
|
370
|
+
const parsed = parseAgirailsMd(content);
|
|
371
|
+
const regParams = extractRegistrationParams(parsed.frontmatter);
|
|
372
|
+
endpoint = regParams.endpoint;
|
|
373
|
+
serviceDescriptors = regParams.serviceDescriptors;
|
|
374
|
+
output.info(`Parsed ${serviceDescriptors.length} service(s) from AGIRAILS.md`);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
const serviceType = 'general';
|
|
378
|
+
endpoint = 'https://agirails.io/agent/pending';
|
|
379
|
+
serviceDescriptors = [{
|
|
380
|
+
serviceTypeHash: ethers.keccak256(ethers.toUtf8Bytes(serviceType)),
|
|
381
|
+
serviceType,
|
|
382
|
+
schemaURI: '',
|
|
383
|
+
minPrice: 0n,
|
|
384
|
+
maxPrice: 1000000000n,
|
|
385
|
+
avgCompletionTime: 3600,
|
|
386
|
+
metadataCID: '',
|
|
387
|
+
}];
|
|
388
|
+
output.info('No AGIRAILS.md found. Using default "general" service.');
|
|
389
|
+
}
|
|
390
|
+
const network = mode === 'testnet' ? 'base-sepolia' : 'base-mainnet';
|
|
391
|
+
const networkConfig = getNetwork(network);
|
|
392
|
+
if (!networkConfig.aa || !networkConfig.contracts.agentRegistry) {
|
|
393
|
+
output.warning('AA or AgentRegistry not configured. Run "actp register" later.');
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
// Check for valid bundler/paymaster URL (CDP_API_KEY must be set)
|
|
397
|
+
const cdpUrl = networkConfig.aa.bundlerUrls.coinbase;
|
|
398
|
+
const hasPimlico = !!networkConfig.aa.bundlerUrls.pimlico;
|
|
399
|
+
if (cdpUrl.endsWith('/') && !hasPimlico) {
|
|
400
|
+
output.warning('CDP_API_KEY not set. Skipping registration.');
|
|
401
|
+
output.info('Set CDP_API_KEY and run "actp register" later.');
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
const provider = new ethers.JsonRpcProvider(networkConfig.rpcUrl);
|
|
405
|
+
const signer = new ethers.Wallet(privateKey, provider);
|
|
406
|
+
const autoWallet = await AutoWalletProvider.create({
|
|
407
|
+
signer,
|
|
408
|
+
provider,
|
|
409
|
+
chainId: networkConfig.chainId,
|
|
410
|
+
actpKernelAddress: networkConfig.contracts.actpKernel,
|
|
411
|
+
bundler: {
|
|
412
|
+
primaryUrl: networkConfig.aa.bundlerUrls.coinbase,
|
|
413
|
+
backupUrl: networkConfig.aa.bundlerUrls.pimlico,
|
|
414
|
+
},
|
|
415
|
+
paymaster: {
|
|
416
|
+
primaryUrl: networkConfig.aa.paymasterUrls.coinbase,
|
|
417
|
+
backupUrl: networkConfig.aa.paymasterUrls.pimlico,
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
const smartWalletAddress = autoWallet.getAddress();
|
|
421
|
+
// Build and submit registration batch
|
|
422
|
+
if (mode === 'testnet') {
|
|
423
|
+
// Testnet: try combined batch first, fall back to separate UserOps
|
|
424
|
+
// Some paymaster configurations reject multi-target batches in simulation
|
|
425
|
+
output.info('Testnet: registering + minting 1000 test USDC...');
|
|
426
|
+
const combinedCalls = buildTestnetInitBatch({
|
|
427
|
+
agentRegistryAddress: networkConfig.contracts.agentRegistry,
|
|
428
|
+
endpoint,
|
|
429
|
+
serviceDescriptors,
|
|
430
|
+
mockUsdcAddress: networkConfig.contracts.usdc,
|
|
431
|
+
recipient: smartWalletAddress,
|
|
432
|
+
mintAmount: '1000000000',
|
|
433
|
+
});
|
|
434
|
+
let receipt;
|
|
435
|
+
try {
|
|
436
|
+
const txRequests = combinedCalls.map((c) => ({
|
|
437
|
+
to: c.target,
|
|
438
|
+
data: c.data,
|
|
439
|
+
value: c.value.toString(),
|
|
440
|
+
}));
|
|
441
|
+
receipt = await autoWallet.sendBatchTransaction(txRequests);
|
|
442
|
+
}
|
|
443
|
+
catch (combinedError) {
|
|
444
|
+
// Combined batch failed — split into two separate UserOps
|
|
445
|
+
output.info('Combined batch failed, trying separate transactions...');
|
|
446
|
+
sdkLogger.warn('Combined testnet batch failed, splitting', {
|
|
447
|
+
error: combinedError instanceof Error ? combinedError.message : String(combinedError),
|
|
448
|
+
});
|
|
449
|
+
// Step 1: Register agent only
|
|
450
|
+
const registerCalls = buildRegisterAgentBatch(networkConfig.contracts.agentRegistry, endpoint, serviceDescriptors);
|
|
451
|
+
const registerTxs = registerCalls.map((c) => ({
|
|
452
|
+
to: c.target,
|
|
453
|
+
data: c.data,
|
|
454
|
+
value: c.value.toString(),
|
|
455
|
+
}));
|
|
456
|
+
const registerReceipt = await autoWallet.sendBatchTransaction(registerTxs);
|
|
457
|
+
if (!registerReceipt.success) {
|
|
458
|
+
output.warning(`Registration failed (tx: ${registerReceipt.hash}). Run "actp register" later.`);
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
output.success('Agent registered on AgentRegistry');
|
|
462
|
+
output.print(` Tx: ${registerReceipt.hash}`);
|
|
463
|
+
// Step 2: Mint test USDC
|
|
464
|
+
try {
|
|
465
|
+
const mintCalls = buildTestnetMintBatch(networkConfig.contracts.usdc, smartWalletAddress, '1000000000');
|
|
466
|
+
const mintTxs = mintCalls.map((c) => ({
|
|
467
|
+
to: c.target,
|
|
468
|
+
data: c.data,
|
|
469
|
+
value: c.value.toString(),
|
|
470
|
+
}));
|
|
471
|
+
const mintReceipt = await autoWallet.sendBatchTransaction(mintTxs);
|
|
472
|
+
if (mintReceipt.success) {
|
|
473
|
+
output.success('Minted 1,000 test USDC to Smart Wallet');
|
|
474
|
+
output.print(` Tx: ${mintReceipt.hash}`);
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
output.warning('USDC mint failed. Mint manually: actp faucet');
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
catch (mintError) {
|
|
481
|
+
output.warning('USDC mint failed. Mint manually: actp faucet');
|
|
482
|
+
sdkLogger.warn('Testnet mint failed', {
|
|
483
|
+
error: mintError instanceof Error ? mintError.message : String(mintError),
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
if (!receipt.success) {
|
|
489
|
+
output.warning(`Registration failed (tx: ${receipt.hash}). Run "actp register" later.`);
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
output.success('Agent registered on AgentRegistry');
|
|
493
|
+
output.success('Minted 1,000 test USDC to Smart Wallet');
|
|
494
|
+
output.print(` Tx: ${receipt.hash}`);
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
// Mainnet: register only (no minting)
|
|
498
|
+
output.info('Registering on AgentRegistry (gasless)...');
|
|
499
|
+
const calls = buildRegisterAgentBatch(networkConfig.contracts.agentRegistry, endpoint, serviceDescriptors);
|
|
500
|
+
const txRequests = calls.map((c) => ({
|
|
501
|
+
to: c.target,
|
|
502
|
+
data: c.data,
|
|
503
|
+
value: c.value.toString(),
|
|
504
|
+
}));
|
|
505
|
+
const receipt = await autoWallet.sendBatchTransaction(txRequests);
|
|
506
|
+
if (!receipt.success) {
|
|
507
|
+
output.warning(`Registration failed (tx: ${receipt.hash}). Run "actp register" later.`);
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
output.success('Agent registered on AgentRegistry');
|
|
511
|
+
output.print(` Tx: ${receipt.hash}`);
|
|
512
|
+
}
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
output.warning(`Registration failed: ${error.message}`);
|
|
517
|
+
output.info('You can register later with: actp register');
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
190
521
|
async function promptPassword() {
|
|
191
522
|
// If not a TTY (e.g. piped or run by agent), skip prompt
|
|
192
523
|
if (!process.stdin.isTTY) {
|
|
@@ -206,7 +537,7 @@ async function promptPassword() {
|
|
|
206
537
|
// ============================================================================
|
|
207
538
|
// Scaffold
|
|
208
539
|
// ============================================================================
|
|
209
|
-
async function runScaffold(options, mode, output) {
|
|
540
|
+
async function runScaffold(options, mode, output, mdConfig) {
|
|
210
541
|
const validIntents = ['earn', 'pay', 'both'];
|
|
211
542
|
const intent = options.intent || 'earn';
|
|
212
543
|
if (!validIntents.includes(intent)) {
|
|
@@ -220,8 +551,8 @@ async function runScaffold(options, mode, output) {
|
|
|
220
551
|
output.warning('agent.ts already exists. Use --force to overwrite.');
|
|
221
552
|
return;
|
|
222
553
|
}
|
|
223
|
-
// Derive agent name
|
|
224
|
-
const agentName = path.basename(process.cwd());
|
|
554
|
+
// Derive agent name: prefer AGIRAILS.md name, fallback to directory name
|
|
555
|
+
const agentName = (mdConfig?.name ? String(mdConfig.name) : null) || path.basename(process.cwd());
|
|
225
556
|
// Get template and substitute variables
|
|
226
557
|
const template = getTemplate(intent);
|
|
227
558
|
const content = template
|
|
@@ -251,8 +582,8 @@ async function runScaffold(options, mode, output) {
|
|
|
251
582
|
const tsconfigContent = JSON.stringify({
|
|
252
583
|
compilerOptions: {
|
|
253
584
|
target: 'ES2022',
|
|
254
|
-
module: '
|
|
255
|
-
moduleResolution: '
|
|
585
|
+
module: 'commonjs',
|
|
586
|
+
moduleResolution: 'node',
|
|
256
587
|
esModuleInterop: true,
|
|
257
588
|
strict: true,
|
|
258
589
|
outDir: 'dist',
|
|
@@ -270,18 +601,7 @@ async function runScaffold(options, mode, output) {
|
|
|
270
601
|
output.warning('Could not generate tsconfig.json');
|
|
271
602
|
}
|
|
272
603
|
}
|
|
273
|
-
//
|
|
274
|
-
const pkgFile = path.join(process.cwd(), 'package.json');
|
|
275
|
-
if (fs.existsSync(pkgFile)) {
|
|
276
|
-
try {
|
|
277
|
-
const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf-8'));
|
|
278
|
-
if (pkg.type !== 'module') {
|
|
279
|
-
output.warning('package.json has type: "' + (pkg.type || 'commonjs') + '". ' +
|
|
280
|
-
'Set "type": "module" for ESM support, or run with: npx ts-node --esm agent.ts');
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
catch { /* ignore parse errors */ }
|
|
284
|
-
}
|
|
604
|
+
// Note: @agirails/sdk is CJS — no type:module check needed
|
|
285
605
|
output.blank();
|
|
286
606
|
output.print('Next steps:');
|
|
287
607
|
output.print(' 1. Edit agent.ts with your logic');
|