@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,1461 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mark II App Types
|
|
3
|
+
*
|
|
4
|
+
* Essential type definitions for the createApp API.
|
|
5
|
+
*
|
|
6
|
+
* Design principles:
|
|
7
|
+
* - All sessions are persistent sessions
|
|
8
|
+
* - Ephemeral execution = create session → send → close immediately
|
|
9
|
+
* - Session is an EventEmitter that emits streaming events
|
|
10
|
+
* - Props are inputs, SendResult is output
|
|
11
|
+
*
|
|
12
|
+
* @module agentick/app
|
|
13
|
+
*/
|
|
14
|
+
import type { EventEmitter } from "node:events";
|
|
15
|
+
import type { Message, StreamEvent as SharedStreamEvent, ToolCall, UsageStats, TimelineEntry, SendInput as SharedSendInput, ContentBlock } from "@agentick/shared";
|
|
16
|
+
import type { COMInput } from "../com/types";
|
|
17
|
+
import type { ExecutableTool } from "../tool/tool";
|
|
18
|
+
import type { MCPConfig } from "../mcp";
|
|
19
|
+
import type { EngineModel } from "../model/model";
|
|
20
|
+
import type { ExecutionHandle, Channel, Procedure } from "@agentick/kernel";
|
|
21
|
+
import type { JSX } from "../jsx/jsx-runtime";
|
|
22
|
+
import type { SchedulerState } from "../compiler/scheduler";
|
|
23
|
+
/**
|
|
24
|
+
* Lifecycle callbacks for session execution.
|
|
25
|
+
*
|
|
26
|
+
* These provide a cleaner alternative to event listeners for common
|
|
27
|
+
* lifecycle events. Callbacks defined on AppOptions are inherited by
|
|
28
|
+
* all sessions; callbacks on SessionOptions override or supplement them.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const app = createApp(MyAgent, {
|
|
33
|
+
* model,
|
|
34
|
+
* onTickStart: (tick) => console.log(`Tick ${tick} starting`),
|
|
35
|
+
* onComplete: (result) => console.log(`Done: ${result.response}`),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Session can add its own callbacks
|
|
39
|
+
* const session = app.session({
|
|
40
|
+
* onEvent: (event) => { ... }, // Receives all events
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export interface LifecycleCallbacks {
|
|
45
|
+
/**
|
|
46
|
+
* Called for every stream event.
|
|
47
|
+
* Use this for fine-grained event handling.
|
|
48
|
+
*/
|
|
49
|
+
onEvent?: (event: StreamEvent) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Called when a tick starts.
|
|
52
|
+
* @param tick - The tick number (1-indexed)
|
|
53
|
+
* @param executionId - The execution ID
|
|
54
|
+
*/
|
|
55
|
+
onTickStart?: (tick: number, executionId: string) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Called when a tick ends.
|
|
58
|
+
* @param tick - The tick number
|
|
59
|
+
* @param usage - Token usage for this tick
|
|
60
|
+
*/
|
|
61
|
+
onTickEnd?: (tick: number, usage?: UsageStats) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Called when execution completes successfully.
|
|
64
|
+
* @param result - The final result
|
|
65
|
+
*/
|
|
66
|
+
onComplete?: (result: SendResult) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Called when an error occurs during execution.
|
|
69
|
+
* @param error - The error that occurred
|
|
70
|
+
*/
|
|
71
|
+
onError?: (error: Error) => void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Storage adapter for persisting hibernated sessions.
|
|
75
|
+
*
|
|
76
|
+
* Implement this interface to enable session hibernation with your storage backend
|
|
77
|
+
* (Redis, database, filesystem, etc.).
|
|
78
|
+
*
|
|
79
|
+
* @example In-memory implementation
|
|
80
|
+
* ```typescript
|
|
81
|
+
* class MemorySessionStore implements SessionStore {
|
|
82
|
+
* private store = new Map<string, SessionSnapshot>();
|
|
83
|
+
*
|
|
84
|
+
* async save(sessionId: string, snapshot: SessionSnapshot) {
|
|
85
|
+
* this.store.set(sessionId, snapshot);
|
|
86
|
+
* }
|
|
87
|
+
*
|
|
88
|
+
* async load(sessionId: string) {
|
|
89
|
+
* return this.store.get(sessionId) ?? null;
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* async delete(sessionId: string) {
|
|
93
|
+
* this.store.delete(sessionId);
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Redis implementation
|
|
99
|
+
* ```typescript
|
|
100
|
+
* class RedisSessionStore implements SessionStore {
|
|
101
|
+
* constructor(private redis: Redis, private prefix = 'session:') {}
|
|
102
|
+
*
|
|
103
|
+
* async save(sessionId: string, snapshot: SessionSnapshot) {
|
|
104
|
+
* await this.redis.set(
|
|
105
|
+
* this.prefix + sessionId,
|
|
106
|
+
* JSON.stringify(snapshot),
|
|
107
|
+
* 'EX', 86400 // 24 hour TTL
|
|
108
|
+
* );
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* async load(sessionId: string) {
|
|
112
|
+
* const data = await this.redis.get(this.prefix + sessionId);
|
|
113
|
+
* return data ? JSON.parse(data) : null;
|
|
114
|
+
* }
|
|
115
|
+
*
|
|
116
|
+
* async delete(sessionId: string) {
|
|
117
|
+
* await this.redis.del(this.prefix + sessionId);
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export interface SessionStore {
|
|
123
|
+
/**
|
|
124
|
+
* Save a session snapshot to storage.
|
|
125
|
+
* Called when a session hibernates.
|
|
126
|
+
*/
|
|
127
|
+
save(sessionId: string, snapshot: SessionSnapshot): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Load a session snapshot from storage.
|
|
130
|
+
* Called when hydrating a hibernated session.
|
|
131
|
+
* Returns null if session not found.
|
|
132
|
+
*/
|
|
133
|
+
load(sessionId: string): Promise<SessionSnapshot | null>;
|
|
134
|
+
/**
|
|
135
|
+
* Delete a session snapshot from storage.
|
|
136
|
+
* Called when a session is permanently closed.
|
|
137
|
+
*/
|
|
138
|
+
delete(sessionId: string): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* List all hibernated session IDs.
|
|
141
|
+
* Optional - used for session discovery/management.
|
|
142
|
+
*/
|
|
143
|
+
list?(): Promise<string[]>;
|
|
144
|
+
/**
|
|
145
|
+
* Check if a hibernated session exists.
|
|
146
|
+
* Optional - optimization to avoid full load when checking existence.
|
|
147
|
+
*/
|
|
148
|
+
has?(sessionId: string): Promise<boolean>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Configuration for the built-in SQLite session store.
|
|
152
|
+
*/
|
|
153
|
+
export interface SqliteStoreConfig {
|
|
154
|
+
type: "sqlite";
|
|
155
|
+
/**
|
|
156
|
+
* Path to SQLite database file.
|
|
157
|
+
* Use ':memory:' for in-memory database (default).
|
|
158
|
+
*/
|
|
159
|
+
path?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Table name for storing sessions.
|
|
162
|
+
* @default 'agentick_sessions'
|
|
163
|
+
*/
|
|
164
|
+
table?: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Store configuration options.
|
|
168
|
+
*
|
|
169
|
+
* Can be:
|
|
170
|
+
* - A string file path for SQLite storage (e.g., './sessions.db')
|
|
171
|
+
* - A SQLite config object with additional options
|
|
172
|
+
* - A custom SessionStore implementation
|
|
173
|
+
*
|
|
174
|
+
* @example SQLite file path
|
|
175
|
+
* ```typescript
|
|
176
|
+
* store: './data/sessions.db'
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @example In-memory SQLite (default)
|
|
180
|
+
* ```typescript
|
|
181
|
+
* store: ':memory:'
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @example SQLite with options
|
|
185
|
+
* ```typescript
|
|
186
|
+
* store: { type: 'sqlite', path: './sessions.db', table: 'my_sessions' }
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @example Custom store (Redis, Postgres, etc.)
|
|
190
|
+
* ```typescript
|
|
191
|
+
* store: new RedisSessionStore(redis)
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export type StoreConfig = string | SqliteStoreConfig | SessionStore;
|
|
195
|
+
/**
|
|
196
|
+
* Session management configuration.
|
|
197
|
+
*
|
|
198
|
+
* Controls how the App manages session lifecycles including
|
|
199
|
+
* hibernation, limits, and auto-cleanup.
|
|
200
|
+
*/
|
|
201
|
+
export interface SessionManagementOptions {
|
|
202
|
+
/**
|
|
203
|
+
* Storage adapter for hibernated sessions.
|
|
204
|
+
*
|
|
205
|
+
* Can be:
|
|
206
|
+
* - A file path string for SQLite storage (e.g., './sessions.db')
|
|
207
|
+
* - `':memory:'` for in-memory SQLite
|
|
208
|
+
* - A `{ type: 'sqlite', ... }` config object
|
|
209
|
+
* - A custom `SessionStore` implementation
|
|
210
|
+
*
|
|
211
|
+
* If not provided, sessions cannot hibernate (they will be closed instead).
|
|
212
|
+
*
|
|
213
|
+
* @example File-based SQLite
|
|
214
|
+
* ```typescript
|
|
215
|
+
* sessions: { store: './data/sessions.db' }
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @example Custom Redis store
|
|
219
|
+
* ```typescript
|
|
220
|
+
* sessions: { store: new RedisSessionStore(redis) }
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
store?: StoreConfig;
|
|
224
|
+
/**
|
|
225
|
+
* Maximum number of active (in-memory) sessions.
|
|
226
|
+
* When exceeded, the least-recently used session is hibernated.
|
|
227
|
+
* @default unlimited
|
|
228
|
+
*/
|
|
229
|
+
maxActive?: number;
|
|
230
|
+
/**
|
|
231
|
+
* Milliseconds of inactivity before auto-hibernating a session.
|
|
232
|
+
* Activity is tracked via send(), render(), queue(), and channel publish.
|
|
233
|
+
* Set to 0 or undefined to disable auto-hibernation.
|
|
234
|
+
*/
|
|
235
|
+
idleTimeout?: number;
|
|
236
|
+
/**
|
|
237
|
+
* Whether to automatically hibernate idle sessions.
|
|
238
|
+
* @default true if store is provided, false otherwise
|
|
239
|
+
*/
|
|
240
|
+
autoHibernate?: boolean;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Configuration options for creating an App instance.
|
|
244
|
+
*
|
|
245
|
+
* AppOptions configure the execution environment - things that apply
|
|
246
|
+
* across all sessions created from this app.
|
|
247
|
+
*/
|
|
248
|
+
export interface AppOptions extends LifecycleCallbacks {
|
|
249
|
+
/**
|
|
250
|
+
* Override model from JSX (for testing/mocking).
|
|
251
|
+
* If not provided, uses the model from <Model> component in JSX tree.
|
|
252
|
+
*/
|
|
253
|
+
model?: EngineModel;
|
|
254
|
+
/**
|
|
255
|
+
* Additional tools to make available.
|
|
256
|
+
* These are merged with tools from <Tool> components in JSX.
|
|
257
|
+
*/
|
|
258
|
+
tools?: ExecutableTool[];
|
|
259
|
+
/**
|
|
260
|
+
* MCP server configurations.
|
|
261
|
+
*/
|
|
262
|
+
mcpServers?: Record<string, MCPConfig>;
|
|
263
|
+
/**
|
|
264
|
+
* Maximum number of ticks before stopping execution.
|
|
265
|
+
* @default 10
|
|
266
|
+
*/
|
|
267
|
+
maxTicks?: number;
|
|
268
|
+
/**
|
|
269
|
+
* Enable DevTools event emission for all sessions created by this app.
|
|
270
|
+
*
|
|
271
|
+
* When true, lifecycle events (execution_start, tick_start, tick_end,
|
|
272
|
+
* execution_end, fiber_snapshot) are emitted to the DevTools emitter.
|
|
273
|
+
*
|
|
274
|
+
* @default false
|
|
275
|
+
*/
|
|
276
|
+
devTools?: boolean;
|
|
277
|
+
/**
|
|
278
|
+
* App-level abort signal.
|
|
279
|
+
* All sessions will respect this signal.
|
|
280
|
+
*/
|
|
281
|
+
signal?: AbortSignal;
|
|
282
|
+
/**
|
|
283
|
+
* Session management configuration.
|
|
284
|
+
*
|
|
285
|
+
* Controls hibernation, limits, and auto-cleanup of sessions.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* const app = createApp(MyAgent, {
|
|
290
|
+
* sessions: {
|
|
291
|
+
* store: new RedisSessionStore(redis),
|
|
292
|
+
* maxActive: 100,
|
|
293
|
+
* idleTimeout: 5 * 60 * 1000, // 5 minutes
|
|
294
|
+
* },
|
|
295
|
+
* });
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
sessions?: SessionManagementOptions;
|
|
299
|
+
/**
|
|
300
|
+
* Called when a session is created.
|
|
301
|
+
*/
|
|
302
|
+
onSessionCreate?: (session: Session) => void;
|
|
303
|
+
/**
|
|
304
|
+
* Called when a session is closed and removed from the registry.
|
|
305
|
+
*/
|
|
306
|
+
onSessionClose?: (sessionId: string) => void;
|
|
307
|
+
/**
|
|
308
|
+
* Called before a session hibernates.
|
|
309
|
+
*
|
|
310
|
+
* Use this to:
|
|
311
|
+
* - Cancel hibernation (return false)
|
|
312
|
+
* - Modify the snapshot before saving (return modified snapshot)
|
|
313
|
+
* - Perform cleanup before hibernation
|
|
314
|
+
*
|
|
315
|
+
* @param session - The session about to hibernate
|
|
316
|
+
* @param snapshot - The snapshot that will be saved
|
|
317
|
+
* @returns false to cancel, modified snapshot, or void to proceed
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```typescript
|
|
321
|
+
* onBeforeHibernate: (session, snapshot) => {
|
|
322
|
+
* // Don't hibernate sessions with pending tool calls
|
|
323
|
+
* if (session.inspect().lastToolCalls.length > 0) {
|
|
324
|
+
* return false;
|
|
325
|
+
* }
|
|
326
|
+
* // Add custom metadata to snapshot
|
|
327
|
+
* return { ...snapshot, metadata: { hibernatedAt: Date.now() } };
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
onBeforeHibernate?: (session: Session, snapshot: SessionSnapshot) => boolean | SessionSnapshot | void | Promise<boolean | SessionSnapshot | void>;
|
|
332
|
+
/**
|
|
333
|
+
* Called after a session has been hibernated.
|
|
334
|
+
*
|
|
335
|
+
* The session is no longer in memory at this point.
|
|
336
|
+
* Use this for logging, metrics, or cleanup.
|
|
337
|
+
*
|
|
338
|
+
* @param sessionId - The ID of the hibernated session
|
|
339
|
+
* @param snapshot - The snapshot that was saved
|
|
340
|
+
*/
|
|
341
|
+
onAfterHibernate?: (sessionId: string, snapshot: SessionSnapshot) => void | Promise<void>;
|
|
342
|
+
/**
|
|
343
|
+
* Called before a session is hydrated from storage.
|
|
344
|
+
*
|
|
345
|
+
* Use this to:
|
|
346
|
+
* - Cancel hydration (return false)
|
|
347
|
+
* - Migrate/transform old snapshot formats (return modified snapshot)
|
|
348
|
+
* - Validate snapshot before restoration
|
|
349
|
+
*
|
|
350
|
+
* @param sessionId - The ID of the session being hydrated
|
|
351
|
+
* @param snapshot - The snapshot loaded from storage
|
|
352
|
+
* @returns false to cancel, modified snapshot, or void to proceed
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* onBeforeHydrate: (sessionId, snapshot) => {
|
|
357
|
+
* // Migrate old snapshot format
|
|
358
|
+
* if (snapshot.version === '0.9') {
|
|
359
|
+
* return migrateSnapshot(snapshot);
|
|
360
|
+
* }
|
|
361
|
+
* return snapshot;
|
|
362
|
+
* }
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
onBeforeHydrate?: (sessionId: string, snapshot: SessionSnapshot) => boolean | SessionSnapshot | void | Promise<boolean | SessionSnapshot | void>;
|
|
366
|
+
/**
|
|
367
|
+
* Called after a session has been hydrated.
|
|
368
|
+
*
|
|
369
|
+
* The session is now live and in memory.
|
|
370
|
+
* Use this for post-restoration setup, logging, or metrics.
|
|
371
|
+
*
|
|
372
|
+
* @param session - The hydrated session
|
|
373
|
+
* @param snapshot - The snapshot that was used
|
|
374
|
+
*/
|
|
375
|
+
onAfterHydrate?: (session: Session, snapshot: SessionSnapshot) => void | Promise<void>;
|
|
376
|
+
/**
|
|
377
|
+
* Called before send is executed.
|
|
378
|
+
* Return a modified input to override what is sent.
|
|
379
|
+
*/
|
|
380
|
+
onBeforeSend?: <P extends Record<string, unknown>>(session: Session<P>, input: SendInput<P>) => void | SendInput<P>;
|
|
381
|
+
/**
|
|
382
|
+
* Called after send completes successfully.
|
|
383
|
+
*/
|
|
384
|
+
onAfterSend?: (session: Session, result: SendResult) => void;
|
|
385
|
+
/**
|
|
386
|
+
* Callback for tool confirmation.
|
|
387
|
+
* Called when a tool with requiresConfirmation is invoked.
|
|
388
|
+
* Return true to allow, false to deny.
|
|
389
|
+
*/
|
|
390
|
+
onToolConfirmation?: (call: ToolCall, message: string) => Promise<boolean>;
|
|
391
|
+
/**
|
|
392
|
+
* Whether to inherit middleware and telemetry from the global Agentick instance.
|
|
393
|
+
*
|
|
394
|
+
* When true (default), the app inherits:
|
|
395
|
+
* - Middleware registered via `Agentick.use('*', mw)`, `Agentick.use('tool:*', mw)`, etc.
|
|
396
|
+
* - Telemetry provider from `Agentick.telemetryProvider`
|
|
397
|
+
*
|
|
398
|
+
* Set to false for isolated apps (useful in testing).
|
|
399
|
+
*
|
|
400
|
+
* @default true
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* // App inherits Agentick defaults (default behavior)
|
|
405
|
+
* const app = createApp(MyAgent, { model });
|
|
406
|
+
*
|
|
407
|
+
* // Isolated app - no Agentick middleware
|
|
408
|
+
* const testApp = createApp(TestAgent, { model, inheritDefaults: false });
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
inheritDefaults?: boolean;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Recording mode for debugging and replay.
|
|
415
|
+
*
|
|
416
|
+
* - 'full': Capture everything (fiber tree, COM, model I/O). Best for development.
|
|
417
|
+
* - 'lightweight': Only COM output and model I/O. Good for production debugging.
|
|
418
|
+
* - 'none': No recording (default). Minimal overhead.
|
|
419
|
+
*/
|
|
420
|
+
export type RecordingMode = "full" | "lightweight" | "none";
|
|
421
|
+
/**
|
|
422
|
+
* Options for creating or configuring a session.
|
|
423
|
+
*
|
|
424
|
+
* SessionOptions are specific to a particular session instance -
|
|
425
|
+
* things like state to hydrate, per-session limits, etc.
|
|
426
|
+
*
|
|
427
|
+
* Lifecycle callbacks from AppOptions are inherited; SessionOptions
|
|
428
|
+
* callbacks will override them.
|
|
429
|
+
*/
|
|
430
|
+
export interface SessionOptions extends LifecycleCallbacks {
|
|
431
|
+
/**
|
|
432
|
+
* Explicit session ID (used by App-managed sessions).
|
|
433
|
+
*/
|
|
434
|
+
sessionId?: string;
|
|
435
|
+
/**
|
|
436
|
+
* Maximum number of ticks for this session.
|
|
437
|
+
* Overrides AppOptions.maxTicks.
|
|
438
|
+
*/
|
|
439
|
+
maxTicks?: number;
|
|
440
|
+
/**
|
|
441
|
+
* Per-session abort signal.
|
|
442
|
+
*/
|
|
443
|
+
signal?: AbortSignal;
|
|
444
|
+
/**
|
|
445
|
+
* Initial timeline entries to hydrate the conversation history.
|
|
446
|
+
*
|
|
447
|
+
* Use this to load an existing conversation when creating a session.
|
|
448
|
+
* These entries will be available via `useConversationHistory()` and
|
|
449
|
+
* rendered by `<Timeline />` on tick 1 and beyond.
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```typescript
|
|
453
|
+
* const session = app.session({
|
|
454
|
+
* initialTimeline: loadedConversation.entries,
|
|
455
|
+
* });
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
initialTimeline?: TimelineEntry[];
|
|
459
|
+
/**
|
|
460
|
+
* Initial state to hydrate (for resuming sessions).
|
|
461
|
+
* @future Phase 3 serialization
|
|
462
|
+
*/
|
|
463
|
+
snapshot?: SessionSnapshot;
|
|
464
|
+
/**
|
|
465
|
+
* Recording mode for time-travel debugging.
|
|
466
|
+
*
|
|
467
|
+
* - 'full': Capture everything (fiber tree, COM, model I/O). Best for development.
|
|
468
|
+
* - 'lightweight': Only COM output and model I/O. Good for production debugging.
|
|
469
|
+
* - 'none': No recording (default). Minimal overhead.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```typescript
|
|
473
|
+
* // Enable full recording for debugging
|
|
474
|
+
* const session = app.session({ recording: 'full' });
|
|
475
|
+
*
|
|
476
|
+
* // After execution, get the recording
|
|
477
|
+
* const recording = session.getRecording();
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
recording?: RecordingMode;
|
|
481
|
+
/**
|
|
482
|
+
* Enable DevTools event emission.
|
|
483
|
+
*
|
|
484
|
+
* When true, lifecycle events (execution_start, tick_start, tick_end,
|
|
485
|
+
* execution_end, fiber_snapshot) are emitted to the DevTools emitter.
|
|
486
|
+
*
|
|
487
|
+
* @default false
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```typescript
|
|
491
|
+
* // Enable DevTools for debugging
|
|
492
|
+
* const session = app.session({ devTools: true });
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
devTools?: boolean;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Per-execution overrides for a single tick/send.
|
|
499
|
+
*/
|
|
500
|
+
export interface ExecutionOptions {
|
|
501
|
+
/** Override maxTicks for this execution */
|
|
502
|
+
maxTicks?: number;
|
|
503
|
+
/** Per-execution abort signal */
|
|
504
|
+
signal?: AbortSignal;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Serialized session state for persistence/resumption.
|
|
508
|
+
*/
|
|
509
|
+
export interface SessionSnapshot {
|
|
510
|
+
/** Session version for compatibility */
|
|
511
|
+
version: string;
|
|
512
|
+
/** Session ID */
|
|
513
|
+
sessionId: string;
|
|
514
|
+
/** Tick number at snapshot time */
|
|
515
|
+
tick: number;
|
|
516
|
+
/** Serialized conversation/timeline */
|
|
517
|
+
timeline: unknown;
|
|
518
|
+
/** Serialized component state (hooks) */
|
|
519
|
+
componentState: unknown;
|
|
520
|
+
/** Accumulated usage stats across all sends */
|
|
521
|
+
usage?: UsageStats;
|
|
522
|
+
/** Timestamp of snapshot */
|
|
523
|
+
timestamp: number;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Input for sending messages to a session.
|
|
527
|
+
*
|
|
528
|
+
* Extends the wire-safe SharedSendInput with local execution fields.
|
|
529
|
+
* Always uses `messages` array (no singular `message` form).
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```typescript
|
|
533
|
+
* session.send({
|
|
534
|
+
* messages: [{ role: "user", content: [{ type: "text", text: "Hello!" }] }],
|
|
535
|
+
* maxTicks: 5,
|
|
536
|
+
* });
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
export interface SendInput<P = Record<string, unknown>> extends SharedSendInput<P> {
|
|
540
|
+
/** Override maxTicks for this execution */
|
|
541
|
+
maxTicks?: number;
|
|
542
|
+
/** Per-execution abort signal (not serializable — local only) */
|
|
543
|
+
signal?: AbortSignal;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Input for run() and app.run().
|
|
547
|
+
*
|
|
548
|
+
* Extends SendInput with configuration for the implicit layers
|
|
549
|
+
* (app creation, session creation) that run() and app.run() handle.
|
|
550
|
+
*
|
|
551
|
+
* Progressive disclosure: run() needs model, app.run() doesn't (already configured).
|
|
552
|
+
*
|
|
553
|
+
* @example run() — needs everything
|
|
554
|
+
* ```typescript
|
|
555
|
+
* const result = await run(<MyAgent />, {
|
|
556
|
+
* model,
|
|
557
|
+
* messages: [{ role: "user", content: [{ type: "text", text: "Hello!" }] }],
|
|
558
|
+
* history: previousConversation.entries,
|
|
559
|
+
* maxTicks: 5,
|
|
560
|
+
* });
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* @example app.run() — model already configured
|
|
564
|
+
* ```typescript
|
|
565
|
+
* const result = await app.run({
|
|
566
|
+
* props: { system: "You are helpful" },
|
|
567
|
+
* messages: [{ role: "user", content: [{ type: "text", text: "Hello!" }] }],
|
|
568
|
+
* history: previousConversation.entries,
|
|
569
|
+
* });
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
export interface RunInput<P = Record<string, unknown>> extends SendInput<P> {
|
|
573
|
+
/** Model instance (required for run(), optional for app.run()) */
|
|
574
|
+
model?: EngineModel;
|
|
575
|
+
/**
|
|
576
|
+
* Previous conversation history to hydrate.
|
|
577
|
+
*
|
|
578
|
+
* These become the initial timeline entries, available via
|
|
579
|
+
* `useConversationHistory()` and rendered by `<Timeline />`.
|
|
580
|
+
*/
|
|
581
|
+
history?: TimelineEntry[];
|
|
582
|
+
/** Enable DevTools event emission */
|
|
583
|
+
devTools?: boolean;
|
|
584
|
+
/** Recording mode for time-travel debugging */
|
|
585
|
+
recording?: RecordingMode;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Result from session.render() with structured outputs.
|
|
589
|
+
*
|
|
590
|
+
* This is the primary output interface. Props go in, SendResult comes out.
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* ```typescript
|
|
594
|
+
* const session = app.session();
|
|
595
|
+
* const result = await session.render({ messages: [...], context: 'Be concise' });
|
|
596
|
+
*
|
|
597
|
+
* console.log(result.response); // Model's text response
|
|
598
|
+
* console.log(result.outputs.decide); // Structured data from OUTPUT tool
|
|
599
|
+
* ```
|
|
600
|
+
*/
|
|
601
|
+
export interface SendResult {
|
|
602
|
+
/**
|
|
603
|
+
* The model's text response (concatenated from all assistant messages).
|
|
604
|
+
*/
|
|
605
|
+
response: string;
|
|
606
|
+
/**
|
|
607
|
+
* Structured outputs from OUTPUT-type tools, keyed by tool name.
|
|
608
|
+
* When a tool has executionType="OUTPUT", its data appears here
|
|
609
|
+
* instead of being sent back to the model as a tool_result.
|
|
610
|
+
*/
|
|
611
|
+
outputs: Record<string, unknown>;
|
|
612
|
+
/**
|
|
613
|
+
* Token usage and execution statistics.
|
|
614
|
+
*/
|
|
615
|
+
usage: UsageStats;
|
|
616
|
+
/**
|
|
617
|
+
* Reason execution stopped.
|
|
618
|
+
*/
|
|
619
|
+
stopReason?: string;
|
|
620
|
+
/**
|
|
621
|
+
* Raw compiled output (for advanced use cases).
|
|
622
|
+
*/
|
|
623
|
+
raw: COMInput;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Events emitted during streaming execution.
|
|
627
|
+
*/
|
|
628
|
+
export type StreamEvent = SharedStreamEvent;
|
|
629
|
+
/**
|
|
630
|
+
* Handle for interacting with a running session execution.
|
|
631
|
+
*
|
|
632
|
+
* SessionExecutionHandle wraps the kernel's ExecutionHandle with session-specific
|
|
633
|
+
* methods using explicit delegation. This is the return type of session.send()
|
|
634
|
+
* and session.render().
|
|
635
|
+
*
|
|
636
|
+
* The handle is AsyncIterable (not PromiseLike):
|
|
637
|
+
* - `await handle.result` → resolves to SendResult
|
|
638
|
+
* - `for await (const event of handle)` → streams StreamEvent
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```typescript
|
|
642
|
+
* // send/render are Procedures — await to get the handle
|
|
643
|
+
* const handle = await session.send({ messages: [...] });
|
|
644
|
+
*
|
|
645
|
+
* // Stream events
|
|
646
|
+
* for await (const event of handle) {
|
|
647
|
+
* if (event.type === 'content_delta') {
|
|
648
|
+
* process.stdout.write(event.delta);
|
|
649
|
+
* }
|
|
650
|
+
* }
|
|
651
|
+
*
|
|
652
|
+
* // Or get result directly via ProcedurePromise chaining
|
|
653
|
+
* const result = await session.send({ messages: [...] }).result;
|
|
654
|
+
* console.log(result.response);
|
|
655
|
+
*
|
|
656
|
+
* // Mid-execution interaction
|
|
657
|
+
* handle.queueMessage({ role: "user", content: [...] });
|
|
658
|
+
* handle.abort("User cancelled");
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
export interface SessionExecutionHandle extends ExecutionHandle<SendResult, StreamEvent> {
|
|
662
|
+
/** The session ID */
|
|
663
|
+
readonly sessionId: string;
|
|
664
|
+
/** Current tick number */
|
|
665
|
+
readonly currentTick: number;
|
|
666
|
+
/**
|
|
667
|
+
* Queue a message during execution.
|
|
668
|
+
* Delivered to onMessage hooks if running, queued for next tick otherwise.
|
|
669
|
+
*/
|
|
670
|
+
queueMessage(message: Message): void;
|
|
671
|
+
/**
|
|
672
|
+
* Submit a tool confirmation result.
|
|
673
|
+
* Used when a tool requires user confirmation.
|
|
674
|
+
*/
|
|
675
|
+
submitToolResult(toolUseId: string, response: {
|
|
676
|
+
approved: boolean;
|
|
677
|
+
reason?: string;
|
|
678
|
+
modifiedArguments?: Record<string, unknown>;
|
|
679
|
+
}): void;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Session status.
|
|
683
|
+
*/
|
|
684
|
+
export type SessionStatus = "idle" | "running" | "closed";
|
|
685
|
+
/**
|
|
686
|
+
* Execution phase during a tick.
|
|
687
|
+
*/
|
|
688
|
+
export type ExecutionPhase = "compile" | "model" | "tools" | "ingest";
|
|
689
|
+
/**
|
|
690
|
+
* Hook type identifier for inspection.
|
|
691
|
+
*/
|
|
692
|
+
export type HookType = "useState" | "useReducer" | "useEffect" | "useLayoutEffect" | "useMemo" | "useCallback" | "useRef" | "useSignal" | "useComputed" | "useContext" | "useOnMessage" | "useQueuedMessages";
|
|
693
|
+
/**
|
|
694
|
+
* Result of session.inspect() - live session state for debugging.
|
|
695
|
+
*
|
|
696
|
+
* Combines live data (status, queued messages) with snapshot data
|
|
697
|
+
* (last output, model output) and aggregates (total usage).
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```typescript
|
|
701
|
+
* const session = app.session();
|
|
702
|
+
* await session.render({ query: "Hello!" });
|
|
703
|
+
*
|
|
704
|
+
* const info = session.inspect();
|
|
705
|
+
* console.log('Status:', info.status);
|
|
706
|
+
* console.log('Tick:', info.currentTick);
|
|
707
|
+
* console.log('Tokens used:', info.totalUsage.totalTokens);
|
|
708
|
+
* console.log('Components:', info.components.names);
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
711
|
+
export interface SessionInspection {
|
|
712
|
+
/** Session ID */
|
|
713
|
+
id: string;
|
|
714
|
+
/** Current session status */
|
|
715
|
+
status: SessionStatus;
|
|
716
|
+
/** Current tick number */
|
|
717
|
+
currentTick: number;
|
|
718
|
+
/** Messages queued for the next tick */
|
|
719
|
+
queuedMessages: Message[];
|
|
720
|
+
/** If running, what phase of the tick loop? */
|
|
721
|
+
currentPhase?: ExecutionPhase;
|
|
722
|
+
/** Whether the session has been aborted */
|
|
723
|
+
isAborted: boolean;
|
|
724
|
+
/** Last compiled COM output */
|
|
725
|
+
lastOutput: COMInput | null;
|
|
726
|
+
/** Last model response */
|
|
727
|
+
lastModelOutput: {
|
|
728
|
+
content: ContentBlock[];
|
|
729
|
+
stopReason: string;
|
|
730
|
+
} | null;
|
|
731
|
+
/** Tool calls from last tick */
|
|
732
|
+
lastToolCalls: ToolCall[];
|
|
733
|
+
/** Tool results from last tick */
|
|
734
|
+
lastToolResults: {
|
|
735
|
+
toolUseId: string;
|
|
736
|
+
name: string;
|
|
737
|
+
success: boolean;
|
|
738
|
+
}[];
|
|
739
|
+
/** Total token usage across all ticks */
|
|
740
|
+
totalUsage: UsageStats;
|
|
741
|
+
/** Number of completed ticks */
|
|
742
|
+
tickCount: number;
|
|
743
|
+
/** Component tree summary */
|
|
744
|
+
components: {
|
|
745
|
+
/** Number of mounted components */
|
|
746
|
+
count: number;
|
|
747
|
+
/** Unique component names in the tree */
|
|
748
|
+
names: string[];
|
|
749
|
+
};
|
|
750
|
+
/** Hook usage summary */
|
|
751
|
+
hooks: {
|
|
752
|
+
/** Total number of hooks */
|
|
753
|
+
count: number;
|
|
754
|
+
/** Hook count by type */
|
|
755
|
+
byType: Partial<Record<HookType, number>>;
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Serialized error for JSON transport/storage.
|
|
760
|
+
*/
|
|
761
|
+
export interface SerializedError {
|
|
762
|
+
name: string;
|
|
763
|
+
message: string;
|
|
764
|
+
stack?: string;
|
|
765
|
+
cause?: SerializedError;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Serialized hook state for snapshots.
|
|
769
|
+
*/
|
|
770
|
+
export interface SerializedHookState {
|
|
771
|
+
/** Hook index in the component */
|
|
772
|
+
index: number;
|
|
773
|
+
/** Hook type */
|
|
774
|
+
type: HookType;
|
|
775
|
+
/** JSON-serializable hook value */
|
|
776
|
+
value: unknown;
|
|
777
|
+
/** Dependencies (for effects/memos) */
|
|
778
|
+
deps?: unknown[];
|
|
779
|
+
/** Effect status */
|
|
780
|
+
status?: "pending" | "mounted" | "cleanup";
|
|
781
|
+
/** Number of signal subscribers (for useSignal) */
|
|
782
|
+
subscribers?: number;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Serialized hook state for devtools.
|
|
786
|
+
*/
|
|
787
|
+
export interface SerializedHook {
|
|
788
|
+
index: number;
|
|
789
|
+
type: string;
|
|
790
|
+
value: unknown;
|
|
791
|
+
deps?: unknown[];
|
|
792
|
+
status?: string;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Serialized fiber node for snapshots and devtools.
|
|
796
|
+
*
|
|
797
|
+
* Captures the component tree structure with props.
|
|
798
|
+
* Matches the FiberNode interface expected by devtools UI.
|
|
799
|
+
*/
|
|
800
|
+
export interface SerializedFiberNode {
|
|
801
|
+
/** Unique identifier for the node */
|
|
802
|
+
id: string;
|
|
803
|
+
/** Component name or element type */
|
|
804
|
+
type: string;
|
|
805
|
+
/** React key */
|
|
806
|
+
key: string | number | null;
|
|
807
|
+
/** JSON-safe props (functions/symbols removed) */
|
|
808
|
+
props: Record<string, unknown>;
|
|
809
|
+
/** Hook states (empty in v2 since React manages hooks internally) */
|
|
810
|
+
hooks: SerializedHook[];
|
|
811
|
+
/** Child fibers */
|
|
812
|
+
children: SerializedFiberNode[];
|
|
813
|
+
/** Human-readable summary for display */
|
|
814
|
+
_summary?: string;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Tool definition as captured in snapshot (minimal, JSON-safe).
|
|
818
|
+
*/
|
|
819
|
+
export interface SnapshotToolDefinition {
|
|
820
|
+
name: string;
|
|
821
|
+
description?: string;
|
|
822
|
+
inputSchema?: Record<string, unknown>;
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* TickSnapshot captures everything about a single tick.
|
|
826
|
+
*
|
|
827
|
+
* This is the atomic unit for time-travel debugging, replay, and DevTools.
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
830
|
+
* ```typescript
|
|
831
|
+
* // Enable recording when creating session
|
|
832
|
+
* const session = app.session({ recording: 'full' });
|
|
833
|
+
*
|
|
834
|
+
* // After some ticks...
|
|
835
|
+
* const recording = session.getRecording();
|
|
836
|
+
* const snapshot = recording?.snapshots[2]; // Tick 3's snapshot
|
|
837
|
+
*
|
|
838
|
+
* console.log(snapshot.model.output.content); // What the model said
|
|
839
|
+
* console.log(snapshot.tools.calls); // What tools were called
|
|
840
|
+
* console.log(snapshot.fiber.summary); // Component tree stats
|
|
841
|
+
* ```
|
|
842
|
+
*/
|
|
843
|
+
export interface TickSnapshot {
|
|
844
|
+
/** Session ID this snapshot belongs to */
|
|
845
|
+
sessionId: string;
|
|
846
|
+
/** Tick number (1-indexed) */
|
|
847
|
+
tick: number;
|
|
848
|
+
/** ISO 8601 timestamp when tick completed */
|
|
849
|
+
timestamp: string;
|
|
850
|
+
/** Duration of the tick in milliseconds */
|
|
851
|
+
duration: number;
|
|
852
|
+
/** Fiber tree state (component tree structure and hooks) */
|
|
853
|
+
fiber: {
|
|
854
|
+
/** Serialized fiber tree (null in 'lightweight' mode) */
|
|
855
|
+
tree: SerializedFiberNode | null;
|
|
856
|
+
/** Summary statistics (always present) */
|
|
857
|
+
summary: {
|
|
858
|
+
componentCount: number;
|
|
859
|
+
hookCount: number;
|
|
860
|
+
hooksByType: Partial<Record<HookType, number>>;
|
|
861
|
+
};
|
|
862
|
+
};
|
|
863
|
+
/** Compiled output (what the model "sees") */
|
|
864
|
+
com: {
|
|
865
|
+
/** System sections */
|
|
866
|
+
sections: Record<string, {
|
|
867
|
+
content: string;
|
|
868
|
+
priority?: number;
|
|
869
|
+
}>;
|
|
870
|
+
/** Conversation timeline */
|
|
871
|
+
timeline: TimelineEntry[];
|
|
872
|
+
/** Available tools */
|
|
873
|
+
tools: SnapshotToolDefinition[];
|
|
874
|
+
/** Model ID being used */
|
|
875
|
+
modelId: string | null;
|
|
876
|
+
/** Metadata */
|
|
877
|
+
metadata: Record<string, unknown>;
|
|
878
|
+
};
|
|
879
|
+
/** Model input and output for this tick */
|
|
880
|
+
model: {
|
|
881
|
+
/** What was sent to the model */
|
|
882
|
+
input: {
|
|
883
|
+
/** Formatted prompt (may be truncated for large prompts) */
|
|
884
|
+
formatted: string;
|
|
885
|
+
/** Token count if available */
|
|
886
|
+
tokenCount?: number;
|
|
887
|
+
};
|
|
888
|
+
/** What the model returned */
|
|
889
|
+
output: {
|
|
890
|
+
/** Response content blocks */
|
|
891
|
+
content: ContentBlock[];
|
|
892
|
+
/** Why the model stopped */
|
|
893
|
+
stopReason: string;
|
|
894
|
+
/** Output token count */
|
|
895
|
+
tokenCount?: number;
|
|
896
|
+
};
|
|
897
|
+
/** Time spent waiting for model response (ms) */
|
|
898
|
+
latency: number;
|
|
899
|
+
};
|
|
900
|
+
/** Tool calls and results from this tick */
|
|
901
|
+
tools: {
|
|
902
|
+
/** Tool calls made by the model */
|
|
903
|
+
calls: ToolCall[];
|
|
904
|
+
/** Results from tool execution */
|
|
905
|
+
results: Array<{
|
|
906
|
+
toolUseId: string;
|
|
907
|
+
name: string;
|
|
908
|
+
success: boolean;
|
|
909
|
+
/** Result content (may be truncated) */
|
|
910
|
+
content: unknown;
|
|
911
|
+
/** Execution time (ms) */
|
|
912
|
+
duration?: number;
|
|
913
|
+
}>;
|
|
914
|
+
/** Total time spent executing tools (ms) */
|
|
915
|
+
totalDuration: number;
|
|
916
|
+
};
|
|
917
|
+
/** Execution state at end of tick */
|
|
918
|
+
execution: {
|
|
919
|
+
/** Phase when snapshot was taken */
|
|
920
|
+
phase: "complete";
|
|
921
|
+
/** Should the tick loop continue? */
|
|
922
|
+
shouldContinue: boolean;
|
|
923
|
+
/** Reason for stopping (if applicable) */
|
|
924
|
+
stopReason?: string;
|
|
925
|
+
/** Messages queued during this tick */
|
|
926
|
+
queuedMessages: Message[];
|
|
927
|
+
/** Error if tick failed */
|
|
928
|
+
error?: SerializedError;
|
|
929
|
+
/** Execution ID from ALS context (for DevTools linking) */
|
|
930
|
+
executionId?: string;
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Input recorded for session replay.
|
|
935
|
+
*/
|
|
936
|
+
export interface RecordedInput {
|
|
937
|
+
/** Which tick received this input */
|
|
938
|
+
tick: number;
|
|
939
|
+
/** When the input was received */
|
|
940
|
+
timestamp: string;
|
|
941
|
+
/** The message */
|
|
942
|
+
message: Message;
|
|
943
|
+
/** How the message was added */
|
|
944
|
+
source: "initial" | "queued" | "send";
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* SessionRecording is the complete history of a session.
|
|
948
|
+
*
|
|
949
|
+
* Contains all tick snapshots and metadata for replay/forking.
|
|
950
|
+
*
|
|
951
|
+
* @example
|
|
952
|
+
* ```typescript
|
|
953
|
+
* const session = app.session({ recording: 'full' });
|
|
954
|
+
* await session.render({ query: "Hello!" });
|
|
955
|
+
* await session.render({ query: "Tell me more" });
|
|
956
|
+
*
|
|
957
|
+
* const recording = session.getRecording();
|
|
958
|
+
* console.log(recording.summary.tickCount); // 2
|
|
959
|
+
* console.log(recording.summary.totalUsage); // Token usage
|
|
960
|
+
* console.log(recording.snapshots[0].model.output); // First response
|
|
961
|
+
* ```
|
|
962
|
+
*/
|
|
963
|
+
export interface SessionRecording {
|
|
964
|
+
/** Session ID */
|
|
965
|
+
sessionId: string;
|
|
966
|
+
/** When recording started */
|
|
967
|
+
startedAt: string;
|
|
968
|
+
/** When recording ended (if session closed) */
|
|
969
|
+
endedAt?: string;
|
|
970
|
+
/** How the session was created */
|
|
971
|
+
config: {
|
|
972
|
+
/** Component name */
|
|
973
|
+
componentName: string;
|
|
974
|
+
/** Initial props (first tick) */
|
|
975
|
+
initialProps: Record<string, unknown>;
|
|
976
|
+
/** Max ticks setting */
|
|
977
|
+
maxTicks: number;
|
|
978
|
+
/** Recording mode */
|
|
979
|
+
mode: RecordingMode;
|
|
980
|
+
};
|
|
981
|
+
/** All inputs during the session */
|
|
982
|
+
inputs: RecordedInput[];
|
|
983
|
+
/** Tick-by-tick history */
|
|
984
|
+
snapshots: TickSnapshot[];
|
|
985
|
+
/** Summary statistics */
|
|
986
|
+
summary: {
|
|
987
|
+
/** Number of ticks completed */
|
|
988
|
+
tickCount: number;
|
|
989
|
+
/** Total session duration (ms) */
|
|
990
|
+
totalDuration: number;
|
|
991
|
+
/** Total token usage */
|
|
992
|
+
totalUsage: UsageStats;
|
|
993
|
+
/** How the session ended */
|
|
994
|
+
finalStatus: "completed" | "aborted" | "error" | "max_ticks" | "running";
|
|
995
|
+
/** Final stop reason */
|
|
996
|
+
finalStopReason?: string;
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* A persistent session for multi-turn conversations.
|
|
1001
|
+
*
|
|
1002
|
+
* Session is an EventEmitter that emits StreamEvent during execution.
|
|
1003
|
+
* Use session.events() to convert to an AsyncIterable.
|
|
1004
|
+
*
|
|
1005
|
+
* @example
|
|
1006
|
+
* ```typescript
|
|
1007
|
+
* const session = app.session();
|
|
1008
|
+
*
|
|
1009
|
+
* // Listen to events via EventEmitter
|
|
1010
|
+
* session.on('event', (event) => console.log(event));
|
|
1011
|
+
*
|
|
1012
|
+
* // Or convert to AsyncIterable
|
|
1013
|
+
* for await (const event of session.events()) {
|
|
1014
|
+
* console.log(event);
|
|
1015
|
+
* }
|
|
1016
|
+
*
|
|
1017
|
+
* // Run with props, get handle
|
|
1018
|
+
* const handle = await session.render({ query: "Hello!" });
|
|
1019
|
+
* const result = await handle.result;
|
|
1020
|
+
* console.log(result.response);
|
|
1021
|
+
*
|
|
1022
|
+
* // Or get result directly via ProcedurePromise chaining
|
|
1023
|
+
* const result2 = await session.render({ query: "Follow up" }).result;
|
|
1024
|
+
*
|
|
1025
|
+
* // Queue messages for next tick
|
|
1026
|
+
* await session.queue.exec({ role: "user", content: [...] });
|
|
1027
|
+
*
|
|
1028
|
+
* // Interrupt running execution
|
|
1029
|
+
* session.interrupt({ role: "user", content: [...] }, "user_interrupt");
|
|
1030
|
+
*
|
|
1031
|
+
* // Clean up when done
|
|
1032
|
+
* session.close();
|
|
1033
|
+
* ```
|
|
1034
|
+
*/
|
|
1035
|
+
export interface Session<P = Record<string, unknown>> extends EventEmitter {
|
|
1036
|
+
/** Unique session ID */
|
|
1037
|
+
readonly id: string;
|
|
1038
|
+
/** Current session status */
|
|
1039
|
+
readonly status: SessionStatus;
|
|
1040
|
+
/** Current tick number */
|
|
1041
|
+
readonly currentTick: number;
|
|
1042
|
+
/** Whether the session has been aborted */
|
|
1043
|
+
readonly isAborted: boolean;
|
|
1044
|
+
/** Parent session, or null for root sessions. */
|
|
1045
|
+
readonly parent: Session | null;
|
|
1046
|
+
/** Active child sessions (currently running spawns). */
|
|
1047
|
+
readonly children: readonly Session[];
|
|
1048
|
+
/** Messages queued for the next tick (read-only view) */
|
|
1049
|
+
readonly queuedMessages: readonly Message[];
|
|
1050
|
+
/**
|
|
1051
|
+
* Current scheduler state for DevTools.
|
|
1052
|
+
*
|
|
1053
|
+
* Returns the scheduler's current state, including status,
|
|
1054
|
+
* pending reasons, and reconciliation metrics.
|
|
1055
|
+
*
|
|
1056
|
+
* Returns null if the session hasn't been initialized yet.
|
|
1057
|
+
*/
|
|
1058
|
+
readonly schedulerState: SchedulerState | null;
|
|
1059
|
+
/**
|
|
1060
|
+
* Queue a message to be included in the next tick.
|
|
1061
|
+
*
|
|
1062
|
+
* Queues the message and notifies onMessage hooks if components are mounted.
|
|
1063
|
+
* Does NOT trigger execution - use send() if you want to trigger render().
|
|
1064
|
+
*
|
|
1065
|
+
* This is a procedure (without execution boundary) so you can use:
|
|
1066
|
+
* - `session.queue.withContext({ userId }).exec(message)`
|
|
1067
|
+
* - `session.queue.use(middleware).exec(message)`
|
|
1068
|
+
*/
|
|
1069
|
+
queue: Procedure<(message: Message) => Promise<void>, true>;
|
|
1070
|
+
/**
|
|
1071
|
+
* Send messages and/or update props.
|
|
1072
|
+
*
|
|
1073
|
+
* Returns SessionExecutionHandle (AsyncIterable, not PromiseLike):
|
|
1074
|
+
* - `await handle.result` → SendResult when execution completes
|
|
1075
|
+
* - `for await (const event of handle)` → stream events
|
|
1076
|
+
*
|
|
1077
|
+
* Concurrent calls return THE SAME handle - messages queue, handle resolves
|
|
1078
|
+
* when the tick loop settles.
|
|
1079
|
+
*
|
|
1080
|
+
* @example
|
|
1081
|
+
* ```typescript
|
|
1082
|
+
* // Await Procedure to get handle, then stream events
|
|
1083
|
+
* const handle = await session.send({ messages: [...] });
|
|
1084
|
+
* for await (const event of handle) {
|
|
1085
|
+
* console.log(event);
|
|
1086
|
+
* }
|
|
1087
|
+
*
|
|
1088
|
+
* // Or get the result directly via ProcedurePromise chaining
|
|
1089
|
+
* const result = await session.send({ messages: [...] }).result;
|
|
1090
|
+
* ```
|
|
1091
|
+
*/
|
|
1092
|
+
send: Procedure<(input: SendInput<P>) => SessionExecutionHandle, true>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Run the component with props, execute tick loop.
|
|
1095
|
+
*
|
|
1096
|
+
* Returns SessionExecutionHandle (AsyncIterable, not PromiseLike).
|
|
1097
|
+
* If already running, returns the existing handle (hot-update support).
|
|
1098
|
+
*
|
|
1099
|
+
* Note: If called with no props (or empty props) and no queued messages, returns an
|
|
1100
|
+
* empty handle and does not run a tick.
|
|
1101
|
+
*
|
|
1102
|
+
* @example
|
|
1103
|
+
* ```typescript
|
|
1104
|
+
* const handle = await session.render(props);
|
|
1105
|
+
* handle.queueMessage({ role: "user", content: [...] });
|
|
1106
|
+
* const result = await handle.result;
|
|
1107
|
+
* ```
|
|
1108
|
+
*/
|
|
1109
|
+
render: Procedure<(props: P, options?: ExecutionOptions) => SessionExecutionHandle, true>;
|
|
1110
|
+
/**
|
|
1111
|
+
* Spawn a child session with a different agent/component.
|
|
1112
|
+
*
|
|
1113
|
+
* Creates an ephemeral child session, runs it to completion, and returns
|
|
1114
|
+
* the same SessionExecutionHandle as session.send().
|
|
1115
|
+
*
|
|
1116
|
+
* The child session is NOT registered in the App's session registry.
|
|
1117
|
+
* Parent abort propagates to child. Max spawn depth is 10.
|
|
1118
|
+
*
|
|
1119
|
+
* @param component - ComponentFunction or JSX element
|
|
1120
|
+
* @param input - Optional SendInput for the child session
|
|
1121
|
+
*
|
|
1122
|
+
* @example
|
|
1123
|
+
* ```typescript
|
|
1124
|
+
* // From a tool handler via ctx.spawn()
|
|
1125
|
+
* const handle = await ctx.spawn(ResearchAgent, {
|
|
1126
|
+
* messages: [{ role: "user", content: [{ type: "text", text: query }] }],
|
|
1127
|
+
* });
|
|
1128
|
+
* const result = await handle.result;
|
|
1129
|
+
* ```
|
|
1130
|
+
*/
|
|
1131
|
+
spawn: Procedure<(component: ComponentFunction | JSX.Element, input?: SendInput) => SessionExecutionHandle, true>;
|
|
1132
|
+
/**
|
|
1133
|
+
* Interrupt the current execution, optionally with a message.
|
|
1134
|
+
*
|
|
1135
|
+
* If the session is running:
|
|
1136
|
+
* 1. Aborts the current execution
|
|
1137
|
+
* 2. Queues the message (if provided)
|
|
1138
|
+
*
|
|
1139
|
+
* If the session is idle:
|
|
1140
|
+
* 1. Queues the message (if provided)
|
|
1141
|
+
*
|
|
1142
|
+
* @param message - Optional message to queue
|
|
1143
|
+
* @param reason - Optional abort reason
|
|
1144
|
+
*/
|
|
1145
|
+
interrupt(message?: Message, reason?: string): void;
|
|
1146
|
+
/**
|
|
1147
|
+
* Clear the aborted state flag, allowing the session to continue.
|
|
1148
|
+
*/
|
|
1149
|
+
clearAbort(): void;
|
|
1150
|
+
/**
|
|
1151
|
+
* Convert EventEmitter to AsyncIterable for the current/next execution.
|
|
1152
|
+
*
|
|
1153
|
+
* Call this before send() to capture events as an AsyncIterable.
|
|
1154
|
+
* The iterable completes when the execution finishes.
|
|
1155
|
+
*/
|
|
1156
|
+
events(): AsyncIterable<StreamEvent>;
|
|
1157
|
+
/**
|
|
1158
|
+
* Export session state for persistence.
|
|
1159
|
+
*/
|
|
1160
|
+
snapshot(): SessionSnapshot;
|
|
1161
|
+
/**
|
|
1162
|
+
* Hibernate the session (serialize and remove from memory).
|
|
1163
|
+
*
|
|
1164
|
+
* This is called automatically by the App when:
|
|
1165
|
+
* - Session exceeds idle timeout
|
|
1166
|
+
* - Max active sessions limit is reached
|
|
1167
|
+
*
|
|
1168
|
+
* Can also be called manually to explicitly hibernate a session.
|
|
1169
|
+
*
|
|
1170
|
+
* After hibernation:
|
|
1171
|
+
* - The session is removed from memory
|
|
1172
|
+
* - The snapshot is saved to the configured SessionStore
|
|
1173
|
+
* - Calling `app.session(id)` will rehydrate from storage
|
|
1174
|
+
*
|
|
1175
|
+
* @returns The snapshot that was saved, or null if hibernation was cancelled
|
|
1176
|
+
*
|
|
1177
|
+
* @example
|
|
1178
|
+
* ```typescript
|
|
1179
|
+
* const session = app.session('conv-123');
|
|
1180
|
+
* await session.render({ query: "Hello!" });
|
|
1181
|
+
*
|
|
1182
|
+
* // Manually hibernate
|
|
1183
|
+
* const snapshot = await session.hibernate();
|
|
1184
|
+
*
|
|
1185
|
+
* // Later, rehydrate by accessing the session
|
|
1186
|
+
* const restored = app.session('conv-123'); // Loads from store
|
|
1187
|
+
* ```
|
|
1188
|
+
*/
|
|
1189
|
+
hibernate(): Promise<SessionSnapshot | null>;
|
|
1190
|
+
/**
|
|
1191
|
+
* Inspect the current session state for debugging.
|
|
1192
|
+
*
|
|
1193
|
+
* Returns a snapshot of live status, last outputs, aggregated usage,
|
|
1194
|
+
* and component/hook summaries. Useful for DevTools integration and
|
|
1195
|
+
* debugging mid-execution.
|
|
1196
|
+
*
|
|
1197
|
+
* @example
|
|
1198
|
+
* ```typescript
|
|
1199
|
+
* const session = app.session();
|
|
1200
|
+
* await session.render({ query: "Hello!" });
|
|
1201
|
+
*
|
|
1202
|
+
* const info = session.inspect();
|
|
1203
|
+
* console.log('Tick:', info.currentTick);
|
|
1204
|
+
* console.log('Components:', info.components.names);
|
|
1205
|
+
* console.log('Total tokens:', info.totalUsage.totalTokens);
|
|
1206
|
+
* ```
|
|
1207
|
+
*/
|
|
1208
|
+
inspect(): SessionInspection;
|
|
1209
|
+
/**
|
|
1210
|
+
* Start recording tick snapshots.
|
|
1211
|
+
*
|
|
1212
|
+
* If already recording, changes the mode.
|
|
1213
|
+
*
|
|
1214
|
+
* @param mode - Recording mode ('full' or 'lightweight')
|
|
1215
|
+
*
|
|
1216
|
+
* @example
|
|
1217
|
+
* ```typescript
|
|
1218
|
+
* const session = app.session();
|
|
1219
|
+
* session.startRecording('full');
|
|
1220
|
+
* await session.render({ query: "Hello!" });
|
|
1221
|
+
* const recording = session.getRecording();
|
|
1222
|
+
* ```
|
|
1223
|
+
*/
|
|
1224
|
+
startRecording(mode: RecordingMode): void;
|
|
1225
|
+
/**
|
|
1226
|
+
* Stop recording tick snapshots.
|
|
1227
|
+
*
|
|
1228
|
+
* The recording is preserved and can still be retrieved with getRecording().
|
|
1229
|
+
*/
|
|
1230
|
+
stopRecording(): void;
|
|
1231
|
+
/**
|
|
1232
|
+
* Get the session recording.
|
|
1233
|
+
*
|
|
1234
|
+
* Returns null if recording was never started.
|
|
1235
|
+
*
|
|
1236
|
+
* @example
|
|
1237
|
+
* ```typescript
|
|
1238
|
+
* const session = app.session({ recording: 'full' });
|
|
1239
|
+
* await session.render({ query: "Hello!" });
|
|
1240
|
+
*
|
|
1241
|
+
* const recording = session.getRecording();
|
|
1242
|
+
* console.log(recording?.snapshots.length); // 1
|
|
1243
|
+
* console.log(recording?.summary.totalUsage);
|
|
1244
|
+
* ```
|
|
1245
|
+
*/
|
|
1246
|
+
getRecording(): SessionRecording | null;
|
|
1247
|
+
/**
|
|
1248
|
+
* Get a specific tick's snapshot.
|
|
1249
|
+
*
|
|
1250
|
+
* @param tick - Tick number (1-indexed)
|
|
1251
|
+
* @returns The snapshot, or null if not found or recording not enabled
|
|
1252
|
+
*
|
|
1253
|
+
* @example
|
|
1254
|
+
* ```typescript
|
|
1255
|
+
* const snapshot = session.getSnapshotAt(2);
|
|
1256
|
+
* if (snapshot) {
|
|
1257
|
+
* console.log(snapshot.model.output.content);
|
|
1258
|
+
* console.log(snapshot.tools.calls);
|
|
1259
|
+
* }
|
|
1260
|
+
* ```
|
|
1261
|
+
*/
|
|
1262
|
+
getSnapshotAt(tick: number): TickSnapshot | null;
|
|
1263
|
+
/**
|
|
1264
|
+
* Get a named channel for pub/sub communication.
|
|
1265
|
+
*
|
|
1266
|
+
* Channels allow external code to communicate with running components
|
|
1267
|
+
* and vice versa. Components can subscribe to channels using useChannel().
|
|
1268
|
+
*
|
|
1269
|
+
* Built-in channels:
|
|
1270
|
+
* - 'messages': Message queue updates
|
|
1271
|
+
* - 'tool_confirmation': Tool confirmation requests/responses
|
|
1272
|
+
*
|
|
1273
|
+
* @param name - Channel name
|
|
1274
|
+
* @returns The channel instance
|
|
1275
|
+
*
|
|
1276
|
+
* @example
|
|
1277
|
+
* ```typescript
|
|
1278
|
+
* // External code publishes to session
|
|
1279
|
+
* session.channel('custom').publish({ action: 'refresh' });
|
|
1280
|
+
*
|
|
1281
|
+
* // Component subscribes
|
|
1282
|
+
* const channel = useChannel('custom');
|
|
1283
|
+
* useEffect(() => channel.subscribe(handleEvent), []);
|
|
1284
|
+
* ```
|
|
1285
|
+
*/
|
|
1286
|
+
channel(name: string): Channel;
|
|
1287
|
+
/**
|
|
1288
|
+
* Submit tool confirmation result out-of-band.
|
|
1289
|
+
* Used when client sends tool confirmation outside of execution handle.
|
|
1290
|
+
*/
|
|
1291
|
+
submitToolResult(toolUseId: string, response: {
|
|
1292
|
+
approved: boolean;
|
|
1293
|
+
reason?: string;
|
|
1294
|
+
modifiedArguments?: Record<string, unknown>;
|
|
1295
|
+
}): void;
|
|
1296
|
+
/**
|
|
1297
|
+
* Close the session and release resources.
|
|
1298
|
+
*/
|
|
1299
|
+
close(): void;
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* Component function type for createApp.
|
|
1303
|
+
*/
|
|
1304
|
+
export type ComponentFunction<P = Record<string, unknown>> = (props: P) => JSX.Element;
|
|
1305
|
+
/**
|
|
1306
|
+
* A reusable app instance created by createApp().
|
|
1307
|
+
*
|
|
1308
|
+
* All sessions are persistent sessions internally. Ephemeral execution
|
|
1309
|
+
* (run/stream) creates a session, sends once, then closes immediately.
|
|
1310
|
+
*
|
|
1311
|
+
* @example
|
|
1312
|
+
* ```typescript
|
|
1313
|
+
* const MyAgent = ({ query, context }) => (
|
|
1314
|
+
* <>
|
|
1315
|
+
* <System>You are helpful. {context}</System>
|
|
1316
|
+
* <Timeline />
|
|
1317
|
+
* <User>{query}</User>
|
|
1318
|
+
* </>
|
|
1319
|
+
* );
|
|
1320
|
+
*
|
|
1321
|
+
* const app = createApp(MyAgent, { model });
|
|
1322
|
+
*
|
|
1323
|
+
* // Ephemeral: create → send → close
|
|
1324
|
+
* const result = await app.run({ query: "Hello!", context: "Be concise" });
|
|
1325
|
+
*
|
|
1326
|
+
* // Streaming ephemeral
|
|
1327
|
+
* for await (const event of app.stream({ query: "Hello!" })) {
|
|
1328
|
+
* console.log(event);
|
|
1329
|
+
* }
|
|
1330
|
+
*
|
|
1331
|
+
* // Persistent session (new with generated ID)
|
|
1332
|
+
* const session = app.session();
|
|
1333
|
+
* await session.render({ query: "Hello!" });
|
|
1334
|
+
* await session.render({ query: "Follow up" });
|
|
1335
|
+
* session.close();
|
|
1336
|
+
*
|
|
1337
|
+
* // Named session (get-or-create by ID)
|
|
1338
|
+
* const conv = app.session('conv-123');
|
|
1339
|
+
* await conv.render({ query: "Hello!" });
|
|
1340
|
+
*
|
|
1341
|
+
* // Session with options
|
|
1342
|
+
* const withOpts = app.session({ sessionId: 'conv-456', maxTicks: 5 });
|
|
1343
|
+
* ```
|
|
1344
|
+
*/
|
|
1345
|
+
export interface App<P = Record<string, unknown>> {
|
|
1346
|
+
/**
|
|
1347
|
+
* Run the app with input.
|
|
1348
|
+
*
|
|
1349
|
+
* Returns SessionExecutionHandle (AsyncIterable, not PromiseLike):
|
|
1350
|
+
* - `await handle.result` → SendResult
|
|
1351
|
+
* - `for await (const event of handle)` → StreamEvent
|
|
1352
|
+
*
|
|
1353
|
+
* Creates an ephemeral session internally (create → run → close).
|
|
1354
|
+
*
|
|
1355
|
+
* @example Get result
|
|
1356
|
+
* ```typescript
|
|
1357
|
+
* const result = await app.run({
|
|
1358
|
+
* props: { system: "You are helpful" },
|
|
1359
|
+
* messages: [{ role: "user", content: [{ type: "text", text: "Hello!" }] }],
|
|
1360
|
+
* }).result;
|
|
1361
|
+
* console.log(result.response);
|
|
1362
|
+
* ```
|
|
1363
|
+
*
|
|
1364
|
+
* @example With history and session config
|
|
1365
|
+
* ```typescript
|
|
1366
|
+
* const result = await app.run({
|
|
1367
|
+
* props: { system: "You are helpful" },
|
|
1368
|
+
* messages: [{ role: "user", content: [{ type: "text", text: "Follow up" }] }],
|
|
1369
|
+
* history: previousConversation.entries,
|
|
1370
|
+
* maxTicks: 5,
|
|
1371
|
+
* devTools: true,
|
|
1372
|
+
* }).result;
|
|
1373
|
+
* ```
|
|
1374
|
+
*
|
|
1375
|
+
* @example Use handle for control
|
|
1376
|
+
* ```typescript
|
|
1377
|
+
* const handle = await app.run({ messages });
|
|
1378
|
+
* handle.queueMessage({ role: "user", content: [...] });
|
|
1379
|
+
* const result = await handle.result;
|
|
1380
|
+
* ```
|
|
1381
|
+
*/
|
|
1382
|
+
run: Procedure<(input: RunInput<P>) => SessionExecutionHandle, true>;
|
|
1383
|
+
/**
|
|
1384
|
+
* Send to a session.
|
|
1385
|
+
*
|
|
1386
|
+
* Without sessionId: creates ephemeral session, executes, destroys.
|
|
1387
|
+
* With sessionId: creates or reuses managed session (may hydrate from store).
|
|
1388
|
+
*/
|
|
1389
|
+
send(input: SendInput<P>, options?: {
|
|
1390
|
+
sessionId?: string;
|
|
1391
|
+
}): Promise<SessionExecutionHandle>;
|
|
1392
|
+
/**
|
|
1393
|
+
* Get or create a session.
|
|
1394
|
+
*
|
|
1395
|
+
* This is the primary way to access sessions:
|
|
1396
|
+
* - `session()` - Creates new session with generated ID
|
|
1397
|
+
* - `session('id')` - Gets existing or creates new session with that ID
|
|
1398
|
+
* - `session({ sessionId, ...opts })` - Gets or creates with options
|
|
1399
|
+
*
|
|
1400
|
+
* Use `app.has(id)` to check if a session exists without creating it.
|
|
1401
|
+
*
|
|
1402
|
+
* @example
|
|
1403
|
+
* ```typescript
|
|
1404
|
+
* // New session with generated ID
|
|
1405
|
+
* const session = app.session();
|
|
1406
|
+
*
|
|
1407
|
+
* // Get or create by ID
|
|
1408
|
+
* const conv = app.session('conv-123');
|
|
1409
|
+
*
|
|
1410
|
+
* // With options
|
|
1411
|
+
* const withOpts = await app.session({ sessionId: 'conv-456', maxTicks: 5 });
|
|
1412
|
+
* const newWithOpts = await app.session({ maxTicks: 5 }); // Generated ID
|
|
1413
|
+
* ```
|
|
1414
|
+
*/
|
|
1415
|
+
session(id?: string): Promise<Session<P>>;
|
|
1416
|
+
session(options: SessionOptions): Promise<Session<P>>;
|
|
1417
|
+
/**
|
|
1418
|
+
* Close and cleanup a session.
|
|
1419
|
+
*/
|
|
1420
|
+
close(sessionId: string): Promise<void>;
|
|
1421
|
+
/**
|
|
1422
|
+
* List active session IDs.
|
|
1423
|
+
*/
|
|
1424
|
+
readonly sessions: readonly string[];
|
|
1425
|
+
/**
|
|
1426
|
+
* Check if a session exists (in memory).
|
|
1427
|
+
*/
|
|
1428
|
+
has(sessionId: string): boolean;
|
|
1429
|
+
/**
|
|
1430
|
+
* Check if a session is hibernated (in storage but not in memory).
|
|
1431
|
+
*
|
|
1432
|
+
* Returns false if no SessionStore is configured.
|
|
1433
|
+
*/
|
|
1434
|
+
isHibernated(sessionId: string): Promise<boolean>;
|
|
1435
|
+
/**
|
|
1436
|
+
* Hibernate a session by ID.
|
|
1437
|
+
*
|
|
1438
|
+
* Convenience method equivalent to `app.session(id).hibernate()`.
|
|
1439
|
+
* Returns the snapshot that was saved, or null if:
|
|
1440
|
+
* - Session doesn't exist
|
|
1441
|
+
* - Hibernation was cancelled by onBeforeHibernate
|
|
1442
|
+
* - No SessionStore is configured
|
|
1443
|
+
*/
|
|
1444
|
+
hibernate(sessionId: string): Promise<SessionSnapshot | null>;
|
|
1445
|
+
/**
|
|
1446
|
+
* List all hibernated session IDs.
|
|
1447
|
+
*
|
|
1448
|
+
* Returns empty array if no SessionStore is configured or
|
|
1449
|
+
* if the store doesn't implement `list()`.
|
|
1450
|
+
*/
|
|
1451
|
+
hibernatedSessions(): Promise<string[]>;
|
|
1452
|
+
/**
|
|
1453
|
+
* Register onSessionCreate handler.
|
|
1454
|
+
*/
|
|
1455
|
+
onSessionCreate(handler: (session: Session<P>) => void): () => void;
|
|
1456
|
+
/**
|
|
1457
|
+
* Register onSessionClose handler.
|
|
1458
|
+
*/
|
|
1459
|
+
onSessionClose(handler: (sessionId: string) => void): () => void;
|
|
1460
|
+
}
|
|
1461
|
+
//# sourceMappingURL=types.d.ts.map
|