MCPcopy Index your code
hub / github.com/github/copilot-sdk / Input

Method Input

go/session.go:1250–1297  ·  view source on GitHub ↗

Input shows a text input dialog. Returns the entered text, or empty string and false if the user declines/cancels.

(ctx context.Context, message string, opts *UIInputOptions)

Source from the content-addressed store, hash-verified

1248// Input shows a text input dialog. Returns the entered text, or empty string and
1249// false if the user declines/cancels.
1250func (ui *SessionUI) Input(ctx context.Context, message string, opts *UIInputOptions) (string, bool, error) {
1251 if err := ui.session.assertElicitation(); err != nil {
1252 return "", false, err
1253 }
1254 prop := &rpc.UIElicitationSchemaPropertyString{}
1255 if opts != nil {
1256 if opts.Title != "" {
1257 prop.Title = &opts.Title
1258 }
1259 if opts.Description != "" {
1260 prop.Description = &opts.Description
1261 }
1262 if opts.MinLength != nil {
1263 f := int64(*opts.MinLength)
1264 prop.MinLength = &f
1265 }
1266 if opts.MaxLength != nil {
1267 f := int64(*opts.MaxLength)
1268 prop.MaxLength = &f
1269 }
1270 if opts.Format != "" {
1271 format := rpc.UIElicitationSchemaPropertyStringFormat(opts.Format)
1272 prop.Format = &format
1273 }
1274 if opts.Default != "" {
1275 prop.Default = String(opts.Default)
1276 }
1277 }
1278 rpcResult, err := ui.session.RPC.UI.Elicitation(ctx, &rpc.UIElicitationRequest{
1279 Message: message,
1280 RequestedSchema: rpc.UIElicitationSchema{
1281 Type: rpc.UIElicitationSchemaTypeObject,
1282 Properties: map[string]rpc.UIElicitationSchemaProperty{
1283 "value": prop,
1284 },
1285 Required: []string{"value"},
1286 },
1287 })
1288 if err != nil {
1289 return "", false, err
1290 }
1291 if rpcResult.Action == rpc.UIElicitationResponseActionAccept {
1292 if value, ok := rpcResult.Content["value"].(rpc.UIElicitationStringValue); ok {
1293 return string(value), true, nil
1294 }
1295 }
1296 return "", false, nil
1297}
1298
1299// fromRPCElicitationResult converts the RPC result to the SDK ElicitationResult.
1300func fromRPCElicitationResult(r *rpc.UIElicitationResponse) *ElicitationResult {

Callers 2

TestUIElicitationE2EFunction · 0.80

Calls 3

StringFunction · 0.85
assertElicitationMethod · 0.45
ElicitationMethod · 0.45

Tested by 2

TestUIElicitationE2EFunction · 0.64