@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,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V2 Session Hibernation
|
|
3
|
+
*
|
|
4
|
+
* Serialize and restore session state for persistence.
|
|
5
|
+
*
|
|
6
|
+
* Unlike React's hydration (which is about attaching to pre-rendered DOM),
|
|
7
|
+
* this is about serializing our state and restoring it later.
|
|
8
|
+
*
|
|
9
|
+
* Key insight: We don't need to serialize React's fiber tree. We serialize
|
|
10
|
+
* OUR state, and React rebuilds its tree from scratch on restore. Since our
|
|
11
|
+
* hooks (useData, etc.) read from our caches, the render produces the same
|
|
12
|
+
* output as before hibernation.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Create a serializable snapshot of the session state.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const snapshot = hibernate(compiler, {
|
|
20
|
+
* sessionId: session.id,
|
|
21
|
+
* tick: session.currentTick,
|
|
22
|
+
* timeline: session.timeline,
|
|
23
|
+
* comState: session.ctx.state,
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Store snapshot
|
|
27
|
+
* await db.sessions.save(session.id, JSON.stringify(snapshot));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function hibernate(compiler, state, options = {}) {
|
|
31
|
+
return {
|
|
32
|
+
version: 1,
|
|
33
|
+
sessionId: state.sessionId,
|
|
34
|
+
tick: state.tick,
|
|
35
|
+
timeline: state.timeline.map((entry) => ({
|
|
36
|
+
id: entry.id,
|
|
37
|
+
role: entry.role,
|
|
38
|
+
content: entry.content,
|
|
39
|
+
createdAt: entry.createdAt.toISOString(),
|
|
40
|
+
})),
|
|
41
|
+
comState: Object.fromEntries(state.comState),
|
|
42
|
+
dataCache: compiler.getSerializableDataCache(),
|
|
43
|
+
createdAt: new Date().toISOString(),
|
|
44
|
+
metadata: options.metadata,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Restore session state from a snapshot.
|
|
49
|
+
*
|
|
50
|
+
* This restores our caches and returns the state to apply to a session.
|
|
51
|
+
* The session can then render and React will produce the same output
|
|
52
|
+
* because our hooks read from the restored caches.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Load snapshot from storage
|
|
57
|
+
* const json = await db.sessions.get(sessionId);
|
|
58
|
+
* const snapshot = JSON.parse(json) as SessionSnapshot;
|
|
59
|
+
*
|
|
60
|
+
* // Create compiler first
|
|
61
|
+
* const compiler = new FiberCompiler(ctx);
|
|
62
|
+
*
|
|
63
|
+
* // Hydrate - restores data cache into compiler
|
|
64
|
+
* const state = hydrate(compiler, snapshot);
|
|
65
|
+
*
|
|
66
|
+
* // Now create/configure session with restored state
|
|
67
|
+
* session.timeline = state.timeline;
|
|
68
|
+
* session.currentTick = state.tick;
|
|
69
|
+
* // etc.
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function hydrate(compiler, snapshot) {
|
|
73
|
+
// Validate version
|
|
74
|
+
if (snapshot.version !== 1) {
|
|
75
|
+
throw new Error(`Unsupported snapshot version: ${snapshot.version}`);
|
|
76
|
+
}
|
|
77
|
+
// Restore data cache into the compiler's runtime store
|
|
78
|
+
compiler.setDataCache(snapshot.dataCache);
|
|
79
|
+
// Convert timeline dates back
|
|
80
|
+
const timeline = snapshot.timeline.map((entry) => ({
|
|
81
|
+
id: entry.id,
|
|
82
|
+
role: entry.role,
|
|
83
|
+
content: entry.content,
|
|
84
|
+
createdAt: new Date(entry.createdAt),
|
|
85
|
+
}));
|
|
86
|
+
// Convert comState back to Map
|
|
87
|
+
const comState = new Map(Object.entries(snapshot.comState));
|
|
88
|
+
return {
|
|
89
|
+
sessionId: snapshot.sessionId,
|
|
90
|
+
tick: snapshot.tick,
|
|
91
|
+
timeline,
|
|
92
|
+
comState,
|
|
93
|
+
metadata: snapshot.metadata,
|
|
94
|
+
snapshotCreatedAt: new Date(snapshot.createdAt),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// ============================================================
|
|
98
|
+
// Utilities
|
|
99
|
+
// ============================================================
|
|
100
|
+
/**
|
|
101
|
+
* Check if a snapshot is valid.
|
|
102
|
+
*/
|
|
103
|
+
export function isValidSnapshot(obj) {
|
|
104
|
+
if (!obj || typeof obj !== "object")
|
|
105
|
+
return false;
|
|
106
|
+
const s = obj;
|
|
107
|
+
return (s.version === 1 &&
|
|
108
|
+
typeof s.sessionId === "string" &&
|
|
109
|
+
typeof s.tick === "number" &&
|
|
110
|
+
Array.isArray(s.timeline) &&
|
|
111
|
+
typeof s.comState === "object" &&
|
|
112
|
+
typeof s.dataCache === "object" &&
|
|
113
|
+
typeof s.createdAt === "string");
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get snapshot age in milliseconds.
|
|
117
|
+
*/
|
|
118
|
+
export function getSnapshotAge(snapshot) {
|
|
119
|
+
return Date.now() - new Date(snapshot.createdAt).getTime();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a deep clone of a snapshot (for testing/debugging).
|
|
123
|
+
*/
|
|
124
|
+
export function cloneSnapshot(snapshot) {
|
|
125
|
+
return JSON.parse(JSON.stringify(snapshot));
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hibernation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA2D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Aa,CAAC,QAAyB;IACrD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HookRegistry } from "./hook-registry";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for hook registries that provides common overloaded register methods.
|
|
4
|
+
* Reduces code duplication across ModelHookRegistry, ToolHookRegistry, etc.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseHookRegistry<THookName extends string, TSelector, THookMiddleware> {
|
|
7
|
+
protected registry: HookRegistry<THookName, TSelector, THookMiddleware>;
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Get all possible hook names for this registry.
|
|
11
|
+
* Must be implemented by subclasses.
|
|
12
|
+
*/
|
|
13
|
+
protected abstract getAllHookNames(): readonly THookName[];
|
|
14
|
+
/**
|
|
15
|
+
* Check if a value is a hook name.
|
|
16
|
+
* Can be overridden by subclasses to provide custom logic.
|
|
17
|
+
* Default implementation checks if the value is in getAllHookNames().
|
|
18
|
+
*/
|
|
19
|
+
protected isHookName(value: any): value is THookName;
|
|
20
|
+
/**
|
|
21
|
+
* Register middleware for a hook.
|
|
22
|
+
*
|
|
23
|
+
* Overloads:
|
|
24
|
+
* - register(hookName, selector, middleware) - specific hook, specific selector
|
|
25
|
+
* - register(hookName, middleware) - specific hook, global selector
|
|
26
|
+
* - register(selector, middleware) - all hooks, specific selector (if selectors are supported)
|
|
27
|
+
* - register(middleware) - all hooks, global selector
|
|
28
|
+
*/
|
|
29
|
+
register<T extends THookName>(hookName: T, selector: TSelector | undefined, middleware: THookMiddleware): void;
|
|
30
|
+
register<T extends THookName>(hookName: T, middleware: THookMiddleware): void;
|
|
31
|
+
register(selector: TSelector, middleware: THookMiddleware): void;
|
|
32
|
+
register(middleware: THookMiddleware): void;
|
|
33
|
+
/**
|
|
34
|
+
* Copy all hooks from another registry of the same type.
|
|
35
|
+
* Useful for inheriting hooks from parent engine to child engine.
|
|
36
|
+
*
|
|
37
|
+
* @param sourceRegistry - The registry to copy hooks from
|
|
38
|
+
*/
|
|
39
|
+
copyHooksFrom(sourceRegistry: BaseHookRegistry<THookName, TSelector, THookMiddleware>): void;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=base-hook-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-hook-registry.d.ts","sourceRoot":"","sources":["../../src/hooks/base-hook-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;GAGG;AACH,8BAAsB,gBAAgB,CAAC,SAAS,SAAS,MAAM,EAAE,SAAS,EAAE,eAAe;IACzF,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;;IAMxE;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,eAAe,IAAI,SAAS,SAAS,EAAE;IAE1D;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,SAAS;IAIpD;;;;;;;;OAQG;IACH,QAAQ,CAAC,CAAC,SAAS,SAAS,EAC1B,QAAQ,EAAE,CAAC,EACX,QAAQ,EAAE,SAAS,GAAG,SAAS,EAC/B,UAAU,EAAE,eAAe,GAC1B,IAAI;IACP,QAAQ,CAAC,CAAC,SAAS,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,eAAe,GAAG,IAAI;IAC7E,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,GAAG,IAAI;IAChE,QAAQ,CAAC,UAAU,EAAE,eAAe,GAAG,IAAI;IAwC3C;;;;;OAKG;IACH,aAAa,CAAC,cAAc,EAAE,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,eAAe,CAAC,GAAG,IAAI;CAe7F"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { HookRegistry } from "./hook-registry";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for hook registries that provides common overloaded register methods.
|
|
4
|
+
* Reduces code duplication across ModelHookRegistry, ToolHookRegistry, etc.
|
|
5
|
+
*/
|
|
6
|
+
export class BaseHookRegistry {
|
|
7
|
+
registry;
|
|
8
|
+
constructor() {
|
|
9
|
+
this.registry = new HookRegistry();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Check if a value is a hook name.
|
|
13
|
+
* Can be overridden by subclasses to provide custom logic.
|
|
14
|
+
* Default implementation checks if the value is in getAllHookNames().
|
|
15
|
+
*/
|
|
16
|
+
isHookName(value) {
|
|
17
|
+
return this.getAllHookNames().includes(value);
|
|
18
|
+
}
|
|
19
|
+
register(arg1, arg2, arg3) {
|
|
20
|
+
const allHookNames = this.getAllHookNames();
|
|
21
|
+
// Determine which overload was called
|
|
22
|
+
if (arg3 !== undefined) {
|
|
23
|
+
// register(hookName, selector, middleware)
|
|
24
|
+
const hookName = arg1;
|
|
25
|
+
const selector = arg2;
|
|
26
|
+
const middleware = arg3;
|
|
27
|
+
this.registry.register(hookName, selector, middleware);
|
|
28
|
+
}
|
|
29
|
+
else if (arg2 !== undefined) {
|
|
30
|
+
// Could be register(hookName, middleware) or register(selector, middleware)
|
|
31
|
+
// Check if arg1 is a hook name
|
|
32
|
+
if (this.isHookName(arg1)) {
|
|
33
|
+
// register(hookName, middleware) - specific hook, global selector
|
|
34
|
+
const hookName = arg1;
|
|
35
|
+
const middleware = arg2;
|
|
36
|
+
this.registry.register(hookName, undefined, middleware);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// register(selector, middleware) - all hooks, specific selector
|
|
40
|
+
const selector = arg1;
|
|
41
|
+
const middleware = arg2;
|
|
42
|
+
for (const hookName of allHookNames) {
|
|
43
|
+
this.registry.register(hookName, selector, middleware);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// register(middleware) - all hooks, global selector
|
|
49
|
+
const middleware = arg1;
|
|
50
|
+
for (const hookName of allHookNames) {
|
|
51
|
+
this.registry.register(hookName, undefined, middleware);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Copy all hooks from another registry of the same type.
|
|
57
|
+
* Useful for inheriting hooks from parent engine to child engine.
|
|
58
|
+
*
|
|
59
|
+
* @param sourceRegistry - The registry to copy hooks from
|
|
60
|
+
*/
|
|
61
|
+
copyHooksFrom(sourceRegistry) {
|
|
62
|
+
const allHookNames = this.getAllHookNames();
|
|
63
|
+
for (const hookName of allHookNames) {
|
|
64
|
+
const sourceHookMap = sourceRegistry.registry.getHookMap(hookName);
|
|
65
|
+
if (sourceHookMap) {
|
|
66
|
+
// Copy all middleware for each selector (including undefined for global)
|
|
67
|
+
for (const [selector, middlewareArray] of sourceHookMap.entries()) {
|
|
68
|
+
for (const middleware of middlewareArray) {
|
|
69
|
+
this.registry.register(hookName, selector, middleware);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=base-hook-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-hook-registry.js","sourceRoot":"","sources":["../../src/hooks/base-hook-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;GAGG;AACH,MAAM,OAAgB,gBAAgB;IAC1B,QAAQ,CAAsD;IAExE;QACE,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAyC,CAAC;IAC5E,CAAC;IAQD;;;;OAIG;IACO,UAAU,CAAC,KAAU;QAC7B,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAmBD,Q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C;IACH,CAAC;IAED;;;;;OAKG;IACH,aAAa,CAAC,cAAuE;QACnF,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAE5C,KAAK,MAAM,QAAQ,IAAI,YAAY,EAAE,CAAC;YACpC,MAAM,aAAa,GAAG,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YACnE,IAAI,aAAa,EAAE,CAAC;gBAClB,yEAAyE;gBACzE,KAAK,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,IAAI,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC;oBAClE,KAAK,MAAM,UAAU,IAAI,eAAe,EAAE,CAAC;wBACzC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;oBACzD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* COM State Hook
|
|
3
|
+
*
|
|
4
|
+
* Provides state storage in the COM (Context Object Model).
|
|
5
|
+
* State persists across renders and changes trigger re-renders.
|
|
6
|
+
*
|
|
7
|
+
* This is similar to useState but:
|
|
8
|
+
* - State is stored in the shared COM, not component-local
|
|
9
|
+
* - State persists across ticks
|
|
10
|
+
* - Returns a Signal-like interface
|
|
11
|
+
*
|
|
12
|
+
* Reactivity: Subscribes to COM's "state:changed" events via a React
|
|
13
|
+
* version counter, ensuring the component re-renders when state is
|
|
14
|
+
* modified externally (e.g. from a tool handler).
|
|
15
|
+
*/
|
|
16
|
+
import type { Signal } from "./signal";
|
|
17
|
+
/**
|
|
18
|
+
* Use state stored in the COM.
|
|
19
|
+
*
|
|
20
|
+
* @param key - Unique key for this state in the COM
|
|
21
|
+
* @param initialValue - Initial value if not already set
|
|
22
|
+
* @returns A Signal-like object for reading and writing the state
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* function StatusComponent() {
|
|
27
|
+
* const status = useComState('status', 'pending');
|
|
28
|
+
*
|
|
29
|
+
* // Read the value
|
|
30
|
+
* console.log(status()); // or status.value
|
|
31
|
+
*
|
|
32
|
+
* // Update the value
|
|
33
|
+
* status.set('active');
|
|
34
|
+
*
|
|
35
|
+
* return <System>Status: {status()}</System>;
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function useComState<T>(key: string, initialValue: T): Signal<T>;
|
|
40
|
+
//# sourceMappingURL=com-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"com-state.d.ts","sourceRoot":"","sources":["../../src/hooks/com-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAgEtE"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* COM State Hook
|
|
3
|
+
*
|
|
4
|
+
* Provides state storage in the COM (Context Object Model).
|
|
5
|
+
* State persists across renders and changes trigger re-renders.
|
|
6
|
+
*
|
|
7
|
+
* This is similar to useState but:
|
|
8
|
+
* - State is stored in the shared COM, not component-local
|
|
9
|
+
* - State persists across ticks
|
|
10
|
+
* - Returns a Signal-like interface
|
|
11
|
+
*
|
|
12
|
+
* Reactivity: Subscribes to COM's "state:changed" events via a React
|
|
13
|
+
* version counter, ensuring the component re-renders when state is
|
|
14
|
+
* modified externally (e.g. from a tool handler).
|
|
15
|
+
*/
|
|
16
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
17
|
+
import { useCom } from "./context";
|
|
18
|
+
/**
|
|
19
|
+
* Use state stored in the COM.
|
|
20
|
+
*
|
|
21
|
+
* @param key - Unique key for this state in the COM
|
|
22
|
+
* @param initialValue - Initial value if not already set
|
|
23
|
+
* @returns A Signal-like object for reading and writing the state
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* function StatusComponent() {
|
|
28
|
+
* const status = useComState('status', 'pending');
|
|
29
|
+
*
|
|
30
|
+
* // Read the value
|
|
31
|
+
* console.log(status()); // or status.value
|
|
32
|
+
*
|
|
33
|
+
* // Update the value
|
|
34
|
+
* status.set('active');
|
|
35
|
+
*
|
|
36
|
+
* return <System>Status: {status()}</System>;
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function useComState(key, initialValue) {
|
|
41
|
+
const ctx = useCom();
|
|
42
|
+
// Initialize if needed
|
|
43
|
+
if (ctx.getState(key) === undefined) {
|
|
44
|
+
ctx.setState(key, initialValue);
|
|
45
|
+
}
|
|
46
|
+
// Version counter triggers React re-render when COM state changes externally
|
|
47
|
+
const [, setVersion] = useState(0);
|
|
48
|
+
const setVersionRef = useRef(setVersion);
|
|
49
|
+
setVersionRef.current = setVersion;
|
|
50
|
+
// Subscribe to COM "state:changed" events for this key
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const handler = (changedKey) => {
|
|
53
|
+
if (changedKey === key) {
|
|
54
|
+
setVersionRef.current((v) => v + 1);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
ctx.on("state:changed", handler);
|
|
58
|
+
return () => {
|
|
59
|
+
ctx.off("state:changed", handler);
|
|
60
|
+
};
|
|
61
|
+
}, [ctx, key]);
|
|
62
|
+
// Read directly from COM (always fresh — works in tool handlers, effects, etc.)
|
|
63
|
+
const getValue = useCallback(() => {
|
|
64
|
+
return (ctx.getState(key) ?? initialValue);
|
|
65
|
+
}, [ctx, key, initialValue]);
|
|
66
|
+
// Set a new value — writes to COM, which emits event, which triggers re-render
|
|
67
|
+
const setValue = useCallback((value) => {
|
|
68
|
+
const currentValue = getValue();
|
|
69
|
+
const newValue = typeof value === "function" ? value(currentValue) : value;
|
|
70
|
+
ctx.setState(key, newValue);
|
|
71
|
+
ctx.requestRecompile(`COM state '${key}' changed`);
|
|
72
|
+
}, [ctx, key, getValue]);
|
|
73
|
+
// Update with function
|
|
74
|
+
const update = useCallback((fn) => {
|
|
75
|
+
setValue(fn);
|
|
76
|
+
}, [setValue]);
|
|
77
|
+
// Create the Signal-like interface — reads from COM directly, always fresh
|
|
78
|
+
const signal = useMemo(() => {
|
|
79
|
+
const fn = getValue;
|
|
80
|
+
Object.defineProperty(fn, "value", {
|
|
81
|
+
get: getValue,
|
|
82
|
+
enumerable: true,
|
|
83
|
+
});
|
|
84
|
+
fn.set = setValue;
|
|
85
|
+
fn.update = update;
|
|
86
|
+
return fn;
|
|
87
|
+
}, [getValue, setValue, update]);
|
|
88
|
+
return signal;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=com-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"com-state.js","sourceRoot":"","sources":["../../src/hooks/com-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,WAAW,CAAI,GAAW,EAAE,YAAe;IACzD,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IAErB,uBAAuB;IACvB,IAAI,GAAG,CAAC,QAAQ,CAAI,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;QACvC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,6EAA6E;IAC7E,MAAM,CAAC,EAAE,UAA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AAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CACrB,CAAC;IAEF,uBAAuB;IACvB,MAAM,MAAM,GAAG,WAAW,CACxB,CAAC,EAAkB,EAAE,EAAE;QACrB,QAAQ,CAAC,EAAE,CAAC,CAAC;IACf,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,2EAA2E;IAC3E,MAAM,MAAM,GAAG,OAAO,CAAC,GAAc,EAAE;QACrC,MAAM,EAAE,GAAG,QAAqB,CAAC;QACjC,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE;YACjC,GAAG,EAAE,QAAQ;YACb,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QACH,EAAE,CAAC,GAAG,GAAG,QAAQ,CAAC;QAClB,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC;QACnB,OAAO,EAAE,CAAC;IACZ,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IAEjC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Info Hook
|
|
3
|
+
*
|
|
4
|
+
* Provides real-time access to context utilization information within JSX components.
|
|
5
|
+
* Updated by the session after each tick with token usage and model capabilities.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function MyComponent() {
|
|
10
|
+
* const contextInfo = useContextInfo();
|
|
11
|
+
*
|
|
12
|
+
* if (contextInfo?.utilization && contextInfo.utilization > 80) {
|
|
13
|
+
* // Context is getting full, maybe summarize or truncate
|
|
14
|
+
* return <Section id="summary">Summarized content...</Section>;
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* return <Section id="full">Full detailed content...</Section>;
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import React, { type ReactNode } from "react";
|
|
22
|
+
/**
|
|
23
|
+
* Context utilization information.
|
|
24
|
+
* Updated after each tick with current token usage and model info.
|
|
25
|
+
*/
|
|
26
|
+
export interface ContextInfo {
|
|
27
|
+
/** Model ID (e.g., "gpt-4o", "claude-3-5-sonnet-20241022") */
|
|
28
|
+
modelId: string;
|
|
29
|
+
/** Human-readable model name */
|
|
30
|
+
modelName?: string;
|
|
31
|
+
/** Provider name (e.g., "openai", "anthropic") */
|
|
32
|
+
provider?: string;
|
|
33
|
+
/** Context window size in tokens */
|
|
34
|
+
contextWindow?: number;
|
|
35
|
+
/** Input tokens used this tick */
|
|
36
|
+
inputTokens: number;
|
|
37
|
+
/** Output tokens generated this tick */
|
|
38
|
+
outputTokens: number;
|
|
39
|
+
/** Total tokens this tick */
|
|
40
|
+
totalTokens: number;
|
|
41
|
+
/** Context utilization percentage (0-100) */
|
|
42
|
+
utilization?: number;
|
|
43
|
+
/** Max output tokens for this model */
|
|
44
|
+
maxOutputTokens?: number;
|
|
45
|
+
/** Model capabilities */
|
|
46
|
+
supportsVision?: boolean;
|
|
47
|
+
supportsToolUse?: boolean;
|
|
48
|
+
isReasoningModel?: boolean;
|
|
49
|
+
/** Estimated total context tokens (from token estimation, pre-model-call) */
|
|
50
|
+
estimatedContextTokens?: number;
|
|
51
|
+
/** Current tick number */
|
|
52
|
+
tick: number;
|
|
53
|
+
/** Cumulative usage across all ticks in this execution */
|
|
54
|
+
cumulativeUsage?: {
|
|
55
|
+
inputTokens: number;
|
|
56
|
+
outputTokens: number;
|
|
57
|
+
totalTokens: number;
|
|
58
|
+
ticks: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Context info store - holds current context utilization state.
|
|
63
|
+
*/
|
|
64
|
+
export interface ContextInfoStore {
|
|
65
|
+
/** Current context info (null before first tick completes) */
|
|
66
|
+
current: ContextInfo | null;
|
|
67
|
+
/** Update the context info */
|
|
68
|
+
update: (info: ContextInfo) => void;
|
|
69
|
+
/** Clear the context info */
|
|
70
|
+
clear: () => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a new context info store.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createContextInfoStore(): ContextInfoStore;
|
|
76
|
+
/**
|
|
77
|
+
* Get the context info store from context.
|
|
78
|
+
* Returns null if not within a provider (for optional access).
|
|
79
|
+
*/
|
|
80
|
+
export declare function useContextInfoStore(): ContextInfoStore | null;
|
|
81
|
+
/**
|
|
82
|
+
* Hook to access current context utilization info.
|
|
83
|
+
*
|
|
84
|
+
* Returns null if:
|
|
85
|
+
* - Not within a session (no ContextInfoProvider)
|
|
86
|
+
* - Before first tick completes
|
|
87
|
+
*
|
|
88
|
+
* @example Basic usage
|
|
89
|
+
* ```tsx
|
|
90
|
+
* function MyComponent() {
|
|
91
|
+
* const contextInfo = useContextInfo();
|
|
92
|
+
*
|
|
93
|
+
* if (!contextInfo) {
|
|
94
|
+
* return null; // Not available yet
|
|
95
|
+
* }
|
|
96
|
+
*
|
|
97
|
+
* console.log(`Using ${contextInfo.utilization}% of context`);
|
|
98
|
+
* return <Section id="content">...</Section>;
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example Conditional rendering based on context usage
|
|
103
|
+
* ```tsx
|
|
104
|
+
* function AdaptiveContent() {
|
|
105
|
+
* const contextInfo = useContextInfo();
|
|
106
|
+
*
|
|
107
|
+
* // If context is over 75% full, use abbreviated content
|
|
108
|
+
* const isContextTight = contextInfo?.utilization && contextInfo.utilization > 75;
|
|
109
|
+
*
|
|
110
|
+
* return isContextTight
|
|
111
|
+
* ? <Section id="brief">Brief summary...</Section>
|
|
112
|
+
* : <Section id="detailed">Full detailed content...</Section>;
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example Access model capabilities
|
|
117
|
+
* ```tsx
|
|
118
|
+
* function ImageTool() {
|
|
119
|
+
* const contextInfo = useContextInfo();
|
|
120
|
+
*
|
|
121
|
+
* // Only render image tool if model supports vision
|
|
122
|
+
* if (!contextInfo?.supportsVision) {
|
|
123
|
+
* return null;
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
* return <Tool name="analyze_image" ... />;
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare function useContextInfo(): ContextInfo | null;
|
|
131
|
+
/**
|
|
132
|
+
* Provider for context info.
|
|
133
|
+
* Used internally by Session to make context info available to components.
|
|
134
|
+
*/
|
|
135
|
+
export declare function ContextInfoProvider({ store, children, }: {
|
|
136
|
+
store: ContextInfoStore;
|
|
137
|
+
children?: ReactNode;
|
|
138
|
+
}): React.ReactElement;
|
|
139
|
+
//# sourceMappingURL=context-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-info.d.ts","sourceRoot":"","sources":["../../src/hooks/context-info.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AASzE;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yBAAyB;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,6EAA6E;IAC7E,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,eAAe,CAAC,EAAE;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,8BAA8B;IAC9B,MAAM,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IACpC,6BAA6B;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAMD;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAczD;AAQD;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,IAAI,CAE7D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,cAAc,IAAI,WAAW,GAAG,IAAI,CAGnD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,GAAG,KAAK,CAAC,YAAY,CAErB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Info Hook
|
|
3
|
+
*
|
|
4
|
+
* Provides real-time access to context utilization information within JSX components.
|
|
5
|
+
* Updated by the session after each tick with token usage and model capabilities.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function MyComponent() {
|
|
10
|
+
* const contextInfo = useContextInfo();
|
|
11
|
+
*
|
|
12
|
+
* if (contextInfo?.utilization && contextInfo.utilization > 80) {
|
|
13
|
+
* // Context is getting full, maybe summarize or truncate
|
|
14
|
+
* return <Section id="summary">Summarized content...</Section>;
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* return <Section id="full">Full detailed content...</Section>;
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import React, { createContext, useContext } from "react";
|
|
22
|
+
// Helper for createElement
|
|
23
|
+
const h = React.createElement;
|
|
24
|
+
// ============================================================
|
|
25
|
+
// Store Factory
|
|
26
|
+
// ============================================================
|
|
27
|
+
/**
|
|
28
|
+
* Create a new context info store.
|
|
29
|
+
*/
|
|
30
|
+
export function createContextInfoStore() {
|
|
31
|
+
let current = null;
|
|
32
|
+
return {
|
|
33
|
+
get current() {
|
|
34
|
+
return current;
|
|
35
|
+
},
|
|
36
|
+
update(info) {
|
|
37
|
+
current = info;
|
|
38
|
+
},
|
|
39
|
+
clear() {
|
|
40
|
+
current = null;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// ============================================================
|
|
45
|
+
// React Context
|
|
46
|
+
// ============================================================
|
|
47
|
+
const ContextInfoContext = createContext(null);
|
|
48
|
+
/**
|
|
49
|
+
* Get the context info store from context.
|
|
50
|
+
* Returns null if not within a provider (for optional access).
|
|
51
|
+
*/
|
|
52
|
+
export function useContextInfoStore() {
|
|
53
|
+
return useContext(ContextInfoContext);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Hook to access current context utilization info.
|
|
57
|
+
*
|
|
58
|
+
* Returns null if:
|
|
59
|
+
* - Not within a session (no ContextInfoProvider)
|
|
60
|
+
* - Before first tick completes
|
|
61
|
+
*
|
|
62
|
+
* @example Basic usage
|
|
63
|
+
* ```tsx
|
|
64
|
+
* function MyComponent() {
|
|
65
|
+
* const contextInfo = useContextInfo();
|
|
66
|
+
*
|
|
67
|
+
* if (!contextInfo) {
|
|
68
|
+
* return null; // Not available yet
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* console.log(`Using ${contextInfo.utilization}% of context`);
|
|
72
|
+
* return <Section id="content">...</Section>;
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example Conditional rendering based on context usage
|
|
77
|
+
* ```tsx
|
|
78
|
+
* function AdaptiveContent() {
|
|
79
|
+
* const contextInfo = useContextInfo();
|
|
80
|
+
*
|
|
81
|
+
* // If context is over 75% full, use abbreviated content
|
|
82
|
+
* const isContextTight = contextInfo?.utilization && contextInfo.utilization > 75;
|
|
83
|
+
*
|
|
84
|
+
* return isContextTight
|
|
85
|
+
* ? <Section id="brief">Brief summary...</Section>
|
|
86
|
+
* : <Section id="detailed">Full detailed content...</Section>;
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @example Access model capabilities
|
|
91
|
+
* ```tsx
|
|
92
|
+
* function ImageTool() {
|
|
93
|
+
* const contextInfo = useContextInfo();
|
|
94
|
+
*
|
|
95
|
+
* // Only render image tool if model supports vision
|
|
96
|
+
* if (!contextInfo?.supportsVision) {
|
|
97
|
+
* return null;
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* return <Tool name="analyze_image" ... />;
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function useContextInfo() {
|
|
105
|
+
const store = useContext(ContextInfoContext);
|
|
106
|
+
return store?.current ?? null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Provider for context info.
|
|
110
|
+
* Used internally by Session to make context info available to components.
|
|
111
|
+
*/
|
|
112
|
+
export function ContextInfoProvider({ store, children, }) {
|
|
113
|
+
return h(ContextInfoContext.Provider, { value: store }, children);
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=context-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-info.js","sourceRoot":"","sources":["../../src/hooks/context-info.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAEzE,2BAA2B;AAC3B,MAAM,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC;AA0D9B,+DAA+D;AAC/D,gBAAgB;AAChB,+DAA+D;AAE/D;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACpC,IAAI,OAAO,GAAuB,IAAI,CAAC;IAEvC,OAAO;QACL,IAAI,OAAO;YACT,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,MAAM,CAAC,IAAiB;YACtB,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;QACD,KAAK;YACH,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,+DAA+D;AAC/D,gBAAgB;AAChB,+DAA+D;AAE/D,MAAM,kBAAkB,GAAG,aAAa,CAA0B,IAAI,CAAC,CAAC;AAExE;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,UAAU,CAAC,kBAAkB,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC7C,OAAO,KAAK,EAAE,OAAO,IAAI,IAAI,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,GAIT;IACC,OAAO,CAAC,CAAC,kBAAkB,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,CAAC;AACpE,CAAC"}
|