Skip to main content

Task Workers

TaskWorker connects to Sekuire task stream (SSE), executes capability handlers, and reports completion.

This shares credentials with SDK/Beacon automatically.

import { SekuireSDK } from '@sekuire/sdk';

const sdk = SekuireSDK.fromEnv();
await sdk.start();

const worker = sdk.createTaskWorker({
capabilities: ['summarize'],
heartbeatIntervalMs: 10_000,
});

worker.onTask('summarize', async (_ctx, input) => {
const text = String(input.text ?? '');
return { summary: text.slice(0, 140) };
});

await worker.start();

Manual Worker Creation​

import { createWorker } from '@sekuire/sdk';

const worker = createWorker({
apiBaseUrl: 'https://api.sekuire.ai',
agentId: process.env.SEKUIRE_AGENT_ID!,
installToken: process.env.SEKUIRE_INSTALL_TOKEN,
// Or use runtime/recovery credentials directly:
// runtimeToken: process.env.SEKUIRE_RUNTIME_TOKEN,
// installationId: process.env.SEKUIRE_INSTALLATION_ID,
// refreshToken: process.env.SEKUIRE_REFRESH_TOKEN,
capabilities: ['summarize'],
});

worker.onTask('summarize', async (ctx, input) => {
console.log(ctx.taskId, ctx.workspaceId, ctx.traceId);
return { summary: String(input.text ?? '').slice(0, 140) };
});

await worker.start();

Authentication Priority​

Worker startup auth order:

  1. runtimeToken (or tokenProvider / credentialsStore runtime token)
  2. installationId + refreshToken recovery
  3. installToken bootstrap

Control Commands​

Worker listens for platform control commands (pause, resume, terminate).

worker.onCommand((cmd) => {
console.log(cmd.type, cmd.reason);
});

if (worker.getIsPaused()) {
console.log('Worker is paused');
}

Paused workers reject new tasks and report failure responses.

Policy Gateway Integration​

Pass policyGateway in worker config (or use sdk.createTaskWorker() where available) to enforce:

  • request rate limits before handler execution
  • capability allow/deny checks per task

Worker heartbeats also process active_policy_hash and call policyGateway.onHeartbeatResponse(...) to refresh policy when server policy changes.

Shared Credential Store​

If Beacon and Worker run together manually, use one RuntimeCredentialsStore for both to keep refreshed runtime tokens in sync.

Next Steps​