sovkora 0.0.0-stage → 1.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.
- package/LICENSE +202 -0
- package/NOTICE +9 -0
- package/README.md +67 -2
- package/dist/commands/agent.command.js +267 -0
- package/dist/commands/chat.command.js +214 -0
- package/dist/commands/chat.handlers.js +150 -0
- package/dist/commands/chat.types.js +44 -0
- package/dist/commands/cinema.command.js +643 -0
- package/dist/commands/config.command.js +228 -0
- package/dist/commands/db.command.js +114 -0
- package/dist/commands/demo.command.js +55 -0
- package/dist/commands/dev.command.js +462 -0
- package/dist/commands/docs.command.js +135 -0
- package/dist/commands/doctor.command.js +119 -0
- package/dist/commands/forgot.command.js +57 -0
- package/dist/commands/generate.command.js +376 -0
- package/dist/commands/graph.command.js +54 -0
- package/dist/commands/init.command.js +380 -0
- package/dist/commands/init.steps.js +115 -0
- package/dist/commands/install.command.js +459 -0
- package/dist/commands/login.command.js +110 -0
- package/dist/commands/logs.command.js +215 -0
- package/dist/commands/logs.steps.js +130 -0
- package/dist/commands/mcp.command.js +104 -0
- package/dist/commands/models.command.js +164 -0
- package/dist/commands/onboard.command.js +236 -0
- package/dist/commands/pack.command.js +255 -0
- package/dist/commands/profile.command.js +51 -0
- package/dist/commands/recover.command.js +489 -0
- package/dist/commands/register.command.js +94 -0
- package/dist/commands/release.command.js +99 -0
- package/dist/commands/reset.command.js +79 -0
- package/dist/commands/runs.command.js +201 -0
- package/dist/commands/settings.command.js +85 -0
- package/dist/commands/start.command.js +590 -0
- package/dist/commands/status.command.js +167 -0
- package/dist/commands/stop.command.js +313 -0
- package/dist/commands/studio.command.js +266 -0
- package/dist/commands/test.command.js +134 -0
- package/dist/commands/verify.command.js +52 -0
- package/dist/commands/video.command.js +73 -0
- package/dist/commands/workspace-guard.js +72 -0
- package/dist/index.js +207 -0
- package/dist/renderers.js +250 -0
- package/dist/services/api-client.js +150 -0
- package/dist/services/auth.api.js +87 -0
- package/dist/services/chat.api.js +117 -0
- package/dist/services/cinema-estimate.json +42 -0
- package/dist/services/cinema.childsafe.js +52 -0
- package/dist/services/cinema.director.js +285 -0
- package/dist/services/cinema.production.js +417 -0
- package/dist/services/cinema.staging.js +323 -0
- package/dist/services/cinema.story.js +758 -0
- package/dist/services/cinema.treatment.js +393 -0
- package/dist/services/composer.run.js +94 -0
- package/dist/services/demo/demo.documents.js +108 -0
- package/dist/services/demo/demo.guard.js +49 -0
- package/dist/services/demo/demo.persona.js +114 -0
- package/dist/services/demo/demo.seed.js +281 -0
- package/dist/services/diagnostics.js +327 -0
- package/dist/services/image-model-recipes.json +93 -0
- package/dist/services/image-models.js +152 -0
- package/dist/services/local-store.js +145 -0
- package/dist/services/mcp.api.js +38 -0
- package/dist/services/model-catalog.js +70 -0
- package/dist/services/notify.js +55 -0
- package/dist/services/pack.api.js +23 -0
- package/dist/services/pack.bundle.js +241 -0
- package/dist/services/pack.sources.js +101 -0
- package/dist/services/release-manifest.js +266 -0
- package/dist/services/runs.view.js +80 -0
- package/dist/services/runs.wait.js +38 -0
- package/dist/services/semver.js +55 -0
- package/dist/services/settings.api.js +108 -0
- package/dist/services/string-utils.js +70 -0
- package/dist/services/studio.api.js +120 -0
- package/dist/services/templates.js +893 -0
- package/dist/services/tool-installer.js +353 -0
- package/dist/services/tool-path.js +72 -0
- package/dist/services/version-manager.js +253 -0
- package/dist/services/workspace-bootstrap.js +68 -0
- package/dist/threads.js +202 -0
- package/dist/types/api.types.js +6 -0
- package/dist/types/local.types.js +6 -0
- package/dist/ui/box.js +46 -0
- package/dist/ui/logger.js +28 -0
- package/dist/ui/platform.js +32 -0
- package/dist/ui/prompts.js +130 -0
- package/dist/ui/table.js +33 -0
- package/dist/utils/config.js +150 -0
- package/dist/utils/development-status.js +22 -0
- package/dist/utils/endpoints.js +41 -0
- package/dist/utils/health.js +94 -0
- package/dist/utils/pid.js +83 -0
- package/dist/utils/platform.js +358 -0
- package/dist/utils/process.js +139 -0
- package/dist/utils/state-dir.js +105 -0
- package/package.json +95 -4
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file demo.persona.ts
|
|
4
|
+
* @description The demonstration persona: who signs in when Sovkora is shown to a client.
|
|
5
|
+
*
|
|
6
|
+
* "admin" is a role, not a person — nobody watching a demo can picture themselves in it. Eric is
|
|
7
|
+
* an invented head of sales at an invented Montréal lighting studio (it sells in Canadian dollars): a first name a client can read at a
|
|
8
|
+
* glance, a generic surname, a reserved e-mail domain (RFC 2606, `example.com`, never delivered)
|
|
9
|
+
* and no avatar but his initial. Nothing here describes a real person or a real company.
|
|
10
|
+
*
|
|
11
|
+
* Pure data: the seeder (demo.seed.ts) decides how each line reaches the platform.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DEMO_RUNS = exports.DEMO_STUDIOS = exports.DEMO_PACKS = exports.DEMO_CREDITS = exports.DEMO_PLAN = exports.DEMO_PERSONA = void 0;
|
|
15
|
+
const demo_documents_1 = require("./demo.documents");
|
|
16
|
+
/** The account and the profile answers a new user gives at onboarding. */
|
|
17
|
+
exports.DEMO_PERSONA = {
|
|
18
|
+
/** What the application greets: "Good evening, Eric". */
|
|
19
|
+
username: "Eric",
|
|
20
|
+
fullName: "Eric Morel",
|
|
21
|
+
email: "eric.morel@example.com",
|
|
22
|
+
/**
|
|
23
|
+
* Eric's sign-in on a local stack, public by design and no secret: `sovkora demo seed` prints it at the end of every
|
|
24
|
+
* run, the web client's tour script (apps/web/scripts/tour/eric.mjs) holds the same, and the seeder refuses any target
|
|
25
|
+
* but a local, non-deployed one (demo.guard.ts). DEMO_PASSWORD replaces it.
|
|
26
|
+
*/
|
|
27
|
+
publicSignIn: "Demo-Lumen-2026",
|
|
28
|
+
language: "en",
|
|
29
|
+
company: "Lumen Atelier",
|
|
30
|
+
/** Onboarding answers (krizaka-users stores them as profile attributes, never interprets them). */
|
|
31
|
+
onboarding: {
|
|
32
|
+
theme: "amber",
|
|
33
|
+
voiceModel: "nova",
|
|
34
|
+
primaryIndustry: "creative",
|
|
35
|
+
aiBehavior: "Eric leads sales at Lumen Atelier, a small Montréal studio that designs ceramic lamps. Prices are in Canadian dollars. Answer clearly, in short paragraphs, and end with the next step.",
|
|
36
|
+
},
|
|
37
|
+
/** Preferences the client reads (profile → Appearance, chat defaults). */
|
|
38
|
+
preferences: {
|
|
39
|
+
language: "en",
|
|
40
|
+
"tts-voice": "nova",
|
|
41
|
+
"image-aspect-ratio": "4:3",
|
|
42
|
+
"chat-temperature": 0.6,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
/** The plan Eric is on: the paid tier a client would buy, so every Studio below is unlocked. */
|
|
46
|
+
exports.DEMO_PLAN = "premium";
|
|
47
|
+
/** Credits in his wallet: the premium period grant in v2 credits (ADR-047: 5 000 × 10). */
|
|
48
|
+
exports.DEMO_CREDITS = 50_000;
|
|
49
|
+
/**
|
|
50
|
+
* Packs Eric holds. `orazaka-media` (generate, listen, describe) is included with every plan;
|
|
51
|
+
* `outbound-prospection` is the sales pack a head of sales would buy; `document-validation` checks the
|
|
52
|
+
* leases and supplier invoices that cross his desk.
|
|
53
|
+
*/
|
|
54
|
+
exports.DEMO_PACKS = ["orazaka-media", "outbound-prospection", "document-validation"];
|
|
55
|
+
/** Studios on his shelf — what a sales lead at a product company uses in a week. */
|
|
56
|
+
exports.DEMO_STUDIOS = [
|
|
57
|
+
"image-generation",
|
|
58
|
+
"video-generation",
|
|
59
|
+
"speech-synthesis",
|
|
60
|
+
"image-analysis",
|
|
61
|
+
"compliance-check",
|
|
62
|
+
"document-authenticity",
|
|
63
|
+
"lead-research",
|
|
64
|
+
"outbound-prospection",
|
|
65
|
+
"followup-sequences",
|
|
66
|
+
];
|
|
67
|
+
/**
|
|
68
|
+
* The work on his shelf after `sovkora demo seed --runs`: a product photo, a voice-over for the same lamp, a
|
|
69
|
+
* prospect dossier, a lease checked against the law, a supplier invoice examined for tampering — and, with
|
|
70
|
+
* `--with-video`, a few seconds of footage. Every result is generated on this machine by the real Studios;
|
|
71
|
+
* the documents are invented (demo.documents.ts).
|
|
72
|
+
*/
|
|
73
|
+
exports.DEMO_RUNS = [
|
|
74
|
+
{
|
|
75
|
+
studioKey: "image-generation",
|
|
76
|
+
inputs: {
|
|
77
|
+
prompt: "Studio product photo of a hand-glazed ceramic table lamp, warm amber glow, dark slate plinth, deep ink-blue background, soft rim light",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
studioKey: "speech-synthesis",
|
|
82
|
+
inputs: {
|
|
83
|
+
text: "Meet Ember, our new table lamp. Shaped by hand in Montréal, glazed in amber, and lit to make an evening feel like home.",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
studioKey: "lead-research",
|
|
88
|
+
inputs: {
|
|
89
|
+
prospects: [
|
|
90
|
+
"Maison Lumière, concept store, Montréal",
|
|
91
|
+
"Auberge des Érables, boutique hotel, Québec City",
|
|
92
|
+
"Atelier Nord, interior architects, Toronto",
|
|
93
|
+
],
|
|
94
|
+
offer: "Hand-glazed ceramic lamps made to order, delivered in four weeks",
|
|
95
|
+
icp: "Boutique hotels and interior architects furnishing 10 to 60 rooms",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{ studioKey: "compliance-check", inputs: { document: demo_documents_1.DEMO_LEASE, jurisdiction: "FR" } },
|
|
99
|
+
{
|
|
100
|
+
studioKey: "document-authenticity",
|
|
101
|
+
inputs: () => ({ documentBase64: (0, demo_documents_1.demoInvoicePdf)().toString("base64"), expectedIssuer: "Emaux & Terres" }),
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
studioKey: "video-generation",
|
|
105
|
+
// The text-to-video pipeline by name: the catalogue's default video model is an image-to-video one, which starts
|
|
106
|
+
// from a still and refuses this machine's memory without it.
|
|
107
|
+
inputs: {
|
|
108
|
+
prompt: "Slow orbit around a glowing amber ceramic table lamp on a dark slate plinth, soft light, ink-blue background",
|
|
109
|
+
durationSeconds: 4,
|
|
110
|
+
model: "ByteDance/AnimateDiff-Lightning",
|
|
111
|
+
},
|
|
112
|
+
heavy: true,
|
|
113
|
+
},
|
|
114
|
+
];
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file demo.seed.ts
|
|
4
|
+
* @description Puts the demo persona (demo.persona.ts) on a local stack through the platform's own
|
|
5
|
+
* public API — the same calls a person makes in the application, never a write into a database.
|
|
6
|
+
*
|
|
7
|
+
* Every step is replayable: an account that exists is signed into, a verified e-mail is not
|
|
8
|
+
* verified twice, a pack or a Studio already held is left as it is. Running the seed twice gives
|
|
9
|
+
* the state running it once gives.
|
|
10
|
+
*
|
|
11
|
+
* Conversation transcripts are not seeded here: the web client keeps them in the browser that held
|
|
12
|
+
* them (useMessageHistory), so they are written by holding the conversations in the application
|
|
13
|
+
* (orazaka-web-client `npm run record:tour -- prepare`).
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.DemoSeeder = void 0;
|
|
17
|
+
exports.actorIdOf = actorIdOf;
|
|
18
|
+
exports.verificationTokenIn = verificationTokenIn;
|
|
19
|
+
const demo_guard_1 = require("./demo.guard");
|
|
20
|
+
const demo_persona_1 = require("./demo.persona");
|
|
21
|
+
/** The subject of a session JWT: the actor id every service addresses the user by. */
|
|
22
|
+
function actorIdOf(token) {
|
|
23
|
+
const payload = token.split(".")[1];
|
|
24
|
+
if (!payload)
|
|
25
|
+
throw new Error("The session token is not a JWT.");
|
|
26
|
+
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
27
|
+
if (!claims.sub)
|
|
28
|
+
throw new Error("The session token carries no subject.");
|
|
29
|
+
return claims.sub;
|
|
30
|
+
}
|
|
31
|
+
/** The verification token in the e-mail the notification service sends (`…/verify?token=…`). */
|
|
32
|
+
function verificationTokenIn(text) {
|
|
33
|
+
const match = /verify\?token=([A-Za-z0-9._~%-]+)/.exec(text);
|
|
34
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
35
|
+
}
|
|
36
|
+
class DemoSeeder {
|
|
37
|
+
o;
|
|
38
|
+
constructor(options) {
|
|
39
|
+
this.o = options;
|
|
40
|
+
}
|
|
41
|
+
async run() {
|
|
42
|
+
(0, demo_guard_1.assertLocalDemoTarget)(this.o.baseUrl, this.o.env);
|
|
43
|
+
const login = await this.account();
|
|
44
|
+
const token = login.token;
|
|
45
|
+
const actorId = actorIdOf(token);
|
|
46
|
+
await this.onboarding(token, login.activeInterceptions ?? []);
|
|
47
|
+
if (this.o.fresh)
|
|
48
|
+
await this.clearConversations(token);
|
|
49
|
+
await this.call("PUT", "/api/v1/profile/preferences", token, demo_persona_1.DEMO_PERSONA.preferences);
|
|
50
|
+
this.o.onStep("Preferences set (English, Nova voice, 4:3 visuals)");
|
|
51
|
+
const adminToken = await this.adminToken();
|
|
52
|
+
await this.plan(actorId, adminToken);
|
|
53
|
+
const credits = await this.credits(actorId, adminToken);
|
|
54
|
+
const packs = await this.packs(token);
|
|
55
|
+
const studios = await this.studios(token);
|
|
56
|
+
const runs = this.o.runs ? await this.demoRuns(token) : [];
|
|
57
|
+
return { actorId, email: demo_persona_1.DEMO_PERSONA.email, plan: demo_persona_1.DEMO_PLAN, credits, packs, studios, runs };
|
|
58
|
+
}
|
|
59
|
+
/** Registers the account if needed, verifies it through the local mailbox, and signs in. */
|
|
60
|
+
async account() {
|
|
61
|
+
const { username, email, language } = demo_persona_1.DEMO_PERSONA;
|
|
62
|
+
const res = await this.raw("POST", "/api/v1/auth/register", undefined, {
|
|
63
|
+
username,
|
|
64
|
+
email,
|
|
65
|
+
password: this.o.password,
|
|
66
|
+
language,
|
|
67
|
+
});
|
|
68
|
+
if (res.status === 201) {
|
|
69
|
+
const body = (await res.json());
|
|
70
|
+
this.o.onStep(`Account created: ${username} <${email}>`);
|
|
71
|
+
if (body.requires_verification)
|
|
72
|
+
await this.verify();
|
|
73
|
+
}
|
|
74
|
+
else if (res.status === 409) {
|
|
75
|
+
this.o.onStep(`Account already exists: ${email}`);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw new Error(`Registration failed: HTTP ${res.status} ${await res.text()}`);
|
|
79
|
+
}
|
|
80
|
+
let login = await this.raw("POST", "/api/v1/auth/login", undefined, { email, password: this.o.password });
|
|
81
|
+
if (login.status === 401 && res.status === 409) {
|
|
82
|
+
// An earlier run stopped before verifying: the e-mail is still in the local mailbox.
|
|
83
|
+
await this.verify();
|
|
84
|
+
login = await this.raw("POST", "/api/v1/auth/login", undefined, { email, password: this.o.password });
|
|
85
|
+
}
|
|
86
|
+
if (!login.ok)
|
|
87
|
+
throw new Error(`Sign-in failed for ${email}: HTTP ${login.status}. Was the account created with another DEMO_PASSWORD?`);
|
|
88
|
+
return (await login.json());
|
|
89
|
+
}
|
|
90
|
+
/** Reads the newest verification e-mail for the persona in Mailpit and confirms it. */
|
|
91
|
+
async verify() {
|
|
92
|
+
const deadline = Date.now() + (this.o.mailTimeoutMs ?? 30_000);
|
|
93
|
+
const query = encodeURIComponent(`to:"${demo_persona_1.DEMO_PERSONA.email}"`);
|
|
94
|
+
for (;;) {
|
|
95
|
+
const list = await this.o.fetch(`${this.o.mailUrl}/api/v1/search?query=${query}&limit=5`);
|
|
96
|
+
if (list.ok) {
|
|
97
|
+
const { messages = [] } = (await list.json());
|
|
98
|
+
for (const m of messages) {
|
|
99
|
+
if (await this.confirmFrom(m.ID))
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (Date.now() > deadline) {
|
|
104
|
+
throw new Error(`No verification e-mail for ${demo_persona_1.DEMO_PERSONA.email} in ${this.o.mailUrl}: is the notifications service running?`);
|
|
105
|
+
}
|
|
106
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Confirms the e-mail with the token one mailbox message carries; false when it has none or is refused. */
|
|
110
|
+
async confirmFrom(messageId) {
|
|
111
|
+
const msg = await this.o.fetch(`${this.o.mailUrl}/api/v1/message/${messageId}`);
|
|
112
|
+
const { Text = "", HTML = "" } = (await msg.json());
|
|
113
|
+
const token = verificationTokenIn(Text) ?? verificationTokenIn(HTML);
|
|
114
|
+
if (!token)
|
|
115
|
+
return false;
|
|
116
|
+
const res = await this.raw("POST", "/api/v1/auth/verify", undefined, { token });
|
|
117
|
+
if (res.ok)
|
|
118
|
+
this.o.onStep("E-mail verified through the local mailbox");
|
|
119
|
+
return res.ok;
|
|
120
|
+
}
|
|
121
|
+
/** Removes the conversations Eric holds, through the same endpoint the application's delete uses. */
|
|
122
|
+
async clearConversations(token) {
|
|
123
|
+
const sessions = (await this.call("GET", "/api/v1/chat/sessions", token));
|
|
124
|
+
for (const s of sessions)
|
|
125
|
+
await this.call("DELETE", `/api/v1/chat/sessions/${s.id}`, token);
|
|
126
|
+
this.o.onStep(`Conversations cleared (${sessions.length})`);
|
|
127
|
+
}
|
|
128
|
+
/** Answers the onboarding form a new user meets at first sign-in, as Eric would. */
|
|
129
|
+
async onboarding(token, pending) {
|
|
130
|
+
for (const name of pending) {
|
|
131
|
+
// The web client resolves `/interceptions/<name>` with the name as both type and schema id.
|
|
132
|
+
await this.call("POST", "/api/v1/interceptions/resolve", token, {
|
|
133
|
+
interceptionType: name,
|
|
134
|
+
schemaId: name,
|
|
135
|
+
responses: demo_persona_1.DEMO_PERSONA.onboarding,
|
|
136
|
+
});
|
|
137
|
+
this.o.onStep(`Onboarding answered (${name})`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async adminToken() {
|
|
141
|
+
const admin = await this.raw("POST", "/api/v1/auth/login", undefined, this.o.admin);
|
|
142
|
+
if (!admin.ok)
|
|
143
|
+
throw new Error(`Administrator sign-in failed (ADMIN_EMAIL): HTTP ${admin.status}`);
|
|
144
|
+
return (await admin.json()).token;
|
|
145
|
+
}
|
|
146
|
+
/** Puts Eric on the paid plan, as an administrator would. */
|
|
147
|
+
async plan(actorId, token) {
|
|
148
|
+
const current = await this.raw("GET", `/api/v1/billing/subscriptions/${actorId}`, token);
|
|
149
|
+
if (current.ok) {
|
|
150
|
+
const sub = (await current.json());
|
|
151
|
+
if (sub.planKey === demo_persona_1.DEMO_PLAN && sub.status === "ACTIVE") {
|
|
152
|
+
this.o.onStep(`Plan already ${demo_persona_1.DEMO_PLAN}`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
await this.call("POST", `/api/v1/billing/subscriptions/${actorId}`, token, {
|
|
157
|
+
planKey: demo_persona_1.DEMO_PLAN,
|
|
158
|
+
status: "ACTIVE",
|
|
159
|
+
});
|
|
160
|
+
this.o.onStep(`Plan set to ${demo_persona_1.DEMO_PLAN}`);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Tops the wallet up to the plan's period grant with an administrator adjustment: billing does
|
|
164
|
+
* not write a period grant on a plan change yet, so without it a new subscriber starts at zero.
|
|
165
|
+
* Only the difference is granted, so a replay never inflates the balance.
|
|
166
|
+
*/
|
|
167
|
+
async credits(actorId, token) {
|
|
168
|
+
const res = await this.raw("GET", `/api/v1/billing/wallets/${actorId}`, token);
|
|
169
|
+
let available = 0;
|
|
170
|
+
if (res.ok) {
|
|
171
|
+
const w = (await res.json());
|
|
172
|
+
available = (w.balanceGranted ?? 0) + (w.balancePurchased ?? 0) - (w.held ?? 0);
|
|
173
|
+
}
|
|
174
|
+
else if (res.status !== 404) {
|
|
175
|
+
throw new Error(`Wallet: HTTP ${res.status} ${await res.text()}`);
|
|
176
|
+
}
|
|
177
|
+
const missing = demo_persona_1.DEMO_CREDITS - available;
|
|
178
|
+
if (missing <= 0) {
|
|
179
|
+
this.o.onStep(`Credits already at ${available}`);
|
|
180
|
+
return available;
|
|
181
|
+
}
|
|
182
|
+
await this.call("POST", `/api/v1/billing/wallets/${actorId}/adjustments`, token, {
|
|
183
|
+
bucket: "GRANTED",
|
|
184
|
+
amount: missing,
|
|
185
|
+
reason: `Demo persona: ${demo_persona_1.DEMO_PLAN} period grant`,
|
|
186
|
+
});
|
|
187
|
+
this.o.onStep(`Credits topped up to ${demo_persona_1.DEMO_CREDITS}`);
|
|
188
|
+
return demo_persona_1.DEMO_CREDITS;
|
|
189
|
+
}
|
|
190
|
+
async packs(token) {
|
|
191
|
+
for (const pack of demo_persona_1.DEMO_PACKS) {
|
|
192
|
+
const res = await this.raw("POST", `/api/v1/billing/pack-subscriptions/me/${pack}`, token);
|
|
193
|
+
if (!res.ok && res.status !== 409)
|
|
194
|
+
throw new Error(`Pack ${pack}: HTTP ${res.status} ${await res.text()}`);
|
|
195
|
+
this.o.onStep(res.status === 409 ? `Pack already held: ${pack}` : `Pack added: ${pack}`);
|
|
196
|
+
}
|
|
197
|
+
return [...demo_persona_1.DEMO_PACKS];
|
|
198
|
+
}
|
|
199
|
+
async studios(token) {
|
|
200
|
+
const installed = (await this.call("GET", "/api/v1/studios/installations", token));
|
|
201
|
+
const held = new Set(installed.map((i) => i.studioKey));
|
|
202
|
+
for (const key of demo_persona_1.DEMO_STUDIOS) {
|
|
203
|
+
if (held.has(key)) {
|
|
204
|
+
this.o.onStep(`Studio already installed: ${key}`);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const res = await this.raw("POST", `/api/v1/studios/${key}/installations?locale=${demo_persona_1.DEMO_PERSONA.language}`, token, { config: {} });
|
|
208
|
+
if (res.status === 409) {
|
|
209
|
+
// A Studio a held pack includes has nothing to install: it runs directly (`studio_included`).
|
|
210
|
+
const { status } = (await res.json());
|
|
211
|
+
if (status !== "studio_included")
|
|
212
|
+
throw new Error(`Studio ${key}: HTTP 409 ${String(status)}`);
|
|
213
|
+
this.o.onStep(`Studio included in a pack: ${key}`);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (!res.ok)
|
|
217
|
+
throw new Error(`Studio ${key}: HTTP ${res.status} ${await res.text()}`);
|
|
218
|
+
this.o.onStep(`Studio installed: ${key}`);
|
|
219
|
+
}
|
|
220
|
+
return [...demo_persona_1.DEMO_STUDIOS];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Starts the demo runs through the same endpoint the run form uses. Replayable: a Studio Eric already ran with
|
|
224
|
+
* success — or that is still running — is not run again, so a second seed adds no work and spends no credit.
|
|
225
|
+
* The runs go on in the background: the jobs page and the bell show them as they finish.
|
|
226
|
+
*/
|
|
227
|
+
async demoRuns(token) {
|
|
228
|
+
const history = (await this.call("GET", "/api/v1/studios/runs?limit=200", token));
|
|
229
|
+
const done = new Set(history.filter((r) => r.status === "SUCCEEDED" || r.status === "RUNNING").map((r) => r.studioKey));
|
|
230
|
+
const started = [];
|
|
231
|
+
for (const run of demo_persona_1.DEMO_RUNS) {
|
|
232
|
+
if (run.heavy && !this.o.withVideo)
|
|
233
|
+
continue;
|
|
234
|
+
if (done.has(run.studioKey)) {
|
|
235
|
+
this.o.onStep(`Run already done: ${run.studioKey}`);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const inputs = typeof run.inputs === "function" ? run.inputs() : run.inputs;
|
|
239
|
+
await this.startWhenFree(run.studioKey, inputs, token);
|
|
240
|
+
this.o.onStep(`Run started: ${run.studioKey}`);
|
|
241
|
+
started.push(run.studioKey);
|
|
242
|
+
}
|
|
243
|
+
return started;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Starts one run, waiting for a free slot when the plan's concurrent-run limit is reached (409 run_refused):
|
|
247
|
+
* the machine does one piece of work after another instead of being refused — and never saturated.
|
|
248
|
+
*/
|
|
249
|
+
async startWhenFree(studioKey, inputs, token) {
|
|
250
|
+
const deadline = Date.now() + (this.o.runSlotTimeoutMs ?? 10 * 60_000);
|
|
251
|
+
for (;;) {
|
|
252
|
+
const res = await this.raw("POST", `/api/v1/studios/${studioKey}/runs`, token, { inputs });
|
|
253
|
+
if (res.ok)
|
|
254
|
+
return;
|
|
255
|
+
const text = await res.text();
|
|
256
|
+
if (res.status !== 409 || !text.includes("run_refused") || Date.now() > deadline) {
|
|
257
|
+
throw new Error(`POST /api/v1/studios/${studioKey}/runs: HTTP ${res.status} ${text}`);
|
|
258
|
+
}
|
|
259
|
+
this.o.onStep(`Waiting for a free run slot before ${studioKey}…`);
|
|
260
|
+
await new Promise((r) => setTimeout(r, this.o.runSlotPollMs ?? 5_000));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
raw(method, path, token, body) {
|
|
264
|
+
return this.o.fetch(`${this.o.baseUrl}${path}`, {
|
|
265
|
+
method,
|
|
266
|
+
headers: {
|
|
267
|
+
...(body === undefined ? {} : { "Content-Type": "application/json" }),
|
|
268
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
269
|
+
},
|
|
270
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
async call(method, path, token, body) {
|
|
274
|
+
const res = await this.raw(method, path, token, body);
|
|
275
|
+
if (!res.ok)
|
|
276
|
+
throw new Error(`${method} ${path}: HTTP ${res.status} ${await res.text()}`);
|
|
277
|
+
const text = await res.text();
|
|
278
|
+
return text ? JSON.parse(text) : null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.DemoSeeder = DemoSeeder;
|