@coralai/sps-plugin-api 0.1.0 → 0.2.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,69 @@ export interface SpsPromptSection {
94
94
  export interface SpsSystemPrompt {
95
95
  section(section: SpsPromptSection): () => void;
96
96
  }
97
+ export interface SpsEvent {
98
+ /** 事件名。点分层级,订阅时按前缀过滤(`'card.'` 收全部卡片事件)。 */
99
+ type: string;
100
+ /** 发生时刻(ms),由**发布方**打 —— 你拿到的时间可能晚很多。 */
101
+ at: number;
102
+ /** 谁发的:`sps` = 宿主,其余是插件 id。 */
103
+ source: string;
104
+ project?: string;
105
+ /** 🔴 只有 sps 自己的概念(project / seq / state / slot …)。**没有租户 id** —— 那是平台自己的映射。 */
106
+ payload: Record<string, unknown>;
107
+ }
108
+ /**
109
+ * 订阅"执行侧真的发生了什么"。
110
+ *
111
+ * 🔴 **没有重放、没有缓冲。** 进程没跑时发生的事拿不到,你掉线期间的也补不回来。
112
+ * **对账走 API**,别把它当可靠队列 —— 否则会出现"我以为我知道、其实漏了一段"。
113
+ * 🔴 **别在回调里做慢事**:宿主不 await 你,但你占着的是发布方的调用栈。
114
+ * 要发网络请求就自己排队。
115
+ *
116
+ * 今天宿主发的:
117
+ * ```
118
+ * card.moved { seq, to } card.labeled { seq, label }
119
+ * card.unlabeled { seq, label } card.claimed { seq, slot }
120
+ * card.released { seq } card.created { seq, title, state }
121
+ * ```
122
+ */
123
+ export interface SpsEvents {
124
+ emit(ev: Omit<SpsEvent, 'at' | 'source'> & {
125
+ source?: string;
126
+ }): void;
127
+ subscribe(prefix: string, cb: (ev: SpsEvent) => void): () => void;
128
+ }
129
+ export interface SpsLlmTextRequest {
130
+ prompt: string;
131
+ system?: string;
132
+ /**
133
+ * 谁在调 —— 你的插件 id。**必填**:插件调模型花的是宿主的额度,
134
+ * 归因唯一可靠的来源是调用方自报(从调用栈猜会在异步边界上失真)。
135
+ */
136
+ by: string;
137
+ /** 上限,超了当失败。默认 180s。 */
138
+ timeoutMs?: number;
139
+ }
140
+ export interface SpsLlmTextResult {
141
+ text: string;
142
+ /** 实际用的模型。 */
143
+ model: string;
144
+ }
145
+ /**
146
+ * 用 sps 配好的模型出一段文本。
147
+ *
148
+ * 🔴 **它不是 dsh 的 `llm`。** dsh 的那个是一整套适配器注册表
149
+ * (`stream / listModels / resolveModel / registerAdapter / …`)。
150
+ * 这里只承诺一件事:出一段文本。别照着 dsh 的用法写。
151
+ */
152
+ export interface SpsLlm {
153
+ text(req: SpsLlmTextRequest): Promise<SpsLlmTextResult>;
154
+ /** 现在会用哪个模型(不发请求)。 */
155
+ describe(): {
156
+ provider: string;
157
+ model: string;
158
+ };
159
+ }
97
160
  export interface SpsSpawnSpec {
98
161
  argv: readonly string[];
99
162
  cwd: string;
@@ -137,6 +200,8 @@ export declare const SPS_SERVICES: {
137
200
  readonly webserver: "sps.webserver";
138
201
  readonly settings: "sps.settings";
139
202
  readonly systemPrompt: "sps.systemPrompt";
203
+ readonly llm: "sps.llm";
204
+ readonly events: "sps.events";
140
205
  readonly subprocess: "sps.subprocess";
141
206
  readonly attachments: "sps.attachments";
142
207
  readonly media: "sps.media";
@@ -154,6 +219,8 @@ export interface SpsPluginContext {
154
219
  'sps.webserver': SpsWebServer;
155
220
  'sps.settings': SpsSettings;
156
221
  'sps.systemPrompt': SpsSystemPrompt;
222
+ 'sps.llm': SpsLlm;
223
+ 'sps.events': SpsEvents;
157
224
  'sps.subprocess': SpsSubprocess;
158
225
  'sps.attachments': SpsAttachments;
159
226
  }
package/dist/index.js CHANGED
@@ -19,6 +19,8 @@ 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',
22
24
  subprocess: 'sps.subprocess',
23
25
  attachments: 'sps.attachments',
24
26
  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.2.0",
4
4
  "description": "sps 宿主半区的插件契约:ctx 上那些服务的方法签名。插件装它拿类型。",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",