@riddledc/riddle-proof 0.7.225 → 0.7.227
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/dist/adapters/codex-exec-agent.cjs +893 -0
- package/dist/adapters/codex-exec-agent.d.cts +3 -0
- package/dist/adapters/codex-exec-agent.d.ts +3 -0
- package/dist/adapters/codex-exec-agent.js +13 -0
- package/dist/adapters/codex.cjs +893 -0
- package/dist/adapters/codex.d.cts +3 -0
- package/dist/adapters/codex.d.ts +3 -0
- package/dist/adapters/codex.js +13 -0
- package/dist/adapters/local-agent.cjs +893 -0
- package/dist/adapters/local-agent.d.cts +3 -0
- package/dist/adapters/local-agent.d.ts +3 -0
- package/dist/adapters/local-agent.js +13 -0
- package/dist/adapters/openclaw.cjs +213 -0
- package/dist/adapters/openclaw.d.cts +2 -0
- package/dist/adapters/openclaw.d.ts +2 -0
- package/dist/adapters/openclaw.js +17 -0
- package/dist/advanced/engine-harness.cjs +5701 -0
- package/dist/advanced/engine-harness.d.cts +2 -0
- package/dist/advanced/engine-harness.d.ts +2 -0
- package/dist/advanced/engine-harness.js +16 -0
- package/dist/advanced/index.cjs +6242 -0
- package/dist/advanced/index.d.cts +5 -0
- package/dist/advanced/index.d.ts +5 -0
- package/dist/advanced/index.js +23 -0
- package/dist/advanced/proof-run-core.cjs +1085 -0
- package/dist/advanced/proof-run-core.d.cts +1 -0
- package/dist/advanced/proof-run-core.d.ts +1 -0
- package/dist/advanced/proof-run-core.js +59 -0
- package/dist/advanced/proof-run-engine.cjs +2905 -0
- package/dist/advanced/proof-run-engine.d.cts +2 -0
- package/dist/advanced/proof-run-engine.d.ts +2 -0
- package/dist/advanced/proof-run-engine.js +10 -0
- package/dist/advanced/runner.cjs +833 -0
- package/dist/advanced/runner.d.cts +2 -0
- package/dist/advanced/runner.d.ts +2 -0
- package/dist/advanced/runner.js +12 -0
- package/dist/app-contract/index.cjs +24 -0
- package/dist/app-contract/index.d.cts +1 -0
- package/dist/app-contract/index.d.ts +1 -0
- package/dist/app-contract/index.js +2 -0
- package/dist/basic-gameplay.js +1 -0
- package/dist/checkpoint.js +1 -0
- package/dist/chunk-BHL4JSGM.js +1900 -0
- package/dist/chunk-BTN76IGW.js +115 -0
- package/dist/{chunk-TGHTM66Z.js → chunk-COERZX63.js} +10 -2
- package/dist/{chunk-4DRRIJDX.js → chunk-IWLQQ5S5.js} +27 -4
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-OFSECTSC.js +0 -0
- package/dist/{chunk-GBVEQQIM.js → chunk-TJ63IE65.js} +36 -1
- package/dist/chunk-VZD5LH7U.js +4138 -0
- package/dist/cli/index.cjs +18 -0
- package/dist/cli/index.d.cts +2 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli.cjs +19 -2
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +8 -4139
- package/dist/codex-exec-agent.d.cts +1 -1
- package/dist/codex-exec-agent.d.ts +1 -1
- package/dist/codex-exec-agent.js +1 -0
- package/dist/diagnostics.js +1 -0
- package/dist/engine-harness-CMACHP6A.d.ts +96 -0
- package/dist/engine-harness-LBfqbFSe.d.cts +96 -0
- package/dist/engine-harness.cjs +19 -2
- package/dist/engine-harness.d.cts +2 -79
- package/dist/engine-harness.d.ts +2 -79
- package/dist/engine-harness.js +3 -2
- package/dist/index.cjs +19 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -3
- package/dist/local-agent.d.cts +1 -1
- package/dist/local-agent.d.ts +1 -1
- package/dist/local-agent.js +1 -0
- package/dist/openclaw.js +8 -107
- package/dist/playability.js +1 -0
- package/dist/profile/index.cjs +9403 -0
- package/dist/profile/index.d.cts +2 -0
- package/dist/profile/index.d.ts +2 -0
- package/dist/profile/index.js +53 -0
- package/dist/profile.js +1 -0
- package/dist/proof-run-core-CE0jx7wL.d.cts +359 -0
- package/dist/proof-run-core-CE0jx7wL.d.ts +359 -0
- package/dist/proof-run-core.d.cts +1 -322
- package/dist/proof-run-core.d.ts +1 -322
- package/dist/proof-run-core.js +2 -1
- package/dist/proof-run-engine-CSSc0mNn.d.ts +764 -0
- package/dist/proof-run-engine-HSRpUeBi.d.cts +764 -0
- package/dist/proof-run-engine.cjs +4 -0
- package/dist/proof-run-engine.d.cts +2 -757
- package/dist/proof-run-engine.d.ts +2 -757
- package/dist/proof-run-engine.js +5 -1881
- package/dist/proof-session.js +1 -0
- package/dist/result.js +1 -0
- package/dist/riddle-client.js +1 -0
- package/dist/run-card.js +1 -0
- package/dist/runner-4LJ5z0D-.d.cts +29 -0
- package/dist/runner-BdQpOkZD.d.ts +29 -0
- package/dist/runner.d.cts +2 -22
- package/dist/runner.d.ts +2 -22
- package/dist/runner.js +3 -2
- package/dist/runtime/index.cjs +528 -0
- package/dist/runtime/index.d.cts +1 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +37 -0
- package/dist/runtime/riddle-client.cjs +528 -0
- package/dist/runtime/riddle-client.d.cts +1 -0
- package/dist/runtime/riddle-client.d.ts +1 -0
- package/dist/runtime/riddle-client.js +37 -0
- package/dist/spec/checkpoint.cjs +807 -0
- package/dist/spec/checkpoint.d.cts +2 -0
- package/dist/spec/checkpoint.d.ts +2 -0
- package/dist/spec/checkpoint.js +34 -0
- package/dist/spec/index.cjs +1510 -0
- package/dist/spec/index.d.cts +5 -0
- package/dist/spec/index.d.ts +5 -0
- package/dist/spec/index.js +80 -0
- package/dist/spec/result.cjs +259 -0
- package/dist/spec/result.d.cts +2 -0
- package/dist/spec/result.d.ts +2 -0
- package/dist/spec/result.js +21 -0
- package/dist/spec/run-card.cjs +287 -0
- package/dist/spec/run-card.d.cts +2 -0
- package/dist/spec/run-card.d.ts +2 -0
- package/dist/spec/run-card.js +11 -0
- package/dist/spec/state.cjs +541 -0
- package/dist/spec/state.d.cts +2 -0
- package/dist/spec/state.d.ts +2 -0
- package/dist/spec/state.js +28 -0
- package/dist/spec/types.cjs +18 -0
- package/dist/spec/types.d.cts +1 -0
- package/dist/spec/types.d.ts +1 -0
- package/dist/spec/types.js +1 -0
- package/dist/state.js +1 -0
- package/package.json +95 -2
- package/runtime/lib/verify.py +53 -3
- package/runtime/pipelines/riddle-proof-setup.lobster +45 -41
- package/runtime/tests/recon_verify_smoke.py +41 -0
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/runtime/index.ts
|
|
31
|
+
var runtime_exports = {};
|
|
32
|
+
__export(runtime_exports, {
|
|
33
|
+
DEFAULT_RIDDLE_API_BASE_URL: () => DEFAULT_RIDDLE_API_BASE_URL,
|
|
34
|
+
DEFAULT_RIDDLE_API_KEY_FILE: () => DEFAULT_RIDDLE_API_KEY_FILE,
|
|
35
|
+
RiddleApiError: () => RiddleApiError,
|
|
36
|
+
collectRiddlePreviewDeployWarnings: () => collectRiddlePreviewDeployWarnings,
|
|
37
|
+
createRiddleApiClient: () => createRiddleApiClient,
|
|
38
|
+
deployRiddlePreview: () => deployRiddlePreview,
|
|
39
|
+
deployRiddleStaticPreview: () => deployRiddleStaticPreview,
|
|
40
|
+
getRiddleBalance: () => getRiddleBalance,
|
|
41
|
+
isTerminalRiddleJobStatus: () => isTerminalRiddleJobStatus,
|
|
42
|
+
parseRiddleViewport: () => parseRiddleViewport,
|
|
43
|
+
pollRiddleJob: () => pollRiddleJob,
|
|
44
|
+
resolveRiddleApiKey: () => resolveRiddleApiKey,
|
|
45
|
+
resolveRiddleApiKeySource: () => resolveRiddleApiKeySource,
|
|
46
|
+
riddleRequestJson: () => riddleRequestJson,
|
|
47
|
+
runRiddleScript: () => runRiddleScript,
|
|
48
|
+
runRiddleServerPreview: () => runRiddleServerPreview
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
51
|
+
|
|
52
|
+
// src/riddle-client.ts
|
|
53
|
+
var import_node_child_process = require("child_process");
|
|
54
|
+
var import_node_fs = require("fs");
|
|
55
|
+
var import_node_os = require("os");
|
|
56
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
57
|
+
var DEFAULT_RIDDLE_API_BASE_URL = "https://api.riddledc.com";
|
|
58
|
+
var DEFAULT_RIDDLE_API_KEY_FILE = "/tmp/riddle-api-key";
|
|
59
|
+
var RiddleApiError = class extends Error {
|
|
60
|
+
constructor(pathname, status, body) {
|
|
61
|
+
super(`Riddle API ${pathname} failed HTTP ${status}: ${body}`);
|
|
62
|
+
this.name = "RiddleApiError";
|
|
63
|
+
this.status = status;
|
|
64
|
+
this.body = body;
|
|
65
|
+
this.path = pathname;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var PREVIEW_PUBLISH_RECOVERY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
69
|
+
var PREVIEW_PUBLISH_RECOVERY_ATTEMPTS = 30;
|
|
70
|
+
var PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS = 2e3;
|
|
71
|
+
function normalizeBaseUrl(value) {
|
|
72
|
+
return (value || DEFAULT_RIDDLE_API_BASE_URL).replace(/\/$/, "");
|
|
73
|
+
}
|
|
74
|
+
function fetchFor(config = {}) {
|
|
75
|
+
return config.fetchImpl || fetch;
|
|
76
|
+
}
|
|
77
|
+
function resolveRiddleApiKeyWithSource(config = {}) {
|
|
78
|
+
if (config.apiKey?.trim()) return { apiKey: config.apiKey.trim(), source: "option" };
|
|
79
|
+
if (process.env.RIDDLE_API_KEY?.trim()) return { apiKey: process.env.RIDDLE_API_KEY.trim(), source: "env" };
|
|
80
|
+
const keyFile = config.apiKeyFile || process.env.RIDDLE_API_KEY_FILE || DEFAULT_RIDDLE_API_KEY_FILE;
|
|
81
|
+
if ((0, import_node_fs.existsSync)(keyFile)) {
|
|
82
|
+
const key = (0, import_node_fs.readFileSync)(keyFile, "utf8").trim();
|
|
83
|
+
if (key) return { apiKey: key, source: "file", file: keyFile };
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`Riddle API key missing. Set RIDDLE_API_KEY or write ${DEFAULT_RIDDLE_API_KEY_FILE}.`);
|
|
86
|
+
}
|
|
87
|
+
function resolveRiddleApiKeySource(config = {}) {
|
|
88
|
+
const { apiKey: _apiKey, ...source } = resolveRiddleApiKeyWithSource(config);
|
|
89
|
+
return source;
|
|
90
|
+
}
|
|
91
|
+
function resolveRiddleApiKey(config = {}) {
|
|
92
|
+
return resolveRiddleApiKeyWithSource(config).apiKey;
|
|
93
|
+
}
|
|
94
|
+
async function riddleRequestJson(config, pathname, init = {}) {
|
|
95
|
+
const response = await fetchFor(config)(`${normalizeBaseUrl(config.apiBaseUrl)}${pathname}`, {
|
|
96
|
+
...init,
|
|
97
|
+
headers: {
|
|
98
|
+
Authorization: `Bearer ${resolveRiddleApiKey(config)}`,
|
|
99
|
+
"Content-Type": "application/json",
|
|
100
|
+
...init.headers || {}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const text = await response.text();
|
|
104
|
+
let json = null;
|
|
105
|
+
try {
|
|
106
|
+
json = JSON.parse(text);
|
|
107
|
+
} catch {
|
|
108
|
+
}
|
|
109
|
+
if (!response.ok) throw new RiddleApiError(pathname, response.status, text);
|
|
110
|
+
return json ?? text;
|
|
111
|
+
}
|
|
112
|
+
async function getRiddleBalance(config = {}) {
|
|
113
|
+
return riddleRequestJson(config, "/v1/balance", { method: "GET" });
|
|
114
|
+
}
|
|
115
|
+
function previewDeployResultFromRecord(input) {
|
|
116
|
+
const { record, id, label, framework, expiresAt, publishRecovered, publishError } = input;
|
|
117
|
+
return {
|
|
118
|
+
ok: true,
|
|
119
|
+
id: String(record.id || record.preview_id || id),
|
|
120
|
+
label,
|
|
121
|
+
framework,
|
|
122
|
+
preview_url: String(record.preview_url || ""),
|
|
123
|
+
file_count: typeof record.file_count === "number" ? record.file_count : void 0,
|
|
124
|
+
total_bytes: typeof record.total_bytes === "number" ? record.total_bytes : void 0,
|
|
125
|
+
expires_at: expiresAt,
|
|
126
|
+
publish_recovered: publishRecovered || void 0,
|
|
127
|
+
publish_error: publishError,
|
|
128
|
+
warnings: input.warnings?.length ? input.warnings : void 0,
|
|
129
|
+
raw: record
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function canRecoverPreviewPublish(error) {
|
|
133
|
+
return error instanceof RiddleApiError && PREVIEW_PUBLISH_RECOVERY_STATUSES.has(error.status);
|
|
134
|
+
}
|
|
135
|
+
async function waitForPublishedPreview(config, input) {
|
|
136
|
+
for (let attempt = 1; attempt <= PREVIEW_PUBLISH_RECOVERY_ATTEMPTS; attempt += 1) {
|
|
137
|
+
const status = await riddleRequestJson(config, `/v1/preview/${input.id}`);
|
|
138
|
+
if (String(status.status || "") === "ready" && String(status.preview_url || "").trim()) {
|
|
139
|
+
return previewDeployResultFromRecord({
|
|
140
|
+
record: status,
|
|
141
|
+
id: input.id,
|
|
142
|
+
label: input.label,
|
|
143
|
+
framework: input.framework,
|
|
144
|
+
expiresAt: input.expiresAt,
|
|
145
|
+
publishRecovered: true,
|
|
146
|
+
publishError: input.publishError.message,
|
|
147
|
+
warnings: input.warnings
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (attempt < PREVIEW_PUBLISH_RECOVERY_ATTEMPTS) {
|
|
151
|
+
await new Promise((resolve) => setTimeout(resolve, PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
throw input.publishError;
|
|
155
|
+
}
|
|
156
|
+
async function deployRiddlePreview(config, directory, label, framework = "static") {
|
|
157
|
+
if (!directory?.trim()) throw new Error("directory is required");
|
|
158
|
+
if (!label?.trim()) throw new Error("label is required");
|
|
159
|
+
if (framework !== "spa" && framework !== "static") throw new Error("framework must be spa or static");
|
|
160
|
+
const warnings = collectRiddlePreviewDeployWarnings(directory, framework);
|
|
161
|
+
const created = await riddleRequestJson(config, "/v1/preview", {
|
|
162
|
+
method: "POST",
|
|
163
|
+
body: JSON.stringify({ framework, label })
|
|
164
|
+
});
|
|
165
|
+
const id = String(created.id || "");
|
|
166
|
+
const uploadUrl = String(created.upload_url || "");
|
|
167
|
+
if (!id || !uploadUrl) throw new Error("Riddle preview create response was missing id or upload_url.");
|
|
168
|
+
const scratch = (0, import_node_fs.mkdtempSync)(import_node_path.default.join((0, import_node_os.tmpdir)(), "riddle-preview-upload-"));
|
|
169
|
+
const tarball = import_node_path.default.join(scratch, `${id}.tar.gz`);
|
|
170
|
+
try {
|
|
171
|
+
(0, import_node_child_process.execFileSync)("tar", ["czf", tarball, "-C", directory, "."], { stdio: "pipe" });
|
|
172
|
+
const upload = await fetchFor(config)(uploadUrl, {
|
|
173
|
+
method: "PUT",
|
|
174
|
+
headers: { "Content-Type": "application/gzip" },
|
|
175
|
+
body: (0, import_node_fs.readFileSync)(tarball)
|
|
176
|
+
});
|
|
177
|
+
if (!upload.ok) {
|
|
178
|
+
throw new RiddleApiError(uploadUrl, upload.status, await upload.text());
|
|
179
|
+
}
|
|
180
|
+
} finally {
|
|
181
|
+
(0, import_node_fs.rmSync)(scratch, { recursive: true, force: true });
|
|
182
|
+
}
|
|
183
|
+
const expiresAt = typeof created.expires_at === "string" ? created.expires_at : void 0;
|
|
184
|
+
try {
|
|
185
|
+
const published = await riddleRequestJson(config, `/v1/preview/${id}/publish`, {
|
|
186
|
+
method: "POST"
|
|
187
|
+
});
|
|
188
|
+
return previewDeployResultFromRecord({ record: published, id, label, framework, expiresAt, warnings });
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (!canRecoverPreviewPublish(error)) throw error;
|
|
191
|
+
return waitForPublishedPreview(config, {
|
|
192
|
+
id,
|
|
193
|
+
label,
|
|
194
|
+
framework,
|
|
195
|
+
expiresAt,
|
|
196
|
+
publishError: error,
|
|
197
|
+
warnings
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function latestMatchingMtimeMs(directory, predicate) {
|
|
202
|
+
let latest = 0;
|
|
203
|
+
const stack = [directory];
|
|
204
|
+
let visited = 0;
|
|
205
|
+
while (stack.length) {
|
|
206
|
+
const current = stack.pop();
|
|
207
|
+
for (const entry of (0, import_node_fs.readdirSync)(current, { withFileTypes: true })) {
|
|
208
|
+
const fullPath = import_node_path.default.join(current, entry.name);
|
|
209
|
+
if (entry.isDirectory()) {
|
|
210
|
+
stack.push(fullPath);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (!entry.isFile() || !predicate(fullPath)) continue;
|
|
214
|
+
const stat = (0, import_node_fs.statSync)(fullPath);
|
|
215
|
+
latest = Math.max(latest, stat.mtimeMs);
|
|
216
|
+
visited += 1;
|
|
217
|
+
if (visited >= 1e4) return latest;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return latest;
|
|
221
|
+
}
|
|
222
|
+
function collectRiddlePreviewDeployWarnings(directory, framework = "static") {
|
|
223
|
+
try {
|
|
224
|
+
if (framework !== "static") return [];
|
|
225
|
+
const resolvedDirectory = import_node_path.default.resolve(directory);
|
|
226
|
+
if (import_node_path.default.basename(resolvedDirectory) !== "out") return [];
|
|
227
|
+
const repoRoot = import_node_path.default.dirname(resolvedDirectory);
|
|
228
|
+
const nextAppDir = import_node_path.default.join(repoRoot, ".next", "server", "app");
|
|
229
|
+
if (!(0, import_node_fs.existsSync)(nextAppDir)) return [];
|
|
230
|
+
const nextRenderedMtimeMs = latestMatchingMtimeMs(nextAppDir, (filePath) => /\.(?:html|rsc)$/i.test(filePath));
|
|
231
|
+
if (!nextRenderedMtimeMs) return [];
|
|
232
|
+
const outRenderedMtimeMs = (0, import_node_fs.existsSync)(resolvedDirectory) ? latestMatchingMtimeMs(resolvedDirectory, (filePath) => /\.(?:html|txt|rsc)$/i.test(filePath)) : 0;
|
|
233
|
+
if (!outRenderedMtimeMs) {
|
|
234
|
+
return [
|
|
235
|
+
"Riddle Preview static deploy target is an out/ directory with newer Next render output in .next/server/app, but no rendered HTML/RSC files were found in out/. Run the project static bundle/export step before deploying."
|
|
236
|
+
];
|
|
237
|
+
}
|
|
238
|
+
if (nextRenderedMtimeMs > outRenderedMtimeMs + 1e3) {
|
|
239
|
+
return [
|
|
240
|
+
"Riddle Preview static deploy target out/ appears older than the Next render output in .next/server/app. Run the project static bundle/export step, such as npm run build:static-deploy or next export, before deploying to avoid a stale Preview."
|
|
241
|
+
];
|
|
242
|
+
}
|
|
243
|
+
return [];
|
|
244
|
+
} catch {
|
|
245
|
+
return [];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async function deployRiddleStaticPreview(config, directory, label) {
|
|
249
|
+
return deployRiddlePreview(config, directory, label, "static");
|
|
250
|
+
}
|
|
251
|
+
function createTarball(directory, label, exclude = []) {
|
|
252
|
+
const scratch = (0, import_node_fs.mkdtempSync)(import_node_path.default.join((0, import_node_os.tmpdir)(), "riddle-upload-"));
|
|
253
|
+
const tarball = import_node_path.default.join(scratch, `${label}.tar.gz`);
|
|
254
|
+
const excludeArgs = exclude.flatMap((item) => ["--exclude", item]);
|
|
255
|
+
try {
|
|
256
|
+
(0, import_node_child_process.execFileSync)("tar", ["czf", tarball, ...excludeArgs, "-C", directory, "."], { stdio: "pipe" });
|
|
257
|
+
return { scratch, tarball };
|
|
258
|
+
} catch (error) {
|
|
259
|
+
(0, import_node_fs.rmSync)(scratch, { recursive: true, force: true });
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function parseRiddleViewport(value) {
|
|
264
|
+
if (!value) return void 0;
|
|
265
|
+
const match = /^(\d+)x(\d+)$/.exec(value.trim());
|
|
266
|
+
if (!match) throw new Error("viewport must look like 1280x720");
|
|
267
|
+
return { width: Number(match[1]), height: Number(match[2]) };
|
|
268
|
+
}
|
|
269
|
+
function scriptErrorFrom(job) {
|
|
270
|
+
const nested = job?.proof_of_execution && typeof job.proof_of_execution === "object" && !Array.isArray(job.proof_of_execution) ? job.proof_of_execution : null;
|
|
271
|
+
return typeof job?.script_error === "string" && job.script_error.trim() ? job.script_error : typeof nested?.script_error === "string" && nested.script_error.trim() ? nested.script_error : null;
|
|
272
|
+
}
|
|
273
|
+
async function runRiddleServerPreview(config, input) {
|
|
274
|
+
if (!input.directory?.trim()) throw new Error("directory is required");
|
|
275
|
+
if (!input.script?.trim()) throw new Error("script is required");
|
|
276
|
+
const port = input.port || 3e3;
|
|
277
|
+
const routePath = input.path || "/";
|
|
278
|
+
const timeoutSec = input.timeoutSec || 180;
|
|
279
|
+
const created = await riddleRequestJson(config, "/v1/server-preview", {
|
|
280
|
+
method: "POST",
|
|
281
|
+
body: JSON.stringify({
|
|
282
|
+
image: input.image || "node:22-slim",
|
|
283
|
+
command: input.command || "node scripts/riddleSpaPreviewServer.mjs build 3000",
|
|
284
|
+
port,
|
|
285
|
+
path: routePath,
|
|
286
|
+
readiness_path: input.readinessPath || routePath,
|
|
287
|
+
readiness_timeout: input.readinessTimeoutSec || 90,
|
|
288
|
+
wait_until: input.waitUntil || "domcontentloaded",
|
|
289
|
+
wait_for_selector: input.waitForSelector || "body",
|
|
290
|
+
navigation_timeout: input.navigationTimeoutSec || 60,
|
|
291
|
+
viewport: input.viewport,
|
|
292
|
+
timeout: timeoutSec,
|
|
293
|
+
script: input.script
|
|
294
|
+
})
|
|
295
|
+
});
|
|
296
|
+
const jobId = String(created.job_id || "");
|
|
297
|
+
const uploadUrl = String(created.upload_url || "");
|
|
298
|
+
if (!jobId || !uploadUrl) {
|
|
299
|
+
throw new Error(`Riddle server preview create response was missing job_id or upload_url.`);
|
|
300
|
+
}
|
|
301
|
+
const { scratch, tarball } = createTarball(input.directory, jobId, [
|
|
302
|
+
".git",
|
|
303
|
+
"node_modules",
|
|
304
|
+
"test-results",
|
|
305
|
+
...input.exclude || []
|
|
306
|
+
]);
|
|
307
|
+
try {
|
|
308
|
+
const upload = await fetchFor(config)(uploadUrl, {
|
|
309
|
+
method: "PUT",
|
|
310
|
+
headers: { "Content-Type": "application/gzip" },
|
|
311
|
+
body: (0, import_node_fs.readFileSync)(tarball)
|
|
312
|
+
});
|
|
313
|
+
if (!upload.ok) throw new RiddleApiError(uploadUrl, upload.status, await upload.text());
|
|
314
|
+
} finally {
|
|
315
|
+
(0, import_node_fs.rmSync)(scratch, { recursive: true, force: true });
|
|
316
|
+
}
|
|
317
|
+
await riddleRequestJson(config, `/v1/server-preview/${jobId}/start`, {
|
|
318
|
+
method: "POST"
|
|
319
|
+
});
|
|
320
|
+
let job = null;
|
|
321
|
+
const attempts = input.pollAttempts || Math.ceil((timeoutSec + 90) / 2);
|
|
322
|
+
const intervalMs = input.pollIntervalMs || 2e3;
|
|
323
|
+
for (let index = 0; index < attempts; index += 1) {
|
|
324
|
+
job = await riddleRequestJson(config, `/v1/server-preview/${jobId}`);
|
|
325
|
+
if (isTerminalRiddleJobStatus(job.status)) break;
|
|
326
|
+
if (index + 1 < attempts) await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
327
|
+
}
|
|
328
|
+
const status = job?.status ? String(job.status) : null;
|
|
329
|
+
const scriptError = scriptErrorFrom(job);
|
|
330
|
+
return {
|
|
331
|
+
ok: (status === "completed" || status === "complete") && !scriptError,
|
|
332
|
+
job_id: jobId,
|
|
333
|
+
status,
|
|
334
|
+
terminal: isTerminalRiddleJobStatus(status),
|
|
335
|
+
script_error: scriptError,
|
|
336
|
+
job
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
async function runRiddleScript(config, input) {
|
|
340
|
+
if (!input.url?.trim()) throw new Error("url is required");
|
|
341
|
+
if (!input.script?.trim()) throw new Error("script is required");
|
|
342
|
+
const payload = {
|
|
343
|
+
url: input.url,
|
|
344
|
+
script: input.script,
|
|
345
|
+
sync: input.sync ?? false,
|
|
346
|
+
timeout_sec: input.timeoutSec || 120
|
|
347
|
+
};
|
|
348
|
+
if (input.viewport) payload.viewport = input.viewport;
|
|
349
|
+
if (input.include) payload.include = input.include;
|
|
350
|
+
if (typeof input.strict === "boolean") payload.strict = input.strict;
|
|
351
|
+
if (input.options) payload.options = input.options;
|
|
352
|
+
return riddleRequestJson(config, "/v1/run", {
|
|
353
|
+
method: "POST",
|
|
354
|
+
body: JSON.stringify(payload)
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
function isTerminalRiddleJobStatus(status) {
|
|
358
|
+
return ["completed", "complete", "completed_error", "completed_timeout", "failed"].includes(String(status || ""));
|
|
359
|
+
}
|
|
360
|
+
function stringField(record, key) {
|
|
361
|
+
const value = record?.[key];
|
|
362
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
363
|
+
}
|
|
364
|
+
function parseTimestampMs(value) {
|
|
365
|
+
if (!value) return null;
|
|
366
|
+
const parsed = Date.parse(value);
|
|
367
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
368
|
+
}
|
|
369
|
+
function buildPollSnapshot(jobId, job, input) {
|
|
370
|
+
const status = job?.status ? String(job.status) : null;
|
|
371
|
+
const terminal = isTerminalRiddleJobStatus(status);
|
|
372
|
+
const createdAt = stringField(job, "created_at");
|
|
373
|
+
const submittedAt = stringField(job, "submitted_at");
|
|
374
|
+
const completedAt = stringField(job, "completed_at");
|
|
375
|
+
const createdMs = parseTimestampMs(createdAt);
|
|
376
|
+
const submittedMs = parseTimestampMs(submittedAt);
|
|
377
|
+
let queueElapsedMs = null;
|
|
378
|
+
if (createdMs !== null && submittedMs !== null) {
|
|
379
|
+
queueElapsedMs = Math.max(0, submittedMs - createdMs);
|
|
380
|
+
} else if (createdMs !== null && !submittedAt && !terminal) {
|
|
381
|
+
queueElapsedMs = Math.max(0, input.observedAt - createdMs);
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
job_id: jobId,
|
|
385
|
+
status,
|
|
386
|
+
terminal,
|
|
387
|
+
attempt: input.attempt,
|
|
388
|
+
attempts: input.attempts,
|
|
389
|
+
elapsed_ms: Math.max(0, input.observedAt - input.startedAt),
|
|
390
|
+
created_at: createdAt,
|
|
391
|
+
submitted_at: submittedAt,
|
|
392
|
+
completed_at: completedAt,
|
|
393
|
+
queue_elapsed_ms: queueElapsedMs,
|
|
394
|
+
pre_submission_elapsed_ms: Math.max(0, Math.floor(input.preSubmissionElapsedMs ?? 0)),
|
|
395
|
+
running_without_submission: Boolean(status && !terminal && !submittedAt)
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function pollMessage(snapshot, timedOut) {
|
|
399
|
+
if (!timedOut) return void 0;
|
|
400
|
+
const submitted = snapshot.submitted_at || "not submitted";
|
|
401
|
+
const queue = snapshot.queue_elapsed_ms !== null ? ` queue_elapsed_ms=${snapshot.queue_elapsed_ms}` : "";
|
|
402
|
+
const preSubmit = snapshot.pre_submission_elapsed_ms > 0 ? ` pre_submission_elapsed_ms=${snapshot.pre_submission_elapsed_ms}` : "";
|
|
403
|
+
return `Riddle job ${snapshot.job_id} did not reach a terminal status after ${snapshot.attempt} poll attempts; status=${snapshot.status || "unknown"} submitted_at=${submitted}.${queue}${preSubmit}`;
|
|
404
|
+
}
|
|
405
|
+
async function pollRiddleJob(config, jobId, options = {}) {
|
|
406
|
+
if (!jobId?.trim()) throw new Error("jobId is required");
|
|
407
|
+
const attempts = Math.max(1, Math.floor(options.attempts ?? (options.wait ? 300 : 1)));
|
|
408
|
+
const intervalMs = Math.max(0, Math.floor(options.intervalMs ?? 2e3));
|
|
409
|
+
const progressEveryMs = Math.max(0, Math.floor(options.progressEveryMs ?? 1e4));
|
|
410
|
+
const unsubmittedTimeoutMs = Math.max(0, Math.floor(options.unsubmittedTimeoutMs ?? 0));
|
|
411
|
+
const startedAt = Date.now();
|
|
412
|
+
let job = null;
|
|
413
|
+
let lastSnapshot = null;
|
|
414
|
+
let lastProgressAt = 0;
|
|
415
|
+
let lastProgressKey = "";
|
|
416
|
+
let preSubmissionElapsedMs = 0;
|
|
417
|
+
let unsubmittedTimedOut = false;
|
|
418
|
+
for (let index = 0; index < attempts; index += 1) {
|
|
419
|
+
job = await riddleRequestJson(config, `/v1/jobs/${jobId}`);
|
|
420
|
+
const observedAt = Date.now();
|
|
421
|
+
const nextSnapshot = buildPollSnapshot(jobId, job, {
|
|
422
|
+
attempt: index + 1,
|
|
423
|
+
attempts,
|
|
424
|
+
startedAt,
|
|
425
|
+
observedAt,
|
|
426
|
+
preSubmissionElapsedMs
|
|
427
|
+
});
|
|
428
|
+
if (nextSnapshot.running_without_submission) {
|
|
429
|
+
preSubmissionElapsedMs = Math.max(preSubmissionElapsedMs, nextSnapshot.elapsed_ms);
|
|
430
|
+
}
|
|
431
|
+
lastSnapshot = {
|
|
432
|
+
...nextSnapshot,
|
|
433
|
+
pre_submission_elapsed_ms: preSubmissionElapsedMs
|
|
434
|
+
};
|
|
435
|
+
const progressKey = [
|
|
436
|
+
lastSnapshot.status || "unknown",
|
|
437
|
+
lastSnapshot.terminal ? "terminal" : "nonterminal",
|
|
438
|
+
lastSnapshot.submitted_at ? "submitted" : "unsubmitted"
|
|
439
|
+
].join(":");
|
|
440
|
+
if (options.onProgress) {
|
|
441
|
+
const shouldReport = index === 0 || lastSnapshot.terminal || progressKey !== lastProgressKey || observedAt - lastProgressAt >= progressEveryMs;
|
|
442
|
+
if (shouldReport) {
|
|
443
|
+
lastProgressAt = observedAt;
|
|
444
|
+
lastProgressKey = progressKey;
|
|
445
|
+
await options.onProgress(lastSnapshot);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
unsubmittedTimedOut = Boolean(
|
|
449
|
+
options.wait && unsubmittedTimeoutMs > 0 && lastSnapshot.running_without_submission && !lastSnapshot.created_at && !lastSnapshot.submitted_at && preSubmissionElapsedMs >= unsubmittedTimeoutMs
|
|
450
|
+
);
|
|
451
|
+
if (lastSnapshot.terminal) break;
|
|
452
|
+
if (unsubmittedTimedOut) break;
|
|
453
|
+
if (index + 1 < attempts) {
|
|
454
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
const status = job?.status ? String(job.status) : null;
|
|
458
|
+
const fallbackObservedAt = Date.now();
|
|
459
|
+
const snapshot = lastSnapshot || buildPollSnapshot(jobId, job, {
|
|
460
|
+
attempt: 0,
|
|
461
|
+
attempts,
|
|
462
|
+
startedAt,
|
|
463
|
+
observedAt: fallbackObservedAt
|
|
464
|
+
});
|
|
465
|
+
if (!isTerminalRiddleJobStatus(status)) {
|
|
466
|
+
const timedOut = Boolean(options.wait);
|
|
467
|
+
return {
|
|
468
|
+
ok: !timedOut,
|
|
469
|
+
job_id: jobId,
|
|
470
|
+
status,
|
|
471
|
+
terminal: false,
|
|
472
|
+
job,
|
|
473
|
+
poll: {
|
|
474
|
+
...snapshot,
|
|
475
|
+
timed_out: timedOut,
|
|
476
|
+
interval_ms: intervalMs,
|
|
477
|
+
unsubmitted_timeout: unsubmittedTimedOut || void 0,
|
|
478
|
+
unsubmitted_timeout_ms: unsubmittedTimedOut ? unsubmittedTimeoutMs : void 0,
|
|
479
|
+
message: pollMessage(snapshot, timedOut)
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
const artifacts = await riddleRequestJson(config, `/v1/jobs/${jobId}/artifacts`);
|
|
484
|
+
return {
|
|
485
|
+
ok: status === "completed" || status === "complete",
|
|
486
|
+
job_id: jobId,
|
|
487
|
+
status,
|
|
488
|
+
terminal: true,
|
|
489
|
+
job,
|
|
490
|
+
artifacts,
|
|
491
|
+
poll: {
|
|
492
|
+
...snapshot,
|
|
493
|
+
timed_out: false,
|
|
494
|
+
interval_ms: intervalMs
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function createRiddleApiClient(config = {}) {
|
|
499
|
+
return {
|
|
500
|
+
apiKeySource: () => resolveRiddleApiKeySource(config),
|
|
501
|
+
requestJson: (pathname, init) => riddleRequestJson(config, pathname, init),
|
|
502
|
+
getBalance: () => getRiddleBalance(config),
|
|
503
|
+
deployPreview: (directory, label, framework = "static") => deployRiddlePreview(config, directory, label, framework),
|
|
504
|
+
deployStaticPreview: (directory, label) => deployRiddleStaticPreview(config, directory, label),
|
|
505
|
+
runScript: (input) => runRiddleScript(config, input),
|
|
506
|
+
runServerPreview: (input) => runRiddleServerPreview(config, input),
|
|
507
|
+
pollJob: (jobId, options) => pollRiddleJob(config, jobId, options)
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
511
|
+
0 && (module.exports = {
|
|
512
|
+
DEFAULT_RIDDLE_API_BASE_URL,
|
|
513
|
+
DEFAULT_RIDDLE_API_KEY_FILE,
|
|
514
|
+
RiddleApiError,
|
|
515
|
+
collectRiddlePreviewDeployWarnings,
|
|
516
|
+
createRiddleApiClient,
|
|
517
|
+
deployRiddlePreview,
|
|
518
|
+
deployRiddleStaticPreview,
|
|
519
|
+
getRiddleBalance,
|
|
520
|
+
isTerminalRiddleJobStatus,
|
|
521
|
+
parseRiddleViewport,
|
|
522
|
+
pollRiddleJob,
|
|
523
|
+
resolveRiddleApiKey,
|
|
524
|
+
resolveRiddleApiKeySource,
|
|
525
|
+
riddleRequestJson,
|
|
526
|
+
runRiddleScript,
|
|
527
|
+
runRiddleServerPreview
|
|
528
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DEFAULT_RIDDLE_API_BASE_URL, DEFAULT_RIDDLE_API_KEY_FILE, RiddleApiError, RiddleApiKeySource, RiddleBalanceResult, RiddleClientConfig, RiddleFetch, RiddlePollJobOptions, RiddlePollJobResult, RiddlePollProgressSnapshot, RiddlePollSummary, RiddlePreviewDeployResult, RiddlePreviewFramework, RiddleRunScriptInput, RiddleServerPreviewInput, RiddleServerPreviewResult, collectRiddlePreviewDeployWarnings, createRiddleApiClient, deployRiddlePreview, deployRiddleStaticPreview, getRiddleBalance, isTerminalRiddleJobStatus, parseRiddleViewport, pollRiddleJob, resolveRiddleApiKey, resolveRiddleApiKeySource, riddleRequestJson, runRiddleScript, runRiddleServerPreview } from '../riddle-client.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DEFAULT_RIDDLE_API_BASE_URL, DEFAULT_RIDDLE_API_KEY_FILE, RiddleApiError, RiddleApiKeySource, RiddleBalanceResult, RiddleClientConfig, RiddleFetch, RiddlePollJobOptions, RiddlePollJobResult, RiddlePollProgressSnapshot, RiddlePollSummary, RiddlePreviewDeployResult, RiddlePreviewFramework, RiddleRunScriptInput, RiddleServerPreviewInput, RiddleServerPreviewResult, collectRiddlePreviewDeployWarnings, createRiddleApiClient, deployRiddlePreview, deployRiddleStaticPreview, getRiddleBalance, isTerminalRiddleJobStatus, parseRiddleViewport, pollRiddleJob, resolveRiddleApiKey, resolveRiddleApiKeySource, riddleRequestJson, runRiddleScript, runRiddleServerPreview } from '../riddle-client.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_RIDDLE_API_BASE_URL,
|
|
3
|
+
DEFAULT_RIDDLE_API_KEY_FILE,
|
|
4
|
+
RiddleApiError,
|
|
5
|
+
collectRiddlePreviewDeployWarnings,
|
|
6
|
+
createRiddleApiClient,
|
|
7
|
+
deployRiddlePreview,
|
|
8
|
+
deployRiddleStaticPreview,
|
|
9
|
+
getRiddleBalance,
|
|
10
|
+
isTerminalRiddleJobStatus,
|
|
11
|
+
parseRiddleViewport,
|
|
12
|
+
pollRiddleJob,
|
|
13
|
+
resolveRiddleApiKey,
|
|
14
|
+
resolveRiddleApiKeySource,
|
|
15
|
+
riddleRequestJson,
|
|
16
|
+
runRiddleScript,
|
|
17
|
+
runRiddleServerPreview
|
|
18
|
+
} from "../chunk-TWTEUS7R.js";
|
|
19
|
+
import "../chunk-MLKGABMK.js";
|
|
20
|
+
export {
|
|
21
|
+
DEFAULT_RIDDLE_API_BASE_URL,
|
|
22
|
+
DEFAULT_RIDDLE_API_KEY_FILE,
|
|
23
|
+
RiddleApiError,
|
|
24
|
+
collectRiddlePreviewDeployWarnings,
|
|
25
|
+
createRiddleApiClient,
|
|
26
|
+
deployRiddlePreview,
|
|
27
|
+
deployRiddleStaticPreview,
|
|
28
|
+
getRiddleBalance,
|
|
29
|
+
isTerminalRiddleJobStatus,
|
|
30
|
+
parseRiddleViewport,
|
|
31
|
+
pollRiddleJob,
|
|
32
|
+
resolveRiddleApiKey,
|
|
33
|
+
resolveRiddleApiKeySource,
|
|
34
|
+
riddleRequestJson,
|
|
35
|
+
runRiddleScript,
|
|
36
|
+
runRiddleServerPreview
|
|
37
|
+
};
|