@palettelab/cli 0.3.73 → 0.3.75

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.
Files changed (29) hide show
  1. package/README.md +50 -15
  2. package/backend-sdk/palette_sdk/__init__.py +1 -1
  3. package/backend-sdk/palette_sdk/connections_generated.py +26 -0
  4. package/backend-sdk/palette_sdk/platform_services.py +73 -1
  5. package/backend-sdk/palette_sdk/plugin_context.py +8 -2
  6. package/backend-sdk/pyproject.toml +1 -1
  7. package/docs/python-backend-sdk.md +35 -11
  8. package/lib/acp.js +227 -25
  9. package/lib/agent-client.js +56 -27
  10. package/lib/cli.js +1 -0
  11. package/lib/commands/agent.js +145 -50
  12. package/lib/commands/dev.js +19 -2
  13. package/lib/connection-catalog.json +132 -0
  14. package/lib/dev-simulator.js +29 -14
  15. package/package.json +1 -1
  16. package/template-fallback/backend/pytest.ini +3 -0
  17. package/template-fallback/backend/tests/test_import.py +4 -8
  18. package/template-fallback/package.json +1 -1
  19. package/template-fallback/pyproject.toml +5 -0
  20. package/template-fallback/templates/consumer-app/package.json +1 -1
  21. package/template-fallback/templates/dashboard/package.json +1 -1
  22. package/template-fallback/templates/database/package.json +1 -1
  23. package/template-fallback/templates/external-service/backend/api/main.py +7 -6
  24. package/template-fallback/templates/external-service/package.json +1 -1
  25. package/template-fallback/templates/external-service/palette-plugin.json +7 -0
  26. package/template-fallback/templates/frontend-only/package.json +1 -1
  27. package/template-fallback/templates/next/package.json +1 -1
  28. package/template-fallback/templates/palette-app/package.json +1 -1
  29. package/template-fallback/templates/provider-app/package.json +1 -1
@@ -10,15 +10,19 @@ const fs = require("fs")
10
10
  const path = require("path")
11
11
  const readline = require("readline")
12
12
  const { once } = require("events")
13
- const { setTimeout: sleep } = require("timers/promises")
13
+ const consumers = require("stream/consumers")
14
14
  const { parseFlags } = require("../environments")
15
- const { connect, locate, untilIdle } = require("../agent-client")
15
+ const { connect, locate, sessionOf, followLog, untilIdle } = require("../agent-client")
16
16
  const { AcpServer } = require("../acp")
17
17
 
18
18
  const USAGE = `usage:
19
- pltt agent run --app <id> "<change>" [--format json|text] [--timeout <s>]
20
- change a built app and follow it to the end
21
- (exit 0 done, 2 stopped short, 1 error)
19
+ pltt agent run --app <id> ["<change>" | --file <path> | -] [--auto] [--format json|text] [--timeout <s>]
20
+ change a built app and follow it to the end; the change comes
21
+ as words, from a file, or on standard input (- or piped in).
22
+ --auto answers for nobody watching: each permission ask is
23
+ allowed once, each question goes on with the agent's assumption.
24
+ Exit 0 done, 2 stopped short, 1 error; Ctrl+C and SIGTERM
25
+ interrupt the session and exit 130 and 143
22
26
  pltt agent edit --app <id> "<change>" [--follow] start a change (steers the agent when it is working)
23
27
  pltt agent attach <session> follow live, answer permission asks and questions,
24
28
  type to steer, /exit to leave
@@ -45,6 +49,8 @@ const USAGE = `usage:
45
49
  pltt agent permit <session> <request> once|always|reject [message]
46
50
  pltt agent questions <session> open questions
47
51
  pltt agent answer <session> <question> "<answer>"
52
+ pltt agent ask <session> "<question>" a side question, answered from the session's transcript
53
+ (its history stays as it is; billed to the session)
48
54
  pltt agent fork <session> [--seq <n>] [--title <t>]
49
55
  pltt agent export <session> [--sanitize] [-o <file>]
50
56
  pltt agent import --app <id> <file>
@@ -60,8 +66,6 @@ const USAGE = `usage:
60
66
  pltt agent skills the skills a session can load (or invoke as /<skill>)
61
67
  pltt agent models [query] the models a subagent can run on
62
68
  pltt agent mcp the MCP servers the agent can use, with their tools
63
- pltt agent config the Build Agent's effective settings
64
- pltt agent plugins hook-bus plugins (changed plugin files reload)
65
69
  pltt agent api <METHOD> <path> [json] a raw call under /api/v1/build-sessions
66
70
  pltt agent agents the agents a session can run
67
71
  pltt agent commands the slash commands a message can start with
@@ -186,19 +190,48 @@ function describe(event) {
186
190
  }
187
191
  }
188
192
 
193
+ // What `run`, `edit --follow`, `attach` and `log` print for each event. --json: every event as one line, live ones
194
+ // ("live": true) included. Text: describe()'s line, plus the agent's text as it streams in (text.delta), a line at a
195
+ // time, and a running command's newest output line (tool.progress) when it changes; a step whose text streamed in
196
+ // does not print it again when its text.ended arrives.
189
197
  function printer(json, log) {
198
+ let partial = null // the streamed text after its last newline; null: nothing streamed in this step yet
199
+ let step = null // the step whose text streamed in
200
+ let progress = ""
190
201
  return (event) => {
191
- const line = json ? JSON.stringify(event) : describe(event)
202
+ if (json) return log(JSON.stringify(event))
203
+ const d = event.data || {}
204
+ if (event.type === "text.delta") {
205
+ const lines = `${partial ?? "agent: "}${d.text || ""}`.split("\n")
206
+ partial = lines.pop()
207
+ lines.forEach((line) => log(line))
208
+ step = d.step
209
+ return
210
+ }
211
+ if (event.type === "tool.progress") {
212
+ const line = ` … ${d.name}: ${String(d.tail || "").trimEnd().split(/[\r\n]/).pop().slice(0, 160)}`
213
+ if (line !== progress) log((progress = line))
214
+ return
215
+ }
216
+ if (event.live) return // thinking (reasoning.delta), and live kinds newer than this CLI
217
+ if (partial !== null && (event.type === "tool.called" || event.type === "text.ended")) {
218
+ if (partial) log(partial)
219
+ const said = step === d.step
220
+ partial = step = null
221
+ if (said && event.type === "text.ended") return
222
+ }
223
+ const line = describe(event)
192
224
  if (line) log(line)
193
225
  }
194
226
  }
195
227
 
196
228
  // `log`: replay the durable log; live, stream it until the round running now ends (a round.ended in the replay is
197
- // history, not the end).
229
+ // history, not the end), across dropped connections.
198
230
  async function follow(client, sessionId, { after = 0, live = true, print, signal }) {
199
231
  let last = after
200
232
  let synced = false
201
- for await (const event of client.log(sessionId, { after, follow: live, signal })) {
233
+ const events = live ? followLog(client, sessionId, { after, signal }) : client.log(sessionId, { after, follow: false, signal })
234
+ for await (const event of events) {
202
235
  if (event.type === "log.synced") {
203
236
  if (!live) return { last: event.seq, stop: null }
204
237
  synced = true
@@ -222,27 +255,89 @@ function promptLine(result) {
222
255
  return result.running ? "[pltt] sent — the agent picks it up between two steps" : "[pltt] waiting — the session is not running now; its next round starts with it"
223
256
  }
224
257
 
225
- // `run` (and `edit --follow`): send the change, follow its session until it is idle, exit by how it stopped. Never
226
- // attends: a permission ask is decided unattended (denied) by the server.
227
- async function runChange(client, { app, text, json, log, timeout }) {
228
- const signal = AbortSignal.timeout(timeout * 1000)
258
+ // A change's text: the words given, a file (--file <path>), or standard input (`-`, `--file -`, or piped in with no
259
+ // words).
260
+ async function changeText(words, file, { cwd, stdin }) {
261
+ const piped = file === "-" || (!file && (words.join(" ") === "-" || (!words.length && !(stdin || process.stdin).isTTY)))
262
+ const text = piped ? await consumers.text(stdin || process.stdin) : file ? fs.readFileSync(path.resolve(cwd, file), "utf8") : words.join(" ")
263
+ if (!text.trim()) throw new Error(`no change given: pass it as words, with --file <path>, or on standard input\n${USAGE}`)
264
+ return text.trim()
265
+ }
266
+
267
+ // --auto: nobody is there to answer, so the run does. A permission ask is allowed for that one call (never always);
268
+ // a question gets the agent's own assumption back at once, instead of waiting out its timer.
269
+ async function autoReply(client, session, event) {
270
+ const d = event.data || {}
271
+ try {
272
+ if (event.type === "permission.asked") await client.permit(session, d.id, "once")
273
+ if (event.type === "question.asked") {
274
+ await client.answer(session, d.id, `Unattended run: nobody can answer, so go with your assumption${d.assumption ? ` (${d.assumption})` : ""}.`)
275
+ }
276
+ } catch (err) {
277
+ console.error(`[pltt] could not answer ${d.id}: ${err.message}`)
278
+ }
279
+ }
280
+
281
+ // `run` (and `edit --follow`): send the change, follow its session until it is idle, exit by how it stopped. Without
282
+ // --auto it never attends, so the server decides each ask unattended: a permission ask is denied, a question goes on
283
+ // with the agent's assumption. With --auto it attends and answers them itself (autoReply). Ctrl+C (SIGINT) and
284
+ // SIGTERM interrupt the session and exit 130 and 143; a second one ends the process at once.
285
+ async function runChange(client, { app, text, json, log, timeout, auto }) {
286
+ const controller = new AbortController()
287
+ const { signal } = controller
288
+ const timer = setTimeout(() => controller.abort(), Math.min(timeout * 1000, 2 ** 31 - 1)) // a timer's longest delay
289
+ let stopped = null // the signal that stopped the run
290
+ const handlers = ["SIGINT", "SIGTERM"].map((name) => [name, () => {
291
+ stopped = stopped || name
292
+ controller.abort()
293
+ }])
294
+ for (const [name, handler] of handlers) process.once(name, handler)
295
+ const print = printer(json, log)
296
+ let before = []
297
+ let result = null
229
298
  let session = null
299
+ let attending
230
300
  let state
231
301
  try {
232
- const { sessions: before } = await client.sessions(app, { limit: 100 })
233
- const result = await client.edit(app, text)
234
- log(json ? JSON.stringify(result) : `[pltt] ${editLine(result)}`)
302
+ ;({ sessions: before } = await client.sessions(app, { limit: 100 }))
303
+ signal.throwIfAborted() // stopped before the change was sent: nothing to interrupt
304
+ result = await client.edit(app, text)
305
+ log(json ? JSON.stringify({ type: "edit.sent", ...result }) : `[pltt] ${editLine(result)}`)
235
306
  const found = await locate(client, app, result, before, signal)
236
307
  session = found.session
237
- if (!json) log(`[pltt] following ${session}`)
238
- state = await untilIdle(client, session, { after: found.after, signal, onEvent: printer(json, log) })
308
+ log(json ? JSON.stringify({ type: "run.following", session, after: found.after }) : `[pltt] following ${session}`)
309
+ if (auto) {
310
+ const attend = () => client.attend(session).catch((err) => console.error(`[pltt] attend failed: ${err.message}`))
311
+ attend()
312
+ attending = setInterval(attend, 30_000)
313
+ }
314
+ state = await untilIdle(client, session, {
315
+ after: found.after,
316
+ signal,
317
+ onEvent: async (event) => {
318
+ print(event)
319
+ if (auto) await autoReply(client, session, event)
320
+ },
321
+ })
239
322
  } catch (err) {
240
323
  if (!signal.aborted) throw err
324
+ if (stopped) {
325
+ session = session || (await sessionOf(client, app, result, before))
326
+ if (session) await client.interrupt(session).catch((error) => console.error(`[pltt] interrupt failed: ${error.message}`))
327
+ }
241
328
  state = session ? await client.wait(session, 1) : { status: null, done: false, last_stop: null }
329
+ } finally {
330
+ clearTimeout(timer)
331
+ clearInterval(attending)
332
+ for (const [name, handler] of handlers) process.removeListener(name, handler)
242
333
  }
243
- const outcome = !state.done ? `still running after ${timeout}s` : state.last_stop === "done" ? "done" : `stopped: ${state.last_stop}`
244
- log(json ? JSON.stringify(state) : `[pltt] ${outcome}${state.summary ? ` — ${state.summary}` : ""}`)
245
- process.exitCode = exitCode(state)
334
+ const code = stopped ? { SIGINT: 130, SIGTERM: 143 }[stopped] : exitCode(state)
335
+ const outcome = stopped ? `interrupted (${stopped})`
336
+ : !state.done ? `still running after ${timeout}s` : state.last_stop === "done" ? "done" : `stopped: ${state.last_stop}`
337
+ log(json
338
+ ? JSON.stringify({ type: "run.ended", session, ...state, exit_code: code, ...(stopped ? { signal: stopped } : {}) })
339
+ : `[pltt] ${outcome}${state.summary ? ` — ${state.summary}` : ""}`)
340
+ process.exitCode = code
246
341
  }
247
342
 
248
343
  // What a line typed into `attach` does, given the oldest open ask (a permission ask or a question; null when none):
@@ -273,9 +368,10 @@ function askLine(ask) {
273
368
 
274
369
  // `attach`: a line-mode follower. Attends (so asks wait for the owner), prompts for each open ask, and sends any other
275
370
  // line as a steering message. Leaves on /exit or the end of input.
276
- async function attach(client, sessionId, { log }) {
371
+ async function attach(client, sessionId, { log, json }) {
277
372
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
278
373
  const controller = new AbortController()
374
+ const print = printer(json, log)
279
375
  const asks = [] // open permission asks and questions, oldest first
280
376
  let synced = false
281
377
  const promptNext = () => {
@@ -305,27 +401,21 @@ async function attach(client, sessionId, { log }) {
305
401
  promptNext()
306
402
  })
307
403
  rl.on("close", () => controller.abort())
308
- let after = 0
309
404
  try {
310
- while (!controller.signal.aborted) {
311
- for await (const event of client.log(sessionId, { after, follow: true, signal: controller.signal })) {
312
- if (event.type === "log.synced") {
313
- synced = true
314
- promptNext()
315
- continue
316
- }
317
- after = event.seq ?? after
318
- const d = event.data || {}
319
- if (event.type === "permission.asked" || event.type === "question.asked") asks.push({ kind: event.type.split(".")[0], ...d })
320
- if (event.type === "permission.replied" || event.type === "question.replied") {
321
- const at = asks.findIndex((ask) => ask.id === d.id)
322
- if (at >= 0) asks.splice(at, 1)
323
- }
324
- const line = describe(event)
325
- if (line) log(line)
326
- if (synced && /^(permission|question)\.(asked|replied)$/.test(event.type)) promptNext()
405
+ for await (const event of followLog(client, sessionId, { signal: controller.signal })) {
406
+ if (event.type === "log.synced") {
407
+ synced = true
408
+ promptNext()
409
+ continue
410
+ }
411
+ const d = event.data || {}
412
+ if (event.type === "permission.asked" || event.type === "question.asked") asks.push({ kind: event.type.split(".")[0], ...d })
413
+ if (event.type === "permission.replied" || event.type === "question.replied") {
414
+ const at = asks.findIndex((ask) => ask.id === d.id)
415
+ if (at >= 0) asks.splice(at, 1)
327
416
  }
328
- await sleep(1000, undefined, { signal: controller.signal }) // the stream dropped: reconnect
417
+ print(event)
418
+ if (synced && /^(permission|question)\.(asked|replied)$/.test(event.type)) promptNext()
329
419
  }
330
420
  } catch (err) {
331
421
  if (!controller.signal.aborted) throw err
@@ -371,7 +461,7 @@ function diffStat(data, log) {
371
461
  log(` ${files.length} file${files.length === 1 ? "" : "s"} changed, +${data.additions} -${data.deletions}`)
372
462
  }
373
463
 
374
- async function run(argv, { cwd = process.cwd(), log = console.log } = {}) {
464
+ async function run(argv, { cwd = process.cwd(), log = console.log, stdin } = {}) {
375
465
  const [sub, ...args] = argv
376
466
  const { flags, rest } = parseFlags(args)
377
467
  const json = flags.json
@@ -450,15 +540,19 @@ async function run(argv, { cwd = process.cwd(), log = console.log } = {}) {
450
540
  const app = option(rest, "--app")
451
541
  const format = option(rest, "--format")
452
542
  const timeout = option(rest, "--timeout")
543
+ const file = option(rest, "--file")
544
+ const auto = flag(rest, "--auto")
453
545
  const followIt = flag(rest, "--follow") || sub === "run"
454
- need(app, rest[0])
455
- const text = rest.join(" ")
456
- if (followIt) return runChange(client, { app, text, json: json || format === "json", log, timeout: timeout ? positiveInt(timeout, "--timeout") : 1800 })
546
+ need(app)
547
+ const text = await changeText(rest, file, { cwd, stdin })
548
+ if (followIt) {
549
+ return runChange(client, { app, text, json: json || format === "json", log, timeout: timeout ? positiveInt(timeout, "--timeout") : 1800, auto })
550
+ }
457
551
  return out(await client.edit(app, text), (result) => log(`[pltt] ${editLine(result)}`))
458
552
  }
459
553
  case "attach":
460
554
  need(id)
461
- return attach(client, id, { log })
555
+ return attach(client, id, { log, json })
462
556
  case "acp": {
463
557
  const app = option(rest, "--app")
464
558
  need(app)
@@ -555,6 +649,9 @@ async function run(argv, { cwd = process.cwd(), log = console.log } = {}) {
555
649
  case "answer":
556
650
  need(id, words[0], words[1])
557
651
  return out(await client.answer(id, words[0], words.slice(1).join(" ")), () => log(`[pltt] answered ${words[0]}`))
652
+ case "ask":
653
+ need(id, words[0])
654
+ return out(await client.ask(id, words.join(" ")), (r) => log(r.answer))
558
655
  case "fork": {
559
656
  const seq = option(rest, "--seq")
560
657
  const title = option(rest, "--title")
@@ -637,10 +734,8 @@ async function run(argv, { cwd = process.cwd(), log = console.log } = {}) {
637
734
  ? data.servers.forEach((m) => log(`${m.name}: ${m.error ? `unavailable (${m.error})` : `${(m.tools || []).length} tools, ${(m.resources || []).length} resources, ${(m.prompts || []).length} prompts`}`))
638
735
  : log("[pltt] no MCP servers are configured"))
639
736
  case "config":
640
- return out(await client.config(), (data) => Object.entries(data.config).forEach(([k, v]) => log(`${k.padEnd(20)} ${JSON.stringify(v)}`)))
641
737
  case "plugins":
642
- return out(await client.plugins(), (data) =>
643
- data.plugins.forEach((p) => log(`${p.name.padEnd(20)} ${(p.points || []).join(", ") || "-"}${p.error ? ` ERROR ${p.error}` : ""}`)))
738
+ throw new Error(`the Build Agent's ${sub === "config" ? "settings" : "plugins"} are for platform operators (the superadmin console's Build Agent tab)`)
644
739
  case "api": {
645
740
  const [method, route, body] = rest
646
741
  need(method, route)
@@ -8,7 +8,7 @@ const { loadManifest } = require("../manifest")
8
8
  const { watchFrontend, watchFrontendBuffer } = require("../bundler")
9
9
  const { parseFlags, resolveEnvironment } = require("../environments")
10
10
  const { resolveDevPorts } = require("../ports")
11
- const { startSimulator } = require("../dev-simulator")
11
+ const { resolveDevRole, startSimulator } = require("../dev-simulator")
12
12
  const { loadLocalEnvDetails } = require("../secrets")
13
13
  const buildCommand = require("./build")
14
14
  const publish = require("./publish")
@@ -192,6 +192,15 @@ async function startPreviewWatch({ cwd, flags, record, json }) {
192
192
  )
193
193
  }
194
194
 
195
+ // `--role member` / `--role=member`; validated by resolveDevRole.
196
+ function parseRoleFlag(args) {
197
+ for (let i = 0; i < args.length; i++) {
198
+ if (args[i] === "--role") return args[i + 1] ?? ""
199
+ if (args[i].startsWith("--role=")) return args[i].slice("--role=".length)
200
+ }
201
+ return undefined
202
+ }
203
+
195
204
  async function run(args, { cwd }) {
196
205
  notifyIfUpdateAvailable(args).catch(() => {})
197
206
  const { flags, rest } = parseFlags(args)
@@ -252,6 +261,13 @@ async function run(args, { cwd }) {
252
261
  const manifest = loadManifest(cwd)
253
262
  lintMigrationsForDev(cwd, manifest)
254
263
  const pluginId = manifest.id
264
+ let role
265
+ try {
266
+ role = resolveDevRole(parseRoleFlag(args))
267
+ } catch (err) {
268
+ console.error(`[pltt] ${err.message}`)
269
+ process.exit(1)
270
+ }
255
271
  const ports = await resolveDevPorts({ host: platform ? "0.0.0.0" : "127.0.0.1" })
256
272
 
257
273
  if (!platform) {
@@ -261,7 +277,7 @@ async function run(args, { cwd }) {
261
277
  if (ports.backend !== ports.preferredBackend) {
262
278
  console.log(`[pltt] backend port ${ports.preferredBackend} is busy; using ${ports.backend}`)
263
279
  }
264
- await startSimulator({ cwd, frontendPort: ports.frontend, backendPort: ports.backend })
280
+ await startSimulator({ cwd, frontendPort: ports.frontend, backendPort: ports.backend, role })
265
281
  return
266
282
  }
267
283
 
@@ -347,3 +363,4 @@ async function run(args, { cwd }) {
347
363
  }
348
364
 
349
365
  module.exports = run
366
+ module.exports.parseRoleFlag = parseRoleFlag
@@ -1310,6 +1310,61 @@
1310
1310
  }
1311
1311
  }
1312
1312
  }
1313
+ },
1314
+ {
1315
+ "name": "youtube.list_channels",
1316
+ "namespace": "youtube",
1317
+ "method": "list_channels",
1318
+ "description": "List the YouTube channels of the connected account (id, title, handle).",
1319
+ "mutating": false,
1320
+ "risk": "read",
1321
+ "input_schema": {
1322
+ "type": "object",
1323
+ "properties": {
1324
+ "limit": {
1325
+ "type": "integer",
1326
+ "description": "Max to return (optional)"
1327
+ }
1328
+ }
1329
+ }
1330
+ },
1331
+ {
1332
+ "name": "youtube.upload_video",
1333
+ "namespace": "youtube",
1334
+ "method": "upload_video",
1335
+ "description": "Post a video Palette made to the connected YouTube channel. A vertical video up to 3 minutes shows as a Short. Returns its link.",
1336
+ "mutating": true,
1337
+ "risk": "external_write",
1338
+ "input_schema": {
1339
+ "type": "object",
1340
+ "properties": {
1341
+ "video_url": {
1342
+ "type": "string",
1343
+ "description": "The video's link exactly as Palette gave it (generate_video's url)"
1344
+ },
1345
+ "title": {
1346
+ "type": "string",
1347
+ "description": "Title, at most 100 characters"
1348
+ },
1349
+ "description": {
1350
+ "type": "string",
1351
+ "description": "Description; hashtags go here"
1352
+ },
1353
+ "privacy_status": {
1354
+ "type": "string",
1355
+ "enum": [
1356
+ "public",
1357
+ "unlisted",
1358
+ "private"
1359
+ ],
1360
+ "description": "Who can watch it (default public)"
1361
+ }
1362
+ },
1363
+ "required": [
1364
+ "video_url",
1365
+ "title"
1366
+ ]
1367
+ }
1313
1368
  }
1314
1369
  ]
1315
1370
  },
@@ -1318,6 +1373,51 @@
1318
1373
  "label": "Facebook / Instagram",
1319
1374
  "auth_type": "oauth2",
1320
1375
  "tools": [
1376
+ {
1377
+ "name": "instagram.list_accounts",
1378
+ "namespace": "instagram",
1379
+ "method": "list_accounts",
1380
+ "description": "List the Instagram professional accounts linked to the account's Facebook Pages.",
1381
+ "mutating": false,
1382
+ "risk": "read",
1383
+ "input_schema": {
1384
+ "type": "object",
1385
+ "properties": {
1386
+ "limit": {
1387
+ "type": "integer",
1388
+ "description": "Max to return (optional)"
1389
+ }
1390
+ }
1391
+ }
1392
+ },
1393
+ {
1394
+ "name": "instagram.publish_reel",
1395
+ "namespace": "instagram",
1396
+ "method": "publish_reel",
1397
+ "description": "Post a video Palette made as a Reel on the linked Instagram professional account (its only one unless account_id names one). Takes a minute or two while Instagram processes it.",
1398
+ "mutating": true,
1399
+ "risk": "external_write",
1400
+ "input_schema": {
1401
+ "type": "object",
1402
+ "properties": {
1403
+ "video_url": {
1404
+ "type": "string",
1405
+ "description": "The video's link exactly as Palette gave it (generate_video's url)"
1406
+ },
1407
+ "caption": {
1408
+ "type": "string",
1409
+ "description": "The Reel's caption; hashtags go here"
1410
+ },
1411
+ "account_id": {
1412
+ "type": "string",
1413
+ "description": "Account id from instagram.list_accounts, when there are several"
1414
+ }
1415
+ },
1416
+ "required": [
1417
+ "video_url"
1418
+ ]
1419
+ }
1420
+ },
1321
1421
  {
1322
1422
  "name": "meta.create_page_post",
1323
1423
  "namespace": "meta",
@@ -1364,6 +1464,38 @@
1364
1464
  }
1365
1465
  }
1366
1466
  },
1467
+ {
1468
+ "name": "meta.publish_video",
1469
+ "namespace": "meta",
1470
+ "method": "publish_video",
1471
+ "description": "Post a video Palette made to a Facebook Page the account manages (its only Page unless page_id names one). Returns its link.",
1472
+ "mutating": true,
1473
+ "risk": "external_write",
1474
+ "input_schema": {
1475
+ "type": "object",
1476
+ "properties": {
1477
+ "video_url": {
1478
+ "type": "string",
1479
+ "description": "The video's link exactly as Palette gave it (generate_video's url)"
1480
+ },
1481
+ "description": {
1482
+ "type": "string",
1483
+ "description": "The post's text"
1484
+ },
1485
+ "title": {
1486
+ "type": "string",
1487
+ "description": "Video title (optional)"
1488
+ },
1489
+ "page_id": {
1490
+ "type": "string",
1491
+ "description": "Page id from meta.list_pages, when it has several"
1492
+ }
1493
+ },
1494
+ "required": [
1495
+ "video_url"
1496
+ ]
1497
+ }
1498
+ },
1367
1499
  {
1368
1500
  "name": "meta.read_page_posts",
1369
1501
  "namespace": "meta",
@@ -165,7 +165,21 @@ function ensurePythonEnv(cwd, devDir, manifest) {
165
165
  // The Python below is a JS template literal: a backtick or a bare ${ inside it
166
166
  // terminates the string and the whole CLI stops loading. Keep docstrings
167
167
  // backtick-free.
168
- function writeBackendRunner(cwd, devDir, manifest, backendEntry, backendPort) {
168
+ const DEV_ROLES = ["owner", "admin", "member"]
169
+
170
+ // The role the simulator plays: the flag wins over PALETTE_DEV_ROLE; the default is owner.
171
+ function resolveDevRole(flagValue, env = process.env) {
172
+ const fromFlag = flagValue !== undefined
173
+ const role = fromFlag ? flagValue : env.PALETTE_DEV_ROLE || "owner"
174
+ if (!DEV_ROLES.includes(role)) {
175
+ throw new Error(
176
+ `${fromFlag ? "--role" : "PALETTE_DEV_ROLE"} must be one of ${DEV_ROLES.join(", ")} (got "${role}")`,
177
+ )
178
+ }
179
+ return role
180
+ }
181
+
182
+ function writeBackendRunner(cwd, devDir, manifest, backendEntry, backendPort, role = "owner") {
169
183
  const runner = path.join(devDir, "backend_runner.py")
170
184
  const sdkPath = localBackendSdkPath()
171
185
  const databasePath = path.join(devDir, `${manifest.id}.sqlite3`)
@@ -557,7 +571,7 @@ def _local_job_context(session):
557
571
  user_id="dev-user",
558
572
  organization_id=1,
559
573
  organization=OrganizationInfo.from_dict(DEV_ORGANIZATION),
560
- org_role="owner",
574
+ org_role=${JSON.stringify(role)},
561
575
  plugin_id=MANIFEST.get("id", ""),
562
576
  permissions=MANIFEST.get("permissions", []),
563
577
  storage=DEV_STORAGE or UnavailablePlatformService("storage"),
@@ -639,7 +653,7 @@ class DevPluginContextMiddleware(BaseHTTPMiddleware):
639
653
  name="Palette Developer",
640
654
  organization_id=1,
641
655
  )
642
- request.state.org_role = "owner"
656
+ request.state.org_role = ${JSON.stringify(role)}
643
657
  request.state.organization_info = DEV_ORGANIZATION
644
658
  request.state.plugin_id = MANIFEST.get("id", "")
645
659
  request.state.plugin_permissions = MANIFEST.get("permissions", [])
@@ -801,14 +815,14 @@ async def create_local_database_tables():
801
815
  return runner
802
816
  }
803
817
 
804
- function startBackend(cwd, devDir, manifest, backendPort) {
818
+ function startBackend(cwd, devDir, manifest, backendPort, role) {
805
819
  const backendEntry = manifest.backend?.entry
806
820
  if (!backendEntry) return null
807
821
  const absEntry = path.resolve(cwd, backendEntry)
808
822
  if (!fs.existsSync(absEntry)) throw new Error(`backend entry not found: ${backendEntry}`)
809
823
 
810
824
  const python = ensurePythonEnv(cwd, devDir, manifest)
811
- const runner = writeBackendRunner(cwd, devDir, manifest, backendEntry, backendPort)
825
+ const runner = writeBackendRunner(cwd, devDir, manifest, backendEntry, backendPort, role)
812
826
  const sdkPath = localBackendSdkPath()
813
827
  const env = { ...process.env }
814
828
  if (sdkPath) {
@@ -823,7 +837,7 @@ function startBackend(cwd, devDir, manifest, backendPort) {
823
837
  return child
824
838
  }
825
839
 
826
- function simulatorEntrySource(cwd, pluginEntry, manifest, backendPort) {
840
+ function simulatorEntrySource(cwd, pluginEntry, manifest, backendPort, role = "owner") {
827
841
  const localConnections = loadLocalConnections(cwd, manifest)
828
842
  return `
829
843
  import React from "react"
@@ -915,11 +929,11 @@ const basePlatform = {
915
929
  org_app_store_enabled: true,
916
930
  org_enabled_agent_ids: null,
917
931
  organization_id: 1,
918
- org_role: "owner",
932
+ org_role: ${JSON.stringify(role)},
919
933
  },
920
934
  organizationId: 1,
921
935
  pluginId: ${JSON.stringify(manifest.id)},
922
- orgRole: "owner",
936
+ orgRole: ${JSON.stringify(role)},
923
937
  orgs: [{ id: 1, name: "Palette Dev", slug: "palette-dev", theme_id: "default", logo_url: null }],
924
938
  agents: [],
925
939
  permissions: ${JSON.stringify(manifest.permissions || [])},
@@ -1094,7 +1108,7 @@ function escapeHtml(value) {
1094
1108
  }[ch]))
1095
1109
  }
1096
1110
 
1097
- async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
1111
+ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort, role) {
1098
1112
  const entry = manifest.frontend?.entry || "./frontend/src/index.tsx"
1099
1113
  const pluginEntry = manifest.frontend?.framework === "palette-app"
1100
1114
  ? generatePaletteAppEntry(cwd, entry || "./frontend/app", path.join(devDir, "palette-app-entry.tsx"))
@@ -1104,7 +1118,7 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
1104
1118
  const generatedEntry = path.join(devDir, "simulator-entry.jsx")
1105
1119
  const bundlePath = path.join(devDir, "simulator.js")
1106
1120
  const cssPath = path.join(devDir, "simulator.css")
1107
- fs.writeFileSync(generatedEntry, simulatorEntrySource(cwd, absEntry, manifest, backendPort))
1121
+ fs.writeFileSync(generatedEntry, simulatorEntrySource(cwd, absEntry, manifest, backendPort, role))
1108
1122
  const buildConfig = frontendBuildConfig(cwd, { ...(manifest.frontend || {}), entry })
1109
1123
 
1110
1124
  const sseClients = new Set()
@@ -1210,15 +1224,16 @@ async function startFrontend(cwd, devDir, manifest, frontendPort, backendPort) {
1210
1224
  return { server, ctx, sseClients }
1211
1225
  }
1212
1226
 
1213
- async function startSimulator({ cwd, frontendPort, backendPort }) {
1227
+ async function startSimulator({ cwd, frontendPort, backendPort, role = "owner" }) {
1214
1228
  const manifest = loadManifest(cwd)
1215
1229
  const devDir = path.join(cwd, ".palette", "dev")
1216
1230
  fs.mkdirSync(devDir, { recursive: true })
1217
1231
 
1218
- const backend = startBackend(cwd, devDir, manifest, backendPort)
1219
- const frontend = await startFrontend(cwd, devDir, manifest, frontendPort, backendPort)
1232
+ const backend = startBackend(cwd, devDir, manifest, backendPort, role)
1233
+ const frontend = await startFrontend(cwd, devDir, manifest, frontendPort, backendPort, role)
1220
1234
 
1221
1235
  console.log("[pltt] running local SDK simulator (no Docker)")
1236
+ console.log(`[pltt] role: ${role} (ctx.org_role; change with --role owner|admin|member)`)
1222
1237
  console.log(`[pltt] app: http://localhost:${frontendPort}/`)
1223
1238
  if (backend) console.log(`[pltt] backend: http://localhost:${backendPort}/api/v1/plugins/${manifest.id}`)
1224
1239
  console.log("[pltt] logs: streaming frontend requests, frontend bundle rebuilds, and backend output")
@@ -1250,4 +1265,4 @@ async function startSimulator({ cwd, frontendPort, backendPort }) {
1250
1265
  await stop()
1251
1266
  }
1252
1267
 
1253
- module.exports = { databaseDriverDependencies, resolveDevSecrets, startSimulator, writeBackendRunner }
1268
+ module.exports = { databaseDriverDependencies, resolveDevRole, resolveDevSecrets, startSimulator, writeBackendRunner }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palettelab/cli",
3
- "version": "0.3.73",
3
+ "version": "0.3.75",
4
4
  "description": "Developer CLI for building Palette platform plugins — no platform source access required.",
5
5
  "bin": {
6
6
  "pltt": "bin/pltt.js"
@@ -0,0 +1,3 @@
1
+ [pytest]
2
+ # The backend entry's folder is on the import path, as the platform loader puts it: tests import `main`.
3
+ pythonpath = api