54 lines
2.1 KiB
Go
54 lines
2.1 KiB
Go
// Package chattools is the harness-neutral half of the Pipelines chat tools:
|
|
// the MCP server a chat's model calls to show the operator a file, an image or
|
|
// an HTML view, or to notify their phone. The tools act on Pipelines itself,
|
|
// never on the harness or the workspace.
|
|
//
|
|
// The server (internal/server) owns tokens, persistence and the tool effects.
|
|
// The harness adapters (claude, codex, opencode) only need the endpoint URL to
|
|
// register, which they obtain from the Registry configured here, so none of
|
|
// them imports the server.
|
|
package chattools
|
|
|
|
import "sync"
|
|
|
|
// ServerName is the MCP server name every harness registers. It fixes the tool
|
|
// names the harnesses report: Claude "mcp__pipelines__show_file", OpenCode
|
|
// "pipelines_show_file", Codex "pipelines/show_file".
|
|
const ServerName = "pipelines"
|
|
|
|
// Registry issues the loopback MCP endpoint URLs harnesses register. Each URL
|
|
// embeds an unguessable token the server resolves to the chat it serves.
|
|
type Registry interface {
|
|
// SessionURL is the endpoint dedicated to one chat session, stable across
|
|
// server restarts so a detached harness process keeps working.
|
|
SessionURL(sessionID string) (string, error)
|
|
// PendingURL is an endpoint for a chat whose id the harness assigns when
|
|
// it creates it (a Codex thread). bind attaches it to that id; calls are
|
|
// refused until then.
|
|
PendingURL() (url string, bind func(sessionID string) error, err error)
|
|
// InstanceURL is the endpoint of one harness process that serves many
|
|
// chats (the OpenCode service). Its calls are attributed only to the one
|
|
// chat whose matching tool call is running at that moment.
|
|
InstanceURL(harness string) (string, error)
|
|
}
|
|
|
|
var (
|
|
mu sync.RWMutex
|
|
current Registry
|
|
)
|
|
|
|
// Configure installs the registry the harness adapters use. A nil registry
|
|
// disables registration: chats start without the Pipelines tools.
|
|
func Configure(registry Registry) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
current = registry
|
|
}
|
|
|
|
// Current returns the configured registry, or nil when tools are disabled.
|
|
func Current() Registry {
|
|
mu.RLock()
|
|
defer mu.RUnlock()
|
|
return current
|
|
}
|