@falai/agent 3.4.5 → 4.0.0-alpha.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 +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 +11 -6
- 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/providers/ZaiProvider.d.ts +6 -4
- package/dist/cjs/providers/ZaiProvider.d.ts.map +1 -1
- package/dist/cjs/providers/ZaiProvider.js +6 -4
- package/dist/cjs/providers/ZaiProvider.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 +11 -6
- 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/providers/ZaiProvider.d.ts +6 -4
- package/dist/providers/ZaiProvider.d.ts.map +1 -1
- package/dist/providers/ZaiProvider.js +6 -4
- package/dist/providers/ZaiProvider.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 +46 -13
- package/src/providers/ZaiProvider.ts +6 -4
- 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,496 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Stores"
|
|
3
|
+
description: "The seven Store classes: the client each takes, the table or collection it expects, and how each one checks the version on save."
|
|
4
|
+
type: reference
|
|
5
|
+
order: 11
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Stores
|
|
9
|
+
|
|
10
|
+
A store keeps session blobs. It has two methods, `load(id)` and `save(session, expectedVersion)`, and the package ships seven of them. You build the database client yourself and pass it in; the package imports no driver. The six drivers are optional peer dependencies (`pg ^8`, `@prisma/client ^6`, `ioredis ^5`, `mongodb ^6`, `better-sqlite3 ^11 || ^12`, `@opensearch-project/opensearch ^2`), and each store types its client as a small interface, so anything with the same methods fits.
|
|
11
|
+
|
|
12
|
+
## What every store does
|
|
13
|
+
|
|
14
|
+
All seven read and write the same row through `src/persistence/sessionRow.ts`:
|
|
15
|
+
|
|
16
|
+
- **Write.** The blob is the `Session` with `id`, `v: 4`, the new `version`, `data`, `runs`, `claims`, `inputs`, `metadata`, plus `lastUserAt`, `lastAssistantAt` and `history` only when set. A store's own `created_at` / `updated_at` columns are not part of the session.
|
|
17
|
+
- **Read.** Text is parsed as JSON, then the blob goes through `assertSession`. Anything that is not a v4 session throws `InvalidSessionError`; a corrupt row never comes back as a fresh conversation.
|
|
18
|
+
- **Version.** `save(session, 0)` inserts and fails when a row exists. `save(session, n)` updates only the row whose stored version is `n`. Either failure throws `SessionConflictError`. Success stores `n + 1` and returns the session with that number. The check and the write happen in one statement, script or conditional update, never as a read followed by a write.
|
|
19
|
+
- **`save` returns the blob it wrote**, not a re-read of the row.
|
|
20
|
+
|
|
21
|
+
| Class | Client type | Where the row lives (default) | Insert (version 0) | Update (version n) |
|
|
22
|
+
|-------|-------------|-------------------------------|--------------------|--------------------|
|
|
23
|
+
| `MemoryStore` | none | a `Map` in the process | key exists = conflict | version differs = conflict |
|
|
24
|
+
| `PostgresStore` | `PgClient` | table `agent_sessions` | `INSERT … ON CONFLICT (id) DO NOTHING`, no row back = conflict | `UPDATE … WHERE id = $1 AND version = $4`, no row back = conflict |
|
|
25
|
+
| `PrismaStore` | `PrismaClient` | model `agentSession` | `create`, Prisma `P2002` = conflict | `updateMany({ where: { id, version } })`, `count === 0` = conflict |
|
|
26
|
+
| `RedisStore` | `RedisClient` | hash `agent:session:<id>` | one Lua script | the same script |
|
|
27
|
+
| `MongoStore` | `MongoClient` | collection `agent_sessions` | `insertOne`, code `11000` = conflict | `updateOne({ _id, version })`, `matchedCount === 0` = conflict |
|
|
28
|
+
| `SQLiteStore` | `SqliteDatabase` | table `agent_sessions` | `INSERT OR IGNORE`, `changes === 0` = conflict | `UPDATE … WHERE id = ? AND version = ?`, `changes === 0` = conflict |
|
|
29
|
+
| `OpenSearchStore` | `OpenSearchClient` | index `agent_sessions` | `index` with `op_type: 'create'`, HTTP 409 = conflict | scripted `update`, `noop` = conflict |
|
|
30
|
+
|
|
31
|
+
## MemoryStore
|
|
32
|
+
|
|
33
|
+
For tests and prototypes. Everything is lost when the process stops. Rows are kept as JSON text and read back through the same check as every other store, so `Date` objects come back as text and `undefined` drops, exactly as they would through PostgreSQL.
|
|
34
|
+
|
|
35
|
+
### Signature
|
|
36
|
+
|
|
37
|
+
```ts fragment
|
|
38
|
+
class MemoryStore<D = unknown> implements Store<D> {
|
|
39
|
+
load(id: string): Promise<Session<D> | null>;
|
|
40
|
+
save(session: Session<D>, expectedVersion: number): Promise<Session<D>>;
|
|
41
|
+
/** Drop every session. */
|
|
42
|
+
clear(): void;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Example
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { MemoryStore } from "@falai/agent";
|
|
50
|
+
import type { Session } from "@falai/agent";
|
|
51
|
+
|
|
52
|
+
const store = new MemoryStore<{ nome: string }>();
|
|
53
|
+
console.log(await store.load("s1")); // null: nothing saved yet
|
|
54
|
+
|
|
55
|
+
const session: Session<{ nome: string }> = {
|
|
56
|
+
id: "s1", v: 4, version: 0, data: {}, runs: [], claims: {}, inputs: [], metadata: {},
|
|
57
|
+
};
|
|
58
|
+
const saved = await store.save(session, 0);
|
|
59
|
+
console.log(saved.version); // 1
|
|
60
|
+
|
|
61
|
+
store.clear();
|
|
62
|
+
console.log(await store.load("s1")); // null
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## PostgresStore
|
|
66
|
+
|
|
67
|
+
Over a `pg` `Client` or `Pool`. One row per session; the blob is JSONB, so PostgreSQL hands it back parsed.
|
|
68
|
+
|
|
69
|
+
### Signature
|
|
70
|
+
|
|
71
|
+
```ts fragment
|
|
72
|
+
interface PostgresStoreOptions {
|
|
73
|
+
client: PgClient;
|
|
74
|
+
/** Table name. Default `agent_sessions`. */
|
|
75
|
+
tables?: { sessions?: string };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Matches `pg`'s Client and Pool. */
|
|
79
|
+
interface PgClient {
|
|
80
|
+
query<T = Record<string, unknown>>(sql: string, values?: unknown[]): Promise<PgQueryResult<T>>;
|
|
81
|
+
end(): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface PgQueryResult<T = Record<string, unknown>> {
|
|
85
|
+
rows: T[];
|
|
86
|
+
rowCount?: number | null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
class PostgresStore<D = unknown> implements Store<D> {
|
|
90
|
+
constructor(options: PostgresStoreOptions);
|
|
91
|
+
/** Create the table when it is missing. */
|
|
92
|
+
initialize(): Promise<void>;
|
|
93
|
+
/** Calls `client.end()`. */
|
|
94
|
+
disconnect(): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### The table
|
|
99
|
+
|
|
100
|
+
`initialize()` runs this; run it yourself if you manage migrations:
|
|
101
|
+
|
|
102
|
+
```sql
|
|
103
|
+
CREATE TABLE IF NOT EXISTS agent_sessions (
|
|
104
|
+
id VARCHAR(255) PRIMARY KEY,
|
|
105
|
+
version INTEGER NOT NULL,
|
|
106
|
+
blob JSONB NOT NULL,
|
|
107
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
108
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
109
|
+
);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
A 3.x `agent_sessions` table has different columns. Point `tables.sessions` at a fresh table and move old rows through `migrateSession` at the place you deserialize them, not through this table.
|
|
113
|
+
|
|
114
|
+
### Behaviour
|
|
115
|
+
|
|
116
|
+
- Version 0: `INSERT INTO t (id, version, blob) VALUES ($1, $2, $3) ON CONFLICT (id) DO NOTHING RETURNING version`. No row back means a row already existed.
|
|
117
|
+
- Version n: `UPDATE t SET version = $2, blob = $3, updated_at = NOW() WHERE id = $1 AND version = $4 RETURNING version`. No row back means the stored version is not `n`, or the row is gone.
|
|
118
|
+
- On a conflict the store runs one more `SELECT version` to fill `SessionConflictError.actualVersion`.
|
|
119
|
+
|
|
120
|
+
### Example
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { PostgresStore } from "@falai/agent";
|
|
124
|
+
import type { PgClient } from "@falai/agent";
|
|
125
|
+
|
|
126
|
+
// const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
127
|
+
declare const pool: PgClient;
|
|
128
|
+
|
|
129
|
+
const store = new PostgresStore<{ nome: string }>({ client: pool });
|
|
130
|
+
await store.initialize();
|
|
131
|
+
|
|
132
|
+
const session = await store.load("s1"); // null on a first turn
|
|
133
|
+
console.log(session?.version ?? 0);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## PrismaStore
|
|
137
|
+
|
|
138
|
+
Over a generated Prisma client. The store looks up one model delegate by name (default `agentSession`) and needs `create`, `findUnique` and `updateMany` on it.
|
|
139
|
+
|
|
140
|
+
### Signature
|
|
141
|
+
|
|
142
|
+
```ts fragment
|
|
143
|
+
interface PrismaStoreOptions {
|
|
144
|
+
prisma: PrismaClient;
|
|
145
|
+
/** Model name on the client. Default `agentSession`. */
|
|
146
|
+
tables?: { sessions?: string };
|
|
147
|
+
/** Field names when the model uses other names. */
|
|
148
|
+
fieldMappings?: { sessions?: Partial<Record<PrismaSessionField, string>> };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
type PrismaSessionField = "id" | "version" | "blob" | "createdAt" | "updatedAt";
|
|
152
|
+
|
|
153
|
+
/** Matches a generated Prisma client: model delegates by name, plus `$disconnect`. */
|
|
154
|
+
interface PrismaClient {
|
|
155
|
+
[model: string]: unknown;
|
|
156
|
+
$disconnect?: () => Promise<void>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The delegate a generated client exposes per model. */
|
|
160
|
+
interface PrismaSessionModel {
|
|
161
|
+
create(params: { data: Record<string, unknown> }): Promise<Record<string, unknown>>;
|
|
162
|
+
findUnique(params: { where: Record<string, unknown> }): Promise<Record<string, unknown> | null>;
|
|
163
|
+
updateMany(params: { where: Record<string, unknown>; data: Record<string, unknown> }): Promise<{ count: number }>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
class PrismaStore<D = unknown> implements Store<D> {
|
|
167
|
+
constructor(options: PrismaStoreOptions);
|
|
168
|
+
/** Calls `prisma.$disconnect()` when it exists. */
|
|
169
|
+
disconnect(): Promise<void>;
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### The model
|
|
174
|
+
|
|
175
|
+
```prisma
|
|
176
|
+
model AgentSession {
|
|
177
|
+
id String @id
|
|
178
|
+
version Int
|
|
179
|
+
blob Json
|
|
180
|
+
createdAt DateTime @default(now())
|
|
181
|
+
updatedAt DateTime @updatedAt
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Prisma exposes this as `prisma.agentSession`. Other names go through `tables.sessions` (the delegate) and `fieldMappings.sessions` (the five fields). All five fields are required; 3.x tolerated a model without `version`, and that no longer works.
|
|
186
|
+
|
|
187
|
+
### Behaviour
|
|
188
|
+
|
|
189
|
+
- The constructor checks the delegate at once. A missing model throws a `TypeError`: `[TypeError] PrismaStore cannot use model "agentSession": the client has no such delegate with create, findUnique and updateMany. Add the model to schema.prisma and run prisma generate, or pass tables.sessions with its name.`
|
|
190
|
+
- Version 0: `create({ data: { id, version: 1, blob, createdAt, updatedAt } })`. Prisma's unique violation, error `code === "P2002"`, is the conflict. Any other error is rethrown.
|
|
191
|
+
- Version n: `updateMany({ where: { id, version: n }, data: { version: n + 1, blob, updatedAt } })`. `count === 0` is the conflict.
|
|
192
|
+
- The blob is stored as a JSON value (Prisma's `Json`), not as text.
|
|
193
|
+
|
|
194
|
+
### Example
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { PrismaStore } from "@falai/agent";
|
|
198
|
+
import type { PrismaClient } from "@falai/agent";
|
|
199
|
+
|
|
200
|
+
// const prisma = new PrismaClient(); // from @prisma/client
|
|
201
|
+
declare const prisma: PrismaClient;
|
|
202
|
+
|
|
203
|
+
const store = new PrismaStore<{ nome: string }>({
|
|
204
|
+
prisma,
|
|
205
|
+
tables: { sessions: "conversa" },
|
|
206
|
+
fieldMappings: { sessions: { blob: "estado", updatedAt: "atualizadoEm" } },
|
|
207
|
+
});
|
|
208
|
+
console.log(await store.load("s1")); // null on a first turn
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## RedisStore
|
|
212
|
+
|
|
213
|
+
Over an ioredis-shaped client. One hash per session with the fields `version`, `blob` (JSON text), `createdAt` and `updatedAt`.
|
|
214
|
+
|
|
215
|
+
### Signature
|
|
216
|
+
|
|
217
|
+
```ts fragment
|
|
218
|
+
interface RedisStoreOptions {
|
|
219
|
+
redis: RedisClient;
|
|
220
|
+
/** Prefix of every key. Default `agent:`. */
|
|
221
|
+
keyPrefix?: string;
|
|
222
|
+
/** Seconds a session lives after its last save; `0` keeps it forever. Default 7 days. */
|
|
223
|
+
sessionTTL?: number;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Matches ioredis. node-redis users wrap `eval` to this positional form. */
|
|
227
|
+
interface RedisClient {
|
|
228
|
+
hgetall(key: string): Promise<Record<string, string>>;
|
|
229
|
+
eval(script: string, numKeys: number, ...args: (string | number)[]): Promise<unknown>;
|
|
230
|
+
quit(): Promise<string>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
class RedisStore<D = unknown> implements Store<D> {
|
|
234
|
+
constructor(options: RedisStoreOptions);
|
|
235
|
+
/** Calls `redis.quit()`. */
|
|
236
|
+
disconnect(): Promise<void>;
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### The key
|
|
241
|
+
|
|
242
|
+
`${keyPrefix}session:${id}`, so `agent:session:s1` by default. Nothing to create ahead of time.
|
|
243
|
+
|
|
244
|
+
### Behaviour
|
|
245
|
+
|
|
246
|
+
The version check and the write are one Lua script, so two writers on a shared client cannot interleave between the read and the write:
|
|
247
|
+
|
|
248
|
+
```lua
|
|
249
|
+
local current = redis.call('HGET', KEYS[1], 'version')
|
|
250
|
+
if ARGV[1] == '0' then
|
|
251
|
+
if current then return current end
|
|
252
|
+
elseif current ~= ARGV[1] then
|
|
253
|
+
return current or 'missing'
|
|
254
|
+
end
|
|
255
|
+
redis.call('HSET', KEYS[1], 'version', ARGV[2], 'blob', ARGV[3], 'updatedAt', ARGV[4])
|
|
256
|
+
redis.call('HSETNX', KEYS[1], 'createdAt', ARGV[4])
|
|
257
|
+
if tonumber(ARGV[5]) > 0 then redis.call('EXPIRE', KEYS[1], ARGV[5]) end
|
|
258
|
+
return nil
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
`ARGV` is the expected version, the next version, the blob, now as ISO text and the TTL in seconds. `nil` back is success; a version back is the conflict (`actualVersion` is that number); `'missing'` means the hash is gone (`actualVersion` is `undefined`).
|
|
262
|
+
|
|
263
|
+
- `sessionTTL` defaults to `7 * 24 * 60 * 60` = 604800 seconds and is reset on every save. `0` never expires.
|
|
264
|
+
- `load` returns `null` when the hash has no fields.
|
|
265
|
+
|
|
266
|
+
### Example
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import { RedisStore } from "@falai/agent";
|
|
270
|
+
import type { RedisClient } from "@falai/agent";
|
|
271
|
+
|
|
272
|
+
// const redis = new Redis(process.env.REDIS_URL); // from ioredis
|
|
273
|
+
declare const redis: RedisClient;
|
|
274
|
+
|
|
275
|
+
const store = new RedisStore<{ nome: string }>({ redis, keyPrefix: "vendas:", sessionTTL: 30 * 24 * 60 * 60 });
|
|
276
|
+
console.log(await store.load("s1")); // reads hash vendas:session:s1
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## MongoStore
|
|
280
|
+
|
|
281
|
+
Over the official driver's client. One document per session: `_id` is the session id.
|
|
282
|
+
|
|
283
|
+
### Signature
|
|
284
|
+
|
|
285
|
+
```ts fragment
|
|
286
|
+
interface MongoStoreOptions {
|
|
287
|
+
client: MongoClient;
|
|
288
|
+
databaseName: string;
|
|
289
|
+
/** Collection name. Default `agent_sessions`. */
|
|
290
|
+
collections?: { sessions?: string };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
interface MongoClient {
|
|
294
|
+
db(name?: string): MongoDatabase;
|
|
295
|
+
close(): Promise<void>;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
interface MongoDatabase {
|
|
299
|
+
collection<T = Record<string, unknown>>(name: string): MongoCollection<T>;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Matches the mongodb driver's Collection. */
|
|
303
|
+
interface MongoCollection<T = Record<string, unknown>> {
|
|
304
|
+
insertOne(doc: T): Promise<unknown>;
|
|
305
|
+
findOne(filter: Record<string, unknown>): Promise<T | null>;
|
|
306
|
+
updateOne(filter: Record<string, unknown>, update: Record<string, unknown>): Promise<{ matchedCount: number }>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
class MongoStore<D = unknown> implements Store<D> {
|
|
310
|
+
constructor(options: MongoStoreOptions);
|
|
311
|
+
/** Calls `client.close()`. */
|
|
312
|
+
disconnect(): Promise<void>;
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### The document
|
|
317
|
+
|
|
318
|
+
```json
|
|
319
|
+
{ "_id": "s1", "version": 3, "blob": "{\"id\":\"s1\",\"v\":4,...}", "createdAt": ISODate, "updatedAt": ISODate }
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
`blob` is JSON text, not a sub-document, because claim keys carry channel message ids and those may contain dots, which older servers reject in field names. Nothing to create: `_id` is unique on its own.
|
|
323
|
+
|
|
324
|
+
### Behaviour
|
|
325
|
+
|
|
326
|
+
- Version 0: `insertOne({ _id, version: 1, blob, createdAt, updatedAt })`. The driver's duplicate key error, `code === 11000`, is the conflict. Any other error is rethrown.
|
|
327
|
+
- Version n: `updateOne({ _id, version: n }, { $set: { version: n + 1, blob, updatedAt } })`. `matchedCount === 0` is the conflict.
|
|
328
|
+
|
|
329
|
+
### Example
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
import { MongoStore } from "@falai/agent";
|
|
333
|
+
import type { MongoClient } from "@falai/agent";
|
|
334
|
+
|
|
335
|
+
// const client = new MongoClient(process.env.MONGO_URL); // from mongodb
|
|
336
|
+
declare const client: MongoClient;
|
|
337
|
+
|
|
338
|
+
const store = new MongoStore<{ nome: string }>({ client, databaseName: "vendas" });
|
|
339
|
+
console.log(await store.load("s1")); // null on a first turn
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## SQLiteStore
|
|
343
|
+
|
|
344
|
+
Over a better-sqlite3-shaped database; `bun:sqlite` fits the same interface. The blob is JSON text.
|
|
345
|
+
|
|
346
|
+
### Signature
|
|
347
|
+
|
|
348
|
+
```ts fragment
|
|
349
|
+
interface SQLiteStoreOptions {
|
|
350
|
+
db: SqliteDatabase;
|
|
351
|
+
/** Table name. Default `agent_sessions`. */
|
|
352
|
+
tables?: { sessions?: string };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** Matches better-sqlite3 and bun:sqlite databases. */
|
|
356
|
+
interface SqliteDatabase {
|
|
357
|
+
prepare(sql: string): SqliteStatement;
|
|
358
|
+
exec(sql: string): unknown;
|
|
359
|
+
close(): void;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
interface SqliteStatement {
|
|
363
|
+
run(...params: unknown[]): { changes: number };
|
|
364
|
+
get(...params: unknown[]): unknown;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
class SQLiteStore<D = unknown> implements Store<D> {
|
|
368
|
+
constructor(options: SQLiteStoreOptions);
|
|
369
|
+
/** Create the table when it is missing. */
|
|
370
|
+
initialize(): Promise<void>;
|
|
371
|
+
/** Calls `db.close()`. */
|
|
372
|
+
disconnect(): Promise<void>;
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### The table
|
|
377
|
+
|
|
378
|
+
```sql
|
|
379
|
+
CREATE TABLE IF NOT EXISTS agent_sessions (
|
|
380
|
+
id TEXT PRIMARY KEY,
|
|
381
|
+
version INTEGER NOT NULL,
|
|
382
|
+
blob TEXT NOT NULL,
|
|
383
|
+
created_at TEXT NOT NULL,
|
|
384
|
+
updated_at TEXT NOT NULL
|
|
385
|
+
);
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Same note as PostgreSQL: a 3.x table has other columns, so use a fresh table.
|
|
389
|
+
|
|
390
|
+
### Behaviour
|
|
391
|
+
|
|
392
|
+
- Version 0: `INSERT OR IGNORE INTO t (id, version, blob, created_at, updated_at) VALUES (?, ?, ?, ?, ?)`. `changes === 0` is the conflict.
|
|
393
|
+
- Version n: `UPDATE t SET version = ?, blob = ?, updated_at = ? WHERE id = ? AND version = ?`. `changes === 0` is the conflict.
|
|
394
|
+
- The driver is synchronous; the store wraps each call in a promise so a thrown error is a rejection like everywhere else.
|
|
395
|
+
|
|
396
|
+
### Example
|
|
397
|
+
|
|
398
|
+
```ts
|
|
399
|
+
import { SQLiteStore } from "@falai/agent";
|
|
400
|
+
import type { SqliteDatabase } from "@falai/agent";
|
|
401
|
+
|
|
402
|
+
// const db = new Database("sessions.db"); // from better-sqlite3 or bun:sqlite
|
|
403
|
+
declare const db: SqliteDatabase;
|
|
404
|
+
|
|
405
|
+
const store = new SQLiteStore<{ nome: string }>({ db });
|
|
406
|
+
await store.initialize();
|
|
407
|
+
console.log(await store.load("s1")); // null on a first turn
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## OpenSearchStore
|
|
411
|
+
|
|
412
|
+
Over `@opensearch-project/opensearch`'s client; Elasticsearch 7.x fits the same calls. One document per session, with `blob` stored but not indexed. The constructor takes the client first and the options second.
|
|
413
|
+
|
|
414
|
+
### Signature
|
|
415
|
+
|
|
416
|
+
```ts fragment
|
|
417
|
+
interface OpenSearchStoreOptions {
|
|
418
|
+
/** Index name. Default `agent_sessions`. */
|
|
419
|
+
indices?: { sessions?: string };
|
|
420
|
+
/** Create the index with its mappings on `initialize()`. Default true. */
|
|
421
|
+
autoCreateIndices?: boolean;
|
|
422
|
+
/** Refresh policy on writes: `true` at once, `false` in the background, `'wait_for'` blocks. Default false. */
|
|
423
|
+
refresh?: boolean | "wait_for";
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Matches `@opensearch-project/opensearch`'s Client. */
|
|
427
|
+
interface OpenSearchClient {
|
|
428
|
+
index(params: { index: string; id: string; body: Record<string, unknown>; op_type?: "index" | "create"; refresh?: boolean | "wait_for" }): Promise<{ body: { result: string } }>;
|
|
429
|
+
update(params: { index: string; id: string; body: Record<string, unknown>; retry_on_conflict?: number; refresh?: boolean | "wait_for" }): Promise<{ body: { result: string } }>;
|
|
430
|
+
get(params: { index: string; id: string }): Promise<{ body: { _source: Record<string, unknown> } }>;
|
|
431
|
+
indices: {
|
|
432
|
+
exists(params: { index: string }): Promise<{ body: boolean }>;
|
|
433
|
+
create(params: { index: string; body: { mappings?: Record<string, unknown> } }): Promise<{ body: { acknowledged: boolean } }>;
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
class OpenSearchStore<D = unknown> implements Store<D> {
|
|
438
|
+
constructor(client: OpenSearchClient, options?: OpenSearchStoreOptions);
|
|
439
|
+
/** Create the index with its mappings when it is missing and `autoCreateIndices` is on. */
|
|
440
|
+
initialize(): Promise<void>;
|
|
441
|
+
}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
There is no `disconnect()` on this store.
|
|
445
|
+
|
|
446
|
+
### The index
|
|
447
|
+
|
|
448
|
+
`initialize()` creates it with these mappings when it is missing:
|
|
449
|
+
|
|
450
|
+
```json
|
|
451
|
+
{
|
|
452
|
+
"mappings": {
|
|
453
|
+
"properties": {
|
|
454
|
+
"id": { "type": "keyword" },
|
|
455
|
+
"version": { "type": "integer" },
|
|
456
|
+
"blob": { "type": "object", "enabled": false },
|
|
457
|
+
"createdAt": { "type": "date" },
|
|
458
|
+
"updatedAt": { "type": "date" }
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
The document id is the session id; `blob` is the session object itself, stored and never indexed.
|
|
465
|
+
|
|
466
|
+
### Behaviour
|
|
467
|
+
|
|
468
|
+
- Version 0: `index({ id, op_type: 'create', body: { id, version: 1, blob, createdAt, updatedAt } })`. An HTTP 409 (`error.statusCode`) is the conflict. Any other error is rethrown.
|
|
469
|
+
- Version n: a Painless script `update` with `retry_on_conflict: 3` that compares `ctx._source.version` to `n` and sets `ctx.op = 'noop'` when they differ; otherwise it writes `version`, `blob` and `updatedAt`. A `noop` result, a 404 or a 409 is the conflict.
|
|
470
|
+
- `load` treats a 404 as `null`.
|
|
471
|
+
- `refresh` is passed on every write; it defaults to `false`.
|
|
472
|
+
|
|
473
|
+
### Example
|
|
474
|
+
|
|
475
|
+
```ts
|
|
476
|
+
import { OpenSearchStore } from "@falai/agent";
|
|
477
|
+
import type { OpenSearchClient } from "@falai/agent";
|
|
478
|
+
|
|
479
|
+
// const client = new Client({ node: process.env.OPENSEARCH_URL }); // from @opensearch-project/opensearch
|
|
480
|
+
declare const client: OpenSearchClient;
|
|
481
|
+
|
|
482
|
+
const store = new OpenSearchStore<{ nome: string }>(client, { indices: { sessions: "conversas" }, refresh: "wait_for" });
|
|
483
|
+
await store.initialize();
|
|
484
|
+
console.log(await store.load("s1")); // null on a first turn
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
## Writing your own
|
|
488
|
+
|
|
489
|
+
Implement `Store<D>`: `load` returns the session or `null`; `save` checks the version and writes in one atomic step, throws `SessionConflictError(sessionId, expectedVersion, actualVersion)` when the check fails, and returns the session stamped with `expectedVersion + 1`. Run the blob you read through `assertSession(blob, id)` so a bad row throws `InvalidSessionError` instead of starting a fresh conversation. The contract test in `tests/store-contract.test.ts` is the same for all seven; a new store should pass it too.
|
|
490
|
+
|
|
491
|
+
## See also
|
|
492
|
+
|
|
493
|
+
- [Session](./session.md): what the blob holds and who writes each field.
|
|
494
|
+
- [Persistence](../guides/persistence.md): the host loop, `migrateSession` for 3.x rows, and picking a store.
|
|
495
|
+
- [Go to production](../start/05-go-to-production.md): from `MemoryStore` to `PostgresStore` step by step.
|
|
496
|
+
- [Errors](./errors.md): `SessionConflictError` and `InvalidSessionError`.
|