@myagentroam/agent 0.9.115 → 0.9.117

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/index.d.ts CHANGED
@@ -1,17 +1,13 @@
1
1
  export { MarAgentError } from './error.js';
2
2
  export { SecretValue, marAgentReasoningEffortSchema, parseModelCatalog, resolveModelDefaultReasoningEffort, type MarAgentModelConfiguration, type MarAgentReasoningEffort, type ModelCatalog, type ModelCredential, type ModelCredentialAcquireReason, type ModelCredentialProvider, type ResponsesTransport } from './model/configuration.js';
3
3
  export { MAR_AGENT_HOST_API_VERSION, negotiateHost, type HostDescription, type MarAgentHostCapability } from './host/contracts.js';
4
- export { OpenAiResponsesAdapter } from './model/openai-responses.js';
5
- export { AnthropicMessagesAdapter } from './model/anthropic-messages.js';
6
- export type { ClientToolDefinition, ModelAdapter, ModelEvent, ModelMessage, ModelRequest, ModelStopReason, ModelTurnSession, ModelUsage } from './model/contracts.js';
7
- export { LocalWorkspaceTools, type ExecInput, type ExecResult } from './tools/local-workspace-tools.js';
4
+ export { testMarAgentModelTransport } from './model/transport-test.js';
5
+ export type { ClientToolDefinition } from './model/contracts.js';
8
6
  export type { ApplyPatchFileResult, ApplyPatchResult } from './tools/apply-patch.js';
9
7
  export { openMarAgentSessionCatalog, type MarAgentContextUsage, type MarAgentSessionDeleteResult, type MarAgentHistoryEntry, type MarAgentHistoryPage, type MarAgentSessionCatalog, type MarAgentSessionImage, type MarAgentSessionPage, type MarAgentSessionSummary } from './session/catalog.js';
10
8
  export { LocalAgentHost, selectExecutionShell, type LocalAgentExecutionMcpBinding, type LocalAgentMcpBinding, type LocalAgentExecutionExtensions } from './host/local-agent-host.js';
11
9
  export type { LocalProcessExecutor, LocalProcessSpawnRequest } from './host/local-process-executor.js';
12
10
  export type { WorkspacePathMount } from './tools/shared/path-resolver.js';
11
+ export type { SessionListInput, SessionSource } from './session/types.js';
13
12
  export { createMarAgent } from './sdk/agent.js';
14
- export { MAR_AGENT_PROMPT_VERSION, buildSystemPrompt } from './prompts/index.js';
15
- export { TodoStore, type TodoItem } from './tools/todo.js';
16
- export { SubagentScheduler, type SubagentOutputOptions, type SubagentMessageOptions, type SubagentRunOptions, type SubagentTaskInput, type SubagentTaskResult, type SubagentTaskSnapshot } from './subagent/scheduler.js';
17
13
  export type { AccessMode, CreateMarAgentOptions, CreateSessionInput, ExecutionHandle, ExecutionMode, ExecutionResult, HostSessionResourceSnapshot, HostSkill, HostExecutionExtensions, McpToolCatalogContext, MarAgent, MarAgentEvent, MarAgentHost, MarAgentImageMetadata, MarAgentSession, MarAgentToolArtifact, MarAgentToolImageArtifact, RolloutBudgetOptions, RunInput, RunInputImage, ToolCall, ToolExecutionContext, ToolExecutionResult } from './sdk/types.js';
package/dist/index.js CHANGED
@@ -1,12 +1,7 @@
1
1
  export { MarAgentError } from './error.js';
2
2
  export { SecretValue, marAgentReasoningEffortSchema, parseModelCatalog, resolveModelDefaultReasoningEffort } from './model/configuration.js';
3
3
  export { MAR_AGENT_HOST_API_VERSION, negotiateHost } from './host/contracts.js';
4
- export { OpenAiResponsesAdapter } from './model/openai-responses.js';
5
- export { AnthropicMessagesAdapter } from './model/anthropic-messages.js';
6
- export { LocalWorkspaceTools } from './tools/local-workspace-tools.js';
4
+ export { testMarAgentModelTransport } from './model/transport-test.js';
7
5
  export { openMarAgentSessionCatalog } from './session/catalog.js';
8
6
  export { LocalAgentHost, selectExecutionShell } from './host/local-agent-host.js';
9
7
  export { createMarAgent } from './sdk/agent.js';
10
- export { MAR_AGENT_PROMPT_VERSION, buildSystemPrompt } from './prompts/index.js';
11
- export { TodoStore } from './tools/todo.js';
12
- export { SubagentScheduler } from './subagent/scheduler.js';
@@ -0,0 +1,3 @@
1
+ import type { MarAgentModelConfiguration } from './configuration.js';
2
+ /** Probe a configured protocol without exposing its adapter or wire events. */
3
+ export declare function testMarAgentModelTransport(configuration: MarAgentModelConfiguration, signal: AbortSignal): Promise<boolean>;
@@ -0,0 +1,23 @@
1
+ import { AnthropicMessagesAdapter } from './anthropic-messages.js';
2
+ import { OpenAiResponsesAdapter } from './openai-responses.js';
3
+ /** Probe a configured protocol without exposing its adapter or wire events. */
4
+ export async function testMarAgentModelTransport(configuration, signal) {
5
+ const adapter = configuration.protocol === 'OPENAI_RESPONSES'
6
+ ? new OpenAiResponsesAdapter(configuration)
7
+ : new AnthropicMessagesAdapter(configuration);
8
+ try {
9
+ let completed = false;
10
+ for await (const event of adapter.start({
11
+ system: 'You are performing a model transport connectivity test.',
12
+ messages: [{ role: 'user', content: 'Reply with OK.' }],
13
+ tools: [],
14
+ allowTools: false
15
+ }, signal))
16
+ if (event.type === 'completed')
17
+ completed = true;
18
+ return completed;
19
+ }
20
+ finally {
21
+ await adapter.close?.();
22
+ }
23
+ }
@@ -1,2 +1,11 @@
1
+ import { type MarAgentModelConfiguration } from '../model/configuration.js';
2
+ import type { ModelAdapter } from '../model/contracts.js';
1
3
  import type { CreateMarAgentOptions, MarAgent } from './types.js';
4
+ interface InternalCreateMarAgentOptions extends CreateMarAgentOptions {
5
+ readonly adapterFactory?: (configuration: MarAgentModelConfiguration) => ModelAdapter;
6
+ }
7
+ /** Validate models before Host negotiation and expose only built-in protocol adapters. */
2
8
  export declare function createMarAgent(options: CreateMarAgentOptions): Promise<MarAgent>;
9
+ /** Package-internal seam for deterministic adapter tests; not a package export. */
10
+ export declare function createMarAgentWithAdapter(options: InternalCreateMarAgentOptions): Promise<MarAgent>;
11
+ export {};
package/dist/sdk/agent.js CHANGED
@@ -33,6 +33,7 @@ import { executeRegisteredTool } from '../tools/runtime.js';
33
33
  import { scheduleToolCallBatch } from '../tools/scheduler.js';
34
34
  import { withCodeModeResultTypes } from '../tools/code-mode.js';
35
35
  import { SubagentSessionController } from '../subagent/session-controller.js';
36
+ /** Retry only classified recoverable failures within the attempt budget; never retry cancellation. */
36
37
  async function recoverModelStream(error, retryState, signal) {
37
38
  if (signal.aborted ||
38
39
  !(isRetryableModelRequestError(error) ||
@@ -45,7 +46,14 @@ async function recoverModelStream(error, retryState, signal) {
45
46
  await waitForModelRetry(typeof error.details?.retryAfter === 'string' ? error.details.retryAfter : null, retryState.attempts - 1, signal, delayMs);
46
47
  return true;
47
48
  }
49
+ /** Validate models before Host negotiation and expose only built-in protocol adapters. */
48
50
  export async function createMarAgent(options) {
51
+ if (Object.hasOwn(options, 'adapterFactory'))
52
+ throw new MarAgentError('MAR_AGENT_MODEL_CONFIG_INVALID', 'Custom model adapters are not supported.');
53
+ return createMarAgentWithAdapter(options);
54
+ }
55
+ /** Package-internal seam for deterministic adapter tests; not a package export. */
56
+ export async function createMarAgentWithAdapter(options) {
49
57
  const rolloutBudgetOptions = resolveRolloutBudgetOptions(options.rolloutBudget);
50
58
  const resolvedModels = resolveAgentModels(options.models);
51
59
  let { models, defaultModelId } = resolvedModels;
@@ -155,6 +163,7 @@ export async function createMarAgent(options) {
155
163
  let manualCompactionStarted = false;
156
164
  let emitTail = Promise.resolve();
157
165
  let exhaustedModelAttempt;
166
+ // Serialize durable events before either the local stream or Host observes them.
158
167
  const emit = (event) => {
159
168
  const full = {
160
169
  ...event,
@@ -344,26 +353,21 @@ export async function createMarAgent(options) {
344
353
  const inputImageMetadata = input.images?.length
345
354
  ? await store.persistInputImages(sessionId, input.images)
346
355
  : [];
347
- try {
348
- await store.append(sessionId, {
349
- type: 'turn.user',
350
- payload: {
351
- prompt: input.prompt,
352
- ...(internal.delivery ? { messageId: internal.delivery.messageId } : {}),
353
- ...(internal.inputSource === undefined
354
- ? {}
355
- : { inputSource: internal.inputSource }),
356
- ...(input.clientMessageId ? { clientMessageId: input.clientMessageId } : {}),
357
- ...(inputImageMetadata.length ? { images: inputImageMetadata } : {})
358
- },
359
- executionId,
360
- turnId
361
- });
362
- }
363
- catch (error) {
364
- await store.removeInputImages(sessionId, inputImageMetadata).catch(() => undefined);
365
- throw error;
366
- }
356
+ // A failed sync can still leave a complete record; lease recovery decides image ownership.
357
+ await store.append(sessionId, {
358
+ type: 'turn.user',
359
+ payload: {
360
+ prompt: input.prompt,
361
+ ...(internal.delivery ? { messageId: internal.delivery.messageId } : {}),
362
+ ...(internal.inputSource === undefined
363
+ ? {}
364
+ : { inputSource: internal.inputSource }),
365
+ ...(input.clientMessageId ? { clientMessageId: input.clientMessageId } : {}),
366
+ ...(inputImageMetadata.length ? { images: inputImageMetadata } : {})
367
+ },
368
+ executionId,
369
+ turnId
370
+ });
367
371
  messages.push({ role: 'user', content: input.prompt });
368
372
  currentExecutionUserIndex = messages.length - 1;
369
373
  internal.delivery?.applied();
@@ -1157,6 +1161,7 @@ export async function createMarAgent(options) {
1157
1161
  if (mode !== 'compact' &&
1158
1162
  sessionSource.type !== 'subagent' &&
1159
1163
  latestUsage !== undefined) {
1164
+ // Only a committed GC checkpoint may replace active context and invalidate continuation.
1160
1165
  const committed = await contextGc.run({
1161
1166
  store,
1162
1167
  sessionId,
@@ -2079,6 +2084,7 @@ function stableJson(value) {
2079
2084
  .join(',')}}`;
2080
2085
  return JSON.stringify(value) ?? 'undefined';
2081
2086
  }
2087
+ /** Project only known, validated tool result shapes into public structured events. */
2082
2088
  function structuredToolEventData(toolName, value) {
2083
2089
  if (!isRecord(value))
2084
2090
  return undefined;
@@ -2172,6 +2178,7 @@ function structuredToolArtifacts(value) {
2172
2178
  throw new MarAgentError('MAR_AGENT_TOOL_OUTPUT_INVALID', 'Tool image artifact is invalid.');
2173
2179
  return value.map((artifact) => ({ ...artifact }));
2174
2180
  }
2181
+ /** Keep streaming deltas live-only; exec output has one durable copy in model context records. */
2175
2182
  function eventForPersistence(event) {
2176
2183
  if (event.type === 'message.delta' || event.type === 'context.compacting')
2177
2184
  return undefined;
@@ -1,8 +1,7 @@
1
1
  import type { HostDescription } from '../host/contracts.js';
2
2
  import type { MarAgentModelConfiguration, MarAgentReasoningEffort } from '../model/configuration.js';
3
- import type { ModelAdapter } from '../model/contracts.js';
4
3
  import type { MarAgentSessionPage, MarAgentSessionSummary } from '../session/catalog.js';
5
- import type { SessionListInput, SessionSource } from '../session/jsonl-store.js';
4
+ import type { SessionListInput, SessionSource } from '../session/types.js';
6
5
  /** @deprecated MAR Agent always executes tools directly through the Host. */
7
6
  export type AccessMode = 'full-access';
8
7
  export type ExecutionMode = 'run' | 'plan' | 'compact';
@@ -68,6 +67,7 @@ export interface HostSessionResourceSnapshot {
68
67
  cwd: string;
69
68
  }[];
70
69
  }
70
+ /** The Host owns workspace/tool effects; the SDK owns JSONL storage beneath its supplied HOME. */
71
71
  export interface MarAgentHost {
72
72
  describe(): Promise<HostDescription>;
73
73
  executeTool(call: ToolCall, context: ToolExecutionContext): Promise<ToolExecutionResult>;
@@ -229,11 +229,14 @@ export interface ExecutionResult {
229
229
  errorCode?: string;
230
230
  errorMessage?: string;
231
231
  }
232
+ /** A live execution exposes streamed events separately from its terminal result. */
232
233
  export interface ExecutionHandle extends AsyncIterable<MarAgentEvent> {
233
234
  readonly executionId: string;
234
235
  result(): Promise<ExecutionResult>;
236
+ /** Signals abort; await result() to observe the terminal status and cleanup. */
235
237
  cancel(): void;
236
238
  }
239
+ /** A persisted Session permits one active main execution at a time. */
237
240
  export interface MarAgentSession {
238
241
  readonly id: string;
239
242
  run(input: RunInput): ExecutionHandle;
@@ -246,11 +249,13 @@ export interface MarAgent {
246
249
  openSession(sessionId: string): Promise<MarAgentSession>;
247
250
  listSessions(input?: SessionListInput): Promise<MarAgentSessionPage>;
248
251
  clearSession(sessionId: string): Promise<void>;
252
+ /** Rebinds future main executions only; running subagents keep their captured model providers. */
249
253
  reconfigureModels(input: {
250
254
  readonly models: readonly MarAgentModelConfiguration[];
251
255
  readonly defaultModelId?: string;
252
256
  }): Promise<void>;
253
257
  deleteSession(sessionId: string): Promise<void>;
258
+ /** Cancels active executions, then closes SDK-owned providers, the Host and the Session store. */
254
259
  dispose(): Promise<void>;
255
260
  }
256
261
  export interface RolloutBudgetOptions {
@@ -271,6 +276,5 @@ export interface CreateMarAgentOptions {
271
276
  readonly physicalPath: string;
272
277
  };
273
278
  rolloutBudget?: false | RolloutBudgetOptions;
274
- adapterFactory?: (configuration: MarAgentModelConfiguration) => ModelAdapter;
275
279
  }
276
280
  export type { MarAgentSessionSummary, SessionListInput, SessionSource };
@@ -1,4 +1,4 @@
1
- import { type SessionListInput, type SessionSource } from './jsonl-store.js';
1
+ import type { SessionListInput, SessionSource } from './types.js';
2
2
  import type { MarAgentEvent, MarAgentImageMetadata } from '../sdk/types.js';
3
3
  export interface MarAgentSessionSummary {
4
4
  id: string;
@@ -1,3 +1,4 @@
1
+ import { MarAgentError } from '../error.js';
1
2
  import { JsonlSessionStore } from './jsonl-store.js';
2
3
  const MAX_INPUT_IMAGE_BYTES = 5 * 1024 * 1024;
3
4
  const INPUT_IMAGE_MIME_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);
@@ -90,8 +91,8 @@ function parseCursor(cursor) {
90
91
  if (cursor === undefined)
91
92
  return undefined;
92
93
  const value = Number(cursor);
93
- if (!Number.isSafeInteger(value) || value < 1)
94
- return undefined;
94
+ if (!/^[1-9]\d*$/u.test(cursor) || !Number.isSafeInteger(value))
95
+ throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Session history cursor is invalid.');
95
96
  return value;
96
97
  }
97
98
  function isRecord(value) {
@@ -2,6 +2,8 @@ import type { ModelUsage } from '../model/contracts.js';
2
2
  import type { EnvironmentContextState } from '../prompts/core.js';
3
3
  import { type TodoSnapshot } from '../tools/todo.js';
4
4
  import { type ContextGcCheckpointDraft } from './context-gc-checkpoint.js';
5
+ import type { SessionListInput, SessionSource } from './types.js';
6
+ export type { SessionListInput, SessionSource } from './types.js';
5
7
  export interface SessionRecord {
6
8
  schemaVersion: 1;
7
9
  recordId: string;
@@ -18,23 +20,6 @@ export interface SessionExecutionState {
18
20
  todo: TodoSnapshot;
19
21
  contextRecords: SessionRecord[];
20
22
  }
21
- export type SessionSource = {
22
- readonly type: 'user';
23
- } | {
24
- readonly type: 'subagent';
25
- readonly parentSessionId: string;
26
- readonly rootSessionId: string;
27
- readonly parentExecutionId: string;
28
- readonly role: 'general-purpose' | 'explore';
29
- readonly description: string;
30
- };
31
- export interface SessionListInput {
32
- readonly limit?: number;
33
- readonly cursor?: string;
34
- readonly source?: SessionSource['type'];
35
- readonly parentSessionId?: string;
36
- readonly rootSessionId?: string;
37
- }
38
23
  export interface CompactHistoryMessage {
39
24
  role: 'user';
40
25
  content: string;
@@ -68,6 +53,7 @@ interface SessionMeta {
68
53
  source?: SessionSource;
69
54
  nextSequence: number;
70
55
  automaticTitlePending?: boolean;
56
+ storageTransactionId?: string;
71
57
  resume?: {
72
58
  version: 1;
73
59
  compactSequence?: number;
@@ -84,10 +70,12 @@ interface SessionMeta {
84
70
  bytes: number;
85
71
  }>;
86
72
  }
73
+ /** SDK-owned JSONL history with per-HOME in-process sharing and cross-process file locks. */
87
74
  export declare class JsonlSessionStore {
88
75
  #private;
89
76
  private constructor();
90
77
  static open(home: string): Promise<JsonlSessionStore>;
78
+ /** Append the durable creation record before making this Session visible in the index. */
91
79
  createSession(input: {
92
80
  title?: string;
93
81
  workspace: string;
@@ -96,13 +84,13 @@ export declare class JsonlSessionStore {
96
84
  sessionDirectory(sessionId: string): string;
97
85
  readContextualWorldState(sessionId: string): Promise<unknown | undefined>;
98
86
  writeContextualWorldState(sessionId: string, state: unknown): Promise<void>;
87
+ /** Mark each image pending before publication; turn.user or lease recovery resolves ownership. */
99
88
  persistInputImages(sessionId: string, images: readonly SessionInputImage[]): Promise<SessionInputImageMetadata[]>;
100
89
  readInputImages(sessionId: string, value: unknown): Promise<RestoredSessionInputImage[]>;
101
90
  readInputImage(sessionId: string, input: {
102
91
  readonly sequence: number;
103
92
  readonly imageIndex: number;
104
93
  }): Promise<SessionInputImageData | undefined>;
105
- removeInputImages(sessionId: string, images: readonly Pick<SessionInputImageMetadata, 'fileName'>[]): Promise<void>;
106
94
  forkSession(sourceSessionId: string, input: {
107
95
  readonly boundaryTurnId: string | null;
108
96
  readonly title: string;
@@ -114,6 +102,7 @@ export declare class JsonlSessionStore {
114
102
  lastActivityAt: string;
115
103
  source: SessionSource | undefined;
116
104
  }>;
105
+ /** Replace history under a journal; the indexed transaction ID decides the commit side. */
117
106
  rollbackSession(sessionId: string, input: {
118
107
  readonly boundaryTurnId: string | null;
119
108
  }): Promise<{
@@ -128,6 +117,7 @@ export declare class JsonlSessionStore {
128
117
  executionId?: string;
129
118
  turnId?: string;
130
119
  }): Promise<void>;
120
+ /** Reset history with the same recovery journal while preserving the Session identity. */
131
121
  clearSession(sessionId: string): Promise<{
132
122
  id: string;
133
123
  title: string;
@@ -155,6 +145,7 @@ export declare class JsonlSessionStore {
155
145
  readExecutionState(sessionId: string): Promise<SessionExecutionState>;
156
146
  readContext(sessionId: string): Promise<SessionRecord[]>;
157
147
  contextGcProjectionHash(sessionId: string, boundarySequence: number): Promise<string>;
148
+ /** Recheck a planned GC checkpoint against authoritative records before appending it. */
158
149
  commitContextGc(sessionId: string, draft: ContextGcCheckpointDraft): Promise<SessionRecord>;
159
150
  readPage(sessionId: string, input?: {
160
151
  limit?: number;
@@ -174,6 +165,7 @@ export declare class JsonlSessionStore {
174
165
  executionId?: string;
175
166
  turnId?: string;
176
167
  }): Promise<SessionRecord>;
168
+ /** Recover files under the sole writer lock; flush dirty index state before releasing it. */
177
169
  acquireSessionLease(sessionId: string): Promise<() => Promise<void>>;
178
170
  list(input?: SessionListInput): Promise<{
179
171
  nextCursor?: string;
@@ -209,4 +201,3 @@ export declare class JsonlSessionStore {
209
201
  }
210
202
  export declare function compactSummaryFromCheckpoint(record: SessionRecord | undefined): string | undefined;
211
203
  export declare function replacementHistoryFromCheckpoint(record: SessionRecord): CompactHistoryMessage[] | undefined;
212
- export {};