@agentproto/adapter-mastra-agent 0.5.5 → 0.7.0
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/{chunk-6ILIPWNM.mjs → chunk-2FKFITFT.mjs} +183 -24
- package/dist/chunk-2FKFITFT.mjs.map +1 -0
- package/dist/cli.mjs +1 -1
- package/dist/index.d.ts +216 -178
- package/dist/index.mjs +1 -1
- package/package.json +8 -7
- package/dist/chunk-6ILIPWNM.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AgentCliHandle, AgentCliRuntime } from '@agentproto/driver-agent-cli';
|
|
|
2
2
|
export { AgentCliHandle, AgentCliRuntime } from '@agentproto/driver-agent-cli';
|
|
3
3
|
import { MastraToolLike } from '@agentproto/mastra';
|
|
4
4
|
import { BuiltinToolId, AgentController, PermissionRules, AgentControllerEvent } from '@mastra/core/agent-controller';
|
|
5
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
5
6
|
import { Agent, AgentSideConnection, InitializeRequest, InitializeResponse, AuthenticateRequest, NewSessionRequest, NewSessionResponse, LoadSessionRequest, LoadSessionResponse, PromptRequest, PromptResponse, CancelNotification, SetSessionConfigOptionRequest, SetSessionConfigOptionResponse, SetSessionModeRequest, SessionUpdate, ToolKind } from '@agentclientprotocol/sdk';
|
|
6
7
|
import { LanguageModelV3 } from '@ai-sdk/provider';
|
|
7
8
|
import { ModelRef, MemoryConfig } from '@agentproto/agent';
|
|
@@ -9,6 +10,184 @@ import { createTool } from '@mastra/core/tools';
|
|
|
9
10
|
import { LibSQLStore } from '@mastra/libsql';
|
|
10
11
|
import { Memory } from '@mastra/memory';
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Zero-dependency HTTP client for the agentproto daemon.
|
|
15
|
+
*
|
|
16
|
+
* The adapter is spawned as an ACP child with `AGENTPROTO_SESSION_ID` /
|
|
17
|
+
* `AGENTPROTO_PARENT_SESSION_ID` in its env, but no daemon URL/token — unlike
|
|
18
|
+
* the CLI (`packages/cli/src/commands/_daemon-helpers.ts`, read as reference),
|
|
19
|
+
* this package cannot import `@agentproto/runtime` or `@agentproto/cli`
|
|
20
|
+
* (would pull the whole daemon runtime into an agent process). So this is a
|
|
21
|
+
* deliberately smaller reimplementation of that discovery order:
|
|
22
|
+
*
|
|
23
|
+
* 1. `AGENTPROTO_DAEMON_URL` env (+ optional `AGENTPROTO_DAEMON_TOKEN`)
|
|
24
|
+
* 2. `<cwd>/.agentproto/runtime.json`
|
|
25
|
+
* 3. `~/.agentproto/runtime.json`
|
|
26
|
+
* 4. central registry `~/.agentproto/daemons/*.json`, newest-mtime-first
|
|
27
|
+
*
|
|
28
|
+
* Unlike the CLI helper, this skips the `workspaces.json` walk (needs
|
|
29
|
+
* `@agentproto/runtime`'s config loader) and the declared-port preference
|
|
30
|
+
* in the central registry (needs `loadConfig()`). Good enough for an agent
|
|
31
|
+
* process discovering the daemon that spawned it or one on the same host.
|
|
32
|
+
*
|
|
33
|
+
* A runtime.json / registry entry whose `pid` is dead (`process.kill(pid, 0)`
|
|
34
|
+
* throwing anything but `EPERM`) is never trusted — same footgun the CLI
|
|
35
|
+
* helper guards against (a crashed daemon's stale token 401ing a fresh one
|
|
36
|
+
* on the same port).
|
|
37
|
+
*/
|
|
38
|
+
interface DaemonEndpoint {
|
|
39
|
+
url: string;
|
|
40
|
+
token?: string;
|
|
41
|
+
/** Path of the runtime.json / registry file the endpoint came from.
|
|
42
|
+
* Undefined when the endpoint came from env vars. */
|
|
43
|
+
sourcePath?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Thrown when no daemon endpoint can be discovered. */
|
|
46
|
+
declare class DaemonNotFoundError extends Error {
|
|
47
|
+
constructor(message?: string);
|
|
48
|
+
}
|
|
49
|
+
/** Thrown on a non-2xx daemon HTTP response. */
|
|
50
|
+
declare class DaemonHttpError extends Error {
|
|
51
|
+
readonly status: number;
|
|
52
|
+
readonly body: string;
|
|
53
|
+
constructor(message: string, status: number, body: string);
|
|
54
|
+
}
|
|
55
|
+
interface DiscoverDaemonOptions {
|
|
56
|
+
cwd?: string;
|
|
57
|
+
env?: NodeJS.ProcessEnv;
|
|
58
|
+
/** Override `homedir()` for BOTH `~/.agentproto/runtime.json` and the
|
|
59
|
+
* central registry dir (unless `registryDir` also overrides the latter
|
|
60
|
+
* separately) — test hook, so discovery never has to touch a real
|
|
61
|
+
* developer machine's `~/.agentproto`. */
|
|
62
|
+
homeDir?: string;
|
|
63
|
+
/** Override the central registry directory — test hook. Wins over `homeDir`. */
|
|
64
|
+
registryDir?: string;
|
|
65
|
+
/** Override the liveness check for a runtime.json / registry entry's
|
|
66
|
+
* `pid` — test hook. Defaults to a real `process.kill(pid, 0)` probe. */
|
|
67
|
+
isPidAlive?: (pid: number) => boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolve the first live daemon endpoint, in the order documented above.
|
|
71
|
+
* Returns undefined when nothing live is found.
|
|
72
|
+
*/
|
|
73
|
+
declare function discoverDaemonEndpoint(opts?: DiscoverDaemonOptions): Promise<DaemonEndpoint | undefined>;
|
|
74
|
+
interface StartAgentInput {
|
|
75
|
+
adapter: string;
|
|
76
|
+
cwd?: string;
|
|
77
|
+
model?: string;
|
|
78
|
+
prompt?: string;
|
|
79
|
+
label?: string;
|
|
80
|
+
}
|
|
81
|
+
interface PromptAgentOptions {
|
|
82
|
+
/** Cancel the in-flight turn and deliver this prompt instead. Default false. */
|
|
83
|
+
interrupt?: boolean;
|
|
84
|
+
/** `false` returns as soon as the prompt is queued/validated, without
|
|
85
|
+
* waiting for the turn to drain. Default true (blocking). */
|
|
86
|
+
wait?: boolean;
|
|
87
|
+
}
|
|
88
|
+
interface ListSessionsOptions {
|
|
89
|
+
includeArchived?: boolean;
|
|
90
|
+
kind?: string;
|
|
91
|
+
}
|
|
92
|
+
interface ReadOutputOptions {
|
|
93
|
+
format?: "markdown" | "json";
|
|
94
|
+
}
|
|
95
|
+
interface PollEventsOptions {
|
|
96
|
+
/** Cursor from a prior call's `nextSeq`. Omit to start from the beginning. */
|
|
97
|
+
since?: number;
|
|
98
|
+
/** Client-side filter on each record's `kind` field. Omit → all kinds. */
|
|
99
|
+
types?: string[];
|
|
100
|
+
limit?: number;
|
|
101
|
+
}
|
|
102
|
+
interface PollEventsResult {
|
|
103
|
+
sessionId: string;
|
|
104
|
+
events: Array<Record<string, unknown>>;
|
|
105
|
+
nextSeq: number;
|
|
106
|
+
complete: boolean;
|
|
107
|
+
}
|
|
108
|
+
interface DaemonClientOptions {
|
|
109
|
+
cwd?: string;
|
|
110
|
+
env?: NodeJS.ProcessEnv;
|
|
111
|
+
/** Injectable fetch — test hook. Defaults to the global `fetch`. */
|
|
112
|
+
fetchImpl?: typeof fetch;
|
|
113
|
+
/** Pre-resolved endpoint — skips discovery, mainly a test hook. */
|
|
114
|
+
endpoint?: DaemonEndpoint;
|
|
115
|
+
/** Test hooks forwarded to {@link discoverDaemonEndpoint}. */
|
|
116
|
+
homeDir?: string;
|
|
117
|
+
registryDir?: string;
|
|
118
|
+
isPidAlive?: (pid: number) => boolean;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Thin HTTP client over the daemon's REST surface (`packages/runtime/src/http-server.ts`,
|
|
122
|
+
* read-only reference — this package never imports it). Discovers the daemon
|
|
123
|
+
* endpoint lazily on first call and caches it; a connection failure triggers
|
|
124
|
+
* one re-discovery attempt (covers a daemon restart on the same well-known
|
|
125
|
+
* runtime.json / registry path but a new port/token).
|
|
126
|
+
*/
|
|
127
|
+
declare class DaemonClient {
|
|
128
|
+
private readonly cwd;
|
|
129
|
+
private readonly env;
|
|
130
|
+
private readonly fetchImpl;
|
|
131
|
+
private readonly homeDir;
|
|
132
|
+
private readonly registryDir;
|
|
133
|
+
private readonly isPidAlive;
|
|
134
|
+
private cachedEndpoint;
|
|
135
|
+
constructor(opts?: DaemonClientOptions);
|
|
136
|
+
private resolveEndpoint;
|
|
137
|
+
private request;
|
|
138
|
+
/**
|
|
139
|
+
* Spawn a child session — `POST /sessions/agent`. `parentSessionId` is
|
|
140
|
+
* derived from `AGENTPROTO_SESSION_ID` (set by the daemon on every
|
|
141
|
+
* ACP-spawned adapter) when present, so session lineage is recorded
|
|
142
|
+
* without the caller having to thread it through.
|
|
143
|
+
*/
|
|
144
|
+
startAgent(input: StartAgentInput): Promise<Record<string, unknown>>;
|
|
145
|
+
/** Send a follow-up turn to a live session — `POST /sessions/:id/prompt`. */
|
|
146
|
+
promptAgent(sessionId: string, text: string, opts?: PromptAgentOptions): Promise<Record<string, unknown>>;
|
|
147
|
+
/** List sessions — `GET /sessions`. */
|
|
148
|
+
listSessions(opts?: ListSessionsOptions): Promise<{
|
|
149
|
+
sessions: Array<Record<string, unknown>>;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Read a session's transcript — `GET /sessions/:id/export`. Chosen over
|
|
153
|
+
* `/sessions/:id/conversation` (needs a provider-native store registered
|
|
154
|
+
* for the adapter; not every adapter has one) and `/sessions/:id/preview`
|
|
155
|
+
* (a raw ring-buffer snapshot, not a rendered transcript): `/export`
|
|
156
|
+
* works for ANY agent-cli session, falling back to the daemon's own
|
|
157
|
+
* `events.jsonl` capture when no provider-native reader is registered
|
|
158
|
+
* (`source: "auto"`, see `transcript-export.ts`) — the one built for
|
|
159
|
+
* programmatic reads of "what did this session say".
|
|
160
|
+
*/
|
|
161
|
+
readOutput(sessionId: string, opts?: ReadOutputOptions): Promise<Record<string, unknown>>;
|
|
162
|
+
/**
|
|
163
|
+
* Cursor-based poll of a session's structured event log —
|
|
164
|
+
* `GET /sessions/:id/events`. NOT the same event source as the MCP
|
|
165
|
+
* `session_events_poll` tool: that tool reads the daemon's in-memory,
|
|
166
|
+
* cross-session `EventRing` (turn-end/awaiting-input/exited/... lifecycle
|
|
167
|
+
* events, `packages/runtime/src/orchestration-tools.ts:528`), which has no
|
|
168
|
+
* plain-HTTP equivalent — it's only reachable over the MCP JSON-RPC
|
|
169
|
+
* transport, which this zero-dependency client doesn't speak. This route
|
|
170
|
+
* is the per-SESSION structured `events.jsonl` transcript instead
|
|
171
|
+
* (`packages/runtime/src/transcript-writer.ts`): cursor-based via
|
|
172
|
+
* `since`/`nextSeq` same as the MCP tool, and its records DO carry many of
|
|
173
|
+
* the same `kind`s (`turn-end`, `error`, `permission-resolved`, ...) — but
|
|
174
|
+
* it has no `exited` / `session:spawned` records (those are registry
|
|
175
|
+
* state changes, not transcript writes) and no cross-session fan-in
|
|
176
|
+
* (`sessionIds` filter). `types` is therefore filtered client-side here
|
|
177
|
+
* against each record's `kind`, not sent as a query param.
|
|
178
|
+
*
|
|
179
|
+
* WP-6 (`AgentprotoSignalProvider`, polling every 5s): this is a
|
|
180
|
+
* non-blocking snapshot read, so it's a direct fit for a poll loop. If
|
|
181
|
+
* WP-6 needs the actual cross-session lifecycle events (`exited`,
|
|
182
|
+
* `session:spawned`, multi-session fan-in), it either needs its own
|
|
183
|
+
* light MCP JSON-RPC client to call `session_events_poll` directly, or
|
|
184
|
+
* per-session `GET /sessions/:id/wait?since=&event=` (a blocking
|
|
185
|
+
* long-poll over the SAME EventRing `session_events_poll` reads, but
|
|
186
|
+
* scoped to one session and one event name at a time — no `types` array).
|
|
187
|
+
*/
|
|
188
|
+
pollEvents(sessionId: string, opts?: PollEventsOptions): Promise<PollEventsResult>;
|
|
189
|
+
}
|
|
190
|
+
|
|
12
191
|
/**
|
|
13
192
|
* Builds a runnable Mastra `AgentController` from an AIP-42 AGENT.md — either
|
|
14
193
|
* a caller's file or a zero-config built-in default — wiring the model, the
|
|
@@ -47,6 +226,31 @@ interface AgentSourceOptions {
|
|
|
47
226
|
* — see this WP's report).
|
|
48
227
|
*/
|
|
49
228
|
modes?: false | "default";
|
|
229
|
+
/** Auto-injected into `app_*` daemon tool calls that omit `appId` (see
|
|
230
|
+
* `daemon-mcp-tools.ts`'s `injectAppId`). Defaults to
|
|
231
|
+
* `AGENTPROTO_APP_ID` — an explicit value here is mainly a test hook. */
|
|
232
|
+
appId?: string;
|
|
233
|
+
/**
|
|
234
|
+
* Exact absolute paths OUTSIDE `cwd` the read-only workspace tools may
|
|
235
|
+
* also read — the daemon's AGENTS.md pointer contract grant. Defaults to
|
|
236
|
+
* parsing `AGENTPROTO_ADDITIONAL_READ_PATHS` (a JSON array, set by the
|
|
237
|
+
* driver when the spawn carries the grant); malformed values are ignored
|
|
238
|
+
* (the grant is advisory — a bad payload must never break a spawn) and an
|
|
239
|
+
* explicit value here is mainly a test hook. See
|
|
240
|
+
* `WorkspaceToolsOptions.additionalReadPaths`.
|
|
241
|
+
*/
|
|
242
|
+
additionalReadPaths?: string[];
|
|
243
|
+
/** Test hook: skip discovering + connecting to a real daemon MCP endpoint.
|
|
244
|
+
* `client` injects an already-connected client outright (e.g. one wired
|
|
245
|
+
* to an in-memory fake server); `discoverOptions` isolates
|
|
246
|
+
* `discoverDaemonEndpoint` (homeDir/registryDir/env) from a real
|
|
247
|
+
* developer machine's `~/.agentproto` without faking a whole client.
|
|
248
|
+
* Neither set ⇒ production behaviour (real discovery + connect, lazily,
|
|
249
|
+
* only if an AGENT.md ref needs it). */
|
|
250
|
+
daemonMcp?: {
|
|
251
|
+
client?: Client;
|
|
252
|
+
discoverOptions?: DiscoverDaemonOptions;
|
|
253
|
+
};
|
|
50
254
|
}
|
|
51
255
|
/** The built-in AGENT.md used when no file is supplied. */
|
|
52
256
|
declare function defaultAgentManifest(model: string): string;
|
|
@@ -318,6 +522,18 @@ interface WorkspaceToolsOptions {
|
|
|
318
522
|
allowExec?: boolean;
|
|
319
523
|
/** Per-tool execution timeout (ms), enforced on every tool by `withTimeoutGuard`. Default 120_000. */
|
|
320
524
|
execTimeoutMs?: number;
|
|
525
|
+
/**
|
|
526
|
+
* Exact absolute paths OUTSIDE `cwd` the READ-ONLY tools (`read_file`,
|
|
527
|
+
* `file_read`, `file_info`) may additionally access. The daemon hands down
|
|
528
|
+
* the AGENTS.md file an inherited pointer prompt names
|
|
529
|
+
* (`AGENTPROTO_ADDITIONAL_READ_PATHS`, see `session-spawn.ts`) so the
|
|
530
|
+
* agent can actually read the contract it was told to load first.
|
|
531
|
+
* Deliberately narrow: exact files only (no parent-dir listing), the
|
|
532
|
+
* write tools (`write_file`, `edit_file`, …) never honour the grant, and
|
|
533
|
+
* sibling paths stay rejected — `escapes the workspace` still throws for
|
|
534
|
+
* everything else.
|
|
535
|
+
*/
|
|
536
|
+
additionalReadPaths?: string[];
|
|
321
537
|
/**
|
|
322
538
|
* Extra tools merged over the built-ins, keyed by id — lets an embedding
|
|
323
539
|
* host add tools the built-in toolset doesn't cover. On id collision, an
|
|
@@ -333,184 +549,6 @@ declare function resolveInCwd(cwd: string, p: string): string;
|
|
|
333
549
|
*/
|
|
334
550
|
declare function makeWorkspaceTools(opts: WorkspaceToolsOptions): Record<string, ReturnType<typeof createTool>>;
|
|
335
551
|
|
|
336
|
-
/**
|
|
337
|
-
* Zero-dependency HTTP client for the agentproto daemon.
|
|
338
|
-
*
|
|
339
|
-
* The adapter is spawned as an ACP child with `AGENTPROTO_SESSION_ID` /
|
|
340
|
-
* `AGENTPROTO_PARENT_SESSION_ID` in its env, but no daemon URL/token — unlike
|
|
341
|
-
* the CLI (`packages/cli/src/commands/_daemon-helpers.ts`, read as reference),
|
|
342
|
-
* this package cannot import `@agentproto/runtime` or `@agentproto/cli`
|
|
343
|
-
* (would pull the whole daemon runtime into an agent process). So this is a
|
|
344
|
-
* deliberately smaller reimplementation of that discovery order:
|
|
345
|
-
*
|
|
346
|
-
* 1. `AGENTPROTO_DAEMON_URL` env (+ optional `AGENTPROTO_DAEMON_TOKEN`)
|
|
347
|
-
* 2. `<cwd>/.agentproto/runtime.json`
|
|
348
|
-
* 3. `~/.agentproto/runtime.json`
|
|
349
|
-
* 4. central registry `~/.agentproto/daemons/*.json`, newest-mtime-first
|
|
350
|
-
*
|
|
351
|
-
* Unlike the CLI helper, this skips the `workspaces.json` walk (needs
|
|
352
|
-
* `@agentproto/runtime`'s config loader) and the declared-port preference
|
|
353
|
-
* in the central registry (needs `loadConfig()`). Good enough for an agent
|
|
354
|
-
* process discovering the daemon that spawned it or one on the same host.
|
|
355
|
-
*
|
|
356
|
-
* A runtime.json / registry entry whose `pid` is dead (`process.kill(pid, 0)`
|
|
357
|
-
* throwing anything but `EPERM`) is never trusted — same footgun the CLI
|
|
358
|
-
* helper guards against (a crashed daemon's stale token 401ing a fresh one
|
|
359
|
-
* on the same port).
|
|
360
|
-
*/
|
|
361
|
-
interface DaemonEndpoint {
|
|
362
|
-
url: string;
|
|
363
|
-
token?: string;
|
|
364
|
-
/** Path of the runtime.json / registry file the endpoint came from.
|
|
365
|
-
* Undefined when the endpoint came from env vars. */
|
|
366
|
-
sourcePath?: string;
|
|
367
|
-
}
|
|
368
|
-
/** Thrown when no daemon endpoint can be discovered. */
|
|
369
|
-
declare class DaemonNotFoundError extends Error {
|
|
370
|
-
constructor(message?: string);
|
|
371
|
-
}
|
|
372
|
-
/** Thrown on a non-2xx daemon HTTP response. */
|
|
373
|
-
declare class DaemonHttpError extends Error {
|
|
374
|
-
readonly status: number;
|
|
375
|
-
readonly body: string;
|
|
376
|
-
constructor(message: string, status: number, body: string);
|
|
377
|
-
}
|
|
378
|
-
interface DiscoverDaemonOptions {
|
|
379
|
-
cwd?: string;
|
|
380
|
-
env?: NodeJS.ProcessEnv;
|
|
381
|
-
/** Override `homedir()` for BOTH `~/.agentproto/runtime.json` and the
|
|
382
|
-
* central registry dir (unless `registryDir` also overrides the latter
|
|
383
|
-
* separately) — test hook, so discovery never has to touch a real
|
|
384
|
-
* developer machine's `~/.agentproto`. */
|
|
385
|
-
homeDir?: string;
|
|
386
|
-
/** Override the central registry directory — test hook. Wins over `homeDir`. */
|
|
387
|
-
registryDir?: string;
|
|
388
|
-
/** Override the liveness check for a runtime.json / registry entry's
|
|
389
|
-
* `pid` — test hook. Defaults to a real `process.kill(pid, 0)` probe. */
|
|
390
|
-
isPidAlive?: (pid: number) => boolean;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Resolve the first live daemon endpoint, in the order documented above.
|
|
394
|
-
* Returns undefined when nothing live is found.
|
|
395
|
-
*/
|
|
396
|
-
declare function discoverDaemonEndpoint(opts?: DiscoverDaemonOptions): Promise<DaemonEndpoint | undefined>;
|
|
397
|
-
interface StartAgentInput {
|
|
398
|
-
adapter: string;
|
|
399
|
-
cwd?: string;
|
|
400
|
-
model?: string;
|
|
401
|
-
prompt?: string;
|
|
402
|
-
label?: string;
|
|
403
|
-
}
|
|
404
|
-
interface PromptAgentOptions {
|
|
405
|
-
/** Cancel the in-flight turn and deliver this prompt instead. Default false. */
|
|
406
|
-
interrupt?: boolean;
|
|
407
|
-
/** `false` returns as soon as the prompt is queued/validated, without
|
|
408
|
-
* waiting for the turn to drain. Default true (blocking). */
|
|
409
|
-
wait?: boolean;
|
|
410
|
-
}
|
|
411
|
-
interface ListSessionsOptions {
|
|
412
|
-
includeArchived?: boolean;
|
|
413
|
-
kind?: string;
|
|
414
|
-
}
|
|
415
|
-
interface ReadOutputOptions {
|
|
416
|
-
format?: "markdown" | "json";
|
|
417
|
-
}
|
|
418
|
-
interface PollEventsOptions {
|
|
419
|
-
/** Cursor from a prior call's `nextSeq`. Omit to start from the beginning. */
|
|
420
|
-
since?: number;
|
|
421
|
-
/** Client-side filter on each record's `kind` field. Omit → all kinds. */
|
|
422
|
-
types?: string[];
|
|
423
|
-
limit?: number;
|
|
424
|
-
}
|
|
425
|
-
interface PollEventsResult {
|
|
426
|
-
sessionId: string;
|
|
427
|
-
events: Array<Record<string, unknown>>;
|
|
428
|
-
nextSeq: number;
|
|
429
|
-
complete: boolean;
|
|
430
|
-
}
|
|
431
|
-
interface DaemonClientOptions {
|
|
432
|
-
cwd?: string;
|
|
433
|
-
env?: NodeJS.ProcessEnv;
|
|
434
|
-
/** Injectable fetch — test hook. Defaults to the global `fetch`. */
|
|
435
|
-
fetchImpl?: typeof fetch;
|
|
436
|
-
/** Pre-resolved endpoint — skips discovery, mainly a test hook. */
|
|
437
|
-
endpoint?: DaemonEndpoint;
|
|
438
|
-
/** Test hooks forwarded to {@link discoverDaemonEndpoint}. */
|
|
439
|
-
homeDir?: string;
|
|
440
|
-
registryDir?: string;
|
|
441
|
-
isPidAlive?: (pid: number) => boolean;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Thin HTTP client over the daemon's REST surface (`packages/runtime/src/http-server.ts`,
|
|
445
|
-
* read-only reference — this package never imports it). Discovers the daemon
|
|
446
|
-
* endpoint lazily on first call and caches it; a connection failure triggers
|
|
447
|
-
* one re-discovery attempt (covers a daemon restart on the same well-known
|
|
448
|
-
* runtime.json / registry path but a new port/token).
|
|
449
|
-
*/
|
|
450
|
-
declare class DaemonClient {
|
|
451
|
-
private readonly cwd;
|
|
452
|
-
private readonly env;
|
|
453
|
-
private readonly fetchImpl;
|
|
454
|
-
private readonly homeDir;
|
|
455
|
-
private readonly registryDir;
|
|
456
|
-
private readonly isPidAlive;
|
|
457
|
-
private cachedEndpoint;
|
|
458
|
-
constructor(opts?: DaemonClientOptions);
|
|
459
|
-
private resolveEndpoint;
|
|
460
|
-
private request;
|
|
461
|
-
/**
|
|
462
|
-
* Spawn a child session — `POST /sessions/agent`. `parentSessionId` is
|
|
463
|
-
* derived from `AGENTPROTO_SESSION_ID` (set by the daemon on every
|
|
464
|
-
* ACP-spawned adapter) when present, so session lineage is recorded
|
|
465
|
-
* without the caller having to thread it through.
|
|
466
|
-
*/
|
|
467
|
-
startAgent(input: StartAgentInput): Promise<Record<string, unknown>>;
|
|
468
|
-
/** Send a follow-up turn to a live session — `POST /sessions/:id/prompt`. */
|
|
469
|
-
promptAgent(sessionId: string, text: string, opts?: PromptAgentOptions): Promise<Record<string, unknown>>;
|
|
470
|
-
/** List sessions — `GET /sessions`. */
|
|
471
|
-
listSessions(opts?: ListSessionsOptions): Promise<{
|
|
472
|
-
sessions: Array<Record<string, unknown>>;
|
|
473
|
-
}>;
|
|
474
|
-
/**
|
|
475
|
-
* Read a session's transcript — `GET /sessions/:id/export`. Chosen over
|
|
476
|
-
* `/sessions/:id/conversation` (needs a provider-native store registered
|
|
477
|
-
* for the adapter; not every adapter has one) and `/sessions/:id/preview`
|
|
478
|
-
* (a raw ring-buffer snapshot, not a rendered transcript): `/export`
|
|
479
|
-
* works for ANY agent-cli session, falling back to the daemon's own
|
|
480
|
-
* `events.jsonl` capture when no provider-native reader is registered
|
|
481
|
-
* (`source: "auto"`, see `transcript-export.ts`) — the one built for
|
|
482
|
-
* programmatic reads of "what did this session say".
|
|
483
|
-
*/
|
|
484
|
-
readOutput(sessionId: string, opts?: ReadOutputOptions): Promise<Record<string, unknown>>;
|
|
485
|
-
/**
|
|
486
|
-
* Cursor-based poll of a session's structured event log —
|
|
487
|
-
* `GET /sessions/:id/events`. NOT the same event source as the MCP
|
|
488
|
-
* `session_events_poll` tool: that tool reads the daemon's in-memory,
|
|
489
|
-
* cross-session `EventRing` (turn-end/awaiting-input/exited/... lifecycle
|
|
490
|
-
* events, `packages/runtime/src/orchestration-tools.ts:528`), which has no
|
|
491
|
-
* plain-HTTP equivalent — it's only reachable over the MCP JSON-RPC
|
|
492
|
-
* transport, which this zero-dependency client doesn't speak. This route
|
|
493
|
-
* is the per-SESSION structured `events.jsonl` transcript instead
|
|
494
|
-
* (`packages/runtime/src/transcript-writer.ts`): cursor-based via
|
|
495
|
-
* `since`/`nextSeq` same as the MCP tool, and its records DO carry many of
|
|
496
|
-
* the same `kind`s (`turn-end`, `error`, `permission-resolved`, ...) — but
|
|
497
|
-
* it has no `exited` / `session:spawned` records (those are registry
|
|
498
|
-
* state changes, not transcript writes) and no cross-session fan-in
|
|
499
|
-
* (`sessionIds` filter). `types` is therefore filtered client-side here
|
|
500
|
-
* against each record's `kind`, not sent as a query param.
|
|
501
|
-
*
|
|
502
|
-
* WP-6 (`AgentprotoSignalProvider`, polling every 5s): this is a
|
|
503
|
-
* non-blocking snapshot read, so it's a direct fit for a poll loop. If
|
|
504
|
-
* WP-6 needs the actual cross-session lifecycle events (`exited`,
|
|
505
|
-
* `session:spawned`, multi-session fan-in), it either needs its own
|
|
506
|
-
* light MCP JSON-RPC client to call `session_events_poll` directly, or
|
|
507
|
-
* per-session `GET /sessions/:id/wait?since=&event=` (a blocking
|
|
508
|
-
* long-poll over the SAME EventRing `session_events_poll` reads, but
|
|
509
|
-
* scoped to one session and one event name at a time — no `types` array).
|
|
510
|
-
*/
|
|
511
|
-
pollEvents(sessionId: string, opts?: PollEventsOptions): Promise<PollEventsResult>;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
552
|
/**
|
|
515
553
|
* Daemon sub-agent-spawning tools — the Mastra-tool front for
|
|
516
554
|
* {@link DaemonClient}. Lets the agent spawn/prompt/read/list sibling
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DEFAULT_MODEL, DEFAULT_MODEL_CATALOG, DEFAULT_TOOL_IDS, DISABLED_BUILTIN_TOOL_IDS, DaemonClient, DaemonHttpError, DaemonNotFoundError, MastraAcpAgent, buildSqliteMemory, buildSqliteStore, createEventMapper, defaultAgentManifest, discoverDaemonEndpoint, makeAgentFactory, makeDaemonTools, makeWorkspaceTools, messageText, modelRefToString, promptContent, promptText, providerOf, resolveInCwd, resolveMastraModel, resolveMemoryDbPath, runAcpOverStdio, toolCallTitle, toolKindFor } from './chunk-
|
|
1
|
+
export { DEFAULT_MODEL, DEFAULT_MODEL_CATALOG, DEFAULT_TOOL_IDS, DISABLED_BUILTIN_TOOL_IDS, DaemonClient, DaemonHttpError, DaemonNotFoundError, MastraAcpAgent, buildSqliteMemory, buildSqliteStore, createEventMapper, defaultAgentManifest, discoverDaemonEndpoint, makeAgentFactory, makeDaemonTools, makeWorkspaceTools, messageText, modelRefToString, promptContent, promptText, providerOf, resolveInCwd, resolveMastraModel, resolveMemoryDbPath, runAcpOverStdio, toolCallTitle, toolKindFor } from './chunk-2FKFITFT.mjs';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
3
|
import { defineAgentCli, createAgentCliRuntime } from '@agentproto/driver-agent-cli';
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentproto/adapter-mastra-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "@agentproto/adapter-mastra-agent — first-party agentproto agent. An AIP-42 AGENT.md run as a live Mastra agent behind an AIP-44 ACP server, spawnable by the daemon like any other AGENT-CLI arm AND launchable standalone via `agentproto-mastra acp`. Our own loop, our own models — no external CLI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentproto",
|
|
@@ -53,20 +53,21 @@
|
|
|
53
53
|
"@mastra/core": "^1.61.0",
|
|
54
54
|
"@mastra/libsql": "~1.21.1",
|
|
55
55
|
"@mastra/memory": "^1.27.0",
|
|
56
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
56
57
|
"zod": "^4.5.4",
|
|
57
58
|
"@agentproto/agent": "0.2.2",
|
|
58
|
-
"@agentproto/driver-agent-cli": "2.4.
|
|
59
|
-
"@agentproto/mastra": "0.2.
|
|
60
|
-
"@agentproto/runtime": "2.
|
|
59
|
+
"@agentproto/driver-agent-cli": "2.4.1",
|
|
60
|
+
"@agentproto/mastra": "0.2.11",
|
|
61
|
+
"@agentproto/runtime": "2.12.0"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@types/node": "^25.6.2",
|
|
64
65
|
"tsup": "^8.5.1",
|
|
65
66
|
"typescript": "^5.9.3",
|
|
66
67
|
"vitest": "^3.2.4",
|
|
67
|
-
"@agentproto/app-kit": "0.
|
|
68
|
-
"@agentproto/apps": "0.
|
|
69
|
-
"@agentproto/tooling": "0.1.0
|
|
68
|
+
"@agentproto/app-kit": "1.0.0",
|
|
69
|
+
"@agentproto/apps": "0.9.1",
|
|
70
|
+
"@agentproto/tooling": "0.1.0"
|
|
70
71
|
},
|
|
71
72
|
"scripts": {
|
|
72
73
|
"dev": "tsup --watch",
|