lampson 0.5.0 → 0.5.1
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/README.md +15 -0
- package/lampson.ps1 +13 -6
- package/lampson.sh +11 -5
- package/lib/api.syn +46 -2
- package/lib/apikeys.syn +42 -9
- package/lib/apptools.syn +549 -0
- package/lib/loop.syn +13 -0
- package/lib/mailbox.syn +24 -10
- package/lib/mcp_server.syn +6 -5
- package/lib/permission.syn +22 -1
- package/lib/remotetools.syn +76 -0
- package/lib/runtime.syn +157 -9
- package/lib/sdktools.syn +73 -0
- package/lib/session.syn +8 -0
- package/lib/tools/common.syn +5 -0
- package/lib/tools/url.syn +82 -9
- package/lib/workspaces.syn +29 -3
- package/package.json +2 -2
- package/public/css/panel.css +2 -0
- package/public/index.html +2 -0
- package/public/js/apptools.js +63 -0
- package/public/js/panel.js +2 -2
- package/run.syn +87 -6
- package/sdk/index.d.ts +64 -3
- package/sdk/index.js +253 -11
- package/skills/lampson/SKILL.md +15 -0
- package/web.syn +30 -4
package/lib/tools/common.syn
CHANGED
|
@@ -35,6 +35,11 @@ export task ws(path)
|
|
|
35
35
|
-- quiso guardar una "memoria global" fuera del workspace, como el install global de skills).
|
|
36
36
|
when contains(split(p, "/")[0], ":") or has_dotdot(p)
|
|
37
37
|
raise("path escapes the workspace: \"" + text(path) + "\" — file tools only reach the mounted workspace; use paths relative to its root (e.g. \"src/app.ts\"). Do not retry with other path variants. To keep notes across sessions use the memory tool (the harness stores them per project, outside the repo); for anything else outside the workspace, explain what you need and ask the user.")
|
|
38
|
+
-- alias de Windows: "x." y "x " son "x", "lampso~1" es el nombre corto 8.3 de ".lampson", "a:b" es un stream.
|
|
39
|
+
-- Con ellos, una regla por nombre (.lampson/, .env) se saltaba; ningún proyecto los necesita
|
|
40
|
+
each seg in split(p, "/")
|
|
41
|
+
when seg != "." and seg != ".." and (ends_with(seg, ".") or ends_with(seg, " ") or contains(seg, ":") or matches(seg, ".*~[0-9].*"))
|
|
42
|
+
raise("path not allowed: \"" + text(path) + "\" — a name ending in '.' or a space, with '~' and a digit, or with ':' is another name for a different file on Windows. Use the plain name.")
|
|
38
43
|
when p == "." or p == "" or p == ROOT
|
|
39
44
|
give ROOT
|
|
40
45
|
when starts_with(p, ROOT + "/")
|
package/lib/tools/url.syn
CHANGED
|
@@ -111,6 +111,86 @@ task ipv4_class(o)
|
|
|
111
111
|
give "private"
|
|
112
112
|
give "public"
|
|
113
113
|
|
|
114
|
+
-- "0db8" → 3512; nothing si no es hex de 1 a 4 dígitos
|
|
115
|
+
task hex16(s)
|
|
116
|
+
when not matches(s, "[0-9a-f]{1,4}")
|
|
117
|
+
give nothing
|
|
118
|
+
let n be 0
|
|
119
|
+
each ch in split(s, "")
|
|
120
|
+
set n to n * 16 + index_of("0123456789abcdef", ch)
|
|
121
|
+
give n
|
|
122
|
+
|
|
123
|
+
-- los 8 grupos de una IPv6 (con "::" y un IPv4 al final, "::ffff:1.2.3.4") o nothing si no es una IPv6 válida
|
|
124
|
+
task ipv6_groups(h)
|
|
125
|
+
let a be split(h, "%")[0]
|
|
126
|
+
let tail be []
|
|
127
|
+
let segs be split(a, ":")
|
|
128
|
+
let last be segs[length(segs) - 1]
|
|
129
|
+
when contains(last, ".")
|
|
130
|
+
let o be ipv4_octets(last)
|
|
131
|
+
when o == nothing
|
|
132
|
+
give nothing
|
|
133
|
+
set tail to [o[0] * 256 + o[1], o[2] * 256 + o[3]]
|
|
134
|
+
set a to slice(a, 0, length(a) - length(last)) + "0"
|
|
135
|
+
let halves be split(a, "::")
|
|
136
|
+
when length(halves) > 2
|
|
137
|
+
give nothing
|
|
138
|
+
let left be where(split(halves[0], ":"), (g) => g != "")
|
|
139
|
+
let right be when length(halves) == 2 then where(split(halves[1], ":"), (g) => g != "") otherwise []
|
|
140
|
+
when length(tail) > 0
|
|
141
|
+
set right to when length(halves) == 2 then slice(right, 0, length(right) - 1) otherwise right
|
|
142
|
+
set left to when length(halves) == 2 then left otherwise slice(left, 0, length(left) - 1)
|
|
143
|
+
let n be length(left) + length(right) + length(tail)
|
|
144
|
+
when (length(halves) == 1 and n != 8) or n > 8 or (length(halves) == 2 and n == 8)
|
|
145
|
+
give nothing
|
|
146
|
+
let out be []
|
|
147
|
+
each g in left
|
|
148
|
+
let v be hex16(g)
|
|
149
|
+
when v == nothing
|
|
150
|
+
give nothing
|
|
151
|
+
set out to append(out, v)
|
|
152
|
+
when length(halves) == 2
|
|
153
|
+
each i in range(8 - n)
|
|
154
|
+
set out to append(out, 0)
|
|
155
|
+
each g in right
|
|
156
|
+
let v be hex16(g)
|
|
157
|
+
when v == nothing
|
|
158
|
+
give nothing
|
|
159
|
+
set out to append(out, v)
|
|
160
|
+
give out + tail
|
|
161
|
+
|
|
162
|
+
-- solo 2000::/3 es internet; dentro, 6to4 (2002::/16) y Teredo (2001:0::/32) llevan una IPv4 adentro → privado.
|
|
163
|
+
-- IPv4 mapeadas (::ffff:a.b.c.d), compatibles (::a.b.c.d) y NAT64 (64:ff9b::a.b.c.d) se clasifican por esa IPv4
|
|
164
|
+
task ipv6_class(h)
|
|
165
|
+
let g be ipv6_groups(h)
|
|
166
|
+
when g == nothing
|
|
167
|
+
give "private"
|
|
168
|
+
when g == [64768, 3778, 0, 0, 0, 0, 0, 596]
|
|
169
|
+
give "blocked"
|
|
170
|
+
let v4 be [floor(g[6] / 256), g[6] % 256, floor(g[7] / 256), g[7] % 256]
|
|
171
|
+
when slice(g, 0, 5) == [0, 0, 0, 0, 0] and (g[5] == 65535 or (g[5] == 0 and g[6] != 0))
|
|
172
|
+
give ipv4_class(v4)
|
|
173
|
+
when g[0] == 100 and g[1] == 65435 and slice(g, 2, 6) == [0, 0, 0, 0]
|
|
174
|
+
give ipv4_class(v4)
|
|
175
|
+
when g[0] < 8192 or g[0] > 16383 or g[0] == 8194 or (g[0] == 8193 and g[1] == 0)
|
|
176
|
+
give "private"
|
|
177
|
+
give "public"
|
|
178
|
+
|
|
179
|
+
-- ¿el host es una IP escrita (IPv4, IPv6, o las formas numéricas raras) y no un nombre?
|
|
180
|
+
export task is_ip_literal(host)
|
|
181
|
+
let h be lower(text(host))
|
|
182
|
+
give contains(h, ":") or matches(h, "[0-9.]+") or matches(h, "0x[0-9a-fx.]+")
|
|
183
|
+
|
|
184
|
+
-- loopback de verdad: localhost, 127.0.0.0/8, ::1 (en cualquier forma)
|
|
185
|
+
export task is_loopback(host)
|
|
186
|
+
let h be lower(text(host))
|
|
187
|
+
when h == "localhost" or ends_with(h, ".localhost")
|
|
188
|
+
give true
|
|
189
|
+
let o be ipv4_octets(h)
|
|
190
|
+
when o != nothing
|
|
191
|
+
give o[0] == 127
|
|
192
|
+
give contains(h, ":") and ipv6_groups(h) == [0, 0, 0, 0, 0, 0, 0, 1]
|
|
193
|
+
|
|
114
194
|
export task host_class(host)
|
|
115
195
|
let h be lower(text(host))
|
|
116
196
|
when h == "metadata.google.internal" or h == "metadata.goog" or h == "fd00:ec2::254"
|
|
@@ -118,16 +198,9 @@ export task host_class(host)
|
|
|
118
198
|
let o be ipv4_octets(h)
|
|
119
199
|
when o != nothing
|
|
120
200
|
give ipv4_class(o)
|
|
121
|
-
-- IPv6:
|
|
201
|
+
-- IPv6 por su valor expandido: comparar el texto dejaba pasar [0::1] y [0000::1] como públicos (2026-10-19)
|
|
122
202
|
when contains(h, ":")
|
|
123
|
-
|
|
124
|
-
give "private"
|
|
125
|
-
when starts_with(h, "::ffff:")
|
|
126
|
-
let inner be ipv4_octets(slice(h, 7, length(h)))
|
|
127
|
-
give when inner != nothing then ipv4_class(inner) otherwise "private"
|
|
128
|
-
when starts_with(h, "fc") or starts_with(h, "fd") or starts_with(h, "fe8") or starts_with(h, "fe9") or starts_with(h, "fea") or starts_with(h, "feb")
|
|
129
|
-
give "private"
|
|
130
|
-
give "public"
|
|
203
|
+
give ipv6_class(h)
|
|
131
204
|
when h == "localhost" or ends_with(h, ".localhost") or ends_with(h, ".internal") or ends_with(h, ".local") or ends_with(h, ".home.arpa") or ends_with(h, ".lan")
|
|
132
205
|
give "private"
|
|
133
206
|
-- formas numéricas ambiguas (2130706433, 0x7f000001, 0177.0.0.1): clásicos de bypass → tratar como privado
|
package/lib/workspaces.syn
CHANGED
|
@@ -322,7 +322,7 @@ export task ensure(path)
|
|
|
322
322
|
let parts be where(split(replace(text(path), "\\", "/"), "/"), (x) => x != "")
|
|
323
323
|
set w to {"slug": slug, "name": parts[length(parts) - 1], "path": text(path), "port": port, "policy": "auto", "created": now(), "last_used": now()}
|
|
324
324
|
put(w)
|
|
325
|
-
when regen_hub() and
|
|
325
|
+
when regen_hub() and hub_ours()
|
|
326
326
|
restart_hub_later()
|
|
327
327
|
prepare(w)
|
|
328
328
|
give w
|
|
@@ -348,7 +348,7 @@ export task remove(slug)
|
|
|
348
348
|
set keep[k] to doc["workspaces"][k]
|
|
349
349
|
set doc["workspaces"] to keep
|
|
350
350
|
save_reg(doc)
|
|
351
|
-
when regen_hub() and
|
|
351
|
+
when regen_hub() and hub_ours()
|
|
352
352
|
restart_hub_later()
|
|
353
353
|
give "workspace '" + slug + "' quitado del registro (la carpeta " + dir_of(slug) + " y el proyecto quedan en disco)"
|
|
354
354
|
|
|
@@ -513,7 +513,7 @@ export task stop_ws(w)
|
|
|
513
513
|
|
|
514
514
|
-- Lampson entero (lampson --hub stop, ⚙ → Apagar o reiniciar): workspaces y hub en una sola pasada, y el edge
|
|
515
515
|
export task stop_all()
|
|
516
|
-
let ports be [HUB_PORT]
|
|
516
|
+
let ports be when hub_alive() and not hub_ours() then [] otherwise [HUB_PORT]
|
|
517
517
|
each w in all()
|
|
518
518
|
set ports to append(ports, w["port"])
|
|
519
519
|
stop_edge()
|
|
@@ -529,6 +529,30 @@ export task hub_alive()
|
|
|
529
529
|
recover err
|
|
530
530
|
give false
|
|
531
531
|
|
|
532
|
+
-- ¿el hub que contesta en HUB_PORT es el de ESTA instalación? Otro LAMPSON_HOME en la misma máquina (una app que
|
|
533
|
+
-- embebe Lampson con el SDK, un home de pruebas) veía el hub del usuario como propio y lo reiniciaba: le mataba el
|
|
534
|
+
-- 8080 y levantaba el suyo con sus workspaces (2026-10-18). Reiniciar o parar el hub es solo para el propio.
|
|
535
|
+
task norm_home(p)
|
|
536
|
+
let s be lower(replace(text(p), "\\", "/"))
|
|
537
|
+
while length(s) > 1 and ends_with(s, "/")
|
|
538
|
+
set s to slice(s, 0, length(s) - 1)
|
|
539
|
+
give s
|
|
540
|
+
|
|
541
|
+
export task hub_ours()
|
|
542
|
+
require net("127.0.0.1")
|
|
543
|
+
require time
|
|
544
|
+
require exec
|
|
545
|
+
require env("LAMPSON_*")
|
|
546
|
+
require env("OS")
|
|
547
|
+
try
|
|
548
|
+
let r be http_get("http://127.0.0.1:" + text(HUB_PORT) + "/api/hub", {"timeout": 2})
|
|
549
|
+
when not r["ok"]
|
|
550
|
+
give false
|
|
551
|
+
let doc be json_decode(r["body"])
|
|
552
|
+
give type_of(doc) == "map" and contains(doc, "home") and norm_home(doc["home"]) == norm_home(home())
|
|
553
|
+
recover err
|
|
554
|
+
give false
|
|
555
|
+
|
|
532
556
|
export task start_hub()
|
|
533
557
|
require exec
|
|
534
558
|
require time
|
|
@@ -581,6 +605,8 @@ export task stop_hub()
|
|
|
581
605
|
require time
|
|
582
606
|
require env("LAMPSON_*")
|
|
583
607
|
require env("OS")
|
|
608
|
+
when hub_alive() and not hub_ours()
|
|
609
|
+
give false
|
|
584
610
|
give kill_ports([HUB_PORT]) > 0
|
|
585
611
|
|
|
586
612
|
-- ---------- dominio propio (opcional): edge HTTPS en :443 ----------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lampson",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "A coding agent written in Synsema: terminal + web, tools confined to the mounted project, plugins (your own tools, any language), LSP, MCP, sub-agents. Also an SDK: import { Lampson } from \"lampson\" (server or local mode).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"node": ">=18"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"synsema": "^0.6.
|
|
50
|
+
"synsema": "^0.6.44"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"test": "pwsh -NoProfile -File tests/run.ps1"
|
package/public/css/panel.css
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
.panel .pghost { display:inline-flex; align-items:center; justify-content:center; width:26px; height:26px; padding:0; margin:0; font:400 13px/1 var(--mono); letter-spacing:0; text-transform:none; border:1px solid var(--rule); border-radius:var(--r); background:transparent; color:var(--ink-3); cursor:pointer; }
|
|
16
16
|
.panel .pghost:hover { color:var(--ink); border-color:var(--rule-2); }
|
|
17
17
|
.panel .pghost + .pghost { margin-left:6px; }
|
|
18
|
+
.panel .pghost.wide { width:auto; padding:0 10px; white-space:nowrap; }
|
|
18
19
|
|
|
19
20
|
/* pestañas */
|
|
20
21
|
.panel .ptabs { display:flex; gap:2px; border-bottom:1px solid var(--rule); margin:0 0 14px; flex:none; }
|
|
@@ -112,6 +113,7 @@
|
|
|
112
113
|
.panel .tool .go { margin-top:10px; display:flex; align-items:center; gap:10px; }
|
|
113
114
|
.panel .tool .go button { font:400 12px/1 var(--mono); padding:5px 10px; }
|
|
114
115
|
.panel .tool .go .st { color:var(--ink-3); font-size:11.5px; }
|
|
116
|
+
.panel pre.src { margin-top:12px; max-height:46vh; overflow:auto; font:400 11.5px/1.45 var(--mono); border:1px solid var(--rule); border-radius:var(--r); padding:10px; white-space:pre-wrap; }
|
|
115
117
|
.panel .tool pre.out { margin-top:8px; max-height:38vh; overflow:auto; font:400 11.5px/1.45 var(--mono); border:1px solid var(--rule); border-radius:var(--r); padding:8px; white-space:pre-wrap; }
|
|
116
118
|
/* conversación resumida (sesiones) */
|
|
117
119
|
.panel .dmsgs { margin-top:12px; display:flex; flex-direction:column; gap:8px; }
|
package/public/index.html
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
<select id="perm" title="qué pasa con un comando peligroso (rm -rf, git push --force, sudo…)"><option value="ask">permisos: preguntar</option><option value="yolo">permisos: permitir todo</option><option value="strict">permisos: denegar</option></select>
|
|
46
46
|
<span class="pill on" id="wsPill" style="display:none" title="cambiar de workspace">workspace ▾</span>
|
|
47
47
|
<span class="pill" id="plugins" title="plugins: tools propias que vos encendés · clic para ver y activar">plugins</span>
|
|
48
|
+
<span class="pill" id="apptools" hidden title="herramientas .syn del proyecto: corren solo aprobadas">herramientas</span>
|
|
48
49
|
<span class="pill" id="model" title="proveedor y modelo · clic para cambiarlos o cargar una API key">…</span>
|
|
49
50
|
</div>
|
|
50
51
|
</header>
|
|
@@ -141,6 +142,7 @@
|
|
|
141
142
|
<script src="/js/mcp.js"></script>
|
|
142
143
|
<script src="/js/lsp.js"></script>
|
|
143
144
|
<script src="/js/plugins.js"></script>
|
|
145
|
+
<script src="/js/apptools.js"></script>
|
|
144
146
|
<script src="/js/engine.js"></script>
|
|
145
147
|
<script src="/js/schedules.js"></script>
|
|
146
148
|
<script src="/js/approvals.js"></script>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// apptools.js — herramientas .syn del proyecto (lib/apptools.syn): pill en la cabecera (solo si hay) + vista browse
|
|
2
|
+
// del Panel con cada archivo, su estado, qué puede tocar y su código, y el botón para aprobarlo. Una herramienta corre
|
|
3
|
+
// solo con el contenido que aprobó una persona; esto es lo mismo que `lampson tools list|approve`.
|
|
4
|
+
let apptoolsData = { files: [], dir: '', error: '' };
|
|
5
|
+
const APPTOOL_STATUS = {
|
|
6
|
+
ok: ['●', 'aprobada'], new: ['○', 'nueva · sin aprobar'], changed: ['△', 'cambió · sin aprobar'],
|
|
7
|
+
missing: ['·', 'borrada (estaba aprobada)'], unreadable: ['!', 'no se puede leer'], too_big: ['!', 'pasa el tope'],
|
|
8
|
+
link: ['!', 'link a otra carpeta: no se permite'],
|
|
9
|
+
};
|
|
10
|
+
const apptoolPending = f => f.status !== 'ok' && f.status !== 'missing';
|
|
11
|
+
async function fetchAppTools() {
|
|
12
|
+
let r; try { r = await (await fetch(BASE + '/api/apptools')).json(); } catch (e) { return apptoolsData; }
|
|
13
|
+
apptoolsData = { files: r.files || [], dir: r.dir || '', error: r.error || '' };
|
|
14
|
+
const pill = $('#apptools'), tools = apptoolsData.files.filter(f => f.tool), pending = apptoolsData.files.filter(apptoolPending);
|
|
15
|
+
pill.hidden = !apptoolsData.files.length && !apptoolsData.error;
|
|
16
|
+
pill.textContent = pending.length ? `herramientas · ${pending.length} sin aprobar` : `herramientas ${tools.length}`;
|
|
17
|
+
pill.classList.toggle('nokey', pending.length > 0 || !!apptoolsData.error);
|
|
18
|
+
pill.title = pending.length ? 'hay archivos de herramientas .syn sin aprobar: mientras tanto ninguna corre · clic para revisarlos' : 'herramientas .syn del proyecto: corren solo con el contenido que aprobaste';
|
|
19
|
+
return apptoolsData;
|
|
20
|
+
}
|
|
21
|
+
async function approveAppTool(name, errEl) {
|
|
22
|
+
const r = await api(BASE + '/api/apptools/approve', { name });
|
|
23
|
+
if (!r.ok) { if (errEl) errEl.textContent = r.data.error || ('error ' + r.status); return; }
|
|
24
|
+
add('meta', '☼ aprobado: ' + esc((r.data.approved || []).join(', ') || 'nada que aprobar'));
|
|
25
|
+
await fetchAppTools(); if (Panel.is('apptools')) Panel.refresh();
|
|
26
|
+
}
|
|
27
|
+
function openAppTools() {
|
|
28
|
+
Panel.open({
|
|
29
|
+
id: 'apptools', eyebrow: 'herramientas', title: 'Herramientas .syn', layout: 'browse',
|
|
30
|
+
headActions: [{ label: 'aprobar todo', wide: true, title: 'aprobar el contenido actual de todos los archivos de la carpeta', onClick: () => approveAppTool('') }],
|
|
31
|
+
browse: {
|
|
32
|
+
placeholder: 'buscar archivo…', listWidth: '280px',
|
|
33
|
+
key: f => f.file,
|
|
34
|
+
load: async (q) => { const d = await fetchAppTools(); return d.files.filter(f => !q || f.file.toLowerCase().includes(q.toLowerCase())); },
|
|
35
|
+
render: (f) => { const s = APPTOOL_STATUS[f.status] || ['?', f.status]; return `<span class="dot">${s[0]}</span><div><div class="nm">${esc(f.file)}</div><div class="meta">${esc(s[1])}${f.tool ? '' : (f.file.endsWith('.syn') ? ' · ayudante' : ' · va al prompt')}</div></div>`; },
|
|
36
|
+
count: (rows) => `${rows.length} archivo${rows.length === 1 ? '' : 's'}`,
|
|
37
|
+
emptyHtml: 'ninguno',
|
|
38
|
+
emptyDetail: `No hay herramientas .syn en <code>${esc(shortPath(apptoolsData.dir))}</code>.${apptoolsData.error ? `<br><br>La carpeta no se pudo leer: ${esc(apptoolsData.error)}` : ''}<br><br>Un archivo por herramienta, con su <code>intent:</code>, sus <code>require</code> y <code>export task <nombre>(…)</code>: <a href="https://lampson.org/es/docs/sdk#en-synsema-con-garantias" target="_blank" rel="noopener">cómo se escriben</a>.`,
|
|
39
|
+
detail: (f) => {
|
|
40
|
+
const s = APPTOOL_STATUS[f.status] || ['?', f.status], t = f.tool;
|
|
41
|
+
const canApprove = f.status === 'new' || f.status === 'changed';
|
|
42
|
+
return `<div class="dhead"><span class="nm">${esc(f.file)}</span><span class="meta">${esc(s[1])}</span></div>`
|
|
43
|
+
+ (t ? (t.description ? `<div class="ddesc">${esc(t.description)}</div>` : '') + (t.error && f.status === 'ok' ? `<div class="dcap err">${esc(t.error)}</div>` : `<div class="dcap">puede tocar: ${esc(t.ceiling)}</div>`)
|
|
44
|
+
+ (t.params && t.params.length ? `<div class="ds">parámetros: ${t.params.map(p => esc(p.name) + (p.optional ? '?' : '')).join(', ')}</div>` : '') : '')
|
|
45
|
+
+ (canApprove ? `<div class="dnote">Mientras haya un archivo sin aprobar, <b>ninguna</b> herramienta .syn corre. Revisá el código y lo que puede tocar; si lo cambió un agente sin que lo pidieras, no lo apruebes.</div><div class="go"><button class="primary approve">aprobar este contenido</button></div>` : '')
|
|
46
|
+
+ (f.status === 'missing' ? `<div class="dnote">Lo borraron de la carpeta. «aprobar todo» lo saca de la lista.</div>` : '')
|
|
47
|
+
+ (['unreadable', 'too_big', 'link'].includes(f.status) ? `<div class="dnote">Frena todas las herramientas .syn hasta que lo saques de la carpeta.</div>` : '')
|
|
48
|
+
+ (f.status !== 'missing' && f.status !== 'link' ? `<pre class="out src">cargando…</pre>` : '')
|
|
49
|
+
+ `<div class="dfoot"><span>${esc(shortPath(apptoolsData.dir))}</span></div><div class="err" data-err></div>`;
|
|
50
|
+
},
|
|
51
|
+
wire: async (f, box) => {
|
|
52
|
+
const errEl = box.querySelector('[data-err]');
|
|
53
|
+
const b = box.querySelector('button.approve'); if (b) b.onclick = () => approveAppTool(f.file, errEl);
|
|
54
|
+
const src = box.querySelector('pre.src'); if (!src) return;
|
|
55
|
+
try { const r = await (await fetch(BASE + '/api/apptools/source?file=' + encodeURIComponent(f.file))).json(); src.textContent = r.text !== undefined ? r.text : (r.error || 'no se pudo leer'); }
|
|
56
|
+
catch (e) { src.textContent = 'no se pudo leer'; }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
$('#apptools').onclick = () => openAppTools();
|
|
62
|
+
fetchAppTools();
|
|
63
|
+
if (location.hash === '#apptools') setTimeout(() => openAppTools(), 400);
|
package/public/js/panel.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// panel.js — EL componente modal de la app. Un cascarón y tres layouts; cada vista aporta solo su contenido.
|
|
2
2
|
//
|
|
3
3
|
// Panel.open({ eyebrow, title, sub, size: 'lg'|'md'|'sm', layout: 'browse'|'tabs'|'form',
|
|
4
|
-
// headActions: [{label, title, onClick}], // botones chicos en la cabecera (p.ej.
|
|
4
|
+
// headActions: [{label, title, onClick, wide?}], // botones chicos en la cabecera (p.ej. «?»; wide: con texto)
|
|
5
5
|
// noClose: bool, // sin ✕/Esc (onboarding)
|
|
6
6
|
// onClose(), select: clave de la fila a dejar elegida al abrir (browse),
|
|
7
7
|
// browse: { placeholder, listWidth, load(q) → rows, render(row, q) → html de la fila, key(row) → id estable,
|
|
@@ -28,7 +28,7 @@ const Panel = (() => {
|
|
|
28
28
|
const box = () => ensure().querySelector('.panel');
|
|
29
29
|
function head(spec) {
|
|
30
30
|
// {href} = un enlace de texto (a otra pantalla o a la guía), no un botón cuadrado
|
|
31
|
-
const acts = (spec.headActions || []).map((a, i) => a.href ? `<a class="plink" href="${esc(a.href)}"${a.external ? ' target="_blank" rel="noopener"' : ''} title="${esc(a.title || '')}">${esc(a.label)}</a>` : `<button class="pghost" data-ha="${i}" title="${esc(a.title || '')}">${esc(a.label)}</button>`).join('');
|
|
31
|
+
const acts = (spec.headActions || []).map((a, i) => a.href ? `<a class="plink" href="${esc(a.href)}"${a.external ? ' target="_blank" rel="noopener"' : ''} title="${esc(a.title || '')}">${esc(a.label)}</a>` : `<button class="pghost${a.wide ? ' wide' : ''}" data-ha="${i}" title="${esc(a.title || '')}">${esc(a.label)}</button>`).join('');
|
|
32
32
|
return `<div class="phead"><span class="eyebrow">${esc(spec.eyebrow || '')}</span><h3>${esc(spec.title || '')}</h3><span class="sub">${esc(spec.sub || '')}</span><span class="spacer"></span>${acts}${spec.noClose ? '' : `<button class="pghost" data-close title="cerrar (Esc)">${ICON_X}</button>`}</div>`;
|
|
33
33
|
}
|
|
34
34
|
function open(spec) {
|
package/run.syn
CHANGED
|
@@ -47,6 +47,8 @@ use "./lib/apikeys.syn" as apikeys
|
|
|
47
47
|
use "./lib/mcp_server.syn" as mcp_server
|
|
48
48
|
use "./lib/approvals.syn" as approvals
|
|
49
49
|
use "./lib/plugins.syn" as plugins
|
|
50
|
+
use "./lib/sdktools.syn" as sdktools
|
|
51
|
+
use "./lib/apptools.syn" as apptools
|
|
50
52
|
use "./lib/channels.syn" as channels
|
|
51
53
|
|
|
52
54
|
-- `lampson key add|list|remove`: API keys de la API /v1 de este workspace (lib/apikeys.syn, lib/api.syn)
|
|
@@ -81,6 +83,8 @@ when key_cmd != ""
|
|
|
81
83
|
print("")
|
|
82
84
|
print(" " + k["key"])
|
|
83
85
|
print("")
|
|
86
|
+
print(" Firma de sus callbacks (X-Lampson-Signature, verifySignature del SDK): " + k["secret"])
|
|
87
|
+
print("")
|
|
84
88
|
print(" API (apps, bots): " + api_base + "/messages")
|
|
85
89
|
print(" MCP (otros agentes): " + api_base + "/mcp con el header Authorization: Bearer <la key>")
|
|
86
90
|
when pub == ""
|
|
@@ -92,7 +96,7 @@ when key_cmd != ""
|
|
|
92
96
|
when length(ks) == 0
|
|
93
97
|
print("sin API keys en este workspace (lampson key add [--agent ID] [--name NOMBRE])")
|
|
94
98
|
each k in ks
|
|
95
|
-
print(" " + k["id"] + " " + (when k["name"] == "" then "(sin nombre)" otherwise k["name"]) + " agentes: " + join(k["agents"], ", ") + " " + (when k["rate"] == 0 then "sin límite" otherwise text(k["rate"]) + "/min") + (when length(k["callbacks"]) > 0 then " callbacks: " + join(k["callbacks"], ", ") otherwise "") + " creada " + k["created"] + " último uso " + (when k["last_used"] == nothing then "nunca" otherwise text(k["last_used"])))
|
|
99
|
+
print(" " + k["id"] + " " + (when k["name"] == "" then "(sin nombre)" otherwise k["name"]) + " agentes: " + join(k["agents"], ", ") + " " + (when k["rate"] == 0 then "sin límite" otherwise text(k["rate"]) + "/min") + (when length(k["callbacks"]) > 0 then " callbacks: " + join(k["callbacks"], ", ") otherwise "") + (when not k["own_secret"] then " [vieja: firma con el secreto global" + (when length(k["callbacks"]) == 0 then " y manda callbacks a cualquier host público" otherwise "") + "; reemplazala]" otherwise "") + " creada " + k["created"] + " último uso " + (when k["last_used"] == nothing then "nunca" otherwise text(k["last_used"])))
|
|
96
100
|
print(" API: " + api_base + "/messages · MCP: " + api_base + "/mcp")
|
|
97
101
|
otherwise when key_cmd == "remove"
|
|
98
102
|
let kid be env("LAMPSON_KEY_ID", "")
|
|
@@ -203,6 +207,55 @@ when env("LAMPSON_TEAM_CMD", "") != ""
|
|
|
203
207
|
print(" ✗ " + e)
|
|
204
208
|
exit(0)
|
|
205
209
|
|
|
210
|
+
-- `lampson plugin list|on|off [nombre]`: encender un plugin sin interfaz (una VPS por SSH, un script)
|
|
211
|
+
let pl_cmd be env("LAMPSON_PLUGIN_CMD", "")
|
|
212
|
+
when pl_cmd != ""
|
|
213
|
+
let pl_name be lower(env("LAMPSON_PLUGIN_NAME", ""))
|
|
214
|
+
when pl_cmd == "list"
|
|
215
|
+
let ls be plugins.all()
|
|
216
|
+
when length(ls) == 0
|
|
217
|
+
print("no hay plugins (proyecto: workspace/.lampson/plugins/<nombre>/plugin.json · globales: plugins/<nombre>/)")
|
|
218
|
+
each l in ls
|
|
219
|
+
print(" " + (when l["enabled"] then "● " otherwise "○ ") + l["name"] + " " + l["scope"] + " " + (when l["error"] != nothing then "roto: " + text(l["error"]) otherwise join(apply((t) => t["name"], l["tools"]), ", ")))
|
|
220
|
+
exit(0)
|
|
221
|
+
when (pl_cmd == "on" or pl_cmd == "off") and pl_name != ""
|
|
222
|
+
try
|
|
223
|
+
print(plugins.set_enabled(pl_name, pl_cmd == "on"))
|
|
224
|
+
recover err
|
|
225
|
+
print("lampson plugin: " + text(err))
|
|
226
|
+
exit(2)
|
|
227
|
+
exit(0)
|
|
228
|
+
print("uso: lampson plugin list · plugin on|off <nombre>")
|
|
229
|
+
exit(2)
|
|
230
|
+
|
|
231
|
+
-- `lampson tools list|approve [nombre]`: las herramientas .syn del proyecto (lib/apptools.syn) y su aprobación
|
|
232
|
+
let tl_cmd be env("LAMPSON_TOOLS_CMD", "")
|
|
233
|
+
when tl_cmd != ""
|
|
234
|
+
let tl_name be env("LAMPSON_TOOLS_NAME", "")
|
|
235
|
+
let tdir be apptools.dir()
|
|
236
|
+
when tl_cmd == "list"
|
|
237
|
+
let st be apptools.approval()
|
|
238
|
+
when length(keys(st)) == 0
|
|
239
|
+
print("no hay herramientas .syn (" + slice(tdir, length("workspace/"), length(tdir)) + "/<nombre>.syn en el proyecto)")
|
|
240
|
+
let byfile be {}
|
|
241
|
+
each e in apptools.scan_files()
|
|
242
|
+
set byfile[e["file"]] to e
|
|
243
|
+
each f in sort(keys(st))
|
|
244
|
+
let mark be when st[f] == "ok" then "● " otherwise (when st[f] == "new" then "○ nueva, sin aprobar " otherwise (when st[f] == "missing" then "· borrada (estaba aprobada; approve la saca) " otherwise (when st[f] == "unreadable" then "✕ no se puede leer " otherwise (when st[f] == "too_big" then "✕ pasa el tope (1 MB por archivo, 500 .syn) " otherwise (when st[f] == "link" then "✕ link a una carpeta: no se permite " otherwise "△ cambió, sin aprobar ")))))
|
|
245
|
+
let info be when contains(byfile, f) then (when byfile[f]["error"] != nothing then "rota: " + text(byfile[f]["error"]) otherwise "puede tocar: " + apptools.ceiling(byfile[f])) otherwise (when starts_with(f, "_") then "ayudante" otherwise "va al prompt")
|
|
246
|
+
print(" " + mark + f + " " + info)
|
|
247
|
+
exit(0)
|
|
248
|
+
when tl_cmd == "approve"
|
|
249
|
+
let done be apptools.approve(tl_name)
|
|
250
|
+
when length(done) == 0
|
|
251
|
+
print(when tl_name == "" then "nada que aprobar: todo está al día" otherwise "nada que aprobar con ese nombre (lampson tools list)")
|
|
252
|
+
each f in done
|
|
253
|
+
let es be where(apptools.scan_files(), (e) => e["file"] == f)
|
|
254
|
+
print("aprobada " + f + (when length(es) > 0 and es[0]["error"] == nothing then " · puede tocar: " + apptools.ceiling(es[0]) otherwise ""))
|
|
255
|
+
exit(0)
|
|
256
|
+
print("uso: lampson tools list · tools approve [nombre] (sin nombre: todo lo que está en la carpeta)")
|
|
257
|
+
exit(2)
|
|
258
|
+
|
|
206
259
|
-- `lampson channel list|on|off|setup [canal]`: los canales (plugins con "channel", lib/channels.syn)
|
|
207
260
|
let ch_cmd be env("LAMPSON_CHANNEL_CMD", "")
|
|
208
261
|
when ch_cmd != ""
|
|
@@ -269,7 +322,8 @@ task lampson_subagent(spec_json)
|
|
|
269
322
|
-- {"id": "r2", "op": "agents"} · {"id": "r3", "op": "ping"}
|
|
270
323
|
-- y por stdout, una línea JSON por evento con ese id: los mismos que `--json` (session, assistant, tool_call…) y
|
|
271
324
|
-- {"id", "kind": "done", "data": {agent, thread, session, text, steps, usage, stopped}} al terminar cada ask. Al
|
|
272
|
-
-- arrancar, {"kind": "ready", "data": {"agents": […], "protocol": 2}}
|
|
325
|
+
-- arrancar, {"kind": "ready", "data": {"agents": […], "protocol": 2, "warnings": […]}}; antes de un ask cuyo agente lista
|
|
326
|
+
-- tools que no tiene (plugin apagado…), {"id", "kind": "warning", "data": "<por qué>"}.
|
|
273
327
|
-- CONCURRENCIA (protocolo 2): cada ask corre en su propio agente de Synsema; conversaciones distintas van en
|
|
274
328
|
-- paralelo, dos asks de la MISMA conversación (agente + thread) esperan en fila. Un agente que imprime sale con
|
|
275
329
|
-- prefijo "[Agente_N]" (rompería el JSON): por eso los trabajos publican en el bus y SOLO el hilo principal escribe.
|
|
@@ -349,9 +403,15 @@ task stdio_ask(req, rid)
|
|
|
349
403
|
let ss be when contains(req, "session") and req["session"] != nothing then text(req["session"]) otherwise ""
|
|
350
404
|
-- la fila es por conversación: (agente, thread), o la sesión; sin ninguno, el pedido solo (va en paralelo)
|
|
351
405
|
let key be when th != "" then agent_id + "\n" + th otherwise (when ss != "" then agent_id + "\nsession:" + ss otherwise "req:" + rid)
|
|
352
|
-
|
|
353
|
-
|
|
406
|
+
-- from: quien escribe, tal como lo dice la app (el SDK lo documenta; las herramientas de la app lo reciben en ctx)
|
|
407
|
+
let rf be when contains(req, "from") and type_of(req["from"]) == "map" then req["from"] otherwise {}
|
|
408
|
+
let from be {"id": text(get(rf, "id", "")), "name": text(get(rf, "name", "")), "kind": text(get(rf, "kind", "human"))}
|
|
409
|
+
let sobre be {"to": agent_id, "thread": th, "session": ss, "from": from, "text": msg, "images": when contains(req, "images") and type_of(req["images"]) == "list" then req["images"] otherwise [], "channel": "sdk", "meta": when contains(req, "meta") and type_of(req["meta"]) == "map" then req["meta"] otherwise {}}
|
|
410
|
+
give {"ok": true, "key": key, "warnings": runtime.missing(spec), "job": {"id": rid, "to": agent_id, "thread": th, "mode": mode, "key": key, "sobre": sobre}}
|
|
354
411
|
|
|
412
|
+
when env("LAMPSON_RUN_STDIO", "") == "1" and env("LAMPSON_APPROVE_TOOLS", "") == "1"
|
|
413
|
+
-- SDK local con approveTools: lo que dejó el dev en la carpeta, aprobado una vez al arrancar (lib/apptools.syn)
|
|
414
|
+
apptools.approve("")
|
|
355
415
|
when env("LAMPSON_RUN_STDIO", "") == "1"
|
|
356
416
|
share {"id": text(now())} as "lampson:run"
|
|
357
417
|
share {"kind": "sdk"} as "lampson:ui"
|
|
@@ -365,7 +425,11 @@ when env("LAMPSON_RUN_STDIO", "") == "1"
|
|
|
365
425
|
mcp.start_all(8)
|
|
366
426
|
let sub be bus_subscribe(["stdio.line", "stdio.out", "stdio.done", "stdio.eof"], {"max_queue": 100000, "on_full": "error"})
|
|
367
427
|
spawn StdioReader
|
|
368
|
-
|
|
428
|
+
-- tools que algún agente lista y no va a tener (plugin apagado, nombre mal escrito): el SDK las muestra al arrancar
|
|
429
|
+
let warns be []
|
|
430
|
+
each n in all_names
|
|
431
|
+
set warns to warns + runtime.missing(runtime.get(n))
|
|
432
|
+
stdio_out({"kind": "ready", "data": {"agents": all_names, "protocol": 2, "warnings": warns}})
|
|
369
433
|
let busy be {}
|
|
370
434
|
let waiting be {}
|
|
371
435
|
let running be 0
|
|
@@ -408,10 +472,20 @@ when env("LAMPSON_RUN_STDIO", "") == "1"
|
|
|
408
472
|
let op be when contains(req, "op") and req["op"] != nothing then lower(text(req["op"])) otherwise "ask"
|
|
409
473
|
when op == "ping"
|
|
410
474
|
stdio_out({"id": rid, "kind": "pong"})
|
|
475
|
+
otherwise when op == "tools"
|
|
476
|
+
-- funciones de la app (lampson.tool() del SDK, lib/sdktools.syn): reemplaza la lista entera
|
|
477
|
+
let nt be sdktools.normalize(when contains(req, "tools") then req["tools"] otherwise [])
|
|
478
|
+
share {"tools": nt["tools"]} as "sdk:tools"
|
|
479
|
+
stdio_out({"id": rid, "kind": "tools", "data": {"tools": apply((t) => t["name"], nt["tools"]), "errors": nt["errors"]}})
|
|
480
|
+
otherwise when op == "tool_result"
|
|
481
|
+
bus_publish("sdktool.result", req)
|
|
411
482
|
otherwise when op == "agents"
|
|
412
483
|
stdio_out({"id": rid, "kind": "agents", "data": apply((n) => {"id": n, "description": runtime.get(n)["description"]}, runtime.names())})
|
|
413
484
|
otherwise when op == "ask"
|
|
414
485
|
let a be stdio_ask(req, rid)
|
|
486
|
+
when a["ok"]
|
|
487
|
+
each w in a["warnings"]
|
|
488
|
+
stdio_out({"id": rid, "kind": "warning", "data": w, "tag": "", "agent": a["job"]["to"], "thread": a["job"]["thread"]})
|
|
415
489
|
when not a["ok"]
|
|
416
490
|
stdio_out({"id": rid, "kind": "done", "data": a["done"], "tag": "", "agent": a["done"]["agent"], "thread": a["done"]["thread"]})
|
|
417
491
|
otherwise when contains(busy, a["key"]) and busy[a["key"]]
|
|
@@ -422,7 +496,7 @@ when env("LAMPSON_RUN_STDIO", "") == "1"
|
|
|
422
496
|
set running to running + 1
|
|
423
497
|
spawn StdioJob with spec_json = json_encode(a["job"])
|
|
424
498
|
otherwise
|
|
425
|
-
stdio_out({"id": rid, "kind": "error", "data": "unknown op '" + op + "' (ask, agents, ping)"})
|
|
499
|
+
stdio_out({"id": rid, "kind": "error", "data": "unknown op '" + op + "' (ask, agents, tools, tool_result, ping)"})
|
|
426
500
|
exit(0)
|
|
427
501
|
|
|
428
502
|
let json_out be env("LAMPSON_RUN_JSON", "") == "1"
|
|
@@ -467,6 +541,13 @@ task emit_json(kind, data, tag)
|
|
|
467
541
|
print(json_encode({"kind": kind, "data": data, "tag": tag, "agent": agent_id, "thread": thread}))
|
|
468
542
|
flush()
|
|
469
543
|
|
|
544
|
+
-- en texto el aviso va a stderr (eprint, Synsema 0.6.42+): stdout queda solo para la respuesta
|
|
545
|
+
each w in runtime.missing(spec)
|
|
546
|
+
when json_out
|
|
547
|
+
print(json_encode({"kind": "warning", "data": w, "tag": "", "agent": agent_id, "thread": thread}))
|
|
548
|
+
otherwise
|
|
549
|
+
eprint("lampson run: warning: " + w)
|
|
550
|
+
|
|
470
551
|
task on_start(info)
|
|
471
552
|
set thread to info["thread"]
|
|
472
553
|
when json_out
|
package/sdk/index.d.ts
CHANGED
|
@@ -9,14 +9,27 @@ export interface ServerOptions {
|
|
|
9
9
|
fetch?: typeof fetch;
|
|
10
10
|
/** Per-request timeout in ms (default 15 min: an agent can take a while). */
|
|
11
11
|
timeout?: number;
|
|
12
|
+
/** Your tools in server mode: the PUBLIC URL of toolsHandler(), where Lampson POSTs each call (in the key's list). */
|
|
13
|
+
toolsUrl?: string;
|
|
14
|
+
/** The key's signing secret (whsec_…, shown by `lampson key add`): toolsHandler() verifies Lampson's calls with it. */
|
|
15
|
+
toolsSecret?: string;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
export interface LocalOptions {
|
|
15
19
|
local: {
|
|
16
20
|
/** The project folder the agents work in. */
|
|
17
21
|
workspace: string;
|
|
18
|
-
/** LAMPSON_HOME: where Lampson keeps its config, sessions and plugins (default ~/lampson). */
|
|
22
|
+
/** LAMPSON_HOME: where Lampson keeps its config, sessions and plugins (default ~/lampson). Relative to process.cwd(). */
|
|
19
23
|
home?: string;
|
|
24
|
+
/** false: no tool of Lampson's own (bash, read, write, fetch…) exists in this process, not even for the built-in
|
|
25
|
+
* agents — your agents get only the tools you give them. Default true. */
|
|
26
|
+
lampsonTools?: boolean;
|
|
27
|
+
/** Your tools in Synsema: a folder inside `workspace` with one `<name>.syn` per tool (default `<workspace>/.lampson/tools`).
|
|
28
|
+
* Each file has an `intent:` line (its description), its `require`s (all it can touch) and `export task <name>(…)`. */
|
|
29
|
+
tools?: string;
|
|
30
|
+
/** A `.syn` tool runs only once a person approved that exact content (`lampson tools approve`). true approves what
|
|
31
|
+
* is in the folder when Lampson starts (later changes, even the agent's, need approval): for development, where you edit the tools. Never on a shared server. */
|
|
32
|
+
approveTools?: boolean;
|
|
20
33
|
/** Extra environment for the Lampson process (e.g. provider keys). */
|
|
21
34
|
env?: Record<string, string>;
|
|
22
35
|
/** Advanced / tests: an exact command that speaks the `lampson run --stdio` protocol. */
|
|
@@ -24,6 +37,13 @@ export interface LocalOptions {
|
|
|
24
37
|
};
|
|
25
38
|
}
|
|
26
39
|
|
|
40
|
+
export interface CommonOptions {
|
|
41
|
+
/** The agent that answers when a message does not say `agent`. Without it: the workspace default ("build"). */
|
|
42
|
+
agent?: string;
|
|
43
|
+
/** Local mode: called once per tool an agent lists but will not have (plugin off, typo). Default console.warn; null = silent. */
|
|
44
|
+
onWarning?: ((message: string) => void) | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
export interface Message {
|
|
28
48
|
/** The agent that answers (alias: `to`). Default: the workspace's default agent. */
|
|
29
49
|
agent?: string;
|
|
@@ -63,7 +83,7 @@ export interface Result {
|
|
|
63
83
|
export interface Queued { job: string; status: 'queued' }
|
|
64
84
|
|
|
65
85
|
export interface LampsonEvent {
|
|
66
|
-
kind: 'session' | 'assistant' | 'tool_call' | 'tool_result' | 'tool_denied' | 'usage' | 'inbox' | 'error' | 'compact' | 'done' | string;
|
|
86
|
+
kind: 'session' | 'assistant' | 'tool_call' | 'tool_result' | 'tool_denied' | 'usage' | 'inbox' | 'error' | 'compact' | 'warning' | 'done' | string;
|
|
67
87
|
data: any;
|
|
68
88
|
tag?: string;
|
|
69
89
|
agent?: string;
|
|
@@ -80,14 +100,55 @@ export class LampsonError extends Error {
|
|
|
80
100
|
stderr?: string[];
|
|
81
101
|
}
|
|
82
102
|
|
|
103
|
+
/** What your app's tool receives besides its arguments: set by your app (the message), never by the model. */
|
|
104
|
+
export interface ToolContext {
|
|
105
|
+
from?: { id?: string; name?: string; kind?: string };
|
|
106
|
+
thread?: string;
|
|
107
|
+
agent?: string;
|
|
108
|
+
session?: string;
|
|
109
|
+
meta?: Record<string, unknown>;
|
|
110
|
+
channel?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** A function of your app as a tool — the AI SDK shape. */
|
|
114
|
+
export interface ToolDefinition<A = any> {
|
|
115
|
+
description?: string;
|
|
116
|
+
/** A zod schema (validated before execute) or a JSON Schema. */
|
|
117
|
+
inputSchema?: unknown;
|
|
118
|
+
/** A JSON Schema (alias of inputSchema). */
|
|
119
|
+
parameters?: unknown;
|
|
120
|
+
execute: (args: A, ctx: Readonly<ToolContext>) => unknown | Promise<unknown>;
|
|
121
|
+
/** Seconds Lampson waits for the answer (default 60, max 600). */
|
|
122
|
+
timeout?: number;
|
|
123
|
+
}
|
|
124
|
+
|
|
83
125
|
export class Lampson {
|
|
84
|
-
constructor(opts: ServerOptions | LocalOptions);
|
|
126
|
+
constructor(opts: (ServerOptions | LocalOptions) & CommonOptions);
|
|
85
127
|
readonly mode: 'server' | 'local';
|
|
128
|
+
/** A function of your app as a tool (server mode needs toolsUrl); list its name in the agent's "tools". */
|
|
129
|
+
tool<A = any>(name: string, def: ToolDefinition<A>): this;
|
|
130
|
+
/** Several tools at once — an AI SDK tools object works as is. */
|
|
131
|
+
tools(map: Record<string, ToolDefinition>): this;
|
|
132
|
+
/**
|
|
133
|
+
* Server mode: the endpoint for Lampson's tool calls — verifies the signature, runs the tool, answers.
|
|
134
|
+
* Web standard (Next route handler, Hono, Bun, Deno) or Node (Express, http.createServer).
|
|
135
|
+
*/
|
|
136
|
+
toolsHandler(opts?: {
|
|
137
|
+
/** true if this call_id already ran (and record it if not). Default: in this process. With several instances
|
|
138
|
+
* (serverless, workers) share it, e.g. Redis `SET call:<id> 1 NX EX 600`. A repeated call answers 409. */
|
|
139
|
+
seen?: (callId: string) => boolean | Promise<boolean>;
|
|
140
|
+
}): (req: any, res?: any) => Promise<Response | void>;
|
|
141
|
+
/** The default agent given in the options ("" = the workspace default). */
|
|
142
|
+
readonly agent: string;
|
|
143
|
+
/** Local mode: tools some agent lists but will not have, one message each (filled once the process is ready). */
|
|
144
|
+
readonly warnings: string[];
|
|
86
145
|
ask(msg: Message): Promise<Result | Queued>;
|
|
87
146
|
stream(msg: Omit<Message, 'callback'>): AsyncGenerator<LampsonEvent, void, unknown>;
|
|
88
147
|
agents(): Promise<AgentInfo[]>;
|
|
89
148
|
job(id: string): Promise<unknown>;
|
|
90
149
|
close(): Promise<void>;
|
|
150
|
+
/** Checks a tool call's RFC 9421 signature by hand (toolsHandler() does it) → {keyid, created} or null. */
|
|
151
|
+
static verifyToolRequest(req: { method: string; url: string; headers: Record<string, string> | Headers; body: string | Buffer }, secret: string, opts?: { now?: number }): { keyid: string; created: number } | null;
|
|
91
152
|
static verifySignature(rawBody: string | Buffer, signature: string | undefined, secret: string): boolean;
|
|
92
153
|
}
|
|
93
154
|
|