@adonis-agora/agent 0.34.0 → 0.35.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +34 -0
  3. package/dist/assets/spa/assets/index-7XqfoeQH.js +9 -0
  4. package/dist/assets/spa/index.html +1 -1
  5. package/dist/providers/agent_provider.d.ts.map +1 -1
  6. package/dist/providers/agent_provider.js +4 -0
  7. package/dist/providers/agent_provider.js.map +1 -1
  8. package/dist/src/agent-deps-factory.d.ts +5 -0
  9. package/dist/src/agent-deps-factory.d.ts.map +1 -1
  10. package/dist/src/agent-deps-factory.js +6 -0
  11. package/dist/src/agent-deps-factory.js.map +1 -1
  12. package/dist/src/agent-deps.d.ts +5 -0
  13. package/dist/src/agent-deps.d.ts.map +1 -1
  14. package/dist/src/agent-deps.js.map +1 -1
  15. package/dist/src/define_config.d.ts +12 -0
  16. package/dist/src/define_config.d.ts.map +1 -1
  17. package/dist/src/define_config.js.map +1 -1
  18. package/dist/src/guardrails/agent.d.ts +211 -0
  19. package/dist/src/guardrails/agent.d.ts.map +1 -0
  20. package/dist/src/guardrails/agent.js +433 -0
  21. package/dist/src/guardrails/agent.js.map +1 -0
  22. package/dist/src/guardrails/detectors/custom.d.ts +9 -0
  23. package/dist/src/guardrails/detectors/custom.d.ts.map +1 -0
  24. package/dist/src/guardrails/detectors/custom.js +81 -0
  25. package/dist/src/guardrails/detectors/custom.js.map +1 -0
  26. package/dist/src/guardrails/detectors/injection.d.ts +23 -0
  27. package/dist/src/guardrails/detectors/injection.d.ts.map +1 -0
  28. package/dist/src/guardrails/detectors/injection.js +208 -0
  29. package/dist/src/guardrails/detectors/injection.js.map +1 -0
  30. package/dist/src/guardrails/detectors/pii.d.ts +23 -0
  31. package/dist/src/guardrails/detectors/pii.d.ts.map +1 -0
  32. package/dist/src/guardrails/detectors/pii.js +295 -0
  33. package/dist/src/guardrails/detectors/pii.js.map +1 -0
  34. package/dist/src/guardrails/detectors/secrets.d.ts +5 -0
  35. package/dist/src/guardrails/detectors/secrets.d.ts.map +1 -0
  36. package/dist/src/guardrails/detectors/secrets.js +110 -0
  37. package/dist/src/guardrails/detectors/secrets.js.map +1 -0
  38. package/dist/src/guardrails/detectors/tool-poisoning.d.ts +16 -0
  39. package/dist/src/guardrails/detectors/tool-poisoning.d.ts.map +1 -0
  40. package/dist/src/guardrails/detectors/tool-poisoning.js +116 -0
  41. package/dist/src/guardrails/detectors/tool-poisoning.js.map +1 -0
  42. package/dist/src/guardrails/engine.d.ts +90 -0
  43. package/dist/src/guardrails/engine.d.ts.map +1 -0
  44. package/dist/src/guardrails/engine.js +324 -0
  45. package/dist/src/guardrails/engine.js.map +1 -0
  46. package/dist/src/guardrails/glob.d.ts +4 -0
  47. package/dist/src/guardrails/glob.d.ts.map +1 -0
  48. package/dist/src/guardrails/glob.js +20 -0
  49. package/dist/src/guardrails/glob.js.map +1 -0
  50. package/dist/src/guardrails/index.d.ts +20 -0
  51. package/dist/src/guardrails/index.d.ts.map +1 -0
  52. package/dist/src/guardrails/index.js +20 -0
  53. package/dist/src/guardrails/index.js.map +1 -0
  54. package/dist/src/guardrails/segments.d.ts +14 -0
  55. package/dist/src/guardrails/segments.d.ts.map +1 -0
  56. package/dist/src/guardrails/segments.js +32 -0
  57. package/dist/src/guardrails/segments.js.map +1 -0
  58. package/dist/src/guardrails/types.d.ts +161 -0
  59. package/dist/src/guardrails/types.d.ts.map +1 -0
  60. package/dist/src/guardrails/types.js +49 -0
  61. package/dist/src/guardrails/types.js.map +1 -0
  62. package/dist/src/guardrails/vault.d.ts +44 -0
  63. package/dist/src/guardrails/vault.d.ts.map +1 -0
  64. package/dist/src/guardrails/vault.js +103 -0
  65. package/dist/src/guardrails/vault.js.map +1 -0
  66. package/dist/src/index.d.ts +1 -1
  67. package/dist/src/index.js +1 -1
  68. package/dist/src/mcp-client/index.d.ts +1 -1
  69. package/dist/src/mcp-client/index.d.ts.map +1 -1
  70. package/dist/src/mcp-client/index.js.map +1 -1
  71. package/dist/src/mcp-client/options.d.ts +32 -0
  72. package/dist/src/mcp-client/options.d.ts.map +1 -1
  73. package/dist/src/mcp-client/tool-source.d.ts +2 -0
  74. package/dist/src/mcp-client/tool-source.d.ts.map +1 -1
  75. package/dist/src/mcp-client/tool-source.js +27 -1
  76. package/dist/src/mcp-client/tool-source.js.map +1 -1
  77. package/dist/src/rag/http-reranker.d.ts +46 -0
  78. package/dist/src/rag/http-reranker.d.ts.map +1 -0
  79. package/dist/src/rag/http-reranker.js +83 -0
  80. package/dist/src/rag/http-reranker.js.map +1 -0
  81. package/dist/src/rag/hybrid-retriever.d.ts +6 -1
  82. package/dist/src/rag/hybrid-retriever.d.ts.map +1 -1
  83. package/dist/src/rag/hybrid-retriever.js +27 -3
  84. package/dist/src/rag/hybrid-retriever.js.map +1 -1
  85. package/dist/src/rag/index.d.ts +5 -2
  86. package/dist/src/rag/index.d.ts.map +1 -1
  87. package/dist/src/rag/index.js +5 -2
  88. package/dist/src/rag/index.js.map +1 -1
  89. package/dist/src/rag/lexical-retriever.d.ts +23 -0
  90. package/dist/src/rag/lexical-retriever.d.ts.map +1 -0
  91. package/dist/src/rag/lexical-retriever.js +28 -0
  92. package/dist/src/rag/lexical-retriever.js.map +1 -0
  93. package/dist/src/rag/openai-embeddings.d.ts +62 -0
  94. package/dist/src/rag/openai-embeddings.d.ts.map +1 -0
  95. package/dist/src/rag/openai-embeddings.js +106 -0
  96. package/dist/src/rag/openai-embeddings.js.map +1 -0
  97. package/dist/src/rag/pg-vector-store.d.ts +111 -6
  98. package/dist/src/rag/pg-vector-store.d.ts.map +1 -1
  99. package/dist/src/rag/pg-vector-store.js +224 -31
  100. package/dist/src/rag/pg-vector-store.js.map +1 -1
  101. package/dist/src/rag/vector-store.d.ts +15 -0
  102. package/dist/src/rag/vector-store.d.ts.map +1 -1
  103. package/dist/src/rag/vector-store.js +4 -0
  104. package/dist/src/rag/vector-store.js.map +1 -1
  105. package/dist/src/stores/factory.d.ts +25 -3
  106. package/dist/src/stores/factory.d.ts.map +1 -1
  107. package/dist/src/stores/factory.js +21 -3
  108. package/dist/src/stores/factory.js.map +1 -1
  109. package/dist/src/testing/fake-embedding-provider.d.ts +12 -0
  110. package/dist/src/testing/fake-embedding-provider.d.ts.map +1 -1
  111. package/dist/src/testing/fake-embedding-provider.js +35 -0
  112. package/dist/src/testing/fake-embedding-provider.js.map +1 -1
  113. package/dist/src/testing/index.d.ts +1 -1
  114. package/dist/src/testing/index.d.ts.map +1 -1
  115. package/dist/src/testing/index.js +1 -1
  116. package/dist/src/testing/index.js.map +1 -1
  117. package/package.json +14 -8
  118. package/dist/assets/spa/assets/index-DjIMQOxi.js +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @adonis-agora/agent
2
2
 
3
+ ## 0.35.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#186](https://github.com/DavideCarvalho/adonis-agora-agent/pull/186) [`e7d75e1`](https://github.com/DavideCarvalho/adonis-agora-agent/commit/e7d75e1f1e931d5071de94d5f9d207eb83c76c42) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Guardrails, and processors you can actually configure
8
+
9
+ - **`@adonis-agora/agent/guardrails`** — PII (Luhn-validated cards, CPF/CNPJ, SSN, IBAN, phones, emails, IPv4), secret (provider key formats, JWT, PEM, entropy-gated assignments), prompt-injection (EN / PT-BR / ES, hidden Unicode, encoded payloads) and tool-poisoning detectors; a rule engine with `allow`/`log`/`redact`/`approve`/`block`, fail modes and reversible redaction (`Vault`); and `createGuardrails(options)`, which runs it on the loop's processor seams — `guardrails.input` / `guardrails.output`, `wrapTool` for tool arguments, `screenTool` for tool definitions — with per-call rule resolution (per tenant) and an audit hook. A port of `@dudousxd/nestjs-agent-core/guardrails`.
10
+ - **`inputProcessors` / `outputProcessors` in `config/agent.ts`.** The loop has taken processors since they were ported, but nothing between the config and the loop carried them, so an app using the provider could not register one. They now reach every agent's turn, inline and durable.
11
+ - **`mcpServers[].screen`** — inspect each listed tool definition before it is imported, and skip the ones it refuses (a screen that throws skips the tool too).
12
+
13
+ - [#185](https://github.com/DavideCarvalho/adonis-agora-agent/pull/185) [`2f4fc8c`](https://github.com/DavideCarvalho/adonis-agora-agent/commit/2f4fc8cf865e1b310280a40e2df91ed7f72caf93) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - First-party HTTP embedding and rerank adapters
14
+
15
+ New `openAiEmbeddings` — an `EmbeddingProvider` over any OpenAI-compatible `/v1/embeddings` (OpenAI, gateways, TEI, Ollama, vLLM), with `embedWithUsage` so embedding spend reaches the ledger and quota — and `HttpReranker`, a `Reranker` over Cohere/Jina/Voyage/TEI-style `/rerank`. Both are dependency-free and throw `HttpModelError`. `@adonis-agora/agent/testing` adds `hashedEmbeddings(dimensions)`, a deterministic Unicode-aware hashed embedder.
16
+
17
+ - [#184](https://github.com/DavideCarvalho/adonis-agora-agent/pull/184) [`1b8cc02`](https://github.com/DavideCarvalho/adonis-agora-agent/commit/1b8cc02fc447841e01bd58219e5c674413b46cc1) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - pgvector: batched upserts, full-text hybrid search, mixed dimensions
18
+
19
+ `PgVectorStore` now upserts in multi-row `INSERT … ON CONFLICT` statements (`upsertBatchSize`, default 100; duplicate ids in one call keep the last), and gains opt-in `nullableEmbeddings` (`embedding: []` → `NULL`), mixed-dimension tables (`dimension: [768, 1536]`, one partial HNSW index per width, searches compare like with like), and pgvector ≥ 0.8 `iterativeScan` / `efSearch` (`SET LOCAL` inside a Lucid transaction, skipped on older pgvector). New `PgLexicalVectorStore` (Postgres full-text `searchText`), `LexicalVectorStore` / `isLexicalVectorStore` and `LexicalRetriever`; `retrievers.pgvector({ fullText: {} })` returns a `HybridRetriever` of both legs. `HybridRetriever` gains `retrieveWithUsage`, so embedding spend from its legs still reaches the ledger. Everything is off by default.
20
+
21
+ ## 0.34.1
22
+
23
+ ### Patch Changes
24
+
25
+ - fix(deps): update dependency @modelcontextprotocol/sdk to v1.30.1 ([#180](https://github.com/DavideCarvalho/adonis-agora-agent/issues/180))
26
+
3
27
  ## 0.34.0
4
28
 
5
29
  ### Minor Changes
package/README.md CHANGED
@@ -152,6 +152,40 @@ export const executeSql = dataTool({
152
152
  })
153
153
  ```
154
154
 
155
+ ### Guardrails — PII, secrets, prompt injection, tool poisoning
156
+
157
+ `@adonis-agora/agent/guardrails` puts detectors and a rule engine on the loop's processor seams,
158
+ which `config/agent.ts` now takes as `inputProcessors` / `outputProcessors`:
159
+
160
+ ```ts
161
+ // config/agent.ts
162
+ import { createGuardrails } from '@adonis-agora/agent/guardrails'
163
+
164
+ const guardrails = createGuardrails({
165
+ pii: 'redact', // reversible: the model sees [EMAIL_1], the reader the address
166
+ secrets: 'block',
167
+ injection: { threshold: 0.6 }, // the prompt and every tool result; default action: block
168
+ toolPoisoning: true, // guardrails.screenTool, for `mcpServers[].screen`
169
+ rules: (ctx) => rulesForTenant(ctx.actor?.tenantRef), // more rules, resolved per scan
170
+ onEvent: (event) => audit(event), // hits carry fingerprints, never values
171
+ })
172
+
173
+ export default defineConfig({
174
+ model: () => aiSdkModel(openai('gpt-4o-mini')),
175
+ inputProcessors: [guardrails.input],
176
+ outputProcessors: [guardrails.output],
177
+ mcpServers: [{ name: 'docs', transport: { type: 'http', url }, screen: (t) => guardrails.screenTool(t) }],
178
+ })
179
+ ```
180
+
181
+ A blocked prompt fails the run (`ProcessorFailedError` caused by a `GuardrailBlockedError`); a
182
+ blocked tool result is withheld and the turn goes on; a blocked answer or tool call is an
183
+ `OutputRejectedError`. `guardrails.wrapTool(name, handler)` restores placeholders into a tool's
184
+ arguments and runs the `tool_args` rules on them. The output processor declares `incremental`, so the
185
+ answer keeps streaming. The detectors (`detectPii` with Luhn/CPF/CNPJ/IBAN checks, `detectSecrets`,
186
+ `scoreInjection`, `scoreToolText`) and `scan` work on their own. Same code as
187
+ `@dudousxd/nestjs-agent-core/guardrails`, which also carries the raw OpenAI/Anthropic stream guard.
188
+
155
189
  ### Framework-agnostic core (no AdonisJS)
156
190
 
157
191
  `runAgentLoop(deps, input, hooks)` is the shared turn body both the in-process (`InlineAgentRunner`)