lampson 0.5.0 → 0.5.2
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 +17 -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 +297 -12
- package/skills/lampson/SKILL.md +15 -0
- package/web.syn +30 -4
package/README.md
CHANGED
|
@@ -116,8 +116,25 @@ lampson run --agent shop "hi" # one message from a script; --
|
|
|
116
116
|
import { Lampson } from "lampson"; // also: pip install lampson
|
|
117
117
|
const lampson = new Lampson({ local: { workspace: "./my-project" } }); // or { url, key } for a running Lampson
|
|
118
118
|
const r = await lampson.ask({ agent: "shop", thread: "customer-42", text: "do you have whole-wheat bread?" });
|
|
119
|
+
|
|
120
|
+
// tools are the AI SDK shape: zod 4, zod 3 (objects, strings, numbers, enums, arrays, optional… — for the rest add
|
|
121
|
+
// zod-to-json-schema) or a plain JSON Schema
|
|
122
|
+
// an agent for your customers: only the tools you give it — no bash, read, write or fetch of Lampson's own
|
|
123
|
+
const shop = new Lampson({ agent: "shop", local: { workspace: "./my-project", lampsonTools: false } });
|
|
124
|
+
shop.tool("stock", { description: "Units in stock", inputSchema: z.object({ product: z.string() }),
|
|
125
|
+
execute: async ({ product }, ctx) => db.stock(product, ctx.from.id) }); // your function; ctx comes from your app
|
|
126
|
+
|
|
127
|
+
// Lampson on another machine: the same tools; it POSTs each call to your endpoint, signed with the key's secret
|
|
128
|
+
const remote = new Lampson({ url, key, toolsUrl: "https://my-app.com/api/lampson/tools", toolsSecret });
|
|
129
|
+
export const POST = remote.toolsHandler(); // Next/Hono/Bun; Express: app.post(path, remote.toolsHandler())
|
|
119
130
|
```
|
|
120
131
|
|
|
132
|
+
Or write the tool in Synsema — `.lampson/tools/stock.syn`, one file per tool — and its `require`s are everything it can
|
|
133
|
+
touch: a message that tricks the model into sending data elsewhere gets `Capability not granted`. It reads only
|
|
134
|
+
the variables it names with `env("NAME")` (never Lampson's own, never the folder's `.env`), and it runs only once
|
|
135
|
+
you approved that exact content (`lampson tools approve`, or *herramientas* in the web UI): if an agent rewrites
|
|
136
|
+
it, it stops until you look.
|
|
137
|
+
|
|
121
138
|
- **An agent is a file**: `.lampson/agents/shop.agent.json` (or `~/lampson/agents/` for every project) — its prompt,
|
|
122
139
|
the exact tools it may use (optionally limited to some paths, with per-tool approval) and its model.
|
|
123
140
|
- **One conversation per customer** (`thread`), and a mailbox per conversation: a burst of messages gets one
|
package/lampson.ps1
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
# lampson key add [--agent ID[,ID]] [--name NOMBRE] [--rate N] [--callback URL] · key list · key remove <id> # API keys /v1
|
|
14
14
|
# lampson mcp serve [--agent ID[,ID]] [--workspace RUTA] # Lampson como servidor MCP (stdio) para otros agentes
|
|
15
15
|
# lampson channel list · channel on|off <canal> · channel setup <canal> # canales (Telegram, Chatwoot…)
|
|
16
|
+
# lampson plugin list · plugin on|off <nombre> # encender plugins sin interfaz (VPS por SSH, scripts)
|
|
17
|
+
# lampson tools list · tools approve [nombre] # herramientas .syn del proyecto: corren solo aprobadas
|
|
16
18
|
# lampson objective add "…" --agent ID | --team ID [--budget N] [--round S] · objective list · show <id> · reply <id> "…" [--approve|--deny] · cancel <id> # objetivos
|
|
17
19
|
# lampson team list # equipos de agentes y quién reporta a quién
|
|
18
20
|
#
|
|
@@ -25,7 +27,7 @@ $caller = (Get-Location).Path
|
|
|
25
27
|
|
|
26
28
|
# --- args: acepta --flag y -Flag, sin distinguir mayúsculas ---
|
|
27
29
|
$Workspace = ""; $Web = $false; $Agent = ""; $Perm = ""; $Hub = ""; $Install = ""; $Domain = $null; $Email = ""; $Pair = $null
|
|
28
|
-
$Run = $false; $Message = @(); $Thread = ""; $Session = ""; $Json = $false; $Key = ""; $KeyName = ""; $KeyId = ""; $McpServe = $false; $ChannelCmd = ""; $ChannelName = ""; $Stdio = $false; $KeyRate = ""; $KeyCallbacks = @(); $ObjCmd = ""; $ObjId = ""; $ObjTeam = ""; $ObjBudget = ""; $ObjRound = ""; $ObjDecision = ""; $TeamCmd = ""
|
|
30
|
+
$Run = $false; $Message = @(); $Thread = ""; $Session = ""; $Json = $false; $Key = ""; $KeyName = ""; $KeyId = ""; $McpServe = $false; $ChannelCmd = ""; $ChannelName = ""; $Stdio = $false; $KeyRate = ""; $KeyCallbacks = @(); $PluginCmd = ""; $PluginName = ""; $ToolsCmd = ""; $ObjCmd = ""; $ObjId = ""; $ObjTeam = ""; $ObjBudget = ""; $ObjRound = ""; $ObjDecision = ""; $TeamCmd = ""
|
|
29
31
|
$i = 0
|
|
30
32
|
# `lampson run …`: subcomando sin interfaz (run.syn, spec/engine.md); las palabras sueltas son el mensaje
|
|
31
33
|
if ($args.Count -gt 0 -and ([string]$args[0]).ToLower() -eq "run") { $Run = $true; $i = 1 }
|
|
@@ -33,6 +35,10 @@ if ($args.Count -gt 0 -and ([string]$args[0]).ToLower() -eq "run") { $Run = $tru
|
|
|
33
35
|
# `lampson mcp serve …`: servidor MCP por stdio (run.syn con LAMPSON_MCP_SERVE)
|
|
34
36
|
if ($args.Count -gt 1 -and ([string]$args[0]).ToLower() -eq "mcp" -and ([string]$args[1]).ToLower() -eq "serve") { $Run = $true; $McpServe = $true; $i = 2 }
|
|
35
37
|
# `lampson channel list|on|off|setup <canal>` (run.syn con LAMPSON_CHANNEL_CMD)
|
|
38
|
+
# `lampson plugin list|on|off <nombre>` (run.syn con LAMPSON_PLUGIN_CMD)
|
|
39
|
+
# `lampson tools list|approve [nombre]` (run.syn con LAMPSON_TOOLS_CMD): aprobar las herramientas .syn del proyecto
|
|
40
|
+
if ($args.Count -gt 0 -and ([string]$args[0]).ToLower() -eq "tools") { $Run = $true; $ToolsCmd = $(if ($args.Count -gt 1) { ([string]$args[1]).ToLower() } else { "list" }); $i = 2 }
|
|
41
|
+
if ($args.Count -gt 0 -and ([string]$args[0]).ToLower() -eq "plugin") { $Run = $true; $PluginCmd = $(if ($args.Count -gt 1) { ([string]$args[1]).ToLower() } else { "list" }); $i = 2 }
|
|
36
42
|
if ($args.Count -gt 0 -and ([string]$args[0]).ToLower() -eq "channel") { $Run = $true; $ChannelCmd = $(if ($args.Count -gt 1) { ([string]$args[1]).ToLower() } else { "list" }); $i = 2 }
|
|
37
43
|
# `lampson objective add|list|show|reply|cancel` y `lampson team list` (run.syn con LAMPSON_OBJ_CMD / LAMPSON_TEAM_CMD)
|
|
38
44
|
if ($args.Count -gt 0 -and ([string]$args[0]).ToLower() -eq "objective") { $Run = $true; $ObjCmd = $(if ($args.Count -gt 1) { ([string]$args[1]).ToLower() } else { "list" }); $i = 2 }
|
|
@@ -68,14 +74,15 @@ while ($i -lt $args.Count) {
|
|
|
68
74
|
'^--?deny$' { $ObjDecision = "deny" }
|
|
69
75
|
'^--?(update|u)$' { Write-Host "actualizando Lampson en $here"; git -C $here pull --ff-only origin main; Write-Host ("lampson " + (git -C $here rev-parse --short HEAD)); exit $LASTEXITCODE }
|
|
70
76
|
'^--?(help|h|\?)$' { Get-Content $PSCommandPath | Select-Object -Skip 1 -First 9 | ForEach-Object { $_.TrimStart('#',' ') }; exit 0 }
|
|
71
|
-
default { if ($ObjCmd -ne "" -and $ObjId -eq "" -and @("show", "reply", "cancel") -contains $ObjCmd -and -not $a.StartsWith("-")) { $ObjId = $a } elseif ($ObjCmd -ne "" -and -not $a.StartsWith("-")) { $Message += $a } elseif ($ChannelCmd -ne "" -and -not $a.StartsWith("-")) { $ChannelName = $a } elseif ($Key -ne "" -and -not $a.StartsWith("-")) { $KeyId = $a } elseif ($Run -and -not $a.StartsWith("-")) { $Message += $a } elseif ($Workspace -eq "" -and -not $a.StartsWith("-")) { $Workspace = $a } else { Write-Error "argumento desconocido: $a (probá lampson --help)"; exit 1 } }
|
|
77
|
+
default { if ($ObjCmd -ne "" -and $ObjId -eq "" -and @("show", "reply", "cancel") -contains $ObjCmd -and -not $a.StartsWith("-")) { $ObjId = $a } elseif ($ObjCmd -ne "" -and -not $a.StartsWith("-")) { $Message += $a } elseif ($ChannelCmd -ne "" -and -not $a.StartsWith("-")) { $ChannelName = $a } elseif (($PluginCmd -ne "" -or $ToolsCmd -ne "") -and -not $a.StartsWith("-")) { $PluginName = $a } elseif ($Key -ne "" -and -not $a.StartsWith("-")) { $KeyId = $a } elseif ($Run -and -not $a.StartsWith("-")) { $Message += $a } elseif ($Workspace -eq "" -and -not $a.StartsWith("-")) { $Workspace = $a } else { Write-Error "argumento desconocido: $a (probá lampson --help)"; exit 1 } }
|
|
72
78
|
}
|
|
73
79
|
$i++
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
# motor mínimo: el hub y los workspaces
|
|
82
|
+
# motor mínimo: `trust proxy` en el hub y los workspaces (0.6.42+), y las herramientas de la app usan --cap-set,
|
|
83
|
+
# --no-env-file y http_sign (probados en 0.6.44). Con uno viejo el
|
|
77
84
|
# hub ni arranca: mejor decirlo acá que dejar un 502
|
|
78
|
-
$MinEngine = [version]"0.6.
|
|
85
|
+
$MinEngine = [version]"0.6.44"
|
|
79
86
|
$engine = ((& synsema --version 2>$null) -replace '^\D*', '').Trim()
|
|
80
87
|
if (-not ($engine -as [version]) -or [version]$engine -lt $MinEngine) { Write-Error "lampson necesita synsema $MinEngine o más nuevo (tenés '$engine'): synsema update"; exit 1 }
|
|
81
88
|
|
|
@@ -219,7 +226,7 @@ try {
|
|
|
219
226
|
$env:LAMPSON_KEY_CMD = $Key; $env:LAMPSON_KEY_NAME = $KeyName; $env:LAMPSON_KEY_ID = $KeyId; $env:LAMPSON_KEY_AGENTS = $Agent
|
|
220
227
|
$env:LAMPSON_KEY_RATE = $KeyRate; $env:LAMPSON_KEY_CALLBACKS = ($KeyCallbacks -join ",")
|
|
221
228
|
$env:LAMPSON_MCP_SERVE = $(if ($McpServe) { "1" } else { "" }); $env:LAMPSON_MCP_AGENTS = $(if ($McpServe) { $Agent } else { "" })
|
|
222
|
-
$env:LAMPSON_CHANNEL_CMD = $ChannelCmd; $env:LAMPSON_CHANNEL_NAME = $ChannelName
|
|
229
|
+
$env:LAMPSON_CHANNEL_CMD = $ChannelCmd; $env:LAMPSON_CHANNEL_NAME = $ChannelName; $env:LAMPSON_PLUGIN_CMD = $PluginCmd; $env:LAMPSON_PLUGIN_NAME = $PluginName; $env:LAMPSON_TOOLS_CMD = $ToolsCmd; $env:LAMPSON_TOOLS_NAME = $PluginName
|
|
223
230
|
$env:LAMPSON_RUN_STDIO = $(if ($Stdio) { "1" } else { "" })
|
|
224
231
|
$env:LAMPSON_OBJ_CMD = $ObjCmd; $env:LAMPSON_OBJ_ID = $ObjId; $env:LAMPSON_OBJ_AGENT = $(if ($ObjCmd -ne "") { $Agent } else { "" }); $env:LAMPSON_OBJ_TEAM = $ObjTeam
|
|
225
232
|
$env:LAMPSON_OBJ_BUDGET = $ObjBudget; $env:LAMPSON_OBJ_ROUND = $ObjRound; $env:LAMPSON_OBJ_DECISION = $ObjDecision; $env:LAMPSON_TEAM_CMD = $TeamCmd
|
|
@@ -230,7 +237,7 @@ try {
|
|
|
230
237
|
Pop-Location
|
|
231
238
|
# `lampson` corre este script dentro de TU sesión de PowerShell: lo de `run`/`key` no debe quedar en el entorno
|
|
232
239
|
# (un LAMPSON_SESSION que queda haría que el próximo `lampson` retome esa sesión sin pedirlo)
|
|
233
|
-
if ($Run) { foreach ($v in "LAMPSON_MESSAGE","LAMPSON_RUN_PERMISSION","LAMPSON_THREAD","LAMPSON_SESSION","LAMPSON_RUN_JSON","LAMPSON_KEY_CMD","LAMPSON_KEY_NAME","LAMPSON_KEY_ID","LAMPSON_KEY_AGENTS","LAMPSON_MCP_SERVE","LAMPSON_MCP_AGENTS","LAMPSON_CHANNEL_CMD","LAMPSON_CHANNEL_NAME","LAMPSON_RUN_STDIO","LAMPSON_KEY_RATE","LAMPSON_KEY_CALLBACKS","LAMPSON_OBJ_CMD","LAMPSON_OBJ_ID","LAMPSON_OBJ_AGENT","LAMPSON_OBJ_TEAM","LAMPSON_OBJ_BUDGET","LAMPSON_OBJ_ROUND","LAMPSON_OBJ_DECISION","LAMPSON_TEAM_CMD") { Remove-Item "Env:$v" -ErrorAction SilentlyContinue } }
|
|
240
|
+
if ($Run) { foreach ($v in "LAMPSON_MESSAGE","LAMPSON_RUN_PERMISSION","LAMPSON_THREAD","LAMPSON_SESSION","LAMPSON_RUN_JSON","LAMPSON_KEY_CMD","LAMPSON_KEY_NAME","LAMPSON_KEY_ID","LAMPSON_KEY_AGENTS","LAMPSON_MCP_SERVE","LAMPSON_MCP_AGENTS","LAMPSON_CHANNEL_CMD","LAMPSON_CHANNEL_NAME","LAMPSON_PLUGIN_CMD","LAMPSON_PLUGIN_NAME","LAMPSON_TOOLS_CMD","LAMPSON_TOOLS_NAME","LAMPSON_RUN_STDIO","LAMPSON_KEY_RATE","LAMPSON_KEY_CALLBACKS","LAMPSON_OBJ_CMD","LAMPSON_OBJ_ID","LAMPSON_OBJ_AGENT","LAMPSON_OBJ_TEAM","LAMPSON_OBJ_BUDGET","LAMPSON_OBJ_ROUND","LAMPSON_OBJ_DECISION","LAMPSON_TEAM_CMD") { Remove-Item "Env:$v" -ErrorAction SilentlyContinue } }
|
|
234
241
|
}
|
|
235
242
|
} finally {
|
|
236
243
|
Pop-Location
|
package/lampson.sh
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# lampson key add [--agent ID[,ID]] [--name NOMBRE] [--rate N] [--callback URL] · key list · key remove <id> # API keys /v1
|
|
13
13
|
# lampson mcp serve [--agent ID[,ID]] [--workspace RUTA] # Lampson como servidor MCP (stdio) para otros agentes
|
|
14
14
|
# lampson channel list · channel on|off <canal> · channel setup <canal> # canales (Telegram, Chatwoot…)
|
|
15
|
+
# lampson plugin list · plugin on|off <nombre> # encender plugins sin interfaz (VPS por SSH, scripts)
|
|
16
|
+
# lampson tools list · tools approve [nombre] # herramientas .syn del proyecto: corren solo aprobadas
|
|
15
17
|
# lampson objective add "…" --agent ID | --team ID [--budget N] [--round S] · objective list · show <id> · reply <id> "…" [--approve|--deny] · cancel <id> # objetivos
|
|
16
18
|
# lampson team list # equipos de agentes y quién reporta a quién
|
|
17
19
|
set -euo pipefail
|
|
@@ -19,7 +21,7 @@ set -euo pipefail
|
|
|
19
21
|
here="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
|
|
20
22
|
caller="$(pwd)"
|
|
21
23
|
ws=""; web=0; hub=""; install=""; domain="-"; email=""; pair_url="-"
|
|
22
|
-
run=0; msg=""; perm_flag=""; key=""; key_name=""; key_id=""; mcp_serve=""; ch_cmd=""; ch_name=""
|
|
24
|
+
run=0; msg=""; perm_flag=""; key=""; key_name=""; key_id=""; mcp_serve=""; ch_cmd=""; ch_name=""; pl_cmd=""; pl_name=""; tl_cmd=""
|
|
23
25
|
obj_cmd=""; obj_id=""; obj_team=""; obj_budget=""; obj_round=""; obj_decision=""; team_cmd=""
|
|
24
26
|
# `lampson run …`: subcomando sin interfaz (run.syn); las palabras sueltas son el mensaje, no el workspace
|
|
25
27
|
if [ "${1:-}" = run ]; then run=1; shift; fi
|
|
@@ -28,6 +30,10 @@ if [ "${1:-}" = run ]; then run=1; shift; fi
|
|
|
28
30
|
if [ "${1:-}" = mcp ] && [ "${2:-}" = serve ]; then run=1; mcp_serve=1; shift 2; fi
|
|
29
31
|
# `lampson channel list|on|off|setup <canal>` (run.syn con LAMPSON_CHANNEL_CMD)
|
|
30
32
|
if [ "${1:-}" = channel ]; then run=1; ch_cmd="${2:-list}"; shift; [ $# -gt 0 ] && shift; fi
|
|
33
|
+
# `lampson plugin list|on|off <nombre>` (run.syn con LAMPSON_PLUGIN_CMD)
|
|
34
|
+
# `lampson tools list|approve [nombre]` (run.syn con LAMPSON_TOOLS_CMD): aprobar las herramientas .syn del proyecto
|
|
35
|
+
if [ "${1:-}" = tools ]; then run=1; tl_cmd="${2:-list}"; shift; [ $# -gt 0 ] && shift; fi
|
|
36
|
+
if [ "${1:-}" = plugin ]; then run=1; pl_cmd="${2:-list}"; shift; [ $# -gt 0 ] && shift; fi
|
|
31
37
|
if [ "${1:-}" = key ]; then run=1; key="${2:-help}"; shift; [ $# -gt 0 ] && shift; fi
|
|
32
38
|
# `lampson objective add|list|show|reply|cancel` y `lampson team list` (run.syn con LAMPSON_OBJ_CMD / LAMPSON_TEAM_CMD)
|
|
33
39
|
if [ "${1:-}" = objective ]; then run=1; obj_cmd="${2:-list}"; shift; [ $# -gt 0 ] && shift; fi
|
|
@@ -60,13 +66,13 @@ while [ $# -gt 0 ]; do
|
|
|
60
66
|
--deny) obj_decision=deny ;;
|
|
61
67
|
--update) echo "actualizando Lampson en $here"; git -C "$here" pull --ff-only origin main; echo "lampson $(git -C "$here" rev-parse --short HEAD)"; exit $? ;;
|
|
62
68
|
-*) echo "uso: lampson run [--agent ID] [--thread T|--session ID] [--json] [--yolo|--strict|--ask] [mensaje]" >&2; echo "uso: lampson [--web] [--hub start|stop|status|logs|restart] [--domain DOMINIO|off [--email EMAIL]] [--pair [URL]] [--install|--uninstall] [--workspace RUTA] [--agent PERFIL] [--yolo|--strict|--ask] [--update]" >&2; exit 1 ;;
|
|
63
|
-
*) if [ -n "$obj_cmd" ] && [ -z "$obj_id" ] && { [ "$obj_cmd" = show ] || [ "$obj_cmd" = reply ] || [ "$obj_cmd" = cancel ]; }; then obj_id="$1"; elif [ -n "$obj_cmd" ]; then msg="${msg:+$msg }$1"; elif [ -n "$ch_cmd" ]; then ch_name="$1"; elif [ -n "$key" ]; then key_id="$1"; elif [ "$run" = 1 ]; then msg="${msg:+$msg }$1"; else ws="$1"; fi ;;
|
|
69
|
+
*) if [ -n "$obj_cmd" ] && [ -z "$obj_id" ] && { [ "$obj_cmd" = show ] || [ "$obj_cmd" = reply ] || [ "$obj_cmd" = cancel ]; }; then obj_id="$1"; elif [ -n "$obj_cmd" ]; then msg="${msg:+$msg }$1"; elif [ -n "$ch_cmd" ]; then ch_name="$1"; elif [ -n "$pl_cmd" ] || [ -n "$tl_cmd" ]; then pl_name="$1"; elif [ -n "$key" ]; then key_id="$1"; elif [ "$run" = 1 ]; then msg="${msg:+$msg }$1"; else ws="$1"; fi ;;
|
|
64
70
|
esac
|
|
65
71
|
shift
|
|
66
72
|
done
|
|
67
73
|
export LAMPSON_HOME="$here"
|
|
68
|
-
# motor mínimo:
|
|
69
|
-
min_engine="0.6.
|
|
74
|
+
# motor mínimo: `trust proxy` (0.6.42+) y, para las herramientas de la app, --cap-set, --no-env-file y http_sign (0.6.44)
|
|
75
|
+
min_engine="0.6.44"
|
|
70
76
|
engine="$(synsema --version 2>/dev/null | sed 's/^[^0-9]*//')"
|
|
71
77
|
if [ -z "$engine" ] || [ "$(printf '%s\n%s\n' "$min_engine" "$engine" | sort -V | head -n1)" != "$min_engine" ]; then
|
|
72
78
|
echo "lampson necesita synsema $min_engine o más nuevo (tenés '${engine:-ninguno}'): synsema update" >&2; exit 1
|
|
@@ -183,7 +189,7 @@ if [ "$run" = 1 ]; then
|
|
|
183
189
|
# sin interfaz: los permisos los fija el flag, o el agente (run.syn: strict si el agente no dice nada)
|
|
184
190
|
entry=run.syn; export LAMPSON_MESSAGE="$msg" LAMPSON_RUN_PERMISSION="$perm_flag"
|
|
185
191
|
export LAMPSON_KEY_CMD="$key" LAMPSON_KEY_NAME="$key_name" LAMPSON_KEY_ID="$key_id" LAMPSON_KEY_AGENTS="${LAMPSON_AGENT:-}"
|
|
186
|
-
export LAMPSON_CHANNEL_CMD="$ch_cmd" LAMPSON_CHANNEL_NAME="$ch_name"
|
|
192
|
+
export LAMPSON_CHANNEL_CMD="$ch_cmd" LAMPSON_CHANNEL_NAME="$ch_name" LAMPSON_PLUGIN_CMD="$pl_cmd" LAMPSON_PLUGIN_NAME="$pl_name" LAMPSON_TOOLS_CMD="$tl_cmd" LAMPSON_TOOLS_NAME="$pl_name"
|
|
187
193
|
export LAMPSON_OBJ_CMD="$obj_cmd" LAMPSON_OBJ_ID="$obj_id" LAMPSON_OBJ_AGENT="$([ -n "$obj_cmd" ] && echo "${LAMPSON_AGENT:-}")" LAMPSON_OBJ_TEAM="$obj_team"
|
|
188
194
|
export LAMPSON_OBJ_BUDGET="$obj_budget" LAMPSON_OBJ_ROUND="$obj_round" LAMPSON_OBJ_DECISION="$obj_decision" LAMPSON_TEAM_CMD="$team_cmd"
|
|
189
195
|
export LAMPSON_MCP_SERVE="$mcp_serve" LAMPSON_MCP_AGENTS="$([ -n "$mcp_serve" ] && echo "${LAMPSON_AGENT:-}")"
|
package/lib/api.syn
CHANGED
|
@@ -26,6 +26,9 @@ use "./teams.syn" as teams
|
|
|
26
26
|
use "./schedule.syn" as schedule
|
|
27
27
|
use "./worktree.syn" as worktree
|
|
28
28
|
use "./diagnose.syn" as diagnose
|
|
29
|
+
use "./sdktools.syn" as sdktools
|
|
30
|
+
use "./apptools.syn" as apptools
|
|
31
|
+
use "./tools/url.syn" as urls
|
|
29
32
|
|
|
30
33
|
|
|
31
34
|
-- la key del header Authorization (o nothing)
|
|
@@ -106,7 +109,7 @@ export task parse(body, rec)
|
|
|
106
109
|
when cb != "" and not (starts_with(cb, "https://") or starts_with(cb, "http://"))
|
|
107
110
|
give {"ok": false, "status": 400, "error": "callback must be an http(s) URL"}
|
|
108
111
|
when cb != "" and not apikeys.callback_allowed(rec, cb)
|
|
109
|
-
give {"ok": false, "status": 403, "error": "this API key cannot send callbacks to " + cb + " (allowed: " + join(rec["callbacks"], ", ") + ")"}
|
|
112
|
+
give {"ok": false, "status": 403, "error": "this API key cannot send callbacks to " + cb + (when length(field(rec, "callbacks", [])) > 0 then " (allowed: " + join(rec["callbacks"], ", ") + ")" otherwise ": this API key has no callback list; create one with `lampson key add --callback URL`")}
|
|
110
113
|
let images be field(body, "images", [])
|
|
111
114
|
when type_of(images) != "list"
|
|
112
115
|
set images to []
|
|
@@ -120,8 +123,49 @@ export task parse(body, rec)
|
|
|
120
123
|
when contains(body, "sent_at") and body["sent_at"] != nothing
|
|
121
124
|
set meta["sent_at"] to body["sent_at"]
|
|
122
125
|
let sobre be {"to": target, "thread": text(field(body, "thread", "")), "session": text(field(body, "session", "")), "from": from, "text": msg, "images": images, "channel": text(field(body, "channel", "http")), "meta": meta}
|
|
126
|
+
-- funciones de la app (lib/remotetools.syn): viajan en el mensaje, sin estado en Lampson. tools_url tiene que
|
|
127
|
+
-- estar en la lista de callbacks de la key (obligatoria acá: sin lista no hay tools_url) y ser https salvo loopback
|
|
128
|
+
let rt be field(body, "tools", nothing)
|
|
129
|
+
when rt != nothing
|
|
130
|
+
let tu be text(field(body, "tools_url", ""))
|
|
131
|
+
when tu == ""
|
|
132
|
+
give {"ok": false, "status": 400, "error": "tools needs tools_url: the URL where your app answers the tool calls"}
|
|
133
|
+
let tp be urls.parse(tu)
|
|
134
|
+
when not tp["ok"] or contains(tu, "#") or (tp["scheme"] != "https" and not urls.is_loopback(tp["host"]))
|
|
135
|
+
give {"ok": false, "status": 400, "error": "tools_url must be an https URL without #fragment (http only for localhost)"}
|
|
136
|
+
when length(field(rec, "callbacks", [])) == 0 or not apikeys.callback_allowed(rec, tu)
|
|
137
|
+
give {"ok": false, "status": 403, "error": "this API key cannot call tools at " + tu + ": add it to the key's list (`lampson key add --callback URL`)"}
|
|
138
|
+
when apikeys.signing_secret(rec["id"]) == ""
|
|
139
|
+
give {"ok": false, "status": 403, "error": "this API key predates per-key signing secrets: create a new one to use app tools"}
|
|
140
|
+
let nt be sdktools.normalize(rt)
|
|
141
|
+
when length(nt["errors"]) > 0
|
|
142
|
+
give {"ok": false, "status": 400, "error": join(nt["errors"], "; ")}
|
|
143
|
+
let clash be where(nt["tools"], (t) => contains(apptools.names(), t["name"]))
|
|
144
|
+
when length(clash) > 0
|
|
145
|
+
give {"ok": false, "status": 400, "error": "tool '" + clash[0]["name"] + "' already exists as a Synsema tool of this project (.lampson/tools/)"}
|
|
146
|
+
set sobre["tools"] to nt["tools"]
|
|
147
|
+
set sobre["tools_url"] to tu
|
|
148
|
+
set sobre["tools_key"] to rec["id"]
|
|
149
|
+
set sobre to scope_sobre(sobre, rec)
|
|
150
|
+
-- retomar una sesión: solo una de esta key. Una ajena (otra app, la web del dueño, un equipo) es 404, no una
|
|
151
|
+
-- sesión nueva callada: la app creería que siguió la conversación
|
|
152
|
+
when sobre["session"] != "" and runtime.session_space(sobre["session"]) != sobre["space"]
|
|
153
|
+
give {"ok": false, "status": 404, "error": "no such session: " + sobre["session"]}
|
|
123
154
|
give {"ok": true, "status": 200, "error": "", "sobre": sobre, "callback": cb, "stream": field(body, "stream", false) == true}
|
|
124
155
|
|
|
156
|
+
-- la conversación es de la key que la empezó: por dentro el thread es "key:<id>:<thread>" y la app sigue viendo el
|
|
157
|
+
-- suyo (shown_thread). Antes, dos apps con el mismo thread compartían historial y lote: la de B corría con las
|
|
158
|
+
-- herramientas y el `from` de A (2026-10-19). Tampoco puede escribir en "team:…" u "objective:…".
|
|
159
|
+
export task space_of(rec)
|
|
160
|
+
give "key:" + text(rec["id"]) + ":"
|
|
161
|
+
|
|
162
|
+
task scope_sobre(sobre, rec)
|
|
163
|
+
set sobre["space"] to space_of(rec)
|
|
164
|
+
when sobre["thread"] != ""
|
|
165
|
+
set sobre["shown_thread"] to sobre["thread"]
|
|
166
|
+
set sobre["thread"] to space_of(rec) + sobre["thread"]
|
|
167
|
+
give sobre
|
|
168
|
+
|
|
125
169
|
-- el modo de un agente por la API: el suyo, y si no dice → strict (nadie en la request para preguntarle)
|
|
126
170
|
export task mode_for(spec)
|
|
127
171
|
give when spec != nothing and spec["permission"] != "" then "" otherwise "strict"
|
|
@@ -140,7 +184,7 @@ export task create_job(id, rec, sobre, callback)
|
|
|
140
184
|
require time
|
|
141
185
|
require file(".lampson")
|
|
142
186
|
require file(".lampson/*")
|
|
143
|
-
mailbox.save_job({"job": id, "status": "queued", "key": rec["id"], "agent": sobre["to"], "thread": sobre["thread"], "callback": callback, "created": format_time(now()), "result": nothing, "delivered": false, "merged_into": nothing})
|
|
187
|
+
mailbox.save_job({"job": id, "status": "queued", "key": rec["id"], "agent": sobre["to"], "thread": get(sobre, "shown_thread", sobre["thread"]), "callback": callback, "created": format_time(now()), "result": nothing, "delivered": false, "merged_into": nothing})
|
|
144
188
|
|
|
145
189
|
export task job(id)
|
|
146
190
|
require file.read(".lampson")
|
package/lib/apikeys.syn
CHANGED
|
@@ -6,11 +6,16 @@
|
|
|
6
6
|
--
|
|
7
7
|
-- create(name, agents) → {id, key, name, agents} agents: ["tienda"] o ["*"] (todos los elegibles)
|
|
8
8
|
-- create_with(name, agents, {rate, callbacks}) rate = pedidos/minuto (default 120; 0 = sin límite);
|
|
9
|
-
-- callbacks =
|
|
9
|
+
-- callbacks = URLs permitidas: mismo esquema, host y puerto, y
|
|
10
|
+
-- el path como prefijo ([] = cualquier host PÚBLICO)
|
|
11
|
+
-- → también {secret}: con él se firman SUS callbacks
|
|
12
|
+
-- signing_secret(id) → el secreto de esa key ("" en keys de antes de 2026-10-18: usan LAMPSON_WEBHOOK_SECRET)
|
|
10
13
|
-- check(key) → registro sin hash | nothing (y anota last_used)
|
|
11
14
|
-- allows(rec, agent) → bool
|
|
12
15
|
-- list() / remove(id)
|
|
13
16
|
|
|
17
|
+
use "./tools/url.syn" as urls
|
|
18
|
+
|
|
14
19
|
export let FILE be ".lampson/api_keys.json"
|
|
15
20
|
export let PREFIX be "lk_"
|
|
16
21
|
export let DEFAULT_RATE be 120
|
|
@@ -35,7 +40,7 @@ task store(keys_list)
|
|
|
35
40
|
write_file(FILE, json_encode({"keys": keys_list}))
|
|
36
41
|
|
|
37
42
|
task public(k)
|
|
38
|
-
give {"id": k["id"], "name": k["name"], "agents": k["agents"], "created": k["created"], "last_used": k["last_used"], "rate": when contains(k, "rate") then k["rate"] otherwise DEFAULT_RATE, "callbacks": when contains(k, "callbacks") then k["callbacks"] otherwise []}
|
|
43
|
+
give {"id": k["id"], "name": k["name"], "agents": k["agents"], "created": k["created"], "last_used": k["last_used"], "rate": when contains(k, "rate") then k["rate"] otherwise DEFAULT_RATE, "callbacks": when contains(k, "callbacks") then k["callbacks"] otherwise [], "own_secret": contains(k, "secret")}
|
|
39
44
|
|
|
40
45
|
export task create(name, agents)
|
|
41
46
|
require time
|
|
@@ -54,19 +59,47 @@ export task create_with(name, agents, opts)
|
|
|
54
59
|
let cbs be when contains(opts, "callbacks") and opts["callbacks"] != nothing then opts["callbacks"] otherwise []
|
|
55
60
|
let key be PREFIX + token(24)
|
|
56
61
|
let id be "k" + slice(token(16), 0, 8)
|
|
57
|
-
|
|
62
|
+
-- un secreto por key para firmar sus callbacks: con uno global, una app que comparte este Lampson podía firmar una
|
|
63
|
+
-- callback falsa hacia otra (2026-10-18). Se guarda en claro (hace falta para firmar), como el webhook global
|
|
64
|
+
let secret be "whsec_" + token(24)
|
|
65
|
+
let rec be {"id": id, "name": text(name), "agents": ag, "hash": hash_of(key), "created": format_time(now()), "last_used": nothing, "rate": rate, "callbacks": cbs, "secret": secret}
|
|
58
66
|
store(append(load(), rec))
|
|
59
|
-
give {"id": id, "key": key, "name": rec["name"], "agents": ag, "rate": rate, "callbacks": cbs}
|
|
67
|
+
give {"id": id, "key": key, "name": rec["name"], "agents": ag, "rate": rate, "callbacks": cbs, "secret": secret}
|
|
60
68
|
|
|
61
69
|
-- ¿esta key puede pedir un callback a esta URL? sin lista = cualquiera; con lista = solo esos prefijos
|
|
70
|
+
-- ¿esta key puede mandar una callback a `url`? Con lista: mismo esquema, host y puerto, y el path de la lista como
|
|
71
|
+
-- prefijo de carpeta ("https://app.com/hooks" deja /hooks y /hooks/x, no /hooks-x). Sin lista: ninguna, salvo en
|
|
72
|
+
-- las keys de antes del secreto por key, que llegan a un NOMBRE público
|
|
73
|
+
-- — nunca una IP escrita, loopback, red privada ni metadatos de la nube. (Un nombre que resuelve a 127.0.0.1 pasa:
|
|
74
|
+
-- el techo de red de Synsema 0.6.44 compara nombres, no la IP con la que conecta.) Antes (hasta 2026-10-18) era starts_with sobre la URL
|
|
75
|
+
-- entera: "https://app.com" dejaba pasar "https://app.com.evil.net", y sin lista, cualquier URL (SSRF).
|
|
62
76
|
export task callback_allowed(rec, url)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
let u be urls.parse(url)
|
|
78
|
+
when not u["ok"]
|
|
79
|
+
give false
|
|
80
|
+
let cbs be when contains(rec, "callbacks") then rec["callbacks"] otherwise []
|
|
81
|
+
when length(cbs) == 0
|
|
82
|
+
-- una key con secreto propio (creada desde 2026-10-19) sin lista no manda callbacks: "solo públicos" no se
|
|
83
|
+
-- puede prometer mientras el motor no mire la IP. Las de antes siguen como estaban, `key list` las marca
|
|
84
|
+
when get(rec, "own_secret", false) == true or contains(rec, "secret")
|
|
85
|
+
give false
|
|
86
|
+
give not urls.is_ip_literal(u["host"]) and urls.host_class(u["host"]) == "public"
|
|
87
|
+
each pre in cbs
|
|
88
|
+
let p be urls.parse(pre)
|
|
89
|
+
when p["ok"] and p["scheme"] == u["scheme"] and p["host"] == u["host"] and p["port"] == u["port"]
|
|
90
|
+
let base be p["path"]
|
|
91
|
+
while ends_with(base, "/")
|
|
92
|
+
set base to slice(base, 0, length(base) - 1)
|
|
93
|
+
when base == "" or u["path"] == base or starts_with(u["path"], base + "/")
|
|
94
|
+
give true
|
|
68
95
|
give false
|
|
69
96
|
|
|
97
|
+
export task signing_secret(id)
|
|
98
|
+
require file.read(".lampson")
|
|
99
|
+
require file.read(".lampson/*")
|
|
100
|
+
let f be where(load(), (k) => k["id"] == id)
|
|
101
|
+
give when length(f) > 0 and contains(f[0], "secret") then text(f[0]["secret"]) otherwise ""
|
|
102
|
+
|
|
70
103
|
export task list()
|
|
71
104
|
require file.read(".lampson")
|
|
72
105
|
require file.read(".lampson/*")
|