veryfront 0.1.324 → 0.1.327
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/esm/cli/commands/extension/init-command.js +2 -2
- package/esm/cli/commands/extension/validate-command.js +1 -1
- package/esm/deno.d.ts +7 -0
- package/esm/deno.js +8 -1
- package/esm/deps/esm.sh/react-dom@19.2.4/client.d.ts +2 -0
- package/esm/deps/esm.sh/react-dom@19.2.4/client.d.ts.map +1 -0
- package/esm/deps/esm.sh/react-dom@19.2.4/client.js +5 -0
- package/esm/deps/esm.sh/scheduler@^0.27.0.d.ts +2 -0
- package/esm/deps/esm.sh/scheduler@^0.27.0.d.ts.map +1 -0
- package/esm/deps/esm.sh/scheduler@^0.27.0.js +3 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.js +65 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assert.d.ts +17 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assert.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assert.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equal.d.ts +25 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equal.js +194 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equals.d.ts +37 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/equals.js +61 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/exists.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/exists.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/fail.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/fail.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/fail.js +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/false.d.ts +19 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/false.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/false.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.js +52 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts +25 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less.d.ts +19 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less.js +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/match.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/match.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/mod.d.ts +44 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/mod.js +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.js +39 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.js +32 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.js +177 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts +42 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts +24 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.js +58 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/throws.d.ts +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/throws.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/throws.js +44 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.js +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.js +20 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/assertion_state.d.ts +150 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/assertion_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/assertion_state.js +224 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/build_message.d.ts +80 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/build_message.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/build_message.js +116 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/diff.d.ts +140 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/diff.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/diff.js +276 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/diff_str.d.ts +99 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/diff_str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/diff_str.js +182 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/format.d.ts +29 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/format.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/format.js +70 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/styles.d.ts +159 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/styles.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/styles.js +207 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/types.d.ts +25 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.13/types.js +3 -0
- package/esm/deps/jsr.io/@std/testing/1.0.18/_test_suite.d.ts +80 -0
- package/esm/deps/jsr.io/@std/testing/1.0.18/_test_suite.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.18/_test_suite.js +348 -0
- package/esm/deps/jsr.io/@std/testing/1.0.18/bdd.d.ts +738 -0
- package/esm/deps/jsr.io/@std/testing/1.0.18/bdd.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.18/bdd.js +656 -0
- package/esm/src/agent/fork-runtime-stream.d.ts +143 -0
- package/esm/src/agent/fork-runtime-stream.d.ts.map +1 -0
- package/esm/src/agent/fork-runtime-stream.js +505 -0
- package/esm/src/agent/hosted-child-fork-stream-execution.d.ts +130 -0
- package/esm/src/agent/hosted-child-fork-stream-execution.d.ts.map +1 -0
- package/esm/src/agent/hosted-child-fork-stream-execution.js +391 -0
- package/esm/src/agent/index.d.ts +2 -0
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +2 -0
- package/esm/src/chat/conversation.d.ts +5 -5
- package/esm/src/chat/final-step-fallback.js +2 -2
- package/esm/src/modules/index.d.ts +12 -0
- package/esm/src/modules/index.d.ts.map +1 -0
- package/esm/src/modules/index.js +10 -0
- package/esm/src/modules/module-resolver.d.ts +28 -0
- package/esm/src/modules/module-resolver.d.ts.map +1 -0
- package/esm/src/modules/module-resolver.js +106 -0
- package/esm/src/rendering/cleanup.d.ts +7 -0
- package/esm/src/rendering/cleanup.d.ts.map +1 -0
- package/esm/src/rendering/cleanup.js +22 -0
- package/esm/src/rendering/ssr/index.d.ts +10 -0
- package/esm/src/rendering/ssr/index.d.ts.map +1 -0
- package/esm/src/rendering/ssr/index.js +8 -0
- package/esm/src/rendering/ssr/mdx-module-loader.d.ts +5 -0
- package/esm/src/rendering/ssr/mdx-module-loader.d.ts.map +1 -0
- package/esm/src/rendering/ssr/mdx-module-loader.js +150 -0
- package/esm/src/rendering/ssr/mdx-renderer.d.ts +4 -0
- package/esm/src/rendering/ssr/mdx-renderer.d.ts.map +1 -0
- package/esm/src/rendering/ssr/mdx-renderer.js +44 -0
- package/esm/src/rendering/ssr/types.d.ts +13 -0
- package/esm/src/rendering/ssr/types.d.ts.map +1 -0
- package/esm/src/rendering/ssr/types.js +1 -0
- package/esm/src/sandbox/index.d.ts +1 -0
- package/esm/src/sandbox/index.d.ts.map +1 -1
- package/esm/src/sandbox/index.js +1 -0
- package/esm/src/sandbox/shell-tools.d.ts +39 -0
- package/esm/src/sandbox/shell-tools.d.ts.map +1 -0
- package/esm/src/sandbox/shell-tools.js +177 -0
- package/esm/src/server/shared/index.d.ts +7 -0
- package/esm/src/server/shared/index.d.ts.map +1 -0
- package/esm/src/server/shared/index.js +6 -0
- package/esm/src/testing/assert.d.ts +22 -0
- package/esm/src/testing/assert.d.ts.map +1 -0
- package/esm/src/testing/assert.js +217 -0
- package/esm/src/testing/bdd.d.ts +67 -0
- package/esm/src/testing/bdd.d.ts.map +1 -0
- package/esm/src/testing/bdd.js +401 -0
- package/esm/src/testing/deno-compat.d.ts +26 -0
- package/esm/src/testing/deno-compat.d.ts.map +1 -0
- package/esm/src/testing/deno-compat.js +146 -0
- package/esm/src/testing/index.d.ts +28 -0
- package/esm/src/testing/index.d.ts.map +1 -0
- package/esm/src/testing/index.js +27 -0
- package/esm/src/testing/init.d.ts +2 -0
- package/esm/src/testing/init.d.ts.map +1 -0
- package/esm/src/testing/init.js +18 -0
- package/esm/src/testing/isolation.d.ts +30 -0
- package/esm/src/testing/isolation.d.ts.map +1 -0
- package/esm/src/testing/isolation.js +151 -0
- package/esm/src/testing/timing.d.ts +4 -0
- package/esm/src/testing/timing.d.ts.map +1 -0
- package/esm/src/testing/timing.js +22 -0
- package/esm/src/testing/utils.d.ts +6 -0
- package/esm/src/testing/utils.d.ts.map +1 -0
- package/esm/src/testing/utils.js +49 -0
- package/esm/src/types/global-guards.d.ts +11 -0
- package/esm/src/types/global-guards.d.ts.map +1 -0
- package/esm/src/types/global-guards.js +12 -0
- package/esm/src/utils/cache/keys/namespace.d.ts +3 -0
- package/esm/src/utils/cache/keys/namespace.d.ts.map +1 -0
- package/esm/src/utils/cache/keys/namespace.js +19 -0
- package/esm/src/utils/clsx.d.ts +3 -3
- package/esm/src/utils/clsx.d.ts.map +1 -1
- package/esm/src/utils/clsx.js +2 -3
- package/esm/src/utils/mime-types.d.ts +0 -6
- package/esm/src/utils/mime-types.d.ts.map +1 -1
- package/esm/src/utils/mime-types.js +0 -1
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +14 -1
- package/src/cli/commands/extension/init-command.ts +2 -2
- package/src/cli/commands/extension/validate-command.ts +1 -1
- package/src/deno.js +8 -1
- package/src/deps/esm.sh/@types/react-dom@19.2.3/client.d.ts +105 -0
- package/src/deps/esm.sh/@types/react@19.2.14/global.d.ts +166 -0
- package/src/deps/esm.sh/@types/react@19.2.14/index.d.ts +4370 -0
- package/src/deps/esm.sh/@types/scheduler@0.26.0/index.d.ts +30 -0
- package/src/deps/esm.sh/csstype@3.2.3/index.d.ts +22569 -0
- package/src/deps/esm.sh/react-dom@19.2.4/client.d.ts +105 -0
- package/src/deps/esm.sh/react-dom@19.2.4/client.js +5 -0
- package/src/deps/esm.sh/scheduler@^0.27.0.d.ts +30 -0
- package/src/deps/esm.sh/scheduler@^0.27.0.js +3 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/almost_equals.ts +56 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/array_includes.ts +76 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/assert.ts +24 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/assertion_error.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/equal.ts +226 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/equals.ts +68 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/exists.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/fail.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/false.ts +27 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/greater.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/instance_of.ts +64 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/is_error.ts +65 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/less.ts +29 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/less_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/mod.ts +47 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/not_equals.ts +43 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/not_instance_of.ts +33 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/not_match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.ts +42 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/object_match.ts +224 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/rejects.ts +123 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/strict_equals.ts +68 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/string_includes.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/throws.ts +111 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/unimplemented.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.19/unreachable.ts +21 -0
- package/src/deps/jsr.io/@std/internal/1.0.13/assertion_state.ts +248 -0
- package/src/deps/jsr.io/@std/internal/1.0.13/build_message.ts +147 -0
- package/src/deps/jsr.io/@std/internal/1.0.13/diff.ts +317 -0
- package/src/deps/jsr.io/@std/internal/1.0.13/diff_str.ts +208 -0
- package/src/deps/jsr.io/@std/internal/1.0.13/format.ts +89 -0
- package/src/deps/jsr.io/@std/internal/1.0.13/styles.ts +233 -0
- package/src/deps/jsr.io/@std/internal/1.0.13/types.ts +30 -0
- package/src/deps/jsr.io/@std/testing/1.0.18/_test_suite.ts +461 -0
- package/src/deps/jsr.io/@std/testing/1.0.18/bdd.ts +1294 -0
- package/src/src/agent/fork-runtime-stream.ts +780 -0
- package/src/src/agent/hosted-child-fork-stream-execution.ts +579 -0
- package/src/src/agent/index.ts +26 -0
- package/src/src/chat/final-step-fallback.ts +2 -2
- package/src/src/modules/index.ts +43 -0
- package/src/src/modules/module-resolver.ts +145 -0
- package/src/src/rendering/cleanup.ts +27 -0
- package/src/src/rendering/ssr/index.ts +10 -0
- package/src/src/rendering/ssr/mdx-module-loader.ts +185 -0
- package/src/src/rendering/ssr/mdx-renderer.ts +66 -0
- package/src/src/rendering/ssr/types.ts +14 -0
- package/src/src/sandbox/index.ts +9 -0
- package/src/src/sandbox/shell-tools.ts +242 -0
- package/src/src/server/shared/index.ts +12 -0
- package/src/src/testing/assert.ts +352 -0
- package/src/src/testing/bdd.ts +618 -0
- package/src/src/testing/deno-compat.ts +206 -0
- package/src/src/testing/index.ts +92 -0
- package/src/src/testing/init.ts +21 -0
- package/src/src/testing/isolation.ts +177 -0
- package/src/src/testing/timing.ts +27 -0
- package/src/src/testing/utils.ts +44 -0
- package/src/src/types/global-guards.ts +21 -0
- package/src/src/utils/cache/keys/namespace.ts +25 -0
- package/src/src/utils/clsx.ts +2 -4
- package/src/src/utils/mime-types.ts +0 -2
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
2
|
+
import type { Tool } from "../tool/index.js";
|
|
3
|
+
import { isRecord } from "../chat/conversation.js";
|
|
4
|
+
import { safeJsonParse } from "../chat/provider-errors.js";
|
|
5
|
+
import { runWithVeryfrontCloudContextAsync } from "../provider/veryfront-cloud/context.js";
|
|
6
|
+
import type { AgUiRuntimeStreamEvent } from "./ag-ui-browser-encoder.js";
|
|
7
|
+
import {
|
|
8
|
+
mergeToolInputDelta,
|
|
9
|
+
parseToolInputObject,
|
|
10
|
+
stripLeadingEmptyObjectPlaceholder,
|
|
11
|
+
} from "./data-stream.js";
|
|
12
|
+
import {
|
|
13
|
+
HOSTED_CHILD_STREAM_TIMEOUT_TOKEN,
|
|
14
|
+
resolveHostedChildPromiseWithTimeout,
|
|
15
|
+
} from "./hosted-child-stream-watchdog.js";
|
|
16
|
+
import { AgentRuntime } from "./runtime/index.js";
|
|
17
|
+
import type { AgentResponse, Message as AgentMessage } from "./schemas/index.js";
|
|
18
|
+
|
|
19
|
+
interface ForkStreamPart {
|
|
20
|
+
type: "reasoning-delta" | "text-delta";
|
|
21
|
+
text: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ForkToolInputStartPart {
|
|
25
|
+
type: "tool-input-start";
|
|
26
|
+
toolCallId: string;
|
|
27
|
+
toolName: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface ForkToolInputDeltaPart {
|
|
31
|
+
type: "tool-input-delta";
|
|
32
|
+
toolCallId: string;
|
|
33
|
+
delta: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ForkToolCallPart {
|
|
37
|
+
type: "tool-call";
|
|
38
|
+
toolName: string;
|
|
39
|
+
toolCallId: string;
|
|
40
|
+
input: unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface ForkToolResultPart {
|
|
44
|
+
type: "tool-result";
|
|
45
|
+
toolName: string;
|
|
46
|
+
toolCallId: string;
|
|
47
|
+
input: unknown;
|
|
48
|
+
output: unknown;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface ForkToolErrorPart {
|
|
52
|
+
type: "tool-error";
|
|
53
|
+
toolName: string;
|
|
54
|
+
toolCallId: string;
|
|
55
|
+
input: unknown;
|
|
56
|
+
error: Error;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface ForkErrorPart {
|
|
60
|
+
type: "error";
|
|
61
|
+
error: Error;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ForkRuntimeStep {
|
|
65
|
+
text: string;
|
|
66
|
+
messages: unknown[];
|
|
67
|
+
toolCalls: Array<{
|
|
68
|
+
toolCallId: string;
|
|
69
|
+
toolName: string;
|
|
70
|
+
input: unknown;
|
|
71
|
+
}>;
|
|
72
|
+
toolResults: Array<{
|
|
73
|
+
toolCallId: string;
|
|
74
|
+
toolName: string;
|
|
75
|
+
input: unknown;
|
|
76
|
+
output: unknown;
|
|
77
|
+
}>;
|
|
78
|
+
finishReason: string | null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface RecoveredToolObservation {
|
|
82
|
+
sawInputStart: boolean;
|
|
83
|
+
sawInputDelta: boolean;
|
|
84
|
+
sawInputAvailable: boolean;
|
|
85
|
+
sawOutputAvailable: boolean;
|
|
86
|
+
sawOutputError: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ForkRecoveredPartsState {
|
|
90
|
+
toolCalls: Map<string, RecoveredToolObservation>;
|
|
91
|
+
emittedToolCallIds: Set<string>;
|
|
92
|
+
emittedToolResultIds: Set<string>;
|
|
93
|
+
logger?: ForkRuntimeStreamLogger;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
type FrameworkToolCallState = RecoveredToolObservation & {
|
|
97
|
+
toolName: string;
|
|
98
|
+
inputText: string;
|
|
99
|
+
input: Record<string, unknown>;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
type StreamedToolCallState = {
|
|
103
|
+
toolCallId: string;
|
|
104
|
+
toolName: string;
|
|
105
|
+
inputText: string;
|
|
106
|
+
input: unknown;
|
|
107
|
+
status: "pending" | "completed" | "error";
|
|
108
|
+
output?: unknown;
|
|
109
|
+
errorText?: string;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
type StreamedMessage = {
|
|
113
|
+
role: "assistant" | "tool";
|
|
114
|
+
parts: AgentMessage["parts"];
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
type StreamedStepState = {
|
|
118
|
+
text: string;
|
|
119
|
+
toolCalls: Map<string, StreamedToolCallState>;
|
|
120
|
+
messages: StreamedMessage[];
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export type FrameworkStreamState = {
|
|
124
|
+
toolCalls: Map<string, FrameworkToolCallState>;
|
|
125
|
+
emittedToolCallIds: Set<string>;
|
|
126
|
+
emittedToolResultIds: Set<string>;
|
|
127
|
+
logger?: ForkRuntimeStreamLogger;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export type ForkPart =
|
|
131
|
+
| ForkStreamPart
|
|
132
|
+
| ForkToolInputStartPart
|
|
133
|
+
| ForkToolInputDeltaPart
|
|
134
|
+
| ForkToolCallPart
|
|
135
|
+
| ForkToolResultPart
|
|
136
|
+
| ForkToolErrorPart
|
|
137
|
+
| ForkErrorPart;
|
|
138
|
+
|
|
139
|
+
export type ForkRuntimeStreamLogger = {
|
|
140
|
+
warn: (message: string, metadata?: Record<string, unknown>) => void;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export interface ForkRuntimeStreamResult {
|
|
144
|
+
fullStream: AsyncIterable<ForkPart>;
|
|
145
|
+
steps: PromiseLike<readonly ForkRuntimeStep[]>;
|
|
146
|
+
totalUsage: PromiseLike<
|
|
147
|
+
| {
|
|
148
|
+
inputTokens?: number;
|
|
149
|
+
outputTokens?: number;
|
|
150
|
+
}
|
|
151
|
+
| undefined
|
|
152
|
+
>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const DEFAULT_FORK_RESPONSE_PROMISE_TIMEOUT_MS = 1_000;
|
|
156
|
+
|
|
157
|
+
function createFrameworkForkAbortError(abortSignal?: AbortSignal): Error {
|
|
158
|
+
if (abortSignal?.reason instanceof Error) {
|
|
159
|
+
return abortSignal.reason;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return new DOMException("Framework fork aborted before completion.", "AbortError");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function runFrameworkForkStep(input: {
|
|
166
|
+
apiUrl: string;
|
|
167
|
+
authToken: string;
|
|
168
|
+
projectId: string | null;
|
|
169
|
+
model: string;
|
|
170
|
+
messages: AgentMessage[];
|
|
171
|
+
system: string;
|
|
172
|
+
abortSignal?: AbortSignal;
|
|
173
|
+
forkToolNames: string[];
|
|
174
|
+
frameworkTools: Record<string, Tool | boolean>;
|
|
175
|
+
providerOptions?: Record<string, unknown>;
|
|
176
|
+
}): Promise<{
|
|
177
|
+
stream: ReadableStream<Uint8Array>;
|
|
178
|
+
responsePromise: Promise<AgentResponse>;
|
|
179
|
+
}> {
|
|
180
|
+
let resolveResponsePromise: (response: AgentResponse) => void;
|
|
181
|
+
let rejectResponsePromise: (error: Error) => void;
|
|
182
|
+
const responsePromise = new Promise<AgentResponse>((resolve, reject) => {
|
|
183
|
+
resolveResponsePromise = resolve;
|
|
184
|
+
rejectResponsePromise = reject;
|
|
185
|
+
});
|
|
186
|
+
const abortHandler = () => {
|
|
187
|
+
rejectResponsePromise(createFrameworkForkAbortError(input.abortSignal));
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
if (input.abortSignal) {
|
|
191
|
+
if (input.abortSignal.aborted) {
|
|
192
|
+
abortHandler();
|
|
193
|
+
} else {
|
|
194
|
+
input.abortSignal.addEventListener("abort", abortHandler, { once: true });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const runtimeConfig = {
|
|
199
|
+
model: input.model,
|
|
200
|
+
system: input.system,
|
|
201
|
+
tools: input.frameworkTools,
|
|
202
|
+
maxSteps: 1,
|
|
203
|
+
...(input.providerOptions
|
|
204
|
+
? { resolveModelTransport: () => ({ providerOptions: input.providerOptions }) }
|
|
205
|
+
: {}),
|
|
206
|
+
__vfAllowedRemoteTools: input.forkToolNames,
|
|
207
|
+
};
|
|
208
|
+
const runtime = new AgentRuntime("invoke-agent-child-framework", runtimeConfig);
|
|
209
|
+
|
|
210
|
+
const stream = await runWithVeryfrontCloudContextAsync(
|
|
211
|
+
{
|
|
212
|
+
apiBaseUrl: input.apiUrl,
|
|
213
|
+
apiToken: input.authToken,
|
|
214
|
+
serviceLayer: "cloud",
|
|
215
|
+
},
|
|
216
|
+
() =>
|
|
217
|
+
runtime.stream(
|
|
218
|
+
input.messages,
|
|
219
|
+
input.projectId ? { projectId: input.projectId } : undefined,
|
|
220
|
+
{
|
|
221
|
+
onFinish: (response) => {
|
|
222
|
+
input.abortSignal?.removeEventListener("abort", abortHandler);
|
|
223
|
+
resolveResponsePromise(response);
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
input.model,
|
|
227
|
+
undefined,
|
|
228
|
+
input.abortSignal,
|
|
229
|
+
),
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
stream,
|
|
234
|
+
responsePromise,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function createStreamedStepState(): StreamedStepState {
|
|
239
|
+
return {
|
|
240
|
+
text: "",
|
|
241
|
+
toolCalls: new Map(),
|
|
242
|
+
messages: [],
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function appendStreamedMessagePart(
|
|
247
|
+
state: StreamedStepState,
|
|
248
|
+
role: "assistant" | "tool",
|
|
249
|
+
part: AgentMessage["parts"][number],
|
|
250
|
+
): void {
|
|
251
|
+
const lastMessage = state.messages.at(-1);
|
|
252
|
+
if (lastMessage?.role === role) {
|
|
253
|
+
lastMessage.parts.push(part);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
state.messages.push({
|
|
258
|
+
role,
|
|
259
|
+
parts: [part],
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function isFrameworkTextPart(
|
|
264
|
+
part: AgentMessage["parts"][number],
|
|
265
|
+
): part is Extract<AgentMessage["parts"][number], { type: "text" }> {
|
|
266
|
+
return part.type === "text";
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function applyPartToStreamedStepState(state: StreamedStepState, part: ForkPart) {
|
|
270
|
+
switch (part.type) {
|
|
271
|
+
case "tool-input-start": {
|
|
272
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
273
|
+
state.toolCalls.set(part.toolCallId, {
|
|
274
|
+
toolCallId: part.toolCallId,
|
|
275
|
+
toolName: part.toolName,
|
|
276
|
+
inputText: existing?.inputText ?? "",
|
|
277
|
+
input: existing?.input ?? {},
|
|
278
|
+
status: existing?.status ?? "pending",
|
|
279
|
+
...(existing?.output !== undefined ? { output: existing.output } : {}),
|
|
280
|
+
...(existing?.errorText ? { errorText: existing.errorText } : {}),
|
|
281
|
+
});
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case "text-delta": {
|
|
285
|
+
state.text += part.text;
|
|
286
|
+
const lastAssistantMessage = state.messages.at(-1);
|
|
287
|
+
const lastAssistantPart = lastAssistantMessage?.role === "assistant"
|
|
288
|
+
? lastAssistantMessage.parts.at(-1)
|
|
289
|
+
: null;
|
|
290
|
+
if (lastAssistantMessage && lastAssistantPart && isFrameworkTextPart(lastAssistantPart)) {
|
|
291
|
+
lastAssistantPart.text += part.text;
|
|
292
|
+
} else {
|
|
293
|
+
appendStreamedMessagePart(state, "assistant", {
|
|
294
|
+
type: "text",
|
|
295
|
+
text: part.text,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
case "tool-input-delta": {
|
|
301
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
302
|
+
if (!existing) {
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
existing.inputText = mergeToolInputDelta(existing.inputText, part.delta);
|
|
307
|
+
const parsedInput = getParsedStreamedToolInput(existing.inputText);
|
|
308
|
+
if (parsedInput) {
|
|
309
|
+
existing.input = parsedInput;
|
|
310
|
+
}
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case "tool-call": {
|
|
314
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
315
|
+
state.toolCalls.set(part.toolCallId, {
|
|
316
|
+
toolCallId: part.toolCallId,
|
|
317
|
+
toolName: part.toolName,
|
|
318
|
+
input: part.input,
|
|
319
|
+
inputText: existing?.inputText ?? "",
|
|
320
|
+
status: "pending",
|
|
321
|
+
...(existing?.output !== undefined ? { output: existing.output } : {}),
|
|
322
|
+
...(existing?.errorText ? { errorText: existing.errorText } : {}),
|
|
323
|
+
});
|
|
324
|
+
appendStreamedMessagePart(state, "assistant", {
|
|
325
|
+
type: `tool-${part.toolName}`,
|
|
326
|
+
toolCallId: part.toolCallId,
|
|
327
|
+
toolName: part.toolName,
|
|
328
|
+
args: parseToolInputObject(part.input),
|
|
329
|
+
});
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
case "tool-result": {
|
|
333
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
334
|
+
state.toolCalls.set(part.toolCallId, {
|
|
335
|
+
toolCallId: part.toolCallId,
|
|
336
|
+
toolName: part.toolName,
|
|
337
|
+
input: part.input,
|
|
338
|
+
inputText: existing?.inputText ?? "",
|
|
339
|
+
status: "completed",
|
|
340
|
+
output: part.output,
|
|
341
|
+
...(existing?.errorText ? { errorText: existing.errorText } : {}),
|
|
342
|
+
});
|
|
343
|
+
appendStreamedMessagePart(state, "tool", {
|
|
344
|
+
type: "tool-result",
|
|
345
|
+
toolCallId: part.toolCallId,
|
|
346
|
+
toolName: part.toolName,
|
|
347
|
+
result: part.output,
|
|
348
|
+
});
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
case "tool-error": {
|
|
352
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
353
|
+
state.toolCalls.set(part.toolCallId, {
|
|
354
|
+
toolCallId: part.toolCallId,
|
|
355
|
+
toolName: part.toolName,
|
|
356
|
+
input: part.input,
|
|
357
|
+
inputText: existing?.inputText ?? "",
|
|
358
|
+
status: "error",
|
|
359
|
+
...(existing?.output !== undefined ? { output: existing.output } : {}),
|
|
360
|
+
errorText: part.error.message,
|
|
361
|
+
});
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
default:
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function buildFallbackFrameworkMessages(
|
|
370
|
+
baseMessages: readonly AgentMessage[],
|
|
371
|
+
state: StreamedStepState,
|
|
372
|
+
): AgentMessage[] {
|
|
373
|
+
const messages: AgentMessage[] = baseMessages.map((message) => ({
|
|
374
|
+
...message,
|
|
375
|
+
parts: [...message.parts],
|
|
376
|
+
}));
|
|
377
|
+
|
|
378
|
+
if (state.messages.length > 0) {
|
|
379
|
+
messages.push(
|
|
380
|
+
...state.messages.map((message) => ({
|
|
381
|
+
id: dntShim.crypto.randomUUID(),
|
|
382
|
+
role: message.role,
|
|
383
|
+
timestamp: Date.now(),
|
|
384
|
+
parts: structuredClone(message.parts),
|
|
385
|
+
})),
|
|
386
|
+
);
|
|
387
|
+
} else if (state.text.trim().length > 0) {
|
|
388
|
+
messages.push({
|
|
389
|
+
id: dntShim.crypto.randomUUID(),
|
|
390
|
+
role: "assistant",
|
|
391
|
+
timestamp: Date.now(),
|
|
392
|
+
parts: [{ type: "text", text: state.text }],
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return messages;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function collectToolResultPaths(messages: readonly AgentMessage[]): string[] {
|
|
400
|
+
const paths = new Set<string>();
|
|
401
|
+
|
|
402
|
+
for (const message of messages) {
|
|
403
|
+
for (const part of message.parts) {
|
|
404
|
+
if (part.type !== "tool-result") {
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const partResult = "result" in part ? part.result : null;
|
|
409
|
+
const result = isRecord(partResult) ? partResult : null;
|
|
410
|
+
const path = typeof result?.path === "string" ? result.path : null;
|
|
411
|
+
if (path) {
|
|
412
|
+
paths.add(path);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return [...paths];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function buildRecoverablePriorWorkState(
|
|
421
|
+
messages: readonly AgentMessage[],
|
|
422
|
+
): StreamedStepState | null {
|
|
423
|
+
const paths = collectToolResultPaths(messages);
|
|
424
|
+
if (paths.length === 0) {
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const previewPaths = paths.slice(0, 8);
|
|
429
|
+
const suffix = paths.length > previewPaths.length
|
|
430
|
+
? ` and ${paths.length - previewPaths.length} more`
|
|
431
|
+
: "";
|
|
432
|
+
const text = `Completed child tool work. Project artifact(s): ${
|
|
433
|
+
previewPaths.join(", ")
|
|
434
|
+
}${suffix}.`;
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
text,
|
|
438
|
+
toolCalls: new Map(),
|
|
439
|
+
messages: [
|
|
440
|
+
{
|
|
441
|
+
role: "assistant",
|
|
442
|
+
parts: [{ type: "text", text }],
|
|
443
|
+
},
|
|
444
|
+
],
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function hasFallbackStepContent(state: StreamedStepState): boolean {
|
|
449
|
+
return state.text.trim().length > 0 || state.toolCalls.size > 0;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function buildFallbackAgentResponse(input: {
|
|
453
|
+
baseMessages: readonly AgentMessage[];
|
|
454
|
+
state: StreamedStepState;
|
|
455
|
+
}): AgentResponse {
|
|
456
|
+
return {
|
|
457
|
+
text: input.state.text,
|
|
458
|
+
messages: buildFallbackFrameworkMessages(input.baseMessages, input.state),
|
|
459
|
+
toolCalls: [...input.state.toolCalls.values()].map((toolCall) => ({
|
|
460
|
+
id: toolCall.toolCallId,
|
|
461
|
+
name: toolCall.toolName,
|
|
462
|
+
args: parseToolInputObject(toolCall.input),
|
|
463
|
+
status: toolCall.status,
|
|
464
|
+
...(toolCall.status === "completed" ? { result: toolCall.output } : {}),
|
|
465
|
+
...(toolCall.status === "error" && toolCall.errorText ? { error: toolCall.errorText } : {}),
|
|
466
|
+
})),
|
|
467
|
+
metadata: {},
|
|
468
|
+
status: "completed",
|
|
469
|
+
} satisfies AgentResponse;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export async function resolveForkStepResponse(input: {
|
|
473
|
+
responsePromise: Promise<AgentResponse>;
|
|
474
|
+
responseTimeoutMs: number;
|
|
475
|
+
abortSignal?: AbortSignal;
|
|
476
|
+
currentMessages: readonly AgentMessage[];
|
|
477
|
+
streamedStepState: StreamedStepState;
|
|
478
|
+
}): Promise<AgentResponse> {
|
|
479
|
+
const resolvedResponse = await resolveHostedChildPromiseWithTimeout(
|
|
480
|
+
input.responsePromise,
|
|
481
|
+
input.responseTimeoutMs,
|
|
482
|
+
);
|
|
483
|
+
|
|
484
|
+
if (resolvedResponse !== HOSTED_CHILD_STREAM_TIMEOUT_TOKEN) {
|
|
485
|
+
return resolvedResponse;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (input.abortSignal?.aborted) {
|
|
489
|
+
throw createFrameworkForkAbortError(input.abortSignal);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const fallbackState = hasFallbackStepContent(input.streamedStepState)
|
|
493
|
+
? input.streamedStepState
|
|
494
|
+
: buildRecoverablePriorWorkState(input.currentMessages);
|
|
495
|
+
|
|
496
|
+
if (!fallbackState) {
|
|
497
|
+
throw new Error("Framework fork stream ended without onFinish and without recoverable output.");
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return buildFallbackAgentResponse({
|
|
501
|
+
baseMessages: input.currentMessages,
|
|
502
|
+
state: fallbackState,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function warnForkRuntimeStream(
|
|
507
|
+
logger: ForkRuntimeStreamLogger | undefined,
|
|
508
|
+
message: string,
|
|
509
|
+
metadata: Record<string, unknown>,
|
|
510
|
+
): void {
|
|
511
|
+
logger?.warn(message, metadata);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export function buildRecoveredStepParts(
|
|
515
|
+
step: ForkRuntimeStep,
|
|
516
|
+
state: ForkRecoveredPartsState,
|
|
517
|
+
): Array<ForkToolCallPart | ForkToolResultPart> {
|
|
518
|
+
const recoveredParts: Array<ForkToolCallPart | ForkToolResultPart> = [];
|
|
519
|
+
|
|
520
|
+
for (const toolCall of step.toolCalls) {
|
|
521
|
+
if (state.emittedToolCallIds.has(toolCall.toolCallId)) {
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const streamedCall = state.toolCalls.get(toolCall.toolCallId);
|
|
526
|
+
warnForkRuntimeStream(state.logger, "Child fork recovered missing tool-call from final step", {
|
|
527
|
+
toolCallId: toolCall.toolCallId,
|
|
528
|
+
toolName: toolCall.toolName,
|
|
529
|
+
sawInputStart: streamedCall?.sawInputStart ?? false,
|
|
530
|
+
sawInputDelta: streamedCall?.sawInputDelta ?? false,
|
|
531
|
+
sawInputAvailable: streamedCall?.sawInputAvailable ?? false,
|
|
532
|
+
sawOutputAvailable: streamedCall?.sawOutputAvailable ?? false,
|
|
533
|
+
sawOutputError: streamedCall?.sawOutputError ?? false,
|
|
534
|
+
});
|
|
535
|
+
state.emittedToolCallIds.add(toolCall.toolCallId);
|
|
536
|
+
recoveredParts.push({
|
|
537
|
+
type: "tool-call",
|
|
538
|
+
toolCallId: toolCall.toolCallId,
|
|
539
|
+
toolName: toolCall.toolName,
|
|
540
|
+
input: toolCall.input,
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
for (const toolResult of step.toolResults) {
|
|
545
|
+
if (state.emittedToolResultIds.has(toolResult.toolCallId)) {
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const streamedCall = state.toolCalls.get(toolResult.toolCallId);
|
|
550
|
+
warnForkRuntimeStream(
|
|
551
|
+
state.logger,
|
|
552
|
+
"Child fork recovered missing tool-result from final step",
|
|
553
|
+
{
|
|
554
|
+
toolCallId: toolResult.toolCallId,
|
|
555
|
+
toolName: toolResult.toolName,
|
|
556
|
+
sawInputStart: streamedCall?.sawInputStart ?? false,
|
|
557
|
+
sawInputDelta: streamedCall?.sawInputDelta ?? false,
|
|
558
|
+
sawInputAvailable: streamedCall?.sawInputAvailable ?? false,
|
|
559
|
+
sawOutputAvailable: streamedCall?.sawOutputAvailable ?? false,
|
|
560
|
+
sawOutputError: streamedCall?.sawOutputError ?? false,
|
|
561
|
+
},
|
|
562
|
+
);
|
|
563
|
+
state.emittedToolResultIds.add(toolResult.toolCallId);
|
|
564
|
+
recoveredParts.push({
|
|
565
|
+
type: "tool-result",
|
|
566
|
+
toolCallId: toolResult.toolCallId,
|
|
567
|
+
toolName: toolResult.toolName,
|
|
568
|
+
input: toolResult.input,
|
|
569
|
+
output: toolResult.output,
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
return recoveredParts;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function isEmptyRecord(value: Record<string, unknown>): boolean {
|
|
577
|
+
return Object.keys(value).length === 0;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function getParsedStreamedToolInput(inputText: string): Record<string, unknown> | null {
|
|
581
|
+
const strippedInputText = stripLeadingEmptyObjectPlaceholder(inputText).trim();
|
|
582
|
+
const normalizedInputText = strippedInputText.startsWith('"')
|
|
583
|
+
? `{${strippedInputText}`
|
|
584
|
+
: strippedInputText;
|
|
585
|
+
if (normalizedInputText.length === 0) {
|
|
586
|
+
return {};
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const parsed = safeJsonParse(normalizedInputText);
|
|
590
|
+
if (!parsed.ok) {
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
return isRecord(parsed.value) ? Object.fromEntries(Object.entries(parsed.value)) : {};
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function buildToolCallPartIfNeeded(
|
|
598
|
+
toolCallId: string,
|
|
599
|
+
state: FrameworkStreamState,
|
|
600
|
+
): ForkToolCallPart[] {
|
|
601
|
+
const toolCall = state.toolCalls.get(toolCallId);
|
|
602
|
+
if (!toolCall || state.emittedToolCallIds.has(toolCallId)) {
|
|
603
|
+
return [];
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
state.emittedToolCallIds.add(toolCallId);
|
|
607
|
+
return [
|
|
608
|
+
{
|
|
609
|
+
type: "tool-call",
|
|
610
|
+
toolCallId,
|
|
611
|
+
toolName: toolCall.toolName,
|
|
612
|
+
input: toolCall.input,
|
|
613
|
+
},
|
|
614
|
+
];
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
export function createFrameworkStreamState(
|
|
618
|
+
input: { logger?: ForkRuntimeStreamLogger } = {},
|
|
619
|
+
): FrameworkStreamState {
|
|
620
|
+
return {
|
|
621
|
+
toolCalls: new Map(),
|
|
622
|
+
emittedToolCallIds: new Set(),
|
|
623
|
+
emittedToolResultIds: new Set(),
|
|
624
|
+
...(input.logger ? { logger: input.logger } : {}),
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
export function mapFrameworkEventToForkParts(
|
|
629
|
+
event: AgUiRuntimeStreamEvent,
|
|
630
|
+
state: FrameworkStreamState,
|
|
631
|
+
): ForkPart[] {
|
|
632
|
+
switch (event.type) {
|
|
633
|
+
case "reasoning-delta":
|
|
634
|
+
return typeof event.delta === "string"
|
|
635
|
+
? [{ type: "reasoning-delta", text: event.delta }]
|
|
636
|
+
: [];
|
|
637
|
+
|
|
638
|
+
case "text-delta":
|
|
639
|
+
return typeof event.delta === "string" ? [{ type: "text-delta", text: event.delta }] : [];
|
|
640
|
+
|
|
641
|
+
case "tool-input-start": {
|
|
642
|
+
const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
|
|
643
|
+
const toolName = typeof event.toolName === "string" ? event.toolName : null;
|
|
644
|
+
if (!toolCallId || !toolName) {
|
|
645
|
+
return [];
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
const existing = state.toolCalls.get(toolCallId);
|
|
649
|
+
state.toolCalls.set(toolCallId, {
|
|
650
|
+
toolName,
|
|
651
|
+
inputText: existing?.inputText ?? "",
|
|
652
|
+
input: existing?.input ?? {},
|
|
653
|
+
sawInputStart: true,
|
|
654
|
+
sawInputDelta: existing?.sawInputDelta ?? false,
|
|
655
|
+
sawInputAvailable: existing?.sawInputAvailable ?? false,
|
|
656
|
+
sawOutputAvailable: existing?.sawOutputAvailable ?? false,
|
|
657
|
+
sawOutputError: existing?.sawOutputError ?? false,
|
|
658
|
+
});
|
|
659
|
+
return [{ type: "tool-input-start", toolCallId, toolName }];
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
case "tool-input-delta": {
|
|
663
|
+
const inputToolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
|
|
664
|
+
const inputDelta = typeof event.inputTextDelta === "string" ? event.inputTextDelta : null;
|
|
665
|
+
if (!inputToolCallId || !inputDelta) {
|
|
666
|
+
return [];
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
const existing = state.toolCalls.get(inputToolCallId);
|
|
670
|
+
if (existing) {
|
|
671
|
+
existing.inputText = mergeToolInputDelta(existing.inputText, inputDelta);
|
|
672
|
+
existing.sawInputDelta = true;
|
|
673
|
+
const parsedInput = getParsedStreamedToolInput(existing.inputText);
|
|
674
|
+
if (parsedInput) {
|
|
675
|
+
existing.input = parsedInput;
|
|
676
|
+
}
|
|
677
|
+
} else {
|
|
678
|
+
warnForkRuntimeStream(
|
|
679
|
+
state.logger,
|
|
680
|
+
"Child fork received tool-input-delta before tool-input-start",
|
|
681
|
+
{
|
|
682
|
+
toolCallId: inputToolCallId,
|
|
683
|
+
deltaLength: inputDelta.length,
|
|
684
|
+
},
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
return [{ type: "tool-input-delta", toolCallId: inputToolCallId, delta: inputDelta }];
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
case "tool-input-available": {
|
|
692
|
+
const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
|
|
693
|
+
const toolName = typeof event.toolName === "string" ? event.toolName : null;
|
|
694
|
+
if (!toolCallId || !toolName) {
|
|
695
|
+
return [];
|
|
696
|
+
}
|
|
697
|
+
const input = parseToolInputObject(event.input);
|
|
698
|
+
const existing = state.toolCalls.get(toolCallId);
|
|
699
|
+
const resolvedInput = existing && isEmptyRecord(input) && !isEmptyRecord(existing.input)
|
|
700
|
+
? existing.input
|
|
701
|
+
: input;
|
|
702
|
+
state.toolCalls.set(toolCallId, {
|
|
703
|
+
toolName,
|
|
704
|
+
inputText: "",
|
|
705
|
+
input: resolvedInput,
|
|
706
|
+
sawInputStart: existing?.sawInputStart ?? false,
|
|
707
|
+
sawInputDelta: existing?.sawInputDelta ?? false,
|
|
708
|
+
sawInputAvailable: true,
|
|
709
|
+
sawOutputAvailable: existing?.sawOutputAvailable ?? false,
|
|
710
|
+
sawOutputError: existing?.sawOutputError ?? false,
|
|
711
|
+
});
|
|
712
|
+
return buildToolCallPartIfNeeded(toolCallId, state);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
case "tool-output-available": {
|
|
716
|
+
if (event.preliminary === true) {
|
|
717
|
+
return [];
|
|
718
|
+
}
|
|
719
|
+
const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
|
|
720
|
+
if (!toolCallId) {
|
|
721
|
+
return [];
|
|
722
|
+
}
|
|
723
|
+
const call = state.toolCalls.get(toolCallId);
|
|
724
|
+
if (!call) {
|
|
725
|
+
return [];
|
|
726
|
+
}
|
|
727
|
+
call.sawOutputAvailable = true;
|
|
728
|
+
const parts: Array<ForkToolCallPart | ForkToolResultPart> = [
|
|
729
|
+
...buildToolCallPartIfNeeded(toolCallId, state),
|
|
730
|
+
];
|
|
731
|
+
state.emittedToolResultIds.add(toolCallId);
|
|
732
|
+
parts.push({
|
|
733
|
+
type: "tool-result",
|
|
734
|
+
toolCallId,
|
|
735
|
+
toolName: call.toolName,
|
|
736
|
+
input: call.input,
|
|
737
|
+
output: Object.hasOwn(event, "output") ? event.output : null,
|
|
738
|
+
});
|
|
739
|
+
return parts;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
case "tool-output-error":
|
|
743
|
+
case "tool-input-error": {
|
|
744
|
+
const toolCallId = typeof event.toolCallId === "string" ? event.toolCallId : null;
|
|
745
|
+
if (!toolCallId) {
|
|
746
|
+
return [];
|
|
747
|
+
}
|
|
748
|
+
const call = state.toolCalls.get(toolCallId);
|
|
749
|
+
const errorText = typeof event.errorText === "string"
|
|
750
|
+
? event.errorText
|
|
751
|
+
: typeof event.error === "string"
|
|
752
|
+
? event.error
|
|
753
|
+
: "Tool execution failed";
|
|
754
|
+
if (call) {
|
|
755
|
+
call.sawOutputError = true;
|
|
756
|
+
}
|
|
757
|
+
const parts: Array<ForkToolCallPart | ForkToolErrorPart> = [
|
|
758
|
+
...buildToolCallPartIfNeeded(toolCallId, state),
|
|
759
|
+
];
|
|
760
|
+
parts.push({
|
|
761
|
+
type: "tool-error",
|
|
762
|
+
toolCallId,
|
|
763
|
+
toolName: call?.toolName ?? "unknown",
|
|
764
|
+
input: call?.input ?? {},
|
|
765
|
+
error: new Error(errorText),
|
|
766
|
+
});
|
|
767
|
+
return parts;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
case "error": {
|
|
771
|
+
const errorText = typeof event.errorText === "string"
|
|
772
|
+
? event.errorText
|
|
773
|
+
: "Framework stream failed";
|
|
774
|
+
return [{ type: "error", error: new Error(errorText) }];
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
default:
|
|
778
|
+
return [];
|
|
779
|
+
}
|
|
780
|
+
}
|