@app-vitals/agent-lib 1.118.0 → 1.120.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/child-env.ts +37 -4
- package/child-env.unit.test.ts +53 -2
- package/package.json +1 -1
- package/web/toolbar.ts +14 -1
package/child-env.ts
CHANGED
|
@@ -42,8 +42,6 @@ export const CHILD_ALLOWED_SECRET_ENV_VARS = [
|
|
|
42
42
|
"GH_TOKEN",
|
|
43
43
|
"SLACK_BOT_TOKEN",
|
|
44
44
|
"SHIPWRIGHT_AGENT_API_KEY",
|
|
45
|
-
// Tools-kind token for the model's process; passes through for now.
|
|
46
|
-
"SHIPWRIGHT_AGENT_TOOLS_API_KEY",
|
|
47
45
|
"SHIPWRIGHT_TASK_STORE_TOKEN",
|
|
48
46
|
"SHIPWRIGHT_CHAT_SERVICE_TOKEN",
|
|
49
47
|
// The shipped shipwright task-store skill still mints scoped tokens with
|
|
@@ -62,8 +60,33 @@ export const CHILD_ALLOWED_SECRET_ENV_VARS = [
|
|
|
62
60
|
] as const satisfies readonly SecretEnvVar[];
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
63
|
+
* Secrets the child receives under a different name. The tools-kind token is
|
|
64
|
+
* handed to the child as SHIPWRIGHT_AGENT_API_KEY (the name skills read), and
|
|
65
|
+
* the tools variable itself is not passed on. The runtime keeps the pod's own
|
|
66
|
+
* SHIPWRIGHT_AGENT_API_KEY for its admin calls.
|
|
67
|
+
*/
|
|
68
|
+
export const MAPPED_ENV_VARS = [
|
|
69
|
+
"SHIPWRIGHT_AGENT_TOOLS_API_KEY",
|
|
70
|
+
] as const satisfies readonly SecretEnvVar[];
|
|
71
|
+
|
|
72
|
+
const TOOLS_KEY = "SHIPWRIGHT_AGENT_TOOLS_API_KEY";
|
|
73
|
+
const AGENT_KEY = "SHIPWRIGHT_AGENT_API_KEY";
|
|
74
|
+
|
|
75
|
+
let warnedMissingToolsKey = false;
|
|
76
|
+
|
|
77
|
+
/** Test hook: re-arm the once-per-process fallback warning. */
|
|
78
|
+
export function resetChildEnvWarning(): void {
|
|
79
|
+
warnedMissingToolsKey = false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Copy `env`, drop every runtime-only key, map the tools token onto
|
|
84
|
+
* SHIPWRIGHT_AGENT_API_KEY, then layer `extra` last so a per-run override
|
|
85
|
+
* still wins.
|
|
86
|
+
*
|
|
87
|
+
* Phase A fallback: with no tools token the child keeps the old key and one
|
|
88
|
+
* warning is logged per process, so a runtime deployed before admin's backfill
|
|
89
|
+
* keeps working.
|
|
67
90
|
*/
|
|
68
91
|
export function buildChildEnv(
|
|
69
92
|
env: Record<string, string | undefined>,
|
|
@@ -71,5 +94,15 @@ export function buildChildEnv(
|
|
|
71
94
|
): Record<string, string | undefined> {
|
|
72
95
|
const child: Record<string, string | undefined> = { ...env };
|
|
73
96
|
for (const key of RUNTIME_ONLY_ENV_VARS) delete child[key];
|
|
97
|
+
const toolsKey = child[TOOLS_KEY];
|
|
98
|
+
delete child[TOOLS_KEY];
|
|
99
|
+
if (toolsKey) {
|
|
100
|
+
child[AGENT_KEY] = toolsKey;
|
|
101
|
+
} else if (!warnedMissingToolsKey) {
|
|
102
|
+
warnedMissingToolsKey = true;
|
|
103
|
+
console.warn(
|
|
104
|
+
`[child-env] ${TOOLS_KEY} is not set; the child keeps ${AGENT_KEY} (fallback)`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
74
107
|
return { ...child, ...extra };
|
|
75
108
|
}
|
package/child-env.unit.test.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
|
|
2
2
|
import {
|
|
3
3
|
buildChildEnv,
|
|
4
4
|
CHILD_ALLOWED_SECRET_ENV_VARS,
|
|
5
|
+
MAPPED_ENV_VARS,
|
|
5
6
|
RUNTIME_ONLY_ENV_VARS,
|
|
7
|
+
resetChildEnvWarning,
|
|
6
8
|
} from "./child-env.ts";
|
|
7
9
|
import { SECRET_ENV_VARS } from "./secret-env-vars.ts";
|
|
8
10
|
|
|
@@ -75,10 +77,59 @@ describe("buildChildEnv", () => {
|
|
|
75
77
|
describe("secret classification", () => {
|
|
76
78
|
const runtimeOnly: readonly string[] = RUNTIME_ONLY_ENV_VARS;
|
|
77
79
|
const childAllowed: readonly string[] = CHILD_ALLOWED_SECRET_ENV_VARS;
|
|
80
|
+
const mapped: readonly string[] = MAPPED_ENV_VARS;
|
|
78
81
|
|
|
79
82
|
test.each([...SECRET_ENV_VARS])("%s is in exactly one list", (name) => {
|
|
80
83
|
const count =
|
|
81
|
-
Number(runtimeOnly.includes(name)) +
|
|
84
|
+
Number(runtimeOnly.includes(name)) +
|
|
85
|
+
Number(childAllowed.includes(name)) +
|
|
86
|
+
Number(mapped.includes(name));
|
|
82
87
|
expect(count).toBe(1);
|
|
83
88
|
});
|
|
84
89
|
});
|
|
90
|
+
|
|
91
|
+
describe("buildChildEnv tools-token mapping", () => {
|
|
92
|
+
let warn: ReturnType<typeof spyOn>;
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
resetChildEnvWarning();
|
|
95
|
+
warn = spyOn(console, "warn").mockImplementation(() => {});
|
|
96
|
+
});
|
|
97
|
+
afterEach(() => warn.mockRestore());
|
|
98
|
+
|
|
99
|
+
test("MAPPED_ENV_VARS is the tools key and is not also pass-through", () => {
|
|
100
|
+
expect([...MAPPED_ENV_VARS]).toEqual(["SHIPWRIGHT_AGENT_TOOLS_API_KEY"]);
|
|
101
|
+
for (const k of MAPPED_ENV_VARS)
|
|
102
|
+
expect(
|
|
103
|
+
(CHILD_ALLOWED_SECRET_ENV_VARS as readonly string[]).includes(k),
|
|
104
|
+
).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("with the tools key set, the child gets it as the agent key and not under its own name", () => {
|
|
108
|
+
const env = {
|
|
109
|
+
SHIPWRIGHT_AGENT_API_KEY: "pod-key",
|
|
110
|
+
SHIPWRIGHT_AGENT_TOOLS_API_KEY: "tools-key",
|
|
111
|
+
};
|
|
112
|
+
const child = buildChildEnv(env);
|
|
113
|
+
expect(child.SHIPWRIGHT_AGENT_API_KEY).toBe("tools-key");
|
|
114
|
+
expect("SHIPWRIGHT_AGENT_TOOLS_API_KEY" in child).toBe(false);
|
|
115
|
+
expect(env.SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
|
|
116
|
+
expect(env.SHIPWRIGHT_AGENT_TOOLS_API_KEY).toBe("tools-key");
|
|
117
|
+
expect(warn).not.toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("without the tools key, the child keeps the old key and warns once per process", () => {
|
|
121
|
+
const env = { SHIPWRIGHT_AGENT_API_KEY: "pod-key" };
|
|
122
|
+
expect(buildChildEnv(env).SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
|
|
123
|
+
expect(buildChildEnv(env).SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
|
|
124
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("an empty tools key counts as absent", () => {
|
|
128
|
+
const child = buildChildEnv({
|
|
129
|
+
SHIPWRIGHT_AGENT_API_KEY: "pod-key",
|
|
130
|
+
SHIPWRIGHT_AGENT_TOOLS_API_KEY: "",
|
|
131
|
+
});
|
|
132
|
+
expect(child.SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
|
|
133
|
+
expect("SHIPWRIGHT_AGENT_TOOLS_API_KEY" in child).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
});
|
package/package.json
CHANGED
package/web/toolbar.ts
CHANGED
|
@@ -60,6 +60,18 @@ export interface ShipwrightToolbarOptions {
|
|
|
60
60
|
adminBaseUrl?: string;
|
|
61
61
|
/** Public task board URL, used only for the public audience. Defaults to "/public/tasks". */
|
|
62
62
|
tasksUrl?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Optional logo rendered beside the wordmark. Must be a same-origin path
|
|
65
|
+
* (starts with a single "/"); anything else is ignored. Unset = no logo.
|
|
66
|
+
*/
|
|
67
|
+
logoUrl?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Returns an escaped <img> for a same-origin logo path, or "" if unset/unsafe. */
|
|
71
|
+
export function renderToolbarLogo(logoUrl: string | undefined): string {
|
|
72
|
+
if (!logoUrl) return "";
|
|
73
|
+
if (!/^\/(?![/\\])[^\s\\]*$/.test(logoUrl)) return "";
|
|
74
|
+
return `<img src="${escapeHtml(logoUrl)}" alt="" class="vos-logo" width="20" height="20" />`;
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
/** localStorage key holding the visitor's saved theme: "light" or "dark". */
|
|
@@ -220,6 +232,7 @@ export function baseStyles(): string {
|
|
|
220
232
|
letter-spacing: -0.3px;
|
|
221
233
|
flex-shrink: 0;
|
|
222
234
|
}
|
|
235
|
+
.vos-logo { vertical-align: middle; margin-right: 8px; border-radius: 4px; }
|
|
223
236
|
.vos-wordmark:hover { color: var(--vos-brand); }
|
|
224
237
|
.vos-nav {
|
|
225
238
|
display: flex;
|
|
@@ -437,7 +450,7 @@ export function renderShipwrightToolbar(
|
|
|
437
450
|
|
|
438
451
|
return `<input type="checkbox" id="vos-nav-toggle" class="vos-nav-toggle" aria-hidden="true">
|
|
439
452
|
<nav class="vos-toolbar" aria-label="Site navigation">
|
|
440
|
-
<a href="${adminBase}/admin/agents" class="vos-wordmark"
|
|
453
|
+
<a href="${adminBase}/admin/agents" class="vos-wordmark">${renderToolbarLogo(opts.logoUrl)}Shipwright</a>
|
|
441
454
|
<div id="vos-nav-content" class="vos-nav">
|
|
442
455
|
${links}
|
|
443
456
|
</div>
|