@coralai/sps-plugin-api 0.5.0 → 0.6.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.
Files changed (2) hide show
  1. package/dist/index.d.ts +95 -1
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -94,6 +94,84 @@ export interface SpsPromptSection {
94
94
  export interface SpsSystemPrompt {
95
95
  section(section: SpsPromptSection): () => void;
96
96
  }
97
+ /**
98
+ * 一个**工具卡能力** —— 由编排驱动、不占 worker 槽位的那类执行体。
99
+ *
100
+ * 🔴 和 `sps.tools`(MCP 工具)的区别不是形状,是**谁触发、多久**:
101
+ * MCP 工具是 **agent 主动调**,agent 阻塞等它 —— 适合秒级。
102
+ * 能力是**编排调度的一张卡**,和 worker 并行、可以跑分钟级,
103
+ * `mode:'async'` 的甚至返回后任务仍在跑(由 join 卡等终态)。
104
+ * 要做"生成一批图"这种事,选能力,别选工具。
105
+ */
106
+ export interface SpsCapability {
107
+ /** 能力 id,卡片用它引用。命名 `<域>.<动作>`,如 `art.chromaKey`。 */
108
+ id: string;
109
+ mode: 'sync' | 'async';
110
+ /**
111
+ * 参数形状由**能力**定,不是卡片里的自由 JSON。
112
+ * ⚠️ 运行时必须是一个 **Zod schema**(能力表拿它校验卡片参数)——
113
+ * 这里只声明结构最小面,免得契约包为此依赖 zod。
114
+ */
115
+ inputSchema: {
116
+ parse(value: unknown): unknown;
117
+ };
118
+ /**
119
+ * 这个能力会写什么(相对项目根的路径模式)。
120
+ * 🔴 **可审计性的来源**:不读代码就知道这张卡会写什么。
121
+ * ⚠️ 你声明了不等于 sps 会拦 —— 越界靠围栏兜(realpath + 项目根内),不靠这条声明。
122
+ */
123
+ produces: string[];
124
+ /** 可信度来源。卡片不看这一格,**审计要看**。 */
125
+ source: {
126
+ kind: 'built-in';
127
+ } | {
128
+ kind: 'script';
129
+ template: string;
130
+ script: string;
131
+ };
132
+ /** 一句话说明,给编排页展示。 */
133
+ summary: string;
134
+ /** 执行体。`async` 能力返回后**任务仍在跑**。 */
135
+ run(input: unknown, ctx: {
136
+ /** 项目在共享树下的相对路径(`t<租户>/<产品>/<项目>`)。 */
137
+ project: string;
138
+ /** 项目工作区绝对路径。**能力不从卡片收路径**,只从这里取根。 */
139
+ projectDir: string;
140
+ }): Promise<Record<string, unknown>>;
141
+ }
142
+ export interface SpsCapabilities {
143
+ register(cap: SpsCapability): () => void;
144
+ get(id: string): SpsCapability | undefined;
145
+ list(): SpsCapability[];
146
+ }
147
+ /**
148
+ * ⚠️ 下面四个的**载荷形状**(adapter / factory)住在 sps 里,还没有真实的第三方消费方,
149
+ * 所以这里只声明**注册表本身**,载荷留 `unknown`。
150
+ * 要写这四类插件时告诉我们,按真实需求把形状定出来 ——
151
+ * 凭空定一个大接口,大概率定错位置和粒度。
152
+ */
153
+ export interface SpsRegistryByKey<T = unknown> {
154
+ register(key: string, value: T): () => void;
155
+ get(key: string): T | undefined;
156
+ list(): string[];
157
+ }
158
+ /** 工厂自带 id,注册时不另给 key。 */
159
+ export interface SpsRegistryByFactory<T = unknown> {
160
+ register(factory: T): () => void;
161
+ list(): string[];
162
+ }
163
+ /**
164
+ * ⚠️ 同上:这两个是**甲·工厂型**(换实现,不是收一组),
165
+ * 今天没有第三方在换它们。声明方法名,形状留 `unknown`。
166
+ */
167
+ export interface SpsMemory {
168
+ buildInjection(refs: unknown[]): string;
169
+ }
170
+ export interface SpsNotifier {
171
+ open(config: unknown): {
172
+ send(message: string, level?: 'info' | 'success' | 'warning' | 'error'): Promise<void>;
173
+ };
174
+ }
97
175
  /** 建一张卡。形状照 MCP 面上的 `add_card`,不另发明。 */
98
176
  export interface SpsNewCard {
99
177
  title: string;
@@ -129,7 +207,16 @@ export interface SpsCardRef {
129
207
  * ⚠️ 不开 move / delete:那些是流水线在做的事,掺进来就有两个写入方。
130
208
  */
131
209
  export interface SpsCards {
132
- /** 失败**抛**(建卡没成功而静默返回,你会以为建好了)。 */
210
+ /**
211
+ * 失败**抛**(建卡没成功而静默返回,你会以为建好了)。
212
+ *
213
+ * 🔴 **你传的 `labels` 会被核对**:落不上会抛,并把 `seq` 带出来。
214
+ * 底层 `setLabels` 失败是被吞掉的,而回执在某些路径下会拿你传的值填 ——
215
+ * 两处叠加就是"卡建了、label 没落上、回执还说落上了"。
216
+ * 对 `AI-PIPELINE` 那只是"没走流水线";
217
+ * 但拿 label 当**幂等键**时,下一轮找不到键就会**重复建一整套**,全程不报错。
218
+ * ⇒ 这一层替你核过了。抛的时候卡**已经建了**,`seq` 在错误消息里,自己收拾。
219
+ */
133
220
  create(project: string, card: SpsNewCard): Promise<SpsCardRef>;
134
221
  list(project: string): Promise<SpsCardRef[]>;
135
222
  }
@@ -309,6 +396,13 @@ export interface SpsPluginContext {
309
396
  'sps.events': SpsEvents;
310
397
  'sps.projects': SpsProjects;
311
398
  'sps.cards': SpsCards;
399
+ 'sps.capabilities': SpsCapabilities;
400
+ 'sps.media': SpsRegistryByKey;
401
+ 'sps.im': SpsRegistryByKey;
402
+ 'sps.agents': SpsRegistryByFactory;
403
+ 'sps.repo': SpsRegistryByFactory;
404
+ 'sps.memory': SpsMemory;
405
+ 'sps.notifier': SpsNotifier;
312
406
  'sps.subprocess': SpsSubprocess;
313
407
  'sps.attachments': SpsAttachments;
314
408
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralai/sps-plugin-api",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "sps 宿主半区的插件契约:ctx 上那些服务的方法签名。插件装它拿类型。",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",