会话事件类型添加
add-event
添加从 LLM 会话流向客户端订阅者的新事件类型。涵盖从 ManagedSession 触发事件、持久化到 CMS,以及在 PilotSwarmSession.on() 中进行过滤。
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 16
- Forks
- 10
01 前言 Front Matter
- name
- add-event
- description
- Add a new event type that flows from the LLM session through to client subscribers. Covers firing the event from ManagedSession, persisting to CMS, and filtering in PilotSwarmSession.on().
03 SKILL.md 正文
Add a New Event Type
Events flow from the Copilot SDK through ManagedSession, get persisted to CMS, and are delivered to client subscribers.
Steps
-
Fire the event from
ManagedSessioninsrc/managed-session.ts:- Events are captured via the
onEventcallback passed torunTurn(). - Inside the
copilotSession.on()handler, events are captured asCapturedEventobjects:const captured: CapturedEvent = { eventType: "my.event_type", data: eventData, }; collectedEvents.push(captured); opts?.onEvent?.(captured);
- Events are captured via the
-
Persist to CMS — events are automatically persisted by the activity in
src/session-proxy.tsvia theonEventcallback, which callscatalog.recordEvents(). No changes needed unless you want special handling. -
Filter in
PilotSwarmSession.on()— if the event needs special client-side filtering (e.g., excluding ephemeral events from persistence), add logic insrc/client.ts:session.on("my.event_type", (event) => { ... }); -
Add a test — verify the event appears in
session.getMessages()and/or viasession.on()polling.
Event naming conventions
- Use dot-separated names:
category.action(e.g.,assistant.message,tool.execution_start). - Ephemeral events (like
assistant.message_delta) should NOT be persisted to CMS — they are filtered out insession-proxy.ts.
Event flow
CopilotSession.on(event) ← Copilot SDK fires event
↓
ManagedSession captures as CapturedEvent
↓
onEvent callback → session-proxy.ts → catalog.recordEvents() ← persisted to CMS
↓
PilotSwarmSession.on() polls CMS → delivers to client subscribers
Key files
- src/managed-session.ts — event capture during
runTurn() - src/session-proxy.ts — event persistence to CMS
- src/cms.ts —
recordEvents()andgetSessionEvents() - src/client.ts —
PilotSwarmSession.on()polling and dispatch
04 同仓库更多 Skills
workflow-testing
Load before you test a Workflow with mocked effects — the test, test_respond and test_advance operations, fixtures, interception ids, valid answers, the virtual clock, test evidence and what a test run does not prove.
workflow-tools
Every argument of the Workflow tools, testing a revision, package definitions and the refusals you can fix. Load when a Workflow tool's short description is not enough.
workflow-reference
Field reference for Workflow YAML (root keys, every state type, bindings, outputs, runtime error codes), what the engine guarantees, and a review fan-out example. For design, call load_skill with name workflow-authoring.
workflow-patterns
Load when one Workflow must run different nodes in its branches at the same time (a different prompt or model for each branch), or loops back to a state (a polling loop). Named branches, the router pattern, examples that compile.
workflow-authoring
Load before you create, edit, publish or run a Workflow (pilotswarm.dev/v1) — choosing states, bounded graphs, bindings, typed contracts, agent and parallel states, the lifecycle and failure diagnosis.
tla-formal-validation
Required for any change to the core orchestrations (the durable session orchestration, session hydration and dehydration, and the Workflow controller and store). Teaches how to model the change in TLA+, update the existing models, run TLC with the repo runner, read the results, turn a counterexample into a fix and a regression test, and record the binding to the code.