gen-ai-studio-mcp 0.1.1 → 0.1.2
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.md +1 -0
- package/dist/src/auth.js +38 -7
- package/dist/src/server.js +1 -0
- package/dist/src/tools.js +23 -0
- package/dist/src/world.js +122 -0
- package/dist/test/helpers.js +51 -2
- package/dist/test/stdio.test.js +1 -0
- package/dist/test/tools.test.js +42 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ Then ask Claude to "log in to Gen AI Studio". The browser opens, you sign in and
|
|
|
42
42
|
| `list_models` | Every integrated model in one line each, with whether it was tested for real, plus how auth, jobs and spend work |
|
|
43
43
|
| `list_model_apis` | One model's routes read live from the gateway: method, path, every field with type, required/optional, allowed values, default |
|
|
44
44
|
| `api_details` | The full guide to one model: why and when, modes, limits, mistakes seen, a working example, the recipe, plus the live fields |
|
|
45
|
+
| `get_influencer_world` | Every influencer, or one influencer's whole world: bible, cast with character-sheet pictures saved as local files, voice samples, posts, her project id |
|
|
45
46
|
| `view_video_frames` | Show Claude a contact sheet of frames from a local video, so it can judge a result |
|
|
46
47
|
|
|
47
48
|
Claude calls the GPU APIs itself with HTTP (curl). `use_account` and `status` return what it
|
package/dist/src/auth.js
CHANGED
|
@@ -9,20 +9,51 @@ import { spawn } from "node:child_process";
|
|
|
9
9
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
10
10
|
import http from "node:http";
|
|
11
11
|
import { LoginRequired, UserError, cleanBaseUrl, configuredBaseUrl, loadSession, saveSession, } from "./core.js";
|
|
12
|
-
const CALLBACK_PAGE = `<!doctype html
|
|
13
|
-
<
|
|
14
|
-
<
|
|
12
|
+
const CALLBACK_PAGE = `<!doctype html>
|
|
13
|
+
<html lang="en"><head><meta charset="utf-8">
|
|
14
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
15
|
+
<title>Gen AI Studio – Sign-in</title>
|
|
16
|
+
<style>
|
|
17
|
+
:root{--bg:#f6f7fb;--card:#fff;--fg:#14161f;--muted:#5d6475;--ok:#12805c;--err:#c2331f;--accent:#5b5bd6;--line:#e4e6ee}
|
|
18
|
+
@media (prefers-color-scheme:dark){:root{--bg:#0e1017;--card:#171a24;--fg:#eef0f6;--muted:#9aa1b5;--ok:#3ccf9b;--err:#ff7a66;--accent:#8c8cff;--line:#272b3a}}
|
|
19
|
+
*{box-sizing:border-box}
|
|
20
|
+
body{margin:0;min-height:100vh;display:grid;place-items:center;background:var(--bg);color:var(--fg);font:16px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif;padding:16px}
|
|
21
|
+
.card{width:100%;max-width:26rem;background:var(--card);border:1px solid var(--line);border-radius:16px;padding:2rem 1.75rem;text-align:center;box-shadow:0 8px 30px rgba(0,0,0,.08)}
|
|
22
|
+
.brand{font-weight:600;letter-spacing:.02em;color:var(--accent);margin-bottom:1.25rem}
|
|
23
|
+
.icon{width:56px;height:56px;margin:0 auto 1rem;border-radius:50%;display:grid;place-items:center;font-size:28px;color:#fff;background:var(--accent)}
|
|
24
|
+
.ok .icon{background:var(--ok)}.err .icon{background:var(--err)}
|
|
25
|
+
.spin .icon{background:none;border:4px solid var(--line);border-top-color:var(--accent);animation:r 1s linear infinite;font-size:0}
|
|
26
|
+
@keyframes r{to{transform:rotate(360deg)}}
|
|
27
|
+
h1{font-size:1.3rem;margin:0 0 .5rem}
|
|
28
|
+
p{margin:0;color:var(--muted)}
|
|
29
|
+
.note{margin-top:1.5rem;padding-top:1rem;border-top:1px solid var(--line);font-size:.8rem}
|
|
30
|
+
</style></head>
|
|
31
|
+
<body>
|
|
32
|
+
<main class="card spin" id="c">
|
|
33
|
+
<div class="brand">Gen AI Studio</div>
|
|
34
|
+
<div class="icon" id="i"></div>
|
|
35
|
+
<h1 id="t">Connecting…</h1>
|
|
36
|
+
<p id="m">Finishing your sign-in, one moment.</p>
|
|
37
|
+
<p class="note">This page is served by the Gen AI Studio connector running on your own computer (127.0.0.1). Your sign-in never leaves this machine.</p>
|
|
38
|
+
</main>
|
|
15
39
|
<script>
|
|
16
40
|
(async () => {
|
|
17
|
-
const
|
|
41
|
+
const set = (cls, icon, title, msg) => {
|
|
42
|
+
document.getElementById("c").className = "card " + cls;
|
|
43
|
+
document.getElementById("i").textContent = icon;
|
|
44
|
+
document.getElementById("t").textContent = title;
|
|
45
|
+
document.getElementById("m").textContent = msg;
|
|
46
|
+
};
|
|
18
47
|
try {
|
|
19
48
|
const fields = Object.fromEntries(new URLSearchParams(location.hash.slice(1)));
|
|
20
49
|
history.replaceState(null, "", location.pathname);
|
|
21
50
|
const r = await fetch("/token", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(fields) });
|
|
22
|
-
|
|
23
|
-
|
|
51
|
+
if (r.ok) set("ok", "\\u2713", "You're connected", "You can close this tab and go back to Claude.");
|
|
52
|
+
else set("err", "!", "Could not connect", "Start the login again from Claude.");
|
|
53
|
+
} catch (e) { set("err", "!", "Could not connect", "Start the login again from Claude."); }
|
|
24
54
|
})();
|
|
25
|
-
</script
|
|
55
|
+
</script>
|
|
56
|
+
</body></html>`;
|
|
26
57
|
const REQUIRED = ["state", "access_token", "refresh_token", "mcp_session", "session_expires_at"];
|
|
27
58
|
function sameString(a, b) {
|
|
28
59
|
const x = Buffer.from(a);
|
package/dist/src/server.js
CHANGED
|
@@ -4,6 +4,7 @@ export const VERSION = "0.1.0";
|
|
|
4
4
|
const INSTRUCTIONS = `Gen AI Studio gives you authenticated access to GPU generation APIs (images, video, audio). You call the APIs yourself over HTTP; these tools only sign in, pick the account and explain the APIs.
|
|
5
5
|
Start: status, then login if needed, then list_accounts and use_account. use_account returns base_url, a token (valid about an hour; status gives a fresh one) and project_id.
|
|
6
6
|
Before calling a model: list_models, then api_details (why, modes, limits, pitfalls, example, live fields) or list_model_apis (exact fields read live from the gateway).
|
|
7
|
+
To make something of a person, call get_influencer_world first: it gives her character-sheet pictures (as local files), her cast, voice and style so you use the right references.
|
|
7
8
|
Always LOOK at what you make (open images; view_video_frames for video) next to the reference before accepting it, and say plainly what is right and wrong.
|
|
8
9
|
Generation costs real money and the gateway does not stop you at the monthly limit: use drafts first, check list_accounts for the remaining allowance, and never start a batch you cannot afford.
|
|
9
10
|
Never write the token into files, commit messages or anything that leaves this computer.`;
|
package/dist/src/tools.js
CHANGED
|
@@ -10,6 +10,7 @@ import { UserError, clearSession, configuredBaseUrl, loadSession, outputDir } fr
|
|
|
10
10
|
import { contactSheet, probe, shrinkForViewing } from "./ffmpeg.js";
|
|
11
11
|
import { connection, fetchSpec, requireAccount, selectAccount } from "./gateway.js";
|
|
12
12
|
import { formatOperations, operationsFor } from "./spec.js";
|
|
13
|
+
import { findInfluencer, listInfluencers, loadWorld } from "./world.js";
|
|
13
14
|
const text = (value) => ({
|
|
14
15
|
content: [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value, null, 2) }],
|
|
15
16
|
});
|
|
@@ -160,6 +161,28 @@ export function registerTools(server) {
|
|
|
160
161
|
}
|
|
161
162
|
return { content: [{ type: "text", text: JSON.stringify(doc, null, 2) }, { type: "text", text: live }] };
|
|
162
163
|
}));
|
|
164
|
+
// ---- influencer worlds: the references to generate from -----------------------------------
|
|
165
|
+
server.registerTool("get_influencer_world", {
|
|
166
|
+
title: "Influencer worlds",
|
|
167
|
+
description: "Without an argument: every influencer on the selected account. With influencer (name, handle or id): her whole world - bible, cast (each character with role, sheet text and character-sheet pictures saved to local files you can pass as flux2 image_1), voice samples, the posts that show her style, her project_id and the context text. Use this to pick the right reference pictures before generating.",
|
|
168
|
+
inputSchema: {
|
|
169
|
+
influencer: z.string().optional().describe("Name, handle or id; leave out to list all."),
|
|
170
|
+
download: z.boolean().default(true).describe("Save the sheet pictures and voice samples to the output folder and return their paths."),
|
|
171
|
+
},
|
|
172
|
+
annotations: { readOnlyHint: true },
|
|
173
|
+
}, ({ influencer, download }) => guard(async () => {
|
|
174
|
+
if (!influencer) {
|
|
175
|
+
const all = await listInfluencers();
|
|
176
|
+
return text(all.length
|
|
177
|
+
? { influencers: all, next: "Call get_influencer_world with influencer set to a name to see her cast and reference pictures." }
|
|
178
|
+
: "No influencers on this account yet. Create one in the web app first.");
|
|
179
|
+
}
|
|
180
|
+
const world = await loadWorld(await findInfluencer(influencer), download);
|
|
181
|
+
return text({
|
|
182
|
+
...world,
|
|
183
|
+
how_to_use: "For a picture of her: POST /flux2/ with image_1 = a sheet file of the person (ready_as_reference must be true), image_2 = the scene reference; save generations under influencer.project_id to keep them in her folder. Characters with no sheet pictures cannot be generated consistently yet.",
|
|
184
|
+
});
|
|
185
|
+
}));
|
|
163
186
|
// ---- looking at video ---------------------------------------------------------------------
|
|
164
187
|
server.registerTool("view_video_frames", {
|
|
165
188
|
title: "Look at a video",
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// An influencer's world as Claude needs it for references: who she is, her cast with their
|
|
2
|
+
// character-sheet pictures (saved locally so they can be passed to a generator), her voice
|
|
3
|
+
// samples, and the posts that show her style. Read from the selected account's gateway.
|
|
4
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { authedFetch } from "./auth.js";
|
|
7
|
+
import { UserError, outputDir } from "./core.js";
|
|
8
|
+
import { requireAccount } from "./gateway.js";
|
|
9
|
+
const obj = (value) => (value && typeof value === "object" ? value : {});
|
|
10
|
+
const list = (value) => (Array.isArray(value) ? value.map(obj) : []);
|
|
11
|
+
const str = (value) => (typeof value === "string" && value ? value : undefined);
|
|
12
|
+
async function gatewayJson(route) {
|
|
13
|
+
const account = await requireAccount();
|
|
14
|
+
const response = await authedFetch(`${account.base_url}${route}`).catch((error) => {
|
|
15
|
+
if (error instanceof UserError)
|
|
16
|
+
throw error;
|
|
17
|
+
throw new UserError(`Could not reach the gateway of "${account.name}" (${error.message}).`);
|
|
18
|
+
});
|
|
19
|
+
if (response.status === 404)
|
|
20
|
+
throw new UserError(`Not found on "${account.name}": ${route}. Influencers are stored per login; is this the right account?`);
|
|
21
|
+
if (!response.ok)
|
|
22
|
+
throw new UserError(`The gateway answered ${response.status} for ${route}.`);
|
|
23
|
+
return response.json();
|
|
24
|
+
}
|
|
25
|
+
export async function listInfluencers() {
|
|
26
|
+
return list(await gatewayJson("/influencers/")).map((row) => ({
|
|
27
|
+
id: String(row.id),
|
|
28
|
+
name: String(row.name),
|
|
29
|
+
handle: str(row.handle),
|
|
30
|
+
age: typeof row.age === "number" ? row.age : undefined,
|
|
31
|
+
niche: str(row.niche),
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
/** One influencer by id, exact name or handle (case-insensitive); a clear error when none or several match. */
|
|
35
|
+
export async function findInfluencer(needle) {
|
|
36
|
+
const all = await listInfluencers();
|
|
37
|
+
const key = needle.trim().toLowerCase();
|
|
38
|
+
const exact = all.filter((i) => i.id === needle.trim() || i.name.toLowerCase() === key || (i.handle ?? "").toLowerCase() === key);
|
|
39
|
+
const found = exact.length ? exact : all.filter((i) => i.name.toLowerCase().includes(key));
|
|
40
|
+
if (found.length === 1)
|
|
41
|
+
return found[0];
|
|
42
|
+
throw new UserError(found.length === 0
|
|
43
|
+
? `No influencer matches "${needle}". Known: ${all.map((i) => i.name).join(", ") || "(none)"}.`
|
|
44
|
+
: `"${needle}" matches several influencers (${found.map((i) => i.name).join(", ")}). Use the exact name or the id.`);
|
|
45
|
+
}
|
|
46
|
+
const EXTENSIONS = { "image/png": ".png", "image/jpeg": ".jpg", "image/webp": ".webp", "audio/wav": ".wav", "audio/mpeg": ".mp3", "audio/x-wav": ".wav" };
|
|
47
|
+
const safe = (value) => value.replace(/[^a-z0-9_-]+/gi, "_").slice(0, 40) || "file";
|
|
48
|
+
/** Saves one picture or audio file next to the others; returns its path, or null when it cannot be fetched. */
|
|
49
|
+
async function saveFile(url, folder, stem) {
|
|
50
|
+
try {
|
|
51
|
+
const account = await requireAccount();
|
|
52
|
+
// Files on the gateway need the login; public storage addresses must not receive it.
|
|
53
|
+
const sameHost = new URL(url).origin === new URL(account.base_url).origin;
|
|
54
|
+
const response = sameHost ? await authedFetch(url) : await fetch(url);
|
|
55
|
+
if (!response.ok)
|
|
56
|
+
return null;
|
|
57
|
+
const type = (response.headers.get("content-type") ?? "").split(";")[0].trim();
|
|
58
|
+
await mkdir(folder, { recursive: true });
|
|
59
|
+
const file = path.join(folder, `${safe(stem)}${EXTENSIONS[type] ?? path.extname(new URL(url).pathname) ?? ""}`);
|
|
60
|
+
await writeFile(file, Buffer.from(await response.arrayBuffer()));
|
|
61
|
+
return file;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const MAX_POSTS = 30;
|
|
68
|
+
const MAX_FILES = 24;
|
|
69
|
+
export async function loadWorld(summary, download) {
|
|
70
|
+
const data = obj(await gatewayJson(`/influencers/${encodeURIComponent(summary.id)}`));
|
|
71
|
+
const influencer = obj(data.influencer);
|
|
72
|
+
const context = str(obj(await gatewayJson(`/influencers/${encodeURIComponent(summary.id)}/context`)).context);
|
|
73
|
+
const folder = path.join(outputDir(), "influencers", safe(summary.name));
|
|
74
|
+
let saved = 0;
|
|
75
|
+
const budget = () => download && saved++ < MAX_FILES;
|
|
76
|
+
const characters = [];
|
|
77
|
+
for (const row of list(data.characters)) {
|
|
78
|
+
const name = String(row.name);
|
|
79
|
+
const images = [];
|
|
80
|
+
let n = 0;
|
|
81
|
+
for (const image of list(row.sheet_images)) {
|
|
82
|
+
n += 1;
|
|
83
|
+
const url = str(image.url);
|
|
84
|
+
images.push({ label: str(image.label), url, file: url && budget() ? await saveFile(url, folder, `${name}_sheet_${n}`) : null });
|
|
85
|
+
}
|
|
86
|
+
const voice = str(obj(row.voice_sample).url);
|
|
87
|
+
characters.push({
|
|
88
|
+
id: row.id,
|
|
89
|
+
role: row.role,
|
|
90
|
+
name,
|
|
91
|
+
sheet: row.sheet,
|
|
92
|
+
sheet_images: images,
|
|
93
|
+
voice_sample: voice ? { url: voice, file: budget() ? await saveFile(voice, folder, `${name}_voice`) : null } : null,
|
|
94
|
+
ready_as_reference: images.length > 0,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const allPosts = list(data.posts);
|
|
98
|
+
const posts = allPosts.slice(0, MAX_POSTS).map((post) => ({
|
|
99
|
+
id: post.id,
|
|
100
|
+
kind: post.kind,
|
|
101
|
+
caption: str(post.caption),
|
|
102
|
+
description: str(post.description),
|
|
103
|
+
media: list(post.media).map((m) => ({ type: m.media_type, thumb_url: str(m.thumb_url), original_url: m.original_deleted ? undefined : str(m.original_url) })),
|
|
104
|
+
}));
|
|
105
|
+
return {
|
|
106
|
+
influencer: {
|
|
107
|
+
id: influencer.id,
|
|
108
|
+
name: influencer.name,
|
|
109
|
+
handle: str(influencer.handle),
|
|
110
|
+
age: influencer.age,
|
|
111
|
+
niche: str(influencer.niche),
|
|
112
|
+
profile: influencer.profile,
|
|
113
|
+
lora_id: str(influencer.lora_id),
|
|
114
|
+
project_id: str(influencer.project_id),
|
|
115
|
+
},
|
|
116
|
+
characters,
|
|
117
|
+
posts,
|
|
118
|
+
posts_total: allPosts.length,
|
|
119
|
+
saved_to: download ? folder : undefined,
|
|
120
|
+
context_text: context,
|
|
121
|
+
};
|
|
122
|
+
}
|
package/dist/test/helpers.js
CHANGED
|
@@ -122,10 +122,13 @@ export async function startFakeApp(gatewayUrl) {
|
|
|
122
122
|
const port = await listen(server);
|
|
123
123
|
return { url: `http://127.0.0.1:${port}`, state, close: () => new Promise((r) => { server.closeAllConnections(); server.close(() => r()); }) };
|
|
124
124
|
}
|
|
125
|
+
/** A 1x1 PNG. */
|
|
126
|
+
const PNG = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/q842iQAAAABJRU5ErkJggg==", "base64");
|
|
125
127
|
/** Plays an account's gateway: serves the real OpenAPI document (a fixture generated from the routers) to a logged-in caller only. */
|
|
126
128
|
export async function startFakeGateway() {
|
|
127
129
|
const spec = await readFile(new URL("../../test/fixtures/api-spec.json", import.meta.url), "utf8");
|
|
128
|
-
|
|
130
|
+
let storageUrl = "";
|
|
131
|
+
const gateway = { url: "", specAuth: [], noSpec: false, fileAuth: [], publicAuth: [], close: async () => undefined };
|
|
129
132
|
const server = http.createServer((req, res) => {
|
|
130
133
|
const url = new URL(req.url ?? "/", "http://x");
|
|
131
134
|
if (url.pathname === "/api-spec") {
|
|
@@ -136,11 +139,57 @@ export async function startFakeGateway() {
|
|
|
136
139
|
return send(res, 401, { detail: "Login required" });
|
|
137
140
|
return send(res, 200, JSON.parse(spec));
|
|
138
141
|
}
|
|
142
|
+
// Influencer routes: owner-only, so they answer 401 without a login.
|
|
143
|
+
if (url.pathname.startsWith("/influencers/") && !req.headers.authorization)
|
|
144
|
+
return send(res, 401, { detail: "Login required" });
|
|
145
|
+
if (url.pathname === "/influencers/") {
|
|
146
|
+
return send(res, 200, [
|
|
147
|
+
{ id: "inf-1", name: "Elena Rossi", handle: "@elena", age: 27, niche: "fashion" },
|
|
148
|
+
{ id: "inf-2", name: "Elena Moss", handle: "@moss", age: 30, niche: "travel" },
|
|
149
|
+
{ id: "inf-3", name: "Mira", handle: null, age: null, niche: null },
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
if (url.pathname === "/influencers/inf-3") {
|
|
153
|
+
return send(res, 200, { influencer: { id: "inf-3", name: "Mira", project_id: null, profile: {} }, characters: [{ id: "c9", role: "main", name: "Mira", sheet: {}, sheet_images: [], voice_sample: null }], posts: [] });
|
|
154
|
+
}
|
|
155
|
+
if (url.pathname === "/influencers/inf-1") {
|
|
156
|
+
const own = `${gateway.url}/files/sheet-front`;
|
|
157
|
+
return send(res, 200, {
|
|
158
|
+
influencer: { id: "inf-1", name: "Elena Rossi", handle: "@elena", age: 27, niche: "fashion", profile: { style: "quiet luxury" }, lora_id: null, project_id: "11111111-1111-4111-8111-111111111111" },
|
|
159
|
+
characters: [
|
|
160
|
+
{ id: "c1", role: "main", name: "Elena Rossi", sheet: { hair: "dark" }, sheet_images: [{ label: "front", url: own }, { label: "side", url: `${storageUrl}/public/sheet-side.png` }, { label: "gone", url: `${storageUrl}/public/missing.png` }], voice_sample: { url: `${storageUrl}/public/voice.wav` } },
|
|
161
|
+
{ id: "c2", role: "mother", name: "Anna", sheet: {}, sheet_images: [], voice_sample: null },
|
|
162
|
+
],
|
|
163
|
+
posts: [{ id: "p1", kind: "reel", caption: "Morning", description: "She turns in a sunlit hallway", media: [{ media_type: "video", thumb_url: `${storageUrl}/public/t.jpg`, original_url: `${storageUrl}/public/o.mp4`, original_deleted: true }] }],
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (url.pathname === "/influencers/inf-1/context")
|
|
167
|
+
return send(res, 200, { context: "INFLUENCER: Elena Rossi (@elena)" });
|
|
168
|
+
if (/^\/influencers\/inf-\d\/context$/.test(url.pathname))
|
|
169
|
+
return send(res, 200, { context: "INFLUENCER: someone" });
|
|
170
|
+
if (url.pathname === "/files/sheet-front") {
|
|
171
|
+
gateway.fileAuth.push(req.headers.authorization);
|
|
172
|
+
return send(res, 200, PNG, { "Content-Type": "image/png" });
|
|
173
|
+
}
|
|
139
174
|
return send(res, 404, {});
|
|
140
175
|
});
|
|
176
|
+
// Public storage is another host (like Supabase storage): it must never see the login.
|
|
177
|
+
const storage = http.createServer((req, res) => {
|
|
178
|
+
const url = new URL(req.url ?? "/", "http://x");
|
|
179
|
+
gateway.publicAuth.push(req.headers.authorization);
|
|
180
|
+
if (url.pathname.endsWith("missing.png"))
|
|
181
|
+
return send(res, 404, {});
|
|
182
|
+
const wav = url.pathname.endsWith(".wav");
|
|
183
|
+
return send(res, 200, wav ? Buffer.from("RIFFxxxxWAVE") : PNG, { "Content-Type": wav ? "audio/wav" : "image/png" });
|
|
184
|
+
});
|
|
185
|
+
const storagePort = await listen(storage);
|
|
186
|
+
storageUrl = `http://127.0.0.1:${storagePort}`;
|
|
141
187
|
const port = await listen(server);
|
|
142
188
|
gateway.url = `http://127.0.0.1:${port}`;
|
|
143
|
-
gateway.close =
|
|
189
|
+
gateway.close = async () => {
|
|
190
|
+
for (const s of [server, storage])
|
|
191
|
+
await new Promise((r) => { s.closeAllConnections(); s.close(() => r()); });
|
|
192
|
+
};
|
|
144
193
|
return gateway;
|
|
145
194
|
}
|
|
146
195
|
// ---------------------------------------------------------------------------------------------
|
package/dist/test/stdio.test.js
CHANGED
|
@@ -25,6 +25,7 @@ after(async () => {
|
|
|
25
25
|
const EXPECTED = [
|
|
26
26
|
"login", "logout", "status", "list_accounts", "use_account", "get_usage",
|
|
27
27
|
"list_models", "list_model_apis", "api_details",
|
|
28
|
+
"get_influencer_world",
|
|
28
29
|
"view_video_frames",
|
|
29
30
|
];
|
|
30
31
|
test("the packaged server starts over stdio and lists every tool with a description and a schema", async () => {
|
package/dist/test/tools.test.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
2
3
|
import { after, before, test } from "node:test";
|
|
3
4
|
import { setBrowserOpener } from "../src/auth.js";
|
|
4
5
|
import { loadSession } from "../src/core.js";
|
|
@@ -134,6 +135,47 @@ test("api_details still gives the guide when the live spec cannot be read", asyn
|
|
|
134
135
|
assert.match(textOf(result), /Live routes could not be read/);
|
|
135
136
|
gateway.noSpec = false;
|
|
136
137
|
});
|
|
138
|
+
test("get_influencer_world lists every influencer when asked for none", async () => {
|
|
139
|
+
const info = JSON.parse(textOf(await call("get_influencer_world")));
|
|
140
|
+
assert.deepEqual(info.influencers.map((i) => i.name), ["Elena Rossi", "Elena Moss", "Mira"]);
|
|
141
|
+
assert.match(info.next, /influencer set to a name/);
|
|
142
|
+
});
|
|
143
|
+
test("get_influencer_world returns the cast, saves sheet pictures and voice, and keeps the login off public files", async () => {
|
|
144
|
+
const before = { own: gateway.fileAuth.length, pub: gateway.publicAuth.length };
|
|
145
|
+
const world = JSON.parse(textOf(await call("get_influencer_world", { influencer: "@ELENA" })));
|
|
146
|
+
assert.equal(world.influencer.project_id, "11111111-1111-4111-8111-111111111111");
|
|
147
|
+
assert.match(world.context_text, /INFLUENCER: Elena Rossi/);
|
|
148
|
+
const [elena, anna] = world.characters;
|
|
149
|
+
assert.equal(elena.ready_as_reference, true);
|
|
150
|
+
assert.equal(anna.ready_as_reference, false, "a person with no sheet pictures is not ready");
|
|
151
|
+
const files = elena.sheet_images.map((i) => i.file);
|
|
152
|
+
assert.ok(files[0] && files[1], "front and side are saved");
|
|
153
|
+
assert.equal(files[2], null, "a picture that cannot be fetched is reported, not fatal");
|
|
154
|
+
assert.ok((await stat(files[0])).size > 50);
|
|
155
|
+
assert.match(files[0], /\.png$/);
|
|
156
|
+
assert.match(elena.voice_sample.file, /\.wav$/);
|
|
157
|
+
assert.equal(world.posts[0].description, "She turns in a sunlit hallway");
|
|
158
|
+
assert.equal(world.posts[0].media[0].original_url, undefined, "a deleted original is not offered");
|
|
159
|
+
assert.equal(gateway.fileAuth.length, before.own + 1);
|
|
160
|
+
assert.equal(gateway.fileAuth.at(-1), "Bearer access-1", "gateway files get the login");
|
|
161
|
+
assert.ok(gateway.publicAuth.length > before.pub);
|
|
162
|
+
assert.ok(gateway.publicAuth.slice(before.pub).every((h) => h === undefined), "public storage must never receive the token");
|
|
163
|
+
assert.match(world.saved_to, /influencers/);
|
|
164
|
+
});
|
|
165
|
+
test("get_influencer_world with download=false saves nothing", async () => {
|
|
166
|
+
const world = JSON.parse(textOf(await call("get_influencer_world", { influencer: "inf-1", download: false })));
|
|
167
|
+
assert.ok(world.characters[0].sheet_images.every((i) => i.file === null));
|
|
168
|
+
assert.equal(world.saved_to, undefined);
|
|
169
|
+
});
|
|
170
|
+
test("get_influencer_world explains an unknown or ambiguous name", async () => {
|
|
171
|
+
assert.match(textOf(await call("get_influencer_world", { influencer: "Nobody" })), /No influencer matches "Nobody"\. Known: Elena Rossi/);
|
|
172
|
+
assert.match(textOf(await call("get_influencer_world", { influencer: "elena" })), /several influencers/);
|
|
173
|
+
});
|
|
174
|
+
test("an influencer with no sheet pictures says she is not ready", async () => {
|
|
175
|
+
const world = JSON.parse(textOf(await call("get_influencer_world", { influencer: "Mira" })));
|
|
176
|
+
assert.equal(world.characters[0].ready_as_reference, false);
|
|
177
|
+
assert.equal(world.influencer.project_id, undefined);
|
|
178
|
+
});
|
|
137
179
|
test("an expired access token is renewed silently in the middle of a tool call", async () => {
|
|
138
180
|
app.state.valid.delete("access-1");
|
|
139
181
|
const before = app.state.refreshCount;
|
package/package.json
CHANGED