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.
Files changed (98) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +9 -0
  3. package/README.md +67 -2
  4. package/dist/commands/agent.command.js +267 -0
  5. package/dist/commands/chat.command.js +214 -0
  6. package/dist/commands/chat.handlers.js +150 -0
  7. package/dist/commands/chat.types.js +44 -0
  8. package/dist/commands/cinema.command.js +643 -0
  9. package/dist/commands/config.command.js +228 -0
  10. package/dist/commands/db.command.js +114 -0
  11. package/dist/commands/demo.command.js +55 -0
  12. package/dist/commands/dev.command.js +462 -0
  13. package/dist/commands/docs.command.js +135 -0
  14. package/dist/commands/doctor.command.js +119 -0
  15. package/dist/commands/forgot.command.js +57 -0
  16. package/dist/commands/generate.command.js +376 -0
  17. package/dist/commands/graph.command.js +54 -0
  18. package/dist/commands/init.command.js +380 -0
  19. package/dist/commands/init.steps.js +115 -0
  20. package/dist/commands/install.command.js +459 -0
  21. package/dist/commands/login.command.js +110 -0
  22. package/dist/commands/logs.command.js +215 -0
  23. package/dist/commands/logs.steps.js +130 -0
  24. package/dist/commands/mcp.command.js +104 -0
  25. package/dist/commands/models.command.js +164 -0
  26. package/dist/commands/onboard.command.js +236 -0
  27. package/dist/commands/pack.command.js +255 -0
  28. package/dist/commands/profile.command.js +51 -0
  29. package/dist/commands/recover.command.js +489 -0
  30. package/dist/commands/register.command.js +94 -0
  31. package/dist/commands/release.command.js +99 -0
  32. package/dist/commands/reset.command.js +79 -0
  33. package/dist/commands/runs.command.js +201 -0
  34. package/dist/commands/settings.command.js +85 -0
  35. package/dist/commands/start.command.js +590 -0
  36. package/dist/commands/status.command.js +167 -0
  37. package/dist/commands/stop.command.js +313 -0
  38. package/dist/commands/studio.command.js +266 -0
  39. package/dist/commands/test.command.js +134 -0
  40. package/dist/commands/verify.command.js +52 -0
  41. package/dist/commands/video.command.js +73 -0
  42. package/dist/commands/workspace-guard.js +72 -0
  43. package/dist/index.js +207 -0
  44. package/dist/renderers.js +250 -0
  45. package/dist/services/api-client.js +150 -0
  46. package/dist/services/auth.api.js +87 -0
  47. package/dist/services/chat.api.js +117 -0
  48. package/dist/services/cinema-estimate.json +42 -0
  49. package/dist/services/cinema.childsafe.js +52 -0
  50. package/dist/services/cinema.director.js +285 -0
  51. package/dist/services/cinema.production.js +417 -0
  52. package/dist/services/cinema.staging.js +323 -0
  53. package/dist/services/cinema.story.js +758 -0
  54. package/dist/services/cinema.treatment.js +393 -0
  55. package/dist/services/composer.run.js +94 -0
  56. package/dist/services/demo/demo.documents.js +108 -0
  57. package/dist/services/demo/demo.guard.js +49 -0
  58. package/dist/services/demo/demo.persona.js +114 -0
  59. package/dist/services/demo/demo.seed.js +281 -0
  60. package/dist/services/diagnostics.js +327 -0
  61. package/dist/services/image-model-recipes.json +93 -0
  62. package/dist/services/image-models.js +152 -0
  63. package/dist/services/local-store.js +145 -0
  64. package/dist/services/mcp.api.js +38 -0
  65. package/dist/services/model-catalog.js +70 -0
  66. package/dist/services/notify.js +55 -0
  67. package/dist/services/pack.api.js +23 -0
  68. package/dist/services/pack.bundle.js +241 -0
  69. package/dist/services/pack.sources.js +101 -0
  70. package/dist/services/release-manifest.js +266 -0
  71. package/dist/services/runs.view.js +80 -0
  72. package/dist/services/runs.wait.js +38 -0
  73. package/dist/services/semver.js +55 -0
  74. package/dist/services/settings.api.js +108 -0
  75. package/dist/services/string-utils.js +70 -0
  76. package/dist/services/studio.api.js +120 -0
  77. package/dist/services/templates.js +893 -0
  78. package/dist/services/tool-installer.js +353 -0
  79. package/dist/services/tool-path.js +72 -0
  80. package/dist/services/version-manager.js +253 -0
  81. package/dist/services/workspace-bootstrap.js +68 -0
  82. package/dist/threads.js +202 -0
  83. package/dist/types/api.types.js +6 -0
  84. package/dist/types/local.types.js +6 -0
  85. package/dist/ui/box.js +46 -0
  86. package/dist/ui/logger.js +28 -0
  87. package/dist/ui/platform.js +32 -0
  88. package/dist/ui/prompts.js +130 -0
  89. package/dist/ui/table.js +33 -0
  90. package/dist/utils/config.js +150 -0
  91. package/dist/utils/development-status.js +22 -0
  92. package/dist/utils/endpoints.js +41 -0
  93. package/dist/utils/health.js +94 -0
  94. package/dist/utils/pid.js +83 -0
  95. package/dist/utils/platform.js +358 -0
  96. package/dist/utils/process.js +139 -0
  97. package/dist/utils/state-dir.js +105 -0
  98. package/package.json +95 -4
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+ /**
3
+ * @file release-manifest.ts
4
+ * @description The release manifest of an Sovkora bundle (docs/DELIVERY.md §5 in krizaka/orazaka).
5
+ *
6
+ * One version for the whole bundle: the manifest pins, for that version, every component's commit,
7
+ * every container image by digest, every native artefact by SHA-256, every model by revision and
8
+ * every pack by version. `sovkora install` and `sovkora update` read it; nothing is fetched by tag.
9
+ *
10
+ * This module checks the manifest's shape (JSON Schema) and the rules a schema cannot say, and
11
+ * verifies the artefacts of an offline bundle against it. Its signature is the next step's.
12
+ */
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ var __importDefault = (this && this.__importDefault) || function (mod) {
47
+ return (mod && mod.__esModule) ? mod : { "default": mod };
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.releaseManifestSchema = exports.RELEASE_TARGETS = exports.RELEASE_SCHEMA = void 0;
51
+ exports.isBundlePath = isBundlePath;
52
+ exports.validateReleaseManifest = validateReleaseManifest;
53
+ exports.readReleaseManifest = readReleaseManifest;
54
+ exports.verifyArtefacts = verifyArtefacts;
55
+ const crypto = __importStar(require("node:crypto"));
56
+ const fs = __importStar(require("node:fs"));
57
+ const path = __importStar(require("node:path"));
58
+ const _2020_1 = __importDefault(require("ajv/dist/2020"));
59
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
60
+ const semver_1 = require("./semver");
61
+ exports.RELEASE_SCHEMA = "orazaka.dev/release/v1";
62
+ exports.RELEASE_TARGETS = ["mac-arm64", "linux-amd64", "linux-arm64"];
63
+ const NAME = { type: "string", pattern: "^[a-z0-9][a-z0-9.-]*$" };
64
+ const SEMVER = { type: "string", pattern: semver_1.SEMVER_PATTERN };
65
+ const SHA256 = { type: "string", pattern: "^[0-9a-f]{64}$" };
66
+ const list = (item) => ({ type: "array", items: item });
67
+ const record = (required, properties) => ({
68
+ type: "object",
69
+ additionalProperties: false,
70
+ required,
71
+ properties,
72
+ });
73
+ /** The shape. Every field is required: a release that does not know a value has not been built yet. */
74
+ exports.releaseManifestSchema = record([
75
+ "schema",
76
+ "version",
77
+ "channel",
78
+ "releasedAt",
79
+ "upgradeFrom",
80
+ "cli",
81
+ "targets",
82
+ "components",
83
+ "images",
84
+ "artefacts",
85
+ "models",
86
+ "packs",
87
+ ], {
88
+ schema: { const: exports.RELEASE_SCHEMA },
89
+ version: SEMVER,
90
+ channel: { enum: ["stable", "candidate"] },
91
+ releasedAt: { type: "string", format: "date-time" },
92
+ upgradeFrom: SEMVER,
93
+ cli: record(["package", "version"], { package: { type: "string", minLength: 1 }, version: SEMVER }),
94
+ targets: { type: "array", minItems: 1, uniqueItems: true, items: { enum: [...exports.RELEASE_TARGETS] } },
95
+ components: list(record(["name", "repository", "version", "commit"], {
96
+ name: NAME,
97
+ repository: { type: "string", pattern: "^krizaka/[a-z0-9-]+$" },
98
+ version: { type: "string", minLength: 1 },
99
+ commit: { type: "string", pattern: "^[0-9a-f]{40}$" },
100
+ })),
101
+ images: list(record(["name", "ref", "digest", "platforms"], {
102
+ name: NAME,
103
+ // Pinned by digest, never by tag: the ref is the repository, the digest is what runs.
104
+ ref: { type: "string", pattern: "^[a-z0-9.-]+(:[0-9]+)?/[a-z0-9._/-]+$" },
105
+ digest: { type: "string", pattern: "^sha256:[0-9a-f]{64}$" },
106
+ platforms: { type: "array", minItems: 1, uniqueItems: true, items: { enum: ["linux/amd64", "linux/arm64"] } },
107
+ gpu: { enum: ["none", "cuda"] },
108
+ })),
109
+ artefacts: list(record(["name", "file", "sha256", "size", "target"], {
110
+ name: NAME,
111
+ file: { type: "string", minLength: 1 },
112
+ sha256: SHA256,
113
+ size: { type: "integer", minimum: 1 },
114
+ target: { enum: [...exports.RELEASE_TARGETS] },
115
+ })),
116
+ models: list(record(["id", "source", "repo", "revision", "licence", "commercialUse", "downloadGb", "hardware"], {
117
+ id: { type: "string", minLength: 1 },
118
+ source: { enum: ["huggingface", "ollama"] },
119
+ repo: { type: "string", minLength: 1 },
120
+ revision: { type: "string", minLength: 1 },
121
+ licence: { type: "string", minLength: 1 },
122
+ // Only weights whose licence allows commercial use ship to a client (worker-media models.yaml).
123
+ commercialUse: { const: true },
124
+ downloadGb: { type: "number", exclusiveMinimum: 0 },
125
+ hardware: { type: "array", minItems: 1, uniqueItems: true, items: { enum: ["metal", "cuda", "cpu"] } },
126
+ })),
127
+ packs: list(record(["key", "version", "distribution"], {
128
+ key: NAME,
129
+ version: SEMVER,
130
+ distribution: { enum: ["OSS", "COMMERCIAL"] },
131
+ })),
132
+ });
133
+ function describe(errors) {
134
+ return (errors ?? []).map((error) => {
135
+ const where = error.instancePath === "" ? "(root)" : error.instancePath;
136
+ return `${where} ${error.message ?? "is invalid"}`;
137
+ });
138
+ }
139
+ function duplicates(values, what) {
140
+ const seen = new Set();
141
+ const problems = [];
142
+ for (const value of values) {
143
+ if (seen.has(value))
144
+ problems.push(`${what} '${value}' is listed twice`);
145
+ seen.add(value);
146
+ }
147
+ return problems;
148
+ }
149
+ /** A path inside the bundle: relative, forward slashes, never climbing out of it. */
150
+ function isBundlePath(file) {
151
+ if (file.startsWith("/") || file.includes("\\") || /^[a-zA-Z]:/.test(file))
152
+ return false;
153
+ return !file.split("/").some((part) => part === ".." || part === "." || part === "");
154
+ }
155
+ /** The rules the schema cannot say. Runs on a manifest whose shape is already valid. */
156
+ function invariants(m) {
157
+ const problems = [
158
+ ...duplicates(m.components.map((c) => c.name), "component"),
159
+ ...duplicates(m.images.map((i) => i.name), "image"),
160
+ ...duplicates(m.artefacts.map((a) => a.name), "artefact"),
161
+ ...duplicates(m.models.map((x) => x.id), "model"),
162
+ ...duplicates(m.packs.map((p) => p.key), "pack"),
163
+ ];
164
+ problems.push(...versionProblems(m), ...imageProblems(m), ...artefactProblems(m));
165
+ return problems;
166
+ }
167
+ function versionProblems(m) {
168
+ const problems = [];
169
+ const prerelease = (0, semver_1.parseSemver)(m.version)?.prerelease ?? "";
170
+ if (m.channel === "stable" && prerelease !== "") {
171
+ problems.push(`a stable release has no pre-release tag (got ${m.version})`);
172
+ }
173
+ if (m.channel === "candidate" && prerelease === "") {
174
+ problems.push(`a candidate release carries a pre-release tag such as -rc.1 (got ${m.version})`);
175
+ }
176
+ if ((0, semver_1.compareSemver)(m.upgradeFrom, m.version) > 0) {
177
+ problems.push(`upgradeFrom ${m.upgradeFrom} is newer than the release itself (${m.version})`);
178
+ }
179
+ return problems;
180
+ }
181
+ function imageProblems(m) {
182
+ const problems = [];
183
+ // Containers run on Linux everywhere; on a Mac they run in an arm64 VM, so every image a Mac
184
+ // runs must exist for linux/arm64. The CUDA image only runs on an NVIDIA Linux box.
185
+ const linuxPlatforms = new Set(m.targets.map((t) => (t === "linux-amd64" ? "linux/amd64" : "linux/arm64")));
186
+ for (const image of m.images) {
187
+ const needed = image.gpu === "cuda" ? ["linux/amd64"] : [...linuxPlatforms];
188
+ for (const platform of needed.filter((p) => !image.platforms.includes(p))) {
189
+ problems.push(`image ${image.name} has no ${platform} variant, which target(s) ${m.targets.join(", ")} need`);
190
+ }
191
+ }
192
+ return problems;
193
+ }
194
+ function artefactProblems(m) {
195
+ const problems = [];
196
+ for (const artefact of m.artefacts) {
197
+ if (!m.targets.includes(artefact.target)) {
198
+ problems.push(`artefact ${artefact.name} is for ${artefact.target}, which the release does not target`);
199
+ }
200
+ if (!isBundlePath(artefact.file)) {
201
+ problems.push(`artefact ${artefact.name} has a file path outside the bundle: ${artefact.file}`);
202
+ }
203
+ }
204
+ return problems;
205
+ }
206
+ /** Every problem of the manifest, shape first; an empty list means it can be trusted as data. */
207
+ function validateReleaseManifest(manifest) {
208
+ const ajv = new _2020_1.default({ allErrors: true, strict: false });
209
+ (0, ajv_formats_1.default)(ajv);
210
+ const validate = ajv.compile(exports.releaseManifestSchema);
211
+ if (!validate(manifest))
212
+ return describe(validate.errors);
213
+ return invariants(manifest);
214
+ }
215
+ /** Reads a manifest file; a file that is not JSON is reported, not thrown. */
216
+ function readReleaseManifest(file) {
217
+ if (!fs.existsSync(file))
218
+ return { problems: [`manifest not found: ${file}`] };
219
+ try {
220
+ return { manifest: JSON.parse(fs.readFileSync(file, "utf-8")), problems: [] };
221
+ }
222
+ catch (e) {
223
+ return { problems: [`manifest is not valid JSON: ${e instanceof Error ? e.message : String(e)}`] };
224
+ }
225
+ }
226
+ function sha256Of(file) {
227
+ const hash = crypto.createHash("sha256");
228
+ const fd = fs.openSync(file, "r");
229
+ try {
230
+ const buffer = Buffer.allocUnsafe(1 << 20);
231
+ let read;
232
+ while ((read = fs.readSync(fd, buffer, 0, buffer.length, null)) > 0)
233
+ hash.update(buffer.subarray(0, read));
234
+ }
235
+ finally {
236
+ fs.closeSync(fd);
237
+ }
238
+ return hash.digest("hex");
239
+ }
240
+ /**
241
+ * Checks the artefacts of an offline bundle directory against a valid manifest: each file is
242
+ * present, has the recorded size and the recorded SHA-256. `target` limits it to one machine's files.
243
+ */
244
+ function verifyArtefacts(manifest, dir, target) {
245
+ const problems = [];
246
+ for (const artefact of manifest.artefacts) {
247
+ if (target && artefact.target !== target)
248
+ continue;
249
+ if (!isBundlePath(artefact.file))
250
+ continue; // already reported by validateReleaseManifest
251
+ const file = path.join(dir, artefact.file);
252
+ if (!fs.existsSync(file)) {
253
+ problems.push(`${artefact.name}: ${artefact.file} is missing`);
254
+ continue;
255
+ }
256
+ const size = fs.statSync(file).size;
257
+ if (size !== artefact.size) {
258
+ problems.push(`${artefact.name}: ${artefact.file} is ${size} bytes, the manifest says ${artefact.size}`);
259
+ continue;
260
+ }
261
+ if (sha256Of(file) !== artefact.sha256) {
262
+ problems.push(`${artefact.name}: ${artefact.file} does not match its SHA-256`);
263
+ }
264
+ }
265
+ return problems;
266
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * @file runs.view.ts
4
+ * @description Pure shaping of Studio runs for `sovkora runs` (ADR-088, orazaka-cli#90): one row per run, the
5
+ * folded timeline of a run, and the stable `--json` shapes. No I/O here, so it is tested without a server.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.elapsedSeconds = elapsedSeconds;
9
+ exports.formatElapsed = formatElapsed;
10
+ exports.currentStep = currentStep;
11
+ exports.toRow = toRow;
12
+ exports.costAgainstBudget = costAgainstBudget;
13
+ exports.sortRuns = sortRuns;
14
+ exports.rowLine = rowLine;
15
+ exports.timelineLines = timelineLines;
16
+ exports.normaliseRef = normaliseRef;
17
+ const ACTIVE_STEP = new Set(["RUNNING", "PENDING", "QUEUED", "WAITING"]);
18
+ function elapsedSeconds(run, now) {
19
+ const end = run.finishedAt ? new Date(run.finishedAt) : now;
20
+ return Math.max(0, Math.round((end.getTime() - new Date(run.startedAt).getTime()) / 1000));
21
+ }
22
+ function formatElapsed(seconds) {
23
+ if (seconds < 60)
24
+ return `${String(seconds)}s`;
25
+ const minutes = Math.floor(seconds / 60);
26
+ if (minutes < 60)
27
+ return `${String(minutes)}m${String(seconds % 60).padStart(2, "0")}s`;
28
+ return `${String(Math.floor(minutes / 60))}h${String(minutes % 60).padStart(2, "0")}m`;
29
+ }
30
+ function currentStep(steps) {
31
+ return steps.find((step) => ACTIVE_STEP.has(step.status))?.stepId ?? null;
32
+ }
33
+ function toRow(run, now) {
34
+ return {
35
+ id: run.id,
36
+ name: run.name ?? null,
37
+ studioKey: run.studioKey,
38
+ status: run.status,
39
+ currentStep: currentStep(run.steps ?? []),
40
+ elapsedSeconds: elapsedSeconds(run, now),
41
+ cost: run.cost ?? null,
42
+ budget: run.budget ?? null,
43
+ };
44
+ }
45
+ function costAgainstBudget(row) {
46
+ if (row.cost === null)
47
+ return "-";
48
+ const spent = `$${row.cost.toFixed(2)}`;
49
+ return row.budget === null ? spent : `${spent} / $${row.budget.toFixed(2)}`;
50
+ }
51
+ /** Newest first, like the web console. */
52
+ function sortRuns(runs) {
53
+ return [...runs].sort((a, b) => b.startedAt.localeCompare(a.startedAt));
54
+ }
55
+ function rowLine(row) {
56
+ const label = row.name ?? row.id.slice(0, 8);
57
+ return [
58
+ label.padEnd(20),
59
+ row.status.padEnd(10),
60
+ (row.currentStep ?? "-").padEnd(18),
61
+ formatElapsed(row.elapsedSeconds).padEnd(8),
62
+ costAgainstBudget(row),
63
+ ].join(" ");
64
+ }
65
+ /** The folded timeline, one line per step: ordinal, status, step id, job. */
66
+ function timelineLines(run) {
67
+ return (run.steps ?? []).map((step) => {
68
+ const fanOut = step.ordinal > 0 ? ` #${String(step.ordinal + 1)}` : "";
69
+ const job = step.jobId ? ` job ${step.jobId}` : "";
70
+ const error = step.error ? ` - ${step.error}` : "";
71
+ return `${step.status.padEnd(10)} ${step.stepId}${fanOut}${job}${error}`;
72
+ });
73
+ }
74
+ /** A run is addressed by its id or by its name; the server resolves it, the CLI only refuses an empty ref. */
75
+ function normaliseRef(ref) {
76
+ const trimmed = ref.trim();
77
+ if (trimmed === "")
78
+ throw new Error("A run name or id is required");
79
+ return trimmed;
80
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * @file runs.wait.ts
4
+ * @description Follows one run until it ends or needs a person (orazaka-cli#90): `studio run` in the foreground,
5
+ * `runs wait`, and the detached watcher behind `--background --notify`. The sleep is injected so tests run at once.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.outcomeOf = outcomeOf;
9
+ exports.waitForRun = waitForRun;
10
+ const studio_api_1 = require("./studio.api");
11
+ const POLL_MS = 3000; // @fixed: a terminal refresh rate, not a business parameter
12
+ function outcomeOf(status) {
13
+ if (status === "AWAITING_INPUT")
14
+ return "needs-approval";
15
+ if (status === "SUCCEEDED")
16
+ return "finished";
17
+ if (status === "FAILED")
18
+ return "failed";
19
+ if (status === "CANCELLED")
20
+ return "cancelled";
21
+ return null;
22
+ }
23
+ /** Re-reads the run until it ends or waits for an answer; `onStatus` sees each distinct status. */
24
+ async function waitForRun(runId, options = {}) {
25
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
26
+ let last = "";
27
+ for (;;) {
28
+ const run = await studio_api_1.StudioApi.runDetail(runId);
29
+ if (run.status !== last) {
30
+ last = run.status;
31
+ options.onStatus?.(run.status);
32
+ }
33
+ const outcome = outcomeOf(run.status);
34
+ if (outcome)
35
+ return { outcome, run };
36
+ await sleep(POLL_MS);
37
+ }
38
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * @file semver.ts
4
+ * @description The few Semantic Versioning 2.0.0 rules the release manifest needs: parse and compare.
5
+ * Build metadata (`+…`) is accepted and ignored by the comparison, as the specification says.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.SEMVER_PATTERN = void 0;
9
+ exports.parseSemver = parseSemver;
10
+ exports.compareSemver = compareSemver;
11
+ exports.SEMVER_PATTERN = String.raw `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$`;
12
+ const SEMVER = new RegExp(exports.SEMVER_PATTERN);
13
+ function parseSemver(version) {
14
+ const match = SEMVER.exec(version);
15
+ if (!match)
16
+ return undefined;
17
+ return { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), prerelease: match[4] ?? "" };
18
+ }
19
+ function compareIdentifiers(a, b) {
20
+ const numeric = /^\d+$/;
21
+ if (numeric.test(a) && numeric.test(b))
22
+ return Math.sign(Number(a) - Number(b));
23
+ if (numeric.test(a))
24
+ return -1; // numeric identifiers sort before alphanumeric ones
25
+ if (numeric.test(b))
26
+ return 1;
27
+ if (a === b)
28
+ return 0;
29
+ return a < b ? -1 : 1;
30
+ }
31
+ /** -1, 0 or 1. Throws on a version that is not SemVer: callers validate first. */
32
+ function compareSemver(a, b) {
33
+ const x = parseSemver(a);
34
+ const y = parseSemver(b);
35
+ if (!x || !y)
36
+ throw new Error(`not a semantic version: ${!x ? a : b}`);
37
+ for (const key of ["major", "minor", "patch"]) {
38
+ if (x[key] !== y[key])
39
+ return Math.sign(x[key] - y[key]);
40
+ }
41
+ if (x.prerelease === y.prerelease)
42
+ return 0;
43
+ if (x.prerelease === "")
44
+ return 1; // 1.0.0 > 1.0.0-rc.1
45
+ if (y.prerelease === "")
46
+ return -1;
47
+ const xs = x.prerelease.split(".");
48
+ const ys = y.prerelease.split(".");
49
+ for (let i = 0; i < Math.min(xs.length, ys.length); i += 1) {
50
+ const order = compareIdentifiers(xs[i], ys[i]);
51
+ if (order !== 0)
52
+ return order;
53
+ }
54
+ return Math.sign(xs.length - ys.length);
55
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ /**
3
+ * @file settings.api.ts
4
+ * @description Outbound adapter service for User Profile settings, Operation Graph, and Interception operations.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.SettingsApi = void 0;
8
+ const api_client_1 = require("./api-client");
9
+ exports.SettingsApi = {
10
+ /**
11
+ * Fetches the currently authenticated user's profile and preferences.
12
+ */
13
+ getMe: async () => {
14
+ const query = `
15
+ query GetMe {
16
+ me {
17
+ id
18
+ username
19
+ email
20
+ authorities
21
+ preferences
22
+ }
23
+ }
24
+ `;
25
+ const data = await api_client_1.ApiClient.requestGql(query);
26
+ return data.me;
27
+ },
28
+ /**
29
+ * Fetches the compiled Operation Graph.
30
+ */
31
+ getOperationGraph: async () => {
32
+ const query = `
33
+ query GetOperationGraph {
34
+ operationGraph {
35
+ nodes {
36
+ id
37
+ presentationContext
38
+ state {
39
+ type
40
+ reason
41
+ lockedAt
42
+ }
43
+ }
44
+ }
45
+ }
46
+ `;
47
+ const data = await api_client_1.ApiClient.requestGql(query);
48
+ return data.operationGraph.nodes;
49
+ },
50
+ /**
51
+ * Fetches an interception schema by ID.
52
+ */
53
+ getInterceptionSchema: async (schemaId) => {
54
+ const query = `
55
+ query GetInterceptionSchema($schemaId: String!) {
56
+ interceptionSchema(schemaId: $schemaId)
57
+ }
58
+ `;
59
+ const data = await api_client_1.ApiClient.requestGql(query, {
60
+ schemaId,
61
+ });
62
+ return data.interceptionSchema;
63
+ },
64
+ /**
65
+ * Updates user preferences via atomic merge mutation.
66
+ */
67
+ updatePreferences: async (preferences) => {
68
+ const mutation = `
69
+ mutation UpdatePrefs($prefs: Map!) {
70
+ updatePreferences(preferences: $prefs) {
71
+ id
72
+ username
73
+ email
74
+ authorities
75
+ preferences
76
+ }
77
+ }
78
+ `;
79
+ const data = await api_client_1.ApiClient.requestGql(mutation, {
80
+ prefs: preferences,
81
+ });
82
+ return data.updatePreferences;
83
+ },
84
+ /**
85
+ * Resolves an active user interception.
86
+ */
87
+ resolveInterception: async (interceptionType, schemaId, responses) => {
88
+ const mutation = `
89
+ mutation ResolveInterception(
90
+ $interceptionType: String!
91
+ $schemaId: String!
92
+ $responses: Map!
93
+ ) {
94
+ resolveInterception(
95
+ interceptionType: $interceptionType
96
+ schemaId: $schemaId
97
+ responses: $responses
98
+ )
99
+ }
100
+ `;
101
+ const data = await api_client_1.ApiClient.requestGql(mutation, {
102
+ interceptionType,
103
+ schemaId,
104
+ responses,
105
+ });
106
+ return data.resolveInterception;
107
+ },
108
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * @file string-utils.ts
4
+ * @description String transformation utilities for template generation.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.pascalCase = pascalCase;
8
+ exports.camelCase = camelCase;
9
+ exports.kebabCase = kebabCase;
10
+ exports.snakeCase = snakeCase;
11
+ exports.constantCase = constantCase;
12
+ exports.isValidIdentifier = isValidIdentifier;
13
+ exports.isValidKebabCase = isValidKebabCase;
14
+ /**
15
+ * Converts a string to PascalCase (UpperCamelCase).
16
+ * Example: "hello-world" -> "HelloWorld"
17
+ */
18
+ function pascalCase(str) {
19
+ return str
20
+ .split(/[-_\s]+/)
21
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
22
+ .join("");
23
+ }
24
+ /**
25
+ * Converts a string to camelCase.
26
+ * Example: "hello-world" -> "helloWorld"
27
+ */
28
+ function camelCase(str) {
29
+ const pascal = pascalCase(str);
30
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
31
+ }
32
+ /**
33
+ * Converts a string to kebab-case (slug).
34
+ * Example: "HelloWorld" -> "hello-world"
35
+ */
36
+ function kebabCase(str) {
37
+ return str
38
+ .replace(/([a-z])([A-Z])/g, "$1-$2")
39
+ .replace(/[\s_]+/g, "-")
40
+ .toLowerCase();
41
+ }
42
+ /**
43
+ * Converts a string to snake_case.
44
+ * Example: "HelloWorld" -> "hello_world"
45
+ */
46
+ function snakeCase(str) {
47
+ return str
48
+ .replace(/([a-z])([A-Z])/g, "$1_$2")
49
+ .replace(/[\s-]+/g, "_")
50
+ .toLowerCase();
51
+ }
52
+ /**
53
+ * Converts a string to CONSTANT_CASE.
54
+ * Example: "hello-world" -> "HELLO_WORLD"
55
+ */
56
+ function constantCase(str) {
57
+ return snakeCase(str).toUpperCase();
58
+ }
59
+ /**
60
+ * Validates if a string is a valid identifier (variable/class name).
61
+ */
62
+ function isValidIdentifier(str) {
63
+ return /^[a-zA-Z_]\w*$/.test(str);
64
+ }
65
+ /**
66
+ * Validates if a string is a valid kebab-case identifier.
67
+ */
68
+ function isValidKebabCase(str) {
69
+ return /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(str);
70
+ }