@palettelab/cli 0.3.72 → 0.3.73
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 +29 -5
- package/backend-sdk/palette_sdk/__init__.py +3 -1
- package/backend-sdk/palette_sdk/manifest.py +2 -2
- package/backend-sdk/palette_sdk/platform_services.py +254 -1
- package/backend-sdk/palette_sdk/plugin_context.py +8 -0
- package/backend-sdk/pyproject.toml +1 -1
- package/docs/python-backend-sdk.md +51 -4
- package/lib/cli.js +7 -2
- package/lib/commands/categories.js +25 -0
- package/lib/commands/doctor.js +2 -1
- package/lib/commands/platform.js +3 -2
- package/lib/commands/publish.js +7 -0
- package/lib/dev-simulator.js +8 -0
- package/lib/manifest.js +11 -1
- package/package.json +1 -1
- package/template-fallback/README.md +2 -2
- package/template-fallback/package.json +1 -1
- package/template-fallback/templates/agent-tool/palette-plugin.json +1 -1
- 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/external-service/palette-plugin.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/README.md
CHANGED
|
@@ -309,7 +309,7 @@ async def create_invoice(body: InvoiceIn, ctx: PluginContext = Depends(get_plugi
|
|
|
309
309
|
Backend SDK features for app-owned data:
|
|
310
310
|
|
|
311
311
|
- `PluginRouter`, `PluginContext`, and `get_plugin_context` provide the FastAPI route and request-context surface. A parameter annotated `ctx: PluginContext` is wired automatically — `Depends(get_plugin_context)` is still accepted and behaves identically.
|
|
312
|
-
- `PluginContext` exposes `user_id`, `organization_id`, `org_role`, `plugin_id`, `permissions`, `storage`, `ctx.db`, `ctx.jobs`, `ctx.data_rooms`, `ctx.connections`, `ctx.members`, `ctx.redis`, `ctx.vector`, `ctx.llm`, `ctx.media`, `ctx.web`, `ctx.config`, and `ctx.logger`.
|
|
312
|
+
- `PluginContext` exposes `user_id`, `organization_id`, `org_role`, `plugin_id`, `permissions`, `storage`, `ctx.db`, `ctx.jobs`, `ctx.data_rooms`, `ctx.connections`, `ctx.members`, `ctx.redis`, `ctx.vector`, `ctx.llm`, `ctx.media`, `ctx.web`, `ctx.email`, `ctx.config`, and `ctx.logger`.
|
|
313
313
|
- `ctx.db` is the full scoped SQLAlchemy `AsyncSession` for app-owned database data.
|
|
314
314
|
- `ctx.repo(Model)` gives org-safe CRUD helpers for app tables.
|
|
315
315
|
- `ctx.data_rooms` gives backend access to Palette Data Rooms without importing platform internals.
|
|
@@ -326,7 +326,8 @@ Backend SDK features for app-owned data:
|
|
|
326
326
|
- `ctx.llm` gives chat, streaming, embeddings and image generation on the PLATFORM's own provider keys when `"llm"` is declared — no `OPENAI_API_KEY` secret to ship or rotate. An app picks any model the workspace's own chat offers with `model=` — Palette's own models and the latest Claude, GPT and Gemini models, premium ones included, no declaration — and nothing bypasses the workspace's SECURE policy. `fallback=False` runs exactly the requested model or raises `ModelUnavailable`; every reply reports the model that actually ran. Tool calls (`tools=`, `tool_calls`, `reply["message"]` for the history) are supported. Calls spend the workspace's credits under its plan, seat and member limits, and are refused (the billing `CreditError`) when the workspace could not start a chat turn either.
|
|
327
327
|
- `ctx.llm` also takes provider passthrough (`response_format`, `top_p`, `stop`, `seed`, …) as plain keywords, and reports `ctx.llm.catalog()` (models with limits and unavailable reasons), `ctx.llm.models()` and `ctx.llm.spend()` so an app can offer a real model picker and explain a refusal.
|
|
328
328
|
- `ctx.media` gives fal.ai on the PLATFORM's key when `"media"` is declared — no `FAL_KEY` secret to ship or rotate. `ctx.media.run(model, payload)` reaches ANY fal model with the payload passed through untouched (so a model fal shipped today needs no SDK release); `image`, `video`, `speech` and `transcribe` are the same call with a default model filled in, `submit`/`status`/`result`/`cancel` handle multi-minute renders through a durable handle (`MediaStillRunning.handle`), `upload` puts bytes, public URLs or the app's own `ctx.storage` files on fal's CDN, `catalog()` lists the fal models it can run, and `save` copies an output into the app's own storage — fal's URLs expire. It spends the workspace's credits like `ctx.llm`.
|
|
329
|
-
- `ctx.web` gives web search and an SSRF-guarded page reader (HTML tables and PDFs handled) when `"web"` is declared.
|
|
329
|
+
- `ctx.web` gives web search and an SSRF-guarded page reader (HTML tables and PDFs handled) when `"web"` is declared. `ctx.web.fetch(url, render=True)` loads the page in a browser first, for content its scripts build after it loads (a shop page's size table); it takes tens of seconds and `pltt dev` ignores the flag.
|
|
330
|
+
- `ctx.email.send(to, subject, html=..., text=..., cc=..., bcc=..., reply_to=..., from_name=..., attachments=[...], headers=..., tags=...)` sends email through the PLATFORM's email provider when `"email"` is declared — from the platform's sender address under the app's name, so no SendGrid key, SMTP login or verified domain to ship. Attachments are bytes or text with an optional `content_type`, and a `content_id` makes one inline for `<img src="cid:...">`. Up to 50 recipients and 10 MB per message, within a daily recipient allowance per workspace. `pltt dev` sends nothing: each message is checked with the hosted rules and saved to `.palette/dev-outbox/` as an `.eml` file.
|
|
330
331
|
- `pltt platform list` prints every service above with a snippet and its `pltt dev` mode; `pltt platform enable <name>` writes the manifest declaration.
|
|
331
332
|
- `ctx.connections` gives the viewer's OS service connections — see `pltt connections`.
|
|
332
333
|
- `@job(...)`, `JobExecution`, and `ctx.jobs` provide durable async work with retries, progress, status, and cancellation.
|
|
@@ -748,7 +749,7 @@ install-scoped values or labels/help text:
|
|
|
748
749
|
"STRIPE_SECRET": { "scope": "plugin", "required": true },
|
|
749
750
|
"DEBUG_PROBE_URL": { "scope": "dev", "required": false }
|
|
750
751
|
},
|
|
751
|
-
"platform_services": ["llm", "media", "redis", "storage", "vector", "web"]
|
|
752
|
+
"platform_services": ["email", "llm", "media", "redis", "storage", "vector", "web"]
|
|
752
753
|
}
|
|
753
754
|
```
|
|
754
755
|
|
|
@@ -770,6 +771,9 @@ Managed platform services do not require developer Redis/Qdrant keys. Declare
|
|
|
770
771
|
them and use scoped SDK clients:
|
|
771
772
|
|
|
772
773
|
```python
|
|
774
|
+
await ctx.email.send("ann@example.com", "Your order", html="<p>Thanks!</p>",
|
|
775
|
+
attachments=[{"filename": "receipt.pdf", "content": pdf_bytes}])
|
|
776
|
+
|
|
773
777
|
await ctx.redis.set("cart:123", {"items": [1, 2]}, ttl=3600)
|
|
774
778
|
cart = await ctx.redis.get("cart:123")
|
|
775
779
|
|
|
@@ -1108,6 +1112,7 @@ pltt platform disable web
|
|
|
1108
1112
|
| `llm` | `OPENAI_API_KEY` / `ANTHROPIC_API_KEY` | chat with tool calls, streaming, embeddings, image generation; receipts name the model that ran |
|
|
1109
1113
|
| `media` | `FAL_KEY` | fal.ai — image, video, speech, transcription, any model fal publishes; `upload()` for private inputs |
|
|
1110
1114
|
| `web` | `TAVILY_API_KEY` / `SERPAPI_KEY` | search + SSRF-guarded page reader |
|
|
1115
|
+
| `email` | `SENDGRID_API_KEY` / SMTP login + a verified domain | `ctx.email.send(...)` — to/cc/bcc, html + text, reply_to, attachments and inline images, headers, tags; from the platform's address under the app's name |
|
|
1111
1116
|
| `storage` | an S3/GCS bucket | per-app, per-org objects with resumable uploads |
|
|
1112
1117
|
| `vector` | a Pinecone/Qdrant account | namespaced vector search |
|
|
1113
1118
|
| `redis` | `REDIS_URL` | KV, lists, sets, sorted sets, counters, locks |
|
|
@@ -1123,10 +1128,15 @@ Notes:
|
|
|
1123
1128
|
settings you already wrote are kept.
|
|
1124
1129
|
- `llm` and `media` spend the workspace's credits under its plan, seat and
|
|
1125
1130
|
member limits. `ctx.llm.spend()["workspace"]` reports what is left.
|
|
1131
|
+
- `email` is not billed. Each app has a daily recipient allowance per
|
|
1132
|
+
workspace (200 per UTC day unless the platform sets another); one message
|
|
1133
|
+
reaches up to 50 recipients and 10 MB. A wrong message raises `ValueError`; a
|
|
1134
|
+
used-up allowance or an unavailable provider raises `PlatformServiceUnavailable`.
|
|
1126
1135
|
- Under `pltt dev` there is no platform: `llm` and `media` use your own
|
|
1127
1136
|
`OPENAI_API_KEY` / `FAL_KEY` when `.env.local` has them and return
|
|
1128
|
-
deterministic stubs when it does not. `
|
|
1129
|
-
|
|
1137
|
+
deterministic stubs when it does not. `email` sends nothing: each message is
|
|
1138
|
+
checked with the hosted rules and saved to `.palette/dev-outbox/` as an `.eml`
|
|
1139
|
+
file (open it in any mail app). `pltt doctor` prints which mode each one is in.
|
|
1130
1140
|
|
|
1131
1141
|
- Bigger calls are declared on `llm`'s object form —
|
|
1132
1142
|
`{"llm": {"max_output_tokens": 12000, "max_images": 16}}` — in the manifest
|
|
@@ -1166,6 +1176,20 @@ pltt models --json --env staging
|
|
|
1166
1176
|
`budget_exhausted` (the workspace is out of credits). The same reason is what a
|
|
1167
1177
|
`fallback=False` call raises as `ModelUnavailable`.
|
|
1168
1178
|
|
|
1179
|
+
|
|
1180
|
+
### `pltt categories`
|
|
1181
|
+
|
|
1182
|
+
The App Store categories `category` in `palette-plugin.json` can name.
|
|
1183
|
+
Superadmins keep the list on the platform, so it is read from there, never
|
|
1184
|
+
shipped with the CLI. Any other value, or no category, is filed under
|
|
1185
|
+
`Other`, and `pltt publish` says where the app went. A superadmin can move
|
|
1186
|
+
the app to another category at any time.
|
|
1187
|
+
|
|
1188
|
+
```bash
|
|
1189
|
+
pltt categories # one name per line, Other last
|
|
1190
|
+
pltt categories --json --env staging
|
|
1191
|
+
```
|
|
1192
|
+
|
|
1169
1193
|
### `pltt connections`
|
|
1170
1194
|
|
|
1171
1195
|
Use the third-party services the OS already holds — Gmail, Drive, Calendar,
|
|
@@ -11,6 +11,7 @@ from palette_sdk.notifications import NotificationRecipient, NotificationsClient
|
|
|
11
11
|
from palette_sdk.organization import OrganizationInfo
|
|
12
12
|
from palette_sdk.talk import TalkClient
|
|
13
13
|
from palette_sdk.platform_services import (
|
|
14
|
+
LocalEmailService,
|
|
14
15
|
LocalLLMService,
|
|
15
16
|
LocalMediaService,
|
|
16
17
|
LocalRedisService,
|
|
@@ -90,6 +91,7 @@ __all__ = [
|
|
|
90
91
|
"NotificationsClient",
|
|
91
92
|
"NotificationRecipient",
|
|
92
93
|
"TalkClient",
|
|
94
|
+
"LocalEmailService",
|
|
93
95
|
"LocalLLMService",
|
|
94
96
|
"LocalMediaService",
|
|
95
97
|
"LocalRedisService",
|
|
@@ -155,4 +157,4 @@ __all__ = [
|
|
|
155
157
|
"LocalStorageService",
|
|
156
158
|
]
|
|
157
159
|
|
|
158
|
-
__version__ = "0.1.
|
|
160
|
+
__version__ = "0.1.21"
|
|
@@ -330,7 +330,7 @@ class PluginManifest(BaseModel):
|
|
|
330
330
|
version: str = "1.0.0"
|
|
331
331
|
data_scope: Literal["personal", "organization"] = "personal"
|
|
332
332
|
developer: str = ""
|
|
333
|
-
category: str = "
|
|
333
|
+
category: str = "Other" # the store files an app with no registered category under Other
|
|
334
334
|
tagline: str = ""
|
|
335
335
|
description: str = ""
|
|
336
336
|
icon: str = "Puzzle"
|
|
@@ -352,7 +352,7 @@ class PluginManifest(BaseModel):
|
|
|
352
352
|
requires: RequiresSpec | None = None
|
|
353
353
|
consumes: ConsumesSpec | None = None
|
|
354
354
|
mcp: McpSpec | None = None
|
|
355
|
-
platform_services: list[Literal["llm", "media", "redis", "storage", "vector", "web"]] | dict[str, PlatformServiceSpec] = Field(default_factory=list)
|
|
355
|
+
platform_services: list[Literal["email", "llm", "media", "redis", "storage", "vector", "web"]] | dict[str, PlatformServiceSpec] = Field(default_factory=list)
|
|
356
356
|
rating: float = 0.0
|
|
357
357
|
reviews: int = 0
|
|
358
358
|
featured: bool = False
|
|
@@ -6,10 +6,16 @@ import asyncio
|
|
|
6
6
|
import hashlib
|
|
7
7
|
import json
|
|
8
8
|
import math
|
|
9
|
+
import mimetypes
|
|
10
|
+
import re
|
|
9
11
|
import sys
|
|
10
12
|
import time
|
|
11
13
|
import types
|
|
14
|
+
import uuid
|
|
12
15
|
from dataclasses import dataclass, field
|
|
16
|
+
from email.message import EmailMessage
|
|
17
|
+
from email.utils import formataddr, parseaddr
|
|
18
|
+
from pathlib import Path
|
|
13
19
|
from typing import Any
|
|
14
20
|
|
|
15
21
|
|
|
@@ -874,7 +880,10 @@ class LocalWebService:
|
|
|
874
880
|
|
|
875
881
|
return {"results": await asyncio.to_thread(_run)}
|
|
876
882
|
|
|
877
|
-
async def fetch(self, url: str) -> str:
|
|
883
|
+
async def fetch(self, url: str, *, render: bool = False) -> str:
|
|
884
|
+
"""Hosted, `render=True` loads the page in a browser first, for content
|
|
885
|
+
its scripts build late. pltt dev has no browser: the flag is accepted
|
|
886
|
+
and the page comes back as fetched."""
|
|
878
887
|
import httpx
|
|
879
888
|
|
|
880
889
|
async with httpx.AsyncClient(timeout=20, follow_redirects=True) as client:
|
|
@@ -883,6 +892,250 @@ class LocalWebService:
|
|
|
883
892
|
return response.text
|
|
884
893
|
|
|
885
894
|
|
|
895
|
+
# ---- email rules shared with palette_sdk --------------------------------------
|
|
896
|
+
# ctx.email checks a message with the same rules hosted and under pltt dev, so a
|
|
897
|
+
# message pltt dev accepts is never refused once the app is published. The block
|
|
898
|
+
# is the same text in backend/app/plugins/platform_services.py and
|
|
899
|
+
# sdk/backend/palette_sdk/platform_services.py (backend test_plugin_email pins it).
|
|
900
|
+
EMAIL_MAX_RECIPIENTS = 50 # to + cc + bcc of one message
|
|
901
|
+
EMAIL_MAX_BYTES = 10 * 1024 * 1024 # bodies + attachments before encoding; fits every major inbox
|
|
902
|
+
_EMAIL_ADDRESS_RE = re.compile(r"^[^\s@<>()\[\]\\,;:\"]{1,64}@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$")
|
|
903
|
+
_EMAIL_HEADER_RE = re.compile(r"^[A-Za-z0-9-]{1,64}$")
|
|
904
|
+
_EMAIL_CONTENT_ID_RE = re.compile(r"^[A-Za-z0-9._@-]{1,100}$")
|
|
905
|
+
_EMAIL_MIME_RE = re.compile(r"^[A-Za-z0-9.+-]+/[A-Za-z0-9.+-]+$")
|
|
906
|
+
# Set by the provider, or they would let one message pass itself off as another.
|
|
907
|
+
_EMAIL_RESERVED_HEADERS = frozenset({
|
|
908
|
+
"bcc", "cc", "content-transfer-encoding", "content-type", "date", "dkim-signature", "from",
|
|
909
|
+
"message-id", "mime-version", "received", "reply-to", "return-path", "sender", "subject", "to",
|
|
910
|
+
"x-sg-eid", "x-sg-id",
|
|
911
|
+
})
|
|
912
|
+
# Files Gmail and Outlook refuse to deliver: refused here instead of as a bounce.
|
|
913
|
+
_EMAIL_BLOCKED_EXTENSIONS = frozenset({
|
|
914
|
+
"ade", "adp", "apk", "appx", "bat", "cab", "chm", "cmd", "com", "cpl", "dll", "dmg", "exe", "hta",
|
|
915
|
+
"ins", "iso", "isp", "jar", "jnlp", "js", "jse", "lib", "lnk", "mde", "msc", "msi", "msix", "msp",
|
|
916
|
+
"mst", "nsh", "pif", "ps1", "scr", "sct", "shb", "sys", "vb", "vbe", "vbs", "vhd", "vxd", "wsc",
|
|
917
|
+
"wsf", "wsh", "xll",
|
|
918
|
+
})
|
|
919
|
+
_EMAIL_ATTACHMENT_KEYS = frozenset({"filename", "content", "content_type", "content_id"})
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
def _email_line(value: Any, label: str, limit: int) -> str:
|
|
923
|
+
"""One header's worth of text: a line break here would forge headers."""
|
|
924
|
+
if not isinstance(value, str) or "\r" in value or "\n" in value or len(value) > limit:
|
|
925
|
+
raise ValueError(f"ctx.email: {label} must be one line of text, at most {limit} characters")
|
|
926
|
+
return value.strip()
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
def _email_name(value: Any, label: str) -> str:
|
|
930
|
+
# SendGrid silently drops a message whose recipient name holds a comma or a
|
|
931
|
+
# semicolon, so names lose both here, hosted and under pltt dev alike.
|
|
932
|
+
return " ".join(_email_line(value or "", label, 100).replace(",", " ").replace(";", " ").split())
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
def _email_addresses(value: Any, label: str) -> list[dict[str, str]]:
|
|
936
|
+
"""'a@x.com', 'Ann <a@x.com>', {"email": ..., "name": ...}, or a list of those."""
|
|
937
|
+
if value is None:
|
|
938
|
+
return []
|
|
939
|
+
out = []
|
|
940
|
+
for item in value if isinstance(value, (list, tuple)) else [value]:
|
|
941
|
+
if isinstance(item, dict):
|
|
942
|
+
name, address = item.get("name"), item.get("email")
|
|
943
|
+
elif isinstance(item, str) and item.count("@") == 1:
|
|
944
|
+
name, address = parseaddr(item)
|
|
945
|
+
else:
|
|
946
|
+
raise ValueError(
|
|
947
|
+
f"ctx.email: each {label} entry is one address ('a@x.com', 'Ann <a@x.com>' or "
|
|
948
|
+
f'{{"email": ..., "name": ...}}) — pass a list for several, got {item!r}'
|
|
949
|
+
)
|
|
950
|
+
address = _email_line(address, f"{label} address", 254)
|
|
951
|
+
if not _EMAIL_ADDRESS_RE.match(address):
|
|
952
|
+
raise ValueError(f"ctx.email: {label} has an invalid address: {address!r}")
|
|
953
|
+
entry = {"email": address}
|
|
954
|
+
if name := _email_name(name, f"{label} name"):
|
|
955
|
+
entry["name"] = name
|
|
956
|
+
out.append(entry)
|
|
957
|
+
return out
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
def _email_message(
|
|
961
|
+
to: Any,
|
|
962
|
+
subject: Any,
|
|
963
|
+
*,
|
|
964
|
+
html: Any = None,
|
|
965
|
+
text: Any = None,
|
|
966
|
+
cc: Any = None,
|
|
967
|
+
bcc: Any = None,
|
|
968
|
+
reply_to: Any = None,
|
|
969
|
+
from_name: Any = None,
|
|
970
|
+
attachments: Any = None,
|
|
971
|
+
headers: Any = None,
|
|
972
|
+
tags: Any = None,
|
|
973
|
+
) -> dict[str, Any]:
|
|
974
|
+
"""The checked, normalized message; ValueError names the first problem.
|
|
975
|
+
|
|
976
|
+
An address repeated across to/cc/bcc is kept once, where it first appears
|
|
977
|
+
(the provider refuses duplicates).
|
|
978
|
+
"""
|
|
979
|
+
seen: set[str] = set()
|
|
980
|
+
lists: dict[str, list[dict[str, str]]] = {}
|
|
981
|
+
for label, value in (("to", to), ("cc", cc), ("bcc", bcc)):
|
|
982
|
+
lists[label] = []
|
|
983
|
+
for entry in _email_addresses(value, label):
|
|
984
|
+
if entry["email"].lower() not in seen:
|
|
985
|
+
seen.add(entry["email"].lower())
|
|
986
|
+
lists[label].append(entry)
|
|
987
|
+
if not lists["to"]:
|
|
988
|
+
raise ValueError("ctx.email: to needs at least one address")
|
|
989
|
+
if len(seen) > EMAIL_MAX_RECIPIENTS:
|
|
990
|
+
raise ValueError(f"ctx.email: {len(seen)} recipients; one message reaches at most {EMAIL_MAX_RECIPIENTS} (to + cc + bcc)")
|
|
991
|
+
replies = _email_addresses(reply_to, "reply_to")
|
|
992
|
+
if len(replies) > 1:
|
|
993
|
+
raise ValueError("ctx.email: reply_to takes one address")
|
|
994
|
+
subject = _email_line(subject, "subject", 998)
|
|
995
|
+
if not subject:
|
|
996
|
+
raise ValueError("ctx.email: subject is required")
|
|
997
|
+
bodies = {}
|
|
998
|
+
for label, value in (("html", html), ("text", text)):
|
|
999
|
+
if value is not None and not isinstance(value, str):
|
|
1000
|
+
raise ValueError(f"ctx.email: {label} must be a string")
|
|
1001
|
+
bodies[label] = value or None
|
|
1002
|
+
if not bodies["html"] and not bodies["text"]:
|
|
1003
|
+
raise ValueError("ctx.email: pass html, text, or both")
|
|
1004
|
+
if headers is not None and not isinstance(headers, dict):
|
|
1005
|
+
raise ValueError("ctx.email: headers must be a dict of header name to value")
|
|
1006
|
+
clean_headers = {}
|
|
1007
|
+
for name, value in (headers or {}).items():
|
|
1008
|
+
if not isinstance(name, str) or not _EMAIL_HEADER_RE.match(name) or name.lower() in _EMAIL_RESERVED_HEADERS:
|
|
1009
|
+
raise ValueError(f"ctx.email: header {name!r} cannot be set by an app")
|
|
1010
|
+
clean_headers[name] = _email_line(value, f"header {name}", 998)
|
|
1011
|
+
tags = [] if tags is None else tags
|
|
1012
|
+
if not isinstance(tags, (list, tuple)) or len(tags) > 10 or not all(
|
|
1013
|
+
isinstance(tag, str) and tag.strip() and tag.isascii() for tag in tags
|
|
1014
|
+
):
|
|
1015
|
+
raise ValueError("ctx.email: tags are a list of up to 10 non-empty ASCII strings")
|
|
1016
|
+
tags = list(dict.fromkeys(_email_line(tag, "tag", 255) for tag in tags))
|
|
1017
|
+
if attachments is not None and not isinstance(attachments, (list, tuple)):
|
|
1018
|
+
raise ValueError("ctx.email: attachments must be a list")
|
|
1019
|
+
files = []
|
|
1020
|
+
size = sum(len(body.encode("utf-8")) for body in bodies.values() if body)
|
|
1021
|
+
for item in attachments or []:
|
|
1022
|
+
if not isinstance(item, dict) or set(item) - _EMAIL_ATTACHMENT_KEYS:
|
|
1023
|
+
raise ValueError(
|
|
1024
|
+
'ctx.email: each attachment is {"filename": ..., "content": bytes or str, '
|
|
1025
|
+
'"content_type": optional, "content_id": optional, for inline <img src="cid:...">}'
|
|
1026
|
+
)
|
|
1027
|
+
filename = _email_line(item.get("filename"), "attachment filename", 255).replace("\\", "/").rsplit("/", 1)[-1]
|
|
1028
|
+
if not filename:
|
|
1029
|
+
raise ValueError("ctx.email: attachment filename is required")
|
|
1030
|
+
extension = filename.rsplit(".", 1)[-1].lower() if "." in filename else ""
|
|
1031
|
+
if extension in _EMAIL_BLOCKED_EXTENSIONS:
|
|
1032
|
+
raise ValueError(f"ctx.email: {filename}: mail servers refuse .{extension} attachments")
|
|
1033
|
+
content = item.get("content")
|
|
1034
|
+
if isinstance(content, str):
|
|
1035
|
+
content = content.encode("utf-8")
|
|
1036
|
+
elif isinstance(content, (bytearray, memoryview)):
|
|
1037
|
+
content = bytes(content)
|
|
1038
|
+
if not isinstance(content, bytes) or not content:
|
|
1039
|
+
raise ValueError(f"ctx.email: attachment {filename} needs non-empty content (bytes, or str sent as UTF-8)")
|
|
1040
|
+
content_type = item.get("content_type") or mimetypes.guess_type(filename)[0] or "application/octet-stream"
|
|
1041
|
+
if not isinstance(content_type, str) or not _EMAIL_MIME_RE.match(content_type):
|
|
1042
|
+
raise ValueError(f"ctx.email: attachment {filename} has an invalid content_type: {content_type!r}")
|
|
1043
|
+
content_id = item.get("content_id")
|
|
1044
|
+
if content_id is not None and not (isinstance(content_id, str) and _EMAIL_CONTENT_ID_RE.match(content_id)):
|
|
1045
|
+
raise ValueError(f"ctx.email: attachment {filename} content_id may use only letters, digits and ._@-")
|
|
1046
|
+
size += len(content)
|
|
1047
|
+
files.append({"filename": filename, "content": content, "content_type": content_type, "content_id": content_id})
|
|
1048
|
+
if size > EMAIL_MAX_BYTES:
|
|
1049
|
+
raise ValueError(f"ctx.email: the message is {size} bytes; bodies and attachments may total {EMAIL_MAX_BYTES}")
|
|
1050
|
+
return {
|
|
1051
|
+
"from_name": _email_name(from_name, "from_name"),
|
|
1052
|
+
"to": lists["to"],
|
|
1053
|
+
"cc": lists["cc"],
|
|
1054
|
+
"bcc": lists["bcc"],
|
|
1055
|
+
"reply_to": replies[0] if replies else None,
|
|
1056
|
+
"subject": subject,
|
|
1057
|
+
"text": bodies["text"],
|
|
1058
|
+
"html": bodies["html"],
|
|
1059
|
+
"attachments": files,
|
|
1060
|
+
"headers": clean_headers,
|
|
1061
|
+
"tags": tags,
|
|
1062
|
+
"recipients": len(seen),
|
|
1063
|
+
}
|
|
1064
|
+
# ---- end of email rules shared with palette_sdk -------------------------------
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
class LocalEmailService:
|
|
1068
|
+
"""`ctx.email` for pltt dev: checked with the hosted rules, never sent.
|
|
1069
|
+
|
|
1070
|
+
Each message is written to `outbox` as an .eml file (open it in any mail
|
|
1071
|
+
app to see the bodies, attachments and inline images) and the file comes
|
|
1072
|
+
back as `path`. Hosted, the platform's email provider sends it from the
|
|
1073
|
+
platform's address under the app's name, within a daily recipient
|
|
1074
|
+
allowance per workspace.
|
|
1075
|
+
"""
|
|
1076
|
+
|
|
1077
|
+
def __init__(self, outbox: str | Path = ".palette/dev-outbox", *, app_name: str = "Palette app"):
|
|
1078
|
+
self.outbox = Path(outbox)
|
|
1079
|
+
self.app_name = app_name
|
|
1080
|
+
|
|
1081
|
+
async def send(
|
|
1082
|
+
self,
|
|
1083
|
+
to: Any,
|
|
1084
|
+
subject: str,
|
|
1085
|
+
*,
|
|
1086
|
+
html: str | None = None,
|
|
1087
|
+
text: str | None = None,
|
|
1088
|
+
cc: Any = None,
|
|
1089
|
+
bcc: Any = None,
|
|
1090
|
+
reply_to: Any = None,
|
|
1091
|
+
from_name: str | None = None,
|
|
1092
|
+
attachments: list[dict[str, Any]] | None = None,
|
|
1093
|
+
headers: dict[str, str] | None = None,
|
|
1094
|
+
tags: list[str] | None = None,
|
|
1095
|
+
) -> dict[str, Any]:
|
|
1096
|
+
"""Same arguments, checks and errors as hosted ctx.email.send; returns
|
|
1097
|
+
{"id", "recipients", "path"} where hosted returns {"id", "recipients"}."""
|
|
1098
|
+
message = _email_message(
|
|
1099
|
+
to, subject, html=html, text=text, cc=cc, bcc=bcc, reply_to=reply_to,
|
|
1100
|
+
from_name=from_name or self.app_name, attachments=attachments, headers=headers, tags=tags,
|
|
1101
|
+
)
|
|
1102
|
+
message_id = f"local-{uuid.uuid4().hex[:16]}"
|
|
1103
|
+
mime = EmailMessage()
|
|
1104
|
+
mime["Message-ID"] = f"<{message_id}@palette.local>"
|
|
1105
|
+
mime["From"] = formataddr((message["from_name"], "no-reply@palette.local"))
|
|
1106
|
+
for header, key in (("To", "to"), ("Cc", "cc"), ("Bcc", "bcc")):
|
|
1107
|
+
if message[key]:
|
|
1108
|
+
mime[header] = ", ".join(formataddr((entry.get("name", ""), entry["email"])) for entry in message[key])
|
|
1109
|
+
if message["reply_to"]:
|
|
1110
|
+
mime["Reply-To"] = formataddr((message["reply_to"].get("name", ""), message["reply_to"]["email"]))
|
|
1111
|
+
mime["Subject"] = message["subject"]
|
|
1112
|
+
if message["tags"]:
|
|
1113
|
+
mime["X-Palette-Tags"] = ", ".join(message["tags"])
|
|
1114
|
+
for name, value in message["headers"].items():
|
|
1115
|
+
mime[name] = value
|
|
1116
|
+
if message["text"]:
|
|
1117
|
+
mime.set_content(message["text"])
|
|
1118
|
+
if message["html"]:
|
|
1119
|
+
mime.add_alternative(message["html"], subtype="html")
|
|
1120
|
+
else:
|
|
1121
|
+
mime.set_content(message["html"], subtype="html")
|
|
1122
|
+
for item in message["attachments"]:
|
|
1123
|
+
maintype, subtype = item["content_type"].split("/", 1)
|
|
1124
|
+
mime.add_attachment(
|
|
1125
|
+
item["content"],
|
|
1126
|
+
maintype=maintype,
|
|
1127
|
+
subtype=subtype,
|
|
1128
|
+
filename=item["filename"],
|
|
1129
|
+
disposition="inline" if item["content_id"] else "attachment",
|
|
1130
|
+
cid=f"<{item['content_id']}>" if item["content_id"] else None,
|
|
1131
|
+
)
|
|
1132
|
+
self.outbox.mkdir(parents=True, exist_ok=True)
|
|
1133
|
+
path = self.outbox / f"{time.strftime('%Y%m%d-%H%M%S')}-{message_id}.eml"
|
|
1134
|
+
path.write_bytes(bytes(mime))
|
|
1135
|
+
print(f"[pltt] ctx.email: {message['subject']!r} to {message['recipients']} recipient(s) saved to {path}, not sent")
|
|
1136
|
+
return {"id": message_id, "recipients": message["recipients"], "path": str(path)}
|
|
1137
|
+
|
|
1138
|
+
|
|
886
1139
|
# 1x1 transparent PNG. Enough for a stubbed render to flow through an <img>
|
|
887
1140
|
# and any "did I get a URL back" branch without a network call.
|
|
888
1141
|
_STUB_PNG = (
|
|
@@ -65,6 +65,11 @@ class PluginContext:
|
|
|
65
65
|
publishes, with the payload passed through untouched; `upload()`
|
|
66
66
|
puts private files on fal's CDN, `submit()` returns a durable
|
|
67
67
|
handle. Needs platform_services: ["media"]; no FAL_KEY of its own.
|
|
68
|
+
email: Send email through the platform's email provider —
|
|
69
|
+
`await ctx.email.send(to, subject, html=..., text=..., cc=...,
|
|
70
|
+
bcc=..., reply_to=..., from_name=..., attachments=[...],
|
|
71
|
+
headers=..., tags=...)`; from the platform's address under the
|
|
72
|
+
app's name, no SendGrid key of its own. platform_services: ["email"].
|
|
68
73
|
"""
|
|
69
74
|
db: AsyncSession
|
|
70
75
|
user_id: str
|
|
@@ -90,6 +95,8 @@ class PluginContext:
|
|
|
90
95
|
# fal.ai on the platform's key — any model, any payload, no FAL_KEY of your
|
|
91
96
|
# own. platform_services: ["media"].
|
|
92
97
|
media: Any = field(default_factory=lambda: UnavailablePlatformService("media"))
|
|
98
|
+
# The platform's email provider — platform_services: ["email"].
|
|
99
|
+
email: Any = field(default_factory=lambda: UnavailablePlatformService("email"))
|
|
93
100
|
events: EventPublisher = field(default_factory=EventPublisher)
|
|
94
101
|
jobs: JobsClient = field(default_factory=JobsClient)
|
|
95
102
|
config: dict[str, Any] = field(default_factory=dict)
|
|
@@ -183,6 +190,7 @@ async def get_plugin_context(request: Request) -> PluginContext:
|
|
|
183
190
|
llm=getattr(state, "llm", None) or UnavailablePlatformService("llm"),
|
|
184
191
|
web=getattr(state, "web", None) or UnavailablePlatformService("web"),
|
|
185
192
|
media=getattr(state, "media", None) or UnavailablePlatformService("media"),
|
|
193
|
+
email=getattr(state, "email", None) or UnavailablePlatformService("email"),
|
|
186
194
|
events=EventPublisher(getattr(state, "plugin_events", None)),
|
|
187
195
|
jobs=JobsClient(getattr(state, "plugin_jobs", None)),
|
|
188
196
|
config=getattr(state, "plugin_config", {}),
|
|
@@ -136,8 +136,9 @@ Available context values:
|
|
|
136
136
|
| `ctx.redis` | Plugin/org-scoped Redis-style service when `platform_services` includes `redis` |
|
|
137
137
|
| `ctx.vector` | Plugin/org-scoped vector service when `platform_services` includes `vector` |
|
|
138
138
|
| `ctx.llm` | The platform's own model keys, billed to the workspace's credits, when `platform_services` includes `llm` |
|
|
139
|
-
| `ctx.web` | Web search + SSRF-guarded page reader when `platform_services` includes `web` |
|
|
139
|
+
| `ctx.web` | Web search + SSRF-guarded page reader (`fetch(url, render=True)` for pages built by their scripts) when `platform_services` includes `web` |
|
|
140
140
|
| `ctx.media` | fal.ai on the platform's key — any model, any payload — when `platform_services` includes `media` |
|
|
141
|
+
| `ctx.email` | Send email through the platform's provider (to/cc/bcc, html + text, reply_to, attachments, inline images, headers, tags) when `platform_services` includes `email` |
|
|
141
142
|
| `ctx.config` | App install/config values |
|
|
142
143
|
| `ctx.logger` | Runtime logger for backend code |
|
|
143
144
|
| `ctx.repo(Model)` | Org-safe CRUD helper for app-owned tables |
|
|
@@ -171,9 +172,9 @@ These are the public Python helpers exported by `palette_sdk`.
|
|
|
171
172
|
| `ensure_org_rls(op, table)` | Alembic helper that enables org row-level security |
|
|
172
173
|
| `plugin_safe_id(...)`, `plugin_schema(...)`, `plugin_table_prefix(...)` | Manifest id to database-safe naming helpers |
|
|
173
174
|
| `get_config(ctx, key)`, `require_config(ctx, key)` | Functional form of config reads when not using `ctx.config_value(...)` |
|
|
174
|
-
| `ctx.llm`, `ctx.media`, `ctx.web` | The platform's model, fal.ai
|
|
175
|
+
| `ctx.llm`, `ctx.media`, `ctx.web`, `ctx.email` | The platform's model, fal.ai, web-search and email-provider keys, declared in `platform_services` |
|
|
175
176
|
| `MediaStillRunning` | `ctx.media.run` gave up waiting; carries `request_id` to collect the render later |
|
|
176
|
-
| `LocalLLMService`, `LocalMediaService`, `LocalWebService`, `LocalRedisService`, `LocalVectorService`, `LocalStorageService` | Local `pltt dev` service emulators and test fakes |
|
|
177
|
+
| `LocalLLMService`, `LocalMediaService`, `LocalWebService`, `LocalEmailService`, `LocalRedisService`, `LocalVectorService`, `LocalStorageService` | Local `pltt dev` service emulators and test fakes |
|
|
177
178
|
| `McpClient`, `mcp_tool(...)`, `mcp_resource(...)`, `mcp_prompt(...)` | Provide and consume MCP tools, resources and prompts |
|
|
178
179
|
| `PlatformServiceUnavailable`, `UnavailablePlatformService` | Clear errors when an undeclared platform service is used |
|
|
179
180
|
| `LifecycleHooks` | Install/update/enable/disable/uninstall callbacks |
|
|
@@ -898,7 +899,7 @@ declaration for you:
|
|
|
898
899
|
|
|
899
900
|
```json
|
|
900
901
|
{
|
|
901
|
-
"platform_services": ["llm", "media", "redis", "storage", "vector", "web"]
|
|
902
|
+
"platform_services": ["email", "llm", "media", "redis", "storage", "vector", "web"]
|
|
902
903
|
}
|
|
903
904
|
```
|
|
904
905
|
|
|
@@ -970,6 +971,24 @@ state = await ctx.media.status(job["request_id"], model=job["model"])
|
|
|
970
971
|
# Web search + reader (HTML tables and PDFs already handled).
|
|
971
972
|
hits = await ctx.web.search("palette os changelog", limit=5)
|
|
972
973
|
text = await ctx.web.fetch("https://example.com/report.pdf")
|
|
974
|
+
# render=True loads the page in a browser first, for content its scripts build
|
|
975
|
+
# late (a shop page's size table). Tens of seconds; ignored in pltt dev.
|
|
976
|
+
page = await ctx.web.fetch("https://shop.example/product/123", render=True)
|
|
977
|
+
|
|
978
|
+
# Email through the platform's provider, from its sender address under the app's name.
|
|
979
|
+
# Recipients: "a@x.com", "Ann <a@x.com>", {"email", "name"} or a list (50 max across to/cc/bcc).
|
|
980
|
+
# Attachments: bytes or str (UTF-8), optional content_type; content_id = inline <img src="cid:...">.
|
|
981
|
+
# ValueError = the message is wrong; PlatformServiceUnavailable = daily allowance used up or provider down.
|
|
982
|
+
await ctx.email.send(
|
|
983
|
+
["Ann <ann@example.com>"], "Invoice 42",
|
|
984
|
+
html='<p>Attached.</p><img src="cid:logo">', text="Attached.",
|
|
985
|
+
cc="finance@example.com", bcc=["audit@acme.io"], reply_to="billing@acme.io", from_name="Acme Billing",
|
|
986
|
+
attachments=[
|
|
987
|
+
{"filename": "invoice-42.pdf", "content": pdf_bytes},
|
|
988
|
+
{"filename": "logo.png", "content": logo_bytes, "content_id": "logo"},
|
|
989
|
+
],
|
|
990
|
+
headers={"X-Invoice-Id": "42"}, tags=["invoice"],
|
|
991
|
+
) # pltt dev: nothing is sent; the message is saved to .palette/dev-outbox/*.eml
|
|
973
992
|
|
|
974
993
|
await ctx.redis.set("cache:summary", {"ready": True}, ttl=600)
|
|
975
994
|
value = await ctx.redis.get("cache:summary")
|
|
@@ -1000,6 +1019,34 @@ Under `pltt dev` there is no platform, so these run against your own
|
|
|
1000
1019
|
deterministic stubs when it does not — the app's code path is exercisable with
|
|
1001
1020
|
zero setup either way. `pltt doctor` prints which mode each service is in.
|
|
1002
1021
|
|
|
1022
|
+
### Email — `ctx.email`
|
|
1023
|
+
|
|
1024
|
+
`await ctx.email.send(to, subject, *, html=None, text=None, cc=None, bcc=None,
|
|
1025
|
+
reply_to=None, from_name=None, attachments=None, headers=None, tags=None)`
|
|
1026
|
+
sends one email through the platform's email provider and returns
|
|
1027
|
+
`{"id": <provider message id>, "recipients": <n>}`.
|
|
1028
|
+
|
|
1029
|
+
| Argument | Accepts |
|
|
1030
|
+
|---|---|
|
|
1031
|
+
| `to`, `cc`, `bcc` | `"a@x.com"`, `"Ann <a@x.com>"`, `{"email": ..., "name": ...}`, or a list of those; at most 50 across all three, an address repeated across them is sent once, commas and semicolons are dropped from names |
|
|
1032
|
+
| `subject` | One line, required |
|
|
1033
|
+
| `html`, `text` | Either or both; `text` is the plain-text alternative |
|
|
1034
|
+
| `reply_to` | One address, in any recipient form |
|
|
1035
|
+
| `from_name` | Display name; defaults to the app's name. The address is always the platform's sender |
|
|
1036
|
+
| `attachments` | `[{"filename", "content", "content_type"?, "content_id"?}]` — `content` is bytes, or a str sent as UTF-8; `content_type` is guessed from the filename; `content_id` makes the file inline for `<img src="cid:...">`. Executables (`.exe`, `.js`, `.bat`, ...) are refused |
|
|
1037
|
+
| `headers` | Custom headers such as `List-Unsubscribe` or `X-...`; `From`, `To`, `Subject`, `Reply-To`, `Content-Type` and the other headers the provider sets are refused |
|
|
1038
|
+
| `tags` | Up to 10 ASCII labels kept with the message at the provider |
|
|
1039
|
+
|
|
1040
|
+
Bodies and attachments together stay under 10 MB. `ValueError` means the
|
|
1041
|
+
message itself is wrong — nothing is sent or counted. `PlatformServiceUnavailable`
|
|
1042
|
+
means it cannot go out now: the app's daily recipient allowance in this
|
|
1043
|
+
workspace is used up (200 per UTC day unless the platform sets another), or the
|
|
1044
|
+
platform's provider is not configured or unreachable. Email is not billed to
|
|
1045
|
+
credits, and it is backend only. Under `pltt dev` nothing is sent:
|
|
1046
|
+
`LocalEmailService` checks each message with the same rules, saves it to
|
|
1047
|
+
`.palette/dev-outbox/` as an `.eml` file and returns its `path` as well;
|
|
1048
|
+
`pltt dev --sandbox` sends for real from a hosted preview.
|
|
1049
|
+
|
|
1003
1050
|
## 10. Managed Connections
|
|
1004
1051
|
|
|
1005
1052
|
Declare third-party OAuth or API-key connections in `palette-plugin.json`.
|
package/lib/cli.js
CHANGED
|
@@ -19,6 +19,7 @@ const capabilities = require("./commands/capabilities")
|
|
|
19
19
|
const connections = require("./commands/connections")
|
|
20
20
|
const platform = require("./commands/platform")
|
|
21
21
|
const models = require("./commands/models")
|
|
22
|
+
const categories = require("./commands/categories")
|
|
22
23
|
const agent = require("./commands/agent")
|
|
23
24
|
const check = require("./commands/check")
|
|
24
25
|
|
|
@@ -77,6 +78,10 @@ const COMMANDS = {
|
|
|
77
78
|
run: models,
|
|
78
79
|
help: "List the chat/image/video/audio models this app can use in your workspace (ids, limits, why not)",
|
|
79
80
|
},
|
|
81
|
+
categories: {
|
|
82
|
+
run: categories,
|
|
83
|
+
help: "List the App Store categories a manifest can name; anything else is filed under Other",
|
|
84
|
+
},
|
|
80
85
|
services: {
|
|
81
86
|
run: services,
|
|
82
87
|
help: "Inspect / pull / scaffold OS-broker services (list, pull, scaffold)",
|
|
@@ -105,7 +110,7 @@ function printHelp() {
|
|
|
105
110
|
console.log(` ${name.padEnd(12)} ${help}`)
|
|
106
111
|
}
|
|
107
112
|
console.log("\nGlobal flags:")
|
|
108
|
-
console.log(" --json Emit machine-readable JSON output (status, logs, package, publish, test, check, update, version, login, dev --sandbox, platform, models, services, capabilities)")
|
|
113
|
+
console.log(" --json Emit machine-readable JSON output (status, logs, package, publish, test, check, update, version, login, dev --sandbox, platform, models, categories, services, capabilities)")
|
|
109
114
|
console.log(" -v, --version Show the installed pltt CLI version")
|
|
110
115
|
console.log("\nPublish flags:")
|
|
111
116
|
console.log(" --env <name> Target environment from ~/.palette/config.json (default: local)")
|
|
@@ -125,7 +130,7 @@ function printHelp() {
|
|
|
125
130
|
console.log(" --tail <n> Tail last n events (default 50)")
|
|
126
131
|
console.log(" -f, --follow Stream events (poll every 3s)")
|
|
127
132
|
console.log("\nPlatform services (ctx.* — the platform's own credentials):")
|
|
128
|
-
console.log(" pltt platform list # llm, media, storage, vector, redis, web")
|
|
133
|
+
console.log(" pltt platform list # llm, media, storage, vector, redis, web, email")
|
|
129
134
|
console.log(" pltt platform enable llm media # declare them in palette-plugin.json")
|
|
130
135
|
console.log(" pltt platform disable web")
|
|
131
136
|
console.log("\nModels (what ctx.llm / ctx.media will run for this app):")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
const { parseFlags, resolveEnvironment } = require("../environments")
|
|
4
|
+
|
|
5
|
+
// Superadmins keep the store's categories on the platform, so the list is
|
|
6
|
+
// read from it, never shipped with the CLI. A manifest `category` that names
|
|
7
|
+
// none of them (or no category at all) is filed under Other at publish.
|
|
8
|
+
async function run(argv, { cwd, log = console.log } = {}) {
|
|
9
|
+
const { flags } = parseFlags(argv)
|
|
10
|
+
const env = resolveEnvironment({ cwd, flags })
|
|
11
|
+
const url = `${env.url}/api/v1/appstore/categories`
|
|
12
|
+
const res = await fetch(url)
|
|
13
|
+
if (!res.ok) throw new Error(`GET ${url} → ${res.status}: ${await res.text()}`)
|
|
14
|
+
const { categories } = await res.json()
|
|
15
|
+
if (flags.json) {
|
|
16
|
+
log(JSON.stringify({ categories }, null, 2))
|
|
17
|
+
return categories
|
|
18
|
+
}
|
|
19
|
+
log(`App Store categories on ${env.name} (set "category" in palette-plugin.json to one of them):`)
|
|
20
|
+
for (const name of categories) log(` ${name}`)
|
|
21
|
+
log('Any other value, or none, is filed under "Other". A superadmin can move the app at any time.')
|
|
22
|
+
return categories
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = run
|
package/lib/commands/doctor.js
CHANGED
|
@@ -63,7 +63,8 @@ function reportPlatformServices(manifest, cwd) {
|
|
|
63
63
|
ok(`manifest declares ${names.length} platform service(s): ${names.join(", ")}`)
|
|
64
64
|
for (const name of names) {
|
|
65
65
|
const note = PLATFORM_SERVICE_DEV_NOTES[name]
|
|
66
|
-
|
|
66
|
+
const dev = note ? note(cwd) : PLATFORM_SERVICES.find((service) => service.name === name)?.dev
|
|
67
|
+
if (dev) console.log(` ctx.${name} — ${dev}`)
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
package/lib/commands/platform.js
CHANGED
|
@@ -37,7 +37,7 @@ function list(manifest, cwd, json) {
|
|
|
37
37
|
const rows = PLATFORM_SERVICES.map((service) => ({
|
|
38
38
|
...service,
|
|
39
39
|
declared: on.has(service.name),
|
|
40
|
-
dev: devNote(service.name, cwd),
|
|
40
|
+
dev: service.dev || devNote(service.name, cwd),
|
|
41
41
|
}))
|
|
42
42
|
// The other half of what `ctx` can do: clients switched on by a manifest
|
|
43
43
|
// permission rather than by platform_services. Printing them together is the
|
|
@@ -106,7 +106,8 @@ function enable(cwd, names) {
|
|
|
106
106
|
console.log(`[pltt] ${service.accessor} enabled — ${service.summary}`)
|
|
107
107
|
if (service.python) console.log(` ${service.python}`)
|
|
108
108
|
const key = DEV_KEYS[name]
|
|
109
|
-
if (
|
|
109
|
+
if (service.dev) console.log(` ${service.dev}`)
|
|
110
|
+
else if (key) console.log(` pltt dev stubs this unless ${key} is in .env.local`)
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
package/lib/commands/publish.js
CHANGED
|
@@ -503,6 +503,13 @@ async function run(argv, { cwd }) {
|
|
|
503
503
|
if (record.review_url && record.status !== "active") {
|
|
504
504
|
console.log(`[pltt] review queue: ${record.review_url}`)
|
|
505
505
|
}
|
|
506
|
+
// Where the store filed the app: a manifest category that names no store
|
|
507
|
+
// category lands in Other (older platforms send neither field).
|
|
508
|
+
if (record.category_note) {
|
|
509
|
+
console.log(`[pltt] ${record.category_note}`)
|
|
510
|
+
} else if (record.category) {
|
|
511
|
+
console.log(`[pltt] store category: ${record.category}`)
|
|
512
|
+
}
|
|
506
513
|
if (record.preview_url) {
|
|
507
514
|
console.log(`[pltt] preview: ${record.preview_url}`)
|
|
508
515
|
}
|
package/lib/dev-simulator.js
CHANGED
|
@@ -222,6 +222,7 @@ DEV_STORAGE = None
|
|
|
222
222
|
DEV_LLM = None
|
|
223
223
|
DEV_WEB = None
|
|
224
224
|
DEV_MEDIA = None
|
|
225
|
+
DEV_EMAIL = None
|
|
225
226
|
if _service_enabled("llm"):
|
|
226
227
|
from palette_sdk.platform_services import LocalLLMService
|
|
227
228
|
DEV_LLM = LocalLLMService(DEV_SECRETS.get("OPENAI_API_KEY") or os.environ.get("OPENAI_API_KEY", ""))
|
|
@@ -229,6 +230,10 @@ if _service_enabled("llm"):
|
|
|
229
230
|
if _service_enabled("web"):
|
|
230
231
|
from palette_sdk.platform_services import LocalWebService
|
|
231
232
|
DEV_WEB = LocalWebService()
|
|
233
|
+
if _service_enabled("email"):
|
|
234
|
+
from palette_sdk.platform_services import LocalEmailService
|
|
235
|
+
DEV_EMAIL = LocalEmailService(ROOT / ".palette" / "dev-outbox", app_name=MANIFEST.get("name") or MANIFEST.get("id", ""))
|
|
236
|
+
print("[pltt] ctx.email: messages are saved to .palette/dev-outbox as .eml files, not sent")
|
|
232
237
|
if _service_enabled("redis"):
|
|
233
238
|
from palette_sdk.platform_services import LocalRedisService
|
|
234
239
|
DEV_REDIS = LocalRedisService()
|
|
@@ -542,6 +547,8 @@ def _local_job_context(session):
|
|
|
542
547
|
extra["talk"] = TalkClient(TALK, MANIFEST.get("permissions", []))
|
|
543
548
|
if "media" in getattr(PluginContext, "__dataclass_fields__", {}):
|
|
544
549
|
extra["media"] = DEV_MEDIA or UnavailablePlatformService("media")
|
|
550
|
+
if "email" in getattr(PluginContext, "__dataclass_fields__", {}):
|
|
551
|
+
extra["email"] = DEV_EMAIL or UnavailablePlatformService("email")
|
|
545
552
|
if "user_name" in getattr(PluginContext, "__dataclass_fields__", {}):
|
|
546
553
|
extra["user_name"] = "Palette Developer"
|
|
547
554
|
|
|
@@ -644,6 +651,7 @@ class DevPluginContextMiddleware(BaseHTTPMiddleware):
|
|
|
644
651
|
request.state.llm = DEV_LLM
|
|
645
652
|
request.state.web = DEV_WEB
|
|
646
653
|
request.state.media = DEV_MEDIA
|
|
654
|
+
request.state.email = DEV_EMAIL
|
|
647
655
|
request.state.plugin_local_connections = DEV_CONNECTIONS
|
|
648
656
|
request.state.plugin_apps = LocalAppInteropService()
|
|
649
657
|
request.state.plugin_events = LocalEventPublisher()
|
package/lib/manifest.js
CHANGED
|
@@ -291,10 +291,18 @@ const PLATFORM_SERVICES = [
|
|
|
291
291
|
{
|
|
292
292
|
name: "web",
|
|
293
293
|
accessor: "ctx.web",
|
|
294
|
-
summary: "Web search plus an SSRF-guarded page reader (HTML tables, PDFs)",
|
|
294
|
+
summary: "Web search plus an SSRF-guarded page reader (HTML tables, PDFs; render=True for pages built by scripts)",
|
|
295
295
|
python: 'hits = await ctx.web.search("fx rates", limit=5)',
|
|
296
296
|
instead_of: "TAVILY_API_KEY / SERPAPI_KEY",
|
|
297
297
|
},
|
|
298
|
+
{
|
|
299
|
+
name: "email",
|
|
300
|
+
accessor: "ctx.email",
|
|
301
|
+
summary: "Send email through the platform's provider — to/cc/bcc, html + text, reply_to, attachments and inline images, headers, tags",
|
|
302
|
+
python: 'await ctx.email.send("ann@acme.com", "Your invoice", html=body, attachments=[{"filename": "invoice.pdf", "content": pdf}])',
|
|
303
|
+
instead_of: "SENDGRID_API_KEY / SMTP credentials + a verified sender domain",
|
|
304
|
+
dev: "pltt dev: checked like hosted, saved to .palette/dev-outbox as .eml — nothing is sent",
|
|
305
|
+
},
|
|
298
306
|
]
|
|
299
307
|
|
|
300
308
|
function validatePlatformServices(value, errors) {
|
|
@@ -815,6 +823,8 @@ function validateManifest(m) {
|
|
|
815
823
|
errors.push("data_scope must be personal or organization")
|
|
816
824
|
}
|
|
817
825
|
requireString(m, "developer", "manifest", errors)
|
|
826
|
+
// Superadmins keep the store's categories on the platform (`pltt categories`), so
|
|
827
|
+
// the value is checked at publish: one that names none is filed under Other.
|
|
818
828
|
requireString(m, "category", "manifest", errors)
|
|
819
829
|
requireString(m, "tagline", "manifest", errors)
|
|
820
830
|
requireString(m, "description", "manifest", errors)
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@ pltt package --json
|
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
See what the platform already gives your app before adding an API key or a
|
|
12
|
-
dependency — models, fal.ai media, web search, storage, vector and redis
|
|
13
|
-
available through `ctx.*` on the platform's own credentials:
|
|
12
|
+
dependency — models, fal.ai media, web search, email, storage, vector and redis
|
|
13
|
+
are all available through `ctx.*` on the platform's own credentials:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
pltt platform list # every service + a snippet, and its pltt dev mode
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"name": "My Agent Tool",
|
|
6
6
|
"version": "1.0.0",
|
|
7
7
|
"developer": "Your Team",
|
|
8
|
-
"category": "
|
|
8
|
+
"category": "Productivity",
|
|
9
9
|
"tagline": "A tool an agent can call",
|
|
10
10
|
"description": "Registers a callable tool that any agent in the org can invoke.",
|
|
11
11
|
"icon": "Toolbox",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"name": "My External Service",
|
|
6
6
|
"version": "1.0.0",
|
|
7
7
|
"developer": "Your Team",
|
|
8
|
-
"category": "
|
|
8
|
+
"category": "Productivity",
|
|
9
9
|
"tagline": "Calls a third-party API",
|
|
10
10
|
"description": "Demonstrates declared external_network access and a scoped per-org config token.",
|
|
11
11
|
"icon": "CloudArrowUp",
|