unstructured-client
Version:
<h3 align="center"> <img src="https://raw.githubusercontent.com/Unstructured-IO/unstructured/main/img/unstructured_logo.png" height="200" > </h3>
76 lines • 3.13 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerMCPExtensions = exports.tool$generalPartitionCorrect = void 0;
const tools_js_1 = require("./tools.js");
const generalPartition_js_1 = require("../funcs/generalPartition.js");
const promises_1 = __importDefault(require("node:fs/promises"));
const zod_1 = require("zod");
const partitionparameters_js_1 = require("../sdk/models/shared/partitionparameters.js");
const FileRequest$inboundSchema = zod_1.z.object({
file_content: zod_1.z.string().optional(),
file_path: zod_1.z.string().optional(),
file_name: zod_1.z.string(),
strategy: partitionparameters_js_1.Strategy$inboundSchema.default(partitionparameters_js_1.Strategy.HiRes),
});
const customToolArg = {
request: FileRequest$inboundSchema
};
exports.tool$generalPartitionCorrect = {
name: "correct_general-partition",
description: `use this tool to pass a file to unstructured. You must BASE64 ENCODE uploaded file content before passing to unstructured. Alternatively, if the user did not upload a file they can provide a full local file path. `,
args: customToolArg,
tool: async (client, args, ctx) => {
let data;
if (args.request.file_content) {
try {
data = new Uint8Array(Buffer.from(args.request.file_content, 'base64'));
}
catch (e) {
return {
content: [{
type: "text",
text: `You must BASE64 encode this file content then pass it to the tool.`,
}],
isError: true,
};
}
}
else if (args.request.file_path) {
data = new Uint8Array(await promises_1.default.readFile(args.request.file_path));
}
else {
return {
content: [{
type: "text",
text: `A full file path for file content must be provided`,
}],
isError: true,
};
}
const [result, apiCall] = await (0, generalPartition_js_1.generalPartition)(client, {
partitionParameters: {
files: {
content: data,
fileName: args.request.file_name,
},
strategy: args.request.strategy,
}
}, { fetchOptions: { signal: ctx.signal } }).$inspect();
if (!result.ok) {
return {
content: [{ type: "text", text: result.error.message }],
isError: true,
};
}
const value = result.value;
return (0, tools_js_1.formatResult)(value, apiCall);
},
};
function registerMCPExtensions(register) {
register.tool(exports.tool$generalPartitionCorrect);
}
exports.registerMCPExtensions = registerMCPExtensions;
//# sourceMappingURL=server.extensions.js.map
;