@springbrand/agent-runtime 0.2.0-alpha.43 → 0.2.0-alpha.44

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@springbrand/agent-runtime",
3
- "version": "0.2.0-alpha.43",
3
+ "version": "0.2.0-alpha.44",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -855,6 +855,10 @@ export interface RuntimeTurnEventsPort {
855
855
  readonly submissionId: string;
856
856
  readonly approvalExecutionId: string;
857
857
  }): Promise<void>;
858
+ /**
859
+ * 至少一次投当前 Session Activity;Host 应按 revision 幂等处理重试。
860
+ * Runtime 恢复时会略过已过时的 revision,避免重放旧 working 状态。
861
+ */
858
862
  onActivityChanged?(
859
863
  projection: RuntimeActivityProjection,
860
864
  ): Promise<void>;
package/src/runtime.ts CHANGED
@@ -48,6 +48,7 @@ import type {
48
48
  } from "./kernel/extensions";
49
49
  import type {
50
50
  RuntimeActivity,
51
+ RuntimeActivityProjection,
51
52
  RuntimeState,
52
53
  RuntimeTurnState,
53
54
  } from "./kernel/state";
@@ -153,6 +154,7 @@ const CHAT_RECOVERY_TERMINAL_MESSAGE =
153
154
 
154
155
  type RuntimeEventOutboxPayload =
155
156
  | { readonly type: "model-usage"; readonly event: RuntimeModelUsageEvent }
157
+ | { readonly type: "activity"; readonly projection: RuntimeActivityProjection }
156
158
  | {
157
159
  readonly type: "tool-settlement";
158
160
  readonly event: RuntimeToolSettlementEvent;
@@ -1105,12 +1107,12 @@ export abstract class AgentRuntimeKernel<
1105
1107
  async onStart(): Promise<void> {
1106
1108
  this.runtimeLoad.reset();
1107
1109
  this.telemetry.recover(() => this.ensureRuntimeReady());
1110
+ await this.broadcastApprovals();
1108
1111
  if (this.db.runtimeEvents.hasPending()) {
1109
1112
  this.ctx.waitUntil(
1110
1113
  this.ensureRuntimeReady().then(() => this.drainRuntimeEvents()),
1111
1114
  );
1112
1115
  }
1113
- await this.broadcastApprovals();
1114
1116
  await this.approvals.dispatchPendingContinuations();
1115
1117
  const running = this.db.submissions.findRunning() as StoredSubmission | null;
1116
1118
  if (running) {
@@ -1134,6 +1136,13 @@ export abstract class AgentRuntimeKernel<
1134
1136
  const payload = JSON.parse(row.body) as RuntimeEventOutboxPayload;
1135
1137
  if (payload.type === "model-usage") {
1136
1138
  await turnEvents.onModelUsage?.(payload.event);
1139
+ } else if (payload.type === "activity") {
1140
+ if (
1141
+ !this.state.activity ||
1142
+ payload.projection.revision >= this.state.activity.revision
1143
+ ) {
1144
+ await turnEvents.onActivityChanged?.(payload.projection);
1145
+ }
1137
1146
  } else if (payload.type === "tool-settlement") {
1138
1147
  await turnEvents.onToolSettled?.(payload.event);
1139
1148
  } else if (payload.type === "subagent-usage") {
@@ -4598,6 +4607,13 @@ export abstract class AgentRuntimeKernel<
4598
4607
  backgroundWork,
4599
4608
  revision: (currentActivity?.revision ?? 0) + 1,
4600
4609
  };
4610
+ this.db.transaction(() => {
4611
+ this.db.runtimeEvents.insert({
4612
+ eventId: `session-activity:${nextActivity.revision}`,
4613
+ body: json({ type: "activity", projection: nextActivity }),
4614
+ createdAt: Date.now(),
4615
+ });
4616
+ });
4601
4617
  if (
4602
4618
  this.state?.approvals === undefined ||
4603
4619
  json(this.state.approvals) !== json(approvals) ||
@@ -4611,14 +4627,9 @@ export abstract class AgentRuntimeKernel<
4611
4627
  turn,
4612
4628
  });
4613
4629
  }
4614
- const projection = this.turnEventsPort()?.onActivityChanged?.(nextActivity);
4615
- if (projection) {
4616
- this.ctx.waitUntil(
4617
- projection.catch(() => undefined),
4618
- );
4619
- }
4630
+ this.ctx.waitUntil(this.drainRuntimeEvents());
4620
4631
  } catch {
4621
- // Approval projection is best effort and must not block execution.
4632
+ // Rebuilding UI state is best effort; queued activity delivery retries independently.
4622
4633
  }
4623
4634
  }
4624
4635