@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,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boundary System for Tentickle
|
|
3
|
+
*
|
|
4
|
+
* Boundaries extend Context with collection-phase effects. They provide a generic
|
|
5
|
+
* mechanism for components that affect how their children are processed during
|
|
6
|
+
* compilation, without hardcoding specific component checks in the compiler.
|
|
7
|
+
*
|
|
8
|
+
* The abstraction ladder:
|
|
9
|
+
* - createContext: render-phase values, read via useContext
|
|
10
|
+
* - createBoundary: render-phase values + collection-phase effects
|
|
11
|
+
* - createFormatter: convenience for formatter boundaries (collection-time)
|
|
12
|
+
* - createPolicy: convenience for policy boundaries (format-time, auto-accumulating)
|
|
13
|
+
*
|
|
14
|
+
* @example Formatter boundary (like XML, Markdown)
|
|
15
|
+
* ```tsx
|
|
16
|
+
* // XML/Markdown use the unified FormatterBoundary
|
|
17
|
+
* <XML>
|
|
18
|
+
* <Content />
|
|
19
|
+
* </XML>
|
|
20
|
+
*
|
|
21
|
+
* // To get the current formatter during render:
|
|
22
|
+
* const formatter = useBoundary(FormatterBoundary);
|
|
23
|
+
* if (formatter) {
|
|
24
|
+
* const formatted = formatter.formatter(blocks);
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Policy boundary (like TokenBudget)
|
|
29
|
+
* ```tsx
|
|
30
|
+
* // Policies auto-accumulate - nested policies are combined
|
|
31
|
+
* <TokenBudget maxTokens={8000} strategy="drop-oldest">
|
|
32
|
+
* <Timeline />
|
|
33
|
+
* <TokenBudget maxTokens={2000} strategy="truncate">
|
|
34
|
+
* <User>{message}</User> {/* Both policies apply \*\/}
|
|
35
|
+
* </TokenBudget>
|
|
36
|
+
* </TokenBudget>
|
|
37
|
+
*
|
|
38
|
+
* // To get all active policies during render:
|
|
39
|
+
* const policyValue = useBoundary(PolicyBoundary);
|
|
40
|
+
* if (policyValue) {
|
|
41
|
+
* console.log('Active policies:', policyValue.policies.map(p => p.name));
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @module tentickle/boundary
|
|
46
|
+
*/
|
|
47
|
+
import type { JSX } from "../jsx/jsx-runtime";
|
|
48
|
+
import { type Context } from "./context";
|
|
49
|
+
import type { Formatter } from "../renderers";
|
|
50
|
+
import type { COMTimelineEntry } from "../com/types";
|
|
51
|
+
/**
|
|
52
|
+
* Symbol used to mark boundary provider components.
|
|
53
|
+
* The fiber compiler detects this to handle boundary effects.
|
|
54
|
+
*/
|
|
55
|
+
export declare const BOUNDARY_PROVIDER_SYMBOL: unique symbol;
|
|
56
|
+
/**
|
|
57
|
+
* Boundary class determines how the compiler handles the boundary.
|
|
58
|
+
* - 'formatter': Affects content rendering during collection (e.g., XML, Markdown)
|
|
59
|
+
* - 'policy': Affects entries after collection, during formatInput (e.g., TokenBudget)
|
|
60
|
+
*/
|
|
61
|
+
export type BoundaryClass = "formatter" | "policy";
|
|
62
|
+
/**
|
|
63
|
+
* Definition for creating a boundary.
|
|
64
|
+
*
|
|
65
|
+
* @template T - The type of value this boundary holds
|
|
66
|
+
*/
|
|
67
|
+
export interface BoundaryDefinition<T> {
|
|
68
|
+
/** Default value when no provider above */
|
|
69
|
+
defaultValue: T | null;
|
|
70
|
+
/** Display name for debugging */
|
|
71
|
+
displayName?: string;
|
|
72
|
+
/** Boundary class - determines how compiler handles it */
|
|
73
|
+
class: BoundaryClass;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A Boundary object created by createBoundary().
|
|
77
|
+
*
|
|
78
|
+
* Boundaries ARE contexts with additional collection-phase effects.
|
|
79
|
+
*
|
|
80
|
+
* @template T - The type of value this boundary holds
|
|
81
|
+
*/
|
|
82
|
+
export interface Boundary<T> {
|
|
83
|
+
/** The underlying context (boundaries ARE contexts) */
|
|
84
|
+
readonly Context: Context<T | null>;
|
|
85
|
+
/** Provider component */
|
|
86
|
+
readonly Provider: BoundaryProvider<T>;
|
|
87
|
+
/** Boundary class */
|
|
88
|
+
readonly class: BoundaryClass;
|
|
89
|
+
/** Display name for debugging */
|
|
90
|
+
displayName?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Internal: the definition.
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
readonly _definition: BoundaryDefinition<T>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Props for a boundary Provider component.
|
|
99
|
+
*/
|
|
100
|
+
export interface BoundaryProviderProps<T> {
|
|
101
|
+
/** The value to provide */
|
|
102
|
+
value: T;
|
|
103
|
+
/** Child components */
|
|
104
|
+
children?: any;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Internal data attached to boundary providers.
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
export interface BoundaryProviderData<T> {
|
|
111
|
+
class: BoundaryClass;
|
|
112
|
+
definition: BoundaryDefinition<T>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A boundary Provider component type.
|
|
116
|
+
*/
|
|
117
|
+
export type BoundaryProvider<T> = {
|
|
118
|
+
(props: BoundaryProviderProps<T>): JSX.Element;
|
|
119
|
+
/** @internal - Boundary data for compiler detection */
|
|
120
|
+
[BOUNDARY_PROVIDER_SYMBOL]: BoundaryProviderData<T>;
|
|
121
|
+
/** Display name for debugging */
|
|
122
|
+
displayName?: string;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Creates a Boundary that extends Context with collection-phase effects.
|
|
126
|
+
*
|
|
127
|
+
* Boundaries can provide:
|
|
128
|
+
* - Context values (readable via useBoundary/useContext during render)
|
|
129
|
+
* - Formatter effects (affect content rendering during collection)
|
|
130
|
+
* - Policy effects (process entries after collection)
|
|
131
|
+
*
|
|
132
|
+
* @param definition - The boundary definition
|
|
133
|
+
* @returns A Boundary object with a Provider component
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```tsx
|
|
137
|
+
* const MyBoundary = createBoundary({
|
|
138
|
+
* defaultValue: null,
|
|
139
|
+
* displayName: 'MyBoundary',
|
|
140
|
+
* class: 'formatter',
|
|
141
|
+
* formatter: (value) => new MyRenderer(),
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* // Use it
|
|
145
|
+
* <MyBoundary.Provider value={{}}>
|
|
146
|
+
* {children}
|
|
147
|
+
* </MyBoundary.Provider>
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function createBoundary<T>(definition: BoundaryDefinition<T>): Boundary<T>;
|
|
151
|
+
/**
|
|
152
|
+
* Reads the current value of a boundary.
|
|
153
|
+
*
|
|
154
|
+
* This is a convenience wrapper around useContext that works with Boundary objects.
|
|
155
|
+
* Returns the value from the nearest Provider ancestor, or null if no Provider is found.
|
|
156
|
+
*
|
|
157
|
+
* @param boundary - The Boundary object (created by createBoundary)
|
|
158
|
+
* @returns The current boundary value, or null
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```tsx
|
|
162
|
+
* const TokenBudgetBoundary = createPolicy<TokenBudgetProps>('TokenBudget', process);
|
|
163
|
+
*
|
|
164
|
+
* function TokenCounter() {
|
|
165
|
+
* const budget = useBoundary(TokenBudgetBoundary);
|
|
166
|
+
* if (!budget) return null;
|
|
167
|
+
* return <System>Budget: {budget.maxTokens} tokens</System>;
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export declare function useBoundary<T>(boundary: Boundary<T>): T | null;
|
|
172
|
+
/**
|
|
173
|
+
* Value type for the FormatterBoundary.
|
|
174
|
+
* Just contains a formatter function - ContentRenderer is an internal implementation detail.
|
|
175
|
+
*/
|
|
176
|
+
export interface FormatterBoundaryValue {
|
|
177
|
+
/** The formatter function - transforms semantic blocks to content blocks */
|
|
178
|
+
formatter: Formatter;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The unified formatter boundary used by XML, Markdown, JSON, etc.
|
|
182
|
+
*
|
|
183
|
+
* All formatter components (XML, Markdown, JSON) use this single boundary.
|
|
184
|
+
* The value contains a formatter function. Use `useBoundary(FormatterBoundary)`
|
|
185
|
+
* to get the current formatter regardless of which formatter type is active.
|
|
186
|
+
*
|
|
187
|
+
* **Inner wins semantics:** When formatters are nested, the innermost formatter
|
|
188
|
+
* is used for content within its scope.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```tsx
|
|
192
|
+
* // In a component - get the current formatter
|
|
193
|
+
* const formatterValue = useBoundary(FormatterBoundary);
|
|
194
|
+
* if (formatterValue) {
|
|
195
|
+
* const formatted = formatterValue.formatter(blocks);
|
|
196
|
+
* }
|
|
197
|
+
*
|
|
198
|
+
* // XML, Markdown, etc. use this boundary internally
|
|
199
|
+
* function XML({ children }) {
|
|
200
|
+
* return (
|
|
201
|
+
* <FormatterBoundary.Provider value={{ formatter: (blocks) => xmlRenderer.format(blocks) }}>
|
|
202
|
+
* {children}
|
|
203
|
+
* </FormatterBoundary.Provider>
|
|
204
|
+
* );
|
|
205
|
+
* }
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare const FormatterBoundary: Boundary<FormatterBoundaryValue>;
|
|
209
|
+
/**
|
|
210
|
+
* Creates a formatter component that uses the unified FormatterBoundary.
|
|
211
|
+
*
|
|
212
|
+
* This is a convenience function for creating formatter components like XML, Markdown.
|
|
213
|
+
* It creates a component that wraps children in FormatterBoundary.Provider with the
|
|
214
|
+
* provided formatter function.
|
|
215
|
+
*
|
|
216
|
+
* @param name - Display name for debugging
|
|
217
|
+
* @param formatter - The formatter function or factory
|
|
218
|
+
* @returns A component function that provides the formatter to children
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```tsx
|
|
222
|
+
* // Create a custom formatter
|
|
223
|
+
* const CustomFormat = createFormatter('CustomFormat', (blocks) => {
|
|
224
|
+
* return blocks.map(block => ({ type: 'text', text: `[${block.text}]` }));
|
|
225
|
+
* });
|
|
226
|
+
*
|
|
227
|
+
* // Use it
|
|
228
|
+
* <CustomFormat>
|
|
229
|
+
* <Content />
|
|
230
|
+
* </CustomFormat>
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export declare function createFormatter(name: string, formatter: Formatter | (() => Formatter)): (props: {
|
|
234
|
+
children?: any;
|
|
235
|
+
}) => JSX.Element;
|
|
236
|
+
/**
|
|
237
|
+
* Policy process function type.
|
|
238
|
+
* Transforms timeline entries (filtering, summarization, etc.).
|
|
239
|
+
*/
|
|
240
|
+
export type PolicyProcessFunction<TConfig = unknown> = (entries: COMTimelineEntry[], config: TConfig) => COMTimelineEntry[] | Promise<COMTimelineEntry[]>;
|
|
241
|
+
/**
|
|
242
|
+
* A single policy in the policy chain.
|
|
243
|
+
*/
|
|
244
|
+
export interface PolicyEntry<TConfig = unknown> {
|
|
245
|
+
/** Policy name for debugging/identification */
|
|
246
|
+
name: string;
|
|
247
|
+
/** The process function that transforms entries */
|
|
248
|
+
process: PolicyProcessFunction<TConfig>;
|
|
249
|
+
/** Configuration for this policy instance */
|
|
250
|
+
config: TConfig;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Value type for the PolicyBoundary.
|
|
254
|
+
* Holds an array of accumulated policies.
|
|
255
|
+
*/
|
|
256
|
+
export interface PolicyBoundaryValue {
|
|
257
|
+
/** Accumulated policies from all ancestors plus current */
|
|
258
|
+
policies: PolicyEntry[];
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The unified policy boundary used by TokenBudget, etc.
|
|
262
|
+
*
|
|
263
|
+
* All policy components use this single boundary. Policies **accumulate** -
|
|
264
|
+
* nested policies don't replace parent policies, they add to them.
|
|
265
|
+
* Use `useBoundary(PolicyBoundary)` to get ALL active policies in scope.
|
|
266
|
+
*
|
|
267
|
+
* **Accumulating semantics:** When policies are nested, ALL policies apply
|
|
268
|
+
* to content within their combined scope, processed in order (outer first).
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```tsx
|
|
272
|
+
* // In a component - get all active policies
|
|
273
|
+
* const policyValue = useBoundary(PolicyBoundary);
|
|
274
|
+
* if (policyValue) {
|
|
275
|
+
* console.log('Active policies:', policyValue.policies.map(p => p.name));
|
|
276
|
+
* // e.g., ['TokenBudget', 'Summarizer']
|
|
277
|
+
* }
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @example Nested policies accumulate - both TokenBudget AND Summarizer apply
|
|
281
|
+
* ```tsx
|
|
282
|
+
* <TokenBudget maxTokens={8000}>
|
|
283
|
+
* <Summarizer threshold={5000}>
|
|
284
|
+
* <Timeline />
|
|
285
|
+
* </Summarizer>
|
|
286
|
+
* </TokenBudget>
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
export declare const PolicyBoundary: Boundary<PolicyBoundaryValue>;
|
|
290
|
+
/**
|
|
291
|
+
* Creates a policy component that auto-accumulates into PolicyBoundary.
|
|
292
|
+
*
|
|
293
|
+
* Policy boundaries affect the timeline entries during the formatInput phase,
|
|
294
|
+
* after all entries have been collected. Use this for filtering, transforming,
|
|
295
|
+
* or managing entries (e.g., token budgets, summarization).
|
|
296
|
+
*
|
|
297
|
+
* **Auto-accumulation:** The created component automatically reads parent policies
|
|
298
|
+
* from PolicyBoundary, appends its own policy, and provides the combined list.
|
|
299
|
+
* You don't need to manually handle accumulation.
|
|
300
|
+
*
|
|
301
|
+
* @param name - Display name for debugging
|
|
302
|
+
* @param process - Function to process entries
|
|
303
|
+
* @returns An object with Provider component and usePolicy hook
|
|
304
|
+
*
|
|
305
|
+
* @example Creating a policy
|
|
306
|
+
* ```typescript
|
|
307
|
+
* const tokenBudget = createPolicy<TokenBudgetProps>(
|
|
308
|
+
* 'TokenBudget',
|
|
309
|
+
* async (entries, props) => applyTokenBudget(entries, props)
|
|
310
|
+
* );
|
|
311
|
+
*
|
|
312
|
+
* // Use the Provider - auto-accumulates with parent policies
|
|
313
|
+
* // <tokenBudget.Provider value={{ maxTokens: 4000, strategy: 'drop-oldest' }}>
|
|
314
|
+
* // <Timeline />
|
|
315
|
+
* // </tokenBudget.Provider>
|
|
316
|
+
*
|
|
317
|
+
* // Read this specific policy's config with usePolicy hook
|
|
318
|
+
* // const config = tokenBudget.usePolicy();
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
export declare function createPolicy<TConfig>(name: string, process: PolicyProcessFunction<TConfig>): {
|
|
322
|
+
/** Provider component that auto-accumulates into PolicyBoundary */
|
|
323
|
+
Provider: (props: {
|
|
324
|
+
value: TConfig;
|
|
325
|
+
children?: any;
|
|
326
|
+
}) => JSX.Element;
|
|
327
|
+
/** Hook to read this specific policy's config (innermost) */
|
|
328
|
+
usePolicy: () => TConfig | null;
|
|
329
|
+
/** The policy name */
|
|
330
|
+
name: string;
|
|
331
|
+
/** The process function */
|
|
332
|
+
process: PolicyProcessFunction<TConfig>;
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* Check if a component is a boundary provider.
|
|
336
|
+
* Used by the fiber compiler during traversal.
|
|
337
|
+
*
|
|
338
|
+
* @internal
|
|
339
|
+
*/
|
|
340
|
+
export declare function isBoundaryProvider(component: unknown): component is BoundaryProvider<unknown>;
|
|
341
|
+
/**
|
|
342
|
+
* Get the boundary data from a provider component.
|
|
343
|
+
*
|
|
344
|
+
* @internal
|
|
345
|
+
*/
|
|
346
|
+
export declare function getBoundaryData<T>(provider: BoundaryProvider<T>): BoundaryProviderData<T>;
|
|
347
|
+
//# sourceMappingURL=boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/state/boundary.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boundary System for Tentickle
|
|
3
|
+
*
|
|
4
|
+
* Boundaries extend Context with collection-phase effects. They provide a generic
|
|
5
|
+
* mechanism for components that affect how their children are processed during
|
|
6
|
+
* compilation, without hardcoding specific component checks in the compiler.
|
|
7
|
+
*
|
|
8
|
+
* The abstraction ladder:
|
|
9
|
+
* - createContext: render-phase values, read via useContext
|
|
10
|
+
* - createBoundary: render-phase values + collection-phase effects
|
|
11
|
+
* - createFormatter: convenience for formatter boundaries (collection-time)
|
|
12
|
+
* - createPolicy: convenience for policy boundaries (format-time, auto-accumulating)
|
|
13
|
+
*
|
|
14
|
+
* @example Formatter boundary (like XML, Markdown)
|
|
15
|
+
* ```tsx
|
|
16
|
+
* // XML/Markdown use the unified FormatterBoundary
|
|
17
|
+
* <XML>
|
|
18
|
+
* <Content />
|
|
19
|
+
* </XML>
|
|
20
|
+
*
|
|
21
|
+
* // To get the current formatter during render:
|
|
22
|
+
* const formatter = useBoundary(FormatterBoundary);
|
|
23
|
+
* if (formatter) {
|
|
24
|
+
* const formatted = formatter.formatter(blocks);
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Policy boundary (like TokenBudget)
|
|
29
|
+
* ```tsx
|
|
30
|
+
* // Policies auto-accumulate - nested policies are combined
|
|
31
|
+
* <TokenBudget maxTokens={8000} strategy="drop-oldest">
|
|
32
|
+
* <Timeline />
|
|
33
|
+
* <TokenBudget maxTokens={2000} strategy="truncate">
|
|
34
|
+
* <User>{message}</User> {/* Both policies apply \*\/}
|
|
35
|
+
* </TokenBudget>
|
|
36
|
+
* </TokenBudget>
|
|
37
|
+
*
|
|
38
|
+
* // To get all active policies during render:
|
|
39
|
+
* const policyValue = useBoundary(PolicyBoundary);
|
|
40
|
+
* if (policyValue) {
|
|
41
|
+
* console.log('Active policies:', policyValue.policies.map(p => p.name));
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @module tentickle/boundary
|
|
46
|
+
*/
|
|
47
|
+
import { createElement } from "../jsx/jsx-runtime";
|
|
48
|
+
import { createContext, useContext } from "./context";
|
|
49
|
+
// ============================================================================
|
|
50
|
+
// Types
|
|
51
|
+
// ============================================================================
|
|
52
|
+
/**
|
|
53
|
+
* Symbol used to mark boundary provider components.
|
|
54
|
+
* The fiber compiler detects this to handle boundary effects.
|
|
55
|
+
*/
|
|
56
|
+
export const BOUNDARY_PROVIDER_SYMBOL = Symbol.for("tentickle.boundary.provider");
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// createBoundary
|
|
59
|
+
// ============================================================================
|
|
60
|
+
/**
|
|
61
|
+
* Creates a Boundary that extends Context with collection-phase effects.
|
|
62
|
+
*
|
|
63
|
+
* Boundaries can provide:
|
|
64
|
+
* - Context values (readable via useBoundary/useContext during render)
|
|
65
|
+
* - Formatter effects (affect content rendering during collection)
|
|
66
|
+
* - Policy effects (process entries after collection)
|
|
67
|
+
*
|
|
68
|
+
* @param definition - The boundary definition
|
|
69
|
+
* @returns A Boundary object with a Provider component
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```tsx
|
|
73
|
+
* const MyBoundary = createBoundary({
|
|
74
|
+
* defaultValue: null,
|
|
75
|
+
* displayName: 'MyBoundary',
|
|
76
|
+
* class: 'formatter',
|
|
77
|
+
* formatter: (value) => new MyRenderer(),
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* // Use it
|
|
81
|
+
* <MyBoundary.Provider value={{}}>
|
|
82
|
+
* {children}
|
|
83
|
+
* </MyBoundary.Provider>
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export function createBoundary(definition) {
|
|
87
|
+
const displayName = definition.displayName || "Boundary";
|
|
88
|
+
// Create underlying context (boundaries ARE contexts)
|
|
89
|
+
const Context = createContext(definition.defaultValue, displayName);
|
|
90
|
+
// Create the Provider component
|
|
91
|
+
function Provider(props) {
|
|
92
|
+
// Provider wraps Context.Provider
|
|
93
|
+
// The fiber compiler detects this via BOUNDARY_PROVIDER_SYMBOL
|
|
94
|
+
// and applies the boundary effects during traversal
|
|
95
|
+
return createElement(Context.Provider, {
|
|
96
|
+
value: props.value,
|
|
97
|
+
children: props.children,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// Mark as boundary provider so compiler can detect it
|
|
101
|
+
const boundaryData = {
|
|
102
|
+
class: definition.class,
|
|
103
|
+
definition,
|
|
104
|
+
};
|
|
105
|
+
Provider[BOUNDARY_PROVIDER_SYMBOL] = boundaryData;
|
|
106
|
+
Provider.displayName = `${displayName}.Provider`;
|
|
107
|
+
// Create the boundary object
|
|
108
|
+
const boundary = {
|
|
109
|
+
Context,
|
|
110
|
+
Provider: Provider,
|
|
111
|
+
class: definition.class,
|
|
112
|
+
displayName,
|
|
113
|
+
_definition: definition,
|
|
114
|
+
};
|
|
115
|
+
return boundary;
|
|
116
|
+
}
|
|
117
|
+
// ============================================================================
|
|
118
|
+
// useBoundary
|
|
119
|
+
// ============================================================================
|
|
120
|
+
/**
|
|
121
|
+
* Reads the current value of a boundary.
|
|
122
|
+
*
|
|
123
|
+
* This is a convenience wrapper around useContext that works with Boundary objects.
|
|
124
|
+
* Returns the value from the nearest Provider ancestor, or null if no Provider is found.
|
|
125
|
+
*
|
|
126
|
+
* @param boundary - The Boundary object (created by createBoundary)
|
|
127
|
+
* @returns The current boundary value, or null
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```tsx
|
|
131
|
+
* const TokenBudgetBoundary = createPolicy<TokenBudgetProps>('TokenBudget', process);
|
|
132
|
+
*
|
|
133
|
+
* function TokenCounter() {
|
|
134
|
+
* const budget = useBoundary(TokenBudgetBoundary);
|
|
135
|
+
* if (!budget) return null;
|
|
136
|
+
* return <System>Budget: {budget.maxTokens} tokens</System>;
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export function useBoundary(boundary) {
|
|
141
|
+
return useContext(boundary.Context);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The unified formatter boundary used by XML, Markdown, JSON, etc.
|
|
145
|
+
*
|
|
146
|
+
* All formatter components (XML, Markdown, JSON) use this single boundary.
|
|
147
|
+
* The value contains a formatter function. Use `useBoundary(FormatterBoundary)`
|
|
148
|
+
* to get the current formatter regardless of which formatter type is active.
|
|
149
|
+
*
|
|
150
|
+
* **Inner wins semantics:** When formatters are nested, the innermost formatter
|
|
151
|
+
* is used for content within its scope.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```tsx
|
|
155
|
+
* // In a component - get the current formatter
|
|
156
|
+
* const formatterValue = useBoundary(FormatterBoundary);
|
|
157
|
+
* if (formatterValue) {
|
|
158
|
+
* const formatted = formatterValue.formatter(blocks);
|
|
159
|
+
* }
|
|
160
|
+
*
|
|
161
|
+
* // XML, Markdown, etc. use this boundary internally
|
|
162
|
+
* function XML({ children }) {
|
|
163
|
+
* return (
|
|
164
|
+
* <FormatterBoundary.Provider value={{ formatter: (blocks) => xmlRenderer.format(blocks) }}>
|
|
165
|
+
* {children}
|
|
166
|
+
* </FormatterBoundary.Provider>
|
|
167
|
+
* );
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export const FormatterBoundary = createBoundary({
|
|
172
|
+
defaultValue: null,
|
|
173
|
+
displayName: "Formatter",
|
|
174
|
+
class: "formatter",
|
|
175
|
+
});
|
|
176
|
+
// ============================================================================
|
|
177
|
+
// createFormatter
|
|
178
|
+
// ============================================================================
|
|
179
|
+
/**
|
|
180
|
+
* Creates a formatter component that uses the unified FormatterBoundary.
|
|
181
|
+
*
|
|
182
|
+
* This is a convenience function for creating formatter components like XML, Markdown.
|
|
183
|
+
* It creates a component that wraps children in FormatterBoundary.Provider with the
|
|
184
|
+
* provided formatter function.
|
|
185
|
+
*
|
|
186
|
+
* @param name - Display name for debugging
|
|
187
|
+
* @param formatter - The formatter function or factory
|
|
188
|
+
* @returns A component function that provides the formatter to children
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```tsx
|
|
192
|
+
* // Create a custom formatter
|
|
193
|
+
* const CustomFormat = createFormatter('CustomFormat', (blocks) => {
|
|
194
|
+
* return blocks.map(block => ({ type: 'text', text: `[${block.text}]` }));
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* // Use it
|
|
198
|
+
* <CustomFormat>
|
|
199
|
+
* <Content />
|
|
200
|
+
* </CustomFormat>
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export function createFormatter(name, formatter) {
|
|
204
|
+
const resolvedFormatter = typeof formatter === "function" && formatter.length === 0
|
|
205
|
+
? formatter()
|
|
206
|
+
: formatter;
|
|
207
|
+
function FormatterComponent(props) {
|
|
208
|
+
return createElement(FormatterBoundary.Provider, {
|
|
209
|
+
value: { formatter: resolvedFormatter },
|
|
210
|
+
children: props.children,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
FormatterComponent.displayName = name;
|
|
214
|
+
return FormatterComponent;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The unified policy boundary used by TokenBudget, etc.
|
|
218
|
+
*
|
|
219
|
+
* All policy components use this single boundary. Policies **accumulate** -
|
|
220
|
+
* nested policies don't replace parent policies, they add to them.
|
|
221
|
+
* Use `useBoundary(PolicyBoundary)` to get ALL active policies in scope.
|
|
222
|
+
*
|
|
223
|
+
* **Accumulating semantics:** When policies are nested, ALL policies apply
|
|
224
|
+
* to content within their combined scope, processed in order (outer first).
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```tsx
|
|
228
|
+
* // In a component - get all active policies
|
|
229
|
+
* const policyValue = useBoundary(PolicyBoundary);
|
|
230
|
+
* if (policyValue) {
|
|
231
|
+
* console.log('Active policies:', policyValue.policies.map(p => p.name));
|
|
232
|
+
* // e.g., ['TokenBudget', 'Summarizer']
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @example Nested policies accumulate - both TokenBudget AND Summarizer apply
|
|
237
|
+
* ```tsx
|
|
238
|
+
* <TokenBudget maxTokens={8000}>
|
|
239
|
+
* <Summarizer threshold={5000}>
|
|
240
|
+
* <Timeline />
|
|
241
|
+
* </Summarizer>
|
|
242
|
+
* </TokenBudget>
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
export const PolicyBoundary = createBoundary({
|
|
246
|
+
defaultValue: null,
|
|
247
|
+
displayName: "Policy",
|
|
248
|
+
class: "policy",
|
|
249
|
+
});
|
|
250
|
+
// ============================================================================
|
|
251
|
+
// createPolicy
|
|
252
|
+
// ============================================================================
|
|
253
|
+
/**
|
|
254
|
+
* Creates a policy component that auto-accumulates into PolicyBoundary.
|
|
255
|
+
*
|
|
256
|
+
* Policy boundaries affect the timeline entries during the formatInput phase,
|
|
257
|
+
* after all entries have been collected. Use this for filtering, transforming,
|
|
258
|
+
* or managing entries (e.g., token budgets, summarization).
|
|
259
|
+
*
|
|
260
|
+
* **Auto-accumulation:** The created component automatically reads parent policies
|
|
261
|
+
* from PolicyBoundary, appends its own policy, and provides the combined list.
|
|
262
|
+
* You don't need to manually handle accumulation.
|
|
263
|
+
*
|
|
264
|
+
* @param name - Display name for debugging
|
|
265
|
+
* @param process - Function to process entries
|
|
266
|
+
* @returns An object with Provider component and usePolicy hook
|
|
267
|
+
*
|
|
268
|
+
* @example Creating a policy
|
|
269
|
+
* ```typescript
|
|
270
|
+
* const tokenBudget = createPolicy<TokenBudgetProps>(
|
|
271
|
+
* 'TokenBudget',
|
|
272
|
+
* async (entries, props) => applyTokenBudget(entries, props)
|
|
273
|
+
* );
|
|
274
|
+
*
|
|
275
|
+
* // Use the Provider - auto-accumulates with parent policies
|
|
276
|
+
* // <tokenBudget.Provider value={{ maxTokens: 4000, strategy: 'drop-oldest' }}>
|
|
277
|
+
* // <Timeline />
|
|
278
|
+
* // </tokenBudget.Provider>
|
|
279
|
+
*
|
|
280
|
+
* // Read this specific policy's config with usePolicy hook
|
|
281
|
+
* // const config = tokenBudget.usePolicy();
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
export function createPolicy(name, process) {
|
|
285
|
+
// Create a context for this specific policy's config
|
|
286
|
+
const PolicyConfigContext = createContext(null, `${name}Config`);
|
|
287
|
+
function PolicyProvider(props) {
|
|
288
|
+
// Get parent policies (auto-accumulation)
|
|
289
|
+
const parentValue = useContext(PolicyBoundary.Context);
|
|
290
|
+
const parentPolicies = parentValue?.policies || [];
|
|
291
|
+
// Create new policy entry
|
|
292
|
+
const newPolicy = {
|
|
293
|
+
name,
|
|
294
|
+
process: process,
|
|
295
|
+
config: props.value,
|
|
296
|
+
};
|
|
297
|
+
// Combine parent policies with this one
|
|
298
|
+
const combinedPolicies = [...parentPolicies, newPolicy];
|
|
299
|
+
// Provide both the combined policies AND this policy's specific config
|
|
300
|
+
return createElement(PolicyBoundary.Provider, {
|
|
301
|
+
value: { policies: combinedPolicies },
|
|
302
|
+
children: createElement(PolicyConfigContext.Provider, {
|
|
303
|
+
value: props.value,
|
|
304
|
+
children: props.children,
|
|
305
|
+
}),
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
PolicyProvider.displayName = `${name}.Provider`;
|
|
309
|
+
function usePolicy() {
|
|
310
|
+
return useContext(PolicyConfigContext);
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
Provider: PolicyProvider,
|
|
314
|
+
usePolicy,
|
|
315
|
+
name,
|
|
316
|
+
process,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
// ============================================================================
|
|
320
|
+
// Utilities
|
|
321
|
+
// ============================================================================
|
|
322
|
+
/**
|
|
323
|
+
* Check if a component is a boundary provider.
|
|
324
|
+
* Used by the fiber compiler during traversal.
|
|
325
|
+
*
|
|
326
|
+
* @internal
|
|
327
|
+
*/
|
|
328
|
+
export function isBoundaryProvider(component) {
|
|
329
|
+
return (typeof component === "function" &&
|
|
330
|
+
BOUNDARY_PROVIDER_SYMBOL in component &&
|
|
331
|
+
component[BOUNDARY_PROVIDER_SYMBOL] !== undefined);
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Get the boundary data from a provider component.
|
|
335
|
+
*
|
|
336
|
+
* @internal
|
|
337
|
+
*/
|
|
338
|
+
export function getBoundaryData(provider) {
|
|
339
|
+
return provider[BOUNDARY_PROVIDER_SYMBOL];
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=boundary.js.map
|