@moureau/pipeflow 0.0.1 → 0.0.2
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/README.md +245 -117
- package/dist/cjs/agents/agent.js +1 -1
- package/dist/cjs/agents/agent.js.map +3 -3
- package/dist/cjs/agents/tools/tools.js +1 -1
- package/dist/cjs/agents/tools/tools.js.map +3 -3
- package/dist/cjs/conversations/conversation/conversation.js +1 -1
- package/dist/cjs/conversations/conversation/conversation.js.map +3 -3
- package/dist/cjs/conversations/conversations.js +1 -1
- package/dist/cjs/conversations/conversations.js.map +3 -3
- package/dist/cjs/conversations/index.js +1 -1
- package/dist/cjs/conversations/index.js.map +3 -3
- package/dist/cjs/conversations/orchestration/coordination/coordination.js +10 -0
- package/dist/cjs/conversations/orchestration/coordination/coordination.js.map +7 -0
- package/dist/cjs/conversations/orchestration/coordination/index.js +2 -0
- package/dist/cjs/conversations/orchestration/coordination/index.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/coordination-runner/coordination-runner.js +4 -0
- package/dist/cjs/conversations/orchestration/orchestrator/coordination-runner/coordination-runner.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/coordination-runner/index.js +2 -0
- package/dist/cjs/conversations/orchestration/orchestrator/coordination-runner/index.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/generation/generation.js +2 -0
- package/dist/cjs/conversations/orchestration/orchestrator/generation/generation.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/generation/index.js +2 -0
- package/dist/cjs/conversations/orchestration/orchestrator/generation/index.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/history/history.js +4 -0
- package/dist/cjs/conversations/orchestration/orchestrator/history/history.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/history/index.js +2 -0
- package/dist/cjs/conversations/orchestration/orchestrator/history/index.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/index.js +1 -1
- package/dist/cjs/conversations/orchestration/orchestrator/index.js.map +3 -3
- package/dist/cjs/conversations/orchestration/orchestrator/orchestrator.js +1 -2
- package/dist/cjs/conversations/orchestration/orchestrator/orchestrator.js.map +3 -3
- package/dist/cjs/conversations/orchestration/orchestrator/routing/index.js +2 -0
- package/dist/cjs/conversations/orchestration/orchestrator/routing/index.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/routing/routing.js +23 -0
- package/dist/cjs/conversations/orchestration/orchestrator/routing/routing.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/speech/index.js +2 -0
- package/dist/cjs/conversations/orchestration/orchestrator/speech/index.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/speech/speech.js +2 -0
- package/dist/cjs/conversations/orchestration/orchestrator/speech/speech.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/tools/index.js +2 -0
- package/dist/cjs/conversations/orchestration/orchestrator/tools/index.js.map +7 -0
- package/dist/cjs/conversations/orchestration/orchestrator/tools/tools.js +2 -0
- package/dist/cjs/conversations/orchestration/orchestrator/tools/tools.js.map +7 -0
- package/dist/cjs/conversations/orchestration/test-harness.js +2 -0
- package/dist/cjs/conversations/orchestration/test-harness.js.map +7 -0
- package/dist/cjs/conversations/orchestration/text-chunker/index.js +2 -0
- package/dist/cjs/conversations/orchestration/text-chunker/index.js.map +7 -0
- package/dist/cjs/conversations/orchestration/text-chunker/text-chunker.js +3 -0
- package/dist/cjs/conversations/orchestration/text-chunker/text-chunker.js.map +7 -0
- package/dist/cjs/conversations/stream/conversation-stream.js +2 -0
- package/dist/cjs/conversations/stream/conversation-stream.js.map +7 -0
- package/dist/cjs/conversations/stream/index.js +2 -0
- package/dist/cjs/conversations/stream/index.js.map +7 -0
- package/dist/cjs/conversations/types.js +1 -1
- package/dist/cjs/conversations/types.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/persistence/adapters/sqlite/sqlite.js +18 -14
- package/dist/cjs/persistence/adapters/sqlite/sqlite.js.map +3 -3
- package/dist/cjs/pipeflow/index.js +2 -0
- package/dist/cjs/pipeflow/index.js.map +7 -0
- package/dist/cjs/pipeflow/pipeflow.js +2 -0
- package/dist/cjs/pipeflow/pipeflow.js.map +7 -0
- package/dist/cjs/providers/index.js +1 -1
- package/dist/cjs/providers/index.js.map +2 -2
- package/dist/cjs/providers/llm/adapters/claude/claude.js +5 -0
- package/dist/cjs/providers/llm/adapters/claude/claude.js.map +7 -0
- package/dist/cjs/providers/llm/adapters/claude/index.js +2 -0
- package/dist/cjs/providers/llm/adapters/claude/index.js.map +7 -0
- package/dist/cjs/providers/llm/adapters/deepseek/deepseek.js +1 -1
- package/dist/cjs/providers/llm/adapters/deepseek/deepseek.js.map +3 -3
- package/dist/cjs/providers/llm/adapters/index.js +1 -1
- package/dist/cjs/providers/llm/adapters/index.js.map +3 -3
- package/dist/cjs/providers/llm/adapters/openai/index.js +2 -0
- package/dist/cjs/providers/llm/adapters/openai/index.js.map +7 -0
- package/dist/cjs/providers/llm/adapters/openai/openai.js +2 -0
- package/dist/cjs/providers/llm/adapters/openai/openai.js.map +7 -0
- package/dist/cjs/providers/llm/adapters/openai-compatible.js +10 -0
- package/dist/cjs/providers/llm/adapters/openai-compatible.js.map +7 -0
- package/dist/cjs/providers/llm/adapters/openrouter/index.js +2 -0
- package/dist/cjs/providers/llm/adapters/openrouter/index.js.map +7 -0
- package/dist/cjs/providers/llm/adapters/openrouter/openrouter.js +2 -0
- package/dist/cjs/providers/llm/adapters/openrouter/openrouter.js.map +7 -0
- package/dist/cjs/providers/llm/index.js +1 -1
- package/dist/cjs/providers/llm/index.js.map +3 -3
- package/dist/cjs/providers/llm/toolmode/index.js +2 -0
- package/dist/cjs/providers/llm/toolmode/index.js.map +7 -0
- package/dist/cjs/providers/llm/toolmode/toolmode.js +2 -0
- package/dist/cjs/providers/llm/toolmode/toolmode.js.map +7 -0
- package/dist/cjs/providers/llm/types.js +1 -1
- package/dist/cjs/providers/llm/types.js.map +3 -3
- package/dist/cjs/providers/stt/adapters/deepgram/deepgram.js +1 -1
- package/dist/cjs/providers/stt/adapters/deepgram/deepgram.js.map +3 -3
- package/dist/cjs/providers/stt/adapters/index.js +1 -1
- package/dist/cjs/providers/stt/adapters/index.js.map +3 -3
- package/dist/cjs/providers/stt/adapters/openrouter/index.js +2 -0
- package/dist/cjs/providers/stt/adapters/openrouter/index.js.map +7 -0
- package/dist/cjs/providers/stt/adapters/openrouter/openrouter.js +2 -0
- package/dist/cjs/providers/stt/adapters/openrouter/openrouter.js.map +7 -0
- package/dist/cjs/providers/tts/adapters/index.js +1 -1
- package/dist/cjs/providers/tts/adapters/index.js.map +3 -3
- package/dist/cjs/providers/tts/adapters/kokoro/kokoro.js +4 -1
- package/dist/cjs/providers/tts/adapters/kokoro/kokoro.js.map +3 -3
- package/dist/cjs/providers/tts/adapters/openrouter/index.js +2 -0
- package/dist/cjs/providers/tts/adapters/openrouter/index.js.map +7 -0
- package/dist/cjs/providers/tts/adapters/openrouter/openrouter.js +2 -0
- package/dist/cjs/providers/tts/adapters/openrouter/openrouter.js.map +7 -0
- package/dist/cjs/transport/streamobject/field-stream/field-stream.js +2 -0
- package/dist/cjs/transport/streamobject/field-stream/field-stream.js.map +7 -0
- package/dist/cjs/transport/streamobject/field-stream/index.js +2 -0
- package/dist/cjs/transport/streamobject/field-stream/index.js.map +7 -0
- package/dist/cjs/transport/streamobject/index.js +2 -0
- package/dist/cjs/transport/streamobject/index.js.map +7 -0
- package/dist/cjs/transport/streamobject/json-adapter/index.js +2 -0
- package/dist/cjs/transport/streamobject/json-adapter/index.js.map +7 -0
- package/dist/cjs/transport/streamobject/json-adapter/json-adapter.js +4 -0
- package/dist/cjs/transport/streamobject/json-adapter/json-adapter.js.map +7 -0
- package/dist/cjs/transport/streamobject/reference/index.js +2 -0
- package/dist/cjs/transport/streamobject/reference/index.js.map +7 -0
- package/dist/cjs/transport/streamobject/reference/reference.js +2 -0
- package/dist/cjs/transport/streamobject/reference/reference.js.map +7 -0
- package/dist/cjs/transport/streamobject/stream-object/index.js +2 -0
- package/dist/cjs/transport/streamobject/stream-object/index.js.map +7 -0
- package/dist/cjs/transport/streamobject/stream-object/stream-object.js +2 -0
- package/dist/cjs/transport/streamobject/stream-object/stream-object.js.map +7 -0
- package/dist/esm/agents/agent.js +1 -1
- package/dist/esm/agents/agent.js.map +3 -3
- package/dist/esm/agents/tools/tools.js +1 -1
- package/dist/esm/agents/tools/tools.js.map +3 -3
- package/dist/esm/conversations/conversation/conversation.js +1 -1
- package/dist/esm/conversations/conversation/conversation.js.map +3 -3
- package/dist/esm/conversations/conversations.js +1 -1
- package/dist/esm/conversations/conversations.js.map +3 -3
- package/dist/esm/conversations/index.js +1 -1
- package/dist/esm/conversations/index.js.map +3 -3
- package/dist/esm/conversations/orchestration/coordination/coordination.js +10 -0
- package/dist/esm/conversations/orchestration/coordination/coordination.js.map +7 -0
- package/dist/esm/conversations/orchestration/coordination/index.js +2 -0
- package/dist/esm/conversations/orchestration/coordination/index.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/coordination-runner/coordination-runner.js +4 -0
- package/dist/esm/conversations/orchestration/orchestrator/coordination-runner/coordination-runner.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/coordination-runner/index.js +2 -0
- package/dist/esm/conversations/orchestration/orchestrator/coordination-runner/index.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/generation/generation.js +2 -0
- package/dist/esm/conversations/orchestration/orchestrator/generation/generation.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/generation/index.js +2 -0
- package/dist/esm/conversations/orchestration/orchestrator/generation/index.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/history/history.js +4 -0
- package/dist/esm/conversations/orchestration/orchestrator/history/history.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/history/index.js +2 -0
- package/dist/esm/conversations/orchestration/orchestrator/history/index.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/index.js +1 -1
- package/dist/esm/conversations/orchestration/orchestrator/index.js.map +3 -3
- package/dist/esm/conversations/orchestration/orchestrator/orchestrator.js +1 -2
- package/dist/esm/conversations/orchestration/orchestrator/orchestrator.js.map +3 -3
- package/dist/esm/conversations/orchestration/orchestrator/routing/index.js +2 -0
- package/dist/esm/conversations/orchestration/orchestrator/routing/index.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/routing/routing.js +23 -0
- package/dist/esm/conversations/orchestration/orchestrator/routing/routing.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/speech/index.js +2 -0
- package/dist/esm/conversations/orchestration/orchestrator/speech/index.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/speech/speech.js +2 -0
- package/dist/esm/conversations/orchestration/orchestrator/speech/speech.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/tools/index.js +2 -0
- package/dist/esm/conversations/orchestration/orchestrator/tools/index.js.map +7 -0
- package/dist/esm/conversations/orchestration/orchestrator/tools/tools.js +2 -0
- package/dist/esm/conversations/orchestration/orchestrator/tools/tools.js.map +7 -0
- package/dist/esm/conversations/orchestration/test-harness.js +2 -0
- package/dist/esm/conversations/orchestration/test-harness.js.map +7 -0
- package/dist/esm/conversations/orchestration/text-chunker/index.js +2 -0
- package/dist/esm/conversations/orchestration/text-chunker/index.js.map +7 -0
- package/dist/esm/conversations/orchestration/text-chunker/text-chunker.js +3 -0
- package/dist/esm/conversations/orchestration/text-chunker/text-chunker.js.map +7 -0
- package/dist/esm/conversations/stream/conversation-stream.js +2 -0
- package/dist/esm/conversations/stream/conversation-stream.js.map +7 -0
- package/dist/esm/conversations/stream/index.js +2 -0
- package/dist/esm/conversations/stream/index.js.map +7 -0
- package/dist/esm/conversations/types.js +1 -1
- package/dist/esm/conversations/types.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/persistence/adapters/sqlite/sqlite.js +18 -14
- package/dist/esm/persistence/adapters/sqlite/sqlite.js.map +3 -3
- package/dist/esm/pipeflow/index.js +2 -0
- package/dist/esm/pipeflow/index.js.map +7 -0
- package/dist/esm/pipeflow/pipeflow.js +2 -0
- package/dist/esm/pipeflow/pipeflow.js.map +7 -0
- package/dist/esm/providers/index.js +1 -1
- package/dist/esm/providers/index.js.map +3 -3
- package/dist/esm/providers/llm/adapters/claude/claude.js +5 -0
- package/dist/esm/providers/llm/adapters/claude/claude.js.map +7 -0
- package/dist/esm/providers/llm/adapters/claude/index.js +2 -0
- package/dist/esm/providers/llm/adapters/claude/index.js.map +7 -0
- package/dist/esm/providers/llm/adapters/deepseek/deepseek.js +1 -1
- package/dist/esm/providers/llm/adapters/deepseek/deepseek.js.map +3 -3
- package/dist/esm/providers/llm/adapters/index.js +1 -1
- package/dist/esm/providers/llm/adapters/index.js.map +3 -3
- package/dist/esm/providers/llm/adapters/openai/index.js +2 -0
- package/dist/esm/providers/llm/adapters/openai/index.js.map +7 -0
- package/dist/esm/providers/llm/adapters/openai/openai.js +2 -0
- package/dist/esm/providers/llm/adapters/openai/openai.js.map +7 -0
- package/dist/esm/providers/llm/adapters/openai-compatible.js +10 -0
- package/dist/esm/providers/llm/adapters/openai-compatible.js.map +7 -0
- package/dist/esm/providers/llm/adapters/openrouter/index.js +2 -0
- package/dist/esm/providers/llm/adapters/openrouter/index.js.map +7 -0
- package/dist/esm/providers/llm/adapters/openrouter/openrouter.js +2 -0
- package/dist/esm/providers/llm/adapters/openrouter/openrouter.js.map +7 -0
- package/dist/esm/providers/llm/index.js +1 -1
- package/dist/esm/providers/llm/index.js.map +3 -3
- package/dist/esm/providers/llm/toolmode/index.js +2 -0
- package/dist/esm/providers/llm/toolmode/index.js.map +7 -0
- package/dist/esm/providers/llm/toolmode/toolmode.js +2 -0
- package/dist/esm/providers/llm/toolmode/toolmode.js.map +7 -0
- package/dist/esm/providers/llm/types.js +1 -0
- package/dist/esm/providers/llm/types.js.map +4 -4
- package/dist/esm/providers/stt/adapters/deepgram/deepgram.js +1 -1
- package/dist/esm/providers/stt/adapters/deepgram/deepgram.js.map +3 -3
- package/dist/esm/providers/stt/adapters/index.js +1 -1
- package/dist/esm/providers/stt/adapters/index.js.map +3 -3
- package/dist/esm/providers/stt/adapters/openrouter/index.js +2 -0
- package/dist/esm/providers/stt/adapters/openrouter/index.js.map +7 -0
- package/dist/esm/providers/stt/adapters/openrouter/openrouter.js +2 -0
- package/dist/esm/providers/stt/adapters/openrouter/openrouter.js.map +7 -0
- package/dist/esm/providers/tts/adapters/index.js +1 -1
- package/dist/esm/providers/tts/adapters/index.js.map +3 -3
- package/dist/esm/providers/tts/adapters/kokoro/kokoro.js +4 -1
- package/dist/esm/providers/tts/adapters/kokoro/kokoro.js.map +3 -3
- package/dist/esm/providers/tts/adapters/openrouter/index.js +2 -0
- package/dist/esm/providers/tts/adapters/openrouter/index.js.map +7 -0
- package/dist/esm/providers/tts/adapters/openrouter/openrouter.js +2 -0
- package/dist/esm/providers/tts/adapters/openrouter/openrouter.js.map +7 -0
- package/dist/esm/transport/streamobject/field-stream/field-stream.js +2 -0
- package/dist/esm/transport/streamobject/field-stream/field-stream.js.map +7 -0
- package/dist/esm/transport/streamobject/field-stream/index.js +2 -0
- package/dist/esm/transport/streamobject/field-stream/index.js.map +7 -0
- package/dist/esm/transport/streamobject/index.js +2 -0
- package/dist/esm/transport/streamobject/index.js.map +7 -0
- package/dist/esm/transport/streamobject/json-adapter/index.js +2 -0
- package/dist/esm/transport/streamobject/json-adapter/index.js.map +7 -0
- package/dist/esm/transport/streamobject/json-adapter/json-adapter.js +4 -0
- package/dist/esm/transport/streamobject/json-adapter/json-adapter.js.map +7 -0
- package/dist/esm/transport/streamobject/reference/index.js +2 -0
- package/dist/esm/transport/streamobject/reference/index.js.map +7 -0
- package/dist/esm/transport/streamobject/reference/reference.js +2 -0
- package/dist/esm/transport/streamobject/reference/reference.js.map +7 -0
- package/dist/esm/transport/streamobject/stream-object/index.js +2 -0
- package/dist/esm/transport/streamobject/stream-object/index.js.map +7 -0
- package/dist/esm/transport/streamobject/stream-object/stream-object.js +2 -0
- package/dist/esm/transport/streamobject/stream-object/stream-object.js.map +7 -0
- package/dist/types/agents/agent.d.ts +3 -0
- package/dist/types/agents/tools/tools.d.ts +28 -6
- package/dist/types/conversations/conversation/conversation.d.ts +85 -6
- package/dist/types/conversations/conversations.d.ts +11 -1
- package/dist/types/conversations/index.d.ts +2 -1
- package/dist/types/conversations/orchestration/coordination/coordination.d.ts +192 -0
- package/dist/types/conversations/orchestration/coordination/index.d.ts +2 -0
- package/dist/types/conversations/orchestration/orchestrator/coordination-runner/coordination-runner.d.ts +108 -0
- package/dist/types/conversations/orchestration/orchestrator/coordination-runner/index.d.ts +2 -0
- package/dist/types/conversations/orchestration/orchestrator/generation/generation.d.ts +43 -0
- package/dist/types/conversations/orchestration/orchestrator/generation/index.d.ts +2 -0
- package/dist/types/conversations/orchestration/orchestrator/history/history.d.ts +62 -0
- package/dist/types/conversations/orchestration/orchestrator/history/index.d.ts +1 -0
- package/dist/types/conversations/orchestration/orchestrator/index.d.ts +10 -0
- package/dist/types/conversations/orchestration/orchestrator/orchestrator.d.ts +45 -27
- package/dist/types/conversations/orchestration/orchestrator/routing/index.d.ts +1 -0
- package/dist/types/conversations/orchestration/orchestrator/routing/routing.d.ts +19 -0
- package/dist/types/conversations/orchestration/orchestrator/speech/index.d.ts +2 -0
- package/dist/types/conversations/orchestration/orchestrator/speech/speech.d.ts +49 -0
- package/dist/types/conversations/orchestration/orchestrator/tools/index.d.ts +2 -0
- package/dist/types/conversations/orchestration/orchestrator/tools/tools.d.ts +31 -0
- package/dist/types/conversations/orchestration/test-harness.d.ts +96 -0
- package/dist/types/conversations/orchestration/text-chunker/index.d.ts +1 -0
- package/dist/types/conversations/orchestration/text-chunker/text-chunker.d.ts +39 -0
- package/dist/types/conversations/stream/conversation-stream.d.ts +42 -0
- package/dist/types/conversations/stream/index.d.ts +1 -0
- package/dist/types/conversations/types.d.ts +32 -0
- package/dist/types/index.d.ts +5 -38
- package/dist/types/pipeflow/index.d.ts +2 -0
- package/dist/types/pipeflow/pipeflow.d.ts +35 -0
- package/dist/types/providers/index.d.ts +1 -1
- package/dist/types/providers/llm/adapters/claude/claude.d.ts +45 -0
- package/dist/types/providers/llm/adapters/claude/index.d.ts +2 -0
- package/dist/types/providers/llm/adapters/deepseek/deepseek.d.ts +23 -2
- package/dist/types/providers/llm/adapters/index.d.ts +3 -0
- package/dist/types/providers/llm/adapters/openai/index.d.ts +2 -0
- package/dist/types/providers/llm/adapters/openai/openai.d.ts +45 -0
- package/dist/types/providers/llm/adapters/openai-compatible.d.ts +44 -0
- package/dist/types/providers/llm/adapters/openrouter/index.d.ts +2 -0
- package/dist/types/providers/llm/adapters/openrouter/openrouter.d.ts +60 -0
- package/dist/types/providers/llm/index.d.ts +5 -2
- package/dist/types/providers/llm/toolmode/index.d.ts +2 -0
- package/dist/types/providers/llm/toolmode/toolmode.d.ts +99 -0
- package/dist/types/providers/llm/types.d.ts +62 -0
- package/dist/types/providers/stt/adapters/deepgram/deepgram.d.ts +4 -1
- package/dist/types/providers/stt/adapters/index.d.ts +1 -0
- package/dist/types/providers/stt/adapters/openrouter/index.d.ts +2 -0
- package/dist/types/providers/stt/adapters/openrouter/openrouter.d.ts +94 -0
- package/dist/types/providers/tts/adapters/index.d.ts +1 -0
- package/dist/types/providers/tts/adapters/kokoro/kokoro.d.ts +17 -2
- package/dist/types/providers/tts/adapters/openrouter/index.d.ts +2 -0
- package/dist/types/providers/tts/adapters/openrouter/openrouter.d.ts +45 -0
- package/dist/types/transport/streamobject/field-stream/field-stream.d.ts +85 -0
- package/dist/types/transport/streamobject/field-stream/index.d.ts +2 -0
- package/dist/types/transport/streamobject/index.d.ts +8 -0
- package/dist/types/transport/streamobject/json-adapter/index.d.ts +2 -0
- package/dist/types/transport/streamobject/json-adapter/json-adapter.d.ts +65 -0
- package/dist/types/transport/streamobject/reference/index.d.ts +2 -0
- package/dist/types/transport/streamobject/reference/reference.d.ts +127 -0
- package/dist/types/transport/streamobject/stream-object/index.d.ts +2 -0
- package/dist/types/transport/streamobject/stream-object/stream-object.d.ts +31 -0
- package/package.json +23 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/transport/streamobject/reference/index.ts"],
|
|
4
|
+
"sourcesContent": ["export {\n ReferenceDecoder,\n Receiver,\n decode,\n encodeText,\n executeRecords,\n materializeObject,\n parseBooleanPayload,\n parseIntegerPayload,\n parseNumberPayload,\n} from \"./reference\";\nexport type {\n Decoder,\n Event,\n FieldDef,\n FieldType,\n FieldValue,\n Payload,\n ScalarValue,\n Schema,\n StreamRecord,\n} from \"./reference\";\n"],
|
|
5
|
+
"mappings": "AAAA,OACE,oBAAAA,EACA,YAAAC,EACA,UAAAC,EACA,cAAAC,EACA,kBAAAC,EACA,qBAAAC,EACA,uBAAAC,EACA,uBAAAC,EACA,sBAAAC,MACK",
|
|
6
|
+
"names": ["ReferenceDecoder", "Receiver", "decode", "encodeText", "executeRecords", "materializeObject", "parseBooleanPayload", "parseIntegerPayload", "parseNumberPayload"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var v=Object.defineProperty;var s=(r,e)=>v(r,"name",{value:e,configurable:!0});const y=/^-?(0|[1-9][0-9]*)$/,w=/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?$/;function E(r){if(!y.test(r)||r==="-0")return null;const e=Number(r);return Number.isSafeInteger(e)?e:null}s(E,"parseIntegerPayload");function x(r){if(!w.test(r))return null;const e=Number(r);return Number.isFinite(e)?e:null}s(x,"parseNumberPayload");function k(r){return r==="0"?!1:r==="1"?!0:null}s(k,"parseBooleanPayload");function h(r,e,t){switch(r){case"string":return e;case"integer":{const n=E(e);if(n===null)throw new Error(`field ${t}: invalid integer payload`);return n}case"number":{const n=x(e);if(n===null)throw new Error(`field ${t}: invalid number payload`);return n}case"boolean":{const n=k(e);if(n===null)throw new Error(`field ${t}: invalid boolean payload`);return n}}}s(h,"parseTyped");class u{static{s(this,"Receiver")}schema;state;acc;events=[];onEvent;ended=!1;constructor(e,t){this.schema=e,this.onEvent=t,this.state=new Uint8Array(e.length),this.acc=new Array(e.length)}append(e,t){if(this.assertActive(),this.assertField(e),this.state[e]===2)throw new Error(`field ${e}: append after completion`);const n=this.schema[e];if(n.mode==="array"){const i=this.acc[e]??=[],o=n.maxItems;if(i.length>=o)throw new Error(`field ${e}: exceeds maxItems=${o}`);if(n.maxLength!==void 0&&t.length>n.maxLength)throw new Error(`field ${e}: item exceeds maxLength=${n.maxLength}`);i.push(t)}else{const i=this.acc[e]??="";if(n.maxLength!==void 0&&i.length+t.length>n.maxLength)throw new Error(`field ${e}: exceeds maxLength=${n.maxLength}`);this.acc[e]=i+t}this.state[e]=1}complete(e){if(this.assertActive(),this.assertField(e),this.state[e]===2)throw new Error(`field ${e}: completed twice`);const t=this.schema[e];if(this.state[e]===0){if(t.type!=="string"&&t.mode!=="array")throw new Error(`field ${e}: cannot complete an empty ${t.type} field`);this.state[e]=2,this.emit({kind:"field",field:e,value:t.mode==="array"?[]:""});return}this.state[e]=2,this.emit({kind:"field",field:e,value:S(this.schema,e,this.acc[e])})}objectComplete(){this.assertActive(),this.ended=!0,this.emit({kind:"object-complete"})}objectAbort(){this.assertActive(),this.ended=!0,this.emit({kind:"object-abort"})}getEvents(){return this.events}get isEnded(){return this.ended}assertActive(){if(this.ended)throw new Error("object already ended")}assertField(e){if(e<0||e>=this.schema.length)throw new Error(`unknown field ${e}`)}emit(e){this.events.push(e),this.onEvent?.(e)}}function S(r,e,t){const n=r[e];return n.mode==="array"?t.map(i=>h(n.type,i,e)):h(n.type,t,e)}s(S,"materialize");function M(r,e){const t=new u(r);for(const n of e)switch(n.kind){case"append":t.append(n.field,n.payload);break;case"complete":t.complete(n.field);break;case"object-complete":t.objectComplete();break;case"object-abort":t.objectAbort();break}if(!t.isEnded)throw new Error("stream ended before object completion");return t.getEvents()}s(M,"executeRecords");function P(r,e){const t={};for(const n of e)n.kind==="field"&&R(t,r[n.field].path,n.value);return t}s(P,"materializeObject");function R(r,e,t){let n=r;for(let i=0;i<e.length-1;i++){const o=e[i];(typeof n[o]!="object"||n[o]===null)&&(n[o]={}),n=n[o]}n[e[e.length-1]]=t}s(R,"setPath");function T(r){let e="";for(const t of r)switch(t.kind){case"append":e+=`${t.field}:${t.payload.length}:${t.payload};`;break;case"complete":e+=`!${t.field};`;break;case"object-complete":e+="!;";break;case"object-abort":e+="~;";break}return e}s(T,"encodeText");class ${static{s(this,"ReferenceDecoder")}receiver;state="header";fieldId="";length="";payload="";remaining=0;constructor(e,t){this.receiver=new u(e,t)}push(e){for(let t=0;t<e.length;t++){const n=e[t];switch(this.state){case"header":this.onHeader(n);break;case"field-id":this.onFieldId(n);break;case"length":this.onLength(n);break;case"payload":this.onPayload(n);break;case"payload-end":this.onPayloadEnd(n);break;case"control":this.onControl(n);break;case"abort":this.onAbort(n);break}}}end(){if(!this.receiver.isEnded)throw new Error("stream ended before object completion");return this.receiver.getEvents()}onHeader(e){if(c(e)){this.reset(),this.fieldId=e,this.state="field-id";return}if(e==="!"){this.reset(),this.state="control";return}if(e==="~"){this.state="abort";return}throw new Error(`expected record start, got ${JSON.stringify(e)}`)}onFieldId(e){if(c(e)){this.fieldId+=e;return}if(e===":"){this.state="length";return}throw new Error(`expected ':' after field id, got ${JSON.stringify(e)}`)}onLength(e){if(c(e)){this.length+=e;return}if(e===":"){if(this.length==="")throw new Error("empty payload length");this.remaining=Number(this.length),this.payload="",this.state=this.remaining===0?"payload-end":"payload";return}throw new Error(`expected ':' after length, got ${JSON.stringify(e)}`)}onPayload(e){this.payload+=e,--this.remaining===0&&(this.state="payload-end")}onPayloadEnd(e){if(e!==";")throw new Error(`expected ';' after payload, got ${JSON.stringify(e)}`);this.receiver.append(Number(this.fieldId),this.payload),this.state="header"}onControl(e){if(c(e)){this.fieldId+=e;return}if(e===";"){this.fieldId===""?this.receiver.objectComplete():this.receiver.complete(Number(this.fieldId)),this.state="header";return}throw new Error(`expected field id or ';' after '!', got ${JSON.stringify(e)}`)}onAbort(e){if(e!==";")throw new Error(`expected ';' after '~', got ${JSON.stringify(e)}`);this.receiver.objectAbort(),this.state="header"}reset(){this.fieldId="",this.length="",this.payload="",this.remaining=0}}function c(r){return r>="0"&&r<="9"}s(c,"isDigit");function C(r,e){const t=new $(e);for(const n of r)t.push(n);return t.end()}s(C,"decode");function V(r){let e=r>>>0;return()=>{e=e+1831565813>>>0;let t=e;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}s(V,"mulberry32");function O(r,e){const t=[];for(let o=1;o<r.length;o++)e()<.3&&t.push(o);const n=[];let i=0;for(const o of t)n.push(r.slice(i,o)),i=o;return n.push(r.slice(i)),n}s(O,"fragment");function D(r){const e=[];for(let t=1;t<r.length;t++)e.push([r.slice(0,t),r.slice(t)]);return e}s(D,"allSingleCuts");function J(r){const e=[];for(let t=0;t<1<<r.length-1;t++){const n=[];let i=0;for(let o=1;o<r.length;o++)t&1<<o-1&&(n.push(r.slice(i,o)),i=o);n.push(r.slice(i)),e.push(n)}return e}s(J,"allCompositions");const p=["string","integer","number","boolean"],m="abZ09;:!~ \xE9\u{1F600}";function B(r){const e=1+Math.floor(r()*4),t=[];for(let n=0;n<e;n++){const i=p[Math.floor(r()*p.length)],o=r()<.4;t.push({path:[`f${n}`],type:i,...o?{mode:"array",maxItems:1+Math.floor(r()*4)}:{},...r()<.8?{maxLength:1+Math.floor(r()*16)}:{}})}return t}s(B,"randomSchema");function j(r,e){let t="";for(;t.length<e&&r()<.85;)t+=m[Math.floor(r()*m.length)];return t}s(j,"randomString");function I(r,e,t){switch(e){case"string":return r()<.15?"":j(r,t);case"integer":return String(Math.floor(r()*2e3)-1e3);case"number":{const n=r();return n<.4?String(Math.floor(r()*2e3)-1e3):n<.7?String(Math.round((r()*2e3-1e3)*100)/100):String((r()*2-1)*1e10)}case"boolean":return r()<.5?"0":"1"}}s(I,"randomTyped");function f(r,e,t){const n=t??12;for(let i=0;i<100;i++){const o=I(r,e,n);if(o.length<=n)return o}return e==="string"?"":"0"}s(f,"payloadFor");function F(r,e){if(r.length===0)return[];const t=[];let n=0;for(let i=1;i<e;i++){const o=Math.floor(i*r.length/e);t.push(r.slice(n,o)),n=o}return t.push(r.slice(n)),t.filter(i=>i.length>0)}s(F,"splitFragments");function A(r,e,t){const n=e[t],i=[];if(n.mode==="array"){const l=n.maxItems,b=Math.floor(r()*(l+1));for(let d=0;d<b;d++)i.push({kind:"append",field:t,payload:f(r,n.type,n.maxLength)});return r()<.8&&i.push({kind:"complete",field:t}),i}const o=f(r,n.type,n.maxLength),a=F(o,1+Math.floor(r()*4));for(const l of a)i.push({kind:"append",field:t,payload:l});const g=n.type==="string";return(i.length>0?r()<.85:g&&r()<.5)&&i.push({kind:"complete",field:t}),i}s(A,"fieldRecords");function H(r,e){const t=e.map((o,a)=>({field:a,records:A(r,e,a),pos:0})),n=[];let i=t.reduce((o,a)=>o+a.records.length,0);for(;i>0;){let o=t[Math.floor(r()*t.length)];for(;o.pos>=o.records.length;)o=t[(o.field+1)%t.length];n.push(o.records[o.pos]),o.pos++,i--}return n.push(r()<.1?{kind:"object-abort"}:{kind:"object-complete"}),n}s(H,"generateValidRecords");export{u as Receiver,$ as ReferenceDecoder,J as allCompositions,D as allSingleCuts,C as decode,T as encodeText,M as executeRecords,A as fieldRecords,O as fragment,H as generateValidRecords,P as materializeObject,V as mulberry32,k as parseBooleanPayload,E as parseIntegerPayload,x as parseNumberPayload,B as randomSchema};
|
|
2
|
+
//# sourceMappingURL=reference.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/transport/streamobject/reference/reference.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * StreamObject Protocol v0.1 \u2014 reference implementation (the executable spec).\n *\n * Deliberately boring: no arena, no pooling, no typed-array chunk chains.\n * Its purpose is to pin down semantics so the optimized receiver can be\n * validated against it instead of inventing behavior.\n *\n * Layering:\n * records --(encodeText)--> text --(fragment)--> chunks\n * chunks --(ReferenceDecoder)--> events\n * records --(Receiver / executeRecords)--> events <- the oracle\n *\n * Contract (the property every decoder must satisfy):\n * decode(fragment(encodeText(records))) === executeRecords(records)\n *\n * See README.md (in this directory) for the normative spec this implements.\n */\n\nexport type Payload = string; // payload as a JS string (UTF-16 code units)\n\nexport type StreamRecord =\n | { kind: \"append\"; field: number; payload: Payload }\n | { kind: \"complete\"; field: number }\n | { kind: \"object-complete\" }\n | { kind: \"object-abort\" };\n\nexport type FieldType = \"string\" | \"integer\" | \"number\" | \"boolean\";\n\nexport interface FieldDef {\n path: string[];\n type: FieldType;\n mode?: \"array\";\n /** Required for array fields. */\n maxItems?: number;\n /** Scalar: cap on accumulated payload length. Array: cap per item. */\n maxLength?: number;\n}\n\nexport type Schema = FieldDef[];\n\nexport type ScalarValue = string | number | boolean;\nexport type FieldValue = ScalarValue | ScalarValue[];\n\nexport type Event =\n | { kind: \"field\"; field: number; value: FieldValue }\n /** Adapter-observable item completion (arrays); not emitted by the v0.1 wire decoder. */\n | { kind: \"item\"; field: number; index: number; value: ScalarValue }\n | { kind: \"object-complete\" }\n | { kind: \"object-abort\" };\n\n// ---- canonical typed payloads (spec \u00A72.1) -----------------------------------\n\nconst INTEGER_RE = /^-?(0|[1-9][0-9]*)$/;\nconst NUMBER_RE = /^-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][+-]?[0-9]+)?$/;\n\nexport function parseIntegerPayload(s: string): number | null {\n if (!INTEGER_RE.test(s)) return null;\n if (s === \"-0\") return null;\n const n = Number(s);\n return Number.isSafeInteger(n) ? n : null;\n}\n\nexport function parseNumberPayload(s: string): number | null {\n if (!NUMBER_RE.test(s)) return null;\n const n = Number(s);\n return Number.isFinite(n) ? n : null;\n}\n\nexport function parseBooleanPayload(s: string): boolean | null {\n if (s === \"0\") return false;\n if (s === \"1\") return true;\n return null;\n}\n\nfunction parseTyped(type: FieldType, s: string, field: number): ScalarValue {\n switch (type) {\n case \"string\":\n return s;\n case \"integer\": {\n const v = parseIntegerPayload(s);\n if (v === null) throw new Error(`field ${field}: invalid integer payload`);\n return v;\n }\n case \"number\": {\n const v = parseNumberPayload(s);\n if (v === null) throw new Error(`field ${field}: invalid number payload`);\n return v;\n }\n case \"boolean\": {\n const v = parseBooleanPayload(s);\n if (v === null) throw new Error(`field ${field}: invalid boolean payload`);\n return v;\n }\n }\n}\n\n// ---- semantic engine (shared by oracle and decoder) --------------------------\n\nexport class Receiver {\n private readonly schema: Schema;\n private readonly state: Uint8Array; // 0 unseen, 1 streaming, 2 done\n private readonly acc: Array<string | string[]>;\n private readonly events: Event[] = [];\n private readonly onEvent: ((event: Event) => void) | undefined;\n private ended = false;\n\n constructor(schema: Schema, onEvent?: (event: Event) => void) {\n this.schema = schema;\n this.onEvent = onEvent;\n this.state = new Uint8Array(schema.length);\n this.acc = new Array(schema.length);\n }\n\n append(field: number, payload: string): void {\n this.assertActive();\n this.assertField(field);\n if (this.state[field] === 2) {\n throw new Error(`field ${field}: append after completion`);\n }\n const def = this.schema[field]!;\n if (def.mode === \"array\") {\n const items = (this.acc[field] ??= []) as string[];\n const maxItems = def.maxItems as number;\n if (items.length >= maxItems) {\n throw new Error(`field ${field}: exceeds maxItems=${maxItems}`);\n }\n if (def.maxLength !== undefined && payload.length > def.maxLength) {\n throw new Error(`field ${field}: item exceeds maxLength=${def.maxLength}`);\n }\n items.push(payload);\n } else {\n const current = (this.acc[field] ??= \"\") as string;\n if (def.maxLength !== undefined && current.length + payload.length > def.maxLength) {\n throw new Error(`field ${field}: exceeds maxLength=${def.maxLength}`);\n }\n this.acc[field] = current + payload;\n }\n this.state[field] = 1;\n }\n\n complete(field: number): void {\n this.assertActive();\n this.assertField(field);\n if (this.state[field] === 2) {\n throw new Error(`field ${field}: completed twice`);\n }\n const def = this.schema[field]!;\n if (this.state[field] === 0) {\n if (def.type !== \"string\" && def.mode !== \"array\") {\n throw new Error(`field ${field}: cannot complete an empty ${def.type} field`);\n }\n this.state[field] = 2;\n this.emit({ kind: \"field\", field, value: def.mode === \"array\" ? [] : \"\" });\n return;\n }\n this.state[field] = 2;\n this.emit({\n kind: \"field\",\n field,\n value: materialize(this.schema, field, this.acc[field] as string | string[]),\n });\n }\n\n objectComplete(): void {\n this.assertActive();\n this.ended = true;\n this.emit({ kind: \"object-complete\" });\n }\n\n objectAbort(): void {\n this.assertActive();\n this.ended = true;\n this.emit({ kind: \"object-abort\" });\n }\n\n getEvents(): Event[] {\n return this.events;\n }\n\n get isEnded(): boolean {\n return this.ended;\n }\n\n private assertActive(): void {\n if (this.ended) throw new Error(\"object already ended\");\n }\n\n private assertField(field: number): void {\n if (field < 0 || field >= this.schema.length) {\n throw new Error(`unknown field ${field}`);\n }\n }\n\n private emit(event: Event): void {\n this.events.push(event);\n this.onEvent?.(event);\n }\n}\n\nfunction materialize(schema: Schema, field: number, raw: string | string[]): FieldValue {\n const def = schema[field]!;\n if (def.mode === \"array\") {\n return (raw as string[]).map((item) => parseTyped(def.type, item, field));\n }\n return parseTyped(def.type, raw as string, field);\n}\n\n/** The oracle: execute logical records directly. */\nexport function executeRecords(schema: Schema, records: StreamRecord[]): Event[] {\n const receiver = new Receiver(schema);\n for (const record of records) {\n switch (record.kind) {\n case \"append\":\n receiver.append(record.field, record.payload);\n break;\n case \"complete\":\n receiver.complete(record.field);\n break;\n case \"object-complete\":\n receiver.objectComplete();\n break;\n case \"object-abort\":\n receiver.objectAbort();\n break;\n }\n }\n if (!receiver.isEnded) throw new Error(\"stream ended before object completion\");\n return receiver.getEvents();\n}\n\n// ---- materialization ----------------------------------------------------------\n\nexport function materializeObject(schema: Schema, events: Event[]): Record<string, unknown> {\n const object: Record<string, unknown> = {};\n for (const event of events) {\n if (event.kind !== \"field\") continue;\n setPath(object, schema[event.field]!.path, event.value);\n }\n return object;\n}\n\nfunction setPath(object: Record<string, unknown>, path: string[], value: unknown): void {\n let target = object;\n for (let i = 0; i < path.length - 1; i++) {\n const key = path[i]!;\n if (typeof target[key] !== \"object\" || target[key] === null) {\n target[key] = {};\n }\n target = target[key] as Record<string, unknown>;\n }\n target[path[path.length - 1]!] = value;\n}\n\n// ---- reference text encoding (spec \u00A78) ----------------------------------------\n\nexport function encodeText(records: StreamRecord[]): string {\n let out = \"\";\n for (const record of records) {\n switch (record.kind) {\n case \"append\":\n out += `${record.field}:${record.payload.length}:${record.payload};`;\n break;\n case \"complete\":\n out += `!${record.field};`;\n break;\n case \"object-complete\":\n out += \"!;\";\n break;\n case \"object-abort\":\n out += \"~;\";\n break;\n }\n }\n return out;\n}\n\n// ---- reference decoder ----------------------------------------------------------\n\n/**\n * The contract every implementation (including the future arena-backed\n * receiver) must satisfy:\n *\n * push(fragment(encodeText(records))) + end() === executeRecords(schema, records)\n */\nexport interface Decoder {\n push(chunk: string): void;\n end(): Event[];\n}\n\ntype ParserState = \"header\" | \"field-id\" | \"length\" | \"payload\" | \"payload-end\" | \"control\" | \"abort\";\n\nexport class ReferenceDecoder implements Decoder {\n private readonly receiver: Receiver;\n private state: ParserState = \"header\";\n private fieldId = \"\";\n private length = \"\";\n private payload = \"\";\n private remaining = 0;\n\n constructor(schema: Schema, onEvent?: (event: Event) => void) {\n this.receiver = new Receiver(schema, onEvent);\n }\n\n push(chunk: string): void {\n for (let i = 0; i < chunk.length; i++) {\n const c = chunk[i]!;\n switch (this.state) {\n case \"header\":\n this.onHeader(c);\n break;\n case \"field-id\":\n this.onFieldId(c);\n break;\n case \"length\":\n this.onLength(c);\n break;\n case \"payload\":\n this.onPayload(c);\n break;\n case \"payload-end\":\n this.onPayloadEnd(c);\n break;\n case \"control\":\n this.onControl(c);\n break;\n case \"abort\":\n this.onAbort(c);\n break;\n }\n }\n }\n\n end(): Event[] {\n if (!this.receiver.isEnded) throw new Error(\"stream ended before object completion\");\n return this.receiver.getEvents();\n }\n\n private onHeader(c: string): void {\n if (isDigit(c)) {\n this.reset();\n this.fieldId = c;\n this.state = \"field-id\";\n return;\n }\n if (c === \"!\") {\n this.reset();\n this.state = \"control\";\n return;\n }\n if (c === \"~\") {\n this.state = \"abort\";\n return;\n }\n throw new Error(`expected record start, got ${JSON.stringify(c)}`);\n }\n\n private onFieldId(c: string): void {\n if (isDigit(c)) {\n this.fieldId += c;\n return;\n }\n if (c === \":\") {\n this.state = \"length\";\n return;\n }\n throw new Error(`expected ':' after field id, got ${JSON.stringify(c)}`);\n }\n\n private onLength(c: string): void {\n if (isDigit(c)) {\n this.length += c;\n return;\n }\n if (c === \":\") {\n if (this.length === \"\") throw new Error(\"empty payload length\");\n this.remaining = Number(this.length);\n this.payload = \"\";\n this.state = this.remaining === 0 ? \"payload-end\" : \"payload\";\n return;\n }\n throw new Error(`expected ':' after length, got ${JSON.stringify(c)}`);\n }\n\n private onPayload(c: string): void {\n this.payload += c;\n if (--this.remaining === 0) this.state = \"payload-end\";\n }\n\n private onPayloadEnd(c: string): void {\n if (c !== \";\") throw new Error(`expected ';' after payload, got ${JSON.stringify(c)}`);\n this.receiver.append(Number(this.fieldId), this.payload);\n this.state = \"header\";\n }\n\n private onControl(c: string): void {\n if (isDigit(c)) {\n this.fieldId += c;\n return;\n }\n if (c === \";\") {\n if (this.fieldId === \"\") this.receiver.objectComplete();\n else this.receiver.complete(Number(this.fieldId));\n this.state = \"header\";\n return;\n }\n throw new Error(`expected field id or ';' after '!', got ${JSON.stringify(c)}`);\n }\n\n private onAbort(c: string): void {\n if (c !== \";\") throw new Error(`expected ';' after '~', got ${JSON.stringify(c)}`);\n this.receiver.objectAbort();\n this.state = \"header\";\n }\n\n private reset(): void {\n this.fieldId = \"\";\n this.length = \"\";\n this.payload = \"\";\n this.remaining = 0;\n }\n}\n\nfunction isDigit(c: string): boolean {\n return c >= \"0\" && c <= \"9\";\n}\n\n/** Decode a sequence of transport chunks into events. */\nexport function decode(chunks: string[], schema: Schema): Event[] {\n const decoder = new ReferenceDecoder(schema);\n for (const chunk of chunks) decoder.push(chunk);\n return decoder.end();\n}\n\n// ---- test utilities: rng, fragmentation, generators ----------------------------\n\nexport type Rng = () => number;\n\nexport function mulberry32(seed: number): Rng {\n let a = seed >>> 0;\n return () => {\n a = (a + 0x6d2b79f5) >>> 0;\n let t = a;\n t = Math.imul(t ^ (t >>> 15), t | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n };\n}\n\nexport function fragment(text: string, rng: Rng): string[] {\n const cuts: number[] = [];\n for (let i = 1; i < text.length; i++) {\n if (rng() < 0.3) cuts.push(i);\n }\n const chunks: string[] = [];\n let prev = 0;\n for (const cut of cuts) {\n chunks.push(text.slice(prev, cut));\n prev = cut;\n }\n chunks.push(text.slice(prev));\n return chunks;\n}\n\n/** Every single-cut fragmentation of a message. */\nexport function allSingleCuts(text: string): string[][] {\n const out: string[][] = [];\n for (let i = 1; i < text.length; i++) {\n out.push([text.slice(0, i), text.slice(i)]);\n }\n return out;\n}\n\n/** Every composition into 1..n chunks \u2014 2^(n-1) cases. Only for small messages. */\nexport function allCompositions(text: string): string[][] {\n const out: string[][] = [];\n for (let mask = 0; mask < 1 << (text.length - 1); mask++) {\n const chunks: string[] = [];\n let prev = 0;\n for (let i = 1; i < text.length; i++) {\n if (mask & (1 << (i - 1))) {\n chunks.push(text.slice(prev, i));\n prev = i;\n }\n }\n chunks.push(text.slice(prev));\n out.push(chunks);\n }\n return out;\n}\n\n// ---- random valid stream generators ----------------------------------------------\n\nconst TYPES: FieldType[] = [\"string\", \"integer\", \"number\", \"boolean\"];\nconst ALPHABET = \"abZ09;:!~ \u00E9\uD83D\uDE00\"; // protocol punctuation inside payloads + astral chars\n\nexport function randomSchema(rng: Rng): Schema {\n const count = 1 + Math.floor(rng() * 4);\n const schema: Schema = [];\n for (let i = 0; i < count; i++) {\n const type = TYPES[Math.floor(rng() * TYPES.length)]!;\n const isArray = rng() < 0.4;\n schema.push({\n path: [`f${i}`],\n type,\n ...(isArray ? { mode: \"array\" as const, maxItems: 1 + Math.floor(rng() * 4) } : {}),\n ...(rng() < 0.8 ? { maxLength: 1 + Math.floor(rng() * 16) } : {}),\n });\n }\n return schema;\n}\n\nfunction randomString(rng: Rng, cap: number): string {\n let s = \"\";\n while (s.length < cap && rng() < 0.85) {\n s += ALPHABET[Math.floor(rng() * ALPHABET.length)]!;\n }\n return s;\n}\n\nfunction randomTyped(rng: Rng, type: FieldType, cap: number): string {\n switch (type) {\n case \"string\":\n return rng() < 0.15 ? \"\" : randomString(rng, cap);\n case \"integer\":\n return String(Math.floor(rng() * 2000) - 1000);\n case \"number\": {\n const r = rng();\n if (r < 0.4) return String(Math.floor(rng() * 2000) - 1000);\n if (r < 0.7) return String(Math.round((rng() * 2000 - 1000) * 100) / 100);\n return String((rng() * 2 - 1) * 1e10);\n }\n case \"boolean\":\n return rng() < 0.5 ? \"0\" : \"1\";\n }\n}\n\n/** A payload that satisfies the type and (when set) the length cap. */\nfunction payloadFor(rng: Rng, type: FieldType, cap: number | undefined): string {\n const limit = cap ?? 12;\n for (let i = 0; i < 100; i++) {\n const p = randomTyped(rng, type, limit);\n if (p.length <= limit) return p;\n }\n return type === \"string\" ? \"\" : \"0\";\n}\n\nfunction splitFragments(s: string, count: number): string[] {\n if (s.length === 0) return [];\n const chunks: string[] = [];\n let prev = 0;\n for (let i = 1; i < count; i++) {\n const cut = Math.floor((i * s.length) / count);\n chunks.push(s.slice(prev, cut));\n prev = cut;\n }\n chunks.push(s.slice(prev));\n return chunks.filter((c) => c.length > 0);\n}\n\n/** Records for one field: appends (one item each for arrays), maybe a completion. */\nexport function fieldRecords(rng: Rng, schema: Schema, field: number): StreamRecord[] {\n const def = schema[field]!;\n const records: StreamRecord[] = [];\n\n if (def.mode === \"array\") {\n const maxItems = def.maxItems as number;\n const count = Math.floor(rng() * (maxItems + 1));\n for (let i = 0; i < count; i++) {\n records.push({ kind: \"append\", field, payload: payloadFor(rng, def.type, def.maxLength) });\n }\n if (rng() < 0.8) records.push({ kind: \"complete\", field });\n return records;\n }\n\n // scalar: generate the final payload, then fragment it across appends\n const total = payloadFor(rng, def.type, def.maxLength);\n const fragments = splitFragments(total, 1 + Math.floor(rng() * 4));\n for (const fragment of fragments) {\n records.push({ kind: \"append\", field, payload: fragment });\n }\n\n const canCompleteEmpty = def.type === \"string\";\n const hasContent = records.length > 0;\n if (hasContent ? rng() < 0.85 : canCompleteEmpty && rng() < 0.5) {\n records.push({ kind: \"complete\", field });\n }\n return records;\n}\n\n/** A valid record sequence for the schema, randomly scheduled. */\nexport function generateValidRecords(rng: Rng, schema: Schema): StreamRecord[] {\n const queues = schema.map((_, field) => ({\n field,\n records: fieldRecords(rng, schema, field),\n pos: 0,\n }));\n const out: StreamRecord[] = [];\n let remaining = queues.reduce((n, q) => n + q.records.length, 0);\n\n while (remaining > 0) {\n let queue = queues[Math.floor(rng() * queues.length)]!;\n while (queue.pos >= queue.records.length) {\n queue = queues[(queue.field + 1) % queues.length]!;\n }\n out.push(queue.records[queue.pos]!);\n queue.pos++;\n remaining--;\n }\n\n out.push(rng() < 0.1 ? { kind: \"object-abort\" } : { kind: \"object-complete\" });\n return out;\n}\n"],
|
|
5
|
+
"mappings": "+EAoDA,MAAMA,EAAa,sBACbC,EAAY,mDAEX,SAASC,EAAoBC,EAA0B,CAE5D,GADI,CAACH,EAAW,KAAKG,CAAC,GAClBA,IAAM,KAAM,OAAO,KACvB,MAAMC,EAAI,OAAOD,CAAC,EAClB,OAAO,OAAO,cAAcC,CAAC,EAAIA,EAAI,IACvC,CALgBC,EAAAH,EAAA,uBAOT,SAASI,EAAmBH,EAA0B,CAC3D,GAAI,CAACF,EAAU,KAAKE,CAAC,EAAG,OAAO,KAC/B,MAAMC,EAAI,OAAOD,CAAC,EAClB,OAAO,OAAO,SAASC,CAAC,EAAIA,EAAI,IAClC,CAJgBC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Payload", "parseTyped", "type", "field", "v", "Receiver", "schema", "onEvent", "payload", "def", "items", "maxItems", "current", "materialize", "event", "raw", "item", "executeRecords", "records", "receiver", "record", "materializeObject", "events", "object", "setPath", "path", "value", "target", "key", "encodeText", "out", "ReferenceDecoder", "chunk", "i", "c", "isDigit", "decode", "chunks", "decoder", "mulberry32", "seed", "a", "fragment", "text", "rng", "cuts", "prev", "cut", "allSingleCuts", "allCompositions", "mask", "TYPES", "ALPHABET", "randomSchema", "count", "isArray", "randomString", "cap", "randomTyped", "r", "payloadFor", "limit", "p", "splitFragments", "fieldRecords", "total", "fragments", "canCompleteEmpty", "generateValidRecords", "queues", "_", "remaining", "q", "queue"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/transport/streamobject/stream-object/index.ts"],
|
|
4
|
+
"sourcesContent": ["export { StreamObject } from \"./stream-object\";\nexport type {\n ErrorHandler,\n FieldHandler,\n ItemHandler,\n ObjectDoneHandler,\n StreamObjectOptions,\n} from \"./stream-object\";\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,gBAAAA,MAAoB",
|
|
6
|
+
"names": ["StreamObject"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var n=Object.defineProperty;var r=(i,a)=>n(i,"name",{value:a,configurable:!0});import{FieldStream as c}from"../field-stream/field-stream.js";import{JsonToStreamObjectAdapter as l}from"../json-adapter/json-adapter.js";class h extends c{constructor(o,e,t={}){super(e,t);this.source=o}source;static{r(this,"StreamObject")}started=!1;async start(){if(this.started)throw new Error("StreamObject already started");this.started=!0;const o=new l(this.schema,{onFieldDone:r((e,t)=>this.emitField(e,t),"onFieldDone"),onItemDone:r((e,t,s)=>this.emitItem(e,t,s),"onItemDone"),onObjectDone:r(()=>this.emitObject(o.getEvents()),"onObjectDone")});try{for await(const e of this.source){if(this.cancelled)break;for(let t=0;t<e.length&&!this.cancelled;t++)o.push(e[t])}if(!this.cancelled&&!this.objectCompleted)throw new Error("stream ended before object completion")}catch(e){if(this.cancelled)return;this.fail(e)}}}export{h as StreamObject};
|
|
2
|
+
//# sourceMappingURL=stream-object.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/transport/streamobject/stream-object/stream-object.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * StreamObject \u2014 consumes an AsyncIterable of text chunks through the\n * incremental JSON adapter and exposes the FieldStream completion API.\n *\n * const stream = new StreamObject(source, schema);\n * stream.when(\"summary\", (summary) => { ... }); // field completion\n * stream.whenItem(\"searchQueries\", (query, i) => { ... }); // item completion\n * stream.whenObjectDone((object) => { ... }); // whole object\n * stream.onError((error) => { ... }); // failures\n * await stream.start();\n *\n * `when` means completion, not mutation: handlers never see chunks, JSON,\n * SSE, or the wire codec. Handlers are invoked synchronously at the\n * completion boundary and never block the source; async handlers run\n * concurrently and their rejections are routed to onError. `cancel()` stops\n * the source and invokes the optional onCancel hook (e.g. to abort the\n * producer's request).\n *\n * Errors: delivered to onError handlers when registered; otherwise start()\n * rejects with the error. Cancelling the stream is not an error.\n */\n\nimport { FieldStream, type FieldStreamOptions } from \"../field-stream/field-stream\";\nimport { JsonToStreamObjectAdapter } from \"../json-adapter/json-adapter\";\nimport type { Schema } from \"../reference/reference\";\n\nexport type {\n ErrorHandler,\n FieldHandler,\n FieldStreamOptions,\n ItemHandler,\n ObjectDoneHandler,\n} from \"../field-stream/field-stream\";\n\nexport type StreamObjectOptions = FieldStreamOptions;\n\nexport class StreamObject extends FieldStream {\n private started = false;\n\n constructor(\n private readonly source: AsyncIterable<string>,\n schema: Schema,\n options: StreamObjectOptions = {},\n ) {\n super(schema, options);\n }\n\n async start(): Promise<void> {\n if (this.started) throw new Error(\"StreamObject already started\");\n this.started = true;\n\n const adapter = new JsonToStreamObjectAdapter(this.schema, {\n onFieldDone: (field, value) => this.emitField(field, value),\n onItemDone: (field, index, value) => this.emitItem(field, index, value),\n onObjectDone: () => this.emitObject(adapter.getEvents()),\n });\n\n try {\n for await (const chunk of this.source) {\n if (this.cancelled) break;\n for (let i = 0; i < chunk.length; i++) {\n if (this.cancelled) break;\n adapter.push(chunk[i]!);\n }\n }\n if (!this.cancelled && !this.objectCompleted) {\n throw new Error(\"stream ended before object completion\");\n }\n } catch (error) {\n if (this.cancelled) return; // intended cancellation (e.g. producer aborted)\n this.fail(error);\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAsBA,OAAS,eAAAA,MAA4C,+BACrD,OAAS,6BAAAC,MAAiC,+BAanC,MAAMC,UAAqBF,CAAY,CAG5C,YACmBG,EACjBC,EACAC,EAA+B,CAAC,EAChC,CACA,MAAMD,EAAQC,CAAO,EAJJ,YAAAF,CAKnB,CALmB,OAxCrB,MAoC8C,CAAAG,EAAA,qBACpC,QAAU,GAUlB,MAAM,OAAuB,CAC3B,GAAI,KAAK,QAAS,MAAM,IAAI,MAAM,8BAA8B,EAChE,KAAK,QAAU,GAEf,MAAMC,EAAU,IAAIN,EAA0B,KAAK,OAAQ,CACzD,YAAaK,EAAA,CAACE,EAAOC,IAAU,KAAK,UAAUD,EAAOC,CAAK,EAA7C,eACb,WAAYH,EAAA,CAACE,EAAOE,EAAOD,IAAU,KAAK,SAASD,EAAOE,EAAOD,CAAK,EAA1D,cACZ,aAAcH,EAAA,IAAM,KAAK,WAAWC,EAAQ,UAAU,CAAC,EAAzC,eAChB,CAAC,EAED,GAAI,CACF,gBAAiBI,KAAS,KAAK,OAAQ,CACrC,GAAI,KAAK,UAAW,MACpB,QAASC,EAAI,EAAGA,EAAID,EAAM,QACpB,MAAK,UADuBC,IAEhCL,EAAQ,KAAKI,EAAMC,CAAC,CAAE,CAE1B,CACA,GAAI,CAAC,KAAK,WAAa,CAAC,KAAK,gBAC3B,MAAM,IAAI,MAAM,uCAAuC,CAE3D,OAASC,EAAO,CACd,GAAI,KAAK,UAAW,OACpB,KAAK,KAAKA,CAAK,CACjB,CACF,CACF",
|
|
6
|
+
"names": ["FieldStream", "JsonToStreamObjectAdapter", "StreamObject", "source", "schema", "options", "__name", "adapter", "field", "value", "index", "chunk", "i", "error"]
|
|
7
|
+
}
|
|
@@ -2,6 +2,8 @@ import { Tool } from "./tools/tools.js";
|
|
|
2
2
|
import type { LLM, LLMMessage } from "../providers/llm/types.js";
|
|
3
3
|
export interface AgentOptions {
|
|
4
4
|
name: string;
|
|
5
|
+
/** Names a participant might use to address this agent. */
|
|
6
|
+
aliases?: string[];
|
|
5
7
|
context?: string;
|
|
6
8
|
tools?: Tool<never, unknown>[];
|
|
7
9
|
/** LLM provider used by `run()`. Injected by `Pipeflow.agent()`. */
|
|
@@ -40,6 +42,7 @@ export interface AgentRunResult {
|
|
|
40
42
|
*/
|
|
41
43
|
export declare class Agent {
|
|
42
44
|
readonly name: string;
|
|
45
|
+
readonly aliases: string[];
|
|
43
46
|
readonly context: string;
|
|
44
47
|
private readonly toolRegistry;
|
|
45
48
|
/** LLM provider used by `run()` and the orchestrator. */
|
|
@@ -1,9 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schemas for a tool's arguments. `in` shapes what the model sends (and
|
|
4
|
+
* derives the LLM-facing JSON schema); `out` is what `execute` receives after
|
|
5
|
+
* validation. Keeping them separate means `in` stays plain JSON-schema-able
|
|
6
|
+
* while `out` may transform, normalize, or narrow.
|
|
7
|
+
*/
|
|
8
|
+
export interface ToolSchema<TOut, TIn> {
|
|
9
|
+
/** What the model sends — derives the LLM-facing JSON schema. */
|
|
10
|
+
in: z.ZodType<TIn>;
|
|
11
|
+
/** What `execute` receives, validated at run time. Defaults to `in`. */
|
|
12
|
+
out?: z.ZodType<TOut>;
|
|
13
|
+
}
|
|
14
|
+
export interface ToolOptions<TOut, TResult, TIn> {
|
|
2
15
|
name: string;
|
|
3
16
|
description: string;
|
|
4
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Zod schemas for the tool arguments — the single source of truth: `in`
|
|
19
|
+
* derives the LLM-facing JSON schema (`parameters`), and `out` (defaulting
|
|
20
|
+
* to `in`) validates the arguments at `execute()` time, so a model sending
|
|
21
|
+
* garbage surfaces a clear tool error instead of a crash inside the tool.
|
|
22
|
+
* Mutually exclusive with `parameters`.
|
|
23
|
+
*/
|
|
24
|
+
schema?: ToolSchema<TOut, TIn>;
|
|
25
|
+
/** JSON schema describing the arguments for the LLM (no runtime validation). */
|
|
5
26
|
parameters?: Record<string, unknown>;
|
|
6
|
-
execute: (args:
|
|
27
|
+
execute: (args: TOut) => TResult | Promise<TResult>;
|
|
7
28
|
}
|
|
8
29
|
/**
|
|
9
30
|
* A capability exposed by the application to an agent.
|
|
@@ -11,12 +32,13 @@ export interface ToolOptions<TArgs, TResult> {
|
|
|
11
32
|
* Tools execute in the application's backend: Pipeflow never runs
|
|
12
33
|
* application code directly.
|
|
13
34
|
*/
|
|
14
|
-
export declare class Tool<
|
|
35
|
+
export declare class Tool<TOut = Record<string, unknown>, TResult = unknown, TIn = TOut> {
|
|
15
36
|
readonly name: string;
|
|
16
37
|
readonly description: string;
|
|
17
38
|
readonly parameters: Record<string, unknown> | undefined;
|
|
39
|
+
private readonly parse;
|
|
18
40
|
private readonly executor;
|
|
19
|
-
constructor(options: ToolOptions<
|
|
41
|
+
constructor(options: ToolOptions<TOut, TResult, TIn>);
|
|
20
42
|
/** Execute the tool. Sync throws and rejections both surface as rejections. */
|
|
21
|
-
execute(args:
|
|
43
|
+
execute(args: TIn): Promise<TResult>;
|
|
22
44
|
}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import type { Agent } from "../../agents/agent.js";
|
|
2
2
|
import type { Persistence } from "../../persistence/persistence.js";
|
|
3
|
+
import type { STT } from "../../providers/stt/types.js";
|
|
4
|
+
import type { TTS } from "../../providers/tts/types.js";
|
|
3
5
|
import type { AudioChunk, ConversationId, ConversationState, ConversationStatus, Generation, Participant, ParticipantInput, Turn, UserId } from "../types.js";
|
|
4
6
|
import { Transcription, type TranscriptEntry, type TranscriptEntryInput } from "../transcription/transcription.js";
|
|
5
7
|
import type { ToolCall, ToolCallResult } from "../types.js";
|
|
8
|
+
/** Timing points a generation can record, keyed by the stream event. */
|
|
9
|
+
type TimingPoint = "firstToken" | "firstTtsText" | "firstTtsRequest" | "firstTtsAudio";
|
|
6
10
|
export interface ConversationOptions {
|
|
7
11
|
id: ConversationId;
|
|
8
12
|
agents?: Agent[];
|
|
9
13
|
persistence?: Persistence;
|
|
14
|
+
/**
|
|
15
|
+
* STT provider used to attach realtime processing automatically on
|
|
16
|
+
* `start()`.
|
|
17
|
+
*/
|
|
18
|
+
stt?: STT;
|
|
19
|
+
tts?: TTS;
|
|
10
20
|
}
|
|
11
21
|
export interface ConversationEvents {
|
|
12
22
|
start: {
|
|
@@ -25,6 +35,12 @@ export interface ConversationEvents {
|
|
|
25
35
|
userId: UserId;
|
|
26
36
|
audio: AudioChunk;
|
|
27
37
|
};
|
|
38
|
+
/** A finalized text turn via `send()`. Consumed by the orchestrator. */
|
|
39
|
+
"text-in": {
|
|
40
|
+
conversationId: ConversationId;
|
|
41
|
+
userId: UserId;
|
|
42
|
+
text: string;
|
|
43
|
+
};
|
|
28
44
|
/** Generated audio to be played by the application. */
|
|
29
45
|
audio: {
|
|
30
46
|
conversationId: ConversationId;
|
|
@@ -42,6 +58,20 @@ export interface ConversationEvents {
|
|
|
42
58
|
conversationId: ConversationId;
|
|
43
59
|
generation: Generation;
|
|
44
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* The current generation's text, streamed as LLM deltas arrive. Emitted by
|
|
63
|
+
* the orchestrator; the agent name is included when the generation is known.
|
|
64
|
+
*/
|
|
65
|
+
"text-delta": {
|
|
66
|
+
conversationId: ConversationId;
|
|
67
|
+
text: string;
|
|
68
|
+
agentName?: string;
|
|
69
|
+
};
|
|
70
|
+
/** The current (top-level) generation finished generating. */
|
|
71
|
+
"generation-complete": {
|
|
72
|
+
conversationId: ConversationId;
|
|
73
|
+
generation: Generation;
|
|
74
|
+
};
|
|
45
75
|
/** Live STT partials, for captions and fast UX. Not persisted. */
|
|
46
76
|
"partial-transcript": {
|
|
47
77
|
conversationId: ConversationId;
|
|
@@ -75,10 +105,11 @@ export interface ConversationEvents {
|
|
|
75
105
|
* The public realtime conversation API.
|
|
76
106
|
*
|
|
77
107
|
* A `Conversation` is a runtime handle to a persistent conversation:
|
|
78
|
-
* lifecycle (`start`/`stop`), participants, audio intake (`listen`),
|
|
79
|
-
* events.
|
|
80
|
-
*
|
|
81
|
-
*
|
|
108
|
+
* lifecycle (`start`/`stop`), participants, audio intake (`listen`), text
|
|
109
|
+
* turns (`send`), and events. When an STT provider or agents are configured,
|
|
110
|
+
* `start()` automatically attaches the orchestrator, which runs the
|
|
111
|
+
* STT/LLM/TTS pipeline (or routes text turns) and pushes generated audio,
|
|
112
|
+
* turns, transcripts, and tool calls back through conversation events.
|
|
82
113
|
*/
|
|
83
114
|
export declare class Conversation {
|
|
84
115
|
readonly id: ConversationId;
|
|
@@ -86,13 +117,21 @@ export declare class Conversation {
|
|
|
86
117
|
readonly transcription: Transcription;
|
|
87
118
|
readonly state: ConversationState;
|
|
88
119
|
private readonly persistence;
|
|
120
|
+
private readonly stt;
|
|
121
|
+
private readonly tts;
|
|
89
122
|
private readonly listeners;
|
|
90
123
|
private readonly pendingToolCallsById;
|
|
124
|
+
private readonly subGenerations;
|
|
91
125
|
private nextAudioSequence;
|
|
92
126
|
constructor(options: ConversationOptions);
|
|
93
127
|
get status(): ConversationStatus;
|
|
94
128
|
get participants(): Participant[];
|
|
95
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Move the conversation into the started state. This attaches the
|
|
131
|
+
* orchestrator whenever there is realtime work: an STT provider (voice
|
|
132
|
+
* pipeline) or agents to route text turns to (`send()`).
|
|
133
|
+
*/
|
|
134
|
+
start(): Promise<void>;
|
|
96
135
|
stop(): Promise<void>;
|
|
97
136
|
participate(input: ParticipantInput | ParticipantInput[]): Promise<Participant[]>;
|
|
98
137
|
/**
|
|
@@ -103,7 +142,22 @@ export declare class Conversation {
|
|
|
103
142
|
userId: UserId;
|
|
104
143
|
audio: Uint8Array;
|
|
105
144
|
}): void;
|
|
106
|
-
/**
|
|
145
|
+
/**
|
|
146
|
+
* Send a finalized text turn, bypassing STT. Triggers the same pipeline as
|
|
147
|
+
* a transcribed utterance (routing, coordination, generation, resume) —
|
|
148
|
+
* useful for text-first integrations such as chat or Discord text channels.
|
|
149
|
+
*/
|
|
150
|
+
send(input: {
|
|
151
|
+
userId: UserId;
|
|
152
|
+
text: string;
|
|
153
|
+
}): void;
|
|
154
|
+
/**
|
|
155
|
+
* Stop the currently active generation and prevent any further generated
|
|
156
|
+
* audio from reaching the conversation. The orchestrator cancels the LLM
|
|
157
|
+
* and TTS streams, force-resolves pending tool calls, and discards queued
|
|
158
|
+
* audio; the next participant turn starts fresh. Interrupt responsiveness
|
|
159
|
+
* is a tested invariant — audio stops within ~100ms of this call.
|
|
160
|
+
*/
|
|
107
161
|
interrupt(): void;
|
|
108
162
|
on<K extends keyof ConversationEvents>(event: K, listener: (payload: ConversationEvents[K]) => void): () => void;
|
|
109
163
|
/**
|
|
@@ -117,8 +171,20 @@ export declare class Conversation {
|
|
|
117
171
|
pushTurn(turn: Turn): Promise<void>;
|
|
118
172
|
/** Append a transcript entry and notify listeners. */
|
|
119
173
|
pushTranscript(input: Omit<TranscriptEntryInput, "conversationId">): Promise<TranscriptEntry>;
|
|
174
|
+
/**
|
|
175
|
+
* Stream the current generation's text, as produced by the orchestrator
|
|
176
|
+
* from LLM deltas. Emits the `text-delta` event so applications can render
|
|
177
|
+
* or act on partial replies.
|
|
178
|
+
*/
|
|
179
|
+
pushTextDelta(text: string): void;
|
|
120
180
|
/** Push an agent generation into the conversation. */
|
|
121
181
|
pushGeneration(generation: Generation): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Record a timing point on a generation. Without an id this targets the
|
|
184
|
+
* current generation; with one, a dispatched sub-generation. Each point is
|
|
185
|
+
* recorded at most once.
|
|
186
|
+
*/
|
|
187
|
+
noteTiming(point: TimingPoint, generationId?: string): void;
|
|
122
188
|
/** Tool calls requested by the model that are awaiting resolution. */
|
|
123
189
|
get pendingToolCalls(): ToolCall[];
|
|
124
190
|
/**
|
|
@@ -131,8 +197,21 @@ export declare class Conversation {
|
|
|
131
197
|
resolveToolCall(result: ToolCallResult): void;
|
|
132
198
|
/** Mark the current generation as completed, recording its final text. */
|
|
133
199
|
completeGeneration(text?: string): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Push a sub-generation: a task the coordinator dispatched to another
|
|
202
|
+
* agent. Unlike `pushGeneration`, it does not become the conversation's
|
|
203
|
+
* current generation, so parallel tasks don't clobber the coordinator's
|
|
204
|
+
* own in-flight generation.
|
|
205
|
+
*/
|
|
206
|
+
pushSubGeneration(generation: Generation): Promise<void>;
|
|
207
|
+
/** Mark a dispatched sub-generation as completed with its final text. */
|
|
208
|
+
completeSubGeneration(id: string, text?: string): Promise<void>;
|
|
209
|
+
/** Mark a dispatched sub-generation as cancelled (e.g. barge-in). */
|
|
210
|
+
cancelSubGeneration(id: string): Promise<void>;
|
|
134
211
|
/** The live in-memory transcript. */
|
|
135
212
|
transcript(): TranscriptEntry[];
|
|
136
213
|
private cancelCurrentGeneration;
|
|
214
|
+
private buildRealtime;
|
|
137
215
|
private emitState;
|
|
138
216
|
}
|
|
217
|
+
export {};
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import type { Agent } from "../agents/agent.js";
|
|
2
2
|
import type { Persistence } from "../persistence/persistence.js";
|
|
3
|
+
import type { STT } from "../providers/stt/types.js";
|
|
4
|
+
import type { TTS } from "../providers/tts/types.js";
|
|
3
5
|
import type { ConversationId } from "./types.js";
|
|
4
6
|
import type { TranscriptEntry } from "./transcription/transcription.js";
|
|
5
7
|
import { Conversation } from "./conversation/conversation.js";
|
|
6
8
|
export interface CreateConversationOptions {
|
|
7
9
|
agents?: Agent[];
|
|
8
10
|
}
|
|
11
|
+
export interface ConversationsOptions {
|
|
12
|
+
persistence: Persistence;
|
|
13
|
+
/** Passed to conversations so `start()` can attach realtime processing. */
|
|
14
|
+
stt?: STT;
|
|
15
|
+
tts?: TTS;
|
|
16
|
+
}
|
|
9
17
|
/**
|
|
10
18
|
* The conversations API surface of a Pipeflow instance: create persistent
|
|
11
19
|
* conversations and retrieve their transcripts.
|
|
12
20
|
*/
|
|
13
21
|
export declare class Conversations {
|
|
14
22
|
private readonly persistence;
|
|
15
|
-
|
|
23
|
+
private readonly stt;
|
|
24
|
+
private readonly tts;
|
|
25
|
+
constructor(options: ConversationsOptions);
|
|
16
26
|
/** Create a persistent conversation. Realtime execution is separate. */
|
|
17
27
|
create(options?: CreateConversationOptions): Promise<Conversation>;
|
|
18
28
|
/** Retrieve the persisted transcript of a conversation. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AudioChunk, ConversationId, ConversationState, ConversationStatus, Generation, GenerationStatus, Participant, ParticipantInput, ToolCall, ToolCallResult, Turn, TurnId, UserId, } from "./types.js";
|
|
1
|
+
export type { AudioChunk, ConversationId, ConversationState, ConversationStatus, Generation, GenerationStatus, GenerationTiming, Participant, ParticipantInput, ToolCall, ToolCallResult, Turn, TurnId, UserId, } from "./types.js";
|
|
2
2
|
export { createConversationState } from "./types.js";
|
|
3
3
|
export { Conversation } from "./conversation/index.js";
|
|
4
4
|
export type { ConversationEvents, ConversationOptions, } from "./conversation/index.js";
|
|
@@ -6,5 +6,6 @@ export { Conversations } from "./conversations.js";
|
|
|
6
6
|
export type { CreateConversationOptions } from "./conversations.js";
|
|
7
7
|
export { Orchestrator } from "./orchestration/orchestrator/index.js";
|
|
8
8
|
export type { OrchestratorOptions } from "./orchestration/orchestrator/index.js";
|
|
9
|
+
export { ConversationStream } from "./stream/index.js";
|
|
9
10
|
export { Transcription, TranscriptEntry } from "./transcription/index.js";
|
|
10
11
|
export type { TranscriptEntryInput, TranscriptSpeakerKind, } from "./transcription/index.js";
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { Agent } from "../../../agents/agent.js";
|
|
2
|
+
import type { LLM, LLMMessage, LLMToolDefinition } from "../../../providers/llm/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* One task delegated to an agent: a self-contained prompt for a roster member.
|
|
5
|
+
*/
|
|
6
|
+
export interface DelegatedTask {
|
|
7
|
+
agent: string;
|
|
8
|
+
prompt: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The outcome of a delegated agent run (or sub-coordination, via `error`).
|
|
12
|
+
*/
|
|
13
|
+
export interface DelegationResult {
|
|
14
|
+
agent: string;
|
|
15
|
+
text: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
/** What a coordination's LLM may decide to do next. */
|
|
19
|
+
export type DelegateAction = {
|
|
20
|
+
action: "agents";
|
|
21
|
+
tasks: DelegatedTask[];
|
|
22
|
+
} | {
|
|
23
|
+
action: "coordination";
|
|
24
|
+
coordination: string;
|
|
25
|
+
input?: unknown;
|
|
26
|
+
} | {
|
|
27
|
+
action: "clarify";
|
|
28
|
+
missing: string[];
|
|
29
|
+
} | {
|
|
30
|
+
action: "user";
|
|
31
|
+
question: string;
|
|
32
|
+
} | {
|
|
33
|
+
action: "complete";
|
|
34
|
+
output: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The runtime a coordination reasons against: the roster, every registered
|
|
38
|
+
* coordination, and the primitives for delegating work. Supplied by the
|
|
39
|
+
* orchestrator, so coordinations never couple to it directly.
|
|
40
|
+
*/
|
|
41
|
+
export interface CoordinationRuntime {
|
|
42
|
+
readonly agents: readonly Agent[];
|
|
43
|
+
readonly coordinations: readonly Coordination[];
|
|
44
|
+
/** Shared LLM used for coordination reasoning. */
|
|
45
|
+
readonly llm: LLM;
|
|
46
|
+
/** Shared conversation history, seeded into fresh runs. */
|
|
47
|
+
readonly history: readonly LLMMessage[];
|
|
48
|
+
/** Run one or more agents in parallel (text-only) and return their outputs. */
|
|
49
|
+
delegateAgentTasks(tasks: DelegatedTask[]): Promise<DelegationResult[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Ask the user a question. Never returns: it throws `CoordinationSuspension`
|
|
52
|
+
* carrying the innermost frame, which the orchestrator catches to park the
|
|
53
|
+
* execution until the user answers.
|
|
54
|
+
*/
|
|
55
|
+
askUser(frame: PendingFrame, question: string): Promise<never>;
|
|
56
|
+
/** Stream a delta to speech (TTS narration). */
|
|
57
|
+
onDelta(delta: string): void;
|
|
58
|
+
/** Flush pending narration (e.g. before delegating or suspending). */
|
|
59
|
+
flushSpeech(): void;
|
|
60
|
+
/** Speak a standalone sentence (e.g. a `complete` output). */
|
|
61
|
+
speak(sentence: string): void;
|
|
62
|
+
/** True once an interrupt/stop has cancelled this run. */
|
|
63
|
+
isCancelled(): boolean;
|
|
64
|
+
/** Throw if the run exceeded the coordination step budget. */
|
|
65
|
+
checkBudget(): void;
|
|
66
|
+
}
|
|
67
|
+
export interface CoordinationOptions {
|
|
68
|
+
name: string;
|
|
69
|
+
/** System prompt describing the coordination's reasoning role. */
|
|
70
|
+
prompt?: string;
|
|
71
|
+
/** Overrides the runtime's shared LLM for this coordination. */
|
|
72
|
+
llm?: LLM;
|
|
73
|
+
maxTokens?: number;
|
|
74
|
+
/** Hard wall-clock limit for a single run (including suspensions). */
|
|
75
|
+
maxDurationMs?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Deterministic cap on user-question rounds per run (both the structured
|
|
78
|
+
* `clarify` action and open-ended `user` questions, across suspensions).
|
|
79
|
+
* Once exhausted, the coordination is told to state reasonable
|
|
80
|
+
* assumptions and complete. Defaults to 2.
|
|
81
|
+
*/
|
|
82
|
+
maxQuestionRounds?: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A coordination registered in the orchestrator by name — the registry key
|
|
86
|
+
* is the coordination's name, so it is not repeated here.
|
|
87
|
+
*/
|
|
88
|
+
export type CoordinationRegistration = Omit<CoordinationOptions, "name">;
|
|
89
|
+
/**
|
|
90
|
+
* Render a batched clarification question from the missing details, so the
|
|
91
|
+
* wording is deterministic regardless of how the model phrases the labels.
|
|
92
|
+
*/
|
|
93
|
+
export declare function renderClarifyQuestion(missing: string[]): string;
|
|
94
|
+
/**
|
|
95
|
+
* The system prompt for a `clarify` coordination: a generic,
|
|
96
|
+
* domain-agnostic information-acquisition unit. It turns an underspecified
|
|
97
|
+
* request into a clear one by asking the user for missing details via the
|
|
98
|
+
* structured `clarify` action (batched), with a hard two-round cap enforced
|
|
99
|
+
* by the runtime. Register it alongside `understand`:
|
|
100
|
+
*
|
|
101
|
+
* ```ts
|
|
102
|
+
* coordinations: { clarify: { prompt: buildClarifyPrompt() } }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function buildClarifyPrompt(): string;
|
|
106
|
+
/**
|
|
107
|
+
* The resumable state of one coordination invocation. Plain data so it can be
|
|
108
|
+
* parked in a `PendingExecution` while waiting for the user.
|
|
109
|
+
*/
|
|
110
|
+
export interface CoordinationState {
|
|
111
|
+
messages: LLMMessage[];
|
|
112
|
+
startedAt: number;
|
|
113
|
+
/** Everything the coordination has spoken so far, for the final record. */
|
|
114
|
+
narration: string;
|
|
115
|
+
/** How many user-question rounds this run has used (across suspensions). */
|
|
116
|
+
questionRounds: number;
|
|
117
|
+
/** Tool call id awaiting a sub-coordination result, for resume replies. */
|
|
118
|
+
pendingToolCallId?: string;
|
|
119
|
+
}
|
|
120
|
+
/** One frame of a suspended execution stack (outermost first). */
|
|
121
|
+
export interface PendingFrame {
|
|
122
|
+
coordination: Coordination;
|
|
123
|
+
state: CoordinationState;
|
|
124
|
+
}
|
|
125
|
+
/** Thrown when a coordination asks the user; carries the whole frame stack. */
|
|
126
|
+
export declare class CoordinationSuspension extends Error {
|
|
127
|
+
readonly frames: PendingFrame[];
|
|
128
|
+
readonly question: string;
|
|
129
|
+
constructor(frames: PendingFrame[], question: string);
|
|
130
|
+
}
|
|
131
|
+
/** Thrown when a coordination run is cancelled (interrupt/stop). */
|
|
132
|
+
export declare class CoordinationCancelled extends Error {
|
|
133
|
+
constructor();
|
|
134
|
+
}
|
|
135
|
+
/** Thrown when a coordination exceeded its step or duration budget. */
|
|
136
|
+
export declare class CoordinationBudgetExceeded extends Error {
|
|
137
|
+
constructor(detail: string);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The tool definition that lets a coordination's LLM choose the next execution
|
|
141
|
+
* target: agents (one or more, in parallel), another coordination, the user,
|
|
142
|
+
* or completion.
|
|
143
|
+
*
|
|
144
|
+
* The parameters are deliberately FLAT (action enum + optional fields) even
|
|
145
|
+
* though the parser enforces a discriminated union per action. Why: Amazon
|
|
146
|
+
* Bedrock (nova) ignores `oneOf` in tool input schemas, which makes the tool
|
|
147
|
+
* effectively empty — the model stops calling it and answers directly instead
|
|
148
|
+
* (measured: 0/2 tool calls and ~5k-token essays vs reliable ~1s calls with
|
|
149
|
+
* the flat shape). The flat schema works across every provider tested; the
|
|
150
|
+
* discriminated contract is enforced when the call is parsed, and an invalid
|
|
151
|
+
* combination costs one bounded retry rather than a broken tool.
|
|
152
|
+
*/
|
|
153
|
+
export declare function delegateToolDefinition(agents: readonly Agent[], coordinations: readonly Coordination[]): LLMToolDefinition;
|
|
154
|
+
export declare function parseDelegateAction(argumentsJson: string, agents: readonly Agent[], coordinations: readonly Coordination[]): DelegateAction;
|
|
155
|
+
/**
|
|
156
|
+
* A hardcoded reasoning/control-flow unit. Unlike an `Agent` (input → LLM →
|
|
157
|
+
* output), a coordination decides *what should happen next*: run agents, pass
|
|
158
|
+
* work to another coordination, ask the user, or complete. Definitions are
|
|
159
|
+
* stateless; each invocation carries its own `CoordinationState`, which can be
|
|
160
|
+
* parked (suspended) while waiting for the user and resumed later.
|
|
161
|
+
*/
|
|
162
|
+
export declare class Coordination {
|
|
163
|
+
readonly name: string;
|
|
164
|
+
readonly prompt: string;
|
|
165
|
+
readonly maxTokens: number | undefined;
|
|
166
|
+
readonly maxDurationMs: number | undefined;
|
|
167
|
+
readonly maxQuestionRounds: number;
|
|
168
|
+
private readonly runtime;
|
|
169
|
+
private readonly llm;
|
|
170
|
+
private cachedToolDefinition;
|
|
171
|
+
private cachedSchema;
|
|
172
|
+
constructor(options: CoordinationOptions, runtime: CoordinationRuntime);
|
|
173
|
+
/** The delegate tool definition, generated once from the roster. */
|
|
174
|
+
private toolDefinition;
|
|
175
|
+
/** Parse a `delegate` tool call against the roster's strict schema. */
|
|
176
|
+
private parseDelegate;
|
|
177
|
+
/** Run the coordination with fresh state (seeded with the shared history). */
|
|
178
|
+
run(input?: unknown): Promise<unknown>;
|
|
179
|
+
/** Resume a suspended state with the user's answer. */
|
|
180
|
+
resume(state: CoordinationState, answer: string): Promise<unknown>;
|
|
181
|
+
/** Continue a suspended state with an injected message (e.g. a sub-result). */
|
|
182
|
+
continueWith(state: CoordinationState, message: LLMMessage): Promise<unknown>;
|
|
183
|
+
/**
|
|
184
|
+
* The coordination loop: one LLM round trip per iteration, choosing the next
|
|
185
|
+
* execution target via the `delegate` tool. Throws `CoordinationSuspension`
|
|
186
|
+
* when asking the user; the state carried in the suspension is resumable.
|
|
187
|
+
*/
|
|
188
|
+
private loop;
|
|
189
|
+
/** Delegate to a sub-coordination, attaching this frame on suspension. */
|
|
190
|
+
private delegateToCoordination;
|
|
191
|
+
private completeOutput;
|
|
192
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { Coordination, CoordinationSuspension, CoordinationCancelled, CoordinationBudgetExceeded, delegateToolDefinition, parseDelegateAction, } from "./coordination.js";
|
|
2
|
+
export type { CoordinationOptions, CoordinationRuntime, CoordinationState, DelegateAction, DelegatedTask, DelegationResult, PendingFrame, } from "./coordination.js";
|