@codemation/core-nodes-ocr 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/{analyzeInvoiceNode-BqZsN8iL.js → analyzeInvoiceNode-BQzww-XC.js} +1 -9
- package/dist/analyzeInvoiceNode-BQzww-XC.js.map +1 -0
- package/dist/{analyzeInvoiceNode-CmMsifbw.cjs → analyzeInvoiceNode-CW_SXNQf.cjs} +1 -9
- package/dist/analyzeInvoiceNode-CW_SXNQf.cjs.map +1 -0
- package/dist/codemation.plugin.cjs +178 -346
- package/dist/codemation.plugin.cjs.map +1 -1
- package/dist/codemation.plugin.d.cts +1 -73
- package/dist/codemation.plugin.d.ts +1 -58
- package/dist/codemation.plugin.js +179 -347
- package/dist/codemation.plugin.js.map +1 -1
- package/dist/{index-RNoZqCPr.d.ts → index-DdjAAXvy.d.ts} +9 -291
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -46
- package/dist/index.d.ts +7 -29
- package/dist/index.js +1 -1
- package/dist/metadata.json +1 -1
- package/dist/{runtimeTypes-B6RO-Yki.d.cts → runtimeTypes-D_9j5Pat.d.cts} +9 -259
- package/package.json +2 -2
- package/src/lib/analyzeWithAzure.ts +0 -9
- package/src/nodes/analyzeDocumentNode.ts +0 -9
- package/src/nodes/analyzeImageNode.ts +0 -9
- package/src/nodes/analyzeInvoiceNode.ts +0 -4
- package/dist/analyzeInvoiceNode-BqZsN8iL.js.map +0 -1
- package/dist/analyzeInvoiceNode-CmMsifbw.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @codemation/core-nodes-ocr
|
|
2
2
|
|
|
3
|
+
## 0.2.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#247](https://github.com/MadeRelevant/codemation/pull/247) [`bfdd759`](https://github.com/MadeRelevant/codemation/commit/bfdd7590b4903676b223c2f302b9bcd0f4a4583c) Thanks [@cblokland90](https://github.com/cblokland90)! - Remove all human-written comments from TypeScript source files and add `codemation/no-comments` ESLint rule to enforce self-describing code going forward.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`60f23a3`](https://github.com/MadeRelevant/codemation/commit/60f23a37660cdda34e3d61acca8b2bf581a9db0e), [`a5457bb`](https://github.com/MadeRelevant/codemation/commit/a5457bb58edafec01e85cdcf6d30f9ca54521e27), [`510e0d8`](https://github.com/MadeRelevant/codemation/commit/510e0d8a5f137a4fe10f43cbf46e40d05fea4977), [`d5f49f7`](https://github.com/MadeRelevant/codemation/commit/d5f49f7f80deafc109dbc29f16ff0d571ee8591a), [`364507a`](https://github.com/MadeRelevant/codemation/commit/364507a9fba45fd66cb208d5a41ee1f3bdc68311), [`0dc8a9d`](https://github.com/MadeRelevant/codemation/commit/0dc8a9def376e4cd1821f3b92b0f887720e0c842), [`3facadf`](https://github.com/MadeRelevant/codemation/commit/3facadf3bc09d21f33e698213a521fb64168d5dd), [`c08cf33`](https://github.com/MadeRelevant/codemation/commit/c08cf33ead44fec64d3d43b9294fccfdf6674156), [`597fa8f`](https://github.com/MadeRelevant/codemation/commit/597fa8f697300d8d861a02c11e9819892f7947fa), [`b15f8c6`](https://github.com/MadeRelevant/codemation/commit/b15f8c68125e3ec3082bab8d79414871f942e409), [`bfdd759`](https://github.com/MadeRelevant/codemation/commit/bfdd7590b4903676b223c2f302b9bcd0f4a4583c), [`0a681b3`](https://github.com/MadeRelevant/codemation/commit/0a681b357afd7b15ba3925788c732fd439d8e6b0), [`ab5185a`](https://github.com/MadeRelevant/codemation/commit/ab5185a839118868eda1aab42b82f7a921037f37), [`fd188a2`](https://github.com/MadeRelevant/codemation/commit/fd188a2bac65c86dd62cf2f540034769c5bc0ac7), [`f2aa0c4`](https://github.com/MadeRelevant/codemation/commit/f2aa0c42b2f9d2e9eb7bc4f3393f74342f7ef460), [`cf2b146`](https://github.com/MadeRelevant/codemation/commit/cf2b146b452317e1ccaa1dfeaaa1a0e153181e30)]:
|
|
10
|
+
- @codemation/core@0.15.0
|
|
11
|
+
|
|
3
12
|
## 0.2.7
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -60,14 +60,9 @@ const azureContentUnderstandingCredentialType = defineCredential({
|
|
|
60
60
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/lib/analyzeWithAzure.ts
|
|
63
|
-
/**
|
|
64
|
-
* Analyzes a binary document using an Azure Content Understanding prebuilt analyzer.
|
|
65
|
-
* Retries on transient failures are handled by the engine via the node's `retryPolicy`.
|
|
66
|
-
*/
|
|
67
63
|
async function analyzeWithAzure(args) {
|
|
68
64
|
return mapAnalysisResult(await new ContentUnderstandingClient(args.session.endpoint, new AzureKeyCredential(args.session.apiKey)).analyzeBinary(args.analyzerId, args.body, args.contentType).pollUntilDone());
|
|
69
65
|
}
|
|
70
|
-
/** @internal Exported for testing — maps a raw AnalysisResult to the node output shape. */
|
|
71
66
|
function mapAnalysisResult(result) {
|
|
72
67
|
const contents = result.contents ?? [];
|
|
73
68
|
const markdownParts = [];
|
|
@@ -126,7 +121,6 @@ function resolveFieldKind(field) {
|
|
|
126
121
|
|
|
127
122
|
//#endregion
|
|
128
123
|
//#region src/nodes/analyzeDocumentNode.ts
|
|
129
|
-
/** Default Azure Content Understanding prebuilt general document analyzer ID. */
|
|
130
124
|
const DEFAULT_DOCUMENT_ANALYZER_ID = "prebuilt-document";
|
|
131
125
|
const analyzeDocumentNode = defineNode({
|
|
132
126
|
key: "azure-ocr.analyze-document",
|
|
@@ -180,7 +174,6 @@ const analyzeDocumentNode = defineNode({
|
|
|
180
174
|
|
|
181
175
|
//#endregion
|
|
182
176
|
//#region src/nodes/analyzeImageNode.ts
|
|
183
|
-
/** Default Azure Content Understanding prebuilt image analyzer ID. */
|
|
184
177
|
const DEFAULT_IMAGE_ANALYZER_ID = "prebuilt-imageAnalyzer";
|
|
185
178
|
const analyzeImageNode = defineNode({
|
|
186
179
|
key: "azure-ocr.analyze-image",
|
|
@@ -234,7 +227,6 @@ const analyzeImageNode = defineNode({
|
|
|
234
227
|
|
|
235
228
|
//#endregion
|
|
236
229
|
//#region src/nodes/analyzeInvoiceNode.ts
|
|
237
|
-
/** Azure Content Understanding prebuilt invoice analyzer ID. */
|
|
238
230
|
const PREBUILT_INVOICE_ANALYZER_ID = "prebuilt-invoice";
|
|
239
231
|
const analyzeInvoiceNode = defineNode({
|
|
240
232
|
key: "azure-ocr.analyze-invoice",
|
|
@@ -286,4 +278,4 @@ const analyzeInvoiceNode = defineNode({
|
|
|
286
278
|
|
|
287
279
|
//#endregion
|
|
288
280
|
export { mapAnalysisResult as a, analyzeWithAzure as i, analyzeImageNode as n, azureContentUnderstandingCredentialType as o, analyzeDocumentNode as r, analyzeInvoiceNode as t };
|
|
289
|
-
//# sourceMappingURL=analyzeInvoiceNode-
|
|
281
|
+
//# sourceMappingURL=analyzeInvoiceNode-BQzww-XC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzeInvoiceNode-BQzww-XC.js","names":["markdownParts: string[]","out: Record<string, unknown>"],"sources":["../src/credentials/azureContentUnderstandingCredential.ts","../src/lib/analyzeWithAzure.ts","../src/nodes/analyzeDocumentNode.ts","../src/nodes/analyzeImageNode.ts","../src/nodes/analyzeInvoiceNode.ts"],"sourcesContent":["import { ContentUnderstandingClient } from \"@azure/ai-content-understanding\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { defineCredential } from \"@codemation/core\";\n\nexport type AzureContentUnderstandingSession = Readonly<{\n endpoint: string;\n apiKey: string;\n}>;\n\nfunction normalizeEndpoint(raw: string): string {\n return raw.trim().replace(/\\/+$/, \"\");\n}\n\nfunction buildSession(args: {\n readonly publicConfig: Readonly<Record<string, unknown>>;\n readonly material: Readonly<Record<string, unknown>>;\n}): AzureContentUnderstandingSession {\n const endpoint = normalizeEndpoint(String(args.publicConfig[\"endpoint\"] ?? \"\"));\n const apiKey = String(args.material[\"apiKey\"] ?? \"\").trim();\n if (!endpoint) {\n throw new Error(\"Azure Content Understanding credential is incomplete: endpoint is required.\");\n }\n if (!apiKey) {\n throw new Error(\"Azure Content Understanding credential is incomplete: API key is required.\");\n }\n return { endpoint, apiKey };\n}\n\nexport const azureContentUnderstandingCredentialType = defineCredential({\n key: \"azure.contentUnderstanding\",\n label: \"Azure Content Understanding\",\n description: \"Azure AI Content Understanding (endpoint + key) for prebuilt document, invoice, and image analyzers.\",\n public: {\n endpoint: {\n key: \"endpoint\",\n label: \"Endpoint\",\n type: \"string\" as const,\n required: true,\n placeholder: \"https://your-resource.cognitiveservices.azure.com/\",\n helpText: \"Content Understanding resource endpoint URL (no trailing slash).\",\n order: 0,\n },\n },\n secret: {\n apiKey: {\n key: \"apiKey\",\n label: \"API key\",\n type: \"password\" as const,\n required: true,\n order: 1,\n },\n },\n async createSession(args) {\n return buildSession(args);\n },\n async test(args) {\n try {\n const session = buildSession(args);\n const client = new ContentUnderstandingClient(session.endpoint, new AzureKeyCredential(session.apiKey));\n const iter = client.listAnalyzers();\n await iter.next();\n return {\n status: \"healthy\",\n message: \"Listed analyzers successfully.\",\n testedAt: new Date().toISOString(),\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n status: \"failing\",\n message: message || \"Azure Content Understanding connection failed.\",\n testedAt: new Date().toISOString(),\n };\n }\n },\n});\n","import type {\n AnalysisResult,\n ArrayField,\n BooleanField,\n ContentField,\n ContentFieldUnion,\n DateField,\n IntegerField,\n JsonField,\n NumberField,\n ObjectField,\n StringField,\n TimeField,\n} from \"@azure/ai-content-understanding\";\nimport { ContentUnderstandingClient } from \"@azure/ai-content-understanding\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport type { AzureContentUnderstandingSession } from \"../credentials/azureContentUnderstandingCredential\";\n\nexport type OcrStructuredFields = Readonly<Record<string, unknown>>;\n\nexport type OcrAnalysisOutput = Readonly<{\n content: string;\n fields: OcrStructuredFields;\n}>;\n\nexport async function analyzeWithAzure(\n args: Readonly<{\n session: AzureContentUnderstandingSession;\n analyzerId: string;\n body: Uint8Array;\n contentType: string;\n }>,\n): Promise<OcrAnalysisOutput> {\n const client = new ContentUnderstandingClient(args.session.endpoint, new AzureKeyCredential(args.session.apiKey));\n const poller = client.analyzeBinary(args.analyzerId, args.body, args.contentType);\n const result = await poller.pollUntilDone();\n return mapAnalysisResult(result);\n}\n\nexport function mapAnalysisResult(result: AnalysisResult): OcrAnalysisOutput {\n const contents = result.contents ?? [];\n const markdownParts: string[] = [];\n for (const c of contents) {\n if (typeof c.markdown === \"string\" && c.markdown.length > 0) {\n markdownParts.push(c.markdown);\n }\n }\n const content = markdownParts.join(\"\\n\\n\");\n if (contents.length === 0) {\n return { content: \"\", fields: {} };\n }\n if (contents.length === 1) {\n const c = contents[0]!;\n return {\n content,\n fields: c.fields ? fieldsToStructuredMap(c.fields) : {},\n };\n }\n return {\n content,\n fields: {\n segments: contents.map((c, index) => ({\n index,\n markdown: typeof c.markdown === \"string\" && c.markdown.trim().length > 0 ? c.markdown : undefined,\n fields: c.fields ? fieldsToStructuredMap(c.fields) : {},\n })),\n },\n };\n}\n\nfunction fieldsToStructuredMap(fields: Readonly<Record<string, ContentFieldUnion>>): OcrStructuredFields {\n const out: Record<string, unknown> = {};\n for (const [name, field] of Object.entries(fields)) {\n out[name] = fieldToStructuredValue(field);\n }\n return out;\n}\n\nfunction fieldToStructuredValue(field: ContentFieldUnion): unknown {\n const kind = resolveFieldKind(field);\n switch (kind) {\n case \"string\":\n return (field as StringField).value ?? null;\n case \"date\": {\n const d = (field as DateField).value;\n return d ? d.toISOString() : null;\n }\n case \"time\":\n return (field as TimeField).value ?? null;\n case \"number\":\n return (field as NumberField).value ?? null;\n case \"integer\":\n return (field as IntegerField).value ?? null;\n case \"boolean\":\n return (field as BooleanField).value ?? null;\n case \"array\": {\n const values = (field as ArrayField).value ?? [];\n return values.map((element) => fieldToStructuredValue(element));\n }\n case \"object\": {\n const properties = (field as ObjectField).value ?? {};\n return fieldsToStructuredMap(properties);\n }\n case \"json\":\n return (field as JsonField).value ?? null;\n default: {\n const base = field as ContentField;\n if (base.value === undefined || base.value === null) {\n return null;\n }\n return typeof base.value === \"object\" ? base.value : String(base.value);\n }\n }\n}\n\nfunction resolveFieldKind(field: ContentFieldUnion): string {\n if (\"fieldType\" in field && typeof field.fieldType === \"string\") {\n return field.fieldType;\n }\n return (field as ContentField).type;\n}\n","import { defineNode } from \"@codemation/core\";\nimport type { AzureContentUnderstandingSession } from \"../credentials/azureContentUnderstandingCredential\";\nimport { azureContentUnderstandingCredentialType } from \"../credentials/azureContentUnderstandingCredential\";\nimport { analyzeWithAzure } from \"../lib/analyzeWithAzure\";\n\nconst DEFAULT_DOCUMENT_ANALYZER_ID = \"prebuilt-document\";\n\nexport type AnalyzeDocumentConfig = Readonly<{\n binaryField?: string;\n contentType?: string;\n analyzerId?: string;\n maxBytes?: number;\n}>;\n\nexport const analyzeDocumentNode = defineNode({\n key: \"azure-ocr.analyze-document\",\n title: \"Analyze Document\",\n description:\n \"Runs an Azure Content Understanding document analyzer on a binary attachment and returns markdown text plus structured fields. Defaults to the prebuilt general document analyzer.\",\n icon: \"lucide:scan-text\",\n input: {\n binaryField: \"data\",\n contentType: undefined as string | undefined,\n analyzerId: undefined as string | undefined,\n maxBytes: undefined as number | undefined,\n },\n credentials: {\n contentUnderstanding: {\n type: azureContentUnderstandingCredentialType as import(\"@codemation/core\").AnyCredentialType,\n label: \"Azure Content Understanding\",\n helpText: \"Bind an Azure Content Understanding credential (endpoint + key).\",\n },\n },\n inspectorSummary({ config }) {\n const cfg = config as unknown as AnalyzeDocumentConfig;\n const analyzerId = cfg.analyzerId ?? DEFAULT_DOCUMENT_ANALYZER_ID;\n const rows = [{ label: \"Analyzer\", value: analyzerId }];\n const binaryField = cfg.binaryField ?? \"data\";\n if (binaryField !== \"data\") {\n rows.push({ label: \"Binary field\", value: binaryField });\n }\n if (cfg.contentType) {\n rows.push({ label: \"Content type\", value: cfg.contentType });\n }\n return rows;\n },\n async execute({ item, ctx }, { config: rawConfig, credentials }) {\n const config = rawConfig as unknown as AnalyzeDocumentConfig;\n const session = (await credentials.contentUnderstanding()) as AzureContentUnderstandingSession;\n const binaryField = config.binaryField ?? \"data\";\n const attachment = item.binary?.[binaryField];\n if (!attachment) {\n throw new Error(`Analyze Document: no binary attachment at key \"${binaryField}\".`);\n }\n const analyzerId = config.analyzerId ?? DEFAULT_DOCUMENT_ANALYZER_ID;\n const contentType = config.contentType ?? attachment.mimeType ?? \"application/octet-stream\";\n const body = await ctx.binary.getBytes(attachment, config.maxBytes);\n return analyzeWithAzure({ session, analyzerId, body, contentType });\n },\n});\n","import { defineNode } from \"@codemation/core\";\nimport type { AzureContentUnderstandingSession } from \"../credentials/azureContentUnderstandingCredential\";\nimport { azureContentUnderstandingCredentialType } from \"../credentials/azureContentUnderstandingCredential\";\nimport { analyzeWithAzure } from \"../lib/analyzeWithAzure\";\n\nconst DEFAULT_IMAGE_ANALYZER_ID = \"prebuilt-imageAnalyzer\";\n\nexport type AnalyzeImageConfig = Readonly<{\n binaryField?: string;\n contentType?: string;\n analyzerId?: string;\n maxBytes?: number;\n}>;\n\nexport const analyzeImageNode = defineNode({\n key: \"azure-ocr.analyze-image\",\n title: \"Analyze Image\",\n description:\n \"Runs an Azure Content Understanding image analyzer on a binary attachment and returns markdown text plus structured fields. Defaults to the prebuilt image analyzer.\",\n icon: \"lucide:image-search\",\n input: {\n binaryField: \"data\",\n contentType: undefined as string | undefined,\n analyzerId: undefined as string | undefined,\n maxBytes: undefined as number | undefined,\n },\n credentials: {\n contentUnderstanding: {\n type: azureContentUnderstandingCredentialType as import(\"@codemation/core\").AnyCredentialType,\n label: \"Azure Content Understanding\",\n helpText: \"Bind an Azure Content Understanding credential (endpoint + key).\",\n },\n },\n inspectorSummary({ config }) {\n const cfg = config as unknown as AnalyzeImageConfig;\n const analyzerId = cfg.analyzerId ?? DEFAULT_IMAGE_ANALYZER_ID;\n const rows = [{ label: \"Analyzer\", value: analyzerId }];\n const binaryField = cfg.binaryField ?? \"data\";\n if (binaryField !== \"data\") {\n rows.push({ label: \"Binary field\", value: binaryField });\n }\n if (cfg.contentType) {\n rows.push({ label: \"Content type\", value: cfg.contentType });\n }\n return rows;\n },\n async execute({ item, ctx }, { config: rawConfig, credentials }) {\n const config = rawConfig as unknown as AnalyzeImageConfig;\n const session = (await credentials.contentUnderstanding()) as AzureContentUnderstandingSession;\n const binaryField = config.binaryField ?? \"data\";\n const attachment = item.binary?.[binaryField];\n if (!attachment) {\n throw new Error(`Analyze Image: no binary attachment at key \"${binaryField}\".`);\n }\n const analyzerId = config.analyzerId ?? DEFAULT_IMAGE_ANALYZER_ID;\n const contentType = config.contentType ?? attachment.mimeType ?? \"application/octet-stream\";\n const body = await ctx.binary.getBytes(attachment, config.maxBytes);\n return analyzeWithAzure({ session, analyzerId, body, contentType });\n },\n});\n","import { defineNode } from \"@codemation/core\";\nimport type { AzureContentUnderstandingSession } from \"../credentials/azureContentUnderstandingCredential\";\nimport { azureContentUnderstandingCredentialType } from \"../credentials/azureContentUnderstandingCredential\";\nimport { analyzeWithAzure } from \"../lib/analyzeWithAzure\";\n\nconst PREBUILT_INVOICE_ANALYZER_ID = \"prebuilt-invoice\";\n\nexport type AnalyzeInvoiceConfig = Readonly<{\n binaryField?: string;\n contentType?: string;\n maxBytes?: number;\n}>;\n\nexport const analyzeInvoiceNode = defineNode({\n key: \"azure-ocr.analyze-invoice\",\n title: \"Analyze Invoice\",\n description:\n \"Runs the Azure Content Understanding prebuilt invoice analyzer on a binary attachment and returns markdown text plus structured fields.\",\n icon: \"lucide:receipt\",\n input: {\n binaryField: \"data\",\n contentType: undefined as string | undefined,\n maxBytes: undefined as number | undefined,\n },\n credentials: {\n contentUnderstanding: {\n type: azureContentUnderstandingCredentialType as import(\"@codemation/core\").AnyCredentialType,\n label: \"Azure Content Understanding\",\n helpText: \"Bind an Azure Content Understanding credential (endpoint + key).\",\n },\n },\n inspectorSummary({ config }) {\n const cfg = config as unknown as AnalyzeInvoiceConfig;\n const rows = [{ label: \"Analyzer\", value: \"Invoice (prebuilt)\" }];\n const binaryField = cfg.binaryField ?? \"data\";\n if (binaryField !== \"data\") {\n rows.push({ label: \"Binary field\", value: binaryField });\n }\n if (cfg.contentType) {\n rows.push({ label: \"Content type\", value: cfg.contentType });\n }\n return rows;\n },\n async execute({ item, ctx }, { config: rawConfig, credentials }) {\n const config = rawConfig as unknown as AnalyzeInvoiceConfig;\n const session = (await credentials.contentUnderstanding()) as AzureContentUnderstandingSession;\n const binaryField = config.binaryField ?? \"data\";\n const attachment = item.binary?.[binaryField];\n if (!attachment) {\n throw new Error(`Analyze Invoice: no binary attachment at key \"${binaryField}\".`);\n }\n const contentType = config.contentType ?? attachment.mimeType ?? \"application/octet-stream\";\n const body = await ctx.binary.getBytes(attachment, config.maxBytes);\n return analyzeWithAzure({ session, analyzerId: PREBUILT_INVOICE_ANALYZER_ID, body, contentType });\n },\n});\n"],"mappings":";;;;;AASA,SAAS,kBAAkB,KAAqB;AAC9C,QAAO,IAAI,MAAM,CAAC,QAAQ,QAAQ,GAAG;;AAGvC,SAAS,aAAa,MAGe;CACnC,MAAM,WAAW,kBAAkB,OAAO,KAAK,aAAa,eAAe,GAAG,CAAC;CAC/E,MAAM,SAAS,OAAO,KAAK,SAAS,aAAa,GAAG,CAAC,MAAM;AAC3D,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,8EAA8E;AAEhG,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,6EAA6E;AAE/F,QAAO;EAAE;EAAU;EAAQ;;AAG7B,MAAa,0CAA0C,iBAAiB;CACtE,KAAK;CACL,OAAO;CACP,aAAa;CACb,QAAQ,EACN,UAAU;EACR,KAAK;EACL,OAAO;EACP,MAAM;EACN,UAAU;EACV,aAAa;EACb,UAAU;EACV,OAAO;EACR,EACF;CACD,QAAQ,EACN,QAAQ;EACN,KAAK;EACL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,aAAa,KAAK,SAAS;AACjC,MAAI,CAAC,WACH,OAAM,IAAI,MAAM,iDAAiD,YAAY,IAAI;EAEnF,MAAM,cAAc,OAAO,eAAe,WAAW,YAAY;AAEjE,SAAO,iBAAiB;GAAE;GAAS,YAAY;GAA8B,MADhE,MAAM,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS;GACgB;GAAa,CAAC;;CAEpG,CAAC"}
|
|
@@ -64,14 +64,9 @@ const azureContentUnderstandingCredentialType = (0, __codemation_core.defineCred
|
|
|
64
64
|
|
|
65
65
|
//#endregion
|
|
66
66
|
//#region src/lib/analyzeWithAzure.ts
|
|
67
|
-
/**
|
|
68
|
-
* Analyzes a binary document using an Azure Content Understanding prebuilt analyzer.
|
|
69
|
-
* Retries on transient failures are handled by the engine via the node's `retryPolicy`.
|
|
70
|
-
*/
|
|
71
67
|
async function analyzeWithAzure(args) {
|
|
72
68
|
return mapAnalysisResult(await new __azure_ai_content_understanding.ContentUnderstandingClient(args.session.endpoint, new __azure_core_auth.AzureKeyCredential(args.session.apiKey)).analyzeBinary(args.analyzerId, args.body, args.contentType).pollUntilDone());
|
|
73
69
|
}
|
|
74
|
-
/** @internal Exported for testing — maps a raw AnalysisResult to the node output shape. */
|
|
75
70
|
function mapAnalysisResult(result) {
|
|
76
71
|
const contents = result.contents ?? [];
|
|
77
72
|
const markdownParts = [];
|
|
@@ -130,7 +125,6 @@ function resolveFieldKind(field) {
|
|
|
130
125
|
|
|
131
126
|
//#endregion
|
|
132
127
|
//#region src/nodes/analyzeDocumentNode.ts
|
|
133
|
-
/** Default Azure Content Understanding prebuilt general document analyzer ID. */
|
|
134
128
|
const DEFAULT_DOCUMENT_ANALYZER_ID = "prebuilt-document";
|
|
135
129
|
const analyzeDocumentNode = (0, __codemation_core.defineNode)({
|
|
136
130
|
key: "azure-ocr.analyze-document",
|
|
@@ -184,7 +178,6 @@ const analyzeDocumentNode = (0, __codemation_core.defineNode)({
|
|
|
184
178
|
|
|
185
179
|
//#endregion
|
|
186
180
|
//#region src/nodes/analyzeImageNode.ts
|
|
187
|
-
/** Default Azure Content Understanding prebuilt image analyzer ID. */
|
|
188
181
|
const DEFAULT_IMAGE_ANALYZER_ID = "prebuilt-imageAnalyzer";
|
|
189
182
|
const analyzeImageNode = (0, __codemation_core.defineNode)({
|
|
190
183
|
key: "azure-ocr.analyze-image",
|
|
@@ -238,7 +231,6 @@ const analyzeImageNode = (0, __codemation_core.defineNode)({
|
|
|
238
231
|
|
|
239
232
|
//#endregion
|
|
240
233
|
//#region src/nodes/analyzeInvoiceNode.ts
|
|
241
|
-
/** Azure Content Understanding prebuilt invoice analyzer ID. */
|
|
242
234
|
const PREBUILT_INVOICE_ANALYZER_ID = "prebuilt-invoice";
|
|
243
235
|
const analyzeInvoiceNode = (0, __codemation_core.defineNode)({
|
|
244
236
|
key: "azure-ocr.analyze-invoice",
|
|
@@ -325,4 +317,4 @@ Object.defineProperty(exports, 'mapAnalysisResult', {
|
|
|
325
317
|
return mapAnalysisResult;
|
|
326
318
|
}
|
|
327
319
|
});
|
|
328
|
-
//# sourceMappingURL=analyzeInvoiceNode-
|
|
320
|
+
//# sourceMappingURL=analyzeInvoiceNode-CW_SXNQf.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzeInvoiceNode-CW_SXNQf.cjs","names":["ContentUnderstandingClient","AzureKeyCredential","ContentUnderstandingClient","AzureKeyCredential","markdownParts: string[]","out: Record<string, unknown>"],"sources":["../src/credentials/azureContentUnderstandingCredential.ts","../src/lib/analyzeWithAzure.ts","../src/nodes/analyzeDocumentNode.ts","../src/nodes/analyzeImageNode.ts","../src/nodes/analyzeInvoiceNode.ts"],"sourcesContent":["import { ContentUnderstandingClient } from \"@azure/ai-content-understanding\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { defineCredential } from \"@codemation/core\";\n\nexport type AzureContentUnderstandingSession = Readonly<{\n endpoint: string;\n apiKey: string;\n}>;\n\nfunction normalizeEndpoint(raw: string): string {\n return raw.trim().replace(/\\/+$/, \"\");\n}\n\nfunction buildSession(args: {\n readonly publicConfig: Readonly<Record<string, unknown>>;\n readonly material: Readonly<Record<string, unknown>>;\n}): AzureContentUnderstandingSession {\n const endpoint = normalizeEndpoint(String(args.publicConfig[\"endpoint\"] ?? \"\"));\n const apiKey = String(args.material[\"apiKey\"] ?? \"\").trim();\n if (!endpoint) {\n throw new Error(\"Azure Content Understanding credential is incomplete: endpoint is required.\");\n }\n if (!apiKey) {\n throw new Error(\"Azure Content Understanding credential is incomplete: API key is required.\");\n }\n return { endpoint, apiKey };\n}\n\nexport const azureContentUnderstandingCredentialType = defineCredential({\n key: \"azure.contentUnderstanding\",\n label: \"Azure Content Understanding\",\n description: \"Azure AI Content Understanding (endpoint + key) for prebuilt document, invoice, and image analyzers.\",\n public: {\n endpoint: {\n key: \"endpoint\",\n label: \"Endpoint\",\n type: \"string\" as const,\n required: true,\n placeholder: \"https://your-resource.cognitiveservices.azure.com/\",\n helpText: \"Content Understanding resource endpoint URL (no trailing slash).\",\n order: 0,\n },\n },\n secret: {\n apiKey: {\n key: \"apiKey\",\n label: \"API key\",\n type: \"password\" as const,\n required: true,\n order: 1,\n },\n },\n async createSession(args) {\n return buildSession(args);\n },\n async test(args) {\n try {\n const session = buildSession(args);\n const client = new ContentUnderstandingClient(session.endpoint, new AzureKeyCredential(session.apiKey));\n const iter = client.listAnalyzers();\n await iter.next();\n return {\n status: \"healthy\",\n message: \"Listed analyzers successfully.\",\n testedAt: new Date().toISOString(),\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n status: \"failing\",\n message: message || \"Azure Content Understanding connection failed.\",\n testedAt: new Date().toISOString(),\n };\n }\n },\n});\n","import type {\n AnalysisResult,\n ArrayField,\n BooleanField,\n ContentField,\n ContentFieldUnion,\n DateField,\n IntegerField,\n JsonField,\n NumberField,\n ObjectField,\n StringField,\n TimeField,\n} from \"@azure/ai-content-understanding\";\nimport { ContentUnderstandingClient } from \"@azure/ai-content-understanding\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport type { AzureContentUnderstandingSession } from \"../credentials/azureContentUnderstandingCredential\";\n\nexport type OcrStructuredFields = Readonly<Record<string, unknown>>;\n\nexport type OcrAnalysisOutput = Readonly<{\n content: string;\n fields: OcrStructuredFields;\n}>;\n\nexport async function analyzeWithAzure(\n args: Readonly<{\n session: AzureContentUnderstandingSession;\n analyzerId: string;\n body: Uint8Array;\n contentType: string;\n }>,\n): Promise<OcrAnalysisOutput> {\n const client = new ContentUnderstandingClient(args.session.endpoint, new AzureKeyCredential(args.session.apiKey));\n const poller = client.analyzeBinary(args.analyzerId, args.body, args.contentType);\n const result = await poller.pollUntilDone();\n return mapAnalysisResult(result);\n}\n\nexport function mapAnalysisResult(result: AnalysisResult): OcrAnalysisOutput {\n const contents = result.contents ?? [];\n const markdownParts: string[] = [];\n for (const c of contents) {\n if (typeof c.markdown === \"string\" && c.markdown.length > 0) {\n markdownParts.push(c.markdown);\n }\n }\n const content = markdownParts.join(\"\\n\\n\");\n if (contents.length === 0) {\n return { content: \"\", fields: {} };\n }\n if (contents.length === 1) {\n const c = contents[0]!;\n return {\n content,\n fields: c.fields ? fieldsToStructuredMap(c.fields) : {},\n };\n }\n return {\n content,\n fields: {\n segments: contents.map((c, index) => ({\n index,\n markdown: typeof c.markdown === \"string\" && c.markdown.trim().length > 0 ? c.markdown : undefined,\n fields: c.fields ? fieldsToStructuredMap(c.fields) : {},\n })),\n },\n };\n}\n\nfunction fieldsToStructuredMap(fields: Readonly<Record<string, ContentFieldUnion>>): OcrStructuredFields {\n const out: Record<string, unknown> = {};\n for (const [name, field] of Object.entries(fields)) {\n out[name] = fieldToStructuredValue(field);\n }\n return out;\n}\n\nfunction fieldToStructuredValue(field: ContentFieldUnion): unknown {\n const kind = resolveFieldKind(field);\n switch (kind) {\n case \"string\":\n return (field as StringField).value ?? null;\n case \"date\": {\n const d = (field as DateField).value;\n return d ? d.toISOString() : null;\n }\n case \"time\":\n return (field as TimeField).value ?? null;\n case \"number\":\n return (field as NumberField).value ?? null;\n case \"integer\":\n return (field as IntegerField).value ?? null;\n case \"boolean\":\n return (field as BooleanField).value ?? null;\n case \"array\": {\n const values = (field as ArrayField).value ?? [];\n return values.map((element) => fieldToStructuredValue(element));\n }\n case \"object\": {\n const properties = (field as ObjectField).value ?? {};\n return fieldsToStructuredMap(properties);\n }\n case \"json\":\n return (field as JsonField).value ?? null;\n default: {\n const base = field as ContentField;\n if (base.value === undefined || base.value === null) {\n return null;\n }\n return typeof base.value === \"object\" ? base.value : String(base.value);\n }\n }\n}\n\nfunction resolveFieldKind(field: ContentFieldUnion): string {\n if (\"fieldType\" in field && typeof field.fieldType === \"string\") {\n return field.fieldType;\n }\n return (field as ContentField).type;\n}\n","import { defineNode } from \"@codemation/core\";\nimport type { AzureContentUnderstandingSession } from \"../credentials/azureContentUnderstandingCredential\";\nimport { azureContentUnderstandingCredentialType } from \"../credentials/azureContentUnderstandingCredential\";\nimport { analyzeWithAzure } from \"../lib/analyzeWithAzure\";\n\nconst DEFAULT_DOCUMENT_ANALYZER_ID = \"prebuilt-document\";\n\nexport type AnalyzeDocumentConfig = Readonly<{\n binaryField?: string;\n contentType?: string;\n analyzerId?: string;\n maxBytes?: number;\n}>;\n\nexport const analyzeDocumentNode = defineNode({\n key: \"azure-ocr.analyze-document\",\n title: \"Analyze Document\",\n description:\n \"Runs an Azure Content Understanding document analyzer on a binary attachment and returns markdown text plus structured fields. Defaults to the prebuilt general document analyzer.\",\n icon: \"lucide:scan-text\",\n input: {\n binaryField: \"data\",\n contentType: undefined as string | undefined,\n analyzerId: undefined as string | undefined,\n maxBytes: undefined as number | undefined,\n },\n credentials: {\n contentUnderstanding: {\n type: azureContentUnderstandingCredentialType as import(\"@codemation/core\").AnyCredentialType,\n label: \"Azure Content Understanding\",\n helpText: \"Bind an Azure Content Understanding credential (endpoint + key).\",\n },\n },\n inspectorSummary({ config }) {\n const cfg = config as unknown as AnalyzeDocumentConfig;\n const analyzerId = cfg.analyzerId ?? DEFAULT_DOCUMENT_ANALYZER_ID;\n const rows = [{ label: \"Analyzer\", value: analyzerId }];\n const binaryField = cfg.binaryField ?? \"data\";\n if (binaryField !== \"data\") {\n rows.push({ label: \"Binary field\", value: binaryField });\n }\n if (cfg.contentType) {\n rows.push({ label: \"Content type\", value: cfg.contentType });\n }\n return rows;\n },\n async execute({ item, ctx }, { config: rawConfig, credentials }) {\n const config = rawConfig as unknown as AnalyzeDocumentConfig;\n const session = (await credentials.contentUnderstanding()) as AzureContentUnderstandingSession;\n const binaryField = config.binaryField ?? \"data\";\n const attachment = item.binary?.[binaryField];\n if (!attachment) {\n throw new Error(`Analyze Document: no binary attachment at key \"${binaryField}\".`);\n }\n const analyzerId = config.analyzerId ?? DEFAULT_DOCUMENT_ANALYZER_ID;\n const contentType = config.contentType ?? attachment.mimeType ?? \"application/octet-stream\";\n const body = await ctx.binary.getBytes(attachment, config.maxBytes);\n return analyzeWithAzure({ session, analyzerId, body, contentType });\n },\n});\n","import { defineNode } from \"@codemation/core\";\nimport type { AzureContentUnderstandingSession } from \"../credentials/azureContentUnderstandingCredential\";\nimport { azureContentUnderstandingCredentialType } from \"../credentials/azureContentUnderstandingCredential\";\nimport { analyzeWithAzure } from \"../lib/analyzeWithAzure\";\n\nconst DEFAULT_IMAGE_ANALYZER_ID = \"prebuilt-imageAnalyzer\";\n\nexport type AnalyzeImageConfig = Readonly<{\n binaryField?: string;\n contentType?: string;\n analyzerId?: string;\n maxBytes?: number;\n}>;\n\nexport const analyzeImageNode = defineNode({\n key: \"azure-ocr.analyze-image\",\n title: \"Analyze Image\",\n description:\n \"Runs an Azure Content Understanding image analyzer on a binary attachment and returns markdown text plus structured fields. Defaults to the prebuilt image analyzer.\",\n icon: \"lucide:image-search\",\n input: {\n binaryField: \"data\",\n contentType: undefined as string | undefined,\n analyzerId: undefined as string | undefined,\n maxBytes: undefined as number | undefined,\n },\n credentials: {\n contentUnderstanding: {\n type: azureContentUnderstandingCredentialType as import(\"@codemation/core\").AnyCredentialType,\n label: \"Azure Content Understanding\",\n helpText: \"Bind an Azure Content Understanding credential (endpoint + key).\",\n },\n },\n inspectorSummary({ config }) {\n const cfg = config as unknown as AnalyzeImageConfig;\n const analyzerId = cfg.analyzerId ?? DEFAULT_IMAGE_ANALYZER_ID;\n const rows = [{ label: \"Analyzer\", value: analyzerId }];\n const binaryField = cfg.binaryField ?? \"data\";\n if (binaryField !== \"data\") {\n rows.push({ label: \"Binary field\", value: binaryField });\n }\n if (cfg.contentType) {\n rows.push({ label: \"Content type\", value: cfg.contentType });\n }\n return rows;\n },\n async execute({ item, ctx }, { config: rawConfig, credentials }) {\n const config = rawConfig as unknown as AnalyzeImageConfig;\n const session = (await credentials.contentUnderstanding()) as AzureContentUnderstandingSession;\n const binaryField = config.binaryField ?? \"data\";\n const attachment = item.binary?.[binaryField];\n if (!attachment) {\n throw new Error(`Analyze Image: no binary attachment at key \"${binaryField}\".`);\n }\n const analyzerId = config.analyzerId ?? DEFAULT_IMAGE_ANALYZER_ID;\n const contentType = config.contentType ?? attachment.mimeType ?? \"application/octet-stream\";\n const body = await ctx.binary.getBytes(attachment, config.maxBytes);\n return analyzeWithAzure({ session, analyzerId, body, contentType });\n },\n});\n","import { defineNode } from \"@codemation/core\";\nimport type { AzureContentUnderstandingSession } from \"../credentials/azureContentUnderstandingCredential\";\nimport { azureContentUnderstandingCredentialType } from \"../credentials/azureContentUnderstandingCredential\";\nimport { analyzeWithAzure } from \"../lib/analyzeWithAzure\";\n\nconst PREBUILT_INVOICE_ANALYZER_ID = \"prebuilt-invoice\";\n\nexport type AnalyzeInvoiceConfig = Readonly<{\n binaryField?: string;\n contentType?: string;\n maxBytes?: number;\n}>;\n\nexport const analyzeInvoiceNode = defineNode({\n key: \"azure-ocr.analyze-invoice\",\n title: \"Analyze Invoice\",\n description:\n \"Runs the Azure Content Understanding prebuilt invoice analyzer on a binary attachment and returns markdown text plus structured fields.\",\n icon: \"lucide:receipt\",\n input: {\n binaryField: \"data\",\n contentType: undefined as string | undefined,\n maxBytes: undefined as number | undefined,\n },\n credentials: {\n contentUnderstanding: {\n type: azureContentUnderstandingCredentialType as import(\"@codemation/core\").AnyCredentialType,\n label: \"Azure Content Understanding\",\n helpText: \"Bind an Azure Content Understanding credential (endpoint + key).\",\n },\n },\n inspectorSummary({ config }) {\n const cfg = config as unknown as AnalyzeInvoiceConfig;\n const rows = [{ label: \"Analyzer\", value: \"Invoice (prebuilt)\" }];\n const binaryField = cfg.binaryField ?? \"data\";\n if (binaryField !== \"data\") {\n rows.push({ label: \"Binary field\", value: binaryField });\n }\n if (cfg.contentType) {\n rows.push({ label: \"Content type\", value: cfg.contentType });\n }\n return rows;\n },\n async execute({ item, ctx }, { config: rawConfig, credentials }) {\n const config = rawConfig as unknown as AnalyzeInvoiceConfig;\n const session = (await credentials.contentUnderstanding()) as AzureContentUnderstandingSession;\n const binaryField = config.binaryField ?? \"data\";\n const attachment = item.binary?.[binaryField];\n if (!attachment) {\n throw new Error(`Analyze Invoice: no binary attachment at key \"${binaryField}\".`);\n }\n const contentType = config.contentType ?? attachment.mimeType ?? \"application/octet-stream\";\n const body = await ctx.binary.getBytes(attachment, config.maxBytes);\n return analyzeWithAzure({ session, analyzerId: PREBUILT_INVOICE_ANALYZER_ID, body, contentType });\n },\n});\n"],"mappings":";;;;;;;;;AASA,SAAS,kBAAkB,KAAqB;AAC9C,QAAO,IAAI,MAAM,CAAC,QAAQ,QAAQ,GAAG;;AAGvC,SAAS,aAAa,MAGe;CACnC,MAAM,WAAW,kBAAkB,OAAO,KAAK,aAAa,eAAe,GAAG,CAAC;CAC/E,MAAM,SAAS,OAAO,KAAK,SAAS,aAAa,GAAG,CAAC,MAAM;AAC3D,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,8EAA8E;AAEhG,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,6EAA6E;AAE/F,QAAO;EAAE;EAAU;EAAQ;;AAG7B,MAAa,kFAA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