-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionsInvokeCommandApiCommand.g.cs
More file actions
117 lines (100 loc) · 5.35 KB
/
Copy pathFunctionsInvokeCommandApiCommand.g.cs
File metadata and controls
117 lines (100 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#nullable enable
#pragma warning disable CS0618
using System.CommandLine;
namespace Browserbase.CLI.Commands;
internal static partial class FunctionsInvokeCommandApiCommand
{
private static Argument<global::System.Guid> Id { get; } = new(
name: @"id")
{
Description = @"",
};
private static Option<object?> Params { get; } = new(
name: @"--params")
{
Description = @"JSON object that can be stored in a JSONB column",
};
private static Option<global::Browserbase.FunctionsInvokeRequestSessionCreateParams?> SessionCreateParams { get; } = new(
name: @"--session-create-params")
{
Description = @"",
};
private static Option<string?> Input { get; } = new(@"--input")
{
Description = "Load request JSON from a file path, '-' for stdin, or an inline JSON object/array string.",
};
private static Option<string?> RequestJson { get; } = new(@"--request-json")
{
Description = "Request body as JSON.",
Hidden = true,
};
private static Option<string?> RequestFile { get; } = new(@"--request-file")
{
Description = "Path to a JSON request file, or '-' for stdin.",
Hidden = true,
};
private static string FormatResponse(ParseResult parseResult, global::Browserbase.Invocation value, global::System.Text.Json.Serialization.JsonSerializerContext context, bool truncateLongStrings)
{
string? text = null;
CustomizeResponseText(parseResult, value, ref text);
if (!string.IsNullOrWhiteSpace(text))
{
return text;
}
var hints = new Dictionary<string, CliFormatHint>(StringComparer.OrdinalIgnoreCase)
{
};
CustomizeResponseFormatHints(hints);
return CliRuntime.FormatHumanReadable(value, context, truncateLongStrings, hints);
}
static partial void CustomizeResponseText(ParseResult parseResult, global::Browserbase.Invocation value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);
public static Command Create()
{
var command = new Command(@"functions-invoke", @"Invoke a Function");
command.Arguments.Add(Id);
command.Options.Add(Params);
command.Options.Add(SessionCreateParams);
command.Options.Add(Input);
command.Options.Add(RequestJson);
command.Options.Add(RequestFile);
command.Validators.Add(result =>
{
var hasInput = result.GetResult(Input) is not null;
var hasRequestJson = result.GetResult(RequestJson) is not null;
var hasRequestFile = result.GetResult(RequestFile) is not null;
var specifiedCount = (hasInput ? 1 : 0) + (hasRequestJson ? 1 : 0) + (hasRequestFile ? 1 : 0);
if (specifiedCount > 1)
{
result.AddError(@"Specify at most one of --input, --request-json, or --request-file.");
}
});
command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var __requestBase = await CliRuntime.ReadRequestOrDefaultAsync<global::Browserbase.FunctionsInvokeRequest>(
parseResult,
Input,
RequestJson,
RequestFile,
global::Browserbase.SourceGenerationContext.Default,
cancellationToken).ConfigureAwait(false);
var id = parseResult.GetRequiredValue(Id);
var @params = CliRuntime.WasSpecified(parseResult, Params) ? parseResult.GetValue(Params) : (__requestBase is { } __@paramsBaseValue ? __@paramsBaseValue.Params : default);
var sessionCreateParams = CliRuntime.WasSpecified(parseResult, SessionCreateParams) ? parseResult.GetValue(SessionCreateParams) : (__requestBase is { } __SessionCreateParamsBaseValue ? __SessionCreateParamsBaseValue.SessionCreateParams : default);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);
var response = await client.FunctionsInvokeAsync(
id: id,
@params: @params,
sessionCreateParams: sessionCreateParams,
cancellationToken: cancellationToken).ConfigureAwait(false);
await CliRuntime.WriteResponseAsync(
parseResult,
response,
global::Browserbase.SourceGenerationContext.Default,
FormatResponse,
cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false));
return command;
}
}