@tambo-ai/react 1.0.3 → 1.2.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/README.md +1 -1
- package/dist/context-helpers/current-interactables-context-helper.d.ts +16 -2
- package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
- package/dist/context-helpers/current-interactables-context-helper.js.map +1 -1
- package/dist/context-helpers/current-interactables-context-helper.test.d.ts +2 -0
- package/dist/context-helpers/current-interactables-context-helper.test.d.ts.map +1 -0
- package/dist/context-helpers/current-interactables-context-helper.test.js +70 -0
- package/dist/context-helpers/current-interactables-context-helper.test.js.map +1 -0
- package/dist/mcp/elicitation.d.ts +3 -37
- package/dist/mcp/elicitation.d.ts.map +1 -1
- package/dist/mcp/elicitation.js +7 -24
- package/dist/mcp/elicitation.js.map +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +2 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/mcp-client.test.js +17 -17
- package/dist/mcp/mcp-client.test.js.map +1 -1
- package/dist/mcp/mcp-hooks.d.ts.map +1 -1
- package/dist/mcp/mcp-hooks.js +8 -5
- package/dist/mcp/mcp-hooks.js.map +1 -1
- package/dist/mcp/mcp-hooks.test.js +30 -29
- package/dist/mcp/mcp-hooks.test.js.map +1 -1
- package/dist/mcp/tambo-mcp-provider.d.ts +6 -9
- package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js +9 -13
- package/dist/mcp/tambo-mcp-provider.js.map +1 -1
- package/dist/mcp/tambo-mcp-provider.test.js +26 -25
- package/dist/mcp/tambo-mcp-provider.test.js.map +1 -1
- package/dist/mcp/use-mcp-servers.test.js +2 -1
- package/dist/mcp/use-mcp-servers.test.js.map +1 -1
- package/dist/model/component-metadata.d.ts +7 -372
- package/dist/model/component-metadata.d.ts.map +1 -1
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/model/validate-input.test.d.ts +2 -0
- package/dist/model/validate-input.test.d.ts.map +1 -0
- package/dist/model/validate-input.test.js +38 -0
- package/dist/model/validate-input.test.js.map +1 -0
- package/dist/providers/tambo-interactable-provider.d.ts +7 -7
- package/dist/providers/tambo-registry-provider.d.ts +1 -1
- package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
- package/dist/providers/tambo-registry-provider.js.map +1 -1
- package/dist/providers/tambo-registry-schema-compat.test.js +4 -4
- package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/dist/schema/index.d.ts +2 -4
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +9 -11
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/json-schema.d.ts +1 -17
- package/dist/schema/json-schema.d.ts.map +1 -1
- package/dist/schema/json-schema.js +5 -69
- package/dist/schema/json-schema.js.map +1 -1
- package/dist/schema/schema.test.js +24 -25
- package/dist/schema/schema.test.js.map +1 -1
- package/dist/schema/standard-schema.test.js +25 -25
- package/dist/schema/standard-schema.test.js.map +1 -1
- package/dist/schema/validate.test.js +33 -33
- package/dist/schema/validate.test.js.map +1 -1
- package/dist/testing/tools.d.ts +4 -4
- package/dist/testing/tools.test.d.ts +2 -0
- package/dist/testing/tools.test.d.ts.map +1 -0
- package/dist/testing/tools.test.js +60 -0
- package/dist/testing/tools.test.js.map +1 -0
- package/dist/util/mcp-server-utils.d.ts +1 -1
- package/dist/util/mcp-server-utils.d.ts.map +1 -1
- package/dist/util/mcp-server-utils.js +4 -4
- package/dist/util/mcp-server-utils.js.map +1 -1
- package/dist/util/mcp-server-utils.test.js +27 -27
- package/dist/util/mcp-server-utils.test.js.map +1 -1
- package/dist/util/registry.js +1 -1
- package/dist/util/registry.js.map +1 -1
- package/dist/util/resource-content-resolver.js +5 -5
- package/dist/util/resource-content-resolver.js.map +1 -1
- package/dist/util/resource-content-resolver.test.js +6 -6
- package/dist/util/resource-content-resolver.test.js.map +1 -1
- package/dist/util/tool-caller.test.d.ts +2 -0
- package/dist/util/tool-caller.test.d.ts.map +1 -0
- package/dist/util/tool-caller.test.js +71 -0
- package/dist/util/tool-caller.test.js.map +1 -0
- package/dist/v1/__tests__/v1-interactables.test.js +1 -0
- package/dist/v1/__tests__/v1-interactables.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-auth-state.d.ts +1 -1
- package/dist/v1/hooks/use-tambo-v1-auth-state.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-auth-state.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-component-state.js +2 -2
- package/dist/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-component-state.test.js +1 -1
- package/dist/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.js +17 -17
- package/dist/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js +1 -1
- package/dist/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-stream-status.js +2 -2
- package/dist/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-stream-status.test.js +9 -5
- package/dist/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-suggestions.js +2 -2
- package/dist/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js +104 -0
- package/dist/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.d.ts +7 -6
- package/dist/v1/hooks/use-tambo-v1.d.ts.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.js +2 -2
- package/dist/v1/hooks/use-tambo-v1.js.map +1 -1
- package/dist/v1/hooks/use-tambo-v1.test.js +23 -23
- package/dist/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/dist/v1/index.d.ts +6 -6
- package/dist/v1/index.d.ts.map +1 -1
- package/dist/v1/index.js +2 -2
- package/dist/v1/index.js.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.d.ts +2 -1
- package/dist/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-provider.js +2 -0
- package/dist/v1/providers/tambo-v1-provider.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.d.ts +2 -2
- package/dist/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.js +9 -9
- package/dist/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stream-context.test.js +35 -0
- package/dist/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.js +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.js.map +1 -1
- package/dist/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts +1 -1
- package/dist/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
- package/dist/v1/providers/tambo-v1-thread-input-provider.js +33 -17
- package/dist/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
- package/dist/v1/types/event.test.js +13 -13
- package/dist/v1/types/event.test.js.map +1 -1
- package/dist/v1/types/message.d.ts +12 -109
- package/dist/v1/types/message.d.ts.map +1 -1
- package/dist/v1/types/message.js +0 -7
- package/dist/v1/types/message.js.map +1 -1
- package/dist/v1/utils/event-accumulator.test.js +183 -184
- package/dist/v1/utils/event-accumulator.test.js.map +1 -1
- package/dist/v1/utils/json-patch.test.js +4 -4
- package/dist/v1/utils/json-patch.test.js.map +1 -1
- package/dist/v1/utils/keyed-throttle.test.js +12 -12
- package/dist/v1/utils/keyed-throttle.test.js.map +1 -1
- package/dist/v1/utils/registry-conversion.test.js +13 -13
- package/dist/v1/utils/registry-conversion.test.js.map +1 -1
- package/dist/v1/utils/stream-handler.test.js +5 -5
- package/dist/v1/utils/stream-handler.test.js.map +1 -1
- package/dist/v1/utils/tool-call-tracker.test.js +15 -9
- package/dist/v1/utils/tool-call-tracker.test.js.map +1 -1
- package/dist/v1/utils/tool-executor.test.js +25 -26
- package/dist/v1/utils/tool-executor.test.js.map +1 -1
- package/dist/v1/utils/unstrictify.test.js +16 -16
- package/dist/v1/utils/unstrictify.test.js.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.d.ts +16 -2
- package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.test.d.ts +2 -0
- package/esm/context-helpers/current-interactables-context-helper.test.d.ts.map +1 -0
- package/esm/context-helpers/current-interactables-context-helper.test.js +68 -0
- package/esm/context-helpers/current-interactables-context-helper.test.js.map +1 -0
- package/esm/mcp/elicitation.d.ts +3 -37
- package/esm/mcp/elicitation.d.ts.map +1 -1
- package/esm/mcp/elicitation.js +4 -24
- package/esm/mcp/elicitation.js.map +1 -1
- package/esm/mcp/index.d.ts +4 -4
- package/esm/mcp/index.d.ts.map +1 -1
- package/esm/mcp/index.js +1 -1
- package/esm/mcp/index.js.map +1 -1
- package/esm/mcp/mcp-client.test.js +1 -1
- package/esm/mcp/mcp-client.test.js.map +1 -1
- package/esm/mcp/mcp-hooks.d.ts.map +1 -1
- package/esm/mcp/mcp-hooks.js +4 -1
- package/esm/mcp/mcp-hooks.js.map +1 -1
- package/esm/mcp/mcp-hooks.test.js +3 -2
- package/esm/mcp/mcp-hooks.test.js.map +1 -1
- package/esm/mcp/tambo-mcp-provider.d.ts +6 -9
- package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js +4 -8
- package/esm/mcp/tambo-mcp-provider.js.map +1 -1
- package/esm/mcp/tambo-mcp-provider.test.js +3 -2
- package/esm/mcp/tambo-mcp-provider.test.js.map +1 -1
- package/esm/mcp/use-mcp-servers.test.js +2 -1
- package/esm/mcp/use-mcp-servers.test.js.map +1 -1
- package/esm/model/component-metadata.d.ts +7 -372
- package/esm/model/component-metadata.d.ts.map +1 -1
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/model/validate-input.test.d.ts +2 -0
- package/esm/model/validate-input.test.d.ts.map +1 -0
- package/esm/model/validate-input.test.js +36 -0
- package/esm/model/validate-input.test.js.map +1 -0
- package/esm/providers/tambo-interactable-provider.d.ts +7 -7
- package/esm/providers/tambo-registry-provider.d.ts +1 -1
- package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
- package/esm/providers/tambo-registry-provider.js.map +1 -1
- package/esm/providers/tambo-registry-schema-compat.test.js +4 -4
- package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/esm/schema/index.d.ts +2 -4
- package/esm/schema/index.d.ts.map +1 -1
- package/esm/schema/index.js +2 -4
- package/esm/schema/index.js.map +1 -1
- package/esm/schema/json-schema.d.ts +1 -17
- package/esm/schema/json-schema.d.ts.map +1 -1
- package/esm/schema/json-schema.js +2 -67
- package/esm/schema/json-schema.js.map +1 -1
- package/esm/schema/schema.test.js +1 -2
- package/esm/schema/schema.test.js.map +1 -1
- package/esm/schema/standard-schema.test.js +1 -1
- package/esm/schema/standard-schema.test.js.map +1 -1
- package/esm/schema/validate.test.js +1 -1
- package/esm/schema/validate.test.js.map +1 -1
- package/esm/testing/tools.d.ts +4 -4
- package/esm/testing/tools.test.d.ts +2 -0
- package/esm/testing/tools.test.d.ts.map +1 -0
- package/esm/testing/tools.test.js +58 -0
- package/esm/testing/tools.test.js.map +1 -0
- package/esm/util/mcp-server-utils.d.ts +1 -1
- package/esm/util/mcp-server-utils.d.ts.map +1 -1
- package/esm/util/mcp-server-utils.js +1 -1
- package/esm/util/mcp-server-utils.js.map +1 -1
- package/esm/util/mcp-server-utils.test.js +1 -1
- package/esm/util/mcp-server-utils.test.js.map +1 -1
- package/esm/util/registry.js +1 -1
- package/esm/util/registry.js.map +1 -1
- package/esm/util/resource-content-resolver.js +1 -1
- package/esm/util/resource-content-resolver.js.map +1 -1
- package/esm/util/resource-content-resolver.test.js +2 -2
- package/esm/util/resource-content-resolver.test.js.map +1 -1
- package/esm/util/tool-caller.test.d.ts +2 -0
- package/esm/util/tool-caller.test.d.ts.map +1 -0
- package/esm/util/tool-caller.test.js +69 -0
- package/esm/util/tool-caller.test.js.map +1 -0
- package/esm/v1/__tests__/v1-interactables.test.js +1 -0
- package/esm/v1/__tests__/v1-interactables.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-auth-state.d.ts +1 -1
- package/esm/v1/hooks/use-tambo-v1-auth-state.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-auth-state.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-component-state.js +1 -1
- package/esm/v1/hooks/use-tambo-v1-component-state.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-component-state.test.js +1 -1
- package/esm/v1/hooks/use-tambo-v1-component-state.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.js +6 -6
- package/esm/v1/hooks/use-tambo-v1-send-message.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js +1 -1
- package/esm/v1/hooks/use-tambo-v1-send-message.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-stream-status.js +1 -1
- package/esm/v1/hooks/use-tambo-v1-stream-status.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-stream-status.test.js +9 -5
- package/esm/v1/hooks/use-tambo-v1-stream-status.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.js +1 -1
- package/esm/v1/hooks/use-tambo-v1-suggestions.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js +104 -0
- package/esm/v1/hooks/use-tambo-v1-thread-input.test.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.d.ts +7 -6
- package/esm/v1/hooks/use-tambo-v1.d.ts.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.js +1 -1
- package/esm/v1/hooks/use-tambo-v1.js.map +1 -1
- package/esm/v1/hooks/use-tambo-v1.test.js +22 -22
- package/esm/v1/hooks/use-tambo-v1.test.js.map +1 -1
- package/esm/v1/index.d.ts +6 -6
- package/esm/v1/index.d.ts.map +1 -1
- package/esm/v1/index.js +1 -1
- package/esm/v1/index.js.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.d.ts +2 -1
- package/esm/v1/providers/tambo-v1-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-provider.js +2 -0
- package/esm/v1/providers/tambo-v1-provider.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.d.ts +2 -2
- package/esm/v1/providers/tambo-v1-stream-context.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.js +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stream-context.test.js +35 -0
- package/esm/v1/providers/tambo-v1-stream-context.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.js +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.js.map +1 -1
- package/esm/v1/providers/tambo-v1-stub-provider.test.js.map +1 -1
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts +1 -1
- package/esm/v1/providers/tambo-v1-thread-input-provider.d.ts.map +1 -1
- package/esm/v1/providers/tambo-v1-thread-input-provider.js +32 -16
- package/esm/v1/providers/tambo-v1-thread-input-provider.js.map +1 -1
- package/esm/v1/types/event.test.js +1 -1
- package/esm/v1/types/event.test.js.map +1 -1
- package/esm/v1/types/message.d.ts +12 -109
- package/esm/v1/types/message.d.ts.map +1 -1
- package/esm/v1/types/message.js +0 -7
- package/esm/v1/types/message.js.map +1 -1
- package/esm/v1/utils/event-accumulator.test.js +2 -3
- package/esm/v1/utils/event-accumulator.test.js.map +1 -1
- package/esm/v1/utils/json-patch.test.js +1 -1
- package/esm/v1/utils/json-patch.test.js.map +1 -1
- package/esm/v1/utils/keyed-throttle.test.js +1 -1
- package/esm/v1/utils/keyed-throttle.test.js.map +1 -1
- package/esm/v1/utils/registry-conversion.test.js +1 -1
- package/esm/v1/utils/registry-conversion.test.js.map +1 -1
- package/esm/v1/utils/stream-handler.test.js +1 -1
- package/esm/v1/utils/stream-handler.test.js.map +1 -1
- package/esm/v1/utils/tool-call-tracker.test.js +9 -3
- package/esm/v1/utils/tool-call-tracker.test.js.map +1 -1
- package/esm/v1/utils/tool-executor.test.js +1 -2
- package/esm/v1/utils/tool-executor.test.js.map +1 -1
- package/esm/v1/utils/unstrictify.test.js +1 -1
- package/esm/v1/utils/unstrictify.test.js.map +1 -1
- package/package.json +12 -15
- package/dist/mcp/mcp-client.d.ts +0 -185
- package/dist/mcp/mcp-client.d.ts.map +0 -1
- package/dist/mcp/mcp-client.js +0 -219
- package/dist/mcp/mcp-client.js.map +0 -1
- package/dist/mcp/mcp-constants.d.ts +0 -19
- package/dist/mcp/mcp-constants.d.ts.map +0 -1
- package/dist/mcp/mcp-constants.js +0 -21
- package/dist/mcp/mcp-constants.js.map +0 -1
- package/dist/model/mcp-server-info.d.ts +0 -76
- package/dist/model/mcp-server-info.d.ts.map +0 -1
- package/dist/model/mcp-server-info.js +0 -29
- package/dist/model/mcp-server-info.js.map +0 -1
- package/dist/schema/schema.d.ts +0 -49
- package/dist/schema/schema.d.ts.map +0 -1
- package/dist/schema/schema.js +0 -129
- package/dist/schema/schema.js.map +0 -1
- package/dist/schema/standard-schema.d.ts +0 -22
- package/dist/schema/standard-schema.d.ts.map +0 -1
- package/dist/schema/standard-schema.js +0 -42
- package/dist/schema/standard-schema.js.map +0 -1
- package/dist/schema/validate.d.ts +0 -14
- package/dist/schema/validate.d.ts.map +0 -1
- package/dist/schema/validate.js +0 -148
- package/dist/schema/validate.js.map +0 -1
- package/dist/v1/types/auth.d.ts +0 -24
- package/dist/v1/types/auth.d.ts.map +0 -1
- package/dist/v1/types/auth.js +0 -3
- package/dist/v1/types/auth.js.map +0 -1
- package/dist/v1/types/event.d.ts +0 -89
- package/dist/v1/types/event.d.ts.map +0 -1
- package/dist/v1/types/event.js +0 -57
- package/dist/v1/types/event.js.map +0 -1
- package/dist/v1/types/thread.d.ts +0 -58
- package/dist/v1/types/thread.d.ts.map +0 -1
- package/dist/v1/types/thread.js +0 -9
- package/dist/v1/types/thread.js.map +0 -1
- package/dist/v1/types/tool-choice.d.ts +0 -8
- package/dist/v1/types/tool-choice.d.ts.map +0 -1
- package/dist/v1/types/tool-choice.js +0 -3
- package/dist/v1/types/tool-choice.js.map +0 -1
- package/dist/v1/utils/event-accumulator.d.ts +0 -165
- package/dist/v1/utils/event-accumulator.d.ts.map +0 -1
- package/dist/v1/utils/event-accumulator.js +0 -1277
- package/dist/v1/utils/event-accumulator.js.map +0 -1
- package/dist/v1/utils/json-patch.d.ts +0 -18
- package/dist/v1/utils/json-patch.d.ts.map +0 -1
- package/dist/v1/utils/json-patch.js +0 -35
- package/dist/v1/utils/json-patch.js.map +0 -1
- package/dist/v1/utils/keyed-throttle.d.ts +0 -42
- package/dist/v1/utils/keyed-throttle.d.ts.map +0 -1
- package/dist/v1/utils/keyed-throttle.js +0 -86
- package/dist/v1/utils/keyed-throttle.js.map +0 -1
- package/dist/v1/utils/registry-conversion.d.ts +0 -53
- package/dist/v1/utils/registry-conversion.d.ts.map +0 -1
- package/dist/v1/utils/registry-conversion.js +0 -115
- package/dist/v1/utils/registry-conversion.js.map +0 -1
- package/dist/v1/utils/stream-handler.d.ts +0 -45
- package/dist/v1/utils/stream-handler.d.ts.map +0 -1
- package/dist/v1/utils/stream-handler.js +0 -47
- package/dist/v1/utils/stream-handler.js.map +0 -1
- package/dist/v1/utils/thread-utils.d.ts +0 -16
- package/dist/v1/utils/thread-utils.d.ts.map +0 -1
- package/dist/v1/utils/thread-utils.js +0 -34
- package/dist/v1/utils/thread-utils.js.map +0 -1
- package/dist/v1/utils/tool-call-tracker.d.ts +0 -73
- package/dist/v1/utils/tool-call-tracker.d.ts.map +0 -1
- package/dist/v1/utils/tool-call-tracker.js +0 -180
- package/dist/v1/utils/tool-call-tracker.js.map +0 -1
- package/dist/v1/utils/tool-executor.d.ts +0 -67
- package/dist/v1/utils/tool-executor.d.ts.map +0 -1
- package/dist/v1/utils/tool-executor.js +0 -160
- package/dist/v1/utils/tool-executor.js.map +0 -1
- package/dist/v1/utils/unstrictify.d.ts +0 -32
- package/dist/v1/utils/unstrictify.d.ts.map +0 -1
- package/dist/v1/utils/unstrictify.js +0 -159
- package/dist/v1/utils/unstrictify.js.map +0 -1
- package/esm/mcp/mcp-client.d.ts +0 -185
- package/esm/mcp/mcp-client.d.ts.map +0 -1
- package/esm/mcp/mcp-client.js +0 -216
- package/esm/mcp/mcp-client.js.map +0 -1
- package/esm/mcp/mcp-constants.d.ts +0 -19
- package/esm/mcp/mcp-constants.d.ts.map +0 -1
- package/esm/mcp/mcp-constants.js +0 -18
- package/esm/mcp/mcp-constants.js.map +0 -1
- package/esm/model/mcp-server-info.d.ts +0 -76
- package/esm/model/mcp-server-info.d.ts.map +0 -1
- package/esm/model/mcp-server-info.js +0 -25
- package/esm/model/mcp-server-info.js.map +0 -1
- package/esm/schema/schema.d.ts +0 -49
- package/esm/schema/schema.d.ts.map +0 -1
- package/esm/schema/schema.js +0 -124
- package/esm/schema/schema.js.map +0 -1
- package/esm/schema/standard-schema.d.ts +0 -22
- package/esm/schema/standard-schema.d.ts.map +0 -1
- package/esm/schema/standard-schema.js +0 -39
- package/esm/schema/standard-schema.js.map +0 -1
- package/esm/schema/validate.d.ts +0 -14
- package/esm/schema/validate.d.ts.map +0 -1
- package/esm/schema/validate.js +0 -145
- package/esm/schema/validate.js.map +0 -1
- package/esm/v1/types/auth.d.ts +0 -24
- package/esm/v1/types/auth.d.ts.map +0 -1
- package/esm/v1/types/auth.js +0 -2
- package/esm/v1/types/auth.js.map +0 -1
- package/esm/v1/types/event.d.ts +0 -89
- package/esm/v1/types/event.d.ts.map +0 -1
- package/esm/v1/types/event.js +0 -53
- package/esm/v1/types/event.js.map +0 -1
- package/esm/v1/types/thread.d.ts +0 -58
- package/esm/v1/types/thread.d.ts.map +0 -1
- package/esm/v1/types/thread.js +0 -8
- package/esm/v1/types/thread.js.map +0 -1
- package/esm/v1/types/tool-choice.d.ts +0 -8
- package/esm/v1/types/tool-choice.d.ts.map +0 -1
- package/esm/v1/types/tool-choice.js +0 -2
- package/esm/v1/types/tool-choice.js.map +0 -1
- package/esm/v1/utils/event-accumulator.d.ts +0 -165
- package/esm/v1/utils/event-accumulator.d.ts.map +0 -1
- package/esm/v1/utils/event-accumulator.js +0 -1268
- package/esm/v1/utils/event-accumulator.js.map +0 -1
- package/esm/v1/utils/json-patch.d.ts +0 -18
- package/esm/v1/utils/json-patch.d.ts.map +0 -1
- package/esm/v1/utils/json-patch.js +0 -32
- package/esm/v1/utils/json-patch.js.map +0 -1
- package/esm/v1/utils/keyed-throttle.d.ts +0 -42
- package/esm/v1/utils/keyed-throttle.d.ts.map +0 -1
- package/esm/v1/utils/keyed-throttle.js +0 -83
- package/esm/v1/utils/keyed-throttle.js.map +0 -1
- package/esm/v1/utils/registry-conversion.d.ts +0 -53
- package/esm/v1/utils/registry-conversion.d.ts.map +0 -1
- package/esm/v1/utils/registry-conversion.js +0 -109
- package/esm/v1/utils/registry-conversion.js.map +0 -1
- package/esm/v1/utils/stream-handler.d.ts +0 -45
- package/esm/v1/utils/stream-handler.d.ts.map +0 -1
- package/esm/v1/utils/stream-handler.js +0 -44
- package/esm/v1/utils/stream-handler.js.map +0 -1
- package/esm/v1/utils/thread-utils.d.ts +0 -16
- package/esm/v1/utils/thread-utils.d.ts.map +0 -1
- package/esm/v1/utils/thread-utils.js +0 -31
- package/esm/v1/utils/thread-utils.js.map +0 -1
- package/esm/v1/utils/tool-call-tracker.d.ts +0 -73
- package/esm/v1/utils/tool-call-tracker.d.ts.map +0 -1
- package/esm/v1/utils/tool-call-tracker.js +0 -176
- package/esm/v1/utils/tool-call-tracker.js.map +0 -1
- package/esm/v1/utils/tool-executor.d.ts +0 -67
- package/esm/v1/utils/tool-executor.d.ts.map +0 -1
- package/esm/v1/utils/tool-executor.js +0 -154
- package/esm/v1/utils/tool-executor.js.map +0 -1
- package/esm/v1/utils/unstrictify.d.ts +0 -32
- package/esm/v1/utils/unstrictify.d.ts.map +0 -1
- package/esm/v1/utils/unstrictify.js +0 -155
- package/esm/v1/utils/unstrictify.js.map +0 -1
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stream Handler for Streaming API
|
|
3
|
-
*
|
|
4
|
-
* Provides utilities for handling event streams from the TypeScript SDK.
|
|
5
|
-
* The SDK's client.threads.runs.run() already returns an async iterable,
|
|
6
|
-
* so this module just adds optional debug logging.
|
|
7
|
-
*/
|
|
8
|
-
import type { AGUIEvent } from "@ag-ui/core";
|
|
9
|
-
/**
|
|
10
|
-
* Options for stream handling.
|
|
11
|
-
*/
|
|
12
|
-
export interface StreamHandlerOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Enable debug logging (development mode only).
|
|
15
|
-
* Logs all events to console.
|
|
16
|
-
*/
|
|
17
|
-
debug?: boolean;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Handle an event stream from the TypeScript SDK and yield AG-UI event types.
|
|
21
|
-
*
|
|
22
|
-
* The TypeScript SDK's client.threads.runs.run() and client.threads.runs.create()
|
|
23
|
-
* return async iterables that yield events compatible with AG-UI's AGUIEvent.
|
|
24
|
-
* This function wraps the stream to add optional debug logging and ensures
|
|
25
|
-
* proper typing.
|
|
26
|
-
*
|
|
27
|
-
* Note: SDK events have `type: string` rather than `type: EventType` enum,
|
|
28
|
-
* but the values are compatible with AG-UI event types.
|
|
29
|
-
* @param stream - Async iterable of events from SDK
|
|
30
|
-
* @param options - Optional configuration for stream handling
|
|
31
|
-
* @yields {AGUIEvent} AG-UI event types from the stream
|
|
32
|
-
* @returns Async iterable of AG-UI event types
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* const stream = await client.threads.runs.run(threadId, {
|
|
36
|
-
* message: { role: "user", content: [{ type: "text", text: "hello" }] },
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* for await (const event of handleEventStream(stream, { debug: true })) {
|
|
40
|
-
* dispatch({ type: 'EVENT', event }); // Send to reducer
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function handleEventStream(stream: AsyncIterable<unknown>, options?: StreamHandlerOptions): AsyncIterable<AGUIEvent>;
|
|
45
|
-
//# sourceMappingURL=stream-handler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream-handler.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/stream-handler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAuB,iBAAiB,CACtC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,aAAa,CAAC,SAAS,CAAC,CAY1B"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stream Handler for Streaming API
|
|
3
|
-
*
|
|
4
|
-
* Provides utilities for handling event streams from the TypeScript SDK.
|
|
5
|
-
* The SDK's client.threads.runs.run() already returns an async iterable,
|
|
6
|
-
* so this module just adds optional debug logging.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Handle an event stream from the TypeScript SDK and yield AG-UI event types.
|
|
10
|
-
*
|
|
11
|
-
* The TypeScript SDK's client.threads.runs.run() and client.threads.runs.create()
|
|
12
|
-
* return async iterables that yield events compatible with AG-UI's AGUIEvent.
|
|
13
|
-
* This function wraps the stream to add optional debug logging and ensures
|
|
14
|
-
* proper typing.
|
|
15
|
-
*
|
|
16
|
-
* Note: SDK events have `type: string` rather than `type: EventType` enum,
|
|
17
|
-
* but the values are compatible with AG-UI event types.
|
|
18
|
-
* @param stream - Async iterable of events from SDK
|
|
19
|
-
* @param options - Optional configuration for stream handling
|
|
20
|
-
* @yields {AGUIEvent} AG-UI event types from the stream
|
|
21
|
-
* @returns Async iterable of AG-UI event types
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const stream = await client.threads.runs.run(threadId, {
|
|
25
|
-
* message: { role: "user", content: [{ type: "text", text: "hello" }] },
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* for await (const event of handleEventStream(stream, { debug: true })) {
|
|
29
|
-
* dispatch({ type: 'EVENT', event }); // Send to reducer
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export async function* handleEventStream(stream, options) {
|
|
34
|
-
const { debug = false } = options ?? {};
|
|
35
|
-
for await (const event of stream) {
|
|
36
|
-
if (debug && process.env.NODE_ENV !== "production") {
|
|
37
|
-
// eslint-disable-next-line no-console
|
|
38
|
-
console.log("[StreamHandler] Event:", event);
|
|
39
|
-
}
|
|
40
|
-
// SDK events are compatible with AG-UI AGUIEvent discriminated union
|
|
41
|
-
yield event;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=stream-handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream-handler.js","sourceRoot":"","sources":["../../../src/v1/utils/stream-handler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAeH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,iBAAiB,CACtC,MAA8B,EAC9B,OAA8B;IAE9B,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAExC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACjC,IAAI,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YACnD,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;QAC/C,CAAC;QAED,qEAAqE;QACrE,MAAM,KAAkB,CAAC;IAC3B,CAAC;AACH,CAAC","sourcesContent":["/**\n * Stream Handler for Streaming API\n *\n * Provides utilities for handling event streams from the TypeScript SDK.\n * The SDK's client.threads.runs.run() already returns an async iterable,\n * so this module just adds optional debug logging.\n */\n\nimport type { AGUIEvent } from \"@ag-ui/core\";\n\n/**\n * Options for stream handling.\n */\nexport interface StreamHandlerOptions {\n /**\n * Enable debug logging (development mode only).\n * Logs all events to console.\n */\n debug?: boolean;\n}\n\n/**\n * Handle an event stream from the TypeScript SDK and yield AG-UI event types.\n *\n * The TypeScript SDK's client.threads.runs.run() and client.threads.runs.create()\n * return async iterables that yield events compatible with AG-UI's AGUIEvent.\n * This function wraps the stream to add optional debug logging and ensures\n * proper typing.\n *\n * Note: SDK events have `type: string` rather than `type: EventType` enum,\n * but the values are compatible with AG-UI event types.\n * @param stream - Async iterable of events from SDK\n * @param options - Optional configuration for stream handling\n * @yields {AGUIEvent} AG-UI event types from the stream\n * @returns Async iterable of AG-UI event types\n * @example\n * ```typescript\n * const stream = await client.threads.runs.run(threadId, {\n * message: { role: \"user\", content: [{ type: \"text\", text: \"hello\" }] },\n * });\n *\n * for await (const event of handleEventStream(stream, { debug: true })) {\n * dispatch({ type: 'EVENT', event }); // Send to reducer\n * }\n * ```\n */\nexport async function* handleEventStream(\n stream: AsyncIterable<unknown>,\n options?: StreamHandlerOptions,\n): AsyncIterable<AGUIEvent> {\n const { debug = false } = options ?? {};\n\n for await (const event of stream) {\n if (debug && process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.log(\"[StreamHandler] Event:\", event);\n }\n\n // SDK events are compatible with AG-UI AGUIEvent discriminated union\n yield event as AGUIEvent;\n }\n}\n"]}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thread utility functions for searching and accessing thread content.
|
|
3
|
-
*/
|
|
4
|
-
import type { StreamState } from "./event-accumulator.js";
|
|
5
|
-
import type { TamboComponentContent } from "../types/message.js";
|
|
6
|
-
/**
|
|
7
|
-
* Find a component content block by ID in a specific thread.
|
|
8
|
-
* Searches from most recent messages first since active components are likely near the tail.
|
|
9
|
-
* Only searches the specified thread to prevent cross-thread data access.
|
|
10
|
-
* @param streamState - The current stream state containing thread data
|
|
11
|
-
* @param threadId - The thread ID to search in
|
|
12
|
-
* @param componentId - The component ID to find
|
|
13
|
-
* @returns The component content block, or undefined if not found
|
|
14
|
-
*/
|
|
15
|
-
export declare function findComponentContent(streamState: StreamState, threadId: string, componentId: string): TamboComponentContent | undefined;
|
|
16
|
-
//# sourceMappingURL=thread-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"thread-utils.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/thread-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,qBAAqB,GAAG,SAAS,CAkBnC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thread utility functions for searching and accessing thread content.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Find a component content block by ID in a specific thread.
|
|
6
|
-
* Searches from most recent messages first since active components are likely near the tail.
|
|
7
|
-
* Only searches the specified thread to prevent cross-thread data access.
|
|
8
|
-
* @param streamState - The current stream state containing thread data
|
|
9
|
-
* @param threadId - The thread ID to search in
|
|
10
|
-
* @param componentId - The component ID to find
|
|
11
|
-
* @returns The component content block, or undefined if not found
|
|
12
|
-
*/
|
|
13
|
-
export function findComponentContent(streamState, threadId, componentId) {
|
|
14
|
-
const threadState = streamState.threadMap[threadId];
|
|
15
|
-
if (!threadState) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
// Search from most recent messages first for better performance
|
|
19
|
-
const messages = threadState.thread.messages;
|
|
20
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
21
|
-
const content = messages[i].content;
|
|
22
|
-
for (let j = content.length - 1; j >= 0; j--) {
|
|
23
|
-
const block = content[j];
|
|
24
|
-
if (block.type === "component" && block.id === componentId) {
|
|
25
|
-
return block;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=thread-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"thread-utils.js","sourceRoot":"","sources":["../../../src/v1/utils/thread-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,WAAwB,EACxB,QAAgB,EAChB,WAAmB;IAEnB,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACpD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,gEAAgE;IAChE,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;IAC7C,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACpC,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YACzB,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,EAAE,KAAK,WAAW,EAAE,CAAC;gBAC3D,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Thread utility functions for searching and accessing thread content.\n */\n\nimport type { StreamState } from \"./event-accumulator\";\nimport type { TamboComponentContent } from \"../types/message\";\n\n/**\n * Find a component content block by ID in a specific thread.\n * Searches from most recent messages first since active components are likely near the tail.\n * Only searches the specified thread to prevent cross-thread data access.\n * @param streamState - The current stream state containing thread data\n * @param threadId - The thread ID to search in\n * @param componentId - The component ID to find\n * @returns The component content block, or undefined if not found\n */\nexport function findComponentContent(\n streamState: StreamState,\n threadId: string,\n componentId: string,\n): TamboComponentContent | undefined {\n const threadState = streamState.threadMap[threadId];\n if (!threadState) {\n return undefined;\n }\n\n // Search from most recent messages first for better performance\n const messages = threadState.thread.messages;\n for (let i = messages.length - 1; i >= 0; i--) {\n const content = messages[i].content;\n for (let j = content.length - 1; j >= 0; j--) {\n const block = content[j];\n if (block.type === \"component\" && block.id === componentId) {\n return block;\n }\n }\n }\n return undefined;\n}\n"]}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Call Tracker
|
|
3
|
-
*
|
|
4
|
-
* Tracks tool calls during streaming, accumulating arguments until complete.
|
|
5
|
-
* Owns the tool name → JSON Schema mapping and handles unstrictification
|
|
6
|
-
* so callers don't need to know about schema conversion.
|
|
7
|
-
*/
|
|
8
|
-
import { type AGUIEvent } from "@ag-ui/core";
|
|
9
|
-
import type { JSONSchema7 } from "json-schema";
|
|
10
|
-
import type { TamboTool } from "../../model/component-metadata.js";
|
|
11
|
-
import type { PendingToolCall } from "./tool-executor.js";
|
|
12
|
-
/**
|
|
13
|
-
* Tracks tool calls during streaming, accumulating arguments until complete.
|
|
14
|
-
*
|
|
15
|
-
* Tool calls arrive as a sequence of events:
|
|
16
|
-
* 1. TOOL_CALL_START - initializes the tool call with name
|
|
17
|
-
* 2. TOOL_CALL_ARGS (multiple) - streams JSON argument fragments
|
|
18
|
-
* 3. TOOL_CALL_END - marks the tool call as complete, triggers JSON parsing
|
|
19
|
-
*
|
|
20
|
-
* When constructed with a tool registry, the tracker unstrictifies parsed
|
|
21
|
-
* args (both partial and final) using the original JSON Schemas.
|
|
22
|
-
*/
|
|
23
|
-
export declare class ToolCallTracker {
|
|
24
|
-
private pendingToolCalls;
|
|
25
|
-
private accumulatingArgs;
|
|
26
|
-
private _toolSchemas;
|
|
27
|
-
constructor(toolRegistry?: Record<string, TamboTool>);
|
|
28
|
-
/**
|
|
29
|
-
* The tool-name → JSONSchema7 map, for passing to the reducer.
|
|
30
|
-
* @returns The tool schemas map
|
|
31
|
-
*/
|
|
32
|
-
get toolSchemas(): Map<string, JSONSchema7>;
|
|
33
|
-
/**
|
|
34
|
-
* Handles a streaming event, tracking tool call state as needed.
|
|
35
|
-
* @param event - The streaming event to process
|
|
36
|
-
* @throws {Error} If JSON parsing fails on TOOL_CALL_END (fail-fast, no silent fallback)
|
|
37
|
-
*/
|
|
38
|
-
handleEvent(event: AGUIEvent): void;
|
|
39
|
-
/**
|
|
40
|
-
* Parses partial JSON from the accumulated args for a tool call and
|
|
41
|
-
* unstrictifies the result. Used during streaming to get the current
|
|
42
|
-
* best-effort parsed args.
|
|
43
|
-
* @param toolCallId - ID of the tool call to parse
|
|
44
|
-
* @returns Parsed and unstrictified args, or undefined if not parseable yet
|
|
45
|
-
*/
|
|
46
|
-
parsePartialArgs(toolCallId: string): Record<string, unknown> | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* Gets the name and accumulated args for a tool call that is still accumulating.
|
|
49
|
-
* @param toolCallId - ID of the tool call to look up
|
|
50
|
-
* @returns The tool name and raw accumulated args string, or undefined if not found
|
|
51
|
-
*/
|
|
52
|
-
getAccumulatingToolCall(toolCallId: string): {
|
|
53
|
-
name: string;
|
|
54
|
-
accumulatedArgs: string;
|
|
55
|
-
} | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Gets tool calls for the given IDs, filtered to only those that exist.
|
|
58
|
-
* @param toolCallIds - IDs of tool calls to retrieve
|
|
59
|
-
* @returns Map of tool call ID to pending tool call
|
|
60
|
-
*/
|
|
61
|
-
getToolCallsById(toolCallIds: string[]): Map<string, PendingToolCall>;
|
|
62
|
-
/**
|
|
63
|
-
* Clears tracked tool calls for the given IDs.
|
|
64
|
-
* @param toolCallIds - IDs of tool calls to clear
|
|
65
|
-
*/
|
|
66
|
-
clearToolCalls(toolCallIds: string[]): void;
|
|
67
|
-
/**
|
|
68
|
-
* Unstrictify params using the schema for the given tool name.
|
|
69
|
-
* Returns params unchanged if no schema is available.
|
|
70
|
-
*/
|
|
71
|
-
private unstrictify;
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=tool-call-tracker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-call-tracker.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/tool-call-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AA4BvD;;;;;;;;;;GAUG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,gBAAgB,CAAsC;IAC9D,OAAO,CAAC,gBAAgB,CAA6B;IACrD,OAAO,CAAC,YAAY,CAA2B;gBAEnC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAMpD;;;OAGG;IACH,IAAI,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAE1C;IAED;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IA6CnC;;;;;;OAMG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAsBzE;;;;OAIG;IACH,uBAAuB,CACrB,UAAU,EAAE,MAAM,GACjB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;IAOxD;;;;OAIG;IACH,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC;IAWrE;;;OAGG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI;IAO3C;;;OAGG;IACH,OAAO,CAAC,WAAW;CAQpB"}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Call Tracker
|
|
3
|
-
*
|
|
4
|
-
* Tracks tool calls during streaming, accumulating arguments until complete.
|
|
5
|
-
* Owns the tool name → JSON Schema mapping and handles unstrictification
|
|
6
|
-
* so callers don't need to know about schema conversion.
|
|
7
|
-
*/
|
|
8
|
-
import { EventType } from "@ag-ui/core";
|
|
9
|
-
import { parse as parsePartialJson } from "partial-json";
|
|
10
|
-
import { schemaToJsonSchema } from "../../schema/schema.js";
|
|
11
|
-
import { unstrictifyToolCallParamsFromSchema } from "./unstrictify.js";
|
|
12
|
-
/**
|
|
13
|
-
* Build a tool-name → JSONSchema7 map from the tool registry.
|
|
14
|
-
* Handles both modern `inputSchema` and deprecated `toolSchema` formats.
|
|
15
|
-
* Tools whose schema can't be converted are silently skipped.
|
|
16
|
-
* @param toolRegistry - Record of tool name → tool definition
|
|
17
|
-
* @returns Map of tool name → JSON Schema
|
|
18
|
-
*/
|
|
19
|
-
function buildToolSchemas(toolRegistry) {
|
|
20
|
-
const schemas = new Map();
|
|
21
|
-
for (const tool of Object.values(toolRegistry)) {
|
|
22
|
-
try {
|
|
23
|
-
if ("inputSchema" in tool && tool.inputSchema) {
|
|
24
|
-
schemas.set(tool.name, schemaToJsonSchema(tool.inputSchema));
|
|
25
|
-
}
|
|
26
|
-
else if ("toolSchema" in tool && tool.toolSchema) {
|
|
27
|
-
schemas.set(tool.name, schemaToJsonSchema(tool.toolSchema));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
// Schema conversion failed — tool still works, just without unstrictification
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return schemas;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Tracks tool calls during streaming, accumulating arguments until complete.
|
|
38
|
-
*
|
|
39
|
-
* Tool calls arrive as a sequence of events:
|
|
40
|
-
* 1. TOOL_CALL_START - initializes the tool call with name
|
|
41
|
-
* 2. TOOL_CALL_ARGS (multiple) - streams JSON argument fragments
|
|
42
|
-
* 3. TOOL_CALL_END - marks the tool call as complete, triggers JSON parsing
|
|
43
|
-
*
|
|
44
|
-
* When constructed with a tool registry, the tracker unstrictifies parsed
|
|
45
|
-
* args (both partial and final) using the original JSON Schemas.
|
|
46
|
-
*/
|
|
47
|
-
export class ToolCallTracker {
|
|
48
|
-
pendingToolCalls = new Map();
|
|
49
|
-
accumulatingArgs = new Map();
|
|
50
|
-
_toolSchemas;
|
|
51
|
-
constructor(toolRegistry) {
|
|
52
|
-
this._toolSchemas = toolRegistry
|
|
53
|
-
? buildToolSchemas(toolRegistry)
|
|
54
|
-
: new Map();
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* The tool-name → JSONSchema7 map, for passing to the reducer.
|
|
58
|
-
* @returns The tool schemas map
|
|
59
|
-
*/
|
|
60
|
-
get toolSchemas() {
|
|
61
|
-
return this._toolSchemas;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Handles a streaming event, tracking tool call state as needed.
|
|
65
|
-
* @param event - The streaming event to process
|
|
66
|
-
* @throws {Error} If JSON parsing fails on TOOL_CALL_END (fail-fast, no silent fallback)
|
|
67
|
-
*/
|
|
68
|
-
handleEvent(event) {
|
|
69
|
-
switch (event.type) {
|
|
70
|
-
case EventType.TOOL_CALL_START:
|
|
71
|
-
this.pendingToolCalls.set(event.toolCallId, {
|
|
72
|
-
name: event.toolCallName,
|
|
73
|
-
input: {},
|
|
74
|
-
});
|
|
75
|
-
this.accumulatingArgs.set(event.toolCallId, "");
|
|
76
|
-
break;
|
|
77
|
-
case EventType.TOOL_CALL_ARGS: {
|
|
78
|
-
const current = this.accumulatingArgs.get(event.toolCallId);
|
|
79
|
-
this.accumulatingArgs.set(event.toolCallId, (current ?? "") + event.delta);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
case EventType.TOOL_CALL_END: {
|
|
83
|
-
const jsonStr = this.accumulatingArgs.get(event.toolCallId);
|
|
84
|
-
const toolCall = this.pendingToolCalls.get(event.toolCallId);
|
|
85
|
-
if (toolCall && jsonStr) {
|
|
86
|
-
let parsedInput;
|
|
87
|
-
try {
|
|
88
|
-
parsedInput = JSON.parse(jsonStr);
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
// Fail-fast: don't silently continue with empty input
|
|
92
|
-
throw new Error(`Failed to parse tool call arguments for ${event.toolCallId}: ${error instanceof Error ? error.message : "Unknown error"}. JSON: ${jsonStr.slice(0, 100)}${jsonStr.length > 100 ? "..." : ""}`);
|
|
93
|
-
}
|
|
94
|
-
parsedInput = this.unstrictify(toolCall.name, parsedInput);
|
|
95
|
-
toolCall.input = parsedInput;
|
|
96
|
-
}
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
default:
|
|
100
|
-
// Other event types are ignored - only tool call events are tracked
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Parses partial JSON from the accumulated args for a tool call and
|
|
106
|
-
* unstrictifies the result. Used during streaming to get the current
|
|
107
|
-
* best-effort parsed args.
|
|
108
|
-
* @param toolCallId - ID of the tool call to parse
|
|
109
|
-
* @returns Parsed and unstrictified args, or undefined if not parseable yet
|
|
110
|
-
*/
|
|
111
|
-
parsePartialArgs(toolCallId) {
|
|
112
|
-
const accToolCall = this.getAccumulatingToolCall(toolCallId);
|
|
113
|
-
if (!accToolCall)
|
|
114
|
-
return undefined;
|
|
115
|
-
try {
|
|
116
|
-
const parsed = parsePartialJson(accToolCall.accumulatedArgs);
|
|
117
|
-
if (typeof parsed === "object" &&
|
|
118
|
-
parsed !== null &&
|
|
119
|
-
!Array.isArray(parsed)) {
|
|
120
|
-
return this.unstrictify(accToolCall.name, parsed);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
/* not parseable yet */
|
|
125
|
-
}
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Gets the name and accumulated args for a tool call that is still accumulating.
|
|
130
|
-
* @param toolCallId - ID of the tool call to look up
|
|
131
|
-
* @returns The tool name and raw accumulated args string, or undefined if not found
|
|
132
|
-
*/
|
|
133
|
-
getAccumulatingToolCall(toolCallId) {
|
|
134
|
-
const toolCall = this.pendingToolCalls.get(toolCallId);
|
|
135
|
-
const args = this.accumulatingArgs.get(toolCallId);
|
|
136
|
-
if (!toolCall || args === undefined)
|
|
137
|
-
return undefined;
|
|
138
|
-
return { name: toolCall.name, accumulatedArgs: args };
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Gets tool calls for the given IDs, filtered to only those that exist.
|
|
142
|
-
* @param toolCallIds - IDs of tool calls to retrieve
|
|
143
|
-
* @returns Map of tool call ID to pending tool call
|
|
144
|
-
*/
|
|
145
|
-
getToolCallsById(toolCallIds) {
|
|
146
|
-
const result = new Map();
|
|
147
|
-
for (const id of toolCallIds) {
|
|
148
|
-
const toolCall = this.pendingToolCalls.get(id);
|
|
149
|
-
if (toolCall) {
|
|
150
|
-
result.set(id, toolCall);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return result;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Clears tracked tool calls for the given IDs.
|
|
157
|
-
* @param toolCallIds - IDs of tool calls to clear
|
|
158
|
-
*/
|
|
159
|
-
clearToolCalls(toolCallIds) {
|
|
160
|
-
for (const id of toolCallIds) {
|
|
161
|
-
this.pendingToolCalls.delete(id);
|
|
162
|
-
this.accumulatingArgs.delete(id);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Unstrictify params using the schema for the given tool name.
|
|
167
|
-
* Returns params unchanged if no schema is available.
|
|
168
|
-
*/
|
|
169
|
-
unstrictify(toolName, params) {
|
|
170
|
-
const schema = this._toolSchemas.get(toolName);
|
|
171
|
-
if (!schema)
|
|
172
|
-
return params;
|
|
173
|
-
return unstrictifyToolCallParamsFromSchema(schema, params);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
//# sourceMappingURL=tool-call-tracker.js.map
|
|
@@ -1 +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,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACvD,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACnD,IAAI,CAAC,QAAQ,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QACtD,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;IACxD,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,WAAqB;QACpC,MAAM,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;QAClD,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC/C,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,WAAqB;QAClC,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;YAC7B,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACjC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,WAAW,CACjB,QAAgB,EAChB,MAA+B;QAE/B,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM;YAAE,OAAO,MAAM,CAAC;QAC3B,OAAO,mCAAmC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["/**\n * Tool Call Tracker\n *\n * Tracks tool calls during streaming, accumulating arguments until complete.\n * Owns the tool name → JSON Schema mapping and handles unstrictification\n * so callers don't need to know about schema conversion.\n */\n\nimport { EventType, type AGUIEvent } from \"@ag-ui/core\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport { parse as parsePartialJson } from \"partial-json\";\nimport type { TamboTool } from \"../../model/component-metadata\";\nimport { schemaToJsonSchema } from \"../../schema/schema\";\nimport type { PendingToolCall } from \"./tool-executor\";\nimport { unstrictifyToolCallParamsFromSchema } from \"./unstrictify\";\n\n/**\n * Build a tool-name → JSONSchema7 map from the tool registry.\n * Handles both modern `inputSchema` and deprecated `toolSchema` formats.\n * Tools whose schema can't be converted are silently skipped.\n * @param toolRegistry - Record of tool name → tool definition\n * @returns Map of tool name → JSON Schema\n */\nfunction buildToolSchemas(\n toolRegistry: Record<string, TamboTool>,\n): Map<string, JSONSchema7> {\n const schemas = new Map<string, JSONSchema7>();\n for (const tool of Object.values(toolRegistry)) {\n try {\n if (\"inputSchema\" in tool && tool.inputSchema) {\n schemas.set(tool.name, schemaToJsonSchema(tool.inputSchema));\n } else if (\"toolSchema\" in tool && tool.toolSchema) {\n schemas.set(tool.name, schemaToJsonSchema(tool.toolSchema));\n }\n } catch {\n // Schema conversion failed — tool still works, just without unstrictification\n }\n }\n return schemas;\n}\n\n/**\n * Tracks tool calls during streaming, accumulating arguments until complete.\n *\n * Tool calls arrive as a sequence of events:\n * 1. TOOL_CALL_START - initializes the tool call with name\n * 2. TOOL_CALL_ARGS (multiple) - streams JSON argument fragments\n * 3. TOOL_CALL_END - marks the tool call as complete, triggers JSON parsing\n *\n * When constructed with a tool registry, the tracker unstrictifies parsed\n * args (both partial and final) using the original JSON Schemas.\n */\nexport class ToolCallTracker {\n private pendingToolCalls = new Map<string, PendingToolCall>();\n private accumulatingArgs = new Map<string, string>();\n private _toolSchemas: Map<string, JSONSchema7>;\n\n constructor(toolRegistry?: Record<string, TamboTool>) {\n this._toolSchemas = toolRegistry\n ? buildToolSchemas(toolRegistry)\n : new Map();\n }\n\n /**\n * The tool-name → JSONSchema7 map, for passing to the reducer.\n * @returns The tool schemas map\n */\n get toolSchemas(): Map<string, JSONSchema7> {\n return this._toolSchemas;\n }\n\n /**\n * Handles a streaming event, tracking tool call state as needed.\n * @param event - The streaming event to process\n * @throws {Error} If JSON parsing fails on TOOL_CALL_END (fail-fast, no silent fallback)\n */\n handleEvent(event: AGUIEvent): void {\n switch (event.type) {\n case EventType.TOOL_CALL_START:\n this.pendingToolCalls.set(event.toolCallId, {\n name: event.toolCallName,\n input: {},\n });\n this.accumulatingArgs.set(event.toolCallId, \"\");\n break;\n\n case EventType.TOOL_CALL_ARGS: {\n const current = this.accumulatingArgs.get(event.toolCallId);\n this.accumulatingArgs.set(\n event.toolCallId,\n (current ?? \"\") + event.delta,\n );\n break;\n }\n\n case EventType.TOOL_CALL_END: {\n const jsonStr = this.accumulatingArgs.get(event.toolCallId);\n const toolCall = this.pendingToolCalls.get(event.toolCallId);\n if (toolCall && jsonStr) {\n let parsedInput: Record<string, unknown>;\n try {\n parsedInput = JSON.parse(jsonStr) as Record<string, unknown>;\n } catch (error) {\n // Fail-fast: don't silently continue with empty input\n throw new Error(\n `Failed to parse tool call arguments for ${event.toolCallId}: ${error instanceof Error ? error.message : \"Unknown error\"}. JSON: ${jsonStr.slice(0, 100)}${jsonStr.length > 100 ? \"...\" : \"\"}`,\n );\n }\n\n parsedInput = this.unstrictify(toolCall.name, parsedInput);\n toolCall.input = parsedInput;\n }\n break;\n }\n\n default:\n // Other event types are ignored - only tool call events are tracked\n break;\n }\n }\n\n /**\n * Parses partial JSON from the accumulated args for a tool call and\n * unstrictifies the result. Used during streaming to get the current\n * best-effort parsed args.\n * @param toolCallId - ID of the tool call to parse\n * @returns Parsed and unstrictified args, or undefined if not parseable yet\n */\n parsePartialArgs(toolCallId: string): Record<string, unknown> | undefined {\n const accToolCall = this.getAccumulatingToolCall(toolCallId);\n if (!accToolCall) return undefined;\n\n try {\n const parsed: unknown = parsePartialJson(accToolCall.accumulatedArgs);\n if (\n typeof parsed === \"object\" &&\n parsed !== null &&\n !Array.isArray(parsed)\n ) {\n return this.unstrictify(\n accToolCall.name,\n parsed as Record<string, unknown>,\n );\n }\n } catch {\n /* not parseable yet */\n }\n return undefined;\n }\n\n /**\n * Gets the name and accumulated args for a tool call that is still accumulating.\n * @param toolCallId - ID of the tool call to look up\n * @returns The tool name and raw accumulated args string, or undefined if not found\n */\n getAccumulatingToolCall(\n toolCallId: string,\n ): { name: string; accumulatedArgs: string } | undefined {\n const toolCall = this.pendingToolCalls.get(toolCallId);\n const args = this.accumulatingArgs.get(toolCallId);\n if (!toolCall || args === undefined) return undefined;\n return { name: toolCall.name, accumulatedArgs: args };\n }\n\n /**\n * Gets tool calls for the given IDs, filtered to only those that exist.\n * @param toolCallIds - IDs of tool calls to retrieve\n * @returns Map of tool call ID to pending tool call\n */\n getToolCallsById(toolCallIds: string[]): Map<string, PendingToolCall> {\n const result = new Map<string, PendingToolCall>();\n for (const id of toolCallIds) {\n const toolCall = this.pendingToolCalls.get(id);\n if (toolCall) {\n result.set(id, toolCall);\n }\n }\n return result;\n }\n\n /**\n * Clears tracked tool calls for the given IDs.\n * @param toolCallIds - IDs of tool calls to clear\n */\n clearToolCalls(toolCallIds: string[]): void {\n for (const id of toolCallIds) {\n this.pendingToolCalls.delete(id);\n this.accumulatingArgs.delete(id);\n }\n }\n\n /**\n * Unstrictify params using the schema for the given tool name.\n * Returns params unchanged if no schema is available.\n */\n private unstrictify(\n toolName: string,\n params: Record<string, unknown>,\n ): Record<string, unknown> {\n const schema = this._toolSchemas.get(toolName);\n if (!schema) return params;\n return unstrictifyToolCallParamsFromSchema(schema, params);\n }\n}\n"]}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Executor
|
|
3
|
-
*
|
|
4
|
-
* Handles automatic execution of client-side tools when the model
|
|
5
|
-
* requests them via `tambo.run.awaiting_input` events.
|
|
6
|
-
*/
|
|
7
|
-
import type { TamboTool } from "../../model/component-metadata.js";
|
|
8
|
-
import type { ToolResultContent } from "@tambo-ai/typescript-sdk/resources/threads/threads";
|
|
9
|
-
import type { ToolCallTracker } from "./tool-call-tracker.js";
|
|
10
|
-
import { type KeyedThrottle } from "./keyed-throttle.js";
|
|
11
|
-
/**
|
|
12
|
-
* Pending tool call from the stream accumulator
|
|
13
|
-
*/
|
|
14
|
-
export interface PendingToolCall {
|
|
15
|
-
name: string;
|
|
16
|
-
input: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Execute a streamable tool call during streaming with pre-parsed partial args.
|
|
20
|
-
*
|
|
21
|
-
* Called on each TOOL_CALL_ARGS event for tools annotated with
|
|
22
|
-
* `tamboStreamableHint: true`. Enables incremental UI updates while
|
|
23
|
-
* the model is still generating arguments.
|
|
24
|
-
*
|
|
25
|
-
* Errors are caught silently — streaming tool execution is non-fatal since
|
|
26
|
-
* the final execution via `awaiting_input` is what matters.
|
|
27
|
-
* @param toolCallId - The tool call ID being accumulated
|
|
28
|
-
* @param parsedArgs - Pre-parsed partial JSON args
|
|
29
|
-
* @param toolTracker - Tracker holding pending tool call state
|
|
30
|
-
* @param toolRegistry - Record of tool name to tool definition
|
|
31
|
-
*/
|
|
32
|
-
export declare function executeStreamableToolCall(toolCallId: string, parsedArgs: Record<string, unknown>, toolTracker: ToolCallTracker, toolRegistry: Record<string, TamboTool>): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Creates a throttled wrapper around executeStreamableToolCall.
|
|
35
|
-
*
|
|
36
|
-
* Each tool call ID gets its own independent leading+trailing throttle via
|
|
37
|
-
* {@link createKeyedThrottle}. The first call for a tool ID fires immediately
|
|
38
|
-
* (leading edge). Subsequent calls during the cooldown window update the
|
|
39
|
-
* stored args. After `delay` ms, if new args arrived, the tool re-executes
|
|
40
|
-
* with the latest args (trailing edge). This repeats as long as new args
|
|
41
|
-
* keep arriving — roughly one execution per `delay` ms during streaming.
|
|
42
|
-
*
|
|
43
|
-
* Call `flush()` to force-execute all pending trailing calls and reset to idle.
|
|
44
|
-
* @param toolTracker - Tracker holding pending tool call state
|
|
45
|
-
* @param toolRegistry - Record of tool name to tool definition
|
|
46
|
-
* @param delay - Throttle interval in milliseconds
|
|
47
|
-
* @returns Keyed throttle controller (schedule / flush)
|
|
48
|
-
*/
|
|
49
|
-
export declare function createThrottledStreamableExecutor(toolTracker: ToolCallTracker, toolRegistry: Record<string, TamboTool>, delay?: number): KeyedThrottle<Record<string, unknown>>;
|
|
50
|
-
/**
|
|
51
|
-
* Execute a single client-side tool and return the result.
|
|
52
|
-
* @param tool - The tool definition from the registry
|
|
53
|
-
* @param toolCallId - The ID of the tool call to respond to
|
|
54
|
-
* @param args - The parsed arguments for the tool
|
|
55
|
-
* @returns ToolResultContent with the execution result or error
|
|
56
|
-
*/
|
|
57
|
-
export declare function executeClientTool(tool: TamboTool, toolCallId: string, args: Record<string, unknown>): Promise<ToolResultContent>;
|
|
58
|
-
/**
|
|
59
|
-
* Execute all pending tool calls and return their results.
|
|
60
|
-
* Tools are executed sequentially to avoid race conditions when
|
|
61
|
-
* tools may have side effects that depend on each other.
|
|
62
|
-
* @param toolCalls - Map of tool call IDs to their call details
|
|
63
|
-
* @param registry - Registry of tool names to their definitions (Map or Record)
|
|
64
|
-
* @returns Array of ToolResultContent for all executed tools
|
|
65
|
-
*/
|
|
66
|
-
export declare function executeAllPendingTools(toolCalls: Map<string, PendingToolCall>, registry: Map<string, TamboTool> | Record<string, TamboTool>): Promise<ToolResultContent[]>;
|
|
67
|
-
//# sourceMappingURL=tool-executor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-executor.d.ts","sourceRoot":"","sources":["../../../src/v1/utils/tool-executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,KAAK,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