@aomi-labs/client 0.1.19 → 0.1.21
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/dist/cli.js +97 -10
- package/dist/index.cjs +42 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +42 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -449,6 +449,13 @@ type SessionEventMap = {
|
|
|
449
449
|
processing_start: undefined;
|
|
450
450
|
/** AI finished processing. */
|
|
451
451
|
processing_end: undefined;
|
|
452
|
+
/**
|
|
453
|
+
* Backend transitioned from processing to idle (is_processing went false).
|
|
454
|
+
* Unlike `processing_end`, this fires even when there are unresolved local
|
|
455
|
+
* wallet requests. CLI consumers use it to know that all system events
|
|
456
|
+
* (including wallet requests) have been delivered for the current turn.
|
|
457
|
+
*/
|
|
458
|
+
backend_idle: undefined;
|
|
452
459
|
/** An error occurred during polling or SSE. */
|
|
453
460
|
error: {
|
|
454
461
|
error: unknown;
|
|
@@ -474,6 +481,7 @@ declare class ClientSession extends TypedEventEmitter<SessionEventMap> {
|
|
|
474
481
|
private pollTimer;
|
|
475
482
|
private unsubscribeSSE;
|
|
476
483
|
private _isProcessing;
|
|
484
|
+
private _backendWasProcessing;
|
|
477
485
|
private walletRequests;
|
|
478
486
|
private walletRequestNextId;
|
|
479
487
|
private _messages;
|
package/dist/index.d.ts
CHANGED
|
@@ -449,6 +449,13 @@ type SessionEventMap = {
|
|
|
449
449
|
processing_start: undefined;
|
|
450
450
|
/** AI finished processing. */
|
|
451
451
|
processing_end: undefined;
|
|
452
|
+
/**
|
|
453
|
+
* Backend transitioned from processing to idle (is_processing went false).
|
|
454
|
+
* Unlike `processing_end`, this fires even when there are unresolved local
|
|
455
|
+
* wallet requests. CLI consumers use it to know that all system events
|
|
456
|
+
* (including wallet requests) have been delivered for the current turn.
|
|
457
|
+
*/
|
|
458
|
+
backend_idle: undefined;
|
|
452
459
|
/** An error occurred during polling or SSE. */
|
|
453
460
|
error: {
|
|
454
461
|
error: unknown;
|
|
@@ -474,6 +481,7 @@ declare class ClientSession extends TypedEventEmitter<SessionEventMap> {
|
|
|
474
481
|
private pollTimer;
|
|
475
482
|
private unsubscribeSSE;
|
|
476
483
|
private _isProcessing;
|
|
484
|
+
private _backendWasProcessing;
|
|
477
485
|
private walletRequests;
|
|
478
486
|
private walletRequestNextId;
|
|
479
487
|
private _messages;
|
package/dist/index.js
CHANGED
|
@@ -848,6 +848,7 @@ var ClientSession = class extends TypedEventEmitter {
|
|
|
848
848
|
this.pollTimer = null;
|
|
849
849
|
this.unsubscribeSSE = null;
|
|
850
850
|
this._isProcessing = false;
|
|
851
|
+
this._backendWasProcessing = false;
|
|
851
852
|
this.walletRequests = [];
|
|
852
853
|
this.walletRequestNextId = 1;
|
|
853
854
|
this._messages = [];
|
|
@@ -1078,6 +1079,7 @@ var ClientSession = class extends TypedEventEmitter {
|
|
|
1078
1079
|
startPolling() {
|
|
1079
1080
|
var _a;
|
|
1080
1081
|
if (this.pollTimer || this.closed) return;
|
|
1082
|
+
this._backendWasProcessing = true;
|
|
1081
1083
|
(_a = this.logger) == null ? void 0 : _a.debug("[session] polling started", this.sessionId);
|
|
1082
1084
|
this.pollTimer = setInterval(() => {
|
|
1083
1085
|
void this.pollTick();
|
|
@@ -1103,6 +1105,10 @@ var ClientSession = class extends TypedEventEmitter {
|
|
|
1103
1105
|
if (!this.pollTimer) return;
|
|
1104
1106
|
this.assertUserStateAligned(state.user_state);
|
|
1105
1107
|
this.applyState(state);
|
|
1108
|
+
if (this._backendWasProcessing && !state.is_processing) {
|
|
1109
|
+
this.emit("backend_idle", void 0);
|
|
1110
|
+
}
|
|
1111
|
+
this._backendWasProcessing = !!state.is_processing;
|
|
1106
1112
|
if (!state.is_processing && this.walletRequests.length === 0) {
|
|
1107
1113
|
this.stopPolling();
|
|
1108
1114
|
this._isProcessing = false;
|
|
@@ -1414,6 +1420,10 @@ async function executeViaAA(callList, providerState) {
|
|
|
1414
1420
|
const receipt = callList.length > 1 ? await AA.sendBatchTransaction(callsPayload) : await AA.sendTransaction(callsPayload[0]);
|
|
1415
1421
|
const txHash = receipt.transactionHash;
|
|
1416
1422
|
const providerPrefix = AA.provider.toLowerCase();
|
|
1423
|
+
let delegationAddress = AA.mode === "7702" ? AA.delegationAddress : void 0;
|
|
1424
|
+
if (AA.mode === "7702" && !delegationAddress) {
|
|
1425
|
+
delegationAddress = await resolve7702Delegation(txHash, callList);
|
|
1426
|
+
}
|
|
1417
1427
|
return {
|
|
1418
1428
|
txHash,
|
|
1419
1429
|
txHashes: [txHash],
|
|
@@ -1421,9 +1431,36 @@ async function executeViaAA(callList, providerState) {
|
|
|
1421
1431
|
batched: callList.length > 1,
|
|
1422
1432
|
sponsored: plan.sponsorship !== "disabled",
|
|
1423
1433
|
AAAddress: AA.AAAddress,
|
|
1424
|
-
delegationAddress
|
|
1434
|
+
delegationAddress
|
|
1425
1435
|
};
|
|
1426
1436
|
}
|
|
1437
|
+
async function resolve7702Delegation(txHash, callList) {
|
|
1438
|
+
var _a, _b, _c, _d;
|
|
1439
|
+
try {
|
|
1440
|
+
const { createPublicClient, http } = await import("viem");
|
|
1441
|
+
const chainId = (_a = callList[0]) == null ? void 0 : _a.chainId;
|
|
1442
|
+
if (!chainId) return void 0;
|
|
1443
|
+
const { mainnet, polygon, arbitrum, optimism, base } = await import("viem/chains");
|
|
1444
|
+
const knownChains = {
|
|
1445
|
+
1: mainnet,
|
|
1446
|
+
137: polygon,
|
|
1447
|
+
42161: arbitrum,
|
|
1448
|
+
10: optimism,
|
|
1449
|
+
8453: base
|
|
1450
|
+
};
|
|
1451
|
+
const chain = knownChains[chainId];
|
|
1452
|
+
if (!chain) return void 0;
|
|
1453
|
+
const client = createPublicClient({ chain, transport: http() });
|
|
1454
|
+
const tx = await client.getTransaction({ hash: txHash });
|
|
1455
|
+
const authList = tx.authorizationList;
|
|
1456
|
+
const target = (_d = (_b = authList == null ? void 0 : authList[0]) == null ? void 0 : _b.address) != null ? _d : (_c = authList == null ? void 0 : authList[0]) == null ? void 0 : _c.contractAddress;
|
|
1457
|
+
if (target) {
|
|
1458
|
+
return target;
|
|
1459
|
+
}
|
|
1460
|
+
} catch (e) {
|
|
1461
|
+
}
|
|
1462
|
+
return void 0;
|
|
1463
|
+
}
|
|
1427
1464
|
async function executeViaEoa({
|
|
1428
1465
|
callList,
|
|
1429
1466
|
currentChainId,
|
|
@@ -1782,11 +1819,12 @@ function createPimlicoAAProvider({
|
|
|
1782
1819
|
|
|
1783
1820
|
// src/aa/adapt.ts
|
|
1784
1821
|
function adaptSmartAccount(account) {
|
|
1822
|
+
const delegationAddress = account.mode === "7702" && account.delegationAddress && account.smartAccountAddress && account.delegationAddress.toLowerCase() === account.smartAccountAddress.toLowerCase() ? void 0 : account.delegationAddress;
|
|
1785
1823
|
return {
|
|
1786
1824
|
provider: account.provider,
|
|
1787
1825
|
mode: account.mode,
|
|
1788
1826
|
AAAddress: account.smartAccountAddress,
|
|
1789
|
-
delegationAddress
|
|
1827
|
+
delegationAddress,
|
|
1790
1828
|
sendTransaction: async (call) => {
|
|
1791
1829
|
const receipt = await account.sendTransaction(call);
|
|
1792
1830
|
return { transactionHash: receipt.transactionHash };
|
|
@@ -1807,6 +1845,7 @@ function isAlchemySponsorshipLimitError(error) {
|
|
|
1807
1845
|
import { createAlchemySmartAccount } from "@getpara/aa-alchemy";
|
|
1808
1846
|
import { createPimlicoSmartAccount } from "@getpara/aa-pimlico";
|
|
1809
1847
|
import { privateKeyToAccount } from "viem/accounts";
|
|
1848
|
+
var ALCHEMY_7702_DELEGATION_ADDRESS = "0x69007702764179f14F51cdce752f4f775d74E139";
|
|
1810
1849
|
async function createAAProviderState(options) {
|
|
1811
1850
|
if (options.provider === "alchemy") {
|
|
1812
1851
|
return createAlchemyAAState({
|
|
@@ -2006,7 +2045,7 @@ async function createAlchemyWalletApisState(params) {
|
|
|
2006
2045
|
provider: "alchemy",
|
|
2007
2046
|
mode: params.mode,
|
|
2008
2047
|
AAAddress: accountAddress,
|
|
2009
|
-
delegationAddress: params.mode === "7702" ?
|
|
2048
|
+
delegationAddress: params.mode === "7702" ? ALCHEMY_7702_DELEGATION_ADDRESS : void 0,
|
|
2010
2049
|
sendTransaction: async (call) => sendCalls([call]),
|
|
2011
2050
|
sendBatchTransaction: async (calls) => sendCalls(calls)
|
|
2012
2051
|
};
|