@palettelab/cli 0.3.68 → 0.3.70

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 (35) hide show
  1. package/README.md +23 -18
  2. package/backend-sdk/palette_sdk/__init__.py +3 -3
  3. package/backend-sdk/palette_sdk/agent_routes.py +43 -0
  4. package/backend-sdk/palette_sdk/connections_generated.py +302 -51
  5. package/backend-sdk/palette_sdk/data_rooms.py +12 -0
  6. package/backend-sdk/palette_sdk/manifest.py +2 -2
  7. package/backend-sdk/palette_sdk/permissions.py +1 -3
  8. package/backend-sdk/palette_sdk/platform_services.py +8 -5
  9. package/backend-sdk/palette_sdk/plugin_context.py +10 -12
  10. package/backend-sdk/pyproject.toml +1 -1
  11. package/docs/python-backend-sdk.md +17 -60
  12. package/lib/commands/models.js +12 -8
  13. package/lib/connection-catalog.json +2687 -622
  14. package/lib/dev-simulator.js +2 -83
  15. package/lib/manifest.js +3 -10
  16. package/package.json +1 -1
  17. package/template-fallback/backend/api/main.py +2 -2
  18. package/template-fallback/frontend/src/index.tsx +10 -21
  19. package/template-fallback/frontend/src/translations.ts +6 -12
  20. package/template-fallback/package.json +1 -1
  21. package/template-fallback/palette-plugin.json +1 -3
  22. package/template-fallback/templates/agent-tool/README.md +1 -1
  23. package/template-fallback/templates/consumer-app/package.json +1 -1
  24. package/template-fallback/templates/dashboard/package.json +1 -1
  25. package/template-fallback/templates/database/backend/api/main.py +2 -0
  26. package/template-fallback/templates/database/package.json +1 -1
  27. package/template-fallback/templates/external-service/package.json +1 -1
  28. package/template-fallback/templates/frontend-only/package.json +1 -1
  29. package/template-fallback/templates/frontend-only/palette-plugin.json +1 -1
  30. package/template-fallback/templates/next/package.json +1 -1
  31. package/template-fallback/templates/palette-app/backend/api/main.py +1 -1
  32. package/template-fallback/templates/palette-app/package.json +1 -1
  33. package/template-fallback/templates/palette-app/palette-plugin.json +1 -1
  34. package/template-fallback/templates/provider-app/package.json +1 -1
  35. package/backend-sdk/palette_sdk/tasks.py +0 -117
@@ -17,7 +17,6 @@ from palette_sdk.members import OrganizationMembersClient
17
17
  from palette_sdk.notifications import NotificationsClient
18
18
  from palette_sdk.organization import OrganizationInfo
19
19
  from palette_sdk.talk import TalkClient
20
- from palette_sdk.tasks import TasksClient
21
20
  from palette_sdk.platform_services import UnavailablePlatformService
22
21
  from palette_sdk.events import EventPublisher
23
22
  from palette_sdk.jobs import JobsClient
@@ -39,6 +38,9 @@ class PluginContext:
39
38
  caller's organization automatically. Do not add `WHERE
40
39
  organization_id = ?` — RLS already does it.
41
40
  user_id: UUID of the authenticated user
41
+ user_name: Optional platform profile display name of that user. Missing
42
+ on older hosts; user_id is the stable audit identity. Never sourced
43
+ from an app's request body or a caller-supplied identity header.
42
44
  organization_id: Effective app data partition ID. Kept for backwards
43
45
  compatibility with existing plugin repositories; use
44
46
  `data_partition_id` in new code. The real org is `organization.id`.
@@ -53,12 +55,11 @@ class PluginContext:
53
55
  members: Organization member helpers for the current org
54
56
  notifications: OS notification center push helpers
55
57
  talk: Post into Talk channels as the app's own agent identity
56
- tasks: The caller's task board, scoped to the tasks this app created.
57
- Needs `tasks:read` / `tasks:write` in the manifest.
58
58
  llm: Chat (with tool calls) / stream / embed / image on the platform's
59
- model keys, under the organisation's monthly spend cap; replies name
60
- the model that ran, `fallback=False` refuses substitutes, and
61
- `catalog()` lists models for a picker. platform_services: ["llm"].
59
+ model keys, billed to the workspace's credits; replies name the
60
+ model that ran, `fallback=False` refuses substitutes, `catalog()`
61
+ lists the workspace's models for a picker, and `spend()` its
62
+ credits. platform_services: ["llm"].
62
63
  web: Web search + SSRF-guarded page reader. platform_services: ["web"].
63
64
  media: fal.ai — image, video, speech, transcription, or any model fal
64
65
  publishes, with the payload passed through untouched; `upload()`
@@ -79,10 +80,9 @@ class PluginContext:
79
80
  members: OrganizationMembersClient = field(default_factory=OrganizationMembersClient)
80
81
  notifications: NotificationsClient = field(default_factory=NotificationsClient)
81
82
  talk: TalkClient = field(default_factory=TalkClient)
82
- tasks: TasksClient = field(default_factory=TasksClient)
83
83
  redis: Any = field(default_factory=lambda: UnavailablePlatformService("redis"))
84
84
  vector: Any = field(default_factory=lambda: UnavailablePlatformService("vector"))
85
- # The platform's own model keys, under a per-org spend cap — declare
85
+ # The platform's own model keys, billed to the workspace's credits — declare
86
86
  # platform_services: ["llm"] instead of shipping an OPENAI_API_KEY secret.
87
87
  llm: Any = field(default_factory=lambda: UnavailablePlatformService("llm"))
88
88
  # Web search + SSRF-guarded page reader — platform_services: ["web"].
@@ -94,6 +94,7 @@ class PluginContext:
94
94
  jobs: JobsClient = field(default_factory=JobsClient)
95
95
  config: dict[str, Any] = field(default_factory=dict)
96
96
  logger: logging.Logger = field(default_factory=lambda: logging.getLogger("palette_sdk.plugin"))
97
+ user_name: str | None = None
97
98
 
98
99
  def has_permission(self, permission: str) -> bool:
99
100
  return permission in self.permissions
@@ -155,6 +156,7 @@ async def get_plugin_context(request: Request) -> PluginContext:
155
156
  return PluginContext(
156
157
  db=state.db,
157
158
  user_id=str(state.user.id),
159
+ user_name=getattr(state.user, "name", None),
158
160
  organization_id=getattr(state, "data_partition_id", state.user.organization_id),
159
161
  organization=OrganizationInfo.from_dict(getattr(state, "organization_info", None)),
160
162
  org_role=getattr(state, "org_role", None),
@@ -176,10 +178,6 @@ async def get_plugin_context(request: Request) -> PluginContext:
176
178
  getattr(state, "talk", None),
177
179
  getattr(state, "plugin_permissions", []),
178
180
  ),
179
- tasks=TasksClient(
180
- getattr(state, "tasks", None),
181
- getattr(state, "plugin_permissions", []),
182
- ),
183
181
  redis=getattr(state, "redis", None) or UnavailablePlatformService("redis"),
184
182
  vector=getattr(state, "vector", None) or UnavailablePlatformService("vector"),
185
183
  llm=getattr(state, "llm", None) or UnavailablePlatformService("llm"),
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "palette-sdk"
3
- version = "0.1.17"
3
+ version = "0.1.19"
4
4
  description = "Palette Platform SDK for building backend plugins"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -130,13 +130,12 @@ Available context values:
130
130
  | `ctx.members` | Current organisation member client |
131
131
  | `ctx.notifications` | Push OS notification-center notifications |
132
132
  | `ctx.talk` | Post into Talk channels as the app's own agent (`chat:write`, seat required) |
133
- | `ctx.tasks` | The caller's task board, scoped to this app's own tasks (`tasks:read` / `tasks:write`) |
134
133
  | `ctx.apps` / `services(ctx)` | Governed app-to-app calls through declared `consumes` contracts |
135
134
  | `ctx.events` | Publish event topics declared in `provides.events` |
136
135
  | `ctx.jobs` | Enqueue, inspect, and cancel durable background jobs |
137
136
  | `ctx.redis` | Plugin/org-scoped Redis-style service when `platform_services` includes `redis` |
138
137
  | `ctx.vector` | Plugin/org-scoped vector service when `platform_services` includes `vector` |
139
- | `ctx.llm` | The platform's own model keys under an org spend cap when `platform_services` includes `llm` |
138
+ | `ctx.llm` | The platform's own model keys, billed to the workspace's credits, when `platform_services` includes `llm` |
140
139
  | `ctx.web` | Web search + SSRF-guarded page reader when `platform_services` includes `web` |
141
140
  | `ctx.media` | fal.ai on the platform's key — any model, any payload — when `platform_services` includes `media` |
142
141
  | `ctx.config` | App install/config values |
@@ -164,7 +163,6 @@ These are the public Python helpers exported by `palette_sdk`.
164
163
  | `OrganizationMembersClient`, `ctx.members` | Current-organization member lookup, invite, and role helpers |
165
164
  | `NotificationsClient`, `ctx.notifications` | Push notifications into the OS notification center |
166
165
  | `TalkClient`, `ctx.talk` | Post into Talk channels the app's agent is seated in |
167
- | `TasksClient`, `ctx.tasks` | The caller's task board, scoped to the tasks this app created |
168
166
  | `PluginConnectionsClient`, `ConnectionStatus`, `MissingConnectionError`, `ctx.connections` | Third-party connection status and tool calls (there is no token accessor — the platform holds the credential) |
169
167
  | `AppInteropClient`, `AppServiceClient`, `MissingAppServiceError`, `ctx.apps` | Call required apps/services without direct database access |
170
168
  | `service(...)`, `services(ctx)`, `ServicesClient`, `BrokerCallError` | Provide and consume OS-broker service methods/events |
@@ -367,7 +365,6 @@ async def dashboard(ctx: PluginContext = Depends(get_plugin_context)):
367
365
  Known permissions currently include:
368
366
 
369
367
  ```text
370
- tasks:read, tasks:write
371
368
  data_rooms:read, data_rooms:write
372
369
  agents:read, agents:write
373
370
  chat:read, chat:write
@@ -755,9 +752,14 @@ await ctx.data_rooms.upload_file(
755
752
  content,
756
753
  folder_id=None,
757
754
  content_type=None,
755
+ public=False, # True: every member of the organisation can read it
758
756
  )
759
757
  ```
760
758
 
759
+ Uploads are private to the room's members. With `public=True` every member of
760
+ the organisation can read the file (`read_file_bytes`, Drive download/preview),
761
+ whoever's room holds it; nobody outside the organisation can.
762
+
761
763
  In local unit tests outside the Palette runtime, inject a fake Data Room service
762
764
  if you need to test routes that call `ctx.data_rooms`. In hosted sandbox and
763
765
  real OS runtime, the platform injects the real service.
@@ -844,55 +846,6 @@ Available in request handlers, `@capability` methods, and background jobs.
844
846
  During `pltt dev` nothing reaches a real channel: the simulator reports one
845
847
  fake seat, logs each post as `[palette-talk] {...}`, and returns a stub message.
846
848
 
847
- ## 8c. The Task Board From Python
848
-
849
- `ctx.tasks` puts work on the caller's board and reads it back. Declare
850
- `tasks:read` / `tasks:write` in `permissions`:
851
-
852
- ```python
853
- @router.post("/queue-review", dependencies=[require_permission("tasks:write")])
854
- async def queue_review(ctx: PluginContext = Depends(get_plugin_context)):
855
- task = await ctx.tasks.create(
856
- "Review the Q3 supplier list",
857
- description="Flag anything over 50k.",
858
- priority="high",
859
- tags=["procurement"],
860
- due_date="2026-10-01T09:00:00Z",
861
- )
862
- return {"task_id": task["id"]}
863
-
864
-
865
- @router.post("/finish/{task_id}", dependencies=[require_permission("tasks:write")])
866
- async def finish(task_id: int, ctx: PluginContext = Depends(get_plugin_context)):
867
- # complete() also sets progress to 100 — a "completed" task still at 40% is
868
- # what makes a board stop being trusted.
869
- return await ctx.tasks.complete(task_id, output="12 suppliers checked, 2 flagged.")
870
- ```
871
-
872
- | Helper | Notes |
873
- |---|---|
874
- | `ctx.tasks.create(title, **fields)` | `description`, `status`, `priority`, `progress`, `tags`, `due_date`, `agent_id`, `parent_task_id`, `team_id` |
875
- | `ctx.tasks.list(status=None, limit=50)` | Newest first, capped at 200 |
876
- | `ctx.tasks.get(task_id)` | `None` when it is not this app's task |
877
- | `ctx.tasks.update(task_id, **fields)` | Same fields as `create`, plus `output` |
878
- | `ctx.tasks.complete(task_id, output=None)` | Sets `status="completed"` and `progress=100` |
879
- | `ctx.tasks.fail(task_id, output=None)` | Sets `status="failed"` |
880
- | `ctx.tasks.delete(task_id)` | Removes one of this app's tasks |
881
-
882
- **An app sees only its own tasks.** Every row is stamped with the app's id on
883
- create, and every other path re-checks that stamp. A task belonging to another
884
- app or to a person reads as *missing*, not as a permission error, so an app
885
- cannot probe the board for ids. Declaring `tasks:read` buys an app its own rows
886
- back, not the user's whole board, and the platform's own visibility rules still
887
- run underneath (a member sees their own tasks, an org admin the organisation's).
888
-
889
- Provenance fields — `app_id`, `source`, `source_channel`, `source_client`,
890
- `external_ref`, `routine_id` — are refused with a 422 rather than silently
891
- overwritten, so a caller cannot forge where a task came from.
892
-
893
- During `pltt dev` the board is an in-memory list for the life of the process,
894
- and each create is logged as `[palette-tasks] created {...}`.
895
-
896
849
  ## 9. Config And Secrets
897
850
 
898
851
  Use config for app install settings and secrets for sensitive values.
@@ -981,7 +934,7 @@ image_bytes, mime = await ctx.llm.image("a fox in the snow")
981
934
  # model, the budget and the token cap.
982
935
  strict = await ctx.llm.chat(messages, response_format={"type": "json_object"}, top_p=0.1)
983
936
  available = await ctx.llm.models() # what `model=` will honour ([] under SECURE)
984
- wallet = await ctx.llm.spend() # {"spent_usd", "cap_usd", "remaining_usd"}
937
+ wallet = await ctx.llm.spend() # wallet["workspace"]: the member's credits in the workspace
985
938
 
986
939
  # fal.ai on the platform's key — no FAL_KEY secret to ship or rotate.
987
940
  # `run` reaches ANY fal model and the payload is passed through untouched, so a
@@ -1032,12 +985,15 @@ Palette scopes every Redis key and vector operation by `plugin_id` and
1032
985
  `organization_id`; hosted previews also include the publish id. Plugin code
1033
986
  cannot read, list, update, or delete records owned by another app or org.
1034
987
 
1035
- `ctx.llm` and `ctx.media` draw on **one** monthly wallet per (app, organisation)
1036
- — separate ledgers would just let an app route around the cap it had already
1037
- exhausted. Both fail closed: past the cap the call raises
1038
- `PlatformServiceUnavailable` rather than spending. Call `ctx.llm.spend()` (or
1039
- `ctx.media.spend()` — the same wallet) to show the user why, instead of
1040
- surfacing a bare 503.
988
+ `ctx.llm` and `ctx.media` spend the **workspace's credits**, under its plan, seat
989
+ and member limits — the same gate a chat run passes, so an app can do what its
990
+ member could do in chat. When the workspace is out of credits the call raises
991
+ the billing `CreditError` (HTTP 402, `detail["code"]` such as `usage_exhausted`)
992
+ before anything runs. `ctx.llm.spend()["workspace"]` (or `ctx.media.spend()`)
993
+ shows the member's credits — `available`, `monthly_used`, `monthly_limit`,
994
+ `usage_state`, `execution_allowed` — so the app can say why instead of
995
+ surfacing a bare error. There is no per-app allowance unless the platform sets
996
+ one (`cap_usd`); past it the call raises `PlatformServiceUnavailable`.
1041
997
 
1042
998
  Under `pltt dev` there is no platform, so these run against your own
1043
999
  `OPENAI_API_KEY` / `FAL_KEY` when your `.env.local` has them and return
@@ -1277,6 +1233,7 @@ Advanced provider features are still available through scoped helpers:
1277
1233
  while blocking server/admin commands. `ctx.vector.client()` returns the Qdrant
1278
1234
  client for custom calls; combine it with `collection_name()`, `scoped_filter()`,
1279
1235
  `merge_filter()`, `scoped_payload()`, and `scoped_point()` to preserve isolation.
1236
+ The client is confined to your app's partition: it offers `query_points`, `scroll`, `count`, `retrieve`, `upsert` (of `scoped_point(...)` points only) and `delete`, always filtered to this app and organization; other operations are refused.
1280
1237
 
1281
1238
  Common `ctx.redis` commands:
1282
1239
 
@@ -6,8 +6,9 @@ const { parseFlags, resolveEnvironment } = require("../environments")
6
6
  const KINDS = ["chat", "image", "video", "audio"]
7
7
  const USAGE = "usage: pltt models [--kind chat|image|video|audio] [--available] [--json] [--env <name>]"
8
8
 
9
- // The platform answers with THIS app's view: the manifest goes along so
10
- // declared premium models and capacity (platform_services.llm) are reflected.
9
+ // The platform answers with THIS app's view in the developer's workspace: the
10
+ // models its chat offers, and the workspace credits every call spends. The
11
+ // manifest goes along so declared capacity (platform_services.llm) is reflected.
11
12
  async function fetchModels(env, manifest) {
12
13
  const url = `${env.url}/api/v1/appstore/platform-models`
13
14
  const res = await fetch(url, {
@@ -47,15 +48,18 @@ async function run(argv, { cwd, log = console.log } = {}) {
47
48
  const data = await fetchModels(env, manifest)
48
49
  const rows = selectRows(data, { kind, available: argv.includes("--available") })
49
50
  if (argv.includes("--json")) {
50
- log(JSON.stringify({ app_id: data.app_id, organization_id: data.organization_id, models: rows }, null, 2))
51
+ log(JSON.stringify({ app_id: data.app_id, organization_id: data.organization_id, workspace: data.workspace ?? null, models: rows }, null, 2))
51
52
  return
52
53
  }
53
- log(`Models ${data.app_id} can use in workspace ${data.organization_id} (${env.name}):\n`)
54
- for (const row of rows) log(formatRow(row))
55
- const blocked = rows.filter((row) => row.reason === "not_approved").map((row) => row.id)
56
- if (blocked.length) {
57
- log(`\n Premium models need a declaration, e.g. platform_services.llm.models: ["${blocked[0]}"]`)
54
+ log(`Models ${data.app_id} can use in workspace ${data.organization_id} (${env.name}):`)
55
+ const credits = data.workspace
56
+ if (credits) {
57
+ const available = credits.available == null ? "unlimited" : credits.available.toFixed(2)
58
+ const refused = credits.execution_allowed === false ? " — calls are refused until the workspace has credits" : ""
59
+ log(` Workspace credits: ${available} available (${credits.usage_state})${refused}`)
58
60
  }
61
+ log("")
62
+ for (const row of rows) log(formatRow(row))
59
63
  log("\n Pass an id as ctx.llm.chat(..., model=...) or ctx.media.run(<id>, ...); fallback=False refuses substitutes.")
60
64
  }
61
65