@codemation/core-nodes 0.10.0 → 0.10.2

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/dist/index.d.cts CHANGED
@@ -1428,6 +1428,7 @@ declare class NodeBackedToolConfig<TNodeConfig extends RunnableNodeConfig<any, a
1428
1428
  readonly toolKind: "nodeBacked";
1429
1429
  readonly description?: string;
1430
1430
  readonly presentation?: AgentCanvasPresentation;
1431
+ readonly onRejected?: "halt" | "return";
1431
1432
  private readonly inputSchemaValue;
1432
1433
  private readonly outputSchemaValue;
1433
1434
  private readonly mapInputValue?;
@@ -1589,6 +1590,13 @@ type NodeBackedToolConfigOptions<TNodeConfig extends RunnableNodeConfig<any, any
1589
1590
  outputSchema: TOutputSchema;
1590
1591
  mapInput?: NodeBackedToolInputMapper<TNodeConfig, input<TInputSchema>>;
1591
1592
  mapOutput?: NodeBackedToolOutputMapper<TNodeConfig, input<TInputSchema>, output<TOutputSchema>>;
1593
+ /**
1594
+ * Marks THIS tool binding as human-in-the-loop and sets the behavior when a human rejects the
1595
+ * approval: `"return"` feeds the rejection back to the agent as a tool result, `"halt"` stops the
1596
+ * run. Set per binding, so two tools backed by the same node can reject differently. When set, it
1597
+ * takes precedence over any `humanApprovalToolBehavior` marker carried by the backing node.
1598
+ */
1599
+ onRejected?: "halt" | "return";
1592
1600
  }>;
1593
1601
  interface AgentNodeConfig<TInputJson$1 = unknown, TOutputJson$1 = unknown> extends RunnableNodeConfig<TInputJson$1, TOutputJson$1> {
1594
1602
  readonly messages: AgentMessageConfig<TInputJson$1>;
@@ -1670,7 +1678,13 @@ type HttpBodySpec = Readonly<{
1670
1678
  kind: "none";
1671
1679
  }> | Readonly<{
1672
1680
  kind: "json";
1673
- data: unknown;
1681
+ /**
1682
+ * Serializable object/array to encode as the JSON body. Encoded exactly once via
1683
+ * `JSON.stringify`, so pass the value directly (e.g. `{ a: 1 }`) — never a
1684
+ * pre-stringified string (`JSON.stringify(...)`), which would double-encode it.
1685
+ * Typed as `object` so a bare string/primitive is a compile-time error.
1686
+ */
1687
+ data: object;
1674
1688
  }> | Readonly<{
1675
1689
  kind: "form";
1676
1690
  data: Readonly<Record<string, string>>;
@@ -2680,8 +2694,10 @@ declare class AIAgentNode implements RunnableNode<AIAgent<any, any>> {
2680
2694
  private resolveTools;
2681
2695
  private createItemScopedTools;
2682
2696
  /**
2683
- * Detects whether a tool config is backed by a `defineHumanApprovalNode` marker
2684
- * and returns the HITL behavior config, or `undefined` when not a HITL tool.
2697
+ * Resolves the HITL behavior for a tool binding, or `undefined` when it is not a HITL tool.
2698
+ * A binding is HITL if either the backing node carries a `defineHumanApprovalNode` marker or the
2699
+ * binding sets a per-binding `onRejected` via `asTool(..., { onRejected })`. The per-binding value
2700
+ * wins over the node marker, so two tools backed by the same node can reject differently.
2685
2701
  */
2686
2702
  private resolveHumanApprovalBehavior;
2687
2703
  /**
@@ -2972,7 +2988,7 @@ declare class HttpRequest<TInputJson$1 = Readonly<{
2972
2988
  headers?: Readonly<Record<string, string>>;
2973
2989
  /** Query parameters to append to the URL. */
2974
2990
  query?: Readonly<Record<string, string>>;
2975
- /** Request body specification. For canvas use, pass a JSON string in `body.data`. */
2991
+ /** Request body specification. For `kind:"json"`, pass the object directly in `body.data` — it is JSON-encoded exactly once, so never a pre-stringified string. */
2976
2992
  body?: HttpBodySpec;
2977
2993
  /**
2978
2994
  * Credential slot.
@@ -3054,7 +3070,7 @@ declare class HttpRequest<TInputJson$1 = Readonly<{
3054
3070
  headers?: Readonly<Record<string, string>>;
3055
3071
  /** Query parameters to append to the URL. */
3056
3072
  query?: Readonly<Record<string, string>>;
3057
- /** Request body specification. For canvas use, pass a JSON string in `body.data`. */
3073
+ /** Request body specification. For `kind:"json"`, pass the object directly in `body.data` — it is JSON-encoded exactly once, so never a pre-stringified string. */
3058
3074
  body?: HttpBodySpec;
3059
3075
  /**
3060
3076
  * Credential slot.
package/dist/index.d.ts CHANGED
@@ -1428,6 +1428,7 @@ declare class NodeBackedToolConfig<TNodeConfig extends RunnableNodeConfig<any, a
1428
1428
  readonly toolKind: "nodeBacked";
1429
1429
  readonly description?: string;
1430
1430
  readonly presentation?: AgentCanvasPresentation;
1431
+ readonly onRejected?: "halt" | "return";
1431
1432
  private readonly inputSchemaValue;
1432
1433
  private readonly outputSchemaValue;
1433
1434
  private readonly mapInputValue?;
@@ -1589,6 +1590,13 @@ type NodeBackedToolConfigOptions<TNodeConfig extends RunnableNodeConfig<any, any
1589
1590
  outputSchema: TOutputSchema;
1590
1591
  mapInput?: NodeBackedToolInputMapper<TNodeConfig, input<TInputSchema>>;
1591
1592
  mapOutput?: NodeBackedToolOutputMapper<TNodeConfig, input<TInputSchema>, output<TOutputSchema>>;
1593
+ /**
1594
+ * Marks THIS tool binding as human-in-the-loop and sets the behavior when a human rejects the
1595
+ * approval: `"return"` feeds the rejection back to the agent as a tool result, `"halt"` stops the
1596
+ * run. Set per binding, so two tools backed by the same node can reject differently. When set, it
1597
+ * takes precedence over any `humanApprovalToolBehavior` marker carried by the backing node.
1598
+ */
1599
+ onRejected?: "halt" | "return";
1592
1600
  }>;
1593
1601
  interface AgentNodeConfig<TInputJson$1 = unknown, TOutputJson$1 = unknown> extends RunnableNodeConfig<TInputJson$1, TOutputJson$1> {
1594
1602
  readonly messages: AgentMessageConfig<TInputJson$1>;
@@ -1670,7 +1678,13 @@ type HttpBodySpec = Readonly<{
1670
1678
  kind: "none";
1671
1679
  }> | Readonly<{
1672
1680
  kind: "json";
1673
- data: unknown;
1681
+ /**
1682
+ * Serializable object/array to encode as the JSON body. Encoded exactly once via
1683
+ * `JSON.stringify`, so pass the value directly (e.g. `{ a: 1 }`) — never a
1684
+ * pre-stringified string (`JSON.stringify(...)`), which would double-encode it.
1685
+ * Typed as `object` so a bare string/primitive is a compile-time error.
1686
+ */
1687
+ data: object;
1674
1688
  }> | Readonly<{
1675
1689
  kind: "form";
1676
1690
  data: Readonly<Record<string, string>>;
@@ -2680,8 +2694,10 @@ declare class AIAgentNode implements RunnableNode<AIAgent<any, any>> {
2680
2694
  private resolveTools;
2681
2695
  private createItemScopedTools;
2682
2696
  /**
2683
- * Detects whether a tool config is backed by a `defineHumanApprovalNode` marker
2684
- * and returns the HITL behavior config, or `undefined` when not a HITL tool.
2697
+ * Resolves the HITL behavior for a tool binding, or `undefined` when it is not a HITL tool.
2698
+ * A binding is HITL if either the backing node carries a `defineHumanApprovalNode` marker or the
2699
+ * binding sets a per-binding `onRejected` via `asTool(..., { onRejected })`. The per-binding value
2700
+ * wins over the node marker, so two tools backed by the same node can reject differently.
2685
2701
  */
2686
2702
  private resolveHumanApprovalBehavior;
2687
2703
  /**
@@ -2972,7 +2988,7 @@ declare class HttpRequest<TInputJson$1 = Readonly<{
2972
2988
  headers?: Readonly<Record<string, string>>;
2973
2989
  /** Query parameters to append to the URL. */
2974
2990
  query?: Readonly<Record<string, string>>;
2975
- /** Request body specification. For canvas use, pass a JSON string in `body.data`. */
2991
+ /** Request body specification. For `kind:"json"`, pass the object directly in `body.data` — it is JSON-encoded exactly once, so never a pre-stringified string. */
2976
2992
  body?: HttpBodySpec;
2977
2993
  /**
2978
2994
  * Credential slot.
@@ -3054,7 +3070,7 @@ declare class HttpRequest<TInputJson$1 = Readonly<{
3054
3070
  headers?: Readonly<Record<string, string>>;
3055
3071
  /** Query parameters to append to the URL. */
3056
3072
  query?: Readonly<Record<string, string>>;
3057
- /** Request body specification. For canvas use, pass a JSON string in `body.data`. */
3073
+ /** Request body specification. For `kind:"json"`, pass the object directly in `body.data` — it is JSON-encoded exactly once, so never a pre-stringified string. */
3058
3074
  body?: HttpBodySpec;
3059
3075
  /**
3060
3076
  * Credential slot.
package/dist/index.js CHANGED
@@ -495,10 +495,13 @@ var HttpRequestExecutor = class {
495
495
  var HttpBodyBuilder = class {
496
496
  async build(spec, item, ctx) {
497
497
  if (!spec || spec.kind === "none") return;
498
- if (spec.kind === "json") return {
499
- body: JSON.stringify(spec.data),
500
- contentType: "application/json"
501
- };
498
+ if (spec.kind === "json") {
499
+ if (typeof spec.data === "string") throw new Error("HttpRequest body kind:\"json\" expects a serializable object for \"data\", but received a string. Pass the object directly (e.g. { a: 1 }), not a pre-stringified JSON string (JSON.stringify(...)).");
500
+ return {
501
+ body: JSON.stringify(spec.data),
502
+ contentType: "application/json"
503
+ };
504
+ }
502
505
  if (spec.kind === "form") {
503
506
  const params = new URLSearchParams();
504
507
  for (const [key, value] of Object.entries(spec.data)) params.append(key, value);
@@ -6540,14 +6543,17 @@ let AIAgentNode = class AIAgentNode$1 {
6540
6543
  });
6541
6544
  }
6542
6545
  /**
6543
- * Detects whether a tool config is backed by a `defineHumanApprovalNode` marker
6544
- * and returns the HITL behavior config, or `undefined` when not a HITL tool.
6546
+ * Resolves the HITL behavior for a tool binding, or `undefined` when it is not a HITL tool.
6547
+ * A binding is HITL if either the backing node carries a `defineHumanApprovalNode` marker or the
6548
+ * binding sets a per-binding `onRejected` via `asTool(..., { onRejected })`. The per-binding value
6549
+ * wins over the node marker, so two tools backed by the same node can reject differently.
6545
6550
  */
6546
6551
  resolveHumanApprovalBehavior(config$1) {
6547
6552
  if (!this.isNodeBackedToolConfig(config$1)) return void 0;
6548
6553
  const marker = config$1.node.humanApprovalToolBehavior;
6549
- if (marker === void 0) return void 0;
6550
- return { onRejected: marker.onRejected ?? "return" };
6554
+ const perBinding = config$1.onRejected;
6555
+ if (marker === void 0 && perBinding === void 0) return void 0;
6556
+ return { onRejected: perBinding ?? marker?.onRejected ?? "return" };
6551
6557
  }
6552
6558
  /**
6553
6559
  * Invoke a text turn using the merged tool set from item-scoped tools (coordinator-managed)