@some-useful-agents/temporal-provider 0.1.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.
@@ -0,0 +1,18 @@
1
+ import type { AgentDefinition } from '@some-useful-agents/core';
2
+ export interface RunAgentActivityInput {
3
+ agent: AgentDefinition;
4
+ secretsPath: string;
5
+ }
6
+ export interface RunAgentActivityResult {
7
+ result: string;
8
+ exitCode: number;
9
+ error?: string;
10
+ warnings: string[];
11
+ }
12
+ /**
13
+ * Activity: run an agent end-to-end.
14
+ * This runs on the worker (host machine) with access to shell + claude CLI + secrets store.
15
+ * Workflows call this activity; workflows themselves are deterministic and can't spawn processes.
16
+ */
17
+ export declare function runAgentActivity(input: RunAgentActivityInput): Promise<RunAgentActivityResult>;
18
+ //# sourceMappingURL=activities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../src/activities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGhE,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,eAAe,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CA6BpG"}
@@ -0,0 +1,33 @@
1
+ import { buildAgentEnv, getTrustLevel, executeAgent, EncryptedFileStore } from '@some-useful-agents/core';
2
+ /**
3
+ * Activity: run an agent end-to-end.
4
+ * This runs on the worker (host machine) with access to shell + claude CLI + secrets store.
5
+ * Workflows call this activity; workflows themselves are deterministic and can't spawn processes.
6
+ */
7
+ export async function runAgentActivity(input) {
8
+ const secretsStore = new EncryptedFileStore(input.secretsPath);
9
+ const secrets = await secretsStore.getAll();
10
+ const trustLevel = getTrustLevel(input.agent);
11
+ const { env, missingSecrets, warnings } = buildAgentEnv({
12
+ agent: input.agent,
13
+ trustLevel,
14
+ secrets,
15
+ });
16
+ if (missingSecrets.length > 0) {
17
+ return {
18
+ result: '',
19
+ exitCode: 1,
20
+ error: `Missing secrets: ${missingSecrets.join(', ')}. Run: sua secrets set <name>`,
21
+ warnings,
22
+ };
23
+ }
24
+ const handle = executeAgent(input.agent, env);
25
+ const execResult = await handle.promise;
26
+ return {
27
+ result: execResult.result,
28
+ exitCode: execResult.exitCode,
29
+ error: execResult.error,
30
+ warnings,
31
+ };
32
+ }
33
+ //# sourceMappingURL=activities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activities.js","sourceRoot":"","sources":["../src/activities.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAc1G;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAA4B;IACjE,MAAM,YAAY,GAAG,IAAI,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,CAAC;IAC5C,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAE9C,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC;QACtD,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,UAAU;QACV,OAAO;KACR,CAAC,CAAC;IAEH,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO;YACL,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,CAAC;YACX,KAAK,EAAE,oBAAoB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,+BAA+B;YACnF,QAAQ;SACT,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;IAExC,OAAO;QACL,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,QAAQ;KACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=activities.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activities.test.d.ts","sourceRoot":"","sources":["../src/activities.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,84 @@
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
+ import { rmSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { EncryptedFileStore } from '@some-useful-agents/core';
5
+ import { runAgentActivity } from './activities.js';
6
+ const TEST_DIR = join(import.meta.dirname, '__test-activities__');
7
+ const SECRETS_PATH = join(TEST_DIR, 'secrets.enc');
8
+ beforeEach(() => {
9
+ rmSync(TEST_DIR, { recursive: true, force: true });
10
+ });
11
+ afterEach(() => {
12
+ rmSync(TEST_DIR, { recursive: true, force: true });
13
+ });
14
+ function shellAgent(overrides = {}) {
15
+ return {
16
+ name: 'test-agent',
17
+ type: 'shell',
18
+ command: 'echo hello-from-activity',
19
+ source: 'local',
20
+ ...overrides,
21
+ };
22
+ }
23
+ describe('runAgentActivity', () => {
24
+ it('runs a shell agent end-to-end', async () => {
25
+ const result = await runAgentActivity({
26
+ agent: shellAgent(),
27
+ secretsPath: SECRETS_PATH,
28
+ });
29
+ expect(result.exitCode).toBe(0);
30
+ expect(result.result).toContain('hello-from-activity');
31
+ expect(result.error).toBeUndefined();
32
+ });
33
+ it('captures non-zero exit codes', async () => {
34
+ const result = await runAgentActivity({
35
+ agent: shellAgent({ command: 'exit 42' }),
36
+ secretsPath: SECRETS_PATH,
37
+ });
38
+ expect(result.exitCode).toBe(42);
39
+ expect(result.error).toBeTruthy();
40
+ });
41
+ it('injects secrets from store', async () => {
42
+ const store = new EncryptedFileStore(SECRETS_PATH);
43
+ await store.set('MY_SECRET_VAR', 'injected-value');
44
+ const result = await runAgentActivity({
45
+ agent: shellAgent({
46
+ command: 'echo "got=$MY_SECRET_VAR"',
47
+ secrets: ['MY_SECRET_VAR'],
48
+ }),
49
+ secretsPath: SECRETS_PATH,
50
+ });
51
+ expect(result.exitCode).toBe(0);
52
+ expect(result.result).toContain('got=injected-value');
53
+ });
54
+ it('fails with clear error when secret is missing', async () => {
55
+ const result = await runAgentActivity({
56
+ agent: shellAgent({ secrets: ['DOES_NOT_EXIST'] }),
57
+ secretsPath: SECRETS_PATH,
58
+ });
59
+ expect(result.exitCode).toBe(1);
60
+ expect(result.error).toContain('Missing secrets');
61
+ expect(result.error).toContain('DOES_NOT_EXIST');
62
+ });
63
+ it('community agents do NOT inherit dangerous process.env vars', async () => {
64
+ // Set a fake AWS-looking var in this test's env
65
+ process.env.TEST_FAKE_AWS_SECRET = 'should-not-leak-to-community-agent';
66
+ try {
67
+ const result = await runAgentActivity({
68
+ agent: shellAgent({
69
+ source: 'community',
70
+ command: 'echo "leak=$TEST_FAKE_AWS_SECRET"',
71
+ }),
72
+ secretsPath: SECRETS_PATH,
73
+ });
74
+ expect(result.exitCode).toBe(0);
75
+ // The var should NOT be present in the agent's env
76
+ expect(result.result).toContain('leak=');
77
+ expect(result.result).not.toContain('should-not-leak-to-community-agent');
78
+ }
79
+ finally {
80
+ delete process.env.TEST_FAKE_AWS_SECRET;
81
+ }
82
+ });
83
+ });
84
+ //# sourceMappingURL=activities.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activities.test.js","sourceRoot":"","sources":["../src/activities.test.ts"],"names":[],"mappings":"AAA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E,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAClD,WAAW,EAAE,YAAY;SAC1B,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;QAClD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4DAA4D,EAAE,KAAK,IAAI,EAAE;QAC1E,gDAAgD;QAChD,OAAO,CAAC,GAAG,CAAC,oBAAoB,GAAG,oCAAoC,CAAC;QAExE,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC;gBACpC,KAAK,EAAE,UAAU,CAAC;oBAChB,MAAM,EAAE,WAAW;oBACnB,OAAO,EAAE,mCAAmC;iBAC7C,CAAC;gBACF,WAAW,EAAE,YAAY;aAC1B,CAAC,CAAC;YAEH,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChC,mDAAmD;YACnD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACzC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,oCAAoC,CAAC,CAAC;QAC5E,CAAC;gBAAS,CAAC;YACT,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './provider.js';
2
+ export * from './worker.js';
3
+ export type { RunAgentWorkflowInput, RunAgentWorkflowResult } from './workflows.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,YAAY,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './provider.js';
2
+ export * from './worker.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { Provider, AgentDefinition, Run, RunStatus } from '@some-useful-agents/core';
2
+ export interface TemporalProviderOptions {
3
+ dbPath: string;
4
+ secretsPath: string;
5
+ address?: string;
6
+ namespace?: string;
7
+ taskQueue?: string;
8
+ }
9
+ export declare class TemporalProvider implements Provider {
10
+ name: string;
11
+ private store;
12
+ private client;
13
+ private connection;
14
+ private readonly options;
15
+ constructor(options: TemporalProviderOptions);
16
+ initialize(): Promise<void>;
17
+ shutdown(): Promise<void>;
18
+ submitRun(request: {
19
+ agent: AgentDefinition;
20
+ triggeredBy: Run['triggeredBy'];
21
+ }): Promise<Run>;
22
+ private trackCompletion;
23
+ getRun(runId: string): Promise<Run | null>;
24
+ listRuns(filter?: {
25
+ agentName?: string;
26
+ status?: RunStatus;
27
+ limit?: number;
28
+ }): Promise<Run[]>;
29
+ cancelRun(runId: string): Promise<void>;
30
+ getRunLogs(runId: string): Promise<string>;
31
+ }
32
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAK1F,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,gBAAiB,YAAW,QAAQ;IAC/C,IAAI,SAAc;IAElB,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;gBAEhD,OAAO,EAAE,uBAAuB;IAWtC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAKzB,SAAS,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,eAAe,CAAC;QAAC,WAAW,EAAE,GAAG,CAAC,aAAa,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;YA8BrF,eAAe;IAuBvB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAI1C,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,SAAS,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAI7F,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBvC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAQjD"}
@@ -0,0 +1,111 @@
1
+ import { Connection, Client, WorkflowNotFoundError } from '@temporalio/client';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { RunStore } from '@some-useful-agents/core';
4
+ import { DEFAULT_TASK_QUEUE } from './worker.js';
5
+ export class TemporalProvider {
6
+ name = 'temporal';
7
+ store;
8
+ client;
9
+ connection;
10
+ options;
11
+ constructor(options) {
12
+ this.store = new RunStore(options.dbPath);
13
+ this.options = {
14
+ dbPath: options.dbPath,
15
+ secretsPath: options.secretsPath,
16
+ address: options.address ?? process.env.TEMPORAL_ADDRESS ?? 'localhost:7233',
17
+ namespace: options.namespace ?? 'default',
18
+ taskQueue: options.taskQueue ?? DEFAULT_TASK_QUEUE,
19
+ };
20
+ }
21
+ async initialize() {
22
+ this.connection = await Connection.connect({ address: this.options.address });
23
+ this.client = new Client({ connection: this.connection, namespace: this.options.namespace });
24
+ }
25
+ async shutdown() {
26
+ await this.connection?.close();
27
+ this.store.close();
28
+ }
29
+ async submitRun(request) {
30
+ const run = {
31
+ id: randomUUID(),
32
+ agentName: request.agent.name,
33
+ status: 'pending',
34
+ startedAt: new Date().toISOString(),
35
+ triggeredBy: request.triggeredBy,
36
+ };
37
+ this.store.createRun(run);
38
+ const input = {
39
+ agent: request.agent,
40
+ secretsPath: this.options.secretsPath,
41
+ };
42
+ // Fire-and-forget start; poll for status later via workflow handle
43
+ const handle = await this.client.workflow.start('runAgentWorkflow', {
44
+ taskQueue: this.options.taskQueue,
45
+ workflowId: `sua-run-${run.id}`,
46
+ args: [input],
47
+ });
48
+ this.store.updateRun(run.id, { status: 'running' });
49
+ // Track completion in the background so status queries reflect final state
50
+ void this.trackCompletion(run.id, handle.workflowId);
51
+ return { ...run, status: 'running' };
52
+ }
53
+ async trackCompletion(runId, workflowId) {
54
+ try {
55
+ const handle = this.client.workflow.getHandle(workflowId);
56
+ const result = await handle.result();
57
+ const status = result.exitCode === 0 ? 'completed' : 'failed';
58
+ this.store.updateRun(runId, {
59
+ status,
60
+ completedAt: new Date().toISOString(),
61
+ result: result.result,
62
+ exitCode: result.exitCode,
63
+ error: result.error,
64
+ });
65
+ }
66
+ catch (err) {
67
+ const errorMsg = err instanceof Error ? err.message : String(err);
68
+ this.store.updateRun(runId, {
69
+ status: 'failed',
70
+ completedAt: new Date().toISOString(),
71
+ error: errorMsg,
72
+ });
73
+ }
74
+ }
75
+ async getRun(runId) {
76
+ return this.store.getRun(runId);
77
+ }
78
+ async listRuns(filter) {
79
+ return this.store.listRuns(filter);
80
+ }
81
+ async cancelRun(runId) {
82
+ const run = this.store.getRun(runId);
83
+ if (!run)
84
+ return;
85
+ try {
86
+ const handle = this.client.workflow.getHandle(`sua-run-${runId}`);
87
+ await handle.cancel();
88
+ }
89
+ catch (err) {
90
+ if (!(err instanceof WorkflowNotFoundError))
91
+ throw err;
92
+ }
93
+ this.store.updateRun(runId, {
94
+ status: 'cancelled',
95
+ completedAt: new Date().toISOString(),
96
+ error: 'Cancelled by user',
97
+ });
98
+ }
99
+ async getRunLogs(runId) {
100
+ const run = this.store.getRun(runId);
101
+ if (!run)
102
+ return '';
103
+ const parts = [];
104
+ if (run.result)
105
+ parts.push(run.result);
106
+ if (run.error)
107
+ parts.push(`[ERROR] ${run.error}`);
108
+ return parts.join('\n') || '(no output)';
109
+ }
110
+ }
111
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAWjD,MAAM,OAAO,gBAAgB;IAC3B,IAAI,GAAG,UAAU,CAAC;IAEV,KAAK,CAAW;IAChB,MAAM,CAAU;IAChB,UAAU,CAAc;IACf,OAAO,CAAoC;IAE5D,YAAY,OAAgC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC1C,IA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C,IAAI,CAAC,GAAG;YAAE,OAAO,EAAE,CAAC;QACpB,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,GAAG,CAAC,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,GAAG,CAAC,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;QAClD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC;IAC3C,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import { Worker } from '@temporalio/worker';
2
+ export interface StartWorkerOptions {
3
+ address?: string;
4
+ namespace?: string;
5
+ taskQueue?: string;
6
+ }
7
+ export declare const DEFAULT_TASK_QUEUE = "sua-agents";
8
+ /**
9
+ * Starts the Temporal worker process. This runs on the host, not in Docker,
10
+ * because agents need to spawn shell commands and access Claude CLI.
11
+ */
12
+ export declare function startWorker(options?: StartWorkerOptions): Promise<Worker>;
13
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,oBAAoB,CAAC;AAK9D,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAE/C;;;GAGG;AACH,wBAAsB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBnF"}
package/dist/worker.js ADDED
@@ -0,0 +1,26 @@
1
+ import { Worker, NativeConnection } from '@temporalio/worker';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { dirname, resolve } from 'node:path';
4
+ import * as activities from './activities.js';
5
+ export const DEFAULT_TASK_QUEUE = 'sua-agents';
6
+ /**
7
+ * Starts the Temporal worker process. This runs on the host, not in Docker,
8
+ * because agents need to spawn shell commands and access Claude CLI.
9
+ */
10
+ export async function startWorker(options = {}) {
11
+ const address = options.address ?? process.env.TEMPORAL_ADDRESS ?? 'localhost:7233';
12
+ const namespace = options.namespace ?? 'default';
13
+ const taskQueue = options.taskQueue ?? DEFAULT_TASK_QUEUE;
14
+ const connection = await NativeConnection.connect({ address });
15
+ const here = dirname(fileURLToPath(import.meta.url));
16
+ const workflowsPath = resolve(here, 'workflows.js');
17
+ const worker = await Worker.create({
18
+ connection,
19
+ namespace,
20
+ taskQueue,
21
+ workflowsPath,
22
+ activities,
23
+ });
24
+ return worker;
25
+ }
26
+ //# sourceMappingURL=worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAQ9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,UAA8B,EAAE;IAChE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,gBAAgB,CAAC;IACpF,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC;IACjD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC;IAE1D,MAAM,UAAU,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAE/D,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAEpD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC;QACjC,UAAU;QACV,SAAS;QACT,SAAS;QACT,aAAa;QACb,UAAU;KACX,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type * as activities from './activities.js';
2
+ export interface RunAgentWorkflowInput {
3
+ agent: activities.RunAgentActivityInput['agent'];
4
+ secretsPath: string;
5
+ }
6
+ export interface RunAgentWorkflowResult {
7
+ result: string;
8
+ exitCode: number;
9
+ error?: string;
10
+ warnings: string[];
11
+ }
12
+ /**
13
+ * One-shot workflow: runs a single agent via activity.
14
+ * Kept simple — Temporal's value here is durability and scheduling, not
15
+ * multi-step orchestration (chaining lives in the core chain-executor).
16
+ */
17
+ export declare function runAgentWorkflow(input: RunAgentWorkflowInput): Promise<RunAgentWorkflowResult>;
18
+ //# sourceMappingURL=workflows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../src/workflows.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,UAAU,MAAM,iBAAiB,CAAC;AASnD,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,UAAU,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACjD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAKpG"}
@@ -0,0 +1,19 @@
1
+ import { proxyActivities } from '@temporalio/workflow';
2
+ const { runAgentActivity } = proxyActivities({
3
+ startToCloseTimeout: '10 minutes',
4
+ retry: {
5
+ maximumAttempts: 1, // Agent runs are not idempotent; don't auto-retry
6
+ },
7
+ });
8
+ /**
9
+ * One-shot workflow: runs a single agent via activity.
10
+ * Kept simple — Temporal's value here is durability and scheduling, not
11
+ * multi-step orchestration (chaining lives in the core chain-executor).
12
+ */
13
+ export async function runAgentWorkflow(input) {
14
+ return runAgentActivity({
15
+ agent: input.agent,
16
+ secretsPath: input.secretsPath,
17
+ });
18
+ }
19
+ //# sourceMappingURL=workflows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflows.js","sourceRoot":"","sources":["../src/workflows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,MAAM,EAAE,gBAAgB,EAAE,GAAG,eAAe,CAAoB;IAC9D,mBAAmB,EAAE,YAAY;IACjC,KAAK,EAAE;QACL,eAAe,EAAE,CAAC,EAAE,kDAAkD;KACvE;CACF,CAAC,CAAC;AAcH;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAA4B;IACjE,OAAO,gBAAgB,CAAC;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC,CAAC;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@some-useful-agents/temporal-provider",
3
+ "version": "0.1.0",
4
+ "description": "Temporal workflow provider for some-useful-agents",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "clean": "rm -rf dist"
10
+ },
11
+ "dependencies": {
12
+ "@some-useful-agents/core": "*",
13
+ "@temporalio/client": "^1.11.0",
14
+ "@temporalio/worker": "^1.11.0",
15
+ "@temporalio/workflow": "^1.11.0",
16
+ "@temporalio/activity": "^1.11.0"
17
+ },
18
+ "devDependencies": {
19
+ "typescript": "^5.8.0"
20
+ },
21
+ "license": "MIT",
22
+ "type": "module",
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "README.md",
29
+ "LICENSE"
30
+ ]
31
+ }