MCPcopy Create free account
hub / github.com/diillson/chatcli / parseImageInvocation

Function parseImageInvocation

cli/plugins/builtin_image.go:324–360  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

322}
323
324func parseImageInvocation(args []string) (string, string, error) {
325 payload := strings.TrimSpace(strings.Join(args, " "))
326 if strings.HasPrefix(payload, "{") {
327 var raw map[string]json.RawMessage
328 if err := json.Unmarshal([]byte(payload), &raw); err != nil {
329 return "", "", fmt.Errorf("parse envelope: %w", err)
330 }
331 var cmdStr string
332 if rc, ok := raw["cmd"]; ok {
333 _ = json.Unmarshal(rc, &cmdStr)
334 }
335 canon := canonicalImageCmd(cmdStr)
336 if canon == "" {
337 if !isFlatArgs(raw) {
338 return "", "", fmt.Errorf("missing or unknown cmd %q (valid: gen|status)", cmdStr)
339 }
340 canon = "gen" // flat native args, e.g. {"prompt":"..."}
341 }
342 var inner string
343 if rargs, ok := raw["args"]; ok && len(rargs) > 0 {
344 inner = string(rargs)
345 } else {
346 delete(raw, "cmd")
347 b, _ := json.Marshal(raw)
348 inner = string(b)
349 }
350 return canon, inner, nil
351 }
352 if len(args) == 0 {
353 return "", "", fmt.Errorf("empty args")
354 }
355 canon := canonicalImageCmd(args[0])
356 if canon == "" {
357 return "", "", fmt.Errorf("expected JSON envelope or subcommand; got %q", args[0])
358 }
359 return canon, argvInner(args[1:], "prompt", nil, map[string]bool{"n": true}), nil
360}
361
362func canonicalImageCmd(s string) string {
363 switch strings.ToLower(strings.TrimSpace(s)) {

Callers 2

ExecuteWithStreamMethod · 0.85
DescribeCallMethod · 0.85

Calls 4

canonicalImageCmdFunction · 0.85
isFlatArgsFunction · 0.85
argvInnerFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected