@palettelab/cli 0.3.61 → 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 +80 -5
- package/backend-sdk/palette_sdk/__init__.py +21 -1
- package/backend-sdk/palette_sdk/capabilities.py +126 -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 +78 -3
- 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/services.py +45 -6
- 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 +27 -2
- package/lib/commands/capabilities.js +151 -0
- package/lib/commands/connections.js +234 -0
- package/lib/commands/dev.js +75 -1
- package/lib/commands/doctor.js +70 -0
- package/lib/commands/init.js +3 -2
- package/lib/commands/open.js +43 -0
- package/lib/commands/services.js +74 -8
- package/lib/commands/test.js +89 -1
- package/lib/connection-catalog.json +1185 -0
- package/lib/dev-simulator.js +137 -3
- package/lib/manifest.js +90 -6
- package/package.json +1 -1
- package/template-fallback/package.json +1 -1
- package/template-fallback/templates/agent-tool/README.md +6 -2
- package/template-fallback/templates/agent-tool/backend/api/main.py +27 -6
- package/template-fallback/templates/agent-tool/palette-plugin.json +35 -4
- package/template-fallback/templates/consumer-app/package.json +1 -1
- package/template-fallback/templates/dashboard/package.json +1 -1
- package/template-fallback/templates/database/package.json +1 -1
- package/template-fallback/templates/external-service/package.json +1 -1
- package/template-fallback/templates/frontend-only/package.json +1 -1
- package/template-fallback/templates/next/package.json +1 -1
- package/template-fallback/templates/palette-app/package.json +1 -1
- package/template-fallback/templates/provider-app/package.json +1 -1
- package/template-fallback/templates/agent-tool/backend/tools/echo.py +0 -15
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
const fs = require("fs")
|
|
4
|
+
const path = require("path")
|
|
5
|
+
const { spawn } = require("child_process")
|
|
6
|
+
|
|
7
|
+
function openInBrowser(url) {
|
|
8
|
+
const [cmd, args] =
|
|
9
|
+
process.platform === "darwin"
|
|
10
|
+
? ["open", [url]]
|
|
11
|
+
: process.platform === "win32"
|
|
12
|
+
? ["cmd", ["/c", "start", "", url]]
|
|
13
|
+
: ["xdg-open", [url]]
|
|
14
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true })
|
|
15
|
+
child.unref()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function run(_args, { cwd }) {
|
|
19
|
+
const recordPath = path.join(cwd, ".palette", "last-publish.json")
|
|
20
|
+
if (!fs.existsSync(recordPath)) {
|
|
21
|
+
console.error(
|
|
22
|
+
"[pltt] no publish record found. Run `pltt dev --sandbox` (or `pltt publish`) first.",
|
|
23
|
+
)
|
|
24
|
+
process.exit(1)
|
|
25
|
+
}
|
|
26
|
+
let record
|
|
27
|
+
try {
|
|
28
|
+
record = JSON.parse(fs.readFileSync(recordPath, "utf8"))
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error(`[pltt] could not read ${recordPath}: ${err instanceof Error ? err.message : String(err)}`)
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
33
|
+
if (!record.preview_url) {
|
|
34
|
+
console.error(
|
|
35
|
+
"[pltt] last publish has no preview URL. Publish a preview with `pltt dev --sandbox`.",
|
|
36
|
+
)
|
|
37
|
+
process.exit(1)
|
|
38
|
+
}
|
|
39
|
+
console.log(`[pltt] opening ${record.preview_url}`)
|
|
40
|
+
openInBrowser(record.preview_url)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = run
|
package/lib/commands/services.js
CHANGED
|
@@ -380,20 +380,36 @@ function boolArg(source, name) {
|
|
|
380
380
|
return new RegExp(`${name}\\s*=\\s*True`).test(source)
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
+
function falseArg(source, name) {
|
|
384
|
+
return new RegExp(`${name}\\s*=\\s*False`).test(source)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function intArg(source, name) {
|
|
388
|
+
const match = source.match(new RegExp(`${name}\\s*=\\s*(\\d+)`))
|
|
389
|
+
return match ? Number(match[1]) : null
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function stringListArg(source, name) {
|
|
393
|
+
const match = source.match(new RegExp(`${name}\\s*=\\s*\\[([\\s\\S]*?)\\]`))
|
|
394
|
+
if (!match) return null
|
|
395
|
+
return Array.from(match[1].matchAll(/["']([^"']+)["']/g), (item) => item[1])
|
|
396
|
+
}
|
|
397
|
+
|
|
383
398
|
function discoverServiceDecorators(cwd) {
|
|
384
399
|
const files = listPythonFiles(path.join(cwd, "backend"))
|
|
385
400
|
const found = []
|
|
386
401
|
for (const file of files) {
|
|
387
402
|
const text = fs.readFileSync(file, "utf8")
|
|
388
|
-
const re = /@service\s*\(([\s\S]*?)\)\s*(?:async\s+)?def\s+([A-Za-z_][A-Za-z0-9_]*)/g
|
|
403
|
+
const re = /@(service|capability)\s*\(([\s\S]*?)\)\s*(?:async\s+)?def\s+([A-Za-z_][A-Za-z0-9_]*)/g
|
|
389
404
|
let match
|
|
390
405
|
while ((match = re.exec(text))) {
|
|
391
|
-
const
|
|
406
|
+
const decorator = match[1]
|
|
407
|
+
const args = match[2]
|
|
392
408
|
const name = (args.match(/["']([^"']+)["']/) || [])[1]
|
|
393
409
|
if (!name) continue
|
|
394
410
|
found.push({
|
|
395
411
|
name,
|
|
396
|
-
fn: match[
|
|
412
|
+
fn: match[3],
|
|
397
413
|
scope: argValue(args, "scope"),
|
|
398
414
|
label: argValue(args, "label"),
|
|
399
415
|
description: argValue(args, "description"),
|
|
@@ -403,6 +419,18 @@ function discoverServiceDecorators(cwd) {
|
|
|
403
419
|
output_schema: argValue(args, "output_schema") || argValue(args, "output"),
|
|
404
420
|
deprecated: boolArg(args, "deprecated"),
|
|
405
421
|
replacement: argValue(args, "replacement"),
|
|
422
|
+
agent_exposable: decorator === "capability" || boolArg(args, "agent_exposable"),
|
|
423
|
+
capability_id: argValue(args, "capability_id"),
|
|
424
|
+
effects: stringListArg(args, "effects"),
|
|
425
|
+
risk: argValue(args, "risk"),
|
|
426
|
+
supports_scheduling: falseArg(args, "supports_scheduling") ? false : true,
|
|
427
|
+
idempotent: boolArg(args, "idempotent"),
|
|
428
|
+
timeout_seconds: intArg(args, "timeout_seconds"),
|
|
429
|
+
tags: stringListArg(args, "tags"),
|
|
430
|
+
artifact_inputs: stringListArg(args, "artifact_inputs"),
|
|
431
|
+
artifact_outputs: stringListArg(args, "artifact_outputs"),
|
|
432
|
+
cost_class: argValue(args, "cost_class"),
|
|
433
|
+
latency_class: argValue(args, "latency_class"),
|
|
406
434
|
file: path.relative(cwd, file),
|
|
407
435
|
})
|
|
408
436
|
}
|
|
@@ -414,7 +442,7 @@ async function runSync(argv, { cwd }) {
|
|
|
414
442
|
const manifest = readManifest(cwd)
|
|
415
443
|
const decorators = discoverServiceDecorators(cwd)
|
|
416
444
|
if (!decorators.length) {
|
|
417
|
-
console.log("[pltt] no @service(...) decorators found under backend/.")
|
|
445
|
+
console.log("[pltt] no @service(...) or @capability(...) decorators found under backend/.")
|
|
418
446
|
return
|
|
419
447
|
}
|
|
420
448
|
manifest.provides = manifest.provides || {}
|
|
@@ -443,6 +471,18 @@ async function runSync(argv, { cwd }) {
|
|
|
443
471
|
else method.output_schema = method.output_schema || `schemas/${decl.name}.out.json`
|
|
444
472
|
if (decl.deprecated) method.deprecated = true
|
|
445
473
|
if (decl.replacement) method.replacement = decl.replacement
|
|
474
|
+
if (decl.agent_exposable) method.agent_exposable = true
|
|
475
|
+
if (decl.capability_id) method.capability_id = decl.capability_id
|
|
476
|
+
if (decl.effects) method.effects = decl.effects
|
|
477
|
+
if (decl.risk) method.risk = decl.risk
|
|
478
|
+
if (decl.agent_exposable) method.supports_scheduling = decl.supports_scheduling
|
|
479
|
+
if (decl.agent_exposable) method.idempotent = decl.idempotent
|
|
480
|
+
if (decl.timeout_seconds) method.timeout_seconds = decl.timeout_seconds
|
|
481
|
+
if (decl.tags) method.tags = decl.tags
|
|
482
|
+
if (decl.artifact_inputs) method.artifact_inputs = decl.artifact_inputs
|
|
483
|
+
if (decl.artifact_outputs) method.artifact_outputs = decl.artifact_outputs
|
|
484
|
+
if (decl.cost_class) method.cost_class = decl.cost_class
|
|
485
|
+
if (decl.latency_class) method.latency_class = decl.latency_class
|
|
446
486
|
}
|
|
447
487
|
writeManifest(cwd, manifest)
|
|
448
488
|
console.log(`[pltt] synced ${decorators.length} service method(s) into palette-plugin.json`)
|
|
@@ -544,6 +584,15 @@ async function runScaffold(argv, { cwd }) {
|
|
|
544
584
|
process.exit(1)
|
|
545
585
|
}
|
|
546
586
|
const manifest = readManifest(cwd)
|
|
587
|
+
const agentExposable = argv.includes("--agent") || argv.includes("--capability-id")
|
|
588
|
+
const capabilityId = valueAfter(argv, "--capability-id") || `app.${manifest.id}.${method}`
|
|
589
|
+
const risk = valueAfter(argv, "--risk") || "read"
|
|
590
|
+
const effects = (valueAfter(argv, "--effects") || (risk === "read" ? "external.read" : "external.write"))
|
|
591
|
+
.split(",")
|
|
592
|
+
.map((item) => item.trim())
|
|
593
|
+
.filter(Boolean)
|
|
594
|
+
const supportsScheduling = !argv.includes("--no-scheduling")
|
|
595
|
+
const idempotent = argv.includes("--idempotent")
|
|
547
596
|
const namespace = (manifest.provides && manifest.provides.namespace) || manifest.id
|
|
548
597
|
const provides = manifest.provides || {}
|
|
549
598
|
provides.namespace = namespace
|
|
@@ -556,12 +605,25 @@ async function runScaffold(argv, { cwd }) {
|
|
|
556
605
|
provides.services.push(svc)
|
|
557
606
|
}
|
|
558
607
|
svc.methods = svc.methods || []
|
|
559
|
-
|
|
560
|
-
|
|
608
|
+
let methodSpec = svc.methods.find((m) => m && m.name === method)
|
|
609
|
+
if (!methodSpec) {
|
|
610
|
+
methodSpec = {
|
|
561
611
|
name: method,
|
|
562
612
|
scope: `${namespace}.${method}`,
|
|
563
613
|
input_schema: `schemas/${method}.in.json`,
|
|
564
614
|
output_schema: `schemas/${method}.out.json`,
|
|
615
|
+
}
|
|
616
|
+
svc.methods.push(methodSpec)
|
|
617
|
+
}
|
|
618
|
+
if (agentExposable) {
|
|
619
|
+
Object.assign(methodSpec, {
|
|
620
|
+
agent_exposable: true,
|
|
621
|
+
capability_id: capabilityId,
|
|
622
|
+
description: methodSpec.description || `Agent capability for ${method}.`,
|
|
623
|
+
effects,
|
|
624
|
+
risk,
|
|
625
|
+
supports_scheduling: supportsScheduling,
|
|
626
|
+
idempotent,
|
|
565
627
|
})
|
|
566
628
|
}
|
|
567
629
|
manifest.provides = provides
|
|
@@ -594,8 +656,10 @@ async function runScaffold(argv, { cwd }) {
|
|
|
594
656
|
if (!fs.existsSync(handlerPath)) {
|
|
595
657
|
fs.writeFileSync(
|
|
596
658
|
handlerPath,
|
|
597
|
-
`from palette_sdk import service, PluginContext\n\n` +
|
|
598
|
-
|
|
659
|
+
`from palette_sdk import ${agentExposable ? "capability" : "service"}, PluginContext\n\n` +
|
|
660
|
+
(agentExposable
|
|
661
|
+
? `@capability(${JSON.stringify(method)}, capability_id=${JSON.stringify(capabilityId)}, scope=${JSON.stringify(namespace + "." + method)}, description=${JSON.stringify(`Agent capability for ${method}.`)}, input_schema=${JSON.stringify(`schemas/${method}.in.json`)}, output_schema=${JSON.stringify(`schemas/${method}.out.json`)}, effects=${JSON.stringify(effects)}, risk=${JSON.stringify(risk)}, supports_scheduling=${supportsScheduling ? "True" : "False"}, idempotent=${idempotent ? "True" : "False"})\n`
|
|
662
|
+
: `@service(${JSON.stringify(method)}, scope=${JSON.stringify(namespace + "." + method)})\n`) +
|
|
599
663
|
`async def ${safeIdent(method)}(ctx: PluginContext, payload: dict) -> dict:\n` +
|
|
600
664
|
` """Provider handler for ${namespace}/v1#${method}.\n\n` +
|
|
601
665
|
` The OS broker validates payload against schemas/${method}.in.json and the\n` +
|
|
@@ -662,3 +726,5 @@ async function run(argv, ctx) {
|
|
|
662
726
|
}
|
|
663
727
|
|
|
664
728
|
module.exports = run
|
|
729
|
+
module.exports.runScaffold = runScaffold
|
|
730
|
+
module.exports.discoverServiceDecorators = discoverServiceDecorators
|
package/lib/commands/test.js
CHANGED
|
@@ -169,6 +169,7 @@ function checkBackendContract(cwd, manifest, out, pythonInfo) {
|
|
|
169
169
|
"router = getattr(mod, 'router', None)",
|
|
170
170
|
"assert router is not None, 'backend entry has no router export'",
|
|
171
171
|
"from palette_sdk.permissions import is_permission_dep",
|
|
172
|
+
"from palette_sdk.services import drain_pending_services",
|
|
172
173
|
"public = set(manifest.get('public_routes') or [])",
|
|
173
174
|
"declared = set(manifest.get('permissions') or [])",
|
|
174
175
|
"routes = []",
|
|
@@ -196,7 +197,10 @@ function checkBackendContract(cwd, manifest, out, pythonInfo) {
|
|
|
196
197
|
" routes.append({'path': path, 'methods': methods, 'permissions': sorted(set(perms)), 'public': path in public})",
|
|
197
198
|
" if path not in public and not perms:",
|
|
198
199
|
" ungated.append({'path': path, 'methods': methods})",
|
|
199
|
-
"
|
|
200
|
+
"capabilities = []",
|
|
201
|
+
"for item in drain_pending_services():",
|
|
202
|
+
" capabilities.append({'name': item.name, 'agent_exposable': item.agent_exposable, 'capability_id': item.capability_id, 'effects': list(item.effects), 'risk': item.risk, 'supports_scheduling': item.supports_scheduling, 'idempotent': item.idempotent, 'timeout_seconds': item.timeout_seconds, 'tags': list(item.tags), 'artifact_inputs': list(item.artifact_inputs), 'artifact_outputs': list(item.artifact_outputs), 'cost_class': item.cost_class, 'latency_class': item.latency_class})",
|
|
203
|
+
"print(json.dumps({'routes': routes, 'used_permissions': sorted(used), 'ungated_routes': ungated, 'undeclared_permissions': sorted(used - declared), 'unused_declared_permissions': sorted(declared - used), 'capabilities': capabilities}))",
|
|
200
204
|
].join("\n")
|
|
201
205
|
const res = spawnSync(python, ["-c", script, abs, JSON.stringify(manifest)], { encoding: "utf8", env })
|
|
202
206
|
if (res.status === 0) {
|
|
@@ -244,6 +248,90 @@ function checkBackendContract(cwd, manifest, out, pythonInfo) {
|
|
|
244
248
|
{ permissions: report.unused_declared_permissions },
|
|
245
249
|
)
|
|
246
250
|
}
|
|
251
|
+
const manifestCapabilities = []
|
|
252
|
+
for (const service of manifest.provides?.services || []) {
|
|
253
|
+
for (const method of service.methods || []) {
|
|
254
|
+
if (method.agent_exposable) manifestCapabilities.push(method)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const runtimeByName = new Map((report.capabilities || []).map((item) => [item.name, item]))
|
|
258
|
+
for (const method of manifestCapabilities) {
|
|
259
|
+
if (!method.capability_id) {
|
|
260
|
+
failures += out.fail(
|
|
261
|
+
`agent capability has no stable capability_id: ${method.name}`,
|
|
262
|
+
"Add a semantic id such as creative.poster.generate; saved workflows use it to survive provider changes.",
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
const writeEffects = (method.effects || []).some((effect) => /(^|\.)(write|create|update|delete|publish|send)$/.test(effect))
|
|
266
|
+
if (method.risk === "read" && writeEffects) {
|
|
267
|
+
failures += out.fail(
|
|
268
|
+
`read-only capability declares write effects: ${method.name}`,
|
|
269
|
+
"Set risk to write/destructive or remove the write effect.",
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
if (["write", "destructive"].includes(method.risk) && method.supports_scheduling !== false && method.idempotent !== true) {
|
|
273
|
+
failures += out.fail(
|
|
274
|
+
`scheduled write capability is not idempotent: ${method.name}`,
|
|
275
|
+
"Implement idempotency and set idempotent=true, or set supports_scheduling=false.",
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
const runtime = runtimeByName.get(method.name)
|
|
279
|
+
if (!runtime) {
|
|
280
|
+
failures += out.fail(
|
|
281
|
+
`agent capability has no runtime handler: ${method.name}`,
|
|
282
|
+
`Import a @capability("${method.name}", capability_id="${method.capability_id || "..."}") handler from ${entry}.`,
|
|
283
|
+
)
|
|
284
|
+
continue
|
|
285
|
+
}
|
|
286
|
+
if (!runtime.agent_exposable) {
|
|
287
|
+
failures += out.fail(
|
|
288
|
+
`runtime handler is not agent-exposable: ${method.name}`,
|
|
289
|
+
"Use the @capability decorator or service(..., agent_exposable=True).",
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
if (method.capability_id && runtime.capability_id !== method.capability_id) {
|
|
293
|
+
failures += out.fail(
|
|
294
|
+
`capability id mismatch for ${method.name}`,
|
|
295
|
+
`Make the decorator capability_id exactly "${method.capability_id}".`,
|
|
296
|
+
{ manifest: method.capability_id, runtime: runtime.capability_id },
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
const parityFields = [
|
|
300
|
+
"effects", "risk", "supports_scheduling", "idempotent", "timeout_seconds",
|
|
301
|
+
"tags", "artifact_inputs", "artifact_outputs", "cost_class", "latency_class",
|
|
302
|
+
]
|
|
303
|
+
for (const field of parityFields) {
|
|
304
|
+
if (method[field] === undefined) continue
|
|
305
|
+
if (JSON.stringify(method[field]) !== JSON.stringify(runtime[field])) {
|
|
306
|
+
failures += out.fail(
|
|
307
|
+
`capability metadata mismatch for ${method.name}: ${field}`,
|
|
308
|
+
`Make the @capability ${field} match palette-plugin.json.`,
|
|
309
|
+
{ manifest: method[field], runtime: runtime[field] },
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const manifestNames = new Set(manifestCapabilities.map((item) => item.name))
|
|
315
|
+
for (const runtime of report.capabilities || []) {
|
|
316
|
+
if (runtime.agent_exposable && !manifestNames.has(runtime.name)) {
|
|
317
|
+
failures += out.fail(
|
|
318
|
+
`runtime capability is missing from manifest: ${runtime.name}`,
|
|
319
|
+
"Add a matching agent_exposable provides.services method so publish review can govern it.",
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (manifestCapabilities.length && failures === 0) {
|
|
324
|
+
out.ok("agent capability handlers match the reviewed manifest", {
|
|
325
|
+
capabilities: manifestCapabilities.map((item) => item.capability_id || item.name),
|
|
326
|
+
})
|
|
327
|
+
}
|
|
328
|
+
if ((manifest.tools || []).length) {
|
|
329
|
+
out.warn(
|
|
330
|
+
"manifest.tools is a legacy agent integration surface",
|
|
331
|
+
"Migrate each entry to a typed @capability handler plus an agent_exposable provides.services method.",
|
|
332
|
+
{ tools: manifest.tools.map((item) => item.name) },
|
|
333
|
+
)
|
|
334
|
+
}
|
|
247
335
|
return failures
|
|
248
336
|
}
|
|
249
337
|
return out.fail(
|