ai-fly 0.4.0-alpha.7 → 0.4.0-alpha.9
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/hooks/codex.cjs +12 -0
- package/hooks/env.cjs +10 -0
- package/hooks/file.cjs +27 -0
- package/hooks/secret.cjs +11 -0
- package/package.json +2 -1
- package/webui/dist/assets/{index-BlacE8xb.js → index-BziQsPBL.js} +23 -23
- package/webui/dist/assets/{index-tP1nMXNW.css → index-CufH1z8j.css} +1 -1
- package/webui/dist/index.html +2 -2
package/hooks/codex.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// 内建 hooks 脚本:codex —— 读 codex CLI 登录态(~/.codex/auth.json)。
|
|
2
|
+
// 钩子清单(按函数名命名规范被发现):
|
|
3
|
+
// - authHeader(ctx) -> string:ChatGPT Codex backend 的 Bearer 认证头(去前缀裸值,
|
|
4
|
+
// 框架按需拼 "Bearer " 由 headerSet 配置的 bearer 决定——本脚本返回裸 token)。
|
|
5
|
+
module.exports.authHeader = function authHeader({ homedir }) {
|
|
6
|
+
const { readFileSync } = require("node:fs");
|
|
7
|
+
const { join } = require("node:path");
|
|
8
|
+
const auth = JSON.parse(readFileSync(join(homedir, ".codex", "auth.json"), "utf8"));
|
|
9
|
+
const token = auth && auth.tokens && auth.tokens.access_token;
|
|
10
|
+
if (typeof token !== "string" || token === "") throw new Error("codex auth.json missing access_token");
|
|
11
|
+
return token;
|
|
12
|
+
};
|
package/hooks/env.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// 内建 hooks 脚本:env —— 环境变量桥。
|
|
2
|
+
// 钩子清单:
|
|
3
|
+
// - authHeader(ctx) -> string:读 args.var 指定的环境变量(OPENAI_API_KEY 等)。
|
|
4
|
+
module.exports.authHeader = function authHeader({ args, env: ctxEnv }) {
|
|
5
|
+
const name = args && args.var;
|
|
6
|
+
if (typeof name !== "string" || name === "") throw new Error("env hook requires args.var");
|
|
7
|
+
const value = (ctxEnv && ctxEnv(name)) || process.env[name];
|
|
8
|
+
if (value === undefined || value === "") throw new Error(`env '${name}' unset`);
|
|
9
|
+
return value;
|
|
10
|
+
};
|
package/hooks/file.cjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// 内建 hooks 脚本:file —— JSON 文件取值(点径)。
|
|
2
|
+
// 钩子清单:
|
|
3
|
+
// - authHeader(ctx) -> string:读 args.path(支持 ~)+ args.jsonPath(.a.b 风格);
|
|
4
|
+
// args.bearer 为 "true"/"1" 时返回值拼 "Bearer " 前缀。
|
|
5
|
+
// watch 模式示例(返回 AsyncIterable):unwatchOnClose 实现见文档。
|
|
6
|
+
module.exports.authHeader = function authHeader({ homedir, args }) {
|
|
7
|
+
const { readFileSync } = require("node:fs");
|
|
8
|
+
const { join } = require("node:path");
|
|
9
|
+
const path = args && args.path;
|
|
10
|
+
const jsonPath = (args && args.jsonPath) || ".";
|
|
11
|
+
if (typeof path !== "string" || path === "") throw new Error("file hook requires args.path");
|
|
12
|
+
const abs = path.startsWith("~/") ? join(homedir, path.slice(1)) : path;
|
|
13
|
+
let doc;
|
|
14
|
+
try {
|
|
15
|
+
doc = JSON.parse(readFileSync(abs, "utf8"));
|
|
16
|
+
} catch {
|
|
17
|
+
throw new Error("file unreadable or invalid JSON");
|
|
18
|
+
}
|
|
19
|
+
let cur = doc;
|
|
20
|
+
for (const seg of jsonPath.split(".").filter(Boolean)) {
|
|
21
|
+
if (cur === null || cur === undefined) throw new Error("json path miss");
|
|
22
|
+
cur = cur[seg];
|
|
23
|
+
}
|
|
24
|
+
if (typeof cur !== "string" || cur === "") throw new Error("json path value missing");
|
|
25
|
+
const bearer = args && (args.bearer === "true" || args.bearer === "1");
|
|
26
|
+
return bearer ? `Bearer ${cur}` : cur;
|
|
27
|
+
};
|
package/hooks/secret.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// 内建 hooks 脚本:secret —— 密钥库(SecretsStore)桥。
|
|
2
|
+
// 钩子清单:
|
|
3
|
+
// - authHeader(ctx) -> string:读 args.name 指定的密钥(ctx.secrets 访问器;
|
|
4
|
+
// 值只进头不回显——$secret 法则不变)。
|
|
5
|
+
module.exports.authHeader = function authHeader({ args, secrets }) {
|
|
6
|
+
const name = args && args.name;
|
|
7
|
+
if (typeof name !== "string" || name === "") throw new Error("secret hook requires args.name");
|
|
8
|
+
const value = secrets && secrets(name);
|
|
9
|
+
if (value === undefined || value === "") throw new Error(`secret '${name}' not found`);
|
|
10
|
+
return value;
|
|
11
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-fly",
|
|
3
|
-
"version": "0.4.0-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.9",
|
|
4
4
|
"description": "ai-fly — peer-to-peer HTTP/WebSocket bridge with AI-ready presets, over OpenDWeb fabric",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"dist/*.mjs",
|
|
61
61
|
"dist/*.d.ts",
|
|
62
62
|
"dist/app/**",
|
|
63
|
+
"hooks",
|
|
63
64
|
"webui/dist",
|
|
64
65
|
"resources/app-icons"
|
|
65
66
|
],
|