@palettelab/cli 0.3.61 → 0.3.62
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 +8 -2
- package/backend-sdk/palette_sdk/__init__.py +19 -1
- package/backend-sdk/palette_sdk/capabilities.py +126 -0
- package/backend-sdk/palette_sdk/manifest.py +63 -1
- package/backend-sdk/palette_sdk/services.py +45 -6
- package/lib/cli.js +14 -1
- package/lib/commands/capabilities.js +151 -0
- package/lib/commands/init.js +3 -2
- package/lib/commands/services.js +74 -8
- package/lib/commands/test.js +89 -1
- package/lib/manifest.js +74 -2
- package/package.json +1 -1
- package/template-fallback/package.json +1 -1
- package/template-fallback/templates/agent-tool/README.md +6 -2
- package/template-fallback/templates/agent-tool/backend/api/main.py +27 -6
- package/template-fallback/templates/agent-tool/palette-plugin.json +35 -4
- package/template-fallback/templates/consumer-app/package.json +1 -1
- package/template-fallback/templates/dashboard/package.json +1 -1
- package/template-fallback/templates/database/package.json +1 -1
- package/template-fallback/templates/external-service/package.json +1 -1
- package/template-fallback/templates/frontend-only/package.json +1 -1
- package/template-fallback/templates/next/package.json +1 -1
- package/template-fallback/templates/palette-app/package.json +1 -1
- package/template-fallback/templates/provider-app/package.json +1 -1
- package/template-fallback/templates/agent-tool/backend/tools/echo.py +0 -15
package/README.md
CHANGED
|
@@ -329,7 +329,10 @@ Backend SDK features for app-owned data:
|
|
|
329
329
|
- `plugin_safe_id(...)`, `plugin_schema(...)`, `plugin_table_prefix(...)`, and `ensure_org_rls(...)` keep database names and row-level security consistent.
|
|
330
330
|
- `Event` and `subscribe_event(...)` register in-process platform event handlers.
|
|
331
331
|
- `sign_webhook(...)` and `verify_webhook_signature(...)` handle HMAC-SHA256 webhook signing checks.
|
|
332
|
-
- `
|
|
332
|
+
- `@capability(...)`, `CapabilityResult`, and `ArtifactRef` define typed,
|
|
333
|
+
broker-governed tools shared by chat agents and visual workflows.
|
|
334
|
+
- `ToolDefinition` is legacy compatibility for existing read-only tools;
|
|
335
|
+
migrate new tools to `@capability(...)`.
|
|
333
336
|
- `PluginManifest` and `load_manifest(...)` parse and validate `palette-plugin.json`.
|
|
334
337
|
- `SuccessResponse`, `ErrorResponse`, and `PaginatedResponse` are reusable response schemas.
|
|
335
338
|
- `route_permission_issues(router, public_routes=None)` is the test helper for detecting ungated backend routes.
|
|
@@ -942,13 +945,16 @@ pltt services mock hr/v1#approvalChain.get
|
|
|
942
945
|
pltt services test --offline
|
|
943
946
|
pltt services pull --env staging
|
|
944
947
|
pltt services scaffold approvalChain.get
|
|
948
|
+
pltt capabilities add creative.poster.generate --method poster.generate --risk write --effects artifact.create --idempotent
|
|
949
|
+
pltt capabilities list
|
|
950
|
+
pltt test --agent
|
|
945
951
|
```
|
|
946
952
|
|
|
947
953
|
Subcommands:
|
|
948
954
|
|
|
949
955
|
- `list`: fetches `/api/v1/os-broker/catalog` from the selected environment and prints services/events available to the current org. Use `--json` for the raw catalog.
|
|
950
956
|
- `add <namespace/version#name>`: appends a consumed service target to `consumes.services`. Use `--event` or `--type event` for `consumes.events`, `--optional` for non-required dependencies, and `--reason <text>` to record why the dependency is needed.
|
|
951
|
-
- `sync`: scans backend `@service(...)` decorators and updates `provides.services` so provider contracts do not drift from code.
|
|
957
|
+
- `sync`: scans backend `@service(...)` and `@capability(...)` decorators and updates `provides.services` so provider contracts do not drift from code.
|
|
952
958
|
- `mock <namespace/version#name>`: adds a local response to `.palette/app-services.local.json` for `pltt dev`.
|
|
953
959
|
- `test`: checks local consumes/provides/mocks and, unless `--offline` is set, verifies consumed targets against `/api/v1/os-broker/schemas`.
|
|
954
960
|
- `pull`: reads `consumes.services` and `consumes.events`, fetches JSON Schemas from `/api/v1/os-broker/schemas`, and generates nested `.palette/types/services.ts` plus Python helpers in `.palette/python/services.py`.
|
|
@@ -18,6 +18,16 @@ from palette_sdk.repository import OrgRepository
|
|
|
18
18
|
from palette_sdk.lifecycle import LifecycleHooks
|
|
19
19
|
from palette_sdk.jobs import JobCancelledError, JobExecution, JobHandle, JobsClient, job
|
|
20
20
|
from palette_sdk.tool_definition import ToolDefinition
|
|
21
|
+
from palette_sdk.capabilities import (
|
|
22
|
+
ApprovalRequired,
|
|
23
|
+
ArtifactRef,
|
|
24
|
+
CapabilityError,
|
|
25
|
+
CapabilityResult,
|
|
26
|
+
ConnectionRequired,
|
|
27
|
+
RateLimited,
|
|
28
|
+
RetryableError,
|
|
29
|
+
capability,
|
|
30
|
+
)
|
|
21
31
|
from palette_sdk.manifest import PluginManifest, load_manifest
|
|
22
32
|
from palette_sdk.schemas import (
|
|
23
33
|
SuccessResponse,
|
|
@@ -81,6 +91,14 @@ __all__ = [
|
|
|
81
91
|
"JobsClient",
|
|
82
92
|
"job",
|
|
83
93
|
"ToolDefinition",
|
|
94
|
+
"capability",
|
|
95
|
+
"ArtifactRef",
|
|
96
|
+
"CapabilityResult",
|
|
97
|
+
"CapabilityError",
|
|
98
|
+
"ConnectionRequired",
|
|
99
|
+
"ApprovalRequired",
|
|
100
|
+
"RateLimited",
|
|
101
|
+
"RetryableError",
|
|
84
102
|
"PluginManifest",
|
|
85
103
|
"load_manifest",
|
|
86
104
|
"SuccessResponse",
|
|
@@ -118,4 +136,4 @@ __all__ = [
|
|
|
118
136
|
"LocalStorageService",
|
|
119
137
|
]
|
|
120
138
|
|
|
121
|
-
__version__ = "0.1.
|
|
139
|
+
__version__ = "0.1.12"
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""Typed agent capability contracts for Palette apps."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any, Callable, Literal
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
|
+
|
|
10
|
+
from palette_sdk.services import ServiceHandler, service
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ArtifactRef(BaseModel):
|
|
14
|
+
"""Portable reference to an artifact stored by Palette or an installed app."""
|
|
15
|
+
|
|
16
|
+
id: str
|
|
17
|
+
uri: str
|
|
18
|
+
name: str
|
|
19
|
+
mime_type: str
|
|
20
|
+
kind: str = "file"
|
|
21
|
+
revision: str | None = None
|
|
22
|
+
size_bytes: int | None = None
|
|
23
|
+
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CapabilityResult(BaseModel):
|
|
27
|
+
"""Standard result envelope understood by agents and workflow nodes."""
|
|
28
|
+
|
|
29
|
+
data: Any = None
|
|
30
|
+
artifacts: list[ArtifactRef] = Field(default_factory=list)
|
|
31
|
+
citations: list[str] = Field(default_factory=list)
|
|
32
|
+
warnings: list[str] = Field(default_factory=list)
|
|
33
|
+
continuation: dict[str, Any] | None = None
|
|
34
|
+
telemetry: dict[str, Any] = Field(default_factory=dict)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class CapabilityError(RuntimeError):
|
|
38
|
+
code = "capability_error"
|
|
39
|
+
retryable = False
|
|
40
|
+
|
|
41
|
+
def __init__(self, message: str, *, details: dict[str, Any] | None = None):
|
|
42
|
+
super().__init__(message)
|
|
43
|
+
self.details = details or {}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ConnectionRequired(CapabilityError):
|
|
47
|
+
code = "connection_required"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class ApprovalRequired(CapabilityError):
|
|
51
|
+
code = "approval_required"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class RateLimited(CapabilityError):
|
|
55
|
+
code = "rate_limited"
|
|
56
|
+
retryable = True
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class RetryableError(CapabilityError):
|
|
60
|
+
code = "retryable"
|
|
61
|
+
retryable = True
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def capability(
|
|
65
|
+
name: str,
|
|
66
|
+
*,
|
|
67
|
+
capability_id: str,
|
|
68
|
+
scope: str | None = None,
|
|
69
|
+
version: str | None = None,
|
|
70
|
+
label: str | None = None,
|
|
71
|
+
description: str | None = None,
|
|
72
|
+
input_schema: dict | str | None = None,
|
|
73
|
+
output_schema: dict | str | None = None,
|
|
74
|
+
effects: list[str] | None = None,
|
|
75
|
+
risk: Literal["read", "write", "destructive", "controlled"] = "read",
|
|
76
|
+
supports_scheduling: bool = True,
|
|
77
|
+
idempotent: bool = False,
|
|
78
|
+
timeout_seconds: int = 60,
|
|
79
|
+
tags: list[str] | None = None,
|
|
80
|
+
artifact_inputs: list[str] | None = None,
|
|
81
|
+
artifact_outputs: list[str] | None = None,
|
|
82
|
+
examples: list[dict[str, Any]] | None = None,
|
|
83
|
+
cost_class: Literal["low", "medium", "high"] | None = None,
|
|
84
|
+
latency_class: Literal["interactive", "background", "long_running"] | None = None,
|
|
85
|
+
deprecated: bool = False,
|
|
86
|
+
replacement: str | None = None,
|
|
87
|
+
) -> Callable[[ServiceHandler], ServiceHandler]:
|
|
88
|
+
"""Declare a broker service that agents and visual workflows may call.
|
|
89
|
+
|
|
90
|
+
The matching provides.services method in the manifest remains the reviewed
|
|
91
|
+
publish contract. pltt test --agent verifies decorator/manifest parity.
|
|
92
|
+
"""
|
|
93
|
+
if not re.match(r"^[a-z][a-z0-9_-]*(?:\.[a-z0-9_-]+)+$", capability_id):
|
|
94
|
+
raise ValueError("capability_id must be a stable dotted lowercase id")
|
|
95
|
+
if not description or input_schema is None:
|
|
96
|
+
raise ValueError("agent capabilities require description and input_schema")
|
|
97
|
+
if not effects:
|
|
98
|
+
raise ValueError("agent capabilities require at least one declared effect")
|
|
99
|
+
if risk in {"write", "destructive"} and supports_scheduling and not idempotent:
|
|
100
|
+
raise ValueError(
|
|
101
|
+
"scheduled write capabilities must be idempotent or disable scheduling"
|
|
102
|
+
)
|
|
103
|
+
return service(
|
|
104
|
+
name,
|
|
105
|
+
scope=scope,
|
|
106
|
+
version=version,
|
|
107
|
+
label=label,
|
|
108
|
+
description=description,
|
|
109
|
+
input_schema=input_schema,
|
|
110
|
+
output_schema=output_schema,
|
|
111
|
+
agent_exposable=True,
|
|
112
|
+
capability_id=capability_id,
|
|
113
|
+
effects=effects or [],
|
|
114
|
+
risk=risk,
|
|
115
|
+
supports_scheduling=supports_scheduling,
|
|
116
|
+
idempotent=idempotent,
|
|
117
|
+
timeout_seconds=timeout_seconds,
|
|
118
|
+
tags=tags or [],
|
|
119
|
+
artifact_inputs=artifact_inputs or [],
|
|
120
|
+
artifact_outputs=artifact_outputs or [],
|
|
121
|
+
examples=examples or [],
|
|
122
|
+
cost_class=cost_class,
|
|
123
|
+
latency_class=latency_class,
|
|
124
|
+
deprecated=deprecated,
|
|
125
|
+
replacement=replacement,
|
|
126
|
+
)
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
+
import re
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
from typing import Any, Literal
|
|
8
9
|
|
|
9
|
-
from pydantic import AliasChoices, BaseModel, ConfigDict, Field
|
|
10
|
+
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, model_validator
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class AgentDefinition(BaseModel):
|
|
@@ -113,8 +114,38 @@ class AppServiceMethodSpec(BaseModel):
|
|
|
113
114
|
output: dict[str, Any] | str | None = None
|
|
114
115
|
route_method: Literal["GET", "POST", "PUT", "PATCH", "DELETE"] | None = None
|
|
115
116
|
route_path: str | None = None
|
|
117
|
+
annotations: dict[str, Any] | None = None
|
|
118
|
+
capability_id: str | None = None
|
|
119
|
+
supports_scheduling: bool = True
|
|
120
|
+
agent_exposable: bool = False
|
|
116
121
|
deprecated: bool = False
|
|
117
122
|
replacement: str | None = None
|
|
123
|
+
effects: list[str] = Field(default_factory=list)
|
|
124
|
+
risk: Literal["read", "write", "destructive", "controlled"] = "read"
|
|
125
|
+
idempotent: bool = False
|
|
126
|
+
timeout_seconds: int = Field(default=60, ge=1, le=7200)
|
|
127
|
+
tags: list[str] = Field(default_factory=list)
|
|
128
|
+
artifact_inputs: list[str] = Field(default_factory=list)
|
|
129
|
+
artifact_outputs: list[str] = Field(default_factory=list)
|
|
130
|
+
examples: list[dict[str, Any]] = Field(default_factory=list)
|
|
131
|
+
cost_class: Literal["low", "medium", "high"] | None = None
|
|
132
|
+
latency_class: Literal["interactive", "background", "long_running"] | None = None
|
|
133
|
+
|
|
134
|
+
@model_validator(mode="after")
|
|
135
|
+
def validate_agent_contract(self):
|
|
136
|
+
if not self.agent_exposable:
|
|
137
|
+
return self
|
|
138
|
+
if not self.capability_id or not re.match(
|
|
139
|
+
r"^[a-z][a-z0-9_-]*(?:\.[a-z0-9_-]+)+$", self.capability_id
|
|
140
|
+
):
|
|
141
|
+
raise ValueError("agent-exposable methods require a stable dotted capability_id")
|
|
142
|
+
if not self.description.strip() or self.input_schema is None and self.input is None:
|
|
143
|
+
raise ValueError("agent-exposable methods require description and input_schema")
|
|
144
|
+
if not self.effects:
|
|
145
|
+
raise ValueError("agent-exposable methods require at least one declared effect")
|
|
146
|
+
if self.risk in {"write", "destructive"} and self.supports_scheduling and not self.idempotent:
|
|
147
|
+
raise ValueError("scheduled write capabilities must be idempotent")
|
|
148
|
+
return self
|
|
118
149
|
|
|
119
150
|
|
|
120
151
|
class ProvidedAppServiceSpec(BaseModel):
|
|
@@ -197,6 +228,37 @@ class McpToolSpec(BaseModel):
|
|
|
197
228
|
annotations: dict[str, Any] | None = None # readOnlyHint / destructiveHint ...
|
|
198
229
|
scope: str | None = None
|
|
199
230
|
expose_external: bool = False
|
|
231
|
+
agent_exposable: bool = False
|
|
232
|
+
capability_id: str | None = None
|
|
233
|
+
supports_scheduling: bool = True
|
|
234
|
+
effects: list[str] = Field(default_factory=list)
|
|
235
|
+
risk: Literal["read", "write", "destructive", "controlled"] = "read"
|
|
236
|
+
idempotent: bool = False
|
|
237
|
+
timeout_seconds: int = Field(default=60, ge=1, le=7200)
|
|
238
|
+
tags: list[str] = Field(default_factory=list)
|
|
239
|
+
artifact_inputs: list[str] = Field(default_factory=list)
|
|
240
|
+
artifact_outputs: list[str] = Field(default_factory=list)
|
|
241
|
+
examples: list[dict[str, Any]] = Field(default_factory=list)
|
|
242
|
+
cost_class: Literal["low", "medium", "high"] | None = None
|
|
243
|
+
latency_class: Literal["interactive", "background", "long_running"] | None = None
|
|
244
|
+
deprecated: bool = False
|
|
245
|
+
replacement: str | None = None
|
|
246
|
+
|
|
247
|
+
@model_validator(mode="after")
|
|
248
|
+
def validate_agent_contract(self):
|
|
249
|
+
if not self.agent_exposable:
|
|
250
|
+
return self
|
|
251
|
+
if not self.capability_id or not re.match(
|
|
252
|
+
r"^[a-z][a-z0-9_-]*(?:\.[a-z0-9_-]+)+$", self.capability_id
|
|
253
|
+
):
|
|
254
|
+
raise ValueError("agent-exposable tools require a stable dotted capability_id")
|
|
255
|
+
if not self.description.strip() or self.input_schema is None:
|
|
256
|
+
raise ValueError("agent-exposable tools require description and input_schema")
|
|
257
|
+
if not self.effects:
|
|
258
|
+
raise ValueError("agent-exposable tools require at least one declared effect")
|
|
259
|
+
if self.risk in {"write", "destructive"} and self.supports_scheduling and not self.idempotent:
|
|
260
|
+
raise ValueError("scheduled write capabilities must be idempotent")
|
|
261
|
+
return self
|
|
200
262
|
|
|
201
263
|
|
|
202
264
|
class McpResourceSpec(BaseModel):
|
|
@@ -40,10 +40,23 @@ class ServiceDecl:
|
|
|
40
40
|
scope: str | None = None
|
|
41
41
|
label: str | None = None
|
|
42
42
|
description: str | None = None
|
|
43
|
-
input_schema: dict | None = None
|
|
44
|
-
output_schema: dict | None = None
|
|
43
|
+
input_schema: dict | str | None = None
|
|
44
|
+
output_schema: dict | str | None = None
|
|
45
45
|
deprecated: bool = False
|
|
46
46
|
replacement: str | None = None
|
|
47
|
+
agent_exposable: bool = False
|
|
48
|
+
capability_id: str | None = None
|
|
49
|
+
effects: tuple[str, ...] = ()
|
|
50
|
+
risk: str = "read"
|
|
51
|
+
supports_scheduling: bool = True
|
|
52
|
+
idempotent: bool = False
|
|
53
|
+
timeout_seconds: int = 60
|
|
54
|
+
tags: tuple[str, ...] = ()
|
|
55
|
+
artifact_inputs: tuple[str, ...] = ()
|
|
56
|
+
artifact_outputs: tuple[str, ...] = ()
|
|
57
|
+
examples: tuple[dict[str, Any], ...] = ()
|
|
58
|
+
cost_class: str | None = None
|
|
59
|
+
latency_class: str | None = None
|
|
47
60
|
|
|
48
61
|
|
|
49
62
|
# Plugin-declared service handlers captured during module import. The platform
|
|
@@ -60,12 +73,25 @@ def service(
|
|
|
60
73
|
scope: str | None = None,
|
|
61
74
|
label: str | None = None,
|
|
62
75
|
description: str | None = None,
|
|
63
|
-
input_schema: dict | None = None,
|
|
64
|
-
input: dict | None = None,
|
|
65
|
-
output_schema: dict | None = None,
|
|
66
|
-
output: dict | None = None,
|
|
76
|
+
input_schema: dict | str | None = None,
|
|
77
|
+
input: dict | str | None = None,
|
|
78
|
+
output_schema: dict | str | None = None,
|
|
79
|
+
output: dict | str | None = None,
|
|
67
80
|
deprecated: bool = False,
|
|
68
81
|
replacement: str | None = None,
|
|
82
|
+
agent_exposable: bool = False,
|
|
83
|
+
capability_id: str | None = None,
|
|
84
|
+
effects: list[str] | None = None,
|
|
85
|
+
risk: str = "read",
|
|
86
|
+
supports_scheduling: bool = True,
|
|
87
|
+
idempotent: bool = False,
|
|
88
|
+
timeout_seconds: int = 60,
|
|
89
|
+
tags: list[str] | None = None,
|
|
90
|
+
artifact_inputs: list[str] | None = None,
|
|
91
|
+
artifact_outputs: list[str] | None = None,
|
|
92
|
+
examples: list[dict[str, Any]] | None = None,
|
|
93
|
+
cost_class: str | None = None,
|
|
94
|
+
latency_class: str | None = None,
|
|
69
95
|
) -> Callable[[ServiceHandler], ServiceHandler]:
|
|
70
96
|
"""Mark an async function as a broker-callable service method."""
|
|
71
97
|
|
|
@@ -83,6 +109,19 @@ def service(
|
|
|
83
109
|
output_schema=output_schema or output,
|
|
84
110
|
deprecated=deprecated,
|
|
85
111
|
replacement=replacement,
|
|
112
|
+
agent_exposable=agent_exposable,
|
|
113
|
+
capability_id=capability_id,
|
|
114
|
+
effects=tuple(effects or ()),
|
|
115
|
+
risk=risk,
|
|
116
|
+
supports_scheduling=supports_scheduling,
|
|
117
|
+
idempotent=idempotent,
|
|
118
|
+
timeout_seconds=timeout_seconds,
|
|
119
|
+
tags=tuple(tags or ()),
|
|
120
|
+
artifact_inputs=tuple(artifact_inputs or ()),
|
|
121
|
+
artifact_outputs=tuple(artifact_outputs or ()),
|
|
122
|
+
examples=tuple(examples or ()),
|
|
123
|
+
cost_class=cost_class,
|
|
124
|
+
latency_class=latency_class,
|
|
86
125
|
)
|
|
87
126
|
)
|
|
88
127
|
return fn
|
package/lib/cli.js
CHANGED
|
@@ -14,6 +14,7 @@ const secrets = require("./commands/secrets")
|
|
|
14
14
|
const services = require("./commands/services")
|
|
15
15
|
const version = require("./commands/version")
|
|
16
16
|
const update = require("./commands/update")
|
|
17
|
+
const capabilities = require("./commands/capabilities")
|
|
17
18
|
|
|
18
19
|
const COMMANDS = {
|
|
19
20
|
init: { run: init, help: "Scaffold a new plugin directory from the template" },
|
|
@@ -57,6 +58,14 @@ const COMMANDS = {
|
|
|
57
58
|
run: services,
|
|
58
59
|
help: "Inspect / pull / scaffold OS-broker services (list, pull, scaffold)",
|
|
59
60
|
},
|
|
61
|
+
capability: {
|
|
62
|
+
run: capabilities,
|
|
63
|
+
help: "Add, list, or inspect agent-callable app capabilities",
|
|
64
|
+
},
|
|
65
|
+
capabilities: {
|
|
66
|
+
run: capabilities,
|
|
67
|
+
help: "Add, list, or inspect agent-callable app capabilities",
|
|
68
|
+
},
|
|
60
69
|
version: { run: version, help: "Show the installed pltt CLI version" },
|
|
61
70
|
update: { run: update, help: "Update the globally installed pltt CLI" },
|
|
62
71
|
}
|
|
@@ -83,7 +92,7 @@ function printHelp() {
|
|
|
83
92
|
console.log(" --token <token> Publish token for pltt login")
|
|
84
93
|
console.log(" --no-default Do not make this environment the default")
|
|
85
94
|
console.log("\nInit flags:")
|
|
86
|
-
console.log(" --template <name> One of: dashboard, agent-tool, external-service, database, frontend-only, next")
|
|
95
|
+
console.log(" --template <name> One of: dashboard, agent-ready, agent-tool, external-service, database, frontend-only, next")
|
|
87
96
|
console.log("\nLogs flags:")
|
|
88
97
|
console.log(" --tail <n> Tail last n events (default 50)")
|
|
89
98
|
console.log(" -f, --follow Stream events (poll every 3s)")
|
|
@@ -92,6 +101,10 @@ function printHelp() {
|
|
|
92
101
|
console.log(" pltt services add TARGET # add a consumed service/event target")
|
|
93
102
|
console.log(" pltt services pull # generate typed TS+Python clients from consumes")
|
|
94
103
|
console.log(" pltt services scaffold NAME # add a provider method (schemas + handler stub)")
|
|
104
|
+
console.log("\nAgent capabilities:")
|
|
105
|
+
console.log(" pltt capabilities list")
|
|
106
|
+
console.log(" pltt capabilities inspect CAPABILITY_ID")
|
|
107
|
+
console.log(" pltt capabilities add creative.poster.generate --risk write --idempotent")
|
|
95
108
|
console.log("\nSecrets:")
|
|
96
109
|
console.log(" pltt secrets init")
|
|
97
110
|
console.log(" pltt secrets set NAME --value <secret> --env staging")
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
const { loadManifest } = require("../manifest")
|
|
4
|
+
const servicesCommand = require("./services")
|
|
5
|
+
|
|
6
|
+
function valueAfter(args, flag) {
|
|
7
|
+
const index = args.indexOf(flag)
|
|
8
|
+
return index === -1 ? null : args[index + 1] || null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function methodFromCapabilityId(capabilityId) {
|
|
12
|
+
const parts = String(capabilityId || "").split(".").filter(Boolean)
|
|
13
|
+
return parts.slice(-2).join(".") || "agent.action"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function collect(manifest) {
|
|
17
|
+
const out = []
|
|
18
|
+
for (const service of manifest.provides?.services || []) {
|
|
19
|
+
for (const method of service.methods || []) {
|
|
20
|
+
if (!method.agent_exposable) continue
|
|
21
|
+
out.push({
|
|
22
|
+
capability_id: method.capability_id || "app." + manifest.id + "." + method.name,
|
|
23
|
+
runtime_target: (manifest.provides?.namespace || manifest.id) + "/" + (service.version || "v1") + "#" + method.name,
|
|
24
|
+
name: method.name,
|
|
25
|
+
description: method.description || service.description || "",
|
|
26
|
+
risk: method.risk || (method.annotations?.readOnlyHint ? "read" : "write"),
|
|
27
|
+
effects: method.effects || [],
|
|
28
|
+
supports_scheduling: method.supports_scheduling !== false,
|
|
29
|
+
idempotent: method.idempotent === true,
|
|
30
|
+
timeout_seconds: method.timeout_seconds || 60,
|
|
31
|
+
tags: method.tags || [],
|
|
32
|
+
artifact_inputs: method.artifact_inputs || [],
|
|
33
|
+
artifact_outputs: method.artifact_outputs || [],
|
|
34
|
+
examples: method.examples || [],
|
|
35
|
+
cost_class: method.cost_class || null,
|
|
36
|
+
latency_class: method.latency_class || null,
|
|
37
|
+
deprecated: method.deprecated === true,
|
|
38
|
+
replacement: method.replacement || null,
|
|
39
|
+
input_schema: method.input_schema || method.input || null,
|
|
40
|
+
output_schema: method.output_schema || method.output || null,
|
|
41
|
+
source: "service",
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const tool of manifest.mcp?.provides?.tools || []) {
|
|
46
|
+
if (!tool.agent_exposable) continue
|
|
47
|
+
out.push({
|
|
48
|
+
capability_id: tool.capability_id || "app." + manifest.id + "." + tool.name,
|
|
49
|
+
runtime_target: (manifest.provides?.namespace || manifest.id) + "/v1#" + tool.name,
|
|
50
|
+
name: tool.name,
|
|
51
|
+
description: tool.description || "",
|
|
52
|
+
risk: tool.risk || (tool.annotations?.readOnlyHint ? "read" : "write"),
|
|
53
|
+
effects: tool.effects || [],
|
|
54
|
+
supports_scheduling: tool.supports_scheduling !== false,
|
|
55
|
+
idempotent: tool.idempotent === true,
|
|
56
|
+
timeout_seconds: tool.timeout_seconds || 60,
|
|
57
|
+
tags: tool.tags || [],
|
|
58
|
+
artifact_inputs: tool.artifact_inputs || [],
|
|
59
|
+
artifact_outputs: tool.artifact_outputs || [],
|
|
60
|
+
examples: tool.examples || [],
|
|
61
|
+
cost_class: tool.cost_class || null,
|
|
62
|
+
latency_class: tool.latency_class || null,
|
|
63
|
+
deprecated: tool.deprecated === true,
|
|
64
|
+
replacement: tool.replacement || null,
|
|
65
|
+
input_schema: tool.input_schema || null,
|
|
66
|
+
output_schema: tool.output_schema || null,
|
|
67
|
+
source: "mcp",
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
for (const tool of manifest.tools || []) {
|
|
71
|
+
out.push({
|
|
72
|
+
capability_id: "app." + manifest.id + "." + tool.name,
|
|
73
|
+
name: tool.name,
|
|
74
|
+
description: tool.description || "",
|
|
75
|
+
risk: "unknown",
|
|
76
|
+
effects: [],
|
|
77
|
+
supports_scheduling: false,
|
|
78
|
+
idempotent: false,
|
|
79
|
+
timeout_seconds: null,
|
|
80
|
+
tags: [],
|
|
81
|
+
artifact_inputs: [],
|
|
82
|
+
artifact_outputs: [],
|
|
83
|
+
examples: [],
|
|
84
|
+
cost_class: null,
|
|
85
|
+
latency_class: null,
|
|
86
|
+
deprecated: true,
|
|
87
|
+
replacement: "@capability plus provides.services",
|
|
88
|
+
input_schema: null,
|
|
89
|
+
output_schema: null,
|
|
90
|
+
source: "legacy",
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
return out
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function run(args, { cwd }) {
|
|
97
|
+
const manifest = loadManifest(cwd)
|
|
98
|
+
const json = args.includes("--json")
|
|
99
|
+
const positional = args.filter((arg) => !arg.startsWith("-"))
|
|
100
|
+
const command = positional[0] || "list"
|
|
101
|
+
const id = command === "inspect" ? positional[1] : null
|
|
102
|
+
if (command === "add") {
|
|
103
|
+
const capabilityId = positional[1]
|
|
104
|
+
if (!capabilityId || !/^[a-z][a-z0-9_-]*(\.[a-z0-9_-]+){2,}$/.test(capabilityId)) {
|
|
105
|
+
throw new Error("usage: pltt capabilities add <domain.resource.action> [--method name] [--risk read|write|destructive|controlled] [--effects a,b] [--idempotent] [--no-scheduling]")
|
|
106
|
+
}
|
|
107
|
+
const method = valueAfter(args, "--method") || methodFromCapabilityId(capabilityId)
|
|
108
|
+
const risk = valueAfter(args, "--risk") || "read"
|
|
109
|
+
if (["write", "destructive"].includes(risk) && !args.includes("--idempotent") && !args.includes("--no-scheduling")) {
|
|
110
|
+
throw new Error("scheduled write capabilities require --idempotent, or use --no-scheduling for interactive-only actions")
|
|
111
|
+
}
|
|
112
|
+
const forwarded = [method, "--agent", "--capability-id", capabilityId]
|
|
113
|
+
for (const flag of ["--risk", "--effects"]) {
|
|
114
|
+
const value = valueAfter(args, flag)
|
|
115
|
+
if (value) forwarded.push(flag, value)
|
|
116
|
+
}
|
|
117
|
+
for (const flag of ["--idempotent", "--no-scheduling"]) {
|
|
118
|
+
if (args.includes(flag)) forwarded.push(flag)
|
|
119
|
+
}
|
|
120
|
+
await servicesCommand.runScaffold(forwarded, { cwd })
|
|
121
|
+
console.log("[pltt] agent capability ready; implement the generated handler, then run `pltt test --agent`")
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
const capabilities = collect(manifest)
|
|
125
|
+
|
|
126
|
+
if (command === "inspect") {
|
|
127
|
+
const item = capabilities.find((entry) => entry.capability_id === id || entry.name === id)
|
|
128
|
+
if (!item) throw new Error("capability not found: " + (id || "(missing id)"))
|
|
129
|
+
console.log(JSON.stringify(item, null, 2))
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
if (command !== "list") throw new Error("usage: pltt capabilities [list | inspect <id> | add <id>] [--json]")
|
|
133
|
+
if (json) {
|
|
134
|
+
console.log(JSON.stringify({ app_id: manifest.id, capabilities }, null, 2))
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
if (!capabilities.length) {
|
|
138
|
+
console.log("[pltt] no agent-exposable capabilities declared")
|
|
139
|
+
console.log("[pltt] expose a provides.services method with agent_exposable=true and a stable capability_id")
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
console.log("Capabilities for " + manifest.id + "@" + manifest.version)
|
|
143
|
+
for (const item of capabilities) {
|
|
144
|
+
const scheduling = item.supports_scheduling ? "scheduled" : "interactive-only"
|
|
145
|
+
console.log(" " + item.capability_id + " " + item.risk + ", " + scheduling)
|
|
146
|
+
console.log(" " + item.name + (item.description ? " - " + item.description : ""))
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
module.exports = run
|
|
151
|
+
module.exports.collect = collect
|
package/lib/commands/init.js
CHANGED
|
@@ -10,7 +10,7 @@ const DEFAULT_TEMPLATE_REPO = "palette-lab/plugin-template"
|
|
|
10
10
|
const TEMPLATE_REPO = process.env.PALETTE_TEMPLATE_REPO || DEFAULT_TEMPLATE_REPO
|
|
11
11
|
const TEMPLATE_REF = process.env.PALETTE_TEMPLATE_REF || "main"
|
|
12
12
|
|
|
13
|
-
const KNOWN_TEMPLATES = ["frontend-only", "palette-app", "next", "dashboard", "agent-tool", "external-service", "database", "provider-app", "consumer-app"]
|
|
13
|
+
const KNOWN_TEMPLATES = ["frontend-only", "palette-app", "next", "dashboard", "agent-tool", "agent-ready", "external-service", "database", "provider-app", "consumer-app"]
|
|
14
14
|
|
|
15
15
|
function toSlug(name) {
|
|
16
16
|
return name
|
|
@@ -39,7 +39,8 @@ function fetchTemplate(destDir) {
|
|
|
39
39
|
|
|
40
40
|
function copyLocalFallback(destDir, template) {
|
|
41
41
|
if (template) {
|
|
42
|
-
const
|
|
42
|
+
const resolvedTemplate = template === "agent-ready" ? "agent-tool" : template
|
|
43
|
+
const tplDir = path.resolve(__dirname, "..", "..", "template-fallback", "templates", resolvedTemplate)
|
|
43
44
|
if (!fs.existsSync(tplDir)) return false
|
|
44
45
|
fs.cpSync(tplDir, destDir, { recursive: true })
|
|
45
46
|
return true
|
package/lib/commands/services.js
CHANGED
|
@@ -380,20 +380,36 @@ function boolArg(source, name) {
|
|
|
380
380
|
return new RegExp(`${name}\\s*=\\s*True`).test(source)
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
+
function falseArg(source, name) {
|
|
384
|
+
return new RegExp(`${name}\\s*=\\s*False`).test(source)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function intArg(source, name) {
|
|
388
|
+
const match = source.match(new RegExp(`${name}\\s*=\\s*(\\d+)`))
|
|
389
|
+
return match ? Number(match[1]) : null
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function stringListArg(source, name) {
|
|
393
|
+
const match = source.match(new RegExp(`${name}\\s*=\\s*\\[([\\s\\S]*?)\\]`))
|
|
394
|
+
if (!match) return null
|
|
395
|
+
return Array.from(match[1].matchAll(/["']([^"']+)["']/g), (item) => item[1])
|
|
396
|
+
}
|
|
397
|
+
|
|
383
398
|
function discoverServiceDecorators(cwd) {
|
|
384
399
|
const files = listPythonFiles(path.join(cwd, "backend"))
|
|
385
400
|
const found = []
|
|
386
401
|
for (const file of files) {
|
|
387
402
|
const text = fs.readFileSync(file, "utf8")
|
|
388
|
-
const re = /@service\s*\(([\s\S]*?)\)\s*(?:async\s+)?def\s+([A-Za-z_][A-Za-z0-9_]*)/g
|
|
403
|
+
const re = /@(service|capability)\s*\(([\s\S]*?)\)\s*(?:async\s+)?def\s+([A-Za-z_][A-Za-z0-9_]*)/g
|
|
389
404
|
let match
|
|
390
405
|
while ((match = re.exec(text))) {
|
|
391
|
-
const
|
|
406
|
+
const decorator = match[1]
|
|
407
|
+
const args = match[2]
|
|
392
408
|
const name = (args.match(/["']([^"']+)["']/) || [])[1]
|
|
393
409
|
if (!name) continue
|
|
394
410
|
found.push({
|
|
395
411
|
name,
|
|
396
|
-
fn: match[
|
|
412
|
+
fn: match[3],
|
|
397
413
|
scope: argValue(args, "scope"),
|
|
398
414
|
label: argValue(args, "label"),
|
|
399
415
|
description: argValue(args, "description"),
|
|
@@ -403,6 +419,18 @@ function discoverServiceDecorators(cwd) {
|
|
|
403
419
|
output_schema: argValue(args, "output_schema") || argValue(args, "output"),
|
|
404
420
|
deprecated: boolArg(args, "deprecated"),
|
|
405
421
|
replacement: argValue(args, "replacement"),
|
|
422
|
+
agent_exposable: decorator === "capability" || boolArg(args, "agent_exposable"),
|
|
423
|
+
capability_id: argValue(args, "capability_id"),
|
|
424
|
+
effects: stringListArg(args, "effects"),
|
|
425
|
+
risk: argValue(args, "risk"),
|
|
426
|
+
supports_scheduling: falseArg(args, "supports_scheduling") ? false : true,
|
|
427
|
+
idempotent: boolArg(args, "idempotent"),
|
|
428
|
+
timeout_seconds: intArg(args, "timeout_seconds"),
|
|
429
|
+
tags: stringListArg(args, "tags"),
|
|
430
|
+
artifact_inputs: stringListArg(args, "artifact_inputs"),
|
|
431
|
+
artifact_outputs: stringListArg(args, "artifact_outputs"),
|
|
432
|
+
cost_class: argValue(args, "cost_class"),
|
|
433
|
+
latency_class: argValue(args, "latency_class"),
|
|
406
434
|
file: path.relative(cwd, file),
|
|
407
435
|
})
|
|
408
436
|
}
|
|
@@ -414,7 +442,7 @@ async function runSync(argv, { cwd }) {
|
|
|
414
442
|
const manifest = readManifest(cwd)
|
|
415
443
|
const decorators = discoverServiceDecorators(cwd)
|
|
416
444
|
if (!decorators.length) {
|
|
417
|
-
console.log("[pltt] no @service(...) decorators found under backend/.")
|
|
445
|
+
console.log("[pltt] no @service(...) or @capability(...) decorators found under backend/.")
|
|
418
446
|
return
|
|
419
447
|
}
|
|
420
448
|
manifest.provides = manifest.provides || {}
|
|
@@ -443,6 +471,18 @@ async function runSync(argv, { cwd }) {
|
|
|
443
471
|
else method.output_schema = method.output_schema || `schemas/${decl.name}.out.json`
|
|
444
472
|
if (decl.deprecated) method.deprecated = true
|
|
445
473
|
if (decl.replacement) method.replacement = decl.replacement
|
|
474
|
+
if (decl.agent_exposable) method.agent_exposable = true
|
|
475
|
+
if (decl.capability_id) method.capability_id = decl.capability_id
|
|
476
|
+
if (decl.effects) method.effects = decl.effects
|
|
477
|
+
if (decl.risk) method.risk = decl.risk
|
|
478
|
+
if (decl.agent_exposable) method.supports_scheduling = decl.supports_scheduling
|
|
479
|
+
if (decl.agent_exposable) method.idempotent = decl.idempotent
|
|
480
|
+
if (decl.timeout_seconds) method.timeout_seconds = decl.timeout_seconds
|
|
481
|
+
if (decl.tags) method.tags = decl.tags
|
|
482
|
+
if (decl.artifact_inputs) method.artifact_inputs = decl.artifact_inputs
|
|
483
|
+
if (decl.artifact_outputs) method.artifact_outputs = decl.artifact_outputs
|
|
484
|
+
if (decl.cost_class) method.cost_class = decl.cost_class
|
|
485
|
+
if (decl.latency_class) method.latency_class = decl.latency_class
|
|
446
486
|
}
|
|
447
487
|
writeManifest(cwd, manifest)
|
|
448
488
|
console.log(`[pltt] synced ${decorators.length} service method(s) into palette-plugin.json`)
|
|
@@ -544,6 +584,15 @@ async function runScaffold(argv, { cwd }) {
|
|
|
544
584
|
process.exit(1)
|
|
545
585
|
}
|
|
546
586
|
const manifest = readManifest(cwd)
|
|
587
|
+
const agentExposable = argv.includes("--agent") || argv.includes("--capability-id")
|
|
588
|
+
const capabilityId = valueAfter(argv, "--capability-id") || `app.${manifest.id}.${method}`
|
|
589
|
+
const risk = valueAfter(argv, "--risk") || "read"
|
|
590
|
+
const effects = (valueAfter(argv, "--effects") || (risk === "read" ? "external.read" : "external.write"))
|
|
591
|
+
.split(",")
|
|
592
|
+
.map((item) => item.trim())
|
|
593
|
+
.filter(Boolean)
|
|
594
|
+
const supportsScheduling = !argv.includes("--no-scheduling")
|
|
595
|
+
const idempotent = argv.includes("--idempotent")
|
|
547
596
|
const namespace = (manifest.provides && manifest.provides.namespace) || manifest.id
|
|
548
597
|
const provides = manifest.provides || {}
|
|
549
598
|
provides.namespace = namespace
|
|
@@ -556,12 +605,25 @@ async function runScaffold(argv, { cwd }) {
|
|
|
556
605
|
provides.services.push(svc)
|
|
557
606
|
}
|
|
558
607
|
svc.methods = svc.methods || []
|
|
559
|
-
|
|
560
|
-
|
|
608
|
+
let methodSpec = svc.methods.find((m) => m && m.name === method)
|
|
609
|
+
if (!methodSpec) {
|
|
610
|
+
methodSpec = {
|
|
561
611
|
name: method,
|
|
562
612
|
scope: `${namespace}.${method}`,
|
|
563
613
|
input_schema: `schemas/${method}.in.json`,
|
|
564
614
|
output_schema: `schemas/${method}.out.json`,
|
|
615
|
+
}
|
|
616
|
+
svc.methods.push(methodSpec)
|
|
617
|
+
}
|
|
618
|
+
if (agentExposable) {
|
|
619
|
+
Object.assign(methodSpec, {
|
|
620
|
+
agent_exposable: true,
|
|
621
|
+
capability_id: capabilityId,
|
|
622
|
+
description: methodSpec.description || `Agent capability for ${method}.`,
|
|
623
|
+
effects,
|
|
624
|
+
risk,
|
|
625
|
+
supports_scheduling: supportsScheduling,
|
|
626
|
+
idempotent,
|
|
565
627
|
})
|
|
566
628
|
}
|
|
567
629
|
manifest.provides = provides
|
|
@@ -594,8 +656,10 @@ async function runScaffold(argv, { cwd }) {
|
|
|
594
656
|
if (!fs.existsSync(handlerPath)) {
|
|
595
657
|
fs.writeFileSync(
|
|
596
658
|
handlerPath,
|
|
597
|
-
`from palette_sdk import service, PluginContext\n\n` +
|
|
598
|
-
|
|
659
|
+
`from palette_sdk import ${agentExposable ? "capability" : "service"}, PluginContext\n\n` +
|
|
660
|
+
(agentExposable
|
|
661
|
+
? `@capability(${JSON.stringify(method)}, capability_id=${JSON.stringify(capabilityId)}, scope=${JSON.stringify(namespace + "." + method)}, description=${JSON.stringify(`Agent capability for ${method}.`)}, input_schema=${JSON.stringify(`schemas/${method}.in.json`)}, output_schema=${JSON.stringify(`schemas/${method}.out.json`)}, effects=${JSON.stringify(effects)}, risk=${JSON.stringify(risk)}, supports_scheduling=${supportsScheduling ? "True" : "False"}, idempotent=${idempotent ? "True" : "False"})\n`
|
|
662
|
+
: `@service(${JSON.stringify(method)}, scope=${JSON.stringify(namespace + "." + method)})\n`) +
|
|
599
663
|
`async def ${safeIdent(method)}(ctx: PluginContext, payload: dict) -> dict:\n` +
|
|
600
664
|
` """Provider handler for ${namespace}/v1#${method}.\n\n` +
|
|
601
665
|
` The OS broker validates payload against schemas/${method}.in.json and the\n` +
|
|
@@ -662,3 +726,5 @@ async function run(argv, ctx) {
|
|
|
662
726
|
}
|
|
663
727
|
|
|
664
728
|
module.exports = run
|
|
729
|
+
module.exports.runScaffold = runScaffold
|
|
730
|
+
module.exports.discoverServiceDecorators = discoverServiceDecorators
|
package/lib/commands/test.js
CHANGED
|
@@ -169,6 +169,7 @@ function checkBackendContract(cwd, manifest, out, pythonInfo) {
|
|
|
169
169
|
"router = getattr(mod, 'router', None)",
|
|
170
170
|
"assert router is not None, 'backend entry has no router export'",
|
|
171
171
|
"from palette_sdk.permissions import is_permission_dep",
|
|
172
|
+
"from palette_sdk.services import drain_pending_services",
|
|
172
173
|
"public = set(manifest.get('public_routes') or [])",
|
|
173
174
|
"declared = set(manifest.get('permissions') or [])",
|
|
174
175
|
"routes = []",
|
|
@@ -196,7 +197,10 @@ function checkBackendContract(cwd, manifest, out, pythonInfo) {
|
|
|
196
197
|
" routes.append({'path': path, 'methods': methods, 'permissions': sorted(set(perms)), 'public': path in public})",
|
|
197
198
|
" if path not in public and not perms:",
|
|
198
199
|
" ungated.append({'path': path, 'methods': methods})",
|
|
199
|
-
"
|
|
200
|
+
"capabilities = []",
|
|
201
|
+
"for item in drain_pending_services():",
|
|
202
|
+
" capabilities.append({'name': item.name, 'agent_exposable': item.agent_exposable, 'capability_id': item.capability_id, 'effects': list(item.effects), 'risk': item.risk, 'supports_scheduling': item.supports_scheduling, 'idempotent': item.idempotent, 'timeout_seconds': item.timeout_seconds, 'tags': list(item.tags), 'artifact_inputs': list(item.artifact_inputs), 'artifact_outputs': list(item.artifact_outputs), 'cost_class': item.cost_class, 'latency_class': item.latency_class})",
|
|
203
|
+
"print(json.dumps({'routes': routes, 'used_permissions': sorted(used), 'ungated_routes': ungated, 'undeclared_permissions': sorted(used - declared), 'unused_declared_permissions': sorted(declared - used), 'capabilities': capabilities}))",
|
|
200
204
|
].join("\n")
|
|
201
205
|
const res = spawnSync(python, ["-c", script, abs, JSON.stringify(manifest)], { encoding: "utf8", env })
|
|
202
206
|
if (res.status === 0) {
|
|
@@ -244,6 +248,90 @@ function checkBackendContract(cwd, manifest, out, pythonInfo) {
|
|
|
244
248
|
{ permissions: report.unused_declared_permissions },
|
|
245
249
|
)
|
|
246
250
|
}
|
|
251
|
+
const manifestCapabilities = []
|
|
252
|
+
for (const service of manifest.provides?.services || []) {
|
|
253
|
+
for (const method of service.methods || []) {
|
|
254
|
+
if (method.agent_exposable) manifestCapabilities.push(method)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const runtimeByName = new Map((report.capabilities || []).map((item) => [item.name, item]))
|
|
258
|
+
for (const method of manifestCapabilities) {
|
|
259
|
+
if (!method.capability_id) {
|
|
260
|
+
failures += out.fail(
|
|
261
|
+
`agent capability has no stable capability_id: ${method.name}`,
|
|
262
|
+
"Add a semantic id such as creative.poster.generate; saved workflows use it to survive provider changes.",
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
const writeEffects = (method.effects || []).some((effect) => /(^|\.)(write|create|update|delete|publish|send)$/.test(effect))
|
|
266
|
+
if (method.risk === "read" && writeEffects) {
|
|
267
|
+
failures += out.fail(
|
|
268
|
+
`read-only capability declares write effects: ${method.name}`,
|
|
269
|
+
"Set risk to write/destructive or remove the write effect.",
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
if (["write", "destructive"].includes(method.risk) && method.supports_scheduling !== false && method.idempotent !== true) {
|
|
273
|
+
failures += out.fail(
|
|
274
|
+
`scheduled write capability is not idempotent: ${method.name}`,
|
|
275
|
+
"Implement idempotency and set idempotent=true, or set supports_scheduling=false.",
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
const runtime = runtimeByName.get(method.name)
|
|
279
|
+
if (!runtime) {
|
|
280
|
+
failures += out.fail(
|
|
281
|
+
`agent capability has no runtime handler: ${method.name}`,
|
|
282
|
+
`Import a @capability("${method.name}", capability_id="${method.capability_id || "..."}") handler from ${entry}.`,
|
|
283
|
+
)
|
|
284
|
+
continue
|
|
285
|
+
}
|
|
286
|
+
if (!runtime.agent_exposable) {
|
|
287
|
+
failures += out.fail(
|
|
288
|
+
`runtime handler is not agent-exposable: ${method.name}`,
|
|
289
|
+
"Use the @capability decorator or service(..., agent_exposable=True).",
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
if (method.capability_id && runtime.capability_id !== method.capability_id) {
|
|
293
|
+
failures += out.fail(
|
|
294
|
+
`capability id mismatch for ${method.name}`,
|
|
295
|
+
`Make the decorator capability_id exactly "${method.capability_id}".`,
|
|
296
|
+
{ manifest: method.capability_id, runtime: runtime.capability_id },
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
const parityFields = [
|
|
300
|
+
"effects", "risk", "supports_scheduling", "idempotent", "timeout_seconds",
|
|
301
|
+
"tags", "artifact_inputs", "artifact_outputs", "cost_class", "latency_class",
|
|
302
|
+
]
|
|
303
|
+
for (const field of parityFields) {
|
|
304
|
+
if (method[field] === undefined) continue
|
|
305
|
+
if (JSON.stringify(method[field]) !== JSON.stringify(runtime[field])) {
|
|
306
|
+
failures += out.fail(
|
|
307
|
+
`capability metadata mismatch for ${method.name}: ${field}`,
|
|
308
|
+
`Make the @capability ${field} match palette-plugin.json.`,
|
|
309
|
+
{ manifest: method[field], runtime: runtime[field] },
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const manifestNames = new Set(manifestCapabilities.map((item) => item.name))
|
|
315
|
+
for (const runtime of report.capabilities || []) {
|
|
316
|
+
if (runtime.agent_exposable && !manifestNames.has(runtime.name)) {
|
|
317
|
+
failures += out.fail(
|
|
318
|
+
`runtime capability is missing from manifest: ${runtime.name}`,
|
|
319
|
+
"Add a matching agent_exposable provides.services method so publish review can govern it.",
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (manifestCapabilities.length && failures === 0) {
|
|
324
|
+
out.ok("agent capability handlers match the reviewed manifest", {
|
|
325
|
+
capabilities: manifestCapabilities.map((item) => item.capability_id || item.name),
|
|
326
|
+
})
|
|
327
|
+
}
|
|
328
|
+
if ((manifest.tools || []).length) {
|
|
329
|
+
out.warn(
|
|
330
|
+
"manifest.tools is a legacy agent integration surface",
|
|
331
|
+
"Migrate each entry to a typed @capability handler plus an agent_exposable provides.services method.",
|
|
332
|
+
{ tools: manifest.tools.map((item) => item.name) },
|
|
333
|
+
)
|
|
334
|
+
}
|
|
247
335
|
return failures
|
|
248
336
|
}
|
|
249
337
|
return out.fail(
|
package/lib/manifest.js
CHANGED
|
@@ -125,6 +125,58 @@ function validateArray(value, label, errors) {
|
|
|
125
125
|
if (value !== undefined && !Array.isArray(value)) errors.push(`${label} must be an array`)
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
const CAPABILITY_METADATA_KEYS = [
|
|
129
|
+
"effects", "risk", "idempotent", "timeout_seconds", "tags", "artifact_inputs",
|
|
130
|
+
"artifact_outputs", "examples", "cost_class", "latency_class",
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
function validateCapabilityMetadata(value, label, errors) {
|
|
134
|
+
for (const key of ["effects", "tags", "artifact_inputs", "artifact_outputs"]) {
|
|
135
|
+
if (value[key] !== undefined && (!Array.isArray(value[key]) || value[key].some((item) => typeof item !== "string"))) {
|
|
136
|
+
errors.push(`${label}.${key} must be an array of strings`)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
requireBoolean(value, "idempotent", label, errors)
|
|
140
|
+
if (value.risk !== undefined && !["read", "write", "destructive", "controlled"].includes(value.risk)) {
|
|
141
|
+
errors.push(`${label}.risk must be read, write, destructive, or controlled`)
|
|
142
|
+
}
|
|
143
|
+
if (value.timeout_seconds !== undefined && (!Number.isInteger(value.timeout_seconds) || value.timeout_seconds < 1 || value.timeout_seconds > 7200)) {
|
|
144
|
+
errors.push(`${label}.timeout_seconds must be an integer between 1 and 7200`)
|
|
145
|
+
}
|
|
146
|
+
if (value.examples !== undefined && (!Array.isArray(value.examples) || value.examples.some((item) => !isObject(item)))) {
|
|
147
|
+
errors.push(`${label}.examples must be an array of objects`)
|
|
148
|
+
}
|
|
149
|
+
if (value.cost_class !== undefined && !["low", "medium", "high"].includes(value.cost_class)) {
|
|
150
|
+
errors.push(`${label}.cost_class must be low, medium, or high`)
|
|
151
|
+
}
|
|
152
|
+
if (value.latency_class !== undefined && !["interactive", "background", "long_running"].includes(value.latency_class)) {
|
|
153
|
+
errors.push(`${label}.latency_class must be interactive, background, or long_running`)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function validateAgentCapability(value, label, errors) {
|
|
158
|
+
if (value.agent_exposable !== true) return
|
|
159
|
+
if (typeof value.capability_id !== "string" || !/^[a-z][a-z0-9_-]*(\.[a-z0-9_-]+)+$/.test(value.capability_id)) {
|
|
160
|
+
errors.push(`${label}.capability_id must be a stable dotted lowercase id when agent_exposable is true`)
|
|
161
|
+
}
|
|
162
|
+
if (typeof value.description !== "string" || !value.description.trim()) {
|
|
163
|
+
errors.push(`${label}.description is required when agent_exposable is true`)
|
|
164
|
+
}
|
|
165
|
+
const input = value.input_schema ?? value.input
|
|
166
|
+
if (input === undefined) {
|
|
167
|
+
errors.push(`${label}.input_schema is required when agent_exposable is true`)
|
|
168
|
+
}
|
|
169
|
+
if (!Array.isArray(value.effects) || value.effects.length === 0) {
|
|
170
|
+
errors.push(`${label}.effects must declare at least one effect when agent_exposable is true`)
|
|
171
|
+
}
|
|
172
|
+
if (!value.risk) {
|
|
173
|
+
errors.push(`${label}.risk is required when agent_exposable is true`)
|
|
174
|
+
}
|
|
175
|
+
if (["write", "destructive"].includes(value.risk) && value.supports_scheduling !== false && value.idempotent !== true) {
|
|
176
|
+
errors.push(`${label} scheduled write capabilities must be idempotent or set supports_scheduling=false`)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
128
180
|
function validateSecrets(value, errors) {
|
|
129
181
|
if (value === undefined) return
|
|
130
182
|
if (!isObject(value)) {
|
|
@@ -307,8 +359,13 @@ function validateServiceMethods(value, label, errors) {
|
|
|
307
359
|
"output",
|
|
308
360
|
"route_method",
|
|
309
361
|
"route_path",
|
|
362
|
+
"annotations",
|
|
363
|
+
"capability_id",
|
|
364
|
+
"supports_scheduling",
|
|
365
|
+
"agent_exposable",
|
|
310
366
|
"deprecated",
|
|
311
367
|
"replacement",
|
|
368
|
+
...CAPABILITY_METADATA_KEYS,
|
|
312
369
|
]),
|
|
313
370
|
methodLabel,
|
|
314
371
|
errors,
|
|
@@ -319,11 +376,15 @@ function validateServiceMethods(value, label, errors) {
|
|
|
319
376
|
errors.push(`duplicate provided method name: ${method.name}`)
|
|
320
377
|
}
|
|
321
378
|
seen.add(method.name)
|
|
322
|
-
for (const key of ["scope", "label", "description", "route_path"]) {
|
|
379
|
+
for (const key of ["scope", "label", "description", "route_path", "capability_id"]) {
|
|
323
380
|
requireString(method, key, methodLabel, errors)
|
|
324
381
|
}
|
|
382
|
+
requireBoolean(method, "agent_exposable", methodLabel, errors)
|
|
383
|
+
requireBoolean(method, "supports_scheduling", methodLabel, errors)
|
|
325
384
|
requireBoolean(method, "deprecated", methodLabel, errors)
|
|
326
385
|
requireString(method, "replacement", methodLabel, errors)
|
|
386
|
+
validateCapabilityMetadata(method, methodLabel, errors)
|
|
387
|
+
validateAgentCapability(method, methodLabel, errors)
|
|
327
388
|
for (const key of ["input_schema", "input", "output_schema", "output"]) {
|
|
328
389
|
requireSchema(method, key, methodLabel, errors)
|
|
329
390
|
}
|
|
@@ -527,7 +588,7 @@ function validateMcp(value, errors) {
|
|
|
527
588
|
} else {
|
|
528
589
|
unknownKeys(value.provides, new Set(["tools", "resources", "prompts"]), "mcp.provides", errors)
|
|
529
590
|
const allowedByBucket = {
|
|
530
|
-
tools: new Set(["name", "label", "description", "input_schema", "output_schema", "annotations", "scope", "expose_external"]),
|
|
591
|
+
tools: new Set(["name", "label", "description", "input_schema", "output_schema", "annotations", "scope", "expose_external", "agent_exposable", "capability_id", "supports_scheduling", "deprecated", "replacement", ...CAPABILITY_METADATA_KEYS]),
|
|
531
592
|
resources: new Set(["name", "uri_template", "description", "mime_type", "expose_external"]),
|
|
532
593
|
prompts: new Set(["name", "description", "arguments", "expose_external"]),
|
|
533
594
|
}
|
|
@@ -553,7 +614,18 @@ function validateMcp(value, errors) {
|
|
|
553
614
|
if (seen.has(entry.name)) errors.push(`duplicate mcp.provides.${bucket} name: ${entry.name}`)
|
|
554
615
|
seen.add(entry.name)
|
|
555
616
|
requireBoolean(entry, "expose_external", label, errors)
|
|
617
|
+
requireBoolean(entry, "agent_exposable", label, errors)
|
|
618
|
+
requireBoolean(entry, "supports_scheduling", label, errors)
|
|
619
|
+
requireBoolean(entry, "deprecated", label, errors)
|
|
556
620
|
requireString(entry, "description", label, errors)
|
|
621
|
+
if (bucket === "tools") {
|
|
622
|
+
requireString(entry, "capability_id", label, errors)
|
|
623
|
+
requireString(entry, "replacement", label, errors)
|
|
624
|
+
requireSchema(entry, "input_schema", label, errors)
|
|
625
|
+
requireSchema(entry, "output_schema", label, errors)
|
|
626
|
+
validateCapabilityMetadata(entry, label, errors)
|
|
627
|
+
validateAgentCapability(entry, label, errors)
|
|
628
|
+
}
|
|
557
629
|
})
|
|
558
630
|
}
|
|
559
631
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
# Agent-tool plugin
|
|
2
2
|
|
|
3
|
-
Defines a
|
|
4
|
-
|
|
3
|
+
Defines a typed `echo` capability with the `@capability` SDK decorator and a
|
|
4
|
+
matching reviewed manifest contract. Once installed, chat agents, workflows,
|
|
5
|
+
and scheduled loops discover the same capability automatically.
|
|
6
|
+
|
|
7
|
+
Run `pltt capabilities list` to inspect the agent surface and `pltt test --agent`
|
|
8
|
+
before publishing.
|
|
@@ -1,14 +1,35 @@
|
|
|
1
|
-
"""Agent-
|
|
1
|
+
"""Agent-ready plugin backend with one typed, discoverable capability."""
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
The router exists so superadmin health checks have something to ping.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from palette_sdk import PluginRouter
|
|
3
|
+
from palette_sdk import PluginContext, PluginRouter, capability
|
|
8
4
|
|
|
9
5
|
router = PluginRouter(tags=["my-agent-tool"])
|
|
10
6
|
|
|
11
7
|
|
|
8
|
+
@capability(
|
|
9
|
+
"echo",
|
|
10
|
+
capability_id="utility.text.echo",
|
|
11
|
+
version="v1",
|
|
12
|
+
description="Echo text back as a structured result.",
|
|
13
|
+
input_schema={
|
|
14
|
+
"type": "object",
|
|
15
|
+
"properties": {"message": {"type": "string"}},
|
|
16
|
+
"required": ["message"],
|
|
17
|
+
},
|
|
18
|
+
output_schema={
|
|
19
|
+
"type": "object",
|
|
20
|
+
"properties": {"echoed": {"type": "string"}},
|
|
21
|
+
"required": ["echoed"],
|
|
22
|
+
},
|
|
23
|
+
effects=["read"],
|
|
24
|
+
risk="read",
|
|
25
|
+
idempotent=True,
|
|
26
|
+
timeout_seconds=30,
|
|
27
|
+
tags=["utility", "text"],
|
|
28
|
+
)
|
|
29
|
+
async def echo(ctx: PluginContext, payload: dict) -> dict:
|
|
30
|
+
return {"echoed": str(payload["message"])}
|
|
31
|
+
|
|
32
|
+
|
|
12
33
|
@router.get("/health")
|
|
13
34
|
async def health() -> dict:
|
|
14
35
|
return {"status": "ok"}
|
|
@@ -22,8 +22,39 @@
|
|
|
22
22
|
},
|
|
23
23
|
"backend": { "entry": "./backend/api/main.py" },
|
|
24
24
|
"public_routes": ["/health"],
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
"provides": {
|
|
26
|
+
"namespace": "my-agent-tool",
|
|
27
|
+
"services": [
|
|
28
|
+
{
|
|
29
|
+
"id": "agent-tools",
|
|
30
|
+
"version": "v1",
|
|
31
|
+
"label": "Agent tools",
|
|
32
|
+
"methods": [
|
|
33
|
+
{
|
|
34
|
+
"name": "echo",
|
|
35
|
+
"label": "Echo text",
|
|
36
|
+
"description": "Echo text back as a structured result.",
|
|
37
|
+
"input_schema": {
|
|
38
|
+
"type": "object",
|
|
39
|
+
"properties": { "message": { "type": "string" } },
|
|
40
|
+
"required": ["message"]
|
|
41
|
+
},
|
|
42
|
+
"output_schema": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"properties": { "echoed": { "type": "string" } },
|
|
45
|
+
"required": ["echoed"]
|
|
46
|
+
},
|
|
47
|
+
"capability_id": "utility.text.echo",
|
|
48
|
+
"agent_exposable": true,
|
|
49
|
+
"supports_scheduling": true,
|
|
50
|
+
"effects": ["read"],
|
|
51
|
+
"risk": "read",
|
|
52
|
+
"idempotent": true,
|
|
53
|
+
"timeout_seconds": 30,
|
|
54
|
+
"tags": ["utility", "text"]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
29
60
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"""Echo tool — agents can call this to echo a message back."""
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class EchoInput(BaseModel):
|
|
7
|
-
message: str
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class EchoOutput(BaseModel):
|
|
11
|
-
echoed: str
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
async def run(inp: EchoInput) -> EchoOutput:
|
|
15
|
-
return EchoOutput(echoed=inp.message)
|