@okxweb3/a2a-node 0.1.3 → 0.1.4-beta-520175e226-260702152522
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 +1332 -431
- package/dist/fix-windows-env.ps1 +339 -0
- package/dist/index.js +986 -286
- package/dist/install.ps1 +224 -0
- package/package.json +1 -1
package/dist/install.ps1
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# okx-a2a installer / updater (Windows)
|
|
2
|
+
#
|
|
3
|
+
# Usage:
|
|
4
|
+
# .\install.ps1
|
|
5
|
+
# .\install.ps1 .\okxweb3-a2a-node-0.1.1.tgz
|
|
6
|
+
# .\install.ps1 @okxweb3/a2a-node@latest
|
|
7
|
+
#
|
|
8
|
+
# Behavior:
|
|
9
|
+
# - Installs @okxweb3/a2a-node globally via npm.
|
|
10
|
+
# - Writes okx-a2a shims into %USERPROFILE%\.local\bin.
|
|
11
|
+
# - Adds %USERPROFILE%\.local\bin to the user's PATH, matching onchainos.
|
|
12
|
+
|
|
13
|
+
param(
|
|
14
|
+
[string]$Target = ""
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
$ErrorActionPreference = "Stop"
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
[Net.ServicePointManager]::SecurityProtocol = `
|
|
21
|
+
[Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
|
22
|
+
} catch {}
|
|
23
|
+
|
|
24
|
+
if (-not $env:USERPROFILE) {
|
|
25
|
+
throw "USERPROFILE is required to install okx-a2a on Windows."
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
$scriptPath = $MyInvocation.MyCommand.Path
|
|
29
|
+
$SCRIPT_DIR = if ($scriptPath) { Split-Path -Parent $scriptPath } else { "" }
|
|
30
|
+
$INSTALL_DIR = Join-Path $env:USERPROFILE ".local\bin"
|
|
31
|
+
$PACK_TMP = $null
|
|
32
|
+
|
|
33
|
+
function Resolve-ExternalCommand {
|
|
34
|
+
param([string[]]$Names)
|
|
35
|
+
|
|
36
|
+
foreach ($name in $Names) {
|
|
37
|
+
$command = Get-Command $name -ErrorAction SilentlyContinue
|
|
38
|
+
if ($command -and $command.Source) {
|
|
39
|
+
return $command.Source
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return $null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
$NPM_CMD = Resolve-ExternalCommand -Names @("npm.cmd", "npm")
|
|
46
|
+
if (-not $NPM_CMD) {
|
|
47
|
+
throw "npm is required to install okx-a2a globally."
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
$NODE_CMD = Resolve-ExternalCommand -Names @("node.exe", "node")
|
|
51
|
+
if (-not $NODE_CMD) {
|
|
52
|
+
throw "node is required to run okx-a2a."
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function Invoke-Checked {
|
|
56
|
+
param(
|
|
57
|
+
[string]$Command,
|
|
58
|
+
[string[]]$Arguments
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
& $Command @Arguments
|
|
62
|
+
if ($LASTEXITCODE -ne 0) {
|
|
63
|
+
throw "$Command $($Arguments -join ' ') exited with code $LASTEXITCODE"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function Invoke-CheckedCapture {
|
|
68
|
+
param(
|
|
69
|
+
[string]$Command,
|
|
70
|
+
[string[]]$Arguments
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
$output = & $Command @Arguments 2>&1
|
|
74
|
+
if ($LASTEXITCODE -ne 0) {
|
|
75
|
+
if ($output) {
|
|
76
|
+
$output | ForEach-Object { Write-Error $_ }
|
|
77
|
+
}
|
|
78
|
+
throw "$Command $($Arguments -join ' ') exited with code $LASTEXITCODE"
|
|
79
|
+
}
|
|
80
|
+
return @($output)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function New-PackSourceDir {
|
|
84
|
+
param([string]$SourceDir)
|
|
85
|
+
|
|
86
|
+
$script:PACK_TMP = Join-Path ([System.IO.Path]::GetTempPath()) ("okx-a2a-pack." + [System.Guid]::NewGuid().ToString("N"))
|
|
87
|
+
New-Item -ItemType Directory -Path $script:PACK_TMP -Force | Out-Null
|
|
88
|
+
|
|
89
|
+
Invoke-Checked -Command $script:NPM_CMD -Arguments @("--prefix", $SourceDir, "run", "build")
|
|
90
|
+
$packOutput = Invoke-CheckedCapture -Command $script:NPM_CMD -Arguments @("pack", $SourceDir, "--pack-destination", $script:PACK_TMP)
|
|
91
|
+
$tarballName = $packOutput | Where-Object { $_ -match '\S' } | Select-Object -Last 1
|
|
92
|
+
if (-not $tarballName -or $tarballName -notmatch '\.tgz$') {
|
|
93
|
+
throw "Unable to detect npm pack tarball from output: $($packOutput -join [Environment]::NewLine)"
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
$script:Target = Join-Path $script:PACK_TMP $tarballName
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function Install-RuntimeDeps {
|
|
100
|
+
param([string]$PackageDir)
|
|
101
|
+
|
|
102
|
+
Invoke-Checked -Command $script:NPM_CMD -Arguments @("--prefix", $PackageDir, "install", "--omit=dev")
|
|
103
|
+
$script:Target = $PackageDir
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function Get-GlobalPackageCliPath {
|
|
107
|
+
$npmRootOutput = Invoke-CheckedCapture -Command $script:NPM_CMD -Arguments @("root", "-g")
|
|
108
|
+
$npmRoot = ($npmRootOutput | Where-Object { $_ -match '\S' } | Select-Object -Last 1).Trim()
|
|
109
|
+
if (-not $npmRoot) {
|
|
110
|
+
throw "Unable to detect npm global node_modules directory."
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
$cliPath = Join-Path (Join-Path (Join-Path $npmRoot "@okxweb3") "a2a-node") "dist\cli.js"
|
|
114
|
+
if (-not (Test-Path $cliPath)) {
|
|
115
|
+
throw "okx-a2a was installed, but the CLI entry was not found at $cliPath"
|
|
116
|
+
}
|
|
117
|
+
return $cliPath
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function Write-LocalBinShims {
|
|
121
|
+
$cliPath = Get-GlobalPackageCliPath
|
|
122
|
+
|
|
123
|
+
if (-not (Test-Path $INSTALL_DIR)) {
|
|
124
|
+
New-Item -ItemType Directory -Path $INSTALL_DIR -Force | Out-Null
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
$cmdPath = Join-Path $INSTALL_DIR "okx-a2a.cmd"
|
|
128
|
+
$ps1Path = Join-Path $INSTALL_DIR "okx-a2a.ps1"
|
|
129
|
+
|
|
130
|
+
$cmdContent = @"
|
|
131
|
+
@ECHO off
|
|
132
|
+
SETLOCAL
|
|
133
|
+
IF NOT DEFINED APPDATA (
|
|
134
|
+
ECHO APPDATA is required to find the npm okx-a2a shim. >&2
|
|
135
|
+
EXIT /b 1
|
|
136
|
+
)
|
|
137
|
+
SET "OKX_A2A_NPM_CMD=%APPDATA%\npm\okx-a2a.cmd"
|
|
138
|
+
IF NOT EXIST "%OKX_A2A_NPM_CMD%" (
|
|
139
|
+
ECHO okx-a2a npm shim not found at "%OKX_A2A_NPM_CMD%" >&2
|
|
140
|
+
EXIT /b 1
|
|
141
|
+
)
|
|
142
|
+
CALL "%OKX_A2A_NPM_CMD%" %*
|
|
143
|
+
EXIT /b %ERRORLEVEL%
|
|
144
|
+
"@
|
|
145
|
+
Set-Content -Path $cmdPath -Value $cmdContent -Encoding ASCII
|
|
146
|
+
|
|
147
|
+
$psContent = @"
|
|
148
|
+
`$node = '$($NODE_CMD.Replace("'", "''"))'
|
|
149
|
+
`$cli = '$($cliPath.Replace("'", "''"))'
|
|
150
|
+
if (-not (Test-Path `$cli)) {
|
|
151
|
+
Write-Error "okx-a2a CLI entry not found at `$cli"
|
|
152
|
+
exit 1
|
|
153
|
+
}
|
|
154
|
+
& `$node `$cli @args
|
|
155
|
+
exit `$LASTEXITCODE
|
|
156
|
+
"@
|
|
157
|
+
Set-Content -Path $ps1Path -Value $psContent -Encoding UTF8
|
|
158
|
+
|
|
159
|
+
Write-Host "Installed okx-a2a shims to $INSTALL_DIR"
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function Add-ToPath {
|
|
163
|
+
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
|
164
|
+
$entries = @()
|
|
165
|
+
if ($userPath) {
|
|
166
|
+
$entries = @($userPath -split ";" | Where-Object { $_ })
|
|
167
|
+
}
|
|
168
|
+
$installDirNormalized = $INSTALL_DIR.TrimEnd([char]'\')
|
|
169
|
+
$alreadyPresent = $entries | Where-Object { $_.TrimEnd([char]'\') -ieq $installDirNormalized } | Select-Object -First 1
|
|
170
|
+
if ($alreadyPresent) {
|
|
171
|
+
$env:Path = "${INSTALL_DIR};${env:Path}"
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
$newPath = if ($userPath) { "${INSTALL_DIR};${userPath}" } else { $INSTALL_DIR }
|
|
176
|
+
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
|
|
177
|
+
$env:Path = "${INSTALL_DIR};${env:Path}"
|
|
178
|
+
|
|
179
|
+
Write-Host ""
|
|
180
|
+
Write-Host "Added $INSTALL_DIR to your user PATH."
|
|
181
|
+
Write-Host "Restart your terminal or run the following to use 'okx-a2a' now:"
|
|
182
|
+
Write-Host ""
|
|
183
|
+
Write-Host " `$env:Path = `"${INSTALL_DIR};`$env:Path`""
|
|
184
|
+
Write-Host ""
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
if (-not $Target) {
|
|
189
|
+
if ($SCRIPT_DIR -and (Test-Path (Join-Path $SCRIPT_DIR "scripts\build.mjs"))) {
|
|
190
|
+
New-PackSourceDir $SCRIPT_DIR
|
|
191
|
+
} elseif ($SCRIPT_DIR -and (Test-Path (Join-Path $SCRIPT_DIR "package.json"))) {
|
|
192
|
+
Install-RuntimeDeps $SCRIPT_DIR
|
|
193
|
+
} elseif ($SCRIPT_DIR) {
|
|
194
|
+
$localTarballs = @(Get-ChildItem -Path $SCRIPT_DIR -Filter "*.tgz" -File -ErrorAction SilentlyContinue)
|
|
195
|
+
if ($localTarballs.Count -eq 1) {
|
|
196
|
+
$Target = $localTarballs[0].FullName
|
|
197
|
+
} else {
|
|
198
|
+
$Target = "@okxweb3/a2a-node@latest"
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
$Target = "@okxweb3/a2a-node@latest"
|
|
202
|
+
}
|
|
203
|
+
} elseif ((Test-Path $Target -PathType Container) -and (Test-Path (Join-Path $Target "scripts\build.mjs"))) {
|
|
204
|
+
New-PackSourceDir $Target
|
|
205
|
+
} elseif ((Test-Path $Target -PathType Container) -and (Test-Path (Join-Path $Target "package.json"))) {
|
|
206
|
+
Install-RuntimeDeps $Target
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
Invoke-Checked -Command $NPM_CMD -Arguments @("install", "-g", $Target)
|
|
210
|
+
Write-LocalBinShims
|
|
211
|
+
Add-ToPath
|
|
212
|
+
|
|
213
|
+
$resolved = Get-Command okx-a2a -ErrorAction SilentlyContinue
|
|
214
|
+
if (-not $resolved) {
|
|
215
|
+
throw "okx-a2a was installed, but it is not on PATH. Add $INSTALL_DIR to PATH."
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
Write-Host "okx-a2a installed: $($resolved.Source)"
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
if ($PACK_TMP -and (Test-Path $PACK_TMP)) {
|
|
222
|
+
Remove-Item -Path $PACK_TMP -Recurse -Force -ErrorAction SilentlyContinue
|
|
223
|
+
}
|
|
224
|
+
}
|
package/package.json
CHANGED