ethagent 1.1.2 → 2.0.0
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/LICENSE +21 -21
- package/README.md +126 -30
- package/package.json +7 -2
- package/src/app/FirstRun.tsx +190 -146
- package/src/app/FirstRunTimeline.tsx +47 -0
- package/src/app/input/AppInputProvider.tsx +1 -1
- package/src/app/keybindings/KeybindingProvider.tsx +1 -1
- package/src/chat/ChatBottomPane.tsx +0 -1
- package/src/chat/ChatInput.tsx +6 -6
- package/src/chat/ChatScreen.tsx +35 -15
- package/src/chat/ContextLimitView.tsx +4 -4
- package/src/chat/ContinuityEditReviewView.tsx +10 -22
- package/src/chat/CopyPicker.tsx +0 -1
- package/src/chat/MessageList.tsx +62 -45
- package/src/chat/PermissionPrompt.tsx +13 -9
- package/src/chat/PlanApprovalView.tsx +3 -3
- package/src/chat/ResumeView.tsx +1 -4
- package/src/chat/RewindView.tsx +2 -2
- package/src/chat/chatInputState.ts +1 -1
- package/src/chat/chatScreenUtils.ts +22 -11
- package/src/chat/chatSessionState.ts +2 -2
- package/src/chat/chatTurnOrchestrator.ts +16 -81
- package/src/chat/commands.ts +1 -1
- package/src/chat/textCursor.ts +1 -1
- package/src/chat/transcriptViewport.ts +2 -7
- package/src/cli/ResetConfirmView.tsx +1 -1
- package/src/cli/main.tsx +9 -3
- package/src/cli/preview.tsx +0 -5
- package/src/cli/updateNotice.ts +4 -2
- package/src/identity/continuity/editor.ts +7 -107
- package/src/identity/continuity/envelope.ts +1048 -40
- package/src/identity/continuity/history.ts +4 -4
- package/src/identity/continuity/localBackup.ts +249 -0
- package/src/identity/continuity/privateEdit/apply.ts +170 -0
- package/src/identity/continuity/privateEdit/diff.ts +82 -0
- package/src/identity/continuity/privateEdit/files.ts +23 -0
- package/src/identity/continuity/privateEdit/types.ts +28 -0
- package/src/identity/continuity/privateEdit.ts +10 -298
- package/src/identity/continuity/publicSkills.ts +8 -9
- package/src/identity/continuity/snapshots.ts +17 -6
- package/src/identity/continuity/storage/defaults.ts +111 -0
- package/src/identity/continuity/storage/files.ts +72 -0
- package/src/identity/continuity/storage/markdown.ts +81 -0
- package/src/identity/continuity/storage/paths.ts +24 -0
- package/src/identity/continuity/storage/scaffold.ts +124 -0
- package/src/identity/continuity/storage/status.ts +86 -0
- package/src/identity/continuity/storage/types.ts +27 -0
- package/src/identity/continuity/storage.ts +32 -507
- package/src/identity/continuity/zipWriter.ts +95 -0
- package/src/identity/crypto/backupEnvelope.ts +14 -247
- package/src/identity/crypto/eth.ts +7 -7
- package/src/identity/ens/agentRecords.ts +96 -0
- package/src/identity/ens/ensAutomation/contracts.ts +38 -0
- package/src/identity/ens/ensAutomation/delete.ts +80 -0
- package/src/identity/ens/ensAutomation/names.ts +14 -0
- package/src/identity/ens/ensAutomation/operators.ts +29 -0
- package/src/identity/ens/ensAutomation/read.ts +114 -0
- package/src/identity/ens/ensAutomation/root.ts +63 -0
- package/src/identity/ens/ensAutomation/setup.ts +284 -0
- package/src/identity/ens/ensAutomation/transactions.ts +107 -0
- package/src/identity/ens/ensAutomation/types.ts +126 -0
- package/src/identity/ens/ensAutomation.ts +29 -0
- package/src/identity/ens/ensLookup/client.ts +43 -0
- package/src/identity/ens/ensLookup/constants.ts +26 -0
- package/src/identity/ens/ensLookup/discovery.ts +70 -0
- package/src/identity/ens/ensLookup/names.ts +34 -0
- package/src/identity/ens/ensLookup/records.ts +45 -0
- package/src/identity/ens/ensLookup/resolve.ts +75 -0
- package/src/identity/ens/ensLookup/tokenReference.ts +17 -0
- package/src/identity/ens/ensLookup/types.ts +38 -0
- package/src/identity/ens/ensLookup/validation.ts +72 -0
- package/src/identity/ens/ensLookup.ts +19 -0
- package/src/identity/ens/ensRegistration.ts +199 -0
- package/src/identity/ens/resolverDelegation.ts +48 -0
- package/src/identity/hub/IdentityHub.tsx +13 -817
- package/src/identity/hub/OperationalRoutes.tsx +370 -0
- package/src/identity/hub/Routes.tsx +361 -0
- package/src/identity/hub/advancedEnsValidation.ts +45 -0
- package/src/identity/hub/{screens → components}/DetailsScreen.tsx +14 -8
- package/src/identity/hub/{screens → components}/ErrorScreen.tsx +15 -5
- package/src/identity/hub/components/FlowTimeline.tsx +27 -0
- package/src/identity/hub/components/IdentitySummary.tsx +190 -0
- package/src/identity/hub/components/MenuScreen.tsx +237 -0
- package/src/identity/hub/{screens → components}/NetworkScreen.tsx +3 -3
- package/src/identity/hub/{screens/RebackupStorageScreen.tsx → components/PinataJwtInput.tsx} +21 -18
- package/src/identity/hub/components/UnlinkedIdentityScreen.tsx +76 -0
- package/src/identity/hub/{screens → components}/WalletApprovalScreen.tsx +9 -8
- package/src/identity/hub/components/menuFlagsFromReconciliation.ts +68 -0
- package/src/identity/hub/effects/create.ts +310 -0
- package/src/identity/hub/effects/ens/flows.ts +218 -0
- package/src/identity/hub/effects/ens/index.ts +11 -0
- package/src/identity/hub/effects/ens/transactions.ts +239 -0
- package/src/identity/hub/effects/index.ts +74 -0
- package/src/identity/hub/effects/profile/profileState.ts +173 -0
- package/src/identity/hub/effects/publicProfile/index.ts +5 -0
- package/src/identity/hub/effects/publicProfile/runPublicProfileSave.ts +646 -0
- package/src/identity/hub/effects/rebackup/index.ts +7 -0
- package/src/identity/hub/effects/rebackup/operatorVault.ts +378 -0
- package/src/identity/hub/effects/rebackup/runRebackup.ts +451 -0
- package/src/identity/hub/effects/receipts.ts +46 -0
- package/src/identity/hub/effects/restore/apply.ts +112 -0
- package/src/identity/hub/effects/restore/auth.ts +159 -0
- package/src/identity/hub/effects/restore/discover.ts +86 -0
- package/src/identity/hub/effects/restore/envelopes.ts +21 -0
- package/src/identity/hub/effects/restore/fetch.ts +25 -0
- package/src/identity/hub/effects/restore/index.ts +22 -0
- package/src/identity/hub/effects/restore/recovery.ts +135 -0
- package/src/identity/hub/effects/restore/resolve.ts +102 -0
- package/src/identity/hub/effects/restore/restoreEffects.ts +22 -0
- package/src/identity/hub/effects/restore/shared.ts +91 -0
- package/src/identity/hub/effects/restoreAdmin.ts +93 -0
- package/src/identity/hub/effects/shared/profilePrep.ts +139 -0
- package/src/identity/hub/effects/shared/snapshot.ts +336 -0
- package/src/identity/hub/effects/shared/sync.ts +190 -0
- package/src/identity/hub/effects/token-transfer/index.ts +6 -0
- package/src/identity/hub/effects/token-transfer/progress.ts +59 -0
- package/src/identity/hub/effects/token-transfer/runTokenTransfer.ts +299 -0
- package/src/identity/hub/effects/types.ts +53 -0
- package/src/identity/hub/effects/vault/preflight.ts +50 -0
- package/src/identity/hub/flows/continuity/ContinuityDashboardScreen.tsx +170 -0
- package/src/identity/hub/flows/continuity/RebackupStorageScreen.tsx +28 -0
- package/src/identity/hub/{screens → flows/continuity}/RecoveryConfirmScreen.tsx +28 -19
- package/src/identity/hub/flows/continuity/SavePromptScreen.tsx +49 -0
- package/src/identity/hub/{screens → flows/create}/CreateFlow.tsx +61 -62
- package/src/identity/hub/flows/custody/CustodyEditFlow.tsx +347 -0
- package/src/identity/hub/flows/custody/custodyEffects.ts +321 -0
- package/src/identity/hub/flows/custody/custodyFlowActions.ts +236 -0
- package/src/identity/hub/flows/custody/custodyFlowEffects.ts +163 -0
- package/src/identity/hub/flows/custody/custodyFlowHelpers.ts +25 -0
- package/src/identity/hub/flows/custody/custodyFlowRoutes.tsx +239 -0
- package/src/identity/hub/flows/custody/custodyFlowTypes.ts +45 -0
- package/src/identity/hub/flows/custody/useCustodyFlow.tsx +25 -0
- package/src/identity/hub/flows/ens/EnsEditAdvancedScreens.tsx +336 -0
- package/src/identity/hub/flows/ens/EnsEditFlow.tsx +397 -0
- package/src/identity/hub/flows/ens/EnsEditMaintenanceScreens.tsx +332 -0
- package/src/identity/hub/flows/ens/EnsEditReviewScreens.tsx +471 -0
- package/src/identity/hub/flows/ens/EnsEditRunners.tsx +198 -0
- package/src/identity/hub/flows/ens/EnsEditShared.tsx +162 -0
- package/src/identity/hub/flows/ens/EnsEditSimpleScreens.tsx +518 -0
- package/src/identity/hub/flows/ens/IdentityHubEnsFlow.tsx +299 -0
- package/src/identity/hub/flows/ens/OperatorWalletsScreen.tsx +398 -0
- package/src/identity/hub/flows/ens/ensEditCopy.ts +117 -0
- package/src/identity/hub/flows/ens/ensEditTypes.ts +91 -0
- package/src/identity/hub/flows/profile/EditProfileFlow.tsx +271 -0
- package/src/identity/hub/flows/restore/RestoreFlow.tsx +324 -0
- package/src/identity/hub/flows/restore/useRestoreFlowEffects.ts +77 -0
- package/src/identity/hub/{screens → flows/settings}/StorageCredentialScreen.tsx +23 -44
- package/src/identity/hub/flows/token-transfer/IdentityHubTokenTransferFlow.tsx +162 -0
- package/src/identity/hub/flows/token-transfer/TokenTransferScreens.tsx +256 -0
- package/src/identity/hub/identityHubReducer.ts +164 -99
- package/src/identity/hub/model/continuity.ts +94 -0
- package/src/identity/hub/model/copy.ts +35 -0
- package/src/identity/hub/model/custody.ts +54 -0
- package/src/identity/hub/model/ens.ts +49 -0
- package/src/identity/hub/model/errors.ts +140 -0
- package/src/identity/hub/model/format.ts +15 -0
- package/src/identity/hub/model/identity.ts +94 -0
- package/src/identity/hub/model/network.ts +32 -0
- package/src/identity/hub/model/transfer.ts +57 -0
- package/src/identity/hub/operatorWallets.ts +131 -0
- package/src/identity/hub/reconciliation/agentReconciliation/hook.ts +46 -0
- package/src/identity/hub/reconciliation/agentReconciliation/ownership.ts +129 -0
- package/src/identity/hub/reconciliation/agentReconciliation/run.ts +302 -0
- package/src/identity/hub/reconciliation/agentReconciliation/types.ts +17 -0
- package/src/identity/hub/reconciliation/index.ts +21 -0
- package/src/identity/hub/reconciliation/useAgentReconciliation.ts +10 -0
- package/src/identity/hub/reconciliation/walletSetup.ts +220 -0
- package/src/identity/hub/txGuard.ts +51 -0
- package/src/identity/hub/types.ts +17 -0
- package/src/identity/hub/useIdentityHubContinuity.ts +136 -0
- package/src/identity/hub/useIdentityHubController.ts +396 -0
- package/src/identity/hub/useIdentityHubSideEffects.ts +309 -0
- package/src/identity/hub/utils.ts +79 -0
- package/src/identity/identityCompat.ts +34 -0
- package/src/identity/profile/agentIcon.ts +61 -0
- package/src/identity/profile/imagePicker.ts +12 -12
- package/src/identity/registry/erc8004/abi.ts +14 -0
- package/src/identity/registry/erc8004/chains.ts +150 -0
- package/src/identity/registry/erc8004/client.ts +11 -0
- package/src/identity/registry/erc8004/discovery.ts +511 -0
- package/src/identity/registry/erc8004/metadata.ts +335 -0
- package/src/identity/registry/erc8004/ownership.ts +121 -0
- package/src/identity/registry/erc8004/preflight.ts +123 -0
- package/src/identity/registry/erc8004/transactions.ts +77 -0
- package/src/identity/registry/erc8004/types.ts +88 -0
- package/src/identity/registry/erc8004/uri.ts +59 -0
- package/src/identity/registry/erc8004/utils.ts +58 -0
- package/src/identity/registry/erc8004.ts +53 -1106
- package/src/identity/registry/fieldParsers.ts +28 -0
- package/src/identity/registry/operatorVault/bytecode.ts +98 -0
- package/src/identity/registry/operatorVault/constants.ts +38 -0
- package/src/identity/registry/operatorVault/read.ts +246 -0
- package/src/identity/registry/operatorVault/transactions.ts +81 -0
- package/src/identity/registry/operatorVault.ts +44 -0
- package/src/identity/storage/ipfs.ts +26 -24
- package/src/identity/wallet/browserWallet/gas.ts +41 -0
- package/src/identity/wallet/browserWallet/html.ts +106 -0
- package/src/identity/wallet/browserWallet/http.ts +28 -0
- package/src/identity/wallet/browserWallet/requestServer.ts +106 -0
- package/src/identity/wallet/browserWallet/requests.ts +191 -0
- package/src/identity/wallet/browserWallet/session.ts +325 -0
- package/src/identity/wallet/browserWallet/types.ts +192 -0
- package/src/identity/wallet/browserWallet/validation.ts +74 -0
- package/src/identity/wallet/browserWallet.ts +30 -393
- package/src/identity/wallet/page/constants.ts +5 -0
- package/src/identity/wallet/page/controller.ts +251 -0
- package/src/identity/wallet/page/copy.ts +340 -0
- package/src/identity/wallet/page/grainient.ts +278 -0
- package/src/identity/wallet/page/html.ts +28 -0
- package/src/identity/wallet/page/markup.ts +50 -0
- package/src/identity/wallet/page/state.ts +9 -0
- package/src/identity/wallet/page/styles/base.ts +259 -0
- package/src/identity/wallet/page/styles/components.ts +262 -0
- package/src/identity/wallet/page/styles/index.ts +5 -0
- package/src/identity/wallet/page/styles/responsive.ts +247 -0
- package/src/identity/wallet/page/types.ts +47 -0
- package/src/identity/wallet/page/view.ts +535 -0
- package/src/identity/wallet/page/walletProvider.ts +70 -0
- package/src/identity/wallet/page.tsx +38 -0
- package/src/identity/wallet/walletPurposeCompat.ts +27 -0
- package/src/mcp/manager.ts +0 -1
- package/src/models/ModelPicker.tsx +36 -30
- package/src/models/catalog.ts +5 -2
- package/src/models/huggingface.ts +9 -9
- package/src/models/llamacpp.ts +13 -13
- package/src/models/modelDisplay.ts +75 -0
- package/src/models/modelPickerOptions.ts +16 -3
- package/src/models/modelRecommendation.ts +0 -1
- package/src/providers/errors.ts +16 -0
- package/src/providers/gemini.ts +252 -39
- package/src/providers/registry.ts +2 -2
- package/src/providers/retry.ts +1 -1
- package/src/runtime/sessionMode.ts +1 -1
- package/src/runtime/systemPrompt.ts +2 -0
- package/src/runtime/toolExecution.ts +18 -22
- package/src/runtime/toolIntent.ts +0 -20
- package/src/runtime/turn.ts +0 -92
- package/src/storage/atomicWrite.ts +4 -1
- package/src/storage/config.ts +181 -5
- package/src/storage/identity.ts +9 -3
- package/src/storage/secrets.ts +2 -2
- package/src/tools/bashSafety.ts +8 -0
- package/src/tools/changeDirectoryTool.ts +1 -1
- package/src/tools/deleteFileTool.ts +4 -4
- package/src/tools/editTool.ts +4 -4
- package/src/tools/editUtils.ts +5 -5
- package/src/tools/privateContinuityEditTool.ts +4 -5
- package/src/tools/privateContinuityReadTool.ts +1 -2
- package/src/tools/registry.ts +30 -0
- package/src/tools/writeFileTool.ts +5 -5
- package/src/ui/BrandSplash.tsx +20 -85
- package/src/ui/ProgressBar.tsx +3 -5
- package/src/ui/Select.tsx +20 -8
- package/src/ui/Spinner.tsx +38 -3
- package/src/ui/Surface.tsx +2 -2
- package/src/ui/TextInput.tsx +63 -20
- package/src/ui/theme.ts +7 -34
- package/src/utils/openExternal.ts +21 -0
- package/src/utils/withRetry.ts +47 -3
- package/src/identity/hub/identityHubEffects.ts +0 -937
- package/src/identity/hub/identityHubModel.ts +0 -371
- package/src/identity/hub/screens/ContinuityDashboardScreen.tsx +0 -156
- package/src/identity/hub/screens/EditProfileFlow.tsx +0 -146
- package/src/identity/hub/screens/IdentitySummary.tsx +0 -106
- package/src/identity/hub/screens/MenuScreen.tsx +0 -117
- package/src/identity/hub/screens/RestoreFlow.tsx +0 -206
- package/src/identity/wallet/wallet-page/wallet.html +0 -1202
- /package/src/identity/hub/{screens → components}/BusyScreen.tsx +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Address, PublicClient } from 'viem'
|
|
2
|
+
import type { TransferSnapshotMetadata } from '../../../storage/config.js'
|
|
3
|
+
import type { WalletContinuityRestoreAccessKey } from '../../continuity/envelope.js'
|
|
4
|
+
|
|
5
|
+
export type FetchLike = typeof fetch
|
|
6
|
+
|
|
7
|
+
export type Erc8004RegistryConfig = {
|
|
8
|
+
chainId: number
|
|
9
|
+
rpcUrl: string
|
|
10
|
+
identityRegistryAddress: Address
|
|
11
|
+
fromBlock?: bigint
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type EthagentBackupPointer = {
|
|
15
|
+
cid: string
|
|
16
|
+
envelopeVersion?: string
|
|
17
|
+
createdAt?: string
|
|
18
|
+
agentAddress?: Address
|
|
19
|
+
transferSnapshot?: TransferSnapshotMetadata
|
|
20
|
+
pastBackups?: Array<{ cid: string; createdAt?: string }>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type EthagentPublicDiscoveryPointer = {
|
|
24
|
+
skillsCid?: string
|
|
25
|
+
agentCardCid?: string
|
|
26
|
+
updatedAt?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type EthagentRegistrationPointer = {
|
|
30
|
+
chainId: number
|
|
31
|
+
identityRegistryAddress: Address
|
|
32
|
+
agentId?: string | number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type ApprovedOperatorWalletRecord = {
|
|
36
|
+
address: Address
|
|
37
|
+
challenge?: string
|
|
38
|
+
verifiedAt?: string
|
|
39
|
+
restoreAccessKey?: WalletContinuityRestoreAccessKey
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type EthagentOperatorsPointer = {
|
|
43
|
+
approvedOperatorWallets: ApprovedOperatorWalletRecord[]
|
|
44
|
+
activeOperatorAddress?: Address
|
|
45
|
+
ownerAddress?: Address
|
|
46
|
+
ensName?: string
|
|
47
|
+
restoreAccessEpoch?: number
|
|
48
|
+
ownerRestoreAccessKey?: WalletContinuityRestoreAccessKey
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type EthagentX402Pointer = {
|
|
52
|
+
walletAddress: Address
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type Erc8004AgentCandidate = {
|
|
56
|
+
tokenOwnerAddress?: Address
|
|
57
|
+
ownerAddress: Address
|
|
58
|
+
chainId: number
|
|
59
|
+
rpcUrl: string
|
|
60
|
+
identityRegistryAddress: Address
|
|
61
|
+
agentId: bigint
|
|
62
|
+
agentUri: string
|
|
63
|
+
metadataCid?: string
|
|
64
|
+
name?: string
|
|
65
|
+
description?: string
|
|
66
|
+
imageUrl?: string
|
|
67
|
+
backup?: EthagentBackupPointer
|
|
68
|
+
publicDiscovery?: EthagentPublicDiscoveryPointer
|
|
69
|
+
operators?: EthagentOperatorsPointer
|
|
70
|
+
registration: Record<string, unknown> | null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type DiscoverOwnedAgentsArgs = Erc8004RegistryConfig & {
|
|
74
|
+
ownerHandle: string
|
|
75
|
+
ipfsApiUrl?: string
|
|
76
|
+
publicClient?: PublicClient
|
|
77
|
+
fetchImpl?: FetchLike
|
|
78
|
+
signal?: AbortSignal
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type DiscoverOwnedAgentsAcrossSupportedNetworksArgs = {
|
|
82
|
+
ownerHandle: string
|
|
83
|
+
registryOverrides?: Erc8004RegistryConfig[]
|
|
84
|
+
ipfsApiUrl?: string
|
|
85
|
+
publicClients?: Partial<Record<number, PublicClient>>
|
|
86
|
+
fetchImpl?: FetchLike
|
|
87
|
+
signal?: AbortSignal
|
|
88
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { catFromIpfs, DEFAULT_IPFS_API_URL } from '../../storage/ipfs.js'
|
|
2
|
+
import type { FetchLike } from './types.js'
|
|
3
|
+
import { decodeDataUri, parseJsonObject } from './utils.js'
|
|
4
|
+
|
|
5
|
+
export async function loadAgentRegistration(
|
|
6
|
+
uri: string,
|
|
7
|
+
args: { ipfsApiUrl?: string; fetchImpl?: FetchLike; signal?: AbortSignal } = {},
|
|
8
|
+
): Promise<{ metadataCid?: string; registration: Record<string, unknown> }> {
|
|
9
|
+
const trimmed = uri.trim()
|
|
10
|
+
let raw: string
|
|
11
|
+
if (trimmed.startsWith('ipfs://')) {
|
|
12
|
+
const cid = cidFromUri(trimmed)
|
|
13
|
+
if (!cid) throw new Error('AgentURI is missing an IPFS CID')
|
|
14
|
+
raw = new TextDecoder().decode(await catFromIpfs(
|
|
15
|
+
args.ipfsApiUrl ?? DEFAULT_IPFS_API_URL,
|
|
16
|
+
cid,
|
|
17
|
+
args.fetchImpl,
|
|
18
|
+
args.signal ? { signal: args.signal } : {},
|
|
19
|
+
))
|
|
20
|
+
return { metadataCid: cid, registration: parseJsonObject(raw) }
|
|
21
|
+
}
|
|
22
|
+
if (trimmed.startsWith('data:')) {
|
|
23
|
+
return { registration: parseJsonObject(decodeDataUri(trimmed)) }
|
|
24
|
+
}
|
|
25
|
+
if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) {
|
|
26
|
+
const response = await (args.fetchImpl ?? fetch)(trimmed, args.signal ? { signal: args.signal } : {})
|
|
27
|
+
if (!response.ok) throw new Error('agent token URI fetch failed: ' + response.status + ' ' + response.statusText)
|
|
28
|
+
return { registration: parseJsonObject(await response.text()) }
|
|
29
|
+
}
|
|
30
|
+
throw new Error('Unsupported agentURI scheme')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function cidFromUri(uri: string): string | undefined {
|
|
34
|
+
if (!uri.startsWith('ipfs://')) return undefined
|
|
35
|
+
const withoutScheme = uri.slice('ipfs://'.length)
|
|
36
|
+
return withoutScheme.startsWith('ipfs/') ? withoutScheme.slice('ipfs/'.length) : withoutScheme
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function loadAgentRegistrationWithRetry(
|
|
40
|
+
agentUri: string,
|
|
41
|
+
args: { ipfsApiUrl?: string; fetchImpl?: FetchLike; signal?: AbortSignal },
|
|
42
|
+
attempts = 3,
|
|
43
|
+
): Promise<{ metadataCid?: string; registration: Record<string, unknown> }> {
|
|
44
|
+
let lastErr: unknown
|
|
45
|
+
for (let i = 0; i < attempts; i++) {
|
|
46
|
+
if (args.signal?.aborted) throw new DOMException('discovery cancelled', 'AbortError')
|
|
47
|
+
try {
|
|
48
|
+
return await loadAgentRegistration(agentUri, args)
|
|
49
|
+
} catch (err: unknown) {
|
|
50
|
+
if (args.signal?.aborted || (err instanceof Error && err.name === 'AbortError')) throw err
|
|
51
|
+
lastErr = err
|
|
52
|
+
if (i < attempts - 1) {
|
|
53
|
+
const backoffMs = (i + 1) * 500
|
|
54
|
+
await new Promise(r => setTimeout(r, backoffMs))
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
throw lastErr
|
|
59
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { formatEther } from 'viem'
|
|
2
|
+
|
|
3
|
+
export function uniqueStrings(values: string[]): string[] {
|
|
4
|
+
const out: string[] = []
|
|
5
|
+
for (const value of values) {
|
|
6
|
+
const normalized = value.trim().replace(/\/$/, '')
|
|
7
|
+
if (normalized && !out.includes(normalized)) out.push(normalized)
|
|
8
|
+
}
|
|
9
|
+
return out
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function cleanRpcError(err: unknown): string {
|
|
13
|
+
const message = err instanceof Error ? err.message : String(err)
|
|
14
|
+
return message
|
|
15
|
+
.replace(/s+/g, ' ')
|
|
16
|
+
.slice(0, 220)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function formatEthAmount(wei: bigint): string {
|
|
20
|
+
const [whole = '0', fraction = ''] = formatEther(wei).split('.')
|
|
21
|
+
const trimmedFraction = fraction.slice(0, 6).replace(/0+$/, '')
|
|
22
|
+
return trimmedFraction ? whole + '.' + trimmedFraction : whole
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseJsonObject(raw: string): Record<string, unknown> {
|
|
26
|
+
const parsed = JSON.parse(raw) as unknown
|
|
27
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
28
|
+
throw new Error('Agent token URI must resolve to a JSON object')
|
|
29
|
+
}
|
|
30
|
+
return parsed as Record<string, unknown>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function decodeDataUri(uri: string): string {
|
|
34
|
+
const comma = uri.indexOf(',')
|
|
35
|
+
if (comma === -1) throw new Error('Invalid data URI')
|
|
36
|
+
const meta = uri.slice(0, comma)
|
|
37
|
+
const body = uri.slice(comma + 1)
|
|
38
|
+
return meta.endsWith(';base64')
|
|
39
|
+
? Buffer.from(body, 'base64').toString('utf8')
|
|
40
|
+
: decodeURIComponent(body)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function mapWithConcurrency<input, output>(
|
|
44
|
+
inputs: input[],
|
|
45
|
+
concurrency: number,
|
|
46
|
+
mapper: (input: input) => Promise<output>,
|
|
47
|
+
): Promise<output[]> {
|
|
48
|
+
const out: output[] = new Array(inputs.length)
|
|
49
|
+
let next = 0
|
|
50
|
+
const workers = Array.from({ length: Math.min(concurrency, inputs.length) }, async () => {
|
|
51
|
+
while (next < inputs.length) {
|
|
52
|
+
const index = next++
|
|
53
|
+
out[index] = await mapper(inputs[index]!)
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
await Promise.all(workers)
|
|
57
|
+
return out
|
|
58
|
+
}
|