MCPcopy Index your code
hub / github.com/docker/docker-agent / jsObjectToStringMap

Function jsObjectToStringMap

cmd/wasm/bridge.go:73–89  ·  view source on GitHub ↗

jsObjectToStringMap converts a flat JS object {k: "v", ...} into a Go map[string]string. Non-string values are stringified via Object.toString. A null/undefined input yields a nil map.

(v js.Value)

Source from the content-addressed store, hash-verified

71// map[string]string. Non-string values are stringified via Object.toString.
72// A null/undefined input yields a nil map.
73func jsObjectToStringMap(v js.Value) map[string]string {
74 if v.Type() != js.TypeObject {
75 return nil
76 }
77 keys := js.Global().Get("Object").Call("keys", v)
78 out := make(map[string]string, keys.Length())
79 for i := 0; i < keys.Length(); i++ {
80 k := keys.Index(i).String()
81 val := v.Get(k)
82 if val.Type() == js.TypeString {
83 out[k] = val.String()
84 } else {
85 out[k] = val.Call("toString").String()
86 }
87 }
88 return out
89}
90
91// jsToMessages decodes a JS array of {role, content} objects into a slice of
92// chat.Message. We round-trip through JSON so any extra fields the JS side

Callers 1

chatJSFunction · 0.85

Calls 4

TypeMethod · 0.80
GetMethod · 0.65
LengthMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected