mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
refactor(ai): replace wildcard exports with an explicit public API (#59183)
This commit is contained in:
committed by
GitHub
Unverified
parent
7359a48573
commit
d8607b6616
+105
-1
@@ -18,7 +18,111 @@
|
||||
".": "./src/index.ts",
|
||||
"./effect": "./src/effect.ts",
|
||||
"./testing": "./src/testing.ts",
|
||||
"./*": "./src/*.ts"
|
||||
"./experimental": "./src/experimental.ts",
|
||||
"./route": "./src/route.ts",
|
||||
"./providers": "./src/providers.ts",
|
||||
"./providers/alibaba": "./src/providers/alibaba.ts",
|
||||
"./providers/alibaba/chat": "./src/providers/alibaba/chat.ts",
|
||||
"./providers/alibaba/messages": "./src/providers/alibaba/messages.ts",
|
||||
"./providers/alibaba/responses": "./src/providers/alibaba/responses.ts",
|
||||
"./providers/amazon-bedrock": "./src/providers/amazon-bedrock.ts",
|
||||
"./providers/amazon-bedrock-mantle": "./src/providers/amazon-bedrock-mantle.ts",
|
||||
"./providers/amazon-bedrock/mantle": "./src/providers/amazon-bedrock/mantle.ts",
|
||||
"./providers/amazon-bedrock/mantle/chat": "./src/providers/amazon-bedrock/mantle/chat.ts",
|
||||
"./providers/amazon-bedrock/mantle/messages": "./src/providers/amazon-bedrock/mantle/messages.ts",
|
||||
"./providers/amazon-bedrock/mantle/responses": "./src/providers/amazon-bedrock/mantle/responses.ts",
|
||||
"./providers/anthropic": "./src/providers/anthropic.ts",
|
||||
"./providers/anthropic-compatible": "./src/providers/anthropic-compatible.ts",
|
||||
"./providers/assemblyai": "./src/providers/assemblyai.ts",
|
||||
"./providers/azure": "./src/providers/azure.ts",
|
||||
"./providers/azure/chat": "./src/providers/azure/chat.ts",
|
||||
"./providers/azure/responses": "./src/providers/azure/responses.ts",
|
||||
"./providers/baseten": "./src/providers/baseten.ts",
|
||||
"./providers/black-forest-labs": "./src/providers/black-forest-labs.ts",
|
||||
"./providers/cartesia": "./src/providers/cartesia.ts",
|
||||
"./providers/cerebras": "./src/providers/cerebras.ts",
|
||||
"./providers/cloudflare-ai-gateway": "./src/providers/cloudflare-ai-gateway.ts",
|
||||
"./providers/cloudflare-workers-ai": "./src/providers/cloudflare-workers-ai.ts",
|
||||
"./providers/cohere": "./src/providers/cohere.ts",
|
||||
"./providers/cohere/chat": "./src/providers/cohere/chat.ts",
|
||||
"./providers/deepgram": "./src/providers/deepgram.ts",
|
||||
"./providers/deepinfra": "./src/providers/deepinfra.ts",
|
||||
"./providers/deepseek": "./src/providers/deepseek.ts",
|
||||
"./providers/digitalocean": "./src/providers/digitalocean.ts",
|
||||
"./providers/elevenlabs": "./src/providers/elevenlabs.ts",
|
||||
"./providers/fal": "./src/providers/fal.ts",
|
||||
"./providers/fireworks": "./src/providers/fireworks.ts",
|
||||
"./providers/google": "./src/providers/google.ts",
|
||||
"./providers/google-vertex": "./src/providers/google-vertex.ts",
|
||||
"./providers/google-vertex-chat": "./src/providers/google-vertex-chat.ts",
|
||||
"./providers/google-vertex-interactions": "./src/providers/google-vertex-interactions.ts",
|
||||
"./providers/google-vertex-messages": "./src/providers/google-vertex-messages.ts",
|
||||
"./providers/google-vertex-mistral": "./src/providers/google-vertex-mistral.ts",
|
||||
"./providers/google-vertex-responses": "./src/providers/google-vertex-responses.ts",
|
||||
"./providers/google-vertex/chat": "./src/providers/google-vertex/chat.ts",
|
||||
"./providers/google-vertex/gemini": "./src/providers/google-vertex/gemini.ts",
|
||||
"./providers/google-vertex/interactions": "./src/providers/google-vertex/interactions.ts",
|
||||
"./providers/google-vertex/messages": "./src/providers/google-vertex/messages.ts",
|
||||
"./providers/google-vertex/mistral": "./src/providers/google-vertex/mistral.ts",
|
||||
"./providers/google-vertex/responses": "./src/providers/google-vertex/responses.ts",
|
||||
"./providers/google/interactions": "./src/providers/google/interactions.ts",
|
||||
"./providers/groq": "./src/providers/groq.ts",
|
||||
"./providers/meta": "./src/providers/meta.ts",
|
||||
"./providers/meta/chat": "./src/providers/meta/chat.ts",
|
||||
"./providers/meta/messages": "./src/providers/meta/messages.ts",
|
||||
"./providers/meta/responses": "./src/providers/meta/responses.ts",
|
||||
"./providers/minimax": "./src/providers/minimax.ts",
|
||||
"./providers/minimax/chat": "./src/providers/minimax/chat.ts",
|
||||
"./providers/minimax/messages": "./src/providers/minimax/messages.ts",
|
||||
"./providers/minimax/responses": "./src/providers/minimax/responses.ts",
|
||||
"./providers/mistral": "./src/providers/mistral.ts",
|
||||
"./providers/moonshot": "./src/providers/moonshot.ts",
|
||||
"./providers/moonshot/chat": "./src/providers/moonshot/chat.ts",
|
||||
"./providers/moonshot/messages": "./src/providers/moonshot/messages.ts",
|
||||
"./providers/moonshot/responses": "./src/providers/moonshot/responses.ts",
|
||||
"./providers/openai": "./src/providers/openai.ts",
|
||||
"./providers/openai-compatible": "./src/providers/openai-compatible.ts",
|
||||
"./providers/openai-compatible-responses": "./src/providers/openai-compatible-responses.ts",
|
||||
"./providers/openai-compatible/responses": "./src/providers/openai-compatible/responses.ts",
|
||||
"./providers/openai/chat": "./src/providers/openai/chat.ts",
|
||||
"./providers/openai/responses": "./src/providers/openai/responses.ts",
|
||||
"./providers/opencode": "./src/providers/opencode.ts",
|
||||
"./providers/openrouter": "./src/providers/openrouter.ts",
|
||||
"./providers/replicate": "./src/providers/replicate.ts",
|
||||
"./providers/runway": "./src/providers/runway.ts",
|
||||
"./providers/stability": "./src/providers/stability.ts",
|
||||
"./providers/togetherai": "./src/providers/togetherai.ts",
|
||||
"./providers/typesafe-ai": "./src/providers/typesafe-ai.ts",
|
||||
"./providers/venice": "./src/providers/venice.ts",
|
||||
"./providers/vercel-ai-gateway": "./src/providers/vercel-ai-gateway.ts",
|
||||
"./providers/vercel-ai-gateway/chat": "./src/providers/vercel-ai-gateway/chat.ts",
|
||||
"./providers/vercel-ai-gateway/messages": "./src/providers/vercel-ai-gateway/messages.ts",
|
||||
"./providers/vercel-ai-gateway/responses": "./src/providers/vercel-ai-gateway/responses.ts",
|
||||
"./providers/xai": "./src/providers/xai.ts",
|
||||
"./providers/zai": "./src/providers/zai.ts",
|
||||
"./providers/zai-coding-plan": "./src/providers/zai-coding-plan.ts",
|
||||
"./providers/zai-coding-plan/chat": "./src/providers/zai-coding-plan/chat.ts",
|
||||
"./providers/zai-coding-plan/messages": "./src/providers/zai-coding-plan/messages.ts",
|
||||
"./providers/zai-coding-plan/responses": "./src/providers/zai-coding-plan/responses.ts",
|
||||
"./providers/zai/chat": "./src/providers/zai/chat.ts",
|
||||
"./protocols": "./src/protocols.ts",
|
||||
"./protocols/alibaba-images": "./src/protocols/alibaba-images.ts",
|
||||
"./protocols/cloudflare-run-decisions": "./src/protocols/cloudflare-run-decisions.ts",
|
||||
"./protocols/cloudflare-workers-ai-images": "./src/protocols/cloudflare-workers-ai-images.ts",
|
||||
"./protocols/deepgram-transcription": "./src/protocols/deepgram-transcription.ts",
|
||||
"./protocols/google-images": "./src/protocols/google-images.ts",
|
||||
"./protocols/google-speech": "./src/protocols/google-speech.ts",
|
||||
"./protocols/google-transcription": "./src/protocols/google-transcription.ts",
|
||||
"./protocols/openai-chat": "./src/protocols/openai-chat.ts",
|
||||
"./protocols/openai-decisions": "./src/protocols/openai-decisions.ts",
|
||||
"./protocols/openai-images": "./src/protocols/openai-images.ts",
|
||||
"./protocols/openai-responses": "./src/protocols/openai-responses.ts",
|
||||
"./protocols/openai-speech": "./src/protocols/openai-speech.ts",
|
||||
"./protocols/openai-transcription": "./src/protocols/openai-transcription.ts",
|
||||
"./protocols/system-one": "./src/protocols/system-one.ts",
|
||||
"./protocols/xai-images": "./src/protocols/xai-images.ts",
|
||||
"./protocols/xai-video": "./src/protocols/xai-video.ts",
|
||||
"./protocols/zai-images": "./src/protocols/zai-images.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@clack/prompts": "1.0.0-alpha.1",
|
||||
|
||||
+101
-13
@@ -2,16 +2,109 @@ export { AIClient } from "./ai-client.js"
|
||||
export { LLMClient } from "./route/client.js"
|
||||
export { ImageClient } from "./image-client.js"
|
||||
export { Auth } from "./route/auth.js"
|
||||
export { Provider } from "./provider.js"
|
||||
export { ProviderPackage } from "./provider-package.js"
|
||||
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js"
|
||||
export type { Interface as LLMClientShape, LLMClientService } from "./route/client.js"
|
||||
export {
|
||||
ProtocolID,
|
||||
RouteID,
|
||||
ModelID,
|
||||
ProviderID,
|
||||
ResponseID,
|
||||
ContentBlockID,
|
||||
ToolCallID,
|
||||
JsonSchema,
|
||||
ProviderOptions,
|
||||
ProviderMetadata,
|
||||
HttpTimeout,
|
||||
RequestEncoding,
|
||||
HttpOptions,
|
||||
GenerationOptions,
|
||||
LanguageModelDefaults,
|
||||
ReasoningEfforts,
|
||||
ReasoningEffort,
|
||||
LanguageModelCompatibility,
|
||||
LanguageModel,
|
||||
LanguageModelSchema,
|
||||
CacheTTL,
|
||||
CacheHint,
|
||||
CachePolicyObject,
|
||||
CachePolicy,
|
||||
MessageRole,
|
||||
SystemPart,
|
||||
TextPart,
|
||||
MediaPart,
|
||||
ToolResultValue,
|
||||
ToolOutput,
|
||||
ToolCallPart,
|
||||
ToolResultPart,
|
||||
ReasoningPart,
|
||||
CompactionPart,
|
||||
EffortPart,
|
||||
ContentPart,
|
||||
Message,
|
||||
ToolDefinition,
|
||||
ToolNamespace,
|
||||
ToolEntry,
|
||||
ToolChoice,
|
||||
LLMRequest,
|
||||
FinishReason,
|
||||
Usage,
|
||||
MediaUsage,
|
||||
CompactionResponse,
|
||||
CompactionCheckpointResponse,
|
||||
StepStart,
|
||||
TextStart,
|
||||
TextDelta,
|
||||
TextEnd,
|
||||
ReasoningStart,
|
||||
ReasoningDelta,
|
||||
ReasoningEnd,
|
||||
ToolInputStart,
|
||||
ToolInputDelta,
|
||||
ToolInputEnd,
|
||||
ToolInputError,
|
||||
ToolCall,
|
||||
ToolResult,
|
||||
ToolError,
|
||||
FinishReasonDetails,
|
||||
StepFinish,
|
||||
Finish,
|
||||
MediaEvent,
|
||||
ProviderErrorEvent,
|
||||
LLMEvent,
|
||||
LLMResponse,
|
||||
HttpContext,
|
||||
HttpRateLimitDetails,
|
||||
InvalidRequestError,
|
||||
UnsupportedOperationError,
|
||||
ProviderConfigurationError,
|
||||
NoRouteError,
|
||||
AuthenticationError,
|
||||
RateLimitError,
|
||||
QuotaExceededError,
|
||||
ContentPolicyError,
|
||||
ProviderInternalError,
|
||||
TransportType,
|
||||
TransportOperation,
|
||||
TransportError,
|
||||
InvalidProviderOutputError,
|
||||
UnknownProviderError,
|
||||
TimeoutError,
|
||||
AIErrorReason,
|
||||
AIError,
|
||||
} from "./schema/index.js"
|
||||
export type {
|
||||
RouteLanguageModelInput,
|
||||
RouteRoutedLanguageModelInput,
|
||||
Interface as LLMClientShape,
|
||||
LLMClientService,
|
||||
} from "./route/client.js"
|
||||
export * from "./schema/index.js"
|
||||
GenerationOptionsFields,
|
||||
GenerationOptionsInput,
|
||||
LanguageModelInput,
|
||||
LanguageModelProviderOptions,
|
||||
ToolDefinitionInput,
|
||||
ToolNamespaceInput,
|
||||
ToolNamespaceEntryInput,
|
||||
ToolEntryInput,
|
||||
UsageInput,
|
||||
} from "./schema/index.js"
|
||||
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js"
|
||||
export type {
|
||||
ImageModelOptions,
|
||||
@@ -125,7 +218,7 @@ export type {
|
||||
Snapshot as GenerationSnapshot,
|
||||
Status as GenerationStatus,
|
||||
} from "./generation.js"
|
||||
export { Tool, ToolFailure, toDefinitions } from "./tool.js"
|
||||
export { Tool, ToolFailure, emptyInputJsonSchema, toDefinitions } from "./tool.js"
|
||||
export { ToolRuntime } from "./tool-runtime.js"
|
||||
export type { DispatchResult as ToolDispatchResult, ToolSettlement } from "./tool-runtime.js"
|
||||
export type {
|
||||
@@ -142,11 +235,6 @@ export type {
|
||||
ToolToModelOutput,
|
||||
} from "./tool.js"
|
||||
export * as LLM from "./llm.js"
|
||||
export type {
|
||||
Definition as ProviderDefinition,
|
||||
LanguageModelFactory as ProviderLanguageModelFactory,
|
||||
LanguageModelOptions as ProviderLanguageModelOptions,
|
||||
} from "./provider.js"
|
||||
export type {
|
||||
Definition as ProviderPackageDefinition,
|
||||
Settings as ProviderPackageSettings,
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import type { LanguageModel, ModelID, ProviderID } from "./schema/index.js"
|
||||
|
||||
export type LanguageModelOptions = Pick<LanguageModel.Input, "defaults" | "compatibility">
|
||||
|
||||
/**
|
||||
* Advanced structural provider definition helper. Built-in providers should
|
||||
* prefer explicit `configure(options).model(id)` facades so deployment config is
|
||||
* chosen before model selection. The optional `apis` map remains for external
|
||||
* structural providers that expose multiple route selectors behind one provider.
|
||||
*/
|
||||
export type LanguageModelFactory<Options extends LanguageModelOptions = LanguageModelOptions> = (
|
||||
id: string | ModelID,
|
||||
options?: Options,
|
||||
) => LanguageModel
|
||||
|
||||
type AnyLanguageModelFactory = (...args: never[]) => LanguageModel
|
||||
|
||||
export interface Definition<Factory extends AnyLanguageModelFactory = LanguageModelFactory> {
|
||||
readonly id: ProviderID
|
||||
readonly model: Factory
|
||||
readonly apis?: Record<string, AnyLanguageModelFactory>
|
||||
}
|
||||
|
||||
type DefinitionShape = {
|
||||
readonly id: ProviderID
|
||||
readonly model: (...args: never[]) => LanguageModel
|
||||
readonly apis?: Record<string, (...args: never[]) => LanguageModel>
|
||||
}
|
||||
|
||||
type NoExtraFields<Input, Shape> = Input & Record<Exclude<keyof Input, keyof Shape>, never>
|
||||
|
||||
export const make = <DefinitionType extends DefinitionShape>(
|
||||
definition: NoExtraFields<DefinitionType, DefinitionShape>,
|
||||
) => definition
|
||||
|
||||
export * as Provider from "./provider.js"
|
||||
@@ -18,7 +18,7 @@ import { OpenAISpeech } from "../protocols/openai-speech.js"
|
||||
import { OpenAITranscription } from "../protocols/openai-transcription.js"
|
||||
import { OpenAIDecisions, type OptionsInput as OpenAIDecisionOptionsInput } from "../protocols/openai-decisions.js"
|
||||
|
||||
export type { OpenAIOptionsInput, OpenAIResponseIncludable } from "./openai-options.js"
|
||||
export type { OpenAIOptionsInput, OpenAIResponseIncludable, OpenAIServiceTier } from "./openai-options.js"
|
||||
export type { OpenAIImageOptions } from "../protocols/openai-images.js"
|
||||
export type { OpenAISpeechOptions } from "../protocols/openai-speech.js"
|
||||
export type { OpenAITranscriptionOptions } from "../protocols/openai-transcription.js"
|
||||
|
||||
@@ -592,7 +592,7 @@ const compile = Effect.fn("LLM.compile")(function* (request: LLMRequest, options
|
||||
}
|
||||
})
|
||||
|
||||
/** @internal Test-only projection of the execution compiler; not exported from package barrels. */
|
||||
/** Test-only projection of the execution compiler; exported from `@opencode/ai/testing`. */
|
||||
export const compileRequest = Effect.fn("LLM.compileRequest")(function* (request: LLMRequest) {
|
||||
const compiled = yield* compile(request)
|
||||
return {
|
||||
|
||||
@@ -12,7 +12,7 @@ import { classifyProviderFailure, providerErrorMessage } from "../provider-error
|
||||
import { headerDetails, responseHttp, Service, type HttpMiddleware, type Interface } from "./executor-service.js"
|
||||
|
||||
export { responseHttp, Service } from "./executor-service.js"
|
||||
export type { HttpHandler, HttpMiddleware, Interface } from "./executor-service.js"
|
||||
export type { HttpHandler, HttpMiddleware, Interface, RequestExecutorService } from "./executor-service.js"
|
||||
|
||||
const normalizedHeaders = (headers: Headers.Headers) =>
|
||||
Object.fromEntries(Object.entries(headers).map(([key, value]) => [key.toLowerCase(), value]))
|
||||
|
||||
@@ -26,6 +26,9 @@ export { Framing } from "./framing.js"
|
||||
export { Protocol } from "./protocol.js"
|
||||
export { HttpTransport, WebSocketTransport } from "./transport/index.js"
|
||||
export * as Transport from "./transport/index.js"
|
||||
export { ProviderShared } from "../protocols/shared.js"
|
||||
export { classifyProviderFailure } from "../provider-error.js"
|
||||
export { mergeHttpOptions } from "../schema/index.js"
|
||||
export type { Definition as AuthShape, AuthInput, Credential, CredentialError } from "./auth.js"
|
||||
export type { ApiKeyMode, AuthOverride, ProviderAuthOption } from "./auth-options.js"
|
||||
export type { Definition as EndpointFn, EndpointInput } from "./endpoint.js"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * as TestLLM from "./testing.js"
|
||||
export { compileRequest } from "./route/client.js"
|
||||
|
||||
import {
|
||||
LLMClient,
|
||||
@@ -47,25 +48,12 @@ export interface TestInterface extends ClientInterface {
|
||||
|
||||
export class Test extends Context.Service<Test, TestInterface>()("@opencode/ai/TestLLM/Test") {}
|
||||
|
||||
/** @deprecated Use TestInterface through Test and testLayer. */
|
||||
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: ClientInterface
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
/** @deprecated Use Test and testLayer for normal client methods and test controls. */
|
||||
export class Service extends Context.Service<Service, Interface>()("@opencode/ai/TestLLM") {}
|
||||
|
||||
export const complete = (
|
||||
options: {
|
||||
readonly reason: FinishReasonDetails
|
||||
@@ -173,7 +161,7 @@ const make = (options: LayerOptions) =>
|
||||
}),
|
||||
)
|
||||
}
|
||||
const test = Test.of({
|
||||
return Test.of({
|
||||
compact,
|
||||
stream,
|
||||
generate: (request) =>
|
||||
@@ -216,44 +204,10 @@ const make = (options: LayerOptions) =>
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
return { test, requests }
|
||||
})
|
||||
|
||||
/** Provides one shared implementation under the normal client and test-control tags. */
|
||||
export const testLayer = (options: LayerOptions = {}) =>
|
||||
Layer.effectContext(
|
||||
Effect.map(make(options), (implementation) =>
|
||||
Context.make(LLMClient.Service, implementation.test).pipe(Context.add(Test, implementation.test)),
|
||||
),
|
||||
Effect.map(make(options), (test) => Context.make(LLMClient.Service, test).pipe(Context.add(Test, test))),
|
||||
)
|
||||
|
||||
/** @deprecated Use testLayer; retained for published callers of the legacy control interface. */
|
||||
export const layer = (options: LayerOptions = {}) =>
|
||||
Layer.effect(
|
||||
Service,
|
||||
Effect.map(make(options), (implementation) =>
|
||||
Service.of({
|
||||
requests: implementation.requests,
|
||||
push: implementation.test.push,
|
||||
always: implementation.test.always,
|
||||
wait: implementation.test.wait,
|
||||
gate: implementation.test.gate(),
|
||||
client: implementation.test,
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
/** @deprecated testLayer provides LLMClient.Service directly. */
|
||||
export const clientLayer = Layer.effect(
|
||||
LLMClient.Service,
|
||||
Effect.map(Service, (service) => service.client),
|
||||
)
|
||||
|
||||
export const push = (...responses: readonly Response[]) => Service.use((service) => service.push(...responses))
|
||||
|
||||
export const always = (response: Response) => Service.use((service) => service.always(response))
|
||||
|
||||
export const wait = (count: number) => Service.use((service) => service.wait(count))
|
||||
|
||||
export const gate = Service.use((service) => service.gate)
|
||||
|
||||
@@ -8,11 +8,11 @@ import {
|
||||
ToolCallPart,
|
||||
ToolDefinition,
|
||||
ToolNamespace,
|
||||
mergeProviderOptions,
|
||||
} from "../src/effect.js"
|
||||
import { AnthropicMessages, OpenAIChat, OpenAIResponses } from "../src/protocols.js"
|
||||
import { Auth, LLMClient } from "../src/route.js"
|
||||
import { compileRequest } from "../src/route/client.js"
|
||||
import { mergeProviderOptions } from "../src/schema/index.js"
|
||||
import { it } from "./lib/effect.js"
|
||||
import { dynamicResponse } from "./lib/http.js"
|
||||
import { deltaChunk } from "./lib/openai-chunks.js"
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
LLM,
|
||||
LLMClient,
|
||||
Media,
|
||||
Provider,
|
||||
Speech,
|
||||
SpeechClient,
|
||||
SpeechEvent,
|
||||
@@ -21,7 +20,6 @@ import {
|
||||
VideoClient,
|
||||
} from "@opencode/ai/effect"
|
||||
import { Route, Protocol, RequestExecutor, WebSocketTransport } from "@opencode/ai/route"
|
||||
import { Provider as ProviderSubpath } from "@opencode/ai/provider"
|
||||
import {
|
||||
Alibaba,
|
||||
AssemblyAI,
|
||||
@@ -51,6 +49,7 @@ import {
|
||||
ZAI,
|
||||
} from "@opencode/ai/providers"
|
||||
import {
|
||||
AnthropicMessages,
|
||||
OpenAIChat,
|
||||
OpenAICompatibleChat,
|
||||
OpenAICompatibleResponses,
|
||||
@@ -58,7 +57,6 @@ import {
|
||||
OpenResponses,
|
||||
OpenResponsesChannel,
|
||||
} from "@opencode/ai/protocols"
|
||||
import * as AnthropicMessages from "@opencode/ai/protocols/anthropic-messages"
|
||||
import { TestLLM } from "@opencode/ai/testing"
|
||||
|
||||
describe("public exports", () => {
|
||||
@@ -91,9 +89,6 @@ describe("public exports", () => {
|
||||
expect(SpeechClient.layer).toBeDefined()
|
||||
expect(SpeechEvent.is.audioDelta).toBeFunction()
|
||||
expect(Generation).toBeFunction()
|
||||
expect(Provider.make).toBeFunction()
|
||||
expect(ProviderSubpath.make).toBe(Provider.make)
|
||||
expect(TestLLM.layer).toBeFunction()
|
||||
expect(TestLLM.testLayer).toBeFunction()
|
||||
expect(TestLLM.Test.of).toBeFunction()
|
||||
expect(Decision.generate).toBeFunction()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect } from "bun:test"
|
||||
import { Deferred, Effect, Fiber } from "effect"
|
||||
import * as TestClock from "effect/testing/TestClock"
|
||||
import { HttpOptions, LLM, mergeHttpOptions } from "../src/effect.js"
|
||||
import { LLMClient } from "../src/route.js"
|
||||
import { HttpOptions, LLM } from "../src/effect.js"
|
||||
import { LLMClient, mergeHttpOptions } from "../src/route.js"
|
||||
import { configure } from "../src/providers/openai.js"
|
||||
import { dynamicResponse } from "./lib/http.js"
|
||||
import { deltaChunk, finishChunk } from "./lib/openai-chunks.js"
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import { Provider } from "../src/provider.js"
|
||||
import { ProviderID, type LanguageModel } from "../src/schema/index.js"
|
||||
|
||||
declare const model: (id: string) => LanguageModel
|
||||
declare const requiredModel: (id: string, options: { readonly baseURL: string }) => LanguageModel
|
||||
declare const chat: (id: string, options: { readonly apiKey: string }) => LanguageModel
|
||||
|
||||
Provider.make({
|
||||
id: ProviderID.make("example"),
|
||||
model,
|
||||
})
|
||||
|
||||
Provider.make({
|
||||
id: ProviderID.make("bad"),
|
||||
model,
|
||||
// @ts-expect-error provider definitions should not grow accidental top-level fields.
|
||||
routes: [],
|
||||
})
|
||||
|
||||
const requiredProvider = Provider.make({
|
||||
id: ProviderID.make("required"),
|
||||
model: requiredModel,
|
||||
})
|
||||
|
||||
// Provider.make is advanced structural typing coverage; built-in providers use
|
||||
// configure(...).model(id) facades instead of second-argument selectors.
|
||||
requiredProvider.model("custom", { baseURL: "https://example.com/v1" })
|
||||
|
||||
// @ts-expect-error Provider.make preserves required model options.
|
||||
requiredProvider.model("custom")
|
||||
|
||||
const multiApiProvider = Provider.make({
|
||||
id: ProviderID.make("multi-api"),
|
||||
model,
|
||||
apis: { chat },
|
||||
})
|
||||
|
||||
multiApiProvider.apis.chat("chat-model", { apiKey: "key" })
|
||||
|
||||
// @ts-expect-error Provider.make preserves API-specific option types.
|
||||
multiApiProvider.apis.chat("chat-model")
|
||||
@@ -23,62 +23,8 @@ const request = LLM.request({
|
||||
model: LanguageModel.make({ id: "fictional-model", provider: "fixture", route: OpenAIChat.route }),
|
||||
prompt: "Say hello",
|
||||
})
|
||||
const legacy = testEffect(TestLLM.layer())
|
||||
const it = testEffect(TestLLM.testLayer())
|
||||
|
||||
describe("TestLLM legacy client", () => {
|
||||
legacy.effect("does not observe requests or consume responses until execution", () =>
|
||||
Effect.gen(function* () {
|
||||
const llm = yield* TestLLM.Service
|
||||
yield* llm.push(TestLLM.text("first", "first"), TestLLM.text("second", "second"))
|
||||
|
||||
llm.client.stream(request)
|
||||
llm.client.generate(request)
|
||||
expect(llm.requests).toEqual([])
|
||||
|
||||
expect((yield* llm.client.generate(request)).text).toBe("first")
|
||||
expect((yield* llm.client.generate(request)).text).toBe("second")
|
||||
expect(llm.requests).toEqual([request, request])
|
||||
}),
|
||||
)
|
||||
|
||||
legacy.effect("assigns and records a fresh response for each execution", () =>
|
||||
Effect.gen(function* () {
|
||||
const llm = yield* TestLLM.Service
|
||||
yield* llm.push(
|
||||
TestLLM.text("first", "first"),
|
||||
TestLLM.text("second", "second"),
|
||||
TestLLM.text("third", "third"),
|
||||
TestLLM.text("fourth", "fourth"),
|
||||
)
|
||||
const stream = llm.client.stream(request)
|
||||
const generate = llm.client.generate(request)
|
||||
|
||||
expect(yield* Stream.runCollect(stream)).toEqual(TestLLM.text("first", "first"))
|
||||
expect(yield* Stream.runCollect(stream)).toEqual(TestLLM.text("second", "second"))
|
||||
expect((yield* generate).text).toBe("third")
|
||||
expect((yield* generate).text).toBe("fourth")
|
||||
expect(llm.requests).toEqual([request, request, request, request])
|
||||
}),
|
||||
)
|
||||
|
||||
legacy.effect("keeps module-level controls and clientLayer on the same backing state", () =>
|
||||
Effect.gen(function* () {
|
||||
const llm = yield* TestLLM.Service
|
||||
const requests = llm.requests
|
||||
yield* TestLLM.push(TestLLM.text("queued", "queued"))
|
||||
yield* TestLLM.always(TestLLM.text("fallback", "fallback"))
|
||||
expect((yield* LLMClient.generate(request).pipe(Effect.provide(TestLLM.clientLayer))).text).toBe("queued")
|
||||
yield* TestLLM.wait(1)
|
||||
expect(requests).toEqual([request])
|
||||
requests.length = 0
|
||||
expect((yield* llm.client.generate(request)).text).toBe("fallback")
|
||||
expect(llm.requests).toBe(requests)
|
||||
expect(requests).toEqual([request])
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
describe("TestLLM first-class client", () => {
|
||||
it.effect("returns scripted checkpoints only for trigger compaction", () =>
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -30,9 +30,8 @@ import {
|
||||
type ToolDefinition,
|
||||
type UsageInput,
|
||||
} from "@opencode/ai/effect"
|
||||
import { Auth, Endpoint, RequestExecutor, type AnyRoute, type HttpMiddleware } from "@opencode/ai/route"
|
||||
import { ProviderShared } from "@opencode/ai/protocols/shared"
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { Auth, Endpoint, ProviderShared, RequestExecutor, type AnyRoute, type HttpMiddleware } from "@opencode/ai/route"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
import { Cause, Context, Effect, Layer, Option, Schema, Scope, Stream, Struct } from "effect"
|
||||
import { makeParser } from "effect/encoding/Sse"
|
||||
import { HttpClientRequest, HttpClientResponse } from "effect/http"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export * as CodeModeWeb from "./web.js"
|
||||
|
||||
import { Extension } from "@opencode/codemode"
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
|
||||
const TIMEOUT_MS = 30_000
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export * as ConfigNormalize from "./normalize.js"
|
||||
|
||||
import { isDeepStrictEqual } from "node:util"
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
import { Option, Schema } from "effect"
|
||||
import { Info } from "@opencode/schema/config"
|
||||
import { ConfigAgent } from "@opencode/schema/config/agent"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export * as SkillFile from "./skill-file.js"
|
||||
|
||||
import path from "path"
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
import { Result, Schema, type SchemaIssue, SchemaParser } from "effect"
|
||||
import { ConfigMarkdown } from "../markdown.js"
|
||||
import { AbsolutePath } from "../../schema.js"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Effect } from "effect"
|
||||
import { ChildProcess } from "effect/process"
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
import { FSUtil } from "@opencode/util/fs-util"
|
||||
import { Npm } from "@opencode/util/npm"
|
||||
import { AppProcess } from "@opencode/util/process"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export * as ModelResolver from "./model-resolver.js"
|
||||
|
||||
import { makeLocationNode } from "@opencode/util/effect/app-node"
|
||||
import { HttpOptions, LanguageModel, mergeHttpOptions, ProviderConfigurationError } from "@opencode/ai/effect"
|
||||
import { Auth } from "@opencode/ai/route"
|
||||
import { HttpOptions, LanguageModel, ProviderConfigurationError } from "@opencode/ai/effect"
|
||||
import { Auth, mergeHttpOptions } from "@opencode/ai/route"
|
||||
import { Context, Effect, Layer, Schema, Struct } from "effect"
|
||||
import { AISDK } from "./aisdk.js"
|
||||
import { Credential } from "./credential.js"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { IntegrationOAuthMethodRegistration } from "@opencode/plugin/effect/integration"
|
||||
import type { SessionRequestKind, SessionTitle } from "@opencode/plugin/effect/session"
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
import { Effect, Option, Schema, Semaphore, Stream } from "effect"
|
||||
import { IntegrationConnection } from "../../integration/connection.js"
|
||||
import { Credential } from "../../credential.js"
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Provider } from "@opencode/schema/provider"
|
||||
import { Model } from "@opencode/schema/model"
|
||||
import { makeLocationNode } from "@opencode/util/effect/app-node"
|
||||
import { HttpTimeout, type ProviderPackageDefinition } from "@opencode/ai/effect"
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
import { Npm } from "@opencode/util/npm"
|
||||
import type { DeepMutable } from "./schema.js"
|
||||
import { importModule, resolveModule } from "@opencode/util/runtime-import"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type LLMEvent, type ProviderMetadata, type ToolResultValue } from "@opencode/ai/effect"
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
import type { Agent } from "@opencode/schema/agent"
|
||||
import type { Model } from "@opencode/schema/model"
|
||||
import type { RelativePath } from "@opencode/schema/schema"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { ToolDefinition } from "@opencode/ai/effect"
|
||||
import { emptyInputJsonSchema } from "@opencode/ai/tool"
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { emptyInputJsonSchema, type ToolDefinition } from "@opencode/ai/effect"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
import { Tool } from "@opencode/schema/tool"
|
||||
import type { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec"
|
||||
import { Cache, Effect, JsonPointer, JsonSchema, Schema, SchemaIssue, SchemaRepresentation } from "effect"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export * as ConfigProviderOptionsV1 from "./provider-options.js"
|
||||
|
||||
import { isRecord } from "@opencode/ai/utils/record"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
|
||||
type Options = Readonly<Record<string, unknown>>
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
isContextOverflowFailure,
|
||||
} from "@opencode/ai/effect"
|
||||
import { LLMClient, RequestExecutor } from "@opencode/ai/route"
|
||||
import { compileRequest } from "@opencode/ai/route/client"
|
||||
import { compileRequest } from "@opencode/ai/testing"
|
||||
import { expect } from "bun:test"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { HttpClientRequest, HttpClientResponse } from "effect/http"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect } from "bun:test"
|
||||
import { LLM, LanguageModel, Message } from "@opencode/ai/effect"
|
||||
import { OpenAIChat } from "@opencode/ai/protocols"
|
||||
import { compileRequest } from "@opencode/ai/route/client"
|
||||
import { compileRequest } from "@opencode/ai/testing"
|
||||
import { ConfigProvider, Effect, Layer } from "effect"
|
||||
import { Headers } from "effect/http"
|
||||
import { AISDKNative } from "@opencode/core/aisdk-native"
|
||||
|
||||
@@ -3,8 +3,8 @@ import { Agent } from "@opencode/schema/agent"
|
||||
import { Session } from "@opencode/core/session"
|
||||
import { OpenAIResponses } from "@opencode/ai/protocols/openai-responses"
|
||||
import { AIError, HttpContext, LLM, Message, RateLimitError } from "@opencode/ai/effect"
|
||||
import { classifyProviderFailure } from "@opencode/ai/provider-error"
|
||||
import { compileRequest } from "@opencode/ai/route/client"
|
||||
import { classifyProviderFailure } from "@opencode/ai/route"
|
||||
import { compileRequest } from "@opencode/ai/testing"
|
||||
import { describe, expect } from "bun:test"
|
||||
// import { DateTime, Deferred, Effect, Schedule } from "effect"
|
||||
import { DateTime, Effect, Schedule } from "effect"
|
||||
|
||||
@@ -5,14 +5,15 @@ import { Provider } from "@opencode/core/provider"
|
||||
|
||||
describe("Provider", () => {
|
||||
test("bundles every native provider entrypoint that exports model()", async () => {
|
||||
const providers = path.join(import.meta.dir, "../../ai/src/providers")
|
||||
const manifest = await Bun.file(path.join(import.meta.dir, "../../ai/package.json")).json()
|
||||
const entrypoints = await Promise.all(
|
||||
Array.from(new Bun.Glob("**/*.ts").scanSync(providers)).map(async (file) => {
|
||||
// Bun.Glob yields native separators, and package specifiers always use "/".
|
||||
const specifier = `@opencode/ai/providers/${file.replace(/\.ts$/, "").replaceAll(path.sep, "/")}`
|
||||
const module = await import(specifier)
|
||||
return typeof module.model === "function" ? specifier : undefined
|
||||
}),
|
||||
Object.keys(manifest.exports)
|
||||
.filter((key) => key.startsWith("./providers/"))
|
||||
.map(async (key) => {
|
||||
const specifier = `@opencode/ai${key.slice(1)}`
|
||||
const module = await import(specifier)
|
||||
return typeof module.model === "function" ? specifier : undefined
|
||||
}),
|
||||
)
|
||||
const packages = entrypoints.filter((specifier) => specifier !== undefined).toSorted()
|
||||
|
||||
@@ -24,6 +25,23 @@ describe("Provider", () => {
|
||||
}
|
||||
})
|
||||
|
||||
test("keeps loading the hyphenated provider paths existing configs reference", async () => {
|
||||
for (const name of [
|
||||
"amazon-bedrock-mantle",
|
||||
"google-vertex-chat",
|
||||
"google-vertex-interactions",
|
||||
"google-vertex-messages",
|
||||
"google-vertex-mistral",
|
||||
"google-vertex-responses",
|
||||
"openai-compatible-responses",
|
||||
]) {
|
||||
const specifier = `@opencode/ai/providers/${name}`
|
||||
expect(Provider.builtinPackages.has(specifier)).toBe(true)
|
||||
const loaded = await Effect.runPromise(Provider.loadPackage(specifier))
|
||||
expect(loaded.model).toBeFunction()
|
||||
}
|
||||
})
|
||||
|
||||
test("passes flat settings to native packages without Core settings", () => {
|
||||
expect(
|
||||
Provider.nativeSettings({
|
||||
|
||||
@@ -18,8 +18,7 @@ import {
|
||||
} from "@opencode/ai/effect"
|
||||
import { OpenAIChat } from "@opencode/ai/protocols/openai-chat"
|
||||
import { AnthropicMessages, OpenAIResponses } from "@opencode/ai/protocols"
|
||||
import { compileRequest } from "@opencode/ai/route/client"
|
||||
import { TestLLM } from "@opencode/ai/testing"
|
||||
import { TestLLM, compileRequest } from "@opencode/ai/testing"
|
||||
import type { SessionHooks } from "@opencode/plugin/effect/session"
|
||||
import { Database } from "@opencode/core/database/database"
|
||||
import { makeLocationNode } from "@opencode/util/effect/app-node"
|
||||
@@ -95,17 +94,26 @@ type ToolBarrier = {
|
||||
active: number
|
||||
maxActive: number
|
||||
}
|
||||
const testLLM = TestLLM.layer({
|
||||
fallback: [],
|
||||
transformRequest: (request) =>
|
||||
LLMRequest.update(request, {
|
||||
system: request.system.map((part) => ({
|
||||
...part,
|
||||
text: part.text.replace(emptyCodeMode, ""),
|
||||
})),
|
||||
tools: request.tools.filter((tool) => tool.name !== "execute"),
|
||||
}),
|
||||
})
|
||||
class LLMRequests extends Context.Service<LLMRequests, LLMRequest[]>()("test/LLMRequests") {}
|
||||
const testLLM = Layer.unwrap(
|
||||
Effect.sync(() => {
|
||||
const requests: LLMRequest[] = []
|
||||
return TestLLM.testLayer({
|
||||
fallback: [],
|
||||
transformRequest: (request) => {
|
||||
const transformed = LLMRequest.update(request, {
|
||||
system: request.system.map((part) => ({
|
||||
...part,
|
||||
text: part.text.replace(emptyCodeMode, ""),
|
||||
})),
|
||||
tools: request.tools.filter((tool) => tool.name !== "execute"),
|
||||
})
|
||||
requests.push(transformed)
|
||||
return transformed
|
||||
},
|
||||
}).pipe(Layer.merge(Layer.succeed(LLMRequests, requests)))
|
||||
}),
|
||||
)
|
||||
type ModelLimit = { readonly context: number; readonly input?: number; readonly output: number }
|
||||
const defaultModelLimit = { context: 200_000, output: 32_000 }
|
||||
const modelLimits = new Map<string, ModelLimit>()
|
||||
@@ -413,7 +421,7 @@ const layer = Layer.unwrap(
|
||||
})
|
||||
const replacements: LayerNode.Replacements = [
|
||||
Snapshot.node.replace(Snapshot.noopLayer),
|
||||
LayerNodePlatform.llmClient.replace(TestLLM.clientLayer.pipe(Layer.provide(testLLM))),
|
||||
LayerNodePlatform.llmClient.replace(testLLM),
|
||||
SessionRunnerModel.node.replace(models),
|
||||
InstructionBuiltIns.node.replace(systemContext),
|
||||
InstructionDiscovery.node.replace(instructionContext),
|
||||
@@ -556,7 +564,8 @@ const setup = Effect.gen(function* () {
|
||||
yield* insertSession(sessionID)
|
||||
const state = yield* RunnerState
|
||||
const session = yield* Session.Service
|
||||
const llm = yield* TestLLM.Service
|
||||
const llm = yield* TestLLM.Test
|
||||
const requests = yield* LLMRequests
|
||||
const admit = (text: string) => session.prompt({ sessionID, text, resume: false })
|
||||
const resume = session.resume(sessionID)
|
||||
return Object.assign(state, {
|
||||
@@ -565,7 +574,7 @@ const setup = Effect.gen(function* () {
|
||||
sessionInbox,
|
||||
session,
|
||||
llm,
|
||||
requests: llm.requests,
|
||||
requests,
|
||||
admit,
|
||||
resume,
|
||||
context: session.context(sessionID),
|
||||
@@ -578,7 +587,7 @@ const setup = Effect.gen(function* () {
|
||||
}),
|
||||
// Pause coordinated Session.resume at its first model request, not a direct runner drain.
|
||||
resumePaused: Effect.gen(function* () {
|
||||
const gate = yield* llm.gate
|
||||
const gate = yield* llm.gate()
|
||||
const run = yield* resume.pipe(Effect.forkChild)
|
||||
yield* gate.started
|
||||
return { finish: gate.release.pipe(Effect.andThen(Fiber.join(run))) }
|
||||
@@ -1472,7 +1481,7 @@ describe("SessionRunnerLLM", () => {
|
||||
TestLLM.text("## Objective\n- Entry summary", "entry-summary"),
|
||||
TestLLM.text("Continued", "entry-continuation"),
|
||||
)
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
const run = yield* runner.drain({ sessionID, force: false }).pipe(Effect.forkChild)
|
||||
yield* stream.started
|
||||
const compaction = yield* s.sessionInbox.admitCompaction({
|
||||
@@ -2277,7 +2286,7 @@ describe("SessionRunnerLLM", () => {
|
||||
const first = yield* s.admit("STEER_A")
|
||||
const second = yield* s.admit("STEER_B")
|
||||
yield* s.llm.push(TestLLM.text("## Objective\n- Interrupted checkpoint", "summary"))
|
||||
const summary = yield* s.llm.gate
|
||||
const summary = yield* s.llm.gate()
|
||||
const compact = yield* s.session.compact({ sessionID })
|
||||
yield* summary.started
|
||||
expect(userTexts(s.requests[1]).at(-1)).toContain("Summarize only what the user and the assistant said and did")
|
||||
@@ -3392,14 +3401,14 @@ describe("SessionRunnerLLM", () => {
|
||||
TestLLM.stop(),
|
||||
TestLLM.stop(),
|
||||
)
|
||||
const first = yield* s.llm.gate
|
||||
const first = yield* s.llm.gate()
|
||||
const run = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* first.started
|
||||
expect(reads).toBe(1)
|
||||
expect(resolutions).toBe(1)
|
||||
expect(s.requests[0]?.model).toBe(recoveryModel)
|
||||
|
||||
const summary = yield* s.llm.gate
|
||||
const summary = yield* s.llm.gate()
|
||||
yield* first.release
|
||||
yield* summary.started
|
||||
s.systemBaseline = "Changed during compaction"
|
||||
@@ -3414,7 +3423,7 @@ describe("SessionRunnerLLM", () => {
|
||||
resume: false,
|
||||
})
|
||||
const steered = yield* s.admit("Steered during compaction")
|
||||
const retry = yield* s.llm.gate
|
||||
const retry = yield* s.llm.gate()
|
||||
yield* summary.release
|
||||
yield* retry.started
|
||||
|
||||
@@ -3633,12 +3642,12 @@ describe("SessionRunnerLLM", () => {
|
||||
[LLMEvent.providerError({ message: "prompt too long", classification: "context-overflow" })],
|
||||
TestLLM.text("## Objective\n- Interrupted", "text-summary"),
|
||||
)
|
||||
const first = yield* s.llm.gate
|
||||
const first = yield* s.llm.gate()
|
||||
yield* s.admit("Continue")
|
||||
const run = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* first.started
|
||||
|
||||
const summary = yield* s.llm.gate
|
||||
const summary = yield* s.llm.gate()
|
||||
yield* first.release
|
||||
yield* summary.started
|
||||
|
||||
@@ -3816,7 +3825,7 @@ describe("SessionRunnerLLM", () => {
|
||||
|
||||
scenario("consumes the full provider stream before recording its boundary and settling local tools", function* (s) {
|
||||
yield* s.admit("Echo this")
|
||||
const request = yield* s.llm.gate
|
||||
const request = yield* s.llm.gate()
|
||||
const tail = yield* Deferred.make<void>()
|
||||
const complete = yield* Deferred.make<void>()
|
||||
const finished = yield* Deferred.make<void>()
|
||||
@@ -4161,7 +4170,7 @@ describe("SessionRunnerLLM", () => {
|
||||
yield* s.admit("Run once")
|
||||
|
||||
yield* s.llm.push(TestLLM.text("Once", "text-once"))
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
|
||||
const first = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* stream.started
|
||||
@@ -4219,7 +4228,7 @@ describe("SessionRunnerLLM", () => {
|
||||
const runner = yield* SessionRunner.Service
|
||||
yield* s.admit("A")
|
||||
yield* s.llm.push(TestLLM.stop(), TestLLM.stop(), TestLLM.stop())
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
const run = yield* runner.drain({ sessionID, force: false }).pipe(Effect.forkChild)
|
||||
yield* stream.started
|
||||
|
||||
@@ -4243,7 +4252,7 @@ describe("SessionRunnerLLM", () => {
|
||||
const location = Location.Ref.make({ directory: AbsolutePath.make("/moved") })
|
||||
yield* s.admit("A")
|
||||
yield* s.llm.push(TestLLM.stop(), TestLLM.stop())
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
const run = yield* runner.drain({ sessionID, force: false }).pipe(Effect.forkChild)
|
||||
yield* stream.started
|
||||
|
||||
@@ -4277,7 +4286,7 @@ describe("SessionRunnerLLM", () => {
|
||||
yield* s.admit("Interrupt current work")
|
||||
|
||||
yield* s.llm.push([], TestLLM.stop())
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
|
||||
const run = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* stream.started
|
||||
@@ -4304,7 +4313,7 @@ describe("SessionRunnerLLM", () => {
|
||||
yield* s.admit("Interrupt current work")
|
||||
|
||||
yield* s.llm.push([], TestLLM.stop())
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
|
||||
const run = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* stream.started
|
||||
@@ -4417,13 +4426,13 @@ describe("SessionRunnerLLM", () => {
|
||||
yield* s.admit("Start working")
|
||||
|
||||
yield* s.llm.push(TestLLM.stop(), TestLLM.stop(), TestLLM.stop(), TestLLM.stop())
|
||||
const firstStream = yield* s.llm.gate
|
||||
const firstStream = yield* s.llm.gate()
|
||||
|
||||
const first = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* firstStream.started
|
||||
yield* s.session.prompt({ sessionID, text: "Queue first", delivery: "queue" })
|
||||
yield* s.session.prompt({ sessionID, text: "Queue second", delivery: "queue" })
|
||||
const secondStream = yield* s.llm.gate
|
||||
const secondStream = yield* s.llm.gate()
|
||||
yield* firstStream.release
|
||||
yield* secondStream.started
|
||||
yield* s.session.prompt({ sessionID, text: "Steer before next queued input" })
|
||||
@@ -4552,7 +4561,7 @@ describe("SessionRunnerLLM", () => {
|
||||
inputID: previous,
|
||||
})
|
||||
yield* s.llm.push(TestLLM.text("## Objective\n- New checkpoint", "new-summary"))
|
||||
const gate = yield* s.llm.gate
|
||||
const gate = yield* s.llm.gate()
|
||||
const next = yield* s.session.compact({ sessionID })
|
||||
yield* gate.started
|
||||
expect((yield* s.messages).filter((message) => message.type === "compaction").toReversed()).toMatchObject([
|
||||
@@ -4762,7 +4771,7 @@ describe("SessionRunnerLLM", () => {
|
||||
resume: false,
|
||||
})
|
||||
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
yield* execution.wake(sessionID)
|
||||
yield* stream.started
|
||||
yield* stream.release
|
||||
@@ -4783,7 +4792,7 @@ describe("SessionRunnerLLM", () => {
|
||||
s.requests.length = 0
|
||||
yield* s.llm.push(TestLLM.stop())
|
||||
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
yield* execution.wake(sessionID)
|
||||
yield* stream.started
|
||||
yield* stream.release
|
||||
@@ -4846,7 +4855,7 @@ describe("SessionRunnerLLM", () => {
|
||||
resume: false,
|
||||
})
|
||||
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
|
||||
const first = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* stream.started
|
||||
@@ -4889,7 +4898,7 @@ describe("SessionRunnerLLM", () => {
|
||||
yield* s.admit("Retry after failure")
|
||||
|
||||
yield* s.llm.push(Stream.fail(invalidRequest()))
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
|
||||
const first = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* stream.started
|
||||
@@ -5271,7 +5280,7 @@ describe("SessionRunnerLLM", () => {
|
||||
|
||||
scenario("interrupts a blocked step without local tool execution", function* (s) {
|
||||
yield* s.admit("Interrupt provider")
|
||||
const stream = yield* s.llm.gate
|
||||
const stream = yield* s.llm.gate()
|
||||
|
||||
const run = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* stream.started
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { Effect, Schema, SchemaGetter } from "effect"
|
||||
import { z } from "zod"
|
||||
import { emptyInputJsonSchema } from "@opencode/ai/tool"
|
||||
import { emptyInputJsonSchema } from "@opencode/ai/effect"
|
||||
import { Agent } from "@opencode/schema/agent"
|
||||
import { Session } from "@opencode/schema/session"
|
||||
import { SessionMessage } from "@opencode/schema/session-message"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
/** Plain-record narrowing. Excludes arrays so JSON object checks don't accept tuples as key/value bags. */
|
||||
export const isRecord = (value: unknown): value is Record<string, unknown> =>
|
||||
typeof value === "object" && value !== null && !Array.isArray(value)
|
||||
Reference in New Issue
Block a user