@genkit-ai/anthropic
Version:
Genkit AI framework plugin for Anthropic APIs.
97 lines • 3.59 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var citations_exports = {};
__export(citations_exports, {
fromAnthropicCitation: () => fromAnthropicCitation
});
module.exports = __toCommonJS(citations_exports);
var import_genkit = require("genkit");
const baseCitationSchema = import_genkit.z.object({
cited_text: import_genkit.z.string(),
document_index: import_genkit.z.number(),
document_title: import_genkit.z.string().nullable().optional(),
file_id: import_genkit.z.string().nullable().optional()
});
const charLocationCitationSchema = baseCitationSchema.extend({
type: import_genkit.z.literal("char_location"),
start_char_index: import_genkit.z.number(),
end_char_index: import_genkit.z.number()
});
const pageLocationCitationSchema = baseCitationSchema.extend({
type: import_genkit.z.literal("page_location"),
start_page_number: import_genkit.z.number(),
end_page_number: import_genkit.z.number()
});
const contentBlockLocationCitationSchema = baseCitationSchema.extend({
type: import_genkit.z.literal("content_block_location"),
start_block_index: import_genkit.z.number(),
end_block_index: import_genkit.z.number()
});
const citationSchema = import_genkit.z.discriminatedUnion("type", [
charLocationCitationSchema,
pageLocationCitationSchema,
contentBlockLocationCitationSchema
]);
function fromAnthropicCitation(citation) {
if (citation.document_index === void 0) {
return void 0;
}
const result = citationSchema.safeParse(citation);
if (!result.success) {
return void 0;
}
const parsed = result.data;
switch (parsed.type) {
case "char_location":
return {
type: "char_location",
citedText: parsed.cited_text,
documentIndex: parsed.document_index,
documentTitle: parsed.document_title ?? void 0,
fileId: parsed.file_id ?? void 0,
startCharIndex: parsed.start_char_index,
endCharIndex: parsed.end_char_index
};
case "page_location":
return {
type: "page_location",
citedText: parsed.cited_text,
documentIndex: parsed.document_index,
documentTitle: parsed.document_title ?? void 0,
fileId: parsed.file_id ?? void 0,
startPageNumber: parsed.start_page_number,
endPageNumber: parsed.end_page_number
};
case "content_block_location":
return {
type: "content_block_location",
citedText: parsed.cited_text,
documentIndex: parsed.document_index,
documentTitle: parsed.document_title ?? void 0,
fileId: parsed.file_id ?? void 0,
startBlockIndex: parsed.start_block_index,
endBlockIndex: parsed.end_block_index
};
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
fromAnthropicCitation
});
//# sourceMappingURL=citations.js.map