@codemation/core-nodes-ocr 0.2.3 → 0.2.5
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 +14 -0
- package/dist/{analyzeInvoiceNode-uVwe3GHD.js → analyzeInvoiceNode-BqZsN8iL.js} +4 -36
- package/dist/analyzeInvoiceNode-BqZsN8iL.js.map +1 -0
- package/dist/{analyzeInvoiceNode-BIw8j_Zb.cjs → analyzeInvoiceNode-CmMsifbw.cjs} +4 -36
- package/dist/analyzeInvoiceNode-CmMsifbw.cjs.map +1 -0
- package/dist/codemation.plugin.cjs +140 -49
- package/dist/codemation.plugin.cjs.map +1 -1
- package/dist/codemation.plugin.d.cts +10 -3
- package/dist/codemation.plugin.d.ts +10 -3
- package/dist/codemation.plugin.js +140 -49
- package/dist/codemation.plugin.js.map +1 -1
- package/dist/{index-rc7dB1Ws.d.ts → index-DF2ht42F.d.ts} +20 -4
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/metadata.json +1 -1
- package/dist/{runtimeTypes-MQgcsey7.d.cts → runtimeTypes-WCvsnJMY.d.cts} +17 -1
- package/package.json +2 -2
- package/src/nodes/analyzeDocumentNode.ts +1 -2
- package/src/nodes/analyzeImageNode.ts +1 -2
- package/src/nodes/analyzeInvoiceNode.ts +1 -2
- package/dist/analyzeInvoiceNode-BIw8j_Zb.cjs.map +0 -1
- package/dist/analyzeInvoiceNode-uVwe3GHD.js.map +0 -1
- package/src/lib/readBinaryBody.ts +0 -51
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Container, l as TypeToken, s as WorkflowDefinition, u as AnyCredentialType } from "./runtimeTypes-
|
|
1
|
+
import { c as Container, l as TypeToken, s as WorkflowDefinition, u as AnyCredentialType } from "./runtimeTypes-WCvsnJMY.cjs";
|
|
2
2
|
import { BetterAuthOptions } from "better-auth";
|
|
3
3
|
|
|
4
4
|
//#region ../core/src/contracts/mcpTypes.d.ts
|
|
@@ -277,6 +277,15 @@ interface AppConfig {
|
|
|
277
277
|
readonly repoRoot: string;
|
|
278
278
|
readonly env: Readonly<NodeJS.ProcessEnv>;
|
|
279
279
|
readonly workflowSources: ReadonlyArray<string>;
|
|
280
|
+
/**
|
|
281
|
+
* The discovery directories from `workflowDiscovery.directories` (or the `workflowsDir`
|
|
282
|
+
* shorthand). Stored here so the runtime can re-scan on demand in `serve` mode without
|
|
283
|
+
* needing the raw `CodemationConfig`.
|
|
284
|
+
*
|
|
285
|
+
* Absent or empty when no directory-based discovery is configured (i.e. workflows are
|
|
286
|
+
* provided only via the explicit `workflows` array).
|
|
287
|
+
*/
|
|
288
|
+
readonly workflowDiscoveryDirectories?: ReadonlyArray<string>;
|
|
280
289
|
readonly workflows: ReadonlyArray<WorkflowDefinition>;
|
|
281
290
|
readonly containerRegistrations: ReadonlyArray<CodemationContainerRegistration<unknown>>;
|
|
282
291
|
readonly credentialTypes: ReadonlyArray<AnyCredentialType>;
|
|
@@ -303,8 +312,6 @@ interface AppConfig {
|
|
|
303
312
|
}>;
|
|
304
313
|
readonly auth?: CodemationAuthConfig;
|
|
305
314
|
readonly whitelabel: CodemationWhitelabelConfig;
|
|
306
|
-
readonly webSocketPort: number;
|
|
307
|
-
readonly webSocketBindHost: string;
|
|
308
315
|
}
|
|
309
316
|
//#endregion
|
|
310
317
|
//#region ../host/src/presentation/config/CodemationAppContext.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as TypeToken, c as McpServerDeclaration, i as Container, l as AnyCredentialType, n as DefinedCollection, o as EngineExecutionLimitsPolicyConfig, r as WorkflowDefinition, t as CollectionDefinition } from "./index-
|
|
1
|
+
import { a as TypeToken, c as McpServerDeclaration, i as Container, l as AnyCredentialType, n as DefinedCollection, o as EngineExecutionLimitsPolicyConfig, r as WorkflowDefinition, t as CollectionDefinition } from "./index-DF2ht42F.js";
|
|
2
2
|
import { ZodType, z } from "zod";
|
|
3
3
|
import { BetterAuthOptions } from "better-auth";
|
|
4
4
|
|
|
@@ -217,6 +217,15 @@ interface AppConfig {
|
|
|
217
217
|
readonly repoRoot: string;
|
|
218
218
|
readonly env: Readonly<NodeJS.ProcessEnv>;
|
|
219
219
|
readonly workflowSources: ReadonlyArray<string>;
|
|
220
|
+
/**
|
|
221
|
+
* The discovery directories from `workflowDiscovery.directories` (or the `workflowsDir`
|
|
222
|
+
* shorthand). Stored here so the runtime can re-scan on demand in `serve` mode without
|
|
223
|
+
* needing the raw `CodemationConfig`.
|
|
224
|
+
*
|
|
225
|
+
* Absent or empty when no directory-based discovery is configured (i.e. workflows are
|
|
226
|
+
* provided only via the explicit `workflows` array).
|
|
227
|
+
*/
|
|
228
|
+
readonly workflowDiscoveryDirectories?: ReadonlyArray<string>;
|
|
220
229
|
readonly workflows: ReadonlyArray<WorkflowDefinition>;
|
|
221
230
|
readonly containerRegistrations: ReadonlyArray<CodemationContainerRegistration<unknown>>;
|
|
222
231
|
readonly credentialTypes: ReadonlyArray<AnyCredentialType>;
|
|
@@ -243,8 +252,6 @@ interface AppConfig {
|
|
|
243
252
|
}>;
|
|
244
253
|
readonly auth?: CodemationAuthConfig;
|
|
245
254
|
readonly whitelabel: CodemationWhitelabelConfig;
|
|
246
|
-
readonly webSocketPort: number;
|
|
247
|
-
readonly webSocketBindHost: string;
|
|
248
255
|
}
|
|
249
256
|
//#endregion
|
|
250
257
|
//#region ../host/src/presentation/config/CodemationAppContext.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as __toDynamicImportESM, i as __commonJS, n as require_auth_errors, o as __toESM, r as require_token_error, t as require_token_util } from "./token-util-EUxa8JtH.js";
|
|
2
|
-
import { n as analyzeImageNode, o as azureContentUnderstandingCredentialType, r as analyzeDocumentNode, t as analyzeInvoiceNode } from "./analyzeInvoiceNode-
|
|
2
|
+
import { n as analyzeImageNode, o as azureContentUnderstandingCredentialType, r as analyzeDocumentNode, t as analyzeInvoiceNode } from "./analyzeInvoiceNode-BqZsN8iL.js";
|
|
3
3
|
import { AgentConfigInspector, AgentGuardrailDefaults, AgentMessageConfigNormalizer, CallableToolConfig, ChildExecutionScopeFactory, CodemationTelemetryAttributeNames, CodemationTelemetryMetricNames, ConnectionInvocationIdFactory, ConnectionNodeIdFactory, CoreTokens, GenAiTelemetryAttributeNames, InboxChannelResolverToken, ItemExprResolver, ItemsInputNormalizer, NodeBackedToolConfig, NodeOutputNormalizer, RunnableOutputBehaviorResolver, SuspensionRequest, chatModel, defineCredential, defineHumanApprovalNode, defineNode, emitPorts, getOriginIndexFromItem, inject, injectable, isPortsEmission, node } from "@codemation/core";
|
|
4
4
|
import dns from "node:dns/promises";
|
|
5
5
|
import * as z4 from "zod/v4";
|
|
@@ -8281,6 +8281,59 @@ var OpenAiChatModelPresets = class {
|
|
|
8281
8281
|
};
|
|
8282
8282
|
const openAiChatModelPresets = new OpenAiChatModelPresets();
|
|
8283
8283
|
|
|
8284
|
+
//#endregion
|
|
8285
|
+
//#region ../core-nodes/src/chatModels/ManagedHmacSignerFactory.types.ts
|
|
8286
|
+
/**
|
|
8287
|
+
* Creates an HMAC-signing fetch wrapper that authenticates requests to
|
|
8288
|
+
* Codemation managed services (LLM broker, doc-scanner) with the
|
|
8289
|
+
* Codemation-Hmac v=1 scheme.
|
|
8290
|
+
*
|
|
8291
|
+
* Mirrors HmacRequestSigner from @codemation/host/pairing without importing
|
|
8292
|
+
* that package (which would create a circular dependency since @codemation/host
|
|
8293
|
+
* depends on @codemation/core-nodes).
|
|
8294
|
+
*
|
|
8295
|
+
* @param workspaceId - Workspace identifier injected by the CP provisioner.
|
|
8296
|
+
* @param pairingSecret - Base64-encoded 32-byte HMAC key injected by the provisioner.
|
|
8297
|
+
* @param options - Optional behaviour flags and test seams.
|
|
8298
|
+
*/
|
|
8299
|
+
function managedHmacFetchFactory(workspaceId, pairingSecret, options) {
|
|
8300
|
+
const signBody = options?.signBody ?? true;
|
|
8301
|
+
return async (input, init) => {
|
|
8302
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
8303
|
+
const method = init?.method ?? "POST";
|
|
8304
|
+
let bodyForSigning = "";
|
|
8305
|
+
if (signBody && init?.body !== void 0 && init.body !== null) bodyForSigning = typeof init.body === "string" ? init.body : await new Response(init.body).text();
|
|
8306
|
+
const authHeader = buildHmacAuthHeader(workspaceId, pairingSecret, method, url, bodyForSigning, options);
|
|
8307
|
+
const headers = new Headers(init?.headers);
|
|
8308
|
+
headers.set("Authorization", authHeader);
|
|
8309
|
+
const outgoingBody = signBody ? bodyForSigning || init?.body : init?.body;
|
|
8310
|
+
return fetch(input, {
|
|
8311
|
+
...init,
|
|
8312
|
+
body: outgoingBody,
|
|
8313
|
+
headers
|
|
8314
|
+
});
|
|
8315
|
+
};
|
|
8316
|
+
}
|
|
8317
|
+
/**
|
|
8318
|
+
* Produces a Codemation-Hmac v=1 Authorization header value.
|
|
8319
|
+
* Algorithm must match HmacVerifier.computeSignature() in the control-plane.
|
|
8320
|
+
*/
|
|
8321
|
+
function buildHmacAuthHeader(workspaceId, pairingSecret, method, url, body, overrides) {
|
|
8322
|
+
const ts = overrides?.now ? overrides.now() : Math.floor(Date.now() / 1e3);
|
|
8323
|
+
const nonce = overrides?.nonce ? overrides.nonce() : randomBytes(16).toString("base64");
|
|
8324
|
+
const parsed = new URL(url);
|
|
8325
|
+
const path = (parsed.pathname + parsed.search).toLowerCase();
|
|
8326
|
+
const bodyHash = createHash("sha256").update(body, "utf8").digest("hex");
|
|
8327
|
+
const baseString = [
|
|
8328
|
+
method.toUpperCase(),
|
|
8329
|
+
path,
|
|
8330
|
+
ts,
|
|
8331
|
+
nonce,
|
|
8332
|
+
bodyHash
|
|
8333
|
+
].join("\n");
|
|
8334
|
+
return `Codemation-Hmac v=1,workspaceId=${workspaceId},ts=${ts},nonce=${nonce},sig=${createHmac("sha256", Buffer.from(pairingSecret, "base64")).update(baseString, "utf8").digest("base64")}`;
|
|
8335
|
+
}
|
|
8336
|
+
|
|
8284
8337
|
//#endregion
|
|
8285
8338
|
//#region ../core-nodes/src/chatModels/CodemationChatModelFactory.ts
|
|
8286
8339
|
let CodemationChatModelFactory = class CodemationChatModelFactory$1 {
|
|
@@ -8290,7 +8343,7 @@ let CodemationChatModelFactory = class CodemationChatModelFactory$1 {
|
|
|
8290
8343
|
const workspaceId = process.env["WORKSPACE_ID"];
|
|
8291
8344
|
const pairingSecret = process.env["WORKSPACE_PAIRING_SECRET"];
|
|
8292
8345
|
if (!workspaceId || !pairingSecret) throw new Error("Codemation managed AI not available in this environment (workspace pairing is not configured).");
|
|
8293
|
-
const hmacFetch =
|
|
8346
|
+
const hmacFetch = managedHmacFetchFactory(workspaceId, pairingSecret);
|
|
8294
8347
|
const languageModel = createOpenAI({
|
|
8295
8348
|
baseURL: `${gatewayUrl}/v1`,
|
|
8296
8349
|
apiKey: "codemation-managed",
|
|
@@ -8306,52 +8359,6 @@ let CodemationChatModelFactory = class CodemationChatModelFactory$1 {
|
|
|
8306
8359
|
}
|
|
8307
8360
|
});
|
|
8308
8361
|
}
|
|
8309
|
-
/**
|
|
8310
|
-
* Creates an HMAC-signed fetch wrapper for use with AI SDK's createOpenAI.
|
|
8311
|
-
* Each call signs the request body with the workspace pairing secret so the
|
|
8312
|
-
* LLM broker can authenticate the workspace without a user-managed API key.
|
|
8313
|
-
*
|
|
8314
|
-
* Mirrors HmacRequestSigner from @codemation/host/pairing without importing
|
|
8315
|
-
* that package (which would create a circular dependency since @codemation/host
|
|
8316
|
-
* depends on @codemation/core-nodes).
|
|
8317
|
-
*/
|
|
8318
|
-
buildHmacSignedFetch(workspaceId, pairingSecret) {
|
|
8319
|
-
return async (input, init) => {
|
|
8320
|
-
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
8321
|
-
const method = init?.method ?? "POST";
|
|
8322
|
-
let bodyString = "";
|
|
8323
|
-
if (init?.body !== void 0 && init.body !== null) if (typeof init.body === "string") bodyString = init.body;
|
|
8324
|
-
else bodyString = await new Response(init.body).text();
|
|
8325
|
-
const authHeader = this.buildHmacAuthHeader(workspaceId, pairingSecret, method, url, bodyString);
|
|
8326
|
-
const headers = new Headers(init?.headers);
|
|
8327
|
-
headers.set("Authorization", authHeader);
|
|
8328
|
-
const effectiveBody = bodyString || init?.body;
|
|
8329
|
-
return fetch(input, {
|
|
8330
|
-
...init,
|
|
8331
|
-
body: effectiveBody,
|
|
8332
|
-
headers
|
|
8333
|
-
});
|
|
8334
|
-
};
|
|
8335
|
-
}
|
|
8336
|
-
/**
|
|
8337
|
-
* Produces a Codemation-Hmac v1 Authorization header value.
|
|
8338
|
-
* The algorithm must match HmacVerifier.computeSignature() in the control-plane.
|
|
8339
|
-
*/
|
|
8340
|
-
buildHmacAuthHeader(workspaceId, pairingSecret, method, url, body) {
|
|
8341
|
-
const ts = Math.floor(Date.now() / 1e3);
|
|
8342
|
-
const nonce = randomBytes(16).toString("base64");
|
|
8343
|
-
const parsed = new URL(url);
|
|
8344
|
-
const path = (parsed.pathname + parsed.search).toLowerCase();
|
|
8345
|
-
const bodyHash = createHash("sha256").update(body, "utf8").digest("hex");
|
|
8346
|
-
const baseString = [
|
|
8347
|
-
method.toUpperCase(),
|
|
8348
|
-
path,
|
|
8349
|
-
ts,
|
|
8350
|
-
nonce,
|
|
8351
|
-
bodyHash
|
|
8352
|
-
].join("\n");
|
|
8353
|
-
return `Codemation-Hmac v=1,workspaceId=${workspaceId},ts=${ts},nonce=${nonce},sig=${createHmac("sha256", Buffer.from(pairingSecret, "base64")).update(baseString, "utf8").digest("base64")}`;
|
|
8354
|
-
}
|
|
8355
8362
|
};
|
|
8356
8363
|
CodemationChatModelFactory = __decorate([chatModel({ packageName: "@codemation/core-nodes" })], CodemationChatModelFactory);
|
|
8357
8364
|
|
|
@@ -15989,7 +15996,11 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
15989
15996
|
});
|
|
15990
15997
|
try {
|
|
15991
15998
|
const callOptions = this.resolveCallOptions(model, guardrails.modelInvocationOptions);
|
|
15992
|
-
const
|
|
15999
|
+
const schemaRecord = this.isZodSchema(schema) ? this.executionHelpers.createJsonSchemaRecord(schema, {
|
|
16000
|
+
schemaName: structuredOptions?.schemaName ?? "structured_output",
|
|
16001
|
+
requireObjectRoot: true
|
|
16002
|
+
}) : schema;
|
|
16003
|
+
const outputSchema$1 = output_exports.object({ schema: jsonSchema(schemaRecord) });
|
|
15993
16004
|
const result = await generateText({
|
|
15994
16005
|
model: model.languageModel,
|
|
15995
16006
|
messages: [...messages],
|
|
@@ -18000,6 +18011,86 @@ const inboxApproval = defineHumanApprovalNode({
|
|
|
18000
18011
|
}
|
|
18001
18012
|
});
|
|
18002
18013
|
|
|
18014
|
+
//#endregion
|
|
18015
|
+
//#region ../core-nodes/src/nodes/codemationDocumentScannerNode.ts
|
|
18016
|
+
const ANALYZER_TYPES = [
|
|
18017
|
+
"document",
|
|
18018
|
+
"invoice",
|
|
18019
|
+
"image",
|
|
18020
|
+
"auto"
|
|
18021
|
+
];
|
|
18022
|
+
const codemationDocumentScannerNode = defineNode({
|
|
18023
|
+
key: "codemation.document-scanner",
|
|
18024
|
+
title: "Codemation Document Scanner",
|
|
18025
|
+
description: "Analyzes a binary attachment (document or image) via the managed Codemation document-scanning service and returns markdown text plus structured fields. No Azure credential required — auth uses the workspace pairing secret. Enable includeConfidence to get per-field confidence scores (0–1).",
|
|
18026
|
+
icon: "lucide:scan-text",
|
|
18027
|
+
input: {
|
|
18028
|
+
binaryField: "data",
|
|
18029
|
+
analyzerType: "auto",
|
|
18030
|
+
contentType: void 0,
|
|
18031
|
+
includeConfidence: false,
|
|
18032
|
+
maxBytes: void 0
|
|
18033
|
+
},
|
|
18034
|
+
configSchema: z$1.object({
|
|
18035
|
+
binaryField: z$1.string().optional(),
|
|
18036
|
+
analyzerType: z$1.enum(ANALYZER_TYPES).optional(),
|
|
18037
|
+
contentType: z$1.string().optional(),
|
|
18038
|
+
includeConfidence: z$1.boolean().optional(),
|
|
18039
|
+
maxBytes: z$1.number().int().positive().optional()
|
|
18040
|
+
}),
|
|
18041
|
+
inspectorSummary({ config }) {
|
|
18042
|
+
const cfg = config;
|
|
18043
|
+
const rows = [{
|
|
18044
|
+
label: "Analyzer type",
|
|
18045
|
+
value: cfg.analyzerType ?? "auto"
|
|
18046
|
+
}];
|
|
18047
|
+
const binaryField = cfg.binaryField ?? "data";
|
|
18048
|
+
if (binaryField !== "data") rows.push({
|
|
18049
|
+
label: "Binary field",
|
|
18050
|
+
value: binaryField
|
|
18051
|
+
});
|
|
18052
|
+
if (cfg.includeConfidence) rows.push({
|
|
18053
|
+
label: "Confidence",
|
|
18054
|
+
value: "enabled"
|
|
18055
|
+
});
|
|
18056
|
+
if (cfg.contentType) rows.push({
|
|
18057
|
+
label: "Content type",
|
|
18058
|
+
value: cfg.contentType
|
|
18059
|
+
});
|
|
18060
|
+
return rows;
|
|
18061
|
+
},
|
|
18062
|
+
async execute({ item, ctx }, { config: rawConfig }) {
|
|
18063
|
+
const config = rawConfig;
|
|
18064
|
+
const gatewayUrl = process.env["DOC_SCANNER_GATEWAY_URL"];
|
|
18065
|
+
if (!gatewayUrl) throw new Error("Codemation Document Scanner not available in this environment (DOC_SCANNER_GATEWAY_URL is not set).");
|
|
18066
|
+
const workspaceId = process.env["WORKSPACE_ID"];
|
|
18067
|
+
const pairingSecret = process.env["WORKSPACE_PAIRING_SECRET"];
|
|
18068
|
+
if (!workspaceId || !pairingSecret) throw new Error("Codemation Document Scanner not available (workspace pairing is not configured).");
|
|
18069
|
+
const binaryField = config.binaryField ?? "data";
|
|
18070
|
+
const attachment = item.binary?.[binaryField];
|
|
18071
|
+
if (!attachment) throw new Error(`Codemation Document Scanner: no binary attachment at key "${binaryField}".`);
|
|
18072
|
+
const body = await ctx.binary.getBytes(attachment, config.maxBytes);
|
|
18073
|
+
const contentType = config.contentType ?? attachment.mimeType ?? "application/octet-stream";
|
|
18074
|
+
const analyzerType = config.analyzerType ?? "auto";
|
|
18075
|
+
const confidenceSuffix = config.includeConfidence ?? false ? "&confidence=true" : "";
|
|
18076
|
+
const url = `${gatewayUrl}/analyze?type=${encodeURIComponent(analyzerType)}${confidenceSuffix}`;
|
|
18077
|
+
const response = await managedHmacFetchFactory(workspaceId, pairingSecret, { signBody: false })(url, {
|
|
18078
|
+
method: "POST",
|
|
18079
|
+
body: body.buffer,
|
|
18080
|
+
headers: {
|
|
18081
|
+
"Content-Type": contentType,
|
|
18082
|
+
"Content-Length": String(body.byteLength),
|
|
18083
|
+
"X-Codemation-Caller": "workflow-node"
|
|
18084
|
+
}
|
|
18085
|
+
});
|
|
18086
|
+
if (!response.ok) {
|
|
18087
|
+
const text$1 = await response.text().catch(() => "(unreadable)");
|
|
18088
|
+
throw new Error(`Codemation Document Scanner: service responded ${response.status} ${response.statusText} — ${text$1}`);
|
|
18089
|
+
}
|
|
18090
|
+
return await response.json();
|
|
18091
|
+
}
|
|
18092
|
+
});
|
|
18093
|
+
|
|
18003
18094
|
//#endregion
|
|
18004
18095
|
//#region ../host/src/presentation/config/CodemationAuthoring.types.ts
|
|
18005
18096
|
var CodemationAuthoringConfigFactory = class {
|