mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-12 14:19:00 +01:00
Add capability-aware slash-goal controls, durable provider goal state, PRP v2 negotiation, autonomous goal execution, and safe local session recovery. Integrate with current master, preserve provider session identity, and verify the browser goal/chat/replacement/clear workflow and unsupported-agent rejection. Co-Authored-By: Paperclip <noreply@paperclip.ing>
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
export interface RunnerSessionGoalController {
|
|
control(input: RunnerSessionGoalControlInput): Promise<void>;
|
|
}
|
|
|
|
export interface RunnerSessionGoalControlInput {
|
|
requestId: string;
|
|
action: "create" | "edit" | "replace" | "pause" | "resume" | "clear";
|
|
objective?: string;
|
|
tokenBudget?: number | null;
|
|
}
|
|
|
|
interface GoalControllerBinding {
|
|
companyId: string;
|
|
issueId: string;
|
|
agentId: string;
|
|
runId: string;
|
|
}
|
|
|
|
interface RegisteredGoalController extends GoalControllerBinding {
|
|
controller: RunnerSessionGoalController;
|
|
generation: symbol;
|
|
}
|
|
|
|
const registrations = new Map<string, RegisteredGoalController>();
|
|
|
|
function bindingKey(input: Pick<GoalControllerBinding, "companyId" | "issueId" | "agentId">): string {
|
|
return `${input.companyId}:${input.issueId}:${input.agentId}`;
|
|
}
|
|
|
|
export function registerLiveRunnerGoalController(
|
|
binding: GoalControllerBinding,
|
|
controller: RunnerSessionGoalController,
|
|
): () => void {
|
|
const key = bindingKey(binding);
|
|
const generation = Symbol(binding.runId);
|
|
registrations.set(key, { ...binding, controller, generation });
|
|
return () => {
|
|
if (registrations.get(key)?.generation === generation) registrations.delete(key);
|
|
};
|
|
}
|
|
|
|
export function dispatchLiveRunnerGoalControl(
|
|
binding: Pick<GoalControllerBinding, "companyId" | "issueId" | "agentId">,
|
|
control: RunnerSessionGoalControlInput,
|
|
): { runId: string; completion: Promise<void> } | null {
|
|
const registered = registrations.get(bindingKey(binding));
|
|
if (!registered) return null;
|
|
return {
|
|
runId: registered.runId,
|
|
completion: Promise.resolve().then(() => registered.controller.control(control)),
|
|
};
|
|
}
|
|
|
|
export const runnerGoalControlBrokerInternals = {
|
|
resetForTests(): void {
|
|
registrations.clear();
|
|
},
|
|
};
|