@signalridge/pi-workflows 1.7.5 → 1.9.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/src/errors.ts CHANGED
@@ -67,6 +67,25 @@ export class WorkflowError extends Error {
67
67
  }
68
68
  }
69
69
 
70
+ // Transported VM throws must not acquire provider/abort classification merely
71
+ // because IPC reconstructed them in the host Error realm. Keep provenance and
72
+ // helper-computed text outside user data (including non-Error object throws).
73
+ const scriptThrows = new WeakMap<object, string>();
74
+
75
+ export function markScriptThrow(value: unknown, text: string): void {
76
+ if ((typeof value === "object" && value !== null) || typeof value === "function") scriptThrows.set(value, text);
77
+ }
78
+
79
+ export function scriptThrowText(value: unknown): string | undefined {
80
+ return (typeof value === "object" && value !== null) || typeof value === "function"
81
+ ? scriptThrows.get(value)
82
+ : undefined;
83
+ }
84
+
85
+ export function describeWorkflowError(value: unknown): string {
86
+ return scriptThrowText(value) ?? (value instanceof Error ? value.message : String(value));
87
+ }
88
+
70
89
  /** Narrow an unknown failure to WorkflowError. */
71
90
  export function isWorkflowError(error: unknown): error is WorkflowError {
72
91
  return error instanceof WorkflowError;
@@ -102,6 +121,13 @@ function providerResetHint(message: string): string | undefined {
102
121
  */
103
122
  export function wrapError(error: unknown, context?: { agentLabel?: string }): WorkflowError {
104
123
  if (isWorkflowError(error)) return error;
124
+ const scriptText = scriptThrowText(error);
125
+ if (scriptText !== undefined)
126
+ return new WorkflowError(scriptText, WorkflowErrorCode.AGENT_EXECUTION_ERROR, {
127
+ recoverable: true,
128
+ agentLabel: context?.agentLabel,
129
+ details: error,
130
+ });
105
131
 
106
132
  if (isAbortError(error)) {
107
133
  return new WorkflowError(