tiny.acp.PermissionRequest
Defined in protocol.
One session/request_permission request from the agent: the tool call it names, the decision, and the exact line.
API (13)
Actions
Public operations.
deinit: Frees every owned string with the given allocator and leaves the value undefined for a record built withfromClientRequest.fromClientRequest: Turns one parsed permission request and its decision into aPermissionRequestby readingparamsandparams.toolCallfrom a parsed request object and adding the given decision and line, as the client does for the preview and the record.
Fields and members
Public fields and members.
Source
Source: lib/acp/src/protocol.zig:455
zig
/// One `session/request_permission` request from the agent: the tool call it names, the decision,/// and the exact line. The caller records what the agent asked for and what was answered because/// the observer receives each permission request and its decision as one of these records. The/// client builds one twice per request: a preview for `permissionFn` with outcome `pending`, empty/// option fields, and an empty line, then the full record for `permissionCommitFn`. The record owns/// every `[]u8` field, and `deinit` frees them.pub const PermissionRequest = struct { /// The exact line the agent sent, trimmed of surrounding whitespace, and empty in the preview. /// The line is borrowed from the reader's buffer and remains valid only until /// `permissionCommitFn` returns. envelope: []const u8, /// The request's `params.sessionId`, empty when absent. session_id: []u8, /// The tool call's `toolCallId`, empty when absent. tool_call_id: []u8, /// The tool call's `title`, empty when absent. The permission policy matches its title prefixes /// against it. title: []u8, /// The tool call's `kind`, empty when the tool call omits a kind. tool_kind: []u8, /// The tool call's `status`, empty when absent. status: []u8, /// The id of the chosen option, empty when the outcome is `cancelled` and in the preview. option_id: []u8, /// The kind of the chosen option, such as `allow_once` or `reject_once`, empty when an option /// remains unchosen. option_kind: []u8, /// The decision: `selected`, `cancelled`, or `pending` in the preview. outcome: []u8, /// The number of options the agent offered. The field defaults to 0. options: usize = 0, /// A minified JSON copy of the request's `params` object. raw: []u8, /// Frees every owned string with the given allocator and leaves the value undefined for a /// record built with `fromClientRequest`. The call leaves the borrowed line alone. pub fn deinit(self: *PermissionRequest, allocator: Allocator) void { if (self.session_id.len != 0) allocator.free(self.session_id); if (self.tool_call_id.len != 0) allocator.free(self.tool_call_id); if (self.title.len != 0) allocator.free(self.title); if (self.tool_kind.len != 0) allocator.free(self.tool_kind); if (self.status.len != 0) allocator.free(self.status); if (self.option_id.len != 0) allocator.free(self.option_id); if (self.option_kind.len != 0) allocator.free(self.option_kind); if (self.outcome.len != 0) allocator.free(self.outcome); if (self.raw.len != 0) allocator.free(self.raw); self.* = undefined; } /// Turns one parsed permission request and its decision into a `PermissionRequest` by reading /// `params` and `params.toolCall` from a parsed request object and adding the given decision /// and line, as the client does for the preview and the record. The call fails with /// `error.AgentProtocolError` when `params` or `params.toolCall` is missing. The function /// copies every string it keeps with the allocator, keeps the line by reference, and the caller /// frees the rest with `deinit`. The call fails with `error.OutOfMemory` and leaves nothing /// allocated when a copy fails. pub fn fromClientRequest( allocator: Allocator, object: std.json.ObjectMap, envelope: []const u8, outcome: []const u8, option_id: []const u8, option_kind: []const u8, ) !PermissionRequest { const params = json.objectObject(object, "params") orelse return error.AgentProtocolError; const tool_call = json.objectObject(params, "toolCall") orelse return error.AgentProtocolError; const session_id = try optionalStringAlloc(allocator, params, "sessionId"); errdefer if (session_id.len != 0) allocator.free(session_id); const tool_call_id = try optionalStringAlloc(allocator, tool_call, "toolCallId"); errdefer if (tool_call_id.len != 0) allocator.free(tool_call_id); const title = try optionalStringAlloc(allocator, tool_call, "title"); errdefer if (title.len != 0) allocator.free(title); const tool_kind = try optionalStringAlloc(allocator, tool_call, "kind"); errdefer if (tool_kind.len != 0) allocator.free(tool_kind); const status = try optionalStringAlloc(allocator, tool_call, "status"); errdefer if (status.len != 0) allocator.free(status); const owned_option_id = try allocator.dupe(u8, option_id); errdefer allocator.free(owned_option_id); const owned_option_kind = try allocator.dupe(u8, option_kind); errdefer allocator.free(owned_option_kind); const owned_outcome = try allocator.dupe(u8, outcome); errdefer allocator.free(owned_outcome); const raw = try rawJsonAlloc(allocator, params); errdefer if (raw.len != 0) allocator.free(raw); return .{ .envelope = envelope, .session_id = session_id, .tool_call_id = tool_call_id, .title = title, .tool_kind = tool_kind, .status = status, .option_id = owned_option_id, .option_kind = owned_option_kind, .outcome = owned_outcome, .options = arrayLength(params, "options"), .raw = raw, }; }};Source: lib/acp/src/root.zig:77
zig
pub const PermissionRequest = protocol.PermissionRequest;Audit
| Definitions | 3 |
|---|---|
| Public names | 6 |
| Members | 11 |
| Version | 26.7.0 |
| Revision | daab053ee433 |