@coralai/sps-plugin-api 0.1.0 → 0.3.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 CHANGED
@@ -94,6 +94,98 @@ export interface SpsPromptSection {
94
94
  export interface SpsSystemPrompt {
95
95
  section(section: SpsPromptSection): () => void;
96
96
  }
97
+ /**
98
+ * 一个项目的**身份**信息。
99
+ *
100
+ * ⚠️ 刻意不带卡片/worker 统计:那些每次都要扫盘。要统计走 HTTP API。
101
+ */
102
+ export interface SpsProjectRef {
103
+ name: string;
104
+ /** 显示名。无则 null。 */
105
+ label: string | null;
106
+ /**
107
+ * 目录布局用的分段。
108
+ * ⚠️ **不是权限主体** —— sps 里它只决定工作区目录长什么样,不参与任何决策。
109
+ * 要按租户过滤是你自己的事。
110
+ */
111
+ namespace: string | null;
112
+ /** 创建方标记(`sps` / 平台名)。 */
113
+ origin: string;
114
+ repoDir: string | null;
115
+ }
116
+ /**
117
+ * 项目注册表(**只读**)。
118
+ *
119
+ * 🔴 v1 不开"建项目" —— 那牵着注册边界那一摊(建项目会改写被认领的树)。
120
+ */
121
+ export interface SpsProjects {
122
+ list(): Promise<SpsProjectRef[]>;
123
+ /** 不存在返回 `undefined`,**不抛**。 */
124
+ get(name: string): Promise<SpsProjectRef | undefined>;
125
+ }
126
+ export interface SpsEvent {
127
+ /** 事件名。点分层级,订阅时按前缀过滤(`'card.'` 收全部卡片事件)。 */
128
+ type: string;
129
+ /** 发生时刻(ms),由**发布方**打 —— 你拿到的时间可能晚很多。 */
130
+ at: number;
131
+ /** 谁发的:`sps` = 宿主,其余是插件 id。 */
132
+ source: string;
133
+ project?: string;
134
+ /** 🔴 只有 sps 自己的概念(project / seq / state / slot …)。**没有租户 id** —— 那是平台自己的映射。 */
135
+ payload: Record<string, unknown>;
136
+ }
137
+ /**
138
+ * 订阅"执行侧真的发生了什么"。
139
+ *
140
+ * 🔴 **没有重放、没有缓冲。** 进程没跑时发生的事拿不到,你掉线期间的也补不回来。
141
+ * **对账走 API**,别把它当可靠队列 —— 否则会出现"我以为我知道、其实漏了一段"。
142
+ * 🔴 **别在回调里做慢事**:宿主不 await 你,但你占着的是发布方的调用栈。
143
+ * 要发网络请求就自己排队。
144
+ *
145
+ * 今天宿主发的:
146
+ * ```
147
+ * card.moved { seq, to } card.labeled { seq, label }
148
+ * card.unlabeled { seq, label } card.claimed { seq, slot }
149
+ * card.released { seq } card.created { seq, title, state }
150
+ * ```
151
+ */
152
+ export interface SpsEvents {
153
+ emit(ev: Omit<SpsEvent, 'at' | 'source'> & {
154
+ source?: string;
155
+ }): void;
156
+ subscribe(prefix: string, cb: (ev: SpsEvent) => void): () => void;
157
+ }
158
+ export interface SpsLlmTextRequest {
159
+ prompt: string;
160
+ system?: string;
161
+ /**
162
+ * 谁在调 —— 你的插件 id。**必填**:插件调模型花的是宿主的额度,
163
+ * 归因唯一可靠的来源是调用方自报(从调用栈猜会在异步边界上失真)。
164
+ */
165
+ by: string;
166
+ /** 上限,超了当失败。默认 180s。 */
167
+ timeoutMs?: number;
168
+ }
169
+ export interface SpsLlmTextResult {
170
+ text: string;
171
+ /** 实际用的模型。 */
172
+ model: string;
173
+ }
174
+ /**
175
+ * 用 sps 配好的模型出一段文本。
176
+ *
177
+ * 🔴 **它不是 dsh 的 `llm`。** dsh 的那个是一整套适配器注册表
178
+ * (`stream / listModels / resolveModel / registerAdapter / …`)。
179
+ * 这里只承诺一件事:出一段文本。别照着 dsh 的用法写。
180
+ */
181
+ export interface SpsLlm {
182
+ text(req: SpsLlmTextRequest): Promise<SpsLlmTextResult>;
183
+ /** 现在会用哪个模型(不发请求)。 */
184
+ describe(): {
185
+ provider: string;
186
+ model: string;
187
+ };
188
+ }
97
189
  export interface SpsSpawnSpec {
98
190
  argv: readonly string[];
99
191
  cwd: string;
@@ -137,6 +229,9 @@ export declare const SPS_SERVICES: {
137
229
  readonly webserver: "sps.webserver";
138
230
  readonly settings: "sps.settings";
139
231
  readonly systemPrompt: "sps.systemPrompt";
232
+ readonly llm: "sps.llm";
233
+ readonly events: "sps.events";
234
+ readonly projects: "sps.projects";
140
235
  readonly subprocess: "sps.subprocess";
141
236
  readonly attachments: "sps.attachments";
142
237
  readonly media: "sps.media";
@@ -154,6 +249,9 @@ export interface SpsPluginContext {
154
249
  'sps.webserver': SpsWebServer;
155
250
  'sps.settings': SpsSettings;
156
251
  'sps.systemPrompt': SpsSystemPrompt;
252
+ 'sps.llm': SpsLlm;
253
+ 'sps.events': SpsEvents;
254
+ 'sps.projects': SpsProjects;
157
255
  'sps.subprocess': SpsSubprocess;
158
256
  'sps.attachments': SpsAttachments;
159
257
  }
package/dist/index.js CHANGED
@@ -19,6 +19,9 @@ export const SPS_SERVICES = {
19
19
  webserver: 'sps.webserver',
20
20
  settings: 'sps.settings',
21
21
  systemPrompt: 'sps.systemPrompt',
22
+ llm: 'sps.llm',
23
+ events: 'sps.events',
24
+ projects: 'sps.projects',
22
25
  subprocess: 'sps.subprocess',
23
26
  attachments: 'sps.attachments',
24
27
  media: 'sps.media',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralai/sps-plugin-api",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "sps 宿主半区的插件契约:ctx 上那些服务的方法签名。插件装它拿类型。",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",