🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@opencode-ai/ai

Package Overview
Dependencies
Maintainers
2
Versions
281
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opencode-ai/ai - npm Package Compare versions

Comparing version
0.0.0-next-16389
to
0.0.0-next-16391
+1493
dist/testing.d.ts
export * as TestLLM from "./testing";
import { type Interface as LLMClientShape } from "./route/client";
import { LLMEvent, type FinishReasonDetails, type LLMError, type LLMRequest, type UsageInput } from "./schema";
import { Context, Effect, Layer, Scope, Stream } from "effect";
export type Response = readonly LLMEvent[] | Stream.Stream<LLMEvent, LLMError>;
export type Gate = Readonly<{
started: Effect.Effect<void>;
release: Effect.Effect<void>;
}>;
export interface Interface {
readonly requests: LLMRequest[];
readonly push: (...responses: readonly Response[]) => Effect.Effect<void>;
readonly always: (response: Response) => Effect.Effect<void>;
readonly wait: (count: number) => Effect.Effect<void>;
readonly gate: Effect.Effect<Gate, never, Scope.Scope>;
readonly client: LLMClientShape;
}
export interface LayerOptions {
readonly transformRequest?: (request: LLMRequest) => LLMRequest;
/** Used after the one-shot response queue is exhausted. Omit to defect on unexpected requests. */
readonly fallback?: Response;
}
declare const Service_base: Context.ServiceClass<Service, "@opencode/ai/TestLLM", Interface>;
export declare class Service extends Service_base {
}
export declare const complete: (options: {
readonly reason: FinishReasonDetails;
readonly usage?: UsageInput;
}, ...events: readonly LLMEvent[]) => ({
readonly type: "step-start";
readonly index: number;
} | {
readonly id: string;
readonly type: "text-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "tool-input-start";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly type: "tool-input-delta";
readonly id: string;
readonly name: string;
readonly text: string;
} | {
readonly id: string;
readonly type: "tool-input-end";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "tool-input-error";
readonly id: string;
readonly name: string;
readonly raw: string;
} | {
readonly id: string;
readonly type: "tool-call";
readonly name: string;
readonly input: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-result";
readonly name: string;
readonly result: {
readonly type: "json";
readonly value: unknown;
} | {
readonly type: "text";
readonly value: unknown;
} | {
readonly type: "error";
readonly value: unknown;
} | {
readonly type: "content";
readonly value: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
};
readonly output?: {
readonly structured: unknown;
readonly content: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
} | undefined;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-error";
readonly name: string;
readonly message: string;
readonly error?: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "step-finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly index: number;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "provider-error";
readonly message: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly classification?: "context-overflow" | undefined;
})[];
export declare const stop: (...events: readonly LLMEvent[]) => ({
readonly type: "step-start";
readonly index: number;
} | {
readonly id: string;
readonly type: "text-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "tool-input-start";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly type: "tool-input-delta";
readonly id: string;
readonly name: string;
readonly text: string;
} | {
readonly id: string;
readonly type: "tool-input-end";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "tool-input-error";
readonly id: string;
readonly name: string;
readonly raw: string;
} | {
readonly id: string;
readonly type: "tool-call";
readonly name: string;
readonly input: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-result";
readonly name: string;
readonly result: {
readonly type: "json";
readonly value: unknown;
} | {
readonly type: "text";
readonly value: unknown;
} | {
readonly type: "error";
readonly value: unknown;
} | {
readonly type: "content";
readonly value: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
};
readonly output?: {
readonly structured: unknown;
readonly content: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
} | undefined;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-error";
readonly name: string;
readonly message: string;
readonly error?: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "step-finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly index: number;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "provider-error";
readonly message: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly classification?: "context-overflow" | undefined;
})[];
export declare const toolCalls: (...events: readonly LLMEvent[]) => ({
readonly type: "step-start";
readonly index: number;
} | {
readonly id: string;
readonly type: "text-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "tool-input-start";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly type: "tool-input-delta";
readonly id: string;
readonly name: string;
readonly text: string;
} | {
readonly id: string;
readonly type: "tool-input-end";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "tool-input-error";
readonly id: string;
readonly name: string;
readonly raw: string;
} | {
readonly id: string;
readonly type: "tool-call";
readonly name: string;
readonly input: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-result";
readonly name: string;
readonly result: {
readonly type: "json";
readonly value: unknown;
} | {
readonly type: "text";
readonly value: unknown;
} | {
readonly type: "error";
readonly value: unknown;
} | {
readonly type: "content";
readonly value: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
};
readonly output?: {
readonly structured: unknown;
readonly content: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
} | undefined;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-error";
readonly name: string;
readonly message: string;
readonly error?: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "step-finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly index: number;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "provider-error";
readonly message: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly classification?: "context-overflow" | undefined;
})[];
export declare const text: (value: string, id: string) => ({
readonly type: "step-start";
readonly index: number;
} | {
readonly id: string;
readonly type: "text-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "tool-input-start";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly type: "tool-input-delta";
readonly id: string;
readonly name: string;
readonly text: string;
} | {
readonly id: string;
readonly type: "tool-input-end";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "tool-input-error";
readonly id: string;
readonly name: string;
readonly raw: string;
} | {
readonly id: string;
readonly type: "tool-call";
readonly name: string;
readonly input: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-result";
readonly name: string;
readonly result: {
readonly type: "json";
readonly value: unknown;
} | {
readonly type: "text";
readonly value: unknown;
} | {
readonly type: "error";
readonly value: unknown;
} | {
readonly type: "content";
readonly value: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
};
readonly output?: {
readonly structured: unknown;
readonly content: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
} | undefined;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-error";
readonly name: string;
readonly message: string;
readonly error?: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "step-finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly index: number;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "provider-error";
readonly message: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly classification?: "context-overflow" | undefined;
})[];
export declare const textWithUsage: (value: string, id: string, inputTokens: number) => ({
readonly type: "step-start";
readonly index: number;
} | {
readonly id: string;
readonly type: "text-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "tool-input-start";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly type: "tool-input-delta";
readonly id: string;
readonly name: string;
readonly text: string;
} | {
readonly id: string;
readonly type: "tool-input-end";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "tool-input-error";
readonly id: string;
readonly name: string;
readonly raw: string;
} | {
readonly id: string;
readonly type: "tool-call";
readonly name: string;
readonly input: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-result";
readonly name: string;
readonly result: {
readonly type: "json";
readonly value: unknown;
} | {
readonly type: "text";
readonly value: unknown;
} | {
readonly type: "error";
readonly value: unknown;
} | {
readonly type: "content";
readonly value: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
};
readonly output?: {
readonly structured: unknown;
readonly content: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
} | undefined;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-error";
readonly name: string;
readonly message: string;
readonly error?: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "step-finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly index: number;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "provider-error";
readonly message: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly classification?: "context-overflow" | undefined;
})[];
export declare const tool: (id: string, name: string, input: unknown) => ({
readonly type: "step-start";
readonly index: number;
} | {
readonly id: string;
readonly type: "text-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "tool-input-start";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly type: "tool-input-delta";
readonly id: string;
readonly name: string;
readonly text: string;
} | {
readonly id: string;
readonly type: "tool-input-end";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "tool-input-error";
readonly id: string;
readonly name: string;
readonly raw: string;
} | {
readonly id: string;
readonly type: "tool-call";
readonly name: string;
readonly input: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-result";
readonly name: string;
readonly result: {
readonly type: "json";
readonly value: unknown;
} | {
readonly type: "text";
readonly value: unknown;
} | {
readonly type: "error";
readonly value: unknown;
} | {
readonly type: "content";
readonly value: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
};
readonly output?: {
readonly structured: unknown;
readonly content: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
} | undefined;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-error";
readonly name: string;
readonly message: string;
readonly error?: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "step-finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly index: number;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "provider-error";
readonly message: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly classification?: "context-overflow" | undefined;
})[];
export declare const failAfter: (error: LLMError, ...events: readonly LLMEvent[]) => Stream.Stream<{
readonly type: "step-start";
readonly index: number;
} | {
readonly id: string;
readonly type: "text-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "tool-input-start";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly type: "tool-input-delta";
readonly id: string;
readonly name: string;
readonly text: string;
} | {
readonly id: string;
readonly type: "tool-input-end";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "tool-input-error";
readonly id: string;
readonly name: string;
readonly raw: string;
} | {
readonly id: string;
readonly type: "tool-call";
readonly name: string;
readonly input: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-result";
readonly name: string;
readonly result: {
readonly type: "json";
readonly value: unknown;
} | {
readonly type: "text";
readonly value: unknown;
} | {
readonly type: "error";
readonly value: unknown;
} | {
readonly type: "content";
readonly value: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
};
readonly output?: {
readonly structured: unknown;
readonly content: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
} | undefined;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-error";
readonly name: string;
readonly message: string;
readonly error?: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "step-finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly index: number;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "provider-error";
readonly message: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly classification?: "context-overflow" | undefined;
}, LLMError, never>;
export declare const hangAfter: (...events: readonly LLMEvent[]) => Stream.Stream<{
readonly type: "step-start";
readonly index: number;
} | {
readonly id: string;
readonly type: "text-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "text-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-start";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-delta";
readonly text: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "reasoning-end";
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly id: string;
readonly type: "tool-input-start";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly type: "tool-input-delta";
readonly id: string;
readonly name: string;
readonly text: string;
} | {
readonly id: string;
readonly type: "tool-input-end";
readonly name: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "tool-input-error";
readonly id: string;
readonly name: string;
readonly raw: string;
} | {
readonly id: string;
readonly type: "tool-call";
readonly name: string;
readonly input: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-result";
readonly name: string;
readonly result: {
readonly type: "json";
readonly value: unknown;
} | {
readonly type: "text";
readonly value: unknown;
} | {
readonly type: "error";
readonly value: unknown;
} | {
readonly type: "content";
readonly value: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
};
readonly output?: {
readonly structured: unknown;
readonly content: readonly ({
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly uri: string;
readonly mime: string;
readonly name?: string | undefined;
})[];
} | undefined;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly providerExecuted?: boolean | undefined;
} | {
readonly id: string;
readonly type: "tool-error";
readonly name: string;
readonly message: string;
readonly error?: unknown;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
} | {
readonly type: "step-finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly index: number;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "finish";
readonly reason: {
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
readonly raw?: string | undefined;
};
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly usage?: import("./schema").Usage | undefined;
} | {
readonly type: "provider-error";
readonly message: string;
readonly providerMetadata?: {
readonly [x: string]: {
readonly [x: string]: unknown;
};
} | undefined;
readonly classification?: "context-overflow" | undefined;
}, never, never>;
export declare const layer: (options?: LayerOptions) => Layer.Layer<Service, never, never>;
export declare const clientLayer: Layer.Layer<import(".").LLMClientService, never, Service>;
export declare const push: (...responses: readonly Response[]) => Effect.Effect<void, never, Service>;
export declare const always: (response: Response) => Effect.Effect<void, never, Service>;
export declare const wait: (count: number) => Effect.Effect<void, never, Service>;
export declare const gate: Effect.Effect<Readonly<{
started: Effect.Effect<void>;
release: Effect.Effect<void>;
}>, never, Scope.Scope | Service>;
export * as TestLLM from "./testing";
import { LLMClient } from "./route/client";
import { LLMEvent, LLMResponse, } from "./schema";
import { Context, Deferred, Effect, Latch, Layer, Queue, Scope, Stream } from "effect";
export class Service extends Context.Service()("@opencode/ai/TestLLM") {
}
export const complete = (options, ...events) => [
LLMEvent.stepStart({ index: 0 }),
...events,
LLMEvent.stepFinish({ index: 0, reason: options.reason, usage: options.usage }),
LLMEvent.finish({ reason: options.reason }),
];
export const stop = (...events) => complete({ reason: { normalized: "stop" } }, ...events);
export const toolCalls = (...events) => complete({ reason: { normalized: "tool-calls" } }, ...events);
const textEvents = (value, id) => [
LLMEvent.textStart({ id }),
LLMEvent.textDelta({ id, text: value }),
LLMEvent.textEnd({ id }),
];
export const text = (value, id) => stop(...textEvents(value, id));
export const textWithUsage = (value, id, inputTokens) => complete({ reason: { normalized: "stop" }, usage: { inputTokens, nonCachedInputTokens: inputTokens } }, ...textEvents(value, id));
export const tool = (id, name, input) => toolCalls(LLMEvent.toolCall({ id, name, input }));
export const failAfter = (error, ...events) => Stream.fromIterable(events).pipe(Stream.concat(Stream.fail(error)));
export const hangAfter = (...events) => Stream.concat(Stream.fromIterable(events), Stream.never);
const toStream = (response) => (Stream.isStream(response) ? response : Stream.fromIterable(response));
export const layer = (options = {}) => Layer.effect(Service, Effect.gen(function* () {
const requests = [];
const responses = [];
let started = Deferred.makeUnsafe();
let fallback = options.fallback;
let activeGate;
const wait = (count) => Effect.suspend(() => requests.length >= count ? Effect.void : Deferred.await(started).pipe(Effect.andThen(wait(count))));
const stream = ((request) => {
requests.push(options.transformRequest?.(request) ?? request);
const waiting = started;
started = Deferred.makeUnsafe();
Deferred.doneUnsafe(waiting, Effect.void);
const response = responses.shift() ?? fallback;
if (!response)
return Stream.die(new Error(`TestLLM has no response for request ${requests.length}`));
const streamed = toStream(response);
const gate = activeGate;
if (!gate)
return streamed;
return Stream.unwrap(Queue.offer(gate.started, undefined).pipe(Effect.andThen(gate.release.await), Effect.as(streamed)));
});
const client = LLMClient.Service.of({
prepare: () => Effect.die("TestLLM does not prepare provider-native requests"),
stream,
generate: (request) => stream(request).pipe(Stream.runFold(LLMResponse.empty, LLMResponse.reduce), Effect.flatMap((state) => {
const response = LLMResponse.complete(state);
if (response)
return Effect.succeed(response);
return Effect.die("TestLLM response ended without a terminal finish event");
})),
});
return Service.of({
requests,
push: (...input) => Effect.sync(() => {
responses.push(...input);
}),
always: (response) => Effect.sync(() => {
fallback = response;
}),
wait,
gate: Effect.gen(function* () {
const gate = {
started: yield* Effect.acquireRelease(Queue.unbounded(), Queue.shutdown),
release: yield* Latch.make(),
};
activeGate = gate;
const release = Effect.sync(() => {
if (activeGate === gate)
activeGate = undefined;
}).pipe(Effect.andThen(gate.release.open), Effect.asVoid);
yield* Effect.addFinalizer(() => release);
return {
started: Queue.take(gate.started),
release,
};
}),
client,
});
}));
export const clientLayer = Layer.effect(LLMClient.Service, Effect.map(Service, (service) => service.client));
export const push = (...responses) => Service.use((service) => service.push(...responses));
export const always = (response) => Service.use((service) => service.always(response));
export const wait = (count) => Service.use((service) => service.wait(count));
export const gate = Service.use((service) => service.gate);
+7
-3
{
"$schema": "https://json.schemastore.org/package.json",
"version": "0.0.0-next-16389",
"version": "0.0.0-next-16391",
"name": "@opencode-ai/ai",

@@ -21,2 +21,6 @@ "type": "module",

},
"./testing": {
"import": "./dist/testing.js",
"types": "./dist/testing.d.ts"
},
"./*": {

@@ -30,3 +34,3 @@ "import": "./dist/*.js",

"@effect/platform-node": "4.0.0-beta.101",
"@opencode-ai/http-recorder": "0.0.0-next-16389",
"@opencode-ai/http-recorder": "0.0.0-next-16391",
"@tsconfig/bun": "1.0.9",

@@ -40,3 +44,3 @@ "@types/bun": "1.3.13",

"@smithy/util-utf8": "4.2.2",
"@opencode-ai/schema": "0.0.0-next-16389",
"@opencode-ai/schema": "0.0.0-next-16391",
"aws4fetch": "1.0.20",

@@ -43,0 +47,0 @@ "effect": "4.0.0-beta.101",