35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
// A launch intent survives a lost response and a page reload. It is never
|
|
// replayed automatically; the operator explicitly checks/retries the same key.
|
|
import { newChatOperationId } from "./repository.js";
|
|
|
|
function storageKey(endpoint, pipelineId, version) {
|
|
return `pipelines.web.pendingRun.v1:${endpoint}:${pipelineId}:${version}`;
|
|
}
|
|
|
|
export function pendingRun(storage, endpoint, pipelineId, version) {
|
|
try {
|
|
const item = JSON.parse(storage?.getItem(storageKey(endpoint, pipelineId, version)) ?? "null");
|
|
if (!item || typeof item.requestKey !== "string" || typeof item.prompt !== "string" || typeof item.workspace !== "string") return null;
|
|
if (item.pipelineId !== pipelineId || item.version !== version) return null;
|
|
return item;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function createRunIntent(payload) {
|
|
return { ...payload, requestKey: newChatOperationId() };
|
|
}
|
|
|
|
export function saveRunIntent(storage, endpoint, intent) {
|
|
try {
|
|
storage?.setItem(storageKey(endpoint, intent.pipelineId, intent.version), JSON.stringify(intent));
|
|
} catch { /* In-memory identity still protects retries when storage is unavailable. */ }
|
|
}
|
|
|
|
export function clearRunIntent(storage, endpoint, intent) {
|
|
try {
|
|
storage?.removeItem(storageKey(endpoint, intent.pipelineId, intent.version));
|
|
} catch { /* Storage failure must not turn a completed launch into another run. */ }
|
|
}
|