@yanlinglabs/winter-agent-runtime 0.0.30 → 0.0.32

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.
@@ -1,4 +1,4 @@
1
- import"./index-51673qbw.js";
1
+ import"./index-qdang0ag.js";
2
2
  import {
3
3
  liveProcessGroups,
4
4
  onProcessGroupChange
@@ -6,10 +6,10 @@ import {
6
6
  import"./index-z6s3r4xm.js";
7
7
  import"./index-bgeqc7ax.js";
8
8
  import"./index-bef62z3r.js";
9
- import"./index-9df1q7j4.js";
9
+ import"./index-yg5ve6sg.js";
10
10
  import {
11
11
  runEmbeddedSession2
12
- } from "./index-wsfqsrh5.js";
12
+ } from "./index-y8vfq85w.js";
13
13
  import {
14
14
  Queue
15
15
  } from "./index-97t2rmtf.js";
package/dist/embedded.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  runEmbeddedSession2
3
- } from "./index-wsfqsrh5.js";
4
- import"./index-9df1q7j4.js";
5
- import"./index-51673qbw.js";
3
+ } from "./index-y8vfq85w.js";
4
+ import"./index-yg5ve6sg.js";
5
+ import"./index-qdang0ag.js";
6
6
  import"./index-bgeqc7ax.js";
7
7
  import"./index-bef62z3r.js";
8
8
  import"./index-9s68t0pd.js";
@@ -31,8 +31,9 @@ import {
31
31
  // src/rpc/bridge.ts
32
32
  import { randomUUID } from "node:crypto";
33
33
  import { WinterRpcError, WinterRpcTimeoutError } from "@yanlinglabs/winter-agent-sdk";
34
- function createRpcBridge2(output) {
34
+ function createRpcBridge2(output, bridgeOpts = {}) {
35
35
  const pending = new Map;
36
+ let held = bridgeOpts.holdUntilOpen === true ? new Map : undefined;
36
37
  let closed = false;
37
38
  return {
38
39
  request(subtype, payload, opts) {
@@ -49,6 +50,7 @@ function createRpcBridge2(output) {
49
50
  const timeoutMs = opts.timeoutMs;
50
51
  entry.timer = setTimeout(() => {
51
52
  pending.delete(requestId);
53
+ held?.delete(requestId);
52
54
  entry.detach?.();
53
55
  reject(new WinterRpcTimeoutError(subtype, timeoutMs));
54
56
  }, timeoutMs);
@@ -62,7 +64,8 @@ function createRpcBridge2(output) {
62
64
  pending.delete(requestId);
63
65
  if (entry.timer !== undefined)
64
66
  clearTimeout(entry.timer);
65
- output.write({ type: "control_cancel_request", requestId });
67
+ if (held?.delete(requestId) !== true)
68
+ output.write({ type: "control_cancel_request", requestId });
66
69
  reject(new WinterRpcError("cancelled", `the '${subtype}' request was cancelled: the runtime stopped waiting for it`));
67
70
  };
68
71
  signal.addEventListener("abort", onAbort, { once: true });
@@ -70,9 +73,20 @@ function createRpcBridge2(output) {
70
73
  }
71
74
  pending.set(requestId, entry);
72
75
  const frame = { type: "control_request", requestId, subtype, payload };
73
- output.write(frame);
76
+ if (held !== undefined)
77
+ held.set(requestId, frame);
78
+ else
79
+ output.write(frame);
74
80
  });
75
81
  },
82
+ open() {
83
+ if (held === undefined)
84
+ return;
85
+ const queued = [...held.values()];
86
+ held = undefined;
87
+ for (const frame of queued)
88
+ output.write(frame);
89
+ },
76
90
  ownsRequest(requestId) {
77
91
  return pending.has(requestId);
78
92
  },
@@ -102,6 +116,7 @@ function createRpcBridge2(output) {
102
116
  entry.reject(err);
103
117
  }
104
118
  pending.clear();
119
+ held?.clear();
105
120
  },
106
121
  cancel(requestId) {
107
122
  const entry = pending.get(requestId);
@@ -111,6 +126,7 @@ function createRpcBridge2(output) {
111
126
  clearTimeout(entry.timer);
112
127
  entry.detach?.();
113
128
  pending.delete(requestId);
129
+ held?.delete(requestId);
114
130
  }
115
131
  };
116
132
  }
@@ -5365,6 +5381,9 @@ function createMcpLifecycle(deps) {
5365
5381
  setSlotState(slot.name, "connected", { toolNames });
5366
5382
  }
5367
5383
  async function start() {
5384
+ await launch();
5385
+ }
5386
+ function launch() {
5368
5387
  const alwaysLoadWaits = [];
5369
5388
  for (const slot of slots.values()) {
5370
5389
  if (slot.state === "disabled")
@@ -5379,10 +5398,18 @@ function createMcpLifecycle(deps) {
5379
5398
  }
5380
5399
  }
5381
5400
  if (deps.envConfig.connectionNonblocking === false) {
5382
- await stateSource.waitForPending(undefined, deps.envConfig.connectTimeoutMs);
5383
- } else if (alwaysLoadWaits.length > 0) {
5384
- await Promise.race([Promise.all(alwaysLoadWaits), new Promise((resolve) => setTimeout(resolve, deps.envConfig.connectTimeoutMs).unref?.())]);
5401
+ if (!stateSource.snapshot().some((server) => server.state === "pending"))
5402
+ return;
5403
+ return stateSource.waitForPending(undefined, deps.envConfig.connectTimeoutMs).then(() => {
5404
+ return;
5405
+ });
5406
+ }
5407
+ if (alwaysLoadWaits.length > 0) {
5408
+ return Promise.race([Promise.all(alwaysLoadWaits).then(() => {
5409
+ return;
5410
+ }), new Promise((resolve) => setTimeout(resolve, deps.envConfig.connectTimeoutMs).unref?.())]);
5385
5411
  }
5412
+ return;
5386
5413
  }
5387
5414
  async function dispose() {
5388
5415
  for (const slot of slots.values()) {
@@ -5517,6 +5544,7 @@ function createMcpLifecycle(deps) {
5517
5544
  stateSource,
5518
5545
  controlSeam: createMcpControlSeam(internals, { ...deps.reservedServerName !== undefined ? { reservedServerName: deps.reservedServerName } : {} }),
5519
5546
  start,
5547
+ launch,
5520
5548
  dispose,
5521
5549
  listConnectedServerNames,
5522
5550
  getConnectedClient,
@@ -22032,7 +22060,7 @@ ${escapeAttributionText(msg.body)}
22032
22060
  const bypassAvailableToThisSession = bypassGate.allowDangerouslySkipPermissions && !bypassGate.disableBypassPermissionsMode;
22033
22061
  const policyStateStore = new PolicyStateStore({ mode: initialMode, rules: initialRules }, bypassGate);
22034
22062
  const permissionHome = homedir();
22035
- const bridge = createRpcBridge2(output);
22063
+ const bridge = createRpcBridge2(output, { holdUntilOpen: true });
22036
22064
  hostCredentialChannel?.bind(bridge);
22037
22065
  const bridgePromptStage = createBridgePromptStage(bridge);
22038
22066
  const realPromptStage = {
@@ -22877,6 +22905,7 @@ ${escapeAttributionText(msg.body)}
22877
22905
  }
22878
22906
  const sessionStateKey = config.agentId ?? config.sessionId;
22879
22907
  let mcpLifecycle;
22908
+ let mcpStartupWait;
22880
22909
  let disposeSessionMcpLifecycle;
22881
22910
  if (mcpServerStateSource === undefined && mcpControlSeam === undefined) {
22882
22911
  const sources = [{ origin: "explicit", servers: config.mcpServers ?? {} }, ...extraMcpServerSources ?? []];
@@ -22893,7 +22922,7 @@ ${escapeAttributionText(msg.body)}
22893
22922
  cwd: config.cwd,
22894
22923
  ...mcpOAuthStore !== undefined ? { oauth: createSessionMcpOAuth({ store: mcpOAuthStore, sender: bridge, brand: sessionBrand, ...config.hostCredentials === true ? { hostOwnsRefresh: true } : {} }) } : {}
22895
22924
  });
22896
- await mcpLifecycle.start();
22925
+ mcpStartupWait = mcpLifecycle.launch();
22897
22926
  disposeSessionMcpLifecycle = registerSessionMcpLifecycle(sessionStateKey, mcpLifecycle);
22898
22927
  }
22899
22928
  const effectiveMcpStateSource = mcpServerStateSource ?? mcpLifecycle?.stateSource;
@@ -23139,6 +23168,7 @@ ${escapeAttributionText(msg.body)}
23139
23168
  tools: advertisedToolNames,
23140
23169
  ...mcpServersWire !== undefined ? { mcp_servers: mcpServersWire } : {}
23141
23170
  });
23171
+ bridge.open();
23142
23172
  const initLoadedSurface = {
23143
23173
  slash_commands: initSlashCommands !== undefined ? [...initSlashCommands] : [],
23144
23174
  output_style: initOutputStyle ?? config.outputStyle ?? DEFAULT_OUTPUT_STYLE,
@@ -23182,6 +23212,7 @@ ${escapeAttributionText(msg.body)}
23182
23212
  const notifications = notificationQueueFor(config.sessionId);
23183
23213
  let turnActive = false;
23184
23214
  let controlCompaction;
23215
+ let mcpControlChain = Promise.resolve();
23185
23216
  let compactOnControl;
23186
23217
  let turnStartedByNotification = false;
23187
23218
  let userFramesEnded = false;
@@ -23650,8 +23681,18 @@ ${escapeAttributionText(msg.body)}
23650
23681
  }
23651
23682
  if (cf.subtype === "mcp_status" || cf.subtype === "mcp_reconnect" || cf.subtype === "mcp_toggle" || cf.subtype === "mcp_set_servers") {
23652
23683
  const mcpDeps = { ...effectiveMcpStateSource !== undefined ? { stateSource: effectiveMcpStateSource } : {}, ...effectiveMcpControlSeam !== undefined ? { controlSeam: effectiveMcpControlSeam } : {} };
23653
- const result = cf.subtype === "mcp_status" ? await handleMcpStatus(mcpDeps) : cf.subtype === "mcp_reconnect" ? await handleMcpReconnect(mcpDeps, cf.payload) : cf.subtype === "mcp_toggle" ? await handleMcpToggle(mcpDeps, cf.payload) : await handleMcpSetServers(mcpDeps, cf.payload);
23654
- output.write(result.ok ? { type: "control_response", requestId: cf.requestId, ok: true, ...result.payload !== undefined ? { payload: result.payload } : {} } : { type: "control_response", requestId: cf.requestId, ok: false, error: result.error });
23684
+ const subtype = cf.subtype;
23685
+ const requestId = cf.requestId;
23686
+ const payload = cf.payload;
23687
+ mcpControlChain = mcpControlChain.then(async () => {
23688
+ let result;
23689
+ try {
23690
+ result = subtype === "mcp_status" ? await handleMcpStatus(mcpDeps) : subtype === "mcp_reconnect" ? await handleMcpReconnect(mcpDeps, payload) : subtype === "mcp_toggle" ? await handleMcpToggle(mcpDeps, payload) : await handleMcpSetServers(mcpDeps, payload);
23691
+ } catch (err) {
23692
+ result = { ok: false, error: { code: `${subtype}_failed`, message: err instanceof Error ? err.message : String(err) } };
23693
+ }
23694
+ output.write(result.ok ? { type: "control_response", requestId, ok: true, ...result.payload !== undefined ? { payload: result.payload } : {} } : { type: "control_response", requestId, ok: false, error: result.error });
23695
+ }).catch(() => {});
23655
23696
  continue;
23656
23697
  }
23657
23698
  const resp = {
@@ -23681,6 +23722,8 @@ ${escapeAttributionText(msg.body)}
23681
23722
  envConfig: mcpEnvConfig
23682
23723
  });
23683
23724
  };
23725
+ if (mcpStartupWait !== undefined)
23726
+ await mcpStartupWait;
23684
23727
  {
23685
23728
  const deadlineMs = firstTurnMcpWaitMs();
23686
23729
  if (deadlineMs !== undefined && mcpLifecycle.stateSource.snapshot().some((server) => server.state === "pending")) {
@@ -25371,6 +25414,7 @@ ${reason}` : ""}` : `${promptStop.hookName} hook stopped continuation${reason.le
25371
25414
  await fireObservationalHook("SessionEnd", { payload: { reason: "other" } });
25372
25415
  stopReading();
25373
25416
  await pump.catch(() => {});
25417
+ await mcpControlChain;
25374
25418
  for (const serverName of sdkMcpServerNames) {
25375
25419
  unregisterMcpServerTools(serverName);
25376
25420
  }
@@ -26502,7 +26546,7 @@ class TranscriptWriter2 {
26502
26546
  return entries;
26503
26547
  }
26504
26548
  }
26505
- var RUNTIME_ENGINE_VERSION2 = "0.0.30";
26549
+ var RUNTIME_ENGINE_VERSION2 = "0.0.32";
26506
26550
  function withPermissionJournal(writer, location) {
26507
26551
  return {
26508
26552
  transcriptPath: join25(location.winterHome, "projects", location.projectKey, `${location.sessionId}.jsonl`),
@@ -9,14 +9,14 @@ import {
9
9
  resolveEngineSession2,
10
10
  resolveProductionWinterHome2,
11
11
  resolveProductionStoreHome
12
- } from "./index-51673qbw.js";
12
+ } from "./index-qdang0ag.js";
13
13
  import {
14
14
  registerDefaultChildEngineFactory,
15
15
  loadResumedChain,
16
16
  buildProductionWiring,
17
17
  withAutoSkillPermissions,
18
18
  restoreChildRoster
19
- } from "./index-9df1q7j4.js";
19
+ } from "./index-yg5ve6sg.js";
20
20
 
21
21
  // src/embedded.ts
22
22
  import { splitFrames, encodeFrame } from "@yanlinglabs/winter-agent-sdk";
@@ -85,7 +85,7 @@ import {
85
85
  providerCredentialRef2,
86
86
  createModelClassifier2,
87
87
  selectClassifierRoute2
88
- } from "./index-51673qbw.js";
88
+ } from "./index-qdang0ag.js";
89
89
  import {
90
90
  createKeychainCredentialStore,
91
91
  createKeychainSecretReader,
package/dist/index.js CHANGED
@@ -53,7 +53,7 @@ import {
53
53
  DEFAULT_CLASSIFIER_TIMEOUT_MS2,
54
54
  createModelClassifier2,
55
55
  selectClassifierRoute2
56
- } from "./index-51673qbw.js";
56
+ } from "./index-qdang0ag.js";
57
57
  import"./index-9s68t0pd.js";
58
58
  import"./index-z6s3r4xm.js";
59
59
  import"./index-bgeqc7ax.js";
@@ -130,6 +130,7 @@ export interface McpLifecycle {
130
130
  readonly stateSource: McpServerStateSource;
131
131
  readonly controlSeam: McpControlSeam;
132
132
  start(): Promise<void>;
133
+ launch(): Promise<void> | undefined;
133
134
  dispose(): Promise<void>;
134
135
  listConnectedServerNames(): string[];
135
136
  getConnectedClient(server: string): ConnectedMcpClient | undefined;
@@ -10,5 +10,9 @@ export interface RpcBridge {
10
10
  ownsRequest(requestId: string): boolean;
11
11
  rejectAllPending(err: unknown): void;
12
12
  cancel(requestId: string): void;
13
+ open(): void;
13
14
  }
14
- export declare function createRpcBridge(output: FrameSink): RpcBridge;
15
+ export interface RpcBridgeOptions {
16
+ holdUntilOpen?: boolean;
17
+ }
18
+ export declare function createRpcBridge(output: FrameSink, bridgeOpts?: RpcBridgeOptions): RpcBridge;
@@ -478,7 +478,7 @@ export declare class TranscriptWriter implements SessionPersistence {
478
478
  private dialectRecord;
479
479
  static readBack(store: SessionStore, key: SessionKey): Promise<SessionStoreEntry[]>;
480
480
  }
481
- export declare const RUNTIME_ENGINE_VERSION = "0.0.30";
481
+ export declare const RUNTIME_ENGINE_VERSION = "0.0.32";
482
482
  export interface ResolvedEngineSession {
483
483
  config: RuntimeConfig;
484
484
  store: SessionPersistence | undefined;
package/dist/testing.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  runEngine2,
4
4
  echoProvider2,
5
5
  resolveEngineSession2
6
- } from "./index-51673qbw.js";
6
+ } from "./index-qdang0ag.js";
7
7
  import"./index-9s68t0pd.js";
8
8
  import"./index-z6s3r4xm.js";
9
9
  import"./index-bgeqc7ax.js";
@@ -14,7 +14,7 @@ import {
14
14
  buildProductionWiring,
15
15
  withAutoSkillPermissions,
16
16
  restoreChildRoster
17
- } from "./index-9df1q7j4.js";
17
+ } from "./index-yg5ve6sg.js";
18
18
  import {
19
19
  Queue
20
20
  } from "./index-97t2rmtf.js";
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const RUNTIME_VERSION = "0.0.30";
1
+ export declare const RUNTIME_VERSION = "0.0.32";
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var RUNTIME_VERSION = "0.0.30";
2
+ var RUNTIME_VERSION = "0.0.32";
3
3
  export {
4
4
  RUNTIME_VERSION
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanlinglabs/winter-agent-runtime",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -73,9 +73,9 @@
73
73
  "@modelcontextprotocol/client": "^2.1.0",
74
74
  "ajv": "^8.20.0",
75
75
  "ignore": "7.0.5",
76
- "@yanlinglabs/winter-agent-sdk": "0.0.30",
77
- "@yanlinglabs/winter-provider-runtime": "0.0.30",
78
- "@yanlinglabs/winter-provider-catalog": "0.0.30"
76
+ "@yanlinglabs/winter-agent-sdk": "0.0.32",
77
+ "@yanlinglabs/winter-provider-runtime": "0.0.32",
78
+ "@yanlinglabs/winter-provider-catalog": "0.0.32"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@modelcontextprotocol/server": "^2.1.0"