refactor(plugin): remove async facade exports (#22367)
This commit is contained in:
@@ -73,6 +73,7 @@ export namespace Agent {
|
|||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const config = yield* Config.Service
|
const config = yield* Config.Service
|
||||||
const auth = yield* Auth.Service
|
const auth = yield* Auth.Service
|
||||||
|
const plugin = yield* Plugin.Service
|
||||||
const skill = yield* Skill.Service
|
const skill = yield* Skill.Service
|
||||||
const provider = yield* Provider.Service
|
const provider = yield* Provider.Service
|
||||||
|
|
||||||
@@ -335,9 +336,7 @@ export namespace Agent {
|
|||||||
const language = yield* provider.getLanguage(resolved)
|
const language = yield* provider.getLanguage(resolved)
|
||||||
|
|
||||||
const system = [PROMPT_GENERATE]
|
const system = [PROMPT_GENERATE]
|
||||||
yield* Effect.promise(() =>
|
yield* plugin.trigger("experimental.chat.system.transform", { model: resolved }, { system })
|
||||||
Plugin.trigger("experimental.chat.system.transform", { model: resolved }, { system }),
|
|
||||||
)
|
|
||||||
const existing = yield* InstanceState.useEffect(state, (s) => s.list())
|
const existing = yield* InstanceState.useEffect(state, (s) => s.list())
|
||||||
|
|
||||||
// TODO: clean this up so provider specific logic doesnt bleed over
|
// TODO: clean this up so provider specific logic doesnt bleed over
|
||||||
@@ -398,6 +397,7 @@ export namespace Agent {
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const defaultLayer = layer.pipe(
|
export const defaultLayer = layer.pipe(
|
||||||
|
Layer.provide(Plugin.defaultLayer),
|
||||||
Layer.provide(Provider.defaultLayer),
|
Layer.provide(Provider.defaultLayer),
|
||||||
Layer.provide(Auth.defaultLayer),
|
Layer.provide(Auth.defaultLayer),
|
||||||
Layer.provide(Config.defaultLayer),
|
Layer.provide(Config.defaultLayer),
|
||||||
|
|||||||
@@ -340,6 +340,12 @@ export const ProvidersLoginCommand = cmd({
|
|||||||
}
|
}
|
||||||
return filtered
|
return filtered
|
||||||
})
|
})
|
||||||
|
const hooks = await AppRuntime.runPromise(
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const plugin = yield* Plugin.Service
|
||||||
|
return yield* plugin.list()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
const priority: Record<string, number> = {
|
const priority: Record<string, number> = {
|
||||||
opencode: 0,
|
opencode: 0,
|
||||||
@@ -351,7 +357,7 @@ export const ProvidersLoginCommand = cmd({
|
|||||||
vercel: 6,
|
vercel: 6,
|
||||||
}
|
}
|
||||||
const pluginProviders = resolvePluginProviders({
|
const pluginProviders = resolvePluginProviders({
|
||||||
hooks: await Plugin.list(),
|
hooks,
|
||||||
existingProviders: providers,
|
existingProviders: providers,
|
||||||
disabled,
|
disabled,
|
||||||
enabled,
|
enabled,
|
||||||
@@ -408,7 +414,7 @@ export const ProvidersLoginCommand = cmd({
|
|||||||
provider = selected as string
|
provider = selected as string
|
||||||
}
|
}
|
||||||
|
|
||||||
const plugin = await Plugin.list().then((x) => x.findLast((x) => x.auth?.provider === provider))
|
const plugin = hooks.findLast((x) => x.auth?.provider === provider)
|
||||||
if (plugin && plugin.auth) {
|
if (plugin && plugin.auth) {
|
||||||
const handled = await handlePluginAuth({ auth: plugin.auth }, provider, args.method)
|
const handled = await handlePluginAuth({ auth: plugin.auth }, provider, args.method)
|
||||||
if (handled) return
|
if (handled) return
|
||||||
@@ -422,7 +428,7 @@ export const ProvidersLoginCommand = cmd({
|
|||||||
if (prompts.isCancel(custom)) throw new UI.CancelledError()
|
if (prompts.isCancel(custom)) throw new UI.CancelledError()
|
||||||
provider = custom.replace(/^@ai-sdk\//, "")
|
provider = custom.replace(/^@ai-sdk\//, "")
|
||||||
|
|
||||||
const customPlugin = await Plugin.list().then((x) => x.findLast((x) => x.auth?.provider === provider))
|
const customPlugin = hooks.findLast((x) => x.auth?.provider === provider)
|
||||||
if (customPlugin && customPlugin.auth) {
|
if (customPlugin && customPlugin.auth) {
|
||||||
const handled = await handlePluginAuth({ auth: customPlugin.auth }, provider, args.method)
|
const handled = await handlePluginAuth({ auth: customPlugin.auth }, provider, args.method)
|
||||||
if (handled) return
|
if (handled) return
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import { CloudflareAIGatewayAuthPlugin, CloudflareWorkersAuthPlugin } from "./cl
|
|||||||
import { Effect, Layer, Context, Stream } from "effect"
|
import { Effect, Layer, Context, Stream } from "effect"
|
||||||
import { EffectLogger } from "@/effect/logger"
|
import { EffectLogger } from "@/effect/logger"
|
||||||
import { InstanceState } from "@/effect/instance-state"
|
import { InstanceState } from "@/effect/instance-state"
|
||||||
import { makeRuntime } from "@/effect/run-service"
|
|
||||||
import { errorMessage } from "@/util/error"
|
import { errorMessage } from "@/util/error"
|
||||||
import { PluginLoader } from "./loader"
|
import { PluginLoader } from "./loader"
|
||||||
import { parsePluginSpecifier, readPluginId, readV1Plugin, resolvePluginId } from "./shared"
|
import { parsePluginSpecifier, readPluginId, readV1Plugin, resolvePluginId } from "./shared"
|
||||||
@@ -290,21 +289,4 @@ export namespace Plugin {
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const defaultLayer = layer.pipe(Layer.provide(Bus.layer), Layer.provide(Config.defaultLayer))
|
export const defaultLayer = layer.pipe(Layer.provide(Bus.layer), Layer.provide(Config.defaultLayer))
|
||||||
const { runPromise } = makeRuntime(Service, defaultLayer)
|
|
||||||
|
|
||||||
export async function trigger<
|
|
||||||
Name extends TriggerName,
|
|
||||||
Input = Parameters<Required<Hooks>[Name]>[0],
|
|
||||||
Output = Parameters<Required<Hooks>[Name]>[1],
|
|
||||||
>(name: Name, input: Input, output: Output): Promise<Output> {
|
|
||||||
return runPromise((svc) => svc.trigger(name, input, output))
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function list(): Promise<Hooks[]> {
|
|
||||||
return runPromise((svc) => svc.list())
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function init() {
|
|
||||||
return runPromise((svc) => svc.init())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { afterAll, afterEach, describe, expect, spyOn, test } from "bun:test"
|
import { afterAll, afterEach, describe, expect, spyOn, test } from "bun:test"
|
||||||
|
import { Effect } from "effect"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { pathToFileURL } from "url"
|
import { pathToFileURL } from "url"
|
||||||
@@ -29,9 +30,11 @@ afterEach(async () => {
|
|||||||
async function load(dir: string) {
|
async function load(dir: string) {
|
||||||
return Instance.provide({
|
return Instance.provide({
|
||||||
directory: dir,
|
directory: dir,
|
||||||
fn: async () => {
|
fn: async () =>
|
||||||
await Plugin.list()
|
Effect.gen(function* () {
|
||||||
},
|
const plugin = yield* Plugin.Service
|
||||||
|
yield* plugin.list()
|
||||||
|
}).pipe(Effect.provide(Plugin.defaultLayer), Effect.runPromise),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { afterAll, afterEach, describe, expect, test } from "bun:test"
|
import { afterAll, afterEach, describe, expect, test } from "bun:test"
|
||||||
|
import { Effect } from "effect"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { pathToFileURL } from "url"
|
import { pathToFileURL } from "url"
|
||||||
import { tmpdir } from "../fixture/fixture"
|
import { tmpdir } from "../fixture/fixture"
|
||||||
@@ -56,20 +57,22 @@ describe("plugin.trigger", () => {
|
|||||||
|
|
||||||
const out = await Instance.provide({
|
const out = await Instance.provide({
|
||||||
directory: tmp.path,
|
directory: tmp.path,
|
||||||
fn: async () => {
|
fn: async () =>
|
||||||
const out = { system: [] as string[] }
|
Effect.gen(function* () {
|
||||||
await Plugin.trigger(
|
const plugin = yield* Plugin.Service
|
||||||
"experimental.chat.system.transform",
|
const out = { system: [] as string[] }
|
||||||
{
|
yield* plugin.trigger(
|
||||||
model: {
|
"experimental.chat.system.transform",
|
||||||
providerID: "anthropic",
|
{
|
||||||
modelID: "claude-sonnet-4-6",
|
model: {
|
||||||
} as any,
|
providerID: "anthropic",
|
||||||
},
|
modelID: "claude-sonnet-4-6",
|
||||||
out,
|
} as any,
|
||||||
)
|
},
|
||||||
return out
|
out,
|
||||||
},
|
)
|
||||||
|
return out
|
||||||
|
}).pipe(Effect.provide(Plugin.defaultLayer), Effect.runPromise),
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(out.system).toEqual(["sync"])
|
expect(out.system).toEqual(["sync"])
|
||||||
@@ -90,20 +93,22 @@ describe("plugin.trigger", () => {
|
|||||||
|
|
||||||
const out = await Instance.provide({
|
const out = await Instance.provide({
|
||||||
directory: tmp.path,
|
directory: tmp.path,
|
||||||
fn: async () => {
|
fn: async () =>
|
||||||
const out = { system: [] as string[] }
|
Effect.gen(function* () {
|
||||||
await Plugin.trigger(
|
const plugin = yield* Plugin.Service
|
||||||
"experimental.chat.system.transform",
|
const out = { system: [] as string[] }
|
||||||
{
|
yield* plugin.trigger(
|
||||||
model: {
|
"experimental.chat.system.transform",
|
||||||
providerID: "anthropic",
|
{
|
||||||
modelID: "claude-sonnet-4-6",
|
model: {
|
||||||
} as any,
|
providerID: "anthropic",
|
||||||
},
|
modelID: "claude-sonnet-4-6",
|
||||||
out,
|
} as any,
|
||||||
)
|
},
|
||||||
return out
|
out,
|
||||||
},
|
)
|
||||||
|
return out
|
||||||
|
}).pipe(Effect.provide(Plugin.defaultLayer), Effect.runPromise),
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(out.system).toEqual(["async"])
|
expect(out.system).toEqual(["async"])
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { afterAll, afterEach, describe, expect, test } from "bun:test"
|
import { afterAll, afterEach, describe, expect, test } from "bun:test"
|
||||||
|
import { Effect } from "effect"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { pathToFileURL } from "url"
|
import { pathToFileURL } from "url"
|
||||||
import { tmpdir } from "../fixture/fixture"
|
import { tmpdir } from "../fixture/fixture"
|
||||||
@@ -72,15 +73,17 @@ describe("plugin.workspace", () => {
|
|||||||
|
|
||||||
const info = await Instance.provide({
|
const info = await Instance.provide({
|
||||||
directory: tmp.path,
|
directory: tmp.path,
|
||||||
fn: async () => {
|
fn: async () =>
|
||||||
await Plugin.init()
|
Effect.gen(function* () {
|
||||||
return Workspace.create({
|
const plugin = yield* Plugin.Service
|
||||||
type: tmp.extra.type,
|
yield* plugin.init()
|
||||||
branch: null,
|
return Workspace.create({
|
||||||
extra: { key: "value" },
|
type: tmp.extra.type,
|
||||||
projectID: Instance.project.id,
|
branch: null,
|
||||||
})
|
extra: { key: "value" },
|
||||||
},
|
projectID: Instance.project.id,
|
||||||
|
})
|
||||||
|
}).pipe(Effect.provide(Plugin.defaultLayer), Effect.runPromise),
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(info.type).toBe(tmp.extra.type)
|
expect(info.type).toBe(tmp.extra.type)
|
||||||
|
|||||||
@@ -2436,10 +2436,15 @@ test("plugin config providers persist after instance dispose", async () => {
|
|||||||
|
|
||||||
const first = await Instance.provide({
|
const first = await Instance.provide({
|
||||||
directory: tmp.path,
|
directory: tmp.path,
|
||||||
fn: async () => {
|
fn: async () =>
|
||||||
await Plugin.init()
|
AppRuntime.runPromise(
|
||||||
return list()
|
Effect.gen(function* () {
|
||||||
},
|
const plugin = yield* Plugin.Service
|
||||||
|
const provider = yield* Provider.Service
|
||||||
|
yield* plugin.init()
|
||||||
|
return yield* provider.list()
|
||||||
|
}),
|
||||||
|
),
|
||||||
})
|
})
|
||||||
expect(first[ProviderID.make("demo")]).toBeDefined()
|
expect(first[ProviderID.make("demo")]).toBeDefined()
|
||||||
expect(first[ProviderID.make("demo")].models[ModelID.make("chat")]).toBeDefined()
|
expect(first[ProviderID.make("demo")].models[ModelID.make("chat")]).toBeDefined()
|
||||||
|
|||||||
Reference in New Issue
Block a user