@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,92 @@
|
|
|
1
|
+
/** Thrown when no extractor is registered for a content type — ingestion treats it as "skip, don't index". */
|
|
2
|
+
export class UnsupportedContentTypeError extends Error {
|
|
3
|
+
contentType;
|
|
4
|
+
constructor(contentType) {
|
|
5
|
+
super(`No text extractor registered for content type "${contentType}"`);
|
|
6
|
+
this.contentType = contentType;
|
|
7
|
+
this.name = 'UnsupportedContentTypeError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A {@link TextExtractor} that dispatches by content type. Register exact types (`application/json`) or
|
|
12
|
+
* a whole family (`text/*`); an exact match always wins over a family. Unregistered types throw
|
|
13
|
+
* {@link UnsupportedContentTypeError}. This is the extension point for binary formats:
|
|
14
|
+
* `.register('application/pdf', pdfFn)` — the PDF/DOCX library stays entirely on the host side.
|
|
15
|
+
*/
|
|
16
|
+
export class MimeTextExtractor {
|
|
17
|
+
exact = new Map();
|
|
18
|
+
families = [];
|
|
19
|
+
register(contentType, fn) {
|
|
20
|
+
if (contentType.endsWith('/*')) {
|
|
21
|
+
// "text/*" → match anything starting "text/"
|
|
22
|
+
this.families.push({ prefix: contentType.slice(0, -1), fn });
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.exact.set(contentType.toLowerCase(), fn);
|
|
26
|
+
}
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
async extract(bytes, contentType) {
|
|
30
|
+
const normalized = normalizeContentType(contentType);
|
|
31
|
+
const fn = this.resolve(normalized);
|
|
32
|
+
if (fn === undefined) {
|
|
33
|
+
throw new UnsupportedContentTypeError(contentType);
|
|
34
|
+
}
|
|
35
|
+
return fn(bytes, normalized);
|
|
36
|
+
}
|
|
37
|
+
/** Whether a content type would resolve to an extractor (without reading bytes). */
|
|
38
|
+
supports(contentType) {
|
|
39
|
+
return this.resolve(normalizeContentType(contentType)) !== undefined;
|
|
40
|
+
}
|
|
41
|
+
resolve(contentType) {
|
|
42
|
+
const exact = this.exact.get(contentType);
|
|
43
|
+
if (exact !== undefined) {
|
|
44
|
+
return exact;
|
|
45
|
+
}
|
|
46
|
+
for (const family of this.families) {
|
|
47
|
+
if (contentType.startsWith(family.prefix)) {
|
|
48
|
+
return family.fn;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Strip any `; charset=…` parameter off a content type and lower-case it. */
|
|
55
|
+
export function normalizeContentType(contentType) {
|
|
56
|
+
return (contentType.split(';')[0] ?? contentType).trim().toLowerCase();
|
|
57
|
+
}
|
|
58
|
+
/** Decode bytes as UTF-8 — the extractor for `text/*` and JSON. */
|
|
59
|
+
export function decodeUtf8(bytes) {
|
|
60
|
+
return bytes.toString('utf8');
|
|
61
|
+
}
|
|
62
|
+
/** Decode UTF-8 then strip HTML: drop `<script>`/`<style>` bodies and tags, decode common entities. */
|
|
63
|
+
export function extractHtmlText(bytes) {
|
|
64
|
+
return bytes
|
|
65
|
+
.toString('utf8')
|
|
66
|
+
.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, ' ')
|
|
67
|
+
.replace(/<[^>]+>/g, ' ')
|
|
68
|
+
.replace(/ /gi, ' ')
|
|
69
|
+
.replace(/&/gi, '&')
|
|
70
|
+
.replace(/</gi, '<')
|
|
71
|
+
.replace(/>/gi, '>')
|
|
72
|
+
.replace(/"/gi, '"')
|
|
73
|
+
.replace(/�*39;|'/gi, "'")
|
|
74
|
+
.replace(/\s+/g, ' ')
|
|
75
|
+
.trim();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The default extractor: `text/plain`, `text/csv`, `text/markdown` (and the whole `text/*` family) plus
|
|
79
|
+
* `application/json` decode as UTF-8, `text/html` is tag-stripped, and everything else — PDF, DOCX,
|
|
80
|
+
* images — throws {@link UnsupportedContentTypeError} (so binary formats are skipped rather than indexed
|
|
81
|
+
* as garbage). Extend it for those: `.register('application/pdf', myPdfExtractor)`.
|
|
82
|
+
*/
|
|
83
|
+
export function defaultTextExtractor() {
|
|
84
|
+
return new MimeTextExtractor()
|
|
85
|
+
.register('text/html', extractHtmlText)
|
|
86
|
+
.register('text/plain', decodeUtf8)
|
|
87
|
+
.register('text/csv', decodeUtf8)
|
|
88
|
+
.register('text/markdown', decodeUtf8)
|
|
89
|
+
.register('text/*', decodeUtf8)
|
|
90
|
+
.register('application/json', decodeUtf8);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=text-extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-extractor.js","sourceRoot":"","sources":["../../../src/rag-media/text-extractor.ts"],"names":[],"mappings":"AAWA,8GAA8G;AAC9G,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC/B;IAArB,YAAqB,WAAmB;QACtC,KAAK,CAAC,kDAAkD,WAAW,GAAG,CAAC,CAAC;QADrD,gBAAW,GAAX,WAAW,CAAQ;QAEtC,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AAKD;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACX,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAC;IACrC,QAAQ,GAAwC,EAAE,CAAC;IAEpE,QAAQ,CAAC,WAAmB,EAAE,EAAa;QACzC,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,6CAA6C;YAC7C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/D,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,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;IACtC,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,KAAK;SACT,QAAQ,CAAC,MAAM,CAAC;SAChB,OAAO,CAAC,yCAAyC,EAAE,GAAG,CAAC;SACvD,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;SACxB,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;SACxB,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;SACxB,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC;SAChC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,IAAI,iBAAiB,EAAE;SAC3B,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC;SACtC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;SAClC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;SAChC,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;SACrC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;SAC9B,QAAQ,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The minimal Redis surface {@link import('./redis-token-stream-sink.js').RedisTokenStreamSink} needs.
|
|
3
|
+
*
|
|
4
|
+
* The host adapts its own driver (`@adonisjs/redis` / `ioredis`) to this interface — so this package
|
|
5
|
+
* pulls in NO Redis driver of its own (bring your own, exactly like the Lucid store adapters take a
|
|
6
|
+
* database handle). The `tokenSinks.redis()` factory ships an adapter over `@adonisjs/redis` that it
|
|
7
|
+
* imports lazily, so the driver only loads when the Redis sink is actually selected.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: `subscribe` needs a connection in subscriber mode; most drivers require a DEDICATED connection
|
|
10
|
+
* for that (a subscribed client can't run other commands). An adapter should use a separate connection
|
|
11
|
+
* for `subscribe` — the sink only calls `subscribe` from its own `subscribe()`.
|
|
12
|
+
*/
|
|
13
|
+
export interface RedisStreamClient {
|
|
14
|
+
/** Append `value` to the list at `key` (RPUSH). */
|
|
15
|
+
rpush(key: string, value: string): Promise<void>;
|
|
16
|
+
/** The list elements at `key` from `start` to `stop` inclusive; negative indices count from the end (LRANGE). */
|
|
17
|
+
lrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
18
|
+
/** Set `key` to `value` (SET) — used for the terminal marker. */
|
|
19
|
+
set(key: string, value: string): Promise<void>;
|
|
20
|
+
/** The value at `key`, or `null` if unset (GET). */
|
|
21
|
+
get(key: string): Promise<string | null>;
|
|
22
|
+
/** Publish `message` on `channel` (PUBLISH). */
|
|
23
|
+
publish(channel: string, message: string): Promise<void>;
|
|
24
|
+
/** Subscribe to `channel`, invoking `onMessage` per message. Resolves to an unsubscribe function. */
|
|
25
|
+
subscribe(channel: string, onMessage: (message: string) => void): Promise<() => Promise<void>>;
|
|
26
|
+
/** Delete the given keys (DEL). */
|
|
27
|
+
del(...keys: string[]): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=redis-stream-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-stream-client.d.ts","sourceRoot":"","sources":["../../src/redis-stream-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB;IAChC,mDAAmD;IACnD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,iHAAiH;IACjH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACpE,iEAAiE;IACjE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,oDAAoD;IACpD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,gDAAgD;IAChD,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,qGAAqG;IACrG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/F,mCAAmC;IACnC,GAAG,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-stream-client.js","sourceRoot":"","sources":["../../src/redis-stream-client.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { RedisStreamClient } from './redis-stream-client.js';
|
|
2
|
+
import type { SinkWriter, TokenStreamSink } from './spi/token-stream-sink.js';
|
|
3
|
+
export interface RedisTokenStreamSinkOptions {
|
|
4
|
+
/** Key/channel namespace. Defaults to `agent:stream`. Keys are `${keyPrefix}:${runId}:...`. */
|
|
5
|
+
keyPrefix?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A multi-replica {@link TokenStreamSink} over Redis — the shared-transport counterpart to the default
|
|
9
|
+
* {@link import('./in-process-sink.js').InProcessTokenStreamSink}. The replica running the model turn
|
|
10
|
+
* `open`s the writer and appends each token chunk to a Redis LIST (`${keyPrefix}:${runId}:chunks`) so
|
|
11
|
+
* ANY replica can replay the whole stream so far (the same late-subscriber/reconnect guarantee the
|
|
12
|
+
* in-process sink gives, but shared across pods), and PUBLISHes to a per-run channel
|
|
13
|
+
* (`${keyPrefix}:${runId}`) to wake live subscribers. The run's terminal state lives in a marker key
|
|
14
|
+
* (`${keyPrefix}:${runId}:state`), so an SSE handler on ANOTHER replica that subscribes after the run
|
|
15
|
+
* finished still sees the ending and closes the stream.
|
|
16
|
+
*
|
|
17
|
+
* The yielded chunks are byte-identical to the in-process sink's, so the SSE envelope the provider
|
|
18
|
+
* pipes (`data: {"delta":...}`) is unchanged — swapping this in is transparent to clients.
|
|
19
|
+
*
|
|
20
|
+
* The host supplies a {@link RedisStreamClient} adapter over its own Redis driver; `subscribe` needs a
|
|
21
|
+
* connection in subscriber mode (see the client docs). Wire it with `defineConfig({ sink:
|
|
22
|
+
* tokenSinks.redis({...}) })`, which builds the adapter over `@adonisjs/redis` lazily.
|
|
23
|
+
*/
|
|
24
|
+
export declare class RedisTokenStreamSink implements TokenStreamSink {
|
|
25
|
+
private readonly client;
|
|
26
|
+
private readonly keyPrefix;
|
|
27
|
+
constructor(client: RedisStreamClient, options?: RedisTokenStreamSinkOptions);
|
|
28
|
+
private chunksKey;
|
|
29
|
+
private stateKey;
|
|
30
|
+
private channel;
|
|
31
|
+
open(runId: string): SinkWriter;
|
|
32
|
+
subscribe(runId: string): AsyncIterable<Uint8Array>;
|
|
33
|
+
close(runId: string): Promise<void>;
|
|
34
|
+
private hasEnded;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=redis-token-stream-sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-token-stream-sink.d.ts","sourceRoot":"","sources":["../../src/redis-token-stream-sink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAK9E,MAAM,WAAW,2BAA2B;IAC1C,+FAA+F;IAC/F,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,oBAAqB,YAAW,eAAe;IAIxD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAGhB,MAAM,EAAE,iBAAiB,EAC1C,OAAO,GAAE,2BAAgC;IAK3C,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,OAAO;IAIf,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAaxB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC;IAgCpD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAI3B,QAAQ;CAIvB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** Marker stored at the state key once a run's stream has finished. */
|
|
2
|
+
const ENDED = 'ended';
|
|
3
|
+
/**
|
|
4
|
+
* A multi-replica {@link TokenStreamSink} over Redis — the shared-transport counterpart to the default
|
|
5
|
+
* {@link import('./in-process-sink.js').InProcessTokenStreamSink}. The replica running the model turn
|
|
6
|
+
* `open`s the writer and appends each token chunk to a Redis LIST (`${keyPrefix}:${runId}:chunks`) so
|
|
7
|
+
* ANY replica can replay the whole stream so far (the same late-subscriber/reconnect guarantee the
|
|
8
|
+
* in-process sink gives, but shared across pods), and PUBLISHes to a per-run channel
|
|
9
|
+
* (`${keyPrefix}:${runId}`) to wake live subscribers. The run's terminal state lives in a marker key
|
|
10
|
+
* (`${keyPrefix}:${runId}:state`), so an SSE handler on ANOTHER replica that subscribes after the run
|
|
11
|
+
* finished still sees the ending and closes the stream.
|
|
12
|
+
*
|
|
13
|
+
* The yielded chunks are byte-identical to the in-process sink's, so the SSE envelope the provider
|
|
14
|
+
* pipes (`data: {"delta":...}`) is unchanged — swapping this in is transparent to clients.
|
|
15
|
+
*
|
|
16
|
+
* The host supplies a {@link RedisStreamClient} adapter over its own Redis driver; `subscribe` needs a
|
|
17
|
+
* connection in subscriber mode (see the client docs). Wire it with `defineConfig({ sink:
|
|
18
|
+
* tokenSinks.redis({...}) })`, which builds the adapter over `@adonisjs/redis` lazily.
|
|
19
|
+
*/
|
|
20
|
+
export class RedisTokenStreamSink {
|
|
21
|
+
client;
|
|
22
|
+
keyPrefix;
|
|
23
|
+
constructor(client, options = {}) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
this.keyPrefix = options.keyPrefix ?? 'agent:stream';
|
|
26
|
+
}
|
|
27
|
+
chunksKey(runId) {
|
|
28
|
+
return `${this.keyPrefix}:${runId}:chunks`;
|
|
29
|
+
}
|
|
30
|
+
stateKey(runId) {
|
|
31
|
+
return `${this.keyPrefix}:${runId}:state`;
|
|
32
|
+
}
|
|
33
|
+
channel(runId) {
|
|
34
|
+
return `${this.keyPrefix}:${runId}`;
|
|
35
|
+
}
|
|
36
|
+
open(runId) {
|
|
37
|
+
return {
|
|
38
|
+
write: async (chunk) => {
|
|
39
|
+
await this.client.rpush(this.chunksKey(runId), toBase64(chunk));
|
|
40
|
+
await this.client.publish(this.channel(runId), 'chunk');
|
|
41
|
+
},
|
|
42
|
+
end: async () => {
|
|
43
|
+
await this.client.set(this.stateKey(runId), ENDED);
|
|
44
|
+
await this.client.publish(this.channel(runId), 'end');
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async *subscribe(runId) {
|
|
49
|
+
// Notify bridge: the pub/sub handler resolves the current `wake` promise so the drain loop
|
|
50
|
+
// re-reads the list. A promise is armed BEFORE each drain, so a publish arriving mid-drain is
|
|
51
|
+
// never lost.
|
|
52
|
+
let resolveWake = null;
|
|
53
|
+
const onMessage = () => {
|
|
54
|
+
const resolve = resolveWake;
|
|
55
|
+
resolveWake = null;
|
|
56
|
+
resolve?.();
|
|
57
|
+
};
|
|
58
|
+
const unsubscribe = await this.client.subscribe(this.channel(runId), onMessage);
|
|
59
|
+
try {
|
|
60
|
+
let index = 0;
|
|
61
|
+
while (true) {
|
|
62
|
+
const wake = new Promise((resolve) => {
|
|
63
|
+
resolveWake = resolve;
|
|
64
|
+
});
|
|
65
|
+
const chunks = await this.client.lrange(this.chunksKey(runId), index, -1);
|
|
66
|
+
for (const encoded of chunks) {
|
|
67
|
+
index += 1;
|
|
68
|
+
yield fromBase64(encoded);
|
|
69
|
+
}
|
|
70
|
+
if (await this.hasEnded(runId)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
await wake;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await unsubscribe();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async close(runId) {
|
|
81
|
+
await this.client.del(this.chunksKey(runId), this.stateKey(runId));
|
|
82
|
+
}
|
|
83
|
+
async hasEnded(runId) {
|
|
84
|
+
const raw = await this.client.get(this.stateKey(runId));
|
|
85
|
+
return raw === ENDED;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function toBase64(chunk) {
|
|
89
|
+
return Buffer.from(chunk).toString('base64');
|
|
90
|
+
}
|
|
91
|
+
function fromBase64(encoded) {
|
|
92
|
+
return new Uint8Array(Buffer.from(encoded, 'base64'));
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=redis-token-stream-sink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-token-stream-sink.js","sourceRoot":"","sources":["../../src/redis-token-stream-sink.ts"],"names":[],"mappings":"AAGA,uEAAuE;AACvE,MAAM,KAAK,GAAG,OAAO,CAAC;AAOtB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,oBAAoB;IAIZ;IAHF,SAAS,CAAS;IAEnC,YACmB,MAAyB,EAC1C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,CAAC,CAAC;QACxD,OAAO,GAAG,KAAK,KAAK,CAAC;IACvB,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,KAAiB;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,UAAU,CAAC,OAAe;IACjC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AgentDepsFactory } from '../agent-deps-factory.js';
|
|
2
|
+
import type { AgentRunner } from '../spi/agent-runner.js';
|
|
3
|
+
import type { AgentStore } from '../spi/agent-store.js';
|
|
4
|
+
import type { AgentRunInput, Decision } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Runs the agent turn in-process — the default runner (`durable: false`). HITL approval resolves a
|
|
7
|
+
* pending promise keyed run-namespaced by `${runId}:${toolCallId}`, so one run's decision can never
|
|
8
|
+
* satisfy another's pending action. Sub-agent delegation runs a nested loop; a nested sub-agent has
|
|
9
|
+
* no human to prompt, so its action tools are auto-declined rather than hang. Single-replica only —
|
|
10
|
+
* durable is the scaled path (deferred).
|
|
11
|
+
*/
|
|
12
|
+
export declare class InlineAgentRunner implements AgentRunner {
|
|
13
|
+
private readonly factory;
|
|
14
|
+
private readonly store;
|
|
15
|
+
private readonly pending;
|
|
16
|
+
constructor(factory: AgentDepsFactory, store: AgentStore);
|
|
17
|
+
start(input: AgentRunInput): Promise<{
|
|
18
|
+
runId: string;
|
|
19
|
+
}>;
|
|
20
|
+
signal(runId: string, toolCallId: string, decision: Decision): Promise<void>;
|
|
21
|
+
cancel(runId: string): Promise<void>;
|
|
22
|
+
private topLevelHooks;
|
|
23
|
+
/** Delegate to another agent as a nested in-process run (a transient sub-thread). */
|
|
24
|
+
private runNested;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=inline-agent-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-agent-runner.d.ts","sourceRoot":"","sources":["../../../src/runners/inline-agent-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAS,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAElE;;;;;;GAMG;AACH,qBAAa,iBAAkB,YAAW,WAAW;IAIjD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmD;gBAGxD,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,UAAU;IAG9B,KAAK,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAqBvD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5E,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1C,OAAO,CAAC,aAAa;IAerB,qFAAqF;YACvE,SAAS;CA2BxB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { utcDay } from '../agent-deps.js';
|
|
2
|
+
import { runAgentLoop } from '../agent-loop.js';
|
|
3
|
+
/**
|
|
4
|
+
* Runs the agent turn in-process — the default runner (`durable: false`). HITL approval resolves a
|
|
5
|
+
* pending promise keyed run-namespaced by `${runId}:${toolCallId}`, so one run's decision can never
|
|
6
|
+
* satisfy another's pending action. Sub-agent delegation runs a nested loop; a nested sub-agent has
|
|
7
|
+
* no human to prompt, so its action tools are auto-declined rather than hang. Single-replica only —
|
|
8
|
+
* durable is the scaled path (deferred).
|
|
9
|
+
*/
|
|
10
|
+
export class InlineAgentRunner {
|
|
11
|
+
factory;
|
|
12
|
+
store;
|
|
13
|
+
pending = new Map();
|
|
14
|
+
constructor(factory, store) {
|
|
15
|
+
this.factory = factory;
|
|
16
|
+
this.store = store;
|
|
17
|
+
}
|
|
18
|
+
async start(input) {
|
|
19
|
+
const runId = crypto.randomUUID();
|
|
20
|
+
const day = input.day ?? utcDay();
|
|
21
|
+
const deps = this.factory.forAgent(input.agentName);
|
|
22
|
+
const hooks = this.topLevelHooks(runId, deps, input.actor, day);
|
|
23
|
+
void runAgentLoop({ ...deps, day }, input, hooks).catch(async (error) => {
|
|
24
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
25
|
+
console.error(`[@adonis-agora/agent] run ${runId} failed: ${message}`);
|
|
26
|
+
// Settle the run's persisted outcome — the loop only records completions (it can't catch its
|
|
27
|
+
// own crash). First-terminal, so this can't clobber a completion that already landed.
|
|
28
|
+
await this.store.recordRunEnd({ runId, status: 'failed', error: message });
|
|
29
|
+
// Surface the failure on the live stream and close it, so a subscriber isn't left hanging.
|
|
30
|
+
const writer = await deps.sink.open(runId);
|
|
31
|
+
await writer.write(new TextEncoder().encode(`\n[error] ${message}`));
|
|
32
|
+
await writer.end();
|
|
33
|
+
});
|
|
34
|
+
return { runId };
|
|
35
|
+
}
|
|
36
|
+
async signal(runId, toolCallId, decision) {
|
|
37
|
+
const key = `${runId}:${toolCallId}`;
|
|
38
|
+
const resolve = this.pending.get(key);
|
|
39
|
+
if (resolve !== undefined) {
|
|
40
|
+
this.pending.delete(key);
|
|
41
|
+
resolve(decision);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async cancel(runId) {
|
|
45
|
+
// Best-effort: settle the run `cancelled` (first-terminal, so a completed run stays completed),
|
|
46
|
+
// then close the live stream so a subscriber isn't left hanging.
|
|
47
|
+
await this.store.recordRunEnd({ runId, status: 'cancelled' });
|
|
48
|
+
const deps = this.factory.forAgent();
|
|
49
|
+
const writer = await deps.sink.open(runId);
|
|
50
|
+
await writer.end();
|
|
51
|
+
}
|
|
52
|
+
topLevelHooks(runId, deps, actor, day) {
|
|
53
|
+
return {
|
|
54
|
+
runId,
|
|
55
|
+
durable: false,
|
|
56
|
+
openSink: () => deps.sink.open(runId),
|
|
57
|
+
awaitApproval: (call) => new Promise((resolve) => {
|
|
58
|
+
// Run-namespaced key: `${runId}:${toolCallId}` — one run can't approve another's tool call.
|
|
59
|
+
this.pending.set(`${runId}:${call.id}`, resolve);
|
|
60
|
+
}),
|
|
61
|
+
step: (_name, fn) => fn(),
|
|
62
|
+
runAgent: (agentName, task) => this.runNested(agentName, task, actor, day),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Delegate to another agent as a nested in-process run (a transient sub-thread). */
|
|
66
|
+
async runNested(agentName, task, actor, day) {
|
|
67
|
+
const subThread = await this.store.createThread({ actor, persona: 'default', transient: true });
|
|
68
|
+
const runId = crypto.randomUUID();
|
|
69
|
+
const deps = this.factory.forAgent(agentName);
|
|
70
|
+
const hooks = {
|
|
71
|
+
runId,
|
|
72
|
+
durable: false,
|
|
73
|
+
openSink: () => deps.sink.open(runId),
|
|
74
|
+
// A nested sub-agent has no human to ask — decline action tools rather than hang.
|
|
75
|
+
awaitApproval: async () => ({
|
|
76
|
+
approved: false,
|
|
77
|
+
reason: 'nested sub-agent cannot request human approval',
|
|
78
|
+
}),
|
|
79
|
+
step: (_name, fn) => fn(),
|
|
80
|
+
runAgent: (childName, childTask) => this.runNested(childName, childTask, actor, day),
|
|
81
|
+
};
|
|
82
|
+
return runAgentLoop({ ...deps, day }, { threadId: subThread.id, actor, userText: task, agentName, day }, hooks);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=inline-agent-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|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B,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC;SACrF,CAAC;QACF,OAAO,YAAY,CACjB,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,EAChB,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,EACjE,KAAK,CACN,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional read-side lookup from opaque `actorRef`s to human display labels.
|
|
3
|
+
*
|
|
4
|
+
* The agent store keeps an `actorRef` opaque by design (no FK into the host's user table — hosts own
|
|
5
|
+
* their own identity schema). That is fine for enforcement and accounting, but a governance/dashboard
|
|
6
|
+
* read surface showing a raw ref (`"u_8f21..."`) instead of a name is a poor experience. Binding an
|
|
7
|
+
* `ActorDirectory` via `defineConfig({ actorDirectory })` lets those surfaces resolve refs to labels;
|
|
8
|
+
* leaving it unbound just means they render the raw ref.
|
|
9
|
+
*
|
|
10
|
+
* This is the read-side dual of the {@link import('./actor-resolver.js').ActorResolver} write seam:
|
|
11
|
+
* the resolver turns an inbound request into an acting `Actor`, the directory turns a persisted
|
|
12
|
+
* `actorRef` back into something a human can read. Configure one with a factory (e.g.
|
|
13
|
+
* `actorDirectories.memory({ labels })`) or your own implementation over the host's user table.
|
|
14
|
+
*/
|
|
15
|
+
export interface ActorDirectory {
|
|
16
|
+
/**
|
|
17
|
+
* Resolve opaque actor refs to display labels. The returned map is keyed by the input ref; a ref
|
|
18
|
+
* with no known label may be omitted (callers fall back to rendering the raw ref). Never throws for
|
|
19
|
+
* an unknown ref — a missing entry is a normal, expected outcome.
|
|
20
|
+
*/
|
|
21
|
+
resolveDisplay(refs: readonly string[]): Promise<Record<string, string>>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=actor-directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor-directory.d.ts","sourceRoot":"","sources":["../../../src/spi/actor-directory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC1E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor-directory.js","sourceRoot":"","sources":["../../../src/spi/actor-directory.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Actor } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the acting {@link Actor} for an inbound request. This is the identity seam:
|
|
4
|
+
* the agent NEVER fabricates a caller. Configure one via `defineConfig({ actorResolver })`
|
|
5
|
+
* that reads your authenticated principal (Adonis `ctx.auth.user`, a verified session/JWT, ...).
|
|
6
|
+
*
|
|
7
|
+
* When no resolver is configured, the provider installs the `UnconfiguredActorResolver`, which
|
|
8
|
+
* throws on every request — an identity is never invented from a default. See `HeaderActorResolver`
|
|
9
|
+
* for a header-based resolver suitable for demos and gateways that strip/re-set the headers, and
|
|
10
|
+
* `AuthActorResolver` for reading Adonis's `ctx.auth.user`.
|
|
11
|
+
*
|
|
12
|
+
* `req` is the transport request object, typed `unknown` to keep core framework-agnostic;
|
|
13
|
+
* an AdonisJS app receives the `HttpContext`.
|
|
14
|
+
*/
|
|
15
|
+
export interface ActorResolver {
|
|
16
|
+
resolve(req: unknown): Actor | Promise<Actor>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=actor-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor-resolver.d.ts","sourceRoot":"","sources":["../../../src/spi/actor-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;CAC/C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AgentRunInput, Decision } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Runs an agent turn. Two impls exist:
|
|
4
|
+
* - InlineAgentRunner (default): the loop runs in-process — no extra dependencies. This is what
|
|
5
|
+
* `AGENT_RUNNER` binds to unless `durable: true` is set.
|
|
6
|
+
* - DurableAgentRunner (opt-in via `durable: true`): the turn is a `@dudousxd/nestjs-durable`
|
|
7
|
+
* `@Workflow`, so each model/tool call is a checkpointed step and HITL is `ctx.waitForSignal`.
|
|
8
|
+
*
|
|
9
|
+
* `start` ENQUEUES and returns immediately with the runId — the live tokens flow on the
|
|
10
|
+
* TokenStreamSink, not through this call.
|
|
11
|
+
*/
|
|
12
|
+
export interface AgentRunner {
|
|
13
|
+
start(input: AgentRunInput): Promise<{
|
|
14
|
+
runId: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** Deliver a HITL decision for a pending action tool call. */
|
|
17
|
+
signal(runId: string, toolCallId: string, decision: Decision): Promise<void>;
|
|
18
|
+
cancel(runId: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=agent-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-runner.d.ts","sourceRoot":"","sources":["../../../src/spi/agent-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE3D;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,8DAA8D;IAC9D,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7E,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Actor, MessageAttachment, MessageUsage, StoredMessage, ThreadDetail, ThreadSummary, ToolCallRequest, ToolCallStatus, ToolResult, UsagePurpose } from '../types.js';
|
|
2
|
+
export interface CreateThreadInput {
|
|
3
|
+
actor: Actor;
|
|
4
|
+
persona: string;
|
|
5
|
+
transient?: boolean;
|
|
6
|
+
title?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AppendMessageInput {
|
|
9
|
+
threadId: string;
|
|
10
|
+
role: StoredMessage['role'];
|
|
11
|
+
content: string;
|
|
12
|
+
persona?: string;
|
|
13
|
+
toolCalls?: ToolCallRequest[];
|
|
14
|
+
toolResults?: ToolResult[];
|
|
15
|
+
/** Files the user attached to this message (image/PDF); persisted with it and replayed to the model. */
|
|
16
|
+
attachments?: MessageAttachment[];
|
|
17
|
+
followUps?: string[];
|
|
18
|
+
usage?: MessageUsage;
|
|
19
|
+
/** The run (turn) this message belongs to, for run-detail assembly + trace deep-links. */
|
|
20
|
+
runId?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface RecordToolCallInput {
|
|
23
|
+
toolCallId: string;
|
|
24
|
+
messageId: string;
|
|
25
|
+
toolName: string;
|
|
26
|
+
toolType: 'read' | 'action';
|
|
27
|
+
input: unknown;
|
|
28
|
+
status: ToolCallStatus;
|
|
29
|
+
/** The run (turn) this tool call belongs to, for run-detail assembly + trace deep-links. */
|
|
30
|
+
runId?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface UpdateToolCallInput {
|
|
33
|
+
toolCallId: string;
|
|
34
|
+
status: ToolCallStatus;
|
|
35
|
+
output?: unknown;
|
|
36
|
+
error?: string;
|
|
37
|
+
executionMs?: number;
|
|
38
|
+
executedByRef?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface RecordUsageInput {
|
|
41
|
+
threadId: string;
|
|
42
|
+
actorRef: string;
|
|
43
|
+
messageId?: string;
|
|
44
|
+
modelId: string;
|
|
45
|
+
purpose: UsagePurpose;
|
|
46
|
+
usage: MessageUsage;
|
|
47
|
+
/** Provider-reported actual USD cost for this turn, when known (gateways report it). */
|
|
48
|
+
costUsd?: number;
|
|
49
|
+
/** The run (turn) this usage row belongs to, for run-detail assembly + trace deep-links. */
|
|
50
|
+
runId?: string;
|
|
51
|
+
}
|
|
52
|
+
/** A run's lifecycle status: created `running`, then settled once (terminal). */
|
|
53
|
+
export type AgentRunStatus = 'running' | 'completed' | 'failed' | 'cancelled';
|
|
54
|
+
/** Opens a run (turn) row at start — status `running`, `started_at` stamped by the store. */
|
|
55
|
+
export interface RecordRunStartInput {
|
|
56
|
+
runId: string;
|
|
57
|
+
threadId: string;
|
|
58
|
+
/** Acting identity; the store persists `actor.id` as `actor_ref` and `actor.tenantRef` as `tenant_ref`. */
|
|
59
|
+
actor: Actor;
|
|
60
|
+
/** The agent that handled the run; `null`/omitted for the default agent. */
|
|
61
|
+
agentName?: string;
|
|
62
|
+
/** True when the run executes as a replay-safe durable workflow, false for the inline runner. */
|
|
63
|
+
durable?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Settles a run's outcome (terminal). A store MUST apply this only while the run is still `running`
|
|
67
|
+
* (first terminal wins) so a late `completed` from the loop can never overwrite a `failed`/`cancelled`
|
|
68
|
+
* already recorded by the runner. `error` is set only for `failed`. Token/step/cost totals are the
|
|
69
|
+
* loop's run-level rollup on `completed`; a runner-recorded failure/cancel may omit them.
|
|
70
|
+
*/
|
|
71
|
+
export interface RecordRunEndInput {
|
|
72
|
+
runId: string;
|
|
73
|
+
status: Exclude<AgentRunStatus, 'running'>;
|
|
74
|
+
/** Epoch-ms finish time; defaults to now inside the store when omitted. */
|
|
75
|
+
finishedAt?: number;
|
|
76
|
+
stepCount?: number;
|
|
77
|
+
inputTokens?: number;
|
|
78
|
+
outputTokens?: number;
|
|
79
|
+
costUsd?: number;
|
|
80
|
+
error?: string;
|
|
81
|
+
}
|
|
82
|
+
/** ORM-agnostic persistence. Refs are string ids; adapters may add real relations. */
|
|
83
|
+
export interface AgentStore {
|
|
84
|
+
createThread(input: CreateThreadInput): Promise<ThreadSummary>;
|
|
85
|
+
getThread(threadId: string): Promise<ThreadDetail | null>;
|
|
86
|
+
listThreads(actorRef: string, limit?: number): Promise<ThreadSummary[]>;
|
|
87
|
+
softDeleteThread(threadId: string): Promise<void>;
|
|
88
|
+
forkThread(threadId: string, fromMessageId: string): Promise<ThreadSummary>;
|
|
89
|
+
setTitle(threadId: string, title: string): Promise<void>;
|
|
90
|
+
setActiveStream(threadId: string, runId: string | null): Promise<void>;
|
|
91
|
+
appendMessage(input: AppendMessageInput): Promise<StoredMessage>;
|
|
92
|
+
truncateFrom(threadId: string, messageId: string): Promise<void>;
|
|
93
|
+
recordToolCall(input: RecordToolCallInput): Promise<void>;
|
|
94
|
+
updateToolCall(input: UpdateToolCallInput): Promise<void>;
|
|
95
|
+
recordUsage(input: RecordUsageInput): Promise<void>;
|
|
96
|
+
quotaToday(actorRef: string, day: string): Promise<{
|
|
97
|
+
usedTokens: number;
|
|
98
|
+
}>;
|
|
99
|
+
/** Open a run (turn) row at start. Replay-safe: the loop calls it under a durable step. */
|
|
100
|
+
recordRunStart(input: RecordRunStartInput): Promise<void>;
|
|
101
|
+
/** Settle a run's outcome (terminal, first-wins). A no-op when the run is unknown or already settled. */
|
|
102
|
+
recordRunEnd(input: RecordRunEndInput): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=agent-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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