@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.
- package/dist/agent.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/lock.js +15 -3
- package/dist/root-release-io.js +1 -2
- package/dist/root-release.js +2 -3
- package/dist/route.js +1 -1
- package/dist/service.js +4 -4
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/runtime/node_modules/@metro-labs/core/src/automation-store.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/automation-types.ts +2 -2
- package/runtime/node_modules/@metro-labs/core/src/lines.ts +2 -8
- package/runtime/node_modules/@metro-labs/core/src/protocol.ts +0 -6
- package/runtime/node_modules/@metro-labs/core/src/skill-source.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/account-status.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/attachments.ts +5 -9
- package/runtime/node_modules/@metro-labs/core/src/stations/channel-directory.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/mail-text.ts +4 -4
- package/runtime/node_modules/@metro-labs/core/src/stations/mail.ts +3 -2
- package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/oauth.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/profile.ts +2 -2
- package/runtime/node_modules/@metro-labs/core/src/stations/types.ts +2 -2
- package/runtime/node_modules/@metro-labs/core/src/train-error.ts +4 -4
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files.ts +2 -6
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules.ts +6 -6
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/user.ts +0 -24
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/view.ts +3 -3
- package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +3 -4
- package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +4 -9
- package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +1 -6
- package/runtime/node_modules/@metro-labs/daemon/src/channels/inbound.ts +3 -3
- package/runtime/node_modules/@metro-labs/daemon/src/channels/pending.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/claude/files.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-grant.ts +3 -2
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-serve.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/files/upload-api.ts +3 -7
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/accounts.ts +10 -19
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/call-tools.ts +1 -5
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/event-store.ts +3 -4
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/group-tools.ts +1 -2
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/index.ts +2 -4
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-gate.ts +5 -6
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/server-approvals.ts +2 -5
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session.ts +1 -5
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-catalog.ts +2 -4
- package/runtime/node_modules/@metro-labs/daemon/src/mcp-server/announced.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/helper-script.ts +0 -1
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/install.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/tailscale-guard.ts +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +1 -3
- package/runtime/node_modules/@metro-labs/daemon/src/routes/gmail-attach.ts +3 -3
- package/runtime/node_modules/@metro-labs/daemon/src/routes/http.ts +6 -21
- package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +1 -5
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-resolve.ts +6 -6
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach.ts +0 -1
- package/runtime/node_modules/@metro-labs/daemon/src/stations/materialize.ts +12 -61
- package/runtime/node_modules/@metro-labs/daemon/src/stations/supervisor.ts +13 -25
- package/runtime/node_modules/@metro-labs/daemon/src/stations/threema-callbacks.ts +5 -5
- package/runtime/node_modules/@metro-labs/daemon/src/stations/webhook-endpoints.ts +2 -7
- package/runtime/node_modules/@metro-labs/daemon/src/voice/call.ts +2 -6
- package/runtime/node_modules/@metro-labs/daemon/src/voice/calls.ts +12 -12
- package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +5 -23
- package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +1 -7
- package/runtime/node_modules/@metro-labs/discord-bot/src/channels.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +10 -35
- package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +5 -11
- package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +6 -34
- package/runtime/node_modules/@metro-labs/discord-bot/src/profile.ts +11 -14
- package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +1 -3
- package/runtime/node_modules/@metro-labs/discord-bot/src/verify.ts +2 -3
- package/runtime/node_modules/@metro-labs/gmail/src/accounts.ts +3 -3
- package/runtime/node_modules/@metro-labs/gmail/src/auth.ts +8 -8
- package/runtime/node_modules/@metro-labs/gmail/src/managed.ts +3 -2
- package/runtime/node_modules/@metro-labs/http/src/agent-signature.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/api-http.ts +3 -4
- package/runtime/node_modules/@metro-labs/http/src/connector-discovery.ts +0 -113
- package/runtime/node_modules/@metro-labs/http/src/connector-input.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/connector-mcp.ts +12 -13
- package/runtime/node_modules/@metro-labs/http/src/connector-oauth.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/connector-policy.ts +1 -6
- package/runtime/node_modules/@metro-labs/http/src/connector-public-url.ts +4 -2
- package/runtime/node_modules/@metro-labs/http/src/connector-tools.ts +1 -11
- package/runtime/node_modules/@metro-labs/http/src/connector-url.ts +0 -6
- package/runtime/node_modules/@metro-labs/http/src/mcp-server-protocol.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/mcp-server-tools.ts +0 -2
- package/runtime/node_modules/@metro-labs/http/src/mode-api.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/return-to.ts +2 -2
- package/runtime/node_modules/@metro-labs/http/src/workos-token.ts +6 -7
- package/runtime/node_modules/@metro-labs/inference/package.json +1 -0
- package/runtime/node_modules/@metro-labs/inference/src/attempts.ts +3 -3
- package/runtime/node_modules/@metro-labs/inference/src/bedrock.ts +1 -1
- package/runtime/node_modules/@metro-labs/inference/src/codex-translate.ts +2 -2
- package/runtime/node_modules/@metro-labs/inference/src/delivered.ts +1 -1
- package/runtime/node_modules/@metro-labs/inference/src/effort.ts +0 -6
- package/runtime/node_modules/@metro-labs/inference/src/fallback.ts +7 -5
- package/runtime/node_modules/@metro-labs/inference/src/forward.ts +5 -5
- package/runtime/node_modules/@metro-labs/inference/src/measure.ts +2 -3
- package/runtime/node_modules/@metro-labs/inference/src/named.ts +3 -3
- package/runtime/node_modules/@metro-labs/inference/src/probes.ts +98 -0
- package/runtime/node_modules/@metro-labs/inference/src/usage.ts +5 -5
- package/runtime/node_modules/@metro-labs/outlook/src/accounts.ts +6 -8
- package/runtime/node_modules/@metro-labs/outlook/src/auth.ts +2 -1
- package/runtime/node_modules/@metro-labs/outlook/src/inbound.ts +3 -5
- package/runtime/node_modules/@metro-labs/outlook/src/me.ts +6 -6
- package/runtime/node_modules/@metro-labs/outlook/src/outbound.ts +10 -13
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +7 -26
- package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram/src/login.ts +3 -6
- package/runtime/node_modules/@metro-labs/telegram/src/profile.ts +3 -2
- package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +6 -20
- package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +1 -7
- package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +0 -2
- package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +1 -16
- package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +1 -8
- package/runtime/node_modules/@metro-labs/telegram-bot/src/profile.ts +2 -1
- package/runtime/node_modules/@metro-labs/threema/src/actions.ts +1 -8
- package/runtime/node_modules/@metro-labs/threema/src/chats.ts +4 -3
- package/runtime/node_modules/@metro-labs/threema/src/format.ts +15 -17
- package/runtime/node_modules/@metro-labs/threema/src/groups.ts +2 -4
- package/runtime/node_modules/@metro-labs/threema/src/inbound.ts +2 -1
- package/runtime/node_modules/@metro-labs/threema/src/messages.ts +2 -1
- package/runtime/node_modules/@metro-labs/threema/src/outbound.ts +7 -7
- package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +1 -3
- package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +0 -2
- package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +7 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +4 -10
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +4 -5
- package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +14 -26
- package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +1 -7
- package/runtime/node_modules/@metro-labs/xmtp/src/codecs.ts +17 -58
- package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +1 -6
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +10 -31
- package/runtime/node_modules/@metro-labs/xmtp/src/frames.ts +12 -14
- package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +2 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +3 -9
- package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +8 -9
- package/runtime/node_modules/@metro-labs/xmtp/src/names.ts +4 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/network.ts +2 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/profile.ts +2 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/read-attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/sender.ts +2 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +23 -46
- package/runtime/node_modules/@metro-labs/xmtp/src/wallet.ts +5 -4
- package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +12 -15
- package/runtime/runtime.json +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/automation-store.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/automation-types.ts +2 -2
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/lines.ts +2 -8
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/protocol.ts +0 -6
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/skill-source.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/account-status.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/attachments.ts +5 -9
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/channel-directory.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/mail-text.ts +4 -4
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/mail.ts +3 -2
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/oauth.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/profile.ts +2 -2
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/types.ts +2 -2
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/train-error.ts +4 -4
- package/runtime/sdk-runner/runner.json +1 -1
- package/runtime/sdk-runner/src/approvals.ts +2 -2
- package/runtime/sdk-runner/src/automation-command.ts +2 -2
- package/runtime/sdk-runner/src/calls.ts +0 -6
- package/runtime/sdk-runner/src/errors.ts +1 -1
- package/runtime/sdk-runner/src/link.ts +1 -1
- package/runtime/sdk-runner/src/runner.ts +2 -2
- package/runtime/sdk-runner/src/session-watch.ts +5 -34
- package/runtime/sdk-runner/src/task-state.ts +1 -1
- package/runtime/sdk-runner/src/tool-proxy.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +0 -40
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
56
|
-
if (text.length <=
|
|
57
|
-
return `${text.slice(0,
|
|
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
|
-
|
|
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
|
-
.
|
|
164
|
+
.filter(isRecord)
|
|
164
165
|
.filter((a) => typeof a.path === 'string' && a.path !== '')
|
|
165
166
|
.map((a) => ({
|
|
166
167
|
path: String(a.path),
|
|
@@ -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
|
-
|
|
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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
45
|
-
if (!
|
|
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;
|
|
@@ -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
|
-
|
|
10
|
+
type ApprovalWatch = (id: string, ask: ApprovalAsk | null) => void;
|
|
11
11
|
|
|
12
12
|
export interface ApprovalBinding { call: CallSource; signal: AbortSignal }
|
|
13
|
-
|
|
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
|
-
|
|
12
|
+
class AutomationCommandError extends Error {}
|
|
13
13
|
|
|
14
|
-
|
|
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
|
-
|
|
13
|
+
interface SessionFailure {
|
|
14
14
|
code: RunnerFailureCode;
|
|
15
15
|
diagnostic?: RunnerDiagnostic;
|
|
16
16
|
}
|
|
@@ -57,7 +57,7 @@ export function runnerOptions(cfg: RunnerConfig, tools: MetroTools, canUseTool:
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
91
|
+
else if (m.subtype === 'status') this.compactingNow = m.status === 'compacting';
|
|
102
92
|
else if (m.subtype === 'compact_boundary') {
|
|
103
|
-
this.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
}
|