@palettelab/cli 0.3.60 → 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 +44 -5
- package/backend-sdk/palette_sdk/__init__.py +25 -1
- package/backend-sdk/palette_sdk/capabilities.py +126 -0
- package/backend-sdk/palette_sdk/jobs.py +177 -0
- package/backend-sdk/palette_sdk/manifest.py +63 -1
- package/backend-sdk/palette_sdk/plugin_context.py +3 -0
- package/backend-sdk/palette_sdk/services.py +45 -6
- package/docs/python-backend-sdk.md +144 -0
- 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 +91 -3
- package/lib/dev-simulator.js +208 -1
- package/lib/manifest.js +76 -4
- 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/lib/dev-simulator.js
CHANGED
|
@@ -172,17 +172,20 @@ function writeBackendRunner(cwd, devDir, manifest, backendEntry, backendPort) {
|
|
|
172
172
|
|
|
173
173
|
import importlib
|
|
174
174
|
import importlib.util
|
|
175
|
+
import asyncio
|
|
175
176
|
import json
|
|
176
177
|
import os
|
|
177
178
|
import pathlib
|
|
178
179
|
import re
|
|
179
180
|
import sys
|
|
181
|
+
import traceback
|
|
180
182
|
import uuid
|
|
181
183
|
from datetime import datetime, timezone
|
|
182
184
|
from types import SimpleNamespace
|
|
183
185
|
|
|
184
186
|
from fastapi import FastAPI, HTTPException, Request, Response
|
|
185
187
|
from fastapi.middleware.cors import CORSMiddleware
|
|
188
|
+
from fastapi.responses import StreamingResponse
|
|
186
189
|
from starlette.middleware.base import BaseHTTPMiddleware
|
|
187
190
|
|
|
188
191
|
ROOT = pathlib.Path(${JSON.stringify(cwd)}).resolve()
|
|
@@ -367,6 +370,12 @@ router = getattr(module, "router", None)
|
|
|
367
370
|
if router is None:
|
|
368
371
|
raise RuntimeError(f"backend entry has no router export: {ENTRY}")
|
|
369
372
|
|
|
373
|
+
from palette_sdk.jobs import JobCancelledError, JobExecution, JobsClient, drain_pending_jobs
|
|
374
|
+
|
|
375
|
+
LOCAL_JOB_HANDLERS = {decl.name: decl for decl in drain_pending_jobs()}
|
|
376
|
+
LOCAL_JOBS = {}
|
|
377
|
+
LOCAL_JOB_TASKS = set()
|
|
378
|
+
|
|
370
379
|
engine = None
|
|
371
380
|
SessionLocal = None
|
|
372
381
|
if DATABASE_ENABLED:
|
|
@@ -380,6 +389,177 @@ if DATABASE_ENABLED:
|
|
|
380
389
|
engine = create_async_engine(DATABASE_URL)
|
|
381
390
|
SessionLocal = async_sessionmaker(engine, expire_on_commit=False)
|
|
382
391
|
|
|
392
|
+
def _local_job_view(record):
|
|
393
|
+
job_id = record["id"]
|
|
394
|
+
return {
|
|
395
|
+
**{key: value for key, value in record.items() if key != "task"},
|
|
396
|
+
"job_id": job_id,
|
|
397
|
+
"status_url": f"/api/v1/app-jobs/{job_id}",
|
|
398
|
+
"events_url": f"/api/v1/app-jobs/{job_id}/events",
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
class LocalJobExecutionAdapter:
|
|
402
|
+
def __init__(self, record):
|
|
403
|
+
self.record = record
|
|
404
|
+
|
|
405
|
+
async def progress(self, percent, message=None):
|
|
406
|
+
self.record["progress"] = percent
|
|
407
|
+
self.record["message"] = message
|
|
408
|
+
self.record["updated_at"] = datetime.now(timezone.utc).isoformat()
|
|
409
|
+
|
|
410
|
+
async def heartbeat(self):
|
|
411
|
+
self.record["updated_at"] = datetime.now(timezone.utc).isoformat()
|
|
412
|
+
|
|
413
|
+
async def cancelled(self):
|
|
414
|
+
return bool(self.record.get("cancel_requested"))
|
|
415
|
+
|
|
416
|
+
class LocalJobsService:
|
|
417
|
+
async def enqueue(self, name, payload, *, idempotency_key=None):
|
|
418
|
+
declaration = LOCAL_JOB_HANDLERS.get(name)
|
|
419
|
+
if declaration is None:
|
|
420
|
+
raise HTTPException(status_code=422, detail=f"local job handler is not registered: {name}")
|
|
421
|
+
if not isinstance(payload, dict):
|
|
422
|
+
raise HTTPException(status_code=422, detail="job payload must be a JSON object")
|
|
423
|
+
try:
|
|
424
|
+
json.dumps(payload)
|
|
425
|
+
except (TypeError, ValueError) as exc:
|
|
426
|
+
raise HTTPException(status_code=422, detail=f"job payload is not JSON serializable: {exc}")
|
|
427
|
+
if idempotency_key:
|
|
428
|
+
for existing in LOCAL_JOBS.values():
|
|
429
|
+
if existing["handler"] == name and existing.get("idempotency_key") == idempotency_key:
|
|
430
|
+
return _local_job_view(existing)
|
|
431
|
+
job_id = str(uuid.uuid4())
|
|
432
|
+
now = datetime.now(timezone.utc).isoformat()
|
|
433
|
+
record = {
|
|
434
|
+
"id": job_id,
|
|
435
|
+
"plugin_id": MANIFEST.get("id", ""),
|
|
436
|
+
"handler": name,
|
|
437
|
+
"payload": payload or {},
|
|
438
|
+
"result": None,
|
|
439
|
+
"status": "queued",
|
|
440
|
+
"progress": 0,
|
|
441
|
+
"message": None,
|
|
442
|
+
"attempt_count": 0,
|
|
443
|
+
"max_attempts": declaration.max_attempts,
|
|
444
|
+
"cancel_requested": False,
|
|
445
|
+
"error_code": None,
|
|
446
|
+
"error_message": None,
|
|
447
|
+
"idempotency_key": idempotency_key,
|
|
448
|
+
"created_at": now,
|
|
449
|
+
"started_at": None,
|
|
450
|
+
"completed_at": None,
|
|
451
|
+
"updated_at": now,
|
|
452
|
+
}
|
|
453
|
+
LOCAL_JOBS[job_id] = record
|
|
454
|
+
task = asyncio.create_task(_run_local_job(record, declaration))
|
|
455
|
+
LOCAL_JOB_TASKS.add(task)
|
|
456
|
+
task.add_done_callback(LOCAL_JOB_TASKS.discard)
|
|
457
|
+
return _local_job_view(record)
|
|
458
|
+
|
|
459
|
+
async def get(self, job_id):
|
|
460
|
+
record = LOCAL_JOBS.get(str(job_id))
|
|
461
|
+
if record is None:
|
|
462
|
+
raise HTTPException(status_code=404, detail="Local job not found")
|
|
463
|
+
return _local_job_view(record)
|
|
464
|
+
|
|
465
|
+
async def cancel(self, job_id):
|
|
466
|
+
record = LOCAL_JOBS.get(str(job_id))
|
|
467
|
+
if record is None:
|
|
468
|
+
raise HTTPException(status_code=404, detail="Local job not found")
|
|
469
|
+
if record["status"] not in ("completed", "failed", "cancelled"):
|
|
470
|
+
record["cancel_requested"] = True
|
|
471
|
+
if record["status"] == "queued":
|
|
472
|
+
record["status"] = "cancelled"
|
|
473
|
+
record["completed_at"] = datetime.now(timezone.utc).isoformat()
|
|
474
|
+
return _local_job_view(record)
|
|
475
|
+
|
|
476
|
+
LOCAL_JOB_SERVICE = LocalJobsService()
|
|
477
|
+
|
|
478
|
+
def _local_job_context(session):
|
|
479
|
+
from palette_sdk import PluginContext
|
|
480
|
+
from palette_sdk.apps import AppInteropClient
|
|
481
|
+
from palette_sdk.connections import PluginConnectionsClient
|
|
482
|
+
from palette_sdk.events import EventPublisher
|
|
483
|
+
from palette_sdk.notifications import NotificationsClient
|
|
484
|
+
from palette_sdk.organization import OrganizationInfo
|
|
485
|
+
from palette_sdk.platform_services import UnavailablePlatformService
|
|
486
|
+
|
|
487
|
+
return PluginContext(
|
|
488
|
+
db=session,
|
|
489
|
+
user_id="dev-user",
|
|
490
|
+
organization_id=1,
|
|
491
|
+
organization=OrganizationInfo.from_dict(DEV_ORGANIZATION),
|
|
492
|
+
org_role="owner",
|
|
493
|
+
plugin_id=MANIFEST.get("id", ""),
|
|
494
|
+
permissions=MANIFEST.get("permissions", []),
|
|
495
|
+
storage=DEV_STORAGE or UnavailablePlatformService("storage"),
|
|
496
|
+
connections=PluginConnectionsClient(None, DEV_CONNECTIONS),
|
|
497
|
+
apps=AppInteropClient(LocalAppInteropService()),
|
|
498
|
+
notifications=NotificationsClient(NOTIFICATIONS),
|
|
499
|
+
redis=DEV_REDIS or UnavailablePlatformService("redis"),
|
|
500
|
+
vector=DEV_VECTOR or UnavailablePlatformService("vector"),
|
|
501
|
+
events=EventPublisher(LocalEventPublisher()),
|
|
502
|
+
jobs=JobsClient(LOCAL_JOB_SERVICE),
|
|
503
|
+
config={
|
|
504
|
+
"secrets": DEV_SECRETS,
|
|
505
|
+
"secret_specs": MANIFEST.get("secrets") or {},
|
|
506
|
+
"secret_scope": "dev",
|
|
507
|
+
},
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
async def _run_local_job(record, declaration):
|
|
511
|
+
record["status"] = "running"
|
|
512
|
+
record["attempt_count"] = 1
|
|
513
|
+
record["started_at"] = datetime.now(timezone.utc).isoformat()
|
|
514
|
+
record["updated_at"] = record["started_at"]
|
|
515
|
+
adapter = LocalJobExecutionAdapter(record)
|
|
516
|
+
execution = JobExecution(
|
|
517
|
+
adapter,
|
|
518
|
+
job_id=record["id"],
|
|
519
|
+
attempt=1,
|
|
520
|
+
idempotency_key=record.get("idempotency_key"),
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
async def invoke(session):
|
|
524
|
+
ctx = _local_job_context(session)
|
|
525
|
+
return await declaration.handler(ctx, execution, record["payload"])
|
|
526
|
+
|
|
527
|
+
try:
|
|
528
|
+
await execution.check_cancelled()
|
|
529
|
+
if SessionLocal is None:
|
|
530
|
+
result = await asyncio.wait_for(
|
|
531
|
+
invoke(None), timeout=declaration.timeout_seconds
|
|
532
|
+
)
|
|
533
|
+
else:
|
|
534
|
+
async with SessionLocal() as session:
|
|
535
|
+
result = await asyncio.wait_for(
|
|
536
|
+
invoke(session), timeout=declaration.timeout_seconds
|
|
537
|
+
)
|
|
538
|
+
await session.commit()
|
|
539
|
+
if result is not None and not isinstance(result, dict):
|
|
540
|
+
raise TypeError("job handler must return a dict or None")
|
|
541
|
+
json.dumps(result)
|
|
542
|
+
if record["cancel_requested"]:
|
|
543
|
+
record["status"] = "cancelled"
|
|
544
|
+
record["message"] = "Cancelled"
|
|
545
|
+
else:
|
|
546
|
+
record["status"] = "completed"
|
|
547
|
+
record["progress"] = 100
|
|
548
|
+
record["message"] = record["message"] or "Completed"
|
|
549
|
+
record["result"] = result
|
|
550
|
+
except JobCancelledError:
|
|
551
|
+
record["status"] = "cancelled"
|
|
552
|
+
record["message"] = "Cancelled"
|
|
553
|
+
except Exception as exc:
|
|
554
|
+
record["status"] = "failed"
|
|
555
|
+
record["message"] = "Job failed"
|
|
556
|
+
record["error_code"] = type(exc).__name__
|
|
557
|
+
record["error_message"] = str(exc)
|
|
558
|
+
traceback.print_exc()
|
|
559
|
+
finally:
|
|
560
|
+
record["completed_at"] = datetime.now(timezone.utc).isoformat()
|
|
561
|
+
record["updated_at"] = record["completed_at"]
|
|
562
|
+
|
|
383
563
|
class DevPluginContextMiddleware(BaseHTTPMiddleware):
|
|
384
564
|
async def dispatch(self, request: Request, call_next):
|
|
385
565
|
request.state.user = SimpleNamespace(
|
|
@@ -400,6 +580,7 @@ class DevPluginContextMiddleware(BaseHTTPMiddleware):
|
|
|
400
580
|
request.state.plugin_local_connections = DEV_CONNECTIONS
|
|
401
581
|
request.state.plugin_apps = LocalAppInteropService()
|
|
402
582
|
request.state.plugin_events = LocalEventPublisher()
|
|
583
|
+
request.state.plugin_jobs = LOCAL_JOB_SERVICE
|
|
403
584
|
request.state.notifications = NOTIFICATIONS
|
|
404
585
|
request.state.storage = DEV_STORAGE
|
|
405
586
|
if DEV_REDIS is not None:
|
|
@@ -429,6 +610,32 @@ app.add_middleware(
|
|
|
429
610
|
app.add_middleware(DevPluginContextMiddleware)
|
|
430
611
|
app.include_router(router, prefix=f"/api/v1/plugins/{MANIFEST['id']}")
|
|
431
612
|
|
|
613
|
+
@app.get("/api/v1/app-jobs/{job_id}")
|
|
614
|
+
async def get_local_job(job_id: str):
|
|
615
|
+
return await LOCAL_JOB_SERVICE.get(job_id)
|
|
616
|
+
|
|
617
|
+
@app.post("/api/v1/app-jobs/{job_id}/cancel")
|
|
618
|
+
async def cancel_local_job(job_id: str):
|
|
619
|
+
return await LOCAL_JOB_SERVICE.cancel(job_id)
|
|
620
|
+
|
|
621
|
+
@app.get("/api/v1/app-jobs/{job_id}/events")
|
|
622
|
+
async def local_job_events(job_id: str):
|
|
623
|
+
await LOCAL_JOB_SERVICE.get(job_id)
|
|
624
|
+
|
|
625
|
+
async def stream():
|
|
626
|
+
last = None
|
|
627
|
+
while True:
|
|
628
|
+
current = await LOCAL_JOB_SERVICE.get(job_id)
|
|
629
|
+
marker = (current["status"], current["progress"], current["message"], current["updated_at"])
|
|
630
|
+
if marker != last:
|
|
631
|
+
yield "event: job\\ndata: " + json.dumps(current, default=str) + "\\n\\n"
|
|
632
|
+
last = marker
|
|
633
|
+
if current["status"] in ("completed", "failed", "cancelled"):
|
|
634
|
+
return
|
|
635
|
+
await asyncio.sleep(0.5)
|
|
636
|
+
|
|
637
|
+
return StreamingResponse(stream(), media_type="text/event-stream")
|
|
638
|
+
|
|
432
639
|
@app.post("/api/v1/app-storage/{plugin_id}/uploads")
|
|
433
640
|
async def create_local_app_storage_upload(plugin_id: str, request: Request):
|
|
434
641
|
_require_local_storage(plugin_id)
|
|
@@ -887,4 +1094,4 @@ async function startSimulator({ cwd, frontendPort, backendPort }) {
|
|
|
887
1094
|
await stop()
|
|
888
1095
|
}
|
|
889
1096
|
|
|
890
|
-
module.exports = { databaseDriverDependencies, resolveDevSecrets, startSimulator }
|
|
1097
|
+
module.exports = { databaseDriverDependencies, resolveDevSecrets, startSimulator, writeBackendRunner }
|
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
|
}
|
|
@@ -703,11 +775,11 @@ function validateManifest(m) {
|
|
|
703
775
|
else {
|
|
704
776
|
unknownKeys(
|
|
705
777
|
m.capabilities,
|
|
706
|
-
new Set(["frontend", "backend", "database", "webhooks", "scheduled_jobs", "file_uploads", "external_network"]),
|
|
778
|
+
new Set(["frontend", "backend", "database", "webhooks", "scheduled_jobs", "background_jobs", "file_uploads", "external_network"]),
|
|
707
779
|
"capabilities",
|
|
708
780
|
errors,
|
|
709
781
|
)
|
|
710
|
-
for (const key of ["frontend", "backend", "database", "webhooks", "scheduled_jobs", "file_uploads"]) {
|
|
782
|
+
for (const key of ["frontend", "backend", "database", "webhooks", "scheduled_jobs", "background_jobs", "file_uploads"]) {
|
|
711
783
|
requireBoolean(m.capabilities, key, "capabilities", errors)
|
|
712
784
|
}
|
|
713
785
|
if (m.capabilities.external_network !== undefined) {
|
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)
|