@rudderjs/ai 1.17.2 → 1.18.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/README.md +19 -1274
- package/dist/budget-orm/index.d.ts +1 -95
- package/dist/budget-orm/index.d.ts.map +1 -1
- package/dist/budget-orm/index.js +4 -176
- package/dist/budget-orm/index.js.map +1 -1
- package/dist/chat-mentions.d.ts +1 -58
- package/dist/chat-mentions.d.ts.map +1 -1
- package/dist/chat-mentions.js +4 -80
- package/dist/chat-mentions.js.map +1 -1
- package/dist/commands/ai-eval.d.ts +1 -92
- package/dist/commands/ai-eval.d.ts.map +1 -1
- package/dist/commands/ai-eval.js +4 -377
- package/dist/commands/ai-eval.js.map +1 -1
- package/dist/commands/make-agent.d.ts +1 -2
- package/dist/commands/make-agent.d.ts.map +1 -1
- package/dist/commands/make-agent.js +4 -22
- package/dist/commands/make-agent.js.map +1 -1
- package/dist/computer-use/index.d.ts +1 -52
- package/dist/computer-use/index.d.ts.map +1 -1
- package/dist/computer-use/index.js +4 -50
- package/dist/computer-use/index.js.map +1 -1
- package/dist/conversation-orm/index.d.ts +1 -108
- package/dist/conversation-orm/index.d.ts.map +1 -1
- package/dist/conversation-orm/index.js +4 -214
- package/dist/conversation-orm/index.js.map +1 -1
- package/dist/doctor.d.ts +1 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +4 -65
- package/dist/doctor.js.map +1 -1
- package/dist/eval/index.d.ts +1 -270
- package/dist/eval/index.d.ts.map +1 -1
- package/dist/eval/index.js +4 -509
- package/dist/eval/index.js.map +1 -1
- package/dist/gateway/index.d.ts +1 -10
- package/dist/gateway/index.d.ts.map +1 -1
- package/dist/gateway/index.js +4 -10
- package/dist/gateway/index.js.map +1 -1
- package/dist/index.d.ts +1 -66
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -78
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -15
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +4 -14
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory-embedding/index.d.ts +1 -120
- package/dist/memory-embedding/index.d.ts.map +1 -1
- package/dist/memory-embedding/index.js +4 -228
- package/dist/memory-embedding/index.js.map +1 -1
- package/dist/memory-orm/index.d.ts +1 -117
- package/dist/memory-orm/index.d.ts.map +1 -1
- package/dist/memory-orm/index.js +4 -186
- package/dist/memory-orm/index.js.map +1 -1
- package/dist/node/index.d.ts +1 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +4 -2
- package/dist/node/index.js.map +1 -1
- package/dist/observers.d.ts +1 -129
- package/dist/observers.d.ts.map +1 -1
- package/dist/observers.js +4 -39
- package/dist/observers.js.map +1 -1
- package/dist/react/index.d.ts +1 -15
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +4 -15
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -1
- package/dist/server/index.js.map +1 -1
- package/package.json +9 -13
- package/boost/guidelines.md +0 -260
- package/boost/skills/ai-agents/SKILL.md +0 -240
- package/boost/skills/ai-tools/SKILL.md +0 -260
- package/dist/agent-run-store.d.ts +0 -161
- package/dist/agent-run-store.d.ts.map +0 -1
- package/dist/agent-run-store.js +0 -98
- package/dist/agent-run-store.js.map +0 -1
- package/dist/agent-sse.d.ts +0 -153
- package/dist/agent-sse.d.ts.map +0 -1
- package/dist/agent-sse.js +0 -282
- package/dist/agent-sse.js.map +0 -1
- package/dist/agent.d.ts +0 -508
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js +0 -1538
- package/dist/agent.js.map +0 -1
- package/dist/attachment.d.ts +0 -31
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -89
- package/dist/attachment.js.map +0 -1
- package/dist/audio.d.ts +0 -45
- package/dist/audio.d.ts.map +0 -1
- package/dist/audio.js +0 -93
- package/dist/audio.js.map +0 -1
- package/dist/base64.d.ts +0 -7
- package/dist/base64.d.ts.map +0 -1
- package/dist/base64.js +0 -39
- package/dist/base64.js.map +0 -1
- package/dist/budget/pricing.d.ts +0 -124
- package/dist/budget/pricing.d.ts.map +0 -1
- package/dist/budget/pricing.js +0 -175
- package/dist/budget/pricing.js.map +0 -1
- package/dist/budget/storage.d.ts +0 -104
- package/dist/budget/storage.d.ts.map +0 -1
- package/dist/budget/storage.js +0 -0
- package/dist/budget/storage.js.map +0 -1
- package/dist/budget/with-budget.d.ts +0 -119
- package/dist/budget/with-budget.d.ts.map +0 -1
- package/dist/budget/with-budget.js +0 -175
- package/dist/budget/with-budget.js.map +0 -1
- package/dist/cached-embedding.d.ts +0 -14
- package/dist/cached-embedding.d.ts.map +0 -1
- package/dist/cached-embedding.js +0 -44
- package/dist/cached-embedding.js.map +0 -1
- package/dist/computer-use/actions.d.ts +0 -214
- package/dist/computer-use/actions.d.ts.map +0 -1
- package/dist/computer-use/actions.js +0 -48
- package/dist/computer-use/actions.js.map +0 -1
- package/dist/computer-use/errors.d.ts +0 -57
- package/dist/computer-use/errors.d.ts.map +0 -1
- package/dist/computer-use/errors.js +0 -76
- package/dist/computer-use/errors.js.map +0 -1
- package/dist/computer-use/playwright.d.ts +0 -76
- package/dist/computer-use/playwright.d.ts.map +0 -1
- package/dist/computer-use/playwright.js +0 -270
- package/dist/computer-use/playwright.js.map +0 -1
- package/dist/computer-use/tool.d.ts +0 -154
- package/dist/computer-use/tool.d.ts.map +0 -1
- package/dist/computer-use/tool.js +0 -210
- package/dist/computer-use/tool.js.map +0 -1
- package/dist/continuation-validation.d.ts +0 -85
- package/dist/continuation-validation.d.ts.map +0 -1
- package/dist/continuation-validation.js +0 -166
- package/dist/continuation-validation.js.map +0 -1
- package/dist/conversation-persistence.d.ts +0 -46
- package/dist/conversation-persistence.d.ts.map +0 -1
- package/dist/conversation-persistence.js +0 -176
- package/dist/conversation-persistence.js.map +0 -1
- package/dist/conversation.d.ts +0 -11
- package/dist/conversation.d.ts.map +0 -1
- package/dist/conversation.js +0 -55
- package/dist/conversation.js.map +0 -1
- package/dist/eval/fixtures.d.ts +0 -65
- package/dist/eval/fixtures.d.ts.map +0 -1
- package/dist/eval/fixtures.js +0 -110
- package/dist/eval/fixtures.js.map +0 -1
- package/dist/eval/html-reporter.d.ts +0 -25
- package/dist/eval/html-reporter.d.ts.map +0 -1
- package/dist/eval/html-reporter.js +0 -209
- package/dist/eval/html-reporter.js.map +0 -1
- package/dist/eval/json-reporter.d.ts +0 -43
- package/dist/eval/json-reporter.d.ts.map +0 -1
- package/dist/eval/json-reporter.js +0 -40
- package/dist/eval/json-reporter.js.map +0 -1
- package/dist/facade.d.ts +0 -96
- package/dist/facade.d.ts.map +0 -1
- package/dist/facade.js +0 -146
- package/dist/facade.js.map +0 -1
- package/dist/fake.d.ts +0 -201
- package/dist/fake.d.ts.map +0 -1
- package/dist/fake.js +0 -428
- package/dist/fake.js.map +0 -1
- package/dist/file-search.d.ts +0 -168
- package/dist/file-search.d.ts.map +0 -1
- package/dist/file-search.js +0 -158
- package/dist/file-search.js.map +0 -1
- package/dist/files.d.ts +0 -27
- package/dist/files.d.ts.map +0 -1
- package/dist/files.js +0 -44
- package/dist/files.js.map +0 -1
- package/dist/gateway/http-gateway-adapter.d.ts +0 -94
- package/dist/gateway/http-gateway-adapter.d.ts.map +0 -1
- package/dist/gateway/http-gateway-adapter.js +0 -106
- package/dist/gateway/http-gateway-adapter.js.map +0 -1
- package/dist/gateway/sse.d.ts +0 -28
- package/dist/gateway/sse.d.ts.map +0 -1
- package/dist/gateway/sse.js +0 -78
- package/dist/gateway/sse.js.map +0 -1
- package/dist/handoff.d.ts +0 -95
- package/dist/handoff.d.ts.map +0 -1
- package/dist/handoff.js +0 -78
- package/dist/handoff.js.map +0 -1
- package/dist/handoffs-driver.d.ts +0 -58
- package/dist/handoffs-driver.d.ts.map +0 -1
- package/dist/handoffs-driver.js +0 -103
- package/dist/handoffs-driver.js.map +0 -1
- package/dist/image.d.ts +0 -40
- package/dist/image.d.ts.map +0 -1
- package/dist/image.js +0 -109
- package/dist/image.js.map +0 -1
- package/dist/mcp/client-tools.d.ts +0 -39
- package/dist/mcp/client-tools.d.ts.map +0 -1
- package/dist/mcp/client-tools.js +0 -147
- package/dist/mcp/client-tools.js.map +0 -1
- package/dist/mcp/server-from-agent.d.ts +0 -24
- package/dist/mcp/server-from-agent.d.ts.map +0 -1
- package/dist/mcp/server-from-agent.js +0 -113
- package/dist/mcp/server-from-agent.js.map +0 -1
- package/dist/mcp/types.d.ts +0 -64
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/mcp/types.js +0 -6
- package/dist/mcp/types.js.map +0 -1
- package/dist/memory-extract.d.ts +0 -60
- package/dist/memory-extract.d.ts.map +0 -1
- package/dist/memory-extract.js +0 -163
- package/dist/memory-extract.js.map +0 -1
- package/dist/memory-inject.d.ts +0 -39
- package/dist/memory-inject.d.ts.map +0 -1
- package/dist/memory-inject.js +0 -135
- package/dist/memory-inject.js.map +0 -1
- package/dist/memory.d.ts +0 -55
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js +0 -132
- package/dist/memory.js.map +0 -1
- package/dist/middleware.d.ts +0 -18
- package/dist/middleware.d.ts.map +0 -1
- package/dist/middleware.js +0 -72
- package/dist/middleware.js.map +0 -1
- package/dist/node/attachment.d.ts +0 -6
- package/dist/node/attachment.d.ts.map +0 -1
- package/dist/node/attachment.js +0 -35
- package/dist/node/attachment.js.map +0 -1
- package/dist/node/transcription.d.ts +0 -4
- package/dist/node/transcription.d.ts.map +0 -1
- package/dist/node/transcription.js +0 -8
- package/dist/node/transcription.js.map +0 -1
- package/dist/output.d.ts +0 -22
- package/dist/output.d.ts.map +0 -1
- package/dist/output.js +0 -60
- package/dist/output.js.map +0 -1
- package/dist/provider-tools.d.ts +0 -87
- package/dist/provider-tools.d.ts.map +0 -1
- package/dist/provider-tools.js +0 -189
- package/dist/provider-tools.js.map +0 -1
- package/dist/providers/anthropic.d.ts +0 -24
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js +0 -405
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/azure.d.ts +0 -13
- package/dist/providers/azure.d.ts.map +0 -1
- package/dist/providers/azure.js +0 -15
- package/dist/providers/azure.js.map +0 -1
- package/dist/providers/bedrock.d.ts +0 -75
- package/dist/providers/bedrock.d.ts.map +0 -1
- package/dist/providers/bedrock.js +0 -181
- package/dist/providers/bedrock.js.map +0 -1
- package/dist/providers/cohere.d.ts +0 -13
- package/dist/providers/cohere.d.ts.map +0 -1
- package/dist/providers/cohere.js +0 -87
- package/dist/providers/cohere.js.map +0 -1
- package/dist/providers/deepseek.d.ts +0 -12
- package/dist/providers/deepseek.d.ts.map +0 -1
- package/dist/providers/deepseek.js +0 -15
- package/dist/providers/deepseek.js.map +0 -1
- package/dist/providers/elevenlabs.d.ts +0 -98
- package/dist/providers/elevenlabs.d.ts.map +0 -1
- package/dist/providers/elevenlabs.js +0 -229
- package/dist/providers/elevenlabs.js.map +0 -1
- package/dist/providers/google-cache-registry.d.ts +0 -132
- package/dist/providers/google-cache-registry.d.ts.map +0 -1
- package/dist/providers/google-cache-registry.js +0 -209
- package/dist/providers/google-cache-registry.js.map +0 -1
- package/dist/providers/google.d.ts +0 -38
- package/dist/providers/google.d.ts.map +0 -1
- package/dist/providers/google.js +0 -903
- package/dist/providers/google.js.map +0 -1
- package/dist/providers/groq.d.ts +0 -12
- package/dist/providers/groq.d.ts.map +0 -1
- package/dist/providers/groq.js +0 -15
- package/dist/providers/groq.js.map +0 -1
- package/dist/providers/jina.d.ts +0 -13
- package/dist/providers/jina.d.ts.map +0 -1
- package/dist/providers/jina.js +0 -90
- package/dist/providers/jina.js.map +0 -1
- package/dist/providers/mistral.d.ts +0 -13
- package/dist/providers/mistral.d.ts.map +0 -1
- package/dist/providers/mistral.js +0 -46
- package/dist/providers/mistral.js.map +0 -1
- package/dist/providers/ollama.d.ts +0 -11
- package/dist/providers/ollama.d.ts.map +0 -1
- package/dist/providers/ollama.js +0 -15
- package/dist/providers/ollama.js.map +0 -1
- package/dist/providers/openai.d.ts +0 -79
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js +0 -792
- package/dist/providers/openai.js.map +0 -1
- package/dist/providers/openrouter.d.ts +0 -43
- package/dist/providers/openrouter.d.ts.map +0 -1
- package/dist/providers/openrouter.js +0 -21
- package/dist/providers/openrouter.js.map +0 -1
- package/dist/providers/voyage.d.ts +0 -91
- package/dist/providers/voyage.d.ts.map +0 -1
- package/dist/providers/voyage.js +0 -166
- package/dist/providers/voyage.js.map +0 -1
- package/dist/providers/xai.d.ts +0 -12
- package/dist/providers/xai.d.ts.map +0 -1
- package/dist/providers/xai.js +0 -15
- package/dist/providers/xai.js.map +0 -1
- package/dist/queue-job.d.ts +0 -100
- package/dist/queue-job.d.ts.map +0 -1
- package/dist/queue-job.js +0 -185
- package/dist/queue-job.js.map +0 -1
- package/dist/react/agent-run.d.ts +0 -111
- package/dist/react/agent-run.d.ts.map +0 -1
- package/dist/react/agent-run.js +0 -107
- package/dist/react/agent-run.js.map +0 -1
- package/dist/react/useAgentRun.d.ts +0 -68
- package/dist/react/useAgentRun.d.ts.map +0 -1
- package/dist/react/useAgentRun.js +0 -125
- package/dist/react/useAgentRun.js.map +0 -1
- package/dist/registry.d.ts +0 -45
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -131
- package/dist/registry.js.map +0 -1
- package/dist/rerank.d.ts +0 -20
- package/dist/rerank.d.ts.map +0 -1
- package/dist/rerank.js +0 -40
- package/dist/rerank.js.map +0 -1
- package/dist/resume-approval.d.ts +0 -30
- package/dist/resume-approval.d.ts.map +0 -1
- package/dist/resume-approval.js +0 -147
- package/dist/resume-approval.js.map +0 -1
- package/dist/sanitize-conversation.d.ts +0 -43
- package/dist/sanitize-conversation.d.ts.map +0 -1
- package/dist/sanitize-conversation.js +0 -85
- package/dist/sanitize-conversation.js.map +0 -1
- package/dist/scoped-tool.d.ts +0 -98
- package/dist/scoped-tool.d.ts.map +0 -1
- package/dist/scoped-tool.js +0 -174
- package/dist/scoped-tool.js.map +0 -1
- package/dist/server/provider.d.ts +0 -22
- package/dist/server/provider.d.ts.map +0 -1
- package/dist/server/provider.js +0 -194
- package/dist/server/provider.js.map +0 -1
- package/dist/similarity-search.d.ts +0 -163
- package/dist/similarity-search.d.ts.map +0 -1
- package/dist/similarity-search.js +0 -147
- package/dist/similarity-search.js.map +0 -1
- package/dist/sub-agent-run-store.d.ts +0 -157
- package/dist/sub-agent-run-store.d.ts.map +0 -1
- package/dist/sub-agent-run-store.js +0 -87
- package/dist/sub-agent-run-store.js.map +0 -1
- package/dist/tool-execution.d.ts +0 -16
- package/dist/tool-execution.d.ts.map +0 -1
- package/dist/tool-execution.js +0 -498
- package/dist/tool-execution.js.map +0 -1
- package/dist/tool-helpers.d.ts +0 -77
- package/dist/tool-helpers.d.ts.map +0 -1
- package/dist/tool-helpers.js +0 -117
- package/dist/tool-helpers.js.map +0 -1
- package/dist/tool.d.ts +0 -216
- package/dist/tool.d.ts.map +0 -1
- package/dist/tool.js +0 -175
- package/dist/tool.js.map +0 -1
- package/dist/transcription.d.ts +0 -42
- package/dist/transcription.d.ts.map +0 -1
- package/dist/transcription.js +0 -77
- package/dist/transcription.js.map +0 -1
- package/dist/types.d.ts +0 -1020
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/util/hash.d.ts +0 -11
- package/dist/util/hash.d.ts.map +0 -1
- package/dist/util/hash.js +0 -23
- package/dist/util/hash.js.map +0 -1
- package/dist/vector-stores/index.d.ts +0 -96
- package/dist/vector-stores/index.d.ts.map +0 -1
- package/dist/vector-stores/index.js +0 -153
- package/dist/vector-stores/index.js.map +0 -1
- package/dist/vercel-protocol.d.ts +0 -18
- package/dist/vercel-protocol.d.ts.map +0 -1
- package/dist/vercel-protocol.js +0 -75
- package/dist/vercel-protocol.js.map +0 -1
- package/dist/zod-to-json-schema.d.ts +0 -16
- package/dist/zod-to-json-schema.d.ts.map +0 -1
- package/dist/zod-to-json-schema.js +0 -17
- package/dist/zod-to-json-schema.js.map +0 -1
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { AiMessage, ContinuationValidator, ValidateContinuationOptions } from './types.js';
|
|
2
|
-
export type { ContinuationValidator, ValidateContinuationOptions } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Continuation validation — defends the auto-persist / continuation path
|
|
5
|
-
* against a client that resubmits a forged conversation.
|
|
6
|
-
*
|
|
7
|
-
* `runWithPersistence` (and the explicit `forUser`/`continue` form) trusts
|
|
8
|
-
* the caller's incoming history. A continuation request after a client-tool
|
|
9
|
-
* or approval round-trip carries the prior messages back from the browser,
|
|
10
|
-
* which means a malicious caller can:
|
|
11
|
-
*
|
|
12
|
-
* 1. **Rewrite history / continue someone else's thread (IDOR)** — send
|
|
13
|
-
* messages that don't match what the server persisted for this thread.
|
|
14
|
-
* 2. **Forge a tool result** — append a `tool` message answering a tool
|
|
15
|
-
* call that the server never issued (smuggling attacker-chosen data in
|
|
16
|
-
* as if a tool produced it).
|
|
17
|
-
* 3. **Forge an approval** — claim `approvedToolCallIds` for a tool call
|
|
18
|
-
* that isn't actually pending approval.
|
|
19
|
-
*
|
|
20
|
-
* {@link validateContinuation} runs all three checks against the trusted
|
|
21
|
-
* `persisted` history and returns a verdict. {@link assertValidContinuation}
|
|
22
|
-
* throws {@link ContinuationValidationError} on failure, and
|
|
23
|
-
* {@link defaultContinuationValidator} adapts it to the
|
|
24
|
-
* {@link ContinuationValidator} hook shape consumed by `AgentPromptOptions`.
|
|
25
|
-
*/
|
|
26
|
-
export type ContinuationRejectionCode = 'not-a-prefix' | 'forged-tool-result' | 'forged-approval';
|
|
27
|
-
export interface ContinuationValidationResult {
|
|
28
|
-
/** `true` when the incoming continuation is a legitimate extension of `persisted`. */
|
|
29
|
-
ok: boolean;
|
|
30
|
-
/** Machine-readable reason, present only when `ok` is `false`. */
|
|
31
|
-
code?: ContinuationRejectionCode;
|
|
32
|
-
/** Human-readable explanation, present only when `ok` is `false`. */
|
|
33
|
-
reason?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Index of the offending message — into `incoming` for `not-a-prefix` and
|
|
36
|
-
* `forged-tool-result`. Absent for `forged-approval` (the offending id is
|
|
37
|
-
* named in `reason` instead).
|
|
38
|
-
*/
|
|
39
|
-
index?: number;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Validate that an `incoming` continuation is a legitimate extension of the
|
|
43
|
-
* server-persisted `persisted` history. Pure and synchronous — safe to call
|
|
44
|
-
* from any runtime. Returns a verdict; never throws.
|
|
45
|
-
*
|
|
46
|
-
* Checks, in order:
|
|
47
|
-
*
|
|
48
|
-
* - **Prefix equality.** Every message the two share by position must match
|
|
49
|
-
* (role, content, `toolCallId`, and any assistant `toolCalls`). Comparison
|
|
50
|
-
* is order-insensitive for nested objects, so a tool-call `arguments` map
|
|
51
|
-
* reordered across a serialization boundary still matches. A genuine
|
|
52
|
-
* mismatch means the caller rewrote history or is replaying a different
|
|
53
|
-
* thread (IDOR) → `not-a-prefix`.
|
|
54
|
-
* - **Tool-result forgery.** Every `tool` message in `incoming` must answer
|
|
55
|
-
* a tool call actually requested by some assistant message (in either
|
|
56
|
-
* `persisted` or `incoming`). A `tool` message with no matching request is
|
|
57
|
-
* smuggled data → `forged-tool-result`.
|
|
58
|
-
* - **Approval forgery.** Every id in `opts.approvedToolCallIds` /
|
|
59
|
-
* `opts.rejectedToolCallIds` must reference a real requested tool call →
|
|
60
|
-
* `forged-approval`.
|
|
61
|
-
*/
|
|
62
|
-
export declare function validateContinuation(persisted: readonly AiMessage[], incoming: readonly AiMessage[], opts?: ValidateContinuationOptions): ContinuationValidationResult;
|
|
63
|
-
/** Thrown by {@link assertValidContinuation} when validation fails. */
|
|
64
|
-
export declare class ContinuationValidationError extends Error {
|
|
65
|
-
readonly code: ContinuationRejectionCode;
|
|
66
|
-
readonly index: number | undefined;
|
|
67
|
-
constructor(result: ContinuationValidationResult);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* {@link validateContinuation} that throws {@link ContinuationValidationError}
|
|
71
|
-
* instead of returning a verdict. Use directly, or via
|
|
72
|
-
* {@link defaultContinuationValidator} as a `validate` hook.
|
|
73
|
-
*/
|
|
74
|
-
export declare function assertValidContinuation(persisted: readonly AiMessage[], incoming: readonly AiMessage[], opts?: ValidateContinuationOptions): void;
|
|
75
|
-
/**
|
|
76
|
-
* A ready-made {@link ContinuationValidator} backed by
|
|
77
|
-
* {@link assertValidContinuation}. Drop into `AgentPromptOptions.validate`
|
|
78
|
-
* for the default prefix + tool-result-forgery + approval-forgery gate:
|
|
79
|
-
*
|
|
80
|
-
* ```ts
|
|
81
|
-
* agent.continue(id).prompt(input, { validate: defaultContinuationValidator() })
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
export declare function defaultContinuationValidator(): ContinuationValidator;
|
|
85
|
-
//# sourceMappingURL=continuation-validation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"continuation-validation.d.ts","sourceRoot":"","sources":["../src/continuation-validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAY,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAEzG,YAAY,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAEpF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,MAAM,yBAAyB,GACjC,cAAc,GACd,oBAAoB,GACpB,iBAAiB,CAAA;AAErB,MAAM,WAAW,4BAA4B;IAC3C,sFAAsF;IACtF,EAAE,EAAE,OAAO,CAAA;IACX,kEAAkE;IAClE,IAAI,CAAC,EAAE,yBAAyB,CAAA;IAChC,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAmED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,SAAS,EAAE,EAC/B,QAAQ,EAAE,SAAS,SAAS,EAAE,EAC9B,IAAI,GAAE,2BAAgC,GACrC,4BAA4B,CA2C9B;AAED,uEAAuE;AACvE,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAA;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;gBACtB,MAAM,EAAE,4BAA4B;CAMjD;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,SAAS,SAAS,EAAE,EAC/B,QAAQ,EAAE,SAAS,SAAS,EAAE,EAC9B,IAAI,GAAE,2BAAgC,GACrC,IAAI,CAGN;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,IAAI,qBAAqB,CAEpE"}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Recursively sort object keys (and drop `undefined`) so two semantically
|
|
3
|
-
* equal values compare equal regardless of key insertion order. Without this,
|
|
4
|
-
* a tool-call `arguments` object reordered across a serialization boundary
|
|
5
|
-
* (e.g. loaded back from a Postgres `jsonb` column, which does not preserve
|
|
6
|
-
* key order, or rebuilt by the client) would be read as a forgery.
|
|
7
|
-
*/
|
|
8
|
-
function canonicalize(value) {
|
|
9
|
-
if (value === null || typeof value !== 'object')
|
|
10
|
-
return value;
|
|
11
|
-
if (Array.isArray(value))
|
|
12
|
-
return value.map(canonicalize);
|
|
13
|
-
const out = {};
|
|
14
|
-
for (const key of Object.keys(value).sort()) {
|
|
15
|
-
const v = value[key];
|
|
16
|
-
if (v === undefined)
|
|
17
|
-
continue;
|
|
18
|
-
out[key] = canonicalize(v);
|
|
19
|
-
}
|
|
20
|
-
return out;
|
|
21
|
-
}
|
|
22
|
-
/** Order-insensitive JSON of a value. */
|
|
23
|
-
function canonicalJson(value) {
|
|
24
|
-
return JSON.stringify(canonicalize(value));
|
|
25
|
-
}
|
|
26
|
-
/** Order-insensitive string form of message content. */
|
|
27
|
-
function contentString(content) {
|
|
28
|
-
return typeof content === 'string' ? content : canonicalJson(content);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Compare two messages field by field, order-insensitively. Returns a
|
|
32
|
-
* human-readable reason naming the first diverging field, or `null` when the
|
|
33
|
-
* messages are equivalent. Used by the prefix check so a rejection points at
|
|
34
|
-
* exactly what diverged.
|
|
35
|
-
*/
|
|
36
|
-
function messageDiffReason(a, b) {
|
|
37
|
-
if (a.role !== b.role)
|
|
38
|
-
return `role: persisted "${a.role}" vs incoming "${b.role}"`;
|
|
39
|
-
if (contentString(a.content) !== contentString(b.content))
|
|
40
|
-
return 'content differs';
|
|
41
|
-
if ((a.toolCallId ?? null) !== (b.toolCallId ?? null)) {
|
|
42
|
-
return `toolCallId: persisted "${a.toolCallId ?? 'null'}" vs incoming "${b.toolCallId ?? 'null'}"`;
|
|
43
|
-
}
|
|
44
|
-
const aCalls = a.toolCalls ?? [];
|
|
45
|
-
const bCalls = b.toolCalls ?? [];
|
|
46
|
-
if (aCalls.length !== bCalls.length)
|
|
47
|
-
return `toolCalls length: persisted ${aCalls.length} vs incoming ${bCalls.length}`;
|
|
48
|
-
for (let i = 0; i < aCalls.length; i++) {
|
|
49
|
-
const ac = aCalls[i];
|
|
50
|
-
const bc = bCalls[i];
|
|
51
|
-
if (ac.id !== bc.id)
|
|
52
|
-
return `toolCalls[${i}].id: persisted "${ac.id}" vs incoming "${bc.id}"`;
|
|
53
|
-
if (ac.name !== bc.name)
|
|
54
|
-
return `toolCalls[${i}].name: persisted "${ac.name}" vs incoming "${bc.name}"`;
|
|
55
|
-
if (canonicalJson(ac.arguments) !== canonicalJson(bc.arguments))
|
|
56
|
-
return `toolCalls[${i}].arguments differ (${ac.name})`;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
/** Collect every tool-call id the model requested across the given messages. */
|
|
61
|
-
function requestedToolCallIds(messages) {
|
|
62
|
-
const ids = new Set();
|
|
63
|
-
for (const m of messages) {
|
|
64
|
-
if (m.role === 'assistant' && m.toolCalls) {
|
|
65
|
-
for (const c of m.toolCalls)
|
|
66
|
-
ids.add(c.id);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return ids;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Validate that an `incoming` continuation is a legitimate extension of the
|
|
73
|
-
* server-persisted `persisted` history. Pure and synchronous — safe to call
|
|
74
|
-
* from any runtime. Returns a verdict; never throws.
|
|
75
|
-
*
|
|
76
|
-
* Checks, in order:
|
|
77
|
-
*
|
|
78
|
-
* - **Prefix equality.** Every message the two share by position must match
|
|
79
|
-
* (role, content, `toolCallId`, and any assistant `toolCalls`). Comparison
|
|
80
|
-
* is order-insensitive for nested objects, so a tool-call `arguments` map
|
|
81
|
-
* reordered across a serialization boundary still matches. A genuine
|
|
82
|
-
* mismatch means the caller rewrote history or is replaying a different
|
|
83
|
-
* thread (IDOR) → `not-a-prefix`.
|
|
84
|
-
* - **Tool-result forgery.** Every `tool` message in `incoming` must answer
|
|
85
|
-
* a tool call actually requested by some assistant message (in either
|
|
86
|
-
* `persisted` or `incoming`). A `tool` message with no matching request is
|
|
87
|
-
* smuggled data → `forged-tool-result`.
|
|
88
|
-
* - **Approval forgery.** Every id in `opts.approvedToolCallIds` /
|
|
89
|
-
* `opts.rejectedToolCallIds` must reference a real requested tool call →
|
|
90
|
-
* `forged-approval`.
|
|
91
|
-
*/
|
|
92
|
-
export function validateContinuation(persisted, incoming, opts = {}) {
|
|
93
|
-
// 1. Prefix equality over the shared region. Comparison is order-insensitive
|
|
94
|
-
// for nested objects (tool-call arguments, structured content) so a
|
|
95
|
-
// legitimately reordered argument map is not mistaken for a forgery.
|
|
96
|
-
const overlap = Math.min(persisted.length, incoming.length);
|
|
97
|
-
for (let i = 0; i < overlap; i++) {
|
|
98
|
-
const diff = messageDiffReason(persisted[i], incoming[i]);
|
|
99
|
-
if (diff) {
|
|
100
|
-
return {
|
|
101
|
-
ok: false,
|
|
102
|
-
code: 'not-a-prefix',
|
|
103
|
-
index: i,
|
|
104
|
-
reason: `incoming message at index ${i} diverges from the persisted history (${diff})`,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
// 2. Tool-result forgery — a tool message must answer a requested call.
|
|
109
|
-
const requested = requestedToolCallIds([...persisted, ...incoming]);
|
|
110
|
-
for (let i = 0; i < incoming.length; i++) {
|
|
111
|
-
const m = incoming[i];
|
|
112
|
-
if (m.role === 'tool' && (!m.toolCallId || !requested.has(m.toolCallId))) {
|
|
113
|
-
return {
|
|
114
|
-
ok: false,
|
|
115
|
-
code: 'forged-tool-result',
|
|
116
|
-
index: i,
|
|
117
|
-
reason: `tool message at index ${i} references tool call "${m.toolCallId ?? '<missing>'}" that was never requested`,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// 3. Approval forgery — approved/rejected ids must be real requested calls.
|
|
122
|
-
for (const id of [...(opts.approvedToolCallIds ?? []), ...(opts.rejectedToolCallIds ?? [])]) {
|
|
123
|
-
if (!requested.has(id)) {
|
|
124
|
-
return {
|
|
125
|
-
ok: false,
|
|
126
|
-
code: 'forged-approval',
|
|
127
|
-
reason: `tool call "${id}" was approved or rejected but was never requested`,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return { ok: true };
|
|
132
|
-
}
|
|
133
|
-
/** Thrown by {@link assertValidContinuation} when validation fails. */
|
|
134
|
-
export class ContinuationValidationError extends Error {
|
|
135
|
-
code;
|
|
136
|
-
index;
|
|
137
|
-
constructor(result) {
|
|
138
|
-
super(`[Rudder AI] Rejected continuation: ${result.reason ?? result.code ?? 'invalid'}`);
|
|
139
|
-
this.name = 'ContinuationValidationError';
|
|
140
|
-
this.code = result.code ?? 'not-a-prefix';
|
|
141
|
-
this.index = result.index;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* {@link validateContinuation} that throws {@link ContinuationValidationError}
|
|
146
|
-
* instead of returning a verdict. Use directly, or via
|
|
147
|
-
* {@link defaultContinuationValidator} as a `validate` hook.
|
|
148
|
-
*/
|
|
149
|
-
export function assertValidContinuation(persisted, incoming, opts = {}) {
|
|
150
|
-
const result = validateContinuation(persisted, incoming, opts);
|
|
151
|
-
if (!result.ok)
|
|
152
|
-
throw new ContinuationValidationError(result);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* A ready-made {@link ContinuationValidator} backed by
|
|
156
|
-
* {@link assertValidContinuation}. Drop into `AgentPromptOptions.validate`
|
|
157
|
-
* for the default prefix + tool-result-forgery + approval-forgery gate:
|
|
158
|
-
*
|
|
159
|
-
* ```ts
|
|
160
|
-
* agent.continue(id).prompt(input, { validate: defaultContinuationValidator() })
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
export function defaultContinuationValidator() {
|
|
164
|
-
return (persisted, incoming, opts) => assertValidContinuation(persisted, incoming, opts);
|
|
165
|
-
}
|
|
166
|
-
//# sourceMappingURL=continuation-validation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"continuation-validation.js","sourceRoot":"","sources":["../src/continuation-validation.ts"],"names":[],"mappings":"AAgDA;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;IACxD,MAAM,GAAG,GAA4B,EAAE,CAAA;IACvC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,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,CAAC,uBAAuB,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;AAC1F,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { AgentPromptOptions, AgentResponse, AgentStreamResponse, AiMessage, ConversationalOverride, ConversationalSpec, ConversationStore } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Internal hook that's awaited by the persistence helpers to find the
|
|
4
|
-
* registered `ConversationStore`. Wired to `setConversationStore()` /
|
|
5
|
-
* `AiProvider`'s `ai.conversations` DI binding via `agent.ts` —
|
|
6
|
-
* provided here as a parameter to keep this file dependency-free.
|
|
7
|
-
*/
|
|
8
|
-
export type ConversationStoreLookup = () => ConversationStore | null | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Resolves the effective {@link ConversationalSpec} for a single
|
|
11
|
-
* `prompt()` / `stream()` call. Returns `null` when the call should run
|
|
12
|
-
* stateless (no auto-persist).
|
|
13
|
-
*
|
|
14
|
-
* Precedence (high → low):
|
|
15
|
-
* 1. Per-call `options.conversation` — `false` opts out, a spec replaces
|
|
16
|
-
* the agent's declaration.
|
|
17
|
-
* 2. Agent's `conversational()` — supports sync OR async returns.
|
|
18
|
-
*
|
|
19
|
-
* The `ConversableAgent` (`forUser` / `continue`) flow does **not** go
|
|
20
|
-
* through this resolver — it builds its own spec and calls the helper
|
|
21
|
-
* directly so the explicit form always wins over both layers below.
|
|
22
|
-
*/
|
|
23
|
-
export declare function resolveAutoPersistSpec(agentDecl: () => false | ConversationalSpec | Promise<false | ConversationalSpec>, perCall: ConversationalOverride | undefined): Promise<ConversationalSpec | null>;
|
|
24
|
-
/**
|
|
25
|
-
* Compose the new turn's messages from the user input + the steps the
|
|
26
|
-
* agent loop produced. Mirrors the old `ConversableAgent.prompt`
|
|
27
|
-
* persistence shape exactly so downstream stores see no behavioral change.
|
|
28
|
-
*/
|
|
29
|
-
export declare function newMessagesFromTurn(input: string, response: AgentResponse): AiMessage[];
|
|
30
|
-
/**
|
|
31
|
-
* Wrap a non-streaming agent run with conversation persistence. Loads
|
|
32
|
-
* history before, appends the new turn after, and stamps `conversationId`
|
|
33
|
-
* onto the result.
|
|
34
|
-
*
|
|
35
|
-
* `inner` receives the merged options (with the loaded history pre-pended
|
|
36
|
-
* to `options.history`) and is expected to invoke the actual agent loop.
|
|
37
|
-
*/
|
|
38
|
-
export declare function runWithPersistence(spec: ConversationalSpec, agentClassName: string, storeLookup: ConversationStoreLookup, input: string, options: AgentPromptOptions | undefined, inner: (effOptions: AgentPromptOptions | undefined) => Promise<AgentResponse>): Promise<AgentResponse>;
|
|
39
|
-
/**
|
|
40
|
-
* Wrap a streaming agent run with conversation persistence. Same shape as
|
|
41
|
-
* {@link runWithPersistence}, but stitched into the
|
|
42
|
-
* `AgentStreamResponse` `{ stream, response }` pair so the caller sees
|
|
43
|
-
* stream chunks flowing first and the persisted result resolving last.
|
|
44
|
-
*/
|
|
45
|
-
export declare function runWithPersistenceStreaming(spec: ConversationalSpec, agentClassName: string, storeLookup: ConversationStoreLookup, input: string, options: AgentPromptOptions | undefined, inner: (effOptions: AgentPromptOptions | undefined) => AgentStreamResponse): AgentStreamResponse;
|
|
46
|
-
//# sourceMappingURL=conversation-persistence.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-persistence.d.ts","sourceRoot":"","sources":["../src/conversation-persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,SAAS,EACT,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,YAAY,CAAA;AAEnB;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,iBAAiB,GAAG,IAAI,GAAG,SAAS,CAAA;AAEhF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,sBAAsB,CAC1C,SAAS,EAAK,MAAM,KAAK,GAAG,kBAAkB,GAAG,OAAO,CAAC,KAAK,GAAG,kBAAkB,CAAC,EACpF,OAAO,EAAO,sBAAsB,GAAG,SAAS,GAC/C,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAWpC;AA0FD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,SAAS,EAAE,CAUvF;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAY,kBAAkB,EAClC,cAAc,EAAE,MAAM,EACtB,WAAW,EAAK,uBAAuB,EACvC,KAAK,EAAW,MAAM,EACtB,OAAO,EAAS,kBAAkB,GAAG,SAAS,EAC9C,KAAK,EAAW,CAAC,UAAU,EAAE,kBAAkB,GAAG,SAAS,KAAK,OAAO,CAAC,aAAa,CAAC,GACrF,OAAO,CAAC,aAAa,CAAC,CAWxB;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAY,kBAAkB,EAClC,cAAc,EAAE,MAAM,EACtB,WAAW,EAAK,uBAAuB,EACvC,KAAK,EAAW,MAAM,EACtB,OAAO,EAAS,kBAAkB,GAAG,SAAS,EAC9C,KAAK,EAAW,CAAC,UAAU,EAAE,kBAAkB,GAAG,SAAS,KAAK,mBAAmB,GAClF,mBAAmB,CAyCrB"}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolves the effective {@link ConversationalSpec} for a single
|
|
3
|
-
* `prompt()` / `stream()` call. Returns `null` when the call should run
|
|
4
|
-
* stateless (no auto-persist).
|
|
5
|
-
*
|
|
6
|
-
* Precedence (high → low):
|
|
7
|
-
* 1. Per-call `options.conversation` — `false` opts out, a spec replaces
|
|
8
|
-
* the agent's declaration.
|
|
9
|
-
* 2. Agent's `conversational()` — supports sync OR async returns.
|
|
10
|
-
*
|
|
11
|
-
* The `ConversableAgent` (`forUser` / `continue`) flow does **not** go
|
|
12
|
-
* through this resolver — it builds its own spec and calls the helper
|
|
13
|
-
* directly so the explicit form always wins over both layers below.
|
|
14
|
-
*/
|
|
15
|
-
export async function resolveAutoPersistSpec(agentDecl, perCall) {
|
|
16
|
-
if (perCall === false)
|
|
17
|
-
return null;
|
|
18
|
-
if (perCall && typeof perCall === 'object') {
|
|
19
|
-
if (!perCall.user && !perCall.id)
|
|
20
|
-
return null; // invalid override → opt out
|
|
21
|
-
return perCall;
|
|
22
|
-
}
|
|
23
|
-
const declared = await agentDecl();
|
|
24
|
-
if (declared === false || !declared)
|
|
25
|
-
return null;
|
|
26
|
-
if (!declared.user && !declared.id)
|
|
27
|
-
return null;
|
|
28
|
-
return declared;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Run the load-or-create-thread half of the persistence flow. Resolves
|
|
32
|
-
* the conversation id, loads history, applies `historyLimit`, and merges
|
|
33
|
-
* with any caller-supplied `options.history`.
|
|
34
|
-
*/
|
|
35
|
-
async function preparePersistence(spec, agentClassName, store, callerHistory) {
|
|
36
|
-
let convId = spec.id;
|
|
37
|
-
let loaded = [];
|
|
38
|
-
if (convId) {
|
|
39
|
-
loaded = await store.load(convId);
|
|
40
|
-
}
|
|
41
|
-
else if (spec.user) {
|
|
42
|
-
const agentKey = spec.agent ?? agentClassName;
|
|
43
|
-
const threads = await store.list(spec.user);
|
|
44
|
-
// Most-recent thread for this (user, agent) pair. Stores filter by
|
|
45
|
-
// `userId` already; we filter by the agent meta locally so existing
|
|
46
|
-
// stores (which may not persist `agent` in `list()` results) still
|
|
47
|
-
// work — they'll just always create new threads, which is the
|
|
48
|
-
// conservative behavior.
|
|
49
|
-
const candidates = threads.filter(t => (t.agent ?? null) === agentKey);
|
|
50
|
-
const mostRecent = candidates.sort((a, b) => {
|
|
51
|
-
const aT = (a.updatedAt ?? a.createdAt).getTime();
|
|
52
|
-
const bT = (b.updatedAt ?? b.createdAt).getTime();
|
|
53
|
-
return bT - aT;
|
|
54
|
-
})[0];
|
|
55
|
-
if (mostRecent) {
|
|
56
|
-
convId = mostRecent.id;
|
|
57
|
-
loaded = await store.load(convId);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
convId = await store.create(undefined, { userId: spec.user, agent: agentKey });
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
throw new Error('[Rudder AI] ConversationalSpec must include either `user` or `id`.');
|
|
65
|
-
}
|
|
66
|
-
// Snapshot the trusted baseline before any limit slice — the validation
|
|
67
|
-
// hook compares the caller's incoming messages against the FULL persisted
|
|
68
|
-
// thread, not the windowed view fed to the model.
|
|
69
|
-
const persisted = loaded;
|
|
70
|
-
let windowed = loaded;
|
|
71
|
-
if (spec.historyLimit !== undefined && spec.historyLimit > 0) {
|
|
72
|
-
windowed = loaded.slice(-spec.historyLimit);
|
|
73
|
-
}
|
|
74
|
-
const history = [...windowed, ...(callerHistory ?? [])];
|
|
75
|
-
return { spec, store, convId, history, persisted };
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Run the caller-supplied `validate` continuation hook, if present. The
|
|
79
|
-
* "incoming" view is the caller's claimed prior conversation — their
|
|
80
|
-
* `options.messages` (full continuation list) when set, else
|
|
81
|
-
* `options.history`. Throws (propagating the rejection) when the hook does.
|
|
82
|
-
*/
|
|
83
|
-
async function runValidation(ctx, options) {
|
|
84
|
-
if (!options?.validate)
|
|
85
|
-
return;
|
|
86
|
-
const incoming = options.messages ?? options.history ?? [];
|
|
87
|
-
const opts = {};
|
|
88
|
-
if (options.approvedToolCallIds)
|
|
89
|
-
opts.approvedToolCallIds = options.approvedToolCallIds;
|
|
90
|
-
if (options.rejectedToolCallIds)
|
|
91
|
-
opts.rejectedToolCallIds = options.rejectedToolCallIds;
|
|
92
|
-
await options.validate(ctx.persisted, incoming, opts);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Compose the new turn's messages from the user input + the steps the
|
|
96
|
-
* agent loop produced. Mirrors the old `ConversableAgent.prompt`
|
|
97
|
-
* persistence shape exactly so downstream stores see no behavioral change.
|
|
98
|
-
*/
|
|
99
|
-
export function newMessagesFromTurn(input, response) {
|
|
100
|
-
const out = [{ role: 'user', content: input }];
|
|
101
|
-
for (const step of response.steps) {
|
|
102
|
-
out.push(step.message);
|
|
103
|
-
for (const tr of step.toolResults) {
|
|
104
|
-
const resultStr = typeof tr.result === 'string' ? tr.result : JSON.stringify(tr.result);
|
|
105
|
-
out.push({ role: 'tool', content: resultStr, toolCallId: tr.toolCallId });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return out;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Wrap a non-streaming agent run with conversation persistence. Loads
|
|
112
|
-
* history before, appends the new turn after, and stamps `conversationId`
|
|
113
|
-
* onto the result.
|
|
114
|
-
*
|
|
115
|
-
* `inner` receives the merged options (with the loaded history pre-pended
|
|
116
|
-
* to `options.history`) and is expected to invoke the actual agent loop.
|
|
117
|
-
*/
|
|
118
|
-
export async function runWithPersistence(spec, agentClassName, storeLookup, input, options, inner) {
|
|
119
|
-
const store = storeLookup();
|
|
120
|
-
if (!store)
|
|
121
|
-
throw new Error('[Rudder AI] No ConversationStore registered. Bind one via `setConversationStore()` or the `ai.conversations` DI key.');
|
|
122
|
-
const ctx = await preparePersistence(spec, agentClassName, store, options?.history);
|
|
123
|
-
await runValidation(ctx, options);
|
|
124
|
-
const effOptions = { ...options, history: ctx.history };
|
|
125
|
-
const response = await inner(effOptions);
|
|
126
|
-
await store.append(ctx.convId, newMessagesFromTurn(input, response));
|
|
127
|
-
return { ...response, conversationId: ctx.convId };
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Wrap a streaming agent run with conversation persistence. Same shape as
|
|
131
|
-
* {@link runWithPersistence}, but stitched into the
|
|
132
|
-
* `AgentStreamResponse` `{ stream, response }` pair so the caller sees
|
|
133
|
-
* stream chunks flowing first and the persisted result resolving last.
|
|
134
|
-
*/
|
|
135
|
-
export function runWithPersistenceStreaming(spec, agentClassName, storeLookup, input, options, inner) {
|
|
136
|
-
let resolveResponse;
|
|
137
|
-
let rejectResponse;
|
|
138
|
-
const responsePromise = new Promise((res, rej) => { resolveResponse = res; rejectResponse = rej; });
|
|
139
|
-
async function* outer() {
|
|
140
|
-
const store = storeLookup();
|
|
141
|
-
if (!store) {
|
|
142
|
-
const err = new Error('[Rudder AI] No ConversationStore registered. Bind one via `setConversationStore()` or the `ai.conversations` DI key.');
|
|
143
|
-
rejectResponse(err);
|
|
144
|
-
throw err;
|
|
145
|
-
}
|
|
146
|
-
let ctx;
|
|
147
|
-
try {
|
|
148
|
-
ctx = await preparePersistence(spec, agentClassName, store, options?.history);
|
|
149
|
-
await runValidation(ctx, options);
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
rejectResponse(err);
|
|
153
|
-
throw err;
|
|
154
|
-
}
|
|
155
|
-
const innerResp = inner({ ...options, history: ctx.history });
|
|
156
|
-
try {
|
|
157
|
-
for await (const chunk of innerResp.stream)
|
|
158
|
-
yield chunk;
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
rejectResponse(err);
|
|
162
|
-
throw err;
|
|
163
|
-
}
|
|
164
|
-
const response = await innerResp.response;
|
|
165
|
-
try {
|
|
166
|
-
await store.append(ctx.convId, newMessagesFromTurn(input, response));
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
169
|
-
rejectResponse(err);
|
|
170
|
-
throw err;
|
|
171
|
-
}
|
|
172
|
-
resolveResponse({ ...response, conversationId: ctx.convId });
|
|
173
|
-
}
|
|
174
|
-
return { stream: outer(), response: responsePromise };
|
|
175
|
-
}
|
|
176
|
-
//# sourceMappingURL=conversation-persistence.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-persistence.js","sourceRoot":"","sources":["../src/conversation-persistence.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,SAAoF,EACpF,OAAgD;IAEhD,IA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AAe,EAAE,CAAA;AACvD,CAAC"}
|
package/dist/conversation.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AiMessage, ConversationStore, ConversationStoreListEntry, ConversationStoreMeta } from './types.js';
|
|
2
|
-
export declare class MemoryConversationStore implements ConversationStore {
|
|
3
|
-
private readonly conversations;
|
|
4
|
-
create(title?: string, meta?: ConversationStoreMeta): Promise<string>;
|
|
5
|
-
load(conversationId: string): Promise<AiMessage[]>;
|
|
6
|
-
append(conversationId: string, messages: AiMessage[]): Promise<void>;
|
|
7
|
-
setTitle(conversationId: string, title: string): Promise<void>;
|
|
8
|
-
list(userId?: string): Promise<ConversationStoreListEntry[]>;
|
|
9
|
-
delete(conversationId: string): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAOjH,qBAAa,uBAAwB,YAAW,iBAAiB;IAC/D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAM1B;IAEE,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;IAarE,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAMlD,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpE,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM9D,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAa5D,MAAM,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGpD"}
|
package/dist/conversation.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
function generateId() {
|
|
2
|
-
if (typeof globalThis.crypto?.randomUUID === 'function')
|
|
3
|
-
return globalThis.crypto.randomUUID();
|
|
4
|
-
return `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
5
|
-
}
|
|
6
|
-
export class MemoryConversationStore {
|
|
7
|
-
conversations = new Map();
|
|
8
|
-
async create(title, meta) {
|
|
9
|
-
const id = generateId();
|
|
10
|
-
const now = new Date();
|
|
11
|
-
this.conversations.set(id, {
|
|
12
|
-
title: title ?? 'New conversation',
|
|
13
|
-
messages: [],
|
|
14
|
-
meta,
|
|
15
|
-
createdAt: now,
|
|
16
|
-
updatedAt: now,
|
|
17
|
-
});
|
|
18
|
-
return id;
|
|
19
|
-
}
|
|
20
|
-
async load(conversationId) {
|
|
21
|
-
const conv = this.conversations.get(conversationId);
|
|
22
|
-
if (!conv)
|
|
23
|
-
throw new Error(`[Rudder AI] Conversation "${conversationId}" not found.`);
|
|
24
|
-
return [...conv.messages];
|
|
25
|
-
}
|
|
26
|
-
async append(conversationId, messages) {
|
|
27
|
-
const conv = this.conversations.get(conversationId);
|
|
28
|
-
if (!conv)
|
|
29
|
-
throw new Error(`[Rudder AI] Conversation "${conversationId}" not found.`);
|
|
30
|
-
conv.messages.push(...messages);
|
|
31
|
-
conv.updatedAt = new Date();
|
|
32
|
-
}
|
|
33
|
-
async setTitle(conversationId, title) {
|
|
34
|
-
const conv = this.conversations.get(conversationId);
|
|
35
|
-
if (!conv)
|
|
36
|
-
throw new Error(`[Rudder AI] Conversation "${conversationId}" not found.`);
|
|
37
|
-
conv.title = title;
|
|
38
|
-
}
|
|
39
|
-
async list(userId) {
|
|
40
|
-
return Array.from(this.conversations.entries())
|
|
41
|
-
.filter(([, conv]) => userId == null || conv.meta?.userId === userId)
|
|
42
|
-
.map(([id, conv]) => ({
|
|
43
|
-
id,
|
|
44
|
-
title: conv.title,
|
|
45
|
-
createdAt: conv.createdAt,
|
|
46
|
-
updatedAt: conv.updatedAt,
|
|
47
|
-
...(conv.meta?.agent ? { agent: conv.meta.agent } : {}),
|
|
48
|
-
}))
|
|
49
|
-
.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
50
|
-
}
|
|
51
|
-
async delete(conversationId) {
|
|
52
|
-
this.conversations.delete(conversationId);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=conversation.js.map
|
package/dist/conversation.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.js","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAEA,SAAS,UAAU;IACjB,IAAI,OAAO,UAAU,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;IAC9F,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAA;AAChF,CAAC;AAED,MAAM,OAAO,uBAAuB;IACjB,aAAa,GAAG,IAAI,GAAG,EAMpC,CAAA;IAEJ,KAAK,CAAC,MAAM,CAAC,KAAc,EAAE,IAA4B;QACvD,MAAM,EAAE,GAAG,UAAU,EAAE,CAAA;QACvB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;QACtB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,EAAE;YACzB,KAAK,EAAE,KAAK,IAAI,kBAAkB;YAClC,QAAQ,EAAE,EAAE;YACZ,IAAI;YACJ,SAAS,EAAE,GAAG;YACd,SAAS,EAA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EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;YACpB,EAAE;YACF,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxD,CAAC,CAAC;aACF,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,SAAU,CAAC,OAAO,EAAE,CAAC,CAAA;IACpE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,cAAsB;QACjC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;IAC3C,CAAC;CACF"}
|
package/dist/eval/fixtures.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fixture I/O for `pnpm rudder ai:eval --record` / `--replay` (#A5
|
|
3
|
-
* Phase 4). Each case writes one JSON file under
|
|
4
|
-
* `evals/__fixtures__/<suite>/<case>.json` carrying the assistant
|
|
5
|
-
* turns from a real provider run, normalized into the
|
|
6
|
-
* {@link AiFakeStep} shape so `--replay` can re-feed them via
|
|
7
|
-
* `AiFake.respondWithSequence` for zero-API regression tests.
|
|
8
|
-
*
|
|
9
|
-
* The fixture format is versioned. Bumping `version` forces a
|
|
10
|
-
* re-record on stale fixtures rather than silently mis-replaying.
|
|
11
|
-
*/
|
|
12
|
-
import type { AgentResponse } from '../types.js';
|
|
13
|
-
import type { AiFakeStep } from '../fake.js';
|
|
14
|
-
/** Fixture format. Bump `version` when the shape changes incompatibly. */
|
|
15
|
-
export interface EvalFixture {
|
|
16
|
-
version: 1;
|
|
17
|
-
suite: string;
|
|
18
|
-
case: string;
|
|
19
|
-
input: string;
|
|
20
|
-
recordedAt: string;
|
|
21
|
-
steps: AiFakeStep[];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Convert an `AgentResponse` into the assistant-turn `AiFakeStep[]`
|
|
25
|
-
* sequence that `AiFake.respondWithSequence` expects.
|
|
26
|
-
*
|
|
27
|
-
* - Drops user/tool turns — those are framework-generated during a
|
|
28
|
-
* replayed run, not provider output.
|
|
29
|
-
* - Multi-modal assistant content collapses to its concatenated text
|
|
30
|
-
* parts (the fake's transport is text-only; image/document parts
|
|
31
|
-
* wouldn't replay meaningfully).
|
|
32
|
-
* - `toolCalls` carry through verbatim so multi-step tool loops
|
|
33
|
-
* replay deterministically.
|
|
34
|
-
*/
|
|
35
|
-
export declare function stepsFromResponse(response: AgentResponse): AiFakeStep[];
|
|
36
|
-
/**
|
|
37
|
-
* Default fixtures directory: `<cwd>/evals/__fixtures__`. Override
|
|
38
|
-
* via the CLI handler's options for tests / non-standard layouts.
|
|
39
|
-
*/
|
|
40
|
-
export declare function defaultFixturesDir(cwd: string): string;
|
|
41
|
-
/**
|
|
42
|
-
* Filesystem-safe slug for `<suite>/<case>` segments. Letters,
|
|
43
|
-
* digits, dot, dash, underscore pass through; everything else
|
|
44
|
-
* collapses to `-`. Multiple consecutive `-` collapse to one.
|
|
45
|
-
*
|
|
46
|
-
* Pure function; tested directly so suite/case rename diffs stay
|
|
47
|
-
* predictable across editors.
|
|
48
|
-
*/
|
|
49
|
-
export declare function slugify(s: string): string;
|
|
50
|
-
export declare function fixturePath(dir: string, suite: string, caseName: string): string;
|
|
51
|
-
/**
|
|
52
|
-
* Read a fixture file. Returns `null` when the fixture is missing
|
|
53
|
-
* (replay falls back to running normally with a clear stderr line).
|
|
54
|
-
*
|
|
55
|
-
* Throws on parse / version errors — corruption is not a passing
|
|
56
|
-
* case and silently ignoring it would mask real regressions.
|
|
57
|
-
*/
|
|
58
|
-
export declare function readFixture(dir: string, suite: string, caseName: string): Promise<EvalFixture | null>;
|
|
59
|
-
/**
|
|
60
|
-
* Write a fixture, creating intermediate directories as needed.
|
|
61
|
-
* Pretty-printed (2-space) so PR diffs remain readable when the
|
|
62
|
-
* model output evolves.
|
|
63
|
-
*/
|
|
64
|
-
export declare function writeFixture(dir: string, suite: string, caseName: string, payload: Omit<EvalFixture, 'version' | 'suite' | 'case' | 'recordedAt'>): Promise<string>;
|
|
65
|
-
//# sourceMappingURL=fixtures.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/eval/fixtures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,aAAa,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,0EAA0E;AAC1E,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAK,CAAC,CAAA;IACb,KAAK,EAAO,MAAM,CAAA;IAClB,IAAI,EAAQ,MAAM,CAAA;IAClB,KAAK,EAAO,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAO,UAAU,EAAE,CAAA;CACzB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,UAAU,EAAE,CAWvE;AASD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhF;AAID;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAO,MAAM,EAChB,KAAK,EAAK,MAAM,EAChB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