47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import type { AgentToolContext, ToolCallContext } from "@oh-my-pi/pi-agent-core";
|
|
import type { CustomToolContext } from "../extensibility/custom-tools/types";
|
|
import type { ExtensionUIContext } from "../extensibility/extensions/types";
|
|
|
|
declare module "@oh-my-pi/pi-agent-core" {
|
|
interface AgentToolContext extends CustomToolContext {
|
|
ui?: ExtensionUIContext;
|
|
hasUI?: boolean;
|
|
toolNames?: string[];
|
|
toolCall?: ToolCallContext;
|
|
/** Set on `xd://` device dispatches: the write tool's outer approval gate
|
|
* already resolved this call at the mounted tool's tier, so the inner
|
|
* wrapper must not re-prompt for the same action (explicit per-tool
|
|
* policies and overrides still apply). */
|
|
xdevApproved?: boolean;
|
|
/** Set only after an interactive prompt approves provider computer safety checks. */
|
|
providerSafetyApproved?: boolean;
|
|
}
|
|
}
|
|
|
|
export class ToolContextStore {
|
|
#uiContext: ExtensionUIContext | undefined;
|
|
#hasUI = false;
|
|
#toolNames: string[] = [];
|
|
|
|
constructor(private readonly getBaseContext: () => CustomToolContext) {}
|
|
|
|
getContext(toolCall?: ToolCallContext): AgentToolContext {
|
|
return {
|
|
...this.getBaseContext(),
|
|
ui: this.#uiContext,
|
|
hasUI: this.#hasUI,
|
|
toolNames: this.#toolNames,
|
|
toolCall,
|
|
};
|
|
}
|
|
|
|
setUIContext(uiContext: ExtensionUIContext, hasUI: boolean): void {
|
|
this.#uiContext = uiContext;
|
|
this.#hasUI = hasUI;
|
|
}
|
|
|
|
setToolNames(names: string[]): void {
|
|
this.#toolNames = names;
|
|
}
|
|
}
|