@falai/agent 3.4.4 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -34
- package/dist/cjs/core/Agent.d.ts +22 -378
- package/dist/cjs/core/Agent.d.ts.map +1 -1
- package/dist/cjs/core/Agent.js +104 -1178
- package/dist/cjs/core/Agent.js.map +1 -1
- package/dist/cjs/core/CompactionEngine.d.ts.map +1 -1
- package/dist/cjs/core/CompactionEngine.js +5 -3
- package/dist/cjs/core/CompactionEngine.js.map +1 -1
- package/dist/cjs/core/FlowSpec.d.ts +136 -0
- package/dist/cjs/core/FlowSpec.d.ts.map +1 -0
- package/dist/cjs/core/FlowSpec.js +522 -0
- package/dist/cjs/core/FlowSpec.js.map +1 -0
- package/dist/cjs/core/Migrate.d.ts +38 -0
- package/dist/cjs/core/Migrate.d.ts.map +1 -0
- package/dist/cjs/core/Migrate.js +270 -0
- package/dist/cjs/core/Migrate.js.map +1 -0
- package/dist/cjs/core/Prompt.d.ts +54 -0
- package/dist/cjs/core/Prompt.d.ts.map +1 -0
- package/dist/cjs/core/Prompt.js +143 -0
- package/dist/cjs/core/Prompt.js.map +1 -0
- package/dist/cjs/core/Runner.d.ts +160 -0
- package/dist/cjs/core/Runner.d.ts.map +1 -0
- package/dist/cjs/core/Runner.js +1131 -0
- package/dist/cjs/core/Runner.js.map +1 -0
- package/dist/cjs/core/Speak.d.ts +37 -0
- package/dist/cjs/core/Speak.d.ts.map +1 -0
- package/dist/cjs/core/Speak.js +364 -0
- package/dist/cjs/core/Speak.js.map +1 -0
- package/dist/cjs/core/Understand.d.ts +28 -0
- package/dist/cjs/core/Understand.d.ts.map +1 -0
- package/dist/cjs/core/Understand.js +353 -0
- package/dist/cjs/core/Understand.js.map +1 -0
- package/dist/cjs/core/contracts.d.ts +122 -0
- package/dist/cjs/core/contracts.d.ts.map +1 -0
- package/dist/cjs/core/contracts.js +11 -0
- package/dist/cjs/core/contracts.js.map +1 -0
- package/dist/cjs/core/falai.d.ts +57 -0
- package/dist/cjs/core/falai.d.ts.map +1 -0
- package/dist/cjs/core/falai.js +43 -0
- package/dist/cjs/core/falai.js.map +1 -0
- package/dist/cjs/core/predicate.d.ts +9 -0
- package/dist/cjs/core/predicate.d.ts.map +1 -0
- package/dist/cjs/core/predicate.js +58 -0
- package/dist/cjs/core/predicate.js.map +1 -0
- package/dist/cjs/index.d.ts +26 -31
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +46 -68
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/persistence/MemoryStore.d.ts +15 -0
- package/dist/cjs/persistence/MemoryStore.d.ts.map +1 -0
- package/dist/cjs/persistence/MemoryStore.js +39 -0
- package/dist/cjs/persistence/MemoryStore.js.map +1 -0
- package/dist/cjs/persistence/MongoStore.d.ts +42 -0
- package/dist/cjs/persistence/MongoStore.d.ts.map +1 -0
- package/dist/cjs/persistence/MongoStore.js +60 -0
- package/dist/cjs/persistence/MongoStore.js.map +1 -0
- package/dist/cjs/persistence/OpenSearchStore.d.ts +86 -0
- package/dist/cjs/persistence/OpenSearchStore.d.ts.map +1 -0
- package/dist/cjs/persistence/OpenSearchStore.js +120 -0
- package/dist/cjs/persistence/OpenSearchStore.js.map +1 -0
- package/dist/cjs/persistence/PostgresStore.d.ts +41 -0
- package/dist/cjs/persistence/PostgresStore.d.ts.map +1 -0
- package/dist/cjs/persistence/PostgresStore.js +58 -0
- package/dist/cjs/persistence/PostgresStore.js.map +1 -0
- package/dist/cjs/persistence/PrismaStore.d.ts +65 -0
- package/dist/cjs/persistence/PrismaStore.d.ts.map +1 -0
- package/dist/cjs/persistence/PrismaStore.js +95 -0
- package/dist/cjs/persistence/PrismaStore.js.map +1 -0
- package/dist/cjs/persistence/RedisStore.d.ts +34 -0
- package/dist/cjs/persistence/RedisStore.d.ts.map +1 -0
- package/dist/cjs/persistence/RedisStore.js +61 -0
- package/dist/cjs/persistence/RedisStore.js.map +1 -0
- package/dist/cjs/persistence/SQLiteStore.d.ts +45 -0
- package/dist/cjs/persistence/SQLiteStore.d.ts.map +1 -0
- package/dist/cjs/persistence/SQLiteStore.js +74 -0
- package/dist/cjs/persistence/SQLiteStore.js.map +1 -0
- package/dist/cjs/persistence/sessionRow.d.ts +14 -0
- package/dist/cjs/persistence/sessionRow.d.ts.map +1 -0
- package/dist/cjs/persistence/sessionRow.js +50 -0
- package/dist/cjs/persistence/sessionRow.js.map +1 -0
- package/dist/cjs/providers/DeepSeekProvider.d.ts.map +1 -1
- package/dist/cjs/providers/DeepSeekProvider.js +8 -3
- package/dist/cjs/providers/DeepSeekProvider.js.map +1 -1
- package/dist/cjs/providers/GeminiProvider.d.ts +4 -3
- package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/cjs/providers/GeminiProvider.js +4 -3
- package/dist/cjs/providers/GeminiProvider.js.map +1 -1
- package/dist/cjs/providers/OpenAICompatibleProvider.d.ts +4 -0
- package/dist/cjs/providers/OpenAICompatibleProvider.d.ts.map +1 -1
- package/dist/cjs/providers/OpenAICompatibleProvider.js +2 -0
- package/dist/cjs/providers/OpenAICompatibleProvider.js.map +1 -1
- package/dist/cjs/providers/OpenRouterProvider.d.ts.map +1 -1
- package/dist/cjs/providers/OpenRouterProvider.js +2 -4
- package/dist/cjs/providers/OpenRouterProvider.js.map +1 -1
- package/dist/cjs/providers/ProviderAdapter.d.ts +1 -1
- package/dist/cjs/providers/ProviderAdapter.d.ts.map +1 -1
- package/dist/cjs/providers/ProviderAdapter.js +33 -10
- package/dist/cjs/providers/ProviderAdapter.js.map +1 -1
- package/dist/cjs/types/agent.d.ts +153 -383
- package/dist/cjs/types/agent.d.ts.map +1 -1
- package/dist/cjs/types/agent.js +1 -1
- package/dist/cjs/types/ai.d.ts +32 -1
- package/dist/cjs/types/ai.d.ts.map +1 -1
- package/dist/cjs/types/compaction.d.ts +3 -1
- package/dist/cjs/types/compaction.d.ts.map +1 -1
- package/dist/cjs/types/errors.d.ts +9 -12
- package/dist/cjs/types/errors.d.ts.map +1 -1
- package/dist/cjs/types/errors.js +14 -17
- package/dist/cjs/types/errors.js.map +1 -1
- package/dist/cjs/types/flow.d.ts +265 -513
- package/dist/cjs/types/flow.d.ts.map +1 -1
- package/dist/cjs/types/flow.js +7 -1
- package/dist/cjs/types/flow.js.map +1 -1
- package/dist/cjs/types/history.d.ts +7 -18
- package/dist/cjs/types/history.d.ts.map +1 -1
- package/dist/cjs/types/history.js.map +1 -1
- package/dist/cjs/types/index.d.ts +9 -15
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +4 -14
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/session.d.ts +94 -64
- package/dist/cjs/types/session.d.ts.map +1 -1
- package/dist/cjs/types/session.js +5 -1
- package/dist/cjs/types/session.js.map +1 -1
- package/dist/cjs/types/tool.d.ts +37 -207
- package/dist/cjs/types/tool.d.ts.map +1 -1
- package/dist/cjs/types/tool.js +5 -14
- package/dist/cjs/types/tool.js.map +1 -1
- package/dist/cjs/utils/clock.d.ts +28 -0
- package/dist/cjs/utils/clock.d.ts.map +1 -0
- package/dist/cjs/utils/clock.js +64 -0
- package/dist/cjs/utils/clock.js.map +1 -0
- package/dist/cjs/utils/duration.d.ts +11 -0
- package/dist/cjs/utils/duration.d.ts.map +1 -0
- package/dist/cjs/utils/duration.js +31 -0
- package/dist/cjs/utils/duration.js.map +1 -0
- package/dist/cjs/utils/history.d.ts +4 -1
- package/dist/cjs/utils/history.d.ts.map +1 -1
- package/dist/cjs/utils/history.js +2 -2
- package/dist/cjs/utils/history.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +4 -10
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +14 -61
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/json.d.ts +2 -0
- package/dist/cjs/utils/json.d.ts.map +1 -1
- package/dist/cjs/utils/json.js +5 -0
- package/dist/cjs/utils/json.js.map +1 -1
- package/dist/cjs/utils/outcomes.d.ts +48 -0
- package/dist/cjs/utils/outcomes.d.ts.map +1 -0
- package/dist/cjs/utils/outcomes.js +51 -0
- package/dist/cjs/utils/outcomes.js.map +1 -0
- package/dist/cjs/utils/schema.d.ts +50 -0
- package/dist/cjs/utils/schema.d.ts.map +1 -0
- package/dist/cjs/utils/schema.js +138 -0
- package/dist/cjs/utils/schema.js.map +1 -0
- package/dist/cjs/utils/streamingMessage.d.ts +3 -2
- package/dist/cjs/utils/streamingMessage.d.ts.map +1 -1
- package/dist/cjs/utils/streamingMessage.js +38 -4
- package/dist/cjs/utils/streamingMessage.js.map +1 -1
- package/dist/cjs/utils/template.d.ts +13 -149
- package/dist/cjs/utils/template.d.ts.map +1 -1
- package/dist/cjs/utils/template.js +31 -363
- package/dist/cjs/utils/template.js.map +1 -1
- package/dist/cjs/utils/usage.d.ts +19 -0
- package/dist/cjs/utils/usage.d.ts.map +1 -0
- package/dist/cjs/utils/usage.js +35 -0
- package/dist/cjs/utils/usage.js.map +1 -0
- package/dist/core/Agent.d.ts +22 -378
- package/dist/core/Agent.d.ts.map +1 -1
- package/dist/core/Agent.js +107 -1181
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/CompactionEngine.d.ts.map +1 -1
- package/dist/core/CompactionEngine.js +5 -3
- package/dist/core/CompactionEngine.js.map +1 -1
- package/dist/core/FlowSpec.d.ts +136 -0
- package/dist/core/FlowSpec.d.ts.map +1 -0
- package/dist/core/FlowSpec.js +516 -0
- package/dist/core/FlowSpec.js.map +1 -0
- package/dist/core/Migrate.d.ts +38 -0
- package/dist/core/Migrate.d.ts.map +1 -0
- package/dist/core/Migrate.js +264 -0
- package/dist/core/Migrate.js.map +1 -0
- package/dist/core/Prompt.d.ts +54 -0
- package/dist/core/Prompt.d.ts.map +1 -0
- package/dist/core/Prompt.js +133 -0
- package/dist/core/Prompt.js.map +1 -0
- package/dist/core/Runner.d.ts +160 -0
- package/dist/core/Runner.d.ts.map +1 -0
- package/dist/core/Runner.js +1127 -0
- package/dist/core/Runner.js.map +1 -0
- package/dist/core/Speak.d.ts +37 -0
- package/dist/core/Speak.d.ts.map +1 -0
- package/dist/core/Speak.js +360 -0
- package/dist/core/Speak.js.map +1 -0
- package/dist/core/Understand.d.ts +28 -0
- package/dist/core/Understand.d.ts.map +1 -0
- package/dist/core/Understand.js +349 -0
- package/dist/core/Understand.js.map +1 -0
- package/dist/core/contracts.d.ts +122 -0
- package/dist/core/contracts.d.ts.map +1 -0
- package/dist/core/contracts.js +10 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/core/falai.d.ts +57 -0
- package/dist/core/falai.d.ts.map +1 -0
- package/dist/core/falai.js +40 -0
- package/dist/core/falai.js.map +1 -0
- package/dist/core/predicate.d.ts +9 -0
- package/dist/core/predicate.d.ts.map +1 -0
- package/dist/core/predicate.js +54 -0
- package/dist/core/predicate.js.map +1 -0
- package/dist/index.d.ts +26 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -24
- package/dist/index.js.map +1 -1
- package/dist/persistence/MemoryStore.d.ts +15 -0
- package/dist/persistence/MemoryStore.d.ts.map +1 -0
- package/dist/persistence/MemoryStore.js +35 -0
- package/dist/persistence/MemoryStore.js.map +1 -0
- package/dist/persistence/MongoStore.d.ts +42 -0
- package/dist/persistence/MongoStore.d.ts.map +1 -0
- package/dist/persistence/MongoStore.js +56 -0
- package/dist/persistence/MongoStore.js.map +1 -0
- package/dist/persistence/OpenSearchStore.d.ts +86 -0
- package/dist/persistence/OpenSearchStore.d.ts.map +1 -0
- package/dist/persistence/OpenSearchStore.js +116 -0
- package/dist/persistence/OpenSearchStore.js.map +1 -0
- package/dist/persistence/PostgresStore.d.ts +41 -0
- package/dist/persistence/PostgresStore.d.ts.map +1 -0
- package/dist/persistence/PostgresStore.js +54 -0
- package/dist/persistence/PostgresStore.js.map +1 -0
- package/dist/persistence/PrismaStore.d.ts +65 -0
- package/dist/persistence/PrismaStore.d.ts.map +1 -0
- package/dist/persistence/PrismaStore.js +91 -0
- package/dist/persistence/PrismaStore.js.map +1 -0
- package/dist/persistence/RedisStore.d.ts +34 -0
- package/dist/persistence/RedisStore.d.ts.map +1 -0
- package/dist/persistence/RedisStore.js +57 -0
- package/dist/persistence/RedisStore.js.map +1 -0
- package/dist/persistence/SQLiteStore.d.ts +45 -0
- package/dist/persistence/SQLiteStore.d.ts.map +1 -0
- package/dist/persistence/SQLiteStore.js +70 -0
- package/dist/persistence/SQLiteStore.js.map +1 -0
- package/dist/persistence/sessionRow.d.ts +14 -0
- package/dist/persistence/sessionRow.d.ts.map +1 -0
- package/dist/persistence/sessionRow.js +45 -0
- package/dist/persistence/sessionRow.js.map +1 -0
- package/dist/providers/DeepSeekProvider.d.ts.map +1 -1
- package/dist/providers/DeepSeekProvider.js +8 -3
- package/dist/providers/DeepSeekProvider.js.map +1 -1
- package/dist/providers/GeminiProvider.d.ts +4 -3
- package/dist/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/GeminiProvider.js +4 -3
- package/dist/providers/GeminiProvider.js.map +1 -1
- package/dist/providers/OpenAICompatibleProvider.d.ts +4 -0
- package/dist/providers/OpenAICompatibleProvider.d.ts.map +1 -1
- package/dist/providers/OpenAICompatibleProvider.js +2 -0
- package/dist/providers/OpenAICompatibleProvider.js.map +1 -1
- package/dist/providers/OpenRouterProvider.d.ts.map +1 -1
- package/dist/providers/OpenRouterProvider.js +2 -4
- package/dist/providers/OpenRouterProvider.js.map +1 -1
- package/dist/providers/ProviderAdapter.d.ts +1 -1
- package/dist/providers/ProviderAdapter.d.ts.map +1 -1
- package/dist/providers/ProviderAdapter.js +34 -11
- package/dist/providers/ProviderAdapter.js.map +1 -1
- package/dist/types/agent.d.ts +153 -383
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +1 -1
- package/dist/types/ai.d.ts +32 -1
- package/dist/types/ai.d.ts.map +1 -1
- package/dist/types/compaction.d.ts +3 -1
- package/dist/types/compaction.d.ts.map +1 -1
- package/dist/types/errors.d.ts +9 -12
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +12 -15
- package/dist/types/errors.js.map +1 -1
- package/dist/types/flow.d.ts +265 -513
- package/dist/types/flow.d.ts.map +1 -1
- package/dist/types/flow.js +7 -1
- package/dist/types/flow.js.map +1 -1
- package/dist/types/history.d.ts +7 -18
- package/dist/types/history.d.ts.map +1 -1
- package/dist/types/history.js.map +1 -1
- package/dist/types/index.d.ts +9 -15
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -7
- package/dist/types/index.js.map +1 -1
- package/dist/types/session.d.ts +94 -64
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/session.js +5 -1
- package/dist/types/session.js.map +1 -1
- package/dist/types/tool.d.ts +37 -207
- package/dist/types/tool.d.ts.map +1 -1
- package/dist/types/tool.js +6 -13
- package/dist/types/tool.js.map +1 -1
- package/dist/utils/clock.d.ts +28 -0
- package/dist/utils/clock.d.ts.map +1 -0
- package/dist/utils/clock.js +59 -0
- package/dist/utils/clock.js.map +1 -0
- package/dist/utils/duration.d.ts +11 -0
- package/dist/utils/duration.d.ts.map +1 -0
- package/dist/utils/duration.js +26 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/history.d.ts +4 -1
- package/dist/utils/history.d.ts.map +1 -1
- package/dist/utils/history.js +2 -2
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/index.d.ts +4 -10
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -21
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/json.js +4 -0
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/outcomes.d.ts +48 -0
- package/dist/utils/outcomes.d.ts.map +1 -0
- package/dist/utils/outcomes.js +48 -0
- package/dist/utils/outcomes.js.map +1 -0
- package/dist/utils/schema.d.ts +50 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +129 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/streamingMessage.d.ts +3 -2
- package/dist/utils/streamingMessage.d.ts.map +1 -1
- package/dist/utils/streamingMessage.js +38 -4
- package/dist/utils/streamingMessage.js.map +1 -1
- package/dist/utils/template.d.ts +13 -149
- package/dist/utils/template.d.ts.map +1 -1
- package/dist/utils/template.js +28 -355
- package/dist/utils/template.js.map +1 -1
- package/dist/utils/usage.d.ts +19 -0
- package/dist/utils/usage.d.ts.map +1 -0
- package/dist/utils/usage.js +31 -0
- package/dist/utils/usage.js.map +1 -0
- package/docs/README.md +37 -19
- package/docs/concepts/architecture.md +117 -239
- package/docs/concepts/collection.md +170 -0
- package/docs/concepts/pipeline.md +132 -378
- package/docs/concepts/runs-and-waits.md +192 -0
- package/docs/guides/actions-and-events.md +276 -0
- package/docs/guides/branching.md +119 -208
- package/docs/guides/compaction.md +63 -158
- package/docs/guides/conditions.md +164 -128
- package/docs/guides/error-handling.md +168 -164
- package/docs/guides/flow-control.md +210 -349
- package/docs/guides/flows-from-json.md +224 -0
- package/docs/guides/instructions.md +125 -161
- package/docs/guides/persistence.md +182 -206
- package/docs/guides/streaming.md +50 -114
- package/docs/guides/testing.md +284 -0
- package/docs/guides/triggers.md +401 -0
- package/docs/migration/README.md +8 -15
- package/docs/migration/v1-to-v2.md +1 -1
- package/docs/migration/v2-3-to-v2-4.md +2 -2
- package/docs/migration/v2-6-to-v2-7.md +4 -4
- package/docs/migration/v3-to-v4.md +452 -0
- package/docs/reference/actions-events-conditions.md +396 -0
- package/docs/reference/agent.md +244 -0
- package/docs/reference/branches.md +75 -203
- package/docs/reference/errors.md +188 -144
- package/docs/reference/fields.md +125 -0
- package/docs/reference/flow-spec.md +248 -0
- package/docs/reference/flow.md +104 -192
- package/docs/reference/instruction.md +83 -137
- package/docs/reference/outcomes.md +273 -0
- package/docs/reference/providers.md +525 -302
- package/docs/reference/session.md +210 -0
- package/docs/reference/step.md +194 -312
- package/docs/reference/stores.md +496 -0
- package/docs/reference/tool.md +162 -231
- package/docs/reference/trigger.md +180 -0
- package/docs/rfc/v4-one-flow.md +477 -0
- package/docs/start/01-install.md +59 -44
- package/docs/start/02-first-agent.md +97 -147
- package/docs/start/03-collect-data.md +78 -183
- package/docs/start/04-add-tools.md +159 -227
- package/docs/start/05-go-to-production.md +167 -164
- package/examples/01-quickstart.ts +26 -16
- package/examples/02-fields.ts +75 -0
- package/examples/03-tools.ts +79 -119
- package/examples/04-instructions.ts +60 -87
- package/examples/05-branches.ts +78 -0
- package/examples/06-triggers-and-waits.ts +148 -0
- package/examples/07-streaming.ts +34 -60
- package/examples/08-store-and-migration.ts +97 -0
- package/examples/09-flows-from-json.ts +107 -0
- package/package.json +9 -6
- package/src/core/Agent.ts +116 -1512
- package/src/core/CompactionEngine.ts +7 -4
- package/src/core/FlowSpec.ts +712 -0
- package/src/core/Migrate.ts +256 -0
- package/src/core/Prompt.ts +156 -0
- package/src/core/Runner.ts +1181 -0
- package/src/core/Speak.ts +451 -0
- package/src/core/Understand.ts +422 -0
- package/src/core/contracts.ts +111 -0
- package/src/core/falai.ts +86 -0
- package/src/core/predicate.ts +56 -0
- package/src/index.ts +119 -147
- package/src/persistence/MemoryStore.ts +37 -0
- package/src/persistence/MongoStore.ts +89 -0
- package/src/persistence/OpenSearchStore.ts +153 -0
- package/src/persistence/PostgresStore.ts +89 -0
- package/src/persistence/PrismaStore.ts +127 -0
- package/src/persistence/RedisStore.ts +90 -0
- package/src/persistence/SQLiteStore.ts +103 -0
- package/src/persistence/sessionRow.ts +45 -0
- package/src/providers/DeepSeekProvider.ts +8 -3
- package/src/providers/GeminiProvider.ts +4 -3
- package/src/providers/OpenAICompatibleProvider.ts +6 -0
- package/src/providers/OpenRouterProvider.ts +2 -4
- package/src/providers/ProviderAdapter.ts +36 -8
- package/src/types/agent.ts +124 -397
- package/src/types/ai.ts +33 -1
- package/src/types/compaction.ts +3 -1
- package/src/types/errors.ts +13 -16
- package/src/types/flow.ts +249 -550
- package/src/types/history.ts +7 -20
- package/src/types/index.ts +87 -139
- package/src/types/session.ts +135 -70
- package/src/types/tool.ts +42 -267
- package/src/utils/clock.ts +70 -0
- package/src/utils/duration.ts +33 -0
- package/src/utils/history.ts +3 -2
- package/src/utils/index.ts +8 -66
- package/src/utils/json.ts +5 -0
- package/src/utils/outcomes.ts +56 -0
- package/src/utils/schema.ts +145 -0
- package/src/utils/streamingMessage.ts +34 -4
- package/src/utils/template.ts +32 -423
- package/src/utils/usage.ts +37 -0
- package/dist/adapters/MemoryAdapter.d.ts +0 -47
- package/dist/adapters/MemoryAdapter.d.ts.map +0 -1
- package/dist/adapters/MemoryAdapter.js +0 -204
- package/dist/adapters/MemoryAdapter.js.map +0 -1
- package/dist/adapters/MongoAdapter.d.ts +0 -97
- package/dist/adapters/MongoAdapter.d.ts.map +0 -1
- package/dist/adapters/MongoAdapter.js +0 -196
- package/dist/adapters/MongoAdapter.js.map +0 -1
- package/dist/adapters/OpenSearchAdapter.d.ts +0 -169
- package/dist/adapters/OpenSearchAdapter.d.ts.map +0 -1
- package/dist/adapters/OpenSearchAdapter.js +0 -471
- package/dist/adapters/OpenSearchAdapter.js.map +0 -1
- package/dist/adapters/PostgreSQLAdapter.d.ts +0 -85
- package/dist/adapters/PostgreSQLAdapter.d.ts.map +0 -1
- package/dist/adapters/PostgreSQLAdapter.js +0 -308
- package/dist/adapters/PostgreSQLAdapter.js.map +0 -1
- package/dist/adapters/PrismaAdapter.d.ts +0 -115
- package/dist/adapters/PrismaAdapter.d.ts.map +0 -1
- package/dist/adapters/PrismaAdapter.js +0 -406
- package/dist/adapters/PrismaAdapter.js.map +0 -1
- package/dist/adapters/RedisAdapter.d.ts +0 -72
- package/dist/adapters/RedisAdapter.d.ts.map +0 -1
- package/dist/adapters/RedisAdapter.js +0 -286
- package/dist/adapters/RedisAdapter.js.map +0 -1
- package/dist/adapters/SQLiteAdapter.d.ts +0 -86
- package/dist/adapters/SQLiteAdapter.d.ts.map +0 -1
- package/dist/adapters/SQLiteAdapter.js +0 -337
- package/dist/adapters/SQLiteAdapter.js.map +0 -1
- package/dist/adapters/index.d.ts +0 -17
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js +0 -11
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/sessionRow.d.ts +0 -22
- package/dist/adapters/sessionRow.d.ts.map +0 -1
- package/dist/adapters/sessionRow.js +0 -48
- package/dist/adapters/sessionRow.js.map +0 -1
- package/dist/cjs/adapters/MemoryAdapter.d.ts +0 -47
- package/dist/cjs/adapters/MemoryAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/MemoryAdapter.js +0 -208
- package/dist/cjs/adapters/MemoryAdapter.js.map +0 -1
- package/dist/cjs/adapters/MongoAdapter.d.ts +0 -97
- package/dist/cjs/adapters/MongoAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/MongoAdapter.js +0 -200
- package/dist/cjs/adapters/MongoAdapter.js.map +0 -1
- package/dist/cjs/adapters/OpenSearchAdapter.d.ts +0 -169
- package/dist/cjs/adapters/OpenSearchAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/OpenSearchAdapter.js +0 -475
- package/dist/cjs/adapters/OpenSearchAdapter.js.map +0 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts +0 -85
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.js +0 -312
- package/dist/cjs/adapters/PostgreSQLAdapter.js.map +0 -1
- package/dist/cjs/adapters/PrismaAdapter.d.ts +0 -115
- package/dist/cjs/adapters/PrismaAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/PrismaAdapter.js +0 -410
- package/dist/cjs/adapters/PrismaAdapter.js.map +0 -1
- package/dist/cjs/adapters/RedisAdapter.d.ts +0 -72
- package/dist/cjs/adapters/RedisAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/RedisAdapter.js +0 -290
- package/dist/cjs/adapters/RedisAdapter.js.map +0 -1
- package/dist/cjs/adapters/SQLiteAdapter.d.ts +0 -86
- package/dist/cjs/adapters/SQLiteAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/SQLiteAdapter.js +0 -341
- package/dist/cjs/adapters/SQLiteAdapter.js.map +0 -1
- package/dist/cjs/adapters/index.d.ts +0 -17
- package/dist/cjs/adapters/index.d.ts.map +0 -1
- package/dist/cjs/adapters/index.js +0 -21
- package/dist/cjs/adapters/index.js.map +0 -1
- package/dist/cjs/adapters/sessionRow.d.ts +0 -22
- package/dist/cjs/adapters/sessionRow.d.ts.map +0 -1
- package/dist/cjs/adapters/sessionRow.js +0 -52
- package/dist/cjs/adapters/sessionRow.js.map +0 -1
- package/dist/cjs/constants/index.d.ts +0 -1
- package/dist/cjs/constants/index.d.ts.map +0 -1
- package/dist/cjs/constants/index.js +0 -4
- package/dist/cjs/constants/index.js.map +0 -1
- package/dist/cjs/core/AutoChainExecutor.d.ts +0 -97
- package/dist/cjs/core/AutoChainExecutor.d.ts.map +0 -1
- package/dist/cjs/core/AutoChainExecutor.js +0 -288
- package/dist/cjs/core/AutoChainExecutor.js.map +0 -1
- package/dist/cjs/core/BranchEvaluator.d.ts +0 -55
- package/dist/cjs/core/BranchEvaluator.d.ts.map +0 -1
- package/dist/cjs/core/BranchEvaluator.js +0 -125
- package/dist/cjs/core/BranchEvaluator.js.map +0 -1
- package/dist/cjs/core/DirectiveChainTracker.d.ts +0 -49
- package/dist/cjs/core/DirectiveChainTracker.d.ts.map +0 -1
- package/dist/cjs/core/DirectiveChainTracker.js +0 -121
- package/dist/cjs/core/DirectiveChainTracker.js.map +0 -1
- package/dist/cjs/core/Events.d.ts +0 -26
- package/dist/cjs/core/Events.d.ts.map +0 -1
- package/dist/cjs/core/Events.js +0 -144
- package/dist/cjs/core/Events.js.map +0 -1
- package/dist/cjs/core/Flow.d.ts +0 -183
- package/dist/cjs/core/Flow.d.ts.map +0 -1
- package/dist/cjs/core/Flow.js +0 -551
- package/dist/cjs/core/Flow.js.map +0 -1
- package/dist/cjs/core/FlowRouter.d.ts +0 -183
- package/dist/cjs/core/FlowRouter.d.ts.map +0 -1
- package/dist/cjs/core/FlowRouter.js +0 -1047
- package/dist/cjs/core/FlowRouter.js.map +0 -1
- package/dist/cjs/core/PersistenceManager.d.ts +0 -114
- package/dist/cjs/core/PersistenceManager.d.ts.map +0 -1
- package/dist/cjs/core/PersistenceManager.js +0 -336
- package/dist/cjs/core/PersistenceManager.js.map +0 -1
- package/dist/cjs/core/PromptComposer.d.ts +0 -47
- package/dist/cjs/core/PromptComposer.d.ts.map +0 -1
- package/dist/cjs/core/PromptComposer.js +0 -397
- package/dist/cjs/core/PromptComposer.js.map +0 -1
- package/dist/cjs/core/PromptSectionCache.d.ts +0 -48
- package/dist/cjs/core/PromptSectionCache.d.ts.map +0 -1
- package/dist/cjs/core/PromptSectionCache.js +0 -108
- package/dist/cjs/core/PromptSectionCache.js.map +0 -1
- package/dist/cjs/core/ResponseEngine.d.ts +0 -43
- package/dist/cjs/core/ResponseEngine.d.ts.map +0 -1
- package/dist/cjs/core/ResponseEngine.js +0 -235
- package/dist/cjs/core/ResponseEngine.js.map +0 -1
- package/dist/cjs/core/ResponseGenerationError.d.ts +0 -30
- package/dist/cjs/core/ResponseGenerationError.d.ts.map +0 -1
- package/dist/cjs/core/ResponseGenerationError.js +0 -35
- package/dist/cjs/core/ResponseGenerationError.js.map +0 -1
- package/dist/cjs/core/ResponseModal.d.ts +0 -305
- package/dist/cjs/core/ResponseModal.d.ts.map +0 -1
- package/dist/cjs/core/ResponseModal.js +0 -1414
- package/dist/cjs/core/ResponseModal.js.map +0 -1
- package/dist/cjs/core/ResponsePipeline.d.ts +0 -220
- package/dist/cjs/core/ResponsePipeline.d.ts.map +0 -1
- package/dist/cjs/core/ResponsePipeline.js +0 -1040
- package/dist/cjs/core/ResponsePipeline.js.map +0 -1
- package/dist/cjs/core/SessionFinalizer.d.ts +0 -34
- package/dist/cjs/core/SessionFinalizer.d.ts.map +0 -1
- package/dist/cjs/core/SessionFinalizer.js +0 -88
- package/dist/cjs/core/SessionFinalizer.js.map +0 -1
- package/dist/cjs/core/SessionManager.d.ts +0 -112
- package/dist/cjs/core/SessionManager.d.ts.map +0 -1
- package/dist/cjs/core/SessionManager.js +0 -308
- package/dist/cjs/core/SessionManager.js.map +0 -1
- package/dist/cjs/core/SignalCoordinator.d.ts +0 -103
- package/dist/cjs/core/SignalCoordinator.d.ts.map +0 -1
- package/dist/cjs/core/SignalCoordinator.js +0 -207
- package/dist/cjs/core/SignalCoordinator.js.map +0 -1
- package/dist/cjs/core/SignalEvaluator.d.ts +0 -86
- package/dist/cjs/core/SignalEvaluator.d.ts.map +0 -1
- package/dist/cjs/core/SignalEvaluator.js +0 -319
- package/dist/cjs/core/SignalEvaluator.js.map +0 -1
- package/dist/cjs/core/SignalProcessor.d.ts +0 -152
- package/dist/cjs/core/SignalProcessor.d.ts.map +0 -1
- package/dist/cjs/core/SignalProcessor.js +0 -505
- package/dist/cjs/core/SignalProcessor.js.map +0 -1
- package/dist/cjs/core/Step.d.ts +0 -184
- package/dist/cjs/core/Step.d.ts.map +0 -1
- package/dist/cjs/core/Step.js +0 -599
- package/dist/cjs/core/Step.js.map +0 -1
- package/dist/cjs/core/StepLifecycle.d.ts +0 -43
- package/dist/cjs/core/StepLifecycle.d.ts.map +0 -1
- package/dist/cjs/core/StepLifecycle.js +0 -180
- package/dist/cjs/core/StepLifecycle.js.map +0 -1
- package/dist/cjs/core/StreamingToolExecutor.d.ts +0 -142
- package/dist/cjs/core/StreamingToolExecutor.d.ts.map +0 -1
- package/dist/cjs/core/StreamingToolExecutor.js +0 -490
- package/dist/cjs/core/StreamingToolExecutor.js.map +0 -1
- package/dist/cjs/core/ToolLoopExecutor.d.ts +0 -133
- package/dist/cjs/core/ToolLoopExecutor.d.ts.map +0 -1
- package/dist/cjs/core/ToolLoopExecutor.js +0 -568
- package/dist/cjs/core/ToolLoopExecutor.js.map +0 -1
- package/dist/cjs/core/ToolManager.d.ts +0 -250
- package/dist/cjs/core/ToolManager.d.ts.map +0 -1
- package/dist/cjs/core/ToolManager.js +0 -1104
- package/dist/cjs/core/ToolManager.js.map +0 -1
- package/dist/cjs/core/createAgent.d.ts +0 -35
- package/dist/cjs/core/createAgent.d.ts.map +0 -1
- package/dist/cjs/core/createAgent.js +0 -39
- package/dist/cjs/core/createAgent.js.map +0 -1
- package/dist/cjs/core/flow-namespace.d.ts +0 -64
- package/dist/cjs/core/flow-namespace.d.ts.map +0 -1
- package/dist/cjs/core/flow-namespace.js +0 -182
- package/dist/cjs/core/flow-namespace.js.map +0 -1
- package/dist/cjs/core/toolGates.d.ts +0 -24
- package/dist/cjs/core/toolGates.d.ts.map +0 -1
- package/dist/cjs/core/toolGates.js +0 -52
- package/dist/cjs/core/toolGates.js.map +0 -1
- package/dist/cjs/types/persistence.d.ts +0 -254
- package/dist/cjs/types/persistence.d.ts.map +0 -1
- package/dist/cjs/types/persistence.js +0 -7
- package/dist/cjs/types/persistence.js.map +0 -1
- package/dist/cjs/types/prompt-cache.d.ts +0 -15
- package/dist/cjs/types/prompt-cache.d.ts.map +0 -1
- package/dist/cjs/types/prompt-cache.js +0 -6
- package/dist/cjs/types/prompt-cache.js.map +0 -1
- package/dist/cjs/types/signals.d.ts +0 -263
- package/dist/cjs/types/signals.d.ts.map +0 -1
- package/dist/cjs/types/signals.js +0 -11
- package/dist/cjs/types/signals.js.map +0 -1
- package/dist/cjs/types/template.d.ts +0 -84
- package/dist/cjs/types/template.d.ts.map +0 -1
- package/dist/cjs/types/template.js +0 -3
- package/dist/cjs/types/template.js.map +0 -1
- package/dist/cjs/utils/condition.d.ts +0 -63
- package/dist/cjs/utils/condition.d.ts.map +0 -1
- package/dist/cjs/utils/condition.js +0 -239
- package/dist/cjs/utils/condition.js.map +0 -1
- package/dist/cjs/utils/event.d.ts +0 -6
- package/dist/cjs/utils/event.d.ts.map +0 -1
- package/dist/cjs/utils/event.js +0 -20
- package/dist/cjs/utils/event.js.map +0 -1
- package/dist/cjs/utils/id.d.ts +0 -33
- package/dist/cjs/utils/id.d.ts.map +0 -1
- package/dist/cjs/utils/id.js +0 -84
- package/dist/cjs/utils/id.js.map +0 -1
- package/dist/cjs/utils/serialize.d.ts +0 -36
- package/dist/cjs/utils/serialize.d.ts.map +0 -1
- package/dist/cjs/utils/serialize.js +0 -77
- package/dist/cjs/utils/serialize.js.map +0 -1
- package/dist/cjs/utils/session.d.ts +0 -124
- package/dist/cjs/utils/session.d.ts.map +0 -1
- package/dist/cjs/utils/session.js +0 -396
- package/dist/cjs/utils/session.js.map +0 -1
- package/dist/constants/index.d.ts +0 -2
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/constants/index.js +0 -4
- package/dist/constants/index.js.map +0 -1
- package/dist/core/AutoChainExecutor.d.ts +0 -97
- package/dist/core/AutoChainExecutor.d.ts.map +0 -1
- package/dist/core/AutoChainExecutor.js +0 -284
- package/dist/core/AutoChainExecutor.js.map +0 -1
- package/dist/core/BranchEvaluator.d.ts +0 -55
- package/dist/core/BranchEvaluator.d.ts.map +0 -1
- package/dist/core/BranchEvaluator.js +0 -121
- package/dist/core/BranchEvaluator.js.map +0 -1
- package/dist/core/DirectiveChainTracker.d.ts +0 -49
- package/dist/core/DirectiveChainTracker.d.ts.map +0 -1
- package/dist/core/DirectiveChainTracker.js +0 -117
- package/dist/core/DirectiveChainTracker.js.map +0 -1
- package/dist/core/Events.d.ts +0 -26
- package/dist/core/Events.d.ts.map +0 -1
- package/dist/core/Events.js +0 -137
- package/dist/core/Events.js.map +0 -1
- package/dist/core/Flow.d.ts +0 -183
- package/dist/core/Flow.d.ts.map +0 -1
- package/dist/core/Flow.js +0 -547
- package/dist/core/Flow.js.map +0 -1
- package/dist/core/FlowRouter.d.ts +0 -183
- package/dist/core/FlowRouter.d.ts.map +0 -1
- package/dist/core/FlowRouter.js +0 -1043
- package/dist/core/FlowRouter.js.map +0 -1
- package/dist/core/PersistenceManager.d.ts +0 -114
- package/dist/core/PersistenceManager.d.ts.map +0 -1
- package/dist/core/PersistenceManager.js +0 -332
- package/dist/core/PersistenceManager.js.map +0 -1
- package/dist/core/PromptComposer.d.ts +0 -47
- package/dist/core/PromptComposer.d.ts.map +0 -1
- package/dist/core/PromptComposer.js +0 -393
- package/dist/core/PromptComposer.js.map +0 -1
- package/dist/core/PromptSectionCache.d.ts +0 -48
- package/dist/core/PromptSectionCache.d.ts.map +0 -1
- package/dist/core/PromptSectionCache.js +0 -104
- package/dist/core/PromptSectionCache.js.map +0 -1
- package/dist/core/ResponseEngine.d.ts +0 -43
- package/dist/core/ResponseEngine.d.ts.map +0 -1
- package/dist/core/ResponseEngine.js +0 -231
- package/dist/core/ResponseEngine.js.map +0 -1
- package/dist/core/ResponseGenerationError.d.ts +0 -30
- package/dist/core/ResponseGenerationError.d.ts.map +0 -1
- package/dist/core/ResponseGenerationError.js +0 -31
- package/dist/core/ResponseGenerationError.js.map +0 -1
- package/dist/core/ResponseModal.d.ts +0 -305
- package/dist/core/ResponseModal.d.ts.map +0 -1
- package/dist/core/ResponseModal.js +0 -1410
- package/dist/core/ResponseModal.js.map +0 -1
- package/dist/core/ResponsePipeline.d.ts +0 -220
- package/dist/core/ResponsePipeline.d.ts.map +0 -1
- package/dist/core/ResponsePipeline.js +0 -1035
- package/dist/core/ResponsePipeline.js.map +0 -1
- package/dist/core/SessionFinalizer.d.ts +0 -34
- package/dist/core/SessionFinalizer.d.ts.map +0 -1
- package/dist/core/SessionFinalizer.js +0 -84
- package/dist/core/SessionFinalizer.js.map +0 -1
- package/dist/core/SessionManager.d.ts +0 -112
- package/dist/core/SessionManager.d.ts.map +0 -1
- package/dist/core/SessionManager.js +0 -301
- package/dist/core/SessionManager.js.map +0 -1
- package/dist/core/SignalCoordinator.d.ts +0 -103
- package/dist/core/SignalCoordinator.d.ts.map +0 -1
- package/dist/core/SignalCoordinator.js +0 -203
- package/dist/core/SignalCoordinator.js.map +0 -1
- package/dist/core/SignalEvaluator.d.ts +0 -86
- package/dist/core/SignalEvaluator.d.ts.map +0 -1
- package/dist/core/SignalEvaluator.js +0 -312
- package/dist/core/SignalEvaluator.js.map +0 -1
- package/dist/core/SignalProcessor.d.ts +0 -152
- package/dist/core/SignalProcessor.d.ts.map +0 -1
- package/dist/core/SignalProcessor.js +0 -498
- package/dist/core/SignalProcessor.js.map +0 -1
- package/dist/core/Step.d.ts +0 -184
- package/dist/core/Step.d.ts.map +0 -1
- package/dist/core/Step.js +0 -594
- package/dist/core/Step.js.map +0 -1
- package/dist/core/StepLifecycle.d.ts +0 -43
- package/dist/core/StepLifecycle.d.ts.map +0 -1
- package/dist/core/StepLifecycle.js +0 -176
- package/dist/core/StepLifecycle.js.map +0 -1
- package/dist/core/StreamingToolExecutor.d.ts +0 -142
- package/dist/core/StreamingToolExecutor.d.ts.map +0 -1
- package/dist/core/StreamingToolExecutor.js +0 -483
- package/dist/core/StreamingToolExecutor.js.map +0 -1
- package/dist/core/ToolLoopExecutor.d.ts +0 -133
- package/dist/core/ToolLoopExecutor.d.ts.map +0 -1
- package/dist/core/ToolLoopExecutor.js +0 -564
- package/dist/core/ToolLoopExecutor.js.map +0 -1
- package/dist/core/ToolManager.d.ts +0 -250
- package/dist/core/ToolManager.d.ts.map +0 -1
- package/dist/core/ToolManager.js +0 -1098
- package/dist/core/ToolManager.js.map +0 -1
- package/dist/core/createAgent.d.ts +0 -35
- package/dist/core/createAgent.d.ts.map +0 -1
- package/dist/core/createAgent.js +0 -36
- package/dist/core/createAgent.js.map +0 -1
- package/dist/core/flow-namespace.d.ts +0 -64
- package/dist/core/flow-namespace.d.ts.map +0 -1
- package/dist/core/flow-namespace.js +0 -179
- package/dist/core/flow-namespace.js.map +0 -1
- package/dist/core/toolGates.d.ts +0 -24
- package/dist/core/toolGates.d.ts.map +0 -1
- package/dist/core/toolGates.js +0 -49
- package/dist/core/toolGates.js.map +0 -1
- package/dist/types/persistence.d.ts +0 -254
- package/dist/types/persistence.d.ts.map +0 -1
- package/dist/types/persistence.js +0 -6
- package/dist/types/persistence.js.map +0 -1
- package/dist/types/prompt-cache.d.ts +0 -15
- package/dist/types/prompt-cache.d.ts.map +0 -1
- package/dist/types/prompt-cache.js +0 -5
- package/dist/types/prompt-cache.js.map +0 -1
- package/dist/types/signals.d.ts +0 -263
- package/dist/types/signals.d.ts.map +0 -1
- package/dist/types/signals.js +0 -10
- package/dist/types/signals.js.map +0 -1
- package/dist/types/template.d.ts +0 -84
- package/dist/types/template.d.ts.map +0 -1
- package/dist/types/template.js +0 -2
- package/dist/types/template.js.map +0 -1
- package/dist/utils/condition.d.ts +0 -63
- package/dist/utils/condition.d.ts.map +0 -1
- package/dist/utils/condition.js +0 -230
- package/dist/utils/condition.js.map +0 -1
- package/dist/utils/event.d.ts +0 -6
- package/dist/utils/event.d.ts.map +0 -1
- package/dist/utils/event.js +0 -17
- package/dist/utils/event.js.map +0 -1
- package/dist/utils/id.d.ts +0 -33
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/id.js +0 -77
- package/dist/utils/id.js.map +0 -1
- package/dist/utils/serialize.d.ts +0 -36
- package/dist/utils/serialize.d.ts.map +0 -1
- package/dist/utils/serialize.js +0 -72
- package/dist/utils/serialize.js.map +0 -1
- package/dist/utils/session.d.ts +0 -124
- package/dist/utils/session.d.ts.map +0 -1
- package/dist/utils/session.js +0 -379
- package/dist/utils/session.js.map +0 -1
- package/docs/concepts/directives.md +0 -369
- package/docs/reference/adapters.md +0 -543
- package/docs/reference/create-agent.md +0 -216
- package/docs/reference/directive.md +0 -242
- package/docs/reference/signals.md +0 -368
- package/examples/02-data-extraction.ts +0 -90
- package/examples/05-branching.ts +0 -140
- package/examples/06-flow-control.ts +0 -103
- package/examples/08-persistence.ts +0 -98
- package/examples/09-signals.ts +0 -144
- package/src/adapters/MemoryAdapter.ts +0 -281
- package/src/adapters/MongoAdapter.ts +0 -341
- package/src/adapters/OpenSearchAdapter.ts +0 -693
- package/src/adapters/PostgreSQLAdapter.ts +0 -487
- package/src/adapters/PrismaAdapter.ts +0 -617
- package/src/adapters/RedisAdapter.ts +0 -439
- package/src/adapters/SQLiteAdapter.ts +0 -496
- package/src/adapters/index.ts +0 -43
- package/src/adapters/sessionRow.ts +0 -57
- package/src/constants/index.ts +0 -2
- package/src/core/AutoChainExecutor.ts +0 -397
- package/src/core/BranchEvaluator.ts +0 -161
- package/src/core/DirectiveChainTracker.ts +0 -144
- package/src/core/Events.ts +0 -164
- package/src/core/Flow.ts +0 -665
- package/src/core/FlowRouter.ts +0 -1540
- package/src/core/PersistenceManager.ts +0 -446
- package/src/core/PromptComposer.ts +0 -448
- package/src/core/PromptSectionCache.ts +0 -125
- package/src/core/ResponseEngine.ts +0 -338
- package/src/core/ResponseGenerationError.ts +0 -53
- package/src/core/ResponseModal.ts +0 -1902
- package/src/core/ResponsePipeline.ts +0 -1404
- package/src/core/SessionFinalizer.ts +0 -108
- package/src/core/SessionManager.ts +0 -372
- package/src/core/SignalCoordinator.ts +0 -263
- package/src/core/SignalEvaluator.ts +0 -404
- package/src/core/SignalProcessor.ts +0 -663
- package/src/core/Step.ts +0 -782
- package/src/core/StepLifecycle.ts +0 -242
- package/src/core/StreamingToolExecutor.ts +0 -609
- package/src/core/ToolLoopExecutor.ts +0 -749
- package/src/core/ToolManager.ts +0 -1379
- package/src/core/createAgent.ts +0 -40
- package/src/core/flow-namespace.ts +0 -227
- package/src/core/toolGates.ts +0 -72
- package/src/types/persistence.ts +0 -303
- package/src/types/prompt-cache.ts +0 -17
- package/src/types/signals.ts +0 -338
- package/src/types/template.ts +0 -98
- package/src/utils/condition.ts +0 -296
- package/src/utils/event.ts +0 -16
- package/src/utils/id.ts +0 -91
- package/src/utils/serialize.ts +0 -86
- package/src/utils/session.ts +0 -501
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Triggers"
|
|
3
|
+
description: "The five ways a run starts, what each costs, how if and repeat gate them, and how a message picks its flow."
|
|
4
|
+
type: guide
|
|
5
|
+
order: 1
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Triggers
|
|
9
|
+
|
|
10
|
+
A trigger says when a run of a flow starts. It lives in the flow's `on` list. There are four trigger kinds, and a flow with no `on` is started by the host.
|
|
11
|
+
|
|
12
|
+
| Trigger | A run starts when | Judged by |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| `{ message: [...] }` | the customer asks for this; the run takes the conversation | the model, in the turn's one understand call — the single judging call, see [The turn](../concepts/pipeline.md) |
|
|
15
|
+
| `{ mention: [...] }` | the customer brings this up; the run reacts beside the conversation | the model, in the same call |
|
|
16
|
+
| `{ silence: '24h' }` | the customer has been quiet this long since the assistant last spoke | code, from a wake |
|
|
17
|
+
| `{ event: 'reuniao_marcada' }` | the host reports the event with `turn({ event })` | code |
|
|
18
|
+
| no `on` | the host calls `turn({ start })`, or another flow chains here with `then: { flow }` | code |
|
|
19
|
+
|
|
20
|
+
The smallest flow has one message trigger:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
24
|
+
|
|
25
|
+
const f = falai().fields({
|
|
26
|
+
nome: { type: "string", ask: "Pergunte o nome da pessoa." },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const agent = f.agent({
|
|
30
|
+
name: "Ana",
|
|
31
|
+
// Set GEMINI_API_KEY in your environment before running this.
|
|
32
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
33
|
+
flows: [
|
|
34
|
+
f.flow({
|
|
35
|
+
id: "orcamento",
|
|
36
|
+
name: "Orçamento",
|
|
37
|
+
on: [{ message: ["pede um orçamento", "quer saber o preço"] }],
|
|
38
|
+
steps: [{ id: "quem", collect: ["nome"] }],
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const r = await agent.turn({ sessionId: "s1", message: "quanto custa?", id: "m1" });
|
|
44
|
+
console.log(r.started[0]?.runId); // "orcamento#m1"
|
|
45
|
+
console.log(r.messages[0]?.text); // the model asks for the name
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The customer wrote "quanto custa?", the model matched it to the flow, and a run started. Its id is `orcamento#m1`: the flow id, `#`, and the message id you passed. Pass the channel's message `id` on every message. The framework uses it to spot a replay (`code: 'duplicate-input'`, `changed: false`) and to mint the same keys when the host retries a turn.
|
|
49
|
+
|
|
50
|
+
## Message
|
|
51
|
+
|
|
52
|
+
`message` is a list of phrases that describe what the customer says. The model reads them, plus the flow's `name` and `description`, when it routes. It scores every candidate flow from 0 to 100; how the winner is picked is in [How a message picks its flow](#how-a-message-picks-its-flow) below.
|
|
53
|
+
|
|
54
|
+
A message run takes the conversation: its talk steps ask, and it holds the floor — the right to ask the next question, which only one run has at a time — until it ends or another flow wins the floor. By default it starts once per session (`repeat: 'once'`).
|
|
55
|
+
|
|
56
|
+
`message: []` is the catch-all. It is never scored. It starts when no other message flow wins and no run holds the floor. Its `if` and `repeat` still apply, and `repeat` still defaults to `'once'`: a catch-all that should pick up every new topic needs `repeat: 'always'`.
|
|
57
|
+
|
|
58
|
+
## Mention
|
|
59
|
+
|
|
60
|
+
A mention is something the customer brings up while talking about something else: they ask for a human, they name a competitor. The run starts beside the conversation and does not take it over.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
64
|
+
|
|
65
|
+
const f = falai().fields({
|
|
66
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const agent = f.agent({
|
|
70
|
+
name: "Ana",
|
|
71
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
72
|
+
actions: {
|
|
73
|
+
chamar_humano: f.action({ parameters: {}, run: () => ({ ok: true }) }),
|
|
74
|
+
avisar: f.action({
|
|
75
|
+
parameters: { texto: { type: "string" } },
|
|
76
|
+
run: (params) => {
|
|
77
|
+
console.log(params.texto);
|
|
78
|
+
return { ok: true };
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
82
|
+
flows: [
|
|
83
|
+
f.flow({
|
|
84
|
+
id: "triagem",
|
|
85
|
+
name: "Triagem",
|
|
86
|
+
on: [{ message: [] }],
|
|
87
|
+
steps: [{ id: "quem", collect: ["nome"] }],
|
|
88
|
+
}),
|
|
89
|
+
f.flow({
|
|
90
|
+
id: "pediu_humano",
|
|
91
|
+
name: "Pediu para falar com uma pessoa",
|
|
92
|
+
on: [{ mention: ["pede para falar com uma pessoa, um humano ou um atendente"] }],
|
|
93
|
+
steps: [
|
|
94
|
+
{ id: "s", say: "Claro. Já chamo alguém da equipe para continuar com você." },
|
|
95
|
+
{ id: "a", do: "chamar_humano" },
|
|
96
|
+
],
|
|
97
|
+
}),
|
|
98
|
+
f.flow({
|
|
99
|
+
id: "concorrente",
|
|
100
|
+
name: "Falou de concorrente",
|
|
101
|
+
on: [{ mention: ["cita ou compara com um concorrente"], extract: { trecho: { type: "string" } } }],
|
|
102
|
+
steps: [{ id: "avisa", do: "avisar", with: { texto: 'Falou de concorrente: "{{input.trecho}}"' } }],
|
|
103
|
+
}),
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const r = await agent.turn({ sessionId: "s1", message: "quero falar com uma pessoa", id: "m1" });
|
|
108
|
+
console.log(r.messages.map((m) => [m.kind, m.text])); // [["verbatim", "Claro. Já chamo alguém ..."]]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- The model answers "did the customer bring this up?" with true or false, in the same understand call that routes the message. The prompt tells it to be conservative: true needs clear evidence in the message.
|
|
112
|
+
- `extract` names values to pull from the message when the mention is true. They land in the run's `input`, so `{{input.trecho}}` works in `say`, `prompt` and `with`. They are never written to the collected data.
|
|
113
|
+
- A `say` step in a mention flow answers the customer this turn. The run that was asking does not speak (`code: 'another-reply'`) and asks again on the next message. `do` steps run in the same turn. The turn above costs one model call.
|
|
114
|
+
- A talk step in a mention flow takes the floor like any other talk step: the run that was asking is suspended and resumes when this one ends.
|
|
115
|
+
- Default `repeat: 'once'`: once the flow has run, it is left out of the understand call, so a second mention starts nothing and writes no line. A code-only `mention: []` detector is the exception: it goes through the start order on every message and logs `code: 'already-claimed'` in `skipped[]`.
|
|
116
|
+
|
|
117
|
+
`mention: []` with an `if` is a code-only detector. It costs no model call and is checked on every message:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { falai } from "@falai/agent";
|
|
121
|
+
|
|
122
|
+
interface Ctx {
|
|
123
|
+
lead: { tags: string[] };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const f = falai<Ctx>().fields({});
|
|
127
|
+
|
|
128
|
+
const aviso = f.flow({
|
|
129
|
+
id: "aviso",
|
|
130
|
+
name: "Aviso de humano",
|
|
131
|
+
on: [{ mention: [], if: ({ context }) => context.lead.tags.includes("pediu_humano") }],
|
|
132
|
+
steps: [{ id: "s", say: "Já chamo alguém da equipe." }],
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Silence
|
|
137
|
+
|
|
138
|
+
The customer stopped answering. A silence trigger fires when the assistant's last message has gone this long without a reply.
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
142
|
+
|
|
143
|
+
interface Ctx {
|
|
144
|
+
lead: { owner: "ai" | "human" };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const f = falai<Ctx>().fields({
|
|
148
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const retomar = f.flow({
|
|
152
|
+
id: "retomar",
|
|
153
|
+
name: "Retomar quem sumiu",
|
|
154
|
+
on: [{ silence: "24h", if: ({ context }) => context.lead.owner === "ai" }],
|
|
155
|
+
steps: [
|
|
156
|
+
{ id: "p1", prompt: "Retome a conversa de forma leve e pergunte se ainda faz sentido." },
|
|
157
|
+
{ id: "w1", wait: "2d", else: "end" },
|
|
158
|
+
{ id: "p2", prompt: "Última tentativa, curta e sem pressão." },
|
|
159
|
+
],
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const agent = f.agent({
|
|
163
|
+
name: "Ana",
|
|
164
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
165
|
+
flows: [
|
|
166
|
+
f.flow({ id: "triagem", name: "Triagem", on: [{ message: [] }], steps: [{ id: "quem", collect: ["nome"] }] }),
|
|
167
|
+
retomar,
|
|
168
|
+
],
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const context: Ctx = { lead: { owner: "ai" } };
|
|
172
|
+
const t1 = await agent.turn({ sessionId: "s1", context, message: "oi", id: "m1" });
|
|
173
|
+
console.log(t1.schedule); // [{ key: "silence:retomar:s1:<ms>", at: <24 hours after the assistant's reply> }]
|
|
174
|
+
|
|
175
|
+
// 24 hours later the host's queue fires the job. A real host reloads the session from its store first.
|
|
176
|
+
const t2 = await agent.turn({ sessionId: "s1", context, session: t1.session, wake: t1.schedule[0].key, history: [] });
|
|
177
|
+
console.log(t2.started.map((s) => s.flowId), t2.llmCalls); // ["retomar"], 1
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
How it works, in order:
|
|
181
|
+
|
|
182
|
+
1. The assistant speaks: a talk step, a `say`, or an action that returns `spoke: true`. The turn stamps `session.lastAssistantAt`.
|
|
183
|
+
2. For every silence flow whose `if` holds and whose `repeat` allows, the turn puts a wake in `schedule[]`: key `silence:<flowId>:<sessionId>:<lastAssistantAtMs>`, `at` = that time plus the duration. `replaces` names the previous silence key of the same flow so the host can drop the old job. Dropping it is best effort; a stale wake is harmless.
|
|
184
|
+
3. The host enqueues the wake with `jobId = key` and calls `turn({ wake: key })` when it fires.
|
|
185
|
+
4. The wake is honoured only while the session still shows that silence: the assistant's last message is still the same one and the customer has not written since. Otherwise the turn ends with `code: 'silence-broken'` and `changed: false`.
|
|
186
|
+
5. The run starts, takes the floor and speaks first. A talk step costs one model call; the prompt tells the model there is no new message from the customer.
|
|
187
|
+
|
|
188
|
+
The trigger's `if` is judged with fresh context twice: when the wake is armed and when it fires. The run's premise is re-checked on every later wake too: if the customer wrote since the run started, it ends with `code: 'customer-replied'`. That is why a follow-up flow parks with `wait: '2d', else: 'end'` between its messages: a reply ends the run cleanly.
|
|
189
|
+
|
|
190
|
+
With `businessHours: true`, the agent's `businessHours` function moves the wake forward to the next working hour (see [businessHours](#businesshours)). Default `repeat: 'once'`.
|
|
191
|
+
|
|
192
|
+
## Event
|
|
193
|
+
|
|
194
|
+
Something happened in your program: a deal moved stage, a meeting was booked, a comment landed on a post. Declare the event once, register it on the agent, and name it in the trigger.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
198
|
+
|
|
199
|
+
interface Ctx {
|
|
200
|
+
lead: { stageId: string };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const f = falai<Ctx>().fields({
|
|
204
|
+
urgencia: { type: "string", enum: ["agora", "30 dias", "sem prazo"], ask: "Pergunte para quando precisam resolver." },
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const agent = f.agent({
|
|
208
|
+
name: "Ana",
|
|
209
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
210
|
+
events: {
|
|
211
|
+
stage_entered: f.event<{ stageId: string }>(),
|
|
212
|
+
},
|
|
213
|
+
flows: [
|
|
214
|
+
f.flow({
|
|
215
|
+
id: "interesse",
|
|
216
|
+
name: "Entrou em negociação",
|
|
217
|
+
on: [{ event: "stage_entered", after: "1h", if: ({ context }) => context.lead.stageId === "negociacao" }],
|
|
218
|
+
steps: [{ id: "p", prompt: "Diga que viu o interesse avançar e pergunte para quando precisam.", collect: ["urgencia"] }],
|
|
219
|
+
}),
|
|
220
|
+
],
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const context: Ctx = { lead: { stageId: "negociacao" } };
|
|
224
|
+
const r = await agent.turn({ sessionId: "s1", context, event: "stage_entered", payload: { stageId: "negociacao" }, key: "stage:7" });
|
|
225
|
+
console.log(r.llmCalls); // 0
|
|
226
|
+
console.log(r.schedule[0]?.key); // "interesse#stage:7:start:<ms>", one hour from now
|
|
227
|
+
console.log(r.outcomes[0]?.code); // "awaiting-trigger"
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
- `turn({ event, payload, key })` publishes it. The payload becomes the run's `input`: `{{input.stageId}}` in templates, `ctx.input` in actions, `input` in the trigger's `if`. `input` is typed `unknown` there; narrow it before you read it.
|
|
231
|
+
- `after: '1h'` parks the new run before its first step. The wake key is `<runId>:start:<atMs>`; the outcome line reads `code: 'awaiting-trigger'`. If the same event arrives again for the same flow and anchor while the run is still parked there, the parked run is replaced (`ended[].reason: 'replaced'`). Any other live run makes the new one skip with `code: 'already-running'`.
|
|
232
|
+
- `businessHours: true` moves `after` forward to the next working hour.
|
|
233
|
+
- Default `repeat: 'always'`: every event with a new `key` starts a run. The same `key` twice is skipped with `code: 'already-claimed'`, so publishing an event again is safe.
|
|
234
|
+
- Zero model calls, unless the run reaches a talk step: then the assistant speaks first, one call.
|
|
235
|
+
- An event may carry a `direction`, which stamps the session as the customer or the assistant speaking. See [Actions and events](actions-and-events.md).
|
|
236
|
+
|
|
237
|
+
## Start
|
|
238
|
+
|
|
239
|
+
A flow with no `on` starts only when asked: by the host with `turn({ start })`, or by another flow with `then: { flow }`.
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
243
|
+
|
|
244
|
+
const f = falai().fields({});
|
|
245
|
+
|
|
246
|
+
const agent = f.agent({
|
|
247
|
+
name: "Ana",
|
|
248
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
249
|
+
flows: [
|
|
250
|
+
f.flow({
|
|
251
|
+
id: "boas-vindas",
|
|
252
|
+
name: "Boas-vindas",
|
|
253
|
+
steps: [{ id: "oi", say: "Oi, {{input.nome}}. Vi que você se cadastrou. Posso ajudar em algo?" }],
|
|
254
|
+
}),
|
|
255
|
+
],
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const r = await agent.turn({ sessionId: "s1", start: { flow: "boas-vindas", input: { nome: "Ana" }, key: "signup:456" } });
|
|
259
|
+
console.log(r.messages[0]?.text); // "Oi, Ana. Vi que você se cadastrou. Posso ajudar em algo?"
|
|
260
|
+
console.log(r.llmCalls); // 0
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
`input` becomes the run's `input`. `key` is yours; make it unique per start (`boas-vindas#signup:456` is the run id). Starts repeat by default (`'always'`); the same key twice is skipped. An unknown flow id lands in `skipped[]` with `code: 'flow-gone'`.
|
|
264
|
+
|
|
265
|
+
Chaining from another flow is in [Flow control](flow-control.md).
|
|
266
|
+
|
|
267
|
+
## `if` on a trigger
|
|
268
|
+
|
|
269
|
+
Every trigger takes an `if`: a code predicate the run must pass to start. It sees `context`, `data`, `input` (the event payload or the mention's extract), `silenced` and `now`. A failed `if` starts nothing and writes nothing to `skipped[]`.
|
|
270
|
+
|
|
271
|
+
```ts fragment
|
|
272
|
+
on: [{ event: 'stage_entered', after: '1h', if: ({ context }) => context.lead.stageId === 'negociacao' }]
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
The `if` also becomes the flow's default `while`: it is re-checked with fresh context every time the run is about to move, and the run ends with `code: 'premise-changed'` when it stops holding. Set `while` on the flow to check something else. Conditions in code or JSON, and where each is allowed: [Conditions](conditions.md).
|
|
276
|
+
|
|
277
|
+
## `repeat`
|
|
278
|
+
|
|
279
|
+
How often a trigger may start a run for one session. A flow with `anchor: 'lead'` counts per customer instead; see [One live run per flow and anchor](#one-live-run-per-flow-and-anchor).
|
|
280
|
+
|
|
281
|
+
| `repeat` | Meaning | Skip line |
|
|
282
|
+
|---|---|---|
|
|
283
|
+
| `'once'` | one run ever per flow and anchor | `code: 'already-claimed'` |
|
|
284
|
+
| `'always'` | every trigger key starts a new run | none; the same key twice is `code: 'already-claimed'` |
|
|
285
|
+
| `{ cooldown: '7d' }` | a new run only after this long since the last start | `code: 'cooldown'` |
|
|
286
|
+
|
|
287
|
+
Defaults: `'once'` for `message`, `mention` and `silence`; `'always'` for `event`, manual starts and chained flows.
|
|
288
|
+
|
|
289
|
+
Each start writes a claim in `session.claims` under `<flowId>:<anchor>:<nonce>`. The nonce is empty for `'once'` and cooldown and is the trigger key for `'always'`; the last 50 always-claims per flow and anchor are kept. A run that repeats usually needs `clearOnStart` to forget the fields the previous run collected; otherwise the steps that collect them are skipped as already known.
|
|
290
|
+
|
|
291
|
+
The host can extend the ledger across a customer's other sessions with `turn({ claims: { held, active } })`: `held` maps a dedupe key to when it was claimed, `active` lists `<flowId>:<anchor>` pairs live elsewhere.
|
|
292
|
+
|
|
293
|
+
## One live run per flow and anchor
|
|
294
|
+
|
|
295
|
+
Inside a session, a flow has at most one live run per anchor. A trigger that fires while one is live is skipped with `code: 'already-running'`. The one exception is a run still parked on its trigger's `after`, which the new one replaces.
|
|
296
|
+
|
|
297
|
+
`anchor` defaults to the session. A flow with `anchor: 'lead'` reads its key from `turn({ anchors: { lead: { key: 'lead:456' } } })`, so one run serves every conversation of that customer. More in [Runs and waits](../concepts/runs-and-waits.md).
|
|
298
|
+
|
|
299
|
+
## `businessHours`
|
|
300
|
+
|
|
301
|
+
Timers can wait for working hours. Give the agent a `businessHours` function and set `businessHours: true` where it should apply: a silence trigger, an event's `after`, a `wait` step.
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
305
|
+
|
|
306
|
+
const f = falai().fields({});
|
|
307
|
+
|
|
308
|
+
const agent = f.agent({
|
|
309
|
+
name: "Ana",
|
|
310
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
311
|
+
// 9h to 18h. Anything later moves to 9h the next day.
|
|
312
|
+
businessHours: (at) => {
|
|
313
|
+
const d = new Date(at);
|
|
314
|
+
if (d.getHours() >= 18) d.setHours(33, 0, 0, 0);
|
|
315
|
+
if (d.getHours() < 9) d.setHours(9, 0, 0, 0);
|
|
316
|
+
return d;
|
|
317
|
+
},
|
|
318
|
+
flows: [
|
|
319
|
+
f.flow({
|
|
320
|
+
id: "retomar",
|
|
321
|
+
name: "Retomar",
|
|
322
|
+
on: [{ silence: "24h", businessHours: true }],
|
|
323
|
+
steps: [
|
|
324
|
+
{ id: "p1", prompt: "Retome a conversa de forma leve." },
|
|
325
|
+
{ id: "w1", wait: "2d", businessHours: true, else: "end" },
|
|
326
|
+
],
|
|
327
|
+
}),
|
|
328
|
+
],
|
|
329
|
+
});
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
The function receives the computed time and `{ context }` and returns the time to use. Move it forward; never move it back.
|
|
333
|
+
|
|
334
|
+
## How a message picks its flow
|
|
335
|
+
|
|
336
|
+
Every message turn decides who speaks, in this order:
|
|
337
|
+
|
|
338
|
+
1. **Ingest first.** If the message ends a `wait` with `else` and the run goes on to another step, that run takes the floor and routing is skipped.
|
|
339
|
+
2. **Eligible flows.** Message flows with a non-empty list whose `if` holds and whose `repeat` allows, in the order you passed them to the agent.
|
|
340
|
+
3. **The run that is asking keeps priority.** When a run is asking, its flow is scored too. Another flow wins only when its score is at least 15 above the asking flow's and at least 40. Then a suspended run of that flow resumes, or a new run starts; the run that was asking is suspended and comes back when the winner ends.
|
|
341
|
+
4. **One candidate, no floor.** It starts without scoring. If nothing else needs the model this turn (no mention flows, no pending fields to extract), the turn spends no understand call.
|
|
342
|
+
5. **Several candidates, no floor.** The best score wins if it is at least 40. Otherwise the first `message: []` catch-all that passes `if` and `repeat` starts. Otherwise nobody takes the floor.
|
|
343
|
+
6. **Nobody has the floor.** The idle speaker answers.
|
|
344
|
+
|
|
345
|
+
Scores come from the understand call, 0 to 100 per candidate. The two thresholds, 40 and 15, are constants in `src/core/Runner.ts`.
|
|
346
|
+
|
|
347
|
+
Two flows the model has to tell apart:
|
|
348
|
+
|
|
349
|
+
```ts
|
|
350
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
351
|
+
|
|
352
|
+
const f = falai().fields({
|
|
353
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
const agent = f.agent({
|
|
357
|
+
name: "Ana",
|
|
358
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
359
|
+
idle: { prompt: "Responda pela empresa; não invente preços." },
|
|
360
|
+
flows: [
|
|
361
|
+
f.flow({
|
|
362
|
+
id: "triagem",
|
|
363
|
+
name: "Triagem",
|
|
364
|
+
description: "Quando alguém chega querendo saber se o produto serve para a empresa dele",
|
|
365
|
+
on: [{ message: ["quer saber como funciona", "pede um orçamento"] }],
|
|
366
|
+
steps: [{ id: "quem", collect: ["nome"] }],
|
|
367
|
+
}),
|
|
368
|
+
f.flow({
|
|
369
|
+
id: "suporte",
|
|
370
|
+
name: "Suporte",
|
|
371
|
+
description: "Quando um cliente atual tem um problema com o produto",
|
|
372
|
+
on: [{ message: ["já é cliente e algo não funciona", "pede ajuda com um erro"] }],
|
|
373
|
+
steps: [{ id: "p", prompt: "Peça detalhes do problema e diga que vai encaminhar." }],
|
|
374
|
+
}),
|
|
375
|
+
],
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
const r = await agent.turn({ sessionId: "s1", message: "oi, quero saber como funciona", id: "m1" });
|
|
379
|
+
console.log(r.started.map((s) => s.flowId)); // ["triagem"] when it scores at least 40; otherwise the idle speaker answers
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Write `description` for every message flow: it is the sentence the model reads to score it.
|
|
383
|
+
|
|
384
|
+
### The idle speaker
|
|
385
|
+
|
|
386
|
+
`idle` is the one speaker that is not a step. It answers a message when no run holds the floor and nothing else spoke this turn.
|
|
387
|
+
|
|
388
|
+
```ts fragment
|
|
389
|
+
idle: { prompt: 'Responda pela empresa; não invente preços.', tools: ['faq'], instructions: [] }
|
|
390
|
+
// or
|
|
391
|
+
idle: 'silent'
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
With no `idle` option the model still answers, with the agent's persona and no extra guideline. `'silent'` mutes it: zero calls, no message, but the input is still recorded. The idle message is keyed `idle:<messageId>` and its outcome line has `kind: 'idle'`.
|
|
395
|
+
|
|
396
|
+
## Read next
|
|
397
|
+
|
|
398
|
+
- [Conditions](conditions.md): `if` in code or JSON, `when` for the model.
|
|
399
|
+
- [Actions and events](actions-and-events.md): declaring events, `direction`, `wait: { event }`.
|
|
400
|
+
- [Runs and waits](../concepts/runs-and-waits.md): the floor, keys, claims and anchors.
|
|
401
|
+
- [Trigger reference](../reference/trigger.md): the type, field by field.
|
package/docs/migration/README.md
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Migration"
|
|
3
|
-
description: "
|
|
2
|
+
title: "Migration guides"
|
|
3
|
+
description: "One guide per upgrade of @falai/agent, newest first."
|
|
4
4
|
type: overview
|
|
5
5
|
order: 99
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
# Migration
|
|
8
|
+
# Migration guides
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
One guide per upgrade, newest first. Each has before and after code for every change.
|
|
11
11
|
|
|
12
|
-
[
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[Read the v2.3 → v2.4 migration guide](./v2-3-to-v2-4.md)
|
|
17
|
-
|
|
18
|
-
Upgrading from `1.x`? The consolidated migration guide covers every breaking change in v2 — including the Route → Flow rename, the Instruction unification, the Tool merge, and the Directive collapse — with rename tables, per-adapter schema migrations, and before/after code for each section.
|
|
19
|
-
|
|
20
|
-
[Read the v1 → v2 migration guide](./v1-to-v2.md)
|
|
21
|
-
|
|
22
|
-
Section 3 covers the Route → Flow rename in full, including per-adapter SQL/Mongo/Redis/OpenSearch migration snippets and ID-prefix guidance.
|
|
12
|
+
- [v3 → v4](./v3-to-v4.md) — A clean break: a 3.x program does not compile against 4.0. Every old name has a new shape; the guide shows the before and after for each.
|
|
13
|
+
- [v2.6 → v2.7](./v2-6-to-v2-7.md) — The `message` and `allowedFlows` turn parameters, provider `client` injection, the exported `restoreSession`, and the behaviour changes: a 400-message history bound, finalize before persist, soft-failing tools, session load failures that throw.
|
|
14
|
+
- [v2.3 → v2.4](./v2-3-to-v2-4.md) — Concurrency safety: optimistic session locking with `SessionConflictError`, a normalized `ProviderError`, required `AiProvider.capabilities`, `unknown` generic defaults.
|
|
15
|
+
- [v1 → v2](./v1-to-v2.md) — Route → Flow, one `Instruction` type, one `Tool` type, one `Directive` type, with rename tables and per-adapter schema migrations.
|
|
@@ -5,7 +5,7 @@ type: migration
|
|
|
5
5
|
order: 2
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
# v2.3 → v2.4
|
|
8
|
+
# v2.3 → v2.4 migration
|
|
9
9
|
|
|
10
10
|
**Version:** 2.4.0 — Architecture hardening (concurrency safety, consolidated provider layer, stricter types)
|
|
11
11
|
|
|
@@ -55,7 +55,7 @@ class MyProvider implements AiProvider {
|
|
|
55
55
|
}
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
If your provider wraps an OpenAI-compatible API (Groq, Together, Fireworks, …), consider subclassing the new exported [`OpenAICompatibleProvider`](../reference/providers.md#
|
|
58
|
+
If your provider wraps an OpenAI-compatible API (Groq, Together, Fireworks, …), consider subclassing the new exported [`OpenAICompatibleProvider`](../reference/providers.md#openaicompatibleprovider) base class instead of implementing `AiProvider` from scratch — it supplies message building, tool-call parsing, streaming, retries, backup models, and error normalization.
|
|
59
59
|
|
|
60
60
|
The capability values for the five built-in providers are documented in the [providers reference](../reference/providers.md#capabilities).
|
|
61
61
|
|
|
@@ -5,7 +5,7 @@ type: migration
|
|
|
5
5
|
order: 3
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
# v2.6 → v2.7
|
|
8
|
+
# v2.6 → v2.7 migration
|
|
9
9
|
|
|
10
10
|
**Version:** 2.7.0 — Consumer-fit release surface and correctness batch (tool directives end-to-end, hook desugaring, retry classification, error propagation)
|
|
11
11
|
|
|
@@ -135,7 +135,7 @@ Directives emitted by tools now reliably reach the engine (previously they could
|
|
|
135
135
|
- A `reply` directive short-circuits the remaining tool loop — its verbatim text becomes the final message with no follow-up LLM call.
|
|
136
136
|
- Control-flow fields queue on `session.pendingDirective` and steer the next turn (same deferred semantics as `agent.dispatch()`).
|
|
137
137
|
|
|
138
|
-
See [Tool
|
|
138
|
+
See [Tool reference](../reference/tool.md).
|
|
139
139
|
|
|
140
140
|
---
|
|
141
141
|
|
|
@@ -239,8 +239,8 @@ bun test tests/directive-wiring.test.ts # tool directives + finalize-before-pe
|
|
|
239
239
|
|
|
240
240
|
## Cross-References
|
|
241
241
|
|
|
242
|
-
- [
|
|
242
|
+
- [Agent reference](../reference/agent.md) — the page that replaced the `createAgent` reference
|
|
243
243
|
- [Providers reference](../reference/providers.md) — `client` option and retry classification
|
|
244
244
|
- [Errors reference](../reference/errors.md) — bare `ProviderError`, exported `ResponseGenerationError`
|
|
245
245
|
- [Tool reference](../reference/tool.md) — directive wiring and soft-fail semantics
|
|
246
|
-
- [
|
|
246
|
+
- [Stores reference](../reference/stores.md) — the page that replaced the adapters reference
|