@agentick/core 0.0.1
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/LICENSE +21 -0
- package/README.md +875 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/.tsbuildinfo.build +1 -0
- package/dist/agent.d.ts +32 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +26 -0
- package/dist/agent.js.map +1 -0
- package/dist/agentick-instance.d.ts +285 -0
- package/dist/agentick-instance.d.ts.map +1 -0
- package/dist/agentick-instance.js +700 -0
- package/dist/agentick-instance.js.map +1 -0
- package/dist/aidk-instance.d.ts +294 -0
- package/dist/aidk-instance.d.ts.map +1 -0
- package/dist/aidk-instance.js +340 -0
- package/dist/aidk-instance.js.map +1 -0
- package/dist/app/session-store.d.ts +57 -0
- package/dist/app/session-store.d.ts.map +1 -0
- package/dist/app/session-store.js +87 -0
- package/dist/app/session-store.js.map +1 -0
- package/dist/app/session.d.ts +209 -0
- package/dist/app/session.d.ts.map +1 -0
- package/dist/app/session.js +2131 -0
- package/dist/app/session.js.map +1 -0
- package/dist/app/sqlite-session-store.d.ts +60 -0
- package/dist/app/sqlite-session-store.d.ts.map +1 -0
- package/dist/app/sqlite-session-store.js +234 -0
- package/dist/app/sqlite-session-store.js.map +1 -0
- package/dist/app/types.d.ts +1461 -0
- package/dist/app/types.d.ts.map +1 -0
- package/dist/app/types.js +14 -0
- package/dist/app/types.js.map +1 -0
- package/dist/app.d.ts +79 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +83 -0
- package/dist/app.js.map +1 -0
- package/dist/channels/adapters/index.d.ts +2 -0
- package/dist/channels/adapters/index.d.ts.map +1 -0
- package/dist/channels/adapters/index.js +2 -0
- package/dist/channels/adapters/index.js.map +1 -0
- package/dist/channels/adapters/redis.d.ts +77 -0
- package/dist/channels/adapters/redis.d.ts.map +1 -0
- package/dist/channels/adapters/redis.js +259 -0
- package/dist/channels/adapters/redis.js.map +1 -0
- package/dist/channels/index.d.ts +38 -0
- package/dist/channels/index.d.ts.map +1 -0
- package/dist/channels/index.js +38 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/service.d.ts +684 -0
- package/dist/channels/service.d.ts.map +1 -0
- package/dist/channels/service.js +870 -0
- package/dist/channels/service.js.map +1 -0
- package/dist/channels/transports/index.d.ts +4 -0
- package/dist/channels/transports/index.d.ts.map +1 -0
- package/dist/channels/transports/index.js +4 -0
- package/dist/channels/transports/index.js.map +1 -0
- package/dist/channels/transports/socketio.d.ts +98 -0
- package/dist/channels/transports/socketio.d.ts.map +1 -0
- package/dist/channels/transports/socketio.js +246 -0
- package/dist/channels/transports/socketio.js.map +1 -0
- package/dist/channels/transports/streamable-http.d.ts +107 -0
- package/dist/channels/transports/streamable-http.d.ts.map +1 -0
- package/dist/channels/transports/streamable-http.js +353 -0
- package/dist/channels/transports/streamable-http.js.map +1 -0
- package/dist/channels/transports/websocket.d.ts +117 -0
- package/dist/channels/transports/websocket.d.ts.map +1 -0
- package/dist/channels/transports/websocket.js +416 -0
- package/dist/channels/transports/websocket.js.map +1 -0
- package/dist/com/index.d.ts +29 -0
- package/dist/com/index.d.ts.map +1 -0
- package/dist/com/index.js +29 -0
- package/dist/com/index.js.map +1 -0
- package/dist/com/object-model.d.ts +634 -0
- package/dist/com/object-model.d.ts.map +1 -0
- package/dist/com/object-model.js +963 -0
- package/dist/com/object-model.js.map +1 -0
- package/dist/com/types.d.ts +192 -0
- package/dist/com/types.d.ts.map +1 -0
- package/dist/com/types.js +1 -0
- package/dist/com/types.js.map +1 -0
- package/dist/compiler/collector.d.ts +16 -0
- package/dist/compiler/collector.d.ts.map +1 -0
- package/dist/compiler/collector.js +388 -0
- package/dist/compiler/collector.js.map +1 -0
- package/dist/compiler/content-block-registry.d.ts +11 -0
- package/dist/compiler/content-block-registry.d.ts.map +1 -0
- package/dist/compiler/content-block-registry.js +312 -0
- package/dist/compiler/content-block-registry.js.map +1 -0
- package/dist/compiler/extractors.d.ts +68 -0
- package/dist/compiler/extractors.d.ts.map +1 -0
- package/dist/compiler/extractors.js +547 -0
- package/dist/compiler/extractors.js.map +1 -0
- package/dist/compiler/fiber-compiler.d.ts +203 -0
- package/dist/compiler/fiber-compiler.d.ts.map +1 -0
- package/dist/compiler/fiber-compiler.js +498 -0
- package/dist/compiler/fiber-compiler.js.map +1 -0
- package/dist/compiler/fiber.d.ts +61 -0
- package/dist/compiler/fiber.d.ts.map +1 -0
- package/dist/compiler/fiber.js +244 -0
- package/dist/compiler/fiber.js.map +1 -0
- package/dist/compiler/index.d.ts +18 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +38 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/scheduler.d.ts +95 -0
- package/dist/compiler/scheduler.d.ts.map +1 -0
- package/dist/compiler/scheduler.js +138 -0
- package/dist/compiler/scheduler.js.map +1 -0
- package/dist/compiler/structure-renderer.d.ts +42 -0
- package/dist/compiler/structure-renderer.d.ts.map +1 -0
- package/dist/compiler/structure-renderer.js +189 -0
- package/dist/compiler/structure-renderer.js.map +1 -0
- package/dist/compiler/types.d.ts +96 -0
- package/dist/compiler/types.d.ts.map +1 -0
- package/dist/compiler/types.js +19 -0
- package/dist/compiler/types.js.map +1 -0
- package/dist/component/component-hooks.d.ts +68 -0
- package/dist/component/component-hooks.d.ts.map +1 -0
- package/dist/component/component-hooks.js +112 -0
- package/dist/component/component-hooks.js.map +1 -0
- package/dist/component/component.d.ts +314 -0
- package/dist/component/component.d.ts.map +1 -0
- package/dist/component/component.js +64 -0
- package/dist/component/component.js.map +1 -0
- package/dist/component/index.d.ts +47 -0
- package/dist/component/index.d.ts.map +1 -0
- package/dist/component/index.js +47 -0
- package/dist/component/index.js.map +1 -0
- package/dist/component/tentickle-component.d.ts +185 -0
- package/dist/component/tentickle-component.d.ts.map +1 -0
- package/dist/component/tentickle-component.js +182 -0
- package/dist/component/tentickle-component.js.map +1 -0
- package/dist/content/index.d.ts +12 -0
- package/dist/content/index.d.ts.map +1 -0
- package/dist/content/index.js +17 -0
- package/dist/content/index.js.map +1 -0
- package/dist/context/index.d.ts +51 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +69 -0
- package/dist/context/index.js.map +1 -0
- package/dist/core/channel-helpers.d.ts +31 -0
- package/dist/core/channel-helpers.d.ts.map +1 -0
- package/dist/core/channel-helpers.js +62 -0
- package/dist/core/channel-helpers.js.map +1 -0
- package/dist/core/channel.d.ts +164 -0
- package/dist/core/channel.d.ts.map +1 -0
- package/dist/core/channel.js +199 -0
- package/dist/core/channel.js.map +1 -0
- package/dist/core/context.d.ts +412 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +290 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/event-buffer.d.ts +212 -0
- package/dist/core/event-buffer.d.ts.map +1 -0
- package/dist/core/event-buffer.js +346 -0
- package/dist/core/event-buffer.js.map +1 -0
- package/dist/core/execution-helpers.d.ts +179 -0
- package/dist/core/execution-helpers.d.ts.map +1 -0
- package/dist/core/execution-helpers.js +212 -0
- package/dist/core/execution-helpers.js.map +1 -0
- package/dist/core/execution-tracker.d.ts +53 -0
- package/dist/core/execution-tracker.d.ts.map +1 -0
- package/dist/core/execution-tracker.js +309 -0
- package/dist/core/execution-tracker.js.map +1 -0
- package/dist/core/index.d.ts +58 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +58 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +341 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +346 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/metrics-helpers.d.ts +40 -0
- package/dist/core/metrics-helpers.d.ts.map +1 -0
- package/dist/core/metrics-helpers.js +72 -0
- package/dist/core/metrics-helpers.js.map +1 -0
- package/dist/core/otel-provider.d.ts +54 -0
- package/dist/core/otel-provider.d.ts.map +1 -0
- package/dist/core/otel-provider.js +107 -0
- package/dist/core/otel-provider.js.map +1 -0
- package/dist/core/procedure-graph.d.ts +136 -0
- package/dist/core/procedure-graph.d.ts.map +1 -0
- package/dist/core/procedure-graph.js +272 -0
- package/dist/core/procedure-graph.js.map +1 -0
- package/dist/core/procedure.d.ts +755 -0
- package/dist/core/procedure.d.ts.map +1 -0
- package/dist/core/procedure.js +899 -0
- package/dist/core/procedure.js.map +1 -0
- package/dist/core/stream.d.ts +106 -0
- package/dist/core/stream.d.ts.map +1 -0
- package/dist/core/stream.js +186 -0
- package/dist/core/stream.js.map +1 -0
- package/dist/core/telemetry.d.ts +182 -0
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/core/telemetry.js +124 -0
- package/dist/core/telemetry.js.map +1 -0
- package/dist/engine/client-tool-coordinator.d.ts +50 -0
- package/dist/engine/client-tool-coordinator.d.ts.map +1 -0
- package/dist/engine/client-tool-coordinator.js +121 -0
- package/dist/engine/client-tool-coordinator.js.map +1 -0
- package/dist/engine/engine-events.d.ts +117 -0
- package/dist/engine/engine-events.d.ts.map +1 -0
- package/dist/engine/engine-events.js +178 -0
- package/dist/engine/engine-events.js.map +1 -0
- package/dist/engine/engine-response.d.ts +48 -0
- package/dist/engine/engine-response.d.ts.map +1 -0
- package/dist/engine/engine-response.js +2 -0
- package/dist/engine/engine-response.js.map +1 -0
- package/dist/engine/execution-graph.d.ts +104 -0
- package/dist/engine/execution-graph.d.ts.map +1 -0
- package/dist/engine/execution-graph.js +257 -0
- package/dist/engine/execution-graph.js.map +1 -0
- package/dist/engine/execution-handle.d.ts +212 -0
- package/dist/engine/execution-handle.d.ts.map +1 -0
- package/dist/engine/execution-handle.js +602 -0
- package/dist/engine/execution-handle.js.map +1 -0
- package/dist/engine/execution-types.d.ts +248 -0
- package/dist/engine/execution-types.d.ts.map +1 -0
- package/dist/engine/execution-types.js +23 -0
- package/dist/engine/execution-types.js.map +1 -0
- package/dist/engine/index.d.ts +21 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +23 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/tool-confirmation-coordinator.d.ts +74 -0
- package/dist/engine/tool-confirmation-coordinator.d.ts.map +1 -0
- package/dist/engine/tool-confirmation-coordinator.js +137 -0
- package/dist/engine/tool-confirmation-coordinator.js.map +1 -0
- package/dist/engine/tool-executor.d.ts +127 -0
- package/dist/engine/tool-executor.d.ts.map +1 -0
- package/dist/engine/tool-executor.js +363 -0
- package/dist/engine/tool-executor.js.map +1 -0
- package/dist/hibernation/index.d.ts +126 -0
- package/dist/hibernation/index.d.ts.map +1 -0
- package/dist/hibernation/index.js +127 -0
- package/dist/hibernation/index.js.map +1 -0
- package/dist/hooks/base-hook-registry.d.ts +41 -0
- package/dist/hooks/base-hook-registry.d.ts.map +1 -0
- package/dist/hooks/base-hook-registry.js +76 -0
- package/dist/hooks/base-hook-registry.js.map +1 -0
- package/dist/hooks/com-state.d.ts +40 -0
- package/dist/hooks/com-state.d.ts.map +1 -0
- package/dist/hooks/com-state.js +90 -0
- package/dist/hooks/com-state.js.map +1 -0
- package/dist/hooks/context-info.d.ts +139 -0
- package/dist/hooks/context-info.d.ts.map +1 -0
- package/dist/hooks/context-info.js +115 -0
- package/dist/hooks/context-info.js.map +1 -0
- package/dist/hooks/context-internal.d.ts +21 -0
- package/dist/hooks/context-internal.d.ts.map +1 -0
- package/dist/hooks/context-internal.js +20 -0
- package/dist/hooks/context-internal.js.map +1 -0
- package/dist/hooks/context.d.ts +64 -0
- package/dist/hooks/context.d.ts.map +1 -0
- package/dist/hooks/context.js +83 -0
- package/dist/hooks/context.js.map +1 -0
- package/dist/hooks/data.d.ts +33 -0
- package/dist/hooks/data.d.ts.map +1 -0
- package/dist/hooks/data.js +84 -0
- package/dist/hooks/data.js.map +1 -0
- package/dist/hooks/formatter-context.d.ts +34 -0
- package/dist/hooks/formatter-context.d.ts.map +1 -0
- package/dist/hooks/formatter-context.js +34 -0
- package/dist/hooks/formatter-context.js.map +1 -0
- package/dist/hooks/hook-registry.d.ts +45 -0
- package/dist/hooks/hook-registry.d.ts.map +1 -0
- package/dist/hooks/hook-registry.js +109 -0
- package/dist/hooks/hook-registry.js.map +1 -0
- package/dist/hooks/index.d.ts +20 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +47 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/knob.d.ts +87 -0
- package/dist/hooks/knob.d.ts.map +1 -0
- package/dist/hooks/knob.js +129 -0
- package/dist/hooks/knob.js.map +1 -0
- package/dist/hooks/knobs-component.d.ts +70 -0
- package/dist/hooks/knobs-component.d.ts.map +1 -0
- package/dist/hooks/knobs-component.js +300 -0
- package/dist/hooks/knobs-component.js.map +1 -0
- package/dist/hooks/lifecycle.d.ts +158 -0
- package/dist/hooks/lifecycle.d.ts.map +1 -0
- package/dist/hooks/lifecycle.js +217 -0
- package/dist/hooks/lifecycle.js.map +1 -0
- package/dist/hooks/message-context.d.ts +101 -0
- package/dist/hooks/message-context.d.ts.map +1 -0
- package/dist/hooks/message-context.js +145 -0
- package/dist/hooks/message-context.js.map +1 -0
- package/dist/hooks/policy-context.d.ts.map +1 -0
- package/dist/hooks/runtime-context.d.ts +122 -0
- package/dist/hooks/runtime-context.d.ts.map +1 -0
- package/dist/hooks/runtime-context.js +149 -0
- package/dist/hooks/runtime-context.js.map +1 -0
- package/dist/hooks/signal.d.ts +267 -0
- package/dist/hooks/signal.d.ts.map +1 -0
- package/dist/hooks/signal.js +825 -0
- package/dist/hooks/signal.js.map +1 -0
- package/dist/hooks/types.d.ts +179 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +5 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx/components/agent.d.ts +64 -0
- package/dist/jsx/components/agent.d.ts.map +1 -0
- package/dist/jsx/components/agent.js +80 -0
- package/dist/jsx/components/agent.js.map +1 -0
- package/dist/jsx/components/complete.d.ts +65 -0
- package/dist/jsx/components/complete.d.ts.map +1 -0
- package/dist/jsx/components/complete.js +64 -0
- package/dist/jsx/components/complete.js.map +1 -0
- package/dist/jsx/components/content.d.ts +98 -0
- package/dist/jsx/components/content.d.ts.map +1 -0
- package/dist/jsx/components/content.js +51 -0
- package/dist/jsx/components/content.js.map +1 -0
- package/dist/jsx/components/harness.d.ts +118 -0
- package/dist/jsx/components/harness.d.ts.map +1 -0
- package/dist/jsx/components/harness.js +117 -0
- package/dist/jsx/components/harness.js.map +1 -0
- package/dist/jsx/components/index.d.ts +11 -0
- package/dist/jsx/components/index.d.ts.map +1 -0
- package/dist/jsx/components/index.js +11 -0
- package/dist/jsx/components/index.js.map +1 -0
- package/dist/jsx/components/markdown.d.ts +31 -0
- package/dist/jsx/components/markdown.d.ts.map +1 -0
- package/dist/jsx/components/markdown.js +17 -0
- package/dist/jsx/components/markdown.js.map +1 -0
- package/dist/jsx/components/messages.d.ts +283 -0
- package/dist/jsx/components/messages.d.ts.map +1 -0
- package/dist/jsx/components/messages.js +257 -0
- package/dist/jsx/components/messages.js.map +1 -0
- package/dist/jsx/components/model.d.ts +94 -0
- package/dist/jsx/components/model.d.ts.map +1 -0
- package/dist/jsx/components/model.js +96 -0
- package/dist/jsx/components/model.js.map +1 -0
- package/dist/jsx/components/primitives.d.ts +117 -0
- package/dist/jsx/components/primitives.d.ts.map +1 -0
- package/dist/jsx/components/primitives.js +83 -0
- package/dist/jsx/components/primitives.js.map +1 -0
- package/dist/jsx/components/renderer.d.ts +24 -0
- package/dist/jsx/components/renderer.d.ts.map +1 -0
- package/dist/jsx/components/renderer.js +11 -0
- package/dist/jsx/components/renderer.js.map +1 -0
- package/dist/jsx/components/semantic.d.ts +155 -0
- package/dist/jsx/components/semantic.d.ts.map +1 -0
- package/dist/jsx/components/semantic.js +39 -0
- package/dist/jsx/components/semantic.js.map +1 -0
- package/dist/jsx/components/timeline.d.ts +157 -0
- package/dist/jsx/components/timeline.d.ts.map +1 -0
- package/dist/jsx/components/timeline.js +357 -0
- package/dist/jsx/components/timeline.js.map +1 -0
- package/dist/jsx/components/token-budget.d.ts +70 -0
- package/dist/jsx/components/token-budget.d.ts.map +1 -0
- package/dist/jsx/components/token-budget.js +135 -0
- package/dist/jsx/components/token-budget.js.map +1 -0
- package/dist/jsx/components/xml.d.ts +27 -0
- package/dist/jsx/components/xml.d.ts.map +1 -0
- package/dist/jsx/components/xml.js +17 -0
- package/dist/jsx/components/xml.js.map +1 -0
- package/dist/jsx/index.d.ts +58 -0
- package/dist/jsx/index.d.ts.map +1 -0
- package/dist/jsx/index.js +59 -0
- package/dist/jsx/index.js.map +1 -0
- package/dist/jsx/jsx-runtime.d.ts +370 -0
- package/dist/jsx/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx/jsx-runtime.js +79 -0
- package/dist/jsx/jsx-runtime.js.map +1 -0
- package/dist/jsx/jsx-types.d.ts +23 -0
- package/dist/jsx/jsx-types.d.ts.map +1 -0
- package/dist/jsx/jsx-types.js +1 -0
- package/dist/jsx/jsx-types.js.map +1 -0
- package/dist/mcp/client.d.ts +46 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +138 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/component.d.ts +95 -0
- package/dist/mcp/component.d.ts.map +1 -0
- package/dist/mcp/component.js +185 -0
- package/dist/mcp/component.js.map +1 -0
- package/dist/mcp/create-mcp-tool.d.ts +191 -0
- package/dist/mcp/create-mcp-tool.d.ts.map +1 -0
- package/dist/mcp/create-mcp-tool.js +228 -0
- package/dist/mcp/create-mcp-tool.js.map +1 -0
- package/dist/mcp/index.d.ts +49 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +48 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/service.d.ts +39 -0
- package/dist/mcp/service.d.ts.map +1 -0
- package/dist/mcp/service.js +77 -0
- package/dist/mcp/service.js.map +1 -0
- package/dist/mcp/tool.d.ts +55 -0
- package/dist/mcp/tool.d.ts.map +1 -0
- package/dist/mcp/tool.js +119 -0
- package/dist/mcp/tool.js.map +1 -0
- package/dist/mcp/types.d.ts +72 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +6 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/middleware/defaults.d.ts +9 -0
- package/dist/middleware/defaults.d.ts.map +1 -0
- package/dist/middleware/defaults.js +47 -0
- package/dist/middleware/defaults.js.map +1 -0
- package/dist/model/adapter-helpers.d.ts +161 -0
- package/dist/model/adapter-helpers.d.ts.map +1 -0
- package/dist/model/adapter-helpers.js +351 -0
- package/dist/model/adapter-helpers.js.map +1 -0
- package/dist/model/adapter.d.ts +399 -0
- package/dist/model/adapter.d.ts.map +1 -0
- package/dist/model/adapter.js +497 -0
- package/dist/model/adapter.js.map +1 -0
- package/dist/model/index.d.ts +54 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +55 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/model-hooks.d.ts +45 -0
- package/dist/model/model-hooks.d.ts.map +1 -0
- package/dist/model/model-hooks.js +24 -0
- package/dist/model/model-hooks.js.map +1 -0
- package/dist/model/model.d.ts +302 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +20 -0
- package/dist/model/model.js.map +1 -0
- package/dist/model/simple-adapter.d.ts +176 -0
- package/dist/model/simple-adapter.d.ts.map +1 -0
- package/dist/model/simple-adapter.js +264 -0
- package/dist/model/simple-adapter.js.map +1 -0
- package/dist/model/stream-accumulator.d.ts +284 -0
- package/dist/model/stream-accumulator.d.ts.map +1 -0
- package/dist/model/stream-accumulator.js +532 -0
- package/dist/model/stream-accumulator.js.map +1 -0
- package/dist/model/utils/index.d.ts +2 -0
- package/dist/model/utils/index.d.ts.map +1 -0
- package/dist/model/utils/index.js +2 -0
- package/dist/model/utils/index.js.map +1 -0
- package/dist/model/utils/language-model.d.ts +26 -0
- package/dist/model/utils/language-model.d.ts.map +1 -0
- package/dist/model/utils/language-model.js +706 -0
- package/dist/model/utils/language-model.js.map +1 -0
- package/dist/procedure/index.d.ts +20 -0
- package/dist/procedure/index.d.ts.map +1 -0
- package/dist/procedure/index.js +19 -0
- package/dist/procedure/index.js.map +1 -0
- package/dist/reconciler/devtools-bridge.d.ts +40 -0
- package/dist/reconciler/devtools-bridge.d.ts.map +1 -0
- package/dist/reconciler/devtools-bridge.js +79 -0
- package/dist/reconciler/devtools-bridge.js.map +1 -0
- package/dist/reconciler/host-config.d.ts +39 -0
- package/dist/reconciler/host-config.d.ts.map +1 -0
- package/dist/reconciler/host-config.js +195 -0
- package/dist/reconciler/host-config.js.map +1 -0
- package/dist/reconciler/index.d.ts +7 -0
- package/dist/reconciler/index.d.ts.map +1 -0
- package/dist/reconciler/index.js +7 -0
- package/dist/reconciler/index.js.map +1 -0
- package/dist/reconciler/reconciler.d.ts +47 -0
- package/dist/reconciler/reconciler.d.ts.map +1 -0
- package/dist/reconciler/reconciler.js +89 -0
- package/dist/reconciler/reconciler.js.map +1 -0
- package/dist/reconciler/types.d.ts +86 -0
- package/dist/reconciler/types.d.ts.map +1 -0
- package/dist/reconciler/types.js +37 -0
- package/dist/reconciler/types.js.map +1 -0
- package/dist/renderers/base.d.ts +98 -0
- package/dist/renderers/base.d.ts.map +1 -0
- package/dist/renderers/base.js +82 -0
- package/dist/renderers/base.js.map +1 -0
- package/dist/renderers/index.d.ts +31 -0
- package/dist/renderers/index.d.ts.map +1 -0
- package/dist/renderers/index.js +31 -0
- package/dist/renderers/index.js.map +1 -0
- package/dist/renderers/markdown.d.ts +48 -0
- package/dist/renderers/markdown.d.ts.map +1 -0
- package/dist/renderers/markdown.js +432 -0
- package/dist/renderers/markdown.js.map +1 -0
- package/dist/renderers/types.d.ts +7 -0
- package/dist/renderers/types.d.ts.map +1 -0
- package/dist/renderers/types.js +7 -0
- package/dist/renderers/types.js.map +1 -0
- package/dist/renderers/xml.d.ts +49 -0
- package/dist/renderers/xml.d.ts.map +1 -0
- package/dist/renderers/xml.js +444 -0
- package/dist/renderers/xml.js.map +1 -0
- package/dist/state/boundary.d.ts +347 -0
- package/dist/state/boundary.d.ts.map +1 -0
- package/dist/state/boundary.js +341 -0
- package/dist/state/boundary.js.map +1 -0
- package/dist/state/context.d.ts +138 -0
- package/dist/state/context.d.ts.map +1 -0
- package/dist/state/context.js +139 -0
- package/dist/state/context.js.map +1 -0
- package/dist/state/hooks.d.ts +798 -0
- package/dist/state/hooks.d.ts.map +1 -0
- package/dist/state/hooks.js +1437 -0
- package/dist/state/hooks.js.map +1 -0
- package/dist/state/index.d.ts +72 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +73 -0
- package/dist/state/index.js.map +1 -0
- package/dist/state/signal.d.ts +223 -0
- package/dist/state/signal.d.ts.map +1 -0
- package/dist/state/signal.js +699 -0
- package/dist/state/signal.js.map +1 -0
- package/dist/state/use-state.d.ts +210 -0
- package/dist/state/use-state.d.ts.map +1 -0
- package/dist/state/use-state.js +327 -0
- package/dist/state/use-state.js.map +1 -0
- package/dist/tentickle-instance.d.ts +285 -0
- package/dist/tentickle-instance.d.ts.map +1 -0
- package/dist/tentickle-instance.js +700 -0
- package/dist/tentickle-instance.js.map +1 -0
- package/dist/testing/act.d.ts +59 -0
- package/dist/testing/act.d.ts.map +1 -0
- package/dist/testing/act.js +92 -0
- package/dist/testing/act.js.map +1 -0
- package/dist/testing/async-helpers.d.ts +99 -0
- package/dist/testing/async-helpers.d.ts.map +1 -0
- package/dist/testing/async-helpers.js +193 -0
- package/dist/testing/async-helpers.js.map +1 -0
- package/dist/testing/compile-agent.d.ts +101 -0
- package/dist/testing/compile-agent.d.ts.map +1 -0
- package/dist/testing/compile-agent.js +136 -0
- package/dist/testing/compile-agent.js.map +1 -0
- package/dist/testing/index.d.ts +57 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +59 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-app.d.ts +163 -0
- package/dist/testing/mock-app.d.ts.map +1 -0
- package/dist/testing/mock-app.js +393 -0
- package/dist/testing/mock-app.js.map +1 -0
- package/dist/testing/mocks.d.ts +142 -0
- package/dist/testing/mocks.d.ts.map +1 -0
- package/dist/testing/mocks.js +191 -0
- package/dist/testing/mocks.js.map +1 -0
- package/dist/testing/render-agent.d.ts +146 -0
- package/dist/testing/render-agent.d.ts.map +1 -0
- package/dist/testing/render-agent.js +200 -0
- package/dist/testing/render-agent.js.map +1 -0
- package/dist/testing/test-adapter.d.ts +157 -0
- package/dist/testing/test-adapter.d.ts.map +1 -0
- package/dist/testing/test-adapter.js +297 -0
- package/dist/testing/test-adapter.js.map +1 -0
- package/dist/testing/test-model.d.ts +132 -0
- package/dist/testing/test-model.d.ts.map +1 -0
- package/dist/testing/test-model.js +260 -0
- package/dist/testing/test-model.js.map +1 -0
- package/dist/tool/index.d.ts +61 -0
- package/dist/tool/index.d.ts.map +1 -0
- package/dist/tool/index.js +63 -0
- package/dist/tool/index.js.map +1 -0
- package/dist/tool/tool-hooks.d.ts +45 -0
- package/dist/tool/tool-hooks.d.ts.map +1 -0
- package/dist/tool/tool-hooks.js +35 -0
- package/dist/tool/tool-hooks.js.map +1 -0
- package/dist/tool/tool.d.ts +403 -0
- package/dist/tool/tool.d.ts.map +1 -0
- package/dist/tool/tool.js +176 -0
- package/dist/tool/tool.js.map +1 -0
- package/dist/types.d.ts +442 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +97 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/abort-utils.d.ts +5 -0
- package/dist/utils/abort-utils.d.ts.map +1 -0
- package/dist/utils/abort-utils.js +50 -0
- package/dist/utils/abort-utils.js.map +1 -0
- package/dist/utils/classify-error.d.ts +19 -0
- package/dist/utils/classify-error.d.ts.map +1 -0
- package/dist/utils/classify-error.js +77 -0
- package/dist/utils/classify-error.js.map +1 -0
- package/dist/utils/index.d.ts +21 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/normalization.d.ts +6 -0
- package/dist/utils/normalization.d.ts.map +1 -0
- package/dist/utils/normalization.js +103 -0
- package/dist/utils/normalization.js.map +1 -0
- package/dist/utils/registry.d.ts +15 -0
- package/dist/utils/registry.d.ts.map +1 -0
- package/dist/utils/registry.js +28 -0
- package/dist/utils/registry.js.map +1 -0
- package/dist/utils/schema.d.ts +7 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +13 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/token-estimate.d.ts +87 -0
- package/dist/utils/token-estimate.d.ts.map +1 -0
- package/dist/utils/token-estimate.js +199 -0
- package/dist/utils/token-estimate.js.map +1 -0
- package/dist/v2/reconciler/host-config.d.ts +31 -0
- package/dist/v2/reconciler/host-config.d.ts.map +1 -0
- package/dist/v2/reconciler/host-config.js +197 -0
- package/dist/v2/reconciler/host-config.js.map +1 -0
- package/dist/v2/reconciler/index.d.ts +7 -0
- package/dist/v2/reconciler/index.d.ts.map +1 -0
- package/dist/v2/reconciler/index.js +7 -0
- package/dist/v2/reconciler/index.js.map +1 -0
- package/dist/v2/reconciler/reconciler.d.ts +39 -0
- package/dist/v2/reconciler/reconciler.d.ts.map +1 -0
- package/dist/v2/reconciler/reconciler.js +54 -0
- package/dist/v2/reconciler/reconciler.js.map +1 -0
- package/dist/v2/reconciler/types.d.ts +64 -0
- package/dist/v2/reconciler/types.d.ts.map +1 -0
- package/dist/v2/reconciler/types.js +20 -0
- package/dist/v2/reconciler/types.js.map +1 -0
- package/dist/v2/renderers/index.d.ts +7 -0
- package/dist/v2/renderers/index.d.ts.map +1 -0
- package/dist/v2/renderers/index.js +7 -0
- package/dist/v2/renderers/index.js.map +1 -0
- package/dist/v2/renderers/markdown.d.ts +16 -0
- package/dist/v2/renderers/markdown.d.ts.map +1 -0
- package/dist/v2/renderers/markdown.js +65 -0
- package/dist/v2/renderers/markdown.js.map +1 -0
- package/dist/v2/renderers/types.d.ts +26 -0
- package/dist/v2/renderers/types.d.ts.map +1 -0
- package/dist/v2/renderers/types.js +6 -0
- package/dist/v2/renderers/types.js.map +1 -0
- package/dist/v2/renderers/xml.d.ts +17 -0
- package/dist/v2/renderers/xml.d.ts.map +1 -0
- package/dist/v2/renderers/xml.js +73 -0
- package/dist/v2/renderers/xml.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP (Model Context Protocol) Types
|
|
3
|
+
*
|
|
4
|
+
* Configuration types for MCP integration using @modelcontextprotocol/sdk
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Cursor-style MCP server configuration (simplified format)
|
|
8
|
+
* Used for both EngineConfig.mcpServers and MCPToolComponent config
|
|
9
|
+
*/
|
|
10
|
+
export interface MCPServerConfig {
|
|
11
|
+
command: string;
|
|
12
|
+
args?: string[];
|
|
13
|
+
env?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* MCP transport types
|
|
17
|
+
* Note: 'websocket' maps to StreamableHTTP in the SDK
|
|
18
|
+
*/
|
|
19
|
+
export type MCPTransport = "stdio" | "sse" | "websocket";
|
|
20
|
+
/**
|
|
21
|
+
* MCP server configuration
|
|
22
|
+
*/
|
|
23
|
+
export interface MCPConfig {
|
|
24
|
+
/**
|
|
25
|
+
* Unique identifier for this MCP server connection
|
|
26
|
+
*/
|
|
27
|
+
serverName: string;
|
|
28
|
+
/**
|
|
29
|
+
* Transport type for MCP communication
|
|
30
|
+
*/
|
|
31
|
+
transport: MCPTransport;
|
|
32
|
+
/**
|
|
33
|
+
* Connection details (transport-specific)
|
|
34
|
+
*/
|
|
35
|
+
connection: {
|
|
36
|
+
/**
|
|
37
|
+
* For stdio: command and args to spawn
|
|
38
|
+
*/
|
|
39
|
+
command?: string;
|
|
40
|
+
args?: string[];
|
|
41
|
+
/**
|
|
42
|
+
* For SSE/StreamableHTTP: server URL
|
|
43
|
+
*/
|
|
44
|
+
url?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Additional transport-specific options
|
|
47
|
+
*/
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Optional authentication
|
|
52
|
+
*/
|
|
53
|
+
auth?: {
|
|
54
|
+
type: "bearer" | "api_key" | "custom";
|
|
55
|
+
token?: string;
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* MCP tool definition (from server)
|
|
61
|
+
* Matches the SDK's Tool type structure
|
|
62
|
+
*/
|
|
63
|
+
export interface MCPToolDefinition {
|
|
64
|
+
name: string;
|
|
65
|
+
description: string;
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: "object";
|
|
68
|
+
properties: Record<string, any>;
|
|
69
|
+
required?: string[];
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,KAAK,GAAG,WAAW,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,SAAS,EAAE,YAAY,CAAC;IAExB;;OAEG;IACH,UAAU,EAAE;QACV;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAEhB;;WAEG;QACH,GAAG,CAAC,EAAE,MAAM,CAAC;QAEb;;WAEG;QACH,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IAEF;;OAEG;IACH,IAAI,CAAC,EAAE;QACL,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;QACtC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Middleware } from "@agentick/kernel";
|
|
2
|
+
/**
|
|
3
|
+
* Error normalization middleware for engine procedures.
|
|
4
|
+
*
|
|
5
|
+
* Normalizes errors to EngineError format, classifies them, and determines recoverability.
|
|
6
|
+
* This allows components and error handlers to work with a consistent error format.
|
|
7
|
+
*/
|
|
8
|
+
export declare const errorMiddleware: Middleware;
|
|
9
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/middleware/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,kBAAkB,CAAC;AAIvE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,UAyC7B,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Context, Telemetry } from "@agentick/kernel";
|
|
2
|
+
import {} from "../component/component";
|
|
3
|
+
import { classifyError, isRecoverableError } from "../utils/classify-error";
|
|
4
|
+
/**
|
|
5
|
+
* Error normalization middleware for engine procedures.
|
|
6
|
+
*
|
|
7
|
+
* Normalizes errors to EngineError format, classifies them, and determines recoverability.
|
|
8
|
+
* This allows components and error handlers to work with a consistent error format.
|
|
9
|
+
*/
|
|
10
|
+
export const errorMiddleware = async (args, envelope, next) => {
|
|
11
|
+
try {
|
|
12
|
+
return await next(args);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
// Don't wrap abort errors - let them propagate as-is
|
|
16
|
+
if (error?.name === "AbortError" || error?.message?.includes("aborted")) {
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
// Normalize error to Error instance if needed
|
|
20
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
21
|
+
// Classify the error
|
|
22
|
+
const errorType = classifyError(error);
|
|
23
|
+
const recoverable = isRecoverableError(error);
|
|
24
|
+
// Create EngineError with context (attached to normalized error for downstream handlers)
|
|
25
|
+
const _engineError = {
|
|
26
|
+
error: normalizedError,
|
|
27
|
+
phase: "unknown", // Middleware doesn't know the phase - will be set by engine if needed
|
|
28
|
+
recoverable,
|
|
29
|
+
context: {
|
|
30
|
+
error_type: errorType,
|
|
31
|
+
error_code: error.code,
|
|
32
|
+
error_status: error.status,
|
|
33
|
+
trace_id: Context.tryGet()?.traceId,
|
|
34
|
+
procedure_pid: Context.tryGet()?.procedurePid,
|
|
35
|
+
// Add any other relevant context
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
// Note: EngineError is created for future use when error handlers access it
|
|
39
|
+
// (normalizedError as any).engineError = _engineError;
|
|
40
|
+
// Record error in telemetry
|
|
41
|
+
Telemetry.recordError(normalizedError);
|
|
42
|
+
// Re-throw the normalized error
|
|
43
|
+
// Downstream handlers can access engineError via error.engineError
|
|
44
|
+
throw normalizedError;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/middleware/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAoB,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAe,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;IACxE,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,qDAAqD;QACrD,IAAI,KAAK,EAAE,IAAI,KAAK,YAAY,IAAI,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACxE,MAAM,KAAK,CAAC;QACd,CAAC;QAED,8CAA8C;QAC9C,MAAM,eAAe,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAElF,qBAAqB;QACrB,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE9C,yFAAyF;QACzF,MAAM,YAAY,GAAgB;YAChC,KAAK,EAAE,eAAe;YACtB,KAAK,EAAE,SAAS,EAAE,sEAAsE;YACxF,WAAW;YACX,OAAO,EAAE;gBACP,UAAU,EAAE,SAAS;gBACrB,UAAU,EAAE,KAAK,CAAC,IAAI;gBACtB,YAAY,EAAE,KAAK,CAAC,MAAM;gBAC1B,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,OAAO;gBACnC,aAAa,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,YAAY;gBAC7C,iCAAiC;aAClC;SACF,CAAC;QAEF,4EAA4E;QAC5E,uDAAuD;QAEvD,4BAA4B;QAC5B,SAAS,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;QAEvC,gCAAgC;QAChC,mEAAmE;QACnE,MAAM,eAAe,CAAC;IACxB,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter Helpers - Composable utilities for building adapters
|
|
3
|
+
*
|
|
4
|
+
* These are opt-in helpers adapters can import and use.
|
|
5
|
+
* No magic, no DSLs - just functions.
|
|
6
|
+
*
|
|
7
|
+
* @module agentick/model/adapter-helpers
|
|
8
|
+
*/
|
|
9
|
+
import type { ContentBlock, Message, UsageStats } from "@agentick/shared";
|
|
10
|
+
import { StopReason } from "@agentick/shared";
|
|
11
|
+
/**
|
|
12
|
+
* Extract system messages into a single string, return the rest.
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractSystemPrompt(messages: Message[]): {
|
|
15
|
+
system: string | undefined;
|
|
16
|
+
messages: Message[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Group consecutive tool results by their preceding assistant message.
|
|
20
|
+
* Useful for providers that expect tool results immediately after tool calls.
|
|
21
|
+
*/
|
|
22
|
+
export declare function groupToolResults(messages: Message[]): Array<{
|
|
23
|
+
message: Message;
|
|
24
|
+
toolResults?: Message;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Normalize message - handle string messages, ensure content array exists.
|
|
28
|
+
*/
|
|
29
|
+
export declare function normalizeMessage(msg: Message | string): Message;
|
|
30
|
+
/**
|
|
31
|
+
* Filter empty messages (no content blocks).
|
|
32
|
+
*/
|
|
33
|
+
export declare function filterEmptyMessages(messages: Message[]): Message[];
|
|
34
|
+
/**
|
|
35
|
+
* Extract text from content blocks.
|
|
36
|
+
*/
|
|
37
|
+
export declare function extractText(content: ContentBlock[]): string;
|
|
38
|
+
/**
|
|
39
|
+
* Extract text blocks only.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getTextBlocks(content: ContentBlock[]): Array<{
|
|
42
|
+
type: "text";
|
|
43
|
+
text: string;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Check if content has any images.
|
|
47
|
+
*/
|
|
48
|
+
export declare function hasImages(content: ContentBlock[]): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Check if content has any tool uses.
|
|
51
|
+
*/
|
|
52
|
+
export declare function hasToolUses(content: ContentBlock[]): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Get tool use blocks from content.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getToolUseBlocks(content: ContentBlock[]): Array<{
|
|
57
|
+
type: "tool_use";
|
|
58
|
+
toolUseId: string;
|
|
59
|
+
name: string;
|
|
60
|
+
input: Record<string, unknown>;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Get tool result blocks from content.
|
|
64
|
+
*/
|
|
65
|
+
export declare function getToolResultBlocks(content: ContentBlock[]): Array<{
|
|
66
|
+
type: "tool_result";
|
|
67
|
+
toolUseId: string;
|
|
68
|
+
name: string;
|
|
69
|
+
content: ContentBlock[];
|
|
70
|
+
isError?: boolean;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Get image as base64 data (if available).
|
|
74
|
+
*/
|
|
75
|
+
export declare function imageToBase64(block: ContentBlock): string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Get image as URL (if available).
|
|
78
|
+
*/
|
|
79
|
+
export declare function imageToUrl(block: ContentBlock): string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Get image mime type.
|
|
82
|
+
*/
|
|
83
|
+
export declare function imageMimeType(block: ContentBlock): string | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Check if image is base64.
|
|
86
|
+
*/
|
|
87
|
+
export declare function isBase64Image(block: ContentBlock): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Check if image is URL.
|
|
90
|
+
*/
|
|
91
|
+
export declare function isUrlImage(block: ContentBlock): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Get document as base64 data (if available).
|
|
94
|
+
*/
|
|
95
|
+
export declare function documentToBase64(block: ContentBlock): string | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Get document as URL (if available).
|
|
98
|
+
*/
|
|
99
|
+
export declare function documentToUrl(block: ContentBlock): string | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Normalize tool reference to { name, description, input } shape.
|
|
102
|
+
*/
|
|
103
|
+
export declare function normalizeToolDefinition(tool: unknown): {
|
|
104
|
+
name: string;
|
|
105
|
+
description: string;
|
|
106
|
+
input: unknown;
|
|
107
|
+
} | null;
|
|
108
|
+
/**
|
|
109
|
+
* Convert tool input schema to JSON Schema (if it's a Zod schema).
|
|
110
|
+
* Returns the schema as-is if it's already JSON Schema.
|
|
111
|
+
*/
|
|
112
|
+
export declare function toJsonSchema(schema: unknown): unknown;
|
|
113
|
+
/**
|
|
114
|
+
* Convert tool result content to simple text/json format.
|
|
115
|
+
* Useful for providers that expect simple tool outputs.
|
|
116
|
+
*/
|
|
117
|
+
export declare function toolResultToSimple(content: ContentBlock[], isError?: boolean): {
|
|
118
|
+
type: "text" | "json" | "error";
|
|
119
|
+
value: unknown;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Normalize usage stats from various provider formats.
|
|
123
|
+
*/
|
|
124
|
+
export declare function normalizeUsage(raw: Record<string, unknown> | undefined): UsageStats;
|
|
125
|
+
/**
|
|
126
|
+
* Merge two usage stats (take max of each field).
|
|
127
|
+
*/
|
|
128
|
+
export declare function mergeUsage(a: UsageStats, b: Partial<UsageStats>): UsageStats;
|
|
129
|
+
/**
|
|
130
|
+
* Common stop reason mappings for various providers.
|
|
131
|
+
*/
|
|
132
|
+
export declare const STOP_REASON_MAP: {
|
|
133
|
+
readonly stop: StopReason.STOP;
|
|
134
|
+
readonly length: StopReason.MAX_TOKENS;
|
|
135
|
+
readonly tool_calls: StopReason.TOOL_USE;
|
|
136
|
+
readonly content_filter: StopReason.CONTENT_FILTER;
|
|
137
|
+
readonly function_call: StopReason.TOOL_USE;
|
|
138
|
+
readonly end_turn: StopReason.STOP;
|
|
139
|
+
readonly max_tokens: StopReason.MAX_TOKENS;
|
|
140
|
+
readonly stop_sequence: StopReason.STOP;
|
|
141
|
+
readonly "tool-calls": StopReason.TOOL_USE;
|
|
142
|
+
readonly other: StopReason.OTHER;
|
|
143
|
+
readonly error: StopReason.ERROR;
|
|
144
|
+
readonly STOP: StopReason.STOP;
|
|
145
|
+
readonly MAX_TOKENS: StopReason.MAX_TOKENS;
|
|
146
|
+
readonly SAFETY: StopReason.CONTENT_FILTER;
|
|
147
|
+
readonly RECITATION: StopReason.CONTENT_FILTER;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Map provider stop reason string to StopReason enum.
|
|
151
|
+
*/
|
|
152
|
+
export declare function mapStopReason(reason: string | undefined): StopReason;
|
|
153
|
+
/**
|
|
154
|
+
* Safely get a nested field from an object.
|
|
155
|
+
*/
|
|
156
|
+
export declare function getField<T = unknown>(obj: unknown, ...path: string[]): T | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Check if chunk has a specific type field.
|
|
159
|
+
*/
|
|
160
|
+
export declare function isChunkType(chunk: unknown, type: string): boolean;
|
|
161
|
+
//# sourceMappingURL=adapter-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-helpers.d.ts","sourceRoot":"","sources":["../../src/model/adapter-helpers.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter Helpers - Composable utilities for building adapters
|
|
3
|
+
*
|
|
4
|
+
* These are opt-in helpers adapters can import and use.
|
|
5
|
+
* No magic, no DSLs - just functions.
|
|
6
|
+
*
|
|
7
|
+
* @module agentick/model/adapter-helpers
|
|
8
|
+
*/
|
|
9
|
+
import { StopReason } from "@agentick/shared";
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Message Helpers
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Extract system messages into a single string, return the rest.
|
|
15
|
+
*/
|
|
16
|
+
export function extractSystemPrompt(messages) {
|
|
17
|
+
let system;
|
|
18
|
+
const rest = [];
|
|
19
|
+
for (const msg of messages) {
|
|
20
|
+
if (msg.role === "system") {
|
|
21
|
+
const text = msg.content
|
|
22
|
+
.filter((b) => b.type === "text")
|
|
23
|
+
.map((b) => b.text)
|
|
24
|
+
.join("\n\n");
|
|
25
|
+
system = system ? `${system}\n\n${text}` : text;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
rest.push(msg);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { system, messages: rest };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Group consecutive tool results by their preceding assistant message.
|
|
35
|
+
* Useful for providers that expect tool results immediately after tool calls.
|
|
36
|
+
*/
|
|
37
|
+
export function groupToolResults(messages) {
|
|
38
|
+
const result = [];
|
|
39
|
+
for (let i = 0; i < messages.length; i++) {
|
|
40
|
+
const msg = messages[i];
|
|
41
|
+
if (msg.role === "tool") {
|
|
42
|
+
// Attach to previous entry if it was assistant
|
|
43
|
+
if (result.length > 0 && result[result.length - 1].message.role === "assistant") {
|
|
44
|
+
result[result.length - 1].toolResults = msg;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Orphan tool result - include anyway
|
|
48
|
+
result.push({ message: msg });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
result.push({ message: msg });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Normalize message - handle string messages, ensure content array exists.
|
|
59
|
+
*/
|
|
60
|
+
export function normalizeMessage(msg) {
|
|
61
|
+
if (typeof msg === "string") {
|
|
62
|
+
return { role: "user", content: [{ type: "text", text: msg }] };
|
|
63
|
+
}
|
|
64
|
+
return msg;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Filter empty messages (no content blocks).
|
|
68
|
+
*/
|
|
69
|
+
export function filterEmptyMessages(messages) {
|
|
70
|
+
return messages.filter((m) => m.content && m.content.length > 0);
|
|
71
|
+
}
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// Content Block Helpers
|
|
74
|
+
// ============================================================================
|
|
75
|
+
/**
|
|
76
|
+
* Extract text from content blocks.
|
|
77
|
+
*/
|
|
78
|
+
export function extractText(content) {
|
|
79
|
+
return content
|
|
80
|
+
.filter((b) => b.type === "text")
|
|
81
|
+
.map((b) => b.text)
|
|
82
|
+
.join("");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Extract text blocks only.
|
|
86
|
+
*/
|
|
87
|
+
export function getTextBlocks(content) {
|
|
88
|
+
return content.filter((b) => b.type === "text");
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Check if content has any images.
|
|
92
|
+
*/
|
|
93
|
+
export function hasImages(content) {
|
|
94
|
+
return content.some((b) => b.type === "image");
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if content has any tool uses.
|
|
98
|
+
*/
|
|
99
|
+
export function hasToolUses(content) {
|
|
100
|
+
return content.some((b) => b.type === "tool_use");
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get tool use blocks from content.
|
|
104
|
+
*/
|
|
105
|
+
export function getToolUseBlocks(content) {
|
|
106
|
+
return content.filter((b) => b.type === "tool_use");
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get tool result blocks from content.
|
|
110
|
+
*/
|
|
111
|
+
export function getToolResultBlocks(content) {
|
|
112
|
+
return content.filter((b) => b.type === "tool_result");
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get image as base64 data (if available).
|
|
116
|
+
*/
|
|
117
|
+
export function imageToBase64(block) {
|
|
118
|
+
if (block.type !== "image")
|
|
119
|
+
return undefined;
|
|
120
|
+
const img = block;
|
|
121
|
+
if (img.source.type === "base64")
|
|
122
|
+
return img.source.data;
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get image as URL (if available).
|
|
127
|
+
*/
|
|
128
|
+
export function imageToUrl(block) {
|
|
129
|
+
if (block.type !== "image")
|
|
130
|
+
return undefined;
|
|
131
|
+
const img = block;
|
|
132
|
+
if (img.source.type === "url")
|
|
133
|
+
return img.source.url;
|
|
134
|
+
// Could also construct data: URL from base64
|
|
135
|
+
if (img.source.type === "base64") {
|
|
136
|
+
const mimeType = img.mimeType || "image/png";
|
|
137
|
+
return `data:${mimeType};base64,${img.source.data}`;
|
|
138
|
+
}
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get image mime type.
|
|
143
|
+
*/
|
|
144
|
+
export function imageMimeType(block) {
|
|
145
|
+
if (block.type !== "image")
|
|
146
|
+
return undefined;
|
|
147
|
+
const img = block;
|
|
148
|
+
return img.mimeType;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if image is base64.
|
|
152
|
+
*/
|
|
153
|
+
export function isBase64Image(block) {
|
|
154
|
+
if (block.type !== "image")
|
|
155
|
+
return false;
|
|
156
|
+
return block.source.type === "base64";
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Check if image is URL.
|
|
160
|
+
*/
|
|
161
|
+
export function isUrlImage(block) {
|
|
162
|
+
if (block.type !== "image")
|
|
163
|
+
return false;
|
|
164
|
+
return block.source.type === "url";
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get document as base64 data (if available).
|
|
168
|
+
*/
|
|
169
|
+
export function documentToBase64(block) {
|
|
170
|
+
if (block.type !== "document")
|
|
171
|
+
return undefined;
|
|
172
|
+
const doc = block;
|
|
173
|
+
if (doc.source.type === "base64")
|
|
174
|
+
return doc.source.data;
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get document as URL (if available).
|
|
179
|
+
*/
|
|
180
|
+
export function documentToUrl(block) {
|
|
181
|
+
if (block.type !== "document")
|
|
182
|
+
return undefined;
|
|
183
|
+
const doc = block;
|
|
184
|
+
if (doc.source.type === "url")
|
|
185
|
+
return doc.source.url;
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// Tool Definition Helpers
|
|
190
|
+
// ============================================================================
|
|
191
|
+
/**
|
|
192
|
+
* Normalize tool reference to { name, description, input } shape.
|
|
193
|
+
*/
|
|
194
|
+
export function normalizeToolDefinition(tool) {
|
|
195
|
+
if (!tool || typeof tool !== "object")
|
|
196
|
+
return null;
|
|
197
|
+
// ExecutableTool shape: { metadata: { name, description, input } }
|
|
198
|
+
if ("metadata" in tool && typeof tool.metadata === "object") {
|
|
199
|
+
const meta = tool.metadata;
|
|
200
|
+
return {
|
|
201
|
+
name: meta.name || "",
|
|
202
|
+
description: meta.description || "",
|
|
203
|
+
input: meta.input,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
// ToolDefinition shape: { name, description, input }
|
|
207
|
+
if ("name" in tool) {
|
|
208
|
+
return {
|
|
209
|
+
name: tool.name || "",
|
|
210
|
+
description: tool.description || "",
|
|
211
|
+
input: tool.input,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Convert tool input schema to JSON Schema (if it's a Zod schema).
|
|
218
|
+
* Returns the schema as-is if it's already JSON Schema.
|
|
219
|
+
*/
|
|
220
|
+
export function toJsonSchema(schema) {
|
|
221
|
+
if (!schema)
|
|
222
|
+
return {};
|
|
223
|
+
// Check if it's a Zod schema (has _def property)
|
|
224
|
+
if (typeof schema === "object" && "_def" in schema) {
|
|
225
|
+
// Zod schema - would need zod-to-json-schema to convert
|
|
226
|
+
// For now, return as-is and let the adapter handle it
|
|
227
|
+
return schema;
|
|
228
|
+
}
|
|
229
|
+
// Already JSON Schema or plain object
|
|
230
|
+
return schema;
|
|
231
|
+
}
|
|
232
|
+
// ============================================================================
|
|
233
|
+
// Tool Result Helpers
|
|
234
|
+
// ============================================================================
|
|
235
|
+
/**
|
|
236
|
+
* Convert tool result content to simple text/json format.
|
|
237
|
+
* Useful for providers that expect simple tool outputs.
|
|
238
|
+
*/
|
|
239
|
+
export function toolResultToSimple(content, isError) {
|
|
240
|
+
if (!content || content.length === 0) {
|
|
241
|
+
return { type: isError ? "error" : "text", value: isError ? "Error" : "Success" };
|
|
242
|
+
}
|
|
243
|
+
// Single text block
|
|
244
|
+
if (content.length === 1 && content[0].type === "text") {
|
|
245
|
+
const text = content[0].text;
|
|
246
|
+
return { type: isError ? "error" : "text", value: text };
|
|
247
|
+
}
|
|
248
|
+
// Single JSON block
|
|
249
|
+
if (content.length === 1 && content[0].type === "json") {
|
|
250
|
+
const json = content[0];
|
|
251
|
+
const value = json.data ?? (json.text ? JSON.parse(json.text) : {});
|
|
252
|
+
return { type: isError ? "error" : "json", value };
|
|
253
|
+
}
|
|
254
|
+
// Multiple blocks - combine as text
|
|
255
|
+
const text = content
|
|
256
|
+
.map((b) => {
|
|
257
|
+
if (b.type === "text")
|
|
258
|
+
return b.text;
|
|
259
|
+
if (b.type === "json") {
|
|
260
|
+
const j = b;
|
|
261
|
+
return j.text || JSON.stringify(j.data);
|
|
262
|
+
}
|
|
263
|
+
return JSON.stringify(b);
|
|
264
|
+
})
|
|
265
|
+
.join("\n");
|
|
266
|
+
return { type: isError ? "error" : "text", value: text };
|
|
267
|
+
}
|
|
268
|
+
// ============================================================================
|
|
269
|
+
// Usage Helpers
|
|
270
|
+
// ============================================================================
|
|
271
|
+
/**
|
|
272
|
+
* Normalize usage stats from various provider formats.
|
|
273
|
+
*/
|
|
274
|
+
export function normalizeUsage(raw) {
|
|
275
|
+
if (!raw)
|
|
276
|
+
return { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
277
|
+
const inputTokens = (raw.inputTokens ?? raw.promptTokens ?? raw.prompt_tokens ?? 0);
|
|
278
|
+
const outputTokens = (raw.outputTokens ??
|
|
279
|
+
raw.completionTokens ??
|
|
280
|
+
raw.completion_tokens ??
|
|
281
|
+
0);
|
|
282
|
+
const totalTokens = (raw.totalTokens ?? raw.total_tokens ?? inputTokens + outputTokens);
|
|
283
|
+
return { inputTokens, outputTokens, totalTokens };
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Merge two usage stats (take max of each field).
|
|
287
|
+
*/
|
|
288
|
+
export function mergeUsage(a, b) {
|
|
289
|
+
return {
|
|
290
|
+
inputTokens: Math.max(a.inputTokens, b.inputTokens ?? 0),
|
|
291
|
+
outputTokens: Math.max(a.outputTokens, b.outputTokens ?? 0),
|
|
292
|
+
totalTokens: Math.max(a.totalTokens, b.totalTokens ?? 0),
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
// ============================================================================
|
|
296
|
+
// Stop Reason Helpers
|
|
297
|
+
// ============================================================================
|
|
298
|
+
/**
|
|
299
|
+
* Common stop reason mappings for various providers.
|
|
300
|
+
*/
|
|
301
|
+
export const STOP_REASON_MAP = {
|
|
302
|
+
// OpenAI
|
|
303
|
+
stop: StopReason.STOP,
|
|
304
|
+
length: StopReason.MAX_TOKENS,
|
|
305
|
+
tool_calls: StopReason.TOOL_USE,
|
|
306
|
+
content_filter: StopReason.CONTENT_FILTER,
|
|
307
|
+
function_call: StopReason.TOOL_USE,
|
|
308
|
+
// Anthropic
|
|
309
|
+
end_turn: StopReason.STOP,
|
|
310
|
+
max_tokens: StopReason.MAX_TOKENS,
|
|
311
|
+
stop_sequence: StopReason.STOP,
|
|
312
|
+
// AI SDK
|
|
313
|
+
"tool-calls": StopReason.TOOL_USE,
|
|
314
|
+
other: StopReason.OTHER,
|
|
315
|
+
error: StopReason.ERROR,
|
|
316
|
+
// Google
|
|
317
|
+
STOP: StopReason.STOP,
|
|
318
|
+
MAX_TOKENS: StopReason.MAX_TOKENS,
|
|
319
|
+
SAFETY: StopReason.CONTENT_FILTER,
|
|
320
|
+
RECITATION: StopReason.CONTENT_FILTER,
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Map provider stop reason string to StopReason enum.
|
|
324
|
+
*/
|
|
325
|
+
export function mapStopReason(reason) {
|
|
326
|
+
if (!reason)
|
|
327
|
+
return StopReason.UNSPECIFIED;
|
|
328
|
+
return STOP_REASON_MAP[reason] ?? StopReason.UNSPECIFIED;
|
|
329
|
+
}
|
|
330
|
+
// ============================================================================
|
|
331
|
+
// Chunk Helpers (for mapChunk implementations)
|
|
332
|
+
// ============================================================================
|
|
333
|
+
/**
|
|
334
|
+
* Safely get a nested field from an object.
|
|
335
|
+
*/
|
|
336
|
+
export function getField(obj, ...path) {
|
|
337
|
+
let current = obj;
|
|
338
|
+
for (const key of path) {
|
|
339
|
+
if (current == null || typeof current !== "object")
|
|
340
|
+
return undefined;
|
|
341
|
+
current = current[key];
|
|
342
|
+
}
|
|
343
|
+
return current;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Check if chunk has a specific type field.
|
|
347
|
+
*/
|
|
348
|
+
export function isChunkType(chunk, type) {
|
|
349
|
+
return typeof chunk === "object" && chunk !== null && chunk.type === type;
|
|
350
|
+
}
|
|
351
|
+
//# sourceMappingURL=adapter-helpers.js.map
|