@coralai/sps-plugin-api 0.6.0 → 0.8.0
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/dist/index.d.ts +108 -9
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -103,7 +103,19 @@ export interface SpsSystemPrompt {
|
|
|
103
103
|
* `mode:'async'` 的甚至返回后任务仍在跑(由 join 卡等终态)。
|
|
104
104
|
* 要做"生成一批图"这种事,选能力,别选工具。
|
|
105
105
|
*/
|
|
106
|
-
export
|
|
106
|
+
export type SpsAsyncPoll = {
|
|
107
|
+
done: false;
|
|
108
|
+
} | {
|
|
109
|
+
done: true;
|
|
110
|
+
ok: true;
|
|
111
|
+
result: Record<string, unknown>;
|
|
112
|
+
} | {
|
|
113
|
+
done: true;
|
|
114
|
+
ok: false;
|
|
115
|
+
error: string;
|
|
116
|
+
};
|
|
117
|
+
/** 两种能力共有的那部分。 */
|
|
118
|
+
export interface SpsCapabilityBase {
|
|
107
119
|
/** 能力 id,卡片用它引用。命名 `<域>.<动作>`,如 `art.chromaKey`。 */
|
|
108
120
|
id: string;
|
|
109
121
|
mode: 'sync' | 'async';
|
|
@@ -131,14 +143,52 @@ export interface SpsCapability {
|
|
|
131
143
|
};
|
|
132
144
|
/** 一句话说明,给编排页展示。 */
|
|
133
145
|
summary: string;
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
/**
|
|
147
|
+
* 这个能力失败时,**这张卡怎么处置**。缺省 `'block'`。
|
|
148
|
+
* ```
|
|
149
|
+
* block 留在原地打 NEEDS-FIX —— 波次屏障挡住后面所有卡,图上看得见它卡住了
|
|
150
|
+
* skip 标 Canceled ⇒ 屏障**放行**,后续卡照跑(留痕写进卡片 meta)
|
|
151
|
+
* ```
|
|
152
|
+
* 🔴 声明式,不是"能力自己去改卡片状态" —— 后者会让卡片有两个写入方。
|
|
153
|
+
* ⚠️ `'skip'` 给"部分失败是常态"的工序用;scaffold/package 这种别用。
|
|
154
|
+
*/
|
|
155
|
+
onFailure?: 'block' | 'skip';
|
|
156
|
+
}
|
|
157
|
+
export interface SpsCapabilityCtx {
|
|
158
|
+
/** 项目在共享树下的相对路径(`t<租户>/<产品>/<项目>`)。 */
|
|
159
|
+
project: string;
|
|
160
|
+
/** 项目工作区绝对路径。**能力不从卡片收路径**,只从这里取根。 */
|
|
161
|
+
projectDir: string;
|
|
141
162
|
}
|
|
163
|
+
/** 同步能力:`run` 返回即完成。 */
|
|
164
|
+
export interface SpsSyncCapability extends SpsCapabilityBase {
|
|
165
|
+
mode: 'sync';
|
|
166
|
+
run(input: unknown, ctx: SpsCapabilityCtx): Promise<Record<string, unknown>>;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 异步能力:`start` 立刻返回,引擎每个 tick `poll` 一次。
|
|
170
|
+
*
|
|
171
|
+
* 🔴 **卡片在真正跑完之前不标 Done** —— 波次屏障(`order`)因此天然成为 join。
|
|
172
|
+
* "打包必须等美术"用 order 表达即可,没有单独的 join 卡执行路径,也不需要。
|
|
173
|
+
*/
|
|
174
|
+
export interface SpsAsyncCapability extends SpsCapabilityBase {
|
|
175
|
+
mode: 'async';
|
|
176
|
+
/** 启动外部任务并**立刻返回**。handle 存进卡片 meta。 */
|
|
177
|
+
start(input: unknown, ctx: SpsCapabilityCtx): Promise<{
|
|
178
|
+
handle: string;
|
|
179
|
+
}>;
|
|
180
|
+
/**
|
|
181
|
+
* 问状态。**每个 tick 都会调 ⇒ 必须便宜且幂等。**
|
|
182
|
+
* 别在这里重新扫盘或重新请求全量 —— 它会按 tick 频率被放大。
|
|
183
|
+
*/
|
|
184
|
+
poll(handle: string, ctx: SpsCapabilityCtx): Promise<SpsAsyncPoll>;
|
|
185
|
+
/**
|
|
186
|
+
* 多久算超时(ms)。缺省 **30 分钟**。
|
|
187
|
+
* ⚠️ 超时**由引擎按 startedAt 判**,不问你 —— 你可能正好卡死在自己的等待上。
|
|
188
|
+
*/
|
|
189
|
+
timeoutMs?: number;
|
|
190
|
+
}
|
|
191
|
+
export type SpsCapability = SpsSyncCapability | SpsAsyncCapability;
|
|
142
192
|
export interface SpsCapabilities {
|
|
143
193
|
register(cap: SpsCapability): () => void;
|
|
144
194
|
get(id: string): SpsCapability | undefined;
|
|
@@ -155,6 +205,32 @@ export interface SpsRegistryByKey<T = unknown> {
|
|
|
155
205
|
get(key: string): T | undefined;
|
|
156
206
|
list(): string[];
|
|
157
207
|
}
|
|
208
|
+
/** `sps.media`:注册表 + **一个使用方法**。 */
|
|
209
|
+
export interface SpsMedia extends SpsRegistryByKey {
|
|
210
|
+
/**
|
|
211
|
+
* 用注册进来的适配器生成一个媒体资产并落盘。
|
|
212
|
+
*
|
|
213
|
+
* ⚠️ **同步等待**(一张图几十秒)。async 能力应当把它丢进 `sps.jobs`,
|
|
214
|
+
* 不要在 `start` 里 await —— 那会把 tick 卡住。
|
|
215
|
+
*/
|
|
216
|
+
generate(spec: {
|
|
217
|
+
capability: 'image' | 'video' | 'music' | 'voice' | '3d' | 'embedding' | 'rerank';
|
|
218
|
+
prompt: string;
|
|
219
|
+
/** 运行目录(产物落这)。 */
|
|
220
|
+
cwd: string;
|
|
221
|
+
/** 相对 cwd 的输出路径;省略则自动命名到 assets/。 */
|
|
222
|
+
outPath?: string;
|
|
223
|
+
size?: string;
|
|
224
|
+
referenceUrl?: string;
|
|
225
|
+
/** 点名用哪一家;不传 = 按能力解析默认那家。 */
|
|
226
|
+
providerId?: string;
|
|
227
|
+
}): Promise<{
|
|
228
|
+
path: string;
|
|
229
|
+
provider: string;
|
|
230
|
+
model?: string;
|
|
231
|
+
bytes: number;
|
|
232
|
+
}>;
|
|
233
|
+
}
|
|
158
234
|
/** 工厂自带 id,注册时不另给 key。 */
|
|
159
235
|
export interface SpsRegistryByFactory<T = unknown> {
|
|
160
236
|
register(factory: T): () => void;
|
|
@@ -172,6 +248,27 @@ export interface SpsNotifier {
|
|
|
172
248
|
send(message: string, level?: 'info' | 'success' | 'warning' | 'error'): Promise<void>;
|
|
173
249
|
};
|
|
174
250
|
}
|
|
251
|
+
/** 与 `SpsAsyncPoll` 同形 —— async 能力的 `poll` 可以**直接透传**。 */
|
|
252
|
+
export type SpsJobStatus = SpsAsyncPoll;
|
|
253
|
+
/**
|
|
254
|
+
* 后台任务表:async 能力用它把长任务跑起来并拿到 handle。
|
|
255
|
+
*
|
|
256
|
+
* ```js
|
|
257
|
+
* start: (input, ctx) => ({ handle: jobs.start(() => media.generate({...})) }),
|
|
258
|
+
* poll: (handle) => jobs.poll(handle), // 形状一样,直接透传
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* ⚠️ **在内存里。** `sps tick <project>` 是常驻循环进程,start 与 poll 在同一个进程 ——
|
|
262
|
+
* 但它会被 stop / 重启,那时 handle 就没了。
|
|
263
|
+
* 🔴 **认不出的 handle 会当失败并说明原因**,不会回 `{done:false}` ——
|
|
264
|
+
* 后者的表现是卡片一直等到超时、然后被归因成"任务太慢",而真因是进程重启过。
|
|
265
|
+
* ⚠️ 不做持久化:重启 ⇒ 那张卡失败并说清楚 ⇒ 重跑它。
|
|
266
|
+
*/
|
|
267
|
+
export interface SpsJobs {
|
|
268
|
+
/** 立刻返回 handle。`fn` 抛出**不冒泡**(没人接得住),变成 `poll` 的 error。 */
|
|
269
|
+
start(fn: () => Promise<Record<string, unknown>>): string;
|
|
270
|
+
poll(handle: string): SpsJobStatus;
|
|
271
|
+
}
|
|
175
272
|
/** 建一张卡。形状照 MCP 面上的 `add_card`,不另发明。 */
|
|
176
273
|
export interface SpsNewCard {
|
|
177
274
|
title: string;
|
|
@@ -375,6 +472,7 @@ export declare const SPS_SERVICES: {
|
|
|
375
472
|
readonly events: "sps.events";
|
|
376
473
|
readonly projects: "sps.projects";
|
|
377
474
|
readonly cards: "sps.cards";
|
|
475
|
+
readonly jobs: "sps.jobs";
|
|
378
476
|
readonly subprocess: "sps.subprocess";
|
|
379
477
|
readonly attachments: "sps.attachments";
|
|
380
478
|
readonly media: "sps.media";
|
|
@@ -396,8 +494,9 @@ export interface SpsPluginContext {
|
|
|
396
494
|
'sps.events': SpsEvents;
|
|
397
495
|
'sps.projects': SpsProjects;
|
|
398
496
|
'sps.cards': SpsCards;
|
|
497
|
+
'sps.jobs': SpsJobs;
|
|
399
498
|
'sps.capabilities': SpsCapabilities;
|
|
400
|
-
'sps.media':
|
|
499
|
+
'sps.media': SpsMedia;
|
|
401
500
|
'sps.im': SpsRegistryByKey;
|
|
402
501
|
'sps.agents': SpsRegistryByFactory;
|
|
403
502
|
'sps.repo': SpsRegistryByFactory;
|
package/dist/index.js
CHANGED