Skip to content

Commit 4bd8170

Browse files
Remove bad stdout usage
1 parent 15e8042 commit 4bd8170

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

src/docker.clj

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[clojure.string :as string]
99
[creds]
1010
jsonrpc
11+
[jsonrpc.logger :as logger]
1112
logging
1213
schema)
1314
(:import
@@ -35,10 +36,10 @@
3536
(curl/post
3637
(format "http://localhost/images/create?fromImage=%s" image)
3738
(merge
38-
{:raw-args ["--unix-socket" (let [f (fs/file "/var/run/docker.raw.sock")]
39-
(if (.exists f)
40-
"/var/run/docker.raw.sock"
41-
"/var/run/docker.sock"))]
39+
{:raw-args ["--unix-socket" (let [f (fs/file "/var/run/docker.raw.sock")]
40+
(if (.exists f)
41+
"/var/run/docker.raw.sock"
42+
"/var/run/docker.sock"))]
4243
:throw false}
4344
(when (or creds identity-token)
4445
{:headers {"X-Registry-Auth"
@@ -129,7 +130,7 @@
129130
:WorkingDir (or workdir "/project")}
130131
(when entrypoint {:Entrypoint entrypoint})
131132
(when command {:Cmd command})))
132-
ascii-payload (String. (.getBytes payload "ASCII")) ]
133+
ascii-payload (String. (.getBytes payload "ASCII"))]
133134
(curl/post
134135
"http://localhost/containers/create"
135136
{:raw-args ["--unix-socket" "/var/run/docker.sock"]
@@ -386,10 +387,10 @@
386387
(try
387388
(String. ^bytes (Arrays/copyOfRange ^bytes bytes 8 (count bytes)))
388389
(catch Throwable t
389-
(println t)
390+
(logger/error "not a docker stream: " t)
390391
"")))
391392

392-
(defn function-call-with-stdin
393+
(defn function-call-with-stdin
393394
"creates and starts container, then writes to stdin process
394395
returns container map with Id, and socket - socket is open socket to stdin"
395396
[m]
@@ -442,7 +443,7 @@
442443
"run container with stdin read from a file"
443444
[m]
444445
(let [x (docker/function-call-with-stdin
445-
(assoc m :content (or (-> m :stdin :content) (slurp (-> m :stdin :file)))))]
446+
(assoc m :content (or (-> m :stdin :content) (slurp (-> m :stdin :file)))))]
446447
(async/<!! (async/thread
447448
(Thread/sleep 10)
448449
(docker/finish-call x)))))
@@ -452,14 +453,36 @@
452453
returns ::container-response"
453454
[m]
454455
;; (schema/validate :schema/container-definition)
455-
(cond
456+
(cond
456457
(-> m :stdin)
457458
(run-with-stdin-content m)
458459
(true? (:background m))
459460
(run-background-function m)
460461
:else
461462
(run-function m)))
462463

464+
(comment
465+
(run-container
466+
{:image "vonwig/websocat:latest",
467+
:stdin
468+
{:content
469+
"{\"id\":1,\"method\":\"Page.navigate\",\"params\":{\"url\":\"https://www.docker.com\"}}"},
470+
:command
471+
["-n1"
472+
"--jsonrpc"
473+
"--jsonrpc-omit-jsonrpc"
474+
"http://host.docker.internal:9222/devtools/page/EF1106D0B121836079CE1582C85F6E9A"],
475+
:jsonrpc true,
476+
:host-dir "/Users/slim/docker/labs-ai-tools-for-devs",
477+
:debug true,
478+
:stream true,
479+
:jwt "xxxxxxx",
480+
:save-thread-volume true,
481+
:register [],
482+
:thread-id "thread",
483+
:user "jimclark106",
484+
:platform "darwin"}))
485+
463486
(defn get-login-info-from-desktop-backend
464487
"returns token or nil if not logged in or backend.sock is not available"
465488
[]

src/graph.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
[c h] (chunk-handler)
5050
request (merge
5151
(dissoc metadata :agent :host-dir :workdir :prompt-format :description :name :parameter-values :arguments :resources :defs) ; TODO should we just select relevant keys instead of removing bad ones
52-
{:messages messages
52+
{:messages (->> messages (map #(dissoc % :name :description)))
5353
:level level}
5454
(when (seq functions) {:tools functions})
5555
;; overrides from cli opts, NOT from metadata

src/prompts.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
(update :messages (fn [messages]
204204
(->> messages
205205
(map (partial renderer {}))
206-
(map #(dissoc % :name :description :title)))))
206+
(map #(dissoc % :title)))))
207207
(update :metadata dissoc :functions :tools :extractors)
208208
(assoc :functions (->> (or (:tools metadata) (:functions metadata)) (mapcat function-definition)))))))
209209

src/tools.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
(:workdir defaults))]
8383
{:workdir (first (interpolate arg-context wd))}))
8484

85-
(-> definition :stdin :file) (update-in [:stdin :file] (fn [s] (first (interpolate arg-context s))))
85+
(-> definition :container :stdin :file) (update-in [:stdin :file] (fn [s] (first (interpolate arg-context s))))
8686

87-
(-> definition :stdin :content) (update-in [:stdin :content] (fn [s] (first (interpolate arg-context s)))))]
87+
(-> definition :container :stdin :content) (update-in [:stdin :content] (fn [s] (first (interpolate arg-context s)))))]
8888
(jsonrpc/notify
8989
:message
9090
{:debug (format "function call %s"

test/jsonrpc/db_t.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
(->> @db/db*
4242
:mcp.prompts/registry
4343
vals
44-
(mapcat :mcp/prompt-registry))
44+
)
4545
(get-in (deref db/db*) [:mcp.prompts/registry "curl"])
4646
(server/receive-request "prompts/list" {:db* db/db*} {})
4747
(server/receive-request

0 commit comments

Comments
 (0)