agentfootprint 6.44.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +4 -0
- package/CLAUDE.md +4 -0
- package/README.md +141 -167
- package/ai-instructions/claude-code/SKILL.md +11 -0
- package/ai-instructions/setup.sh +0 -0
- package/dist/adapters/llm/BrowserOpenAIProvider.js +1 -1
- package/dist/adapters/llm/MockProvider.js +2 -1
- package/dist/adapters/llm/MockProvider.js.map +1 -1
- package/dist/core/agent/buildAgentChart.js +2 -1
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +3 -1
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/stages/pickEntry.js +3 -1
- package/dist/core/agent/stages/pickEntry.js.map +1 -1
- package/dist/debug/finders.js +29 -0
- package/dist/debug/finders.js.map +1 -0
- package/dist/debug.js +134 -0
- package/dist/debug.js.map +1 -0
- package/dist/esm/adapters/identity/agentcore.d.ts +100 -0
- package/dist/esm/adapters/llm/AnthropicProvider.d.ts +130 -0
- package/dist/esm/adapters/llm/BedrockProvider.d.ts +100 -0
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.d.ts +41 -0
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.d.ts +95 -0
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.js +1 -1
- package/dist/esm/adapters/llm/MockProvider.d.ts +154 -0
- package/dist/esm/adapters/llm/MockProvider.js +2 -1
- package/dist/esm/adapters/llm/MockProvider.js.map +1 -1
- package/dist/esm/adapters/llm/OpenAIProvider.d.ts +220 -0
- package/dist/esm/adapters/llm/createProvider.d.ts +85 -0
- package/dist/esm/adapters/memory/agentcore.d.ts +146 -0
- package/dist/esm/adapters/memory/bedrockAgentMemory.d.ts +95 -0
- package/dist/esm/adapters/memory/redis.d.ts +127 -0
- package/dist/esm/adapters/observability/agentcore.d.ts +67 -0
- package/dist/esm/adapters/observability/audit.d.ts +254 -0
- package/dist/esm/adapters/observability/cloudwatch.d.ts +96 -0
- package/dist/esm/adapters/observability/otel.d.ts +237 -0
- package/dist/esm/adapters/observability/xray.d.ts +88 -0
- package/dist/esm/adapters/types.d.ts +378 -0
- package/dist/esm/bridge/eventMeta.d.ts +59 -0
- package/dist/esm/cache/CacheDecisionSubflow.d.ts +85 -0
- package/dist/esm/cache/CacheGateDecider.d.ts +127 -0
- package/dist/esm/cache/applyCachePolicy.d.ts +37 -0
- package/dist/esm/cache/cacheRecorder.d.ts +85 -0
- package/dist/esm/cache/index.d.ts +33 -0
- package/dist/esm/cache/strategies/AnthropicCacheStrategy.d.ts +38 -0
- package/dist/esm/cache/strategies/BedrockCacheStrategy.d.ts +33 -0
- package/dist/esm/cache/strategies/NoOpCacheStrategy.d.ts +29 -0
- package/dist/esm/cache/strategies/OpenAICacheStrategy.d.ts +36 -0
- package/dist/esm/cache/strategyRegistry.d.ts +45 -0
- package/dist/esm/cache/types.d.ts +243 -0
- package/dist/esm/conventions.d.ts +203 -0
- package/dist/esm/core/Agent.d.ts +355 -0
- package/dist/esm/core/LLMCall.d.ts +139 -0
- package/dist/esm/core/RunnerBase.d.ts +267 -0
- package/dist/esm/core/agent/AgentBuilder.d.ts +565 -0
- package/dist/esm/core/agent/buildAgentChart.d.ts +109 -0
- package/dist/esm/core/agent/buildAgentChart.js +2 -1
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildAgentMessageApiChart.d.ts +40 -0
- package/dist/esm/core/agent/buildCacheSubflow.d.ts +35 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.d.ts +56 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.js +3 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildMessageApiChart.d.ts +47 -0
- package/dist/esm/core/agent/buildToolRegistry.d.ts +61 -0
- package/dist/esm/core/agent/memoryRecallInjections.d.ts +8 -0
- package/dist/esm/core/agent/stages/breakFinal.d.ts +22 -0
- package/dist/esm/core/agent/stages/callLLM.d.ts +74 -0
- package/dist/esm/core/agent/stages/pickEntry.d.ts +19 -0
- package/dist/esm/core/agent/stages/pickEntry.js +3 -1
- package/dist/esm/core/agent/stages/pickEntry.js.map +1 -1
- package/dist/esm/core/agent/stages/prepareFinal.d.ts +19 -0
- package/dist/esm/core/agent/stages/reliabilityExecution.d.ts +135 -0
- package/dist/esm/core/agent/stages/route.d.ts +18 -0
- package/dist/esm/core/agent/stages/seed.d.ts +53 -0
- package/dist/esm/core/agent/stages/toolCalls.d.ts +76 -0
- package/dist/esm/core/agent/toolArgsValidation.d.ts +62 -0
- package/dist/esm/core/agent/types.d.ts +382 -0
- package/dist/esm/core/agent/validators.d.ts +52 -0
- package/dist/esm/core/cost.d.ts +38 -0
- package/dist/esm/core/flowchartAsTool.d.ts +200 -0
- package/dist/esm/core/humanizeLLMError.d.ts +23 -0
- package/dist/esm/core/outputFallback.d.ts +139 -0
- package/dist/esm/core/outputSchema.d.ts +127 -0
- package/dist/esm/core/pause.d.ts +74 -0
- package/dist/esm/core/runCheckpoint.d.ts +179 -0
- package/dist/esm/core/runner.d.ts +203 -0
- package/dist/esm/core/slots/buildMessagesSlot.d.ts +40 -0
- package/dist/esm/core/slots/buildSystemPromptSlot.d.ts +41 -0
- package/dist/esm/core/slots/buildThinkingSubflow.d.ts +40 -0
- package/dist/esm/core/slots/buildToolsSlot.d.ts +60 -0
- package/dist/esm/core/slots/helpers.d.ts +27 -0
- package/dist/esm/core/toolContract.d.ts +43 -0
- package/dist/esm/core/tools.d.ts +90 -0
- package/dist/esm/core/translator.d.ts +94 -0
- package/dist/esm/core-flow/Conditional.d.ts +119 -0
- package/dist/esm/core-flow/Loop.d.ts +160 -0
- package/dist/esm/core-flow/Parallel.d.ts +360 -0
- package/dist/esm/core-flow/Sequence.d.ts +133 -0
- package/dist/esm/debug/finders.d.ts +12 -0
- package/dist/esm/debug/finders.js +13 -0
- package/dist/esm/debug/finders.js.map +1 -0
- package/dist/esm/debug.d.ts +25 -0
- package/dist/esm/debug.js +54 -0
- package/dist/esm/debug.js.map +1 -0
- package/dist/esm/events/dispatcher.d.ts +134 -0
- package/dist/esm/events/payloads.d.ts +761 -0
- package/dist/esm/events/registry.d.ts +198 -0
- package/dist/esm/events/types.d.ts +70 -0
- package/dist/esm/events.d.ts +18 -0
- package/dist/esm/events.js +22 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/identity/kinds.d.ts +36 -0
- package/dist/esm/identity/staticTokens.d.ts +28 -0
- package/dist/esm/identity/types.d.ts +113 -0
- package/dist/esm/identity/withCredentialRetry.d.ts +64 -0
- package/dist/esm/identity.d.ts +31 -0
- package/dist/esm/index.d.ts +44 -0
- package/dist/esm/index.js +7 -52
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/injection-engine.d.ts +4 -0
- package/dist/esm/lib/canonicalJson.d.ts +56 -0
- package/dist/esm/lib/context-bisect/ablation.d.ts +109 -0
- package/dist/esm/lib/context-bisect/bisect.d.ts +75 -0
- package/dist/esm/lib/context-bisect/cost.d.ts +37 -0
- package/dist/esm/lib/context-bisect/index.d.ts +31 -0
- package/dist/esm/lib/context-bisect/index.js +3 -0
- package/dist/esm/lib/context-bisect/index.js.map +1 -1
- package/dist/esm/lib/context-bisect/llmEdgeWeigher.d.ts +124 -0
- package/dist/esm/lib/context-bisect/localize.d.ts +152 -0
- package/dist/esm/lib/context-bisect/localize.js +2 -0
- package/dist/esm/lib/context-bisect/localize.js.map +1 -1
- package/dist/esm/lib/context-bisect/loop-recall.d.ts +97 -0
- package/dist/esm/lib/context-bisect/missingContext.d.ts +71 -0
- package/dist/esm/lib/context-bisect/restoration.d.ts +39 -0
- package/dist/esm/lib/context-bisect/toBacktrackTrace.d.ts +138 -0
- package/dist/esm/lib/context-bisect/trajectory.d.ts +168 -0
- package/dist/esm/lib/context-bisect/types.d.ts +448 -0
- package/dist/esm/lib/context-bisect/walk-to-root.d.ts +103 -0
- package/dist/esm/lib/influence-core/attributability.d.ts +72 -0
- package/dist/esm/lib/influence-core/cache.d.ts +94 -0
- package/dist/esm/lib/influence-core/contrastive.d.ts +26 -0
- package/dist/esm/lib/influence-core/index.d.ts +34 -0
- package/dist/esm/lib/influence-core/margin.d.ts +33 -0
- package/dist/esm/lib/influence-core/signals.d.ts +128 -0
- package/dist/esm/lib/influence-core/similarity.d.ts +25 -0
- package/dist/esm/lib/influence-core/types.d.ts +252 -0
- package/dist/esm/lib/injection-engine/SkillRegistry.d.ts +147 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.d.ts +110 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/esm/lib/injection-engine/entryScorer.d.ts +93 -0
- package/dist/esm/lib/injection-engine/entryScorer.js +172 -0
- package/dist/esm/lib/injection-engine/entryScorer.js.map +1 -0
- package/dist/esm/lib/injection-engine/evaluator.d.ts +24 -0
- package/dist/esm/lib/injection-engine/factories/defineFact.d.ts +60 -0
- package/dist/esm/lib/injection-engine/factories/defineInjection.d.ts +41 -0
- package/dist/esm/lib/injection-engine/factories/defineInstruction.d.ts +78 -0
- package/dist/esm/lib/injection-engine/factories/defineRelevanceHint.d.ts +26 -0
- package/dist/esm/lib/injection-engine/factories/defineSkill.d.ts +160 -0
- package/dist/esm/lib/injection-engine/factories/defineSteering.d.ts +39 -0
- package/dist/esm/lib/injection-engine/index.d.ts +22 -0
- package/dist/esm/lib/injection-engine/index.js +2 -1
- package/dist/esm/lib/injection-engine/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillContract.d.ts +29 -0
- package/dist/esm/lib/injection-engine/skillGraph.d.ts +290 -0
- package/dist/esm/lib/injection-engine/skillGraph.js +38 -43
- package/dist/esm/lib/injection-engine/skillGraph.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillGraphCheckup.d.ts +49 -0
- package/dist/esm/lib/injection-engine/skillTools.d.ts +72 -0
- package/dist/esm/lib/injection-engine/softmax.d.ts +11 -0
- package/dist/esm/lib/injection-engine/types.d.ts +229 -0
- package/dist/esm/lib/injection-engine/types.js.map +1 -1
- package/dist/esm/lib/lazyRequire.d.ts +29 -0
- package/dist/esm/lib/mcp/index.d.ts +9 -0
- package/dist/esm/lib/mcp/mcpClient.d.ts +46 -0
- package/dist/esm/lib/mcp/mockMcpClient.d.ts +65 -0
- package/dist/esm/lib/mcp/types.d.ts +133 -0
- package/dist/esm/lib/rag/defineRAG.d.ts +139 -0
- package/dist/esm/lib/rag/defineRAG.js +3 -3
- package/dist/esm/lib/rag/index.d.ts +7 -0
- package/dist/esm/lib/rag/indexDocuments.d.ts +106 -0
- package/dist/esm/lib/rag/indexDocuments.js +2 -1
- package/dist/esm/lib/rag/indexDocuments.js.map +1 -1
- package/dist/esm/lib/tool-lint/analyze.d.ts +83 -0
- package/dist/esm/lib/tool-lint/cli.d.ts +43 -0
- package/dist/esm/lib/tool-lint/format.d.ts +18 -0
- package/dist/esm/lib/tool-lint/index.d.ts +23 -0
- package/dist/esm/lib/tool-lint/rules.d.ts +85 -0
- package/dist/esm/lib/tool-lint/types.d.ts +155 -0
- package/dist/esm/lib/trace-toolpack/bounded.d.ts +47 -0
- package/dist/esm/lib/trace-toolpack/debugPrompt.d.ts +19 -0
- package/dist/esm/lib/trace-toolpack/index.d.ts +20 -0
- package/dist/esm/lib/trace-toolpack/lazyToolpack.d.ts +35 -0
- package/dist/esm/lib/trace-toolpack/selfExplain.d.ts +100 -0
- package/dist/esm/lib/trace-toolpack/traceDebugAgent.d.ts +42 -0
- package/dist/esm/lib/trace-toolpack/traceToolpack.d.ts +69 -0
- package/dist/esm/lib/trace-toolpack/types.d.ts +59 -0
- package/dist/esm/llm-providers.d.ts +26 -0
- package/dist/esm/locales/index.d.ts +141 -0
- package/dist/esm/locales/index.js +7 -0
- package/dist/esm/locales/index.js.map +1 -1
- package/dist/esm/memory/beats/extractBeats.d.ts +61 -0
- package/dist/esm/memory/beats/extractor.d.ts +47 -0
- package/dist/esm/memory/beats/formatAsNarrative.d.ts +62 -0
- package/dist/esm/memory/beats/heuristicExtractor.d.ts +37 -0
- package/dist/esm/memory/beats/index.d.ts +12 -0
- package/dist/esm/memory/beats/llmExtractor.d.ts +56 -0
- package/dist/esm/memory/beats/types.d.ts +60 -0
- package/dist/esm/memory/beats/writeBeats.d.ts +22 -0
- package/dist/esm/memory/causal/evidenceRecorder.d.ts +66 -0
- package/dist/esm/memory/causal/index.d.ts +6 -0
- package/dist/esm/memory/causal/loadSnapshot.d.ts +51 -0
- package/dist/esm/memory/causal/snapshotPipeline.d.ts +35 -0
- package/dist/esm/memory/causal/types.d.ts +134 -0
- package/dist/esm/memory/causal/types.js.map +1 -1
- package/dist/esm/memory/causal/writeSnapshot.d.ts +73 -0
- package/dist/esm/memory/define.d.ts +63 -0
- package/dist/esm/memory/define.types.d.ts +278 -0
- package/dist/esm/memory/define.types.js +6 -4
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/embedding/cosine.d.ts +18 -0
- package/dist/esm/memory/embedding/embedMessages.d.ts +58 -0
- package/dist/esm/memory/embedding/index.d.ts +8 -0
- package/dist/esm/memory/embedding/loadRelevant.d.ts +51 -0
- package/dist/esm/memory/embedding/mockEmbedder.d.ts +22 -0
- package/dist/esm/memory/embedding/types.d.ts +46 -0
- package/dist/esm/memory/entry/decay.d.ts +36 -0
- package/dist/esm/memory/entry/index.d.ts +2 -0
- package/dist/esm/memory/entry/types.d.ts +140 -0
- package/dist/esm/memory/facts/extractFacts.d.ts +50 -0
- package/dist/esm/memory/facts/extractor.d.ts +33 -0
- package/dist/esm/memory/facts/formatFacts.d.ts +60 -0
- package/dist/esm/memory/facts/index.d.ts +14 -0
- package/dist/esm/memory/facts/llmFactExtractor.d.ts +64 -0
- package/dist/esm/memory/facts/loadFacts.d.ts +43 -0
- package/dist/esm/memory/facts/patternFactExtractor.d.ts +2 -0
- package/dist/esm/memory/facts/types.d.ts +68 -0
- package/dist/esm/memory/facts/writeFacts.d.ts +19 -0
- package/dist/esm/memory/identity/index.d.ts +2 -0
- package/dist/esm/memory/identity/types.d.ts +49 -0
- package/dist/esm/memory/index.d.ts +19 -0
- package/dist/esm/memory/pipeline/auto.d.ts +59 -0
- package/dist/esm/memory/pipeline/default.d.ts +49 -0
- package/dist/esm/memory/pipeline/ephemeral.d.ts +28 -0
- package/dist/esm/memory/pipeline/fact.d.ts +26 -0
- package/dist/esm/memory/pipeline/index.d.ts +13 -0
- package/dist/esm/memory/pipeline/narrative.d.ts +35 -0
- package/dist/esm/memory/pipeline/semantic.d.ts +37 -0
- package/dist/esm/memory/pipeline/types.d.ts +31 -0
- package/dist/esm/memory/stages/formatDefault.d.ts +64 -0
- package/dist/esm/memory/stages/index.d.ts +13 -0
- package/dist/esm/memory/stages/loadRecent.d.ts +49 -0
- package/dist/esm/memory/stages/pickByBudget.d.ts +63 -0
- package/dist/esm/memory/stages/summarize.d.ts +87 -0
- package/dist/esm/memory/stages/tokenize.d.ts +43 -0
- package/dist/esm/memory/stages/types.d.ts +75 -0
- package/dist/esm/memory/stages/writeMessages.d.ts +71 -0
- package/dist/esm/memory/store/InMemoryStore.d.ts +62 -0
- package/dist/esm/memory/store/index.d.ts +2 -0
- package/dist/esm/memory/store/types.d.ts +223 -0
- package/dist/esm/memory/wire/index.d.ts +2 -0
- package/dist/esm/memory/wire/mountMemoryPipeline.d.ts +108 -0
- package/dist/esm/memory-providers.d.ts +37 -0
- package/dist/esm/observability/contextError/finders/compareFinders.d.ts +19 -0
- package/dist/esm/observability/contextError/finders/index.d.ts +22 -0
- package/dist/esm/observability/contextError/finders/rankSuspects.d.ts +2 -0
- package/dist/esm/observability/contextError/finders/removeAndRetry.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/shrinkToCause.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/testManyCombos.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/traceSteps.d.ts +2 -0
- package/dist/esm/observability/contextError/finders/types.d.ts +88 -0
- package/dist/esm/observability-providers.d.ts +46 -0
- package/dist/esm/observe.d.ts +57 -0
- package/dist/esm/observe.js +7 -36
- package/dist/esm/observe.js.map +1 -1
- package/dist/esm/patterns/Debate.d.ts +39 -0
- package/dist/esm/patterns/MapReduce.d.ts +66 -0
- package/dist/esm/patterns/Reflection.d.ts +51 -0
- package/dist/esm/patterns/SelfConsistency.d.ts +43 -0
- package/dist/esm/patterns/Swarm.d.ts +60 -0
- package/dist/esm/patterns/ToT.d.ts +53 -0
- package/dist/esm/patterns/index.d.ts +22 -0
- package/dist/esm/providers.d.ts +33 -0
- package/dist/esm/providers.js +1 -1
- package/dist/esm/providers.js.map +1 -1
- package/dist/esm/recorders/core/AgentRecorder.d.ts +15 -0
- package/dist/esm/recorders/core/CompositionRecorder.d.ts +17 -0
- package/dist/esm/recorders/core/ContextEvaluatedRecorder.d.ts +23 -0
- package/dist/esm/recorders/core/ContextRecorder.d.ts +47 -0
- package/dist/esm/recorders/core/CostRecorder.d.ts +14 -0
- package/dist/esm/recorders/core/EmitBridge.d.ts +30 -0
- package/dist/esm/recorders/core/ErrorBridge.d.ts +38 -0
- package/dist/esm/recorders/core/EvalRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/MemoryRecorder.d.ts +17 -0
- package/dist/esm/recorders/core/PermissionRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/ReliabilityRecorder.d.ts +24 -0
- package/dist/esm/recorders/core/SkillRecorder.d.ts +14 -0
- package/dist/esm/recorders/core/StreamRecorder.d.ts +15 -0
- package/dist/esm/recorders/core/ToolsRecorder.d.ts +18 -0
- package/dist/esm/recorders/core/ValidationRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/contextEngineering.d.ts +136 -0
- package/dist/esm/recorders/core/typedEmit.d.ts +34 -0
- package/dist/esm/recorders/core/types.d.ts +97 -0
- package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.d.ts +117 -0
- package/dist/esm/recorders/observability/BoundaryRecorder.d.ts +546 -0
- package/dist/esm/recorders/observability/FlowchartRecorder.d.ts +220 -0
- package/dist/esm/recorders/observability/LiveStateRecorder.d.ts +250 -0
- package/dist/esm/recorders/observability/LoggingRecorder.d.ts +91 -0
- package/dist/esm/recorders/observability/RouteRecorder.d.ts +83 -0
- package/dist/esm/recorders/observability/RunStepRecorder.d.ts +231 -0
- package/dist/esm/recorders/observability/StatusRecorder.d.ts +36 -0
- package/dist/esm/recorders/observability/ToolChoiceRecorder.d.ts +164 -0
- package/dist/esm/recorders/observability/ToolLineageRecorder.d.ts +71 -0
- package/dist/esm/recorders/observability/commentary/commentaryTemplates.d.ts +105 -0
- package/dist/esm/recorders/observability/internal/ActorArrowClassifier.d.ts +25 -0
- package/dist/esm/recorders/observability/internal/CandidateAnswerBuffer.d.ts +28 -0
- package/dist/esm/recorders/observability/internal/ForkTracker.d.ts +60 -0
- package/dist/esm/recorders/observability/internal/RootInferrer.d.ts +51 -0
- package/dist/esm/recorders/observability/internal/SequenceSiblingTracker.d.ts +24 -0
- package/dist/esm/recorders/observability/localObservability.d.ts +48 -0
- package/dist/esm/recorders/observability/observeRunId.d.ts +36 -0
- package/dist/esm/recorders/observability/status/statusTemplates.d.ts +106 -0
- package/dist/esm/recorders/observability/trace.d.ts +119 -0
- package/dist/esm/reliability/CircuitBreaker.d.ts +75 -0
- package/dist/esm/reliability/buildReliabilityGateChart.d.ts +53 -0
- package/dist/esm/reliability/classifyError.d.ts +28 -0
- package/dist/esm/reliability/index.d.ts +35 -0
- package/dist/esm/reliability/types.d.ts +327 -0
- package/dist/esm/resilience/fallbackProvider.d.ts +33 -0
- package/dist/esm/resilience/index.d.ts +21 -0
- package/dist/esm/resilience/withCircuitBreaker.d.ts +129 -0
- package/dist/esm/resilience/withFallback.d.ts +45 -0
- package/dist/esm/resilience/withRetry.d.ts +71 -0
- package/dist/esm/security/PermissionPolicy.d.ts +124 -0
- package/dist/esm/security/PolicyHaltError.d.ts +72 -0
- package/dist/esm/security/extractSequence.d.ts +46 -0
- package/dist/esm/security/index.d.ts +44 -0
- package/dist/esm/security/thinkingRedaction.d.ts +50 -0
- package/dist/esm/status.d.ts +54 -0
- package/dist/esm/status.js +13 -4
- package/dist/esm/status.js.map +1 -1
- package/dist/esm/strategies/attach.d.ts +47 -0
- package/dist/esm/strategies/compose.d.ts +48 -0
- package/dist/esm/strategies/defaults/chatBubbleLiveStatus.d.ts +36 -0
- package/dist/esm/strategies/defaults/consoleObservability.d.ts +42 -0
- package/dist/esm/strategies/defaults/inMemorySinkCost.d.ts +50 -0
- package/dist/esm/strategies/defaults/index.d.ts +30 -0
- package/dist/esm/strategies/defaults/noopLens.d.ts +28 -0
- package/dist/esm/strategies/index.d.ts +36 -0
- package/dist/esm/strategies/registry.d.ts +70 -0
- package/dist/esm/strategies/types.d.ts +303 -0
- package/dist/esm/stream.d.ts +82 -0
- package/dist/esm/thinking/AnthropicThinkingHandler.d.ts +42 -0
- package/dist/esm/thinking/MockThinkingHandler.d.ts +50 -0
- package/dist/esm/thinking/OpenAIThinkingHandler.d.ts +37 -0
- package/dist/esm/thinking/index.d.ts +51 -0
- package/dist/esm/thinking/registry.d.ts +33 -0
- package/dist/esm/thinking/types.d.ts +162 -0
- package/dist/esm/tool-providers/gatedTools.d.ts +36 -0
- package/dist/esm/tool-providers/index.d.ts +41 -0
- package/dist/esm/tool-providers/skillScopedTools.d.ts +45 -0
- package/dist/esm/tool-providers/staticTools.d.ts +21 -0
- package/dist/esm/tool-providers/types.d.ts +138 -0
- package/dist/events.js +42 -0
- package/dist/events.js.map +1 -0
- package/dist/index.js +7 -117
- package/dist/index.js.map +1 -1
- package/dist/lib/context-bisect/index.js +3 -0
- package/dist/lib/context-bisect/index.js.map +1 -1
- package/dist/lib/context-bisect/localize.js +2 -0
- package/dist/lib/context-bisect/localize.js.map +1 -1
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/lib/injection-engine/entryScorer.js +178 -0
- package/dist/lib/injection-engine/entryScorer.js.map +1 -0
- package/dist/lib/injection-engine/index.js +6 -2
- package/dist/lib/injection-engine/index.js.map +1 -1
- package/dist/lib/injection-engine/skillGraph.js +40 -45
- package/dist/lib/injection-engine/skillGraph.js.map +1 -1
- package/dist/lib/injection-engine/types.js.map +1 -1
- package/dist/lib/rag/defineRAG.js +3 -3
- package/dist/lib/rag/indexDocuments.js +2 -1
- package/dist/lib/rag/indexDocuments.js.map +1 -1
- package/dist/locales/index.js +2 -1
- package/dist/locales/index.js.map +1 -1
- package/dist/memory/causal/types.js.map +1 -1
- package/dist/memory/define.types.js +6 -4
- package/dist/memory/define.types.js.map +1 -1
- package/dist/observe.js +22 -115
- package/dist/observe.js.map +1 -1
- package/dist/providers.js +3 -1
- package/dist/providers.js.map +1 -1
- package/dist/status.js +13 -5
- package/dist/status.js.map +1 -1
- package/dist/types/adapters/llm/BrowserOpenAIProvider.d.ts +1 -1
- package/dist/types/adapters/llm/MockProvider.d.ts +2 -1
- package/dist/types/adapters/llm/MockProvider.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/stages/pickEntry.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +8 -4
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/debug/finders.d.ts +13 -0
- package/dist/types/debug/finders.d.ts.map +1 -0
- package/dist/types/debug.d.ts +26 -0
- package/dist/types/debug.d.ts.map +1 -0
- package/dist/types/events.d.ts +19 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -24
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/index.d.ts +3 -0
- package/dist/types/lib/context-bisect/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/localize.d.ts +2 -0
- package/dist/types/lib/context-bisect/localize.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/buildInjectionEngineSubflow.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/entryScorer.d.ts +94 -0
- package/dist/types/lib/injection-engine/entryScorer.d.ts.map +1 -0
- package/dist/types/lib/injection-engine/index.d.ts +2 -1
- package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/skillGraph.d.ts +24 -26
- package/dist/types/lib/injection-engine/skillGraph.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/types.d.ts +9 -4
- package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
- package/dist/types/lib/rag/defineRAG.d.ts +3 -3
- package/dist/types/lib/rag/indexDocuments.d.ts +2 -1
- package/dist/types/lib/rag/indexDocuments.d.ts.map +1 -1
- package/dist/types/locales/index.d.ts +9 -0
- package/dist/types/locales/index.d.ts.map +1 -1
- package/dist/types/memory/causal/types.d.ts +13 -9
- package/dist/types/memory/causal/types.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +6 -4
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/observe.d.ts +1 -6
- package/dist/types/observe.d.ts.map +1 -1
- package/dist/types/providers.d.ts +2 -2
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/status.d.ts +10 -4
- package/dist/types/status.d.ts.map +1 -1
- package/dist/types/tool-providers/index.d.ts +1 -1
- package/dist/types/tool-providers/index.d.ts.map +1 -1
- package/package.json +261 -57
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional — routing composition: evaluates branches in order, runs the first match.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: Builder (GoF) + Adapter over footprintjs's `addDeciderFunction`.
|
|
5
|
+
* Role: core-flow/ layer. Picks exactly ONE branch based on a predicate
|
|
6
|
+
* (sync function of input) OR an LLM decision. Chosen branch
|
|
7
|
+
* receives `{ message }` and returns a string.
|
|
8
|
+
* Emits: agentfootprint.composition.enter / exit +
|
|
9
|
+
* composition.route_decided (via compositionRecorder).
|
|
10
|
+
*
|
|
11
|
+
* v1 of this primitive supports `.when(id, predicate, runner)` + `.otherwise(id, runner)`.
|
|
12
|
+
* LLM-gated routing (`.whenLLM(id, prompt, runner)`) lands in Phase 5.
|
|
13
|
+
*/
|
|
14
|
+
import { type FlowchartCheckpoint, type RunOptions, type StructureRecorder } from 'footprintjs';
|
|
15
|
+
import type { GroupMetadata, GroupTranslator } from '../core/translator.js';
|
|
16
|
+
import type { RunnerPauseOutcome } from '../core/pause.js';
|
|
17
|
+
import type { Runner } from '../core/runner.js';
|
|
18
|
+
import { RunnerBase } from '../core/RunnerBase.js';
|
|
19
|
+
export interface ConditionalOptions {
|
|
20
|
+
readonly name?: string;
|
|
21
|
+
readonly id?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional build-time recorders passed through to footprintjs's
|
|
24
|
+
* `flowChart()` factory. Each recorder observes per-node build
|
|
25
|
+
* events (`onStageAdded` / `onSubflowMounted` / etc.) for this
|
|
26
|
+
* composition's internal chart (Seed + Route decider + each branch
|
|
27
|
+
* mount + Finalize). When omitted, no build-time observation is
|
|
28
|
+
* wired up.
|
|
29
|
+
*/
|
|
30
|
+
readonly structureRecorders?: readonly StructureRecorder[];
|
|
31
|
+
/**
|
|
32
|
+
* Optional per-COMPOSITION translator (UI-agnostic). See
|
|
33
|
+
* `core/translator.ts`. When attached, `runner.getUIGroup()` invokes
|
|
34
|
+
* it with the Conditional's `GroupMetadata` (kind `'Conditional'`,
|
|
35
|
+
* id, name, branches as members, plus `extra.fallbackId`).
|
|
36
|
+
* Returns `undefined` when omitted.
|
|
37
|
+
*/
|
|
38
|
+
readonly groupTranslator?: GroupTranslator;
|
|
39
|
+
}
|
|
40
|
+
export interface ConditionalInput {
|
|
41
|
+
readonly message: string;
|
|
42
|
+
}
|
|
43
|
+
export type ConditionalOutput = string;
|
|
44
|
+
type BranchChild = Runner<{
|
|
45
|
+
message: string;
|
|
46
|
+
}, string>;
|
|
47
|
+
export type Predicate = (input: ConditionalInput) => boolean;
|
|
48
|
+
interface BranchEntry {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly runner: BranchChild;
|
|
52
|
+
/** Undefined for the `otherwise` fallback. */
|
|
53
|
+
readonly predicate?: Predicate;
|
|
54
|
+
/** Optional per-method translator override for THIS branch only. */
|
|
55
|
+
readonly groupTranslator?: GroupTranslator;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Options bag accepted by `ConditionalBuilder.when()` and `.otherwise()`
|
|
59
|
+
* for per-method overrides. Backwards-compatible — when the trailing
|
|
60
|
+
* arg is a string, it's still treated as `name`.
|
|
61
|
+
*/
|
|
62
|
+
export interface ConditionalBranchOptions {
|
|
63
|
+
/** Human-friendly name for this branch. Default: the branch id. */
|
|
64
|
+
readonly name?: string;
|
|
65
|
+
/** Per-method translator override. See `BranchEntry.groupTranslator`. */
|
|
66
|
+
readonly groupTranslator?: GroupTranslator;
|
|
67
|
+
}
|
|
68
|
+
export declare class Conditional extends RunnerBase<ConditionalInput, ConditionalOutput> {
|
|
69
|
+
readonly name: string;
|
|
70
|
+
readonly id: string;
|
|
71
|
+
private readonly branches;
|
|
72
|
+
private readonly fallbackId;
|
|
73
|
+
private readonly opts;
|
|
74
|
+
private currentRunContext;
|
|
75
|
+
constructor(opts: ConditionalOptions, branches: readonly BranchEntry[], fallbackId: string);
|
|
76
|
+
static create(opts?: ConditionalOptions): ConditionalBuilder;
|
|
77
|
+
protected getGroupTranslator(): GroupTranslator | undefined;
|
|
78
|
+
/** Conditional: one member per branch (.when / .otherwise), plus
|
|
79
|
+
* `extra.fallbackId` marking the otherwise branch. Per-method
|
|
80
|
+
* overrides (L1c) take precedence over the branch runner's own
|
|
81
|
+
* translator. */
|
|
82
|
+
protected buildUIGroupMetadata(): GroupMetadata;
|
|
83
|
+
run(input: ConditionalInput, options?: RunOptions): Promise<ConditionalOutput | RunnerPauseOutcome>;
|
|
84
|
+
resume(checkpoint: FlowchartCheckpoint, input?: unknown, options?: RunOptions): Promise<ConditionalOutput | RunnerPauseOutcome>;
|
|
85
|
+
private createExecutor;
|
|
86
|
+
private finalizeResult;
|
|
87
|
+
private buildChart;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Fluent builder. Branches evaluate in registration order; first matching
|
|
91
|
+
* predicate wins. `.otherwise()` is the mandatory fallback.
|
|
92
|
+
*/
|
|
93
|
+
export declare class ConditionalBuilder {
|
|
94
|
+
private readonly opts;
|
|
95
|
+
private readonly branches;
|
|
96
|
+
private fallbackRegistered;
|
|
97
|
+
private fallbackId;
|
|
98
|
+
private readonly seenIds;
|
|
99
|
+
constructor(opts: ConditionalOptions);
|
|
100
|
+
/**
|
|
101
|
+
* Register a predicate-gated branch. `predicate` is a pure sync function
|
|
102
|
+
* of the Conditional's input; if it returns true, the corresponding
|
|
103
|
+
* runner executes. Branches evaluate in registration order.
|
|
104
|
+
*
|
|
105
|
+
* Fourth arg accepts EITHER a legacy bare `name` string OR a
|
|
106
|
+
* `ConditionalBranchOptions` bag containing `name` and/or a per-method
|
|
107
|
+
* `groupTranslator` override. The override applies ONLY to this
|
|
108
|
+
* branch's `member.uiGroup`.
|
|
109
|
+
*/
|
|
110
|
+
when(id: string, predicate: Predicate, runner: BranchChild, nameOrOpts?: string | ConditionalBranchOptions): this;
|
|
111
|
+
/**
|
|
112
|
+
* Register the fallback branch. Exactly ONE must be registered before build().
|
|
113
|
+
* Third arg accepts a legacy `name` string OR a `ConditionalBranchOptions`
|
|
114
|
+
* bag (same shape as `.when()`).
|
|
115
|
+
*/
|
|
116
|
+
otherwise(id: string, runner: BranchChild, nameOrOpts?: string | ConditionalBranchOptions): this;
|
|
117
|
+
build(): Conditional;
|
|
118
|
+
}
|
|
119
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop — iteration composition: runs a body runner repeatedly until exit.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: Builder (GoF) + Adapter over footprintjs's `loopTo` + `$break`.
|
|
5
|
+
* Role: core-flow/ layer. Enables Reflection, Self-Refine, Debate,
|
|
6
|
+
* Reflexion, Constitutional AI, and any pattern needing
|
|
7
|
+
* iterative refinement of a composition output.
|
|
8
|
+
* Emits: agentfootprint.composition.enter / exit +
|
|
9
|
+
* composition.iteration_start / iteration_exit
|
|
10
|
+
* (via compositionRecorder).
|
|
11
|
+
*
|
|
12
|
+
* Budget guard is MANDATORY. You must set at least one of:
|
|
13
|
+
* - maxIterations (default 10 if only .body() is set)
|
|
14
|
+
* - maxWallclockMs
|
|
15
|
+
* Hard ceiling of 500 iterations prevents runaway loops even if a guard
|
|
16
|
+
* misfires; exceeding it throws.
|
|
17
|
+
*/
|
|
18
|
+
import { type FlowchartCheckpoint, type RunOptions, type StructureRecorder } from 'footprintjs';
|
|
19
|
+
import type { GroupMetadata, GroupTranslator } from '../core/translator.js';
|
|
20
|
+
import type { RunnerPauseOutcome } from '../core/pause.js';
|
|
21
|
+
import type { Runner } from '../core/runner.js';
|
|
22
|
+
import { RunnerBase } from '../core/RunnerBase.js';
|
|
23
|
+
export interface LoopOptions {
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
readonly id?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Optional build-time recorders passed through to footprintjs's
|
|
28
|
+
* `flowChart()` factory. Each recorder observes per-node build
|
|
29
|
+
* events (`onStageAdded` / `onSubflowMounted` / etc.) for this
|
|
30
|
+
* composition's internal chart (Seed + IterationStart + body mount +
|
|
31
|
+
* Guard). When omitted, no build-time observation is wired up.
|
|
32
|
+
*/
|
|
33
|
+
readonly structureRecorders?: readonly StructureRecorder[];
|
|
34
|
+
/**
|
|
35
|
+
* Optional per-COMPOSITION translator (UI-agnostic). See
|
|
36
|
+
* `core/translator.ts`. When attached, `runner.getUIGroup()` invokes
|
|
37
|
+
* it with the Loop's `GroupMetadata` (kind `'Loop'`, id, name, body
|
|
38
|
+
* as the single member, plus iteration budgets in `extra`).
|
|
39
|
+
* Returns `undefined` when omitted.
|
|
40
|
+
*/
|
|
41
|
+
readonly groupTranslator?: GroupTranslator;
|
|
42
|
+
}
|
|
43
|
+
export interface LoopInput {
|
|
44
|
+
readonly message: string;
|
|
45
|
+
}
|
|
46
|
+
export type LoopOutput = string;
|
|
47
|
+
type BodyChild = Runner<{
|
|
48
|
+
message: string;
|
|
49
|
+
}, string>;
|
|
50
|
+
/**
|
|
51
|
+
* Predicate evaluated AFTER each body iteration. Return true to exit the loop.
|
|
52
|
+
*
|
|
53
|
+
* `latestOutput` is the body's STRING output — by design (B15): the whole
|
|
54
|
+
* core-flow layer composes `Runner<{ message: string }, string>`, and the
|
|
55
|
+
* Loop chart's outputMapper coerces any non-string body output to `''`.
|
|
56
|
+
* For structured exit conditions today, have the body emit JSON (e.g. an
|
|
57
|
+
* Agent with `.outputSchema(...)`) and parse inside the guard:
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* .until(({ latestOutput }) => {
|
|
61
|
+
* try { return (JSON.parse(latestOutput) as { done: boolean }).done; }
|
|
62
|
+
* catch { return false; } // not JSON (yet) — keep looping
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* A typed guard (`Loop<T>` with a structured body output) would require
|
|
67
|
+
* genericizing the Runner output contract shared by Sequence / Parallel /
|
|
68
|
+
* Conditional — tracked as a future enhancement, not in core today.
|
|
69
|
+
*/
|
|
70
|
+
export type UntilGuard = (ctx: {
|
|
71
|
+
readonly iteration: number;
|
|
72
|
+
readonly latestOutput: string;
|
|
73
|
+
readonly startMs: number;
|
|
74
|
+
}) => boolean;
|
|
75
|
+
export declare class Loop extends RunnerBase<LoopInput, LoopOutput> {
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly id: string;
|
|
78
|
+
private readonly body;
|
|
79
|
+
private readonly maxIterations;
|
|
80
|
+
private readonly maxWallclockMs;
|
|
81
|
+
private readonly until;
|
|
82
|
+
private readonly opts;
|
|
83
|
+
/** Per-method translator override on `.repeat()`, when set. Applies
|
|
84
|
+
* to the body member's `uiGroup`. */
|
|
85
|
+
private readonly bodyTranslator;
|
|
86
|
+
private currentRunContext;
|
|
87
|
+
constructor(opts: LoopOptions, body: BodyChild, config: {
|
|
88
|
+
maxIterations: number;
|
|
89
|
+
maxWallclockMs?: number;
|
|
90
|
+
until?: UntilGuard;
|
|
91
|
+
bodyTranslator?: GroupTranslator;
|
|
92
|
+
});
|
|
93
|
+
static create(opts?: LoopOptions): LoopBuilder;
|
|
94
|
+
protected getGroupTranslator(): GroupTranslator | undefined;
|
|
95
|
+
/** Loop has a single body member + iteration budgets in `extra`.
|
|
96
|
+
* Per-method override (L1c) takes precedence over the body
|
|
97
|
+
* runner's own translator. */
|
|
98
|
+
protected buildUIGroupMetadata(): GroupMetadata;
|
|
99
|
+
run(input: LoopInput, options?: RunOptions): Promise<LoopOutput | RunnerPauseOutcome>;
|
|
100
|
+
resume(checkpoint: FlowchartCheckpoint, input?: unknown, options?: RunOptions): Promise<LoopOutput | RunnerPauseOutcome>;
|
|
101
|
+
private createExecutor;
|
|
102
|
+
private finalizeResult;
|
|
103
|
+
private buildChart;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Fluent builder. Reads as natural English:
|
|
107
|
+
* Loop.create().repeat(runner).times(10).forAtMost(30_000).until(fn).build()
|
|
108
|
+
* → "Loop: repeat runner, up to 10 times, for at most 30 seconds, until fn."
|
|
109
|
+
*
|
|
110
|
+
* Enforces a body runner is supplied before .build(). Default budget is
|
|
111
|
+
* 10 iterations (hard ceiling 500). Any of .times / .forAtMost / .until
|
|
112
|
+
* can fire to exit the loop.
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* Options bag accepted by `LoopBuilder.repeat()` for per-method overrides.
|
|
116
|
+
*/
|
|
117
|
+
export interface LoopRepeatOptions {
|
|
118
|
+
/** Per-method translator override for the body runner — overrides
|
|
119
|
+
* the runner's own constructor-level translator for THIS loop only. */
|
|
120
|
+
readonly groupTranslator?: GroupTranslator;
|
|
121
|
+
}
|
|
122
|
+
export declare class LoopBuilder {
|
|
123
|
+
private readonly opts;
|
|
124
|
+
private _body;
|
|
125
|
+
private _bodyTranslator;
|
|
126
|
+
private _maxIterations;
|
|
127
|
+
private _maxWallclockMs;
|
|
128
|
+
private _until;
|
|
129
|
+
constructor(opts: LoopOptions);
|
|
130
|
+
/**
|
|
131
|
+
* The runner that executes each iteration. Required.
|
|
132
|
+
* Each iteration's output string becomes the next iteration's input `{ message }`.
|
|
133
|
+
*
|
|
134
|
+
* Optional second arg `opts.groupTranslator` overrides the body
|
|
135
|
+
* runner's own translator for THIS loop only — only its
|
|
136
|
+
* `member.uiGroup` flips to the override's output.
|
|
137
|
+
*/
|
|
138
|
+
repeat(runner: BodyChild, opts?: LoopRepeatOptions): this;
|
|
139
|
+
/**
|
|
140
|
+
* Maximum iteration count. Default 10 if only `.repeat()` is called.
|
|
141
|
+
* Hard ceiling 500 — larger values are clamped.
|
|
142
|
+
*/
|
|
143
|
+
times(n: number): this;
|
|
144
|
+
/**
|
|
145
|
+
* Wall-clock time budget in milliseconds. The loop exits at the next
|
|
146
|
+
* guard check after this elapses.
|
|
147
|
+
*/
|
|
148
|
+
forAtMost(ms: number): this;
|
|
149
|
+
/**
|
|
150
|
+
* Exit predicate evaluated after each iteration. Return `true` to exit.
|
|
151
|
+
* Receives `{ iteration, latestOutput, startMs }`.
|
|
152
|
+
*
|
|
153
|
+
* `latestOutput` is the body's string output. For structured exit
|
|
154
|
+
* conditions, emit JSON from the body and parse it inside the guard —
|
|
155
|
+
* see the `UntilGuard` JSDoc for the pattern and the design rationale.
|
|
156
|
+
*/
|
|
157
|
+
until(guard: UntilGuard): this;
|
|
158
|
+
build(): Loop;
|
|
159
|
+
}
|
|
160
|
+
export {};
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel — fan-out composition: N branches run concurrently, then merge.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: Builder (GoF) + Adapter over footprintjs's `addSubFlowChart`
|
|
5
|
+
* (fork children).
|
|
6
|
+
* Role: core-flow/ layer. All branches receive the same input
|
|
7
|
+
* `{ message }`. Each returns a string. A merge step combines
|
|
8
|
+
* them: either a pure function OR an LLM.
|
|
9
|
+
* Emits: agentfootprint.composition.enter / exit +
|
|
10
|
+
* composition.fork_start / branch_complete / merge_end
|
|
11
|
+
* (via compositionRecorder).
|
|
12
|
+
*/
|
|
13
|
+
import { type FlowchartCheckpoint, type RunOptions, type StructureRecorder } from 'footprintjs';
|
|
14
|
+
import type { GroupMetadata, GroupTranslator } from '../core/translator.js';
|
|
15
|
+
import type { RunnerPauseOutcome } from '../core/pause.js';
|
|
16
|
+
import type { LLMProvider } from '../adapters/types.js';
|
|
17
|
+
import type { Runner } from '../core/runner.js';
|
|
18
|
+
import { RunnerBase } from '../core/RunnerBase.js';
|
|
19
|
+
export interface ParallelOptions {
|
|
20
|
+
readonly name?: string;
|
|
21
|
+
readonly id?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional build-time recorders passed through to footprintjs's
|
|
24
|
+
* `flowChart()` factory. Each recorder observes per-node build
|
|
25
|
+
* events (`onStageAdded` / `onSubflowMounted` / etc.) for this
|
|
26
|
+
* composition's internal chart (Seed + each branch mount + Merge).
|
|
27
|
+
*
|
|
28
|
+
* Cascade: each branch runner attaches its OWN recorders at its
|
|
29
|
+
* own construction time. footprintjs does NOT propagate
|
|
30
|
+
* StructureRecorders into mounted subflows — so for full coverage,
|
|
31
|
+
* attach the same recorders to every nested composition. See the
|
|
32
|
+
* core-flow README's "StructureRecorder cascade" section.
|
|
33
|
+
*
|
|
34
|
+
* When omitted, no build-time observation is wired up.
|
|
35
|
+
*/
|
|
36
|
+
readonly structureRecorders?: readonly StructureRecorder[];
|
|
37
|
+
/**
|
|
38
|
+
* Optional per-COMPOSITION translator (UI-agnostic). When attached,
|
|
39
|
+
* `runner.getUIGroup()` invokes it with the Parallel's
|
|
40
|
+
* `GroupMetadata` (kind, id, name, branches list, merge strategy)
|
|
41
|
+
* and returns whatever shape the translator produces.
|
|
42
|
+
*
|
|
43
|
+
* Independent of `structureRecorders` — those observe per-node spec
|
|
44
|
+
* events, this shapes whole-composition UI groups. Common case is to
|
|
45
|
+
* thread the SAME `GroupTranslator` reference through every nested
|
|
46
|
+
* composition so `member.uiGroup` is populated recursively; L1c
|
|
47
|
+
* per-method overrides add finer control.
|
|
48
|
+
*
|
|
49
|
+
* When omitted, `getUIGroup()` returns `undefined`.
|
|
50
|
+
*/
|
|
51
|
+
readonly groupTranslator?: GroupTranslator;
|
|
52
|
+
}
|
|
53
|
+
export interface ParallelInput {
|
|
54
|
+
readonly message: string;
|
|
55
|
+
}
|
|
56
|
+
export type ParallelOutput = string;
|
|
57
|
+
type BranchChild = Runner<{
|
|
58
|
+
message: string;
|
|
59
|
+
}, string>;
|
|
60
|
+
export type MergeFn = (branchResults: Readonly<Record<string, string>>) => string;
|
|
61
|
+
/**
|
|
62
|
+
* Outcome per branch in tolerant mode. One of:
|
|
63
|
+
* - `{ ok: true, value: string }` — branch succeeded; `value` is the returned string
|
|
64
|
+
* - `{ ok: false, error: string }` — branch threw; `error` is the error message
|
|
65
|
+
*
|
|
66
|
+
* Consumers in tolerant mode receive `Record<branchId, BranchOutcome>` and
|
|
67
|
+
* decide how to handle partial failure (e.g., fall back to a default,
|
|
68
|
+
* log, retry, or surface a user-facing message).
|
|
69
|
+
*/
|
|
70
|
+
export type BranchOutcome = {
|
|
71
|
+
readonly ok: true;
|
|
72
|
+
readonly value: string;
|
|
73
|
+
} | {
|
|
74
|
+
readonly ok: false;
|
|
75
|
+
readonly error: string;
|
|
76
|
+
};
|
|
77
|
+
export type MergeOutcomesFn = (outcomes: Readonly<Record<string, BranchOutcome>>) => string;
|
|
78
|
+
export interface MergeWithLLMOptions {
|
|
79
|
+
readonly provider: LLMProvider;
|
|
80
|
+
readonly model: string;
|
|
81
|
+
/** Prompt prepended to the branch results when feeding the merge LLM. */
|
|
82
|
+
readonly prompt: string;
|
|
83
|
+
readonly temperature?: number;
|
|
84
|
+
readonly maxTokens?: number;
|
|
85
|
+
}
|
|
86
|
+
interface BranchEntry {
|
|
87
|
+
readonly id: string;
|
|
88
|
+
readonly name: string;
|
|
89
|
+
readonly runner: BranchChild;
|
|
90
|
+
/**
|
|
91
|
+
* Optional per-method translator override for THIS branch only.
|
|
92
|
+
* When set, the branch's `member.uiGroup` is produced by invoking
|
|
93
|
+
* this translator against the runner's own `GroupMetadata`, instead
|
|
94
|
+
* of calling `branch.runner.getUIGroup()` (which would use the
|
|
95
|
+
* runner's own constructor-level translator).
|
|
96
|
+
*/
|
|
97
|
+
readonly groupTranslator?: GroupTranslator;
|
|
98
|
+
/** This branch's failure rejects the whole run. See `ParallelBranchOptions.required`. */
|
|
99
|
+
readonly required?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Options bag accepted by `ParallelBuilder.branch()` for per-method
|
|
103
|
+
* overrides. Backwards-compatible with the legacy
|
|
104
|
+
* `.branch(id, runner, name?)` signature: when the third arg is a
|
|
105
|
+
* string it's still treated as `name`.
|
|
106
|
+
*/
|
|
107
|
+
export interface ParallelBranchOptions {
|
|
108
|
+
/** Human-friendly name for this branch. Default: the branch id. */
|
|
109
|
+
readonly name?: string;
|
|
110
|
+
/** Per-method translator override. See `BranchEntry.groupTranslator`. */
|
|
111
|
+
readonly groupTranslator?: GroupTranslator;
|
|
112
|
+
/**
|
|
113
|
+
* Mark this branch as REQUIRED: its failure rejects the whole Parallel
|
|
114
|
+
* run — even under a tolerant `.mergeOutcomesWithFn()` merge — with an
|
|
115
|
+
* error that names the branch. Default `false` (existing semantics:
|
|
116
|
+
* strict merges aggregate failures at the join; tolerant merges receive
|
|
117
|
+
* them as `BranchOutcome` entries).
|
|
118
|
+
*
|
|
119
|
+
* Fail-fast wiring: when EVERY branch is required, footprintjs's
|
|
120
|
+
* fork-level `failFast` is engaged (`Promise.all`) so the first failure
|
|
121
|
+
* aborts the fan-out immediately — siblings are not awaited and the
|
|
122
|
+
* Merge stage never runs. When only SOME branches are required, the
|
|
123
|
+
* fan-out stays best-effort (`Promise.allSettled`) and required
|
|
124
|
+
* failures are enforced at the Merge join instead — footprintjs's
|
|
125
|
+
* `failFast` is all-or-nothing per fork node, so engaging it for a
|
|
126
|
+
* mixed set would wrongly abort the run when an OPTIONAL sibling
|
|
127
|
+
* throws. See `docs/guides/concepts.md` (Parallel).
|
|
128
|
+
*
|
|
129
|
+
* Pause semantics under fail-fast: with every branch required, a branch
|
|
130
|
+
* that PAUSES (`pauseHere()`) pre-empts its siblings the same way a
|
|
131
|
+
* failure does — `Promise.all` settles on the first non-success, so
|
|
132
|
+
* still-running siblings are not awaited before the run surfaces the
|
|
133
|
+
* `RunnerPauseOutcome`. The checkpoint reflects the paused branch;
|
|
134
|
+
* `resume()` continues from there and re-attributes any post-resume
|
|
135
|
+
* required-branch failure just like `run()` does. Under the default
|
|
136
|
+
* best-effort fork, a pause is only surfaced after every sibling
|
|
137
|
+
* settles.
|
|
138
|
+
*
|
|
139
|
+
* Nested-mounting limitation: required-branch attribution and the
|
|
140
|
+
* synthetic `composition.exit` are wired through `Parallel.run()` /
|
|
141
|
+
* `Parallel.resume()`. When the Parallel's chart is instead MOUNTED
|
|
142
|
+
* into an outer composition (e.g. `Sequence.step('s', parallel)`), the
|
|
143
|
+
* outer runner's executor runs the chart — the fork-level `failFast`
|
|
144
|
+
* still aborts the fan-out, but the rejection surfaces RAW (no
|
|
145
|
+
* `required branch 'x' failed` wrapping) and the nested Parallel's
|
|
146
|
+
* `composition.enter` is left without a matching `exit`. See README
|
|
147
|
+
* Decision 8.
|
|
148
|
+
*/
|
|
149
|
+
readonly required?: boolean;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Per-branch first-error record captured during a run.
|
|
153
|
+
*
|
|
154
|
+
* `raw` is the ORIGINAL thrown value (footprintjs's
|
|
155
|
+
* `FlowErrorEvent.structuredError.raw`) — the identity key used by
|
|
156
|
+
* `rethrowWithBranchAttribution()` to correlate a fail-fast rejection back
|
|
157
|
+
* to its branch regardless of the error's class name. `message` is the
|
|
158
|
+
* BARE message (no `TypeError:` / `RateLimitError:` prefix) used in merge
|
|
159
|
+
* aggregates, tolerant `BranchOutcome.error` strings, and the attributed
|
|
160
|
+
* error text.
|
|
161
|
+
*
|
|
162
|
+
* @internal Exported only for `wrapBranchOutputMapper`'s signature — not
|
|
163
|
+
* part of the public API (not re-exported from the package barrel).
|
|
164
|
+
*/
|
|
165
|
+
export interface BranchErrorRecord {
|
|
166
|
+
readonly message: string;
|
|
167
|
+
readonly raw: unknown;
|
|
168
|
+
}
|
|
169
|
+
type MergeStrategy = {
|
|
170
|
+
readonly kind: 'fn';
|
|
171
|
+
readonly fn: MergeFn;
|
|
172
|
+
} | {
|
|
173
|
+
readonly kind: 'llm';
|
|
174
|
+
readonly opts: MergeWithLLMOptions;
|
|
175
|
+
} | {
|
|
176
|
+
readonly kind: 'outcomes-fn';
|
|
177
|
+
readonly fn: MergeOutcomesFn;
|
|
178
|
+
};
|
|
179
|
+
export declare class Parallel extends RunnerBase<ParallelInput, ParallelOutput> {
|
|
180
|
+
readonly name: string;
|
|
181
|
+
readonly id: string;
|
|
182
|
+
private readonly branches;
|
|
183
|
+
private readonly merge;
|
|
184
|
+
private readonly opts;
|
|
185
|
+
private currentRunContext;
|
|
186
|
+
/**
|
|
187
|
+
* Per-branch first-error records captured during the current run.
|
|
188
|
+
*
|
|
189
|
+
* Filled by an internal CombinedRecorder attached in `createExecutor()`
|
|
190
|
+
* that observes footprintjs `FlowErrorEvent`s. Errors are keyed by the
|
|
191
|
+
* branch id (the first segment of `traversalContext.subflowPath`); only
|
|
192
|
+
* the first error per branch is kept so the surface mirrors the wrapper
|
|
193
|
+
* `try/catch` semantics that preceded the v0.x architectural refactor.
|
|
194
|
+
*
|
|
195
|
+
* Read by the Merge stage to populate strict-mode error messages and
|
|
196
|
+
* tolerant-mode `BranchOutcome.error` strings, and by
|
|
197
|
+
* `rethrowWithBranchAttribution()` to correlate fail-fast rejections by
|
|
198
|
+
* error IDENTITY (`record.raw`). Cleared at the start of every `run()` /
|
|
199
|
+
* `resume()`; writes are epoch-guarded (see `runEpoch`) so abandoned
|
|
200
|
+
* fail-fast stragglers from a dead run cannot contaminate the live one.
|
|
201
|
+
*/
|
|
202
|
+
private readonly branchErrors;
|
|
203
|
+
/**
|
|
204
|
+
* Monotonic run token — incremented at every `createExecutor()` (i.e.
|
|
205
|
+
* each `run()` / `resume()`). The branch-error recorder captures the
|
|
206
|
+
* epoch current at attach time and only writes while it is STILL
|
|
207
|
+
* current. Under fail-fast, abandoned siblings of a rejected run keep
|
|
208
|
+
* executing in the background; without this guard a late failure from
|
|
209
|
+
* run N would land in run N+1's `branchErrors` (first-error-wins would
|
|
210
|
+
* then block run N+1's real error).
|
|
211
|
+
*/
|
|
212
|
+
private runEpoch;
|
|
213
|
+
/** Ids of branches declared `{ required: true }`. See `ParallelBranchOptions.required`. */
|
|
214
|
+
private readonly requiredIds;
|
|
215
|
+
/**
|
|
216
|
+
* True when EVERY branch is required — the fork node carries
|
|
217
|
+
* footprintjs's `failFast` flag, so the first branch failure rejects
|
|
218
|
+
* `executor.run()` with the RAW branch error before the Merge stage
|
|
219
|
+
* can attribute it. `run()`/`resume()` re-attribute via
|
|
220
|
+
* `rethrowWithBranchAttribution()`.
|
|
221
|
+
*/
|
|
222
|
+
private readonly failFastEngaged;
|
|
223
|
+
constructor(opts: ParallelOptions, branches: readonly BranchEntry[], merge: MergeStrategy);
|
|
224
|
+
static create(opts?: ParallelOptions): ParallelBuilder;
|
|
225
|
+
protected getGroupTranslator(): GroupTranslator | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* Build the Parallel's `GroupMetadata` — kind `'Parallel'`, with one
|
|
228
|
+
* `GroupMember` per branch. Each member exposes its `runner` plus
|
|
229
|
+
* the runner's own `getUIGroup()` output (when the consumer
|
|
230
|
+
* threaded the same translator through that branch's construction).
|
|
231
|
+
*/
|
|
232
|
+
protected buildUIGroupMetadata(): GroupMetadata;
|
|
233
|
+
run(input: ParallelInput, options?: RunOptions): Promise<ParallelOutput | RunnerPauseOutcome>;
|
|
234
|
+
resume(checkpoint: FlowchartCheckpoint, input?: unknown, options?: RunOptions): Promise<ParallelOutput | RunnerPauseOutcome>;
|
|
235
|
+
/**
|
|
236
|
+
* Re-attribute a fail-fast abort to its originating branch.
|
|
237
|
+
*
|
|
238
|
+
* When `failFastEngaged` (every branch required), a failing branch
|
|
239
|
+
* rejects `executor.run()` with the RAW branch error — the Merge stage,
|
|
240
|
+
* which normally attributes failures by branch id, never runs. The
|
|
241
|
+
* internal `parallel-branch-errors` recorder DID see the failure
|
|
242
|
+
* (FlowRecorder.onError fires before the fork rejects), so correlate
|
|
243
|
+
* the rejection against that map and wrap it in a branch-naming error.
|
|
244
|
+
* Also emit the `composition.exit` (status `'err'`) the aborted Merge
|
|
245
|
+
* stage could not, preserving enter/exit pairing for dashboards.
|
|
246
|
+
*
|
|
247
|
+
* Correlation is by error IDENTITY first (`record.raw === err` — the
|
|
248
|
+
* recorder stores the ORIGINAL error object from
|
|
249
|
+
* `FlowErrorEvent.structuredError.raw`), with bare-message equality as
|
|
250
|
+
* a fallback for throws whose identity doesn't survive an engine
|
|
251
|
+
* boundary (e.g. non-Error values). Identity matching is what makes
|
|
252
|
+
* attribution work for ANY named Error subclass — `TypeError`, provider
|
|
253
|
+
* SDK errors like `RateLimitError`, etc. — where message-only matching
|
|
254
|
+
* would silently fail against name-prefixed strings.
|
|
255
|
+
*
|
|
256
|
+
* Rejections that don't correlate (engine errors, merge-stage errors,
|
|
257
|
+
* non-fail-fast runs) are rethrown untouched.
|
|
258
|
+
*
|
|
259
|
+
* Only engaged on the `run()` / `resume()` path — a Parallel chart
|
|
260
|
+
* MOUNTED into an outer composition rejects raw (see
|
|
261
|
+
* `ParallelBranchOptions.required` JSDoc, "Nested-mounting limitation").
|
|
262
|
+
*/
|
|
263
|
+
private rethrowWithBranchAttribution;
|
|
264
|
+
/**
|
|
265
|
+
* Find the branch whose recorded first error corresponds to `err`:
|
|
266
|
+
* identity match on the original thrown value first, bare-message
|
|
267
|
+
* equality second. Returns `undefined` when nothing correlates.
|
|
268
|
+
*/
|
|
269
|
+
private correlateBranchError;
|
|
270
|
+
/**
|
|
271
|
+
* Synthetic `composition.exit` for fail-fast aborts (no stage scope to
|
|
272
|
+
* emit from). Meta is built from the SAME run context the paired
|
|
273
|
+
* `composition.enter` used (`buildEventMeta` + `currentRunContext`), so
|
|
274
|
+
* the pair shares one real `runId` — Convention 4 run-scoping. Only the
|
|
275
|
+
* `runtimeStageId` degrades (`'unknown#0'`): the abort happens outside
|
|
276
|
+
* any stage, so there is no stage origin to attach.
|
|
277
|
+
*/
|
|
278
|
+
private emitFailFastAbortExit;
|
|
279
|
+
private createExecutor;
|
|
280
|
+
/**
|
|
281
|
+
* Build the internal recorder that captures first-error-per-branch.
|
|
282
|
+
*
|
|
283
|
+
* footprintjs's `SubflowExecutor` swallows subflow errors into
|
|
284
|
+
* `parentContext.debug.addError(...)` and skips the `outputMapper`,
|
|
285
|
+
* so the failed branch's error message never lands in parent scope.
|
|
286
|
+
* To preserve the per-branch error surface the wrapper-based design
|
|
287
|
+
* provided, we observe `FlowRecorder.onError` and correlate by the
|
|
288
|
+
* first segment of `traversalContext.subflowPath`.
|
|
289
|
+
*
|
|
290
|
+
* Only the FIRST error per branch is kept. Errors fired outside any
|
|
291
|
+
* branch (e.g., a Merge-stage error) are ignored.
|
|
292
|
+
*
|
|
293
|
+
* `epoch` is the run token current at attach time. Under fail-fast, a
|
|
294
|
+
* rejected run's abandoned siblings keep executing in the background —
|
|
295
|
+
* THIS recorder (attached to that dead run's executor) may still
|
|
296
|
+
* receive their late `onError` events while a NEW run is live. The
|
|
297
|
+
* epoch check drops those writes so the live run's map stays clean.
|
|
298
|
+
*/
|
|
299
|
+
private makeBranchErrorRecorder;
|
|
300
|
+
private finalizeResult;
|
|
301
|
+
private buildChart;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Wrap a branch's `outputMapper` so a mapper throw is ATTRIBUTED to its
|
|
305
|
+
* branch before footprintjs swallows it.
|
|
306
|
+
*
|
|
307
|
+
* footprintjs's `SubflowExecutor` catches outputMapper errors into
|
|
308
|
+
* `parentContext.addError('outputMapperError', ...)` WITHOUT firing
|
|
309
|
+
* `FlowRecorder.onError` — so Parallel's internal `parallel-branch-errors`
|
|
310
|
+
* recorder never sees them, and the Merge stage would fall back to
|
|
311
|
+
* `'unknown error'` for the missing branch id. Recording into the
|
|
312
|
+
* branch-error map here (first error per branch wins, mirroring the
|
|
313
|
+
* recorder's semantics) closes that attribution gap. The error is then
|
|
314
|
+
* RETHROWN so footprintjs's existing bookkeeping stays untouched: the
|
|
315
|
+
* `outputMapperError` debug entry is still written and the branch id is
|
|
316
|
+
* still absent from `branchResults` (which is how the Merge stage detects
|
|
317
|
+
* the failure).
|
|
318
|
+
*
|
|
319
|
+
* @internal Exported for direct unit testing — not part of the public API
|
|
320
|
+
* (not re-exported from the package barrel).
|
|
321
|
+
*/
|
|
322
|
+
export declare function wrapBranchOutputMapper(branchId: string, branchErrors: Map<string, BranchErrorRecord>, inner: (sfOutput: unknown) => Record<string, unknown>): (sfOutput: unknown) => Record<string, unknown>;
|
|
323
|
+
/** Fluent builder. Requires at least 2 branches + one merge strategy. */
|
|
324
|
+
export declare class ParallelBuilder {
|
|
325
|
+
private readonly opts;
|
|
326
|
+
private readonly branches;
|
|
327
|
+
private merge;
|
|
328
|
+
private readonly seenIds;
|
|
329
|
+
constructor(opts: ParallelOptions);
|
|
330
|
+
/**
|
|
331
|
+
* Add a branch. All branches run concurrently with the same input.
|
|
332
|
+
*
|
|
333
|
+
* Third arg accepts EITHER a legacy bare `name` string (back-compat
|
|
334
|
+
* with pre-L1c callers) OR a `ParallelBranchOptions` bag containing
|
|
335
|
+
* `name` and/or a per-method `groupTranslator` override. The
|
|
336
|
+
* override applies ONLY to this branch's `member.uiGroup` and does
|
|
337
|
+
* not affect any other branch or the runner's own translator.
|
|
338
|
+
*/
|
|
339
|
+
branch(id: string, runner: BranchChild, nameOrOpts?: string | ParallelBranchOptions): this;
|
|
340
|
+
/**
|
|
341
|
+
* Merge branch results via a pure function.
|
|
342
|
+
* `fn` receives `{ [branchId]: string }` and returns the merged string.
|
|
343
|
+
*/
|
|
344
|
+
mergeWithFn(fn: MergeFn): this;
|
|
345
|
+
/** Merge branch results by feeding them to an LLM for synthesis. */
|
|
346
|
+
mergeWithLLM(opts: MergeWithLLMOptions): this;
|
|
347
|
+
/**
|
|
348
|
+
* Tolerant merge — receives `{ [branchId]: BranchOutcome }` including
|
|
349
|
+
* both successes (`{ ok: true, value }`) and failures (`{ ok: false, error }`).
|
|
350
|
+
* Parallel does NOT throw on partial failure when this merge variant is
|
|
351
|
+
* used; the consumer's `fn` decides how to handle it (fall back, surface
|
|
352
|
+
* a warning, retry at a higher level, etc.).
|
|
353
|
+
*
|
|
354
|
+
* Use the default `mergeWithFn` / `mergeWithLLM` variants when you want
|
|
355
|
+
* a single failing branch to abort the whole Parallel loudly.
|
|
356
|
+
*/
|
|
357
|
+
mergeOutcomesWithFn(fn: MergeOutcomesFn): this;
|
|
358
|
+
build(): Parallel;
|
|
359
|
+
}
|
|
360
|
+
export {};
|