@palettelab/cli 0.3.62 → 0.3.63
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 +72 -3
- package/backend-sdk/palette_sdk/__init__.py +2 -0
- package/backend-sdk/palette_sdk/connections.py +49 -11
- package/backend-sdk/palette_sdk/connections_generated.py +246 -0
- package/backend-sdk/palette_sdk/manifest.py +15 -2
- package/backend-sdk/palette_sdk/platform_services.py +122 -0
- package/backend-sdk/palette_sdk/plugin_context.py +14 -0
- package/backend-sdk/palette_sdk/talk.py +65 -0
- package/backend-sdk/pyproject.toml +1 -1
- package/docs/python-backend-sdk.md +64 -1
- package/lib/bundler.js +64 -0
- package/lib/cli.js +13 -1
- package/lib/commands/connections.js +234 -0
- package/lib/commands/dev.js +75 -1
- package/lib/commands/doctor.js +70 -0
- package/lib/commands/open.js +43 -0
- package/lib/connection-catalog.json +1185 -0
- package/lib/dev-simulator.js +137 -3
- package/lib/manifest.js +16 -4
- package/package.json +1 -1
package/lib/dev-simulator.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
+
const crypto = require("crypto")
|
|
3
4
|
const fs = require("fs")
|
|
4
5
|
const http = require("http")
|
|
5
6
|
const path = require("path")
|
|
@@ -215,6 +216,15 @@ sys.path.insert(0, str(ENTRY.parent))
|
|
|
215
216
|
DEV_REDIS = None
|
|
216
217
|
DEV_VECTOR = None
|
|
217
218
|
DEV_STORAGE = None
|
|
219
|
+
DEV_LLM = None
|
|
220
|
+
DEV_WEB = None
|
|
221
|
+
if _service_enabled("llm"):
|
|
222
|
+
from palette_sdk.platform_services import LocalLLMService
|
|
223
|
+
DEV_LLM = LocalLLMService(DEV_SECRETS.get("OPENAI_API_KEY") or os.environ.get("OPENAI_API_KEY", ""))
|
|
224
|
+
print(f"[pltt] ctx.llm: {'live (your OPENAI_API_KEY)' if DEV_LLM.live else 'stubbed (no OPENAI_API_KEY)'}")
|
|
225
|
+
if _service_enabled("web"):
|
|
226
|
+
from palette_sdk.platform_services import LocalWebService
|
|
227
|
+
DEV_WEB = LocalWebService()
|
|
218
228
|
if _service_enabled("redis"):
|
|
219
229
|
from palette_sdk.platform_services import LocalRedisService
|
|
220
230
|
DEV_REDIS = LocalRedisService()
|
|
@@ -360,7 +370,37 @@ class LocalNotificationsService:
|
|
|
360
370
|
print("[palette-notification]", json.dumps(notification, sort_keys=True))
|
|
361
371
|
return notification
|
|
362
372
|
|
|
373
|
+
class LocalTalkService:
|
|
374
|
+
"""Local stand-in for Talk: logs the post instead of putting it in a room.
|
|
375
|
+
|
|
376
|
+
One fake seat is reported, so a loop over ctx.talk.channels() runs locally
|
|
377
|
+
the way it will once a member invites the app to a channel.
|
|
378
|
+
"""
|
|
379
|
+
|
|
380
|
+
def __init__(self):
|
|
381
|
+
self._next_id = 1
|
|
382
|
+
|
|
383
|
+
async def channels(self):
|
|
384
|
+
return [{"id": "dev-channel", "name": "general", "type": "stream"}]
|
|
385
|
+
|
|
386
|
+
async def post(self, *, text, channel):
|
|
387
|
+
content = (text or "").strip()
|
|
388
|
+
if not content:
|
|
389
|
+
raise ValueError("text is required")
|
|
390
|
+
message = {
|
|
391
|
+
"id": f"dev-message-{self._next_id}",
|
|
392
|
+
"channel_id": str(channel),
|
|
393
|
+
"content": content,
|
|
394
|
+
"message_type": "text",
|
|
395
|
+
"sender": {"kind": "agent", "name": MANIFEST.get("name") or MANIFEST.get("id", "")},
|
|
396
|
+
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
397
|
+
}
|
|
398
|
+
self._next_id += 1
|
|
399
|
+
print("[palette-talk]", json.dumps(message, sort_keys=True))
|
|
400
|
+
return message
|
|
401
|
+
|
|
363
402
|
NOTIFICATIONS = LocalNotificationsService()
|
|
403
|
+
TALK = LocalTalkService()
|
|
364
404
|
|
|
365
405
|
spec = importlib.util.spec_from_file_location("palette_local_backend", ENTRY)
|
|
366
406
|
module = importlib.util.module_from_spec(spec)
|
|
@@ -484,6 +524,14 @@ def _local_job_context(session):
|
|
|
484
524
|
from palette_sdk.organization import OrganizationInfo
|
|
485
525
|
from palette_sdk.platform_services import UnavailablePlatformService
|
|
486
526
|
|
|
527
|
+
# ctx.talk arrived after this simulator shipped its first job context, so a
|
|
528
|
+
# backend pinned to an older palette_sdk keeps working without it.
|
|
529
|
+
extra = {}
|
|
530
|
+
if "talk" in getattr(PluginContext, "__dataclass_fields__", {}):
|
|
531
|
+
from palette_sdk.talk import TalkClient
|
|
532
|
+
|
|
533
|
+
extra["talk"] = TalkClient(TALK, MANIFEST.get("permissions", []))
|
|
534
|
+
|
|
487
535
|
return PluginContext(
|
|
488
536
|
db=session,
|
|
489
537
|
user_id="dev-user",
|
|
@@ -498,6 +546,8 @@ def _local_job_context(session):
|
|
|
498
546
|
notifications=NotificationsClient(NOTIFICATIONS),
|
|
499
547
|
redis=DEV_REDIS or UnavailablePlatformService("redis"),
|
|
500
548
|
vector=DEV_VECTOR or UnavailablePlatformService("vector"),
|
|
549
|
+
llm=DEV_LLM or UnavailablePlatformService("llm"),
|
|
550
|
+
web=DEV_WEB or UnavailablePlatformService("web"),
|
|
501
551
|
events=EventPublisher(LocalEventPublisher()),
|
|
502
552
|
jobs=JobsClient(LOCAL_JOB_SERVICE),
|
|
503
553
|
config={
|
|
@@ -505,6 +555,7 @@ def _local_job_context(session):
|
|
|
505
555
|
"secret_specs": MANIFEST.get("secrets") or {},
|
|
506
556
|
"secret_scope": "dev",
|
|
507
557
|
},
|
|
558
|
+
**extra,
|
|
508
559
|
)
|
|
509
560
|
|
|
510
561
|
async def _run_local_job(record, declaration):
|
|
@@ -577,11 +628,14 @@ class DevPluginContextMiddleware(BaseHTTPMiddleware):
|
|
|
577
628
|
"secret_specs": MANIFEST.get("secrets") or {},
|
|
578
629
|
"secret_scope": "dev",
|
|
579
630
|
}
|
|
631
|
+
request.state.llm = DEV_LLM
|
|
632
|
+
request.state.web = DEV_WEB
|
|
580
633
|
request.state.plugin_local_connections = DEV_CONNECTIONS
|
|
581
634
|
request.state.plugin_apps = LocalAppInteropService()
|
|
582
635
|
request.state.plugin_events = LocalEventPublisher()
|
|
583
636
|
request.state.plugin_jobs = LOCAL_JOB_SERVICE
|
|
584
637
|
request.state.notifications = NOTIFICATIONS
|
|
638
|
+
request.state.talk = TALK
|
|
585
639
|
request.state.storage = DEV_STORAGE
|
|
586
640
|
if DEV_REDIS is not None:
|
|
587
641
|
request.state.redis = DEV_REDIS
|
|
@@ -945,7 +999,7 @@ createRoot(document.getElementById("root")).render(React.createElement(Shell))
|
|
|
945
999
|
`
|
|
946
1000
|
}
|
|
947
1001
|
|
|
948
|
-
function indexHtml(manifest) {
|
|
1002
|
+
function indexHtml(manifest, buildState) {
|
|
949
1003
|
return `<!doctype html>
|
|
950
1004
|
<html lang="en">
|
|
951
1005
|
<head>
|
|
@@ -964,6 +1018,46 @@ function indexHtml(manifest) {
|
|
|
964
1018
|
<body>
|
|
965
1019
|
<div id="root"></div>
|
|
966
1020
|
<script type="module" src="/simulator.js"></script>
|
|
1021
|
+
<script type="module">
|
|
1022
|
+
const loaded = { js: ${JSON.stringify(buildState.jsHash)}, css: ${JSON.stringify(buildState.cssHash)} }
|
|
1023
|
+
const OVERLAY_ID = "__pltt-error-overlay"
|
|
1024
|
+
function showOverlay(errors) {
|
|
1025
|
+
let el = document.getElementById(OVERLAY_ID)
|
|
1026
|
+
if (!el) {
|
|
1027
|
+
el = document.createElement("div")
|
|
1028
|
+
el.id = OVERLAY_ID
|
|
1029
|
+
el.style.cssText = "position:fixed;inset:0;z-index:2147483647;background:rgba(20,18,16,.96);color:#ffb4a2;overflow:auto;padding:32px;font:13px/1.6 ui-monospace,SFMono-Regular,Menlo,monospace"
|
|
1030
|
+
document.body.appendChild(el)
|
|
1031
|
+
}
|
|
1032
|
+
el.innerHTML = ""
|
|
1033
|
+
const title = document.createElement("div")
|
|
1034
|
+
title.textContent = "[pltt] build failed"
|
|
1035
|
+
title.style.cssText = "color:#fff;font-weight:600;margin-bottom:16px"
|
|
1036
|
+
el.appendChild(title)
|
|
1037
|
+
for (const err of errors) {
|
|
1038
|
+
const pre = document.createElement("pre")
|
|
1039
|
+
pre.style.cssText = "white-space:pre-wrap;margin:0 0 12px"
|
|
1040
|
+
pre.textContent = (err.file ? err.file + ":" + (err.line || "?") + " — " : "") + err.text
|
|
1041
|
+
el.appendChild(pre)
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
function clearOverlay() {
|
|
1045
|
+
const el = document.getElementById(OVERLAY_ID)
|
|
1046
|
+
if (el) el.remove()
|
|
1047
|
+
}
|
|
1048
|
+
const events = new EventSource("/__pltt/events")
|
|
1049
|
+
events.addEventListener("build", (evt) => {
|
|
1050
|
+
const state = JSON.parse(evt.data)
|
|
1051
|
+
if (!state.ok) { showOverlay(state.errors || []); return }
|
|
1052
|
+
clearOverlay()
|
|
1053
|
+
if (state.jsHash && state.jsHash !== loaded.js) { location.reload(); return }
|
|
1054
|
+
if (state.cssHash !== loaded.css) {
|
|
1055
|
+
loaded.css = state.cssHash
|
|
1056
|
+
const link = document.querySelector('link[rel="stylesheet"][href^="/simulator.css"]')
|
|
1057
|
+
if (link) link.href = "/simulator.css?t=" + Date.now()
|
|
1058
|
+
}
|
|
1059
|
+
})
|
|
1060
|
+
</script>
|
|
967
1061
|
</body>
|
|
968
1062
|
</html>`
|
|
969
1063
|
}
|
|
@@ -991,6 +1085,21 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
|
|
|
991
1085
|
fs.writeFileSync(generatedEntry, simulatorEntrySource(cwd, absEntry, manifest, backendPort))
|
|
992
1086
|
const buildConfig = frontendBuildConfig(cwd, { ...(manifest.frontend || {}), entry })
|
|
993
1087
|
|
|
1088
|
+
const sseClients = new Set()
|
|
1089
|
+
const fileHash = (file) =>
|
|
1090
|
+
fs.existsSync(file) ? crypto.createHash("sha1").update(fs.readFileSync(file)).digest("hex") : ""
|
|
1091
|
+
const buildState = { ok: true, errors: [], jsHash: "", cssHash: "" }
|
|
1092
|
+
const broadcastBuild = () => {
|
|
1093
|
+
const payload = `event: build\ndata: ${JSON.stringify(buildState)}\n\n`
|
|
1094
|
+
for (const client of sseClients) {
|
|
1095
|
+
try {
|
|
1096
|
+
client.write(payload)
|
|
1097
|
+
} catch (_err) {
|
|
1098
|
+
sseClients.delete(client)
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
994
1103
|
const esbuild = loadEsbuild()
|
|
995
1104
|
const ctx = await esbuild.context({
|
|
996
1105
|
entryPoints: [generatedEntry],
|
|
@@ -1015,10 +1124,22 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
|
|
|
1015
1124
|
if (result.errors.length) {
|
|
1016
1125
|
console.error("[pltt] simulator bundle failed:")
|
|
1017
1126
|
for (const err of result.errors) console.error(` - ${err.text}`)
|
|
1127
|
+
buildState.ok = false
|
|
1128
|
+
buildState.errors = result.errors.map((err) => ({
|
|
1129
|
+
text: err.text,
|
|
1130
|
+
file: err.location?.file,
|
|
1131
|
+
line: err.location?.line,
|
|
1132
|
+
}))
|
|
1133
|
+
broadcastBuild()
|
|
1018
1134
|
return
|
|
1019
1135
|
}
|
|
1020
1136
|
const size = fs.existsSync(bundlePath) ? fs.statSync(bundlePath).size : 0
|
|
1021
1137
|
console.log(`[pltt] simulator bundle ready (${size} bytes)`)
|
|
1138
|
+
buildState.ok = true
|
|
1139
|
+
buildState.errors = []
|
|
1140
|
+
buildState.jsHash = fileHash(bundlePath)
|
|
1141
|
+
buildState.cssHash = fileHash(cssPath)
|
|
1142
|
+
broadcastBuild()
|
|
1022
1143
|
})
|
|
1023
1144
|
},
|
|
1024
1145
|
},
|
|
@@ -1029,6 +1150,18 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
|
|
|
1029
1150
|
|
|
1030
1151
|
const server = http.createServer((req, res) => {
|
|
1031
1152
|
const url = new URL(req.url || "/", `http://127.0.0.1:${frontendPort}`)
|
|
1153
|
+
if (url.pathname === "/__pltt/events") {
|
|
1154
|
+
res.writeHead(200, {
|
|
1155
|
+
"Content-Type": "text/event-stream",
|
|
1156
|
+
"Cache-Control": "no-store",
|
|
1157
|
+
Connection: "keep-alive",
|
|
1158
|
+
})
|
|
1159
|
+
res.write("retry: 1000\n\n")
|
|
1160
|
+
res.write(`event: build\ndata: ${JSON.stringify(buildState)}\n\n`)
|
|
1161
|
+
sseClients.add(res)
|
|
1162
|
+
req.on("close", () => sseClients.delete(res))
|
|
1163
|
+
return
|
|
1164
|
+
}
|
|
1032
1165
|
if (url.pathname === "/simulator.js") {
|
|
1033
1166
|
console.log(`[pltt] frontend GET ${url.pathname} -> 200`)
|
|
1034
1167
|
res.writeHead(200, { "Content-Type": "text/javascript; charset=utf-8", "Cache-Control": "no-store" })
|
|
@@ -1048,11 +1181,11 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
|
|
|
1048
1181
|
}
|
|
1049
1182
|
console.log(`[pltt] frontend GET ${url.pathname} -> 200`)
|
|
1050
1183
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" })
|
|
1051
|
-
res.end(indexHtml(manifest))
|
|
1184
|
+
res.end(indexHtml(manifest, buildState))
|
|
1052
1185
|
})
|
|
1053
1186
|
|
|
1054
1187
|
await new Promise((resolve) => server.listen(frontendPort, "127.0.0.1", resolve))
|
|
1055
|
-
return { server, ctx }
|
|
1188
|
+
return { server, ctx, sseClients }
|
|
1056
1189
|
}
|
|
1057
1190
|
|
|
1058
1191
|
async function startSimulator({ cwd, frontendPort, backendPort }) {
|
|
@@ -1070,6 +1203,7 @@ async function startSimulator({ cwd, frontendPort, backendPort }) {
|
|
|
1070
1203
|
console.log("[pltt] use `pltt dev --platform` for full Docker platform parity")
|
|
1071
1204
|
|
|
1072
1205
|
const stop = async () => {
|
|
1206
|
+
for (const client of frontend.sseClients) client.end()
|
|
1073
1207
|
frontend.server.close()
|
|
1074
1208
|
await frontend.ctx.dispose()
|
|
1075
1209
|
if (backend && !backend.killed) backend.kill("SIGTERM")
|
package/lib/manifest.js
CHANGED
|
@@ -216,7 +216,7 @@ function validateSecrets(value, errors) {
|
|
|
216
216
|
|
|
217
217
|
function validatePlatformServices(value, errors) {
|
|
218
218
|
if (value === undefined) return
|
|
219
|
-
const known = new Set(["llm", "redis", "storage", "vector"])
|
|
219
|
+
const known = new Set(["llm", "redis", "storage", "vector", "web"])
|
|
220
220
|
if (Array.isArray(value)) {
|
|
221
221
|
for (const service of value) {
|
|
222
222
|
if (!known.has(service)) errors.push(`platform_services contains unknown service: ${service}`)
|
|
@@ -242,10 +242,13 @@ function validatePlatformServices(value, errors) {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
// Providers with a live OS service connection — declaring one lets the app call
|
|
246
|
+
// ctx.connections.* against the user's existing connection, no OAuth of its own.
|
|
247
|
+
const LIVE_CONNECTION_PROVIDERS = new Set(["google", "slack", "notion", "telegram", "meta"])
|
|
248
|
+
// Legacy slugs still validate so published manifests keep working, but dispatch nothing.
|
|
245
249
|
const CONNECTION_PROVIDERS = new Set([
|
|
246
|
-
|
|
250
|
+
...LIVE_CONNECTION_PROVIDERS,
|
|
247
251
|
"instagram",
|
|
248
|
-
"slack",
|
|
249
252
|
"linear",
|
|
250
253
|
"hubspot",
|
|
251
254
|
"stripe",
|
|
@@ -260,13 +263,14 @@ function validateConnections(value, errors) {
|
|
|
260
263
|
return
|
|
261
264
|
}
|
|
262
265
|
const seen = new Set()
|
|
266
|
+
const seenProviders = new Set()
|
|
263
267
|
value.forEach((conn, i) => {
|
|
264
268
|
const label = `connections[${i}]`
|
|
265
269
|
if (!isObject(conn)) {
|
|
266
270
|
errors.push(`${label} must be an object`)
|
|
267
271
|
return
|
|
268
272
|
}
|
|
269
|
-
unknownKeys(conn, new Set(["id", "provider", "label", "auth", "scopes", "required"]), label, errors)
|
|
273
|
+
unknownKeys(conn, new Set(["id", "provider", "label", "auth", "scopes", "required", "tools"]), label, errors)
|
|
270
274
|
if (!conn.id || typeof conn.id !== "string" || !/^[a-z0-9][a-z0-9_-]*[a-z0-9]$/.test(conn.id)) {
|
|
271
275
|
errors.push(`${label}.id must be lowercase snake/kebab case`)
|
|
272
276
|
} else if (seen.has(conn.id)) {
|
|
@@ -275,6 +279,14 @@ function validateConnections(value, errors) {
|
|
|
275
279
|
seen.add(conn.id)
|
|
276
280
|
if (!conn.provider || typeof conn.provider !== "string" || !CONNECTION_PROVIDERS.has(conn.provider)) {
|
|
277
281
|
errors.push(`${label}.provider must be one of ${Array.from(CONNECTION_PROVIDERS).join(", ")}`)
|
|
282
|
+
} else if (LIVE_CONNECTION_PROVIDERS.has(conn.provider)) {
|
|
283
|
+
// ctx.connections resolves a grant by provider, so two entries on the
|
|
284
|
+
// same provider would be ambiguous at call time.
|
|
285
|
+
if (seenProviders.has(conn.provider)) errors.push(`duplicate connection provider: ${conn.provider}`)
|
|
286
|
+
seenProviders.add(conn.provider)
|
|
287
|
+
}
|
|
288
|
+
if (conn.tools !== undefined && !Array.isArray(conn.tools)) {
|
|
289
|
+
errors.push(`${label}.tools must be an array`)
|
|
278
290
|
}
|
|
279
291
|
if (!conn.label || typeof conn.label !== "string") errors.push(`${label}.label is required`)
|
|
280
292
|
if (conn.auth !== undefined && conn.auth !== "oauth2" && conn.auth !== "api_key") {
|