donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
69 lines • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CURRENT_METADATA_VERSION = void 0;
exports.normalizeFlowMetadata = normalizeFlowMetadata;
/**
* Current metadata schema version. Bump this when the metadata JSON structure
* changes in a way that requires read-time normalization.
*/
exports.CURRENT_METADATA_VERSION = 1;
/**
* Normalizes flow metadata written by older SDK versions to the current schema.
*
* Rows written by SDK v5+ carry a `metadataVersion` field. Rows without it
* were written by an older SDK and may use a legacy format (e.g. top-level
* `browser` / `targetWebsite` instead of the `{ target, web }` wrapper
* introduced in migration v9).
*/
function normalizeFlowMetadata(raw) {
if (raw.metadataVersion === exports.CURRENT_METADATA_VERSION) {
return raw;
}
// Pre-v5 format: `browser` and `targetWebsite` at the top level, no `target`.
if (!raw.target && raw.browser) {
raw.target = 'web';
raw.web = {
browser: raw.browser,
targetWebsite: raw.targetWebsite ?? '',
};
delete raw.browser;
delete raw.targetWebsite;
}
// The following checks are based on real, in-the-wild examples of flow
// metadata from previous versions of Studio.
// non-existent envVars
if (raw.envVars === undefined) {
raw.envVars = null;
}
// maxToolCalls is a string instead of a number
if (typeof raw.maxToolCalls === 'string') {
try {
raw.maxToolCalls = parseInt(raw.maxToolCalls, 10);
}
catch {
raw.maxToolCalls = null;
}
}
// completionTokensUsed is null: assume 0
if (raw.completionTokensUsed === null) {
raw.completionTokensUsed = 0;
}
if (raw.target === 'web') {
const browser = raw.web.browser;
if (browser === undefined) {
// missing browser: set to the default device
raw.web.browser = {
using: {
type: 'device',
// deviceName defaults to 'Desktop Chromium'
},
};
}
else if (browser.initialState === null) {
// web.browser.initialState is null instead of undefined
delete browser.initialState;
}
}
return raw;
}
//# sourceMappingURL=normalizeFlowMetadata.js.map