@palettelab/cli 0.3.62 → 0.3.65
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 +185 -9
- package/backend-sdk/palette_sdk/__init__.py +13 -1
- package/backend-sdk/palette_sdk/connections.py +49 -11
- package/backend-sdk/palette_sdk/connections_generated.py +246 -0
- package/backend-sdk/palette_sdk/data_rooms.py +2 -2
- package/backend-sdk/palette_sdk/db/base.py +4 -1
- package/backend-sdk/palette_sdk/db/rls.py +7 -1
- package/backend-sdk/palette_sdk/manifest.py +16 -2
- package/backend-sdk/palette_sdk/platform_services.py +400 -0
- package/backend-sdk/palette_sdk/plugin_context.py +41 -2
- package/backend-sdk/palette_sdk/plugin_router.py +64 -8
- package/backend-sdk/palette_sdk/repository.py +12 -3
- package/backend-sdk/palette_sdk/talk.py +65 -0
- package/backend-sdk/palette_sdk/tasks.py +117 -0
- package/backend-sdk/pyproject.toml +1 -1
- package/docs/python-backend-sdk.md +196 -9
- package/lib/bundler.js +64 -0
- package/lib/cli.js +25 -3
- package/lib/commands/capabilities.js +1 -1
- package/lib/commands/connections.js +234 -0
- package/lib/commands/dev.js +75 -1
- package/lib/commands/doctor.js +85 -0
- package/lib/commands/open.js +43 -0
- package/lib/commands/platform.js +137 -0
- package/lib/commands/test.js +47 -4
- package/lib/connection-catalog.json +1185 -0
- package/lib/dev-simulator.js +232 -3
- package/lib/manifest.js +115 -5
- package/package.json +1 -1
- package/template-fallback/README.md +9 -0
- package/template-fallback/frontend/src/translations.ts +2 -2
- package/template-fallback/package.json +1 -1
- package/template-fallback/palette-plugin.json +1 -0
- package/template-fallback/templates/agent-tool/palette-plugin.json +1 -0
- package/template-fallback/templates/consumer-app/package.json +1 -1
- package/template-fallback/templates/consumer-app/palette-plugin.json +1 -0
- package/template-fallback/templates/dashboard/package.json +1 -1
- package/template-fallback/templates/dashboard/palette-plugin.json +1 -0
- package/template-fallback/templates/database/package.json +1 -1
- package/template-fallback/templates/database/palette-plugin.json +1 -0
- package/template-fallback/templates/external-service/package.json +1 -1
- package/template-fallback/templates/external-service/palette-plugin.json +1 -0
- package/template-fallback/templates/frontend-only/package.json +1 -1
- package/template-fallback/templates/frontend-only/palette-plugin.json +1 -0
- package/template-fallback/templates/next/package.json +1 -1
- package/template-fallback/templates/next/palette-plugin.json +1 -0
- package/template-fallback/templates/palette-app/package.json +1 -1
- package/template-fallback/templates/palette-app/palette-plugin.json +1 -0
- package/template-fallback/templates/provider-app/package.json +1 -1
- package/template-fallback/templates/provider-app/palette-plugin.json +1 -0
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")
|
|
@@ -161,6 +162,9 @@ function ensurePythonEnv(cwd, devDir, manifest) {
|
|
|
161
162
|
return venvPython
|
|
162
163
|
}
|
|
163
164
|
|
|
165
|
+
// The Python below is a JS template literal: a backtick or a bare ${ inside it
|
|
166
|
+
// terminates the string and the whole CLI stops loading. Keep docstrings
|
|
167
|
+
// backtick-free.
|
|
164
168
|
function writeBackendRunner(cwd, devDir, manifest, backendEntry, backendPort) {
|
|
165
169
|
const runner = path.join(devDir, "backend_runner.py")
|
|
166
170
|
const sdkPath = localBackendSdkPath()
|
|
@@ -215,6 +219,16 @@ sys.path.insert(0, str(ENTRY.parent))
|
|
|
215
219
|
DEV_REDIS = None
|
|
216
220
|
DEV_VECTOR = None
|
|
217
221
|
DEV_STORAGE = None
|
|
222
|
+
DEV_LLM = None
|
|
223
|
+
DEV_WEB = None
|
|
224
|
+
DEV_MEDIA = None
|
|
225
|
+
if _service_enabled("llm"):
|
|
226
|
+
from palette_sdk.platform_services import LocalLLMService
|
|
227
|
+
DEV_LLM = LocalLLMService(DEV_SECRETS.get("OPENAI_API_KEY") or os.environ.get("OPENAI_API_KEY", ""))
|
|
228
|
+
print(f"[pltt] ctx.llm: {'live (your OPENAI_API_KEY)' if DEV_LLM.live else 'stubbed (no OPENAI_API_KEY)'}")
|
|
229
|
+
if _service_enabled("web"):
|
|
230
|
+
from palette_sdk.platform_services import LocalWebService
|
|
231
|
+
DEV_WEB = LocalWebService()
|
|
218
232
|
if _service_enabled("redis"):
|
|
219
233
|
from palette_sdk.platform_services import LocalRedisService
|
|
220
234
|
DEV_REDIS = LocalRedisService()
|
|
@@ -232,6 +246,11 @@ if _service_enabled("storage"):
|
|
|
232
246
|
organization_name="Palette Dev",
|
|
233
247
|
)
|
|
234
248
|
|
|
249
|
+
if _service_enabled("media"):
|
|
250
|
+
from palette_sdk.platform_services import LocalMediaService
|
|
251
|
+
DEV_MEDIA = LocalMediaService(DEV_SECRETS.get("FAL_KEY") or os.environ.get("FAL_KEY", ""), DEV_STORAGE)
|
|
252
|
+
print(f"[pltt] ctx.media: {'live (your FAL_KEY)' if DEV_MEDIA.live else 'stubbed (no FAL_KEY)'}")
|
|
253
|
+
|
|
235
254
|
DEV_ORGANIZATION = {
|
|
236
255
|
"id": 1,
|
|
237
256
|
"name": "Palette Dev",
|
|
@@ -360,7 +379,115 @@ class LocalNotificationsService:
|
|
|
360
379
|
print("[palette-notification]", json.dumps(notification, sort_keys=True))
|
|
361
380
|
return notification
|
|
362
381
|
|
|
382
|
+
class LocalTalkService:
|
|
383
|
+
"""Local stand-in for Talk: logs the post instead of putting it in a room.
|
|
384
|
+
|
|
385
|
+
One fake seat is reported, so a loop over ctx.talk.channels() runs locally
|
|
386
|
+
the way it will once a member invites the app to a channel.
|
|
387
|
+
"""
|
|
388
|
+
|
|
389
|
+
def __init__(self):
|
|
390
|
+
self._next_id = 1
|
|
391
|
+
|
|
392
|
+
async def channels(self):
|
|
393
|
+
return [{"id": "dev-channel", "name": "general", "type": "stream"}]
|
|
394
|
+
|
|
395
|
+
async def post(self, *, text, channel):
|
|
396
|
+
content = (text or "").strip()
|
|
397
|
+
if not content:
|
|
398
|
+
raise ValueError("text is required")
|
|
399
|
+
message = {
|
|
400
|
+
"id": f"dev-message-{self._next_id}",
|
|
401
|
+
"channel_id": str(channel),
|
|
402
|
+
"content": content,
|
|
403
|
+
"message_type": "text",
|
|
404
|
+
"sender": {"kind": "agent", "name": MANIFEST.get("name") or MANIFEST.get("id", "")},
|
|
405
|
+
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
406
|
+
}
|
|
407
|
+
self._next_id += 1
|
|
408
|
+
print("[palette-talk]", json.dumps(message, sort_keys=True))
|
|
409
|
+
return message
|
|
410
|
+
|
|
411
|
+
class LocalTasksService:
|
|
412
|
+
"""Local stand-in for the task board: an in-memory list that behaves like
|
|
413
|
+
the hosted one, including the app scoping (an app sees only its own rows).
|
|
414
|
+
|
|
415
|
+
Rows live for the life of the pltt dev process — enough to exercise
|
|
416
|
+
create -> list -> complete without a platform.
|
|
417
|
+
"""
|
|
418
|
+
|
|
419
|
+
def __init__(self):
|
|
420
|
+
self._rows = {}
|
|
421
|
+
self._next_id = 1
|
|
422
|
+
|
|
423
|
+
RESERVED = {"app_id", "source", "source_channel", "source_client", "external_ref", "routine_id"}
|
|
424
|
+
|
|
425
|
+
def _clean(self, fields):
|
|
426
|
+
rejected = sorted(self.RESERVED & set(fields))
|
|
427
|
+
if rejected:
|
|
428
|
+
raise HTTPException(
|
|
429
|
+
status_code=422,
|
|
430
|
+
detail="ctx.tasks sets " + ", ".join(rejected) + " itself — remove it from the call",
|
|
431
|
+
)
|
|
432
|
+
return fields
|
|
433
|
+
|
|
434
|
+
async def create(self, *, title, **fields):
|
|
435
|
+
if not str(title or "").strip():
|
|
436
|
+
raise HTTPException(status_code=422, detail="title is required")
|
|
437
|
+
now = datetime.now(timezone.utc).isoformat()
|
|
438
|
+
row = {
|
|
439
|
+
"id": self._next_id,
|
|
440
|
+
"title": str(title),
|
|
441
|
+
"description": "",
|
|
442
|
+
"output": None,
|
|
443
|
+
"status": "pending",
|
|
444
|
+
"priority": "medium",
|
|
445
|
+
"task_type": "manual",
|
|
446
|
+
"progress": 0,
|
|
447
|
+
"tags": [],
|
|
448
|
+
"due_date": None,
|
|
449
|
+
"agent_id": None,
|
|
450
|
+
"parent_task_id": None,
|
|
451
|
+
"team_id": None,
|
|
452
|
+
"app_id": MANIFEST.get("id", ""),
|
|
453
|
+
"source": "app",
|
|
454
|
+
"created_at": now,
|
|
455
|
+
"updated_at": now,
|
|
456
|
+
"completed_at": None,
|
|
457
|
+
"started_at": None,
|
|
458
|
+
}
|
|
459
|
+
row.update(self._clean(fields))
|
|
460
|
+
self._rows[self._next_id] = row
|
|
461
|
+
self._next_id += 1
|
|
462
|
+
print("[palette-tasks] created", json.dumps(row, sort_keys=True, default=str))
|
|
463
|
+
return dict(row)
|
|
464
|
+
|
|
465
|
+
async def list(self, *, status=None, limit=50):
|
|
466
|
+
rows = [r for r in self._rows.values() if status is None or r["status"] == status]
|
|
467
|
+
rows.sort(key=lambda r: r["id"], reverse=True)
|
|
468
|
+
return [dict(r) for r in rows[: max(1, int(limit))]]
|
|
469
|
+
|
|
470
|
+
async def get(self, task_id):
|
|
471
|
+
row = self._rows.get(int(task_id))
|
|
472
|
+
return dict(row) if row else None
|
|
473
|
+
|
|
474
|
+
async def update(self, task_id, **fields):
|
|
475
|
+
row = self._rows.get(int(task_id))
|
|
476
|
+
if row is None:
|
|
477
|
+
raise HTTPException(status_code=404, detail="Task not found")
|
|
478
|
+
row.update(self._clean(fields))
|
|
479
|
+
row["updated_at"] = datetime.now(timezone.utc).isoformat()
|
|
480
|
+
if row["status"] == "completed":
|
|
481
|
+
row["completed_at"] = row["completed_at"] or row["updated_at"]
|
|
482
|
+
row["progress"] = max(int(row.get("progress") or 0), 100)
|
|
483
|
+
return dict(row)
|
|
484
|
+
|
|
485
|
+
async def delete(self, task_id):
|
|
486
|
+
self._rows.pop(int(task_id), None)
|
|
487
|
+
|
|
363
488
|
NOTIFICATIONS = LocalNotificationsService()
|
|
489
|
+
TALK = LocalTalkService()
|
|
490
|
+
TASKS = LocalTasksService()
|
|
364
491
|
|
|
365
492
|
spec = importlib.util.spec_from_file_location("palette_local_backend", ENTRY)
|
|
366
493
|
module = importlib.util.module_from_spec(spec)
|
|
@@ -484,6 +611,20 @@ def _local_job_context(session):
|
|
|
484
611
|
from palette_sdk.organization import OrganizationInfo
|
|
485
612
|
from palette_sdk.platform_services import UnavailablePlatformService
|
|
486
613
|
|
|
614
|
+
# ctx.talk arrived after this simulator shipped its first job context, so a
|
|
615
|
+
# backend pinned to an older palette_sdk keeps working without it.
|
|
616
|
+
extra = {}
|
|
617
|
+
if "talk" in getattr(PluginContext, "__dataclass_fields__", {}):
|
|
618
|
+
from palette_sdk.talk import TalkClient
|
|
619
|
+
|
|
620
|
+
extra["talk"] = TalkClient(TALK, MANIFEST.get("permissions", []))
|
|
621
|
+
if "media" in getattr(PluginContext, "__dataclass_fields__", {}):
|
|
622
|
+
extra["media"] = DEV_MEDIA or UnavailablePlatformService("media")
|
|
623
|
+
if "tasks" in getattr(PluginContext, "__dataclass_fields__", {}):
|
|
624
|
+
from palette_sdk.tasks import TasksClient
|
|
625
|
+
|
|
626
|
+
extra["tasks"] = TasksClient(TASKS, MANIFEST.get("permissions", []))
|
|
627
|
+
|
|
487
628
|
return PluginContext(
|
|
488
629
|
db=session,
|
|
489
630
|
user_id="dev-user",
|
|
@@ -498,6 +639,8 @@ def _local_job_context(session):
|
|
|
498
639
|
notifications=NotificationsClient(NOTIFICATIONS),
|
|
499
640
|
redis=DEV_REDIS or UnavailablePlatformService("redis"),
|
|
500
641
|
vector=DEV_VECTOR or UnavailablePlatformService("vector"),
|
|
642
|
+
llm=DEV_LLM or UnavailablePlatformService("llm"),
|
|
643
|
+
web=DEV_WEB or UnavailablePlatformService("web"),
|
|
501
644
|
events=EventPublisher(LocalEventPublisher()),
|
|
502
645
|
jobs=JobsClient(LOCAL_JOB_SERVICE),
|
|
503
646
|
config={
|
|
@@ -505,6 +648,7 @@ def _local_job_context(session):
|
|
|
505
648
|
"secret_specs": MANIFEST.get("secrets") or {},
|
|
506
649
|
"secret_scope": "dev",
|
|
507
650
|
},
|
|
651
|
+
**extra,
|
|
508
652
|
)
|
|
509
653
|
|
|
510
654
|
async def _run_local_job(record, declaration):
|
|
@@ -577,11 +721,16 @@ class DevPluginContextMiddleware(BaseHTTPMiddleware):
|
|
|
577
721
|
"secret_specs": MANIFEST.get("secrets") or {},
|
|
578
722
|
"secret_scope": "dev",
|
|
579
723
|
}
|
|
724
|
+
request.state.llm = DEV_LLM
|
|
725
|
+
request.state.web = DEV_WEB
|
|
726
|
+
request.state.media = DEV_MEDIA
|
|
580
727
|
request.state.plugin_local_connections = DEV_CONNECTIONS
|
|
581
728
|
request.state.plugin_apps = LocalAppInteropService()
|
|
582
729
|
request.state.plugin_events = LocalEventPublisher()
|
|
583
730
|
request.state.plugin_jobs = LOCAL_JOB_SERVICE
|
|
584
731
|
request.state.notifications = NOTIFICATIONS
|
|
732
|
+
request.state.talk = TALK
|
|
733
|
+
request.state.tasks = TASKS
|
|
585
734
|
request.state.storage = DEV_STORAGE
|
|
586
735
|
if DEV_REDIS is not None:
|
|
587
736
|
request.state.redis = DEV_REDIS
|
|
@@ -945,7 +1094,7 @@ createRoot(document.getElementById("root")).render(React.createElement(Shell))
|
|
|
945
1094
|
`
|
|
946
1095
|
}
|
|
947
1096
|
|
|
948
|
-
function indexHtml(manifest) {
|
|
1097
|
+
function indexHtml(manifest, buildState) {
|
|
949
1098
|
return `<!doctype html>
|
|
950
1099
|
<html lang="en">
|
|
951
1100
|
<head>
|
|
@@ -964,6 +1113,46 @@ function indexHtml(manifest) {
|
|
|
964
1113
|
<body>
|
|
965
1114
|
<div id="root"></div>
|
|
966
1115
|
<script type="module" src="/simulator.js"></script>
|
|
1116
|
+
<script type="module">
|
|
1117
|
+
const loaded = { js: ${JSON.stringify(buildState.jsHash)}, css: ${JSON.stringify(buildState.cssHash)} }
|
|
1118
|
+
const OVERLAY_ID = "__pltt-error-overlay"
|
|
1119
|
+
function showOverlay(errors) {
|
|
1120
|
+
let el = document.getElementById(OVERLAY_ID)
|
|
1121
|
+
if (!el) {
|
|
1122
|
+
el = document.createElement("div")
|
|
1123
|
+
el.id = OVERLAY_ID
|
|
1124
|
+
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"
|
|
1125
|
+
document.body.appendChild(el)
|
|
1126
|
+
}
|
|
1127
|
+
el.innerHTML = ""
|
|
1128
|
+
const title = document.createElement("div")
|
|
1129
|
+
title.textContent = "[pltt] build failed"
|
|
1130
|
+
title.style.cssText = "color:#fff;font-weight:600;margin-bottom:16px"
|
|
1131
|
+
el.appendChild(title)
|
|
1132
|
+
for (const err of errors) {
|
|
1133
|
+
const pre = document.createElement("pre")
|
|
1134
|
+
pre.style.cssText = "white-space:pre-wrap;margin:0 0 12px"
|
|
1135
|
+
pre.textContent = (err.file ? err.file + ":" + (err.line || "?") + " — " : "") + err.text
|
|
1136
|
+
el.appendChild(pre)
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
function clearOverlay() {
|
|
1140
|
+
const el = document.getElementById(OVERLAY_ID)
|
|
1141
|
+
if (el) el.remove()
|
|
1142
|
+
}
|
|
1143
|
+
const events = new EventSource("/__pltt/events")
|
|
1144
|
+
events.addEventListener("build", (evt) => {
|
|
1145
|
+
const state = JSON.parse(evt.data)
|
|
1146
|
+
if (!state.ok) { showOverlay(state.errors || []); return }
|
|
1147
|
+
clearOverlay()
|
|
1148
|
+
if (state.jsHash && state.jsHash !== loaded.js) { location.reload(); return }
|
|
1149
|
+
if (state.cssHash !== loaded.css) {
|
|
1150
|
+
loaded.css = state.cssHash
|
|
1151
|
+
const link = document.querySelector('link[rel="stylesheet"][href^="/simulator.css"]')
|
|
1152
|
+
if (link) link.href = "/simulator.css?t=" + Date.now()
|
|
1153
|
+
}
|
|
1154
|
+
})
|
|
1155
|
+
</script>
|
|
967
1156
|
</body>
|
|
968
1157
|
</html>`
|
|
969
1158
|
}
|
|
@@ -991,6 +1180,21 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
|
|
|
991
1180
|
fs.writeFileSync(generatedEntry, simulatorEntrySource(cwd, absEntry, manifest, backendPort))
|
|
992
1181
|
const buildConfig = frontendBuildConfig(cwd, { ...(manifest.frontend || {}), entry })
|
|
993
1182
|
|
|
1183
|
+
const sseClients = new Set()
|
|
1184
|
+
const fileHash = (file) =>
|
|
1185
|
+
fs.existsSync(file) ? crypto.createHash("sha1").update(fs.readFileSync(file)).digest("hex") : ""
|
|
1186
|
+
const buildState = { ok: true, errors: [], jsHash: "", cssHash: "" }
|
|
1187
|
+
const broadcastBuild = () => {
|
|
1188
|
+
const payload = `event: build\ndata: ${JSON.stringify(buildState)}\n\n`
|
|
1189
|
+
for (const client of sseClients) {
|
|
1190
|
+
try {
|
|
1191
|
+
client.write(payload)
|
|
1192
|
+
} catch (_err) {
|
|
1193
|
+
sseClients.delete(client)
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
|
|
994
1198
|
const esbuild = loadEsbuild()
|
|
995
1199
|
const ctx = await esbuild.context({
|
|
996
1200
|
entryPoints: [generatedEntry],
|
|
@@ -1015,10 +1219,22 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
|
|
|
1015
1219
|
if (result.errors.length) {
|
|
1016
1220
|
console.error("[pltt] simulator bundle failed:")
|
|
1017
1221
|
for (const err of result.errors) console.error(` - ${err.text}`)
|
|
1222
|
+
buildState.ok = false
|
|
1223
|
+
buildState.errors = result.errors.map((err) => ({
|
|
1224
|
+
text: err.text,
|
|
1225
|
+
file: err.location?.file,
|
|
1226
|
+
line: err.location?.line,
|
|
1227
|
+
}))
|
|
1228
|
+
broadcastBuild()
|
|
1018
1229
|
return
|
|
1019
1230
|
}
|
|
1020
1231
|
const size = fs.existsSync(bundlePath) ? fs.statSync(bundlePath).size : 0
|
|
1021
1232
|
console.log(`[pltt] simulator bundle ready (${size} bytes)`)
|
|
1233
|
+
buildState.ok = true
|
|
1234
|
+
buildState.errors = []
|
|
1235
|
+
buildState.jsHash = fileHash(bundlePath)
|
|
1236
|
+
buildState.cssHash = fileHash(cssPath)
|
|
1237
|
+
broadcastBuild()
|
|
1022
1238
|
})
|
|
1023
1239
|
},
|
|
1024
1240
|
},
|
|
@@ -1029,6 +1245,18 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
|
|
|
1029
1245
|
|
|
1030
1246
|
const server = http.createServer((req, res) => {
|
|
1031
1247
|
const url = new URL(req.url || "/", `http://127.0.0.1:${frontendPort}`)
|
|
1248
|
+
if (url.pathname === "/__pltt/events") {
|
|
1249
|
+
res.writeHead(200, {
|
|
1250
|
+
"Content-Type": "text/event-stream",
|
|
1251
|
+
"Cache-Control": "no-store",
|
|
1252
|
+
Connection: "keep-alive",
|
|
1253
|
+
})
|
|
1254
|
+
res.write("retry: 1000\n\n")
|
|
1255
|
+
res.write(`event: build\ndata: ${JSON.stringify(buildState)}\n\n`)
|
|
1256
|
+
sseClients.add(res)
|
|
1257
|
+
req.on("close", () => sseClients.delete(res))
|
|
1258
|
+
return
|
|
1259
|
+
}
|
|
1032
1260
|
if (url.pathname === "/simulator.js") {
|
|
1033
1261
|
console.log(`[pltt] frontend GET ${url.pathname} -> 200`)
|
|
1034
1262
|
res.writeHead(200, { "Content-Type": "text/javascript; charset=utf-8", "Cache-Control": "no-store" })
|
|
@@ -1048,11 +1276,11 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
|
|
|
1048
1276
|
}
|
|
1049
1277
|
console.log(`[pltt] frontend GET ${url.pathname} -> 200`)
|
|
1050
1278
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" })
|
|
1051
|
-
res.end(indexHtml(manifest))
|
|
1279
|
+
res.end(indexHtml(manifest, buildState))
|
|
1052
1280
|
})
|
|
1053
1281
|
|
|
1054
1282
|
await new Promise((resolve) => server.listen(frontendPort, "127.0.0.1", resolve))
|
|
1055
|
-
return { server, ctx }
|
|
1283
|
+
return { server, ctx, sseClients }
|
|
1056
1284
|
}
|
|
1057
1285
|
|
|
1058
1286
|
async function startSimulator({ cwd, frontendPort, backendPort }) {
|
|
@@ -1070,6 +1298,7 @@ async function startSimulator({ cwd, frontendPort, backendPort }) {
|
|
|
1070
1298
|
console.log("[pltt] use `pltt dev --platform` for full Docker platform parity")
|
|
1071
1299
|
|
|
1072
1300
|
const stop = async () => {
|
|
1301
|
+
for (const client of frontend.sseClients) client.end()
|
|
1073
1302
|
frontend.server.close()
|
|
1074
1303
|
await frontend.ctx.dispose()
|
|
1075
1304
|
if (backend && !backend.killed) backend.kill("SIGTERM")
|
package/lib/manifest.js
CHANGED
|
@@ -45,6 +45,7 @@ const TOP_LEVEL_KEYS = new Set([
|
|
|
45
45
|
"tools",
|
|
46
46
|
"permissions",
|
|
47
47
|
"ui_extensions",
|
|
48
|
+
"data_scope",
|
|
48
49
|
"shared_tables",
|
|
49
50
|
"public_routes",
|
|
50
51
|
"rate_limit",
|
|
@@ -214,9 +215,99 @@ function validateSecrets(value, errors) {
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
|
|
218
|
+
// Permission-gated `ctx.*` clients. Declaring the permission in the manifest is
|
|
219
|
+
// what turns the client on; the platform re-checks it on every call.
|
|
220
|
+
const CTX_PERMISSIONS = [
|
|
221
|
+
{
|
|
222
|
+
accessor: "ctx.tasks",
|
|
223
|
+
permissions: ["tasks:read", "tasks:write"],
|
|
224
|
+
summary: "The caller's task board — create, list, update, complete. An app sees only the tasks it created",
|
|
225
|
+
python: 'task = await ctx.tasks.create("Review suppliers", priority="high")',
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
accessor: "ctx.data_rooms",
|
|
229
|
+
permissions: ["data_rooms:read", "data_rooms:write"],
|
|
230
|
+
summary: "The organisation's Drive — search and read indexed documents",
|
|
231
|
+
python: 'hits = await ctx.data_rooms.search("supplier contract")',
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
accessor: "ctx.members",
|
|
235
|
+
permissions: ["members:read", "members:write"],
|
|
236
|
+
summary: "Organisation members — list, get, invite, change role",
|
|
237
|
+
python: "people = await ctx.members.list()",
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
accessor: "ctx.talk",
|
|
241
|
+
permissions: ["chat:write"],
|
|
242
|
+
summary: "Post into Talk channels as the app's own agent (no read path)",
|
|
243
|
+
python: 'await ctx.talk.post("Digest ready", channel="general")',
|
|
244
|
+
},
|
|
245
|
+
]
|
|
246
|
+
|
|
247
|
+
// Declarable, validated, and behind nothing today. Left in the vocabulary so
|
|
248
|
+
// published manifests keep validating; `pltt doctor` says so out loud, because
|
|
249
|
+
// a reviewer reading "agents:write" on an app should not believe it can.
|
|
250
|
+
const INERT_PERMISSIONS = new Set([
|
|
251
|
+
"agents:read",
|
|
252
|
+
"agents:write",
|
|
253
|
+
"routines:read",
|
|
254
|
+
"routines:write",
|
|
255
|
+
"resources:read",
|
|
256
|
+
"resources:write",
|
|
257
|
+
])
|
|
258
|
+
|
|
259
|
+
// What the platform lends an app through `ctx.*` when it declares the service.
|
|
260
|
+
// One table: manifest validation, `pltt doctor`, and `pltt platform` all read it.
|
|
261
|
+
const PLATFORM_SERVICES = [
|
|
262
|
+
{
|
|
263
|
+
name: "llm",
|
|
264
|
+
accessor: "ctx.llm",
|
|
265
|
+
summary: "Chat, streaming, embeddings and image generation on the platform's model keys",
|
|
266
|
+
example: 'const r = await ctx.llm.chat([{role: "user", content: "hi"}], {model: "gpt-4o-mini"})',
|
|
267
|
+
python: 'reply = await ctx.llm.chat([{"role": "user", "content": "hi"}], max_tokens=512)',
|
|
268
|
+
instead_of: "OPENAI_API_KEY / ANTHROPIC_API_KEY",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: "media",
|
|
272
|
+
accessor: "ctx.media",
|
|
273
|
+
summary: "fal.ai — image, video, speech, transcription, or any model fal publishes",
|
|
274
|
+
example: 'const out = await ctx.media.run("fal-ai/flux/dev", {prompt: "a red bike"})',
|
|
275
|
+
python: 'out = await ctx.media.image("a red bike", image_size="square_hd")',
|
|
276
|
+
instead_of: "FAL_KEY",
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
name: "storage",
|
|
280
|
+
accessor: "ctx.storage",
|
|
281
|
+
summary: "Per-app, per-org object storage with resumable uploads",
|
|
282
|
+
python: 'meta = await ctx.storage.upload_file("report.pdf", data, "application/pdf")',
|
|
283
|
+
instead_of: "an S3/GCS bucket + credentials",
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
name: "vector",
|
|
287
|
+
accessor: "ctx.vector",
|
|
288
|
+
summary: "Namespaced vector search, partitioned to this app and org",
|
|
289
|
+
python: 'hits = await ctx.vector.search("notes", query="quarterly plan", top_k=5)',
|
|
290
|
+
instead_of: "a Pinecone/Qdrant account",
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "redis",
|
|
294
|
+
accessor: "ctx.redis",
|
|
295
|
+
summary: "Key/value, lists, sets, sorted sets, counters and locks — key-prefixed per app",
|
|
296
|
+
python: 'await ctx.redis.set("last_sync", ts, ttl=3600)',
|
|
297
|
+
instead_of: "REDIS_URL",
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
name: "web",
|
|
301
|
+
accessor: "ctx.web",
|
|
302
|
+
summary: "Web search plus an SSRF-guarded page reader (HTML tables, PDFs)",
|
|
303
|
+
python: 'hits = await ctx.web.search("fx rates", limit=5)',
|
|
304
|
+
instead_of: "TAVILY_API_KEY / SERPAPI_KEY",
|
|
305
|
+
},
|
|
306
|
+
]
|
|
307
|
+
|
|
217
308
|
function validatePlatformServices(value, errors) {
|
|
218
309
|
if (value === undefined) return
|
|
219
|
-
const known = new Set(
|
|
310
|
+
const known = new Set(PLATFORM_SERVICES.map((s) => s.name))
|
|
220
311
|
if (Array.isArray(value)) {
|
|
221
312
|
for (const service of value) {
|
|
222
313
|
if (!known.has(service)) errors.push(`platform_services contains unknown service: ${service}`)
|
|
@@ -242,10 +333,13 @@ function validatePlatformServices(value, errors) {
|
|
|
242
333
|
}
|
|
243
334
|
}
|
|
244
335
|
|
|
336
|
+
// Providers with a live OS service connection — declaring one lets the app call
|
|
337
|
+
// ctx.connections.* against the user's existing connection, no OAuth of its own.
|
|
338
|
+
const LIVE_CONNECTION_PROVIDERS = new Set(["google", "slack", "notion", "telegram", "meta"])
|
|
339
|
+
// Legacy slugs still validate so published manifests keep working, but dispatch nothing.
|
|
245
340
|
const CONNECTION_PROVIDERS = new Set([
|
|
246
|
-
|
|
341
|
+
...LIVE_CONNECTION_PROVIDERS,
|
|
247
342
|
"instagram",
|
|
248
|
-
"slack",
|
|
249
343
|
"linear",
|
|
250
344
|
"hubspot",
|
|
251
345
|
"stripe",
|
|
@@ -260,13 +354,14 @@ function validateConnections(value, errors) {
|
|
|
260
354
|
return
|
|
261
355
|
}
|
|
262
356
|
const seen = new Set()
|
|
357
|
+
const seenProviders = new Set()
|
|
263
358
|
value.forEach((conn, i) => {
|
|
264
359
|
const label = `connections[${i}]`
|
|
265
360
|
if (!isObject(conn)) {
|
|
266
361
|
errors.push(`${label} must be an object`)
|
|
267
362
|
return
|
|
268
363
|
}
|
|
269
|
-
unknownKeys(conn, new Set(["id", "provider", "label", "auth", "scopes", "required"]), label, errors)
|
|
364
|
+
unknownKeys(conn, new Set(["id", "provider", "label", "auth", "scopes", "required", "tools"]), label, errors)
|
|
270
365
|
if (!conn.id || typeof conn.id !== "string" || !/^[a-z0-9][a-z0-9_-]*[a-z0-9]$/.test(conn.id)) {
|
|
271
366
|
errors.push(`${label}.id must be lowercase snake/kebab case`)
|
|
272
367
|
} else if (seen.has(conn.id)) {
|
|
@@ -275,6 +370,14 @@ function validateConnections(value, errors) {
|
|
|
275
370
|
seen.add(conn.id)
|
|
276
371
|
if (!conn.provider || typeof conn.provider !== "string" || !CONNECTION_PROVIDERS.has(conn.provider)) {
|
|
277
372
|
errors.push(`${label}.provider must be one of ${Array.from(CONNECTION_PROVIDERS).join(", ")}`)
|
|
373
|
+
} else if (LIVE_CONNECTION_PROVIDERS.has(conn.provider)) {
|
|
374
|
+
// ctx.connections resolves a grant by provider, so two entries on the
|
|
375
|
+
// same provider would be ambiguous at call time.
|
|
376
|
+
if (seenProviders.has(conn.provider)) errors.push(`duplicate connection provider: ${conn.provider}`)
|
|
377
|
+
seenProviders.add(conn.provider)
|
|
378
|
+
}
|
|
379
|
+
if (conn.tools !== undefined && !Array.isArray(conn.tools)) {
|
|
380
|
+
errors.push(`${label}.tools must be an array`)
|
|
278
381
|
}
|
|
279
382
|
if (!conn.label || typeof conn.label !== "string") errors.push(`${label}.label is required`)
|
|
280
383
|
if (conn.auth !== undefined && conn.auth !== "oauth2" && conn.auth !== "api_key") {
|
|
@@ -692,6 +795,10 @@ function validateManifest(m) {
|
|
|
692
795
|
if (!m.name || typeof m.name !== "string") errors.push("name is required (string)")
|
|
693
796
|
if (!m.version || typeof m.version !== "string") errors.push("version is required (string)")
|
|
694
797
|
else if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(m.version)) errors.push("version must be semver")
|
|
798
|
+
if (!m.data_scope) errors.push("data_scope is required and must be personal or organization")
|
|
799
|
+
else if (!["personal", "organization"].includes(m.data_scope)) {
|
|
800
|
+
errors.push("data_scope must be personal or organization")
|
|
801
|
+
}
|
|
695
802
|
requireString(m, "developer", "manifest", errors)
|
|
696
803
|
requireString(m, "category", "manifest", errors)
|
|
697
804
|
requireString(m, "tagline", "manifest", errors)
|
|
@@ -888,4 +995,7 @@ function validateManifest(m) {
|
|
|
888
995
|
return errors
|
|
889
996
|
}
|
|
890
997
|
|
|
891
|
-
module.exports = {
|
|
998
|
+
module.exports = {
|
|
999
|
+
PLATFORM_SERVICES,
|
|
1000
|
+
CTX_PERMISSIONS,
|
|
1001
|
+
INERT_PERMISSIONS, loadManifest, validateManifest, SUPPORTED_MANIFEST_VERSIONS, KNOWN_PERMISSIONS }
|
package/package.json
CHANGED
|
@@ -8,6 +8,15 @@ pltt test --json
|
|
|
8
8
|
pltt package --json
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
See what the platform already gives your app before adding an API key or a
|
|
12
|
+
dependency — models, fal.ai media, web search, storage, vector and redis are all
|
|
13
|
+
available through `ctx.*` on the platform's own credentials:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pltt platform list # every service + a snippet, and its pltt dev mode
|
|
17
|
+
pltt platform enable llm # writes platform_services into palette-plugin.json
|
|
18
|
+
```
|
|
19
|
+
|
|
11
20
|
Expected preview flow:
|
|
12
21
|
|
|
13
22
|
```bash
|
|
@@ -9,7 +9,7 @@ export const translations = {
|
|
|
9
9
|
editApi: "Edit backend/api/main.py to add API endpoints",
|
|
10
10
|
usePlatform: "Use usePlatform() to access the authenticated user and API",
|
|
11
11
|
useTasks: "Use usePluginTasks() to manage tasks",
|
|
12
|
-
useDataRooms: "Use usePluginDataRooms() to browse files",
|
|
12
|
+
useDataRooms: "Use usePluginDataRooms() to browse Drive files",
|
|
13
13
|
tasks: "Tasks",
|
|
14
14
|
noTasks: "No tasks yet.",
|
|
15
15
|
createSampleTask: "Create Sample Task",
|
|
@@ -25,7 +25,7 @@ export const translations = {
|
|
|
25
25
|
editApi: "backend/api/main.py를 수정해 API 엔드포인트를 추가하세요",
|
|
26
26
|
usePlatform: "usePlatform()으로 인증 사용자와 API에 접근하세요",
|
|
27
27
|
useTasks: "usePluginTasks()로 작업을 관리하세요",
|
|
28
|
-
useDataRooms: "usePluginDataRooms()로 파일을 둘러보세요",
|
|
28
|
+
useDataRooms: "usePluginDataRooms()로 드라이브 파일을 둘러보세요",
|
|
29
29
|
tasks: "작업",
|
|
30
30
|
noTasks: "아직 작업이 없습니다.",
|
|
31
31
|
createSampleTask: "샘플 작업 만들기",
|