lampson 0.5.5 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lampson.js +1 -1
- package/chat.syn +7 -2
- package/cli.syn +3 -0
- package/hub.tpl.syn +3 -0
- package/lib/agents.syn +30 -13
- package/lib/approvals.syn +4 -1
- package/lib/loop.syn +103 -56
- package/lib/mailbox.syn +29 -2
- package/lib/prompt.syn +3 -3
- package/lib/runtime.syn +19 -0
- package/lib/settings.syn +23 -0
- package/lib/webchat.syn +373 -0
- package/package.json +3 -2
- package/public/css/chat.css +28 -0
- package/public/css/layout.css +3 -1
- package/public/index.html +3 -0
- package/public/js/app.js +2 -1
- package/public/js/chat.js +148 -25
- package/public/js/core.js +32 -13
- package/public/js/editor.js +11 -1
- package/public/js/markdown.js +72 -0
- package/public/js/sessions.js +31 -10
- package/public/js/tree.js +2 -1
- package/public/vendor/README.md +8 -0
- package/public/vendor/dompurify.LICENSE +202 -0
- package/public/vendor/marked.LICENSE +44 -0
- package/public/vendor/marked.umd.js +92 -0
- package/public/vendor/purify.min.js +7 -0
- package/run.syn +5 -0
- package/synsema.json +3 -0
- package/web.syn +104 -63
package/web.syn
CHANGED
|
@@ -49,6 +49,9 @@ require file("memory")
|
|
|
49
49
|
require file("memory/**")
|
|
50
50
|
require file(".lampson")
|
|
51
51
|
require file(".lampson/**")
|
|
52
|
+
-- Config compartida: el destino de esta junction queda fuera del .lampson del workspace.
|
|
53
|
+
require file(".lampson/global")
|
|
54
|
+
require file(".lampson/global/**")
|
|
52
55
|
require file.read("public")
|
|
53
56
|
require file.read("public/**")
|
|
54
57
|
|
|
@@ -82,6 +85,7 @@ use "./lib/runtime.syn" as runtime
|
|
|
82
85
|
use "./lib/api.syn" as api
|
|
83
86
|
use "./lib/apikeys.syn" as apikeys
|
|
84
87
|
use "./lib/mailbox.syn" as mailbox
|
|
88
|
+
use "./lib/webchat.syn" as webchat
|
|
85
89
|
use "./lib/teamrun.syn" as teamrun
|
|
86
90
|
use "./lib/teams.syn" as teams
|
|
87
91
|
use "./lib/channels.syn" as channels
|
|
@@ -129,6 +133,9 @@ task lampson_subagent(spec_json)
|
|
|
129
133
|
task lampson_mailbox_worker(spec_json)
|
|
130
134
|
give mailbox.work(spec_json)
|
|
131
135
|
|
|
136
|
+
task lampson_webchat_worker(spec_json)
|
|
137
|
+
give webchat.work(spec_json)
|
|
138
|
+
|
|
132
139
|
-- Canales en modo sin URL pública (lib/channels.syn): un agente ChannelPoller por canal; el tick lo mantiene vivo
|
|
133
140
|
task lampson_channel_poller(name)
|
|
134
141
|
give channels.poll_loop(name)
|
|
@@ -232,13 +239,21 @@ serve on 8080
|
|
|
232
239
|
when not session.exists(params.id)
|
|
233
240
|
give not_found("session not found")
|
|
234
241
|
let doc be session.load(params.id)
|
|
242
|
+
when get(doc["meta"], "project", memo.slug()) != memo.slug()
|
|
243
|
+
give not_found("session not found in this workspace")
|
|
244
|
+
let active be webchat.status(params.id)
|
|
245
|
+
let run be nothing
|
|
235
246
|
let visible be where(doc["messages"], (m) => m["role"] != "system")
|
|
236
|
-
|
|
247
|
+
when active != nothing
|
|
248
|
+
set run to {"id": active["id"], "active": active["active"], "pending": active["pending"]}
|
|
249
|
+
when active["active"]
|
|
250
|
+
set visible to active["base"]
|
|
251
|
+
give {"id": doc["id"], "updated": doc["updated"], "meta": doc["meta"], "messages": visible, "run": run}
|
|
237
252
|
|
|
238
253
|
route "GET /w/:slug/api/config" requires auth
|
|
239
254
|
private
|
|
240
255
|
let cfg be provider.config()
|
|
241
|
-
give {"provider": cfg["provider"], "model": cfg["model"], "wire": cfg["wire"], "vision": provider.supports_vision(cfg), "providers": provider.providers(), "configured": provider.configured(), "permission": lower(env("LAMPSON_PERMISSION", "ask")), "agents": agents.names(), "workspace": env("LAMPSON_WORKSPACE", "./workspace"), "profiles": agents.PROFILES}
|
|
256
|
+
give {"provider": cfg["provider"], "model": cfg["model"], "wire": cfg["wire"], "vision": provider.supports_vision(cfg), "providers": provider.providers(), "configured": provider.configured(), "permission": lower(env("LAMPSON_PERMISSION", "ask")), "agents": agents.names(), "workspace": env("LAMPSON_WORKSPACE", "./workspace"), "project": memo.slug(), "profiles": agents.PROFILES}
|
|
242
257
|
|
|
243
258
|
-- proveedor/modelo por defecto y API keys → .lampson/config.json (local). La key nunca vuelve al cliente.
|
|
244
259
|
route "POST /w/:slug/api/settings" requires auth
|
|
@@ -259,6 +274,8 @@ serve on 8080
|
|
|
259
274
|
private
|
|
260
275
|
expect body {id: text}
|
|
261
276
|
let b be json of request
|
|
277
|
+
when not webchat.forget(text(b["id"]))
|
|
278
|
+
give fail(409, "stop this conversation before deleting it")
|
|
262
279
|
give {"result": session.delete(text(b["id"]))}
|
|
263
280
|
|
|
264
281
|
route "GET /w/:slug/api/tree" requires auth
|
|
@@ -719,73 +736,97 @@ serve on 8080
|
|
|
719
736
|
let n be when contains(query, "tail") then floor(number(query.tail)) otherwise 300
|
|
720
737
|
give {"id": query.id, "log": schedule.log_tail(query.id, n), "task": schedule.get(query.id)}
|
|
721
738
|
|
|
739
|
+
route "POST /w/:slug/api/chat/input" requires auth
|
|
740
|
+
private
|
|
741
|
+
expect body {session: text, message: text, id: text}
|
|
742
|
+
let b be json of request
|
|
743
|
+
when not matches(b["id"], "[A-Za-z0-9_-]{1,96}")
|
|
744
|
+
give fail(400, "invalid input id")
|
|
745
|
+
let images be []
|
|
746
|
+
let total be 0
|
|
747
|
+
each im in get(b, "images", [])
|
|
748
|
+
when contains(im, "data") and contains(im, "media_type")
|
|
749
|
+
set total to total + length(im["data"])
|
|
750
|
+
when total <= 5000000
|
|
751
|
+
set images to append(images, {"media_type": text(im["media_type"]), "data": text(im["data"])})
|
|
752
|
+
when not webchat.enqueue(b["session"], {"kind": "input", "id": b["id"], "text": b["message"], "images": images})
|
|
753
|
+
give fail(409, "conversation is idle; send this message through /api/chat")
|
|
754
|
+
give respond(json_encode({"ok": true, "id": b["id"], "status": "queued"}), "application/json", 202)
|
|
755
|
+
|
|
756
|
+
route "POST /w/:slug/api/chat/stop" requires auth
|
|
757
|
+
private
|
|
758
|
+
expect body {session: text}
|
|
759
|
+
let b be json of request
|
|
760
|
+
let active be webchat.enqueue(b["session"], {"kind": "stop"})
|
|
761
|
+
give {"ok": true, "active": active}
|
|
762
|
+
|
|
763
|
+
route "POST /w/:slug/api/chat/start" requires auth
|
|
764
|
+
private
|
|
765
|
+
expect body {message: text}
|
|
766
|
+
state_set("lampson:last_used", now())
|
|
767
|
+
let started be webchat.begin(json of request)
|
|
768
|
+
when not started["ok"]
|
|
769
|
+
give fail(409, started["error"])
|
|
770
|
+
give respond(json_encode(started), "application/json", 202)
|
|
771
|
+
|
|
772
|
+
route "GET /w/:slug/api/chat/events" requires auth
|
|
773
|
+
private
|
|
774
|
+
let sid be get(query, "session", "")
|
|
775
|
+
let run_id be get(query, "run", "")
|
|
776
|
+
let info be webchat.run_info(run_id)
|
|
777
|
+
let valid be false
|
|
778
|
+
when info != nothing
|
|
779
|
+
set valid to info["session"] == sid and session.exists(sid)
|
|
780
|
+
let cursor be max(0, floor(number(get(query, "after", "0"))))
|
|
781
|
+
stream
|
|
782
|
+
when not valid
|
|
783
|
+
send {"kind": "run_missing", "data": sid} as "event"
|
|
784
|
+
otherwise
|
|
785
|
+
let deadline be now() + 900
|
|
786
|
+
let finished be false
|
|
787
|
+
while not finished and now() < deadline
|
|
788
|
+
let ev be webchat.event_at(run_id, cursor + 1)
|
|
789
|
+
when ev != nothing
|
|
790
|
+
set cursor to cursor + 1
|
|
791
|
+
send ev as "event"
|
|
792
|
+
when ev["kind"] == "done"
|
|
793
|
+
set finished to true
|
|
794
|
+
otherwise
|
|
795
|
+
let current be webchat.run_info(run_id)
|
|
796
|
+
let alive be when current == nothing then false otherwise current["active"]
|
|
797
|
+
when not alive
|
|
798
|
+
set finished to true
|
|
799
|
+
otherwise
|
|
800
|
+
sleep(0.1)
|
|
801
|
+
|
|
722
802
|
route "POST /w/:slug/api/chat" requires auth
|
|
723
803
|
private
|
|
724
804
|
expect body {message: text}
|
|
725
|
-
let b be json of request
|
|
726
|
-
let message be b["message"]
|
|
727
|
-
let sid be when contains(b, "session") then text(b["session"]) otherwise ""
|
|
728
|
-
let want be when contains(b, "agent") then lower(text(b["agent"])) otherwise "build"
|
|
729
|
-
let mode be when contains(b, "permission") then lower(text(b["permission"])) otherwise lower(env("LAMPSON_PERMISSION", "ask"))
|
|
730
|
-
when mode != "ask" and mode != "yolo" and mode != "strict"
|
|
731
|
-
set mode to "ask"
|
|
732
|
-
let pname be when contains(b, "provider") then lower(text(b["provider"])) otherwise ""
|
|
733
|
-
let pmodel be when contains(b, "model") then text(b["model"]) otherwise ""
|
|
734
805
|
state_set("lampson:last_used", now())
|
|
806
|
+
let started be webchat.begin(json of request)
|
|
735
807
|
stream
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
send {"kind":
|
|
739
|
-
-- aprobación humana: la cola de lib/approvals.syn (id + token) — la UI responde por SSE/POST /api/approve,
|
|
740
|
-
-- y si hay webhook/LAMPSON_PUBLIC_URL también llega un link al canal del usuario (aprobar desde el móvil)
|
|
741
|
-
task ask_web(name, args, why)
|
|
742
|
-
let id be approvals.open("chat", permission.describe_call(name, args), why, APPROVAL_TIMEOUT)
|
|
743
|
-
send {"kind": "approval_request", "data": {"id": id, "name": name, "args": args, "why": why, "timeout": APPROVAL_TIMEOUT}} as "event"
|
|
744
|
-
let t0 be now()
|
|
745
|
-
let ok be approvals.wait(id, APPROVAL_TIMEOUT)
|
|
746
|
-
send {"kind": "approval_result", "data": {"id": id, "approved": ok, "timeout": (not ok) and now() - t0 >= APPROVAL_TIMEOUT - 1}} as "event"
|
|
747
|
-
give ok
|
|
748
|
-
task on_start(info)
|
|
749
|
-
set sid to info["session"]
|
|
750
|
-
send {"kind": "session", "data": sid} as "event"
|
|
751
|
-
send {"kind": "mode", "data": {"agent": info["agent"], "permission": info["mode"], "provider": info["provider"], "model": info["model"], "has_key": info["has_key"]}} as "event"
|
|
752
|
-
-- worker es interno de delegate: por la API tampoco se elige como agente de sesión
|
|
753
|
-
when not contains(runtime.names(), want)
|
|
754
|
-
set want to "build"
|
|
755
|
-
let sobre be {"to": want, "session": sid, "from": {"id": "", "name": "", "kind": "human"}, "text": message, "images": [], "channel": "web", "meta": {}}
|
|
756
|
-
let hooks be {"mode": mode, "provider": pname, "model": pmodel, "ask_fn": ask_web, "on_event": emit, "on_start": on_start}
|
|
757
|
-
when starts_with(trim(message), "!")
|
|
758
|
-
-- comando del USUARIO: sin política de permisos, salida al contexto; el modelo no interviene
|
|
759
|
-
let o be runtime.open(sobre, hooks)
|
|
760
|
-
let cfg be o["ctx"]["cfg"]
|
|
761
|
-
on_start({"session": o["session"], "agent": o["ctx"]["agent"], "thread": o["thread"], "mode": o["mode"], "provider": cfg["provider"], "model": cfg["model"], "has_key": cfg["has_key"]})
|
|
762
|
-
when o["note"] != ""
|
|
763
|
-
trace.event(sid, "inbox", o["note"], "")
|
|
764
|
-
send {"kind": "inbox", "data": o["note"], "tag": ""} as "event"
|
|
765
|
-
let cmd be trim(slice(trim(message), 1, length(trim(message))))
|
|
766
|
-
let bash_tool be agents.registry_for("build")["bash"]
|
|
767
|
-
send {"kind": "tool_call", "data": {"id": "user", "name": "bash", "args": {"command": cmd}}} as "event"
|
|
768
|
-
let out be call_tool(bash_tool, {"command": cmd, "timeout": 600})
|
|
769
|
-
send {"kind": "tool_result", "data": {"call": {"id": "user", "name": "bash", "args": {"command": cmd}}, "output": out}} as "event"
|
|
770
|
-
let messages be append(o["messages"], {"role": "user", "content": "[The user ran this command in the shell themselves]\n$ " + cmd + "\n" + tools.truncate(out, 6000)})
|
|
771
|
-
runtime.save(o, messages)
|
|
772
|
-
send {"kind": "done", "data": {"text": "", "steps": 0, "usage": {"input": 0, "output": 0}, "stopped": "user_command", "session": sid}} as "event"
|
|
808
|
+
when not started["ok"]
|
|
809
|
+
send {"kind": "error", "data": started["error"]} as "event"
|
|
810
|
+
send {"kind": "done", "data": {"session": started["session"], "text": "", "steps": 0, "usage": {"input": 0, "output": 0}, "stopped": "busy"}} as "event"
|
|
773
811
|
otherwise
|
|
774
|
-
|
|
775
|
-
let
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
812
|
+
let run_id be started["run"]
|
|
813
|
+
let cursor be 0
|
|
814
|
+
let finished be false
|
|
815
|
+
let deadline be now() + 900
|
|
816
|
+
while not finished and now() < deadline
|
|
817
|
+
let ev be webchat.event_at(run_id, cursor + 1)
|
|
818
|
+
when ev != nothing
|
|
819
|
+
set cursor to cursor + 1
|
|
820
|
+
send ev as "event"
|
|
821
|
+
when ev["kind"] == "done"
|
|
822
|
+
set finished to true
|
|
823
|
+
otherwise
|
|
824
|
+
let current be webchat.run_info(run_id)
|
|
825
|
+
let alive be when current == nothing then false otherwise current["active"]
|
|
826
|
+
when not alive
|
|
827
|
+
set finished to true
|
|
828
|
+
otherwise
|
|
829
|
+
sleep(0.1)
|
|
789
830
|
|
|
790
831
|
-- ---------- API /v1 para apps (lib/api.syn · spec/engine.md fase 2) ----------
|
|
791
832
|
-- Sin `requires auth`: bajo el hub todo llega por loopback y check_client lo daría por bueno. La API exige SIEMPRE
|