ethagent 1.1.1 → 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 +127 -29
- package/package.json +16 -9
- package/src/app/FirstRun.tsx +192 -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 +43 -18
- package/src/chat/ContextLimitView.tsx +4 -4
- package/src/chat/ContinuityEditReviewView.tsx +11 -17
- package/src/chat/ConversationStack.tsx +3 -0
- 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/TranscriptView.tsx +6 -0
- 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 +5 -3
- 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 -815
- 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/flows/continuity/RecoveryConfirmScreen.tsx +104 -0
- 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 +25 -43
- 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 +166 -101
- 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 +21 -9
- package/src/ui/Spinner.tsx +38 -3
- package/src/ui/Surface.tsx +3 -3
- package/src/ui/TextInput.tsx +191 -29
- 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 -291
- package/src/identity/hub/screens/ContinuityDashboardScreen.tsx +0 -144
- package/src/identity/hub/screens/EditProfileFlow.tsx +0 -145
- package/src/identity/hub/screens/IdentitySummary.tsx +0 -90
- package/src/identity/hub/screens/MenuScreen.tsx +0 -117
- package/src/identity/hub/screens/RecoveryConfirmScreen.tsx +0 -87
- 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
package/src/ui/TextInput.tsx
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import React, { useState } from 'react'
|
|
2
|
-
import { Box, Text } from 'ink'
|
|
1
|
+
import React, { useState, useRef, useEffect } from 'react'
|
|
2
|
+
import { Box, Text, useStdout } from 'ink'
|
|
3
3
|
import { theme } from './theme.js'
|
|
4
4
|
import { useAppInput } from '../app/input/AppInputProvider.js'
|
|
5
|
+
import { moveVerticalVisual } from '../chat/chatInputState.js'
|
|
6
|
+
import {
|
|
7
|
+
getVisualLineIndex,
|
|
8
|
+
getVisualLines,
|
|
9
|
+
} from '../chat/textCursor.js'
|
|
10
|
+
|
|
11
|
+
const DEFAULT_CHROME_WIDTH = 10
|
|
5
12
|
|
|
6
13
|
type TextInputProps = {
|
|
7
14
|
label?: string
|
|
@@ -9,10 +16,19 @@ type TextInputProps = {
|
|
|
9
16
|
isSecret?: boolean
|
|
10
17
|
initialValue?: string
|
|
11
18
|
allowEmpty?: boolean
|
|
19
|
+
multiline?: boolean
|
|
20
|
+
chromeWidth?: number
|
|
12
21
|
maxLength?: number
|
|
13
22
|
validate?: (value: string) => string | null
|
|
14
23
|
onSubmit: (value: string) => void
|
|
15
24
|
onCancel?: () => void
|
|
25
|
+
onNavigateLeft?: () => void
|
|
26
|
+
onNavigateRight?: (value: string) => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type RenderedTextInputLine = {
|
|
30
|
+
visualLineIndex: number
|
|
31
|
+
node: React.ReactNode
|
|
16
32
|
}
|
|
17
33
|
|
|
18
34
|
export function TextInput({
|
|
@@ -21,50 +37,126 @@ export function TextInput({
|
|
|
21
37
|
isSecret,
|
|
22
38
|
initialValue = '',
|
|
23
39
|
allowEmpty = false,
|
|
40
|
+
multiline = false,
|
|
41
|
+
chromeWidth = DEFAULT_CHROME_WIDTH,
|
|
24
42
|
maxLength = 4096,
|
|
25
43
|
validate,
|
|
26
44
|
onSubmit,
|
|
27
45
|
onCancel,
|
|
46
|
+
onNavigateLeft,
|
|
47
|
+
onNavigateRight,
|
|
28
48
|
}: TextInputProps) {
|
|
49
|
+
const { stdout } = useStdout()
|
|
29
50
|
const [value, setValue] = useState(initialValue)
|
|
51
|
+
const [cursor, setCursor] = useState(initialValue.length)
|
|
52
|
+
const [preferredColumn, setPreferredColumn] = useState<number | null>(null)
|
|
30
53
|
const [error, setError] = useState<string | null>(null)
|
|
31
54
|
|
|
55
|
+
const [columns, setColumns] = useState<number>(() => Math.floor(stdout?.columns ?? 80))
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!stdout) return
|
|
58
|
+
const handleResize = () => setColumns(Math.floor(stdout.columns ?? 80))
|
|
59
|
+
stdout.on('resize', handleResize)
|
|
60
|
+
return () => { stdout.off('resize', handleResize) }
|
|
61
|
+
}, [stdout])
|
|
62
|
+
|
|
63
|
+
const wrapWidth = textInputWrapWidth(columns, chromeWidth)
|
|
64
|
+
|
|
65
|
+
const stateRef = useRef({ value, cursor, preferredColumn, wrapWidth })
|
|
66
|
+
stateRef.current = { value, cursor, preferredColumn, wrapWidth }
|
|
67
|
+
|
|
32
68
|
useAppInput((input, key) => {
|
|
33
|
-
|
|
34
|
-
|
|
69
|
+
const { value: val, cursor: cur, preferredColumn: prefCol, wrapWidth: ww } = stateRef.current
|
|
70
|
+
|
|
71
|
+
const submitValue = (submit: (value: string) => void) => {
|
|
72
|
+
if (!allowEmpty && val.trim().length === 0) {
|
|
35
73
|
setError('value cannot be empty')
|
|
36
|
-
return
|
|
74
|
+
return false
|
|
37
75
|
}
|
|
38
|
-
const validationError = validate?.(
|
|
76
|
+
const validationError = validate?.(val) ?? null
|
|
39
77
|
if (validationError) {
|
|
40
78
|
setError(validationError)
|
|
41
|
-
return
|
|
79
|
+
return false
|
|
42
80
|
}
|
|
43
81
|
setError(null)
|
|
44
|
-
|
|
82
|
+
submit(val)
|
|
83
|
+
return true
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (multiline && isTextInputSoftBreak(key)) {
|
|
87
|
+
const next = insertTextInputText(val, cur, '\n', maxLength)
|
|
88
|
+
setValue(next.value)
|
|
89
|
+
setCursor(next.cursor)
|
|
90
|
+
setPreferredColumn(null)
|
|
91
|
+
if (error) setError(null)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
if (key.return) {
|
|
95
|
+
submitValue(onSubmit)
|
|
45
96
|
return
|
|
46
97
|
}
|
|
47
|
-
if (key.escape) {
|
|
98
|
+
if (key.escape || (key.ctrl && input === 'c')) {
|
|
48
99
|
onCancel?.()
|
|
49
100
|
return
|
|
50
101
|
}
|
|
102
|
+
if (key.leftArrow) {
|
|
103
|
+
if (onNavigateLeft && cur === 0) {
|
|
104
|
+
onNavigateLeft()
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
setCursor(Math.max(0, cur - 1))
|
|
108
|
+
setPreferredColumn(null)
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
if (key.rightArrow) {
|
|
112
|
+
if (onNavigateRight && cur === val.length) {
|
|
113
|
+
submitValue(onNavigateRight)
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
setCursor(Math.min(val.length, cur + 1))
|
|
117
|
+
setPreferredColumn(null)
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
if (multiline && (key.upArrow || key.downArrow)) {
|
|
121
|
+
const result = moveVerticalVisual(val, cur, key.upArrow ? -1 : 1, ww, prefCol)
|
|
122
|
+
if (result.kind === 'moved') setCursor(result.cursor)
|
|
123
|
+
setPreferredColumn(result.preferredColumn)
|
|
124
|
+
return
|
|
125
|
+
}
|
|
51
126
|
if (key.backspace || key.delete) {
|
|
52
|
-
|
|
127
|
+
if (cur === 0) return
|
|
128
|
+
setValue(val.slice(0, cur - 1) + val.slice(cur))
|
|
129
|
+
setCursor(cur - 1)
|
|
130
|
+
setPreferredColumn(null)
|
|
53
131
|
if (error) setError(null)
|
|
54
132
|
return
|
|
55
133
|
}
|
|
56
134
|
if (key.ctrl && input === 'u') {
|
|
57
|
-
|
|
135
|
+
const lineStart = val.lastIndexOf('\n', cur - 1) + 1
|
|
136
|
+
if (lineStart === cur) {
|
|
137
|
+
if (!multiline || cur === 0) return
|
|
138
|
+
setValue(val.slice(0, cur - 1) + val.slice(cur))
|
|
139
|
+
setCursor(cur - 1)
|
|
140
|
+
} else {
|
|
141
|
+
setValue(val.slice(0, lineStart) + val.slice(cur))
|
|
142
|
+
setCursor(lineStart)
|
|
143
|
+
}
|
|
144
|
+
setPreferredColumn(null)
|
|
58
145
|
if (error) setError(null)
|
|
59
146
|
return
|
|
60
147
|
}
|
|
61
|
-
if (key.ctrl || key.meta || key.
|
|
148
|
+
if (key.ctrl || key.meta || key.upArrow || key.downArrow || key.tab) {
|
|
62
149
|
return
|
|
63
150
|
}
|
|
64
151
|
if (input) {
|
|
65
|
-
const clean =
|
|
152
|
+
const clean = multiline
|
|
153
|
+
? input.replace(/\r\n/g, '\n').replace(/\r/g, '\n')
|
|
154
|
+
: input.replace(/[\r\n]/g, '')
|
|
66
155
|
if (clean) {
|
|
67
|
-
|
|
156
|
+
const next = insertTextInputText(val, cur, clean, maxLength)
|
|
157
|
+
setValue(next.value)
|
|
158
|
+
setCursor(next.cursor)
|
|
159
|
+
setPreferredColumn(null)
|
|
68
160
|
if (error) setError(null)
|
|
69
161
|
}
|
|
70
162
|
}
|
|
@@ -72,26 +164,96 @@ export function TextInput({
|
|
|
72
164
|
|
|
73
165
|
const display = isSecret ? '*'.repeat(value.length) : value
|
|
74
166
|
const showPlaceholder = value.length === 0 && placeholder
|
|
167
|
+
const renderedLines = multiline
|
|
168
|
+
? renderTextInputLines(display, cursor, true, wrapWidth)
|
|
169
|
+
: []
|
|
75
170
|
|
|
76
171
|
return (
|
|
77
172
|
<Box flexDirection="column">
|
|
78
173
|
{label ? <Text color={theme.dim}>{label}</Text> : null}
|
|
79
|
-
|
|
80
|
-
<
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
174
|
+
{multiline && !showPlaceholder ? (
|
|
175
|
+
<Box flexDirection="column">
|
|
176
|
+
{renderedLines.map(line => (
|
|
177
|
+
<Box key={line.visualLineIndex} flexDirection="row">
|
|
178
|
+
<Text color={line.visualLineIndex === 0 ? theme.accentPeriwinkle : theme.dim}>
|
|
179
|
+
{line.visualLineIndex === 0 ? '> ' : ' '}
|
|
180
|
+
</Text>
|
|
181
|
+
<Box width={wrapWidth}>{line.node}</Box>
|
|
182
|
+
</Box>
|
|
183
|
+
))}
|
|
184
|
+
</Box>
|
|
185
|
+
) : (
|
|
186
|
+
<Box flexDirection="row">
|
|
187
|
+
<Text color={theme.accentPeriwinkle}>{'> '}</Text>
|
|
188
|
+
<Box width={wrapWidth}>
|
|
189
|
+
{showPlaceholder ? (
|
|
190
|
+
<Text wrap={multiline ? 'wrap' : 'truncate-end'}>
|
|
191
|
+
<Text backgroundColor={theme.accentPeriwinkle} color="#0c0c1f">{' '}</Text>
|
|
192
|
+
<Text color={theme.dim}>{placeholder}</Text>
|
|
193
|
+
</Text>
|
|
194
|
+
) : (
|
|
195
|
+
<Text color={theme.text} wrap="truncate-end">
|
|
196
|
+
{display.slice(0, cursor)}
|
|
197
|
+
<Text backgroundColor={theme.accentPeriwinkle} color="#0c0c1f">{display[cursor] ?? ' '}</Text>
|
|
198
|
+
{display.slice(cursor + 1)}
|
|
199
|
+
</Text>
|
|
200
|
+
)}
|
|
201
|
+
</Box>
|
|
202
|
+
</Box>
|
|
203
|
+
)}
|
|
204
|
+
{error ? <Text color={theme.accentError}>{error}</Text> : null}
|
|
94
205
|
</Box>
|
|
95
206
|
)
|
|
96
207
|
}
|
|
97
208
|
|
|
209
|
+
export function textInputWrapWidth(columns: number, chromeWidth = DEFAULT_CHROME_WIDTH): number {
|
|
210
|
+
return Math.max(1, Math.floor(columns) - Math.max(0, Math.floor(chromeWidth)))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function insertTextInputText(value: string, cursor: number, input: string, maxLength = 4096): { value: string; cursor: number } {
|
|
214
|
+
const cleanCursor = Math.max(0, Math.min(cursor, value.length))
|
|
215
|
+
const next = (value.slice(0, cleanCursor) + input + value.slice(cleanCursor)).slice(0, maxLength)
|
|
216
|
+
return {
|
|
217
|
+
value: next,
|
|
218
|
+
cursor: Math.min(cleanCursor + input.length, next.length),
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function isTextInputSoftBreak(key: { return: boolean; shift?: boolean; meta?: boolean }): boolean {
|
|
223
|
+
return key.return && Boolean(key.shift || key.meta)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function renderTextInputLines(
|
|
227
|
+
value: string,
|
|
228
|
+
cursor: number,
|
|
229
|
+
showCursor: boolean,
|
|
230
|
+
wrapWidth: number,
|
|
231
|
+
): RenderedTextInputLine[] {
|
|
232
|
+
const lines = getVisualLines(value, wrapWidth)
|
|
233
|
+
const cursorLine = getVisualLineIndex(lines, cursor)
|
|
234
|
+
|
|
235
|
+
return lines.map((line, visualLineIndex) => {
|
|
236
|
+
const text = value.slice(line.start, line.end)
|
|
237
|
+
if (!showCursor || visualLineIndex !== cursorLine) {
|
|
238
|
+
return {
|
|
239
|
+
visualLineIndex,
|
|
240
|
+
node: <Text color={theme.text} wrap="wrap">{text || ' '}</Text>,
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const column = Math.max(0, Math.min(cursor - line.start, text.length))
|
|
245
|
+
const before = text.slice(0, column)
|
|
246
|
+
const atChar = text[column] ?? ' '
|
|
247
|
+
const after = text.slice(column + 1)
|
|
248
|
+
return {
|
|
249
|
+
visualLineIndex,
|
|
250
|
+
node: (
|
|
251
|
+
<Text color={theme.text} wrap="wrap">
|
|
252
|
+
{before}
|
|
253
|
+
<Text backgroundColor={theme.accentPeriwinkle} color="#0c0c1f">{atChar}</Text>
|
|
254
|
+
{after}
|
|
255
|
+
</Text>
|
|
256
|
+
),
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
}
|
package/src/ui/theme.ts
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
export const palette: Array<[number, number, number]> = [
|
|
2
2
|
[0xff, 0xff, 0xff],
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
6
|
-
[0xe7, 0xf4, 0xec],
|
|
3
|
+
[0xd8, 0xdc, 0xfa],
|
|
4
|
+
[0xe8, 0xee, 0xfd],
|
|
5
|
+
[0xd8, 0xdc, 0xfa],
|
|
7
6
|
[0xff, 0xff, 0xff],
|
|
8
7
|
]
|
|
9
8
|
|
|
10
|
-
export const eyePalette: Array<[number, number, number]> = [
|
|
11
|
-
[0xf5, 0xd8, 0xd8],
|
|
12
|
-
[0xf5, 0xe7, 0xcf],
|
|
13
|
-
[0xf5, 0xf0, 0xd4],
|
|
14
|
-
[0xd4, 0xee, 0xdd],
|
|
15
|
-
[0xd4, 0xe6, 0xf5],
|
|
16
|
-
] as const
|
|
17
|
-
|
|
18
9
|
export const theme = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
accentMint: '#e7f4ec',
|
|
24
|
-
accentPeach: '#e7cdb7',
|
|
25
|
-
accentLavender: '#d9cae8',
|
|
26
|
-
accentInfo: '#90b8e8',
|
|
10
|
+
accentPeriwinkle: '#d8dcfa',
|
|
11
|
+
accentBlue: '#e8eefd',
|
|
12
|
+
accentWhite: '#f5f8ff',
|
|
13
|
+
accentError: '#d99898',
|
|
27
14
|
border: '#555555',
|
|
28
15
|
dim: '#777777',
|
|
29
16
|
text: '#f1f1f1',
|
|
@@ -43,17 +30,3 @@ export function gradientColor(t: number): string {
|
|
|
43
30
|
const b = Math.round(b1 + (b2 - b1) * f)
|
|
44
31
|
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`
|
|
45
32
|
}
|
|
46
|
-
|
|
47
|
-
export function eyeGradientColor(t: number): string {
|
|
48
|
-
const s = Math.max(0, Math.min(1, t)) * (eyePalette.length - 1)
|
|
49
|
-
const i = Math.min(Math.floor(s), eyePalette.length - 2)
|
|
50
|
-
const f = s - i
|
|
51
|
-
const lo = eyePalette[i] ?? eyePalette[0]!
|
|
52
|
-
const hi = eyePalette[i + 1] ?? eyePalette[eyePalette.length - 1]!
|
|
53
|
-
const [r1, g1, b1] = lo
|
|
54
|
-
const [r2, g2, b2] = hi
|
|
55
|
-
const r = Math.round(r1 + (r2 - r1) * f)
|
|
56
|
-
const g = Math.round(g1 + (g2 - g1) * f)
|
|
57
|
-
const b = Math.round(b1 + (b2 - b1) * f)
|
|
58
|
-
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`
|
|
59
|
-
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
|
|
3
|
+
export function openExternalUrl(url: string): void {
|
|
4
|
+
const target = url.trim()
|
|
5
|
+
if (!target) return
|
|
6
|
+
const command = process.platform === 'win32'
|
|
7
|
+
? 'cmd'
|
|
8
|
+
: process.platform === 'darwin'
|
|
9
|
+
? 'open'
|
|
10
|
+
: 'xdg-open'
|
|
11
|
+
const args = process.platform === 'win32'
|
|
12
|
+
? ['/c', 'start', '', target]
|
|
13
|
+
: [target]
|
|
14
|
+
const child = spawn(command, args, {
|
|
15
|
+
detached: true,
|
|
16
|
+
stdio: 'ignore',
|
|
17
|
+
windowsHide: true,
|
|
18
|
+
})
|
|
19
|
+
child.on('error', () => {})
|
|
20
|
+
child.unref()
|
|
21
|
+
}
|
package/src/utils/withRetry.ts
CHANGED
|
@@ -6,6 +6,12 @@ export type RetryClassification = {
|
|
|
6
6
|
code?: string
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
export type RetryBodyHint = {
|
|
10
|
+
retryAfterMs?: number
|
|
11
|
+
fatal?: boolean
|
|
12
|
+
reason?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
export type RetryPolicy = {
|
|
10
16
|
maxRetries: number
|
|
11
17
|
baseDelayMs: number
|
|
@@ -179,6 +185,7 @@ export type FetchWithRetryOptions = {
|
|
|
179
185
|
retryAfterCapMs?: number
|
|
180
186
|
jitterRatio?: number
|
|
181
187
|
rateLimitResetProvider?: RateLimitResetProvider
|
|
188
|
+
parseRetryHintFromBody?: (body: string) => RetryBodyHint | undefined
|
|
182
189
|
signal?: AbortSignal
|
|
183
190
|
fetchImpl?: typeof fetch
|
|
184
191
|
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>
|
|
@@ -205,10 +212,36 @@ export async function fetchWithRetry(
|
|
|
205
212
|
const response = await fetchImpl(input, { ...init, signal: options.signal })
|
|
206
213
|
if (response.ok) return response
|
|
207
214
|
|
|
208
|
-
|
|
209
|
-
|
|
215
|
+
let classification = classifyRetryableProviderResponse(response, now(), options.rateLimitResetProvider)
|
|
216
|
+
let bufferedResponse: Response | undefined
|
|
217
|
+
if (
|
|
218
|
+
classification.retryable
|
|
219
|
+
&& response.status === 429
|
|
220
|
+
&& options.parseRetryHintFromBody
|
|
221
|
+
) {
|
|
222
|
+
let bodyText = ''
|
|
223
|
+
try { bodyText = await response.text() } catch { /* ignore */ }
|
|
224
|
+
bufferedResponse = new Response(bodyText, {
|
|
225
|
+
status: response.status,
|
|
226
|
+
statusText: response.statusText,
|
|
227
|
+
headers: response.headers,
|
|
228
|
+
})
|
|
229
|
+
const hint = bodyText ? safeParseRetryHint(bodyText, options.parseRetryHintFromBody) : undefined
|
|
230
|
+
if (hint?.fatal) {
|
|
231
|
+
return bufferedResponse
|
|
232
|
+
}
|
|
233
|
+
if (hint?.retryAfterMs !== undefined) {
|
|
234
|
+
classification = { ...classification, retryAfterMs: hint.retryAfterMs }
|
|
235
|
+
}
|
|
236
|
+
if (hint?.reason) {
|
|
237
|
+
classification = { ...classification, reason: `${classification.reason} ${hint.reason}` }
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (!classification.retryable || attempt > policy.maxRetries) return bufferedResponse ?? response
|
|
210
241
|
|
|
211
|
-
|
|
242
|
+
if (!bufferedResponse) {
|
|
243
|
+
try { await response.body?.cancel() } catch { /* ignore */ }
|
|
244
|
+
}
|
|
212
245
|
const delayMs = computeBackoffMs(
|
|
213
246
|
attempt,
|
|
214
247
|
classification.retryAfterMs,
|
|
@@ -243,6 +276,17 @@ export async function fetchWithRetry(
|
|
|
243
276
|
throw lastError ?? new Error('fetchWithRetry exhausted')
|
|
244
277
|
}
|
|
245
278
|
|
|
279
|
+
function safeParseRetryHint(
|
|
280
|
+
body: string,
|
|
281
|
+
parser: (body: string) => RetryBodyHint | undefined,
|
|
282
|
+
): RetryBodyHint | undefined {
|
|
283
|
+
try {
|
|
284
|
+
return parser(body)
|
|
285
|
+
} catch {
|
|
286
|
+
return undefined
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
246
290
|
function retryEvent(
|
|
247
291
|
attempt: number,
|
|
248
292
|
maxRetries: number,
|