@pushchain/core 6.0.27-alpha.2 → 6.0.27-alpha.4

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.
Files changed (99) hide show
  1. package/AGW.md +83 -7
  2. package/CHANGELOG.md +13 -0
  3. package/MARKETPLACE.md +206 -0
  4. package/package.json +2 -1
  5. package/src/lib/agentic/codec/rules.js +74 -69
  6. package/src/lib/agentic/codec/universal.js +15 -3
  7. package/src/lib/agentic/constants.d.ts +36 -1
  8. package/src/lib/agentic/constants.js +14 -1
  9. package/src/lib/agentic/contracts/prc20-metadata.d.ts +1 -1
  10. package/src/lib/agentic/contracts/prc20-metadata.js +11 -5
  11. package/src/lib/agentic/contracts/reader.d.ts +21 -0
  12. package/src/lib/agentic/contracts/reader.js +3 -0
  13. package/src/lib/agentic/error-messages.d.ts +3 -0
  14. package/src/lib/agentic/error-messages.js +125 -0
  15. package/src/lib/agentic/errors.d.ts +12 -3
  16. package/src/lib/agentic/errors.js +76 -0
  17. package/src/lib/agentic/management/common.js +6 -0
  18. package/src/lib/agentic/management/destination.d.ts +5 -0
  19. package/src/lib/agentic/management/destination.js +32 -0
  20. package/src/lib/agentic/management/prepare.js +80 -55
  21. package/src/lib/agentic/management/svm-public.js +13 -4
  22. package/src/lib/agentic/presets/catalog.d.ts +2 -0
  23. package/src/lib/agentic/presets/catalog.js +9 -0
  24. package/src/lib/agentic/presets/default-policy.d.ts +9 -0
  25. package/src/lib/agentic/presets/default-policy.js +85 -0
  26. package/src/lib/agentic/presets/default-tokens.d.ts +4 -0
  27. package/src/lib/agentic/presets/default-tokens.js +39 -0
  28. package/src/lib/agentic/presets/index.js +47 -22
  29. package/src/lib/agentic/presets/routes.d.ts +9 -0
  30. package/src/lib/agentic/presets/routes.js +50 -0
  31. package/src/lib/agentic/presets/types.d.ts +24 -8
  32. package/src/lib/agentic/public-rule.js +13 -2
  33. package/src/lib/constants/index.d.ts +35 -0
  34. package/src/lib/index.d.ts +4 -0
  35. package/src/lib/index.js +6 -2
  36. package/src/lib/job/job.d.ts +35 -0
  37. package/src/lib/job/job.js +382 -0
  38. package/src/lib/job/types.d.ts +94 -0
  39. package/src/lib/job/types.js +3 -0
  40. package/src/lib/job/watch.d.ts +3 -0
  41. package/src/lib/job/watch.js +169 -0
  42. package/src/lib/job-spec/codec.d.ts +18 -0
  43. package/src/lib/job-spec/codec.js +348 -0
  44. package/src/lib/job-spec/constants.d.ts +32 -0
  45. package/src/lib/job-spec/constants.js +36 -0
  46. package/src/lib/job-spec/helpers.d.ts +19 -0
  47. package/src/lib/job-spec/helpers.js +138 -0
  48. package/src/lib/job-spec/index.d.ts +14 -0
  49. package/src/lib/job-spec/index.js +17 -0
  50. package/src/lib/job-spec/preview.d.ts +8 -0
  51. package/src/lib/job-spec/preview.js +298 -0
  52. package/src/lib/job-spec/read.d.ts +20 -0
  53. package/src/lib/job-spec/read.js +224 -0
  54. package/src/lib/job-spec/schema.d.ts +290 -0
  55. package/src/lib/job-spec/schema.js +70 -0
  56. package/src/lib/job-spec/types.d.ts +139 -0
  57. package/src/lib/job-spec/types.js +3 -0
  58. package/src/lib/market/contracts/AgenticCommerce.d.ts +1026 -0
  59. package/src/lib/market/contracts/AgenticCommerce.js +1317 -0
  60. package/src/lib/market/contracts/RulesBindingHook.d.ts +235 -0
  61. package/src/lib/market/contracts/RulesBindingHook.js +314 -0
  62. package/src/lib/market/contracts/UniversalMarketplace.d.ts +1770 -0
  63. package/src/lib/market/contracts/UniversalMarketplace.js +2295 -0
  64. package/src/lib/market/contracts/UniversalMarketplaceErrors.d.ts +309 -0
  65. package/src/lib/market/contracts/UniversalMarketplaceErrors.js +416 -0
  66. package/src/lib/market/contracts/UniversalMarketplaceRules.d.ts +241 -0
  67. package/src/lib/market/contracts/UniversalMarketplaceRules.js +323 -0
  68. package/src/lib/market/data.d.ts +8 -0
  69. package/src/lib/market/data.js +60 -0
  70. package/src/lib/market/deployment.d.ts +14 -0
  71. package/src/lib/market/deployment.js +23 -0
  72. package/src/lib/market/deposit.d.ts +24 -0
  73. package/src/lib/market/deposit.js +271 -0
  74. package/src/lib/market/errors.d.ts +13 -0
  75. package/src/lib/market/errors.js +81 -0
  76. package/src/lib/market/history.d.ts +6 -0
  77. package/src/lib/market/history.js +83 -0
  78. package/src/lib/market/index.d.ts +4 -0
  79. package/src/lib/market/index.js +12 -0
  80. package/src/lib/market/kernel-wire.d.ts +15 -0
  81. package/src/lib/market/kernel-wire.js +41 -0
  82. package/src/lib/market/market.d.ts +55 -0
  83. package/src/lib/market/market.js +635 -0
  84. package/src/lib/market/rules.d.ts +106 -0
  85. package/src/lib/market/rules.js +293 -0
  86. package/src/lib/market/runtime.d.ts +35 -0
  87. package/src/lib/market/runtime.js +130 -0
  88. package/src/lib/market/types.d.ts +180 -0
  89. package/src/lib/market/types.js +3 -0
  90. package/src/lib/orchestrator/internals/errors.d.ts +9 -2
  91. package/src/lib/orchestrator/internals/errors.js +9 -2
  92. package/src/lib/orchestrator/internals/push-chain-tx.js +17 -3
  93. package/src/lib/push-chain/push-chain.d.ts +44 -1
  94. package/src/lib/push-chain/push-chain.js +23 -3
  95. package/src/lib/read-state/read-params.d.ts +9 -0
  96. package/src/lib/read-state/read-params.js +5 -1
  97. package/src/lib/universal/prc20-address.js +18 -4
  98. package/src/lib/utils.d.ts +15 -0
  99. package/src/lib/utils.js +4 -0
@@ -1,6 +1,41 @@
1
- /** Public section-7 discovery constants; deployment wiring stays internal. */
1
+ /** Public vocabulary. JOB.ADDRESS is the explicit per-chain job integration surface. */
2
2
  export declare const AGENTIC: Readonly<{
3
3
  WALLET: "agentic:wallet";
4
+ PRINCIPAL: "agentic:principal";
5
+ JOB: Readonly<{
6
+ ADDRESS: Readonly<{
7
+ 'eip155:42101': Readonly<{
8
+ KERNEL: "0x977cf1AC973E9eC4332791d531507575006157Ed";
9
+ HOOK: "0xDe7A94e510b6C571DE7880d441349689F73A32b3";
10
+ EVALUATOR: "0x1afC81396f1bb36F91f74506284952b81e4bd47c";
11
+ }>;
12
+ }>;
13
+ EVALUATION: Readonly<{
14
+ readonly BOOLEAN: "BOOLEAN";
15
+ readonly COMPARE: "COMPARE";
16
+ readonly NUMBER: "NUMBER";
17
+ readonly PERCENTAGE: "PERCENTAGE";
18
+ }>;
19
+ OPERATION: Readonly<{
20
+ readonly EQUAL: "EQUAL";
21
+ readonly NOT_EQUAL: "NOT_EQUAL";
22
+ readonly GREATER_THAN: "GREATER_THAN";
23
+ readonly GREATER_OR_EQUAL: "GREATER_OR_EQUAL";
24
+ readonly LESS_THAN: "LESS_THAN";
25
+ readonly LESS_OR_EQUAL: "LESS_OR_EQUAL";
26
+ }>;
27
+ LOGIC: Readonly<{
28
+ readonly ALL: "ALL";
29
+ readonly ANY: "ANY";
30
+ readonly AT_LEAST: "AT_LEAST";
31
+ }>;
32
+ ALLOWED_MUTABILITY: Readonly<{
33
+ readonly NONE: "NONE";
34
+ readonly CLIENT: "CLIENT";
35
+ readonly PROVIDER: "PROVIDER";
36
+ readonly BOTH: "BOTH";
37
+ }>;
38
+ }>;
4
39
  PRESETS: Readonly<{
5
40
  CATEGORY: Readonly<{
6
41
  DEXES: "DEXES";
@@ -1,9 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AGENTIC = void 0;
4
- /** Public section-7 discovery constants; deployment wiring stays internal. */
4
+ const constants_1 = require("../job-spec/constants");
5
+ const deployment_1 = require("../market/deployment");
6
+ /** Public vocabulary. JOB.ADDRESS is the explicit per-chain job integration surface. */
5
7
  exports.AGENTIC = Object.freeze({
6
8
  WALLET: 'agentic:wallet',
9
+ PRINCIPAL: constants_1.PRINCIPAL,
10
+ JOB: Object.freeze({
11
+ ...constants_1.JOB_VOCABULARY,
12
+ ADDRESS: Object.freeze({
13
+ 'eip155:42101': Object.freeze({
14
+ KERNEL: deployment_1.DONUT_MARKETPLACE.kernel,
15
+ HOOK: deployment_1.DONUT_MARKETPLACE.hook,
16
+ EVALUATOR: deployment_1.DONUT_MARKETPLACE.evaluator,
17
+ }),
18
+ }),
19
+ }),
7
20
  PRESETS: Object.freeze({
8
21
  CATEGORY: Object.freeze({
9
22
  DEXES: 'DEXES',
@@ -22,5 +22,5 @@ export declare const PRC20_SOURCE_ABI: readonly [{
22
22
  export declare function readSvmSourceToken(snap: Snapshot, token: Address, chain: string, network?: PUSH_NETWORK): Promise<Hex>;
23
23
  export declare const CORE_ADDRESS: Address;
24
24
  export declare function readGasPrc20(snap: Snapshot, chain: string): Promise<Address>;
25
- /** Donut native precompile returns a zero word; ERC20 metadata is a dynamic string. */
25
+ /** Solidity PRC20s return a string; Donut precompiles can return an address word. */
26
26
  export declare function readOriginToken(snap: Snapshot, token: Address, chain: string): Promise<Address>;
@@ -64,19 +64,25 @@ exports.CORE_ADDRESS = '0x00000000000000000000000000000000000000C0';
64
64
  async function readGasPrc20(snap, chain) {
65
65
  return (0, viem_1.getAddress)(await snap.read(exports.CORE_ADDRESS, prc20_evm_1.UNIVERSAL_CORE_EVM, 'gasTokenPRC20ByChainNamespace', [chain]));
66
66
  }
67
- /** Donut native precompile returns a zero word; ERC20 metadata is a dynamic string. */
67
+ /** Solidity PRC20s return a string; Donut precompiles can return an address word. */
68
68
  async function readOriginToken(snap, token, chain) {
69
69
  let source;
70
70
  try {
71
71
  source = await snap.read(token, exports.PRC20_SOURCE_ABI, 'SOURCE_TOKEN_ADDRESS');
72
72
  }
73
73
  catch (cause) {
74
- if ((await readGasPrc20(snap, chain)) !== (0, viem_1.getAddress)(token))
74
+ let sourceWord;
75
+ try {
76
+ sourceWord = (0, viem_1.getAddress)(await snap.read(token, NATIVE_SOURCE_ABI, 'SOURCE_TOKEN_ADDRESS'));
77
+ }
78
+ catch {
75
79
  throw cause;
76
- const native = await snap.read(token, NATIVE_SOURCE_ABI, 'SOURCE_TOKEN_ADDRESS');
77
- if ((0, viem_1.getAddress)(native) === viem_1.zeroAddress)
80
+ }
81
+ if (sourceWord !== viem_1.zeroAddress)
82
+ return sourceWord;
83
+ if ((await readGasPrc20(snap, chain)) === (0, viem_1.getAddress)(token))
78
84
  return viem_1.zeroAddress;
79
- throw cause;
85
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, `non-native PRC20 ${token} has an empty source token address`);
80
86
  }
81
87
  if ((0, viem_1.isAddress)(source, { strict: false }))
82
88
  return (0, viem_1.getAddress)(source);
@@ -13,6 +13,12 @@ export interface ChainReader {
13
13
  blockNumber?: bigint;
14
14
  }): Promise<unknown>;
15
15
  getBlockNumber(): Promise<bigint>;
16
+ getBlock?(args: {
17
+ blockNumber: bigint;
18
+ }): Promise<{
19
+ timestamp: bigint;
20
+ hash?: Hex | null;
21
+ }>;
16
22
  getCode(args: {
17
23
  address: Address;
18
24
  blockNumber?: bigint;
@@ -31,5 +37,20 @@ export interface ChainReader {
31
37
  getTransactionReceipt(args: {
32
38
  hash: Hex;
33
39
  }): Promise<TransactionReceipt>;
40
+ getTransaction?(args: {
41
+ hash: Hex;
42
+ }): Promise<{
43
+ input: Hex;
44
+ blockNumber: bigint | null;
45
+ }>;
46
+ /** Raw eth_call, used to verify complete signed marketplace requests before broadcast. */
47
+ call?(args: {
48
+ to: Address;
49
+ data: Hex;
50
+ account?: Address;
51
+ blockNumber?: bigint;
52
+ }): Promise<{
53
+ data?: Hex;
54
+ }>;
34
55
  }
35
56
  export declare function chainReaderFromPublicClient(client: PublicClient): ChainReader;
@@ -7,10 +7,13 @@ function chainReaderFromPublicClient(client) {
7
7
  return {
8
8
  readContract: (args) => client.readContract(args),
9
9
  getBlockNumber: () => client.getBlockNumber({ cacheTime: 0 }),
10
+ getBlock: (args) => client.getBlock(args),
10
11
  getCode: (args) => client.getCode(args),
11
12
  getBalance: (args) => client.getBalance(args),
12
13
  getLogs: (args) => client.getLogs(args),
13
14
  getTransactionReceipt: (args) => client.getTransactionReceipt(args),
15
+ getTransaction: (args) => client.getTransaction(args),
16
+ call: (args) => client.call(args),
14
17
  };
15
18
  }
16
19
  //# sourceMappingURL=reader.js.map
@@ -0,0 +1,3 @@
1
+ import type { AgenticErrorCode } from './errors';
2
+ export declare function agenticUserMessage(code: AgenticErrorCode, diagnostic: string, details?: Readonly<Record<string, unknown>>): string;
3
+ export declare function agenticRevertUserMessage(name?: string): string;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agenticUserMessage = agenticUserMessage;
4
+ exports.agenticRevertUserMessage = agenticRevertUserMessage;
5
+ /** UI copy only. Codes, original messages, hints and causes remain diagnostic data. */
6
+ const MESSAGES = {
7
+ DUPLICATE_RULE: 'Keep one rule per agent and network. Edit the existing rule or remove the duplicate.',
8
+ AGENT_IS_OWNER: 'Choose an agent address different from the wallet owner.',
9
+ AMBIGUOUS_RULE: 'More than one rule matches this agent and network. Keep one active matching rule before sending.',
10
+ TARGET_NOT_ON_RULE_CHAIN: 'Choose an app on the network selected for this rule.',
11
+ ASSET_CHAIN_MISMATCH: 'The selected token belongs to a different network. Choose a token on this rule’s network.',
12
+ TOKEN_ROUTE_UNAVAILABLE: 'This token cannot currently be transferred from Push to the selected network. Choose a token with a supported Push route.',
13
+ REQUEST_REJECTED: 'The wallet request was cancelled. Check wallet activity before trying again.',
14
+ NOT_OWNER_OR_AGENT: 'Connect the wallet owner or an agent authorized by its rules.',
15
+ WALLET_NOT_DEPLOYED: 'This agentic wallet has not been created yet.',
16
+ NOT_AGENTIC_WALLET: 'This address is not a supported agentic wallet.',
17
+ DELETE_NEEDS_TARGET: 'Choose which rules to remove.',
18
+ NO_RULES_FOR_CHAIN: 'This agent has no active rule for the selected network.',
19
+ FROM_NOT_ALLOWED: 'The agentic wallet is the sender. Remove the custom sender selection.',
20
+ NOT_ALLOWED_IN_AGENTIC_MODE: 'This action is unavailable while using an agentic wallet.',
21
+ INVALID_RULE: 'Some rule settings are invalid. Review the rule and try again.',
22
+ CAPABILITY_UNAVAILABLE: 'This feature is not available for this wallet or network yet.',
23
+ READ_ONLY: 'Connect a signing wallet to continue.',
24
+ NOT_WALLET_OWNER: 'Connect the owner wallet to change these permissions.',
25
+ RULE_NOT_FOUND: 'This rule could not be found. Refresh the wallet’s rules and try again.',
26
+ RULE_READ_FAILED: 'The wallet’s current state could not be loaded. Refresh and try again.',
27
+ INCONSISTENT_READ: 'The wallet changed while it was being checked. Refresh before trying again.',
28
+ INDEX_RACE: 'The expected wallet address changed. Refresh wallet information before trying again.',
29
+ RECEIPT_MISMATCH: 'The transaction result needs verification. Check its status before retrying.',
30
+ RECEIPT_UNAVAILABLE: 'The transaction was submitted, but its status could not be confirmed. Check its status before trying again.',
31
+ AGENT_GAS_INSUFFICIENT: 'The agent needs more Push coins to pay transaction fees.',
32
+ WALLET_BALANCE_INSUFFICIENT: 'The agentic wallet does not have enough funds for this action.',
33
+ };
34
+ function agenticUserMessage(code, diagnostic, details) {
35
+ if (code === 'CAPABILITY_UNAVAILABLE') {
36
+ if (details?.['capability'] === 'nativeActions')
37
+ return 'A Push rule can allow at most eight functions. Select fewer functions.';
38
+ if (details?.['capability'] === 'presetCalls')
39
+ return 'Choose a preset configuration with 1 to 32 allowed functions.';
40
+ if (details?.['capability'] === 'presetChain' ||
41
+ details?.['capability'] === 'presetCatalog')
42
+ return 'This preset is unavailable for the selected network.';
43
+ }
44
+ if (code !== 'INVALID_RULE')
45
+ return MESSAGES[code];
46
+ if (/validUntil|expiry|expired|future.*timestamp/i.test(diagnostic))
47
+ return 'Choose an expiry date in the future.';
48
+ if (/label.*(64|length|most)/i.test(diagnostic))
49
+ return 'The wallet name is too long. Shorten it and try again.';
50
+ if (/label/i.test(diagnostic))
51
+ return 'Enter a valid wallet name.';
52
+ if (/maxGasPerCall.*positive/i.test(diagnostic))
53
+ return 'Set a gas budget greater than zero for this rule.';
54
+ if (/allowedCalls.*(1\.\.32|contain|array)/i.test(diagnostic))
55
+ return 'Select between 1 and 32 allowed functions for this rule.';
56
+ if (/rules.*(eight|8)|eight initial rules/i.test(diagnostic))
57
+ return 'A wallet can be created with at most eight rules. Remove some rules before creating it.';
58
+ if (/assets.*(eight|8)/i.test(diagnostic))
59
+ return 'A rule can include at most eight tokens. Select fewer tokens.';
60
+ if (/duplicate.*pin|pin.*duplicate/i.test(diagnostic))
61
+ return 'The same function input has more than one condition. Keep one condition for each input.';
62
+ if (/pins.*(eight|8)/i.test(diagnostic))
63
+ return 'A function can have at most eight conditions. Choose a simpler function configuration.';
64
+ if (/pins.*32|32.*pins/i.test(diagnostic))
65
+ return 'This rule has too many conditions. Select fewer tokens or allowed functions.';
66
+ if (/selector|function signature/i.test(diagnostic))
67
+ return 'The selected function format is invalid. Select the function again or check its signature.';
68
+ if (/dynamic|static|offset|argument.*range|tuple/i.test(diagnostic))
69
+ return 'This function input cannot be constrained in that format. Choose a supported input or function.';
70
+ if (/uint256|bigint|non-negative/i.test(diagnostic))
71
+ return 'One of the spending limits is invalid. Review the amounts and try again.';
72
+ if (/chainNamespace|unsupported.*chain/i.test(diagnostic))
73
+ return 'Choose a supported network for this rule.';
74
+ if (/address/i.test(diagnostic))
75
+ return 'Enter a valid wallet, token or app address for this rule.';
76
+ return MESSAGES.INVALID_RULE;
77
+ }
78
+ function agenticRevertUserMessage(name) {
79
+ if (!name)
80
+ return 'The transaction could not be completed. Check wallet activity before trying again.';
81
+ if (/TooManyAllowedCallPins/.test(name))
82
+ return 'This rule has more than 32 conditions. Select fewer tokens or allowed functions.';
83
+ if (/TooMany.*Pins|PinRuleOutOfRange/.test(name))
84
+ return 'This function has too many conditions. Choose a simpler rule configuration.';
85
+ if (/TooManyActions|TooManyInitialRules|BatchSizeOutOfRange/.test(name))
86
+ return 'Too many rules or functions are selected. Reduce the selection and try again.';
87
+ if (/LabelTooLong/.test(name))
88
+ return 'The wallet name is too long. Shorten it and try again.';
89
+ if (/DuplicateAction|DuplicateAsset|DuplicateSvmPin/.test(name))
90
+ return 'This rule contains duplicate functions, tokens or conditions. Remove the duplicate selection.';
91
+ if (/SpentMismatch|SpentLengthMismatch|AssetSpentMismatch|IndexMismatch|InvalidNonce|IntentGrantNonceMismatch|IntentWalletMismatch/.test(name))
92
+ return 'The wallet changed while this action was being prepared. Refresh its state before trying again.';
93
+ if (/EnforcedPause/.test(name))
94
+ return 'This operation is temporarily paused. Try again later.';
95
+ if (/OwnerSigExpired|SignatureExpired/.test(name))
96
+ return 'The wallet approval has expired. Review and sign a new request.';
97
+ if (/OutsideTimeWindow/.test(name))
98
+ return 'This request is outside its valid time window. Refresh and approve a new request.';
99
+ if (/InvalidExpiry/.test(name))
100
+ return 'Choose a valid future expiry for this rule.';
101
+ if (/Allowance|Approval/.test(name))
102
+ return 'The token spending approval is missing or too small. Review the token approvals.';
103
+ if (/RuleWithoutPin|CeaAccountsMissExpectedCEA|CeaAccountAtUnpinnedIndex/.test(name))
104
+ return 'The rule is missing a required wallet-recipient restriction. Review its recipient settings.';
105
+ if (/Unsupported|WrongVmForCall|WrongModeForCall/.test(name))
106
+ return 'This action is not supported on the selected network or wallet version.';
107
+ if (/InvalidOwnerSignature|InvalidEnableSignature|InvalidSessionKeySignature|SignerNotFound/.test(name))
108
+ return 'The signature could not be verified. Reconnect the authorized wallet and try again.';
109
+ if (/PCValueExceedsCap|Gas.*Cap/.test(name ?? ''))
110
+ return 'The required gas exceeds this rule’s gas budget. Review the budget before trying again.';
111
+ if (/ArgPinAboveMax|AmountExceedsCap|TotalSpendCapExceeded|Value.*Cap|MaxCalls|CallLimitReached|TotalNativeAmountExceeded|TotalValueExceeded/.test(name ?? ''))
112
+ return 'This action exceeds a rule’s spending or usage limit. Reduce the amount or ask the owner to update the rule.';
113
+ if (/Expired|Expiry/.test(name ?? ''))
114
+ return 'This rule has expired. Ask the owner to renew it.';
115
+ if (/ArgPinMismatch|Beneficiary|NotAllowed|NotEnabled|Permission|RuleNot|RulesNot|RecipientTargetMismatch|TargetMismatch|SelectorMismatch|SvmAccountPinMismatch|SvmDataPinMismatch/.test(name ?? ''))
116
+ return 'This action does not match the wallet’s permissions. Check the token, recipient and allowed function.';
117
+ if (/CallerIsNotOwner|UnauthorizedOwner|OwnerLaneRequired/.test(name ?? ''))
118
+ return 'Connect the owner wallet to make this change.';
119
+ if (/CallerIsNotAgent/.test(name ?? ''))
120
+ return 'Connect the agent authorized by this rule.';
121
+ if (/Insufficient|Balance/.test(name ?? ''))
122
+ return 'There are not enough funds for this action. Check the wallet balance and fees.';
123
+ return 'The wallet contract rejected this transaction. Review the permissions and transaction details before trying again.';
124
+ }
125
+ //# sourceMappingURL=error-messages.js.map
@@ -10,6 +10,8 @@ export declare const AGENTIC_ERROR_CODE: {
10
10
  readonly AMBIGUOUS_RULE: "AMBIGUOUS_RULE";
11
11
  readonly TARGET_NOT_ON_RULE_CHAIN: "TARGET_NOT_ON_RULE_CHAIN";
12
12
  readonly ASSET_CHAIN_MISMATCH: "ASSET_CHAIN_MISMATCH";
13
+ readonly TOKEN_ROUTE_UNAVAILABLE: "TOKEN_ROUTE_UNAVAILABLE";
14
+ readonly REQUEST_REJECTED: "REQUEST_REJECTED";
13
15
  readonly NOT_OWNER_OR_AGENT: "NOT_OWNER_OR_AGENT";
14
16
  readonly WALLET_NOT_DEPLOYED: "WALLET_NOT_DEPLOYED";
15
17
  readonly NOT_AGENTIC_WALLET: "NOT_AGENTIC_WALLET";
@@ -36,15 +38,18 @@ export type AgenticErrorCode = (typeof AGENTIC_ERROR_CODE)[keyof typeof AGENTIC_
36
38
  * eligibility or a read that cannot be trusted. Nothing was signed or sent
37
39
  * except receipt errors, which retain the submitted transaction hash.
38
40
  */
39
- export declare class AgenticError extends Error {
40
- readonly code: AgenticErrorCode;
41
+ export declare class AgenticError<Code extends string = AgenticErrorCode> extends Error {
42
+ readonly code: Code;
43
+ /** Safe end-user copy; message/cause retain technical diagnostics. */
44
+ readonly userMessage: string;
41
45
  readonly hint?: string;
42
46
  readonly details?: Readonly<Record<string, unknown>>;
43
47
  readonly cause?: unknown;
44
- constructor(code: AgenticErrorCode, message: string, opts?: {
48
+ constructor(code: Code, message: string, opts?: {
45
49
  hint?: string;
46
50
  details?: Record<string, unknown>;
47
51
  cause?: unknown;
52
+ userMessage?: string;
48
53
  });
49
54
  }
50
55
  /**
@@ -55,6 +60,7 @@ export declare class AgenticError extends Error {
55
60
  */
56
61
  export declare class AgenticRevertError extends PushChainExecutionError {
57
62
  readonly agenticCode?: string;
63
+ readonly userMessage: string;
58
64
  constructor(message: string, opts?: {
59
65
  decodedError?: DecodedErrorPayload;
60
66
  gatewayTxHash?: string;
@@ -62,4 +68,7 @@ export declare class AgenticRevertError extends PushChainExecutionError {
62
68
  cause?: unknown;
63
69
  });
64
70
  }
71
+ export declare function ruleConstraintLimit(actual: number, callCount: number, chainNamespace?: string): AgenticError;
72
+ export declare function ruleErrorContext(error: unknown, ruleIndex: number, chainNamespace?: string): unknown;
73
+ export declare function tokenRouteUnavailable(cause: unknown, token: string, chainNamespace: string, assetIndex: number): AgenticError;
65
74
  export declare function capabilityUnavailable(capability: string, dependency: string, hint?: string): AgenticError;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AgenticRevertError = exports.AgenticError = exports.AGENTIC_ERROR_CODE = void 0;
4
+ exports.ruleConstraintLimit = ruleConstraintLimit;
5
+ exports.ruleErrorContext = ruleErrorContext;
6
+ exports.tokenRouteUnavailable = tokenRouteUnavailable;
4
7
  exports.capabilityUnavailable = capabilityUnavailable;
5
8
  const errors_1 = require("../orchestrator/internals/errors");
9
+ const error_messages_1 = require("./error-messages");
6
10
  /**
7
11
  * Stable AGW error codes. The first groups are specified by the AGW SDK page
8
12
  * (section 3.f); the remainder are SDK-owned codes that keep unsupported or
@@ -15,6 +19,8 @@ exports.AGENTIC_ERROR_CODE = {
15
19
  AMBIGUOUS_RULE: 'AMBIGUOUS_RULE',
16
20
  TARGET_NOT_ON_RULE_CHAIN: 'TARGET_NOT_ON_RULE_CHAIN',
17
21
  ASSET_CHAIN_MISMATCH: 'ASSET_CHAIN_MISMATCH',
22
+ TOKEN_ROUTE_UNAVAILABLE: 'TOKEN_ROUTE_UNAVAILABLE',
23
+ REQUEST_REJECTED: 'REQUEST_REJECTED',
18
24
  // initialize with agenticWallet (spec 3.f)
19
25
  NOT_OWNER_OR_AGENT: 'NOT_OWNER_OR_AGENT',
20
26
  WALLET_NOT_DEPLOYED: 'WALLET_NOT_DEPLOYED',
@@ -46,6 +52,8 @@ exports.AGENTIC_ERROR_CODE = {
46
52
  */
47
53
  class AgenticError extends Error {
48
54
  code;
55
+ /** Safe end-user copy; message/cause retain technical diagnostics. */
56
+ userMessage;
49
57
  hint;
50
58
  details;
51
59
  cause;
@@ -53,6 +61,11 @@ class AgenticError extends Error {
53
61
  super(message);
54
62
  this.name = 'AgenticError';
55
63
  this.code = code;
64
+ this.userMessage =
65
+ opts.userMessage ??
66
+ (Object.prototype.hasOwnProperty.call(exports.AGENTIC_ERROR_CODE, code)
67
+ ? (0, error_messages_1.agenticUserMessage)(code, message, opts.details)
68
+ : message);
56
69
  this.hint = opts.hint;
57
70
  this.details = opts.details;
58
71
  this.cause = opts.cause;
@@ -67,6 +80,7 @@ exports.AgenticError = AgenticError;
67
80
  */
68
81
  class AgenticRevertError extends errors_1.PushChainExecutionError {
69
82
  agenticCode;
83
+ userMessage;
70
84
  constructor(message, opts = {}) {
71
85
  super(message, {
72
86
  decodedError: opts.decodedError,
@@ -75,9 +89,71 @@ class AgenticRevertError extends errors_1.PushChainExecutionError {
75
89
  });
76
90
  this.name = 'AgenticRevertError';
77
91
  this.agenticCode = opts.agenticCode;
92
+ this.userMessage = (0, error_messages_1.agenticRevertUserMessage)(opts.decodedError?.name ?? opts.agenticCode);
78
93
  }
79
94
  }
80
95
  exports.AgenticRevertError = AgenticRevertError;
96
+ function ruleConstraintLimit(actual, callCount, chainNamespace) {
97
+ const message = `This rule has ${actual} conditions. The maximum is 32. Remove duplicate functions or select fewer tokens or functions.`;
98
+ return new AgenticError(exports.AGENTIC_ERROR_CODE.INVALID_RULE, message, {
99
+ userMessage: message,
100
+ hint: 'Regenerate the preset after changing selections. Do not drop individual conditions or bypass the contract limit.',
101
+ details: {
102
+ reason: 'RULE_CONSTRAINT_LIMIT',
103
+ field: 'allowedCalls',
104
+ actual,
105
+ limit: 32,
106
+ callCount,
107
+ chainNamespace,
108
+ },
109
+ });
110
+ }
111
+ function ruleErrorContext(error, ruleIndex, chainNamespace) {
112
+ if (!(error instanceof AgenticError))
113
+ return error;
114
+ if (error.details?.['ruleIndex'] !== undefined)
115
+ return error;
116
+ return new AgenticError(error.code, error.message, {
117
+ hint: error.hint,
118
+ userMessage: `Rule ${ruleIndex + 1}: ${error.userMessage}`,
119
+ cause: error.cause ?? error,
120
+ details: {
121
+ ...error.details,
122
+ ruleIndex,
123
+ ...(chainNamespace ? { chainNamespace } : {}),
124
+ },
125
+ });
126
+ }
127
+ function tokenRouteUnavailable(cause, token, chainNamespace, assetIndex) {
128
+ if (cause instanceof AgenticError)
129
+ return cause;
130
+ const names = {
131
+ 'eip155:1': 'Ethereum',
132
+ 'eip155:11155111': 'Ethereum Sepolia',
133
+ 'eip155:8453': 'Base',
134
+ 'eip155:84532': 'Base Sepolia',
135
+ 'eip155:42161': 'Arbitrum',
136
+ 'eip155:421614': 'Arbitrum Sepolia',
137
+ 'eip155:56': 'BNB Chain',
138
+ 'eip155:97': 'BNB Testnet',
139
+ };
140
+ const network = names[chainNamespace] ??
141
+ (chainNamespace.startsWith('solana:')
142
+ ? 'the selected Solana network'
143
+ : 'the selected network');
144
+ const message = `This token cannot be sent from Push to ${network}. Choose a token with a supported Push route.`;
145
+ return new AgenticError(exports.AGENTIC_ERROR_CODE.TOKEN_ROUTE_UNAVAILABLE, message, {
146
+ userMessage: message,
147
+ hint: 'Choose a supported token on this network, or wait for a verified PRC20 route for this exact token address. Token symbols alone do not identify a route.',
148
+ details: {
149
+ token,
150
+ chainNamespace,
151
+ assetIndex,
152
+ field: `assets[${assetIndex}].token`,
153
+ },
154
+ cause,
155
+ });
156
+ }
81
157
  function capabilityUnavailable(capability, dependency, hint) {
82
158
  return new AgenticError(exports.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE, `AGW capability "${capability}" is not available: ${dependency}`, { hint, details: { capability, dependency } });
83
159
  }
@@ -102,6 +102,12 @@ function wrapSendError(err) {
102
102
  cause: err,
103
103
  });
104
104
  }
105
+ if (err &&
106
+ typeof err === 'object' &&
107
+ (('code' in err && err.code === 4001) ||
108
+ ('name' in err && err.name === 'UserRejectedRequestError'))) {
109
+ return new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.REQUEST_REJECTED, 'The wallet request was cancelled.', { cause: err });
110
+ }
105
111
  if (decoded || err instanceof errors_1.PushChainExecutionError) {
106
112
  const e = err;
107
113
  return new errors_2.AgenticRevertError(e?.message ?? decoded?.name ?? 'AGW revert', {
@@ -0,0 +1,5 @@
1
+ import { type Address } from 'viem';
2
+ import type { CHAIN } from '../../constants/enums';
3
+ import type { AgenticRuntime } from '../runtime';
4
+ /** Preserve read failures as read failures; never report them as bad token routes. */
5
+ export declare function resolveRuleDestination(runtime: AgenticRuntime, wallet: Address, chain: CHAIN): Promise<Address>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveRuleDestination = resolveRuleDestination;
4
+ const viem_1 = require("viem");
5
+ const errors_1 = require("../errors");
6
+ /** Preserve read failures as read failures; never report them as bad token routes. */
7
+ async function resolveRuleDestination(runtime, wallet, chain) {
8
+ try {
9
+ return (0, viem_1.getAddress)((await runtime.resolveCEA(wallet, chain)).cea);
10
+ }
11
+ catch (cause) {
12
+ if (cause instanceof errors_1.AgenticError)
13
+ throw cause;
14
+ const unavailable = cause instanceof Error &&
15
+ cause.message.includes('CEAFactory not available on chain');
16
+ const message = unavailable
17
+ ? 'Agentic wallets are not available on this destination network yet. Choose a supported network.'
18
+ : 'The wallet’s destination account could not be loaded. Try again shortly.';
19
+ throw new errors_1.AgenticError(unavailable
20
+ ? errors_1.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE
21
+ : errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, message, {
22
+ userMessage: message,
23
+ cause,
24
+ details: {
25
+ chainNamespace: chain,
26
+ field: 'chainNamespace',
27
+ stage: 'destinationAccount',
28
+ },
29
+ });
30
+ }
31
+ }
32
+ //# sourceMappingURL=destination.js.map