@kortyx/hooks 0.26.0 → 0.27.0

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.27.0](https://github.com/kortyx-io/kortyx/compare/hooks-v0.26.0...hooks-v0.27.0) (2026-09-21)
4
+
5
+
6
+ ### Features
7
+
8
+ * **observability:** report handled workflow errors ([#222](https://github.com/kortyx-io/kortyx/issues/222)) ([68a3b0e](https://github.com/kortyx-io/kortyx/commit/68a3b0eea5d93cb89bdcef63c4767f3b0d59e60d))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @kortyx/telemetry-contracts bumped to 0.10.0
16
+
3
17
  ## [0.26.0](https://github.com/kortyx-io/kortyx/compare/hooks-v0.25.3...hooks-v0.26.0) (2026-09-18)
4
18
 
5
19
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _kortyx_core from '@kortyx/core';
2
2
  import { WorkflowDefinition, TokenUsage, InterruptInput, GraphState, NodeConfig, InterruptResult } from '@kortyx/core';
3
- import { K as KortyxTelemetryConfig, R as ReasonTraceAdapter, a as KortyxTraceMetadata, b as KortyxTelemetryEventType } from './tracing-BUpf8RrV.js';
4
- export { E as EnsureWorkflowTopologyRequest, c as EnsureWorkflowTopologyResponse, d as KortyxErrorDetails, e as KortyxTelemetryContentCapture, f as KortyxTelemetryCorrelation, g as KortyxTelemetryEvent, h as KortyxTelemetryPrompt, i as KortyxTelemetryReporter, j as KortyxTelemetryService, k as KortyxTraceAdapter, l as KortyxTraceErrorProjection, m as ReasonTraceAttributes, n as ReasonTraceSpan, o as ReasonTraceSpanEndArgs, p as ReasonTraceSpanStartArgs } from './tracing-BUpf8RrV.js';
3
+ import { K as KortyxTelemetryConfig, R as ReasonTraceAdapter, a as KortyxTraceMetadata, b as ReportErrorOptions, c as KortyxTelemetryEventType } from './tracing-BsxYlgEw.js';
4
+ export { E as EnsureWorkflowTopologyRequest, d as EnsureWorkflowTopologyResponse, e as KortyxErrorDetails, f as KortyxTelemetryContentCapture, g as KortyxTelemetryCorrelation, h as KortyxTelemetryEvent, i as KortyxTelemetryPrompt, j as KortyxTelemetryReporter, k as KortyxTelemetryService, l as KortyxTraceAdapter, m as KortyxTraceErrorProjection, n as ReasonTraceAttributes, o as ReasonTraceSpan, p as ReasonTraceSpanEndArgs, q as ReasonTraceSpanStartArgs } from './tracing-BsxYlgEw.js';
5
5
  import { FailureDescriptor, KortyxError } from '@kortyx/core/errors';
6
6
  import * as _kortyx_providers from '@kortyx/providers';
7
7
  import { ToolObservation, ProviderModelRef, KortyxReasoningOptions, KortyxResponseFormat, KortyxExecutableTool, KortyxUsage, KortyxFinishReason, KortyxProviderMetadata, KortyxWarning, KortyxToolCall, KortyxToolResult } from '@kortyx/providers';
@@ -250,6 +250,9 @@ declare function useRuntimeContext<TContext extends Record<string, unknown> = Re
250
250
  declare function useNodeState<T>(initialValue: T): [T, StateSetter<T>];
251
251
  declare function useWorkflowState<T>(key: string, ...rest: [] | [T]): [T, StateSetter<T>];
252
252
 
253
+ /** Reports a handled error to the configured observer without stopping execution. */
254
+ declare function reportError(error: unknown, options?: ReportErrorOptions): void;
255
+
253
256
  type UseToolArgs<T extends KortyxExecutableTool> = {
254
257
  tool: T;
255
258
  input: Parameters<T["execute"]> extends [] ? unknown : Parameters<T["execute"]>[0];
@@ -261,4 +264,4 @@ declare function useTool<T extends KortyxExecutableTool>(args: UseToolArgs<T>):
261
264
  /** Best effort lifecycle facts. Engine snapshots and interrupt tokens never leave the runtime. */
262
265
  declare function emitWorkflowCall(telemetry: KortyxTelemetryConfig | undefined, type: KortyxTelemetryEventType, payload: Record<string, unknown>): void;
263
266
 
264
- export { type CompleteResponseOptions, type HookRuntimeContext, KortyxTelemetryConfig, KortyxTelemetryEventType, KortyxTraceMetadata, ParallelError, ReasonTraceAdapter, type UseInterruptArgs, type UseReasonArgs, type UseReasonResult, type UseReasonStep, type UseReasonToolExecution, type UseStructuredDataArgs, type UseToolArgs, WorkflowCallError, type WorkflowCallOutcome, type WorkflowCallService, completeResponse, createWorkflowHooks, emitWorkflowCall, parallel, runWithHookContext, useAbortSignal, useInterrupt, useNodeState, useReason, useRuntimeContext, useStructuredData, useTool, useWorkflow, useWorkflowState, workflowCallFingerprint };
267
+ export { type CompleteResponseOptions, type HookRuntimeContext, KortyxTelemetryConfig, KortyxTelemetryEventType, KortyxTraceMetadata, ParallelError, ReasonTraceAdapter, ReportErrorOptions, type UseInterruptArgs, type UseReasonArgs, type UseReasonResult, type UseReasonStep, type UseReasonToolExecution, type UseStructuredDataArgs, type UseToolArgs, WorkflowCallError, type WorkflowCallOutcome, type WorkflowCallService, completeResponse, createWorkflowHooks, emitWorkflowCall, parallel, reportError, runWithHookContext, useAbortSignal, useInterrupt, useNodeState, useReason, useRuntimeContext, useStructuredData, useTool, useWorkflow, useWorkflowState, workflowCallFingerprint };
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  createWorkflowHooks: () => createWorkflowHooks,
26
26
  emitWorkflowCall: () => emitWorkflowCall,
27
27
  parallel: () => parallel,
28
+ reportError: () => reportError,
28
29
  runWithHookContext: () => runWithHookContext,
29
30
  useAbortSignal: () => useAbortSignal,
30
31
  useInterrupt: () => useInterrupt,
@@ -531,26 +532,53 @@ var import_errors3 = require("@kortyx/core/errors");
531
532
 
532
533
  // src/error-diagnostics.ts
533
534
  var import_errors2 = require("@kortyx/core/errors");
534
- function errorDiagnostics(error, project) {
535
+ var MAX_STACK_LENGTH = 32768;
536
+ var MAX_CAUSE_DEPTH = 4;
537
+ var projectDetails = (value, depth, seen) => {
538
+ const objectValue = value && typeof value === "object" ? value : void 0;
539
+ if (objectValue) {
540
+ if (seen.has(objectValue))
541
+ return { type: "Error", message: "Circular error cause." };
542
+ seen.add(objectValue);
543
+ }
544
+ const name = (0, import_errors2.errorProperty)(value, "name") ?? (value instanceof Error ? value.name : void 0);
545
+ const message = (0, import_errors2.errorProperty)(value, "message");
546
+ const stack = (0, import_errors2.errorProperty)(value, "stack") ?? (value instanceof Error ? (() => {
547
+ try {
548
+ return value.stack;
549
+ } catch {
550
+ return void 0;
551
+ }
552
+ })() : void 0);
553
+ const cause = depth < MAX_CAUSE_DEPTH ? (0, import_errors2.errorProperty)(value, "cause") : null;
554
+ return {
555
+ type: typeof name === "string" ? name.slice(0, 256) : "Error",
556
+ message: (typeof value === "string" ? value : typeof message === "string" ? message : "Execution reported a fault.").slice(0, 8192),
557
+ ...typeof stack === "string" ? { stack: stack.slice(0, MAX_STACK_LENGTH) } : {},
558
+ ...cause !== null && cause !== void 0 ? { cause: projectDetails(cause, depth + 1, seen) } : {}
559
+ };
560
+ };
561
+ var sanitizeProjectedDetails = (details, depth = 0) => ({
562
+ ...typeof details.type === "string" ? { type: details.type.slice(0, 256) } : {},
563
+ message: typeof details.message === "string" ? details.message.slice(0, 8192) : "Execution reported a fault.",
564
+ ...typeof details.stack === "string" ? { stack: details.stack.slice(0, MAX_STACK_LENGTH) } : {},
565
+ ...depth < MAX_CAUSE_DEPTH && details.cause ? { cause: sanitizeProjectedDetails(details.cause, depth + 1) } : {}
566
+ });
567
+ function exceptionDiagnostics(error, project) {
535
568
  try {
536
- const name = (0, import_errors2.errorProperty)(error, "name") ?? (error instanceof Error ? error.name : void 0);
537
- const message = (0, import_errors2.errorProperty)(error, "message");
538
- const details = project ? project(error) : {
539
- type: typeof name === "string" ? name : "Error",
540
- message: typeof error === "string" ? error : typeof message === "string" ? message : "Execution reported a fault."
541
- };
542
- if (!details) return {};
543
- const projectedMessage = details.message;
544
- const projectedType = details.type;
545
- if (typeof projectedMessage !== "string") return {};
546
- return {
547
- errorMessage: projectedMessage.slice(0, 8192),
548
- ...typeof projectedType === "string" ? { errorType: projectedType.slice(0, 256) } : {}
549
- };
569
+ const details = project ? project(error) : projectDetails(error, 0, /* @__PURE__ */ new WeakSet());
570
+ return details ? sanitizeProjectedDetails(details) : null;
550
571
  } catch {
551
- return {};
572
+ return null;
552
573
  }
553
574
  }
575
+ function errorDiagnostics(error, project) {
576
+ const details = exceptionDiagnostics(error, project);
577
+ return details ? {
578
+ errorMessage: details.message,
579
+ ...details.type ? { errorType: details.type } : {}
580
+ } : {};
581
+ }
554
582
 
555
583
  // src/workflow-telemetry.ts
556
584
  var import_node_crypto2 = require("crypto");
@@ -3387,6 +3415,14 @@ function parallel(values) {
3387
3415
  return promise;
3388
3416
  }
3389
3417
 
3418
+ // src/report-error.ts
3419
+ function reportError(error, options = {}) {
3420
+ try {
3421
+ getReasonTraceAdapter()?.reportError?.(error, options);
3422
+ } catch {
3423
+ }
3424
+ }
3425
+
3390
3426
  // src/workflow.ts
3391
3427
  var import_node_crypto6 = require("crypto");
3392
3428
  var import_core8 = require("@kortyx/core");
@@ -3663,6 +3699,7 @@ async function runWorkflowCall(args, task) {
3663
3699
  createWorkflowHooks,
3664
3700
  emitWorkflowCall,
3665
3701
  parallel,
3702
+ reportError,
3666
3703
  runWithHookContext,
3667
3704
  useAbortSignal,
3668
3705
  useInterrupt,