@stacklink/sdk 0.2.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 +9 -0
- package/README.md +50 -0
- package/compatibility.json +30 -0
- package/dist/src/domain/knowledge-meta-tools.d.ts +12 -0
- package/dist/src/domain/knowledge-meta-tools.d.ts.map +1 -0
- package/dist/src/domain/knowledge-meta-tools.js +38 -0
- package/dist/src/domain/knowledge-meta-tools.js.map +1 -0
- package/dist/src/domain/memory-contract.d.ts +3399 -0
- package/dist/src/domain/memory-contract.d.ts.map +1 -0
- package/dist/src/domain/memory-contract.js +931 -0
- package/dist/src/domain/memory-contract.js.map +1 -0
- package/dist/src/domain/memory-meta-tools.d.ts +5 -0
- package/dist/src/domain/memory-meta-tools.d.ts.map +1 -0
- package/dist/src/domain/memory-meta-tools.js +18 -0
- package/dist/src/domain/memory-meta-tools.js.map +1 -0
- package/dist/src/domain/platform-mcp-tools.d.ts +3 -0
- package/dist/src/domain/platform-mcp-tools.d.ts.map +1 -0
- package/dist/src/domain/platform-mcp-tools.js +30 -0
- package/dist/src/domain/platform-mcp-tools.js.map +1 -0
- package/dist/src/domain/provider-branding.d.ts +27 -0
- package/dist/src/domain/provider-branding.d.ts.map +1 -0
- package/dist/src/domain/provider-branding.js +256 -0
- package/dist/src/domain/provider-branding.js.map +1 -0
- package/dist/src/domain/stacklink-meta-tools.d.ts +80 -0
- package/dist/src/domain/stacklink-meta-tools.d.ts.map +1 -0
- package/dist/src/domain/stacklink-meta-tools.js +456 -0
- package/dist/src/domain/stacklink-meta-tools.js.map +1 -0
- package/dist/src/sdk/claude-agent.d.ts +14 -0
- package/dist/src/sdk/claude-agent.d.ts.map +1 -0
- package/dist/src/sdk/claude-agent.js +15 -0
- package/dist/src/sdk/claude-agent.js.map +1 -0
- package/dist/src/sdk/framework-tools.d.ts +19 -0
- package/dist/src/sdk/framework-tools.d.ts.map +1 -0
- package/dist/src/sdk/framework-tools.js +26 -0
- package/dist/src/sdk/framework-tools.js.map +1 -0
- package/dist/src/sdk/index.d.ts +3443 -0
- package/dist/src/sdk/index.d.ts.map +1 -0
- package/dist/src/sdk/index.js +2782 -0
- package/dist/src/sdk/index.js.map +1 -0
- package/dist/src/sdk/langchain.d.ts +9 -0
- package/dist/src/sdk/langchain.d.ts.map +1 -0
- package/dist/src/sdk/langchain.js +11 -0
- package/dist/src/sdk/langchain.js.map +1 -0
- package/dist/src/sdk/memory-lifecycle.d.ts +75 -0
- package/dist/src/sdk/memory-lifecycle.d.ts.map +1 -0
- package/dist/src/sdk/memory-lifecycle.js +128 -0
- package/dist/src/sdk/memory-lifecycle.js.map +1 -0
- package/dist/src/sdk/openai-agents.d.ts +45 -0
- package/dist/src/sdk/openai-agents.d.ts.map +1 -0
- package/dist/src/sdk/openai-agents.js +182 -0
- package/dist/src/sdk/openai-agents.js.map +1 -0
- package/dist/src/sdk/openai.d.ts +12 -0
- package/dist/src/sdk/openai.d.ts.map +1 -0
- package/dist/src/sdk/openai.js +271 -0
- package/dist/src/sdk/openai.js.map +1 -0
- package/dist/src/sdk/vercel-ai.d.ts +11 -0
- package/dist/src/sdk/vercel-ai.d.ts.map +1 -0
- package/dist/src/sdk/vercel-ai.js +226 -0
- package/dist/src/sdk/vercel-ai.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,2782 @@
|
|
|
1
|
+
import { materializeStacklinkWorkbenchExecutionResponse, } from '../domain/stacklink-meta-tools.js';
|
|
2
|
+
import { platformMcpTools } from '../domain/platform-mcp-tools.js';
|
|
3
|
+
export { StacklinkMemoryLifecycle, StacklinkMemoryLifecycleError, createStacklinkMemoryLifecycle, serializeCompletedConversationTurn, } from './memory-lifecycle.js';
|
|
4
|
+
export const platformToolSurfaceNames = platformMcpTools;
|
|
5
|
+
export const stacklinkTypeScriptSdkVersion = '0.2.0';
|
|
6
|
+
const workbenchReusableRunComparisonWaitMs = 120_000;
|
|
7
|
+
const workbenchReusableRunComparisonPollMs = 1_000;
|
|
8
|
+
export class StacklinkApiError extends Error {
|
|
9
|
+
statusCode;
|
|
10
|
+
code;
|
|
11
|
+
details;
|
|
12
|
+
constructor(message, statusCode, code, details) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.statusCode = statusCode;
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.details = details;
|
|
17
|
+
this.name = 'StacklinkApiError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function withoutCacheControl(input) {
|
|
21
|
+
const { cache: _cache, ...rest } = input;
|
|
22
|
+
return rest;
|
|
23
|
+
}
|
|
24
|
+
function discoveryServerBody(input) {
|
|
25
|
+
const body = withoutCacheControl(input);
|
|
26
|
+
if (input.cache === 'bypass')
|
|
27
|
+
body.cache = 'bypass';
|
|
28
|
+
return body;
|
|
29
|
+
}
|
|
30
|
+
function stableSdkStringify(value) {
|
|
31
|
+
if (value === null || typeof value !== 'object')
|
|
32
|
+
return JSON.stringify(value);
|
|
33
|
+
if (Array.isArray(value))
|
|
34
|
+
return `[${value.map(stableSdkStringify).join(',')}]`;
|
|
35
|
+
const record = value;
|
|
36
|
+
return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${stableSdkStringify(record[key])}`).join(',')}}`;
|
|
37
|
+
}
|
|
38
|
+
function uniqueSdkStrings(values) {
|
|
39
|
+
return Array.from(new Set(values));
|
|
40
|
+
}
|
|
41
|
+
function normalizeKnowledgePackSelection(value) {
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
return { enable: value.filter((entry) => typeof entry === 'string' && entry.length > 0), disable: [] };
|
|
44
|
+
}
|
|
45
|
+
if (value && typeof value === 'object') {
|
|
46
|
+
const record = value;
|
|
47
|
+
return {
|
|
48
|
+
enable: Array.isArray(record.enable) ? record.enable.filter((entry) => typeof entry === 'string' && entry.length > 0) : [],
|
|
49
|
+
disable: Array.isArray(record.disable) ? record.disable.filter((entry) => typeof entry === 'string' && entry.length > 0) : [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return { enable: [], disable: [] };
|
|
53
|
+
}
|
|
54
|
+
function sleep(ms) {
|
|
55
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
56
|
+
}
|
|
57
|
+
export async function verifyWebhookSignature(input) {
|
|
58
|
+
const timestampSeconds = Number(input.timestamp);
|
|
59
|
+
if (!Number.isFinite(timestampSeconds))
|
|
60
|
+
return false;
|
|
61
|
+
const toleranceSeconds = input.toleranceSeconds ?? 300;
|
|
62
|
+
const nowSeconds = Math.floor((input.now ?? new Date()).getTime() / 1000);
|
|
63
|
+
if (Math.abs(nowSeconds - timestampSeconds) > toleranceSeconds)
|
|
64
|
+
return false;
|
|
65
|
+
const expected = await hmacSha256Base64(input.secret, `${input.id}.${input.timestamp}.${input.body}`);
|
|
66
|
+
for (const candidate of signatureCandidates(input.signature)) {
|
|
67
|
+
if (constantTimeStringEqual(candidate, expected))
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
function signatureCandidates(header) {
|
|
73
|
+
const candidates = [];
|
|
74
|
+
for (const entry of header.split(' ')) {
|
|
75
|
+
const parts = entry.split(',');
|
|
76
|
+
for (let index = 0; index < parts.length; index += 1) {
|
|
77
|
+
if (parts[index] === 'v1' && typeof parts[index + 1] === 'string') {
|
|
78
|
+
candidates.push(parts[index + 1] ?? '');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return candidates;
|
|
83
|
+
}
|
|
84
|
+
async function hmacSha256Base64(secret, value) {
|
|
85
|
+
const cryptoImpl = globalThis.crypto;
|
|
86
|
+
if (cryptoImpl?.subtle) {
|
|
87
|
+
const key = await cryptoImpl.subtle.importKey('raw', utf8(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
88
|
+
const signature = await cryptoImpl.subtle.sign('HMAC', key, utf8(value));
|
|
89
|
+
return base64Encode(new Uint8Array(signature));
|
|
90
|
+
}
|
|
91
|
+
const { createHmac } = await import('node:crypto');
|
|
92
|
+
return createHmac('sha256', secret).update(value).digest('base64');
|
|
93
|
+
}
|
|
94
|
+
function constantTimeStringEqual(left, right) {
|
|
95
|
+
const leftBytes = utf8(left);
|
|
96
|
+
const rightBytes = utf8(right);
|
|
97
|
+
let diff = leftBytes.length ^ rightBytes.length;
|
|
98
|
+
const maxLength = Math.max(leftBytes.length, rightBytes.length);
|
|
99
|
+
for (let index = 0; index < maxLength; index += 1) {
|
|
100
|
+
diff |= (leftBytes[index] ?? 0) ^ (rightBytes[index] ?? 0);
|
|
101
|
+
}
|
|
102
|
+
return diff === 0;
|
|
103
|
+
}
|
|
104
|
+
function utf8(value) {
|
|
105
|
+
return new TextEncoder().encode(value);
|
|
106
|
+
}
|
|
107
|
+
function base64Encode(bytes) {
|
|
108
|
+
if (typeof btoa === 'function') {
|
|
109
|
+
let binary = '';
|
|
110
|
+
for (const byte of bytes)
|
|
111
|
+
binary += String.fromCharCode(byte);
|
|
112
|
+
return btoa(binary);
|
|
113
|
+
}
|
|
114
|
+
return Buffer.from(bytes).toString('base64');
|
|
115
|
+
}
|
|
116
|
+
export class Stacklink {
|
|
117
|
+
apiKey;
|
|
118
|
+
registrationKey;
|
|
119
|
+
baseUrl;
|
|
120
|
+
fetchImpl;
|
|
121
|
+
cacheOptions;
|
|
122
|
+
responseCache = new Map();
|
|
123
|
+
webhooks;
|
|
124
|
+
triggers;
|
|
125
|
+
sessions;
|
|
126
|
+
logs;
|
|
127
|
+
apiKeys;
|
|
128
|
+
connectedAccounts;
|
|
129
|
+
authConfigs;
|
|
130
|
+
toolkits;
|
|
131
|
+
tools;
|
|
132
|
+
billing;
|
|
133
|
+
memory;
|
|
134
|
+
constructor(options) {
|
|
135
|
+
this.apiKey = options.apiKey;
|
|
136
|
+
this.registrationKey = options.registrationKey;
|
|
137
|
+
this.baseUrl = options.baseUrl.endsWith('/') ? options.baseUrl.slice(0, -1) : options.baseUrl;
|
|
138
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
139
|
+
this.cacheOptions = {
|
|
140
|
+
enabled: options.cache?.enabled ?? true,
|
|
141
|
+
toolsListTtlMs: options.cache?.toolsListTtlMs ?? 300_000,
|
|
142
|
+
toolkitsTtlMs: options.cache?.toolkitsTtlMs ?? 300_000,
|
|
143
|
+
schemasTtlMs: options.cache?.schemasTtlMs ?? 1_800_000,
|
|
144
|
+
searchTtlMs: options.cache?.searchTtlMs ?? 120_000,
|
|
145
|
+
maxEntries: options.cache?.maxEntries ?? 500,
|
|
146
|
+
};
|
|
147
|
+
this.webhooks = new StacklinkWebhooksClient(this);
|
|
148
|
+
this.triggers = new StacklinkTriggersClient(this);
|
|
149
|
+
this.sessions = new StacklinkSessionsClient(this);
|
|
150
|
+
this.logs = new StacklinkLogsClient(this);
|
|
151
|
+
this.apiKeys = new StacklinkApiKeysClient(this);
|
|
152
|
+
this.connectedAccounts = new StacklinkConnectedAccountsClient(this);
|
|
153
|
+
this.authConfigs = new StacklinkAuthConfigsClient(this);
|
|
154
|
+
this.toolkits = new StacklinkToolkitsClient(this);
|
|
155
|
+
this.tools = new StacklinkProviderToolsClient(this);
|
|
156
|
+
this.billing = new StacklinkBillingClient(this);
|
|
157
|
+
this.memory = new StacklinkMemoryClient(this);
|
|
158
|
+
}
|
|
159
|
+
sessionMcpConnection(descriptor) {
|
|
160
|
+
return {
|
|
161
|
+
url: descriptor.url,
|
|
162
|
+
headers: {
|
|
163
|
+
...descriptor.headers,
|
|
164
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
async create(input) {
|
|
169
|
+
const response = await this.request('/v1/sessions', {
|
|
170
|
+
method: 'POST',
|
|
171
|
+
body: {
|
|
172
|
+
externalTenantId: input.tenantId,
|
|
173
|
+
externalUserId: input.userId,
|
|
174
|
+
tenantDisplayName: input.tenantDisplayName,
|
|
175
|
+
userDisplayName: input.userDisplayName,
|
|
176
|
+
userEmail: input.userEmail,
|
|
177
|
+
scopes: input.scopes ?? [],
|
|
178
|
+
toolRouter: input.toolRouter,
|
|
179
|
+
preset: input.preset,
|
|
180
|
+
preload: input.preload,
|
|
181
|
+
toolkits: input.toolkits,
|
|
182
|
+
tools: input.tools,
|
|
183
|
+
authConfigs: input.authConfigs,
|
|
184
|
+
connectedAccounts: input.connectedAccounts,
|
|
185
|
+
multiAccount: input.multiAccount,
|
|
186
|
+
workbench: input.workbench,
|
|
187
|
+
knowledgePacks: input.knowledgePacks,
|
|
188
|
+
memory: input.memory,
|
|
189
|
+
metaTools: input.metaTools,
|
|
190
|
+
metadata: input.metadata ?? {},
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
const projection = await this.getSessionMetaTools(response.session.id);
|
|
194
|
+
return new ToolRouterSession(this, response.session.id, response.session.tenantId, response.session.mcp, projection.contractVersion, projection.tools);
|
|
195
|
+
}
|
|
196
|
+
async use(sessionId) {
|
|
197
|
+
const response = await this.getSession(sessionId);
|
|
198
|
+
const projection = await this.getSessionMetaTools(sessionId);
|
|
199
|
+
return new ToolRouterSession(this, response.session.id, response.session.tenantId, response.session.mcp, projection.contractVersion, projection.tools);
|
|
200
|
+
}
|
|
201
|
+
clearCache(prefix) {
|
|
202
|
+
if (!prefix) {
|
|
203
|
+
this.responseCache.clear();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
for (const key of this.responseCache.keys()) {
|
|
207
|
+
if (key.startsWith(prefix))
|
|
208
|
+
this.responseCache.delete(key);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async listSessions(query = {}) {
|
|
212
|
+
return this.request('/v1/sessions', { query: { ...query } });
|
|
213
|
+
}
|
|
214
|
+
async getSession(sessionId) {
|
|
215
|
+
return this.request(`/v1/sessions/${sessionId}`);
|
|
216
|
+
}
|
|
217
|
+
async updateSession(sessionId, patch) {
|
|
218
|
+
const response = await this.request(`/v1/sessions/${sessionId}`, {
|
|
219
|
+
method: 'PATCH',
|
|
220
|
+
body: patch,
|
|
221
|
+
});
|
|
222
|
+
this.clearCache(`session:${sessionId}:`);
|
|
223
|
+
return response;
|
|
224
|
+
}
|
|
225
|
+
async closeSession(sessionId) {
|
|
226
|
+
return this.request(`/v1/sessions/${sessionId}/close`, {
|
|
227
|
+
method: 'POST',
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async failSession(sessionId, input = {}) {
|
|
231
|
+
return this.request(`/v1/sessions/${sessionId}/fail`, {
|
|
232
|
+
method: 'POST',
|
|
233
|
+
body: input,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
async listSessionRouterFacts(sessionId, query = {}) {
|
|
237
|
+
return this.request(`/v1/sessions/${sessionId}/router-facts`, { query });
|
|
238
|
+
}
|
|
239
|
+
async listSessionConnectionEvents(sessionId) {
|
|
240
|
+
return this.request(`/v1/sessions/${sessionId}/connection-events`);
|
|
241
|
+
}
|
|
242
|
+
async getSessionTrace(sessionId, query = {}) {
|
|
243
|
+
return this.request(`/v1/sessions/${sessionId}/trace`, { query });
|
|
244
|
+
}
|
|
245
|
+
async getSessionConfigHistory(sessionId, query = {}) {
|
|
246
|
+
return this.request(`/v1/sessions/${sessionId}/config-history`, { query });
|
|
247
|
+
}
|
|
248
|
+
async getSessionWorkbench(sessionId) {
|
|
249
|
+
return this.request(`/v1/sessions/${sessionId}/workbench`);
|
|
250
|
+
}
|
|
251
|
+
async getSessionMetaTools(sessionId) {
|
|
252
|
+
return this.request(`/v1/sessions/${sessionId}/meta-tools`);
|
|
253
|
+
}
|
|
254
|
+
async createApiKey(input) {
|
|
255
|
+
return this.request('/v1/api-keys', {
|
|
256
|
+
method: 'POST',
|
|
257
|
+
body: input,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
async deleteApiKey(apiKeyId) {
|
|
261
|
+
return this.request(`/v1/api-keys/${apiKeyId}`, {
|
|
262
|
+
method: 'DELETE',
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
async listProviders() {
|
|
266
|
+
return this.request('/v1/providers');
|
|
267
|
+
}
|
|
268
|
+
async listProjectProviders(query = {}) {
|
|
269
|
+
return this.request('/v1/project/providers', {
|
|
270
|
+
query: { tenantId: query.tenantId },
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
async listProviderTools(providerKey, input = {}) {
|
|
274
|
+
return this.request(`/v1/providers/${providerKey}/tools`, {
|
|
275
|
+
query: {
|
|
276
|
+
includePlanned: input.includePlanned === true ? 'true' : undefined,
|
|
277
|
+
responseMode: input.responseMode === 'compact' ? 'compact' : undefined,
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
async createProject(input) {
|
|
282
|
+
return this.request('/v1/projects', {
|
|
283
|
+
method: 'POST',
|
|
284
|
+
body: input,
|
|
285
|
+
registration: true,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
async listProjects(input = {}) {
|
|
289
|
+
return this.request('/v1/projects', {
|
|
290
|
+
query: {
|
|
291
|
+
status: input.status,
|
|
292
|
+
limit: input.limit,
|
|
293
|
+
cursor: input.cursor,
|
|
294
|
+
},
|
|
295
|
+
registration: input.registration,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
async getProject(projectId, input = {}) {
|
|
299
|
+
return this.request(`/v1/projects/${projectId}`, {
|
|
300
|
+
registration: input.registration,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
async resetProjectAuthConfigs(projectId) {
|
|
304
|
+
return this.request(`/v1/projects/${projectId}/auth-configs/reset`, {
|
|
305
|
+
method: 'POST',
|
|
306
|
+
registration: true,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async listProjectProviderAccess(projectId) {
|
|
310
|
+
return this.request(`/v1/projects/${projectId}/providers`, {
|
|
311
|
+
registration: false,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
async setProjectProviderAccess(projectId, providerKey, input = {}) {
|
|
315
|
+
return this.request(`/v1/projects/${projectId}/providers/${providerKey}`, {
|
|
316
|
+
method: 'PUT',
|
|
317
|
+
body: {
|
|
318
|
+
status: input.status ?? 'enabled',
|
|
319
|
+
enabledBy: input.enabledBy,
|
|
320
|
+
metadata: input.metadata ?? {},
|
|
321
|
+
},
|
|
322
|
+
registration: false,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
async inspectConnectToken(publicToken) {
|
|
326
|
+
return this.request(`/v1/connect/${publicToken}`);
|
|
327
|
+
}
|
|
328
|
+
async completeConnectToken(publicToken, input) {
|
|
329
|
+
return this.request(`/v1/connect/${publicToken}/complete`, {
|
|
330
|
+
method: 'POST',
|
|
331
|
+
body: input,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
async startOAuthConnect(publicToken) {
|
|
335
|
+
return this.request(`/v1/connect/${publicToken}/oauth/start`);
|
|
336
|
+
}
|
|
337
|
+
async getConnectionRequest(requestId) {
|
|
338
|
+
return this.request(`/v1/connection-requests/${requestId}`);
|
|
339
|
+
}
|
|
340
|
+
async searchTools(input) {
|
|
341
|
+
return this.request('/v1/tools/search', {
|
|
342
|
+
method: 'POST',
|
|
343
|
+
body: input,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
async getToolSchemas(input) {
|
|
347
|
+
return this.request('/v1/tools/schemas', {
|
|
348
|
+
method: 'POST',
|
|
349
|
+
body: input,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
async getRuntimeToolContracts(input) {
|
|
353
|
+
return this.request('/v1/tools/runtime-contracts', {
|
|
354
|
+
method: 'POST',
|
|
355
|
+
body: input,
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
async executeTool(input, options = {}) {
|
|
359
|
+
return this.request('/v1/tools/execute', {
|
|
360
|
+
method: 'POST',
|
|
361
|
+
body: input,
|
|
362
|
+
signal: options.signal,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
async executeToolsBatch(input, options = {}) {
|
|
366
|
+
return this.request('/v1/tools/execute-batch', {
|
|
367
|
+
method: 'POST',
|
|
368
|
+
body: input,
|
|
369
|
+
signal: options.signal,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
async getSubscription() {
|
|
373
|
+
return this.request('/v1/subscription');
|
|
374
|
+
}
|
|
375
|
+
async listBillingPlans() {
|
|
376
|
+
return this.request('/v1/billing/plans');
|
|
377
|
+
}
|
|
378
|
+
async getUsage() {
|
|
379
|
+
return this.request('/v1/usage');
|
|
380
|
+
}
|
|
381
|
+
async listUsageEvents(query = {}) {
|
|
382
|
+
return this.request('/v1/usage/events', { query });
|
|
383
|
+
}
|
|
384
|
+
async createBillingCheckout(input) {
|
|
385
|
+
return this.request('/v1/billing/checkout', {
|
|
386
|
+
method: 'POST',
|
|
387
|
+
body: input,
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
async createBillingPortal(input = {}) {
|
|
391
|
+
return this.request('/v1/billing/portal', {
|
|
392
|
+
method: 'POST',
|
|
393
|
+
body: input,
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
async setWorkspaceSubscriptionPlanForProject(projectId, input) {
|
|
397
|
+
return this.request(`/v1/projects/${projectId}/subscription/plan`, {
|
|
398
|
+
method: 'POST',
|
|
399
|
+
body: input,
|
|
400
|
+
registration: true,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
async listAuthConfigs(query = {}) {
|
|
404
|
+
return this.request('/v1/auth-configs', {
|
|
405
|
+
query: {
|
|
406
|
+
providerKey: query.providerKey,
|
|
407
|
+
includeDisabled: query.includeDisabled,
|
|
408
|
+
},
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
async createAuthConfig(input) {
|
|
412
|
+
return this.request('/v1/auth-configs', {
|
|
413
|
+
method: 'POST',
|
|
414
|
+
body: input,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
async workbenchModels() {
|
|
418
|
+
return this.request('/v1/workbench/models');
|
|
419
|
+
}
|
|
420
|
+
async runWorkbench(input, options = {}) {
|
|
421
|
+
const response = await this.request('/v1/workbench/run', {
|
|
422
|
+
method: 'POST',
|
|
423
|
+
body: input,
|
|
424
|
+
signal: options.signal,
|
|
425
|
+
});
|
|
426
|
+
this.attachAbortSignalCancellation(input, response, options.signal);
|
|
427
|
+
if (input.operation === 'run_code' && input.background !== true) {
|
|
428
|
+
return this.waitForWorkbenchResponse(input, response, options);
|
|
429
|
+
}
|
|
430
|
+
return response;
|
|
431
|
+
}
|
|
432
|
+
async useWorkbenchSession(input) {
|
|
433
|
+
return this.request('/v1/workbench/sessions', {
|
|
434
|
+
method: 'POST',
|
|
435
|
+
body: input,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
async deleteWorkbenchSession(input) {
|
|
439
|
+
return this.request(`/v1/workbench/sessions/${input.workbenchSessionId}`, {
|
|
440
|
+
method: 'DELETE',
|
|
441
|
+
query: { sessionId: input.sessionId },
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
async listWorkbenchFiles(input) {
|
|
445
|
+
return this.request(`/v1/workbench/sessions/${input.workbenchSessionId}/files`, { query: { sessionId: input.sessionId } });
|
|
446
|
+
}
|
|
447
|
+
async readWorkbenchFile(input) {
|
|
448
|
+
return this.request(`/v1/workbench/sessions/${input.workbenchSessionId}/files`, { query: { sessionId: input.sessionId, path: input.path } });
|
|
449
|
+
}
|
|
450
|
+
async uploadWorkbenchFile(input) {
|
|
451
|
+
return this.request(`/v1/workbench/sessions/${input.workbenchSessionId}/files`, {
|
|
452
|
+
method: 'PUT',
|
|
453
|
+
body: {
|
|
454
|
+
sessionId: input.sessionId,
|
|
455
|
+
path: input.path,
|
|
456
|
+
contentBase64: base64Encode(typeof input.content === 'string' ? utf8(input.content) : input.content),
|
|
457
|
+
contentType: input.contentType,
|
|
458
|
+
metadata: input.metadata,
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
async prepareWorkbenchFileUpload(input) {
|
|
463
|
+
return this.request(`/v1/workbench/sessions/${input.workbenchSessionId}/files/upload-url`, { method: 'POST', body: input });
|
|
464
|
+
}
|
|
465
|
+
async finalizeWorkbenchFileUpload(input) {
|
|
466
|
+
return this.request(`/v1/workbench/sessions/${input.workbenchSessionId}/files/finalize-upload`, { method: 'POST', body: input });
|
|
467
|
+
}
|
|
468
|
+
async uploadWorkbenchFileDirect(input) {
|
|
469
|
+
const content = typeof input.content === 'string' ? utf8(input.content) : input.content;
|
|
470
|
+
const contentType = input.contentType ?? (typeof input.content === 'string' ? 'text/plain; charset=utf-8' : 'application/octet-stream');
|
|
471
|
+
const prepared = await this.prepareWorkbenchFileUpload({
|
|
472
|
+
sessionId: input.sessionId,
|
|
473
|
+
workbenchSessionId: input.workbenchSessionId,
|
|
474
|
+
path: input.path,
|
|
475
|
+
contentType,
|
|
476
|
+
sizeBytes: content.byteLength,
|
|
477
|
+
});
|
|
478
|
+
const response = await this.fetchImpl(prepared.upload.uploadUrl, {
|
|
479
|
+
method: 'PUT',
|
|
480
|
+
headers: prepared.upload.requiredHeaders,
|
|
481
|
+
body: content,
|
|
482
|
+
});
|
|
483
|
+
if (!response.ok) {
|
|
484
|
+
throw new StacklinkApiError(`Workbench file upload failed with ${response.status}`, response.status, 'workbench_file_direct_upload_failed');
|
|
485
|
+
}
|
|
486
|
+
return this.finalizeWorkbenchFileUpload({
|
|
487
|
+
sessionId: input.sessionId,
|
|
488
|
+
workbenchSessionId: input.workbenchSessionId,
|
|
489
|
+
uploadId: prepared.upload.uploadId,
|
|
490
|
+
metadata: input.metadata,
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
async getWorkbenchFileDownload(input) {
|
|
494
|
+
return this.request(`/v1/workbench/sessions/${input.workbenchSessionId}/files/download-url`, { query: { sessionId: input.sessionId, path: input.path } });
|
|
495
|
+
}
|
|
496
|
+
async downloadWorkbenchFile(input) {
|
|
497
|
+
const signed = await this.getWorkbenchFileDownload(input);
|
|
498
|
+
const response = await this.fetchImpl(signed.downloadUrl);
|
|
499
|
+
if (!response.ok) {
|
|
500
|
+
throw new StacklinkApiError(`Workbench file download failed with ${response.status}`, response.status, 'workbench_file_download_failed');
|
|
501
|
+
}
|
|
502
|
+
return response;
|
|
503
|
+
}
|
|
504
|
+
async deleteWorkbenchFile(input) {
|
|
505
|
+
return this.request(`/v1/workbench/sessions/${input.workbenchSessionId}/files`, {
|
|
506
|
+
method: 'DELETE',
|
|
507
|
+
query: { sessionId: input.sessionId, path: input.path },
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
async createWorkbenchRunDefinition(input) {
|
|
511
|
+
return this.request('/v1/workbench/run-definitions', {
|
|
512
|
+
method: 'POST',
|
|
513
|
+
body: input,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
async listWorkbenchRunDefinitions(input) {
|
|
517
|
+
return this.request('/v1/workbench/run-definitions', {
|
|
518
|
+
query: input,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
async getWorkbenchRunDefinition(input) {
|
|
522
|
+
return this.request(`/v1/workbench/run-definitions/${input.runDefinitionId}`, { query: { sessionId: input.sessionId } });
|
|
523
|
+
}
|
|
524
|
+
async updateWorkbenchRunDefinition(input) {
|
|
525
|
+
return this.request(`/v1/workbench/run-definitions/${input.runDefinitionId}`, {
|
|
526
|
+
method: 'PATCH',
|
|
527
|
+
body: {
|
|
528
|
+
sessionId: input.sessionId,
|
|
529
|
+
name: input.name,
|
|
530
|
+
description: input.description,
|
|
531
|
+
versionReason: input.versionReason,
|
|
532
|
+
},
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
async replayWorkbenchRunDefinition(input) {
|
|
536
|
+
const accepted = await this.request(`/v1/workbench/run-definitions/${input.runDefinitionId}/replay`, {
|
|
537
|
+
method: 'POST',
|
|
538
|
+
body: {
|
|
539
|
+
sessionId: input.sessionId,
|
|
540
|
+
background: input.background,
|
|
541
|
+
timeoutMs: input.timeoutMs,
|
|
542
|
+
environmentMode: input.environmentMode,
|
|
543
|
+
idempotencyKey: input.idempotencyKey,
|
|
544
|
+
},
|
|
545
|
+
});
|
|
546
|
+
if (input.background === true)
|
|
547
|
+
return accepted;
|
|
548
|
+
const acceptedExecution = isSdkRecord(accepted.execution) ? accepted.execution : undefined;
|
|
549
|
+
if (!acceptedExecution)
|
|
550
|
+
return accepted;
|
|
551
|
+
const completedExecution = await this.waitForWorkbenchResponse({ sessionId: input.sessionId }, acceptedExecution);
|
|
552
|
+
const executionId = typeof completedExecution.executionId === 'string'
|
|
553
|
+
? completedExecution.executionId
|
|
554
|
+
: accepted.comparison.replayExecutionId;
|
|
555
|
+
let comparison = accepted.comparison;
|
|
556
|
+
const comparisonDeadline = Date.now() + workbenchReusableRunComparisonWaitMs;
|
|
557
|
+
while (Date.now() <= comparisonDeadline) {
|
|
558
|
+
const definition = await this.getWorkbenchRunDefinition({
|
|
559
|
+
sessionId: input.sessionId,
|
|
560
|
+
runDefinitionId: accepted.runDefinition.id,
|
|
561
|
+
});
|
|
562
|
+
const replay = definition.runDefinition.replays?.find((entry) => entry.executionId === executionId);
|
|
563
|
+
if (replay)
|
|
564
|
+
comparison = replay.comparison;
|
|
565
|
+
if (comparison.status === 'matched' || comparison.status === 'mismatched')
|
|
566
|
+
break;
|
|
567
|
+
if (Date.now() >= comparisonDeadline)
|
|
568
|
+
break;
|
|
569
|
+
await sleep(workbenchReusableRunComparisonPollMs);
|
|
570
|
+
}
|
|
571
|
+
const executionLog = isSdkRecord(completedExecution.executionLog) ? completedExecution.executionLog : undefined;
|
|
572
|
+
const executionMetadata = executionLog && isSdkRecord(executionLog.metadata) ? executionLog.metadata : undefined;
|
|
573
|
+
const environment = executionMetadata && isSdkRecord(executionMetadata.replayEnvironment)
|
|
574
|
+
? executionMetadata.replayEnvironment
|
|
575
|
+
: accepted.environment;
|
|
576
|
+
return {
|
|
577
|
+
...accepted,
|
|
578
|
+
execution: completedExecution,
|
|
579
|
+
environment: environment,
|
|
580
|
+
comparison,
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
async publishWorkbenchRunDefinition(input) {
|
|
584
|
+
return this.request(`/v1/workbench/run-definitions/${input.runDefinitionId}/publish`, { method: 'POST', body: { sessionId: input.sessionId, expectedPublishedVersion: input.expectedPublishedVersion } });
|
|
585
|
+
}
|
|
586
|
+
async rollbackWorkbenchRunDefinition(input) {
|
|
587
|
+
return this.request(`/v1/workbench/run-definitions/${input.runDefinitionId}/rollback`, { method: 'POST', body: { sessionId: input.sessionId, expectedPublishedVersion: input.expectedPublishedVersion } });
|
|
588
|
+
}
|
|
589
|
+
async destroyWorkbenchSession(input, options = {}) {
|
|
590
|
+
return this.runWorkbench({
|
|
591
|
+
sessionId: input.sessionId,
|
|
592
|
+
workbenchSessionId: input.workbenchSessionId,
|
|
593
|
+
operation: 'destroy',
|
|
594
|
+
}, options);
|
|
595
|
+
}
|
|
596
|
+
async runWorkbenchBash(input, options = {}) {
|
|
597
|
+
const response = await this.request('/v1/workbench/bash', {
|
|
598
|
+
method: 'POST',
|
|
599
|
+
body: input,
|
|
600
|
+
signal: options.signal,
|
|
601
|
+
});
|
|
602
|
+
this.attachAbortSignalCancellation(input, response, options.signal);
|
|
603
|
+
if (input.background !== true) {
|
|
604
|
+
return this.waitForWorkbenchResponse(input, response, options);
|
|
605
|
+
}
|
|
606
|
+
return response;
|
|
607
|
+
}
|
|
608
|
+
async waitForWorkbenchResponse(input, accepted, options = {}) {
|
|
609
|
+
const sessionId = typeof input.sessionId === 'string' ? input.sessionId : undefined;
|
|
610
|
+
const executionId = typeof accepted.executionId === 'string' ? accepted.executionId : undefined;
|
|
611
|
+
const executionKind = accepted.executionKind === 'workbench_code' || accepted.executionKind === 'workbench_bash'
|
|
612
|
+
? accepted.executionKind
|
|
613
|
+
: undefined;
|
|
614
|
+
if (!sessionId || !executionId || !executionKind)
|
|
615
|
+
return accepted;
|
|
616
|
+
while (true) {
|
|
617
|
+
const waited = await this.waitForExecution({
|
|
618
|
+
sessionId,
|
|
619
|
+
executionKind,
|
|
620
|
+
executionId,
|
|
621
|
+
waitTimeoutMs: 10_000,
|
|
622
|
+
pollIntervalMs: 500,
|
|
623
|
+
}, options);
|
|
624
|
+
const execution = isSdkRecord(waited.execution) ? waited.execution : undefined;
|
|
625
|
+
if (execution && isTerminalSdkExecution(execution)) {
|
|
626
|
+
return materializeStacklinkWorkbenchExecutionResponse(accepted, execution);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
async listExecutions(input, options = {}) {
|
|
631
|
+
return this.request('/v1/executions', {
|
|
632
|
+
query: {
|
|
633
|
+
sessionId: input.sessionId,
|
|
634
|
+
executionKind: input.executionKind,
|
|
635
|
+
workbenchSessionId: input.workbenchSessionId,
|
|
636
|
+
status: input.status,
|
|
637
|
+
cursor: input.cursor,
|
|
638
|
+
limit: input.limit,
|
|
639
|
+
},
|
|
640
|
+
signal: options.signal,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
async getExecution(input, options = {}) {
|
|
644
|
+
return this.request(`/v1/executions/${input.executionKind}/${input.executionId}`, {
|
|
645
|
+
query: {
|
|
646
|
+
sessionId: input.sessionId,
|
|
647
|
+
includeEvents: input.includeEvents,
|
|
648
|
+
eventLimit: input.eventLimit,
|
|
649
|
+
},
|
|
650
|
+
signal: options.signal,
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
async readExecutionEvents(input, options = {}) {
|
|
654
|
+
return this.request(`/v1/executions/${input.executionKind}/${input.executionId}/events`, {
|
|
655
|
+
query: {
|
|
656
|
+
sessionId: input.sessionId,
|
|
657
|
+
afterSequence: input.afterSequence === undefined ? undefined : String(input.afterSequence),
|
|
658
|
+
limit: input.limit,
|
|
659
|
+
},
|
|
660
|
+
signal: options.signal,
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
async waitForExecution(input, options = {}) {
|
|
664
|
+
return this.request(`/v1/executions/${input.executionKind}/${input.executionId}/wait`, {
|
|
665
|
+
method: 'POST',
|
|
666
|
+
body: {
|
|
667
|
+
sessionId: input.sessionId,
|
|
668
|
+
waitTimeoutMs: input.waitTimeoutMs,
|
|
669
|
+
pollIntervalMs: input.pollIntervalMs,
|
|
670
|
+
},
|
|
671
|
+
signal: options.signal,
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
async cancelExecution(input, options = {}) {
|
|
675
|
+
return this.request(`/v1/executions/${input.executionKind}/${input.executionId}/cancel`, {
|
|
676
|
+
method: 'POST',
|
|
677
|
+
body: {
|
|
678
|
+
sessionId: input.sessionId,
|
|
679
|
+
reason: input.reason,
|
|
680
|
+
},
|
|
681
|
+
signal: options.signal,
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
async getAuthConfig(authConfigId) {
|
|
685
|
+
return this.request(`/v1/auth-configs/${authConfigId}`);
|
|
686
|
+
}
|
|
687
|
+
async updateAuthConfig(authConfigId, patch) {
|
|
688
|
+
return this.request(`/v1/auth-configs/${authConfigId}`, {
|
|
689
|
+
method: 'PATCH',
|
|
690
|
+
body: patch,
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
async enableAuthConfig(authConfigId) {
|
|
694
|
+
return this.request(`/v1/auth-configs/${authConfigId}/enable`, {
|
|
695
|
+
method: 'POST',
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
async disableAuthConfig(authConfigId) {
|
|
699
|
+
return this.request(`/v1/auth-configs/${authConfigId}/disable`, {
|
|
700
|
+
method: 'POST',
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
async deleteAuthConfig(authConfigId) {
|
|
704
|
+
return this.request(`/v1/auth-configs/${authConfigId}`, {
|
|
705
|
+
method: 'DELETE',
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
async listConnectedAccounts(tenantId) {
|
|
709
|
+
return this.request('/v1/connections', {
|
|
710
|
+
query: { tenantId },
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
async createConnectedAccount(input) {
|
|
714
|
+
return this.request('/v1/connections', {
|
|
715
|
+
method: 'POST',
|
|
716
|
+
body: input,
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
async getConnectedAccount(accountId) {
|
|
720
|
+
return this.request(`/v1/connections/${accountId}`);
|
|
721
|
+
}
|
|
722
|
+
async listConnectedAccountTools(accountId, input = {}) {
|
|
723
|
+
return this.request(`/v1/connections/${accountId}/tools`, {
|
|
724
|
+
query: {
|
|
725
|
+
...(input.includePlanned !== undefined ? { includePlanned: String(input.includePlanned) } : {}),
|
|
726
|
+
...(input.toolKeys ? { toolKeys: input.toolKeys } : {}),
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
async listConnectedAccountResources(accountId, input = {}) {
|
|
731
|
+
return this.request(`/v1/connections/${accountId}/resources`, {
|
|
732
|
+
query: {
|
|
733
|
+
search: input.search,
|
|
734
|
+
resourceKey: input.resourceKey,
|
|
735
|
+
resourceKinds: input.resourceKinds,
|
|
736
|
+
cursor: input.cursor,
|
|
737
|
+
limit: input.limit,
|
|
738
|
+
},
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
async refreshConnectedAccountResources(accountId, input = {}) {
|
|
742
|
+
return this.request(`/v1/connections/${accountId}/resources/refresh`, {
|
|
743
|
+
method: 'POST',
|
|
744
|
+
query: {
|
|
745
|
+
search: input.search,
|
|
746
|
+
resourceKey: input.resourceKey,
|
|
747
|
+
resourceKinds: input.resourceKinds,
|
|
748
|
+
cursor: input.cursor,
|
|
749
|
+
limit: input.limit,
|
|
750
|
+
},
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
async resolveConnectedAccountResource(accountId, input) {
|
|
754
|
+
return this.request(`/v1/connections/${accountId}/resources/resolve`, { method: 'POST', body: input });
|
|
755
|
+
}
|
|
756
|
+
async updateConnectedAccount(accountId, patch) {
|
|
757
|
+
return this.request(`/v1/connections/${accountId}`, {
|
|
758
|
+
method: 'PATCH',
|
|
759
|
+
body: patch,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
async enableConnectedAccount(accountId) {
|
|
763
|
+
return this.request(`/v1/connections/${accountId}/enable`, {
|
|
764
|
+
method: 'POST',
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
async disableConnectedAccount(accountId) {
|
|
768
|
+
return this.request(`/v1/connections/${accountId}/disable`, {
|
|
769
|
+
method: 'POST',
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
async refreshConnectedAccount(accountId) {
|
|
773
|
+
return this.request(`/v1/connections/${accountId}/refresh`, {
|
|
774
|
+
method: 'POST',
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
async validateConnectedAccount(accountId) {
|
|
778
|
+
return this.request(`/v1/connections/${accountId}/validate`, {
|
|
779
|
+
method: 'POST',
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
async deleteConnectedAccount(accountId) {
|
|
783
|
+
return this.request(`/v1/connections/${accountId}`, {
|
|
784
|
+
method: 'DELETE',
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
async listConnectedAccountSecrets(accountId) {
|
|
788
|
+
return this.request(`/v1/connections/${accountId}/secrets`);
|
|
789
|
+
}
|
|
790
|
+
async runConnectionHealthCheck(input = {}) {
|
|
791
|
+
return this.request('/v1/connections/health/run', {
|
|
792
|
+
method: 'POST',
|
|
793
|
+
body: input,
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
async listTriggerTypes(query = {}) {
|
|
797
|
+
return this.request('/v1/triggers/types', {
|
|
798
|
+
query: { providerKey: query.providerKey },
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
async listTriggerSubscriptions(query = {}) {
|
|
802
|
+
return this.request('/v1/triggers/subscriptions', {
|
|
803
|
+
query: { ...query },
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
async createTriggerSubscription(input) {
|
|
807
|
+
return this.request('/v1/triggers/subscriptions', {
|
|
808
|
+
method: 'POST',
|
|
809
|
+
body: input,
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
async getTriggerSubscription(subscriptionId) {
|
|
813
|
+
return this.request(`/v1/triggers/subscriptions/${subscriptionId}`);
|
|
814
|
+
}
|
|
815
|
+
async updateTriggerSubscription(subscriptionId, patch) {
|
|
816
|
+
return this.request(`/v1/triggers/subscriptions/${subscriptionId}`, {
|
|
817
|
+
method: 'PATCH',
|
|
818
|
+
body: patch,
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
async deleteTriggerSubscription(subscriptionId) {
|
|
822
|
+
return this.request(`/v1/triggers/subscriptions/${subscriptionId}`, {
|
|
823
|
+
method: 'DELETE',
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
async listWebhookEventTypes() {
|
|
827
|
+
return this.request('/v1/webhook/event-types');
|
|
828
|
+
}
|
|
829
|
+
async getWebhook() {
|
|
830
|
+
return this.request('/v1/webhook');
|
|
831
|
+
}
|
|
832
|
+
async updateWebhook(input) {
|
|
833
|
+
return this.request('/v1/webhook', {
|
|
834
|
+
method: 'PUT',
|
|
835
|
+
body: input,
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
async rotateWebhookSecret() {
|
|
839
|
+
return this.request('/v1/webhook/rotate-secret', {
|
|
840
|
+
method: 'POST',
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
async sendWebhookTest(input) {
|
|
844
|
+
return this.request('/v1/webhook/test', {
|
|
845
|
+
method: 'POST',
|
|
846
|
+
body: input,
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
async verifyWebhookSignature(input) {
|
|
850
|
+
return verifyWebhookSignature(input);
|
|
851
|
+
}
|
|
852
|
+
async replayProviderEvent(eventId) {
|
|
853
|
+
return this.request(`/v1/events/${eventId}/replay`, {
|
|
854
|
+
method: 'POST',
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
async retryWebhookDelivery(deliveryId, input = {}) {
|
|
858
|
+
return this.request(`/v1/webhook-deliveries/${deliveryId}/retry`, {
|
|
859
|
+
method: 'POST',
|
|
860
|
+
body: input,
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
async redriveDeadLetterWebhookDeliveries(input = {}) {
|
|
864
|
+
return this.request('/v1/webhook-deliveries/dead-letter/redrive', {
|
|
865
|
+
method: 'POST',
|
|
866
|
+
body: input,
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
async runTriggerPoller(input = {}) {
|
|
870
|
+
return this.request('/v1/triggers/poll/run', {
|
|
871
|
+
method: 'POST',
|
|
872
|
+
body: input,
|
|
873
|
+
registration: true,
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
async runTriggerDeliveries(input = {}) {
|
|
877
|
+
return this.request('/v1/triggers/deliveries/run', {
|
|
878
|
+
method: 'POST',
|
|
879
|
+
body: input,
|
|
880
|
+
registration: true,
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
async getProviderArtifact(artifactId) {
|
|
884
|
+
return this.request(`/v1/artifacts/${artifactId}`);
|
|
885
|
+
}
|
|
886
|
+
async getLogSummary(query = {}) {
|
|
887
|
+
return this.request('/v1/logs/summary', { query });
|
|
888
|
+
}
|
|
889
|
+
async listRequestLogs(query = {}) {
|
|
890
|
+
return this.request('/v1/logs/requests', { query });
|
|
891
|
+
}
|
|
892
|
+
async getRequestLog(logId) {
|
|
893
|
+
return this.request(`/v1/logs/requests/${logId}`);
|
|
894
|
+
}
|
|
895
|
+
async listToolLogs(query = {}) {
|
|
896
|
+
return this.request('/v1/logs/tools', { query });
|
|
897
|
+
}
|
|
898
|
+
async getToolLog(logId) {
|
|
899
|
+
return this.request(`/v1/logs/tools/${logId}`);
|
|
900
|
+
}
|
|
901
|
+
async listTriggerLogs(query = {}) {
|
|
902
|
+
return this.request('/v1/logs/triggers', { query });
|
|
903
|
+
}
|
|
904
|
+
async getTriggerLog(logId) {
|
|
905
|
+
return this.request(`/v1/logs/triggers/${logId}`);
|
|
906
|
+
}
|
|
907
|
+
async listWebhookDeliveries(query = {}) {
|
|
908
|
+
return this.request('/v1/logs/webhook-deliveries', { query });
|
|
909
|
+
}
|
|
910
|
+
async getWebhookDeliveryLog(deliveryId) {
|
|
911
|
+
return this.request(`/v1/logs/webhook-deliveries/${deliveryId}`);
|
|
912
|
+
}
|
|
913
|
+
async listWorkbenchSessions(query = {}) {
|
|
914
|
+
return this.request('/v1/workbench/sessions', {
|
|
915
|
+
query: {
|
|
916
|
+
tenantId: query.tenantId,
|
|
917
|
+
platformSessionId: query.platformSessionId,
|
|
918
|
+
status: query.status,
|
|
919
|
+
limit: query.limit,
|
|
920
|
+
},
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
async getWorkbenchSession(workbenchSessionId) {
|
|
924
|
+
return this.request(`/v1/workbench/sessions/${workbenchSessionId}`);
|
|
925
|
+
}
|
|
926
|
+
async getWorkbenchUsage(workbenchSessionId) {
|
|
927
|
+
return this.request(`/v1/workbench/sessions/${workbenchSessionId}/usage`);
|
|
928
|
+
}
|
|
929
|
+
async listWorkbenchArtifacts(query = {}) {
|
|
930
|
+
return this.request('/v1/workbench/artifacts', {
|
|
931
|
+
query: {
|
|
932
|
+
tenantId: query.tenantId,
|
|
933
|
+
workbenchSessionId: query.workbenchSessionId,
|
|
934
|
+
status: query.status,
|
|
935
|
+
limit: query.limit,
|
|
936
|
+
},
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
async getWorkbenchArtifactDownloadUrl(artifactId) {
|
|
940
|
+
return this.request(`/v1/workbench/artifacts/${artifactId}/download-url`);
|
|
941
|
+
}
|
|
942
|
+
async downloadWorkbenchArtifact(artifactId) {
|
|
943
|
+
return this.requestRaw(`/v1/workbench/artifacts/${artifactId}/download`);
|
|
944
|
+
}
|
|
945
|
+
async promoteWorkbenchArtifact(input) {
|
|
946
|
+
return this.request('/v1/workbench/artifacts', {
|
|
947
|
+
method: 'POST',
|
|
948
|
+
body: input,
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
async deleteWorkbenchArtifact(input) {
|
|
952
|
+
return this.request(`/v1/workbench/artifacts/${input.artifactId}`, {
|
|
953
|
+
method: 'DELETE',
|
|
954
|
+
query: {
|
|
955
|
+
sessionId: input.sessionId,
|
|
956
|
+
workbenchSessionId: input.workbenchSessionId,
|
|
957
|
+
path: input.path,
|
|
958
|
+
},
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
async listWorkbenchBudgets(query = {}) {
|
|
962
|
+
return this.request('/v1/workbench/budgets', {
|
|
963
|
+
query: {
|
|
964
|
+
tenantId: query.tenantId,
|
|
965
|
+
workbenchSessionId: query.workbenchSessionId,
|
|
966
|
+
status: query.status,
|
|
967
|
+
limit: query.limit,
|
|
968
|
+
},
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
async createWorkbenchBudget(input) {
|
|
972
|
+
return this.request('/v1/workbench/budgets', {
|
|
973
|
+
method: 'POST',
|
|
974
|
+
body: input,
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
async updateWorkbenchBudget(budgetPolicyId, patch) {
|
|
978
|
+
return this.request(`/v1/workbench/budgets/${budgetPolicyId}`, {
|
|
979
|
+
method: 'PATCH',
|
|
980
|
+
body: patch,
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
async deleteWorkbenchBudget(budgetPolicyId) {
|
|
984
|
+
return this.request(`/v1/workbench/budgets/${budgetPolicyId}`, {
|
|
985
|
+
method: 'DELETE',
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
async mcpRequest(input, options = {}) {
|
|
989
|
+
return this.mcpRequestAtPath('/v1/mcp', input, options);
|
|
990
|
+
}
|
|
991
|
+
async mcpSessionRequest(sessionId, input, options = {}) {
|
|
992
|
+
return this.mcpRequestAtPath(`/v1/sessions/${encodeURIComponent(sessionId)}/mcp`, input, options);
|
|
993
|
+
}
|
|
994
|
+
async mcpRequestAtPath(path, input, options = {}) {
|
|
995
|
+
return this.request(path, {
|
|
996
|
+
method: 'POST',
|
|
997
|
+
body: input,
|
|
998
|
+
signal: options.signal,
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
async mcpRequestStream(input, options = {}) {
|
|
1002
|
+
return this.mcpRequestStreamAtPath('/v1/mcp', input, options);
|
|
1003
|
+
}
|
|
1004
|
+
async mcpSessionRequestStream(sessionId, input, options = {}) {
|
|
1005
|
+
return this.mcpRequestStreamAtPath(`/v1/sessions/${encodeURIComponent(sessionId)}/mcp`, input, options);
|
|
1006
|
+
}
|
|
1007
|
+
async mcpRequestStreamAtPath(path, input, options = {}) {
|
|
1008
|
+
let completed = false;
|
|
1009
|
+
const cancel = () => {
|
|
1010
|
+
if (completed)
|
|
1011
|
+
return;
|
|
1012
|
+
const requestId = input.id;
|
|
1013
|
+
if (typeof requestId !== 'string' && typeof requestId !== 'number')
|
|
1014
|
+
return;
|
|
1015
|
+
void this.mcpRequestAtPath(path, {
|
|
1016
|
+
jsonrpc: '2.0',
|
|
1017
|
+
method: 'notifications/cancelled',
|
|
1018
|
+
params: {
|
|
1019
|
+
requestId,
|
|
1020
|
+
reason: 'sdk_abort_signal',
|
|
1021
|
+
},
|
|
1022
|
+
}).catch(() => undefined);
|
|
1023
|
+
};
|
|
1024
|
+
if (options.signal?.aborted) {
|
|
1025
|
+
cancel();
|
|
1026
|
+
}
|
|
1027
|
+
else {
|
|
1028
|
+
options.signal?.addEventListener('abort', cancel, { once: true });
|
|
1029
|
+
}
|
|
1030
|
+
try {
|
|
1031
|
+
const response = await this.requestRaw(path, {
|
|
1032
|
+
method: 'POST',
|
|
1033
|
+
body: input,
|
|
1034
|
+
signal: options.signal,
|
|
1035
|
+
headers: {
|
|
1036
|
+
accept: 'text/event-stream, application/json',
|
|
1037
|
+
},
|
|
1038
|
+
});
|
|
1039
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
1040
|
+
if (!contentType.includes('text/event-stream')) {
|
|
1041
|
+
return await response.json().catch(() => null);
|
|
1042
|
+
}
|
|
1043
|
+
return await this.readMcpEventStream(response, options.onProgress);
|
|
1044
|
+
}
|
|
1045
|
+
finally {
|
|
1046
|
+
completed = true;
|
|
1047
|
+
options.signal?.removeEventListener('abort', cancel);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
async listMcpTools() {
|
|
1051
|
+
return this.mcpRequest({
|
|
1052
|
+
jsonrpc: '2.0',
|
|
1053
|
+
id: 'tools-list',
|
|
1054
|
+
method: 'tools/list',
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
async callMcpTool(name, args) {
|
|
1058
|
+
return this.mcpRequest({
|
|
1059
|
+
jsonrpc: '2.0',
|
|
1060
|
+
id: `${name}-call`,
|
|
1061
|
+
method: 'tools/call',
|
|
1062
|
+
params: {
|
|
1063
|
+
name,
|
|
1064
|
+
arguments: args,
|
|
1065
|
+
},
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
async callSessionMcpTool(sessionId, name, args) {
|
|
1069
|
+
return this.mcpSessionRequest(sessionId, {
|
|
1070
|
+
jsonrpc: '2.0',
|
|
1071
|
+
id: `${name}-call`,
|
|
1072
|
+
method: 'tools/call',
|
|
1073
|
+
params: {
|
|
1074
|
+
name,
|
|
1075
|
+
arguments: args,
|
|
1076
|
+
},
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
async listKnowledgePacks() {
|
|
1080
|
+
return this.request('/v1/knowledge/packs');
|
|
1081
|
+
}
|
|
1082
|
+
async getKnowledgeCapabilities(input = {}) {
|
|
1083
|
+
const path = input.packKey
|
|
1084
|
+
? `/v1/knowledge/packs/${input.packKey}/capabilities`
|
|
1085
|
+
: '/v1/knowledge/capabilities';
|
|
1086
|
+
return this.request(path, input.sessionId
|
|
1087
|
+
? { query: { sessionId: input.sessionId } }
|
|
1088
|
+
: {});
|
|
1089
|
+
}
|
|
1090
|
+
async listKnowledgeReleases(packKey) {
|
|
1091
|
+
return this.request(`/v1/knowledge/packs/${packKey}/releases`);
|
|
1092
|
+
}
|
|
1093
|
+
async subscribeKnowledgePack(packKey, input = {}) {
|
|
1094
|
+
return this.request(`/v1/knowledge/packs/${packKey}/subscribe`, {
|
|
1095
|
+
method: 'POST',
|
|
1096
|
+
body: input,
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
async searchKnowledge(input) {
|
|
1100
|
+
return this.request('/v1/knowledge/search', {
|
|
1101
|
+
method: 'POST',
|
|
1102
|
+
body: input,
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
async lookupKnowledgeCitation(input) {
|
|
1106
|
+
return this.request('/v1/knowledge/citations/lookup', {
|
|
1107
|
+
method: 'POST',
|
|
1108
|
+
body: input,
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
async getKnowledgeAmendmentTrail(input) {
|
|
1112
|
+
return this.request('/v1/knowledge/amendments/trail', {
|
|
1113
|
+
method: 'POST',
|
|
1114
|
+
body: input,
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
async verifyKnowledgeEvidence(input) {
|
|
1118
|
+
return this.request('/v1/knowledge/evidence/verify', {
|
|
1119
|
+
method: 'POST',
|
|
1120
|
+
body: input,
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
async verifyKnowledgeAnswer(input) {
|
|
1124
|
+
return this.request('/v1/knowledge/answers/verify', {
|
|
1125
|
+
method: 'POST',
|
|
1126
|
+
body: input,
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
async getGstComplianceRule(input) {
|
|
1130
|
+
return this.request('/v1/gst-compliance/rules/query', {
|
|
1131
|
+
method: 'POST',
|
|
1132
|
+
body: input,
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
async getGstDueDateRule(input) {
|
|
1136
|
+
return this.request('/v1/gst-compliance/due-date/rule', {
|
|
1137
|
+
method: 'POST',
|
|
1138
|
+
body: input,
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
async calculateGstDueDate(input) {
|
|
1142
|
+
return this.request('/v1/gst-compliance/due-date/calculate', {
|
|
1143
|
+
method: 'POST',
|
|
1144
|
+
body: input,
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
async getGstLateFeeRule(input) {
|
|
1148
|
+
return this.request('/v1/gst-compliance/late-fee/rule', {
|
|
1149
|
+
method: 'POST',
|
|
1150
|
+
body: input,
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
async calculateGstLateFee(input) {
|
|
1154
|
+
return this.request('/v1/gst-compliance/late-fee/calculate', {
|
|
1155
|
+
method: 'POST',
|
|
1156
|
+
body: input,
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
async getGstInterestRule(input) {
|
|
1160
|
+
return this.request('/v1/gst-compliance/interest/rule', {
|
|
1161
|
+
method: 'POST',
|
|
1162
|
+
body: input,
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
async calculateGstInterest(input) {
|
|
1166
|
+
return this.request('/v1/gst-compliance/interest/calculate', {
|
|
1167
|
+
method: 'POST',
|
|
1168
|
+
body: input,
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
async lookupGstHsnSacRate(input) {
|
|
1172
|
+
return this.request('/v1/gst-compliance/rates/lookup', {
|
|
1173
|
+
method: 'POST',
|
|
1174
|
+
body: input,
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
async checkGstRcm(input) {
|
|
1178
|
+
return this.request('/v1/gst-compliance/rcm/check', {
|
|
1179
|
+
method: 'POST',
|
|
1180
|
+
body: input,
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
async getGstNoticeRule(input) {
|
|
1184
|
+
return this.request('/v1/gst-compliance/notices/rule', {
|
|
1185
|
+
method: 'POST',
|
|
1186
|
+
body: input,
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
async getGstAppealStageRule(input) {
|
|
1190
|
+
return this.request('/v1/gst-compliance/appeals/stage', {
|
|
1191
|
+
method: 'POST',
|
|
1192
|
+
body: input,
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
attachAbortSignalCancellation(input, response, signal) {
|
|
1196
|
+
if (!signal)
|
|
1197
|
+
return;
|
|
1198
|
+
const sessionId = typeof input.sessionId === 'string' ? input.sessionId : undefined;
|
|
1199
|
+
const executionId = typeof response.executionId === 'string'
|
|
1200
|
+
? response.executionId
|
|
1201
|
+
: isSdkRecord(response.executionLog) && typeof response.executionLog.id === 'string'
|
|
1202
|
+
? response.executionLog.id
|
|
1203
|
+
: undefined;
|
|
1204
|
+
const executionKind = response.executionKind === 'workbench_bash' || response.executionKind === 'workbench_code'
|
|
1205
|
+
? response.executionKind
|
|
1206
|
+
: undefined;
|
|
1207
|
+
if (!sessionId || !executionId || !executionKind)
|
|
1208
|
+
return;
|
|
1209
|
+
const cancel = () => {
|
|
1210
|
+
void this.cancelExecution({
|
|
1211
|
+
sessionId,
|
|
1212
|
+
executionKind,
|
|
1213
|
+
executionId,
|
|
1214
|
+
reason: 'sdk_abort_signal',
|
|
1215
|
+
}).catch(() => undefined);
|
|
1216
|
+
};
|
|
1217
|
+
if (signal.aborted) {
|
|
1218
|
+
cancel();
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
1222
|
+
}
|
|
1223
|
+
async request(path, init = {}) {
|
|
1224
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
1225
|
+
for (const [key, value] of Object.entries(init.query ?? {})) {
|
|
1226
|
+
if (Array.isArray(value)) {
|
|
1227
|
+
for (const entry of value) {
|
|
1228
|
+
if (entry !== undefined && entry !== null)
|
|
1229
|
+
url.searchParams.append(key, String(entry));
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
else if (value !== undefined && value !== null) {
|
|
1233
|
+
url.searchParams.set(key, String(value));
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
const headers = this.requestHeaders(init.registration === true, init.headers);
|
|
1237
|
+
const response = await this.fetchImpl(url, {
|
|
1238
|
+
method: init.method ?? 'GET',
|
|
1239
|
+
headers,
|
|
1240
|
+
...(init.signal ? { signal: init.signal } : {}),
|
|
1241
|
+
...(init.body === undefined ? {} : { body: JSON.stringify(init.body) }),
|
|
1242
|
+
});
|
|
1243
|
+
const body = await response.json().catch(() => null);
|
|
1244
|
+
if (!response.ok) {
|
|
1245
|
+
const message = body && typeof body === 'object' && 'message' in body
|
|
1246
|
+
? String(body.message)
|
|
1247
|
+
: `Stacklink request failed with ${response.status}`;
|
|
1248
|
+
const code = body && typeof body === 'object' && 'code' in body && typeof body.code === 'string'
|
|
1249
|
+
? body.code
|
|
1250
|
+
: undefined;
|
|
1251
|
+
const details = body && typeof body === 'object' && 'details' in body
|
|
1252
|
+
? body.details
|
|
1253
|
+
: undefined;
|
|
1254
|
+
throw new StacklinkApiError(message, response.status, code, details);
|
|
1255
|
+
}
|
|
1256
|
+
return body;
|
|
1257
|
+
}
|
|
1258
|
+
async requestRaw(path, init = {}) {
|
|
1259
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
1260
|
+
for (const [key, value] of Object.entries(init.query ?? {})) {
|
|
1261
|
+
if (Array.isArray(value)) {
|
|
1262
|
+
for (const entry of value) {
|
|
1263
|
+
if (entry !== undefined && entry !== null)
|
|
1264
|
+
url.searchParams.append(key, String(entry));
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
else if (value !== undefined && value !== null) {
|
|
1268
|
+
url.searchParams.set(key, String(value));
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
const response = await this.fetchImpl(url, {
|
|
1272
|
+
method: init.method ?? 'GET',
|
|
1273
|
+
headers: this.requestHeaders(init.registration === true, init.headers),
|
|
1274
|
+
...(init.signal ? { signal: init.signal } : {}),
|
|
1275
|
+
...(init.body === undefined ? {} : { body: JSON.stringify(init.body) }),
|
|
1276
|
+
});
|
|
1277
|
+
if (!response.ok) {
|
|
1278
|
+
const body = await response.text().catch(() => '');
|
|
1279
|
+
throw new StacklinkApiError(body || `Stacklink request failed with ${response.status}`, response.status);
|
|
1280
|
+
}
|
|
1281
|
+
return response;
|
|
1282
|
+
}
|
|
1283
|
+
async cachedDiscoveryRequest(cacheKey, ttlMs, control, producer) {
|
|
1284
|
+
if (!this.cacheOptions.enabled || control?.cache === 'bypass')
|
|
1285
|
+
return producer();
|
|
1286
|
+
const now = Date.now();
|
|
1287
|
+
const existing = this.responseCache.get(cacheKey);
|
|
1288
|
+
if (existing && existing.expiresAt > now)
|
|
1289
|
+
return existing.value;
|
|
1290
|
+
const value = await producer();
|
|
1291
|
+
this.responseCache.set(cacheKey, {
|
|
1292
|
+
value,
|
|
1293
|
+
expiresAt: now + ttlMs,
|
|
1294
|
+
});
|
|
1295
|
+
this.trimResponseCache();
|
|
1296
|
+
return value;
|
|
1297
|
+
}
|
|
1298
|
+
discoveryCacheTtl(kind) {
|
|
1299
|
+
if (kind === 'toolsList')
|
|
1300
|
+
return this.cacheOptions.toolsListTtlMs;
|
|
1301
|
+
if (kind === 'toolkits')
|
|
1302
|
+
return this.cacheOptions.toolkitsTtlMs;
|
|
1303
|
+
if (kind === 'schemas')
|
|
1304
|
+
return this.cacheOptions.schemasTtlMs;
|
|
1305
|
+
return this.cacheOptions.searchTtlMs;
|
|
1306
|
+
}
|
|
1307
|
+
trimResponseCache() {
|
|
1308
|
+
const maxEntries = this.cacheOptions.maxEntries;
|
|
1309
|
+
while (this.responseCache.size > maxEntries) {
|
|
1310
|
+
const firstKey = this.responseCache.keys().next().value;
|
|
1311
|
+
if (!firstKey)
|
|
1312
|
+
break;
|
|
1313
|
+
this.responseCache.delete(firstKey);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
async readMcpEventStream(response, onProgress) {
|
|
1317
|
+
if (!response.body)
|
|
1318
|
+
throw new Error('Stacklink MCP stream response has no body.');
|
|
1319
|
+
const reader = response.body.getReader();
|
|
1320
|
+
const decoder = new TextDecoder();
|
|
1321
|
+
let buffer = '';
|
|
1322
|
+
let dataLines = [];
|
|
1323
|
+
let finalResponse;
|
|
1324
|
+
const handleLine = (line) => {
|
|
1325
|
+
if (line.endsWith('\r'))
|
|
1326
|
+
line = line.slice(0, -1);
|
|
1327
|
+
if (line === '') {
|
|
1328
|
+
if (dataLines.length > 0) {
|
|
1329
|
+
const data = dataLines.join('\n');
|
|
1330
|
+
dataLines = [];
|
|
1331
|
+
if (data.length > 0) {
|
|
1332
|
+
const message = JSON.parse(data);
|
|
1333
|
+
if (isSdkRecord(message) && message.method === 'notifications/progress' && isSdkRecord(message.params)) {
|
|
1334
|
+
onProgress?.(message.params);
|
|
1335
|
+
}
|
|
1336
|
+
else if (isSdkRecord(message) && ('result' in message || 'error' in message)) {
|
|
1337
|
+
finalResponse = message;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
if (line.startsWith('data:')) {
|
|
1344
|
+
let value = line.slice(5);
|
|
1345
|
+
if (value.startsWith(' '))
|
|
1346
|
+
value = value.slice(1);
|
|
1347
|
+
dataLines.push(value);
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
while (true) {
|
|
1351
|
+
const read = await reader.read();
|
|
1352
|
+
if (read.done)
|
|
1353
|
+
break;
|
|
1354
|
+
buffer += decoder.decode(read.value, { stream: true });
|
|
1355
|
+
let index = buffer.indexOf('\n');
|
|
1356
|
+
while (index >= 0) {
|
|
1357
|
+
handleLine(buffer.slice(0, index));
|
|
1358
|
+
buffer = buffer.slice(index + 1);
|
|
1359
|
+
index = buffer.indexOf('\n');
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
buffer += decoder.decode();
|
|
1363
|
+
if (buffer.length > 0)
|
|
1364
|
+
handleLine(buffer);
|
|
1365
|
+
handleLine('');
|
|
1366
|
+
if (finalResponse === undefined)
|
|
1367
|
+
throw new Error('Stacklink MCP stream ended without a final JSON-RPC response.');
|
|
1368
|
+
return finalResponse;
|
|
1369
|
+
}
|
|
1370
|
+
requestHeaders(registration, extraHeaders = {}) {
|
|
1371
|
+
if (registration) {
|
|
1372
|
+
if (!this.registrationKey) {
|
|
1373
|
+
throw new Error('Stacklink registrationKey is required for registration/admin SDK methods.');
|
|
1374
|
+
}
|
|
1375
|
+
return {
|
|
1376
|
+
'x-stacklink-registration-key': this.registrationKey,
|
|
1377
|
+
'content-type': 'application/json',
|
|
1378
|
+
...extraHeaders,
|
|
1379
|
+
'x-stacklink-client-channel': 'ts_sdk',
|
|
1380
|
+
'x-stacklink-client-name': 'stacklink-ts',
|
|
1381
|
+
'x-stacklink-client-version': stacklinkTypeScriptSdkVersion,
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
return {
|
|
1385
|
+
authorization: `Bearer ${this.apiKey}`,
|
|
1386
|
+
'content-type': 'application/json',
|
|
1387
|
+
...extraHeaders,
|
|
1388
|
+
'x-stacklink-client-channel': 'ts_sdk',
|
|
1389
|
+
'x-stacklink-client-name': 'stacklink-ts',
|
|
1390
|
+
'x-stacklink-client-version': stacklinkTypeScriptSdkVersion,
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
export class StacklinkWebhooksClient {
|
|
1395
|
+
client;
|
|
1396
|
+
constructor(client) {
|
|
1397
|
+
this.client = client;
|
|
1398
|
+
}
|
|
1399
|
+
listEventTypes() {
|
|
1400
|
+
return this.client.listWebhookEventTypes();
|
|
1401
|
+
}
|
|
1402
|
+
get() {
|
|
1403
|
+
return this.client.getWebhook();
|
|
1404
|
+
}
|
|
1405
|
+
update(input) {
|
|
1406
|
+
return this.client.updateWebhook(input);
|
|
1407
|
+
}
|
|
1408
|
+
rotateSecret() {
|
|
1409
|
+
return this.client.rotateWebhookSecret();
|
|
1410
|
+
}
|
|
1411
|
+
sendTest(input) {
|
|
1412
|
+
return this.client.sendWebhookTest(input);
|
|
1413
|
+
}
|
|
1414
|
+
retryDelivery(deliveryId, input = {}) {
|
|
1415
|
+
return this.client.retryWebhookDelivery(deliveryId, input);
|
|
1416
|
+
}
|
|
1417
|
+
redriveDeadLetters(input = {}) {
|
|
1418
|
+
return this.client.redriveDeadLetterWebhookDeliveries(input);
|
|
1419
|
+
}
|
|
1420
|
+
replayEvent(eventId) {
|
|
1421
|
+
return this.client.replayProviderEvent(eventId);
|
|
1422
|
+
}
|
|
1423
|
+
verifySignature(input) {
|
|
1424
|
+
return this.client.verifyWebhookSignature(input);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
export class StacklinkTriggersClient {
|
|
1428
|
+
client;
|
|
1429
|
+
constructor(client) {
|
|
1430
|
+
this.client = client;
|
|
1431
|
+
}
|
|
1432
|
+
listTypes(query = {}) {
|
|
1433
|
+
return this.client.listTriggerTypes(query);
|
|
1434
|
+
}
|
|
1435
|
+
listSubscriptions(query = {}) {
|
|
1436
|
+
return this.client.listTriggerSubscriptions(query);
|
|
1437
|
+
}
|
|
1438
|
+
createSubscription(input) {
|
|
1439
|
+
return this.client.createTriggerSubscription(input);
|
|
1440
|
+
}
|
|
1441
|
+
getSubscription(subscriptionId) {
|
|
1442
|
+
return this.client.getTriggerSubscription(subscriptionId);
|
|
1443
|
+
}
|
|
1444
|
+
updateSubscription(subscriptionId, patch) {
|
|
1445
|
+
return this.client.updateTriggerSubscription(subscriptionId, patch);
|
|
1446
|
+
}
|
|
1447
|
+
deleteSubscription(subscriptionId) {
|
|
1448
|
+
return this.client.deleteTriggerSubscription(subscriptionId);
|
|
1449
|
+
}
|
|
1450
|
+
runPoll(input = {}) {
|
|
1451
|
+
return this.client.runTriggerPoller(input);
|
|
1452
|
+
}
|
|
1453
|
+
runDeliveries(input = {}) {
|
|
1454
|
+
return this.client.runTriggerDeliveries(input);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
export class StacklinkMemoryClient {
|
|
1458
|
+
client;
|
|
1459
|
+
constructor(client) {
|
|
1460
|
+
this.client = client;
|
|
1461
|
+
}
|
|
1462
|
+
listPolicies() {
|
|
1463
|
+
return this.client.request('/v1/memory/policies');
|
|
1464
|
+
}
|
|
1465
|
+
createPolicy(input) {
|
|
1466
|
+
return this.client.request('/v1/memory/policies', { method: 'POST', body: input });
|
|
1467
|
+
}
|
|
1468
|
+
getPolicy(policyKey = 'default') {
|
|
1469
|
+
return this.client.request(`/v1/memory/policies/${encodeURIComponent(policyKey)}`);
|
|
1470
|
+
}
|
|
1471
|
+
policyHistory(policyKey = 'default') {
|
|
1472
|
+
return this.client.request(`/v1/memory/policies/${encodeURIComponent(policyKey)}/history`);
|
|
1473
|
+
}
|
|
1474
|
+
previewPolicy(input, policyKey = 'default') {
|
|
1475
|
+
return this.client.request(`/v1/memory/policies/${encodeURIComponent(policyKey)}/preview`, {
|
|
1476
|
+
method: 'POST',
|
|
1477
|
+
body: input,
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
updatePolicy(policyKey, input) {
|
|
1481
|
+
return this.client.request(`/v1/memory/policies/${encodeURIComponent(policyKey)}`, {
|
|
1482
|
+
method: 'PATCH',
|
|
1483
|
+
body: input,
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
deletePolicy(policyKey) {
|
|
1487
|
+
return this.client.request(`/v1/memory/policies/${encodeURIComponent(policyKey)}`, { method: 'DELETE' });
|
|
1488
|
+
}
|
|
1489
|
+
ingest(input) {
|
|
1490
|
+
return this.client.request('/v1/memory/ingest', {
|
|
1491
|
+
method: 'POST',
|
|
1492
|
+
body: input,
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
ingestRich(input) {
|
|
1496
|
+
return this.client.request('/v1/memory/ingest-rich', {
|
|
1497
|
+
method: 'POST',
|
|
1498
|
+
body: input,
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
getRichIngest(jobId) {
|
|
1502
|
+
return this.client.request(`/v1/memory/ingest-rich/${encodeURIComponent(jobId)}`);
|
|
1503
|
+
}
|
|
1504
|
+
recordConversationTurn(input) {
|
|
1505
|
+
return this.client.request('/v1/memory/events/conversation-turn-completed', {
|
|
1506
|
+
method: 'POST',
|
|
1507
|
+
body: input,
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
add(input) {
|
|
1511
|
+
return this.ingest({ ...input, mode: 'exact' });
|
|
1512
|
+
}
|
|
1513
|
+
search(input) {
|
|
1514
|
+
return this.client.request('/v1/memory/search', {
|
|
1515
|
+
method: 'POST',
|
|
1516
|
+
body: input,
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
context(input) {
|
|
1520
|
+
return this.client.request('/v1/memory/context', {
|
|
1521
|
+
method: 'POST',
|
|
1522
|
+
body: input,
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
list(input) {
|
|
1526
|
+
return this.client.request('/v1/memory/records', { query: { ...input } });
|
|
1527
|
+
}
|
|
1528
|
+
listForgotten(input) {
|
|
1529
|
+
return this.client.request('/v1/memory/admin/forgotten-records', { query: { ...input } });
|
|
1530
|
+
}
|
|
1531
|
+
get(memoryId, selector) {
|
|
1532
|
+
return this.client.request(`/v1/memory/records/${memoryId}`, { query: { ...selector } });
|
|
1533
|
+
}
|
|
1534
|
+
history(memoryId, selector) {
|
|
1535
|
+
return this.client.request(`/v1/memory/records/${memoryId}/history`, { query: { ...selector } });
|
|
1536
|
+
}
|
|
1537
|
+
update(memoryId, input) {
|
|
1538
|
+
return this.client.request(`/v1/memory/records/${memoryId}`, {
|
|
1539
|
+
method: 'PATCH',
|
|
1540
|
+
body: input,
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
forget(memoryId, input) {
|
|
1544
|
+
return this.client.request(`/v1/memory/records/${memoryId}/forget`, {
|
|
1545
|
+
method: 'POST',
|
|
1546
|
+
body: input,
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
restore(memoryId, input) {
|
|
1550
|
+
return this.client.request(`/v1/memory/records/${memoryId}/restore`, {
|
|
1551
|
+
method: 'POST',
|
|
1552
|
+
body: input,
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
erase(memoryId, input) {
|
|
1556
|
+
return this.client.request(`/v1/memory/records/${memoryId}`, {
|
|
1557
|
+
method: 'DELETE',
|
|
1558
|
+
body: input,
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
previewErasure(memoryId, selector) {
|
|
1562
|
+
return this.client.request(`/v1/memory/records/${memoryId}/erasure-preview`, {
|
|
1563
|
+
method: 'POST',
|
|
1564
|
+
body: selector,
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
getErasure(erasureJobId) {
|
|
1568
|
+
return this.client.request(`/v1/memory/erasures/${erasureJobId}`);
|
|
1569
|
+
}
|
|
1570
|
+
profile(selector) {
|
|
1571
|
+
return this.client.request('/v1/memory/profile', { query: { ...selector } });
|
|
1572
|
+
}
|
|
1573
|
+
subjectProfile(subjectId, selector) {
|
|
1574
|
+
return this.client.request(`/v1/memory/subjects/${subjectId}/profile`, {
|
|
1575
|
+
query: { ...selector },
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
listSubjects(input) {
|
|
1579
|
+
return this.client.request('/v1/memory/subjects', { query: input });
|
|
1580
|
+
}
|
|
1581
|
+
eraseSubject(subjectId, input) {
|
|
1582
|
+
return this.client.request(`/v1/memory/subjects/${subjectId}/erase`, {
|
|
1583
|
+
method: 'POST',
|
|
1584
|
+
body: input,
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
createBlock(input) {
|
|
1588
|
+
return this.client.request('/v1/memory/blocks', { method: 'POST', body: input });
|
|
1589
|
+
}
|
|
1590
|
+
listBlocks(selector) {
|
|
1591
|
+
return this.client.request('/v1/memory/blocks', { query: { ...selector } });
|
|
1592
|
+
}
|
|
1593
|
+
updateBlock(blockId, input) {
|
|
1594
|
+
return this.client.request(`/v1/memory/blocks/${blockId}`, { method: 'PATCH', body: input });
|
|
1595
|
+
}
|
|
1596
|
+
revokeBlock(blockId, selector) {
|
|
1597
|
+
return this.client.request(`/v1/memory/blocks/${blockId}`, { method: 'DELETE', body: selector });
|
|
1598
|
+
}
|
|
1599
|
+
queryGraph(input) {
|
|
1600
|
+
return this.client.request('/v1/memory/graph/query', { method: 'POST', body: input });
|
|
1601
|
+
}
|
|
1602
|
+
createSource(input) {
|
|
1603
|
+
return this.client.request('/v1/memory/sources', { method: 'POST', body: input });
|
|
1604
|
+
}
|
|
1605
|
+
previewConnectedSource(input) {
|
|
1606
|
+
return this.client.request('/v1/memory/sources/connected/preview', {
|
|
1607
|
+
method: 'POST',
|
|
1608
|
+
body: input,
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
createConnectedSource(input) {
|
|
1612
|
+
return this.client.request('/v1/memory/sources/connected', {
|
|
1613
|
+
method: 'POST',
|
|
1614
|
+
body: input,
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
listSources(input) {
|
|
1618
|
+
return this.client.request('/v1/memory/sources', { query: input });
|
|
1619
|
+
}
|
|
1620
|
+
getSource(bindingId) {
|
|
1621
|
+
return this.client.request(`/v1/memory/sources/${bindingId}`);
|
|
1622
|
+
}
|
|
1623
|
+
setSourceStatus(bindingId, status) {
|
|
1624
|
+
return this.updateSource(bindingId, { status });
|
|
1625
|
+
}
|
|
1626
|
+
updateSource(bindingId, input) {
|
|
1627
|
+
return this.client.request(`/v1/memory/sources/${bindingId}`, {
|
|
1628
|
+
method: 'PATCH',
|
|
1629
|
+
body: input,
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
deleteSource(bindingId) {
|
|
1633
|
+
return this.client.request(`/v1/memory/sources/${bindingId}`, { method: 'DELETE' });
|
|
1634
|
+
}
|
|
1635
|
+
replaySourceItem(bindingId, itemId) {
|
|
1636
|
+
return this.client.request(`/v1/memory/sources/${bindingId}/items/${itemId}/replay`, {
|
|
1637
|
+
method: 'POST',
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
listSourceDeliveries(input = {}) {
|
|
1641
|
+
return this.client.request('/v1/memory/source-deliveries', { query: input });
|
|
1642
|
+
}
|
|
1643
|
+
replaySourceDelivery(deliveryId) {
|
|
1644
|
+
return this.client.request(`/v1/memory/source-deliveries/${deliveryId}/replay`, { method: 'POST' });
|
|
1645
|
+
}
|
|
1646
|
+
export(input) {
|
|
1647
|
+
return this.client.request('/v1/memory/exports', { method: 'POST', body: input });
|
|
1648
|
+
}
|
|
1649
|
+
getExport(exportId) {
|
|
1650
|
+
return this.client.request(`/v1/memory/exports/${exportId}`);
|
|
1651
|
+
}
|
|
1652
|
+
dataManagement(input = {}) {
|
|
1653
|
+
return this.client.request('/v1/memory/data-management', { query: input });
|
|
1654
|
+
}
|
|
1655
|
+
createLegalHold(input) {
|
|
1656
|
+
return this.client.request('/v1/memory/legal-holds', { method: 'POST', body: input });
|
|
1657
|
+
}
|
|
1658
|
+
releaseLegalHold(holdId) {
|
|
1659
|
+
return this.client.request(`/v1/memory/legal-holds/${holdId}/release`, { method: 'POST' });
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
export class StacklinkSessionsClient {
|
|
1663
|
+
client;
|
|
1664
|
+
constructor(client) {
|
|
1665
|
+
this.client = client;
|
|
1666
|
+
}
|
|
1667
|
+
create(input) {
|
|
1668
|
+
return this.client.create(input);
|
|
1669
|
+
}
|
|
1670
|
+
use(sessionId) {
|
|
1671
|
+
return this.client.use(sessionId);
|
|
1672
|
+
}
|
|
1673
|
+
list(query = {}) {
|
|
1674
|
+
return this.client.listSessions(query);
|
|
1675
|
+
}
|
|
1676
|
+
get(sessionId) {
|
|
1677
|
+
return this.client.getSession(sessionId);
|
|
1678
|
+
}
|
|
1679
|
+
update(sessionId, patch) {
|
|
1680
|
+
return this.client.updateSession(sessionId, patch);
|
|
1681
|
+
}
|
|
1682
|
+
close(sessionId) {
|
|
1683
|
+
return this.client.closeSession(sessionId);
|
|
1684
|
+
}
|
|
1685
|
+
fail(sessionId, input = {}) {
|
|
1686
|
+
return this.client.failSession(sessionId, input);
|
|
1687
|
+
}
|
|
1688
|
+
metaTools(sessionId) {
|
|
1689
|
+
return this.client.getSessionMetaTools(sessionId);
|
|
1690
|
+
}
|
|
1691
|
+
toolkits(sessionId) {
|
|
1692
|
+
return this.client.request(`/v1/sessions/${sessionId}/toolkits`);
|
|
1693
|
+
}
|
|
1694
|
+
streamEvents(sessionId, input = {}) {
|
|
1695
|
+
return this.client.requestRaw(`/v1/sessions/${sessionId}/events/stream`, {
|
|
1696
|
+
headers: {
|
|
1697
|
+
accept: 'text/event-stream',
|
|
1698
|
+
},
|
|
1699
|
+
query: {
|
|
1700
|
+
after: input.after,
|
|
1701
|
+
eventType: input.eventTypes,
|
|
1702
|
+
limit: input.limit,
|
|
1703
|
+
pollIntervalMs: input.pollIntervalMs,
|
|
1704
|
+
},
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
listRouterFacts(sessionId, query = {}) {
|
|
1708
|
+
return this.client.listSessionRouterFacts(sessionId, query);
|
|
1709
|
+
}
|
|
1710
|
+
listConnectionEvents(sessionId) {
|
|
1711
|
+
return this.client.listSessionConnectionEvents(sessionId);
|
|
1712
|
+
}
|
|
1713
|
+
workbench(sessionId) {
|
|
1714
|
+
return this.client.getSessionWorkbench(sessionId);
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
export class StacklinkLogsClient {
|
|
1718
|
+
client;
|
|
1719
|
+
constructor(client) {
|
|
1720
|
+
this.client = client;
|
|
1721
|
+
}
|
|
1722
|
+
summary() {
|
|
1723
|
+
return this.client.getLogSummary();
|
|
1724
|
+
}
|
|
1725
|
+
listRequests(query = {}) {
|
|
1726
|
+
return this.client.listRequestLogs(query);
|
|
1727
|
+
}
|
|
1728
|
+
getRequest(logId) {
|
|
1729
|
+
return this.client.getRequestLog(logId);
|
|
1730
|
+
}
|
|
1731
|
+
listTools(query = {}) {
|
|
1732
|
+
return this.client.listToolLogs(query);
|
|
1733
|
+
}
|
|
1734
|
+
getTool(logId) {
|
|
1735
|
+
return this.client.getToolLog(logId);
|
|
1736
|
+
}
|
|
1737
|
+
listTriggers(query = {}) {
|
|
1738
|
+
return this.client.listTriggerLogs(query);
|
|
1739
|
+
}
|
|
1740
|
+
getTrigger(logId) {
|
|
1741
|
+
return this.client.getTriggerLog(logId);
|
|
1742
|
+
}
|
|
1743
|
+
listWebhookDeliveries(query = {}) {
|
|
1744
|
+
return this.client.listWebhookDeliveries(query);
|
|
1745
|
+
}
|
|
1746
|
+
getWebhookDelivery(deliveryId) {
|
|
1747
|
+
return this.client.getWebhookDeliveryLog(deliveryId);
|
|
1748
|
+
}
|
|
1749
|
+
retryWebhookDelivery(deliveryId, input = {}) {
|
|
1750
|
+
return this.client.retryWebhookDelivery(deliveryId, input);
|
|
1751
|
+
}
|
|
1752
|
+
redriveDeadLetters(input = {}) {
|
|
1753
|
+
return this.client.redriveDeadLetterWebhookDeliveries(input);
|
|
1754
|
+
}
|
|
1755
|
+
replayProviderEvent(eventId) {
|
|
1756
|
+
return this.client.replayProviderEvent(eventId);
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
export class StacklinkApiKeysClient {
|
|
1760
|
+
client;
|
|
1761
|
+
constructor(client) {
|
|
1762
|
+
this.client = client;
|
|
1763
|
+
}
|
|
1764
|
+
create(input) {
|
|
1765
|
+
return this.client.createApiKey(input);
|
|
1766
|
+
}
|
|
1767
|
+
delete(apiKeyId) {
|
|
1768
|
+
return this.client.deleteApiKey(apiKeyId);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
export class StacklinkBillingClient {
|
|
1772
|
+
client;
|
|
1773
|
+
constructor(client) {
|
|
1774
|
+
this.client = client;
|
|
1775
|
+
}
|
|
1776
|
+
getSubscription() {
|
|
1777
|
+
return this.client.getSubscription();
|
|
1778
|
+
}
|
|
1779
|
+
listPlans() {
|
|
1780
|
+
return this.client.listBillingPlans();
|
|
1781
|
+
}
|
|
1782
|
+
getUsage() {
|
|
1783
|
+
return this.client.getUsage();
|
|
1784
|
+
}
|
|
1785
|
+
listUsageEvents(query = {}) {
|
|
1786
|
+
return this.client.listUsageEvents(query);
|
|
1787
|
+
}
|
|
1788
|
+
createCheckout(input) {
|
|
1789
|
+
return this.client.createBillingCheckout(input);
|
|
1790
|
+
}
|
|
1791
|
+
createPortal(input = {}) {
|
|
1792
|
+
return this.client.createBillingPortal(input);
|
|
1793
|
+
}
|
|
1794
|
+
setWorkspacePlanForProject(projectId, input) {
|
|
1795
|
+
return this.client.setWorkspaceSubscriptionPlanForProject(projectId, input);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
export class StacklinkConnectedAccountsClient {
|
|
1799
|
+
client;
|
|
1800
|
+
constructor(client) {
|
|
1801
|
+
this.client = client;
|
|
1802
|
+
}
|
|
1803
|
+
list(tenantId) {
|
|
1804
|
+
return this.client.listConnectedAccounts(tenantId);
|
|
1805
|
+
}
|
|
1806
|
+
create(input) {
|
|
1807
|
+
return this.client.createConnectedAccount(input);
|
|
1808
|
+
}
|
|
1809
|
+
get(accountId) {
|
|
1810
|
+
return this.client.getConnectedAccount(accountId);
|
|
1811
|
+
}
|
|
1812
|
+
listTools(accountId, input = {}) {
|
|
1813
|
+
return this.client.listConnectedAccountTools(accountId, input);
|
|
1814
|
+
}
|
|
1815
|
+
listResources(accountId) {
|
|
1816
|
+
return this.client.listConnectedAccountResources(accountId);
|
|
1817
|
+
}
|
|
1818
|
+
refreshResources(accountId) {
|
|
1819
|
+
return this.client.refreshConnectedAccountResources(accountId);
|
|
1820
|
+
}
|
|
1821
|
+
resolveResource(accountId, input) {
|
|
1822
|
+
return this.client.resolveConnectedAccountResource(accountId, input);
|
|
1823
|
+
}
|
|
1824
|
+
update(accountId, patch) {
|
|
1825
|
+
return this.client.updateConnectedAccount(accountId, patch);
|
|
1826
|
+
}
|
|
1827
|
+
enable(accountId) {
|
|
1828
|
+
return this.client.enableConnectedAccount(accountId);
|
|
1829
|
+
}
|
|
1830
|
+
disable(accountId) {
|
|
1831
|
+
return this.client.disableConnectedAccount(accountId);
|
|
1832
|
+
}
|
|
1833
|
+
refresh(accountId) {
|
|
1834
|
+
return this.client.refreshConnectedAccount(accountId);
|
|
1835
|
+
}
|
|
1836
|
+
validate(accountId) {
|
|
1837
|
+
return this.client.validateConnectedAccount(accountId);
|
|
1838
|
+
}
|
|
1839
|
+
delete(accountId) {
|
|
1840
|
+
return this.client.deleteConnectedAccount(accountId);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
export class StacklinkAuthConfigsClient {
|
|
1844
|
+
client;
|
|
1845
|
+
constructor(client) {
|
|
1846
|
+
this.client = client;
|
|
1847
|
+
}
|
|
1848
|
+
list(query = {}) {
|
|
1849
|
+
return this.client.listAuthConfigs(query);
|
|
1850
|
+
}
|
|
1851
|
+
create(input) {
|
|
1852
|
+
return this.client.createAuthConfig(input);
|
|
1853
|
+
}
|
|
1854
|
+
get(authConfigId) {
|
|
1855
|
+
return this.client.getAuthConfig(authConfigId);
|
|
1856
|
+
}
|
|
1857
|
+
update(authConfigId, patch) {
|
|
1858
|
+
return this.client.updateAuthConfig(authConfigId, patch);
|
|
1859
|
+
}
|
|
1860
|
+
enable(authConfigId) {
|
|
1861
|
+
return this.client.enableAuthConfig(authConfigId);
|
|
1862
|
+
}
|
|
1863
|
+
disable(authConfigId) {
|
|
1864
|
+
return this.client.disableAuthConfig(authConfigId);
|
|
1865
|
+
}
|
|
1866
|
+
delete(authConfigId) {
|
|
1867
|
+
return this.client.deleteAuthConfig(authConfigId);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
export class StacklinkToolkitsClient {
|
|
1871
|
+
client;
|
|
1872
|
+
constructor(client) {
|
|
1873
|
+
this.client = client;
|
|
1874
|
+
}
|
|
1875
|
+
list() {
|
|
1876
|
+
return this.client.listProviders();
|
|
1877
|
+
}
|
|
1878
|
+
listProject(query = {}) {
|
|
1879
|
+
return this.client.listProjectProviders(query);
|
|
1880
|
+
}
|
|
1881
|
+
listTools(providerKey) {
|
|
1882
|
+
return this.client.listProviderTools(providerKey);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
export class StacklinkProviderToolsClient {
|
|
1886
|
+
client;
|
|
1887
|
+
constructor(client) {
|
|
1888
|
+
this.client = client;
|
|
1889
|
+
}
|
|
1890
|
+
search(input) {
|
|
1891
|
+
return this.client.searchTools(input);
|
|
1892
|
+
}
|
|
1893
|
+
schemas(input) {
|
|
1894
|
+
return this.client.getToolSchemas(input);
|
|
1895
|
+
}
|
|
1896
|
+
runtimeContracts(input) {
|
|
1897
|
+
return this.client.getRuntimeToolContracts(input);
|
|
1898
|
+
}
|
|
1899
|
+
execute(input) {
|
|
1900
|
+
return this.client.executeTool(input);
|
|
1901
|
+
}
|
|
1902
|
+
executeBatch(input) {
|
|
1903
|
+
return this.client.executeToolsBatch(input);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
export class StacklinkSessionMemoryClient {
|
|
1907
|
+
memoryClient;
|
|
1908
|
+
sessionId;
|
|
1909
|
+
constructor(memoryClient, sessionId) {
|
|
1910
|
+
this.memoryClient = memoryClient;
|
|
1911
|
+
this.sessionId = sessionId;
|
|
1912
|
+
}
|
|
1913
|
+
add(input) {
|
|
1914
|
+
return this.memoryClient.add({ ...input, sessionId: this.sessionId });
|
|
1915
|
+
}
|
|
1916
|
+
ingest(input) {
|
|
1917
|
+
return this.memoryClient.ingest({ ...input, sessionId: this.sessionId });
|
|
1918
|
+
}
|
|
1919
|
+
ingestRich(input) {
|
|
1920
|
+
return this.memoryClient.ingestRich({ ...input, sessionId: this.sessionId });
|
|
1921
|
+
}
|
|
1922
|
+
getRichIngest(jobId) {
|
|
1923
|
+
return this.memoryClient.getRichIngest(jobId);
|
|
1924
|
+
}
|
|
1925
|
+
recordConversationTurn(input) {
|
|
1926
|
+
return this.memoryClient.recordConversationTurn({ ...input, sessionId: this.sessionId });
|
|
1927
|
+
}
|
|
1928
|
+
search(input) {
|
|
1929
|
+
return this.memoryClient.search({ ...input, sessionId: this.sessionId });
|
|
1930
|
+
}
|
|
1931
|
+
context(input) {
|
|
1932
|
+
return this.memoryClient.context({ ...input, sessionId: this.sessionId });
|
|
1933
|
+
}
|
|
1934
|
+
recall(input) {
|
|
1935
|
+
return this.context(input);
|
|
1936
|
+
}
|
|
1937
|
+
profile() {
|
|
1938
|
+
return this.memoryClient.profile({ sessionId: this.sessionId });
|
|
1939
|
+
}
|
|
1940
|
+
get(memoryId) {
|
|
1941
|
+
return this.memoryClient.get(memoryId, { sessionId: this.sessionId });
|
|
1942
|
+
}
|
|
1943
|
+
history(memoryId) {
|
|
1944
|
+
return this.memoryClient.history(memoryId, { sessionId: this.sessionId });
|
|
1945
|
+
}
|
|
1946
|
+
update(memoryId, patch) {
|
|
1947
|
+
return this.memoryClient.update(memoryId, { sessionId: this.sessionId, patch });
|
|
1948
|
+
}
|
|
1949
|
+
forget(memoryId, reason) {
|
|
1950
|
+
return this.memoryClient.forget(memoryId, {
|
|
1951
|
+
sessionId: this.sessionId,
|
|
1952
|
+
...(reason ? { reason } : {}),
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
restore(memoryId, reason) {
|
|
1956
|
+
return this.memoryClient.restore(memoryId, {
|
|
1957
|
+
sessionId: this.sessionId,
|
|
1958
|
+
...(reason ? { reason } : {}),
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
export class StacklinkWorkbenchRun {
|
|
1963
|
+
client;
|
|
1964
|
+
platformSessionId;
|
|
1965
|
+
response;
|
|
1966
|
+
executionId;
|
|
1967
|
+
executionKind;
|
|
1968
|
+
constructor(client, platformSessionId, response) {
|
|
1969
|
+
this.client = client;
|
|
1970
|
+
this.platformSessionId = platformSessionId;
|
|
1971
|
+
this.response = response;
|
|
1972
|
+
this.executionId = response.executionId;
|
|
1973
|
+
this.executionKind = response.executionKind;
|
|
1974
|
+
}
|
|
1975
|
+
async *events(input = {}) {
|
|
1976
|
+
let afterSequence;
|
|
1977
|
+
while (true) {
|
|
1978
|
+
const page = await this.client.readExecutionEvents({
|
|
1979
|
+
sessionId: this.platformSessionId,
|
|
1980
|
+
executionKind: this.executionKind,
|
|
1981
|
+
executionId: this.executionId,
|
|
1982
|
+
afterSequence,
|
|
1983
|
+
limit: input.limit ?? 200,
|
|
1984
|
+
});
|
|
1985
|
+
for (const event of page.events) {
|
|
1986
|
+
yield event;
|
|
1987
|
+
if (isSdkRecord(event) && (typeof event.sequence === 'string' || typeof event.sequence === 'number')) {
|
|
1988
|
+
afterSequence = String(event.sequence);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
if (page.hasMore) {
|
|
1992
|
+
if (!page.nextCursor)
|
|
1993
|
+
throw new Error('Execution event page reported hasMore without nextCursor.');
|
|
1994
|
+
afterSequence = page.nextCursor;
|
|
1995
|
+
continue;
|
|
1996
|
+
}
|
|
1997
|
+
const state = await this.client.getExecution({
|
|
1998
|
+
sessionId: this.platformSessionId,
|
|
1999
|
+
executionKind: this.executionKind,
|
|
2000
|
+
executionId: this.executionId,
|
|
2001
|
+
});
|
|
2002
|
+
if (isTerminalSdkExecution(state.execution))
|
|
2003
|
+
return;
|
|
2004
|
+
await sleep(input.pollIntervalMs ?? 500);
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
wait(input = {}) {
|
|
2008
|
+
return this.client.waitForExecution({
|
|
2009
|
+
sessionId: this.platformSessionId,
|
|
2010
|
+
executionKind: this.executionKind,
|
|
2011
|
+
executionId: this.executionId,
|
|
2012
|
+
...input,
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
cancel(reason) {
|
|
2016
|
+
return this.client.cancelExecution({
|
|
2017
|
+
sessionId: this.platformSessionId,
|
|
2018
|
+
executionKind: this.executionKind,
|
|
2019
|
+
executionId: this.executionId,
|
|
2020
|
+
reason,
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
export class StacklinkWorkbenchFiles {
|
|
2025
|
+
client;
|
|
2026
|
+
platformSessionId;
|
|
2027
|
+
workbenchSessionId;
|
|
2028
|
+
constructor(client, platformSessionId, workbenchSessionId) {
|
|
2029
|
+
this.client = client;
|
|
2030
|
+
this.platformSessionId = platformSessionId;
|
|
2031
|
+
this.workbenchSessionId = workbenchSessionId;
|
|
2032
|
+
}
|
|
2033
|
+
async list() {
|
|
2034
|
+
return this.client.listWorkbenchFiles({
|
|
2035
|
+
sessionId: this.platformSessionId,
|
|
2036
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
async read(path) {
|
|
2040
|
+
return this.client.readWorkbenchFile({
|
|
2041
|
+
sessionId: this.platformSessionId,
|
|
2042
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2043
|
+
path,
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
async upload(input) {
|
|
2047
|
+
return this.client.uploadWorkbenchFile({
|
|
2048
|
+
sessionId: this.platformSessionId,
|
|
2049
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2050
|
+
...input,
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
async uploadLarge(input) {
|
|
2054
|
+
return this.client.uploadWorkbenchFileDirect({
|
|
2055
|
+
sessionId: this.platformSessionId,
|
|
2056
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2057
|
+
...input,
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
async download(path) {
|
|
2061
|
+
return this.client.downloadWorkbenchFile({
|
|
2062
|
+
sessionId: this.platformSessionId,
|
|
2063
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2064
|
+
path,
|
|
2065
|
+
});
|
|
2066
|
+
}
|
|
2067
|
+
async delete(path) {
|
|
2068
|
+
return this.client.deleteWorkbenchFile({
|
|
2069
|
+
sessionId: this.platformSessionId,
|
|
2070
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2071
|
+
path,
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
export class StacklinkWorkbenchRuns {
|
|
2076
|
+
client;
|
|
2077
|
+
platformSessionId;
|
|
2078
|
+
workbenchSessionId;
|
|
2079
|
+
constructor(client, platformSessionId, workbenchSessionId) {
|
|
2080
|
+
this.client = client;
|
|
2081
|
+
this.platformSessionId = platformSessionId;
|
|
2082
|
+
this.workbenchSessionId = workbenchSessionId;
|
|
2083
|
+
}
|
|
2084
|
+
async list(seriesId, cursor, limit) {
|
|
2085
|
+
return this.client.listWorkbenchRunDefinitions({
|
|
2086
|
+
sessionId: this.platformSessionId,
|
|
2087
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2088
|
+
...(seriesId ? { seriesId } : {}),
|
|
2089
|
+
...(cursor ? { cursor } : {}),
|
|
2090
|
+
...(limit ? { limit } : {}),
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
get(runDefinitionId) {
|
|
2094
|
+
return this.client.getWorkbenchRunDefinition({
|
|
2095
|
+
sessionId: this.platformSessionId,
|
|
2096
|
+
runDefinitionId,
|
|
2097
|
+
});
|
|
2098
|
+
}
|
|
2099
|
+
update(runDefinitionId, input) {
|
|
2100
|
+
return this.client.updateWorkbenchRunDefinition({
|
|
2101
|
+
sessionId: this.platformSessionId,
|
|
2102
|
+
runDefinitionId,
|
|
2103
|
+
...input,
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
async save(input) {
|
|
2107
|
+
return this.client.createWorkbenchRunDefinition({
|
|
2108
|
+
sessionId: this.platformSessionId,
|
|
2109
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2110
|
+
...input,
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
replay(runDefinitionId, input) {
|
|
2114
|
+
return this.client.replayWorkbenchRunDefinition({
|
|
2115
|
+
sessionId: this.platformSessionId,
|
|
2116
|
+
runDefinitionId,
|
|
2117
|
+
...input,
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
publish(runDefinitionId, expectedPublishedVersion) {
|
|
2121
|
+
return this.client.publishWorkbenchRunDefinition({
|
|
2122
|
+
sessionId: this.platformSessionId,
|
|
2123
|
+
runDefinitionId,
|
|
2124
|
+
expectedPublishedVersion,
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
rollback(runDefinitionId, expectedPublishedVersion) {
|
|
2128
|
+
return this.client.rollbackWorkbenchRunDefinition({
|
|
2129
|
+
sessionId: this.platformSessionId,
|
|
2130
|
+
runDefinitionId,
|
|
2131
|
+
expectedPublishedVersion,
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
export class StacklinkWorkbenchArtifacts {
|
|
2136
|
+
client;
|
|
2137
|
+
platformSessionId;
|
|
2138
|
+
workbenchSessionId;
|
|
2139
|
+
constructor(client, platformSessionId, workbenchSessionId) {
|
|
2140
|
+
this.client = client;
|
|
2141
|
+
this.platformSessionId = platformSessionId;
|
|
2142
|
+
this.workbenchSessionId = workbenchSessionId;
|
|
2143
|
+
}
|
|
2144
|
+
async list() {
|
|
2145
|
+
return this.client.listWorkbenchArtifacts({ workbenchSessionId: await this.workbenchSessionId() });
|
|
2146
|
+
}
|
|
2147
|
+
async promote(input) {
|
|
2148
|
+
return this.client.promoteWorkbenchArtifact({
|
|
2149
|
+
sessionId: this.platformSessionId,
|
|
2150
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2151
|
+
...input,
|
|
2152
|
+
});
|
|
2153
|
+
}
|
|
2154
|
+
downloadUrl(artifactId) {
|
|
2155
|
+
return this.client.getWorkbenchArtifactDownloadUrl(artifactId);
|
|
2156
|
+
}
|
|
2157
|
+
download(artifactId) {
|
|
2158
|
+
return this.client.downloadWorkbenchArtifact(artifactId);
|
|
2159
|
+
}
|
|
2160
|
+
async delete(artifactId, path) {
|
|
2161
|
+
return this.client.deleteWorkbenchArtifact({
|
|
2162
|
+
sessionId: this.platformSessionId,
|
|
2163
|
+
workbenchSessionId: await this.workbenchSessionId(),
|
|
2164
|
+
artifactId,
|
|
2165
|
+
path,
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
export class StacklinkSessionSandbox {
|
|
2170
|
+
client;
|
|
2171
|
+
platformSessionId;
|
|
2172
|
+
files;
|
|
2173
|
+
runs;
|
|
2174
|
+
artifacts;
|
|
2175
|
+
activeWorkbenchSessionId;
|
|
2176
|
+
constructor(client, platformSessionId) {
|
|
2177
|
+
this.client = client;
|
|
2178
|
+
this.platformSessionId = platformSessionId;
|
|
2179
|
+
this.files = new StacklinkWorkbenchFiles(client, platformSessionId, () => this.ensureWorkbenchSession());
|
|
2180
|
+
this.runs = new StacklinkWorkbenchRuns(client, platformSessionId, () => this.ensureWorkbenchSession());
|
|
2181
|
+
this.artifacts = new StacklinkWorkbenchArtifacts(client, platformSessionId, () => this.ensureWorkbenchSession());
|
|
2182
|
+
}
|
|
2183
|
+
async use(workbenchSessionId, input = {}) {
|
|
2184
|
+
const response = await this.client.useWorkbenchSession({
|
|
2185
|
+
sessionId: this.platformSessionId,
|
|
2186
|
+
workbenchSessionId,
|
|
2187
|
+
...input,
|
|
2188
|
+
});
|
|
2189
|
+
this.activeWorkbenchSessionId = response.workbenchSession.id;
|
|
2190
|
+
return response;
|
|
2191
|
+
}
|
|
2192
|
+
async run(input, options = {}) {
|
|
2193
|
+
const workbenchSessionId = input.workbenchSessionId ?? await this.ensureWorkbenchSession();
|
|
2194
|
+
const response = await this.client.runWorkbench({
|
|
2195
|
+
...input,
|
|
2196
|
+
sessionId: this.platformSessionId,
|
|
2197
|
+
workbenchSessionId,
|
|
2198
|
+
operation: 'run_code',
|
|
2199
|
+
}, options);
|
|
2200
|
+
this.activeWorkbenchSessionId = response.workbenchSession.id;
|
|
2201
|
+
return new StacklinkWorkbenchRun(this.client, this.platformSessionId, response);
|
|
2202
|
+
}
|
|
2203
|
+
async bash(input, options = {}) {
|
|
2204
|
+
const workbenchSessionId = input.workbenchSessionId ?? await this.ensureWorkbenchSession();
|
|
2205
|
+
const response = await this.client.runWorkbenchBash({
|
|
2206
|
+
...input,
|
|
2207
|
+
sessionId: this.platformSessionId,
|
|
2208
|
+
workbenchSessionId,
|
|
2209
|
+
}, options);
|
|
2210
|
+
this.activeWorkbenchSessionId = response.workbenchSession.id;
|
|
2211
|
+
return new StacklinkWorkbenchRun(this.client, this.platformSessionId, response);
|
|
2212
|
+
}
|
|
2213
|
+
async destroy() {
|
|
2214
|
+
const workbenchSessionId = await this.ensureWorkbenchSession();
|
|
2215
|
+
return this.client.destroyWorkbenchSession({
|
|
2216
|
+
sessionId: this.platformSessionId,
|
|
2217
|
+
workbenchSessionId,
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
async delete() {
|
|
2221
|
+
const workbenchSessionId = await this.ensureWorkbenchSession();
|
|
2222
|
+
const result = await this.client.deleteWorkbenchSession({
|
|
2223
|
+
sessionId: this.platformSessionId,
|
|
2224
|
+
workbenchSessionId,
|
|
2225
|
+
});
|
|
2226
|
+
this.activeWorkbenchSessionId = undefined;
|
|
2227
|
+
return result;
|
|
2228
|
+
}
|
|
2229
|
+
async ensureWorkbenchSession() {
|
|
2230
|
+
if (this.activeWorkbenchSessionId)
|
|
2231
|
+
return this.activeWorkbenchSessionId;
|
|
2232
|
+
const response = await this.use();
|
|
2233
|
+
return response.workbenchSession.id;
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
export class ToolRouterSession {
|
|
2237
|
+
client;
|
|
2238
|
+
id;
|
|
2239
|
+
tenantId;
|
|
2240
|
+
mcp;
|
|
2241
|
+
memory;
|
|
2242
|
+
sandbox;
|
|
2243
|
+
contractVersion;
|
|
2244
|
+
toolDefinitions;
|
|
2245
|
+
constructor(client, id, tenantId, mcp, contractVersion = 'unknown', toolDefinitions = []) {
|
|
2246
|
+
this.client = client;
|
|
2247
|
+
this.id = id;
|
|
2248
|
+
this.tenantId = tenantId;
|
|
2249
|
+
this.mcp = mcp;
|
|
2250
|
+
this.contractVersion = contractVersion;
|
|
2251
|
+
this.toolDefinitions = [...toolDefinitions];
|
|
2252
|
+
this.memory = new StacklinkSessionMemoryClient(client.memory, id);
|
|
2253
|
+
this.sandbox = new StacklinkSessionSandbox(client, id);
|
|
2254
|
+
}
|
|
2255
|
+
async get() {
|
|
2256
|
+
return this.client.getSession(this.id);
|
|
2257
|
+
}
|
|
2258
|
+
async mcpRequest(input, options = {}) {
|
|
2259
|
+
return this.client.mcpSessionRequest(this.id, input, options);
|
|
2260
|
+
}
|
|
2261
|
+
async mcpRequestStream(input, options = {}) {
|
|
2262
|
+
return this.client.mcpSessionRequestStream(this.id, input, options);
|
|
2263
|
+
}
|
|
2264
|
+
async callMcpTool(name, args) {
|
|
2265
|
+
return this.client.callSessionMcpTool(this.id, name, args);
|
|
2266
|
+
}
|
|
2267
|
+
mcpConnection() {
|
|
2268
|
+
if (!this.mcp) {
|
|
2269
|
+
throw new Error('This Stacklink session does not include an MCP connection descriptor.');
|
|
2270
|
+
}
|
|
2271
|
+
return this.client.sessionMcpConnection(this.mcp);
|
|
2272
|
+
}
|
|
2273
|
+
async update(patch) {
|
|
2274
|
+
const response = await this.client.updateSession(this.id, patch);
|
|
2275
|
+
this.client.clearCache(`session:${this.id}:`);
|
|
2276
|
+
const projection = await this.client.getSessionMetaTools(this.id);
|
|
2277
|
+
this.contractVersion = projection.contractVersion;
|
|
2278
|
+
this.toolDefinitions = [...projection.tools];
|
|
2279
|
+
return response;
|
|
2280
|
+
}
|
|
2281
|
+
toolContractVersion() {
|
|
2282
|
+
return this.contractVersion;
|
|
2283
|
+
}
|
|
2284
|
+
toolRegistry() {
|
|
2285
|
+
return this.toolDefinitions.map((definition) => ({
|
|
2286
|
+
...definition,
|
|
2287
|
+
inputSchema: { ...definition.inputSchema },
|
|
2288
|
+
}));
|
|
2289
|
+
}
|
|
2290
|
+
async close() {
|
|
2291
|
+
return this.client.closeSession(this.id);
|
|
2292
|
+
}
|
|
2293
|
+
async routerFacts(query = {}) {
|
|
2294
|
+
return this.client.listSessionRouterFacts(this.id, query);
|
|
2295
|
+
}
|
|
2296
|
+
async connectionEvents() {
|
|
2297
|
+
return this.client.listSessionConnectionEvents(this.id);
|
|
2298
|
+
}
|
|
2299
|
+
async trace(query = {}) {
|
|
2300
|
+
return this.client.getSessionTrace(this.id, query);
|
|
2301
|
+
}
|
|
2302
|
+
async configHistory(query = {}) {
|
|
2303
|
+
return this.client.getSessionConfigHistory(this.id, query);
|
|
2304
|
+
}
|
|
2305
|
+
async workbenchActivity() {
|
|
2306
|
+
return this.client.getSessionWorkbench(this.id);
|
|
2307
|
+
}
|
|
2308
|
+
async toolkits() {
|
|
2309
|
+
const response = await this.client.cachedDiscoveryRequest(`session:${this.id}:toolkits`, this.client.discoveryCacheTtl('toolkits'), undefined, () => this.client.request(`/v1/sessions/${this.id}/toolkits`));
|
|
2310
|
+
return response.toolkits;
|
|
2311
|
+
}
|
|
2312
|
+
async authorize(providerKey, input = {}) {
|
|
2313
|
+
const response = await this.client.request(`/v1/sessions/${this.id}/connections/authorize`, {
|
|
2314
|
+
method: 'POST',
|
|
2315
|
+
body: {
|
|
2316
|
+
providerKey,
|
|
2317
|
+
callbackUrl: input.callbackUrl,
|
|
2318
|
+
authConfigId: input.authConfigId,
|
|
2319
|
+
authMode: input.authMode,
|
|
2320
|
+
metadata: input.metadata ?? {},
|
|
2321
|
+
},
|
|
2322
|
+
});
|
|
2323
|
+
if (!response.authorization) {
|
|
2324
|
+
throw new Error('Stacklink did not return a connection authorization.');
|
|
2325
|
+
}
|
|
2326
|
+
return new StacklinkConnectionRequest(this.client, response.authorization);
|
|
2327
|
+
}
|
|
2328
|
+
async waitForConnections(connectionRequestIds, timeoutMs = 120_000, intervalMs = 2000) {
|
|
2329
|
+
const startedAt = Date.now();
|
|
2330
|
+
while (Date.now() - startedAt <= timeoutMs) {
|
|
2331
|
+
const connectionRequests = await Promise.all(connectionRequestIds.map(async (requestId) => {
|
|
2332
|
+
const response = await this.client.request(`/v1/connection-requests/${requestId}`);
|
|
2333
|
+
return response.connectionRequest;
|
|
2334
|
+
}));
|
|
2335
|
+
const statuses = connectionRequests.map((request) => request?.status);
|
|
2336
|
+
if (statuses.every((status) => status === 'completed')) {
|
|
2337
|
+
return { status: 'completed', connectionRequests };
|
|
2338
|
+
}
|
|
2339
|
+
const terminalFailure = connectionRequests.find((request) => (request?.status === 'failed'
|
|
2340
|
+
|| request?.status === 'expired'
|
|
2341
|
+
|| request?.status === 'cancelled'));
|
|
2342
|
+
if (terminalFailure) {
|
|
2343
|
+
throw new Error(`Stacklink connection ended with status ${terminalFailure.status}.`);
|
|
2344
|
+
}
|
|
2345
|
+
await sleep(intervalMs);
|
|
2346
|
+
}
|
|
2347
|
+
throw new Error('Timed out waiting for Stacklink connections.');
|
|
2348
|
+
}
|
|
2349
|
+
async connectedAccounts() {
|
|
2350
|
+
const response = await this.client.request('/v1/connections', {
|
|
2351
|
+
query: { tenantId: this.tenantId },
|
|
2352
|
+
});
|
|
2353
|
+
return response.connections;
|
|
2354
|
+
}
|
|
2355
|
+
async getConnectedAccount(accountId) {
|
|
2356
|
+
const response = await this.client.request(`/v1/connections/${accountId}`);
|
|
2357
|
+
return response.account;
|
|
2358
|
+
}
|
|
2359
|
+
async updateConnectedAccount(accountId, patch) {
|
|
2360
|
+
const response = await this.client.request(`/v1/connections/${accountId}`, {
|
|
2361
|
+
method: 'PATCH',
|
|
2362
|
+
body: patch,
|
|
2363
|
+
});
|
|
2364
|
+
this.client.clearCache(`session:${this.id}:`);
|
|
2365
|
+
return response.account;
|
|
2366
|
+
}
|
|
2367
|
+
async enableConnectedAccount(accountId) {
|
|
2368
|
+
const response = await this.client.request(`/v1/connections/${accountId}/enable`, {
|
|
2369
|
+
method: 'POST',
|
|
2370
|
+
});
|
|
2371
|
+
this.client.clearCache(`session:${this.id}:`);
|
|
2372
|
+
return response.account;
|
|
2373
|
+
}
|
|
2374
|
+
async disableConnectedAccount(accountId) {
|
|
2375
|
+
const response = await this.client.request(`/v1/connections/${accountId}/disable`, {
|
|
2376
|
+
method: 'POST',
|
|
2377
|
+
});
|
|
2378
|
+
this.client.clearCache(`session:${this.id}:`);
|
|
2379
|
+
return response.account;
|
|
2380
|
+
}
|
|
2381
|
+
async refreshConnectedAccount(accountId) {
|
|
2382
|
+
const response = await this.client.request(`/v1/connections/${accountId}/refresh`, {
|
|
2383
|
+
method: 'POST',
|
|
2384
|
+
});
|
|
2385
|
+
this.client.clearCache(`session:${this.id}:`);
|
|
2386
|
+
return response.account;
|
|
2387
|
+
}
|
|
2388
|
+
async validateConnectedAccount(accountId) {
|
|
2389
|
+
return this.client.request(`/v1/connections/${accountId}/validate`, {
|
|
2390
|
+
method: 'POST',
|
|
2391
|
+
});
|
|
2392
|
+
}
|
|
2393
|
+
async deleteConnectedAccount(accountId) {
|
|
2394
|
+
const response = await this.client.request(`/v1/connections/${accountId}`, {
|
|
2395
|
+
method: 'DELETE',
|
|
2396
|
+
});
|
|
2397
|
+
this.client.clearCache(`session:${this.id}:`);
|
|
2398
|
+
return response.account;
|
|
2399
|
+
}
|
|
2400
|
+
async connectedAccountSecrets(accountId) {
|
|
2401
|
+
const response = await this.client.request(`/v1/connections/${accountId}/secrets`);
|
|
2402
|
+
return response.secrets;
|
|
2403
|
+
}
|
|
2404
|
+
async connectedAccountResources(accountId) {
|
|
2405
|
+
return this.client.listConnectedAccountResources(accountId);
|
|
2406
|
+
}
|
|
2407
|
+
async refreshConnectedAccountResources(accountId) {
|
|
2408
|
+
const response = await this.client.refreshConnectedAccountResources(accountId);
|
|
2409
|
+
this.client.clearCache(`session:${this.id}:`);
|
|
2410
|
+
return response;
|
|
2411
|
+
}
|
|
2412
|
+
async searchTools(input = {}) {
|
|
2413
|
+
const searchInput = {
|
|
2414
|
+
responseMode: 'compact',
|
|
2415
|
+
includeSchemas: false,
|
|
2416
|
+
includeRelatedTools: false,
|
|
2417
|
+
includeExecutionPlan: false,
|
|
2418
|
+
...input,
|
|
2419
|
+
};
|
|
2420
|
+
return this.client.cachedDiscoveryRequest(`session:${this.id}:search:${stableSdkStringify(withoutCacheControl(searchInput))}`, this.client.discoveryCacheTtl('search'), searchInput, () => this.client.request(`/v1/sessions/${this.id}/tools/search`, {
|
|
2421
|
+
method: 'POST',
|
|
2422
|
+
body: discoveryServerBody(searchInput),
|
|
2423
|
+
}));
|
|
2424
|
+
}
|
|
2425
|
+
async getToolSchemas(toolKeys, input = {}) {
|
|
2426
|
+
return this.client.cachedDiscoveryRequest(`session:${this.id}:schemas:${stableSdkStringify({
|
|
2427
|
+
toolKeys: [...toolKeys].sort(),
|
|
2428
|
+
includePlanned: input.includePlanned === true,
|
|
2429
|
+
})}`, this.client.discoveryCacheTtl('schemas'), input, () => this.client.request(`/v1/sessions/${this.id}/tools/schemas`, {
|
|
2430
|
+
method: 'POST',
|
|
2431
|
+
body: {
|
|
2432
|
+
toolKeys,
|
|
2433
|
+
includePlanned: input.includePlanned,
|
|
2434
|
+
...(input.cache === 'bypass' ? { cache: 'bypass' } : {}),
|
|
2435
|
+
},
|
|
2436
|
+
}));
|
|
2437
|
+
}
|
|
2438
|
+
async prepareRuntimeTools(input = {}) {
|
|
2439
|
+
return this.client.request(`/v1/sessions/${this.id}/tools/runtime-contracts`, {
|
|
2440
|
+
method: 'POST',
|
|
2441
|
+
body: input,
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
async prepareTools(input) {
|
|
2445
|
+
const limitPerIntent = input.limitPerIntent ?? 5;
|
|
2446
|
+
const search = await this.searchTools({
|
|
2447
|
+
cache: input.cache,
|
|
2448
|
+
responseMode: 'compact',
|
|
2449
|
+
includeSchemas: false,
|
|
2450
|
+
includeRelatedTools: false,
|
|
2451
|
+
includeExecutionPlan: false,
|
|
2452
|
+
queries: input.intents.map((intent) => ({
|
|
2453
|
+
query: intent,
|
|
2454
|
+
limit: limitPerIntent,
|
|
2455
|
+
...(input.toolkitKey ? { toolkitKey: input.toolkitKey } : {}),
|
|
2456
|
+
...(input.capability ? { capability: input.capability } : {}),
|
|
2457
|
+
})),
|
|
2458
|
+
includePlanned: input.includePlanned === true,
|
|
2459
|
+
model: input.model,
|
|
2460
|
+
limit: Math.max(limitPerIntent, input.intents.length * limitPerIntent),
|
|
2461
|
+
});
|
|
2462
|
+
const toolKeys = uniqueSdkStrings(search.tools.map((tool) => tool.key));
|
|
2463
|
+
const schemaResponse = input.includeSchemas === false || toolKeys.length === 0
|
|
2464
|
+
? { tools: [] }
|
|
2465
|
+
: await this.getToolSchemas(toolKeys, {
|
|
2466
|
+
cache: input.cache,
|
|
2467
|
+
includePlanned: input.includePlanned,
|
|
2468
|
+
});
|
|
2469
|
+
return {
|
|
2470
|
+
tools: search.tools,
|
|
2471
|
+
schemas: schemaResponse.tools,
|
|
2472
|
+
toolKeys,
|
|
2473
|
+
search,
|
|
2474
|
+
};
|
|
2475
|
+
}
|
|
2476
|
+
async searchKnowledge(input = {}) {
|
|
2477
|
+
return this.client.searchKnowledge({
|
|
2478
|
+
...input,
|
|
2479
|
+
sessionId: this.id,
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
async getKnowledgeCapabilities(input = {}) {
|
|
2483
|
+
return this.client.getKnowledgeCapabilities({
|
|
2484
|
+
...input,
|
|
2485
|
+
sessionId: this.id,
|
|
2486
|
+
});
|
|
2487
|
+
}
|
|
2488
|
+
async lookupKnowledgeCitation(input = {}) {
|
|
2489
|
+
return this.client.lookupKnowledgeCitation({
|
|
2490
|
+
...input,
|
|
2491
|
+
sessionId: this.id,
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
async getKnowledgeAmendmentTrail(input = {}) {
|
|
2495
|
+
return this.client.getKnowledgeAmendmentTrail({
|
|
2496
|
+
...input,
|
|
2497
|
+
sessionId: this.id,
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
async verifyKnowledgeEvidence(input = {}) {
|
|
2501
|
+
return this.client.verifyKnowledgeEvidence({
|
|
2502
|
+
...input,
|
|
2503
|
+
sessionId: this.id,
|
|
2504
|
+
});
|
|
2505
|
+
}
|
|
2506
|
+
async verifyKnowledgeAnswer(input) {
|
|
2507
|
+
return this.client.verifyKnowledgeAnswer({
|
|
2508
|
+
...input,
|
|
2509
|
+
sessionId: this.id,
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
async getGstComplianceRule(input = {}) {
|
|
2513
|
+
return this.client.getGstComplianceRule({
|
|
2514
|
+
...input,
|
|
2515
|
+
sessionId: this.id,
|
|
2516
|
+
});
|
|
2517
|
+
}
|
|
2518
|
+
async getGstDueDateRule(input) {
|
|
2519
|
+
return this.client.getGstDueDateRule({
|
|
2520
|
+
...input,
|
|
2521
|
+
sessionId: this.id,
|
|
2522
|
+
});
|
|
2523
|
+
}
|
|
2524
|
+
async calculateGstDueDate(input) {
|
|
2525
|
+
return this.client.calculateGstDueDate({
|
|
2526
|
+
...input,
|
|
2527
|
+
sessionId: this.id,
|
|
2528
|
+
});
|
|
2529
|
+
}
|
|
2530
|
+
async getGstLateFeeRule(input) {
|
|
2531
|
+
return this.client.getGstLateFeeRule({
|
|
2532
|
+
...input,
|
|
2533
|
+
sessionId: this.id,
|
|
2534
|
+
});
|
|
2535
|
+
}
|
|
2536
|
+
async calculateGstLateFee(input) {
|
|
2537
|
+
return this.client.calculateGstLateFee({
|
|
2538
|
+
...input,
|
|
2539
|
+
sessionId: this.id,
|
|
2540
|
+
});
|
|
2541
|
+
}
|
|
2542
|
+
async getGstInterestRule(input = {}) {
|
|
2543
|
+
return this.client.getGstInterestRule({
|
|
2544
|
+
...input,
|
|
2545
|
+
sessionId: this.id,
|
|
2546
|
+
});
|
|
2547
|
+
}
|
|
2548
|
+
async calculateGstInterest(input) {
|
|
2549
|
+
return this.client.calculateGstInterest({
|
|
2550
|
+
...input,
|
|
2551
|
+
sessionId: this.id,
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
async lookupGstHsnSacRate(input) {
|
|
2555
|
+
return this.client.lookupGstHsnSacRate({
|
|
2556
|
+
...input,
|
|
2557
|
+
sessionId: this.id,
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
async checkGstRcm(input) {
|
|
2561
|
+
return this.client.checkGstRcm({
|
|
2562
|
+
...input,
|
|
2563
|
+
sessionId: this.id,
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
async getGstNoticeRule(input) {
|
|
2567
|
+
return this.client.getGstNoticeRule({
|
|
2568
|
+
...input,
|
|
2569
|
+
sessionId: this.id,
|
|
2570
|
+
});
|
|
2571
|
+
}
|
|
2572
|
+
async getGstAppealStageRule(input) {
|
|
2573
|
+
return this.client.getGstAppealStageRule({
|
|
2574
|
+
...input,
|
|
2575
|
+
sessionId: this.id,
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
async executeTool(input, options = {}) {
|
|
2579
|
+
return this.client.request(`/v1/sessions/${this.id}/tools/execute`, {
|
|
2580
|
+
method: 'POST',
|
|
2581
|
+
body: input,
|
|
2582
|
+
...options,
|
|
2583
|
+
});
|
|
2584
|
+
}
|
|
2585
|
+
async executeToolsBatch(input, options = {}) {
|
|
2586
|
+
return this.client.request(`/v1/sessions/${this.id}/tools/execute-batch`, {
|
|
2587
|
+
method: 'POST',
|
|
2588
|
+
body: input,
|
|
2589
|
+
...options,
|
|
2590
|
+
});
|
|
2591
|
+
}
|
|
2592
|
+
async runWorkbench(input, options = {}) {
|
|
2593
|
+
return this.client.runWorkbench({
|
|
2594
|
+
...input,
|
|
2595
|
+
sessionId: this.id,
|
|
2596
|
+
}, options);
|
|
2597
|
+
}
|
|
2598
|
+
async destroyWorkbenchSession(input, options = {}) {
|
|
2599
|
+
return this.client.destroyWorkbenchSession({
|
|
2600
|
+
...input,
|
|
2601
|
+
sessionId: this.id,
|
|
2602
|
+
}, options);
|
|
2603
|
+
}
|
|
2604
|
+
async deleteWorkbenchSession(input) {
|
|
2605
|
+
return this.client.deleteWorkbenchSession({
|
|
2606
|
+
...input,
|
|
2607
|
+
sessionId: this.id,
|
|
2608
|
+
});
|
|
2609
|
+
}
|
|
2610
|
+
async runWorkbenchBash(input, options = {}) {
|
|
2611
|
+
return this.client.runWorkbenchBash({
|
|
2612
|
+
...input,
|
|
2613
|
+
sessionId: this.id,
|
|
2614
|
+
}, options);
|
|
2615
|
+
}
|
|
2616
|
+
async listExecutions(input = {}, options = {}) {
|
|
2617
|
+
return this.client.listExecutions({
|
|
2618
|
+
...input,
|
|
2619
|
+
sessionId: this.id,
|
|
2620
|
+
}, options);
|
|
2621
|
+
}
|
|
2622
|
+
async getExecution(input, options = {}) {
|
|
2623
|
+
return this.client.getExecution({
|
|
2624
|
+
...input,
|
|
2625
|
+
sessionId: this.id,
|
|
2626
|
+
}, options);
|
|
2627
|
+
}
|
|
2628
|
+
async readExecutionEvents(input, options = {}) {
|
|
2629
|
+
return this.client.readExecutionEvents({
|
|
2630
|
+
...input,
|
|
2631
|
+
sessionId: this.id,
|
|
2632
|
+
}, options);
|
|
2633
|
+
}
|
|
2634
|
+
async waitForExecution(input, options = {}) {
|
|
2635
|
+
return this.client.waitForExecution({
|
|
2636
|
+
...input,
|
|
2637
|
+
sessionId: this.id,
|
|
2638
|
+
}, options);
|
|
2639
|
+
}
|
|
2640
|
+
async cancelExecution(input, options = {}) {
|
|
2641
|
+
return this.client.cancelExecution({
|
|
2642
|
+
...input,
|
|
2643
|
+
sessionId: this.id,
|
|
2644
|
+
}, options);
|
|
2645
|
+
}
|
|
2646
|
+
async streamEvents(input = {}) {
|
|
2647
|
+
return this.client.requestRaw(`/v1/sessions/${this.id}/events/stream`, {
|
|
2648
|
+
headers: {
|
|
2649
|
+
accept: 'text/event-stream',
|
|
2650
|
+
},
|
|
2651
|
+
query: {
|
|
2652
|
+
after: input.after,
|
|
2653
|
+
eventType: input.eventTypes,
|
|
2654
|
+
limit: input.limit === undefined ? undefined : String(input.limit),
|
|
2655
|
+
pollIntervalMs: input.pollIntervalMs === undefined ? undefined : String(input.pollIntervalMs),
|
|
2656
|
+
},
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2659
|
+
tools() {
|
|
2660
|
+
return Object.fromEntries(this.toolDefinitions.map((definition) => [
|
|
2661
|
+
definition.name,
|
|
2662
|
+
{
|
|
2663
|
+
description: definition.description,
|
|
2664
|
+
parameters: definition.inputSchema,
|
|
2665
|
+
execute: async (input) => unwrapMcpToolResult(await this.callMcpTool(definition.name, input)),
|
|
2666
|
+
},
|
|
2667
|
+
]));
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
export { ToolRouterSession as StacklinkSession };
|
|
2671
|
+
export class StacklinkConnectionRequest {
|
|
2672
|
+
client;
|
|
2673
|
+
id;
|
|
2674
|
+
providerKey;
|
|
2675
|
+
status;
|
|
2676
|
+
phase;
|
|
2677
|
+
nextAction;
|
|
2678
|
+
redirectUrl;
|
|
2679
|
+
expiresAt;
|
|
2680
|
+
authModes;
|
|
2681
|
+
authRequirements;
|
|
2682
|
+
constructor(client, input) {
|
|
2683
|
+
this.client = client;
|
|
2684
|
+
this.id = input.id;
|
|
2685
|
+
this.providerKey = input.providerKey;
|
|
2686
|
+
this.status = input.status;
|
|
2687
|
+
this.phase = input.phase;
|
|
2688
|
+
this.nextAction = input.nextAction;
|
|
2689
|
+
this.redirectUrl = input.redirectUrl;
|
|
2690
|
+
this.expiresAt = input.expiresAt;
|
|
2691
|
+
this.authModes = input.authModes;
|
|
2692
|
+
this.authRequirements = input.authRequirements ?? [];
|
|
2693
|
+
}
|
|
2694
|
+
async getStatus() {
|
|
2695
|
+
const response = await this.client.request(`/v1/connection-requests/${this.id}`);
|
|
2696
|
+
return response.connectionRequest;
|
|
2697
|
+
}
|
|
2698
|
+
toJSON() {
|
|
2699
|
+
return {
|
|
2700
|
+
id: this.id,
|
|
2701
|
+
providerKey: this.providerKey,
|
|
2702
|
+
status: this.status,
|
|
2703
|
+
phase: this.phase,
|
|
2704
|
+
nextAction: this.nextAction,
|
|
2705
|
+
redirectUrl: this.redirectUrl,
|
|
2706
|
+
expiresAt: this.expiresAt,
|
|
2707
|
+
authModes: this.authModes,
|
|
2708
|
+
authRequirements: this.authRequirements,
|
|
2709
|
+
};
|
|
2710
|
+
}
|
|
2711
|
+
async waitForConnection(timeoutMs = 120_000, intervalMs = 2000) {
|
|
2712
|
+
const startedAt = Date.now();
|
|
2713
|
+
while (Date.now() - startedAt <= timeoutMs) {
|
|
2714
|
+
const connectionRequest = await this.getStatus();
|
|
2715
|
+
if (connectionRequest?.status === 'completed') {
|
|
2716
|
+
return connectionRequest.connectedAccount;
|
|
2717
|
+
}
|
|
2718
|
+
if (connectionRequest?.status === 'failed'
|
|
2719
|
+
|| connectionRequest?.status === 'expired'
|
|
2720
|
+
|| connectionRequest?.status === 'cancelled') {
|
|
2721
|
+
throw new Error(`Stacklink connection ended with status ${connectionRequest.status}.`);
|
|
2722
|
+
}
|
|
2723
|
+
await sleep(intervalMs);
|
|
2724
|
+
}
|
|
2725
|
+
throw new Error('Timed out waiting for Stacklink connection.');
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
function isSdkRecord(value) {
|
|
2729
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2730
|
+
}
|
|
2731
|
+
function unwrapMcpToolResult(response) {
|
|
2732
|
+
if (!isSdkRecord(response))
|
|
2733
|
+
return response;
|
|
2734
|
+
if (isSdkRecord(response.error)) {
|
|
2735
|
+
const message = typeof response.error.message === 'string'
|
|
2736
|
+
? response.error.message
|
|
2737
|
+
: 'Stacklink MCP tool call failed.';
|
|
2738
|
+
const code = typeof response.error.code === 'string' || typeof response.error.code === 'number'
|
|
2739
|
+
? String(response.error.code)
|
|
2740
|
+
: undefined;
|
|
2741
|
+
throw new StacklinkApiError(message, 400, code, response.error.data);
|
|
2742
|
+
}
|
|
2743
|
+
const result = response.result;
|
|
2744
|
+
if (!isSdkRecord(result))
|
|
2745
|
+
return result;
|
|
2746
|
+
if (result.isError === true) {
|
|
2747
|
+
const errorText = Array.isArray(result.content)
|
|
2748
|
+
? result.content
|
|
2749
|
+
.filter(isSdkRecord)
|
|
2750
|
+
.filter((item) => item.type === 'text' && typeof item.text === 'string')
|
|
2751
|
+
.map((item) => String(item.text))
|
|
2752
|
+
.join('\n')
|
|
2753
|
+
: '';
|
|
2754
|
+
throw new StacklinkApiError(errorText || 'Stacklink MCP tool call failed.', 400, 'mcp_tool_error', result);
|
|
2755
|
+
}
|
|
2756
|
+
if ('structuredContent' in result)
|
|
2757
|
+
return result.structuredContent;
|
|
2758
|
+
if (!Array.isArray(result.content))
|
|
2759
|
+
return result;
|
|
2760
|
+
const textItems = result.content
|
|
2761
|
+
.filter(isSdkRecord)
|
|
2762
|
+
.filter((item) => item.type === 'text' && typeof item.text === 'string')
|
|
2763
|
+
.map((item) => String(item.text));
|
|
2764
|
+
if (textItems.length !== 1)
|
|
2765
|
+
return result;
|
|
2766
|
+
try {
|
|
2767
|
+
return JSON.parse(textItems[0]);
|
|
2768
|
+
}
|
|
2769
|
+
catch {
|
|
2770
|
+
return textItems[0];
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
function isTerminalSdkExecution(value) {
|
|
2774
|
+
if (!isSdkRecord(value))
|
|
2775
|
+
return false;
|
|
2776
|
+
const status = value.status;
|
|
2777
|
+
return status === 'completed'
|
|
2778
|
+
|| status === 'failed'
|
|
2779
|
+
|| status === 'cancelled'
|
|
2780
|
+
|| status === 'timed_out';
|
|
2781
|
+
}
|
|
2782
|
+
//# sourceMappingURL=index.js.map
|