@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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Backend Talk helpers for plugin Python code.
|
|
2
|
+
|
|
3
|
+
Post into a Talk channel as the app's own agent identity — the agent row the
|
|
4
|
+
platform creates for every installation, the same one members `@`-mention:
|
|
5
|
+
|
|
6
|
+
from palette_sdk import PluginContext, get_plugin_context
|
|
7
|
+
|
|
8
|
+
@router.post("/digest", dependencies=[require_permission("chat:write")])
|
|
9
|
+
async def send_digest(ctx: PluginContext = Depends(get_plugin_context)):
|
|
10
|
+
for room in await ctx.talk.channels():
|
|
11
|
+
await ctx.talk.post("Nightly digest is ready.", channel=room["id"])
|
|
12
|
+
|
|
13
|
+
Requires `chat:write` in the manifest's `permissions`, and the app's agent must
|
|
14
|
+
already be a participant of the target channel — a member invites it the same
|
|
15
|
+
way they invite any agent. An app can post into the rooms it was invited to and
|
|
16
|
+
nowhere else, and it cannot read message history at all.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TalkClient:
|
|
25
|
+
"""Thin wrapper around the platform-injected Talk service.
|
|
26
|
+
|
|
27
|
+
In production/hosted sandbox the platform injects the service into
|
|
28
|
+
`PluginContext`. In local unit tests, pass a fake service with the same
|
|
29
|
+
async `post`/`channels` methods.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(self, service: Any = None, permissions: list[str] | None = None):
|
|
33
|
+
self._service = service
|
|
34
|
+
self._permissions = permissions or []
|
|
35
|
+
|
|
36
|
+
def _require_service(self) -> Any:
|
|
37
|
+
if self._service is None:
|
|
38
|
+
raise RuntimeError(
|
|
39
|
+
"Talk service is not available in this runtime. "
|
|
40
|
+
"Run inside Palette OS/hosted sandbox or inject a fake service in tests."
|
|
41
|
+
)
|
|
42
|
+
return self._service
|
|
43
|
+
|
|
44
|
+
def _require_permission(self, permission: str) -> None:
|
|
45
|
+
if permission not in self._permissions:
|
|
46
|
+
raise PermissionError(f"App does not declare required permission: {permission}")
|
|
47
|
+
|
|
48
|
+
async def channels(self) -> list[dict[str, Any]]:
|
|
49
|
+
"""Channels this app's agent is seated in: `{id, name, type}` each.
|
|
50
|
+
|
|
51
|
+
The only Talk read an app gets. Everything else in a room stays private
|
|
52
|
+
to its members.
|
|
53
|
+
"""
|
|
54
|
+
self._require_permission("chat:write")
|
|
55
|
+
return await self._require_service().channels()
|
|
56
|
+
|
|
57
|
+
async def post(self, text: str, *, channel: str) -> dict[str, Any]:
|
|
58
|
+
"""Post `text` to `channel`, as the app's agent. Returns the message.
|
|
59
|
+
|
|
60
|
+
`channel` is a channel id or its name (`"general"`, `"#general"`).
|
|
61
|
+
`@Name` in the text mentions that member or agent exactly as a typed
|
|
62
|
+
message does, so a mentioned agent will answer.
|
|
63
|
+
"""
|
|
64
|
+
self._require_permission("chat:write")
|
|
65
|
+
return await self._require_service().post(text=text, channel=channel)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Backend task-board helpers for plugin Python code.
|
|
2
|
+
|
|
3
|
+
Put work on the user's task board from an app, and read back what happened:
|
|
4
|
+
|
|
5
|
+
from palette_sdk import PluginContext, PluginRouter
|
|
6
|
+
|
|
7
|
+
router = PluginRouter()
|
|
8
|
+
|
|
9
|
+
@router.post("/queue-review")
|
|
10
|
+
async def queue_review(ctx: PluginContext):
|
|
11
|
+
task = await ctx.tasks.create(
|
|
12
|
+
"Review the Q3 supplier list",
|
|
13
|
+
description="Flag anything over £50k.",
|
|
14
|
+
priority="high",
|
|
15
|
+
tags=["procurement"],
|
|
16
|
+
)
|
|
17
|
+
return {"task_id": task["id"]}
|
|
18
|
+
|
|
19
|
+
Requires `tasks:read` / `tasks:write` in the manifest's `permissions`.
|
|
20
|
+
|
|
21
|
+
**An app sees only its own tasks.** Every task created here is stamped with the
|
|
22
|
+
app's id, and `list`/`get`/`update`/`delete` refuse anything another app or a
|
|
23
|
+
person created — declaring `tasks:read` buys an app its own rows back, not the
|
|
24
|
+
user's whole board. The platform's own visibility rules still apply on top of
|
|
25
|
+
that, so a member never sees a colleague's task through an app either.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
from typing import Any
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class TasksClient:
|
|
34
|
+
"""Thin wrapper around the platform-injected task service.
|
|
35
|
+
|
|
36
|
+
In production/hosted sandbox the platform injects the service into
|
|
37
|
+
`PluginContext`. In local unit tests, pass a fake service exposing the same
|
|
38
|
+
async `create`/`list`/`get`/`update`/`delete` methods.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(self, service: Any = None, permissions: list[str] | None = None):
|
|
42
|
+
self._service = service
|
|
43
|
+
self._permissions = permissions or []
|
|
44
|
+
|
|
45
|
+
def _require_service(self) -> Any:
|
|
46
|
+
if self._service is None:
|
|
47
|
+
raise RuntimeError(
|
|
48
|
+
"Task service is not available in this runtime. "
|
|
49
|
+
"Run inside Palette OS/hosted sandbox or inject a fake service in tests."
|
|
50
|
+
)
|
|
51
|
+
return self._service
|
|
52
|
+
|
|
53
|
+
def _require_permission(self, permission: str) -> None:
|
|
54
|
+
if permission not in self._permissions:
|
|
55
|
+
raise PermissionError(f"App does not declare required permission: {permission}")
|
|
56
|
+
|
|
57
|
+
async def create(self, title: str, **fields: Any) -> dict[str, Any]:
|
|
58
|
+
"""Create a task on the caller's board, owned by this app.
|
|
59
|
+
|
|
60
|
+
`title` is the only required field. Everything the board understands is
|
|
61
|
+
accepted as a keyword — `description`, `status`, `priority`
|
|
62
|
+
(`low`/`medium`/`high`/`urgent`), `progress`, `tags`, `due_date`,
|
|
63
|
+
`agent_id`, `parent_task_id`, `team_id` — and is validated by the
|
|
64
|
+
platform, so an unknown or malformed field is a 422 rather than a silent
|
|
65
|
+
drop. `app_id` and `source` are set by the platform and cannot be
|
|
66
|
+
spoofed from here.
|
|
67
|
+
"""
|
|
68
|
+
self._require_permission("tasks:write")
|
|
69
|
+
return await self._require_service().create(title=title, **fields)
|
|
70
|
+
|
|
71
|
+
async def list(self, *, status: str | None = None, limit: int = 50) -> list[dict[str, Any]]:
|
|
72
|
+
"""This app's tasks, newest first. `status` filters to one state
|
|
73
|
+
(`pending`, `in_progress`, `completed`, `failed`, `cancelled`)."""
|
|
74
|
+
self._require_permission("tasks:read")
|
|
75
|
+
return await self._require_service().list(status=status, limit=limit)
|
|
76
|
+
|
|
77
|
+
async def get(self, task_id: int) -> dict[str, Any] | None:
|
|
78
|
+
"""One of this app's tasks, or None — a task belonging to anything else
|
|
79
|
+
reads as missing rather than as a permission error, so an app cannot
|
|
80
|
+
probe the board for ids."""
|
|
81
|
+
self._require_permission("tasks:read")
|
|
82
|
+
return await self._require_service().get(task_id)
|
|
83
|
+
|
|
84
|
+
async def update(self, task_id: int, **fields: Any) -> dict[str, Any]:
|
|
85
|
+
"""Patch one of this app's tasks. Same field names as `create`, plus
|
|
86
|
+
`output` for the result text the board shows when it finishes."""
|
|
87
|
+
self._require_permission("tasks:write")
|
|
88
|
+
return await self._require_service().update(task_id, **fields)
|
|
89
|
+
|
|
90
|
+
async def complete(self, task_id: int, *, output: str | None = None) -> dict[str, Any]:
|
|
91
|
+
"""Mark a task done at 100%, with optional result text.
|
|
92
|
+
|
|
93
|
+
Sugar for the three-field update every caller was writing by hand, and
|
|
94
|
+
it keeps `progress` honest — a "completed" task still sitting at 40% is
|
|
95
|
+
what makes a board stop being trusted.
|
|
96
|
+
"""
|
|
97
|
+
self._require_permission("tasks:write")
|
|
98
|
+
fields: dict[str, Any] = {"status": "completed", "progress": 100}
|
|
99
|
+
if output is not None:
|
|
100
|
+
fields["output"] = output
|
|
101
|
+
return await self._require_service().update(task_id, **fields)
|
|
102
|
+
|
|
103
|
+
async def fail(self, task_id: int, *, output: str | None = None) -> dict[str, Any]:
|
|
104
|
+
"""Mark a task failed, with optional reason text."""
|
|
105
|
+
self._require_permission("tasks:write")
|
|
106
|
+
fields: dict[str, Any] = {"status": "failed"}
|
|
107
|
+
if output is not None:
|
|
108
|
+
fields["output"] = output
|
|
109
|
+
return await self._require_service().update(task_id, **fields)
|
|
110
|
+
|
|
111
|
+
async def delete(self, task_id: int) -> None:
|
|
112
|
+
"""Remove one of this app's tasks."""
|
|
113
|
+
self._require_permission("tasks:write")
|
|
114
|
+
await self._require_service().delete(task_id)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
__all__ = ["TasksClient"]
|
|
@@ -69,14 +69,13 @@ Every backend file exports a `PluginRouter`. Routes are mounted by the platform
|
|
|
69
69
|
under `/api/v1/plugins/<plugin-id>`.
|
|
70
70
|
|
|
71
71
|
```python
|
|
72
|
-
from
|
|
73
|
-
from palette_sdk import PluginRouter, PluginContext, get_plugin_context
|
|
72
|
+
from palette_sdk import PluginRouter, PluginContext
|
|
74
73
|
|
|
75
74
|
router = PluginRouter(tags=["finance-tools"])
|
|
76
75
|
|
|
77
76
|
|
|
78
77
|
@router.get("/me")
|
|
79
|
-
async def me(ctx: PluginContext
|
|
78
|
+
async def me(ctx: PluginContext):
|
|
80
79
|
return {
|
|
81
80
|
"user_id": ctx.user_id,
|
|
82
81
|
"organization_id": ctx.organization_id,
|
|
@@ -85,6 +84,19 @@ async def me(ctx: PluginContext = Depends(get_plugin_context)):
|
|
|
85
84
|
}
|
|
86
85
|
```
|
|
87
86
|
|
|
87
|
+
A parameter annotated `PluginContext` is wired to the platform context
|
|
88
|
+
automatically. The explicit form is identical and still supported — the rest of
|
|
89
|
+
this document uses it:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from fastapi import Depends
|
|
93
|
+
from palette_sdk import get_plugin_context
|
|
94
|
+
|
|
95
|
+
@router.get("/me")
|
|
96
|
+
async def me(ctx: PluginContext = Depends(get_plugin_context)):
|
|
97
|
+
...
|
|
98
|
+
```
|
|
99
|
+
|
|
88
100
|
If the app id is `finance-tools`, this route is available at:
|
|
89
101
|
|
|
90
102
|
```text
|
|
@@ -106,20 +118,27 @@ Available context values:
|
|
|
106
118
|
|---|---|
|
|
107
119
|
| `ctx.db` | Async SQLAlchemy session for the app backend |
|
|
108
120
|
| `ctx.user_id` | Authenticated Palette user id |
|
|
109
|
-
| `ctx.organization_id` |
|
|
121
|
+
| `ctx.organization_id` | The app's data partition id — member tenant for `data_scope: personal`, the real org id for `organization` |
|
|
122
|
+
| `ctx.data_partition_id` | The same value, under the name that says what it is; prefer it in new code |
|
|
123
|
+
| `ctx.organization` | Read-only snapshot of the real organisation (`id`, `name`, `slug`, `logo_url`, `company_type`, `description`), refreshed every request |
|
|
110
124
|
| `ctx.org_role` | User role in the current organization |
|
|
111
125
|
| `ctx.plugin_id` | Current app/plugin id |
|
|
112
126
|
| `ctx.permissions` | Permissions granted from `palette-plugin.json` |
|
|
113
127
|
| `ctx.storage` | Runtime storage service, when available |
|
|
114
128
|
| `ctx.data_rooms` | Backend Data Room client |
|
|
115
|
-
| `ctx.connections` | Palette
|
|
129
|
+
| `ctx.connections` | The viewer's Palette OS connections — `ctx.connections.gmail.search(...)`, no OAuth of your own |
|
|
116
130
|
| `ctx.members` | Current organisation member client |
|
|
117
131
|
| `ctx.notifications` | Push OS notification-center notifications |
|
|
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`) |
|
|
118
134
|
| `ctx.apps` / `services(ctx)` | Governed app-to-app calls through declared `consumes` contracts |
|
|
119
135
|
| `ctx.events` | Publish event topics declared in `provides.events` |
|
|
120
136
|
| `ctx.jobs` | Enqueue, inspect, and cancel durable background jobs |
|
|
121
137
|
| `ctx.redis` | Plugin/org-scoped Redis-style service when `platform_services` includes `redis` |
|
|
122
138
|
| `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` |
|
|
140
|
+
| `ctx.web` | Web search + SSRF-guarded page reader when `platform_services` includes `web` |
|
|
141
|
+
| `ctx.media` | fal.ai on the platform's key — any model, any payload — when `platform_services` includes `media` |
|
|
123
142
|
| `ctx.config` | App install/config values |
|
|
124
143
|
| `ctx.logger` | Runtime logger for backend code |
|
|
125
144
|
| `ctx.repo(Model)` | Org-safe CRUD helper for app-owned tables |
|
|
@@ -144,7 +163,9 @@ These are the public Python helpers exported by `palette_sdk`.
|
|
|
144
163
|
| `DataRoomsClient`, `ctx.data_rooms` | Backend Data Room room/folder/file helpers |
|
|
145
164
|
| `OrganizationMembersClient`, `ctx.members` | Current-organization member lookup, invite, and role helpers |
|
|
146
165
|
| `NotificationsClient`, `ctx.notifications` | Push notifications into the OS notification center |
|
|
147
|
-
| `
|
|
166
|
+
| `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
|
+
| `PluginConnectionsClient`, `ConnectionStatus`, `MissingConnectionError`, `ctx.connections` | Third-party connection status and tool calls (there is no token accessor — the platform holds the credential) |
|
|
148
169
|
| `AppInteropClient`, `AppServiceClient`, `MissingAppServiceError`, `ctx.apps` | Call required apps/services without direct database access |
|
|
149
170
|
| `service(...)`, `services(ctx)`, `ServicesClient`, `BrokerCallError` | Provide and consume OS-broker service methods/events |
|
|
150
171
|
| `OrgRepository`, `ctx.repo(Model)` | Org-safe convenience CRUD for app-owned models |
|
|
@@ -152,7 +173,10 @@ These are the public Python helpers exported by `palette_sdk`.
|
|
|
152
173
|
| `ensure_org_rls(op, table)` | Alembic helper that enables org row-level security |
|
|
153
174
|
| `plugin_safe_id(...)`, `plugin_schema(...)`, `plugin_table_prefix(...)` | Manifest id to database-safe naming helpers |
|
|
154
175
|
| `get_config(ctx, key)`, `require_config(ctx, key)` | Functional form of config reads when not using `ctx.config_value(...)` |
|
|
155
|
-
| `
|
|
176
|
+
| `ctx.llm`, `ctx.media`, `ctx.web` | The platform's model, fal.ai and web-search keys, declared in `platform_services` |
|
|
177
|
+
| `MediaStillRunning` | `ctx.media.run` gave up waiting; carries `request_id` to collect the render later |
|
|
178
|
+
| `LocalLLMService`, `LocalMediaService`, `LocalWebService`, `LocalRedisService`, `LocalVectorService`, `LocalStorageService` | Local `pltt dev` service emulators and test fakes |
|
|
179
|
+
| `McpClient`, `mcp_tool(...)`, `mcp_resource(...)`, `mcp_prompt(...)` | Provide and consume MCP tools, resources and prompts |
|
|
156
180
|
| `PlatformServiceUnavailable`, `UnavailablePlatformService` | Clear errors when an undeclared platform service is used |
|
|
157
181
|
| `LifecycleHooks` | Install/update/enable/disable/uninstall callbacks |
|
|
158
182
|
| `Event`, `EventPublisher`, `subscribe_event(...)` | In-process event subscriptions and declared app event publishing |
|
|
@@ -788,6 +812,87 @@ During `pltt dev` notifications are not delivered to a real notification
|
|
|
788
812
|
center — the simulator logs them as `[palette-notification] {...}` and returns
|
|
789
813
|
a stub response, so your code paths still run.
|
|
790
814
|
|
|
815
|
+
## 8b. Talk Messages From Python
|
|
816
|
+
|
|
817
|
+
Every installed app has an agent identity in Talk — the agent members
|
|
818
|
+
`@`-mention and DM. `ctx.talk` lets your backend speak as it, for the moments
|
|
819
|
+
your app has something to say first (a finished export, a nightly digest, an
|
|
820
|
+
alert from a scheduled job):
|
|
821
|
+
|
|
822
|
+
```python
|
|
823
|
+
from palette_sdk import PluginContext, get_plugin_context, require_permission
|
|
824
|
+
|
|
825
|
+
@router.post("/digest", dependencies=[require_permission("chat:write")])
|
|
826
|
+
async def send_digest(ctx: PluginContext = Depends(get_plugin_context)):
|
|
827
|
+
for room in await ctx.talk.channels():
|
|
828
|
+
await ctx.talk.post("Nightly digest is ready.", channel=room["id"])
|
|
829
|
+
```
|
|
830
|
+
|
|
831
|
+
`channel` takes a channel id or its name (`"general"`, `"#general"`). An
|
|
832
|
+
`@Name` in the text mentions that member or agent just as a typed message does,
|
|
833
|
+
so a mentioned agent will answer.
|
|
834
|
+
|
|
835
|
+
Declare `chat:write` in `permissions` or the call raises `PermissionError`. Two
|
|
836
|
+
runtime rules then apply, both fail-closed:
|
|
837
|
+
|
|
838
|
+
- the app's agent must already be a participant of the target channel — a
|
|
839
|
+
member invites it in Talk, so the room's own people decide who may post;
|
|
840
|
+
- `ctx.talk.channels()` is the only read an app gets (ids, names, types of the
|
|
841
|
+
rooms it is seated in). No history, no member list, no search.
|
|
842
|
+
|
|
843
|
+
Available in request handlers, `@capability` methods, and background jobs.
|
|
844
|
+
During `pltt dev` nothing reaches a real channel: the simulator reports one
|
|
845
|
+
fake seat, logs each post as `[palette-talk] {...}`, and returns a stub message.
|
|
846
|
+
|
|
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
|
+
|
|
791
896
|
## 9. Config And Secrets
|
|
792
897
|
|
|
793
898
|
Use config for app install settings and secrets for sensitive values.
|
|
@@ -834,15 +939,85 @@ during `pltt dev`. During hosted preview/publish, server-only `.env` keys are
|
|
|
834
939
|
uploaded automatically as encrypted plugin secrets. Undeclared keys still fall
|
|
835
940
|
back to the process environment for local compatibility.
|
|
836
941
|
|
|
837
|
-
Managed
|
|
942
|
+
Managed services are declared in the manifest — `pltt platform list` prints the
|
|
943
|
+
whole set with a snippet for each, and `pltt platform enable <name>` writes the
|
|
944
|
+
declaration for you:
|
|
838
945
|
|
|
839
946
|
```json
|
|
840
947
|
{
|
|
841
|
-
"platform_services": ["redis", "vector", "
|
|
948
|
+
"platform_services": ["llm", "media", "redis", "storage", "vector", "web"]
|
|
842
949
|
}
|
|
843
950
|
```
|
|
844
951
|
|
|
952
|
+
Declaring a service is what replaces shipping a key: the platform's own
|
|
953
|
+
credential is used, metered per organisation, and the app ships no `.env` of its
|
|
954
|
+
own for it.
|
|
955
|
+
|
|
845
956
|
```python
|
|
957
|
+
# Third-party services — the user connects once in Palette Connect, grants your
|
|
958
|
+
# app the tools your manifest declares, and the platform proxies every call.
|
|
959
|
+
# Your app never holds a provider token, so scope checks, write approval and the
|
|
960
|
+
# audit trail keep working.
|
|
961
|
+
messages = await ctx.connections.gmail.search(query="invoice newer_than:7d")
|
|
962
|
+
await ctx.connections.slack.post_message(channel="#ops", text="digest ready")
|
|
963
|
+
|
|
964
|
+
# Mutating tools (gmail.send, slack.post_message, …) stage for approval by
|
|
965
|
+
# default and return {"queued_for_approval": True, "approval_id", "preview"} —
|
|
966
|
+
# tell the user what you prepared instead of claiming it was sent. An org admin
|
|
967
|
+
# can allow a specific app+provider to write directly.
|
|
968
|
+
sent = await ctx.connections.gmail.send(to="a@b.com", subject="Hi", body="…")
|
|
969
|
+
if sent.get("queued_for_approval"):
|
|
970
|
+
... # render the pending state
|
|
971
|
+
|
|
972
|
+
# The platform's model keys — no OPENAI_API_KEY secret to ship or rotate.
|
|
973
|
+
reply = await ctx.llm.chat([{"role": "user", "content": "Summarise this"}])
|
|
974
|
+
reply["text"], reply["model"], reply["cost_usd"]
|
|
975
|
+
async for chunk in ctx.llm.stream([{"role": "user", "content": "Write a haiku"}]):
|
|
976
|
+
...
|
|
977
|
+
vectors = await ctx.llm.embed(["some text"])
|
|
978
|
+
image_bytes, mime = await ctx.llm.image("a fox in the snow")
|
|
979
|
+
|
|
980
|
+
# Anything else is passed straight to the provider — the platform only pins the
|
|
981
|
+
# model, the budget and the token cap.
|
|
982
|
+
strict = await ctx.llm.chat(messages, response_format={"type": "json_object"}, top_p=0.1)
|
|
983
|
+
available = await ctx.llm.models() # what `model=` will honour ([] under SECURE)
|
|
984
|
+
wallet = await ctx.llm.spend() # {"spent_usd", "cap_usd", "remaining_usd"}
|
|
985
|
+
|
|
986
|
+
# fal.ai on the platform's key — no FAL_KEY secret to ship or rotate.
|
|
987
|
+
# `run` reaches ANY fal model and the payload is passed through untouched, so a
|
|
988
|
+
# model fal published this morning works with no SDK release.
|
|
989
|
+
out = await ctx.media.run("fal-ai/flux/dev", {"prompt": "a red bike", "num_images": 2})
|
|
990
|
+
out["images"][0]["url"]
|
|
991
|
+
|
|
992
|
+
# The same call with a default model filled in. Every keyword is forwarded to
|
|
993
|
+
# the model, so use whatever fields its own docs list.
|
|
994
|
+
poster = await ctx.media.image("a red bike", image_size="square_hd", seed=7)
|
|
995
|
+
clip = await ctx.media.video("a drone shot over dunes", duration="8", aspect_ratio="16:9")
|
|
996
|
+
speech = await ctx.media.speech("Good morning", voice="rachel")
|
|
997
|
+
words = await ctx.media.transcribe(audio_url, language="en")
|
|
998
|
+
|
|
999
|
+
# fal output URLs EXPIRE — save anything the app shows later (needs "storage" too).
|
|
1000
|
+
saved = await ctx.media.save(poster["images"][0]["url"], filename="poster.png")
|
|
1001
|
+
saved["file_url"]
|
|
1002
|
+
|
|
1003
|
+
# Local bytes a model needs as an input URL (image_url, audio_url, ...).
|
|
1004
|
+
url = await ctx.media.upload(png_bytes, filename="input.png", content_type="image/png")
|
|
1005
|
+
|
|
1006
|
+
# Renders take minutes. Don't hold an HTTP request open — hand the job to ctx.jobs.
|
|
1007
|
+
from palette_sdk import MediaStillRunning
|
|
1008
|
+
try:
|
|
1009
|
+
result = await ctx.media.run(model, payload, timeout=20)
|
|
1010
|
+
except MediaStillRunning as pending:
|
|
1011
|
+
result = await ctx.media.result(pending.request_id, model=pending.model)
|
|
1012
|
+
|
|
1013
|
+
# Or submit and collect explicitly.
|
|
1014
|
+
job = await ctx.media.submit("fal-ai/kling-video/v3/pro/text-to-video", {"prompt": "…"})
|
|
1015
|
+
state = await ctx.media.status(job["request_id"], model=job["model"])
|
|
1016
|
+
|
|
1017
|
+
# Web search + reader (HTML tables and PDFs already handled).
|
|
1018
|
+
hits = await ctx.web.search("palette os changelog", limit=5)
|
|
1019
|
+
text = await ctx.web.fetch("https://example.com/report.pdf")
|
|
1020
|
+
|
|
846
1021
|
await ctx.redis.set("cache:summary", {"ready": True}, ttl=600)
|
|
847
1022
|
value = await ctx.redis.get("cache:summary")
|
|
848
1023
|
|
|
@@ -857,6 +1032,18 @@ Palette scopes every Redis key and vector operation by `plugin_id` and
|
|
|
857
1032
|
`organization_id`; hosted previews also include the publish id. Plugin code
|
|
858
1033
|
cannot read, list, update, or delete records owned by another app or org.
|
|
859
1034
|
|
|
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.
|
|
1041
|
+
|
|
1042
|
+
Under `pltt dev` there is no platform, so these run against your own
|
|
1043
|
+
`OPENAI_API_KEY` / `FAL_KEY` when your `.env.local` has them and return
|
|
1044
|
+
deterministic stubs when it does not — the app's code path is exercisable with
|
|
1045
|
+
zero setup either way. `pltt doctor` prints which mode each service is in.
|
|
1046
|
+
|
|
860
1047
|
## 10. Managed Connections
|
|
861
1048
|
|
|
862
1049
|
Declare third-party OAuth or API-key connections in `palette-plugin.json`.
|
package/lib/bundler.js
CHANGED
|
@@ -497,6 +497,69 @@ async function bundleFrontend(pluginDir, entry, frontend = {}) {
|
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Watch the frontend entry and hand each successful (minified) bundle to
|
|
502
|
+
* `onBundle(buffer)` — used by `pltt dev --sandbox --watch` to push live
|
|
503
|
+
* frontend updates onto an existing preview publish. Returns the esbuild
|
|
504
|
+
* context (caller disposes).
|
|
505
|
+
*/
|
|
506
|
+
async function watchFrontendBuffer(pluginDir, entry, frontend = {}, onBundle) {
|
|
507
|
+
pluginDir = path.resolve(pluginDir)
|
|
508
|
+
const esbuild = loadEsbuild()
|
|
509
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "palette-frontend-watch-"))
|
|
510
|
+
const bundleEntry = isPaletteApp(frontend)
|
|
511
|
+
? generatePaletteAppEntry(pluginDir, entry || "./frontend/app", path.join(tmp, "entry.tsx"))
|
|
512
|
+
: entry
|
|
513
|
+
const absEntry = path.resolve(pluginDir, bundleEntry)
|
|
514
|
+
if (!fs.existsSync(absEntry)) {
|
|
515
|
+
throw new Error(`frontend entry not found: ${entry}`)
|
|
516
|
+
}
|
|
517
|
+
const buildConfig = frontendBuildConfig(pluginDir, { ...frontend, entry })
|
|
518
|
+
|
|
519
|
+
const ctx = await esbuild.context({
|
|
520
|
+
entryPoints: [absEntry],
|
|
521
|
+
bundle: true,
|
|
522
|
+
outfile: path.join(tmp, "frontend.mjs"),
|
|
523
|
+
format: "esm",
|
|
524
|
+
platform: "browser",
|
|
525
|
+
target: ["es2022"],
|
|
526
|
+
write: false,
|
|
527
|
+
jsx: "automatic",
|
|
528
|
+
loader: { ".ts": "tsx", ".tsx": "tsx", ".js": "jsx", ".jsx": "jsx" },
|
|
529
|
+
define: buildConfig.define,
|
|
530
|
+
external: [
|
|
531
|
+
"react",
|
|
532
|
+
"react-dom",
|
|
533
|
+
"react-dom/client",
|
|
534
|
+
"react/jsx-runtime",
|
|
535
|
+
"react/jsx-dev-runtime",
|
|
536
|
+
"@palettelab/sdk",
|
|
537
|
+
],
|
|
538
|
+
minify: true,
|
|
539
|
+
sourcemap: "inline",
|
|
540
|
+
logLevel: "silent",
|
|
541
|
+
absWorkingDir: pluginDir,
|
|
542
|
+
plugins: [
|
|
543
|
+
...buildConfig.plugins,
|
|
544
|
+
{
|
|
545
|
+
name: "palette-watch-buffer",
|
|
546
|
+
setup(build) {
|
|
547
|
+
build.onEnd((result) => {
|
|
548
|
+
if (result.errors.length) {
|
|
549
|
+
console.error("[pltt] frontend bundle failed:")
|
|
550
|
+
for (const err of result.errors) console.error(` - ${err.text}`)
|
|
551
|
+
return
|
|
552
|
+
}
|
|
553
|
+
onBundle(bundleOutputsToFrontendBuffer(result, pluginCssScopeId(frontend)))
|
|
554
|
+
})
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
],
|
|
558
|
+
})
|
|
559
|
+
await ctx.watch()
|
|
560
|
+
return ctx
|
|
561
|
+
}
|
|
562
|
+
|
|
500
563
|
async function watchFrontend(pluginDir, entry, outfile, frontend = {}) {
|
|
501
564
|
pluginDir = path.resolve(pluginDir)
|
|
502
565
|
outfile = path.resolve(outfile)
|
|
@@ -636,6 +699,7 @@ module.exports = {
|
|
|
636
699
|
bundleFrontend,
|
|
637
700
|
bundleBackend,
|
|
638
701
|
watchFrontend,
|
|
702
|
+
watchFrontendBuffer,
|
|
639
703
|
frontendBuildConfig,
|
|
640
704
|
mergePlugins,
|
|
641
705
|
}
|
package/lib/cli.js
CHANGED
|
@@ -12,9 +12,12 @@ const status = require("./commands/status")
|
|
|
12
12
|
const logs = require("./commands/logs")
|
|
13
13
|
const secrets = require("./commands/secrets")
|
|
14
14
|
const services = require("./commands/services")
|
|
15
|
+
const open = require("./commands/open")
|
|
15
16
|
const version = require("./commands/version")
|
|
16
17
|
const update = require("./commands/update")
|
|
17
18
|
const capabilities = require("./commands/capabilities")
|
|
19
|
+
const connections = require("./commands/connections")
|
|
20
|
+
const platform = require("./commands/platform")
|
|
18
21
|
|
|
19
22
|
const COMMANDS = {
|
|
20
23
|
init: { run: init, help: "Scaffold a new plugin directory from the template" },
|
|
@@ -50,10 +53,22 @@ const COMMANDS = {
|
|
|
50
53
|
run: logs,
|
|
51
54
|
help: "Tail telemetry events for a plugin (--follow to stream)",
|
|
52
55
|
},
|
|
56
|
+
open: {
|
|
57
|
+
run: open,
|
|
58
|
+
help: "Open the last publish's preview URL in the browser",
|
|
59
|
+
},
|
|
53
60
|
secrets: {
|
|
54
61
|
run: secrets,
|
|
55
62
|
help: "Initialize local env files and manage plugin-scope secrets",
|
|
56
63
|
},
|
|
64
|
+
connections: {
|
|
65
|
+
run: connections,
|
|
66
|
+
help: "Use the OS service connections (list, add, pull, mock) — no OAuth of your own",
|
|
67
|
+
},
|
|
68
|
+
platform: {
|
|
69
|
+
run: platform,
|
|
70
|
+
help: "List / enable the platform services an app borrows through ctx.* (no keys of your own)",
|
|
71
|
+
},
|
|
57
72
|
services: {
|
|
58
73
|
run: services,
|
|
59
74
|
help: "Inspect / pull / scaffold OS-broker services (list, pull, scaffold)",
|
|
@@ -75,10 +90,10 @@ function printHelp() {
|
|
|
75
90
|
console.log("Usage: pltt <command> [options]\n")
|
|
76
91
|
console.log("Commands:")
|
|
77
92
|
for (const [name, { help }] of Object.entries(COMMANDS)) {
|
|
78
|
-
console.log(` ${name.padEnd(
|
|
93
|
+
console.log(` ${name.padEnd(12)} ${help}`)
|
|
79
94
|
}
|
|
80
95
|
console.log("\nGlobal flags:")
|
|
81
|
-
console.log(" --json Emit machine-readable JSON output (status, logs, package, publish, test, update, version)")
|
|
96
|
+
console.log(" --json Emit machine-readable JSON output (status, logs, package, publish, test, update, version, login, dev --sandbox, platform, services, capabilities)")
|
|
82
97
|
console.log(" -v, --version Show the installed pltt CLI version")
|
|
83
98
|
console.log("\nPublish flags:")
|
|
84
99
|
console.log(" --env <name> Target environment from ~/.palette/config.json (default: local)")
|
|
@@ -86,6 +101,7 @@ function printHelp() {
|
|
|
86
101
|
console.log("\nDev flags:")
|
|
87
102
|
console.log(" --sandbox Publish a reviewable preview to a configured Palette sandbox (no Docker)")
|
|
88
103
|
console.log(" --cloud Alias for --sandbox")
|
|
104
|
+
console.log(" --watch With --sandbox: live-push frontend changes onto the preview (no republish)")
|
|
89
105
|
console.log(" --platform Internal only: run the Docker platform-dev parity container")
|
|
90
106
|
console.log("\nLogin flags:")
|
|
91
107
|
console.log(" --url <url> Palette platform URL for pltt login")
|
|
@@ -96,6 +112,10 @@ function printHelp() {
|
|
|
96
112
|
console.log("\nLogs flags:")
|
|
97
113
|
console.log(" --tail <n> Tail last n events (default 50)")
|
|
98
114
|
console.log(" -f, --follow Stream events (poll every 3s)")
|
|
115
|
+
console.log("\nPlatform services (ctx.* — the platform's own credentials):")
|
|
116
|
+
console.log(" pltt platform list # llm, media, storage, vector, redis, web")
|
|
117
|
+
console.log(" pltt platform enable llm media # declare them in palette-plugin.json")
|
|
118
|
+
console.log(" pltt platform disable web")
|
|
99
119
|
console.log("\nServices (OS broker):")
|
|
100
120
|
console.log(" pltt services list # show provided services/events in the org")
|
|
101
121
|
console.log(" pltt services add TARGET # add a consumed service/event target")
|
|
@@ -116,11 +136,13 @@ function printHelp() {
|
|
|
116
136
|
console.log(" cd my-app && pltt dev")
|
|
117
137
|
console.log(" pltt sandbox --env staging")
|
|
118
138
|
console.log(" pltt preview --env staging")
|
|
119
|
-
console.log(" pltt dev --sandbox --env staging")
|
|
139
|
+
console.log(" pltt dev --sandbox --watch --env staging")
|
|
140
|
+
console.log(" pltt open")
|
|
120
141
|
console.log(" pltt package")
|
|
121
142
|
console.log(" pltt publish --env staging")
|
|
122
143
|
console.log(" pltt status")
|
|
123
144
|
console.log(" pltt update")
|
|
145
|
+
console.log(" pltt platform enable media")
|
|
124
146
|
console.log(" pltt logs --follow")
|
|
125
147
|
console.log(" pltt secrets init")
|
|
126
148
|
}
|
|
@@ -118,7 +118,7 @@ async function run(args, { cwd }) {
|
|
|
118
118
|
if (args.includes(flag)) forwarded.push(flag)
|
|
119
119
|
}
|
|
120
120
|
await servicesCommand.runScaffold(forwarded, { cwd })
|
|
121
|
-
console.log("[pltt] agent capability ready; implement the generated handler, then run `pltt test
|
|
121
|
+
console.log("[pltt] agent capability ready; implement the generated handler, then run `pltt test`")
|
|
122
122
|
return
|
|
123
123
|
}
|
|
124
124
|
const capabilities = collect(manifest)
|