-
Notifications
You must be signed in to change notification settings - Fork 0
ACP interactive host: composer permissions and elicitation #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5980fc8
feat(schemas): add approval and elicitation wire contracts
soorya-u 61babd0
feat(worker): block ACP permissions and elicitation until respond
soorya-u 838240d
feat(view): fold approvals and elicitations into conversation views
soorya-u 3c3ba51
feat(hooks): respond RPCs, non-blocking send, and draft hydration
soorya-u 89f29b0
feat(web): composer interactive prompts and UX polish
soorya-u 505d770
docs(openspec): archive acp-interactive-host and sync main specs
soorya-u bbfdc17
test(cli): pass turnId into runTurn call sites
soorya-u dfe6a03
fix(acp): address interactive host review feedback
soorya-u File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,9 @@ | ||
| import { PermissionDecision, type RuntimeHost } from "@acp-kit/core"; | ||
| import type { RuntimeHost } from "@acp-kit/core"; | ||
| import { createInteractiveHost } from "./interactive"; | ||
|
|
||
| /** Interactive ACP host (permissions block until respondApproval). */ | ||
| export function createDefaultHost( | ||
| onAgentExit?: RuntimeHost["onAgentExit"] | ||
| ): RuntimeHost { | ||
| return { | ||
| requestPermission: (request) => { | ||
| const allow = | ||
| request.options.find((o) => o.kind === "allow_once") ?? | ||
| request.options.find((o) => o.kind === "allow_always"); | ||
|
|
||
| if (!allow?.optionId) return Promise.resolve(PermissionDecision.Deny); | ||
|
|
||
| return Promise.resolve( | ||
| allow.kind === "allow_always" | ||
| ? PermissionDecision.AllowAlways | ||
| : PermissionDecision.AllowOnce | ||
| ); | ||
| }, | ||
| onAgentExit, | ||
| }; | ||
| return createInteractiveHost(onAgentExit); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { PermissionDecision } from "@acp-kit/core"; | ||
| import { InteractivePendingRegistry } from "./interactive"; | ||
|
|
||
| describe("InteractivePendingRegistry", () => { | ||
| test("blocks permission until respondApproval resolves", async () => { | ||
| const registry = new InteractivePendingRegistry(); | ||
| const events: unknown[] = []; | ||
| registry.bindTurn({ | ||
| sessionId: "session-1", | ||
| threadId: "thread-1", | ||
| turnId: "turn-1", | ||
| pushEvent: (event) => events.push(event), | ||
| }); | ||
|
|
||
| const pending = registry.requestPermission({ | ||
| sessionId: "session-1", | ||
| toolCallId: "tool-1", | ||
| toolName: "edit", | ||
| title: "Write file", | ||
| input: {}, | ||
| options: [ | ||
| { optionId: "allow-once", name: "Allow", kind: "allow_once" }, | ||
| { optionId: "reject-once", name: "Reject", kind: "reject_once" }, | ||
| ], | ||
| raw: { | ||
| sessionId: "session-1", | ||
| toolCall: { toolCallId: "tool-1", title: "Write file" }, | ||
| options: [ | ||
| { optionId: "allow-once", name: "Allow", kind: "allow_once" }, | ||
| { optionId: "reject-once", name: "Reject", kind: "reject_once" }, | ||
| ], | ||
| } as never, | ||
| }); | ||
|
|
||
| expect(events).toHaveLength(1); | ||
| expect(events[0]).toMatchObject({ type: "approval_request" }); | ||
|
|
||
| let settled = false; | ||
| pending | ||
| .then(() => { | ||
| settled = true; | ||
| }) | ||
| .catch(() => undefined); | ||
| await Promise.resolve(); | ||
| expect(settled).toBe(false); | ||
|
|
||
| expect( | ||
| registry.respondApproval({ | ||
| threadId: "thread-1", | ||
| toolCallId: "tool-1", | ||
| optionId: "allow-once", | ||
| }) | ||
| ).toEqual({ turnId: "turn-1" }); | ||
|
|
||
| await expect(pending).resolves.toBe(PermissionDecision.AllowOnce); | ||
| }); | ||
|
|
||
| test("cancel denies pending permissions and declines elicitations", async () => { | ||
| const registry = new InteractivePendingRegistry(); | ||
| registry.bindTurn({ | ||
| sessionId: "session-1", | ||
| threadId: "thread-1", | ||
| turnId: "turn-1", | ||
| pushEvent: () => undefined, | ||
| }); | ||
|
|
||
| const permission = registry.requestPermission({ | ||
| sessionId: "session-1", | ||
| toolCallId: "tool-1", | ||
| toolName: "bash", | ||
| title: "Run", | ||
| input: {}, | ||
| options: [{ optionId: "allow-once", name: "Allow", kind: "allow_once" }], | ||
| raw: { | ||
| sessionId: "session-1", | ||
| toolCall: { toolCallId: "tool-1", title: "Run" }, | ||
| options: [ | ||
| { optionId: "allow-once", name: "Allow", kind: "allow_once" }, | ||
| ], | ||
| } as never, | ||
| }); | ||
|
|
||
| const elicitation = registry.awaitElicitation({ | ||
| sessionId: "session-1", | ||
| elicitationId: "elicit-1", | ||
| event: { | ||
| type: "elicitation_request", | ||
| sessionId: "session-1", | ||
| request: { | ||
| mode: "form", | ||
| elicitationId: "elicit-1", | ||
| message: "Name?", | ||
| requestedSchema: { | ||
| type: "object", | ||
| properties: { name: { type: "string" } }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| registry.clearThread("thread-1"); | ||
|
|
||
| await expect(permission).resolves.toBe(PermissionDecision.Deny); | ||
| await expect(elicitation).resolves.toEqual({ action: "decline" }); | ||
| }); | ||
|
|
||
| test("elicitation blocks until respondElicitation", async () => { | ||
| const registry = new InteractivePendingRegistry(); | ||
| registry.bindTurn({ | ||
| sessionId: "session-1", | ||
| threadId: "thread-1", | ||
| turnId: "turn-1", | ||
| pushEvent: () => undefined, | ||
| }); | ||
|
|
||
| const pending = registry.awaitElicitation({ | ||
| sessionId: "session-1", | ||
| elicitationId: "elicit-1", | ||
| event: { | ||
| type: "elicitation_request", | ||
| sessionId: "session-1", | ||
| request: { | ||
| mode: "url", | ||
| elicitationId: "elicit-1", | ||
| url: "https://example.com", | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect( | ||
| registry.respondElicitation({ | ||
| threadId: "thread-1", | ||
| elicitationId: "elicit-1", | ||
| action: "decline", | ||
| }) | ||
| ).toEqual({ turnId: "turn-1" }); | ||
|
|
||
| await expect(pending).resolves.toEqual({ action: "decline" }); | ||
| }); | ||
|
|
||
| test("respondApproval rejects wrong thread", () => { | ||
| const registry = new InteractivePendingRegistry(); | ||
| registry.bindTurn({ | ||
| sessionId: "session-1", | ||
| threadId: "thread-1", | ||
| turnId: "turn-1", | ||
| pushEvent: () => undefined, | ||
| }); | ||
|
|
||
| const pending = registry.requestPermission({ | ||
| sessionId: "session-1", | ||
| toolCallId: "tool-1", | ||
| toolName: "edit", | ||
| title: "Write", | ||
| input: {}, | ||
| options: [{ optionId: "allow-once", name: "Allow", kind: "allow_once" }], | ||
| raw: { | ||
| sessionId: "session-1", | ||
| toolCall: { toolCallId: "tool-1", title: "Write" }, | ||
| options: [ | ||
| { optionId: "allow-once", name: "Allow", kind: "allow_once" }, | ||
| ], | ||
| } as never, | ||
| }); | ||
| pending.catch(() => undefined); | ||
|
|
||
| expect( | ||
| registry.respondApproval({ | ||
| threadId: "other-thread", | ||
| toolCallId: "tool-1", | ||
| optionId: "allow-once", | ||
| }) | ||
| ).toBeNull(); | ||
|
|
||
| expect( | ||
| registry.respondApproval({ | ||
| threadId: "thread-1", | ||
| toolCallId: "tool-1", | ||
| optionId: "allow-once", | ||
| }) | ||
| ).toEqual({ turnId: "turn-1" }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.