@stage-labs/metro 0.1.0-beta.324 → 0.1.0-beta.326

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.
Files changed (176) hide show
  1. package/dist/agent.js +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/lock.js +15 -3
  4. package/dist/root-release-io.js +1 -2
  5. package/dist/root-release.js +2 -3
  6. package/dist/route.js +1 -1
  7. package/dist/service.js +4 -4
  8. package/dist/version.js +1 -1
  9. package/package.json +1 -1
  10. package/runtime/node_modules/@metro-labs/core/src/automation-store.ts +1 -1
  11. package/runtime/node_modules/@metro-labs/core/src/automation-types.ts +2 -2
  12. package/runtime/node_modules/@metro-labs/core/src/lines.ts +2 -8
  13. package/runtime/node_modules/@metro-labs/core/src/protocol.ts +0 -6
  14. package/runtime/node_modules/@metro-labs/core/src/skill-source.ts +1 -1
  15. package/runtime/node_modules/@metro-labs/core/src/stations/account-status.ts +1 -1
  16. package/runtime/node_modules/@metro-labs/core/src/stations/attachments.ts +5 -9
  17. package/runtime/node_modules/@metro-labs/core/src/stations/channel-directory.ts +1 -1
  18. package/runtime/node_modules/@metro-labs/core/src/stations/mail-text.ts +4 -4
  19. package/runtime/node_modules/@metro-labs/core/src/stations/mail.ts +3 -2
  20. package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +1 -1
  21. package/runtime/node_modules/@metro-labs/core/src/stations/oauth.ts +1 -1
  22. package/runtime/node_modules/@metro-labs/core/src/stations/profile.ts +2 -2
  23. package/runtime/node_modules/@metro-labs/core/src/stations/types.ts +2 -2
  24. package/runtime/node_modules/@metro-labs/core/src/train-error.ts +4 -4
  25. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files.ts +2 -6
  26. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules.ts +6 -6
  27. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/user.ts +0 -24
  28. package/runtime/node_modules/@metro-labs/daemon/src/agent-user/view.ts +3 -3
  29. package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +3 -4
  30. package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +4 -9
  31. package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +1 -6
  32. package/runtime/node_modules/@metro-labs/daemon/src/channels/inbound.ts +3 -3
  33. package/runtime/node_modules/@metro-labs/daemon/src/channels/pending.ts +2 -2
  34. package/runtime/node_modules/@metro-labs/daemon/src/claude/files.ts +1 -1
  35. package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +1 -1
  36. package/runtime/node_modules/@metro-labs/daemon/src/files/attach-grant.ts +3 -2
  37. package/runtime/node_modules/@metro-labs/daemon/src/files/attach-serve.ts +1 -1
  38. package/runtime/node_modules/@metro-labs/daemon/src/files/upload-api.ts +3 -7
  39. package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +2 -2
  40. package/runtime/node_modules/@metro-labs/daemon/src/mcp/accounts.ts +10 -19
  41. package/runtime/node_modules/@metro-labs/daemon/src/mcp/call-tools.ts +1 -5
  42. package/runtime/node_modules/@metro-labs/daemon/src/mcp/event-store.ts +3 -4
  43. package/runtime/node_modules/@metro-labs/daemon/src/mcp/group-tools.ts +1 -2
  44. package/runtime/node_modules/@metro-labs/daemon/src/mcp/index.ts +2 -4
  45. package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-gate.ts +5 -6
  46. package/runtime/node_modules/@metro-labs/daemon/src/mcp/server-approvals.ts +2 -5
  47. package/runtime/node_modules/@metro-labs/daemon/src/mcp/session.ts +1 -5
  48. package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-catalog.ts +2 -4
  49. package/runtime/node_modules/@metro-labs/daemon/src/mcp-server/announced.ts +1 -1
  50. package/runtime/node_modules/@metro-labs/daemon/src/metro-user/helper-script.ts +0 -1
  51. package/runtime/node_modules/@metro-labs/daemon/src/metro-user/install.ts +2 -0
  52. package/runtime/node_modules/@metro-labs/daemon/src/metro-user/tailscale-guard.ts +26 -0
  53. package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +1 -3
  54. package/runtime/node_modules/@metro-labs/daemon/src/routes/gmail-attach.ts +3 -3
  55. package/runtime/node_modules/@metro-labs/daemon/src/routes/http.ts +6 -21
  56. package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +1 -5
  57. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-resolve.ts +6 -6
  58. package/runtime/node_modules/@metro-labs/daemon/src/stations/attach.ts +0 -1
  59. package/runtime/node_modules/@metro-labs/daemon/src/stations/materialize.ts +12 -61
  60. package/runtime/node_modules/@metro-labs/daemon/src/stations/supervisor.ts +13 -25
  61. package/runtime/node_modules/@metro-labs/daemon/src/stations/threema-callbacks.ts +5 -5
  62. package/runtime/node_modules/@metro-labs/daemon/src/stations/webhook-endpoints.ts +2 -7
  63. package/runtime/node_modules/@metro-labs/daemon/src/voice/call.ts +2 -6
  64. package/runtime/node_modules/@metro-labs/daemon/src/voice/calls.ts +12 -12
  65. package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +5 -23
  66. package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +1 -7
  67. package/runtime/node_modules/@metro-labs/discord-bot/src/channels.ts +2 -2
  68. package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +10 -35
  69. package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +5 -11
  70. package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +6 -34
  71. package/runtime/node_modules/@metro-labs/discord-bot/src/profile.ts +11 -14
  72. package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +1 -3
  73. package/runtime/node_modules/@metro-labs/discord-bot/src/verify.ts +2 -3
  74. package/runtime/node_modules/@metro-labs/gmail/src/accounts.ts +3 -3
  75. package/runtime/node_modules/@metro-labs/gmail/src/auth.ts +8 -8
  76. package/runtime/node_modules/@metro-labs/gmail/src/managed.ts +3 -2
  77. package/runtime/node_modules/@metro-labs/http/src/agent-signature.ts +1 -1
  78. package/runtime/node_modules/@metro-labs/http/src/api-http.ts +3 -4
  79. package/runtime/node_modules/@metro-labs/http/src/connector-discovery.ts +0 -113
  80. package/runtime/node_modules/@metro-labs/http/src/connector-input.ts +1 -1
  81. package/runtime/node_modules/@metro-labs/http/src/connector-mcp.ts +12 -13
  82. package/runtime/node_modules/@metro-labs/http/src/connector-oauth.ts +1 -1
  83. package/runtime/node_modules/@metro-labs/http/src/connector-policy.ts +1 -6
  84. package/runtime/node_modules/@metro-labs/http/src/connector-public-url.ts +4 -2
  85. package/runtime/node_modules/@metro-labs/http/src/connector-tools.ts +1 -11
  86. package/runtime/node_modules/@metro-labs/http/src/connector-url.ts +0 -6
  87. package/runtime/node_modules/@metro-labs/http/src/mcp-server-protocol.ts +1 -1
  88. package/runtime/node_modules/@metro-labs/http/src/mcp-server-tools.ts +0 -2
  89. package/runtime/node_modules/@metro-labs/http/src/mode-api.ts +1 -1
  90. package/runtime/node_modules/@metro-labs/http/src/return-to.ts +2 -2
  91. package/runtime/node_modules/@metro-labs/http/src/workos-token.ts +6 -7
  92. package/runtime/node_modules/@metro-labs/inference/package.json +1 -0
  93. package/runtime/node_modules/@metro-labs/inference/src/attempts.ts +3 -3
  94. package/runtime/node_modules/@metro-labs/inference/src/bedrock.ts +1 -1
  95. package/runtime/node_modules/@metro-labs/inference/src/codex-translate.ts +2 -2
  96. package/runtime/node_modules/@metro-labs/inference/src/delivered.ts +1 -1
  97. package/runtime/node_modules/@metro-labs/inference/src/effort.ts +0 -6
  98. package/runtime/node_modules/@metro-labs/inference/src/fallback.ts +7 -5
  99. package/runtime/node_modules/@metro-labs/inference/src/forward.ts +5 -5
  100. package/runtime/node_modules/@metro-labs/inference/src/measure.ts +2 -3
  101. package/runtime/node_modules/@metro-labs/inference/src/named.ts +3 -3
  102. package/runtime/node_modules/@metro-labs/inference/src/probes.ts +98 -0
  103. package/runtime/node_modules/@metro-labs/inference/src/usage.ts +5 -5
  104. package/runtime/node_modules/@metro-labs/outlook/src/accounts.ts +6 -8
  105. package/runtime/node_modules/@metro-labs/outlook/src/auth.ts +2 -1
  106. package/runtime/node_modules/@metro-labs/outlook/src/inbound.ts +3 -5
  107. package/runtime/node_modules/@metro-labs/outlook/src/me.ts +6 -6
  108. package/runtime/node_modules/@metro-labs/outlook/src/outbound.ts +10 -13
  109. package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +7 -26
  110. package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +1 -1
  111. package/runtime/node_modules/@metro-labs/telegram/src/login.ts +3 -6
  112. package/runtime/node_modules/@metro-labs/telegram/src/profile.ts +3 -2
  113. package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +6 -20
  114. package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +1 -7
  115. package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +0 -2
  116. package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +1 -16
  117. package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +1 -8
  118. package/runtime/node_modules/@metro-labs/telegram-bot/src/profile.ts +2 -1
  119. package/runtime/node_modules/@metro-labs/threema/src/actions.ts +1 -8
  120. package/runtime/node_modules/@metro-labs/threema/src/chats.ts +4 -3
  121. package/runtime/node_modules/@metro-labs/threema/src/format.ts +15 -17
  122. package/runtime/node_modules/@metro-labs/threema/src/groups.ts +2 -4
  123. package/runtime/node_modules/@metro-labs/threema/src/inbound.ts +2 -1
  124. package/runtime/node_modules/@metro-labs/threema/src/messages.ts +2 -1
  125. package/runtime/node_modules/@metro-labs/threema/src/outbound.ts +7 -7
  126. package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +1 -3
  127. package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +0 -2
  128. package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +1 -1
  129. package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +1 -1
  130. package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +7 -0
  131. package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +4 -10
  132. package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +4 -5
  133. package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +14 -26
  134. package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +1 -7
  135. package/runtime/node_modules/@metro-labs/xmtp/src/codecs.ts +17 -58
  136. package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +1 -6
  137. package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +10 -31
  138. package/runtime/node_modules/@metro-labs/xmtp/src/frames.ts +12 -14
  139. package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +2 -3
  140. package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +3 -9
  141. package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +8 -9
  142. package/runtime/node_modules/@metro-labs/xmtp/src/names.ts +4 -2
  143. package/runtime/node_modules/@metro-labs/xmtp/src/network.ts +2 -3
  144. package/runtime/node_modules/@metro-labs/xmtp/src/profile.ts +2 -1
  145. package/runtime/node_modules/@metro-labs/xmtp/src/read-attachments.ts +2 -2
  146. package/runtime/node_modules/@metro-labs/xmtp/src/sender.ts +2 -1
  147. package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +23 -46
  148. package/runtime/node_modules/@metro-labs/xmtp/src/wallet.ts +5 -4
  149. package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +12 -15
  150. package/runtime/runtime.json +1 -1
  151. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/automation-store.ts +1 -1
  152. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/automation-types.ts +2 -2
  153. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/lines.ts +2 -8
  154. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/protocol.ts +0 -6
  155. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/skill-source.ts +1 -1
  156. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/account-status.ts +1 -1
  157. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/attachments.ts +5 -9
  158. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/channel-directory.ts +1 -1
  159. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/mail-text.ts +4 -4
  160. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/mail.ts +3 -2
  161. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +1 -1
  162. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/oauth.ts +1 -1
  163. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/profile.ts +2 -2
  164. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/types.ts +2 -2
  165. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/train-error.ts +4 -4
  166. package/runtime/sdk-runner/runner.json +1 -1
  167. package/runtime/sdk-runner/src/approvals.ts +2 -2
  168. package/runtime/sdk-runner/src/automation-command.ts +2 -2
  169. package/runtime/sdk-runner/src/calls.ts +0 -6
  170. package/runtime/sdk-runner/src/errors.ts +1 -1
  171. package/runtime/sdk-runner/src/link.ts +1 -1
  172. package/runtime/sdk-runner/src/runner.ts +2 -2
  173. package/runtime/sdk-runner/src/session-watch.ts +5 -34
  174. package/runtime/sdk-runner/src/task-state.ts +1 -1
  175. package/runtime/sdk-runner/src/tool-proxy.ts +1 -1
  176. package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +0 -40
@@ -1,4 +1,4 @@
1
- export const MAX_TEXT_CHARS = 20_000;
1
+ const MAX_TEXT_CHARS = 20_000;
2
2
 
3
3
  const ENTITIES: Record<string, string> = {
4
4
  amp: '&',
@@ -52,9 +52,9 @@ export function tidy(text: string): string {
52
52
  .trim();
53
53
  }
54
54
 
55
- export function capText(text: string, max = MAX_TEXT_CHARS): string {
56
- if (text.length <= max) return text;
57
- return `${text.slice(0, max)}\n[... ${String(text.length - max)} more characters]`;
55
+ export function capText(text: string): string {
56
+ if (text.length <= MAX_TEXT_CHARS) return text;
57
+ return `${text.slice(0, MAX_TEXT_CHARS)}\n[... ${String(text.length - MAX_TEXT_CHARS)} more characters]`;
58
58
  }
59
59
 
60
60
  export function bodyText(body: { contentType?: unknown; content?: unknown } | undefined): string {
@@ -1,4 +1,5 @@
1
1
  import { mintId } from '../ids.js';
2
+ import { isRecord } from '../is-record.js';
2
3
  import { Line } from '../lines.js';
3
4
  import { TrainError } from '../train-error.js';
4
5
  import { capText } from './mail-text.js';
@@ -47,7 +48,7 @@ export interface ReadQuery {
47
48
  limit: number;
48
49
  }
49
50
 
50
- export const DEFAULT_LIMIT = 20;
51
+ const DEFAULT_LIMIT = 20;
51
52
  export const MAX_LIMIT = 50;
52
53
  const SEEN_MAX = 500;
53
54
  const SUBJECT_MAX = 255;
@@ -160,7 +161,7 @@ export function subjectOf(station: MailStation, subject: string, text: string):
160
161
 
161
162
  export const filesOf = (raw: unknown): OutgoingFile[] =>
162
163
  (Array.isArray(raw) ? raw : [])
163
- .map((a) => (a ?? {}) as Record<string, unknown>)
164
+ .filter(isRecord)
164
165
  .filter((a) => typeof a.path === 'string' && a.path !== '')
165
166
  .map((a) => ({
166
167
  path: String(a.path),
@@ -1,6 +1,6 @@
1
1
  type Args = Record<string, unknown>;
2
2
 
3
- export interface Normalized {
3
+ interface Normalized {
4
4
  action: string;
5
5
  args: Args;
6
6
  }
@@ -36,7 +36,7 @@ export function pkcePair(verifier = randomBytes(32).toString('base64url')): Pkce
36
36
  return { verifier, challenge: createHash('sha256').update(verifier).digest('base64url') };
37
37
  }
38
38
 
39
- export const newState = (): string => randomBytes(24).toString('base64url');
39
+ const newState = (): string => randomBytes(24).toString('base64url');
40
40
 
41
41
  export function parseMailbox(value: unknown): string | null {
42
42
  const mailbox = (typeof value === 'string' ? value.trim() : '').toLowerCase();
@@ -3,8 +3,8 @@ import { TrainError } from '../train-error.js';
3
3
  export const PROFILE_FIELDS = ['name', 'bio', 'avatar'] as const;
4
4
  export type ProfileField = (typeof PROFILE_FIELDS)[number];
5
5
 
6
- export const NAME_MAX = 64;
7
- export const BIO_MAX = 512;
6
+ const NAME_MAX = 64;
7
+ const BIO_MAX = 512;
8
8
 
9
9
  export interface ProfileAvatar {
10
10
  path: string;
@@ -82,7 +82,7 @@ export interface MemberOutcome {
82
82
  reason?: string;
83
83
  }
84
84
 
85
- export interface GroupCapability {
85
+ interface GroupCapability {
86
86
  supported: boolean;
87
87
  reason?: string;
88
88
  }
@@ -98,7 +98,7 @@ export interface GroupResult {
98
98
 
99
99
  export type ReadFilter = 'account' | 'query' | 'from' | 'until' | 'unread_only' | 'message_id';
100
100
 
101
- export type AttachmentMode = 'canonical' | 'native' | 'none';
101
+ type AttachmentMode = 'canonical' | 'native' | 'none';
102
102
 
103
103
  export interface Station {
104
104
  name: string;
@@ -1,3 +1,5 @@
1
+ import { isRecord } from './is-record.js';
2
+
1
3
  export interface TrainErrorInfo {
2
4
  code: string;
3
5
  message: string;
@@ -41,10 +43,8 @@ export function serializeTrainError(err: unknown): {
41
43
  return { error: err instanceof Error ? err.message : String(err) };
42
44
  }
43
45
 
44
- export function coerceErrorInfo(v: unknown): TrainErrorInfo | undefined {
45
- if (!v || typeof v !== 'object') return undefined;
46
- const o = v as Record<string, unknown>;
47
- if (typeof o.code !== 'string' || typeof o.message !== 'string')
46
+ export function coerceErrorInfo(o: unknown): TrainErrorInfo | undefined {
47
+ if (!isRecord(o) || typeof o.code !== 'string' || typeof o.message !== 'string')
48
48
  return undefined;
49
49
  const info: TrainErrorInfo = { code: o.code, message: o.message };
50
50
  if (typeof o.retryable === 'boolean') info.retryable = o.retryable;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.0-beta.324",
2
+ "version": "0.1.0-beta.326",
3
3
  "dependencies": {
4
4
  "@anthropic-ai/claude-agent-sdk": "0.3.287",
5
5
  "@modelcontextprotocol/sdk": "^1.29.0",
@@ -7,10 +7,10 @@ import type { Asker } from './link.js';
7
7
  const DENIED = 'The owner did not approve this.';
8
8
 
9
9
  export interface ApprovalAsk { tool: string; worker: string | null }
10
- export type ApprovalWatch = (id: string, ask: ApprovalAsk | null) => void;
10
+ type ApprovalWatch = (id: string, ask: ApprovalAsk | null) => void;
11
11
 
12
12
  export interface ApprovalBinding { call: CallSource; signal: AbortSignal }
13
- export type BindApproval = (tool: string, input: Record<string, unknown>) => ApprovalBinding | null | undefined;
13
+ type BindApproval = (tool: string, input: Record<string, unknown>) => ApprovalBinding | null | undefined;
14
14
 
15
15
  export function approvalsThrough(asker: Asker, waiting: ApprovalWatch = () => undefined, bind: BindApproval = () => undefined): CanUseTool {
16
16
  return async (tool, input, options) => {
@@ -9,9 +9,9 @@ import type { AutomationStore } from '@metro-labs/core/automation-store';
9
9
  const HOUR_MS = 3_600_000;
10
10
  const SLOT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;
11
11
 
12
- export class AutomationCommandError extends Error {}
12
+ class AutomationCommandError extends Error {}
13
13
 
14
- export interface AutomationCommandDeps {
14
+ interface AutomationCommandDeps {
15
15
  store: Pick<AutomationStore, 'validate' | 'submit' | 'requests' | 'statuses' | 'finish'>;
16
16
  now?: () => number;
17
17
  readPrompt?: (path: string) => string;
@@ -103,12 +103,6 @@ export class RunnerCalls {
103
103
  const active = this.active;
104
104
  if (active === null || active.sources.has(source.sourceId) || active.sources.size >= SOURCES_MAX) return;
105
105
  active.sources.add(source.sourceId);
106
- this.enqueue(text);
107
- }
108
-
109
- private enqueue(text: string): void {
110
- const active = this.active;
111
- if (active === null) return;
112
106
  try {
113
107
  active.inputs.push(this.inbox.push('call', text));
114
108
  } catch {
@@ -10,7 +10,7 @@ const ERROR_FAILURES: Record<NonNullable<RunnerDiagnostic['errorCode']>, RunnerF
10
10
  };
11
11
  const KNOWN = ['status_unavailable', 'session_ended', 'interrupted', 'saved_state', 'authentication', 'executable', 'connection', 'module', 'configuration', 'process_exit', 'session_error'] as const;
12
12
 
13
- export interface SessionFailure {
13
+ interface SessionFailure {
14
14
  code: RunnerFailureCode;
15
15
  diagnostic?: RunnerDiagnostic;
16
16
  }
@@ -27,7 +27,7 @@ export interface PermissionAsk {
27
27
  call?: CallSource;
28
28
  }
29
29
 
30
- export interface LinkEvents {
30
+ interface LinkEvents {
31
31
  channel(event: ChannelEvent): void;
32
32
  call?(notice: CallNotice): void;
33
33
  callState?(state: CallState): void;
@@ -57,7 +57,7 @@ export function runnerOptions(cfg: RunnerConfig, tools: MetroTools, canUseTool:
57
57
  };
58
58
  }
59
59
 
60
- export interface CompactState {
60
+ interface CompactState {
61
61
  context: number;
62
62
  floor: number | null;
63
63
  limit: number;
@@ -68,7 +68,7 @@ export const compactDue = (s: CompactState): boolean => !s.busy && s.context >=
68
68
 
69
69
  export type OpenSession = (params: { prompt: AsyncIterable<SDKUserMessage>; options: Options }) => Query;
70
70
 
71
- export interface RunnerParts {
71
+ interface RunnerParts {
72
72
  store: SessionStore;
73
73
  readOnly: (tool: string) => boolean;
74
74
  compactAt?: number;
@@ -27,8 +27,6 @@ function toolResultIds(message: unknown): string[] {
27
27
 
28
28
  export class SessionWatch {
29
29
  private readonly writes = new Set<string>();
30
- private readonly idle: (() => void)[] = [];
31
- private readonly compacted: (() => void)[] = [];
32
30
  private compactingNow = false;
33
31
  private busy = false;
34
32
  private sessionStateSeen = false;
@@ -70,15 +68,7 @@ export class SessionWatch {
70
68
  this.lifecycle(m);
71
69
  if (m.type === 'assistant' && isRecord(m.message)) this.assistant(m.message);
72
70
  else if (m.type === 'stream_event' && isRecord(m.event)) this.stream(m.event);
73
- else if (m.type === 'user') for (const id of toolResultIds(m.message)) this.done(id);
74
- }
75
-
76
- whenNotWriting(): Promise<void> {
77
- return this.writing ? new Promise((resolve) => { this.idle.push(resolve); }) : Promise.resolve();
78
- }
79
-
80
- whenNotCompacting(): Promise<void> {
81
- return this.compactingNow ? new Promise((resolve) => { this.compacted.push(resolve); }) : Promise.resolve();
71
+ else if (m.type === 'user') for (const id of toolResultIds(m.message)) this.writes.delete(id);
82
72
  }
83
73
 
84
74
  private acknowledge(m: Record<string, unknown>): void {
@@ -91,16 +81,16 @@ export class SessionWatch {
91
81
  if (m.type === 'system') this.system(m);
92
82
  else if (m.type === 'result' && !this.sessionStateSeen) {
93
83
  this.busy = typeof m.queued_turn_count === 'number' && m.queued_turn_count > 0;
94
- this.settle();
84
+ this.writes.clear();
95
85
  }
96
86
  if (m.type === 'assistant' || m.type === 'stream_event' || startedCommand(m) !== null) this.busy = true;
97
87
  }
98
88
 
99
89
  private system(m: Record<string, unknown>): void {
100
90
  if (m.subtype === 'session_state_changed') this.sessionState(m.state);
101
- else if (m.subtype === 'status') this.setCompacting(m.status === 'compacting');
91
+ else if (m.subtype === 'status') this.compactingNow = m.status === 'compacting';
102
92
  else if (m.subtype === 'compact_boundary') {
103
- this.setCompacting(false);
93
+ this.compactingNow = false;
104
94
  this.lastContext = 0;
105
95
  this.streamUsage = {};
106
96
  }
@@ -114,7 +104,7 @@ export class SessionWatch {
114
104
  } else if (state === 'idle') {
115
105
  this.busy = false;
116
106
  this.requiresAction = false;
117
- this.settle();
107
+ this.writes.clear();
118
108
  }
119
109
  }
120
110
 
@@ -127,11 +117,6 @@ export class SessionWatch {
127
117
  this.lastContext = contextOf(this.streamUsage) || this.lastContext;
128
118
  }
129
119
 
130
- private setCompacting(on: boolean): void {
131
- this.compactingNow = on;
132
- if (!on) for (const resume of this.compacted.splice(0)) resume();
133
- }
134
-
135
120
  private assistant(message: Record<string, unknown>): void {
136
121
  this.lastContext = contextOf(message.usage) || this.lastContext;
137
122
  if (!Array.isArray(message.content)) return;
@@ -141,18 +126,4 @@ export class SessionWatch {
141
126
  if (tool !== undefined && !this.readOnly(tool)) this.writes.add(block.id);
142
127
  }
143
128
  }
144
-
145
- private done(id: string): void {
146
- if (this.writes.delete(id) && this.writes.size === 0) this.wake();
147
- }
148
-
149
- private settle(): void {
150
- if (this.writes.size === 0) return;
151
- this.writes.clear();
152
- this.wake();
153
- }
154
-
155
- private wake(): void {
156
- for (const resume of this.idle.splice(0)) resume();
157
- }
158
129
  }
@@ -9,7 +9,7 @@ const STATES = ['running', 'completed', 'failed', 'stopped', 'interrupted'] as c
9
9
  const REASONS = ['task_error', 'rate_limit', 'worker_restart', 'interrupted', 'provider_error'] as const;
10
10
  export type TaskReason = (typeof REASONS)[number];
11
11
 
12
- export interface TaskNotice {
12
+ interface TaskNotice {
13
13
  token: string;
14
14
  reason: TaskReason;
15
15
  attempt: number;
@@ -4,7 +4,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema, type CallToolRequest, ty
4
4
 
5
5
  export const METRO_SERVER = 'metro';
6
6
 
7
- export interface ToolSource {
7
+ interface ToolSource {
8
8
  readonly instructions: string | undefined;
9
9
  listTools(): Promise<ListToolsResult>;
10
10
  callTool(params: CallToolRequest['params'], signal: AbortSignal): Promise<CallToolResult>;
@@ -1,40 +0,0 @@
1
- import { TrainError } from '@metro-labs/core/train-error';
2
-
3
- type Args = Record<string, unknown>;
4
-
5
- export function filterStrings(value: unknown): string[] {
6
- if (!Array.isArray(value)) return [];
7
- return value.filter((a) => typeof a === 'string' && a.length > 0) as string[];
8
- }
9
-
10
- export function resolveMembers(args: Args): {
11
- addrs: string[];
12
- inboxes: string[];
13
- } {
14
- const { addresses, inboxIds, memberAddresses, memberInboxIds } = args as {
15
- addresses?: string[];
16
- inboxIds?: string[];
17
- memberAddresses?: string[];
18
- memberInboxIds?: string[];
19
- };
20
- return {
21
- addrs: filterStrings(addresses ?? memberAddresses),
22
- inboxes: filterStrings(inboxIds ?? memberInboxIds),
23
- };
24
- }
25
-
26
- export function parseMemberArgs(
27
- args: Args,
28
- verb: string,
29
- ): { line: string; addrs: string[]; inboxes: string[] } {
30
- const { line } = args as { line: string };
31
- if (!line || typeof line !== 'string')
32
- throw new TrainError('INVALID_ARGS', `${verb} requires a \`line\``);
33
- const { addrs, inboxes } = resolveMembers(args);
34
- if (addrs.length === 0 && inboxes.length === 0)
35
- throw new TrainError(
36
- 'INVALID_ARGS',
37
- `${verb} requires addresses[] or inboxIds[]`,
38
- );
39
- return { line, addrs, inboxes };
40
- }