@celljs/ta-secrets 0.0.0-stage → 4.18.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/README.en.md +22 -0
- package/README.md +22 -2
- package/extension/index.mjs +742 -0
- package/host/index.mjs +1388 -0
- package/package.json +65 -4
- package/web/index.js +593 -0
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-secrets",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.18.0",
|
|
4
|
+
"description": "A pi package for Ta: a vault of secrets kept in the keychain, which Ta uses in commands by name without the model ever seeing them",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/cellbang/ta",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/cellbang/ta/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"web",
|
|
19
|
+
"host",
|
|
20
|
+
"extension",
|
|
21
|
+
"!**/*.map"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -b && bun build web-src/index.tsx --format esm --target browser --outfile web/index.js && bun build web-src/host.ts --format esm --target node --outfile host/index.mjs && bun build web-src/extension.ts --format esm --target node --outfile extension/index.mjs",
|
|
25
|
+
"clean": "rm -rf lib web host extension *.tsbuildinfo",
|
|
26
|
+
"test": "bun test ./lib",
|
|
27
|
+
"watch": "tsc -b -w --preserveWatchOutput"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@celljs/ta-protocol": "4.18.0",
|
|
31
|
+
"@celljs/ta-web": "4.18.0",
|
|
32
|
+
"@types/react": "^19.3.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"pi": {
|
|
38
|
+
"title": {
|
|
39
|
+
"en": "Vault",
|
|
40
|
+
"zh-CN": "保险箱",
|
|
41
|
+
"zh-TW": "保險箱",
|
|
42
|
+
"ja-JP": "金庫"
|
|
43
|
+
},
|
|
44
|
+
"summary": {
|
|
45
|
+
"en": "Keeps your tokens, passwords and keys in the keychain: Ta uses them in commands by name and never sees them; secrets you send in a conversation go there first.",
|
|
46
|
+
"zh-CN": "把 token、密码、密钥存进钥匙串:Ta 按名字在命令里使用,看不到内容;你在对话里发出的密钥也先收进这里。",
|
|
47
|
+
"zh-TW": "把 token、密碼、金鑰存進鑰匙圈:Ta 按名字在命令裡使用,看不到內容;你在對話裡發出的金鑰也先收進這裡。",
|
|
48
|
+
"ja-JP": "トークン、パスワード、鍵をキーチェーンに保管します。Ta は名前でコマンドに使い、中身は見ません。会話で送った秘密もまずここに保管されます。"
|
|
49
|
+
},
|
|
50
|
+
"icon": "KeyRound",
|
|
51
|
+
"web": [
|
|
52
|
+
"./web/index.js"
|
|
53
|
+
],
|
|
54
|
+
"host": "./host/index.mjs",
|
|
55
|
+
"extensions": [
|
|
56
|
+
"./extension/index.mjs"
|
|
57
|
+
],
|
|
58
|
+
"permissions": {
|
|
59
|
+
"host": {
|
|
60
|
+
"*": "settings.manage"
|
|
61
|
+
},
|
|
62
|
+
"tools": {
|
|
63
|
+
"request_secret": "settings.manage"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
package/web/index.js
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
// ../ta-protocol/esm/common/language.js
|
|
2
|
+
var TaLanguageUtil;
|
|
3
|
+
(function(TaLanguageUtil2) {
|
|
4
|
+
TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
|
|
5
|
+
TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
|
|
6
|
+
function of(tag) {
|
|
7
|
+
const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
|
|
8
|
+
if (/^zh(\b|-)/.test(said)) {
|
|
9
|
+
return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
|
|
10
|
+
}
|
|
11
|
+
return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
|
|
12
|
+
}
|
|
13
|
+
TaLanguageUtil2.of = of;
|
|
14
|
+
function server(env = typeof process === "undefined" ? {} : process.env) {
|
|
15
|
+
return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
|
|
16
|
+
}
|
|
17
|
+
TaLanguageUtil2.server = server;
|
|
18
|
+
function pick(language, words) {
|
|
19
|
+
return words[of(language)];
|
|
20
|
+
}
|
|
21
|
+
TaLanguageUtil2.pick = pick;
|
|
22
|
+
function say(words) {
|
|
23
|
+
return words[server()];
|
|
24
|
+
}
|
|
25
|
+
TaLanguageUtil2.say = say;
|
|
26
|
+
function chinese(language) {
|
|
27
|
+
return of(language).startsWith("zh");
|
|
28
|
+
}
|
|
29
|
+
TaLanguageUtil2.chinese = chinese;
|
|
30
|
+
function cjk(language) {
|
|
31
|
+
return of(language) !== "en-US";
|
|
32
|
+
}
|
|
33
|
+
TaLanguageUtil2.cjk = cjk;
|
|
34
|
+
function list(language, items) {
|
|
35
|
+
return items.join(cjk(language) ? "、" : ", ");
|
|
36
|
+
}
|
|
37
|
+
TaLanguageUtil2.list = list;
|
|
38
|
+
})(TaLanguageUtil || (TaLanguageUtil = {}));
|
|
39
|
+
|
|
40
|
+
// web-src/i18n.ts
|
|
41
|
+
var EN = {
|
|
42
|
+
settingsTitle: "Vault",
|
|
43
|
+
captureLabel: "Keep secrets I send",
|
|
44
|
+
captureHint: "Tokens and passwords in a message go into the vault before Ta reads it; Ta sees only their names.",
|
|
45
|
+
personalLabel: "Keep personal details I send",
|
|
46
|
+
personalHint: "Phone numbers, emails, ID numbers and bank cards too: Ta sees a name and a masked hint, and fills the detail in where it is used.",
|
|
47
|
+
howTool: "filled in",
|
|
48
|
+
howSignIn: "signed in",
|
|
49
|
+
keptLabel: "Kept",
|
|
50
|
+
keptKeychain: "In the keychain of this computer. Ta uses them in commands without seeing them.",
|
|
51
|
+
keptFile: "In a file of this computer only you can read. Ta uses them in commands without seeing them.",
|
|
52
|
+
emptyTitle: "Nothing kept yet",
|
|
53
|
+
emptyHint: "Send a token in a conversation, or Ta asks when it needs one",
|
|
54
|
+
usedTimes: "Used {count} times",
|
|
55
|
+
neverUsed: "Not used yet",
|
|
56
|
+
kindCredential: "Credential",
|
|
57
|
+
kindPersonal: "Personal detail",
|
|
58
|
+
kindDesktop: "Remote desktop {name}",
|
|
59
|
+
signInUser: "account {user}",
|
|
60
|
+
remove: "Remove",
|
|
61
|
+
removeTitle: "Remove {name}?",
|
|
62
|
+
removeHint: "Commands that use it will no longer get it.",
|
|
63
|
+
addLabel: "Add",
|
|
64
|
+
addHint: "Ta refers to it by its name and never sees its value.",
|
|
65
|
+
namePlaceholder: "Name, as API_KEY",
|
|
66
|
+
valuePlaceholder: "Value",
|
|
67
|
+
added: "Kept {name}",
|
|
68
|
+
toolAsk: "Ask you for",
|
|
69
|
+
hostsLabel: "only to {hosts}",
|
|
70
|
+
sshKey: "SSH key",
|
|
71
|
+
hostsPlaceholder: "Only to these hosts (optional)",
|
|
72
|
+
usesLabel: "Lately used",
|
|
73
|
+
usesHint: "Commands and requests that were given a secret. One bound to hosts reaches only them, through Ta; an SSH key goes only into an agent of the command.",
|
|
74
|
+
usesNone: "Not used yet",
|
|
75
|
+
howEnv: "command",
|
|
76
|
+
howGit: "git",
|
|
77
|
+
howSsh: "SSH",
|
|
78
|
+
howHttp: "request",
|
|
79
|
+
justNow: "just now"
|
|
80
|
+
};
|
|
81
|
+
var ZH = {
|
|
82
|
+
settingsTitle: "保险箱",
|
|
83
|
+
captureLabel: "收起我发出的密钥",
|
|
84
|
+
captureHint: "消息里的 token、密码先收进保险箱,Ta 只看到名字。",
|
|
85
|
+
personalLabel: "收起我发出的个人信息",
|
|
86
|
+
personalHint: "手机号、邮箱、证件号、银行卡也先收进来:Ta 只看到名字和打码后的样子,用到时再填回去。",
|
|
87
|
+
howTool: "填入",
|
|
88
|
+
howSignIn: "登录",
|
|
89
|
+
keptLabel: "已保存",
|
|
90
|
+
keptKeychain: "存在这台电脑的钥匙串里;Ta 在命令里使用,看不到内容。",
|
|
91
|
+
keptFile: "存在这台电脑上只有你能读的文件里;Ta 在命令里使用,看不到内容。",
|
|
92
|
+
emptyTitle: "保险箱是空的",
|
|
93
|
+
emptyHint: "在对话里发出 token,或等 Ta 需要时向你要",
|
|
94
|
+
usedTimes: "用过 {count} 次",
|
|
95
|
+
neverUsed: "还没用过",
|
|
96
|
+
kindCredential: "凭据",
|
|
97
|
+
kindPersonal: "个人信息",
|
|
98
|
+
kindDesktop: "远程桌面 {name}",
|
|
99
|
+
signInUser: "账号 {user}",
|
|
100
|
+
remove: "删除",
|
|
101
|
+
removeTitle: "删除 {name}?",
|
|
102
|
+
removeHint: "用到它的命令将拿不到它。",
|
|
103
|
+
addLabel: "添加",
|
|
104
|
+
addHint: "Ta 用名字指代它,看不到它的值。",
|
|
105
|
+
namePlaceholder: "名字,如 API_KEY",
|
|
106
|
+
valuePlaceholder: "值",
|
|
107
|
+
added: "已保存 {name}",
|
|
108
|
+
toolAsk: "向你要",
|
|
109
|
+
hostsLabel: "只发往 {hosts}",
|
|
110
|
+
sshKey: "SSH 密钥",
|
|
111
|
+
hostsPlaceholder: "只发往这些主机(可选)",
|
|
112
|
+
usesLabel: "最近使用",
|
|
113
|
+
usesHint: "拿到过密钥的命令和请求。绑定了主机的密钥只经 Ta 发往这些主机;SSH 密钥只放进那条命令自己的 agent。",
|
|
114
|
+
usesNone: "还没用过",
|
|
115
|
+
howEnv: "命令",
|
|
116
|
+
howGit: "git",
|
|
117
|
+
howSsh: "SSH",
|
|
118
|
+
howHttp: "请求",
|
|
119
|
+
justNow: "刚刚"
|
|
120
|
+
};
|
|
121
|
+
var ZH_TW = {
|
|
122
|
+
settingsTitle: "保險箱",
|
|
123
|
+
captureLabel: "收起我發出的金鑰",
|
|
124
|
+
captureHint: "訊息裡的 token、密碼先收進保險箱,Ta 只看到名字。",
|
|
125
|
+
personalLabel: "收起我發出的個人資訊",
|
|
126
|
+
personalHint: "手機號碼、電子郵件、證件號碼、銀行卡也先收進來:Ta 只看到名字和遮蔽後的樣子,用到時再填回去。",
|
|
127
|
+
howTool: "填入",
|
|
128
|
+
howSignIn: "登入",
|
|
129
|
+
keptLabel: "已儲存",
|
|
130
|
+
keptKeychain: "存在這台電腦的鑰匙圈裡;Ta 在命令裡使用,看不到內容。",
|
|
131
|
+
keptFile: "存在這台電腦上只有你能讀的檔案裡;Ta 在命令裡使用,看不到內容。",
|
|
132
|
+
emptyTitle: "保險箱是空的",
|
|
133
|
+
emptyHint: "在對話裡發出 token,或等 Ta 需要時向你要",
|
|
134
|
+
usedTimes: "用過 {count} 次",
|
|
135
|
+
neverUsed: "還沒用過",
|
|
136
|
+
kindCredential: "憑據",
|
|
137
|
+
kindPersonal: "個人資訊",
|
|
138
|
+
kindDesktop: "遠端桌面 {name}",
|
|
139
|
+
signInUser: "帳號 {user}",
|
|
140
|
+
remove: "刪除",
|
|
141
|
+
removeTitle: "刪除 {name}?",
|
|
142
|
+
removeHint: "用到它的命令將拿不到它。",
|
|
143
|
+
addLabel: "新增",
|
|
144
|
+
addHint: "Ta 用名字指代它,看不到它的值。",
|
|
145
|
+
namePlaceholder: "名字,如 API_KEY",
|
|
146
|
+
valuePlaceholder: "值",
|
|
147
|
+
added: "已儲存 {name}",
|
|
148
|
+
toolAsk: "向你要",
|
|
149
|
+
hostsLabel: "只發往 {hosts}",
|
|
150
|
+
sshKey: "SSH 金鑰",
|
|
151
|
+
hostsPlaceholder: "只發往這些主機(選填)",
|
|
152
|
+
usesLabel: "最近使用",
|
|
153
|
+
usesHint: "拿到過金鑰的命令和請求。綁定了主機的金鑰只經 Ta 發往這些主機;SSH 金鑰只放進那條命令自己的 agent。",
|
|
154
|
+
usesNone: "還沒用過",
|
|
155
|
+
howEnv: "命令",
|
|
156
|
+
howGit: "git",
|
|
157
|
+
howSsh: "SSH",
|
|
158
|
+
howHttp: "請求",
|
|
159
|
+
justNow: "剛剛"
|
|
160
|
+
};
|
|
161
|
+
var JA = {
|
|
162
|
+
settingsTitle: "金庫",
|
|
163
|
+
captureLabel: "送信した秘密を保管",
|
|
164
|
+
captureHint: "メッセージ内のトークンやパスワードは Ta が読む前に金庫へ保管され、Ta には名前だけが見えます。",
|
|
165
|
+
personalLabel: "送信した個人情報を保管",
|
|
166
|
+
personalHint: "電話番号、メール、身分証番号、銀行カードも保管します。Ta には名前と伏せ字だけが見え、使う時に元の値が入ります。",
|
|
167
|
+
howTool: "入力",
|
|
168
|
+
howSignIn: "サインイン",
|
|
169
|
+
keptLabel: "保管中",
|
|
170
|
+
keptKeychain: "このコンピュータのキーチェーンに保管。Ta はコマンドで使いますが、中身は見えません。",
|
|
171
|
+
keptFile: "このコンピュータ上の本人だけが読めるファイルに保管。Ta はコマンドで使いますが、中身は見えません。",
|
|
172
|
+
emptyTitle: "まだ何もありません",
|
|
173
|
+
emptyHint: "会話でトークンを送るか、必要なときに Ta が尋ねます",
|
|
174
|
+
usedTimes: "{count} 回使用",
|
|
175
|
+
neverUsed: "未使用",
|
|
176
|
+
kindCredential: "認証情報",
|
|
177
|
+
kindPersonal: "個人情報",
|
|
178
|
+
kindDesktop: "リモートデスクトップ {name}",
|
|
179
|
+
signInUser: "アカウント {user}",
|
|
180
|
+
remove: "削除",
|
|
181
|
+
removeTitle: "{name} を削除しますか?",
|
|
182
|
+
removeHint: "これを使うコマンドは値を受け取れなくなります。",
|
|
183
|
+
addLabel: "追加",
|
|
184
|
+
addHint: "Ta は名前で参照し、値は見えません。",
|
|
185
|
+
namePlaceholder: "名前(例:API_KEY)",
|
|
186
|
+
valuePlaceholder: "値",
|
|
187
|
+
added: "{name} を保管しました",
|
|
188
|
+
toolAsk: "尋ねる",
|
|
189
|
+
hostsLabel: "{hosts} にのみ送信",
|
|
190
|
+
sshKey: "SSH 鍵",
|
|
191
|
+
hostsPlaceholder: "送信先ホスト(任意)",
|
|
192
|
+
usesLabel: "最近の使用",
|
|
193
|
+
usesHint: "秘密を受け取ったコマンドとリクエスト。ホストを指定した秘密は Ta を通してそのホストにだけ送られ、SSH 鍵はそのコマンド専用のエージェントにだけ入ります。",
|
|
194
|
+
usesNone: "まだ使われていません",
|
|
195
|
+
howEnv: "コマンド",
|
|
196
|
+
howGit: "git",
|
|
197
|
+
howSsh: "SSH",
|
|
198
|
+
howHttp: "リクエスト",
|
|
199
|
+
justNow: "たった今"
|
|
200
|
+
};
|
|
201
|
+
var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
|
|
202
|
+
var SecretsWords;
|
|
203
|
+
((SecretsWords) => {
|
|
204
|
+
function of(language) {
|
|
205
|
+
return TaLanguageUtil.pick(language, WORDS);
|
|
206
|
+
}
|
|
207
|
+
SecretsWords.of = of;
|
|
208
|
+
function format(text, values) {
|
|
209
|
+
return text.replace(/\{(\w+)\}/g, (whole, key) => (key in values) ? String(values[key]) : whole);
|
|
210
|
+
}
|
|
211
|
+
SecretsWords.format = format;
|
|
212
|
+
})(SecretsWords ||= {});
|
|
213
|
+
|
|
214
|
+
// web-src/react.ts
|
|
215
|
+
var React;
|
|
216
|
+
function bind(react) {
|
|
217
|
+
React = react;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// web-src/secrets-protocol.ts
|
|
221
|
+
var REQUEST_TOOL = "request_secret";
|
|
222
|
+
var ENV_PREFIX = "TA_SECRET_";
|
|
223
|
+
var Keys;
|
|
224
|
+
((Keys) => {
|
|
225
|
+
Keys.ENTRIES = "entries";
|
|
226
|
+
Keys.CAPTURE = "capture";
|
|
227
|
+
Keys.PERSONAL = "personal";
|
|
228
|
+
Keys.USES = "uses";
|
|
229
|
+
})(Keys ||= {});
|
|
230
|
+
var SecretNames;
|
|
231
|
+
((SecretNames) => {
|
|
232
|
+
SecretNames.MAX = 48;
|
|
233
|
+
function normalize(name) {
|
|
234
|
+
return name.trim().replace(/^\$?\{?TA_SECRET_/i, "").replace(/[^A-Za-z0-9]+/g, "_").replace(/^_+|_+$/g, "").toUpperCase().slice(0, SecretNames.MAX);
|
|
235
|
+
}
|
|
236
|
+
SecretNames.normalize = normalize;
|
|
237
|
+
function valid(name) {
|
|
238
|
+
return /^[A-Z0-9][A-Z0-9_]*$/.test(name) && name.length <= SecretNames.MAX;
|
|
239
|
+
}
|
|
240
|
+
SecretNames.valid = valid;
|
|
241
|
+
function env(name) {
|
|
242
|
+
return ENV_PREFIX + name;
|
|
243
|
+
}
|
|
244
|
+
SecretNames.env = env;
|
|
245
|
+
function handle(name) {
|
|
246
|
+
return `$${env(name)}`;
|
|
247
|
+
}
|
|
248
|
+
SecretNames.handle = handle;
|
|
249
|
+
function references(command) {
|
|
250
|
+
return [...new Set([...command.matchAll(/\bTA_SECRET_([A-Z0-9_]+)/g)].map((match) => match[1]))];
|
|
251
|
+
}
|
|
252
|
+
SecretNames.references = references;
|
|
253
|
+
function free(base, taken) {
|
|
254
|
+
const name = normalize(base) || "SECRET";
|
|
255
|
+
if (!taken.has(name)) {
|
|
256
|
+
return name;
|
|
257
|
+
}
|
|
258
|
+
for (let n = 2;; n++) {
|
|
259
|
+
const next = `${name.slice(0, SecretNames.MAX - String(n).length - 1)}_${n}`;
|
|
260
|
+
if (!taken.has(next)) {
|
|
261
|
+
return next;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
SecretNames.free = free;
|
|
266
|
+
function looksSecret(value) {
|
|
267
|
+
if (/[()[\]{}<>]/.test(value)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return /[0-9]/.test(value) && /[A-Za-z]/.test(value) || value.length >= 20;
|
|
271
|
+
}
|
|
272
|
+
SecretNames.looksSecret = looksSecret;
|
|
273
|
+
function hosts(value) {
|
|
274
|
+
const items = Array.isArray(value) ? value : typeof value === "string" ? value.split(/[\s,;]+/) : [];
|
|
275
|
+
const hosts2 = items.map((item) => String(item).trim().toLowerCase().replace(/^[a-z]+:\/\//, "").replace(/^[^@/]*@/, "").replace(/\/.*$/, "")).filter((host) => /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+(:\d{1,5})?$/.test(host));
|
|
276
|
+
return [...new Set(hosts2)];
|
|
277
|
+
}
|
|
278
|
+
SecretNames.hosts = hosts;
|
|
279
|
+
function defaultHosts(name) {
|
|
280
|
+
return /GITHUB/.test(name) ? ["github.com", "api.github.com"] : /GITLAB/.test(name) ? ["gitlab.com"] : /GITEE/.test(name) ? ["gitee.com"] : [];
|
|
281
|
+
}
|
|
282
|
+
SecretNames.defaultHosts = defaultHosts;
|
|
283
|
+
function gitUser(entry, host) {
|
|
284
|
+
return entry.gitUser || (host === "gitlab.com" || host.startsWith("gitlab.") ? "oauth2" : "x-access-token");
|
|
285
|
+
}
|
|
286
|
+
SecretNames.gitUser = gitUser;
|
|
287
|
+
function privateKey(value) {
|
|
288
|
+
return /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*-----END [A-Z0-9 ]*PRIVATE KEY-----/.test(value);
|
|
289
|
+
}
|
|
290
|
+
SecretNames.privateKey = privateKey;
|
|
291
|
+
function uses(value) {
|
|
292
|
+
return Array.isArray(value) ? value.filter((use) => !!use && typeof use === "object" && typeof use.at === "number" && Array.isArray(use.names)) : [];
|
|
293
|
+
}
|
|
294
|
+
SecretNames.uses = uses;
|
|
295
|
+
function entries(value) {
|
|
296
|
+
if (!Array.isArray(value)) {
|
|
297
|
+
return [];
|
|
298
|
+
}
|
|
299
|
+
return value.map((entry) => entry && typeof entry === "object" && Array.isArray(entry.git) && !entry.hosts ? (({ git, ...rest }) => ({ ...rest, hosts: git }))(entry) : entry).filter((entry) => !!entry && typeof entry === "object" && typeof entry.name === "string" && valid(entry.name));
|
|
300
|
+
}
|
|
301
|
+
SecretNames.entries = entries;
|
|
302
|
+
})(SecretNames ||= {});
|
|
303
|
+
|
|
304
|
+
// web-src/settings.tsx
|
|
305
|
+
function message(error) {
|
|
306
|
+
return error instanceof Error ? error.message : String(error);
|
|
307
|
+
}
|
|
308
|
+
function useStored(pi, key, parse) {
|
|
309
|
+
const [value, setValue] = React.useState(() => parse(undefined));
|
|
310
|
+
React.useEffect(() => {
|
|
311
|
+
let live = true;
|
|
312
|
+
const read = () => void pi.storage.get(key).then((stored) => live && setValue(parse(stored)), () => {
|
|
313
|
+
return;
|
|
314
|
+
});
|
|
315
|
+
read();
|
|
316
|
+
const stop = pi.storage.onChange((keys) => keys.includes(key) && read());
|
|
317
|
+
return () => {
|
|
318
|
+
live = false;
|
|
319
|
+
stop();
|
|
320
|
+
};
|
|
321
|
+
}, [pi, key, parse]);
|
|
322
|
+
return value;
|
|
323
|
+
}
|
|
324
|
+
var capture = (value) => value !== false;
|
|
325
|
+
function CaptureSetting({ pi }) {
|
|
326
|
+
const words = SecretsWords.of(pi.ui.language);
|
|
327
|
+
const on = useStored(pi, Keys.CAPTURE, capture);
|
|
328
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
|
|
329
|
+
checked: on,
|
|
330
|
+
label: words.captureLabel,
|
|
331
|
+
onChange: (next) => pi.callHost("setCapturing", next).catch((error) => {
|
|
332
|
+
pi.ui.notify(message(error), "error");
|
|
333
|
+
throw error;
|
|
334
|
+
})
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function PersonalSetting({ pi }) {
|
|
338
|
+
const words = SecretsWords.of(pi.ui.language);
|
|
339
|
+
const on = useStored(pi, Keys.PERSONAL, capture);
|
|
340
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
|
|
341
|
+
checked: on,
|
|
342
|
+
label: words.personalLabel,
|
|
343
|
+
onChange: (next) => pi.callHost("setCapturingPersonal", next).catch((error) => {
|
|
344
|
+
pi.ui.notify(message(error), "error");
|
|
345
|
+
throw error;
|
|
346
|
+
})
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function RemoveButton({ pi, entry }) {
|
|
350
|
+
const words = SecretsWords.of(pi.ui.language);
|
|
351
|
+
const [busy, run] = pi.ui.useBusy();
|
|
352
|
+
const remove = async () => {
|
|
353
|
+
if (await pi.ui.confirm(SecretsWords.format(words.removeTitle, { name: entry.name }), words.removeHint, { confirmLabel: words.remove, danger: true })) {
|
|
354
|
+
await run(() => pi.callHost("remove", entry.name).catch((error) => pi.ui.notify(message(error), "error")));
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
358
|
+
type: "button",
|
|
359
|
+
className: `ta-button${busy ? " ta-busy" : ""}`,
|
|
360
|
+
"aria-busy": busy || undefined,
|
|
361
|
+
disabled: busy,
|
|
362
|
+
onClick: () => void remove()
|
|
363
|
+
}, busy && /* @__PURE__ */ React.createElement("span", {
|
|
364
|
+
className: "ta-spinner ta-busy-mark"
|
|
365
|
+
}), /* @__PURE__ */ React.createElement("span", null, words.remove));
|
|
366
|
+
}
|
|
367
|
+
function KeptSetting({ pi }) {
|
|
368
|
+
const words = SecretsWords.of(pi.ui.language);
|
|
369
|
+
const entries = useStored(pi, Keys.ENTRIES, SecretNames.entries);
|
|
370
|
+
if (!entries.length) {
|
|
371
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
372
|
+
compact: true,
|
|
373
|
+
title: words.emptyTitle,
|
|
374
|
+
hint: words.emptyHint
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return /* @__PURE__ */ React.createElement("ul", {
|
|
378
|
+
className: "ta-secrets-list"
|
|
379
|
+
}, entries.map((entry) => /* @__PURE__ */ React.createElement("li", {
|
|
380
|
+
key: entry.name
|
|
381
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
382
|
+
className: "ta-secrets-item"
|
|
383
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
384
|
+
className: "ta-secrets-name"
|
|
385
|
+
}, entry.name), /* @__PURE__ */ React.createElement("span", {
|
|
386
|
+
className: "ta-secrets-meta"
|
|
387
|
+
}, [
|
|
388
|
+
entry.signIn ? SecretsWords.format(words.kindDesktop, { name: entry.signIn.name }) : entry.note || (entry.ssh ? words.sshKey : entry.kind === "personal" ? words.kindPersonal : words.kindCredential),
|
|
389
|
+
entry.signIn?.user ? SecretsWords.format(words.signInUser, { user: entry.signIn.user }) : undefined,
|
|
390
|
+
entry.hint,
|
|
391
|
+
entry.ssh && entry.note ? words.sshKey : undefined,
|
|
392
|
+
entry.hosts?.length ? SecretsWords.format(words.hostsLabel, { hosts: entry.hosts.join(", ") }) : undefined,
|
|
393
|
+
entry.uses ? SecretsWords.format(words.usedTimes, { count: entry.uses }) : words.neverUsed
|
|
394
|
+
].filter(Boolean).join(" · "))), /* @__PURE__ */ React.createElement(RemoveButton, {
|
|
395
|
+
pi,
|
|
396
|
+
entry
|
|
397
|
+
}))));
|
|
398
|
+
}
|
|
399
|
+
var HOW = {
|
|
400
|
+
env: "howEnv",
|
|
401
|
+
git: "howGit",
|
|
402
|
+
ssh: "howSsh",
|
|
403
|
+
http: "howHttp",
|
|
404
|
+
tool: "howTool",
|
|
405
|
+
"sign-in": "howSignIn"
|
|
406
|
+
};
|
|
407
|
+
function ago(language, at, justNow) {
|
|
408
|
+
const seconds = Math.round((at - Date.now()) / 1000);
|
|
409
|
+
if (seconds > -60) {
|
|
410
|
+
return justNow;
|
|
411
|
+
}
|
|
412
|
+
const format = new Intl.RelativeTimeFormat(language, { numeric: "auto" });
|
|
413
|
+
for (const [unit, size] of [
|
|
414
|
+
["minute", 60],
|
|
415
|
+
["hour", 3600],
|
|
416
|
+
["day", 86400]
|
|
417
|
+
]) {
|
|
418
|
+
const next = unit === "minute" ? 3600 : unit === "hour" ? 86400 : Number.POSITIVE_INFINITY;
|
|
419
|
+
if (-seconds < next) {
|
|
420
|
+
return format.format(Math.round(seconds / size), unit);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return justNow;
|
|
424
|
+
}
|
|
425
|
+
function UsesSetting({ pi }) {
|
|
426
|
+
const words = SecretsWords.of(pi.ui.language);
|
|
427
|
+
const uses = useStored(pi, Keys.USES, SecretNames.uses);
|
|
428
|
+
if (!uses.length) {
|
|
429
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
430
|
+
compact: true,
|
|
431
|
+
title: words.usesNone
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
return /* @__PURE__ */ React.createElement("ul", {
|
|
435
|
+
className: "ta-secrets-list"
|
|
436
|
+
}, uses.slice(-10).reverse().map((use) => /* @__PURE__ */ React.createElement("li", {
|
|
437
|
+
key: `${use.at}:${use.command}`
|
|
438
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
439
|
+
className: "ta-secrets-item"
|
|
440
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
441
|
+
className: "ta-secrets-name"
|
|
442
|
+
}, use.names.join(", ")), /* @__PURE__ */ React.createElement("span", {
|
|
443
|
+
className: "ta-secrets-meta",
|
|
444
|
+
title: use.command
|
|
445
|
+
}, use.command)), /* @__PURE__ */ React.createElement("span", {
|
|
446
|
+
className: "ta-secrets-when"
|
|
447
|
+
}, [use.how.map((how) => words[HOW[how]]).join(" + "), use.conversation, ago(pi.ui.language, use.at, words.justNow)].filter(Boolean).join(" · ")))));
|
|
448
|
+
}
|
|
449
|
+
function AddSetting({ pi }) {
|
|
450
|
+
const words = SecretsWords.of(pi.ui.language);
|
|
451
|
+
const [name, setName] = React.useState("");
|
|
452
|
+
const [value, setValue] = React.useState("");
|
|
453
|
+
const [hosts, setHosts] = React.useState("");
|
|
454
|
+
const [busy, run] = pi.ui.useBusy();
|
|
455
|
+
const normalized = SecretNames.normalize(name);
|
|
456
|
+
const ready = SecretNames.valid(normalized) && value.length > 0 && !busy;
|
|
457
|
+
const add = (event) => {
|
|
458
|
+
event.preventDefault();
|
|
459
|
+
if (!ready) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
run(() => pi.callHost("add", { name: normalized, value, source: "typed", ...hosts.trim() ? { hosts } : {} }).then((entry) => {
|
|
463
|
+
setName("");
|
|
464
|
+
setValue("");
|
|
465
|
+
setHosts("");
|
|
466
|
+
pi.ui.notify(SecretsWords.format(words.added, { name: entry.name }), "info");
|
|
467
|
+
}, (error) => pi.ui.notify(message(error), "error")));
|
|
468
|
+
};
|
|
469
|
+
return /* @__PURE__ */ React.createElement("form", {
|
|
470
|
+
className: "ta-secrets-add",
|
|
471
|
+
onSubmit: add
|
|
472
|
+
}, /* @__PURE__ */ React.createElement("input", {
|
|
473
|
+
className: "ta-input",
|
|
474
|
+
value: name,
|
|
475
|
+
placeholder: words.namePlaceholder,
|
|
476
|
+
autoCapitalize: "characters",
|
|
477
|
+
autoCorrect: "off",
|
|
478
|
+
spellCheck: false,
|
|
479
|
+
onChange: (event) => setName(event.target.value)
|
|
480
|
+
}), /* @__PURE__ */ React.createElement("textarea", {
|
|
481
|
+
className: "ta-input ta-secrets-value",
|
|
482
|
+
rows: 1,
|
|
483
|
+
value,
|
|
484
|
+
placeholder: words.valuePlaceholder,
|
|
485
|
+
autoComplete: "off",
|
|
486
|
+
autoCorrect: "off",
|
|
487
|
+
autoCapitalize: "off",
|
|
488
|
+
spellCheck: false,
|
|
489
|
+
onChange: (event) => setValue(event.target.value)
|
|
490
|
+
}), /* @__PURE__ */ React.createElement("input", {
|
|
491
|
+
className: "ta-input",
|
|
492
|
+
value: hosts,
|
|
493
|
+
placeholder: words.hostsPlaceholder,
|
|
494
|
+
autoCapitalize: "off",
|
|
495
|
+
autoCorrect: "off",
|
|
496
|
+
spellCheck: false,
|
|
497
|
+
onChange: (event) => setHosts(event.target.value)
|
|
498
|
+
}), /* @__PURE__ */ React.createElement("button", {
|
|
499
|
+
type: "submit",
|
|
500
|
+
className: `ta-button${busy ? " ta-busy" : ""}`,
|
|
501
|
+
"aria-busy": busy || undefined,
|
|
502
|
+
disabled: !ready
|
|
503
|
+
}, busy && /* @__PURE__ */ React.createElement("span", {
|
|
504
|
+
className: "ta-spinner ta-busy-mark"
|
|
505
|
+
}), /* @__PURE__ */ React.createElement("span", null, words.addLabel)));
|
|
506
|
+
}
|
|
507
|
+
function vaultSettings(pi) {
|
|
508
|
+
const words = () => SecretsWords.of(pi.ui.language);
|
|
509
|
+
let store;
|
|
510
|
+
pi.callHost("info").then((info) => {
|
|
511
|
+
store = info.store;
|
|
512
|
+
}, () => {
|
|
513
|
+
return;
|
|
514
|
+
});
|
|
515
|
+
return {
|
|
516
|
+
title: () => words().settingsTitle,
|
|
517
|
+
icon: pi.ui.icons.KeyRound,
|
|
518
|
+
group: "privacy",
|
|
519
|
+
rows: [
|
|
520
|
+
{ key: "capture", label: () => words().captureLabel, description: () => words().captureHint, render: () => /* @__PURE__ */ React.createElement(CaptureSetting, {
|
|
521
|
+
pi
|
|
522
|
+
}) },
|
|
523
|
+
{
|
|
524
|
+
key: "personal",
|
|
525
|
+
label: () => words().personalLabel,
|
|
526
|
+
description: () => words().personalHint,
|
|
527
|
+
render: () => /* @__PURE__ */ React.createElement(PersonalSetting, {
|
|
528
|
+
pi
|
|
529
|
+
})
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
key: "kept",
|
|
533
|
+
label: () => words().keptLabel,
|
|
534
|
+
description: () => store === "file" ? words().keptFile : words().keptKeychain,
|
|
535
|
+
stacked: true,
|
|
536
|
+
render: () => /* @__PURE__ */ React.createElement(KeptSetting, {
|
|
537
|
+
pi
|
|
538
|
+
})
|
|
539
|
+
},
|
|
540
|
+
{ key: "add", label: () => words().addLabel, description: () => words().addHint, stacked: true, render: () => /* @__PURE__ */ React.createElement(AddSetting, {
|
|
541
|
+
pi
|
|
542
|
+
}) },
|
|
543
|
+
{ key: "uses", label: () => words().usesLabel, description: () => words().usesHint, stacked: true, render: () => /* @__PURE__ */ React.createElement(UsesSetting, {
|
|
544
|
+
pi
|
|
545
|
+
}) }
|
|
546
|
+
]
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// web-src/style.ts
|
|
551
|
+
var STYLE = `
|
|
552
|
+
.ta-secrets-list { display: flex; width: 100%; flex-direction: column; margin: 0; padding: 0; list-style: none; }
|
|
553
|
+
.ta-secrets-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 6px 0; border-bottom: 1px solid var(--ta-border-muted); }
|
|
554
|
+
.ta-secrets-list li:last-child { border-bottom: none; }
|
|
555
|
+
.ta-secrets-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
556
|
+
.ta-secrets-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-text); font-family: var(--ta-mono); font-size: calc(13px * var(--ta-font-scale)); }
|
|
557
|
+
.ta-secrets-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
558
|
+
.ta-secrets-add { display: flex; gap: 8px; width: 100%; }
|
|
559
|
+
.ta-secrets-value { display: block; box-sizing: border-box; height: 36px; padding: 0 10px; line-height: 34px; resize: none; overflow: hidden; white-space: nowrap; font: inherit; -webkit-text-security: disc; }
|
|
560
|
+
.ta-secrets-value::placeholder { line-height: 34px; }
|
|
561
|
+
.ta-secrets-when { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); text-align: right; }
|
|
562
|
+
[data-layout='compact'] .ta-secrets-list li:has(.ta-secrets-when) { flex-direction: column; align-items: stretch; gap: 2px; }
|
|
563
|
+
[data-layout='compact'] .ta-secrets-when { max-width: none; text-align: left; }
|
|
564
|
+
.ta-secrets-add .ta-input { flex: 1 1 0; min-width: 0; }
|
|
565
|
+
.ta-secrets-add .ta-input:first-child { font-family: var(--ta-mono); }
|
|
566
|
+
[data-layout='compact'] .ta-secrets-add { flex-direction: column; }
|
|
567
|
+
[data-layout='compact'] .ta-secrets-add .ta-input { flex: none; }
|
|
568
|
+
[data-layout='compact'] .ta-secrets-add .ta-button { height: 36px; }
|
|
569
|
+
`;
|
|
570
|
+
function injectStyle() {
|
|
571
|
+
const element = document.createElement("style");
|
|
572
|
+
element.dataset.taPackage = "ta-secrets";
|
|
573
|
+
element.textContent = STYLE;
|
|
574
|
+
document.head.appendChild(element);
|
|
575
|
+
return () => element.remove();
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// web-src/index.tsx
|
|
579
|
+
function activate(pi) {
|
|
580
|
+
bind(pi.React);
|
|
581
|
+
const removeStyle = injectStyle();
|
|
582
|
+
pi.registerSettings(vaultSettings(pi));
|
|
583
|
+
pi.registerToolRenderer((name, next) => name === REQUEST_TOOL ? next() ?? {
|
|
584
|
+
renderCall: (args) => ({
|
|
585
|
+
verb: SecretsWords.of(pi.ui.language).toolAsk,
|
|
586
|
+
target: typeof args.name === "string" ? args.name : undefined
|
|
587
|
+
})
|
|
588
|
+
} : next());
|
|
589
|
+
return removeStyle;
|
|
590
|
+
}
|
|
591
|
+
export {
|
|
592
|
+
activate as default
|
|
593
|
+
};
|