Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

errors.ts

31 lines1.1 KB

1/**
2 * Thrown when code invokes an optional sandbox capability that the active
3 * provider does not support. Core/middleware should check
4 * `handle.capabilities` BEFORE using an optional capability and degrade
5 * gracefully; this error exists so that a direct call to an unsupported
6 * optional method fails loud instead of silently no-opping.
7 */
8export class UnsupportedCapabilityError extends Error {
9 readonly provider: string
10 readonly capability: string
11​
12 constructor(provider: string, capability: string, hint?: string) {
13 super(
14 `Sandbox provider "${provider}" does not support the "${capability}" capability.` +
15 (hint ? ` ${hint}` : ''),
16 )
17 this.name = 'UnsupportedCapabilityError'
18 this.provider = provider
19 this.capability = capability
20 }
22​
23/** Thrown when a harness adapter requires a sandbox but none was provided. */
24export class MissingSandboxError extends Error {
25 constructor(adapterName: string) {
26 super(
27 `Adapter "${adapterName}" requires a sandbox. Add withSandbox(defineSandbox({ ... })) to chat() middleware.`,
28 )
29 this.name = 'MissingSandboxError'
30 }