feat(core): attach global native tools (#30832)
This commit is contained in:
@@ -3,6 +3,7 @@ export { Agent } from "./agent"
|
||||
export { Model } from "./model"
|
||||
export { OpenCode } from "./opencode"
|
||||
export { Session } from "./session"
|
||||
export { Tool } from "./tool"
|
||||
export { Location } from "./location"
|
||||
export { Prompt } from "../session/prompt"
|
||||
export { AbsolutePath } from "../schema"
|
||||
|
||||
@@ -9,10 +9,13 @@ import { SessionV2 } from "../session"
|
||||
import * as SessionExecutionLocal from "../session/execution/local"
|
||||
import { SessionProjector } from "../session/projector"
|
||||
import { SessionStore } from "../session/store"
|
||||
import { ApplicationTools } from "../tool/application-tools"
|
||||
import { Session } from "./session"
|
||||
import { Tool } from "./tool"
|
||||
|
||||
export interface Interface {
|
||||
readonly sessions: Session.Interface
|
||||
readonly tools: Tool.Service
|
||||
}
|
||||
|
||||
/** Intentional public native API for Effect applications embedding OpenCode. */
|
||||
@@ -28,13 +31,16 @@ const SessionsLayer = SessionV2.layer.pipe(
|
||||
Layer.provide(ProjectV2.defaultLayer),
|
||||
Layer.orDie,
|
||||
)
|
||||
const ApplicationToolsLayer = ApplicationTools.layer
|
||||
|
||||
// TODO: Accept explicit storage so tests and embeddings can select disposable or application-owned persistence.
|
||||
export const layer = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const sessions = yield* SessionV2.Service
|
||||
const tools = yield* ApplicationTools.Service
|
||||
return Service.of({
|
||||
tools: { attach: tools.attach },
|
||||
sessions: {
|
||||
create: (input) =>
|
||||
sessions.create({
|
||||
@@ -65,6 +71,6 @@ export const layer = Layer.effect(
|
||||
},
|
||||
})
|
||||
}),
|
||||
).pipe(Layer.provide(SessionsLayer))
|
||||
).pipe(Layer.provide(Layer.merge(ApplicationToolsLayer, SessionsLayer)))
|
||||
|
||||
// TODO: Add OpenCode.create(...) as the Promise facade over the same native API semantics.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
export * as Tool from "./tool"
|
||||
|
||||
import { Effect, Scope } from "effect"
|
||||
import type { NativeTool } from "../tool/native"
|
||||
|
||||
export { Failure, make } from "../tool/native"
|
||||
export type { Any, Content, Context, Executable } from "../tool/native"
|
||||
|
||||
export interface Service {
|
||||
/**
|
||||
* Attach same-process tools to this OpenCode instance for the current Scope.
|
||||
* Location tools with the same name take precedence where they are installed.
|
||||
* Closing the Scope removes the tools immediately, so calls that have not
|
||||
* started settling may fail because the tool is no longer available.
|
||||
*/
|
||||
readonly attach: (
|
||||
tools: Readonly<Record<string, NativeTool.Any>>,
|
||||
) => Effect.Effect<void, never, Scope.Scope>
|
||||
}
|
||||
Reference in New Issue
Block a user