@adonis-agora/agent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/configure.d.ts +18 -0
- package/dist/configure.d.ts.map +1 -0
- package/dist/configure.js +29 -0
- package/dist/configure.js.map +1 -0
- package/dist/providers/agent_provider.d.ts +25 -0
- package/dist/providers/agent_provider.d.ts.map +1 -0
- package/dist/providers/agent_provider.js +511 -0
- package/dist/providers/agent_provider.js.map +1 -0
- package/dist/src/actor-resolver.d.ts +41 -0
- package/dist/src/actor-resolver.d.ts.map +1 -0
- package/dist/src/agent-deps-factory.d.ts +59 -0
- package/dist/src/agent-deps-factory.d.ts.map +1 -0
- package/dist/src/agent-deps-factory.js +111 -0
- package/dist/src/agent-deps-factory.js.map +1 -0
- package/dist/src/agent-deps.d.ts +42 -0
- package/dist/src/agent-deps.d.ts.map +1 -0
- package/dist/src/agent-deps.js +5 -0
- package/dist/src/agent-deps.js.map +1 -0
- package/dist/src/agent-loop.d.ts +101 -0
- package/dist/src/agent-loop.d.ts.map +1 -0
- package/dist/src/agent-loop.js +396 -0
- package/dist/src/agent-loop.js.map +1 -0
- package/dist/src/agent-registry.d.ts +10 -0
- package/dist/src/agent-registry.d.ts.map +1 -0
- package/dist/src/agent-service.d.ts +50 -0
- package/dist/src/agent-service.d.ts.map +1 -0
- package/dist/src/agent-service.js +82 -0
- package/dist/src/agent-service.js.map +1 -0
- package/dist/src/ai-sdk/ai-sdk-model.d.ts +17 -0
- package/dist/src/ai-sdk/ai-sdk-model.d.ts.map +1 -0
- package/dist/src/ai-sdk/ai-sdk-model.js +263 -0
- package/dist/src/ai-sdk/ai-sdk-model.js.map +1 -0
- package/dist/src/ai-sdk/index.d.ts +2 -0
- package/dist/src/ai-sdk/index.d.ts.map +1 -0
- package/dist/src/ai-tool-ref.d.ts +79 -0
- package/dist/src/ai-tool-ref.d.ts.map +1 -0
- package/dist/src/ai-tool-ref.js +81 -0
- package/dist/src/ai-tool-ref.js.map +1 -0
- package/dist/src/authorizer.d.ts +18 -0
- package/dist/src/authorizer.d.ts.map +1 -0
- package/dist/src/authz/authz-tool-authorizer.d.ts +85 -0
- package/dist/src/authz/authz-tool-authorizer.d.ts.map +1 -0
- package/dist/src/authz/authz-tool-authorizer.js +63 -0
- package/dist/src/authz/authz-tool-authorizer.js.map +1 -0
- package/dist/src/authz/index.d.ts +3 -0
- package/dist/src/authz/index.d.ts.map +1 -0
- package/dist/src/authz/index.js +2 -0
- package/dist/src/authz/index.js.map +1 -0
- package/dist/src/data/data-tool.d.ts +64 -0
- package/dist/src/data/data-tool.d.ts.map +1 -0
- package/dist/src/data/data-tool.js +146 -0
- package/dist/src/data/data-tool.js.map +1 -0
- package/dist/src/data/index.d.ts +7 -0
- package/dist/src/data/index.d.ts.map +1 -0
- package/dist/src/data/index.js +7 -0
- package/dist/src/data/index.js.map +1 -0
- package/dist/src/data/limit.d.ts +12 -0
- package/dist/src/data/limit.d.ts.map +1 -0
- package/dist/src/data/limit.js +29 -0
- package/dist/src/data/limit.js.map +1 -0
- package/dist/src/data/parser.d.ts +27 -0
- package/dist/src/data/parser.d.ts.map +1 -0
- package/dist/src/data/parser.js +18 -0
- package/dist/src/data/parser.js.map +1 -0
- package/dist/src/data/sql-validator.d.ts +37 -0
- package/dist/src/data/sql-validator.d.ts.map +1 -0
- package/dist/src/data/sql-validator.js +92 -0
- package/dist/src/data/sql-validator.js.map +1 -0
- package/dist/src/data/table-access.d.ts +40 -0
- package/dist/src/data/table-access.d.ts.map +1 -0
- package/dist/src/data/table-access.js +41 -0
- package/dist/src/data/table-access.js.map +1 -0
- package/dist/src/data/tenant-scope.d.ts +39 -0
- package/dist/src/data/tenant-scope.d.ts.map +1 -0
- package/dist/src/data/tenant-scope.js +126 -0
- package/dist/src/data/tenant-scope.js.map +1 -0
- package/dist/src/define_config.d.ts +153 -0
- package/dist/src/define_config.d.ts.map +1 -0
- package/dist/src/define_config.js +7 -0
- package/dist/src/define_config.js.map +1 -0
- package/dist/src/diagnostics.d.ts +82 -0
- package/dist/src/diagnostics.d.ts.map +1 -0
- package/dist/src/diagnostics.js +50 -0
- package/dist/src/diagnostics.js.map +1 -0
- package/dist/src/durable/agent-run-context.d.ts +24 -0
- package/dist/src/durable/agent-run-context.d.ts.map +1 -0
- package/dist/src/durable/agent-run-context.js +17 -0
- package/dist/src/durable/agent-run-context.js.map +1 -0
- package/dist/src/durable/agent-run-workflow.d.ts +37 -0
- package/dist/src/durable/agent-run-workflow.d.ts.map +1 -0
- package/dist/src/durable/agent-run-workflow.js +128 -0
- package/dist/src/durable/agent-run-workflow.js.map +1 -0
- package/dist/src/durable/durable-agent-runner.d.ts +25 -0
- package/dist/src/durable/durable-agent-runner.d.ts.map +1 -0
- package/dist/src/durable/durable-agent-runner.js +59 -0
- package/dist/src/durable/durable-agent-runner.js.map +1 -0
- package/dist/src/durable/index.d.ts +17 -0
- package/dist/src/durable/index.d.ts.map +1 -0
- package/dist/src/durable/index.js +20 -0
- package/dist/src/durable/index.js.map +1 -0
- package/dist/src/index.d.ts +55 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +45 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/personas.d.ts +7 -0
- package/dist/src/personas.d.ts.map +1 -0
- package/dist/src/rag/chunk.d.ts +14 -0
- package/dist/src/rag/chunk.d.ts.map +1 -0
- package/dist/src/rag/chunk.js +42 -0
- package/dist/src/rag/chunk.js.map +1 -0
- package/dist/src/rag/embedding-retriever.d.ts +15 -0
- package/dist/src/rag/embedding-retriever.d.ts.map +1 -0
- package/dist/src/rag/embedding-retriever.js +24 -0
- package/dist/src/rag/embedding-retriever.js.map +1 -0
- package/dist/src/rag/filter.d.ts +6 -0
- package/dist/src/rag/filter.d.ts.map +1 -0
- package/dist/src/rag/filter.js +11 -0
- package/dist/src/rag/filter.js.map +1 -0
- package/dist/src/rag/index.d.ts +8 -0
- package/dist/src/rag/index.d.ts.map +1 -0
- package/dist/src/rag/index.js +8 -0
- package/dist/src/rag/index.js.map +1 -0
- package/dist/src/rag/ingest.d.ts +33 -0
- package/dist/src/rag/ingest.d.ts.map +1 -0
- package/dist/src/rag/ingest.js +37 -0
- package/dist/src/rag/ingest.js.map +1 -0
- package/dist/src/rag/memory-vector-store.d.ts +16 -0
- package/dist/src/rag/memory-vector-store.d.ts.map +1 -0
- package/dist/src/rag/memory-vector-store.js +70 -0
- package/dist/src/rag/memory-vector-store.js.map +1 -0
- package/dist/src/rag/pg-vector-store.d.ts +84 -0
- package/dist/src/rag/pg-vector-store.d.ts.map +1 -0
- package/dist/src/rag/pg-vector-store.js +220 -0
- package/dist/src/rag/pg-vector-store.js.map +1 -0
- package/dist/src/rag/vector-store.d.ts +47 -0
- package/dist/src/rag/vector-store.d.ts.map +1 -0
- package/dist/src/rag/vector-store.js +5 -0
- package/dist/src/rag/vector-store.js.map +1 -0
- package/dist/src/rag-media/diagnostics.d.ts +43 -0
- package/dist/src/rag-media/diagnostics.d.ts.map +1 -0
- package/dist/src/rag-media/diagnostics.js +36 -0
- package/dist/src/rag-media/diagnostics.js.map +1 -0
- package/dist/src/rag-media/index.d.ts +5 -0
- package/dist/src/rag-media/index.d.ts.map +1 -0
- package/dist/src/rag-media/index.js +5 -0
- package/dist/src/rag-media/index.js.map +1 -0
- package/dist/src/rag-media/media-events.d.ts +23 -0
- package/dist/src/rag-media/media-events.d.ts.map +1 -0
- package/dist/src/rag-media/media-events.js +28 -0
- package/dist/src/rag-media/media-events.js.map +1 -0
- package/dist/src/rag-media/media-rag-ingestion.d.ts +155 -0
- package/dist/src/rag-media/media-rag-ingestion.d.ts.map +1 -0
- package/dist/src/rag-media/media-rag-ingestion.js +204 -0
- package/dist/src/rag-media/media-rag-ingestion.js.map +1 -0
- package/dist/src/rag-media/text-extractor.d.ts +46 -0
- package/dist/src/rag-media/text-extractor.d.ts.map +1 -0
- package/dist/src/rag-media/text-extractor.js +92 -0
- package/dist/src/rag-media/text-extractor.js.map +1 -0
- package/dist/src/redis-stream-client.d.ts +29 -0
- package/dist/src/redis-stream-client.d.ts.map +1 -0
- package/dist/src/redis-stream-client.js +2 -0
- package/dist/src/redis-stream-client.js.map +1 -0
- package/dist/src/redis-token-stream-sink.d.ts +36 -0
- package/dist/src/redis-token-stream-sink.d.ts.map +1 -0
- package/dist/src/redis-token-stream-sink.js +94 -0
- package/dist/src/redis-token-stream-sink.js.map +1 -0
- package/dist/src/runners/inline-agent-runner.d.ts +26 -0
- package/dist/src/runners/inline-agent-runner.d.ts.map +1 -0
- package/dist/src/runners/inline-agent-runner.js +85 -0
- package/dist/src/runners/inline-agent-runner.js.map +1 -0
- package/dist/src/spi/actor-directory.d.ts +23 -0
- package/dist/src/spi/actor-directory.d.ts.map +1 -0
- package/dist/src/spi/actor-directory.js +2 -0
- package/dist/src/spi/actor-directory.js.map +1 -0
- package/dist/src/spi/actor-resolver.d.ts +18 -0
- package/dist/src/spi/actor-resolver.d.ts.map +1 -0
- package/dist/src/spi/agent-runner.d.ts +20 -0
- package/dist/src/spi/agent-runner.d.ts.map +1 -0
- package/dist/src/spi/agent-store.d.ts +104 -0
- package/dist/src/spi/agent-store.d.ts.map +1 -0
- package/dist/src/spi/agent-store.js +2 -0
- package/dist/src/spi/agent-store.js.map +1 -0
- package/dist/src/spi/attachment-staging.d.ts +27 -0
- package/dist/src/spi/attachment-staging.d.ts.map +1 -0
- package/dist/src/spi/attachment-staging.js +2 -0
- package/dist/src/spi/attachment-staging.js.map +1 -0
- package/dist/src/spi/embedding-provider.d.ts +12 -0
- package/dist/src/spi/embedding-provider.d.ts.map +1 -0
- package/dist/src/spi/embedding-provider.js +2 -0
- package/dist/src/spi/embedding-provider.js.map +1 -0
- package/dist/src/spi/governance-queries.d.ts +215 -0
- package/dist/src/spi/governance-queries.d.ts.map +1 -0
- package/dist/src/spi/governance-queries.js +15 -0
- package/dist/src/spi/governance-queries.js.map +1 -0
- package/dist/src/spi/model-provider.d.ts +41 -0
- package/dist/src/spi/model-provider.d.ts.map +1 -0
- package/dist/src/spi/pricing-store.d.ts +45 -0
- package/dist/src/spi/pricing-store.d.ts.map +1 -0
- package/dist/src/spi/pricing-store.js +24 -0
- package/dist/src/spi/pricing-store.js.map +1 -0
- package/dist/src/spi/quota-store.d.ts +7 -0
- package/dist/src/spi/quota-store.d.ts.map +1 -0
- package/dist/src/spi/reranker.d.ts +17 -0
- package/dist/src/spi/reranker.d.ts.map +1 -0
- package/dist/src/spi/reranker.js +2 -0
- package/dist/src/spi/reranker.js.map +1 -0
- package/dist/src/spi/retriever.d.ts +28 -0
- package/dist/src/spi/retriever.d.ts.map +1 -0
- package/dist/src/spi/retriever.js +11 -0
- package/dist/src/spi/retriever.js.map +1 -0
- package/dist/src/spi/roles-policy.d.ts +11 -0
- package/dist/src/spi/roles-policy.d.ts.map +1 -0
- package/dist/src/spi/tool.d.ts +21 -0
- package/dist/src/spi/tool.d.ts.map +1 -0
- package/dist/src/stores/factory.d.ts +363 -0
- package/dist/src/stores/factory.d.ts.map +1 -0
- package/dist/src/stores/factory.js +341 -0
- package/dist/src/stores/factory.js.map +1 -0
- package/dist/src/stores/ledger-quota.d.ts +23 -0
- package/dist/src/stores/ledger-quota.d.ts.map +1 -0
- package/dist/src/stores/ledger-quota.js +32 -0
- package/dist/src/stores/ledger-quota.js.map +1 -0
- package/dist/src/stores/lucid-governance-queries.d.ts +73 -0
- package/dist/src/stores/lucid-governance-queries.d.ts.map +1 -0
- package/dist/src/stores/lucid-governance-queries.js +510 -0
- package/dist/src/stores/lucid-governance-queries.js.map +1 -0
- package/dist/src/stores/lucid-pricing.d.ts +20 -0
- package/dist/src/stores/lucid-pricing.d.ts.map +1 -0
- package/dist/src/stores/lucid-pricing.js +67 -0
- package/dist/src/stores/lucid-pricing.js.map +1 -0
- package/dist/src/stores/lucid-schema.d.ts +37 -0
- package/dist/src/stores/lucid-schema.d.ts.map +1 -0
- package/dist/src/stores/lucid-schema.js +139 -0
- package/dist/src/stores/lucid-schema.js.map +1 -0
- package/dist/src/stores/lucid.d.ts +73 -0
- package/dist/src/stores/lucid.d.ts.map +1 -0
- package/dist/src/stores/lucid.js +400 -0
- package/dist/src/stores/lucid.js.map +1 -0
- package/dist/src/telescope/dashboard.d.ts +21 -0
- package/dist/src/telescope/dashboard.d.ts.map +1 -0
- package/dist/src/telescope/dashboard.js +140 -0
- package/dist/src/telescope/dashboard.js.map +1 -0
- package/dist/src/telescope/data-providers.d.ts +39 -0
- package/dist/src/telescope/data-providers.d.ts.map +1 -0
- package/dist/src/telescope/data-providers.js +345 -0
- package/dist/src/telescope/data-providers.js.map +1 -0
- package/dist/src/telescope/extension.d.ts +27 -0
- package/dist/src/telescope/extension.d.ts.map +1 -0
- package/dist/src/telescope/extension.js +45 -0
- package/dist/src/telescope/extension.js.map +1 -0
- package/dist/src/telescope/index.d.ts +5 -0
- package/dist/src/telescope/index.d.ts.map +1 -0
- package/dist/src/telescope/index.js +4 -0
- package/dist/src/telescope/index.js.map +1 -0
- package/dist/src/telescope/telescope-sdk.d.ts +126 -0
- package/dist/src/telescope/telescope-sdk.d.ts.map +1 -0
- package/dist/src/telescope/telescope-sdk.js +15 -0
- package/dist/src/telescope/telescope-sdk.js.map +1 -0
- package/dist/src/testing/fake-embedding-provider.d.ts +37 -0
- package/dist/src/testing/fake-embedding-provider.d.ts.map +1 -0
- package/dist/src/testing/fake-embedding-provider.js +67 -0
- package/dist/src/testing/fake-embedding-provider.js.map +1 -0
- package/dist/src/testing/fake-media.d.ts +44 -0
- package/dist/src/testing/fake-media.d.ts.map +1 -0
- package/dist/src/testing/fake-media.js +69 -0
- package/dist/src/testing/fake-media.js.map +1 -0
- package/dist/src/testing/fake-model-provider.d.ts +29 -0
- package/dist/src/testing/fake-model-provider.d.ts.map +1 -0
- package/dist/src/testing/in-memory-actor-directory.d.ts +14 -0
- package/dist/src/testing/in-memory-actor-directory.d.ts.map +1 -0
- package/dist/src/testing/in-memory-actor-directory.js +27 -0
- package/dist/src/testing/in-memory-actor-directory.js.map +1 -0
- package/dist/src/testing/in-memory-attachment-staging.d.ts +22 -0
- package/dist/src/testing/in-memory-attachment-staging.d.ts.map +1 -0
- package/dist/src/testing/in-memory-attachment-staging.js +28 -0
- package/dist/src/testing/in-memory-attachment-staging.js.map +1 -0
- package/dist/src/testing/in-memory-governance-queries.d.ts +34 -0
- package/dist/src/testing/in-memory-governance-queries.d.ts.map +1 -0
- package/dist/src/testing/in-memory-governance-queries.js +373 -0
- package/dist/src/testing/in-memory-governance-queries.js.map +1 -0
- package/dist/src/testing/in-memory-pricing.d.ts +13 -0
- package/dist/src/testing/in-memory-pricing.d.ts.map +1 -0
- package/dist/src/testing/in-memory-pricing.js +27 -0
- package/dist/src/testing/in-memory-pricing.js.map +1 -0
- package/dist/src/testing/in-memory-quota.d.ts +11 -0
- package/dist/src/testing/in-memory-quota.d.ts.map +1 -0
- package/dist/src/testing/in-memory-sink.d.ts +14 -0
- package/dist/src/testing/in-memory-sink.d.ts.map +1 -0
- package/dist/src/testing/in-memory-store.d.ts +119 -0
- package/dist/src/testing/in-memory-store.d.ts.map +1 -0
- package/dist/src/testing/in-memory-store.js +317 -0
- package/dist/src/testing/in-memory-store.js.map +1 -0
- package/dist/src/testing/index.d.ts +11 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +11 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/tool-discovery.d.ts +35 -0
- package/dist/src/tool-discovery.d.ts.map +1 -0
- package/dist/src/tool-registry.d.ts +45 -0
- package/dist/src/tool-registry.d.ts.map +1 -0
- package/dist/src/tool-retry.d.ts +56 -0
- package/dist/src/tool-retry.d.ts.map +1 -0
- package/dist/src/tool-retry.js +95 -0
- package/dist/src/tool-retry.js.map +1 -0
- package/dist/src/types.d.ts +222 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/stubs/config/agent.stub +55 -0
- package/dist/stubs/database/migrations/create_agent_rag_chunks.stub +41 -0
- package/dist/stubs/database/migrations/create_agent_run_tracking.stub +80 -0
- package/dist/stubs/database/migrations/create_agent_tables.stub +113 -0
- package/package.json +174 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const STRING_LITERAL_TYPES = new Set(['string', 'single_quote_string', 'double_quote_string']);
|
|
2
|
+
/**
|
|
3
|
+
* Rewrites a SELECT so every reference to a scoped table is constrained to a
|
|
4
|
+
* single tenant: `<tenantColumn> = '<tenantRef>'` is AND-ed into the WHERE for
|
|
5
|
+
* each scoped table in the FROM. An existing predicate for a different tenant
|
|
6
|
+
* is rejected (no cross-tenant reads). `tenantRef === undefined` is the
|
|
7
|
+
* privileged path and passes the SQL through unchanged.
|
|
8
|
+
*
|
|
9
|
+
* CRITICAL: only a strictly `=== undefined` tenantRef is privileged. A `null`
|
|
10
|
+
* or empty-string tenantRef is NOT privileged — it flows into the rewrite and
|
|
11
|
+
* injects a predicate that matches nothing (fail-closed), so a missing tenant
|
|
12
|
+
* can never accidentally read every tenant's rows.
|
|
13
|
+
*
|
|
14
|
+
* Scoped mode rejects CTEs, UNION/INTERSECT/EXCEPT, and subqueries in FROM:
|
|
15
|
+
* those make it impossible to statically guarantee every tenant-bearing source
|
|
16
|
+
* is constrained, so we fail closed and ask the caller to rephrase.
|
|
17
|
+
*
|
|
18
|
+
* The `node-sql-parser` `Parser` is injected (see {@link loadSqlParser}) so this file never imports the
|
|
19
|
+
* optional peer at module load.
|
|
20
|
+
*/
|
|
21
|
+
export class TenantScopeRewriter {
|
|
22
|
+
parser;
|
|
23
|
+
tenantColumn;
|
|
24
|
+
scopedTables;
|
|
25
|
+
constructor(config, parser) {
|
|
26
|
+
this.parser = parser;
|
|
27
|
+
this.tenantColumn = config.tenantColumn;
|
|
28
|
+
this.scopedTables = new Set(config.scopedTables);
|
|
29
|
+
}
|
|
30
|
+
/** Rewrite `sql` to constrain scoped tables to `tenantRef`. Strictly-`undefined` → pass through. */
|
|
31
|
+
rewrite(sql, tenantRef) {
|
|
32
|
+
if (tenantRef === undefined)
|
|
33
|
+
return sql;
|
|
34
|
+
const parsed = this.parser.astify(sql, { database: 'MySQL' });
|
|
35
|
+
const ast = (Array.isArray(parsed) ? parsed[0] : parsed);
|
|
36
|
+
if (ast.type !== 'select') {
|
|
37
|
+
throw new Error('tenant scope: only SELECT is supported');
|
|
38
|
+
}
|
|
39
|
+
if (ast.with) {
|
|
40
|
+
throw new Error('tenant scope: WITH (CTE) is not supported in scoped mode — rewrite using JOINs/subqueries in FROM');
|
|
41
|
+
}
|
|
42
|
+
if (ast._next) {
|
|
43
|
+
throw new Error('tenant scope: UNION/INTERSECT/EXCEPT is not supported in scoped mode — run each branch as a separate query');
|
|
44
|
+
}
|
|
45
|
+
const fromEntries = ast.from ?? [];
|
|
46
|
+
for (const entry of fromEntries) {
|
|
47
|
+
if (!entry.table && entry.expr?.ast) {
|
|
48
|
+
throw new Error('tenant scope: subqueries in FROM are not supported in scoped mode');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const scopedFrom = fromEntries.filter((entry) => typeof entry.table === 'string' && this.scopedTables.has(entry.table));
|
|
52
|
+
if (scopedFrom.length === 0)
|
|
53
|
+
return sql;
|
|
54
|
+
const existing = this.collectTenantPredicates(ast.where);
|
|
55
|
+
for (const predicate of existing) {
|
|
56
|
+
if (predicate.value !== tenantRef) {
|
|
57
|
+
throw new Error('tenant scope: tenant mismatch — query targets a tenant other than the current session');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const coveredAliases = new Set(existing.map((predicate) => predicate.tableAlias));
|
|
61
|
+
for (const entry of scopedFrom) {
|
|
62
|
+
const alias = entry.as ?? entry.table;
|
|
63
|
+
const isAmbiguous = scopedFrom.length > 1;
|
|
64
|
+
const covered = coveredAliases.has(alias) || (!isAmbiguous && coveredAliases.has(null));
|
|
65
|
+
if (covered)
|
|
66
|
+
continue;
|
|
67
|
+
ast.where = this.andCondition(ast.where, this.buildTenantEquality(isAmbiguous ? alias : null, tenantRef));
|
|
68
|
+
}
|
|
69
|
+
return this.parser.sqlify(ast, { database: 'MySQL' });
|
|
70
|
+
}
|
|
71
|
+
collectTenantPredicates(where) {
|
|
72
|
+
if (!isBinaryExpr(where))
|
|
73
|
+
return [];
|
|
74
|
+
if (where.operator === 'AND' || where.operator === 'OR') {
|
|
75
|
+
return [
|
|
76
|
+
...this.collectTenantPredicates(where.left),
|
|
77
|
+
...this.collectTenantPredicates(where.right),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
if (where.operator !== '=')
|
|
81
|
+
return [];
|
|
82
|
+
const lhs = where.left;
|
|
83
|
+
const rhs = where.right;
|
|
84
|
+
if (!isColumnRef(lhs) || lhs.column !== this.tenantColumn)
|
|
85
|
+
return [];
|
|
86
|
+
if (!isStringLiteral(rhs))
|
|
87
|
+
return [];
|
|
88
|
+
return [{ tableAlias: lhs.table ?? null, value: rhs.value }];
|
|
89
|
+
}
|
|
90
|
+
buildTenantEquality(tableAlias, tenantRef) {
|
|
91
|
+
return {
|
|
92
|
+
type: 'binary_expr',
|
|
93
|
+
operator: '=',
|
|
94
|
+
left: { type: 'column_ref', table: tableAlias, column: this.tenantColumn },
|
|
95
|
+
right: { type: 'single_quote_string', value: tenantRef },
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
andCondition(existing, added) {
|
|
99
|
+
if (existing == null)
|
|
100
|
+
return added;
|
|
101
|
+
return {
|
|
102
|
+
type: 'binary_expr',
|
|
103
|
+
operator: 'AND',
|
|
104
|
+
left: existing,
|
|
105
|
+
right: added,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function isBinaryExpr(value) {
|
|
110
|
+
return (typeof value === 'object' &&
|
|
111
|
+
value !== null &&
|
|
112
|
+
value.type === 'binary_expr');
|
|
113
|
+
}
|
|
114
|
+
function isColumnRef(value) {
|
|
115
|
+
return (typeof value === 'object' &&
|
|
116
|
+
value !== null &&
|
|
117
|
+
value.type === 'column_ref');
|
|
118
|
+
}
|
|
119
|
+
function isStringLiteral(value) {
|
|
120
|
+
return (typeof value === 'object' &&
|
|
121
|
+
value !== null &&
|
|
122
|
+
typeof value.type === 'string' &&
|
|
123
|
+
STRING_LITERAL_TYPES.has(value.type) &&
|
|
124
|
+
typeof value.value === 'string');
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=tenant-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-scope.js","sourceRoot":"","sources":["../../../src/data/tenant-scope.ts"],"names":[],"mappings":"AA2CA,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,qBAAqB,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAE/F;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,mBAAmB;IAMX;IALF,YAAY,CAAS;IACrB,YAAY,CAAc;IAE3C,YACE,MAAyB,EACR,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;QAEtC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;IAED,oGAAoG;IACpG,OAAO,CAAC,GAAW,EAAE,SAA6B;QAChD,IAAI,SAAS,KAAK,SAAS;YAAE,OAAO,GAAG,CAAC;QAExC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAC9D,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAc,CAAC;QAEtE,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,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AC1D,OAAQ,KAA6B,CAAC,KAAK,KAAK,QAAQ,CACzD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { BrandedFunctionalTool } from './ai-tool-ref.js';
|
|
2
|
+
import type { ActorDirectory } from './spi/actor-directory.js';
|
|
3
|
+
import type { ActorResolver } from './spi/actor-resolver.js';
|
|
4
|
+
import type { AttachmentStagingStore } from './spi/attachment-staging.js';
|
|
5
|
+
import type { AgentGovernanceQueries } from './spi/governance-queries.js';
|
|
6
|
+
import type { ModelProvider } from './spi/model-provider.js';
|
|
7
|
+
import type { AgentPricingStore } from './spi/pricing-store.js';
|
|
8
|
+
import type { QuotaStore } from './spi/quota-store.js';
|
|
9
|
+
import type { Retriever } from './spi/retriever.js';
|
|
10
|
+
import type { RolesPolicy } from './spi/roles-policy.js';
|
|
11
|
+
import type { TokenStreamSink } from './spi/token-stream-sink.js';
|
|
12
|
+
import { actorDirectories, attachmentStores, governanceQueries, pricingStores, quotas, retrievers, stores, streamTransports, tokenSinks } from './stores/factory.js';
|
|
13
|
+
import type { ActorDirectoryFactory, AttachmentStagingContext, AttachmentStagingFactory, EmbeddingFactory, GovernanceQueriesContext, GovernanceQueriesFactory, LucidGovernanceConfig, LucidPricingConfig, LucidStoreConfig, MemoryActorDirectoryConfig, MemoryRetrieverConfig, MemoryStoreConfig, PgVectorRetrieverConfig, PricingContext, PricingFactory, QuotaConfig, QuotaContext, QuotaFactory, RedisTokenSinkConfig, RetrieverContext, RetrieverFactory, StoreContext, StoreFactory, TokenSinkFactory } from './stores/factory.js';
|
|
14
|
+
import type { ToolTransientRetrySetting } from './tool-retry.js';
|
|
15
|
+
import type { AgentDefinition } from './types.js';
|
|
16
|
+
/** A lazy factory thunk, so the peer (`ai`/a provider SDK) is imported only when the config loads. */
|
|
17
|
+
export type ModelFactory = () => ModelProvider | Promise<ModelProvider>;
|
|
18
|
+
/** A lazy {@link TokenStreamSink} factory. Omit to use the in-process sink. */
|
|
19
|
+
export type SinkFactory = () => TokenStreamSink | Promise<TokenStreamSink>;
|
|
20
|
+
/** The implicit default agent, configured inline — an {@link AgentDefinition} with `name` optional. */
|
|
21
|
+
export type DefaultAgentOptions = Omit<AgentDefinition, 'name'> & {
|
|
22
|
+
name?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Shape of `config/agent.ts`. Only `model` is required. Pick a `store` by name from the `stores` map
|
|
26
|
+
* (built with the {@link stores} factory so each peer is imported lazily); omit it for the in-memory
|
|
27
|
+
* store. The default runner is in-process (`durable: false`); the actor resolver defaults to one that
|
|
28
|
+
* THROWS — an identity is never fabricated.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { defineConfig, stores } from '@adonis-agora/agent'
|
|
32
|
+
* import { aiSdkModel } from '@adonis-agora/agent/ai-sdk'
|
|
33
|
+
*
|
|
34
|
+
* export default defineConfig({
|
|
35
|
+
* model: () => aiSdkModel({ model: '...' }),
|
|
36
|
+
* store: 'lucid',
|
|
37
|
+
* stores: { lucid: stores.lucid(), memory: stores.memory() },
|
|
38
|
+
* actorResolver: new AuthActorResolver(),
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export interface AgentConfig {
|
|
43
|
+
/** The LLM provider, or a lazy factory thunk so the provider SDK peer loads lazily. Required. */
|
|
44
|
+
model: ModelProvider | ModelFactory;
|
|
45
|
+
/** Name of the store (a key of `stores`). Omit for the in-memory store (single-process). */
|
|
46
|
+
store?: string;
|
|
47
|
+
/** Named stores, built with the {@link stores} factory. Provide `lucid` and/or `memory`. */
|
|
48
|
+
stores?: Record<string, StoreFactory>;
|
|
49
|
+
/**
|
|
50
|
+
* Live token transport ("data plane"), or a lazy factory. Defaults to the in-process sink (single
|
|
51
|
+
* replica). Use `tokenSinks.redis({...})` (a.k.a. `streamTransports.redis`) for the multi-replica
|
|
52
|
+
* Redis sink so any pod can serve any run's SSE stream — the SSE envelope is unchanged either way.
|
|
53
|
+
*/
|
|
54
|
+
sink?: TokenStreamSink | SinkFactory;
|
|
55
|
+
/**
|
|
56
|
+
* Daily token budget, or a lazy factory. Omit to disable quotas (fail-open on budget). Use
|
|
57
|
+
* `quotas.ledger({ limitTokens })` to enforce off the persisted token-usage ledger, or
|
|
58
|
+
* `quotas.memory({ limitTokens })` for a single-process budget.
|
|
59
|
+
*/
|
|
60
|
+
quota?: QuotaStore | QuotaFactory;
|
|
61
|
+
/**
|
|
62
|
+
* Prices each turn's tokens into the assistant message's `usage.costUsd`. A provider-reported cost
|
|
63
|
+
* (a gateway) always wins; otherwise the loop estimates from this store's current price rows (fetched
|
|
64
|
+
* once per run). Omit → `costUsd` is always `null` (never a fabricated `0`). Use
|
|
65
|
+
* `pricingStores.lucid()` for the SQL-backed table or `pricingStores.memory()` for tests.
|
|
66
|
+
*/
|
|
67
|
+
pricingStore?: AgentPricingStore | PricingFactory;
|
|
68
|
+
/**
|
|
69
|
+
* The governance read-model the optional `/agent/governance/*` read routes serve from — per-model /
|
|
70
|
+
* per-actor cost & usage rollups, the daily usage trend, and recent tool-call / thread activity over
|
|
71
|
+
* the persisted agent tables. Pass an {@link AgentGovernanceQueries} instance, or a lazy
|
|
72
|
+
* `governanceQueries.lucid()` factory (which prices its rollups against the configured `pricingStore`).
|
|
73
|
+
* Omit → the governance routes are not mounted. Read-only; safe to leave off.
|
|
74
|
+
*/
|
|
75
|
+
governanceQueries?: AgentGovernanceQueries | GovernanceQueriesFactory;
|
|
76
|
+
/**
|
|
77
|
+
* Enables always-on ("inject") RAG: before each turn the loop retrieves passages for the user message
|
|
78
|
+
* and folds them into the system prompt (replay-safe under durable). Pass a {@link Retriever} directly
|
|
79
|
+
* or a lazy factory — `retrievers.pgvector({ embedder, table, dimension })` for the production pgvector
|
|
80
|
+
* store, or `retrievers.memory({ embedder, documents })` for the in-memory cosine store. Omit → no injection.
|
|
81
|
+
*/
|
|
82
|
+
retriever?: Retriever | RetrieverFactory;
|
|
83
|
+
/** How many passages inject-mode retrieval requests per run. Default 5. */
|
|
84
|
+
retrievalTopK?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Upload-side seam for message attachments (image/PDF). When set, the provider mounts the optional
|
|
87
|
+
* `POST /agent/attachments` route, which stages an uploaded file through this store and returns a
|
|
88
|
+
* {@link import('./spi/attachment-staging.js').MessageAttachment} the client sends with the next
|
|
89
|
+
* chat message. Pass a store instance, or a lazy `attachmentStores.*()` factory
|
|
90
|
+
* (`attachmentStores.memory()` encodes bytes into a `data:` URL for tests/dev). Omit → no upload
|
|
91
|
+
* route; a client sends already-staged attachment references directly on `chat`.
|
|
92
|
+
*/
|
|
93
|
+
attachmentStaging?: AttachmentStagingStore | AttachmentStagingFactory;
|
|
94
|
+
/** Per-file byte cap the upload route enforces. Default 20 MiB. */
|
|
95
|
+
attachmentMaxBytes?: number;
|
|
96
|
+
/** Allowed upload content types. Default: common image types + `application/pdf` + `text/*`. */
|
|
97
|
+
attachmentAllowedContentTypes?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* Tool authorization gate. Defaults to `DefaultToolAuthorizer` (fail-closed, ADMIN-only; role-set
|
|
100
|
+
* intersection). `authorizer` and `rolesPolicy` are aliases — pass either.
|
|
101
|
+
*/
|
|
102
|
+
authorizer?: RolesPolicy;
|
|
103
|
+
/** Alias of {@link AgentConfig.authorizer}. */
|
|
104
|
+
rolesPolicy?: RolesPolicy;
|
|
105
|
+
/** Roles a tool requires when it declares none. Defaults to `['ADMIN']`. */
|
|
106
|
+
defaultRoles?: string[];
|
|
107
|
+
/**
|
|
108
|
+
* Resolves the acting actor per request (the identity seam). Defaults to a resolver that THROWS on
|
|
109
|
+
* every request — the agent never fabricates a caller. Wire `AuthActorResolver` / `HeaderActorResolver`.
|
|
110
|
+
*/
|
|
111
|
+
actorResolver?: ActorResolver;
|
|
112
|
+
/**
|
|
113
|
+
* Read-side lookup from opaque persisted `actorRef`s to human display labels for governance/dashboard
|
|
114
|
+
* surfaces (the read-side dual of {@link AgentConfig.actorResolver}). Pass an {@link ActorDirectory}
|
|
115
|
+
* instance, or a lazy `actorDirectories.memory({ labels })` factory. Omit → surfaces render raw refs.
|
|
116
|
+
*/
|
|
117
|
+
actorDirectory?: ActorDirectory | ActorDirectoryFactory;
|
|
118
|
+
/** Route prefix the `/agent/*` routes mount under. Defaults to `'agent'`. */
|
|
119
|
+
path?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Run each turn as a replay-safe durable workflow (over `@adonis-agora/durable`) instead of
|
|
122
|
+
* in-process: LLM turns / tool executions become memoized durable steps, HITL approval suspends the
|
|
123
|
+
* run on a signal (resuming across a restart), and sub-agent delegation is a tracked child run. Opt
|
|
124
|
+
* in with `true` — requires `@adonis-agora/durable` installed and configured (`config/durable.ts`).
|
|
125
|
+
* If the durable peer can't be wired, the provider logs a warning and falls back to the in-process
|
|
126
|
+
* (inline) runner, so setting it is always safe.
|
|
127
|
+
*/
|
|
128
|
+
durable?: boolean;
|
|
129
|
+
/** Additional named agents (an orchestrator delegates to them via `delegatesTo`). */
|
|
130
|
+
agents?: AgentDefinition[];
|
|
131
|
+
/** The implicit single agent's config (base prompt, personas, tool allow-list). Omit for a bare assistant. */
|
|
132
|
+
defaultAgent?: DefaultAgentOptions;
|
|
133
|
+
/** Static functional tools (`defineTool(...)`) to register at boot, in addition to discovery. */
|
|
134
|
+
tools?: BrandedFunctionalTool[];
|
|
135
|
+
/** Cap on model↔tool iterations per turn. Default 8. */
|
|
136
|
+
maxSteps?: number;
|
|
137
|
+
/**
|
|
138
|
+
* Retries a tool's own invocation, in place, when it throws a classified-transient error (a DB
|
|
139
|
+
* deadlock, a lock-wait timeout, a serialization failure) — a bounded retry inside the tool's
|
|
140
|
+
* durable step, so a replay reuses the memoized result and side effects run once. Default ON
|
|
141
|
+
* (`{ attempts: 2, backoffMs: 150 }` with the default classifier); pass `{ classify }` to
|
|
142
|
+
* widen/narrow which errors count as transient, or `false` to disable. Non-transient failures are
|
|
143
|
+
* never retried — they stay a one-shot business outcome.
|
|
144
|
+
*/
|
|
145
|
+
toolTransientRetry?: ToolTransientRetrySetting;
|
|
146
|
+
/** Emit `agora:agent:*` diagnostics events when `@adonis-agora/diagnostics` is installed. Default true. */
|
|
147
|
+
emitDiagnostics?: boolean;
|
|
148
|
+
}
|
|
149
|
+
/** Identity helper giving `config/agent.ts` full type-checking. */
|
|
150
|
+
export declare function defineConfig(config: AgentConfig): AgentConfig;
|
|
151
|
+
export { stores, quotas, pricingStores, governanceQueries, retrievers, attachmentStores, tokenSinks, streamTransports, actorDirectories, };
|
|
152
|
+
export type { StoreContext, StoreFactory, LucidStoreConfig, MemoryStoreConfig, QuotaContext, QuotaFactory, QuotaConfig, PricingContext, PricingFactory, LucidPricingConfig, GovernanceQueriesContext, GovernanceQueriesFactory, LucidGovernanceConfig, RetrieverContext, RetrieverFactory, MemoryRetrieverConfig, PgVectorRetrieverConfig, EmbeddingFactory, AttachmentStagingContext, AttachmentStagingFactory, TokenSinkFactory, RedisTokenSinkConfig, ActorDirectoryFactory, MemoryActorDirectoryConfig, };
|
|
153
|
+
//# sourceMappingURL=define_config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define_config.d.ts","sourceRoot":"","sources":["../../src/define_config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE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CAAC;IACnC,iGAAiG;IACjG,KAAK,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAChC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,yBAAyB,CAAC;IAC/C,2GAA2G;IAC3G,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAE7D;AAED,OAAO,EACL,MAAM,EACN,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACjB,CAAC;AACF,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,GAC3B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { actorDirectories, attachmentStores, governanceQueries, pricingStores, quotas, retrievers, stores, streamTransports, tokenSinks, } from './stores/factory.js';
|
|
2
|
+
/** Identity helper giving `config/agent.ts` full type-checking. */
|
|
3
|
+
export function defineConfig(config) {
|
|
4
|
+
return config;
|
|
5
|
+
}
|
|
6
|
+
export { stores, quotas, pricingStores, governanceQueries, retrievers, attachmentStores, tokenSinks, streamTransports, actorDirectories, };
|
|
7
|
+
//# sourceMappingURL=define_config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define_config.js","sourceRoot":"","sources":["../../src/define_config.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,MAAM,EACN,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,UAAU,GACX,MAAM,qBAAqB,CAAC;AAoK7B,mEAAmE;AACnE,MAAM,UAAU,YAAY,CAAC,MAAmB;IAC9C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,OAAO,EACL,MAAM,EACN,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACjB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Payloads carried on each `agora:agent:*` channel. */
|
|
2
|
+
export interface AgentRunStarted {
|
|
3
|
+
runId: string;
|
|
4
|
+
threadId: string;
|
|
5
|
+
actorId: string;
|
|
6
|
+
persona?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AgentMessageEvent {
|
|
9
|
+
runId: string;
|
|
10
|
+
threadId: string;
|
|
11
|
+
role: 'user' | 'assistant';
|
|
12
|
+
textLength: number;
|
|
13
|
+
}
|
|
14
|
+
export interface AgentToolCallEvent {
|
|
15
|
+
runId: string;
|
|
16
|
+
toolName: string;
|
|
17
|
+
toolType: 'read' | 'action';
|
|
18
|
+
status: string;
|
|
19
|
+
durationMs?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentQuotaExceeded {
|
|
22
|
+
actorId: string;
|
|
23
|
+
usedTokens: number;
|
|
24
|
+
limitTokens: number;
|
|
25
|
+
}
|
|
26
|
+
export interface AgentRunFinished {
|
|
27
|
+
runId: string;
|
|
28
|
+
threadId: string;
|
|
29
|
+
steps: number;
|
|
30
|
+
inputTokens: number;
|
|
31
|
+
outputTokens: number;
|
|
32
|
+
}
|
|
33
|
+
export interface AgentDelegated {
|
|
34
|
+
runId: string;
|
|
35
|
+
fromAgent?: string;
|
|
36
|
+
toAgent: string;
|
|
37
|
+
}
|
|
38
|
+
export interface AgentRetrieved {
|
|
39
|
+
runId: string;
|
|
40
|
+
/** Length of the query (not the text) — same redaction posture as {@link AgentMessageEvent}. */
|
|
41
|
+
queryLength: number;
|
|
42
|
+
count: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A transient-classified tool error being retried in place (no new checkpoint) — see
|
|
46
|
+
* `invokeWithTransientRetry`. Emitted once per retry (not for the final, non-retried outcome).
|
|
47
|
+
*/
|
|
48
|
+
export interface AgentToolRetry {
|
|
49
|
+
runId: string;
|
|
50
|
+
toolName: string;
|
|
51
|
+
toolCallId: string;
|
|
52
|
+
/** 1-based ordinal of the attempt that just failed and is about to be retried. */
|
|
53
|
+
attempt: number;
|
|
54
|
+
/** The failed attempt's error message. */
|
|
55
|
+
message: string;
|
|
56
|
+
}
|
|
57
|
+
/** Maps each event name to its payload type, so {@link publishAgent} is checked at the call site. */
|
|
58
|
+
export interface AgentDiagnosticPayloads {
|
|
59
|
+
'run.started': AgentRunStarted;
|
|
60
|
+
message: AgentMessageEvent;
|
|
61
|
+
'tool-call': AgentToolCallEvent;
|
|
62
|
+
'quota.exceeded': AgentQuotaExceeded;
|
|
63
|
+
'run.finished': AgentRunFinished;
|
|
64
|
+
delegated: AgentDelegated;
|
|
65
|
+
retrieved: AgentRetrieved;
|
|
66
|
+
'tool.retry': AgentToolRetry;
|
|
67
|
+
}
|
|
68
|
+
export type AgentDiagnosticEvent = keyof AgentDiagnosticPayloads;
|
|
69
|
+
/**
|
|
70
|
+
* Publish an agent event on `agora:agent:<event>` via the structural diagnostics slot. No-op when
|
|
71
|
+
* diagnostics isn't installed (the slot is empty) — and it never throws back into the agent loop.
|
|
72
|
+
*/
|
|
73
|
+
export declare function publishAgent<E extends AgentDiagnosticEvent>(event: E, payload: AgentDiagnosticPayloads[E]): void;
|
|
74
|
+
export declare function publishAgentRunStarted(payload: AgentRunStarted): void;
|
|
75
|
+
export declare function publishAgentMessage(payload: AgentMessageEvent): void;
|
|
76
|
+
export declare function publishAgentToolCall(payload: AgentToolCallEvent): void;
|
|
77
|
+
export declare function publishAgentQuotaExceeded(payload: AgentQuotaExceeded): void;
|
|
78
|
+
export declare function publishAgentRunFinished(payload: AgentRunFinished): void;
|
|
79
|
+
export declare function publishAgentDelegated(payload: AgentDelegated): void;
|
|
80
|
+
export declare function publishAgentRetrieved(payload: AgentRetrieved): void;
|
|
81
|
+
export declare function publishAgentToolRetry(payload: AgentToolRetry): void;
|
|
82
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/diagnostics.ts"],"names":[],"mappings":"AAYA,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB;AACD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AACD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AACD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,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,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAE3E;AACD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAEvE;AACD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAEnE;AACD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAEnE;AACD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAEnE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@adonis-agora/diagnostics` emit capability, published on this global slot at that package's
|
|
3
|
+
* module load. `@adonis-agora/agent` reads it STRUCTURALLY — it never imports or depends on the
|
|
4
|
+
* diagnostics package. When diagnostics isn't installed the slot is empty and emitting is an inert
|
|
5
|
+
* no-op that never throws back into the agent loop.
|
|
6
|
+
*
|
|
7
|
+
* Events land on `agora:agent:<event>`; the payload shapes below are the contract every consumer
|
|
8
|
+
* (dashboard / telescope) reads.
|
|
9
|
+
*/
|
|
10
|
+
const EMIT_SLOT = Symbol.for('@agora/diagnostics:emit');
|
|
11
|
+
/**
|
|
12
|
+
* Publish an agent event on `agora:agent:<event>` via the structural diagnostics slot. No-op when
|
|
13
|
+
* diagnostics isn't installed (the slot is empty) — and it never throws back into the agent loop.
|
|
14
|
+
*/
|
|
15
|
+
export function publishAgent(event, payload) {
|
|
16
|
+
const emit = globalThis[EMIT_SLOT];
|
|
17
|
+
if (typeof emit === 'function') {
|
|
18
|
+
try {
|
|
19
|
+
emit('agent', event, payload);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// diagnostics must never break an agent run
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function publishAgentRunStarted(payload) {
|
|
27
|
+
publishAgent('run.started', payload);
|
|
28
|
+
}
|
|
29
|
+
export function publishAgentMessage(payload) {
|
|
30
|
+
publishAgent('message', payload);
|
|
31
|
+
}
|
|
32
|
+
export function publishAgentToolCall(payload) {
|
|
33
|
+
publishAgent('tool-call', payload);
|
|
34
|
+
}
|
|
35
|
+
export function publishAgentQuotaExceeded(payload) {
|
|
36
|
+
publishAgent('quota.exceeded', payload);
|
|
37
|
+
}
|
|
38
|
+
export function publishAgentRunFinished(payload) {
|
|
39
|
+
publishAgent('run.finished', payload);
|
|
40
|
+
}
|
|
41
|
+
export function publishAgentDelegated(payload) {
|
|
42
|
+
publishAgent('delegated', payload);
|
|
43
|
+
}
|
|
44
|
+
export function publishAgentRetrieved(payload) {
|
|
45
|
+
publishAgent('retrieved', payload);
|
|
46
|
+
}
|
|
47
|
+
export function publishAgentToolRetry(payload) {
|
|
48
|
+
publishAgent('tool.retry', payload);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AA0ExD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAQ,EACR,OAAmC;IAEnC,MAAM,IAAI,GAAI,UAAsC,CAAC,SAAS,CAAuB,CAAC;IACtF,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,4CAA4C;QAC9C,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAwB;IAC7D,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC;AACD,MAAM,UAAU,mBAAmB,CAAC,OAA0B;IAC5D,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC;AACD,MAAM,UAAU,oBAAoB,CAAC,OAA2B;IAC9D,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AACD,MAAM,UAAU,yBAAyB,CAAC,OAA2B;IACnE,YAAY,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC;AACD,MAAM,UAAU,uBAAuB,CAAC,OAAyB;IAC/D,YAAY,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AACD,MAAM,UAAU,qBAAqB,CAAC,OAAuB;IAC3D,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AACD,MAAM,UAAU,qBAAqB,CAAC,OAAuB;IAC3D,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AACD,MAAM,UAAU,qBAAqB,CAAC,OAAuB;IAC3D,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AgentDepsFactory } from '../agent-deps-factory.js';
|
|
2
|
+
import type { AgentStore } from '../spi/agent-store.js';
|
|
3
|
+
/**
|
|
4
|
+
* The runtime graph the durable {@link import('./agent-run-workflow.js').AgentRunWorkflow} body needs.
|
|
5
|
+
*
|
|
6
|
+
* A durable workflow class is instantiated by the engine with NO constructor arguments (see the
|
|
7
|
+
* durable lib's `registerWorkflowClass`), so — unlike the NestJS reference, which injected these via
|
|
8
|
+
* DI — the AdonisJS workflow reads them from this module-level holder instead. The provider populates
|
|
9
|
+
* it once at boot (and a test sets it directly), mirroring the durable lib's own
|
|
10
|
+
* `setWorkflowEngineResolver` seam. Re-read on every replay (it's a pure lookup, no side effect), so
|
|
11
|
+
* it stays deterministic.
|
|
12
|
+
*/
|
|
13
|
+
export interface DurableAgentContext {
|
|
14
|
+
factory: AgentDepsFactory;
|
|
15
|
+
store: AgentStore;
|
|
16
|
+
}
|
|
17
|
+
/** Install (or clear, with `undefined`) the durable agent context. Called by the provider at boot. */
|
|
18
|
+
export declare function setDurableAgentContext(context: DurableAgentContext | undefined): void;
|
|
19
|
+
/**
|
|
20
|
+
* The installed {@link DurableAgentContext}. Throws if the durable runner was reached without the
|
|
21
|
+
* provider having wired it — a misconfiguration, never a normal path.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDurableAgentContext(): DurableAgentContext;
|
|
24
|
+
//# sourceMappingURL=agent-run-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-run-context.d.ts","sourceRoot":"","sources":["../../../src/durable/agent-run-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,gBAAgB,CAAC;IAC1B,KAAK,EAAE,UAAU,CAAC;CACnB;AAID,sGAAsG;AACtG,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,GAAG,IAAI,CAErF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,mBAAmB,CAQ5D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
let current;
|
|
2
|
+
/** Install (or clear, with `undefined`) the durable agent context. Called by the provider at boot. */
|
|
3
|
+
export function setDurableAgentContext(context) {
|
|
4
|
+
current = context;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The installed {@link DurableAgentContext}. Throws if the durable runner was reached without the
|
|
8
|
+
* provider having wired it — a misconfiguration, never a normal path.
|
|
9
|
+
*/
|
|
10
|
+
export function getDurableAgentContext() {
|
|
11
|
+
if (current === undefined) {
|
|
12
|
+
throw new Error('[@adonis-agora/agent] durable agent context is not set — the durable runner was used before ' +
|
|
13
|
+
'the provider wired it (call setDurableAgentContext during boot).');
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=agent-run-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-run-context.js","sourceRoot":"","sources":["../../../src/durable/agent-run-context.ts"],"names":[],"mappings":"AAkBA,IAAI,OAAwC,CAAC;AAE7C,sGAAsG;AACtG,MAAM,UAAU,sBAAsB,CAAC,OAAwC;IAC7E,OAAO,GAAG,OAAO,CAAC;AACpB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IACpC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,8FAA8F;YAC5F,kEAAkE,CACrE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type WorkflowCtx } from '@adonis-agora/durable';
|
|
2
|
+
import type { AgentRunInput } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The workflow input. A superset of {@link AgentRunInput} carrying the two fields only the durable
|
|
5
|
+
* runner threads:
|
|
6
|
+
* - `sinkRunId` — the TOP-LEVEL run whose live stream this run writes into. A sub-agent (child
|
|
7
|
+
* workflow) forwards its tokens into its ancestor's sink so the human watching the parent sees
|
|
8
|
+
* the delegate's output; a top-level run leaves it unset (it owns its own sink, keyed by runId).
|
|
9
|
+
* - `delegationDepth` — how many delegations deep this run is (0 for top-level), carried so a future
|
|
10
|
+
* guard can cap runaway sub-agent chains.
|
|
11
|
+
*/
|
|
12
|
+
export interface DurableAgentRunInput extends AgentRunInput {
|
|
13
|
+
sinkRunId?: string;
|
|
14
|
+
delegationDepth?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The agent turn AS a durable workflow — the replay-safe counterpart of `InlineAgentRunner`. The
|
|
18
|
+
* shared `runAgentLoop` body drives model→tools→model exactly as inline; the durable hooks make it
|
|
19
|
+
* suspend-and-resume:
|
|
20
|
+
* - `step(name, fn)` → `ctx.localStep` — every LLM turn, tool execution, and persist/quota write is a
|
|
21
|
+
* checkpoint, so a replay returns the cached result instead of re-running it (stable ids, no
|
|
22
|
+
* double-write, no re-streamed tokens).
|
|
23
|
+
* - `awaitApproval(call)` → `ctx.waitForSignal('tool:<runId>:<callId>')` — an action tool suspends the
|
|
24
|
+
* run with zero compute until an approve/reject signal arrives (namespaced by run, so one run's
|
|
25
|
+
* decision can never satisfy another's).
|
|
26
|
+
* - `runAgent(name, task)` → `ctx.child(AgentRunWorkflow, …)` — sub-agent delegation is a tracked,
|
|
27
|
+
* replay-safe CHILD run (a node in the durable dashboard) that streams into the top-level sink.
|
|
28
|
+
* - `openSink()` → the run's own sink writer (top-level) or a {@link childSinkWriter} (a child).
|
|
29
|
+
*
|
|
30
|
+
* Instantiated by the engine with no arguments; its deps come from {@link getDurableAgentContext}.
|
|
31
|
+
*/
|
|
32
|
+
export declare class AgentRunWorkflow {
|
|
33
|
+
run(ctx: WorkflowCtx, input: DurableAgentRunInput): Promise<{
|
|
34
|
+
text: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=agent-run-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-run-workflow.d.ts","sourceRoot":"","sources":["../../../src/durable/agent-run-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EAEjB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AAG3D;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AA+BD;;;;;;;;;;;;;;;GAeG;AACH,qBACa,gBAAgB;IACrB,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAuEpF"}
|