@coralai/sps-plugin-api 0.7.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 +50 -1
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -205,6 +205,32 @@ export interface SpsRegistryByKey<T = unknown> {
|
|
|
205
205
|
get(key: string): T | undefined;
|
|
206
206
|
list(): string[];
|
|
207
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
|
+
}
|
|
208
234
|
/** 工厂自带 id,注册时不另给 key。 */
|
|
209
235
|
export interface SpsRegistryByFactory<T = unknown> {
|
|
210
236
|
register(factory: T): () => void;
|
|
@@ -222,6 +248,27 @@ export interface SpsNotifier {
|
|
|
222
248
|
send(message: string, level?: 'info' | 'success' | 'warning' | 'error'): Promise<void>;
|
|
223
249
|
};
|
|
224
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
|
+
}
|
|
225
272
|
/** 建一张卡。形状照 MCP 面上的 `add_card`,不另发明。 */
|
|
226
273
|
export interface SpsNewCard {
|
|
227
274
|
title: string;
|
|
@@ -425,6 +472,7 @@ export declare const SPS_SERVICES: {
|
|
|
425
472
|
readonly events: "sps.events";
|
|
426
473
|
readonly projects: "sps.projects";
|
|
427
474
|
readonly cards: "sps.cards";
|
|
475
|
+
readonly jobs: "sps.jobs";
|
|
428
476
|
readonly subprocess: "sps.subprocess";
|
|
429
477
|
readonly attachments: "sps.attachments";
|
|
430
478
|
readonly media: "sps.media";
|
|
@@ -446,8 +494,9 @@ export interface SpsPluginContext {
|
|
|
446
494
|
'sps.events': SpsEvents;
|
|
447
495
|
'sps.projects': SpsProjects;
|
|
448
496
|
'sps.cards': SpsCards;
|
|
497
|
+
'sps.jobs': SpsJobs;
|
|
449
498
|
'sps.capabilities': SpsCapabilities;
|
|
450
|
-
'sps.media':
|
|
499
|
+
'sps.media': SpsMedia;
|
|
451
500
|
'sps.im': SpsRegistryByKey;
|
|
452
501
|
'sps.agents': SpsRegistryByFactory;
|
|
453
502
|
'sps.repo': SpsRegistryByFactory;
|
package/dist/index.js
CHANGED