@vapi-network/core 0.5.0 → 0.8.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/README.md +406 -5
- package/dist/account-add.d.ts +101 -0
- package/dist/account-add.d.ts.map +1 -0
- package/dist/account-movement-lock.d.ts +10 -0
- package/dist/account-movement-lock.d.ts.map +1 -0
- package/dist/agent-link.d.ts +16 -1
- package/dist/agent-link.d.ts.map +1 -1
- package/dist/agent-link.js +131 -54
- package/dist/agent-link.js.map +3 -3
- package/dist/agent-profile.d.ts +47 -6
- package/dist/agent-profile.d.ts.map +1 -1
- package/dist/agent-run.d.ts +12 -0
- package/dist/agent-run.d.ts.map +1 -0
- package/dist/allocation.d.ts +64 -0
- package/dist/allocation.d.ts.map +1 -0
- package/dist/api-key.js +4 -2
- package/dist/api-key.js.map +1 -1
- package/dist/atomic-file.d.ts +23 -0
- package/dist/atomic-file.d.ts.map +1 -0
- package/dist/audit.d.ts +4 -1
- package/dist/audit.d.ts.map +1 -1
- package/dist/backup.d.ts +307 -0
- package/dist/backup.d.ts.map +1 -0
- package/dist/backup.js +49938 -0
- package/dist/backup.js.map +6 -0
- package/dist/call-contracts-wire.d.ts +12 -12
- package/dist/ceiling.d.ts +98 -0
- package/dist/ceiling.d.ts.map +1 -0
- package/dist/cloud-backup.d.ts +123 -0
- package/dist/cloud-backup.d.ts.map +1 -0
- package/dist/cloud-backup.js +50827 -0
- package/dist/cloud-backup.js.map +6 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/device.d.ts +15 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/distribute.d.ts +68 -0
- package/dist/distribute.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10131 -1228
- package/dist/index.js.map +3 -3
- package/dist/keystore.d.ts +24 -1
- package/dist/keystore.d.ts.map +1 -1
- package/dist/marketplace-contracts.d.ts +14 -14
- package/dist/member-bundle.d.ts +110 -0
- package/dist/member-bundle.d.ts.map +1 -0
- package/dist/movement-open.d.ts +10 -0
- package/dist/movement-open.d.ts.map +1 -0
- package/dist/movement.d.ts +172 -0
- package/dist/movement.d.ts.map +1 -0
- package/dist/networks.d.ts +1 -0
- package/dist/networks.d.ts.map +1 -1
- package/dist/receipts.d.ts +33 -0
- package/dist/receipts.d.ts.map +1 -1
- package/dist/router-client.d.ts +9 -1
- package/dist/router-client.d.ts.map +1 -1
- package/dist/router-client.js +36500 -16308
- package/dist/router-client.js.map +3 -3
- package/dist/run-budget.d.ts +17 -0
- package/dist/run-budget.d.ts.map +1 -0
- package/dist/secret-store.d.ts +23 -5
- package/dist/secret-store.d.ts.map +1 -1
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.d.ts.map +1 -1
- package/dist/secrets.js +1439 -56
- package/dist/secrets.js.map +3 -3
- package/dist/siblings.d.ts +41 -0
- package/dist/siblings.d.ts.map +1 -0
- package/dist/spend-policy.d.ts +12 -0
- package/dist/spend-policy.d.ts.map +1 -1
- package/dist/status.d.ts +73 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/support-report.d.ts +1 -1
- package/dist/swarm-capital.d.ts +147 -0
- package/dist/swarm-capital.d.ts.map +1 -0
- package/dist/swarm.d.ts +224 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/transfer-journal.d.ts +11 -0
- package/dist/transfer-journal.d.ts.map +1 -0
- package/dist/transfer.d.ts +65 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/vault-key.d.ts +41 -0
- package/dist/vault-key.d.ts.map +1 -0
- package/dist/vault-migrate.d.ts +29 -0
- package/dist/vault-migrate.d.ts.map +1 -0
- package/dist/vault.d.ts +104 -0
- package/dist/vault.d.ts.map +1 -0
- package/dist/wallet-store.d.ts +135 -39
- package/dist/wallet-store.d.ts.map +1 -1
- package/dist/x402-pay.d.ts +12 -0
- package/dist/x402-pay.d.ts.map +1 -1
- package/dist/x402.d.ts +3 -0
- package/dist/x402.d.ts.map +1 -1
- package/package.json +9 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { pollDeviceLink as completeDeviceLink, saveAgentLink as storeAgentLink, startDeviceLink as beginDeviceLink } from "./agent-link.js";
|
|
2
|
+
import type { SecretStore } from "./secret-store.js";
|
|
3
|
+
import { type WalletName, type WalletStore } from "./wallet-store.js";
|
|
4
|
+
export type AccountCapsUsd = {
|
|
5
|
+
perCallUsd: string;
|
|
6
|
+
perDayUsd: string;
|
|
7
|
+
};
|
|
8
|
+
export type AccountCapsInput = {
|
|
9
|
+
perCallUsd?: number | string;
|
|
10
|
+
perDayUsd?: number | string;
|
|
11
|
+
};
|
|
12
|
+
type CreatedAccount = {
|
|
13
|
+
account: WalletName;
|
|
14
|
+
address: string;
|
|
15
|
+
caps: AccountCapsUsd;
|
|
16
|
+
created: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type AccountLinkOutcome = {
|
|
19
|
+
linked: true;
|
|
20
|
+
owner: string;
|
|
21
|
+
} | {
|
|
22
|
+
linked: false;
|
|
23
|
+
reason: "denied" | "expired" | "failed";
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
export type AccountLinkResult = {
|
|
27
|
+
linked: boolean;
|
|
28
|
+
autoApproved: boolean;
|
|
29
|
+
link?: {
|
|
30
|
+
userCode: string;
|
|
31
|
+
verificationUri: string;
|
|
32
|
+
verificationUriComplete: string;
|
|
33
|
+
expiresInSeconds: number;
|
|
34
|
+
};
|
|
35
|
+
linkError?: string;
|
|
36
|
+
completion?: Promise<AccountLinkOutcome>;
|
|
37
|
+
};
|
|
38
|
+
export type AccountAddResult = CreatedAccount & AccountLinkResult;
|
|
39
|
+
export declare class AccountCapsRaiseError extends Error {
|
|
40
|
+
constructor(message: string);
|
|
41
|
+
}
|
|
42
|
+
export declare function linkRouterAllowanceUsd(args: {
|
|
43
|
+
scopes: readonly string[];
|
|
44
|
+
explicitUsd?: number | undefined;
|
|
45
|
+
perDayCapUsd?: number | string | undefined;
|
|
46
|
+
trusted: boolean;
|
|
47
|
+
}): number | undefined;
|
|
48
|
+
export declare function createAccount(args: {
|
|
49
|
+
store: WalletStore;
|
|
50
|
+
name: string;
|
|
51
|
+
caps?: AccountCapsInput;
|
|
52
|
+
label?: string;
|
|
53
|
+
existing?: "refuse" | "return";
|
|
54
|
+
}): Promise<CreatedAccount>;
|
|
55
|
+
export declare function lowerAccountCaps(args: {
|
|
56
|
+
store: WalletStore;
|
|
57
|
+
name: string;
|
|
58
|
+
perCallUsd?: number | string;
|
|
59
|
+
perDayUsd?: number | string;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
account: WalletName;
|
|
62
|
+
address: string;
|
|
63
|
+
caps: AccountCapsUsd;
|
|
64
|
+
changed: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
export type AddAccountArgs = {
|
|
67
|
+
store: WalletStore;
|
|
68
|
+
secrets: SecretStore;
|
|
69
|
+
name: string;
|
|
70
|
+
caps?: AccountCapsInput;
|
|
71
|
+
label?: string;
|
|
72
|
+
existing?: "refuse" | "return";
|
|
73
|
+
link?: boolean;
|
|
74
|
+
apiBase: string;
|
|
75
|
+
configPath?: string;
|
|
76
|
+
env?: NodeJS.ProcessEnv;
|
|
77
|
+
hostname?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Explicit router allowance for `router.use`. Without one, a trusted link
|
|
80
|
+
* requests the account's exact per-day cap; an untrusted link leaves the
|
|
81
|
+
* allowance for the owner to choose on the consent page.
|
|
82
|
+
*/
|
|
83
|
+
routerAllowanceUsd?: number;
|
|
84
|
+
scopes?: string[];
|
|
85
|
+
fetchImpl?: typeof fetch;
|
|
86
|
+
now?: () => number;
|
|
87
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
88
|
+
signal?: AbortSignal;
|
|
89
|
+
startDeviceLink?: typeof beginDeviceLink;
|
|
90
|
+
pollDeviceLink?: typeof completeDeviceLink;
|
|
91
|
+
saveAgentLink?: typeof storeAgentLink;
|
|
92
|
+
};
|
|
93
|
+
export type StartAccountLinkArgs = Omit<AddAccountArgs, "name" | "caps" | "existing" | "link"> & {
|
|
94
|
+
account: WalletName;
|
|
95
|
+
/** Start the owner flow without polling when false. Defaults to true. */
|
|
96
|
+
awaitApproval?: boolean;
|
|
97
|
+
};
|
|
98
|
+
export declare function addAccount(args: AddAccountArgs): Promise<AccountAddResult>;
|
|
99
|
+
export declare function startAccountLink(args: StartAccountLinkArgs): Promise<AccountLinkResult>;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=account-add.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-add.d.ts","sourceRoot":"","sources":["../src/account-add.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,cAAc,IAAI,kBAAkB,EACpC,aAAa,IAAI,cAAc,EAC/B,eAAe,IAAI,eAAe,EAGnC,MAAM,iBAAiB,CAAC;AAKzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAoB,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGxF,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,UAAU,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC1B;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAA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MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC,GAAG;IAC/F,OAAO,EAAE,UAAU,CAAC;IACpB,yEAAyE;IACzE,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,wBAAsB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAwBhF;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA6H7F"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WalletName } from "./wallet-name.js";
|
|
2
|
+
export declare class AccountMovementLockedError extends Error {
|
|
3
|
+
readonly account: WalletName;
|
|
4
|
+
readonly code = "account_movement_locked";
|
|
5
|
+
constructor(account: WalletName);
|
|
6
|
+
}
|
|
7
|
+
/** Serializes every signer that can create an EIP-3009 authorization for one account. */
|
|
8
|
+
export declare function withAccountMovementLock<T>(home: string, account: WalletName, timeoutMs: number | undefined, operation: () => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
9
|
+
export declare function withAccountMovementLocks<T>(home: string, accounts: readonly WalletName[], timeoutMs: number | undefined, operation: () => Promise<T>): Promise<T>;
|
|
10
|
+
//# sourceMappingURL=account-movement-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-movement-lock.d.ts","sourceRoot":"","sources":["../src/account-movement-lock.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAa,0BAA2B,SAAQ,KAAK;IAGvC,QAAQ,CAAC,OAAO,EAAE,UAAU;IAFxC,QAAQ,CAAC,IAAI,6BAA6B;gBAErB,OAAO,EAAE,UAAU;CAIzC;AAED,yFAAyF;AACzF,wBAAsB,uBAAuB,CAAC,CAAC,EAC7C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAiCZ;AAED,wBAAsB,wBAAwB,CAAC,CAAC,EAC9C,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,UAAU,EAAE,EAC/B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,CAAC,CAAC,CAOZ"}
|
package/dist/agent-link.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { SecretStore } from "./secret-store.js";
|
|
|
2
2
|
import type { AgentLink, WalletName, WalletStore } from "./wallet-store.js";
|
|
3
3
|
export declare const AGENT_LINK_STATEMENT = "Link this wallet to a vAPI account as an agent.";
|
|
4
4
|
export declare const AGENT_LINK_REVOKED_MESSAGE = "This agent's link was revoked or has expired. Run vapi login to link it again.";
|
|
5
|
+
export declare const REMOTE_AGENT_TOKEN_EXPIRED_MESSAGE = "The Railway run's short-lived vAPI access token expired. Start a new Railway run from the owner machine.";
|
|
5
6
|
export type DeviceLinkStart = {
|
|
6
7
|
clientId: string;
|
|
7
8
|
deviceCode: string;
|
|
@@ -10,6 +11,7 @@ export type DeviceLinkStart = {
|
|
|
10
11
|
verificationUriComplete: string;
|
|
11
12
|
expiresIn: number;
|
|
12
13
|
interval: number;
|
|
14
|
+
autoApproved: boolean;
|
|
13
15
|
};
|
|
14
16
|
export type AgentTokens = {
|
|
15
17
|
accessToken: string;
|
|
@@ -40,6 +42,9 @@ export declare function startDeviceLink(args: {
|
|
|
40
42
|
label: string;
|
|
41
43
|
scopes?: string[];
|
|
42
44
|
routerAllowanceUsd?: number;
|
|
45
|
+
device?: string;
|
|
46
|
+
trustDevice?: boolean;
|
|
47
|
+
bearer?: string;
|
|
43
48
|
fetchImpl?: typeof fetch;
|
|
44
49
|
now?: () => Date;
|
|
45
50
|
}): Promise<DeviceLinkStart>;
|
|
@@ -47,9 +52,19 @@ export declare function pollDeviceLink(args: {
|
|
|
47
52
|
apiBase: string;
|
|
48
53
|
start: DeviceLinkStart;
|
|
49
54
|
fetchImpl?: typeof fetch;
|
|
50
|
-
sleep?: (ms: number) => Promise<void>;
|
|
55
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
51
56
|
now?: () => number;
|
|
57
|
+
immediate?: boolean;
|
|
58
|
+
signal?: AbortSignal;
|
|
52
59
|
}): Promise<LinkResult>;
|
|
60
|
+
export declare function trustedLinkBearer(args: {
|
|
61
|
+
store: WalletStore;
|
|
62
|
+
secrets: SecretStore;
|
|
63
|
+
apiBase: string;
|
|
64
|
+
exclude?: WalletName;
|
|
65
|
+
fetchImpl?: typeof fetch;
|
|
66
|
+
now?: () => number;
|
|
67
|
+
}): Promise<string | undefined>;
|
|
53
68
|
export declare const agentSecretAccounts: (wallet: WalletName) => {
|
|
54
69
|
tokens: string;
|
|
55
70
|
routerStake: string;
|
package/dist/agent-link.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-link.d.ts","sourceRoot":"","sources":["../src/agent-link.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-link.d.ts","sourceRoot":"","sources":["../src/agent-link.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5E,eAAO,MAAM,oBAAoB,oDAAoD,CAAC;AACtF,eAAO,MAAM,0BAA0B,mFAC2C,CAAC;AACnF,eAAO,MAAM,kCAAkC,6GAC6D,CAAC;AAE7G,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,C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,CAAC,EAC7C,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,CAAC,CAAC,CA0BZ"}
|
package/dist/agent-link.js
CHANGED
|
@@ -1203,6 +1203,7 @@ async function appendAudit(home, record, options = {}) {
|
|
|
1203
1203
|
const entry = {
|
|
1204
1204
|
time: (options.now?.() ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
1205
1205
|
event: record.event,
|
|
1206
|
+
...record.run === void 0 ? {} : { run: record.run },
|
|
1206
1207
|
...record.wallet === void 0 ? {} : { wallet: record.wallet },
|
|
1207
1208
|
...record.owner === void 0 ? {} : { owner: record.owner },
|
|
1208
1209
|
tty: record.tty,
|
|
@@ -1217,9 +1218,13 @@ async function appendAudit(home, record, options = {}) {
|
|
|
1217
1218
|
return entry;
|
|
1218
1219
|
}
|
|
1219
1220
|
|
|
1221
|
+
// src/device.ts
|
|
1222
|
+
var DEVICE_NAME_PATTERN = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
1223
|
+
|
|
1220
1224
|
// src/agent-link.ts
|
|
1221
1225
|
var AGENT_LINK_STATEMENT = "Link this wallet to a vAPI account as an agent.";
|
|
1222
1226
|
var AGENT_LINK_REVOKED_MESSAGE = "This agent's link was revoked or has expired. Run vapi login to link it again.";
|
|
1227
|
+
var REMOTE_AGENT_TOKEN_EXPIRED_MESSAGE = "The Railway run's short-lived vAPI access token expired. Start a new Railway run from the owner machine.";
|
|
1223
1228
|
var AgentLinkError = class extends Error {
|
|
1224
1229
|
constructor(code, message) {
|
|
1225
1230
|
super(message);
|
|
@@ -1232,6 +1237,9 @@ var DEFAULT_AGENT_SCOPES = ["mcp:call", "router.use"];
|
|
|
1232
1237
|
var ALLOWED_AGENT_SCOPES = /* @__PURE__ */ new Set([...DEFAULT_AGENT_SCOPES, "call.publish"]);
|
|
1233
1238
|
var publicFetch = createPublicFetch({ allowPrivateNetwork: false });
|
|
1234
1239
|
async function startDeviceLink(args) {
|
|
1240
|
+
if (args.device !== void 0 && !DEVICE_NAME_PATTERN.test(args.device)) {
|
|
1241
|
+
throw new AgentLinkError("http", "The device name is invalid.");
|
|
1242
|
+
}
|
|
1235
1243
|
const scopes = args.scopes ?? [...DEFAULT_AGENT_SCOPES];
|
|
1236
1244
|
if (scopes.some((scope) => !ALLOWED_AGENT_SCOPES.has(scope))) {
|
|
1237
1245
|
throw new AgentLinkError("invalid_scope", "The requested agent scope is not allowed.");
|
|
@@ -1262,14 +1270,20 @@ async function startDeviceLink(args) {
|
|
|
1262
1270
|
apiEndpoint(args.apiBase, "/oauth/device_authorization"),
|
|
1263
1271
|
{
|
|
1264
1272
|
method: "POST",
|
|
1265
|
-
headers: {
|
|
1273
|
+
headers: {
|
|
1274
|
+
"content-type": "application/json",
|
|
1275
|
+
...args.bearer === void 0 ? {} : { authorization: `Bearer ${args.bearer}` }
|
|
1276
|
+
},
|
|
1266
1277
|
body: JSON.stringify({
|
|
1267
1278
|
agent_message: message,
|
|
1268
1279
|
agent_signature: signature,
|
|
1269
1280
|
label: args.label,
|
|
1270
1281
|
scope: scopes.join(" "),
|
|
1271
|
-
...args.routerAllowanceUsd === void 0 ? {} : { router_allowance_usd: args.routerAllowanceUsd }
|
|
1272
|
-
|
|
1282
|
+
...args.routerAllowanceUsd === void 0 ? {} : { router_allowance_usd: args.routerAllowanceUsd },
|
|
1283
|
+
...args.device === void 0 ? {} : { device: args.device },
|
|
1284
|
+
...args.trustDevice === void 0 ? {} : { trust_device: args.trustDevice }
|
|
1285
|
+
}),
|
|
1286
|
+
...args.bearer === void 0 ? {} : { redirect: "manual" }
|
|
1273
1287
|
}
|
|
1274
1288
|
);
|
|
1275
1289
|
const payload = await responseRecord(response);
|
|
@@ -1281,7 +1295,8 @@ async function startDeviceLink(args) {
|
|
|
1281
1295
|
verificationUri: requiredString(payload, "verification_uri"),
|
|
1282
1296
|
verificationUriComplete: requiredString(payload, "verification_uri_complete"),
|
|
1283
1297
|
expiresIn: requiredNumber(payload, "expires_in"),
|
|
1284
|
-
interval: requiredNumber(payload, "interval")
|
|
1298
|
+
interval: requiredNumber(payload, "interval"),
|
|
1299
|
+
autoApproved: payload.auto_approved === true
|
|
1285
1300
|
};
|
|
1286
1301
|
}
|
|
1287
1302
|
async function pollDeviceLink(args) {
|
|
@@ -1289,65 +1304,116 @@ async function pollDeviceLink(args) {
|
|
|
1289
1304
|
const sleep = args.sleep ?? sleepFor;
|
|
1290
1305
|
const now = args.now ?? Date.now;
|
|
1291
1306
|
const deadline = now() + args.start.expiresIn * 1e3;
|
|
1307
|
+
const expiry = new AbortController();
|
|
1308
|
+
const expiryTimer = setTimeout(() => expiry.abort(), Math.max(0, deadline - now()));
|
|
1309
|
+
expiryTimer.unref();
|
|
1310
|
+
const signal = args.signal === void 0 ? expiry.signal : AbortSignal.any([expiry.signal, args.signal]);
|
|
1292
1311
|
let interval = args.start.interval;
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1312
|
+
let firstPoll = true;
|
|
1313
|
+
try {
|
|
1314
|
+
while (now() < deadline && !signal.aborted) {
|
|
1315
|
+
if (args.immediate !== true || !firstPoll) await sleep(interval * 1e3, signal);
|
|
1316
|
+
firstPoll = false;
|
|
1317
|
+
if (now() >= deadline || signal.aborted) break;
|
|
1318
|
+
const body = new URLSearchParams({
|
|
1319
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
1320
|
+
device_code: args.start.deviceCode,
|
|
1321
|
+
client_id: args.start.clientId
|
|
1322
|
+
});
|
|
1323
|
+
let response;
|
|
1324
|
+
try {
|
|
1325
|
+
response = await safeFetch(fetchImpl, apiEndpoint(args.apiBase, "/oauth/token"), {
|
|
1326
|
+
method: "POST",
|
|
1327
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
1328
|
+
body,
|
|
1329
|
+
signal
|
|
1330
|
+
});
|
|
1331
|
+
} catch (error2) {
|
|
1332
|
+
if (expiry.signal.aborted) throw expiredLinkError();
|
|
1333
|
+
throw error2;
|
|
1334
|
+
}
|
|
1335
|
+
const payload = await responseRecord(response);
|
|
1336
|
+
if (response.ok) {
|
|
1337
|
+
const scope = requiredString(payload, "scope");
|
|
1338
|
+
const owner = requiredOwner(payload, "owner_wallet");
|
|
1339
|
+
return {
|
|
1340
|
+
tokens: {
|
|
1341
|
+
accessToken: requiredString(payload, "access_token"),
|
|
1342
|
+
refreshToken: requiredString(payload, "refresh_token"),
|
|
1343
|
+
expiresAt: now() + requiredNumber(payload, "expires_in") * 1e3,
|
|
1344
|
+
scopes: splitScopes(scope)
|
|
1345
|
+
},
|
|
1346
|
+
owner,
|
|
1347
|
+
...optionalStringProperty(payload, "router_key", "routerKey"),
|
|
1348
|
+
...optionalStringProperty(payload, "router_base_url", "routerBaseUrl"),
|
|
1349
|
+
...optionalStringProperty(payload, "router_key_error", "routerKeyError")
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
const error = stringField(payload, "error");
|
|
1353
|
+
if (response.status === 400 && error === "authorization_pending") continue;
|
|
1354
|
+
if (response.status === 400 && error === "slow_down") {
|
|
1355
|
+
interval += 5;
|
|
1356
|
+
continue;
|
|
1357
|
+
}
|
|
1358
|
+
if (response.status === 400 && error === "access_denied") {
|
|
1359
|
+
throw new AgentLinkError("access_denied", "The owner denied the agent link.");
|
|
1360
|
+
}
|
|
1361
|
+
if (response.status === 400 && error === "expired_token") throw expiredLinkError();
|
|
1362
|
+
throw httpError("The vAPI agent link request failed.");
|
|
1331
1363
|
}
|
|
1332
|
-
|
|
1333
|
-
|
|
1364
|
+
} finally {
|
|
1365
|
+
clearTimeout(expiryTimer);
|
|
1334
1366
|
}
|
|
1335
1367
|
throw expiredLinkError();
|
|
1336
1368
|
}
|
|
1369
|
+
async function trustedLinkBearer(args) {
|
|
1370
|
+
if (!args.secrets.available) return void 0;
|
|
1371
|
+
let origin;
|
|
1372
|
+
try {
|
|
1373
|
+
origin = new URL(args.apiBase).origin;
|
|
1374
|
+
await args.store.reload();
|
|
1375
|
+
} catch {
|
|
1376
|
+
return void 0;
|
|
1377
|
+
}
|
|
1378
|
+
const defaultName = args.store.defaultName;
|
|
1379
|
+
const names = [
|
|
1380
|
+
...defaultName === void 0 ? [] : [defaultName],
|
|
1381
|
+
...args.store.names().filter((name) => name !== defaultName)
|
|
1382
|
+
];
|
|
1383
|
+
for (const name of names) {
|
|
1384
|
+
if (name === args.exclude) continue;
|
|
1385
|
+
try {
|
|
1386
|
+
const bearer = await withAgentCredentialLock(args.store, `wallet:${name}`, async () => {
|
|
1387
|
+
await args.store.reload();
|
|
1388
|
+
const link = args.store.entry(name)?.link;
|
|
1389
|
+
if (link === void 0 || new URL(link.apiBase).origin !== origin) return void 0;
|
|
1390
|
+
return await agentAccessToken({
|
|
1391
|
+
secrets: args.secrets,
|
|
1392
|
+
wallets: args.store,
|
|
1393
|
+
wallet: name,
|
|
1394
|
+
...args.fetchImpl === void 0 ? {} : { fetchImpl: args.fetchImpl },
|
|
1395
|
+
...args.now === void 0 ? {} : { now: args.now }
|
|
1396
|
+
});
|
|
1397
|
+
});
|
|
1398
|
+
if (bearer !== void 0) return bearer;
|
|
1399
|
+
} catch {
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
return void 0;
|
|
1403
|
+
}
|
|
1337
1404
|
var agentSecretAccounts = (wallet) => ({
|
|
1338
1405
|
tokens: `vapi.agent.${wallet}.tokens`,
|
|
1339
1406
|
routerStake: `vapi.agent.${wallet}.router.stake`,
|
|
1340
1407
|
routerBalance: `vapi.agent.${wallet}.router.balance`
|
|
1341
1408
|
});
|
|
1342
1409
|
async function renameAgentLinkWallet(args) {
|
|
1343
|
-
await args.wallets.
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
);
|
|
1410
|
+
return await args.wallets.rename(args.from, args.to, {
|
|
1411
|
+
secrets: args.secrets,
|
|
1412
|
+
serialize: async (operation) => {
|
|
1413
|
+
const clientId = args.wallets.entry(args.from)?.link?.clientId;
|
|
1414
|
+
return clientId === void 0 ? await operation() : await withAgentCredentialLock(args.wallets, clientId, operation);
|
|
1415
|
+
}
|
|
1416
|
+
});
|
|
1351
1417
|
}
|
|
1352
1418
|
async function saveAgentLink(args) {
|
|
1353
1419
|
if (!args.secrets.available) {
|
|
@@ -1463,6 +1529,9 @@ async function resolveAgentAccessToken(args, options) {
|
|
|
1463
1529
|
if (options.rejectedAccessToken === void 0 && current.expiresAt - 6e4 > now()) {
|
|
1464
1530
|
return current.accessToken;
|
|
1465
1531
|
}
|
|
1532
|
+
if (current.refreshToken === void 0) {
|
|
1533
|
+
throw new AgentLinkError("not_linked", REMOTE_AGENT_TOKEN_EXPIRED_MESSAGE);
|
|
1534
|
+
}
|
|
1466
1535
|
const response = await safeFetch(
|
|
1467
1536
|
args.fetchImpl ?? publicFetch,
|
|
1468
1537
|
apiEndpoint(currentLink.apiBase, "/oauth/token"),
|
|
@@ -1597,12 +1666,18 @@ function parseTokens(value) {
|
|
|
1597
1666
|
if (!isRecord(parsed)) return void 0;
|
|
1598
1667
|
const accessToken = stringField(parsed, "accessToken");
|
|
1599
1668
|
const refreshToken = stringField(parsed, "refreshToken");
|
|
1669
|
+
const refreshable = parsed.refreshable;
|
|
1600
1670
|
const expiresAt = numberField(parsed, "expiresAt");
|
|
1601
1671
|
const scopes = parsed.scopes;
|
|
1602
|
-
if (accessToken === void 0 ||
|
|
1672
|
+
if (accessToken === void 0 || expiresAt === void 0 || !Array.isArray(scopes) || scopes.some((scope) => typeof scope !== "string") || (refreshToken === void 0 ? refreshable !== false : refreshable === false)) {
|
|
1603
1673
|
return void 0;
|
|
1604
1674
|
}
|
|
1605
|
-
return {
|
|
1675
|
+
return {
|
|
1676
|
+
accessToken,
|
|
1677
|
+
...refreshToken === void 0 ? {} : { refreshToken },
|
|
1678
|
+
expiresAt,
|
|
1679
|
+
scopes
|
|
1680
|
+
};
|
|
1606
1681
|
}
|
|
1607
1682
|
function withBearer(init, accessToken) {
|
|
1608
1683
|
const headers = new Headers(init?.headers);
|
|
@@ -1702,6 +1777,7 @@ export {
|
|
|
1702
1777
|
AGENT_LINK_STATEMENT,
|
|
1703
1778
|
AgentLinkError,
|
|
1704
1779
|
DEFAULT_AGENT_SCOPES,
|
|
1780
|
+
REMOTE_AGENT_TOKEN_EXPIRED_MESSAGE,
|
|
1705
1781
|
agentAccessToken,
|
|
1706
1782
|
agentFetch,
|
|
1707
1783
|
agentSecretAccounts,
|
|
@@ -1710,6 +1786,7 @@ export {
|
|
|
1710
1786
|
renameAgentLinkWallet,
|
|
1711
1787
|
saveAgentLink,
|
|
1712
1788
|
startDeviceLink,
|
|
1789
|
+
trustedLinkBearer,
|
|
1713
1790
|
withAgentCredentialLock
|
|
1714
1791
|
};
|
|
1715
1792
|
//# sourceMappingURL=agent-link.js.map
|