@codemation/core-nodes 0.9.0 → 0.10.1
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 +45 -0
- package/dist/index.cjs +140 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -16
- package/dist/index.d.ts +55 -16
- package/dist/index.js +140 -49
- package/dist/index.js.map +1 -1
- package/dist/metadata.json +13 -1
- package/package.json +2 -2
- package/src/chatModels/CodemationChatModelFactory.ts +2 -61
- package/src/chatModels/ManagedHmacSignerFactory.types.ts +88 -0
- package/src/index.ts +1 -0
- package/src/nodes/AIAgentNode.ts +14 -4
- package/src/nodes/codemationDocumentScannerNode.ts +131 -0
package/dist/index.d.cts
CHANGED
|
@@ -1264,6 +1264,22 @@ interface ExecutionBinaryService {
|
|
|
1264
1264
|
activationId: NodeActivationId;
|
|
1265
1265
|
}): NodeBinaryAttachmentService;
|
|
1266
1266
|
openReadStream(attachment: BinaryAttachment): Promise<BinaryStorageReadResult | undefined>;
|
|
1267
|
+
/**
|
|
1268
|
+
* Reads all bytes from the attachment into a contiguous `Uint8Array`.
|
|
1269
|
+
* Checks `attachment.size` against `maxBytes` *before* any allocation; throws a bounded-read
|
|
1270
|
+
* error when exceeded (no OOM). Throws if the stream is unavailable or the byte count mismatches.
|
|
1271
|
+
*/
|
|
1272
|
+
getBytes(attachment: BinaryAttachment, maxBytes?: number): Promise<Uint8Array>;
|
|
1273
|
+
/**
|
|
1274
|
+
* Reads the attachment and decodes the bytes as UTF-8 text.
|
|
1275
|
+
* Subject to the same bounded-read safety as `getBytes`.
|
|
1276
|
+
*/
|
|
1277
|
+
getText(attachment: BinaryAttachment, maxBytes?: number): Promise<string>;
|
|
1278
|
+
/**
|
|
1279
|
+
* Reads the attachment, decodes as UTF-8 text, and parses as JSON.
|
|
1280
|
+
* Throws a clear error on invalid JSON. Subject to the same bounded-read safety.
|
|
1281
|
+
*/
|
|
1282
|
+
getJson<T = unknown>(attachment: BinaryAttachment, maxBytes?: number): Promise<T>;
|
|
1267
1283
|
}
|
|
1268
1284
|
interface ExecutionContext {
|
|
1269
1285
|
runId: RunId;
|
|
@@ -2232,21 +2248,6 @@ declare class CodemationChatModelFactory implements ChatModelFactory<CodemationC
|
|
|
2232
2248
|
config: CodemationChatModelConfig;
|
|
2233
2249
|
ctx: NodeExecutionContext<any>;
|
|
2234
2250
|
}>): Promise<ChatLanguageModel>;
|
|
2235
|
-
/**
|
|
2236
|
-
* Creates an HMAC-signed fetch wrapper for use with AI SDK's createOpenAI.
|
|
2237
|
-
* Each call signs the request body with the workspace pairing secret so the
|
|
2238
|
-
* LLM broker can authenticate the workspace without a user-managed API key.
|
|
2239
|
-
*
|
|
2240
|
-
* Mirrors HmacRequestSigner from @codemation/host/pairing without importing
|
|
2241
|
-
* that package (which would create a circular dependency since @codemation/host
|
|
2242
|
-
* depends on @codemation/core-nodes).
|
|
2243
|
-
*/
|
|
2244
|
-
private buildHmacSignedFetch;
|
|
2245
|
-
/**
|
|
2246
|
-
* Produces a Codemation-Hmac v1 Authorization header value.
|
|
2247
|
-
* The algorithm must match HmacVerifier.computeSignature() in the control-plane.
|
|
2248
|
-
*/
|
|
2249
|
-
private buildHmacAuthHeader;
|
|
2250
2251
|
}
|
|
2251
2252
|
//#endregion
|
|
2252
2253
|
//#region src/chatModels/ManagedModelFetcher.d.ts
|
|
@@ -3876,5 +3877,43 @@ declare const inboxApproval: DefinedHumanApprovalNode<"inbox.approval", {
|
|
|
3876
3877
|
onTimeout: "halt" | "auto-accept";
|
|
3877
3878
|
}, Record<string, unknown>, undefined>;
|
|
3878
3879
|
//#endregion
|
|
3879
|
-
|
|
3880
|
+
//#region src/nodes/codemationDocumentScannerNode.d.ts
|
|
3881
|
+
declare const ANALYZER_TYPES: readonly ["document", "invoice", "image", "auto"];
|
|
3882
|
+
type DocScannerAnalyzerType = (typeof ANALYZER_TYPES)[number];
|
|
3883
|
+
/** Per-field value/confidence shape as returned by apps/doc-scanner. */
|
|
3884
|
+
type DocScannerField = Readonly<{
|
|
3885
|
+
value: unknown;
|
|
3886
|
+
confidence: number | null;
|
|
3887
|
+
}>;
|
|
3888
|
+
/** Output shape of CodemationDocumentScanner — identical to the service wire response. */
|
|
3889
|
+
type DocScannerOutput = Readonly<{
|
|
3890
|
+
markdown: string;
|
|
3891
|
+
fields: Readonly<Record<string, DocScannerField>>;
|
|
3892
|
+
}>;
|
|
3893
|
+
type CodemationDocumentScannerConfig = Readonly<{
|
|
3894
|
+
/** Key on `item.binary` that holds the document. Default: "data". */
|
|
3895
|
+
binaryField?: string;
|
|
3896
|
+
/** Analyzer type. Default: "auto" (routes on mime type on the service side). */
|
|
3897
|
+
analyzerType?: DocScannerAnalyzerType;
|
|
3898
|
+
/** MIME type override. Falls back to attachment.mimeType. */
|
|
3899
|
+
contentType?: string;
|
|
3900
|
+
/** Include per-field confidence scores (0–1). Default: false.
|
|
3901
|
+
* Enabling this roughly doubles contextualization tokens for document analyzers.
|
|
3902
|
+
* Image and auto-to-image requests silently ignore this flag (confidence stays null). */
|
|
3903
|
+
includeConfidence?: boolean;
|
|
3904
|
+
/** Max bytes checked before any read. Default: 50 MiB (same cap as OCR nodes, LD10). */
|
|
3905
|
+
maxBytes?: number;
|
|
3906
|
+
}>;
|
|
3907
|
+
declare const codemationDocumentScannerNode: DefinedNode<"codemation.document-scanner", {
|
|
3908
|
+
binaryField?: string | undefined;
|
|
3909
|
+
analyzerType?: "auto" | "document" | "invoice" | "image" | undefined;
|
|
3910
|
+
contentType?: string | undefined;
|
|
3911
|
+
includeConfidence?: boolean | undefined;
|
|
3912
|
+
maxBytes?: number | undefined;
|
|
3913
|
+
}, unknown, Readonly<{
|
|
3914
|
+
markdown: string;
|
|
3915
|
+
fields: Readonly<Record<string, DocScannerField>>;
|
|
3916
|
+
}>, undefined>;
|
|
3917
|
+
//#endregion
|
|
3918
|
+
export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentStructuredOutputRepairPromptFactory, AgentStructuredOutputRunner, AgentToolCallPortMap, AgentToolErrorClassifier, AgentToolExecutionCoordinator, AgentToolRepairExhaustedError, AgentToolRepairPolicy, Aggregate, AggregateNode, Assertion, AssertionNode, AssertionOptions, BM25Index, BinaryRef, Callback, CallbackHandler, CallbackNode, CallbackOptions, CallbackResultNormalizer, CanvasIconName, CodemationChatModelConfig, CodemationChatModelFactory, CodemationDocumentScannerConfig, CodemationManagedModel, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, CredentialSession, CronTickJson, CronTrigger, CronTriggerNode, DeferredMetaToolStrategy, DeferredMetaToolStrategyFactory, DefineRestNodeOptions, DocScannerAnalyzerType, DocScannerField, DocScannerOutput, ExecutedToolCall, Filter, FilterNode, FindToolsResult, HTTP_REQUEST_ACCEPTED_CREDENTIAL_TYPES, HttpBodySpec, HttpCredentialDelta, HttpRequest, HttpRequestDownloadMode, HttpRequestNode, HttpRequestOutputJson, HttpRequestResult, HttpRequestSpec, If, IfNode, IsTestRun, IsTestRunNode, ItemScopedToolBinding, ManagedModelDto, ManagedModelFetcher, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, MapDataOptions, Merge, MergeMode, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAiChatModelPresets, OpenAiCredentialSession, OpenAiStrictJsonSchemaFactory, PlannedToolCall, ResolvedTool, RestNodeApi, RestNodeErrorPolicy, RestNodeRequestShape, RestNodeResponseContext, SSRFBlockedError, Split, SplitNode, SsrfGuard, SubWorkflow, SubWorkflowNode, Switch, SwitchCaseKeyResolver, SwitchNode, TestTrigger, TestTriggerNode, TestTriggerOptions, ToolLoadingStrategy, ToolLoadingStrategyInitInput, ToolLoadingStrategyTurnContext, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, type WorkflowAgentMessages, type WorkflowAgentOptions, WorkflowAuthoringBuilder, WorkflowBranchBuilder, WorkflowChain, apiKeyCredentialType, basicAuthCredentialType, bearerTokenCredentialType, codemationDocumentScannerNode, collectionDeleteNode, collectionFindOneNode, collectionGetNode, collectionInsertNode, collectionListNode, collectionUpdateNode, createWorkflowBuilder, defineRestNode, inboxApproval, oauth2ClientCredentialsType, openAiChatModelPresets, registerCoreNodes, workflow };
|
|
3880
3919
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1264,6 +1264,22 @@ interface ExecutionBinaryService {
|
|
|
1264
1264
|
activationId: NodeActivationId;
|
|
1265
1265
|
}): NodeBinaryAttachmentService;
|
|
1266
1266
|
openReadStream(attachment: BinaryAttachment): Promise<BinaryStorageReadResult | undefined>;
|
|
1267
|
+
/**
|
|
1268
|
+
* Reads all bytes from the attachment into a contiguous `Uint8Array`.
|
|
1269
|
+
* Checks `attachment.size` against `maxBytes` *before* any allocation; throws a bounded-read
|
|
1270
|
+
* error when exceeded (no OOM). Throws if the stream is unavailable or the byte count mismatches.
|
|
1271
|
+
*/
|
|
1272
|
+
getBytes(attachment: BinaryAttachment, maxBytes?: number): Promise<Uint8Array>;
|
|
1273
|
+
/**
|
|
1274
|
+
* Reads the attachment and decodes the bytes as UTF-8 text.
|
|
1275
|
+
* Subject to the same bounded-read safety as `getBytes`.
|
|
1276
|
+
*/
|
|
1277
|
+
getText(attachment: BinaryAttachment, maxBytes?: number): Promise<string>;
|
|
1278
|
+
/**
|
|
1279
|
+
* Reads the attachment, decodes as UTF-8 text, and parses as JSON.
|
|
1280
|
+
* Throws a clear error on invalid JSON. Subject to the same bounded-read safety.
|
|
1281
|
+
*/
|
|
1282
|
+
getJson<T = unknown>(attachment: BinaryAttachment, maxBytes?: number): Promise<T>;
|
|
1267
1283
|
}
|
|
1268
1284
|
interface ExecutionContext {
|
|
1269
1285
|
runId: RunId;
|
|
@@ -2232,21 +2248,6 @@ declare class CodemationChatModelFactory implements ChatModelFactory<CodemationC
|
|
|
2232
2248
|
config: CodemationChatModelConfig;
|
|
2233
2249
|
ctx: NodeExecutionContext<any>;
|
|
2234
2250
|
}>): Promise<ChatLanguageModel>;
|
|
2235
|
-
/**
|
|
2236
|
-
* Creates an HMAC-signed fetch wrapper for use with AI SDK's createOpenAI.
|
|
2237
|
-
* Each call signs the request body with the workspace pairing secret so the
|
|
2238
|
-
* LLM broker can authenticate the workspace without a user-managed API key.
|
|
2239
|
-
*
|
|
2240
|
-
* Mirrors HmacRequestSigner from @codemation/host/pairing without importing
|
|
2241
|
-
* that package (which would create a circular dependency since @codemation/host
|
|
2242
|
-
* depends on @codemation/core-nodes).
|
|
2243
|
-
*/
|
|
2244
|
-
private buildHmacSignedFetch;
|
|
2245
|
-
/**
|
|
2246
|
-
* Produces a Codemation-Hmac v1 Authorization header value.
|
|
2247
|
-
* The algorithm must match HmacVerifier.computeSignature() in the control-plane.
|
|
2248
|
-
*/
|
|
2249
|
-
private buildHmacAuthHeader;
|
|
2250
2251
|
}
|
|
2251
2252
|
//#endregion
|
|
2252
2253
|
//#region src/chatModels/ManagedModelFetcher.d.ts
|
|
@@ -3876,5 +3877,43 @@ declare const inboxApproval: DefinedHumanApprovalNode<"inbox.approval", {
|
|
|
3876
3877
|
onTimeout: "halt" | "auto-accept";
|
|
3877
3878
|
}, Record<string, unknown>, undefined>;
|
|
3878
3879
|
//#endregion
|
|
3879
|
-
|
|
3880
|
+
//#region src/nodes/codemationDocumentScannerNode.d.ts
|
|
3881
|
+
declare const ANALYZER_TYPES: readonly ["document", "invoice", "image", "auto"];
|
|
3882
|
+
type DocScannerAnalyzerType = (typeof ANALYZER_TYPES)[number];
|
|
3883
|
+
/** Per-field value/confidence shape as returned by apps/doc-scanner. */
|
|
3884
|
+
type DocScannerField = Readonly<{
|
|
3885
|
+
value: unknown;
|
|
3886
|
+
confidence: number | null;
|
|
3887
|
+
}>;
|
|
3888
|
+
/** Output shape of CodemationDocumentScanner — identical to the service wire response. */
|
|
3889
|
+
type DocScannerOutput = Readonly<{
|
|
3890
|
+
markdown: string;
|
|
3891
|
+
fields: Readonly<Record<string, DocScannerField>>;
|
|
3892
|
+
}>;
|
|
3893
|
+
type CodemationDocumentScannerConfig = Readonly<{
|
|
3894
|
+
/** Key on `item.binary` that holds the document. Default: "data". */
|
|
3895
|
+
binaryField?: string;
|
|
3896
|
+
/** Analyzer type. Default: "auto" (routes on mime type on the service side). */
|
|
3897
|
+
analyzerType?: DocScannerAnalyzerType;
|
|
3898
|
+
/** MIME type override. Falls back to attachment.mimeType. */
|
|
3899
|
+
contentType?: string;
|
|
3900
|
+
/** Include per-field confidence scores (0–1). Default: false.
|
|
3901
|
+
* Enabling this roughly doubles contextualization tokens for document analyzers.
|
|
3902
|
+
* Image and auto-to-image requests silently ignore this flag (confidence stays null). */
|
|
3903
|
+
includeConfidence?: boolean;
|
|
3904
|
+
/** Max bytes checked before any read. Default: 50 MiB (same cap as OCR nodes, LD10). */
|
|
3905
|
+
maxBytes?: number;
|
|
3906
|
+
}>;
|
|
3907
|
+
declare const codemationDocumentScannerNode: DefinedNode<"codemation.document-scanner", {
|
|
3908
|
+
binaryField?: string | undefined;
|
|
3909
|
+
analyzerType?: "auto" | "document" | "invoice" | "image" | undefined;
|
|
3910
|
+
contentType?: string | undefined;
|
|
3911
|
+
includeConfidence?: boolean | undefined;
|
|
3912
|
+
maxBytes?: number | undefined;
|
|
3913
|
+
}, unknown, Readonly<{
|
|
3914
|
+
markdown: string;
|
|
3915
|
+
fields: Readonly<Record<string, DocScannerField>>;
|
|
3916
|
+
}>, undefined>;
|
|
3917
|
+
//#endregion
|
|
3918
|
+
export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentStructuredOutputRepairPromptFactory, AgentStructuredOutputRunner, AgentToolCallPortMap, AgentToolErrorClassifier, AgentToolExecutionCoordinator, AgentToolRepairExhaustedError, AgentToolRepairPolicy, Aggregate, AggregateNode, Assertion, AssertionNode, AssertionOptions, BM25Index, BinaryRef, Callback, CallbackHandler, CallbackNode, CallbackOptions, CallbackResultNormalizer, CanvasIconName, CodemationChatModelConfig, CodemationChatModelFactory, CodemationDocumentScannerConfig, CodemationManagedModel, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, CredentialSession, CronTickJson, CronTrigger, CronTriggerNode, DeferredMetaToolStrategy, DeferredMetaToolStrategyFactory, DefineRestNodeOptions, DocScannerAnalyzerType, DocScannerField, DocScannerOutput, type ExecutedToolCall, Filter, FilterNode, type FindToolsResult, HTTP_REQUEST_ACCEPTED_CREDENTIAL_TYPES, HttpBodySpec, HttpCredentialDelta, HttpRequest, HttpRequestDownloadMode, HttpRequestNode, HttpRequestOutputJson, HttpRequestResult, HttpRequestSpec, If, IfNode, IsTestRun, IsTestRunNode, type ItemScopedToolBinding, ManagedModelDto, ManagedModelFetcher, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, MapDataOptions, Merge, MergeMode, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAiChatModelPresets, OpenAiCredentialSession, OpenAiStrictJsonSchemaFactory, type PlannedToolCall, type ResolvedTool, RestNodeApi, RestNodeErrorPolicy, RestNodeRequestShape, RestNodeResponseContext, SSRFBlockedError, Split, SplitNode, SsrfGuard, SubWorkflow, SubWorkflowNode, Switch, SwitchCaseKeyResolver, SwitchNode, TestTrigger, TestTriggerNode, TestTriggerOptions, type ToolLoadingStrategy, type ToolLoadingStrategyInitInput, type ToolLoadingStrategyTurnContext, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, type WorkflowAgentMessages, type WorkflowAgentOptions, WorkflowAuthoringBuilder, WorkflowBranchBuilder, WorkflowChain, apiKeyCredentialType, basicAuthCredentialType, bearerTokenCredentialType, codemationDocumentScannerNode, collectionDeleteNode, collectionFindOneNode, collectionGetNode, collectionInsertNode, collectionListNode, collectionUpdateNode, createWorkflowBuilder, defineRestNode, inboxApproval, oauth2ClientCredentialsType, openAiChatModelPresets, registerCoreNodes, workflow };
|
|
3880
3919
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -4359,6 +4359,59 @@ var OpenAiChatModelPresets = class {
|
|
|
4359
4359
|
};
|
|
4360
4360
|
const openAiChatModelPresets = new OpenAiChatModelPresets();
|
|
4361
4361
|
|
|
4362
|
+
//#endregion
|
|
4363
|
+
//#region src/chatModels/ManagedHmacSignerFactory.types.ts
|
|
4364
|
+
/**
|
|
4365
|
+
* Creates an HMAC-signing fetch wrapper that authenticates requests to
|
|
4366
|
+
* Codemation managed services (LLM broker, doc-scanner) with the
|
|
4367
|
+
* Codemation-Hmac v=1 scheme.
|
|
4368
|
+
*
|
|
4369
|
+
* Mirrors HmacRequestSigner from @codemation/host/pairing without importing
|
|
4370
|
+
* that package (which would create a circular dependency since @codemation/host
|
|
4371
|
+
* depends on @codemation/core-nodes).
|
|
4372
|
+
*
|
|
4373
|
+
* @param workspaceId - Workspace identifier injected by the CP provisioner.
|
|
4374
|
+
* @param pairingSecret - Base64-encoded 32-byte HMAC key injected by the provisioner.
|
|
4375
|
+
* @param options - Optional behaviour flags and test seams.
|
|
4376
|
+
*/
|
|
4377
|
+
function managedHmacFetchFactory(workspaceId, pairingSecret, options) {
|
|
4378
|
+
const signBody = options?.signBody ?? true;
|
|
4379
|
+
return async (input, init) => {
|
|
4380
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
4381
|
+
const method = init?.method ?? "POST";
|
|
4382
|
+
let bodyForSigning = "";
|
|
4383
|
+
if (signBody && init?.body !== void 0 && init.body !== null) bodyForSigning = typeof init.body === "string" ? init.body : await new Response(init.body).text();
|
|
4384
|
+
const authHeader = buildHmacAuthHeader(workspaceId, pairingSecret, method, url, bodyForSigning, options);
|
|
4385
|
+
const headers = new Headers(init?.headers);
|
|
4386
|
+
headers.set("Authorization", authHeader);
|
|
4387
|
+
const outgoingBody = signBody ? bodyForSigning || init?.body : init?.body;
|
|
4388
|
+
return fetch(input, {
|
|
4389
|
+
...init,
|
|
4390
|
+
body: outgoingBody,
|
|
4391
|
+
headers
|
|
4392
|
+
});
|
|
4393
|
+
};
|
|
4394
|
+
}
|
|
4395
|
+
/**
|
|
4396
|
+
* Produces a Codemation-Hmac v=1 Authorization header value.
|
|
4397
|
+
* Algorithm must match HmacVerifier.computeSignature() in the control-plane.
|
|
4398
|
+
*/
|
|
4399
|
+
function buildHmacAuthHeader(workspaceId, pairingSecret, method, url, body, overrides) {
|
|
4400
|
+
const ts = overrides?.now ? overrides.now() : Math.floor(Date.now() / 1e3);
|
|
4401
|
+
const nonce = overrides?.nonce ? overrides.nonce() : randomBytes(16).toString("base64");
|
|
4402
|
+
const parsed = new URL(url);
|
|
4403
|
+
const path = (parsed.pathname + parsed.search).toLowerCase();
|
|
4404
|
+
const bodyHash = createHash("sha256").update(body, "utf8").digest("hex");
|
|
4405
|
+
const baseString = [
|
|
4406
|
+
method.toUpperCase(),
|
|
4407
|
+
path,
|
|
4408
|
+
ts,
|
|
4409
|
+
nonce,
|
|
4410
|
+
bodyHash
|
|
4411
|
+
].join("\n");
|
|
4412
|
+
return `Codemation-Hmac v=1,workspaceId=${workspaceId},ts=${ts},nonce=${nonce},sig=${createHmac("sha256", Buffer.from(pairingSecret, "base64")).update(baseString, "utf8").digest("base64")}`;
|
|
4413
|
+
}
|
|
4414
|
+
|
|
4362
4415
|
//#endregion
|
|
4363
4416
|
//#region src/chatModels/CodemationChatModelFactory.ts
|
|
4364
4417
|
let CodemationChatModelFactory = class CodemationChatModelFactory$1 {
|
|
@@ -4368,7 +4421,7 @@ let CodemationChatModelFactory = class CodemationChatModelFactory$1 {
|
|
|
4368
4421
|
const workspaceId = process.env["WORKSPACE_ID"];
|
|
4369
4422
|
const pairingSecret = process.env["WORKSPACE_PAIRING_SECRET"];
|
|
4370
4423
|
if (!workspaceId || !pairingSecret) throw new Error("Codemation managed AI not available in this environment (workspace pairing is not configured).");
|
|
4371
|
-
const hmacFetch =
|
|
4424
|
+
const hmacFetch = managedHmacFetchFactory(workspaceId, pairingSecret);
|
|
4372
4425
|
const languageModel = createOpenAI({
|
|
4373
4426
|
baseURL: `${gatewayUrl}/v1`,
|
|
4374
4427
|
apiKey: "codemation-managed",
|
|
@@ -4384,52 +4437,6 @@ let CodemationChatModelFactory = class CodemationChatModelFactory$1 {
|
|
|
4384
4437
|
}
|
|
4385
4438
|
});
|
|
4386
4439
|
}
|
|
4387
|
-
/**
|
|
4388
|
-
* Creates an HMAC-signed fetch wrapper for use with AI SDK's createOpenAI.
|
|
4389
|
-
* Each call signs the request body with the workspace pairing secret so the
|
|
4390
|
-
* LLM broker can authenticate the workspace without a user-managed API key.
|
|
4391
|
-
*
|
|
4392
|
-
* Mirrors HmacRequestSigner from @codemation/host/pairing without importing
|
|
4393
|
-
* that package (which would create a circular dependency since @codemation/host
|
|
4394
|
-
* depends on @codemation/core-nodes).
|
|
4395
|
-
*/
|
|
4396
|
-
buildHmacSignedFetch(workspaceId, pairingSecret) {
|
|
4397
|
-
return async (input, init) => {
|
|
4398
|
-
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
4399
|
-
const method = init?.method ?? "POST";
|
|
4400
|
-
let bodyString = "";
|
|
4401
|
-
if (init?.body !== void 0 && init.body !== null) if (typeof init.body === "string") bodyString = init.body;
|
|
4402
|
-
else bodyString = await new Response(init.body).text();
|
|
4403
|
-
const authHeader = this.buildHmacAuthHeader(workspaceId, pairingSecret, method, url, bodyString);
|
|
4404
|
-
const headers = new Headers(init?.headers);
|
|
4405
|
-
headers.set("Authorization", authHeader);
|
|
4406
|
-
const effectiveBody = bodyString || init?.body;
|
|
4407
|
-
return fetch(input, {
|
|
4408
|
-
...init,
|
|
4409
|
-
body: effectiveBody,
|
|
4410
|
-
headers
|
|
4411
|
-
});
|
|
4412
|
-
};
|
|
4413
|
-
}
|
|
4414
|
-
/**
|
|
4415
|
-
* Produces a Codemation-Hmac v1 Authorization header value.
|
|
4416
|
-
* The algorithm must match HmacVerifier.computeSignature() in the control-plane.
|
|
4417
|
-
*/
|
|
4418
|
-
buildHmacAuthHeader(workspaceId, pairingSecret, method, url, body) {
|
|
4419
|
-
const ts = Math.floor(Date.now() / 1e3);
|
|
4420
|
-
const nonce = randomBytes(16).toString("base64");
|
|
4421
|
-
const parsed = new URL(url);
|
|
4422
|
-
const path = (parsed.pathname + parsed.search).toLowerCase();
|
|
4423
|
-
const bodyHash = createHash("sha256").update(body, "utf8").digest("hex");
|
|
4424
|
-
const baseString = [
|
|
4425
|
-
method.toUpperCase(),
|
|
4426
|
-
path,
|
|
4427
|
-
ts,
|
|
4428
|
-
nonce,
|
|
4429
|
-
bodyHash
|
|
4430
|
-
].join("\n");
|
|
4431
|
-
return `Codemation-Hmac v=1,workspaceId=${workspaceId},ts=${ts},nonce=${nonce},sig=${createHmac("sha256", Buffer.from(pairingSecret, "base64")).update(baseString, "utf8").digest("base64")}`;
|
|
4432
|
-
}
|
|
4433
4440
|
};
|
|
4434
4441
|
CodemationChatModelFactory = __decorate([chatModel({ packageName: "@codemation/core-nodes" })], CodemationChatModelFactory);
|
|
4435
4442
|
|
|
@@ -6785,7 +6792,11 @@ let AIAgentNode = class AIAgentNode$1 {
|
|
|
6785
6792
|
});
|
|
6786
6793
|
try {
|
|
6787
6794
|
const callOptions = this.resolveCallOptions(model, guardrails.modelInvocationOptions);
|
|
6788
|
-
const
|
|
6795
|
+
const schemaRecord = this.isZodSchema(schema) ? this.executionHelpers.createJsonSchemaRecord(schema, {
|
|
6796
|
+
schemaName: structuredOptions?.schemaName ?? "structured_output",
|
|
6797
|
+
requireObjectRoot: true
|
|
6798
|
+
}) : schema;
|
|
6799
|
+
const outputSchema = Output.object({ schema: jsonSchema(schemaRecord) });
|
|
6789
6800
|
const result = await generateText({
|
|
6790
6801
|
model: model.languageModel,
|
|
6791
6802
|
messages: [...messages],
|
|
@@ -9022,5 +9033,85 @@ const inboxApproval = defineHumanApprovalNode({
|
|
|
9022
9033
|
});
|
|
9023
9034
|
|
|
9024
9035
|
//#endregion
|
|
9025
|
-
|
|
9036
|
+
//#region src/nodes/codemationDocumentScannerNode.ts
|
|
9037
|
+
const ANALYZER_TYPES = [
|
|
9038
|
+
"document",
|
|
9039
|
+
"invoice",
|
|
9040
|
+
"image",
|
|
9041
|
+
"auto"
|
|
9042
|
+
];
|
|
9043
|
+
const codemationDocumentScannerNode = defineNode({
|
|
9044
|
+
key: "codemation.document-scanner",
|
|
9045
|
+
title: "Codemation Document Scanner",
|
|
9046
|
+
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).",
|
|
9047
|
+
icon: "lucide:scan-text",
|
|
9048
|
+
input: {
|
|
9049
|
+
binaryField: "data",
|
|
9050
|
+
analyzerType: "auto",
|
|
9051
|
+
contentType: void 0,
|
|
9052
|
+
includeConfidence: false,
|
|
9053
|
+
maxBytes: void 0
|
|
9054
|
+
},
|
|
9055
|
+
configSchema: object({
|
|
9056
|
+
binaryField: string().optional(),
|
|
9057
|
+
analyzerType: _enum(ANALYZER_TYPES).optional(),
|
|
9058
|
+
contentType: string().optional(),
|
|
9059
|
+
includeConfidence: boolean().optional(),
|
|
9060
|
+
maxBytes: number().int().positive().optional()
|
|
9061
|
+
}),
|
|
9062
|
+
inspectorSummary({ config: config$1 }) {
|
|
9063
|
+
const cfg = config$1;
|
|
9064
|
+
const rows = [{
|
|
9065
|
+
label: "Analyzer type",
|
|
9066
|
+
value: cfg.analyzerType ?? "auto"
|
|
9067
|
+
}];
|
|
9068
|
+
const binaryField = cfg.binaryField ?? "data";
|
|
9069
|
+
if (binaryField !== "data") rows.push({
|
|
9070
|
+
label: "Binary field",
|
|
9071
|
+
value: binaryField
|
|
9072
|
+
});
|
|
9073
|
+
if (cfg.includeConfidence) rows.push({
|
|
9074
|
+
label: "Confidence",
|
|
9075
|
+
value: "enabled"
|
|
9076
|
+
});
|
|
9077
|
+
if (cfg.contentType) rows.push({
|
|
9078
|
+
label: "Content type",
|
|
9079
|
+
value: cfg.contentType
|
|
9080
|
+
});
|
|
9081
|
+
return rows;
|
|
9082
|
+
},
|
|
9083
|
+
async execute({ item, ctx }, { config: rawConfig }) {
|
|
9084
|
+
const config$1 = rawConfig;
|
|
9085
|
+
const gatewayUrl = process.env["DOC_SCANNER_GATEWAY_URL"];
|
|
9086
|
+
if (!gatewayUrl) throw new Error("Codemation Document Scanner not available in this environment (DOC_SCANNER_GATEWAY_URL is not set).");
|
|
9087
|
+
const workspaceId = process.env["WORKSPACE_ID"];
|
|
9088
|
+
const pairingSecret = process.env["WORKSPACE_PAIRING_SECRET"];
|
|
9089
|
+
if (!workspaceId || !pairingSecret) throw new Error("Codemation Document Scanner not available (workspace pairing is not configured).");
|
|
9090
|
+
const binaryField = config$1.binaryField ?? "data";
|
|
9091
|
+
const attachment = item.binary?.[binaryField];
|
|
9092
|
+
if (!attachment) throw new Error(`Codemation Document Scanner: no binary attachment at key "${binaryField}".`);
|
|
9093
|
+
const body = await ctx.binary.getBytes(attachment, config$1.maxBytes);
|
|
9094
|
+
const contentType = config$1.contentType ?? attachment.mimeType ?? "application/octet-stream";
|
|
9095
|
+
const analyzerType = config$1.analyzerType ?? "auto";
|
|
9096
|
+
const confidenceSuffix = config$1.includeConfidence ?? false ? "&confidence=true" : "";
|
|
9097
|
+
const url = `${gatewayUrl}/analyze?type=${encodeURIComponent(analyzerType)}${confidenceSuffix}`;
|
|
9098
|
+
const response = await managedHmacFetchFactory(workspaceId, pairingSecret, { signBody: false })(url, {
|
|
9099
|
+
method: "POST",
|
|
9100
|
+
body: body.buffer,
|
|
9101
|
+
headers: {
|
|
9102
|
+
"Content-Type": contentType,
|
|
9103
|
+
"Content-Length": String(body.byteLength),
|
|
9104
|
+
"X-Codemation-Caller": "workflow-node"
|
|
9105
|
+
}
|
|
9106
|
+
});
|
|
9107
|
+
if (!response.ok) {
|
|
9108
|
+
const text = await response.text().catch(() => "(unreadable)");
|
|
9109
|
+
throw new Error(`Codemation Document Scanner: service responded ${response.status} ${response.statusText} — ${text}`);
|
|
9110
|
+
}
|
|
9111
|
+
return await response.json();
|
|
9112
|
+
}
|
|
9113
|
+
});
|
|
9114
|
+
|
|
9115
|
+
//#endregion
|
|
9116
|
+
export { AIAgent, AIAgentConnectionWorkflowExpander, AIAgentExecutionHelpersFactory, AIAgentNode, AgentItemPortMap, AgentMessageFactory, AgentOutputFactory, AgentStructuredOutputRepairPromptFactory, AgentStructuredOutputRunner, AgentToolCallPortMap, AgentToolErrorClassifier, AgentToolExecutionCoordinator, AgentToolRepairExhaustedError, AgentToolRepairPolicy, Aggregate, AggregateNode, Assertion, AssertionNode, BM25Index, Callback, CallbackNode, CallbackResultNormalizer, CodemationChatModelConfig, CodemationChatModelFactory, ConnectionCredentialExecutionContextFactory, ConnectionCredentialNode, ConnectionCredentialNodeConfig, ConnectionCredentialNodeConfigFactory, CronTrigger, CronTriggerNode, DeferredMetaToolStrategy, DeferredMetaToolStrategyFactory, Filter, FilterNode, HTTP_REQUEST_ACCEPTED_CREDENTIAL_TYPES, HttpRequest, HttpRequestNode, If, IfNode, IsTestRun, IsTestRunNode, ManagedModelFetcher, ManualTrigger, ManualTriggerNode, MapData, MapDataNode, Merge, MergeNode, NoOp, NoOpNode, OpenAIChatModelConfig, OpenAIChatModelFactory, OpenAiChatModelPresets, OpenAiStrictJsonSchemaFactory, SSRFBlockedError, Split, SplitNode, SsrfGuard, SubWorkflow, SubWorkflowNode, Switch, SwitchNode, TestTrigger, TestTriggerNode, Wait, WaitDuration, WaitNode, WebhookRespondNowAndContinueError, WebhookRespondNowError, WebhookTrigger, WebhookTriggerNode, WorkflowAuthoringBuilder, WorkflowBranchBuilder, WorkflowChain, apiKeyCredentialType, basicAuthCredentialType, bearerTokenCredentialType, codemationDocumentScannerNode, collectionDeleteNode, collectionFindOneNode, collectionGetNode, collectionInsertNode, collectionListNode, collectionUpdateNode, createWorkflowBuilder, defineRestNode, inboxApproval, oauth2ClientCredentialsType, openAiChatModelPresets, registerCoreNodes, workflow };
|
|
9026
9117
|
//# sourceMappingURL=index.js.map
|