Merge nucleic/warm-north-vole-pf37 into dev

This commit is contained in:
2026-08-04 03:10:06 -07:00
parent f5ee895d3f
commit 817eeff081
6 changed files with 473 additions and 16 deletions
+45 -16
View File
@@ -27,22 +27,17 @@ public static class ClientIntents
writer.WriteString("t", "unsubscribe");
});
public static string ApprovalRespond(
string approvalId, string decisionType, JsonElement? updatedInput = null) =>
Write(writer =>
{
writer.WriteString("approvalID", approvalId);
writer.WritePropertyName("decision");
writer.WriteStartObject();
writer.WriteString("type", decisionType);
if (updatedInput is { } input)
{
writer.WritePropertyName("updatedInput");
input.WriteTo(writer);
}
writer.WriteEndObject();
writer.WriteString("t", "approvalRespond");
});
public static string ApprovalAllow(string approvalId, JsonElement? updatedInput = null) =>
ApprovalRespond(approvalId, "allow", updatedInput: updatedInput);
public static string ApprovalDeny(string approvalId, string? reason = null) =>
ApprovalRespond(approvalId, "deny", reason: reason);
public static string ApprovalAllowAlways(string approvalId, ApprovalAlwaysScope scope) =>
ApprovalRespond(approvalId, "allowAlways", scope: ScopeValue(scope));
public static string ApprovalCancelRun(string approvalId) =>
ApprovalRespond(approvalId, "cancelRun");
public static string SendInput(string sessionId, string text) => Write(writer =>
{
@@ -63,6 +58,33 @@ public static class ClientIntents
private static string TagOnly(string tag) => JsonSerializer.Serialize(
new TagOnlyIntent(tag), ProtocolJsonContext.Default.TagOnlyIntent);
private static string ApprovalRespond(
string approvalId, string decisionType, JsonElement? updatedInput = null,
string? scope = null, string? reason = null) => Write(writer =>
{
writer.WriteString("approvalID", approvalId);
writer.WritePropertyName("decision");
writer.WriteStartObject();
writer.WriteString("type", decisionType);
if (updatedInput is { } input)
{
writer.WritePropertyName("updatedInput");
input.WriteTo(writer);
}
if (scope is not null) writer.WriteString("scope", scope);
if (reason is not null) writer.WriteString("reason", reason);
writer.WriteEndObject();
writer.WriteString("t", "approvalRespond");
});
private static string ScopeValue(ApprovalAlwaysScope scope) => scope switch
{
ApprovalAlwaysScope.Session => "session",
ApprovalAlwaysScope.ToolName => "toolName",
ApprovalAlwaysScope.ToolNameWithPattern => "toolNameWithPattern",
_ => throw new ArgumentOutOfRangeException(nameof(scope)),
};
private static string Write(Action<Utf8JsonWriter> body)
{
using var stream = new MemoryStream();
@@ -78,3 +100,10 @@ public static class ClientIntents
return System.Text.Encoding.UTF8.GetString(stream.GetBuffer(), 0, checked((int)stream.Length));
}
}
public enum ApprovalAlwaysScope
{
Session,
ToolName,
ToolNameWithPattern,
}