@stacklink/sdk 0.4.0 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { botApiSignaturePayload } from '../domain/bot-contract.js';
2
2
  import { materializeStacklinkWorkbenchExecutionResponse, } from '../domain/stacklink-meta-tools.js';
3
3
  export { StacklinkMemoryLifecycle, StacklinkMemoryLifecycleError, createStacklinkMemoryLifecycle, serializeCompletedConversationTurn, } from './memory-lifecycle.js';
4
- export const stacklinkTypeScriptSdkVersion = '0.4.0';
4
+ export const stacklinkTypeScriptSdkVersion = '0.6.3';
5
5
  const workbenchReusableRunComparisonWaitMs = 120_000;
6
6
  const workbenchReusableRunComparisonPollMs = 1_000;
7
7
  export class StacklinkApiError extends Error {
@@ -233,6 +233,7 @@ export class Stacklink {
233
233
  timeoutMs;
234
234
  maxAttempts;
235
235
  bots;
236
+ workflows;
236
237
  approvals;
237
238
  webhooks;
238
239
  triggers;
@@ -261,6 +262,7 @@ export class Stacklink {
261
262
  maxEntries: options.cache?.maxEntries ?? 500,
262
263
  };
263
264
  this.bots = new StacklinkBotsClient(this);
265
+ this.workflows = new StacklinkWorkflowsClient(this);
264
266
  this.approvals = new StacklinkApprovalsClient(this);
265
267
  this.webhooks = new StacklinkWebhooksClient(this);
266
268
  this.triggers = new StacklinkTriggersClient(this);
@@ -551,6 +553,7 @@ export class Stacklink {
551
553
  async runWorkbench(input, options = {}) {
552
554
  const response = await this.request('/v1/workbench/run', {
553
555
  method: 'POST',
556
+ idempotencyKey: typeof input.idempotencyKey === 'string' ? input.idempotencyKey : undefined,
554
557
  body: input,
555
558
  signal: options.signal,
556
559
  });
@@ -791,6 +794,7 @@ export class Stacklink {
791
794
  async runWorkbenchBash(input, options = {}) {
792
795
  const response = await this.request('/v1/workbench/bash', {
793
796
  method: 'POST',
797
+ idempotencyKey: typeof input.idempotencyKey === 'string' ? input.idempotencyKey : undefined,
794
798
  body: input,
795
799
  signal: options.signal,
796
800
  });
@@ -801,7 +805,7 @@ export class Stacklink {
801
805
  return response;
802
806
  }
803
807
  async waitForWorkbenchResponse(input, accepted, options = {}) {
804
- const sessionId = typeof input.sessionId === 'string' ? input.sessionId : undefined;
808
+ const sessionId = workbenchExecutionSessionId(accepted, typeof input.sessionId === 'string' ? input.sessionId : undefined);
805
809
  const executionId = typeof accepted.executionId === 'string' ? accepted.executionId : undefined;
806
810
  const executionKind = accepted.executionKind === 'workbench_code' || accepted.executionKind === 'workbench_bash'
807
811
  ? accepted.executionKind
@@ -1524,7 +1528,7 @@ export class Stacklink {
1524
1528
  attachAbortSignalCancellation(input, response, signal) {
1525
1529
  if (!signal)
1526
1530
  return;
1527
- const sessionId = typeof input.sessionId === 'string' ? input.sessionId : undefined;
1531
+ const sessionId = workbenchExecutionSessionId(response, typeof input.sessionId === 'string' ? input.sessionId : undefined);
1528
1532
  const executionId = typeof response.executionId === 'string'
1529
1533
  ? response.executionId
1530
1534
  : isSdkRecord(response.executionLog) && typeof response.executionLog.id === 'string'
@@ -2482,6 +2486,12 @@ export class StacklinkSessionMemoryClient {
2482
2486
  });
2483
2487
  }
2484
2488
  }
2489
+ function workbenchExecutionSessionId(response, fallback) {
2490
+ const workspace = response.workbenchSession;
2491
+ return isSdkRecord(workspace) && typeof workspace.platformSessionId === 'string'
2492
+ ? workspace.platformSessionId
2493
+ : fallback;
2494
+ }
2485
2495
  export class StacklinkWorkbenchRun {
2486
2496
  client;
2487
2497
  platformSessionId;
@@ -2492,6 +2502,7 @@ export class StacklinkWorkbenchRun {
2492
2502
  this.client = client;
2493
2503
  this.platformSessionId = platformSessionId;
2494
2504
  this.response = response;
2505
+ this.platformSessionId = workbenchExecutionSessionId(response, platformSessionId) ?? platformSessionId;
2495
2506
  this.executionId = response.executionId;
2496
2507
  this.executionKind = response.executionKind;
2497
2508
  }
@@ -2706,7 +2717,9 @@ export class StacklinkSessionSandbox {
2706
2717
  workbenchSessionId,
2707
2718
  operation: 'run_code',
2708
2719
  }, options);
2709
- this.activeWorkbenchSessionId = response.workbenchSession.id;
2720
+ if (!response.workbenchSession.platformSessionId || response.workbenchSession.platformSessionId === this.platformSessionId) {
2721
+ this.activeWorkbenchSessionId = response.workbenchSession.id;
2722
+ }
2710
2723
  return new StacklinkWorkbenchRun(this.client, this.platformSessionId, response);
2711
2724
  }
2712
2725
  async bash(input, options = {}) {
@@ -2716,7 +2729,9 @@ export class StacklinkSessionSandbox {
2716
2729
  sessionId: this.platformSessionId,
2717
2730
  workbenchSessionId,
2718
2731
  }, options);
2719
- this.activeWorkbenchSessionId = response.workbenchSession.id;
2732
+ if (!response.workbenchSession.platformSessionId || response.workbenchSession.platformSessionId === this.platformSessionId) {
2733
+ this.activeWorkbenchSessionId = response.workbenchSession.id;
2734
+ }
2720
2735
  return new StacklinkWorkbenchRun(this.client, this.platformSessionId, response);
2721
2736
  }
2722
2737
  async destroy() {
@@ -2826,6 +2841,7 @@ export class ToolRouterSession {
2826
2841
  body: {
2827
2842
  connectionRef,
2828
2843
  oauthScopeProfile: input.oauthScopeProfile,
2844
+ amazonSellerRegion: input.amazonSellerRegion,
2829
2845
  metadata: input.metadata ?? {},
2830
2846
  },
2831
2847
  });
@@ -3281,13 +3297,14 @@ export class StacklinkBotsClient {
3281
3297
  delete(botId) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}`, { method: 'DELETE' }); }
3282
3298
  deleteCustomerData(botId, sessionId) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}/customer-data/delete`, { method: 'POST', body: { sessionId } }); }
3283
3299
  setState(botId, input) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}/state`, { method: 'POST', body: input }); }
3284
- list() { return this.client.request('/v1/bots'); }
3300
+ list(query) { return this.client.request('/v1/bots', { query }); }
3285
3301
  create(name, identity) { return this.client.request('/v1/bots', { method: 'POST', body: { name, ...identity } }); }
3286
3302
  get(botId) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}`); }
3287
3303
  update(botId, revision, patch) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}`, { method: 'PATCH', body: { revision, patch } }); }
3288
3304
  publish(botId, revision, channels) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}/publish`, { method: 'POST', body: { revision, channels } }); }
3289
3305
  run(botId, input) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}/runs`, { method: 'POST', body: { ...input, runId: input.runId ?? globalThis.crypto.randomUUID() } }); }
3290
3306
  getRun(botId, runId) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}/runs/${encodeURIComponent(runId)}`); }
3307
+ continueRun(botId, runId) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}/runs/${encodeURIComponent(runId)}/continue`, { method: 'POST', body: {} }); }
3291
3308
  /** Observe the same durable run. Returns when finished or when a person must act. */
3292
3309
  async wait(botId, runId, options = {}) {
3293
3310
  const deadline = Date.now() + positiveSdkInteger(options.totalTimeoutMs ?? 300_000, 'totalTimeoutMs');
@@ -3295,7 +3312,7 @@ export class StacklinkBotsClient {
3295
3312
  if (options.signal?.aborted)
3296
3313
  throw options.signal.reason;
3297
3314
  const run = await this.client.request(`/v1/bots/${encodeURIComponent(botId)}/runs/${encodeURIComponent(runId)}`, { signal: options.signal, timeoutMs: Math.min(30_000, deadline - Date.now()) });
3298
- if (['completed', 'failed', 'stopped', 'cancelled', 'waiting_for_approval', 'waiting_for_connection'].includes(run.status))
3315
+ if (['completed', 'failed', 'stopped', 'cancelled', 'waiting_for_approval', 'waiting_for_connection'].includes(run.status) || run.waitingOperation?.kind === 'funding')
3299
3316
  return run;
3300
3317
  await sdkDelay(Math.min(1000, Math.max(1, deadline - Date.now())), options.signal ?? AbortSignal.timeout(Math.max(1, deadline - Date.now())));
3301
3318
  }
@@ -3305,4 +3322,52 @@ export class StacklinkBotsClient {
3305
3322
  stream(botId, runId, options = {}) { return this.client.streamBotEvents(botId, runId, options); }
3306
3323
  cancel(botId, runId) { return this.client.request(`/v1/bots/${encodeURIComponent(botId)}/runs/${encodeURIComponent(runId)}/stop`, { method: 'POST', body: {} }); }
3307
3324
  }
3325
+ /** Visual and code-defined workflows use the same immutable graph and run API. */
3326
+ export class StacklinkWorkflowsClient {
3327
+ client;
3328
+ context;
3329
+ constructor(client, context) {
3330
+ this.client = client;
3331
+ this.context = context;
3332
+ }
3333
+ /** Backend administration of one customer; never expose the project key in the browser. */
3334
+ forCustomer(customerId) { return new StacklinkWorkflowsClient(this.client, { customerId }); }
3335
+ /** Person-scoped data/decision calls from your authenticated backend. Same workflow methods. */
3336
+ withEmbeddedAccess(projectId, accessToken) { return new StacklinkWorkflowsClient(this.client, { projectId, accessToken }); }
3337
+ request(path, init = {}) { return this.client.request(path, { ...init, headers: { ...init.headers, ...(this.context?.customerId ? { 'X-Stacklink-Customer': this.context.customerId } : {}), ...(this.context?.accessToken ? { authorization: `Bearer ${this.context.accessToken}` } : {}) } }); }
3338
+ path(id) { return `${this.context?.projectId ? `/embedded/api/projects/${encodeURIComponent(this.context.projectId)}/workflows` : '/v1/workflows'}${id ? `/${encodeURIComponent(id)}` : ''}`; }
3339
+ list(query) { return this.request(this.path(), { query }); }
3340
+ create(input) { return this.request(this.path(), { method: 'POST', body: input }); }
3341
+ get(id) { return this.request(this.path(id)); }
3342
+ update(id, input) { return this.request(this.path(id), { method: 'PATCH', body: input }); }
3343
+ validate(definition) { return this.request(`${this.path()}/validate`, { method: 'POST', body: { definition } }); }
3344
+ publish(id, revision) { return this.request(`${this.path(id)}/publish`, { method: 'POST', body: { revision } }); }
3345
+ setState(id, paused) { return this.request(`${this.path(id)}/state`, { method: 'POST', body: { paused } }); }
3346
+ versions(id) { return this.request(`${this.path(id)}/versions`); }
3347
+ run(id, input) { return this.request(`${this.path(id)}/runs`, { method: 'POST', body: input, idempotencyKey: input.jobKey }); }
3348
+ runs(id, query) { return this.request(`${this.path(id)}/runs`, { query }); }
3349
+ getRun(id, runId) { return this.request(`${this.path(id)}/runs/${encodeURIComponent(runId)}`); }
3350
+ events(id, runId, query) { return this.request(`${this.path(id)}/runs/${encodeURIComponent(runId)}/events`, { query }); }
3351
+ action(id, runId, input) { return this.request(`${this.path(id)}/runs/${encodeURIComponent(runId)}/actions`, { method: 'POST', body: input }); }
3352
+ triggers(id) { return this.request(`${this.path(id)}/triggers`); }
3353
+ saveTrigger(id, input) { return this.request(`${this.path(id)}/triggers`, { method: 'POST', body: input }); }
3354
+ deleteTrigger(id, triggerId, expectedRevision) { return this.request(`${this.path(id)}/triggers/${encodeURIComponent(triggerId)}`, { method: 'DELETE', query: { expectedRevision } }); }
3355
+ invokeTrigger(id, triggerId, requestId, input) { return this.request(`${this.path(id)}/triggers/${encodeURIComponent(triggerId)}/invoke`, { method: 'POST', body: { requestId, input }, idempotencyKey: requestId }); }
3356
+ previewSchedule(cron, timezone) { return this.request(`${this.path()}/schedule/preview`, { method: 'POST', body: { cron, timezone } }); }
3357
+ searchMentions(query = {}) { return this.request(`${this.path()}/mentions`, { query }); }
3358
+ resolveMentions(references, workflowId) { return this.request(`${this.path()}/mentions/resolve`, { method: 'POST', body: { references, workflowId } }); }
3359
+ suggest(id, description, revision, sessionId, mentions) { return this.request(`${this.path(id)}/suggest`, { method: 'POST', body: { description, revision, sessionId, mentions }, timeoutMs: 60_000 }); }
3360
+ issueEmbeddedAccess(input) { return this.client.request('/v1/workflows/embed/access', { method: 'POST', body: input }); }
3361
+ exchangeEmbeddedAccess(bootstrapToken, origin) { return this.client.request('/v1/workflows/embed/exchange', { method: 'POST', body: { bootstrapToken, origin } }); }
3362
+ embedSettings() { return this.request(`${this.path()}/embed`); }
3363
+ saveEmbedSettings(input) { return this.request(`${this.path()}/embed`, { method: 'PUT', body: input }); }
3364
+ customers(query) { return this.request(`${this.path()}/embed/customers`, { query }); }
3365
+ customer(id) { return this.request(`${this.path()}/embed/customers/${encodeURIComponent(id)}`); }
3366
+ setCustomerAutomations(id, enabled) { return this.request(`${this.path()}/embed/customers/${encodeURIComponent(id)}/automations`, { method: 'POST', body: { enabled } }); }
3367
+ setCustomerPersonAccess(customerId, personId, action) { return this.request(`${this.path()}/embed/customers/${encodeURIComponent(customerId)}/people/${encodeURIComponent(personId)}/access`, { method: 'POST', body: { action } }); }
3368
+ analytics(query) { return this.request(`${this.path()}/analytics`, { query }); }
3369
+ activity(query) { return this.request(`${this.path()}/activity`, { query }); }
3370
+ approvals(query) { return this.request(`${this.path()}/approvals`, { query }); }
3371
+ decideApproval(id, input) { return this.request(`${this.path()}/approvals/${encodeURIComponent(id)}/decide`, { method: 'POST', body: input }); }
3372
+ }
3308
3373
  //# sourceMappingURL=index.js.map