openany-cli-dev 0.0.0-stage → 0.1.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.
Files changed (73) hide show
  1. package/README.md +461 -2
  2. package/bin/openany.js +3 -0
  3. package/package.json +27 -4
  4. package/skills/openany/SKILL.md +347 -0
  5. package/skills/openany/SKILL.zh-CN.md +496 -0
  6. package/skills/openany-provider/SKILL.md +26 -0
  7. package/skills/openany-provider/SKILL.zh-CN.md +26 -0
  8. package/skills/openany-provider/references/apis.md +60 -0
  9. package/skills/openany-provider/references/application.md +49 -0
  10. package/skills/openany-provider/references/application.zh-CN.md +51 -0
  11. package/skills/openany-provider/references/auth.md +59 -0
  12. package/skills/openany-provider/references/connections.md +38 -0
  13. package/skills/openany-provider/references/connections.zh-CN.md +33 -0
  14. package/skills/openany-provider/references/imports.md +38 -0
  15. package/skills/openany-provider/references/imports.zh-CN.md +55 -0
  16. package/skills/openany-provider/references/listing.md +29 -0
  17. package/skills/openany-provider/references/login.md +58 -0
  18. package/skills/openany-provider/references/login.zh-CN.md +59 -0
  19. package/skills/openany-provider/references/model-import.zh-CN.md +12 -0
  20. package/skills/openany-provider/references/models.md +107 -0
  21. package/skills/openany-provider/references/publishing.md +83 -0
  22. package/skills/openany-provider/references/publishing.zh-CN.md +81 -0
  23. package/skills/openany-provider/references/reviews.md +22 -0
  24. package/skills/openany-provider/templates/api-metadata.json +27 -0
  25. package/skills/openany-provider/templates/bindings.json +1 -0
  26. package/skills/openany-provider/templates/models-v2.json +545 -0
  27. package/skills/openany-provider/templates/models.json +10 -0
  28. package/skills/openany-provider/templates/provider-agent-api-template.json +697 -0
  29. package/skills/openany-provider/templates/seller-agent-api-import-template.json +839 -0
  30. package/skills/openany-provider/templates/seller-registration.json +26 -0
  31. package/src/auth-recovery.js +179 -0
  32. package/src/auth.js +1001 -0
  33. package/src/catalog.js +306 -0
  34. package/src/cli.js +601 -0
  35. package/src/config.js +260 -0
  36. package/src/errors.js +53 -0
  37. package/src/http.js +237 -0
  38. package/src/model-curl.js +359 -0
  39. package/src/model-materials.js +58 -0
  40. package/src/model-request.js +402 -0
  41. package/src/model-validation.js +56 -0
  42. package/src/models.js +188 -0
  43. package/src/native/config-acl.ps1 +34 -0
  44. package/src/native/connection-macos.js +109 -0
  45. package/src/native/connection-windows.ps1 +98 -0
  46. package/src/native/setup-macos.js +72 -0
  47. package/src/native/setup-windows.ps1 +83 -0
  48. package/src/native-prompt.js +85 -0
  49. package/src/payment-signing.js +362 -0
  50. package/src/prompt.js +69 -0
  51. package/src/provider-api-import-v2.js +72 -0
  52. package/src/provider-apis.js +3 -0
  53. package/src/provider-client.js +153 -0
  54. package/src/provider-connections.js +152 -0
  55. package/src/provider-import-format.js +289 -0
  56. package/src/provider-imports.js +402 -0
  57. package/src/provider-json.js +49 -0
  58. package/src/provider-model-import-v2.js +61 -0
  59. package/src/provider-models.js +253 -0
  60. package/src/provider-profile.js +65 -0
  61. package/src/provider-reviews.js +61 -0
  62. package/src/provider-state.js +176 -0
  63. package/src/provider.js +75 -0
  64. package/src/setup.js +201 -0
  65. package/src/topups.js +845 -0
  66. package/src/vendor/provider-apply/market-taxonomy.mjs +22 -0
  67. package/src/vendor/provider-apply/provenance.json +8 -0
  68. package/src/vendor/provider-apply/registration.mjs +151 -0
  69. package/src/vendor/provider-import/api-categories.json +29 -0
  70. package/src/vendor/provider-import/api-fields.json +33 -0
  71. package/src/vendor/provider-import/model-fields.json +44 -0
  72. package/src/wallet.js +213 -0
  73. package/src/windows-permissions.js +22 -0
@@ -0,0 +1,109 @@
1
+ // JXA runs in the macOS osascript host; credentials leave only through the private pipe.
2
+ ObjC.import("Cocoa");
3
+
4
+ function run() {
5
+ var data = $.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile;
6
+ var text = $.NSString.alloc.initWithDataEncoding(data, $.NSUTF8StringEncoding);
7
+ var request = JSON.parse(ObjC.unwrap(text));
8
+ var app = $.NSApplication.sharedApplication;
9
+ app.setActivationPolicy($.NSApplicationActivationPolicyRegular);
10
+ var menu = $.NSMenu.alloc.initWithTitle($(""));
11
+ var editItem = $.NSMenuItem.alloc.initWithTitleActionKeyEquivalent($("编辑"), null, $(""));
12
+ var editMenu = $.NSMenu.alloc.initWithTitle($("编辑"));
13
+ [["剪切", "cut:", "x"], ["复制", "copy:", "c"], ["粘贴", "paste:", "v"], ["全选", "selectAll:", "a"]].forEach(function (entry) {
14
+ var item = $.NSMenuItem.alloc.initWithTitleActionKeyEquivalent($(entry[0]), entry[1], $(entry[2]));
15
+ item.keyEquivalentModifierMask = $.NSEventModifierFlagCommand;
16
+ editMenu.addItem(item);
17
+ });
18
+ editItem.submenu = editMenu;
19
+ menu.addItem(editItem);
20
+ app.mainMenu = menu;
21
+
22
+ var alert = $.NSAlert.alloc.init;
23
+ alert.messageText = $("Create OpenAny Provider Connection");
24
+ alert.informativeText = $(request.error || "连接信息将提交到 OpenAny。API Key 不会保存到本地或显示在命令输出中。");
25
+ alert.addButtonWithTitle($("创建连接"));
26
+ var cancel = alert.addButtonWithTitle($("取消"));
27
+ cancel.keyEquivalent = $("\u001b");
28
+ var view = $.NSView.alloc.initWithFrame($.NSMakeRect(0, 0, 480, 400));
29
+ function label(value, y) {
30
+ var field = $.NSTextField.labelWithString($(value));
31
+ field.font = $.NSFont.systemFontOfSize(14);
32
+ field.frame = $.NSMakeRect(0, y, 480, 24);
33
+ view.addSubview(field);
34
+ return field;
35
+ }
36
+ function input(title, y, hidden) {
37
+ var caption = label(title, y + 36);
38
+ var field = (hidden ? $.NSSecureTextField : $.NSTextField).alloc.initWithFrame($.NSMakeRect(0, y, 480, 32));
39
+ field.font = $.NSFont.systemFontOfSize(14);
40
+ view.addSubview(field);
41
+ return { field: field, caption: caption };
42
+ }
43
+ var name = input("连接名称", 332, false);
44
+ var baseUrl = input("Base URL(HTTP / HTTPS)", 252, false);
45
+ var authCaption = label("认证类型", 208);
46
+ var auth = $.NSPopUpButton.alloc.initWithFramePullsDown($.NSMakeRect(0, 172, 480, 32), false);
47
+ auth.font = $.NSFont.systemFontOfSize(14);
48
+ request.authTypes.forEach(function (type) { auth.addItemWithTitle($(type)); });
49
+ auth.selectItemWithTitle($("Authorization"));
50
+ view.addSubview(auth);
51
+ var param = input("认证参数名", 92, false);
52
+ var secret = input("API Key", 12, true);
53
+ function layoutFields() {
54
+ var type = ObjC.unwrap(auth.titleOfSelectedItem).toLowerCase();
55
+ var showParam = type === "query" || type === "path";
56
+ var showSecret = type !== "none";
57
+ var height = 240 + (showParam ? 80 : 0) + (showSecret ? 80 : 0);
58
+ view.frame = $.NSMakeRect(0, 0, 480, height);
59
+ name.field.frame = $.NSMakeRect(0, height - 68, 480, 32);
60
+ name.caption.frame = $.NSMakeRect(0, height - 32, 480, 24);
61
+ baseUrl.field.frame = $.NSMakeRect(0, height - 148, 480, 32);
62
+ baseUrl.caption.frame = $.NSMakeRect(0, height - 112, 480, 24);
63
+ auth.frame = $.NSMakeRect(0, height - 228, 480, 32);
64
+ authCaption.frame = $.NSMakeRect(0, height - 192, 480, 24);
65
+ param.field.hidden = param.caption.hidden = !showParam;
66
+ secret.field.hidden = secret.caption.hidden = !showSecret;
67
+ if (showParam) {
68
+ param.field.frame = $.NSMakeRect(0, height - 308, 480, 32);
69
+ param.caption.frame = $.NSMakeRect(0, height - 272, 480, 24);
70
+ }
71
+ if (showSecret) {
72
+ secret.field.frame = $.NSMakeRect(0, 12, 480, 32);
73
+ secret.caption.frame = $.NSMakeRect(0, 48, 480, 24);
74
+ }
75
+ alert.layout;
76
+ }
77
+ ObjC.registerSubclass({
78
+ name: "OpenAnyConnectionAuthHandler",
79
+ methods: {
80
+ "authChanged:": {
81
+ types: ["void", ["id"]],
82
+ implementation: function () { layoutFields(); },
83
+ },
84
+ },
85
+ });
86
+ var authHandler = $.OpenAnyConnectionAuthHandler.alloc.init;
87
+ auth.target = authHandler;
88
+ auth.action = "authChanged:";
89
+ alert.accessoryView = view;
90
+ layoutFields();
91
+ alert.window.level = $.NSFloatingWindowLevel;
92
+ app.activateIgnoringOtherApps(true);
93
+ alert.window.makeKeyAndOrderFront(null);
94
+ alert.window.initialFirstResponder = name.field;
95
+ var response = Number(alert.runModal);
96
+ var result = { cancelled: true };
97
+ if (response === Number($.NSAlertFirstButtonReturn)) {
98
+ var selectedType = ObjC.unwrap(auth.titleOfSelectedItem);
99
+ result = {
100
+ label: ObjC.unwrap(name.field.stringValue), baseUrl: ObjC.unwrap(baseUrl.field.stringValue),
101
+ authType: selectedType,
102
+ authParamName: ["query", "path"].includes(selectedType.toLowerCase()) ? ObjC.unwrap(param.field.stringValue) : "",
103
+ secret: selectedType.toLowerCase() === "none" ? "" : ObjC.unwrap(secret.field.stringValue),
104
+ };
105
+ }
106
+ secret.field.stringValue = $("");
107
+ var output = $(JSON.stringify(result) + "\n").dataUsingEncoding($.NSUTF8StringEncoding);
108
+ $.NSFileHandle.fileHandleWithStandardOutput.writeData(output);
109
+ }
@@ -0,0 +1,98 @@
1
+ # Connection metadata and credentials travel only through redirected pipes.
2
+ $ErrorActionPreference = 'Stop'
3
+ try {
4
+ [Console]::InputEncoding = [System.Text.UTF8Encoding]::new($false)
5
+ [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
6
+ $request = [Console]::ReadLine() | ConvertFrom-Json
7
+ Add-Type -AssemblyName System.Windows.Forms
8
+ Add-Type -AssemblyName System.Drawing
9
+ [System.Windows.Forms.Application]::EnableVisualStyles()
10
+ $form = New-Object System.Windows.Forms.Form
11
+ $form.Text = 'OpenAny - Create provider connection'
12
+ $form.ClientSize = New-Object System.Drawing.Size(520, 560)
13
+ $form.StartPosition = 'CenterScreen'
14
+ $form.TopMost = $true
15
+ $form.FormBorderStyle = 'FixedDialog'
16
+ $form.MaximizeBox = $false
17
+ $form.MinimizeBox = $false
18
+ $form.Font = New-Object System.Drawing.Font('Segoe UI', 12)
19
+ function Add-Label($text, $y) {
20
+ $label = New-Object System.Windows.Forms.Label
21
+ $label.Text = $text
22
+ $label.SetBounds(24, $y, 472, 28)
23
+ $form.Controls.Add($label)
24
+ return $label
25
+ }
26
+ function Add-Input($title, $y, $hidden, $maxLength) {
27
+ $caption = Add-Label $title ($y - 32)
28
+ $field = New-Object System.Windows.Forms.TextBox
29
+ $field.UseSystemPasswordChar = $hidden
30
+ $field.MaxLength = $maxLength
31
+ $field.SetBounds(24, $y, 472, 32)
32
+ $form.Controls.Add($field)
33
+ return @{ Caption = $caption; Field = $field }
34
+ }
35
+ $notice = New-Object System.Windows.Forms.Label
36
+ $notice.Text = if ($request.error) { $request.error } else { 'Submitted to OpenAny. API keys are never saved locally or printed in command output.' }
37
+ $notice.SetBounds(24, 16, 472, 64)
38
+ $form.Controls.Add($notice)
39
+ $nameInput = Add-Input 'Connection label' 112 $false 120
40
+ $urlInput = Add-Input 'Base URL (HTTP / HTTPS)' 192 $false 2048
41
+ [void](Add-Label 'Authentication type' 240)
42
+ $authInput = New-Object System.Windows.Forms.ComboBox
43
+ $authInput.DropDownStyle = 'DropDownList'
44
+ $authInput.SetBounds(24, 272, 472, 32)
45
+ foreach ($type in $request.authTypes) { [void]$authInput.Items.Add($type) }
46
+ $authInput.SelectedItem = 'Authorization'
47
+ $form.Controls.Add($authInput)
48
+ $paramInput = Add-Input 'Parameter name' 352 $false 2048
49
+ $secretInput = Add-Input 'API key' 432 $true 16384
50
+ $save = New-Object System.Windows.Forms.Button
51
+ $save.Text = 'Create connection'
52
+ $save.SetBounds(296, 508, 200, 36)
53
+ $save.DialogResult = [System.Windows.Forms.DialogResult]::OK
54
+ $form.Controls.Add($save)
55
+ $cancel = New-Object System.Windows.Forms.Button
56
+ $cancel.Text = 'Cancel'
57
+ $cancel.SetBounds(176, 508, 108, 36)
58
+ $cancel.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
59
+ $form.Controls.Add($cancel)
60
+ $updateFields = {
61
+ $type = [string]$authInput.SelectedItem
62
+ $showParam = $type -in @('query', 'path')
63
+ $showSecret = $type -ne 'none'
64
+ $paramInput.Caption.Visible = $showParam
65
+ $paramInput.Field.Visible = $showParam
66
+ $secretInput.Caption.Visible = $showSecret
67
+ $secretInput.Field.Visible = $showSecret
68
+ $height = 400 + $(if ($showParam) { 80 } else { 0 }) + $(if ($showSecret) { 80 } else { 0 })
69
+ $secretY = if ($showParam) { 432 } else { 352 }
70
+ $secretInput.Caption.Top = $secretY - 32
71
+ $secretInput.Field.Top = $secretY
72
+ $save.Top = $height - 52
73
+ $cancel.Top = $height - 52
74
+ $form.ClientSize = New-Object System.Drawing.Size(520, $height)
75
+ }
76
+ $authInput.Add_SelectedIndexChanged($updateFields)
77
+ & $updateFields
78
+ $form.AcceptButton = $save
79
+ $form.CancelButton = $cancel
80
+ $form.Add_Shown({ $form.BringToFront(); $form.Activate(); [void]$nameInput.Field.Focus() })
81
+ $response = $form.ShowDialog()
82
+ $result = @{ cancelled = $true }
83
+ if ($response -eq [System.Windows.Forms.DialogResult]::OK) {
84
+ $selectedType = [string]$authInput.SelectedItem
85
+ $result = @{
86
+ label = $nameInput.Field.Text; baseUrl = $urlInput.Field.Text
87
+ authType = $selectedType
88
+ authParamName = if ($selectedType -in @('query', 'path')) { $paramInput.Field.Text } else { '' }
89
+ secret = if ($selectedType -eq 'none') { '' } else { $secretInput.Field.Text }
90
+ }
91
+ }
92
+ $secretInput.Field.Clear()
93
+ $form.Dispose()
94
+ [Console]::Out.WriteLine(($result | ConvertTo-Json -Compress))
95
+ } catch {
96
+ [Console]::Error.WriteLine('Native connection dialog failed.')
97
+ exit 1
98
+ }
@@ -0,0 +1,72 @@
1
+ // JXA runs in the macOS system osascript host. Secret output is captured by the CLI.
2
+ ObjC.import("Cocoa");
3
+
4
+ function run() {
5
+ var data = $.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile;
6
+ var text = $.NSString.alloc.initWithDataEncoding(data, $.NSUTF8StringEncoding);
7
+ var request = JSON.parse(ObjC.unwrap(text));
8
+ var app = $.NSApplication.sharedApplication;
9
+ app.setActivationPolicy($.NSApplicationActivationPolicyRegular);
10
+ // osascript has no default Edit menu. Route standard shortcuts through
11
+ // the responder chain so text fields receive paste without reading clipboard data here.
12
+ var menu = $.NSMenu.alloc.initWithTitle($(""));
13
+ var editItem = $.NSMenuItem.alloc.initWithTitleActionKeyEquivalent($("编辑"), null, $(""));
14
+ var editMenu = $.NSMenu.alloc.initWithTitle($("编辑"));
15
+ [["剪切", "cut:", "x"], ["复制", "copy:", "c"], ["粘贴", "paste:", "v"], ["全选", "selectAll:", "a"]].forEach(function (entry) {
16
+ var item = $.NSMenuItem.alloc.initWithTitleActionKeyEquivalent($(entry[0]), entry[1], $(entry[2]));
17
+ item.keyEquivalentModifierMask = $.NSEventModifierFlagCommand;
18
+ editMenu.addItem(item);
19
+ });
20
+ editItem.submenu = editMenu;
21
+ menu.addItem(editItem);
22
+ app.mainMenu = menu;
23
+ var alert = $.NSAlert.alloc.init;
24
+ var confirm = request.mode === "confirm";
25
+ var wallet = request.mode === "wallet";
26
+ alert.messageText = $(confirm ? "确认钱包地址" : wallet ? "配置 OpenAny 钱包" : "配置 OpenAny API Key");
27
+ alert.informativeText = $(confirm
28
+ ? "请核对私钥推导出的地址及 Agent ID,确认后保存到本地。"
29
+ : (request.error || "凭据将保存到本机 OpenAny 配置。Agent 仅收到配置状态。"));
30
+ alert.addButtonWithTitle($(confirm ? "确认并保存" : wallet ? "核对地址" : "保存配置"));
31
+ var cancel = alert.addButtonWithTitle($("取消"));
32
+ cancel.keyEquivalent = $("\u001b");
33
+ var view = $.NSView.alloc.initWithFrame($.NSMakeRect(0, 0, 420, confirm ? 100 : 220));
34
+ function label(value, y) {
35
+ var field = $.NSTextField.labelWithString($(value));
36
+ field.font = $.NSFont.systemFontOfSize(14);
37
+ field.frame = $.NSMakeRect(0, y, 420, 24);
38
+ view.addSubview(field);
39
+ }
40
+ var name, secret;
41
+ if (confirm) {
42
+ label(request.address, 64);
43
+ label("Agent ID: " + request.agentId, 24);
44
+ } else {
45
+ label(wallet ? "Agent ID" : "密钥名称", 188);
46
+ name = $.NSTextField.alloc.initWithFrame($.NSMakeRect(0, 152, 420, 32));
47
+ name.font = $.NSFont.systemFontOfSize(14);
48
+ name.stringValue = $(wallet ? request.agentId : request.label);
49
+ view.addSubview(name);
50
+ label(wallet ? "钱包私钥(EVM / Solana)" : "API Key", 116);
51
+ secret = $.NSSecureTextField.alloc.initWithFrame($.NSMakeRect(0, 80, 420, 32));
52
+ secret.font = $.NSFont.systemFontOfSize(14);
53
+ view.addSubview(secret);
54
+
55
+ }
56
+ alert.accessoryView = view;
57
+ // Keep credential and address-confirmation dialogs above normal windows.
58
+ alert.window.level = $.NSFloatingWindowLevel;
59
+ app.activateIgnoringOtherApps(true);
60
+ alert.window.makeKeyAndOrderFront(null);
61
+ var response = Number(alert.runModal);
62
+ var result = { cancelled: true };
63
+ if (response === Number($.NSAlertFirstButtonReturn)) {
64
+ if (confirm) result = { confirmed: true };
65
+ else if (wallet) result = { agentId: ObjC.unwrap(name.stringValue), secret: ObjC.unwrap(secret.stringValue) };
66
+ else result = { label: ObjC.unwrap(name.stringValue), secret: ObjC.unwrap(secret.stringValue) };
67
+ }
68
+ if (secret) secret.stringValue = $("");
69
+ if (name) name.stringValue = $("");
70
+ var output = $(JSON.stringify(result) + "\n").dataUsingEncoding($.NSUTF8StringEncoding);
71
+ $.NSFileHandle.fileHandleWithStandardOutput.writeData(output);
72
+ }
@@ -0,0 +1,83 @@
1
+ # Input metadata and returned credentials travel only through redirected pipes.
2
+ $ErrorActionPreference = 'Stop'
3
+ try {
4
+ [Console]::InputEncoding = [System.Text.UTF8Encoding]::new($false)
5
+ [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
6
+ $request = [Console]::ReadLine() | ConvertFrom-Json
7
+ Add-Type -AssemblyName System.Windows.Forms
8
+ Add-Type -AssemblyName System.Drawing
9
+ [System.Windows.Forms.Application]::EnableVisualStyles()
10
+ $confirm = $request.mode -eq 'confirm'
11
+ $wallet = $request.mode -eq 'wallet'
12
+ $form = New-Object System.Windows.Forms.Form
13
+ $form.Text = if ($confirm) { 'OpenAny - Confirm wallet' } elseif ($wallet) { 'OpenAny - Wallet setup' } else { 'OpenAny - API key setup' }
14
+ $form.ClientSize = New-Object System.Drawing.Size(480, 360)
15
+ $form.StartPosition = 'CenterScreen'
16
+ $form.TopMost = $true
17
+ $form.FormBorderStyle = 'FixedDialog'
18
+ $form.MaximizeBox = $false
19
+ $form.MinimizeBox = $false
20
+ $form.Font = New-Object System.Drawing.Font('Segoe UI', 12)
21
+ function Add-Label($text, $y) {
22
+ $label = New-Object System.Windows.Forms.Label
23
+ $label.Text = $text
24
+ $label.SetBounds(24, $y, 432, 28)
25
+ $form.Controls.Add($label)
26
+ }
27
+ $notice = New-Object System.Windows.Forms.Label
28
+ $notice.Text = if ($request.error) { $request.error } else { 'Saved locally by OpenAny. The agent receives configuration status only.' }
29
+ $notice.SetBounds(24, 16, 432, 64)
30
+ $form.Controls.Add($notice)
31
+ if ($confirm) {
32
+ $notice.Text = 'Verify the derived wallet address before saving.'
33
+ Add-Label 'Wallet address' 96
34
+ $address = New-Object System.Windows.Forms.TextBox
35
+ $address.Text = $request.address
36
+ $address.ReadOnly = $true
37
+ $address.SetBounds(24, 128, 432, 32)
38
+ $form.Controls.Add($address)
39
+ Add-Label ('Agent ID: ' + $request.agentId) 180
40
+ } else {
41
+ Add-Label $(if ($wallet) { 'Agent ID' } else { 'Key label' }) 88
42
+ $nameInput = New-Object System.Windows.Forms.TextBox
43
+ $nameInput.Text = if ($wallet) { $request.agentId } else { $request.label }
44
+ $nameInput.MaxLength = 128
45
+ $nameInput.SetBounds(24, 120, 432, 32)
46
+ $form.Controls.Add($nameInput)
47
+ Add-Label $(if ($wallet) { 'Wallet private key (EVM / Solana)' } else { 'API key' }) 164
48
+ $secretInput = New-Object System.Windows.Forms.TextBox
49
+ $secretInput.UseSystemPasswordChar = $true
50
+ $secretInput.MaxLength = 4096
51
+ $secretInput.SetBounds(24, 196, 432, 32)
52
+ $form.Controls.Add($secretInput)
53
+
54
+ }
55
+ $save = New-Object System.Windows.Forms.Button
56
+ $save.Text = if ($confirm) { 'Confirm' } elseif ($wallet) { 'Review address' } else { 'Save' }
57
+ $save.SetBounds(288, 304, 168, 36)
58
+ $save.DialogResult = [System.Windows.Forms.DialogResult]::OK
59
+ $form.Controls.Add($save)
60
+ $cancel = New-Object System.Windows.Forms.Button
61
+ $cancel.Text = 'Cancel'
62
+ $cancel.SetBounds(168, 304, 108, 36)
63
+ $cancel.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
64
+ $form.Controls.Add($cancel)
65
+ $form.AcceptButton = $save
66
+ $form.CancelButton = $cancel
67
+ $form.Add_Shown({ $form.BringToFront(); $form.Activate() })
68
+ $response = $form.ShowDialog()
69
+ $result = @{ cancelled = $true }
70
+ if ($response -eq [System.Windows.Forms.DialogResult]::OK) {
71
+ if ($confirm) { $result = @{ confirmed = $true } }
72
+ elseif ($wallet) { $result = @{ agentId = $nameInput.Text; secret = $secretInput.Text } }
73
+ else { $result = @{ label = $nameInput.Text; secret = $secretInput.Text } }
74
+ }
75
+ if ($secretInput) { $secretInput.Clear() }
76
+ if ($nameInput) { $nameInput.Clear() }
77
+ $form.Dispose()
78
+ [Console]::Out.WriteLine(($result | ConvertTo-Json -Compress))
79
+ } catch {
80
+ # Fixed diagnostics prevent exception messages from reflecting user input.
81
+ [Console]::Error.WriteLine('Native setup failed.')
82
+ exit 1
83
+ }
@@ -0,0 +1,85 @@
1
+ import { spawn } from "node:child_process";
2
+ import { readFile } from "node:fs/promises";
3
+ import { fileURLToPath } from "node:url";
4
+ import { join } from "node:path";
5
+ import { CLIError } from "./errors.js";
6
+
7
+ export async function nativePrompt(request, { timeoutMs = 300_000 } = {}) {
8
+ const script = request.mode === "connection" ? "connection" : "setup";
9
+ if (process.platform === "darwin") {
10
+ return runNativeProcess("/usr/bin/osascript", [
11
+ "-l", "JavaScript", fileURLToPath(new URL(`./native/${script}-macos.js`, import.meta.url)),
12
+ ], request, { timeoutMs });
13
+ }
14
+ if (process.platform === "win32") {
15
+ const powershell = join(process.env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
16
+ return runNativeProcess(powershell, [
17
+ "-NoLogo", "-NoProfile", "-NonInteractive", "-STA", "-EncodedCommand",
18
+ await encodedPowerShell(new URL(`./native/${script}-windows.ps1`, import.meta.url)),
19
+ ], request, { timeoutMs });
20
+ }
21
+ throw new CLIError("GUI_UNAVAILABLE", "Native setup requires a macOS or Windows desktop. Run setup without --gui in your terminal.");
22
+ }
23
+
24
+ export function runNativeProcess(command, args, request, { timeoutMs = 300_000, spawnProcess = spawn } = {}) {
25
+ if (timeoutMs <= 0)
26
+ return Promise.reject(new CLIError("GUI_TIMEOUT", "Native setup timed out; nothing was saved."));
27
+ // The dialog does not need the caller's API keys, wallet keys, or runtime hooks.
28
+ const env = {};
29
+ for (const name of ["HOME", "USER", "LOGNAME", "PATH", "TMPDIR", "TEMP", "TMP", "SystemRoot", "WINDIR", "USERPROFILE", "LOCALAPPDATA"]) {
30
+ if (process.env[name]) env[name] = process.env[name];
31
+ }
32
+ return new Promise((resolve, reject) => {
33
+ const child = spawnProcess(command, args, { env, stdio: ["pipe", "pipe", "pipe"], windowsHide: true });
34
+ let output = "";
35
+ let size = 0;
36
+ let settled = false;
37
+ const finish = (error, result) => {
38
+ if (settled) return;
39
+ settled = true;
40
+ clearTimeout(timer);
41
+ process.removeListener("SIGINT", cancel);
42
+ process.removeListener("SIGTERM", cancel);
43
+ output = "";
44
+ if (error) { child.kill(); reject(error); }
45
+ else resolve(result);
46
+ };
47
+ const cancel = () => finish(new CLIError("CANCELLED", "Native setup cancelled; nothing was saved."));
48
+ const timer = setTimeout(() => finish(new CLIError("GUI_TIMEOUT", "Native setup timed out; nothing was saved.")), timeoutMs);
49
+ process.once("SIGINT", cancel);
50
+ process.once("SIGTERM", cancel);
51
+ child.on("error", () => finish(new CLIError("GUI_UNAVAILABLE", "Cannot open the native setup dialog. Run setup without --gui in your terminal.")));
52
+ child.stdin.on("error", () => finish(new CLIError("GUI_UNAVAILABLE", "The native setup dialog closed unexpectedly; nothing was saved.")));
53
+ child.stdout.setEncoding("utf8");
54
+ child.stdout.on("data", chunk => {
55
+ size += Buffer.byteLength(chunk);
56
+ if (size > 65536) finish(new CLIError("GUI_PROTOCOL_ERROR", "The native setup response was too large."));
57
+ else output += chunk.toString("utf8");
58
+ });
59
+ // Never forward raw helper diagnostics: they could contain entered values.
60
+ child.stderr.resume();
61
+ child.on("close", code => {
62
+ if (settled) return;
63
+ if (code !== 0) {
64
+ finish(new CLIError("GUI_UNAVAILABLE", "The native dialog failed. Check desktop availability and local script policy, or use terminal setup."));
65
+ return;
66
+ }
67
+ try {
68
+ const result = JSON.parse(output);
69
+ if (!result || typeof result !== "object" || Array.isArray(result)) throw new Error();
70
+ finish(null, result);
71
+ } catch {
72
+ finish(new CLIError("GUI_PROTOCOL_ERROR", "The native setup dialog returned an invalid response."));
73
+ }
74
+ });
75
+ // Only labels, IDs, derived public addresses, and fixed validation messages go to the UI.
76
+ child.stdin.end(JSON.stringify(request) + "\n");
77
+ });
78
+ }
79
+
80
+
81
+ // Execute bundled code as a command; leave the machine execution policy unchanged.
82
+ // No credential or user input is interpolated into this command.
83
+ export async function encodedPowerShell(url) {
84
+ return Buffer.from(await readFile(url, "utf8"), "utf16le").toString("base64");
85
+ }