@ycodium-ai/plugin-api 0.2.5093 → 0.2.5177

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/README.md CHANGED
@@ -325,6 +325,44 @@ is refused with `reason: "undeclared"`.
325
325
  The installation review explains each permission before the user accepts it. Declare only the
326
326
  capabilities your plugin uses; the public TypeScript declarations define each request's shape.
327
327
 
328
+ ## Streams shared by key
329
+
330
+ A `ctx.stream` that pushes changes to several subscribers of the same project (or any other key)
331
+ can hold each subscriber with `holdKeyedSubscriber`. It adds the subscriber to the key's group in
332
+ your map, pushes `current()` once, waits for the subscriber to hang up, and calls `onLast` when
333
+ the last subscriber of the key leaves. To notify a key, call every function in
334
+ `subscribers.get(key)`.
335
+
336
+ - With a signal that is already aborted, `onSubscribe` and `current` still run and nothing is
337
+ emitted; `onLast` still runs only when this was the key's last subscriber.
338
+ - If `onSubscribe`, `current` or the first emit throws, the subscriber is removed (and `onLast`
339
+ runs if it was the last one) before the same error is rethrown. If `onLast` throws, the returned promise rejects
340
+ with its error.
341
+ - An async `onLast` can still be running when a new subscriber starts a new group for the same key,
342
+ so release only what that group owns.
343
+
344
+ ```ts
345
+ import { holdKeyedSubscriber } from "@ycodium-ai/plugin-api";
346
+
347
+ const subscribers = new Map<string, Set<(value: Changes) => void>>();
348
+ ctx.stream({
349
+ name: "watch",
350
+ payloadSchema,
351
+ buffer: { latest: 1 },
352
+ handle: (payload, emit, signal) =>
353
+ holdKeyedSubscriber({
354
+ subscribers,
355
+ key: String(payload.projectId),
356
+ signal,
357
+ emit,
358
+ current: () => latest.get(String(payload.projectId)) ?? initial,
359
+ onLast: () => {
360
+ latest.delete(String(payload.projectId));
361
+ },
362
+ }),
363
+ });
364
+ ```
365
+
328
366
  ## Public service routes
329
367
 
330
368
  Bind a declared `network.serve` service with `{ port, public: true }` to receive external HTTP or
@@ -615,7 +653,25 @@ No thread, timeout, interruption or restart cancels the call. Guard callbacks st
615
653
 
616
654
  <!-- plugin-api-versions:start (generated by scripts/gen-plugin-api-version.ts from packages/plugin-api/version-history.json; edit that file) -->
617
655
 
618
- The current API is **147**. This Ycodium loads plugins declaring 146 through 147.
656
+ The current API is **152**. This Ycodium loads plugins declaring 146 through 152.
657
+
658
+ API 152 adds `ctx.projects.ledgerImport.get`: how this machine's ledger import of a project stands — old data left on this member machine, the import pushed to the home machine and its verification, and the imports the home machine received (work.read).
659
+
660
+ API 152 adds an optional `imported` field to `PluginEvent` (`{ importId, sourceEnvironmentId }`) on events that a ledger import moved in from an older copy of the project on another machine. Such history reaches `ctx.derivedState` folds but never `ctx.reactor`; folds should take its state without treating it as current activity
661
+
662
+ API 152 work history can carry two more verbs, `imported` and `import-diverged`, with an `import` change naming the source machine and its original item number, for items moved in from an older copy of the project on another machine
663
+
664
+ API 151 adds `holdKeyedSubscriber`, which holds a `ctx.stream` subscriber in a per-key group until it hangs up: it pushes the current value first and runs your cleanup when the last subscriber of the key leaves.
665
+
666
+ API 150 adds `thread.group.previous` and `thread.group.next` to the command types returned by `ctx.machineSettings.keybindings.get` and accepted by `ctx.machineSettings.keybindings.upsert` (including `replace`) and `ctx.machineSettings.keybindings.remove`.
667
+
668
+ API 149 adds the optional `authorRemoteThreadId` to the post summaries and views returned by the post read ports.
669
+
670
+ API 149 adds the `{ remoteThread }` send address and an optional `threadId` on remote-agent participants to the message and post send ports.
671
+
672
+ API 148 adds `ctx.projects.machines.threads.list`, `.get` and `.messages.list`: read the sessions of another machine of the project from its home machine (sessionProjection).
673
+
674
+ API 148 adds the optional filters `sessionStatus`, `pendingApproval` and `pendingUserInput` to `ctx.threads.list`; they apply before paging.
619
675
 
620
676
  API 147 adds the optional `peerRemote` `{ principalId, remoteThreadId }` to `communication.wakeLoops.list` entries and `communication.wakeLoops.resume` input: a pair with a session on another machine of the project now counts toward the eight-exchange wake-up limit, and the person on the home machine continues it by that peer. `work.remoteAgentPending.get` wake entries gain the optional `pausedThreads`: the member machine's sessions this wake must not start a turn for. Older hosts omit both fields; no other public type changes.
621
677
 
@@ -5,3 +5,38 @@
5
5
  */
6
6
  /** `type` 闭集与 contracts 的 `ProviderRuntimeEventType` 相同(含 `tool.denied`),不另造事件词汇。 */
7
7
  export type ExecutorEventType = "session.started" | "session.configured" | "session.state.changed" | "session.exited" | "thread.started" | "thread.state.changed" | "thread.metadata.updated" | "thread.token-usage.updated" | "thread.realtime.started" | "thread.realtime.item-added" | "thread.realtime.audio.delta" | "thread.realtime.error" | "thread.realtime.closed" | "turn.started" | "turn.completed" | "turn.aborted" | "turn.plan.updated" | "turn.proposed.delta" | "turn.proposed.completed" | "turn.diff.updated" | "item.started" | "item.updated" | "item.completed" | "content.delta" | "request.opened" | "request.resolved" | "user-input.requested" | "user-input.resolved" | "task.started" | "task.progress" | "task.updated" | "task.completed" | "hook.started" | "hook.progress" | "hook.completed" | "tool.progress" | "tool.summary" | "tool.denied" | "auth.status" | "account.updated" | "account.rate-limits.updated" | "mcp.status.updated" | "mcp.oauth.completed" | "model.rerouted" | "config.warning" | "deprecation.notice" | "files.persisted" | "assistant.attachment.produced" | "assistant.artifact.produced" | "runtime.warning" | "runtime.error";
8
+ /** 与 @ycodium-ai/plugin-api executorEvents 有意双份展开,由 plugin-api 的 executorEvents.consistency.test.ts 守双向同形。 */
9
+ export type ExecutorEventProviderRefs = {
10
+ readonly providerTurnId?: string;
11
+ readonly providerItemId?: string;
12
+ readonly providerRequestId?: string;
13
+ };
14
+ export type ExecutorEventRaw = {
15
+ readonly source: string;
16
+ readonly method?: string;
17
+ readonly messageType?: string;
18
+ readonly payload: unknown;
19
+ };
20
+ export type ExecutorEventBase = {
21
+ /** 跨服务器重启、跨线程都不能重复:宿主拿它当活动 id 全局落库,重复会覆盖已有的旧活动。 */
22
+ readonly eventId: string;
23
+ readonly provider: string;
24
+ readonly providerInstanceId?: string;
25
+ readonly threadId: string;
26
+ readonly createdAt: string;
27
+ readonly turnId?: string;
28
+ readonly itemId?: string;
29
+ /**
30
+ * 同一线程里跨会话重启也不能重复:宿主按它记「已接受」并在重启后恢复,撞号的新请求会被
31
+ * 当成答过的旧请求拒掉。协议自带的序号(如每个进程从 0 数起的 JSON-RPC id)要先加会话级前缀。
32
+ */
33
+ readonly requestId?: string;
34
+ readonly providerRefs?: ExecutorEventProviderRefs;
35
+ readonly raw?: ExecutorEventRaw;
36
+ readonly originResumeCursor?: unknown;
37
+ };
38
+ /** 结构声明:公共基座 + `type` 判别 + payload。payload 形状以 contracts schema 为准。 */
39
+ export type ExecutorEvent = ExecutorEventBase & {
40
+ readonly type: ExecutorEventType;
41
+ readonly payload: unknown;
42
+ };