@flatfile/ai-agents
Advanced tools
Comparing version 0.1.0-alpha.14 to 0.1.0-alpha.15
@@ -414,3 +414,2 @@ // src/graphs/blueprint.graph.ts | ||
// src/workflows/blueprint.workflow.ts | ||
import * as JsonPatch from "fast-json-patch/index.mjs"; | ||
import { z as z7 } from "zod"; | ||
@@ -523,2 +522,68 @@ | ||
// src/utils/json.patch.ts | ||
function getValueByPath(document, path2) { | ||
const keys = path2.split("/").slice(1); | ||
return keys.reduce((acc, key) => acc[key], document); | ||
} | ||
function setValueByPath(document, path2, value) { | ||
const keys = path2.split("/").slice(1); | ||
const lastKey = keys.pop(); | ||
const target = keys.reduce((acc, key) => acc[key], document); | ||
if (Array.isArray(target) && lastKey === "-") { | ||
; | ||
target.push(value); | ||
} else if (lastKey) { | ||
; | ||
target[lastKey] = value; | ||
} | ||
} | ||
function removeValueByPath(document, path2) { | ||
const keys = path2.split("/").slice(1); | ||
const lastKey = keys.pop(); | ||
const target = keys.reduce((acc, key) => acc[key], document); | ||
if (Array.isArray(target) && lastKey !== void 0) { | ||
; | ||
target.splice(Number(lastKey), 1); | ||
} else if (lastKey) { | ||
delete target[lastKey]; | ||
} | ||
} | ||
function applyPatch(document, patch) { | ||
patch.forEach((operation) => { | ||
const pathExists = getValueByPath(document, operation.path) !== void 0; | ||
if (!pathExists && operation.op !== "add" && operation.op !== "move" && operation.op !== "copy") { | ||
throw new Error(`Path does not exist: ${operation.path}`); | ||
} | ||
switch (operation.op) { | ||
case "add": | ||
setValueByPath(document, operation.path, operation.value); | ||
break; | ||
case "remove": | ||
removeValueByPath(document, operation.path); | ||
break; | ||
case "replace": | ||
setValueByPath(document, operation.path, operation.value); | ||
break; | ||
case "move": | ||
const valueToMove = getValueByPath(document, operation.from); | ||
removeValueByPath(document, operation.from); | ||
setValueByPath(document, operation.path, valueToMove); | ||
break; | ||
case "copy": | ||
const valueToCopy = getValueByPath(document, operation.from); | ||
setValueByPath(document, operation.path, valueToCopy); | ||
break; | ||
case "test": | ||
const valueToTest = getValueByPath(document, operation.path); | ||
if (JSON.stringify(valueToTest) !== JSON.stringify(operation.value)) { | ||
throw new Error(`Test operation failed at path: ${operation.path}`); | ||
} | ||
break; | ||
default: | ||
throw new Error(`Unsupported operation: ${operation.op}`); | ||
} | ||
}); | ||
return document; | ||
} | ||
// src/utils/retry.ts | ||
@@ -675,6 +740,4 @@ async function retry(fn, options = { | ||
debug && console.time(`applying constraints to ${sheet.name}`); | ||
const processedFields = JsonPatch.applyPatch( | ||
fields, | ||
constraintsPatch.fields | ||
).newDocument; | ||
const patchResult = applyPatch(fields, constraintsPatch.fields); | ||
const processedFields = Array.isArray(patchResult) ? patchResult : Object.values(patchResult); | ||
debug && console.timeEnd(`applying constraints to ${sheet.name}`); | ||
@@ -737,6 +800,3 @@ processedSheet.fields.push(...processedFields); | ||
debug && console.time(`applying references to ${sheet.name}`); | ||
const processedFields = JsonPatch.applyPatch( | ||
sheet.fields, | ||
referencesPatch.fields | ||
).newDocument; | ||
const processedFields = applyPatch(sheet.fields, referencesPatch.fields); | ||
debug && console.timeEnd(`applying references to ${sheet.name}`); | ||
@@ -743,0 +803,0 @@ sheets[sheets.indexOf(sheet)].fields = processedFields; |
{ | ||
"name": "@flatfile/ai-agents", | ||
"version": "0.1.0-alpha.14", | ||
"version": "0.1.0-alpha.15", | ||
"description": "A collection of AI Agents and Workflows for building in Flatfile", | ||
@@ -46,3 +46,2 @@ "packageManager": "npm@10.8.3", | ||
"dotenv": "^16.4.5", | ||
"fast-json-patch": "^3.1.1", | ||
"pdf-parse": "^1.1.1", | ||
@@ -49,0 +48,0 @@ "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76974
15
1817
- Removedfast-json-patch@^3.1.1
- Removedfast-json-patch@3.1.1(transitive)