@getstackrun/sdk 4.0.0 → 4.4.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/LICENSE +1 -1
- package/README.md +326 -10
- package/dist/agent-auth.d.ts.map +1 -1
- package/dist/agent-auth.js +3 -4
- package/dist/agent-auth.js.map +1 -1
- package/dist/browser-bootstrap.js +1 -1
- package/dist/browser-bootstrap.js.map +1 -1
- package/dist/client.d.ts +86 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +235 -40
- package/dist/client.js.map +1 -1
- package/dist/control-socket-server.d.ts +134 -0
- package/dist/control-socket-server.d.ts.map +1 -0
- package/dist/control-socket-server.js +108 -0
- package/dist/control-socket-server.js.map +1 -0
- package/dist/credentials-file.d.ts +7 -0
- package/dist/credentials-file.d.ts.map +1 -1
- package/dist/credentials-file.js +57 -2
- package/dist/credentials-file.js.map +1 -1
- package/dist/errors.d.ts +316 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +572 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +126 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +150 -22
- package/dist/index.js.map +1 -1
- package/dist/network-install-key.d.ts +56 -0
- package/dist/network-install-key.d.ts.map +1 -0
- package/dist/network-install-key.js +92 -0
- package/dist/network-install-key.js.map +1 -0
- package/dist/network-install.d.ts +134 -0
- package/dist/network-install.d.ts.map +1 -0
- package/dist/network-install.js +70 -0
- package/dist/network-install.js.map +1 -0
- package/dist/service-mcp.d.ts +49 -0
- package/dist/service-mcp.d.ts.map +1 -0
- package/dist/service-mcp.js +122 -0
- package/dist/service-mcp.js.map +1 -0
- package/dist/services/accounts.d.ts +1548 -0
- package/dist/services/accounts.d.ts.map +1 -0
- package/dist/services/accounts.js +724 -0
- package/dist/services/accounts.js.map +1 -0
- package/dist/services/agent-identity.d.ts +58 -0
- package/dist/services/agent-identity.d.ts.map +1 -0
- package/dist/services/agent-identity.js +50 -0
- package/dist/services/agent-identity.js.map +1 -0
- package/dist/services/agents.d.ts +78 -3
- package/dist/services/agents.d.ts.map +1 -1
- package/dist/services/agents.js +29 -2
- package/dist/services/agents.js.map +1 -1
- package/dist/services/audit.d.ts +5 -0
- package/dist/services/audit.d.ts.map +1 -1
- package/dist/services/audit.js +5 -0
- package/dist/services/audit.js.map +1 -1
- package/dist/services/billing.d.ts +67 -0
- package/dist/services/billing.d.ts.map +1 -0
- package/dist/services/billing.js +42 -0
- package/dist/services/billing.js.map +1 -0
- package/dist/services/brain.d.ts +122 -0
- package/dist/services/brain.d.ts.map +1 -0
- package/dist/services/brain.js +40 -0
- package/dist/services/brain.js.map +1 -0
- package/dist/services/calendar.d.ts +256 -0
- package/dist/services/calendar.d.ts.map +1 -0
- package/dist/services/calendar.js +75 -0
- package/dist/services/calendar.js.map +1 -0
- package/dist/services/catalogue.d.ts +185 -0
- package/dist/services/catalogue.d.ts.map +1 -0
- package/dist/services/catalogue.js +31 -0
- package/dist/services/catalogue.js.map +1 -0
- package/dist/services/chat-channels.d.ts +82 -0
- package/dist/services/chat-channels.d.ts.map +1 -0
- package/dist/services/chat-channels.js +42 -0
- package/dist/services/chat-channels.js.map +1 -0
- package/dist/services/control-policies.d.ts +409 -0
- package/dist/services/control-policies.d.ts.map +1 -0
- package/dist/services/control-policies.js +101 -0
- package/dist/services/control-policies.js.map +1 -0
- package/dist/services/control-socket.d.ts +201 -0
- package/dist/services/control-socket.d.ts.map +1 -0
- package/dist/services/control-socket.js +165 -0
- package/dist/services/control-socket.js.map +1 -0
- package/dist/services/credentials.d.ts +2 -1
- package/dist/services/credentials.d.ts.map +1 -1
- package/dist/services/credentials.js +3 -2
- package/dist/services/credentials.js.map +1 -1
- package/dist/services/detector-config.d.ts +13 -12
- package/dist/services/detector-config.d.ts.map +1 -1
- package/dist/services/detector-config.js +13 -12
- package/dist/services/detector-config.js.map +1 -1
- package/dist/services/drive.d.ts +257 -0
- package/dist/services/drive.d.ts.map +1 -0
- package/dist/services/drive.js +167 -0
- package/dist/services/drive.js.map +1 -0
- package/dist/services/dropoffs.d.ts +5 -1
- package/dist/services/dropoffs.d.ts.map +1 -1
- package/dist/services/dropoffs.js +3 -1
- package/dist/services/dropoffs.js.map +1 -1
- package/dist/services/evidence-packs.d.ts +4 -2
- package/dist/services/evidence-packs.d.ts.map +1 -1
- package/dist/services/evidence-packs.js +4 -2
- package/dist/services/evidence-packs.js.map +1 -1
- package/dist/services/flagged-content.d.ts +30 -0
- package/dist/services/flagged-content.d.ts.map +1 -0
- package/dist/services/flagged-content.js +24 -0
- package/dist/services/flagged-content.js.map +1 -0
- package/dist/services/governance.d.ts +69 -0
- package/dist/services/governance.d.ts.map +1 -0
- package/dist/services/governance.js +39 -0
- package/dist/services/governance.js.map +1 -0
- package/dist/services/identity.d.ts +44 -4
- package/dist/services/identity.d.ts.map +1 -1
- package/dist/services/identity.js +54 -6
- package/dist/services/identity.js.map +1 -1
- package/dist/services/inbound-webhooks.d.ts +12 -1
- package/dist/services/inbound-webhooks.d.ts.map +1 -1
- package/dist/services/inbound-webhooks.js +7 -0
- package/dist/services/inbound-webhooks.js.map +1 -1
- package/dist/services/intents.d.ts +8 -2
- package/dist/services/intents.d.ts.map +1 -1
- package/dist/services/intents.js +7 -3
- package/dist/services/intents.js.map +1 -1
- package/dist/services/llm.d.ts +73 -1
- package/dist/services/llm.d.ts.map +1 -1
- package/dist/services/llm.js +62 -0
- package/dist/services/llm.js.map +1 -1
- package/dist/services/making.d.ts +263 -0
- package/dist/services/making.d.ts.map +1 -0
- package/dist/services/making.js +114 -0
- package/dist/services/making.js.map +1 -0
- package/dist/services/meetings.d.ts +183 -0
- package/dist/services/meetings.d.ts.map +1 -0
- package/dist/services/meetings.js +148 -0
- package/dist/services/meetings.js.map +1 -0
- package/dist/services/memory.d.ts +288 -0
- package/dist/services/memory.d.ts.map +1 -0
- package/dist/services/memory.js +116 -0
- package/dist/services/memory.js.map +1 -0
- package/dist/services/message-access.d.ts +50 -0
- package/dist/services/message-access.d.ts.map +1 -0
- package/dist/services/message-access.js +36 -0
- package/dist/services/message-access.js.map +1 -0
- package/dist/services/missions.d.ts +93 -7
- package/dist/services/missions.d.ts.map +1 -1
- package/dist/services/missions.js +29 -1
- package/dist/services/missions.js.map +1 -1
- package/dist/services/network.d.ts +266 -0
- package/dist/services/network.d.ts.map +1 -0
- package/dist/services/network.js +209 -0
- package/dist/services/network.js.map +1 -0
- package/dist/services/partner-accounts.d.ts +215 -0
- package/dist/services/partner-accounts.d.ts.map +1 -0
- package/dist/services/partner-accounts.js +133 -0
- package/dist/services/partner-accounts.js.map +1 -0
- package/dist/services/passports.d.ts +3 -2
- package/dist/services/passports.d.ts.map +1 -1
- package/dist/services/passports.js +3 -2
- package/dist/services/passports.js.map +1 -1
- package/dist/services/payments.d.ts +126 -0
- package/dist/services/payments.d.ts.map +1 -0
- package/dist/services/payments.js +66 -0
- package/dist/services/payments.js.map +1 -0
- package/dist/services/pii-config.d.ts +7 -17
- package/dist/services/pii-config.d.ts.map +1 -1
- package/dist/services/pii-config.js +9 -19
- package/dist/services/pii-config.js.map +1 -1
- package/dist/services/post.d.ts +240 -0
- package/dist/services/post.d.ts.map +1 -0
- package/dist/services/post.js +99 -0
- package/dist/services/post.js.map +1 -0
- package/dist/services/proxy.d.ts +20 -2
- package/dist/services/proxy.d.ts.map +1 -1
- package/dist/services/proxy.js +31 -1
- package/dist/services/proxy.js.map +1 -1
- package/dist/services/rentahuman.d.ts +92 -0
- package/dist/services/rentahuman.d.ts.map +1 -0
- package/dist/services/rentahuman.js +53 -0
- package/dist/services/rentahuman.js.map +1 -0
- package/dist/services/scan.d.ts +1 -1
- package/dist/services/scan.d.ts.map +1 -1
- package/dist/services/scan.js +1 -1
- package/dist/services/scan.js.map +1 -1
- package/dist/services/services.d.ts +28 -2
- package/dist/services/services.d.ts.map +1 -1
- package/dist/services/services.js +49 -1
- package/dist/services/services.js.map +1 -1
- package/dist/services/team.d.ts +13 -1
- package/dist/services/team.d.ts.map +1 -1
- package/dist/services/team.js +12 -0
- package/dist/services/team.js.map +1 -1
- package/dist/services/trust.d.ts +39 -0
- package/dist/services/trust.d.ts.map +1 -0
- package/dist/services/trust.js +35 -0
- package/dist/services/trust.js.map +1 -0
- package/dist/services/usage.d.ts +1 -1
- package/dist/services/usage.js +1 -1
- package/dist/services/wake.d.ts +257 -0
- package/dist/services/wake.d.ts.map +1 -0
- package/dist/services/wake.js +80 -0
- package/dist/services/wake.js.map +1 -0
- package/dist/services/website.d.ts +188 -0
- package/dist/services/website.d.ts.map +1 -0
- package/dist/services/website.js +135 -0
- package/dist/services/website.js.map +1 -0
- package/dist/types.d.ts +259 -25
- package/dist/types.d.ts.map +1 -1
- package/dist/verify-agent-identity.d.ts +73 -0
- package/dist/verify-agent-identity.d.ts.map +1 -0
- package/dist/verify-agent-identity.js +106 -0
- package/dist/verify-agent-identity.js.map +1 -0
- package/dist/verify-network.d.ts +159 -0
- package/dist/verify-network.d.ts.map +1 -0
- package/dist/verify-network.js +153 -0
- package/dist/verify-network.js.map +1 -0
- package/dist/wake-webhook.d.ts +57 -0
- package/dist/wake-webhook.d.ts.map +1 -0
- package/dist/wake-webhook.js +60 -0
- package/dist/wake-webhook.js.map +1 -0
- package/dist/wallet-key.d.ts +30 -0
- package/dist/wallet-key.d.ts.map +1 -0
- package/dist/wallet-key.js +108 -0
- package/dist/wallet-key.js.map +1 -0
- package/dist/webhook.d.ts +63 -0
- package/dist/webhook.d.ts.map +1 -0
- package/dist/webhook.js +136 -0
- package/dist/webhook.js.map +1 -0
- package/dist/x402-pay.d.ts +139 -0
- package/dist/x402-pay.d.ts.map +1 -0
- package/dist/x402-pay.js +235 -0
- package/dist/x402-pay.js.map +1 -0
- package/package.json +2 -1
- package/dist/services/partner-connect.d.ts +0 -64
- package/dist/services/partner-connect.d.ts.map +0 -1
- package/dist/services/partner-connect.js +0 -42
- package/dist/services/partner-connect.js.map +0 -1
- package/dist/services/partner-tenants.d.ts +0 -126
- package/dist/services/partner-tenants.d.ts.map +0 -1
- package/dist/services/partner-tenants.js +0 -79
- package/dist/services/partner-tenants.js.map +0 -1
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
import { MakingService } from './making.js';
|
|
2
|
+
import { assertPayableUrl, payX402, x402WalletOf } from '../x402-pay.js';
|
|
3
|
+
const seg = encodeURIComponent;
|
|
4
|
+
function passport(options) {
|
|
5
|
+
return options?.passportToken ? { headers: { 'X-Passport-Token': options.passportToken } } : undefined;
|
|
6
|
+
}
|
|
7
|
+
function governed(options) {
|
|
8
|
+
return options?.governanceApprovalId ? { headers: { 'X-Governance-Approval': options.governanceApprovalId } } : undefined;
|
|
9
|
+
}
|
|
10
|
+
export class AccountMessagesService {
|
|
11
|
+
client;
|
|
12
|
+
constructor(client) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
/** Inbound mail, SMS, voicemail and call transcripts, newest first. Flagged ones come back withheld with controls on, and with their flag with controls off. */
|
|
16
|
+
async list(accountId, query = {}, options) {
|
|
17
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/messages`, {
|
|
18
|
+
limit: query.limit !== undefined ? String(query.limit) : undefined,
|
|
19
|
+
cursor: query.cursor,
|
|
20
|
+
channel: query.channel,
|
|
21
|
+
}, passport(options));
|
|
22
|
+
}
|
|
23
|
+
async get(accountId, messageId, options) {
|
|
24
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/messages/${seg(messageId)}`, undefined, passport(options));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Search every message the caller may read, across the customer's message accounts and channels, newest first. An
|
|
28
|
+
* owner or admin reads all of them; an agent reads those of every account of the customer unless the owner limited it
|
|
29
|
+
* to its own (`stack.messageAccess`). The summary of each message comes back without its body: read one with `get`, and a file
|
|
30
|
+
* it carries with `readAttachment`. Only a search on `q`, `sender`, `recipient` or `threadId` needs a window of at most 90 days.
|
|
31
|
+
*/
|
|
32
|
+
async search(query = {}, options) {
|
|
33
|
+
return this.client.get('/v1/messages', {
|
|
34
|
+
agent_id: query.agentId,
|
|
35
|
+
channel: query.channel,
|
|
36
|
+
sender: query.sender,
|
|
37
|
+
recipient: query.recipient,
|
|
38
|
+
thread_id: query.threadId,
|
|
39
|
+
after: query.after,
|
|
40
|
+
before: query.before,
|
|
41
|
+
q: query.q,
|
|
42
|
+
limit: query.limit !== undefined ? String(query.limit) : undefined,
|
|
43
|
+
cursor: query.cursor,
|
|
44
|
+
}, passport(options));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A file a message carries (`content.attachments[].file_id`), read through the message: the same answer as `drive.read`
|
|
48
|
+
* (UTF-8 text as text, anything else as base64, 256 KiB at most), including for a file that belongs to another agent of
|
|
49
|
+
* the customer whose messages the caller may read. The content is untrusted.
|
|
50
|
+
*/
|
|
51
|
+
async readAttachment(accountId, messageId, fileId, options) {
|
|
52
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/messages/${seg(messageId)}/attachments/${seg(fileId)}`, undefined, passport(options));
|
|
53
|
+
}
|
|
54
|
+
/** Owner or admin only. */
|
|
55
|
+
async delete(accountId, messageId) {
|
|
56
|
+
await this.client.delete(`/v1/accounts/${seg(accountId)}/messages/${seg(messageId)}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The customer's do-not-contact list: numbers that texted STOP and numbers the customer or an agent added. Texts and calls
|
|
61
|
+
* to a listed number are refused (`RecipientOptedOutError`). The owner, an admin or an agent's credential may list and add;
|
|
62
|
+
* only the owner or an admin removes.
|
|
63
|
+
*/
|
|
64
|
+
export class AccountOptOutsService {
|
|
65
|
+
client;
|
|
66
|
+
constructor(client) {
|
|
67
|
+
this.client = client;
|
|
68
|
+
}
|
|
69
|
+
/** Every number that asked not to be contacted. An agent may read it. */
|
|
70
|
+
async list() {
|
|
71
|
+
return this.client.get('/v1/opt-outs');
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Add a number (E.164) to the list, so texts and calls to it are refused. The owner, an admin or the account's agent may add.
|
|
75
|
+
* A number already listed returns its entry as it is.
|
|
76
|
+
*/
|
|
77
|
+
async add(number) {
|
|
78
|
+
return this.client.post('/v1/opt-outs', { number });
|
|
79
|
+
}
|
|
80
|
+
/** Take a number off the list, by the id `list` returned, so texts and calls to it are allowed again. */
|
|
81
|
+
async remove(optOutId) {
|
|
82
|
+
return this.client.delete(`/v1/opt-outs/${seg(optOutId)}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The customer's blocked-callers list: an incoming call from a listed number is turned away before it rings, wakes no
|
|
87
|
+
* agent, takes no voicemail and costs nothing. The owner, an admin or an agent's credential may list and add; only the
|
|
88
|
+
* owner or an admin removes.
|
|
89
|
+
*/
|
|
90
|
+
export class AccountBlockedCallersService {
|
|
91
|
+
client;
|
|
92
|
+
constructor(client) {
|
|
93
|
+
this.client = client;
|
|
94
|
+
}
|
|
95
|
+
/** Every blocked number. An agent may read it. */
|
|
96
|
+
async list() {
|
|
97
|
+
return this.client.get('/v1/blocked-callers');
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Block a number (E.164). The owner, an admin or the account's agent may add. A number already listed returns its entry
|
|
101
|
+
* as it is.
|
|
102
|
+
*/
|
|
103
|
+
async add(number) {
|
|
104
|
+
return this.client.post('/v1/blocked-callers', { number });
|
|
105
|
+
}
|
|
106
|
+
/** Take a number off the list, by the id `list` returned, so its calls ring again. The owner or an admin. */
|
|
107
|
+
async remove(blockedCallerId) {
|
|
108
|
+
return this.client.delete(`/v1/blocked-callers/${seg(blockedCallerId)}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** The phone provider's toll-free verification for the account's toll-free number, which must be approved before it texts. */
|
|
112
|
+
export class AccountTollFreeVerificationService {
|
|
113
|
+
client;
|
|
114
|
+
constructor(client) {
|
|
115
|
+
this.client = client;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Submit the owner's business details. Account admin only, and a governance
|
|
119
|
+
* action: without a dashboard session this throws
|
|
120
|
+
* `GovernanceApprovalRequiredError`; retry with the same details and its `approvalId`.
|
|
121
|
+
*/
|
|
122
|
+
async submit(accountId, details, options) {
|
|
123
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/phone/toll-free-verification`, details, governed(options));
|
|
124
|
+
}
|
|
125
|
+
/** The verification's status. Operator only. */
|
|
126
|
+
async get(accountId) {
|
|
127
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/phone/toll-free-verification`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export class AccountCallsService {
|
|
131
|
+
client;
|
|
132
|
+
constructor(client) {
|
|
133
|
+
this.client = client;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Place a live call from the account's number to any country Twilio can reach, at cost. Any agent of the customer may
|
|
137
|
+
* place it under its own Passport. Without `brief` the agent holds the call: STACK runs no model and says nothing, the
|
|
138
|
+
* call opens with `greeting` or with silence, and this returns once the call is answered (with what the other side
|
|
139
|
+
* first says, waiting up to `wait_seconds`) or ends unanswered. With `on_behalf_of` and `brief` STACK's model holds the
|
|
140
|
+
* call and this returns at once. One action; the minutes (and a held call's model turns) are charged to the account's
|
|
141
|
+
* budget. A number on the do-not-contact list is refused (`RecipientOptedOutError`), as is one Twilio has no price for
|
|
142
|
+
* or does not allow (`DestinationNotAvailableError`).
|
|
143
|
+
*/
|
|
144
|
+
async place(accountId, input, options) {
|
|
145
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/calls`, input, passport(options));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Answer a call that is ringing on the account's number, held either way as for `place`. A call rings for 30 seconds,
|
|
149
|
+
* then goes to voicemail; `answer_by` on the call says when, and a wake for the source `incoming_call` carries the call
|
|
150
|
+
* id. One action, put to your decider as `call.answer`. A call that is not ringing any more answers 409
|
|
151
|
+
* `CALL_NOT_RINGING` and is not counted.
|
|
152
|
+
*/
|
|
153
|
+
async answer(accountId, callId, input, options) {
|
|
154
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/calls/${seg(callId)}/answer`, input, passport(options));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Decline a call that is ringing on the account's number: the call is
|
|
158
|
+
* hung up with nothing said. Not an action on the meter.
|
|
159
|
+
* A call that is not ringing any more answers 409 `CALL_NOT_RINGING`.
|
|
160
|
+
*/
|
|
161
|
+
async decline(accountId, callId, options) {
|
|
162
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/calls/${seg(callId)}/decline`, undefined, passport(options));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Speak on a call the agent holds: `text` is spoken as it is (none: only waits), then this waits up to `wait_seconds`
|
|
166
|
+
* (0 to 60, default 30) for the other side's next finished sentence. Returns every event since your last call action.
|
|
167
|
+
* Not metered. A call STACK holds is 409 `CALL_HELD_BY_STACK`; one not on the line 409 `CALL_NOT_LIVE`.
|
|
168
|
+
*/
|
|
169
|
+
async say(accountId, callId, input = {}, options) {
|
|
170
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/calls/${seg(callId)}/say`, input, passport(options));
|
|
171
|
+
}
|
|
172
|
+
/** Send keys to the other side as tones: 0-9, `*`, `#`, and `w` for a pause. */
|
|
173
|
+
async pressKeys(accountId, callId, digits, options) {
|
|
174
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/calls/${seg(callId)}/keys`, { digits }, passport(options));
|
|
175
|
+
}
|
|
176
|
+
/** A new voice or language for the rest of a call the agent holds. */
|
|
177
|
+
async setCallVoice(accountId, callId, voice, options) {
|
|
178
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/calls/${seg(callId)}/voice`, { voice }, passport(options));
|
|
179
|
+
}
|
|
180
|
+
/** Hang up a call, whoever holds it. STACK says nothing. The transcript is stored and the account's agent woken. */
|
|
181
|
+
async hangUp(accountId, callId, options) {
|
|
182
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/calls/${seg(callId)}/hang-up`, undefined, passport(options));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The live stream of a call (a WebSocket): every event of the call as it happens, and the agent's words streamed on to
|
|
186
|
+
* the call as they come (`text(token, last)`). The socket closes once the call has ended. In Node the global
|
|
187
|
+
* `WebSocket` (Node 22 or later) is used, with the client's credential in the `Authorization` header; pass
|
|
188
|
+
* `webSocket` to use another implementation that takes headers the same way.
|
|
189
|
+
*/
|
|
190
|
+
async live(accountId, callId, options = {}) {
|
|
191
|
+
const Socket = options.webSocket ?? globalThis.WebSocket;
|
|
192
|
+
if (!Socket)
|
|
193
|
+
throw new Error('No WebSocket implementation: use Node 22 or later, or pass webSocket');
|
|
194
|
+
const url = `${this.client.apiBaseUrl.replace(/^http/, 'ws')}/v1/accounts/${seg(accountId)}/calls/${seg(callId)}/live`;
|
|
195
|
+
const headers = { Authorization: await this.client.authorizationHeader() };
|
|
196
|
+
if (options.passportToken)
|
|
197
|
+
headers['X-Passport-Token'] = options.passportToken;
|
|
198
|
+
return new AccountCallStream(new Socket(url, { headers }));
|
|
199
|
+
}
|
|
200
|
+
/** The account's calls, newest first. */
|
|
201
|
+
async list(accountId, query = {}, options) {
|
|
202
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/calls`, {
|
|
203
|
+
limit: query.limit !== undefined ? String(query.limit) : undefined,
|
|
204
|
+
cursor: query.cursor,
|
|
205
|
+
}, passport(options));
|
|
206
|
+
}
|
|
207
|
+
/** One call: its live transcript while it is on the line, then its stored transcript and outcome. */
|
|
208
|
+
async get(accountId, callId, options) {
|
|
209
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/calls/${seg(callId)}`, undefined, passport(options));
|
|
210
|
+
}
|
|
211
|
+
/** The account's call voice and voicemail greeting. The owner, an admin or the account's own agent. */
|
|
212
|
+
async getAccountVoice(accountId, options) {
|
|
213
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/phone/voice`, undefined, passport(options));
|
|
214
|
+
}
|
|
215
|
+
/** Set the account's call voice and voicemail greeting; a field left out is cleared. Not metered, no approval. */
|
|
216
|
+
async setAccountVoice(accountId, input, options) {
|
|
217
|
+
return this.client.put(`/v1/accounts/${seg(accountId)}/phone/voice`, input, passport(options));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* A call's live stream. `events()` yields every event of the call in order, ending after `ended`; `errors` are the
|
|
222
|
+
* messages the stream could not use. Send with `text`, `pressKeys`, `setVoice` and `hangUp`.
|
|
223
|
+
*/
|
|
224
|
+
export class AccountCallStream {
|
|
225
|
+
socket;
|
|
226
|
+
queue = [];
|
|
227
|
+
waiting = null;
|
|
228
|
+
done = false;
|
|
229
|
+
opened;
|
|
230
|
+
errors = [];
|
|
231
|
+
constructor(socket) {
|
|
232
|
+
this.socket = socket;
|
|
233
|
+
this.opened = new Promise((resolve, reject) => {
|
|
234
|
+
socket.addEventListener('open', () => resolve());
|
|
235
|
+
socket.addEventListener('error', () => reject(new Error('The live stream could not be opened')));
|
|
236
|
+
});
|
|
237
|
+
// A rejection nobody awaits is not an unhandled one: `send` awaits it.
|
|
238
|
+
this.opened.catch(() => undefined);
|
|
239
|
+
socket.addEventListener('message', (event) => {
|
|
240
|
+
let parsed;
|
|
241
|
+
try {
|
|
242
|
+
parsed = JSON.parse(String(event.data));
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const message = parsed;
|
|
248
|
+
if (message.type === 'error')
|
|
249
|
+
this.errors.push({ code: String(message.code), message: String(message.message) });
|
|
250
|
+
else
|
|
251
|
+
this.queue.push(parsed);
|
|
252
|
+
this.wake();
|
|
253
|
+
});
|
|
254
|
+
socket.addEventListener('close', () => {
|
|
255
|
+
this.done = true;
|
|
256
|
+
this.wake();
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
wake() {
|
|
260
|
+
const waiting = this.waiting;
|
|
261
|
+
this.waiting = null;
|
|
262
|
+
waiting?.();
|
|
263
|
+
}
|
|
264
|
+
/** Every event of the call, oldest first from the start of the call, until it ends. */
|
|
265
|
+
async *events() {
|
|
266
|
+
for (;;) {
|
|
267
|
+
const next = this.queue.shift();
|
|
268
|
+
if (next) {
|
|
269
|
+
yield next;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (this.done)
|
|
273
|
+
return;
|
|
274
|
+
await new Promise((resolve) => {
|
|
275
|
+
this.waiting = resolve;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async send(message) {
|
|
280
|
+
await this.opened;
|
|
281
|
+
this.socket.send(JSON.stringify(message));
|
|
282
|
+
}
|
|
283
|
+
/** Words to speak, streamed as they come; `last` on the final token of what the agent says. */
|
|
284
|
+
async text(token, last = false) {
|
|
285
|
+
await this.send({ type: 'text', token, last });
|
|
286
|
+
}
|
|
287
|
+
async pressKeys(digits) {
|
|
288
|
+
await this.send({ type: 'keys', digits });
|
|
289
|
+
}
|
|
290
|
+
async setVoice(voice) {
|
|
291
|
+
await this.send({ type: 'voice', voice });
|
|
292
|
+
}
|
|
293
|
+
async hangUp() {
|
|
294
|
+
await this.send({ type: 'hang_up' });
|
|
295
|
+
}
|
|
296
|
+
close() {
|
|
297
|
+
this.socket.close(1000, 'done');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Paid tools: data endpoints of a paid-tools provider, used by the account's agent
|
|
302
|
+
* under its Passport. Discover and inspect are free; a run holds the worst
|
|
303
|
+
* case first and is charged at the provider's cost from the account's credit.
|
|
304
|
+
*/
|
|
305
|
+
export class AccountToolsService {
|
|
306
|
+
client;
|
|
307
|
+
constructor(client) {
|
|
308
|
+
this.client = client;
|
|
309
|
+
}
|
|
310
|
+
async discover(accountId, input, options) {
|
|
311
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/tools/discover`, input, passport(options));
|
|
312
|
+
}
|
|
313
|
+
/** The endpoint's input schema and price. */
|
|
314
|
+
async inspect(accountId, input, options) {
|
|
315
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/tools/inspect`, input, passport(options));
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Run any endpoint the tool provider lists (the catalogue lists them as tools),
|
|
319
|
+
* charged what the provider reports for the run, with no STACK fee. Its worst
|
|
320
|
+
* case is held first, or an estimate where the price and the input do not bound
|
|
321
|
+
* it (`price_type` `ESTIMATED`); a cost above the hold is taken from the
|
|
322
|
+
* account's credit at once; `max_cost_cents` lowers the hold. A run whose
|
|
323
|
+
* `max_results` is outside 1 to 1000 is refused with `TOOL_PRICE_REFUSED`;
|
|
324
|
+
* nothing is held then.
|
|
325
|
+
* A run whose charge is not yet settled comes back `pending`; read it with `getRun`. */
|
|
326
|
+
async run(accountId, input, options) {
|
|
327
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/tools/run`, input, passport(options));
|
|
328
|
+
}
|
|
329
|
+
async getRun(accountId, runId, options) {
|
|
330
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/tools/runs/${seg(runId)}`, undefined, passport(options));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* The keys an account signs its outbound requests with, so that a site that
|
|
335
|
+
* checks for AI agents can tell whose they are (Web Bot Auth). STACK signs the
|
|
336
|
+
* requests its proxy and cloud browser make for the account's agent, and
|
|
337
|
+
* publishes the public keys at `/.well-known/http-message-signatures-directory`
|
|
338
|
+
* (and, for this account alone, under its agent's id: see `accounts.identity`).
|
|
339
|
+
*/
|
|
340
|
+
export class AccountSigningKeysService {
|
|
341
|
+
client;
|
|
342
|
+
constructor(client) {
|
|
343
|
+
this.client = client;
|
|
344
|
+
}
|
|
345
|
+
/** The key in use and any retired one still published. */
|
|
346
|
+
async list(accountId) {
|
|
347
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/signing-keys`);
|
|
348
|
+
}
|
|
349
|
+
/** A new key signs from now on; the old one stays published for two days. Owner or admin only, never the agent. */
|
|
350
|
+
async rotate(accountId) {
|
|
351
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/signing-keys/rotate`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* What STACK's public answer to "who is this agent?" shows for an account (the lookup is
|
|
356
|
+
* `stack.agentIdentity`). Two switches, both the owner's, never the agent's: `enabled` (on by
|
|
357
|
+
* default) and `show_name` (off by default). Changing one is a row of the account's signed record.
|
|
358
|
+
*/
|
|
359
|
+
export class AccountIdentityService {
|
|
360
|
+
client;
|
|
361
|
+
constructor(client) {
|
|
362
|
+
this.client = client;
|
|
363
|
+
}
|
|
364
|
+
async get(accountId) {
|
|
365
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/identity`);
|
|
366
|
+
}
|
|
367
|
+
/** Show or hide the agent's name, or switch the answer off or on. Owner or admin only, never an agent. */
|
|
368
|
+
async update(accountId, input) {
|
|
369
|
+
return this.client.put(`/v1/accounts/${seg(accountId)}/identity`, input);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* The account's workspace: a machine of its own with a shell and git, with its own internet access, that keeps its
|
|
374
|
+
* files between commands. The agent's calls run under its Passport. The account id of every call is the account that
|
|
375
|
+
* owns the workspace: another agent of the same customer may run commands and read and write files in it while the
|
|
376
|
+
* customer shares it with their agents (the default), under its own Passport and Mission, as its own action; only
|
|
377
|
+
* the machine's time is charged to the owning account. Only the owning account's agent makes a workspace or stops one
|
|
378
|
+
* (the owner may stop it too); listing is open to any principal of the operator. Machine time is held before it
|
|
379
|
+
* starts and charged to the owning account's credit.
|
|
380
|
+
*/
|
|
381
|
+
export class AccountWorkspaceService {
|
|
382
|
+
client;
|
|
383
|
+
constructor(client) {
|
|
384
|
+
this.client = client;
|
|
385
|
+
}
|
|
386
|
+
base(accountId) {
|
|
387
|
+
return `/v1/accounts/${seg(accountId)}/workspaces`;
|
|
388
|
+
}
|
|
389
|
+
async exec(accountId, input, options) {
|
|
390
|
+
return this.client.post(`${this.base(accountId)}/exec`, input, passport(options));
|
|
391
|
+
}
|
|
392
|
+
/** A command started in the background: whether it has ended, its exit code, and what it has printed so far. The workspace must be running. */
|
|
393
|
+
async command(accountId, workspaceId, commandId, options) {
|
|
394
|
+
return this.client.post(`${this.base(accountId)}/${seg(workspaceId)}/commands/read`, { command_id: commandId }, passport(options));
|
|
395
|
+
}
|
|
396
|
+
async readFile(accountId, workspaceId, input, options) {
|
|
397
|
+
return this.client.post(`${this.base(accountId)}/${seg(workspaceId)}/files/read`, input, passport(options));
|
|
398
|
+
}
|
|
399
|
+
async writeFile(accountId, workspaceId, input, options) {
|
|
400
|
+
return this.client.post(`${this.base(accountId)}/${seg(workspaceId)}/files/write`, input, passport(options));
|
|
401
|
+
}
|
|
402
|
+
/** Save a file of the workspace to the account's drive. */
|
|
403
|
+
async saveFile(accountId, workspaceId, input, options) {
|
|
404
|
+
return this.client.post(`${this.base(accountId)}/${seg(workspaceId)}/files/save`, input, passport(options));
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* The workspaces that still exist and the caller may use. With an account, that account's: an agent sees all of its
|
|
408
|
+
* own account's and, of another agent's, only those shared with it. Without one, every workspace the caller may use
|
|
409
|
+
* across the customer's accounts (the owner sees all). Each says whose it is and whether it is shared.
|
|
410
|
+
*/
|
|
411
|
+
async list(accountId) {
|
|
412
|
+
return (await this.client.get(accountId ? this.base(accountId) : '/v1/workspaces')).workspaces;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Whether the customer's other agents may use one workspace (`shared` true, the default for every workspace) or only
|
|
416
|
+
* the agent that owns it (false: every other agent then finds no such workspace). Owner or admin only; an agent
|
|
417
|
+
* cannot change it. Never metered; a change is one audit row.
|
|
418
|
+
*/
|
|
419
|
+
async setSharing(accountId, workspaceId, shared) {
|
|
420
|
+
return this.client.put(`${this.base(accountId)}/${seg(workspaceId)}/sharing`, { shared });
|
|
421
|
+
}
|
|
422
|
+
/** Pause a workspace, or with `delete` delete it and its files. The owning account's agent and the owner only. */
|
|
423
|
+
async stop(accountId, workspaceId, input = {}) {
|
|
424
|
+
return this.client.post(`${this.base(accountId)}/${seg(workspaceId)}/stop`, input);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* The idle pause, the days a stopped workspace is kept and the number of workspaces, with what is in force: for one
|
|
428
|
+
* agent account (its own over the customer's default), or without an account the customer's default. Owner or admin
|
|
429
|
+
* only; an agent cannot read or change its own.
|
|
430
|
+
*/
|
|
431
|
+
async getSettings(accountId) {
|
|
432
|
+
return this.client.get(workspaceSettingsPath(accountId));
|
|
433
|
+
}
|
|
434
|
+
/** Change them, for one agent account or (without an account) the customer's default. Running workspaces take a new idle pause now. */
|
|
435
|
+
async setSettings(input, accountId) {
|
|
436
|
+
return this.client.put(workspaceSettingsPath(accountId), input);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function workspaceSettingsPath(accountId) {
|
|
440
|
+
return accountId ? `/v1/accounts/${seg(accountId)}/workspace/settings` : '/v1/workspace/settings';
|
|
441
|
+
}
|
|
442
|
+
export class AccountBrowserService {
|
|
443
|
+
client;
|
|
444
|
+
constructor(client) {
|
|
445
|
+
this.client = client;
|
|
446
|
+
}
|
|
447
|
+
session(accountId, sessionId) {
|
|
448
|
+
return `/v1/accounts/${seg(accountId)}/browser/sessions/${seg(sessionId)}`;
|
|
449
|
+
}
|
|
450
|
+
/** Start a session. `maxMinutes` (1 to 360, 30 when left out) is how long it may run; the credit held is sized to it. */
|
|
451
|
+
async startSession(accountId, options) {
|
|
452
|
+
const body = options?.maxMinutes === undefined ? undefined : { max_minutes: options.maxMinutes };
|
|
453
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/browser/sessions`, body, passport(options));
|
|
454
|
+
}
|
|
455
|
+
async navigate(accountId, sessionId, input, options) {
|
|
456
|
+
return this.client.post(`${this.session(accountId, sessionId)}/navigate`, input, passport(options));
|
|
457
|
+
}
|
|
458
|
+
async act(accountId, sessionId, input, options) {
|
|
459
|
+
return this.client.post(`${this.session(accountId, sessionId)}/act`, input, passport(options));
|
|
460
|
+
}
|
|
461
|
+
/** The page's main text and accessibility snapshot, scanned first; a page aimed at an agent comes back withheld with controls on, and with its flag with controls off. */
|
|
462
|
+
async read(accountId, sessionId, options) {
|
|
463
|
+
return this.client.post(`${this.session(accountId, sessionId)}/read`, undefined, passport(options));
|
|
464
|
+
}
|
|
465
|
+
async screenshot(accountId, sessionId, options) {
|
|
466
|
+
return this.client.post(`${this.session(accountId, sessionId)}/screenshot`, undefined, passport(options));
|
|
467
|
+
}
|
|
468
|
+
async endSession(accountId, sessionId) {
|
|
469
|
+
return this.client.delete(this.session(accountId, sessionId));
|
|
470
|
+
}
|
|
471
|
+
/** Reserve the budget and start a card payment the customer approves on their own device. */
|
|
472
|
+
async checkout(accountId, sessionId, input, options) {
|
|
473
|
+
return this.client.post(`${this.session(accountId, sessionId)}/checkout`, input, passport(options));
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
export class AccountPurchasesService {
|
|
477
|
+
client;
|
|
478
|
+
constructor(client) {
|
|
479
|
+
this.client = client;
|
|
480
|
+
}
|
|
481
|
+
async get(accountId, purchaseId) {
|
|
482
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/purchases/${seg(purchaseId)}`);
|
|
483
|
+
}
|
|
484
|
+
/** What the merchant's page showed after the customer approved. It never moves money. */
|
|
485
|
+
async reportMerchantResult(accountId, purchaseId, input, options) {
|
|
486
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/purchases/${seg(purchaseId)}/merchant-result`, input, passport(options));
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
export class AccountWalletService {
|
|
490
|
+
client;
|
|
491
|
+
constructor(client) {
|
|
492
|
+
this.client = client;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Pay from the account's wallet with a payment the agent signed with its own
|
|
496
|
+
* wallet key (`signWalletPayment`). STACK checks the budget, the caps and the
|
|
497
|
+
* customer's controls, then passes the request to the wallet provider
|
|
498
|
+
* unchanged, or refuses it (and a refused payment is never sent). STACK holds
|
|
499
|
+
* no key to the wallet. The agent's Passport is required.
|
|
500
|
+
*/
|
|
501
|
+
async pay(accountId, input, options) {
|
|
502
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/wallet/payments`, input, passport(options));
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Buy from an x402 seller in one step: ask `url`, and when the seller answers 402, make the payment it asks for,
|
|
506
|
+
* sign it with the agent's own wallet `key` (here, never sent anywhere), pay through STACK (the same checks as
|
|
507
|
+
* `pay`) and ask again with the payment attached. The seller's answer is what was bought. An answer that is not
|
|
508
|
+
* a 402 comes back unpaid. Only USDC on Base with x402's `exact` scheme can be paid (x402 versions 1 and 2); any
|
|
509
|
+
* other ask, a price over `maxCents` or a URL that is not https is refused with `X402PaymentError` before STACK is
|
|
510
|
+
* asked. The agent's Passport is required.
|
|
511
|
+
*/
|
|
512
|
+
async payUrl(accountId, url, options) {
|
|
513
|
+
assertPayableUrl(url);
|
|
514
|
+
const account = await this.client.get(`/v1/accounts/${seg(accountId)}`, undefined, passport(options));
|
|
515
|
+
return payX402(url, {
|
|
516
|
+
...options,
|
|
517
|
+
wallet: x402WalletOf(account.pieces),
|
|
518
|
+
pay: (input) => this.pay(accountId, input, options),
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Set or change a wallet's caps after it is open (owner or admin, needs controls; an agent context is refused). A cap left
|
|
523
|
+
* out is not changed and `null` removes it. `signer_policy` says what the wallet provider's own rule, fixed when the wallet
|
|
524
|
+
* opened, still holds per payment.
|
|
525
|
+
*/
|
|
526
|
+
async setCaps(accountId, caps) {
|
|
527
|
+
return this.client.put(`/v1/accounts/${seg(accountId)}/wallet/caps`, caps);
|
|
528
|
+
}
|
|
529
|
+
/** Whether the customer has become the owner of their agents' wallets (done at the STACK console). */
|
|
530
|
+
async ownerStatus() {
|
|
531
|
+
return this.client.get('/v1/accounts/wallet-owner');
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* The customer's own mail domains for agent inboxes. An account opened with
|
|
536
|
+
* `inbox: { domain }` gets its inbox there once the domain is verified.
|
|
537
|
+
* Operator only; an agent context is refused. There is no remove call: an
|
|
538
|
+
* unverified claim lapses on its own (`claim_expires_at`).
|
|
539
|
+
*/
|
|
540
|
+
export class AccountMailDomainsService {
|
|
541
|
+
client;
|
|
542
|
+
constructor(client) {
|
|
543
|
+
this.client = client;
|
|
544
|
+
}
|
|
545
|
+
/** Every connected domain, with its records and status. */
|
|
546
|
+
async list() {
|
|
547
|
+
return this.client.get('/v1/accounts/mail-domains');
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Connect a domain and get the DNS records to publish. Needs the platform
|
|
551
|
+
* subscription (`PLATFORM_SUBSCRIPTION_REQUIRED` otherwise) and an owner or
|
|
552
|
+
* admin. Connecting the same name again returns the same domain; a name
|
|
553
|
+
* another customer holds is a 409.
|
|
554
|
+
*/
|
|
555
|
+
async connect(input) {
|
|
556
|
+
return this.client.post('/v1/accounts/mail-domains', input);
|
|
557
|
+
}
|
|
558
|
+
/** Ask the mail provider to check the domain's DNS records now. Owner or admin. */
|
|
559
|
+
async verify(domainId) {
|
|
560
|
+
return this.client.post(`/v1/accounts/mail-domains/${seg(domainId)}/verify`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* An agent's own Telegram bot: its identity on Telegram. `start` returns a link
|
|
565
|
+
* the owner opens in Telegram to have STACK's manager bot make the bot (no
|
|
566
|
+
* BotFather, no pasted token); or you make the bot with BotFather and give
|
|
567
|
+
* STACK its token once with `connect`. People write to it, what they write
|
|
568
|
+
* arrives with the account's other messages (`messages.list({ channel:
|
|
569
|
+
* 'telegram' })`, scanned like mail and texts), and the agent answers with
|
|
570
|
+
* `accounts.sendTelegram`. A bot cannot message a chat first.
|
|
571
|
+
*
|
|
572
|
+
* Operator only: an agent context is refused. The token is sent once, to STACK's
|
|
573
|
+
* own route, and never returned; no OAuth token may connect a bot (the secret
|
|
574
|
+
* would pass through a chat), so use an API key or the console.
|
|
575
|
+
*/
|
|
576
|
+
export class AccountTelegramService {
|
|
577
|
+
client;
|
|
578
|
+
constructor(client) {
|
|
579
|
+
this.client = client;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Ask for the agent's bot to be made through STACK's Telegram manager bot. Returns `create_url`, which the
|
|
583
|
+
* owner opens in Telegram and confirms: nothing is created until then, and STACK reads the new bot's token
|
|
584
|
+
* itself. The link is single-use and lasts 10 minutes. Throws `NOT_CONFIGURED` when the deployment has no
|
|
585
|
+
* manager bot: use `connect` then.
|
|
586
|
+
*/
|
|
587
|
+
async start(accountId, input = {}) {
|
|
588
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/telegram/start`, input);
|
|
589
|
+
}
|
|
590
|
+
/** Give the agent its bot. `botToken` is the token BotFather gave you. */
|
|
591
|
+
async connect(accountId, botToken) {
|
|
592
|
+
return this.client.put(`/v1/accounts/${seg(accountId)}/telegram`, { bot_token: botToken });
|
|
593
|
+
}
|
|
594
|
+
/** The agent's bot. Throws a 404 `NOT_FOUND` when it has none. */
|
|
595
|
+
async get(accountId) {
|
|
596
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/telegram`);
|
|
597
|
+
}
|
|
598
|
+
/** The chats that have written to the bot, which the agent may answer. */
|
|
599
|
+
async chats(accountId) {
|
|
600
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}/telegram/chats`);
|
|
601
|
+
}
|
|
602
|
+
/** Take the bot away: STACK removes its webhook and stops receiving. */
|
|
603
|
+
async disconnect(accountId) {
|
|
604
|
+
await this.client.delete(`/v1/accounts/${seg(accountId)}/telegram`);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
export class AccountsService {
|
|
608
|
+
client;
|
|
609
|
+
telegram;
|
|
610
|
+
messages;
|
|
611
|
+
optOuts;
|
|
612
|
+
blockedCallers;
|
|
613
|
+
tollFreeVerification;
|
|
614
|
+
calls;
|
|
615
|
+
tools;
|
|
616
|
+
workspace;
|
|
617
|
+
browser;
|
|
618
|
+
purchases;
|
|
619
|
+
wallet;
|
|
620
|
+
mailDomains;
|
|
621
|
+
signingKeys;
|
|
622
|
+
identity;
|
|
623
|
+
/** Making: designs, quotes and orders with manufacturing and print-on-demand suppliers. */
|
|
624
|
+
making;
|
|
625
|
+
constructor(client) {
|
|
626
|
+
this.client = client;
|
|
627
|
+
this.telegram = new AccountTelegramService(client);
|
|
628
|
+
this.messages = new AccountMessagesService(client);
|
|
629
|
+
this.optOuts = new AccountOptOutsService(client);
|
|
630
|
+
this.blockedCallers = new AccountBlockedCallersService(client);
|
|
631
|
+
this.tollFreeVerification = new AccountTollFreeVerificationService(client);
|
|
632
|
+
this.calls = new AccountCallsService(client);
|
|
633
|
+
this.tools = new AccountToolsService(client);
|
|
634
|
+
this.workspace = new AccountWorkspaceService(client);
|
|
635
|
+
this.browser = new AccountBrowserService(client);
|
|
636
|
+
this.purchases = new AccountPurchasesService(client);
|
|
637
|
+
this.wallet = new AccountWalletService(client);
|
|
638
|
+
this.mailDomains = new AccountMailDomainsService(client);
|
|
639
|
+
this.signingKeys = new AccountSigningKeysService(client);
|
|
640
|
+
this.identity = new AccountIdentityService(client);
|
|
641
|
+
this.making = new MakingService(client);
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Open an agent account. 201 when created, 200 when the same key already
|
|
645
|
+
* opened it. Without a dashboard session this throws
|
|
646
|
+
* `GovernanceApprovalRequiredError` first; retry with its `approvalId`.
|
|
647
|
+
*/
|
|
648
|
+
async open(input, options) {
|
|
649
|
+
const key = options.idempotencyKey;
|
|
650
|
+
if (typeof key !== 'string' || key.length < 8 || key.length > 128) {
|
|
651
|
+
throw new TypeError('idempotencyKey must be 8 to 128 characters');
|
|
652
|
+
}
|
|
653
|
+
return this.client.post('/v1/accounts', input, {
|
|
654
|
+
headers: {
|
|
655
|
+
'Idempotency-Key': key,
|
|
656
|
+
...(options.governanceApprovalId ? { 'X-Governance-Approval': options.governanceApprovalId } : {}),
|
|
657
|
+
},
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
async get(accountId) {
|
|
661
|
+
return this.client.get(`/v1/accounts/${seg(accountId)}`);
|
|
662
|
+
}
|
|
663
|
+
async list(query = {}) {
|
|
664
|
+
return this.client.get('/v1/accounts', {
|
|
665
|
+
limit: query.limit !== undefined ? String(query.limit) : undefined,
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Set, change or remove (`null`) the account's monthly spend budget, USD cents, a positive whole number. Owner or
|
|
670
|
+
* admin only, never metered. Lowering applies at once. Raising or removing is a governance action: without a
|
|
671
|
+
* dashboard session this throws `GovernanceApprovalRequiredError` first; once the owner approves at its link, send
|
|
672
|
+
* the same call again with `governanceApprovalId`. Setting or raising needs controls (`CONTROLS_REQUIRED` otherwise).
|
|
673
|
+
*/
|
|
674
|
+
async setBudget(accountId, monthlyBudgetCents, options) {
|
|
675
|
+
if (monthlyBudgetCents !== null && (!Number.isSafeInteger(monthlyBudgetCents) || monthlyBudgetCents <= 0)) {
|
|
676
|
+
throw new TypeError('monthlyBudgetCents must be a positive whole number of cents, or null to remove the budget');
|
|
677
|
+
}
|
|
678
|
+
return this.client.put(`/v1/accounts/${seg(accountId)}/budget`, { monthly_budget_cents: monthlyBudgetCents }, governed(options));
|
|
679
|
+
}
|
|
680
|
+
/** Refuse the agent at once and close every piece at its provider. No approval needed. */
|
|
681
|
+
async close(accountId) {
|
|
682
|
+
return this.client.delete(`/v1/accounts/${seg(accountId)}`);
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Send an email to one or several people, with copies and attachments. The mail provider takes one To address, so
|
|
686
|
+
* further `to` addresses are delivered as Cc. Attach a drive file by `file_id` or a small file inline as base64.
|
|
687
|
+
*/
|
|
688
|
+
async sendEmail(accountId, input, options) {
|
|
689
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/email/send`, input, passport(options));
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Answer an email the account received (`messageId` is its message id), in its thread, quoting that message unless
|
|
693
|
+
* `include_quote` is `false`. `reply_all` also reaches everyone it was sent to. A message that cannot be answered throws `EmailMessageNotAnswerableError`.
|
|
694
|
+
*/
|
|
695
|
+
async replyEmail(accountId, messageId, input, options) {
|
|
696
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/messages/${seg(messageId)}/reply`, input, passport(options));
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Send an email the account received on to others, as a new email in no thread, with its text unless `include_quote`
|
|
700
|
+
* is `false` and, unless `include_attachments` is `false`, the attachments that were kept.
|
|
701
|
+
*/
|
|
702
|
+
async forwardEmail(accountId, messageId, input, options) {
|
|
703
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/messages/${seg(messageId)}/forward`, input, passport(options));
|
|
704
|
+
}
|
|
705
|
+
async sendSms(accountId, input, options) {
|
|
706
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/sms/send`, input, passport(options));
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Answer a chat on the agent's own Telegram bot. The chat must have written
|
|
710
|
+
* to the bot first (`TelegramSendRefusedError` with reason `chat_unknown`
|
|
711
|
+
* otherwise); the same admission, controls and data-flow rule as a text. Only the account's own agent (or the owner) sends from its bot.
|
|
712
|
+
*/
|
|
713
|
+
async sendTelegram(accountId, input, options) {
|
|
714
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/telegram/messages`, input, passport(options));
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Lift a pause on the inbox or phone. Owner or admin only; it applies at
|
|
718
|
+
* once and asks no one.
|
|
719
|
+
*/
|
|
720
|
+
async resumePiece(accountId, piece) {
|
|
721
|
+
return this.client.post(`/v1/accounts/${seg(accountId)}/pieces/resume`, { piece });
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
//# sourceMappingURL=accounts.js.map
|