@stage-labs/metro 0.1.0-beta.320 → 0.1.0-beta.322

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 (58) hide show
  1. package/dist/claude-env.js +2 -2
  2. package/dist/cli.js +1 -1
  3. package/package.json +1 -1
  4. package/runtime/node_modules/@metro-labs/core/src/runner-activity.ts +12 -12
  5. package/runtime/node_modules/@metro-labs/daemon/package.json +1 -0
  6. package/runtime/node_modules/@metro-labs/daemon/src/boot/boot.ts +1 -1
  7. package/runtime/node_modules/@metro-labs/daemon/src/claude/session.ts +2 -2
  8. package/runtime/node_modules/@metro-labs/daemon/src/claude/setup.ts +1 -0
  9. package/runtime/node_modules/@metro-labs/daemon/src/gateway/box-gateway.ts +32 -0
  10. package/runtime/node_modules/@metro-labs/daemon/src/gateway/effective.ts +2 -8
  11. package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +6 -6
  12. package/runtime/node_modules/@metro-labs/daemon/src/gateway/org-models.ts +2 -2
  13. package/runtime/node_modules/@metro-labs/daemon/src/gateway/relay.ts +108 -0
  14. package/runtime/node_modules/@metro-labs/daemon/src/mcp-server/config.ts +2 -2
  15. package/runtime/node_modules/@metro-labs/daemon/src/routes/http.ts +1 -2
  16. package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +2 -2
  17. package/runtime/node_modules/@metro-labs/daemon/src/routes/session-apis.ts +1 -2
  18. package/runtime/node_modules/@metro-labs/http/src/api-http.ts +14 -1
  19. package/runtime/node_modules/@metro-labs/http/src/connector-tools.ts +10 -1
  20. package/runtime/node_modules/@metro-labs/http/src/mcp-server-tools.ts +21 -7
  21. package/runtime/node_modules/@metro-labs/inference/package.json +42 -0
  22. package/runtime/node_modules/@metro-labs/inference/src/attempts.ts +120 -0
  23. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/codex.ts +1 -1
  24. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/delivered.ts +7 -1
  25. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/effort.ts +2 -2
  26. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/failures.ts +11 -1
  27. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/fallback.ts +5 -4
  28. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/forward.ts +1 -1
  29. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/gateway.ts +47 -37
  30. package/runtime/node_modules/@metro-labs/inference/src/measure.ts +42 -0
  31. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/model-config.ts +9 -9
  32. package/runtime/node_modules/@metro-labs/inference/src/named.ts +36 -0
  33. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/routeway.ts +2 -1
  34. package/runtime/node_modules/@metro-labs/inference/src/served.ts +18 -0
  35. package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/usage.ts +34 -9
  36. package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +8 -1
  37. package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +1 -0
  38. package/runtime/node_modules/@metro-labs/xmtp/src/tools-handlers.ts +14 -6
  39. package/runtime/node_modules/@metro-labs/xmtp/src/tools.ts +8 -2
  40. package/runtime/runtime.json +1 -1
  41. package/runtime/sdk-runner/node_modules/@metro-labs/core/src/runner-activity.ts +12 -12
  42. package/runtime/sdk-runner/runner.json +1 -1
  43. package/runtime/sdk-runner/src/app.ts +1 -1
  44. package/runtime/sdk-runner/src/runner.ts +1 -1
  45. package/skills/STAGE.md +3 -2
  46. package/runtime/node_modules/@metro-labs/daemon/src/gateway/served.ts +0 -18
  47. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/bedrock.ts +0 -0
  48. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/cache-ttl.ts +0 -0
  49. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/codex-stream.ts +0 -0
  50. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/codex-translate.ts +0 -0
  51. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/codex-version.ts +0 -0
  52. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/eventstream.ts +0 -0
  53. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/frames.ts +0 -0
  54. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/openrouter.ts +0 -0
  55. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/subscription.ts +0 -0
  56. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/text.ts +0 -0
  57. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/tool-search.ts +0 -0
  58. /package/runtime/node_modules/@metro-labs/{daemon/src/gateway → inference/src}/usage-refresh.ts +0 -0
@@ -1,3 +1,4 @@
1
+ import { currentAttempt } from './attempts.js';
1
2
  type Key = string;
2
3
 
3
4
  export interface UsageWindow {
@@ -92,28 +93,49 @@ export function tallyTokens(key: Key, counted: Counted, now = new Date()): void
92
93
  });
93
94
  }
94
95
 
95
- const TOKEN_FIELD = /"(input_tokens|output_tokens|cache_read_input_tokens|cache_creation_input_tokens)"\s*:\s*(\d+)/g;
96
+ const TOKEN_FIELD = /"(input_tokens|output_tokens|cache_read_input_tokens|cache_creation_input_tokens|ephemeral_5m_input_tokens|ephemeral_1h_input_tokens|cost)"\s*:\s*(\d+(?:\.\d+)?)/g;
97
+
98
+ const FIELDS: Record<string, keyof Seen> = {
99
+ input_tokens: 'input',
100
+ output_tokens: 'output',
101
+ cache_read_input_tokens: 'read',
102
+ cache_creation_input_tokens: 'creation',
103
+ ephemeral_5m_input_tokens: 'write5m',
104
+ ephemeral_1h_input_tokens: 'write1h',
105
+ cost: 'cost',
106
+ };
107
+
108
+ interface Seen {
109
+ input: number;
110
+ output: number;
111
+ read: number;
112
+ creation: number;
113
+ write5m: number;
114
+ write1h: number;
115
+ cost: number;
116
+ }
96
117
 
97
118
  export class UsageScanner {
98
119
  private carry = '';
99
- private readonly max = { input: 0, output: 0, read: 0, creation: 0 };
120
+ private readonly max: Seen = { input: 0, output: 0, read: 0, creation: 0, write5m: 0, write1h: 0, cost: 0 };
100
121
  private touched = false;
122
+ private costed = false;
101
123
 
102
124
  constructor(private readonly key: Key) {}
103
125
 
104
126
  private scan(text: string): void {
105
127
  for (const hit of text.matchAll(TOKEN_FIELD)) {
128
+ const field = FIELDS[hit[1] ?? ''];
106
129
  const value = Number(hit[2]);
107
- if (!Number.isFinite(value)) continue;
108
- this.touched = true;
109
- if (hit[1] === 'input_tokens') this.max.input = Math.max(this.max.input, value);
110
- else if (hit[1] === 'output_tokens') this.max.output = Math.max(this.max.output, value);
111
- else if (hit[1] === 'cache_read_input_tokens') this.max.read = Math.max(this.max.read, value);
112
- else this.max.creation = Math.max(this.max.creation, value);
130
+ if (field === undefined || !Number.isFinite(value)) continue;
131
+ if (field === 'cost') this.costed = true;
132
+ else this.touched = true;
133
+ this.max[field] = Math.max(this.max[field], value);
113
134
  }
114
135
  }
115
136
 
116
137
  feed(text: string): void {
138
+ currentAttempt()?.firstByte();
117
139
  const joined = this.carry + text;
118
140
  const cut = joined.lastIndexOf('\n');
119
141
  if (cut === -1) {
@@ -128,7 +150,10 @@ export class UsageScanner {
128
150
  if (this.carry !== '') this.scan(this.carry);
129
151
  this.carry = '';
130
152
  if (!this.touched) return;
131
- tallyTokens(this.key, { input: this.max.input, output: this.max.output, cached: this.max.read + this.max.creation }, now);
153
+ const { input, output, read, creation, write5m, write1h, cost } = this.max;
154
+ const split = write5m + write1h;
155
+ currentAttempt()?.counted({ input, output, cacheRead: read, cacheWrite5m: split > 0 ? write5m : creation, cacheWrite1h: write1h }, this.costed ? cost : null);
156
+ tallyTokens(this.key, { input, output, cached: read + creation }, now);
132
157
  this.touched = false;
133
158
  }
134
159
  }
@@ -25,7 +25,11 @@ async function applyNameAndDescription(
25
25
  group: GroupLike,
26
26
  name: string | undefined,
27
27
  description: string | undefined,
28
+ verb: string,
28
29
  ): Promise<void> {
30
+ if (description !== undefined && typeof group.updateDescription !== 'function') {
31
+ throw new TrainError('INVALID_ARGS', `${verb} target does not support native group descriptions`);
32
+ }
29
33
  if (
30
34
  typeof name === 'string' &&
31
35
  name &&
@@ -88,7 +92,7 @@ async function applyChannelMeta(
88
92
  }
89
93
  }
90
94
 
91
- await applyNameAndDescription(group, name, description);
95
+ await applyNameAndDescription(group, name, description, verb);
92
96
  const merged = await applyMergedAppData(
93
97
  group as GroupLike & { updateAppData: (s: string) => Promise<void> },
94
98
  appData,
@@ -139,6 +143,9 @@ export async function updateChannelMeta(id: string, args: Args): Promise<void> {
139
143
  if (name !== undefined && typeof name !== 'string') {
140
144
  throw new TrainError('INVALID_ARGS', 'name must be a string');
141
145
  }
146
+ if (description !== undefined && typeof description !== 'string') {
147
+ throw new TrainError('INVALID_ARGS', 'description must be a string');
148
+ }
142
149
  const task = () => applyChannelMeta({ line, name, description, appData }, 'updateChannelMeta');
143
150
  const previous = metadataWrites.get(key);
144
151
  const pending = previous ? previous.then(task, task) : task();
@@ -100,6 +100,7 @@ export async function buildGroupInfo(
100
100
  account: acct.cfg.id,
101
101
  version: isDm ? 'dm' : 'group',
102
102
  name: resolvedName ?? '',
103
+ description: 'description' in conv ? conv.description : '',
103
104
  memberCount: inboxIds.length,
104
105
  labels,
105
106
  category,
@@ -12,6 +12,9 @@ export const str = (v: unknown): string => (typeof v === 'string' ? v : '');
12
12
 
13
13
  function channelAppData(a: Record<string, unknown>): Record<string, unknown> {
14
14
  const appData = a.metadata === undefined ? {} : { ...metadataPatch(a.metadata) };
15
+ if (Object.hasOwn(appData, 'description')) {
16
+ throw new TrainError('INVALID_ARGS', 'Use top-level description for the native XMTP group description, not metadata.description');
17
+ }
15
18
  for (const key of ['labels', 'github', 'preview']) {
16
19
  if (!Object.hasOwn(a, key)) continue;
17
20
  if (Object.hasOwn(appData, key)) {
@@ -29,18 +32,23 @@ export async function setChannelMetadata(
29
32
  ) {
30
33
  const line = str(a.line);
31
34
  if (!line) return ctx.err('set_channel_metadata requires `line`');
32
- if (Object.hasOwn(a, 'name') && typeof a.name !== 'string') {
33
- return ctx.err('set_channel_metadata name must be a string');
34
- }
35
+ const invalidField = ['name', 'description'].find(
36
+ (field) => Object.hasOwn(a, field) && typeof a[field] !== 'string',
37
+ );
38
+ if (invalidField) return ctx.err(`set_channel_metadata ${invalidField} must be a string`);
35
39
  const appData = channelAppData(a);
36
40
  const metaName = a.name;
37
41
  const hasName = typeof metaName === 'string' && metaName.length > 0;
38
- if (!hasName && Object.keys(appData).length === 0)
42
+ const hasDescription = typeof a.description === 'string';
43
+ const hasAppData = Object.keys(appData).length > 0;
44
+ if (!hasName && !hasDescription && !hasAppData)
39
45
  return ctx.err(
40
- 'set_channel_metadata requires at least one of `metadata`, `github`, `preview`, `name`, `labels`',
46
+ 'set_channel_metadata requires at least one of `metadata`, `github`, `preview`, `name`, `description`, `labels`',
41
47
  );
42
- const callArgs: Record<string, unknown> = { line, appData };
48
+ const callArgs: Record<string, unknown> = { line };
49
+ if (hasAppData) callArgs.appData = appData;
43
50
  if (hasName) callArgs.name = metaName;
51
+ if (hasDescription) callArgs.description = a.description;
44
52
  return ctx.okJson(await ctx.call('updateChannelMeta', callArgs));
45
53
  }
46
54
 
@@ -115,7 +115,7 @@ export const XMTP_TOOLS: StationTool[] = [
115
115
  group: 'read',
116
116
  description:
117
117
  "Read an XMTP channel's current metadata + membership. Args: line (required). Returns " +
118
- '{line, id, account, version (dm|group), name, memberCount, labels, category, status, priority, github, preview, ' +
118
+ '{line, id, account, version (dm|group), name, description (native XMTP group description, empty for DMs), memberCount, labels, category, status, priority, github, preview, ' +
119
119
  'assigned, appData (stored JSON object), rawAppData (stored JSON string), ' +
120
120
  'members:[{inboxId, address}]}. Syncs first and fails if metadata cannot be read. ' +
121
121
  'xmtp-only (daemon `groupInfo`). Use before ' +
@@ -170,7 +170,9 @@ export const XMTP_TOOLS: StationTool[] = [
170
170
  group: 'write',
171
171
  description:
172
172
  "Update an existing channel's metadata. Args: line (required, the metro:// line), and " +
173
- 'any of metadata? (JSON object), github? (url), preview? (url), name? (string). ' +
173
+ 'any of metadata? (JSON object), github? (url), preview? (url), name? (string), description? (string). ' +
174
+ 'Top-level description updates the standard XMTP group description shown in Stage; "" clears it. ' +
175
+ 'Use group_info.description for native readback. metadata.description is refused; it is not the visible description. ' +
174
176
  'metadata is a shallow appData patch: omitted keys are preserved, supplied nested ' +
175
177
  'values replace that key, and null deletes custom keys. v is reserved. Put labels, ' +
176
178
  'assigned, category, status and priority inside metadata. assigned replaces the array with normalized lowercase ' +
@@ -226,6 +228,10 @@ export const XMTP_TOOLS: StationTool[] = [
226
228
  description: 'Linked preview URL ("" to clear).',
227
229
  },
228
230
  name: { type: 'string', description: 'New channel name.' },
231
+ description: {
232
+ type: 'string',
233
+ description: 'Standard XMTP group description shown in Stage. "" clears it. Omit to preserve it; never put it inside metadata.',
234
+ },
229
235
  },
230
236
  required: ['line'],
231
237
  },
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.1.0-beta.320"
2
+ "version": "0.1.0-beta.322"
3
3
  }
@@ -8,17 +8,17 @@ export type RunnerTaskState = (typeof TASK_STATES)[number];
8
8
  export type RunnerEventKind = (typeof EVENTS)[number];
9
9
 
10
10
  const FAILURE = {
11
- authentication: 'The provider refused authentication. Check the Model page.',
12
- billing: 'The provider refused billing. Check the Model page.',
13
- rate_limit: 'The provider rate limit was reached. Retry later or check the Model page.',
14
- provider_unavailable: 'The provider is unavailable. Retry later or check the Model page.',
15
- invalid_request: 'The provider rejected the request. Check Conversations and the Model page.',
11
+ authentication: 'The provider refused authentication. Check the Gateway page.',
12
+ billing: 'The provider refused billing. Check the Gateway page.',
13
+ rate_limit: 'The provider rate limit was reached. Retry later or check the Gateway page.',
14
+ provider_unavailable: 'The provider is unavailable. Retry later or check the Gateway page.',
15
+ invalid_request: 'The provider rejected the request. Check Conversations and the Gateway page.',
16
16
  output_limit: 'The model reached its output token limit. Check Conversations.',
17
- provider_error: 'SDK turn failed (provider_error). Check Conversations and the Model page.',
18
- error_during_execution: 'SDK turn failed (error_during_execution). Check Conversations and the Model page.',
19
- error_max_turns: 'SDK turn failed (error_max_turns). Check Conversations and the Model page.',
20
- error_max_budget_usd: 'SDK turn failed (error_max_budget_usd). Check Conversations and the Model page.',
21
- error_max_structured_output_retries: 'SDK turn failed (error_max_structured_output_retries). Check Conversations and the Model page.',
17
+ provider_error: 'SDK turn failed (provider_error). Check Conversations and the Gateway page.',
18
+ error_during_execution: 'SDK turn failed (error_during_execution). Check Conversations and the Gateway page.',
19
+ error_max_turns: 'SDK turn failed (error_max_turns). Check Conversations and the Gateway page.',
20
+ error_max_budget_usd: 'SDK turn failed (error_max_budget_usd). Check Conversations and the Gateway page.',
21
+ error_max_structured_output_retries: 'SDK turn failed (error_max_structured_output_retries). Check Conversations and the Gateway page.',
22
22
  read_token_limit: 'Read exceeded its token limit. Read a smaller range with offset and limit, or search the file.',
23
23
  tool_error: 'A tool failed. See its result in Conversations.',
24
24
  task_error: 'A background task failed. See Conversations and Terminal.',
@@ -27,12 +27,12 @@ const FAILURE = {
27
27
  saved_state: 'The saved Agent SDK state cannot be read. Restore it before starting.',
28
28
  executable: 'The SDK executable could not start. Prepare the SDK runtime again.',
29
29
  module: 'The SDK runtime could not load a required module. Prepare the SDK runtime again.',
30
- configuration: 'The SDK launch configuration is missing or invalid. Check Harness and the Model page before starting.',
30
+ configuration: 'The SDK launch configuration is missing or invalid. Check Harness and the Gateway page before starting.',
31
31
  process_exit: 'The SDK process exited unexpectedly. Check its reported exit code or signal before retrying.',
32
32
  connection: 'The SDK connection failed. Check the server and provider connection.',
33
33
  session_ended: 'The Agent SDK session ended unexpectedly.',
34
34
  interrupted: 'The SDK stopped before finishing a chat request. Check Conversations before retrying; actions may already have run.',
35
- session_error: 'The Agent SDK session failed. Check Terminal and the Model page.',
35
+ session_error: 'The Agent SDK session failed. Check Terminal and the Gateway page.',
36
36
  } as const;
37
37
  export type RunnerFailureCode = keyof typeof FAILURE;
38
38
 
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.0-beta.320",
2
+ "version": "0.1.0-beta.322",
3
3
  "dependencies": {
4
4
  "@anthropic-ai/claude-agent-sdk": "0.3.287",
5
5
  "@modelcontextprotocol/sdk": "^1.29.0",
@@ -40,7 +40,7 @@ async function connected(cfg: RunnerConfig, hooks: AppHooks, release: () => Prom
40
40
  callState: (state) => { runner.calls.reconcile(state.route); },
41
41
  toolsChanged: () => { tools?.changed(); },
42
42
  model: (model) => {
43
- log.info({ model }, 'sdk-runner: the Model page picked a model');
43
+ log.info({ model }, 'sdk-runner: the Gateway page picked a model');
44
44
  runner.switchModel(model).catch((err: unknown) => {
45
45
  log.warn({ err: errMsg(err) }, 'sdk-runner: could not switch the model');
46
46
  });
@@ -243,7 +243,7 @@ export class Runner {
243
243
  debugFailure('model switch', err);
244
244
  const failure = new SessionError(this.diagnostics.failure(err));
245
245
  this.parts.activity?.fail(failure);
246
- log.warn({ reason: failure.failure.code, diagnostic: failure.failure.diagnostic, summary: failureSummary(failure) }, 'sdk-runner: the session could not take the model the Model page picked');
246
+ log.warn({ reason: failure.failure.code, diagnostic: failure.failure.diagnostic, summary: failureSummary(failure) }, 'sdk-runner: the session could not take the model the Gateway page picked');
247
247
  });
248
248
  }
249
249
 
package/skills/STAGE.md CHANGED
@@ -11,10 +11,11 @@ Stage (https://stage.box) is a messenger built on XMTP. A Stage channel is an XM
11
11
 
12
12
  **Channels.**
13
13
  - Create: `create_group {"station": "xmtp", "name": "Launch plan", "members": ["0x…"]}`. Members are 0x addresses or XMTP inbox ids. It returns the new `line` and `id`.
14
- - Rename: `set_channel_metadata {"line": "…", "name": "New title"}`. No tool sets the description or the picture.
14
+ - Rename: `set_channel_metadata {"line": "…", "name": "New title"}`. No tool sets the picture.
15
+ - Description: `set_channel_metadata {"line": "…", "description": "What this channel is for"}` sets the standard XMTP group description shown in Stage. `""` clears it. Read `group_info.description` to check it saved. Never put it in `metadata.description`: that is not the visible description and is refused.
15
16
  - Add or remove people: `add_members {"line": "…", "members": ["0x…"]}`. `remove_members` takes the same shape.
16
17
  - Leave: `close_channel {"line": "…", "removeSelf": true}`.
17
- - Read: `group_info {"line": "…"}` gives the name, `labels`, `assigned`, `category`, `status`, `priority`, `appData` and the members (`inboxId`, `address`). `list_members {"line": "…"}` gives the members only.
18
+ - Read: `group_info {"line": "…"}` gives the name, native `description`, `labels`, `assigned`, `category`, `status`, `priority`, `appData` and the members (`inboxId`, `address`). `list_members {"line": "…"}` gives the members only.
18
19
  - Direct chat: `dm {"address": "0x…"}` opens a 1:1 chat and returns its line.
19
20
  - With several XMTP accounts, add `"account": "<id>"` to `create_group` and `dm`.
20
21
 
@@ -1,18 +0,0 @@
1
- export interface Served {
2
- connection: string;
3
- provider: string;
4
- model: string;
5
- at: string;
6
- }
7
-
8
- let last: Served | null = null;
9
-
10
- export const noteServed = (served: Served): void => {
11
- last = served;
12
- };
13
-
14
- export const lastServed = (): Served | null => last;
15
-
16
- export const forgetServed = (): void => {
17
- last = null;
18
- };