@xyz-agent/extension-protocol 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.
package/dist/index.d.mts CHANGED
@@ -309,4 +309,140 @@ declare function getAskUserOther(answers: AskUserAnswers, question: AskUserQuest
309
309
  */
310
310
  declare function isAskUserQuestion(value: unknown): value is AskUserQuestion;
311
311
 
312
- export { ASK_USER_MARKER, type AskUserAnswers, type AskUserOption, type AskUserQuestion, GUI_WIDGET_MARKER, type GuiComponent, type GuiComponentProps, type GuiComponentType, type GuiContext, type GuiRenderResult, PROTOCOL_VERSION, type StatItem, type TreeItem, type TreeItemIcon, type WidgetMeta, askUserInteract, extractGui, getAskUserAnswer, getAskUserOther, guiComponent, guiResult, guiSetWidget, isAskUserQuestion, isGuiCapable, isGuiComponent, isGuiRenderResult };
312
+ /**
313
+ * session-manager 请求的 title marker。runtime event-adapter 和 handler
314
+ * 检测此 marker 区分 session-manager 请求与普通 select。
315
+ *
316
+ * NUL 前缀确保不会与 extension 正常的 select title 冲突。
317
+ * 与 ASK_USER_MARKER / GUI_WIDGET_MARKER 同理。
318
+ */
319
+ declare const SESSION_MANAGER_MARKER = "\0XYZ_SESSION_MANAGER";
320
+ /**
321
+ * 6 个 action 的运行时集合(与 SessionManagerAction 类型同源——types.ts 从此派生)。
322
+ * event-adapter 用它把 JSON 解析出的 action 字符串收窄为联合类型,
323
+ * 非法值折叠为 '__malformed__' 哨兵(与 handler default 分支同走 cancelled)。
324
+ */
325
+ declare const SESSION_MANAGER_ACTIONS: readonly ["create", "send", "history", "status", "list", "abort"];
326
+
327
+ /**
328
+ * session-manager extension 的类型定义。
329
+ *
330
+ * 6 个 action 的请求 params 和结果类型,供 handler 和 extension 共用。
331
+ * marker 检测后按 action 分发到对应 handler 分支。
332
+ */
333
+
334
+ /** session-manager 支持的 6 个 action(从 SESSION_MANAGER_ACTIONS 集合派生,值与类型同源) */
335
+ type SessionManagerAction = (typeof SESSION_MANAGER_ACTIONS)[number];
336
+ /** session-manager 请求的统一形状(extension → runtime via select 通道) */
337
+ interface SessionManagerRequest {
338
+ action: SessionManagerAction;
339
+ params: SessionManagerParams[SessionManagerAction];
340
+ }
341
+ /** 各 action 的请求参数映射 */
342
+ interface SessionManagerParams {
343
+ create: SessionManagerCreateParams;
344
+ send: SessionManagerSendParams;
345
+ history: SessionManagerHistoryParams;
346
+ status: SessionManagerStatusParams;
347
+ list: SessionManagerListParams;
348
+ abort: SessionManagerAbortParams;
349
+ }
350
+ /** create action 参数 */
351
+ interface SessionManagerCreateParams {
352
+ /** session 工作目录 */
353
+ cwd?: string;
354
+ /** session 标签 */
355
+ label?: string;
356
+ /** 初始 prompt(可选;提供时 create 后立即注入——设计文档 §5.2 原子性决策) */
357
+ prompt?: string;
358
+ /** 模型覆盖(可选,透传 SessionService.create 的 modelOverride) */
359
+ model?: string;
360
+ /** thinking 级别覆盖(可选,透传 thinkingOverride) */
361
+ thinkingLevel?: string;
362
+ }
363
+ /** send action 参数 */
364
+ interface SessionManagerSendParams {
365
+ sessionId: string;
366
+ prompt: string;
367
+ }
368
+ /** history action 参数 */
369
+ interface SessionManagerHistoryParams {
370
+ sessionId: string;
371
+ /** 截断尾部 turn 数(0 = 不截断) */
372
+ tailTurns?: number;
373
+ }
374
+ /** status action 参数 */
375
+ interface SessionManagerStatusParams {
376
+ sessionId: string;
377
+ }
378
+ /** list action 参数 */
379
+ interface SessionManagerListParams {
380
+ /** 按 spawnSource 过滤 */
381
+ spawnSource?: 'user' | 'agent';
382
+ /** 按 parentAgentSessionId 过滤(handler 一律以路由上下文父 id 为准,此字段仅作显式收窄提示) */
383
+ parentAgentSessionId?: string;
384
+ }
385
+ /** abort action 参数 */
386
+ interface SessionManagerAbortParams {
387
+ sessionId: string;
388
+ }
389
+ /** create:全字段可选 string */
390
+ declare function isSessionManagerCreateParams(v: unknown): v is SessionManagerCreateParams;
391
+ /** send:sessionId + prompt 必填 */
392
+ declare function isSessionManagerSendParams(v: unknown): v is SessionManagerSendParams;
393
+ /** history:sessionId 必填、tailTurns 可选 number */
394
+ declare function isSessionManagerHistoryParams(v: unknown): v is SessionManagerHistoryParams;
395
+ /** status / abort:sessionId 必填 */
396
+ declare function isSessionManagerStatusParams(v: unknown): v is SessionManagerStatusParams;
397
+ declare function isSessionManagerAbortParams(v: unknown): v is SessionManagerAbortParams;
398
+ /** list:两过滤字段可选(spawnSource 限枚举) */
399
+ declare function isSessionManagerListParams(v: unknown): v is SessionManagerListParams;
400
+ /** create 结果 */
401
+ interface SessionManagerCreateResult {
402
+ sessionId: string;
403
+ status: 'created';
404
+ modelId?: string;
405
+ }
406
+ /**
407
+ * send 结果(sd-u5 起):消息已入队/已投递——目标 busy 时在下一 turn 边界注入。
408
+ * 失败形状走 SessionManagerErrorResult(error + hint),不再出现旧的 {blocked, rejected}。
409
+ */
410
+ interface SessionManagerSendResult {
411
+ queued: true;
412
+ }
413
+ /** history 结果 */
414
+ interface SessionManagerHistoryResult {
415
+ messages: unknown[];
416
+ truncated: boolean;
417
+ }
418
+ /** status 结果 */
419
+ interface SessionManagerStatusResult {
420
+ status: string;
421
+ modelId?: string;
422
+ }
423
+ /** list 结果 */
424
+ interface SessionManagerListResult {
425
+ sessions: SessionManagerSessionSummary[];
426
+ }
427
+ /** list 返回的 session 摘要(精简版) */
428
+ interface SessionManagerSessionSummary {
429
+ id: string;
430
+ label: string;
431
+ cwd: string;
432
+ status: string;
433
+ spawnSource?: 'user' | 'agent';
434
+ parentAgentSessionId?: string;
435
+ }
436
+ /** abort 结果 */
437
+ interface SessionManagerAbortResult {
438
+ success: boolean;
439
+ }
440
+ /** 错误响应形状(send 同步失败时 = { error, hint };create 已成功时另附 sessionId) */
441
+ interface SessionManagerErrorResult {
442
+ error: string;
443
+ /** create 已成功时附 sessionId + hint */
444
+ sessionId?: string;
445
+ hint?: string;
446
+ }
447
+
448
+ export { ASK_USER_MARKER, type AskUserAnswers, type AskUserOption, type AskUserQuestion, GUI_WIDGET_MARKER, type GuiComponent, type GuiComponentProps, type GuiComponentType, type GuiContext, type GuiRenderResult, PROTOCOL_VERSION, SESSION_MANAGER_ACTIONS, SESSION_MANAGER_MARKER, type SessionManagerAbortParams, type SessionManagerAbortResult, type SessionManagerAction, type SessionManagerCreateParams, type SessionManagerCreateResult, type SessionManagerErrorResult, type SessionManagerHistoryParams, type SessionManagerHistoryResult, type SessionManagerListParams, type SessionManagerListResult, type SessionManagerParams, type SessionManagerRequest, type SessionManagerSendParams, type SessionManagerSendResult, type SessionManagerSessionSummary, type SessionManagerStatusParams, type SessionManagerStatusResult, type StatItem, type TreeItem, type TreeItemIcon, type WidgetMeta, askUserInteract, extractGui, getAskUserAnswer, getAskUserOther, guiComponent, guiResult, guiSetWidget, isAskUserQuestion, isGuiCapable, isGuiComponent, isGuiRenderResult, isSessionManagerAbortParams, isSessionManagerCreateParams, isSessionManagerHistoryParams, isSessionManagerListParams, isSessionManagerSendParams, isSessionManagerStatusParams };
package/dist/index.mjs CHANGED
@@ -112,10 +112,45 @@ function isAskUserQuestion(value) {
112
112
  const q = value;
113
113
  return typeof q.question === "string" && (q.header === void 0 || typeof q.header === "string") && (q.options === void 0 || Array.isArray(q.options)) && (q.multiSelect === void 0 || typeof q.multiSelect === "boolean") && (q.allowOther === void 0 || typeof q.allowOther === "boolean");
114
114
  }
115
+
116
+ // src/extensions/session-manager/types.ts
117
+ function isRecord(v) {
118
+ return typeof v === "object" && v !== null;
119
+ }
120
+ function isOptionalString(v) {
121
+ return v === void 0 || typeof v === "string";
122
+ }
123
+ function isSessionIdParams(v) {
124
+ return isRecord(v) && typeof v.sessionId === "string";
125
+ }
126
+ function isSessionManagerCreateParams(v) {
127
+ return isRecord(v) && isOptionalString(v.cwd) && isOptionalString(v.label) && isOptionalString(v.prompt) && isOptionalString(v.model) && isOptionalString(v.thinkingLevel);
128
+ }
129
+ function isSessionManagerSendParams(v) {
130
+ return isRecord(v) && typeof v.sessionId === "string" && typeof v.prompt === "string";
131
+ }
132
+ function isSessionManagerHistoryParams(v) {
133
+ return isRecord(v) && typeof v.sessionId === "string" && (v.tailTurns === void 0 || typeof v.tailTurns === "number");
134
+ }
135
+ function isSessionManagerStatusParams(v) {
136
+ return isSessionIdParams(v);
137
+ }
138
+ function isSessionManagerAbortParams(v) {
139
+ return isSessionIdParams(v);
140
+ }
141
+ function isSessionManagerListParams(v) {
142
+ return isRecord(v) && (v.spawnSource === void 0 || v.spawnSource === "user" || v.spawnSource === "agent") && isOptionalString(v.parentAgentSessionId);
143
+ }
144
+
145
+ // src/extensions/session-manager/marker.ts
146
+ var SESSION_MANAGER_MARKER = "\0XYZ_SESSION_MANAGER";
147
+ var SESSION_MANAGER_ACTIONS = ["create", "send", "history", "status", "list", "abort"];
115
148
  export {
116
149
  ASK_USER_MARKER,
117
150
  GUI_WIDGET_MARKER,
118
151
  PROTOCOL_VERSION,
152
+ SESSION_MANAGER_ACTIONS,
153
+ SESSION_MANAGER_MARKER,
119
154
  askUserInteract,
120
155
  extractGui,
121
156
  getAskUserAnswer,
@@ -126,5 +161,11 @@ export {
126
161
  isAskUserQuestion,
127
162
  isGuiCapable,
128
163
  isGuiComponent,
129
- isGuiRenderResult
164
+ isGuiRenderResult,
165
+ isSessionManagerAbortParams,
166
+ isSessionManagerCreateParams,
167
+ isSessionManagerHistoryParams,
168
+ isSessionManagerListParams,
169
+ isSessionManagerSendParams,
170
+ isSessionManagerStatusParams
130
171
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyz-agent/extension-protocol",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Extension GUI rendering protocol: types and helpers for pi extension dual-mode (TUI/GUI) rendering",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",