@vapi-network/mcp 0.7.0 → 0.9.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.
@@ -1,4 +1,4 @@
1
- import { type AgentProfile, type CeilingSweepHook, type ChatRequest, type ChatResult, type SpendCaps, type VapiConfig, type VapiPaymentAccount, type WalletName } from "@vapi-network/core";
1
+ import { type AgentProfile, type CeilingSweepHook, type ChatRequest, type ChatResult, type RunBudget, type SpendCaps, type VapiConfig, type VapiPaymentAccount, type WalletName } from "@vapi-network/core";
2
2
  import type { AgentEvent, RunAgentDeps } from "./run.js";
3
3
  export declare function createAgentRunDeps(input: {
4
4
  profile: AgentProfile;
@@ -7,6 +7,7 @@ export declare function createAgentRunDeps(input: {
7
7
  account: VapiPaymentAccount;
8
8
  wallet: WalletName;
9
9
  spendCaps: SpendCaps;
10
+ currentSpendCaps?: () => Promise<SpendCaps>;
10
11
  chat: (req: ChatRequest) => Promise<ChatResult>;
11
12
  approve: RunAgentDeps["approve"];
12
13
  onEvent?: (event: AgentEvent) => void;
@@ -15,4 +16,13 @@ export declare function createAgentRunDeps(input: {
15
16
  ledgerPath?: string;
16
17
  receiptsPath?: string;
17
18
  ceilingSweep?: CeilingSweepHook | false;
19
+ budget?: RunBudget;
20
+ now?: () => Date;
21
+ allowanceExpiresAt?: Date;
22
+ runId?: string;
23
+ runMeta?: {
24
+ swarm?: string;
25
+ member?: string;
26
+ parentRunId?: string;
27
+ };
18
28
  }): RunAgentDeps;
@@ -1,3 +1,4 @@
1
+ export { decideFunding, decideRelease, type FundingDecision, type ReleaseDecision, } from "@vapi-network/core";
1
2
  export declare const UNTRUSTED_NOTICE: string;
2
3
  /** Wraps tool output so the model can tell data from instructions. */
3
4
  export declare function wrapUntrusted(tool: string, value: unknown): string;
@@ -1,5 +1,8 @@
1
- import { type AgentProfile, type ChatRequest, type ChatResult, type VapiConfig } from "@vapi-network/core";
2
- import { type ActionRunState } from "../actions/context.js";
1
+ import { type AgentProfile, type ChatRequest, type ChatResult, type RunBudget, type VapiConfig } from "@vapi-network/core";
2
+ import { type CallReadOutput } from "../actions/call-read.js";
3
+ import { type ActionRunState, type SwarmRunScope } from "../actions/context.js";
4
+ import { actions } from "../actions/register.js";
5
+ import { type SwarmAllocateResult, type SwarmDelegateResult } from "../actions/swarm-agent.js";
3
6
  import type { InspectToolResult } from "../tools/inspect.js";
4
7
  export type AgentEvent = {
5
8
  type: "step";
@@ -19,9 +22,23 @@ export type AgentEvent = {
19
22
  reason: string;
20
23
  } | {
21
24
  type: "stopped";
22
- reason: "finished" | "max_steps" | "router_budget" | "paused" | "error";
25
+ reason: "finished" | "max_steps" | "router_budget" | "run_budget" | "paused" | "error";
23
26
  detail?: string;
24
27
  };
28
+ export type SwarmRunContext = SwarmRunScope & {
29
+ allocate(input: {
30
+ amountUsd: string;
31
+ reason?: string;
32
+ requestId: string;
33
+ }): Promise<SwarmAllocateResult>;
34
+ delegate(input: {
35
+ member: string;
36
+ task: string;
37
+ budgetUsd: string;
38
+ parentRunId: string;
39
+ requestId: string;
40
+ }): Promise<SwarmDelegateResult>;
41
+ };
25
42
  export type RunAgentDeps = {
26
43
  profile: AgentProfile;
27
44
  config: VapiConfig;
@@ -39,6 +56,9 @@ export type RunAgentDeps = {
39
56
  description?: string;
40
57
  }>>;
41
58
  inspect: (ref: string) => Promise<InspectToolResult>;
59
+ read?: (input: {
60
+ url: string;
61
+ }) => Promise<CallReadOutput>;
42
62
  pay: (input: {
43
63
  ref: string;
44
64
  body?: unknown;
@@ -61,18 +81,37 @@ export type RunAgentDeps = {
61
81
  onEvent?: (event: AgentEvent) => void;
62
82
  tty?: boolean;
63
83
  now?: () => Date;
84
+ budget?: RunBudget;
85
+ runId?: string;
86
+ runMeta?: {
87
+ swarm?: string;
88
+ member?: string;
89
+ parentRunId?: string;
90
+ };
91
+ swarm?: SwarmRunContext;
64
92
  forRun?: (run: ActionRunState) => RunAgentDeps;
65
93
  };
66
94
  export type RunAgentResult = {
95
+ runId: string;
67
96
  answer: string | null;
68
97
  stoppedBecause: AgentEvent & {
69
98
  type: "stopped";
70
99
  };
71
100
  paidUsd: number;
72
101
  steps: number;
102
+ budget?: {
103
+ limitUsd: number;
104
+ spentUsd: number;
105
+ };
73
106
  };
107
+ type RegisteredAction = (typeof actions)[number];
108
+ export declare function loopActionsFor(profile: {
109
+ tools: readonly string[];
110
+ grants?: readonly string[];
111
+ }): RegisteredAction[];
74
112
  export declare function loopToolsForProfile(profile: {
75
113
  tools: readonly string[];
114
+ grants?: readonly string[];
76
115
  }): ({
77
116
  readonly type: "function";
78
117
  readonly function: {
@@ -106,3 +145,4 @@ export declare function loopToolsForProfile(profile: {
106
145
  };
107
146
  })[];
108
147
  export declare function runAgent(task: string, deps: RunAgentDeps): Promise<RunAgentResult>;
148
+ export {};
@@ -0,0 +1,154 @@
1
+ import { type AgentProfile, type WalletStore } from "@vapi-network/core";
2
+ import { z } from "zod";
3
+ import { type SwarmRunResult } from "./swarm-run.js";
4
+ import type { RunAgentResult } from "./run.js";
5
+ export type RuntimeKind = "local" | "railway";
6
+ export type RuntimeMember = {
7
+ swarm?: string;
8
+ account: string;
9
+ profile: string;
10
+ role?: string;
11
+ };
12
+ export type RuntimeRun = {
13
+ runId: string;
14
+ task: string;
15
+ mode: "agent" | "lead";
16
+ budgetUsd?: string;
17
+ drawUsd?: string;
18
+ parentRunId?: string;
19
+ };
20
+ export type RuntimeHandle = {
21
+ runId: string;
22
+ kind: RuntimeKind;
23
+ member: RuntimeMember;
24
+ startedAt: string;
25
+ /** Adapter-specific process or sandbox reference. It must never contain a secret. */
26
+ ref: string;
27
+ };
28
+ export type RuntimeStatus = {
29
+ state: "running" | "finished" | "failed" | "stopped" | "unknown";
30
+ /** Adapters may return unknown parsed result-file content. */
31
+ result?: RunAgentResult | SwarmRunResult | unknown;
32
+ exitCode?: number;
33
+ detail?: string;
34
+ };
35
+ export interface Runtime {
36
+ kind: RuntimeKind;
37
+ /** An adapter-owned unresolved start that must block another member worker. */
38
+ busy?(member: RuntimeMember): Promise<{
39
+ runId: string;
40
+ detail: string;
41
+ } | undefined>;
42
+ start(member: RuntimeMember, run: RuntimeRun,
43
+ /** Persist this reference before the adapter continues a multi-step launch. */
44
+ persistLaunch?: (handle: RuntimeHandle) => Promise<void>): Promise<RuntimeHandle>;
45
+ /** Recover an adapter-owned reference after the launcher crashed before saving it. */
46
+ recover?(record: RunRecord): Promise<RuntimeHandle | undefined>;
47
+ /** Retire this exact adapter-owned start after the owner confirms its worker is gone. */
48
+ retireUnreconciledStart?(record: RunRecord): Promise<void>;
49
+ stop(handle: RuntimeHandle): Promise<void>;
50
+ status(handle: RuntimeHandle): Promise<RuntimeStatus>;
51
+ }
52
+ export type RunState = RuntimeStatus["state"] | "starting";
53
+ export declare class RuntimeError extends Error {
54
+ readonly code: "member_busy" | "runtime_unavailable" | "run_not_found" | "invalid_run_id";
55
+ readonly name = "RuntimeError";
56
+ constructor(code: "member_busy" | "runtime_unavailable" | "run_not_found" | "invalid_run_id", message: string);
57
+ }
58
+ export type RunRecord = {
59
+ v: 1;
60
+ runId: string;
61
+ kind: RuntimeKind;
62
+ member: RuntimeMember;
63
+ run: RuntimeRun;
64
+ handle: RuntimeHandle;
65
+ startedAt: string;
66
+ endedAt?: string;
67
+ state: RunState;
68
+ exitCode?: number;
69
+ resultPath?: string;
70
+ detail?: string;
71
+ };
72
+ /** A normal adapter launch should have produced a durable reference well before this bound. */
73
+ export declare const STARTING_RECONCILIATION_TIMEOUT_MS: number;
74
+ export declare const runRecordSchema: z.ZodType<RunRecord>;
75
+ export declare function runsDirectory(home: string): string;
76
+ export declare function runRecordPath(home: string, runId: string): string;
77
+ export declare function runLogPath(home: string, runId: string): string;
78
+ export declare function runResultPath(home: string, runId: string): string;
79
+ export declare function writeRunRecord(home: string, record: RunRecord): Promise<void>;
80
+ export declare function readRunRecord(home: string, runId: string): Promise<RunRecord | undefined>;
81
+ export declare function listRunRecords(home: string, filter?: {
82
+ swarm?: string;
83
+ account?: string;
84
+ }): Promise<RunRecord[]>;
85
+ export declare function refreshRunRecord(home: string, record: RunRecord, runtime?: Runtime, now?: () => Date): Promise<RunRecord>;
86
+ export declare function startDetachedRun(args: {
87
+ home: string;
88
+ runtime: Runtime;
89
+ member: RuntimeMember;
90
+ run: RuntimeRun;
91
+ now?: () => Date;
92
+ /** Environment whose secret-named values are scrubbed from the stored task. */
93
+ env?: NodeJS.ProcessEnv;
94
+ }): Promise<RunRecord>;
95
+ /**
96
+ * Scrubs credentials from text that a detached run stores (registry task, result file, log).
97
+ * It removes the values of secret-named environment variables and structurally recognisable
98
+ * secrets (private keys, vAPI API keys, bearer tokens, recovery phrases), and nothing else, so
99
+ * ordinary words and result fields stay intact.
100
+ */
101
+ export declare function redactRunText(value: string, env?: NodeJS.ProcessEnv): string;
102
+ /** Applies {@link redactRunText} to every string value; object keys and other values are kept. */
103
+ export declare function redactRunValue<T>(value: T, env?: NodeJS.ProcessEnv): T;
104
+ export declare function stopRun(args: {
105
+ home: string;
106
+ runtime: Runtime;
107
+ record: RunRecord;
108
+ now?: () => Date;
109
+ confirmWorkerStopped?: boolean;
110
+ }): Promise<RunRecord>;
111
+ export type DetachedRunSummary = {
112
+ member: string;
113
+ role?: string;
114
+ swarm?: string;
115
+ runId: string;
116
+ kind: RuntimeKind;
117
+ mode: "agent" | "lead";
118
+ state: RunState;
119
+ startedAt: string;
120
+ endedAt?: string;
121
+ exitCode?: number;
122
+ parentRunId?: string;
123
+ detail?: string;
124
+ };
125
+ export type DetachedSwarmRunResult = {
126
+ detached: true;
127
+ runId: string;
128
+ mode: "lead" | "each";
129
+ kind: RuntimeKind;
130
+ runs: DetachedRunSummary[];
131
+ skipped: Array<{
132
+ member: string;
133
+ role: string;
134
+ reason: string;
135
+ }>;
136
+ };
137
+ export declare function summarizeRunRecord(record: RunRecord): DetachedRunSummary;
138
+ export declare function startDetachedSwarmRun(input: {
139
+ name: string;
140
+ task: string;
141
+ mode: "lead" | "each";
142
+ lead?: string;
143
+ budgetUsd?: string;
144
+ drawUsd?: string;
145
+ }, deps: {
146
+ home: string;
147
+ store: WalletStore;
148
+ runtime: Runtime;
149
+ readProfile?: (account: string) => Promise<AgentProfile | undefined>;
150
+ newRunId?: () => string;
151
+ now?: () => Date;
152
+ ledgerPath?: string;
153
+ env?: NodeJS.ProcessEnv;
154
+ }): Promise<DetachedSwarmRunResult>;
@@ -0,0 +1,94 @@
1
+ import { type AgentProfile, type RunBudget, type SwarmCapitalDeps, type SwarmFile, type SwarmStatusResult, type WalletStore } from "@vapi-network/core";
2
+ import { runAgent, type RunAgentDeps } from "./run.js";
3
+ export type SwarmRunMode = "lead" | "each";
4
+ export type RunSwarmOptions = {
5
+ name: string;
6
+ task: string;
7
+ mode: SwarmRunMode;
8
+ lead?: string;
9
+ budgetUsd?: string;
10
+ drawUsd?: string;
11
+ concurrency?: number;
12
+ runId?: string;
13
+ };
14
+ export type SwarmRunInput = Omit<RunSwarmOptions, "mode" | "concurrency" | "runId"> & {
15
+ mode?: SwarmRunMode;
16
+ };
17
+ export type SwarmMemberTarget = {
18
+ account: string;
19
+ role: string;
20
+ profile: AgentProfile;
21
+ };
22
+ export type MemberRunOptions = {
23
+ runId: string;
24
+ budget: RunBudget;
25
+ runMeta: {
26
+ swarm: string;
27
+ member: string;
28
+ parentRunId?: string;
29
+ };
30
+ profile: AgentProfile;
31
+ approvals: "tty" | "decline";
32
+ };
33
+ export type RunSwarmDeps = {
34
+ home: string;
35
+ store: WalletStore;
36
+ capital: SwarmCapitalDeps;
37
+ depsForMember(member: SwarmMemberTarget, runOpts: MemberRunOptions): Promise<RunAgentDeps>;
38
+ status(name: string): Promise<SwarmStatusResult>;
39
+ readProfile?: (account: string) => Promise<AgentProfile | undefined>;
40
+ runAgent?: typeof runAgent;
41
+ newRunId?: () => string;
42
+ ledgerPath?: string;
43
+ now?: () => Date;
44
+ };
45
+ export type SwarmRunMemberResult = {
46
+ member: string;
47
+ role: string;
48
+ runId: string | null;
49
+ parentRunId?: string;
50
+ answer: string | null;
51
+ stoppedBecause: {
52
+ reason: string;
53
+ detail?: string;
54
+ } | null;
55
+ spentUsd: number | null;
56
+ budgetUsd: number;
57
+ status: "finished" | "stopped" | "error" | "skipped";
58
+ reason?: string;
59
+ };
60
+ export type SwarmRunResult = {
61
+ runId: string;
62
+ mode: SwarmRunMode;
63
+ members: SwarmRunMemberResult[];
64
+ drawUsedUsd: number;
65
+ drawLimitUsd: number;
66
+ net: Array<{
67
+ member: string;
68
+ balanceUsd: string;
69
+ allocatedInUsd: string;
70
+ sweptOutUsd: string;
71
+ netUsd: string;
72
+ }>;
73
+ netError?: string;
74
+ };
75
+ export declare class SwarmRunError extends Error {
76
+ readonly code: "no_lead" | "invalid_lead" | "invalid_amount" | "no_eligible_members";
77
+ readonly name = "SwarmRunError";
78
+ constructor(code: "no_lead" | "invalid_lead" | "invalid_amount" | "no_eligible_members", message: string);
79
+ }
80
+ export type MemberAssessment = {
81
+ account: string;
82
+ role: string;
83
+ eligible: true;
84
+ target: SwarmMemberTarget;
85
+ } | {
86
+ account: string;
87
+ role: string;
88
+ eligible: false;
89
+ reason: "not_linked" | "no_profile" | "paused";
90
+ };
91
+ export declare function runSwarm(opts: RunSwarmOptions, deps: RunSwarmDeps): Promise<SwarmRunResult>;
92
+ export declare function assessSwarmMembers(swarm: SwarmFile, deps: Pick<RunSwarmDeps, "home" | "store" | "readProfile">): Promise<MemberAssessment[]>;
93
+ export declare function selectLead(opts: Pick<RunSwarmOptions, "name" | "lead">, assessments: readonly MemberAssessment[]): SwarmMemberTarget;
94
+ export declare function memberBudgetAtomic(account: string, configured: bigint | undefined, deps: Pick<RunSwarmDeps, "home" | "store" | "ledgerPath" | "now">): Promise<bigint>;
package/dist/index.d.ts CHANGED
@@ -4,11 +4,17 @@ export { resolveServiceEndpoint, resolveServiceListing, searchMarketplace, type
4
4
  export { getWallet, type WalletAddresses, type WalletBalance } from "./tools/wallet.js";
5
5
  export { WalletSession, type SessionWallet, type SessionWalletInfo, type WalletSessionOptions, } from "./wallet-session.js";
6
6
  export { buildSIWxProof, parseSIWxResponse } from "./siwx.js";
7
- export { UNTRUSTED_NOTICE, decidePayment, wrapUntrusted, type PayDecision, } from "./agent/guards.js";
7
+ export { UNTRUSTED_NOTICE, decideFunding, decidePayment, decideRelease, wrapUntrusted, type FundingDecision, type PayDecision, type ReleaseDecision, } from "./agent/guards.js";
8
8
  export { createAgentRunDeps } from "./agent/deps.js";
9
- export { loopToolsForProfile, runAgent, type AgentEvent, type RunAgentDeps, type RunAgentResult, } from "./agent/run.js";
9
+ export { assessSwarmMembers, memberBudgetAtomic, runSwarm, selectLead, SwarmRunError, type MemberAssessment, type MemberRunOptions, type RunSwarmDeps, type RunSwarmOptions, type SwarmMemberTarget, type SwarmRunInput, type SwarmRunMemberResult, type SwarmRunMode, type SwarmRunResult, } from "./agent/swarm-run.js";
10
+ export { listRunRecords, readRunRecord, redactRunText, redactRunValue, refreshRunRecord, runLogPath, runRecordPath, runRecordSchema, runResultPath, runsDirectory, STARTING_RECONCILIATION_TIMEOUT_MS, RuntimeError, startDetachedRun, startDetachedSwarmRun, stopRun, summarizeRunRecord, writeRunRecord, type DetachedRunSummary, type DetachedSwarmRunResult, type RunRecord, type RunState, type Runtime, type RuntimeHandle, type RuntimeKind, type RuntimeMember, type RuntimeRun, type RuntimeStatus, } from "./agent/runtime.js";
11
+ export { loopActionsFor, loopToolsForProfile, runAgent, type AgentEvent, type RunAgentDeps, type RunAgentResult, type SwarmRunContext, } from "./agent/run.js";
12
+ export { accountsSend, accountsSendInputSchema, accountsSendOutputSchema, type AccountsSendInput, } from "./actions/accounts.js";
10
13
  export { callInspect, callInspectInputSchema, callPay, callPayInputSchema, callSearch, callSearchInputSchema, callToolResultSchema, createCallPort, inspectToolResultSchema, MAX_CACHED_MARKETPLACE_REFS, walletArgument, type CreateCallPortOptions, type PaymentResolution, } from "./actions/call.js";
11
- export { createRunState, inspectionCacheKey, type ActionContext, type ActionRunState, type ActionSurface, type CallPort, } from "./actions/context.js";
14
+ export { callRead, callReadInputSchema, callReadOutputSchema, readPaidOrigin, type CallReadInput, type CallReadOutput, } from "./actions/call-read.js";
15
+ export { createRunState, inspectionCacheKey, type AccountsPort, type ActionContext, type ActionRunState, type ActionSurface, type CallPort, type SwarmRunActionInput, type SwarmRunActionResult, type SwarmRunsInput, type SwarmRunsResult, type SwarmRunScope, } from "./actions/context.js";
12
16
  export { defineAction, toLoopName, type Action, type ActionGrant, type ActionMoney, } from "./actions/define.js";
13
17
  export { checkAction, exactUsdcPrice, type PolicyDecision } from "./actions/policy.js";
14
18
  export { ActionDeclinedError, actions, agentToolNames, findAction, registeredAgentProfileSchema, runAction, } from "./actions/register.js";
19
+ export { attachedSwarmRunOutputSchema, detachedRunSummarySchema, detachedSwarmRunOutputSchema, swarmRun, swarmRunInputSchema, swarmRunOutputSchema, swarmRuns, swarmRunsInputSchema, swarmRunsOutputSchema, swarmAgentActions, type SwarmAllocateResult, type SwarmDelegateResult, } from "./actions/swarm-agent.js";
20
+ export { createAccountsPort, type CreateAccountsPortOptions } from "./tools/accounts.js";